-
Notifications
You must be signed in to change notification settings - Fork 0
/
MSP430 ProgD.c
1160 lines (906 loc) · 32.5 KB
/
MSP430 ProgD.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*==========================================================================*\
| |
| MSP430 ProgD.c |
| |
| Main programfile |
|----------------------------------------------------------------------------|
| Project: MSP430 ProgD |
| Developed using: Microchip MPLAB IDE v8.66 + HITECHC Toolchain 9.83 |
|----------------------------------------------------------------------------|
| Author: STO |
| Version: 1.6 |
| Initial Version: 04-17-02 |
| Last Change: 13-13-05 |
|----------------------------------------------------------------------------|
| Version history: |
| 1.0 04/12 STR Initial version. |
|----------------------------------------------------------------------------|
| Designed 2012 by Steven Rott (STR) |
\*==========================================================================*/
#include "p18f4620.h"
#include "JTAGfunc.h"
#include "MSP430 ProgD.h"
#include "IO.h"
#include "LowLevelfunc.h"
// Configuration bits for PIC16f887
#pragma config OSC = INTIO67
#pragma config WDT = OFF
#pragma config PWRT = ON
#pragma config BOREN = OFF
#pragma config PBADEN = OFF
#pragma config STVREN = OFF
#pragma config XINST = OFF
#pragma code low_vector=0x18
void lowInterrupt(void)
{
_asm GOTO rxInISR _endasm
}
// This is needed to convert the hexadecimal content of the memory to
// rom character set of the display so the user can see whats in the
// memory. This is stored in RAM...
#pragma rom codepad
rom word codepad[2][16]=
{ '0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F',
0x0000,0x1000,0x2000,0x3000,0x4000,0x5000,0x6000,0x7000,0x8000,
0x9000,0xA000,0xB000,0xC000,0xD000,0xE000,0xF000
};
#pragma rom
/*
#pragma rom byteCodepad
rom byte byteCodepad[2][16]=
{ '0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F',
0x00,0x10,0x20,0x30,0x40,0x50,0x60,0x70,0x80,0x90,0xA0,0xB0,0xC0,0xD0,0xE0,0xF0
};
#pragma rom
*/
/* the type of firmware to work with...
the 3dimensional array 'dataLocator' contains the adresses of the needed information
depending on the firmware version (MAR2009, JAN2012) and device type (INT_LN_R, RN_ER).
___________ ________ ____________ _____________ __________
....... | NETID | SGMT-IN | SGMT-OUT | FREQ |
-----------|--------|------------|-------------|--------- |
___________ ________ ____________ _____________ __________ |
RN_ER(0x02)| NETID | SGMT-IN | SGMT-OUT | FREQ |--|
-----------|--------|------------|-------------|----------| |
______________ _________ ____________ _____________ _________ |--|
INT_LN_R(0x01)| NETID | SGMT-IN | SGMT-OUT | FREQ |--| |
--------------|---------|------------|-------------|---------| |--|
(0x01) MAR2009 | 0x8010 | 0x8012 | N/A | N/A |--|
--------------|---------|------------|-------------|---------| |
(0x02) JAN2012 | N/A | N/A | N/A | N/A |--|
--------------|---------|------------|-------------|---------|
(0x03) | | | | |
--------------|---------|------------|-------------|---------|
...
*/
const word data13[4]={0x0A00,0xFF00,0x0000,0x0000};
const word data1[8]={0xA06A,0x0100,0x0008,0xF008,0xA0DA,0x0004,0x0012,0xA27E};
typedef struct{
word net_id_adress;
word sgmt_in_adress;
word sgmt_out_adress;
word freq_adress;
}device;
device int_ln_r;
#pragma rom dataLocator
static rom word dataLocator[4][5]= // [devicetype], [datatype]
{
0,0,0,0,0,
INT_LN_R_NETID, INT_LN_R_SGMT_IN, 0, INT_LN_R_FREQ_A, INT_LN_R_FREQ_B,
RN_ER_2009_NETID, RN_ER_2009_SGMT_IN, RN_ER_2009_SGMT_OUT, RN_ER_2009_FREQ_A,RN_ER_2009_FREQ_B,
0,0,0,0,0
};
#pragma rom
// ISR for recieve
byte charcount=0;
byte length=0;
byte serialdata[8];
word adrSRAM=0x0000;
struct StatusBits {
unsigned rx_begin:1;
unsigned high_nibble:1;
unsigned ready:1;
unsigned rx_len:1;
unsigned high_byte:1;
unsigned rx_adress:1;
unsigned rx_data:1;
unsigned rx_ack:1;
} STATbits={0,1,0,0,1,0,0,0};
#pragma interruptlow rxInISR
void rxInISR(void)
{
byte rxbuf=RCREG;
if(!STATbits.ready)
{
txOut(13,0);
txOut(0,(rom byte*)"Device not ready yet.");
txOut('\n',0);
txOut(13,0);
txOut(0,(rom byte*)"Please start 'programming mode' first,");
txOut('\n',0);
txOut(13,0);
txOut(0,(rom byte*)"by pressing '014'");
txOut('\n',0);
return;
}
/*-----------------------------------------------------------------
Recieving the bytecount from the USART...
------------------------------------------------------------------ */
if(STATbits.rx_begin)
{
serialdata[charcount]=rxbuf;
charcount++;
if(charcount==8u)
{
STATbits.rx_data=TRUE;
STATbits.rx_begin=FALSE;
charcount=0;
length|=ascii2hex(serialdata[0]);
length<<=4;
length|=ascii2hex(serialdata[1]);
length+=length;
adrSRAM|=ascii2hex(serialdata[2]);
adrSRAM<<=4;
adrSRAM|=ascii2hex(serialdata[3]);
adrSRAM<<=4;
adrSRAM|=ascii2hex(serialdata[4]);
adrSRAM<<=4;
adrSRAM|=ascii2hex(serialdata[5]);
}
}
if(STATbits.rx_data&&length)
{
sramWrite(adrSRAM,rxbuf);
length--;
adrSRAM++;
}
if(rxbuf==':')
{
STATbits.rx_begin=TRUE;
STATbits.rx_ack=TRUE;
STATbits.high_nibble=TRUE;
STATbits.rx_len=TRUE;
length=0;
charcount=0;
}
}
/*---------------------------------------------------------------------------
This is the main routine
Arguments:
Result:
*/
void main(void)
{
byte i=0x03;
byte serialData;
byte* dataP;
word iterA;
byte iterB=0;
word adress;
byte temp_2=0;
byte firmwareVersion=0x00;
word cmd;
byte keyStroke;
initController();
// PORT A,B,C*,D* and E as output
// PORTA.0 = !WR (Display and SRAM)
// PORTA.1 = !RD (Display and SRAM)
// PORTA.2 = CS1 (CS LCD)
// PORTA.3 = CD (Command / data input of the display controller)
// PORTA.4 = LAL (AdressLatch of A8..15)
// PORTA.5 = HAL (AdressLatch of A0..7)
// PORTA.6 = AEN (16bit Adress output enable)
// PORTA.7 = CS2 (CS SRAM)
TRISA = 0b00000000; // used for the display and sram (bus control port)
LATA = 0b11001111;
TRISB = 0b11111111; // used as multiplexed adress/databus (for the display and the sram)
TRISC = 0b11000001; // *RC0 - RC5 JTAG Interface PortC.0 is TDO, RC6 UART TX, RC7 UART RX
LATC = 0b00111110;
TRISD = 0b11110000; // *used for the matrix keypad
TRISE = 0b00000000; // unused for now...
// initialize the display controller, (re)start the display and
// draw the "mainmenu-frame"
displayInit();
// show me the Device is working...
txOut(0,(rom byte*)"MSP430 ProgD v0.01");
txOut('\n',0); txOut(13,0);
while(1)
{
switch(getWholeCommand()) // get the user command from the keyboard...
{ // and switch to the corresponding (sub)menu.
case 0x0010:
{ // "< max-length >"
printToScreen(0,0,(rom byte*)">010: applications ",1,1);
printToScreen(0,0,(rom byte*)">020: settings ",1,2);
printToScreen(0,0,(rom byte*)" ",1,3);
printToScreen(0,0,(rom byte*)">030: help ",1,4);
printToScreen(0,0,(rom byte*)" ",1,6);
}break;
case 0x0100:
{ // "< max-length >"
printToScreen(0,0,(rom byte*)">011: clone device ",1,1);
printToScreen(0,0,(rom byte*)">012: read config ",1,2);
printToScreen(0,0,(rom byte*)">013: routersearch ",1,3);
printToScreen(0,0,(rom byte*)">014: progr. mode ",1,4);
printToScreen(0,0,(rom byte*)" ",1,5);
printToScreen(0,0,(rom byte*)"<001: back ",1,6);
}break;
case 0x0110:
{ // "< max-length >"
printToScreen(0,0,(rom byte*)"reading FW data... ",1,1);
printToScreen(0,0,(rom byte*)" ",1,2);
printToScreen(0,0,(rom byte*)" ",1,3);
printToScreen(0,0,(rom byte*)" ",1,4);
printToScreen(0,0,(rom byte*)"<010: back",1,6);
if(GetDevice()!=1u)
{ // "< max-length >"
printToScreen(0,0,(rom byte*)" ERROR 0x1F! ",1,1);
printToScreen(0,0,(rom byte*)" INVALID JTAG-ID! ",1,2);
printToScreen(0,0,(rom byte*)" no connection? ",1,3);
printToScreen(0,0,(rom byte*)"<012: retry ",1,5);
break;
}
else
{
msDelay(1000);
//EraseFLASH(3,0x8000);
txOut('\n',0); txOut(13,0);
txOut(0,(rom byte*)"here comes the data...");
// iterA=adrSRAM;
adrSRAM=0x8000;
txOut('\n',0); txOut(13,0);
for(adrSRAM=0x8000;adrSRAM<=0x8100;adrSRAM++)
{
serialData=sramRead(adrSRAM);
txOut(serialData,0);
}
ReleaseDevice(V_RESET);
}
//WriteFLASH(0x8000,8,data1);
//WriteFLASH(0x8080,4,data13);
}break;
case 0x0120:
{
// "< max-length >"
printToScreen(0,0,(rom byte*)" analysing FW ver ",1,1);
printToScreen(0,0,(rom byte*)" please wait... ",1,2);
printToScreen(0,0,(rom byte*)" ",1,3);
printToScreen(0,0,(rom byte*)" ",1,4);
printToScreen(0,0,(rom byte*)" ",1,5);
printToScreen(0,0,(rom byte*)"<010: back",1,6);
if(GetDevice()!=1u)
{ // "< max-length >"
printToScreen(0,0,(rom byte*)" ERROR 0x1F! ",1,1);
printToScreen(0,0,(rom byte*)" INVALID JTAG-ID! ",1,2);
printToScreen(0,0,(rom byte*)" no connection? ",1,3);
printToScreen(0,0,(rom byte*)"<012: retry ",1,5);
break;
}
else
{
firmwareVersion=getFirmwareVersion();
cacheFirmware(firmwareVersion);
drawFirmwareInfo(firmwareVersion);
msDelay(50);
ReleaseDevice(V_RESET);
}
}break;
case 0x0130:
{ // "< max-length >"
printToScreen(0,0,(rom byte*)" reading current ",1,1);
printToScreen(0,0,(rom byte*)" configuration... ",1,2);
printToScreen(0,0,(rom byte*)" ",1,3);
printToScreen(0,0,(rom byte*)" ",1,4);
printToScreen(0,0,(rom byte*)"<010: back",1,6);
msDelay(1000);
cacheFirmware(INT_LN_R);
drawFirmwareInfo(INT_LN_R);
// "< max-length >"
// "< max-length >"
// printToScreen(0,0,(rom byte*)" edit new config ",1,1);
// printToScreen(0,0,(rom byte*)" ",1,2);
// printToScreen(0,0,(rom byte*)" ",1,3);
printToScreen(0,0,(rom byte*)" please specify new values by ",1,8);
printToScreen(0,0,(rom byte*)" pressing the 'E'key. Press it again ",1,9);
printToScreen(0,0,(rom byte*)" when finished. ",1,10);
while(waitForSingleKey(ASCII)!='E');
usDelay(1000);
keyStroke=0xFF;
while(waitForSingleKey(ASCII)!=0xFF)
usDelay(1000);
for(iterA=0u; iterA<=3u; iterA++){
display(2,15+iterA,1,0x21); // Cursor Pointer (x,y)
while(keyStroke==0xFF)
keyStroke=waitForSingleKey(ASCII);
printToScreen(keyStroke,0,0,15+iterA,1);
keyStroke=0xFF;
while(waitForSingleKey(ASCII)!=0xFF)
usDelay(100);
}
for(iterB=0u; iterB<=63u; iterB++){
temp_2=sramRead(iterB);
temp_2>>=4;
txOut(hex2ascii(temp_2&0x0F),0);
txOut(hex2ascii((sramRead(iterB)&0x0F)),0);
}
EraseFLASH(3,0x8000);
writeFirmware(0x8000,3);
}break;
case 0x0140:
{ // "< max-length >"
// "< max-length >"
printToScreen(0,0,(rom byte*)" You need to erase ",1,1);
printToScreen(0,0,(rom byte*)" the target before ",1,2);
printToScreen(0,0,(rom byte*)" you can continue. ",1,3);
printToScreen(0,0,(rom byte*)" (E)rase. (A)bort ",1,4);
printToScreen(0,0,(rom byte*)"<010: back",1,6);
txOut('\n',0);
txOut(13,0);
txOut(0,(rom byte*)"Device ready for ERASE...");
while(keyStroke!=3u||4u)
{
keyStroke=waitForSingleKey(ASCII);
if(keyStroke==4u)
{
txOut('\n',0);
txOut(13,0);
txOut(0,(rom byte*)"ERASING...");
/*
if(GetDevice()!=1u)
{ // "< max-length >"
printToScreen(0,0,(rom byte*)" ERROR 0x1F! ",1,1);
printToScreen(0,0,(rom byte*)" INVALID JTAG-ID! ",1,2);
printToScreen(0,0,(rom byte*)" no connection? ",1,3);
printToScreen(0,0,(rom byte*)" ",1,4);
printToScreen(0,0,(rom byte*)"<014: retry ",1,5);
break;
}
*/
printToScreen(0,0,(rom byte*)" ERASING... ",1,1);
printToScreen(0,0,(rom byte*)" ",1,2);
printToScreen(0,0,(rom byte*)" ",1,3);
printToScreen(0,0,(rom byte*)" ",1,4);
for(adress=0x8000;adress<=0xFE00;adress+=0x100)
{
// EraseFLASH(3,adress);
}
printToScreen(0,0,(rom byte*)" DONE... ",1,1);
txOut('\n',0); txOut(13,0);
txOut(0,(rom byte*)"ready...");
STATbits.ready=1;
STATbits.rx_ack=FALSE;
adrSRAM=0x0000;
while(!STATbits.rx_ack)
{
printToScreen(0,0,(rom byte*)" Waiting for FW ",1,1);
printToScreen(0,0,(rom byte*)" data. Press 'F' ",1,2);
printToScreen(0,0,(rom byte*)" Button when the ",1,3);
printToScreen(0,0,(rom byte*)" transfer is done. ",1,4);
}
printToScreen(0,0,(rom byte*)" receiving DATA... ",1,1);
printToScreen(0,0,(rom byte*)" ",1,2);
printToScreen(0,0,(rom byte*)" ",1,3);
printToScreen(0,0,(rom byte*)" ",1,4);
}
else if(keyStroke==3u)
{
cmd=0x0100;
txOut('\n',0);
txOut(13,0);
txOut(0,(rom byte*)"Transmission terminated...");
printToScreen(0,0,(rom byte*)">010: applications ",1,1);
printToScreen(0,0,(rom byte*)">020: settings ",1,2);
printToScreen(0,0,(rom byte*)" ",1,3);
printToScreen(0,0,(rom byte*)">030: help ",1,4);
printToScreen(0,0,(rom byte*)" ",1,6);
txOut('\n',0); txOut(13,0);
txOut(0,(rom byte*)"here comes the data...");
// iterA=adrSRAM;
adrSRAM=0x8000;
txOut('\n',0); txOut(13,0);
for(adrSRAM=0x8000;adrSRAM<=0x8100;adrSRAM++)
{
serialData=sramRead(adrSRAM);
txOut(serialData,0);
}break;
}
}
}break;
}
}
}
/*---------------------------------------------------------------------------
This routine is used to write data from sram to flash
Arguments:
Result:
*/
byte writeFirmware(word startAdr, word lenght)
{
byte flashDataByte[16];
word* wDataP;
word flashDataWord[8]={0,0,0,0,0,0,0,0};
byte serialData;
byte serialDataBackup;
byte iterA, iterB;
adrSRAM=0x0000;
txOut('\n',0); txOut(13,0);
for(iterB=0u; iterB<=length;iterB++){ // The data is written to the flash in lines...
for(iterA=0u;iterA<=15u;iterA++){ // of 8 Words each.
serialData=sramRead(adrSRAM);
flashDataByte[iterA]=serialData;
serialDataBackup=serialData;
serialData>>=4;
if(!(iterA%2)&&iterA) // Print out a space char each word (rs232 debugging)
txOut(' ',0);
txOut(hex2ascii(serialData&=0x0F),0); // Print out each Data written to flash...
serialData=serialDataBackup;
txOut(hex2ascii(serialData&=0x0F),0);
if(!(iterA%2)){ // convert sram bytes to little endian format word
// i.e. A6 6E -> 6EA6
flashDataWord[iterA/2]|=serialDataBackup;
flashDataWord[iterA/2]<<=8;
}
else{
flashDataWord[iterA/2]|=serialDataBackup;
}
adrSRAM++;
}
wDataP=flashDataWord;
WriteFLASH(startAdr+(iterB*0x0010),8u,wDataP);
}
ReleaseDevice(V_RESET);
}
/*---------------------------------------------------------------------------
In the first step, here i'll try to find out which FW version i have.
This is important as the information needed is located in an different
location in the flash memory. The Location differs in every FW ver.
Additionally i need to figure out whats the type of component connected
as the Locknodes dont need two segments like the routers...
Arguments: none
Result: 0x01 means: I found a WN.RN.ER with FW of 2009
0x02 means: I found a WN.RN.ER with FW of 2012
0x00 means: I cannot find any known FW
TODO: add the different nodetypes and FW versions
*/
byte getFirmwareVersion(void)
{
word data[6];
word i;
for(i=0xA200;i<0xA4FF;i+=2u) //nothing found? maybe another FW ver!
{
data[0]=ReadMem(F_WORD,i);
if(data[0]==0x7541u)
return RN_ER_2009;
}
for(i=0xEA00;i<0xEDFF;i+=2u) //nothing found? maybe another FW ver!
{
data[0]=ReadMem(F_WORD,i);
if(data[0]==0x614Au)
return RN_ER_2012;
}
return 0; //i did not found any known FW ver info segment!
}
/*---------------------------------------------------------------------------
In the second step, i'll put the corresponding data segment to the
SRAM. The data will get lost otherwise because of the need to
erase the specific flash segment before write. The PIC18F4620 has
4K of RAM. I use a hardware attached 64K 15ns SRAM (61512 AK)
Arguments: The "Firmware Version". Which means basically the type of Device.
Depending on this, different adress locations needed to
be cached.
Result: 0x01 means: a WN.RN.ER with FW of 2009
0x02 means: a WN.RN.ER with FW of 2012
0x30 means: the internal LN.R
0x00 means: I cannot find any known FW
TODO: add the different nodetypes and FW versions
*/
byte cacheFirmware(byte fwVer)
{
word flashDataWord=0x0000;
word flashDataWordBackup=0x0000;
byte flashDataByte=0x00;
byte flashDataByteBackup=0x00;
word adrSRAM=0x8000;
word* ramP;
word iterA=0x0000;
word iterB=0x0000;
switch (fwVer)
{
case RN_ER_2009:
{
//ramP=firmwareData1;
for(adrSRAM=0x8000;adrSRAM<0x808F;adrSRAM+=2u)
{
*ramP=ReadMem(F_WORD,adrSRAM);
ramP++;
}
return STATUS_OK;
}break;
case RN_ER_2012:
{
//ramP=firmwareData1;
for(adrSRAM=0x8000;adrSRAM<0x806F;adrSRAM+=2u)
{
*ramP=ReadMem(F_WORD,adrSRAM);
ramP++;
}
return STATUS_OK;
}break;
case INT_LN_R:
{
//ramP=firmwareData1;
for(adrSRAM=0x8000u;adrSRAM<=0x803Fu;adrSRAM+=2u){
flashDataWord=ReadMem(F_WORD,adrSRAM);
flashDataWordBackup=flashDataWord;
for(iterB=0u; iterB<=1u; iterB++){
flashDataByteBackup|=flashDataWordBackup;
flashDataByteBackup>>=4;
txOut(hex2ascii(flashDataByteBackup&0x0F),0);
txOut(hex2ascii(flashDataWordBackup&0x000F),0);
flashDataWordBackup>>=8;
}
txOut(' ',0);
flashDataByte=flashDataWord;
flashDataWord>>=8;
sramWrite(iterA,flashDataByte);
flashDataByte=flashDataWord;
sramWrite(iterA+1,flashDataByte);
iterA+=2;
}
return STATUS_OK;
}break;
default:
return STATUS_ERROR;
}
}
/*---------------------------------------------------------------------------
Here, the internals of the components firmware is brought to the user
via the screen.
Arguments:
Result: STATUS_ERROR (0)
STATUS_OK (1)
TODO: add the different nodetypes and FW versions
*/
byte drawFirmwareInfo(byte firmwareVersion)
{
switch (firmwareVersion)
{
case NOT_KNOWN:
{
printToScreen(0,0,(rom byte*)" ERROR 0x0F! ",1,1);
printToScreen(0,0,(rom byte*)" UNKOWN FW-ver! ",1,2);
printToScreen(0,0,(rom byte*)"<012: retry ",1,5);
return STATUS_ERROR;
}break;
case RN_ER_2009:
{
// "< max-length >"
printToScreen(0,0,(rom byte*)" FOUND WN.RN.XX ",1,1);
printToScreen(0,0,(rom byte*)" FWver 03.08.2009 ",1,2);
printToScreen(0,0,(rom byte*)" ",1,5);
msDelay(5000);
}break;
case RN_ER_2012:
{
// "< max-length >"
printToScreen(0,0,(rom byte*)" FOUND WN.RN.XX ",1,1);
printToScreen(0,0,(rom byte*)" FWver 03.01.2012 ",1,2);
printToScreen(0,0,(rom byte*)" ",1,5);
msDelay(5000);
}break;
case INT_LN_R:
{
/* // "< max-length >"
printToScreen(0,0,(rom byte*)" Please set the ",1,1);
printToScreen(0,0,(rom byte*)" NETID, SGMT and ",1,2);
printToScreen(0,0,(rom byte*)" Freq. and press ",1,3);
printToScreen(0,0,(rom byte*)" the 'E' key. ",1,4);
msDelay(3000);
*/
cls();
drawInputSgmt(INT_LN_R);
drawNetID(INT_LN_R);
drawFreq(INT_LN_R);
}break;
}
return STATUS_OK;
}
/*---------------------------------------------------------------------------
This is the xy routine
Arguments:
Result:
*/
void drawFreq(byte firmwareVersion){
// the carrier freq is coded as 3 bytes in 2 words, thus the last byte in word 2
// is not used to determine the carrier frequency. each word is little-endian and
// must be converted to big-endian before calculating the correct carrier frequency
// i.e. word 1 = 6E21; word 2 = 99D5 the correct register value is 216ED5 = 2191061 dec :)
// the carrier freq for ti's c1101 is then calc with
// the equation 26.000.000 * 2191061 / 65536 = 869(,)256.387 (M)Hz
byte byteContainer[5]={0,0,0,0,0};
byte cntByteIter;
byte indexCodepad; // indexcounter for the codepad conversion hex <> ascii
byte cntHLByteIter;
byte cntIterForDecData=0;
byte* data_ptr;
word rawData[3];
byte decodedData[10];
dword carrierFreqReg=0;
ufloat carrierFreq=0;
rawData[0]=ReadMem(F_WORD,dataLocator[firmwareVersion][FREQ_A]);
rawData[1]=ReadMem(F_WORD,dataLocator[firmwareVersion][FREQ_B]);
byteContainer[0]|=rawData[0]; // the order of loading the byteContainer defines which byte
rawData[0]>>=8; // of each word is displayed and stored first
byteContainer[1]|=rawData[0]; // important for calculating !
byteContainer[2]|=rawData[1];
//rawData[1]>>=8; // no need to touch the last byte (yet)
//byteContainer[3]|=rawData[1];
for(cntByteIter=0; cntByteIter<3u; cntByteIter++){
carrierFreqReg<<=8;
carrierFreqReg|=byteContainer[cntByteIter];
}
switch (carrierFreqReg){
case 0x00216ed5u:
printToScreen(0,0,(rom byte*)"CarrierFreq: 869,2563MhZ ",2,4);
break;
case 0x002165c2u:
printToScreen(0,0,(rom byte*)"CarrierFreq: 868,3347MhZ ",2,4);
break;
default:
printToScreen(0,0,(rom byte*)"CarrierFreq: NOT FOUND ",2,4);
}
}
/*---------------------------------------------------------------------------
This is the xy routine
Arguments:
Result:
*/
void drawInputSgmt(byte firmwareVersion){
byte j;
byte k;
byte* data_ptr;
word data[2];
byte decodedData[9];
data[0]=ReadMem(F_WORD,dataLocator[firmwareVersion][SEGM_IN]);//
data[1]=data[0];
for(j=0; j<4u; j++)
{
data[0]=data[1];
data[0]&=0xF000;
for(k=0u; k<=15u; k++)
{
if(codepad[1][k]==data[0])
decodedData[j]=codepad[0][k];
}
data[1]<<=4;
}
decodedData[4]='\0';
// "< max-length >"
printToScreen(0,0,(rom byte*)"InputSGMT: ",2,1);
data_ptr=decodedData;
printToScreen(0,data_ptr,0,15,1);
}
/*---------------------------------------------------------------------------
This is the xy routine
Arguments:
Result:
*/
void drawOutputSgmt(byte firmwareVersion){
byte j;
byte k;
byte* data_ptr;
word data[2];
byte decodedData[9];
data[0]=ReadMem(F_WORD,dataLocator[firmwareVersion][SEGM_OUT]); //0x8024
data[1]=data[0];
for(j=0; j<4u; j++)
{
data[0]=data[1];
data[0]&=0xF000;
for(k=0; k<=15u; k++)
{
if(codepad[1][k]==data[0])
decodedData[j]=codepad[0][k];
}
data[1]<<=4;
}
decodedData[4]='\0';
// "< max-length >"
printToScreen(0,0,(rom byte*)"OutputSGMT: ",2,2);
data_ptr=decodedData;
printToScreen(0,data_ptr,0,15,2);
}
/*---------------------------------------------------------------------------
This is the xy routine
Arguments:
Result:
*/
void drawNetID(byte firmwareVersion){
byte j;
byte k;
byte* data_ptr;
word data[2];
byte decodedData[9];
data[0]=ReadMem(F_WORD,dataLocator[firmwareVersion][NETID]);//
data[1]=data[0];
for(j=0; j<4u; j++)
{
data[0]=data[1];
data[0]&=0xF000;
for(k=0u; k<=15u; k++)
{
if(codepad[1][k]==data[0])
decodedData[j]=codepad[0][k];
}
data[1]<<=4;
}
decodedData[4]='\0';
// "< max-length >"
printToScreen(0,0,(rom byte*)"NetID: ",2,3);
data_ptr=decodedData;
printToScreen(0,data_ptr,0,15,3);
}
/*---------------------------------------------------------------------------
This is the xy routine
Arguments:
Result:
*/
byte ascii2hex(byte ascii)
{
//byte temp=ascii;
if(ascii>=48u||ascii<=57u)
return ascii-48;
else if(ascii>=65u||ascii<=70u)
return ascii-55u;
else
return 0;
}
/*---------------------------------------------------------------------------
This is the xy routine
Arguments:
Result:
*/
byte hex2ascii(byte hex)
{
//byte temp=ascii;
if(hex>=0u&&hex<=9u)
return hex+=48;
else if(hex>=10u&&hex<=15u)
return hex+=55;
else
return 0;
}
//#######################################################################################