-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfaV3FirmwareTools.c
More file actions
1332 lines (1102 loc) · 31 KB
/
faV3FirmwareTools.c
File metadata and controls
1332 lines (1102 loc) · 31 KB
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
/* Module: faV3FirmwareTools.c
*
* Description: FADC250 Firmware Tools Library
* Firmware specific functions.
*
* Author:
* Bryan Moffit
* JLab Data Acquisition Group
*
*/
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <pthread.h>
#include <string.h>
#include <ctype.h>
#include <byteswap.h>
#include "faV3Lib.h"
#include "faV3FirmwareTools.h"
extern pthread_mutex_t faV3Mutex;
#define FAV3LOCK if(pthread_mutex_lock(&faV3Mutex)<0) perror("pthread_mutex_lock");
#define FAV3UNLOCK if(pthread_mutex_unlock(&faV3Mutex)<0) perror("pthread_mutex_unlock");
extern int32_t nfaV3;
extern int32_t faV3ID[FAV3_MAX_BOARDS];
extern volatile faV3_t *FAV3p[(FAV3_MAX_BOARDS + 1)]; /* pointers to FAV3 memory map */
#define CHECKID { \
if(id == 0) id = faV3ID[0]; \
if((id <= 0) || (id > 21) || (FAV3p[id] == NULL)) { \
printf("%s: ERROR : ADC in slot %d is not initialized \n", __func__, id); \
return ERROR; }}
#define WAITFORREADY { \
int32_t ready_ret = faV3FirmwareWaitForReady(id, FAV3_FIRMWARE_WAIT, 0); \
if(ready_ret == ERROR) { \
printf("%s: ERROR: Timeout\n", __func__); \
return ERROR; \
}}
const uint32_t ConfigRomHostEndOfCmd = 0x0100;
const uint32_t ConfigRomHostExec = 0x0200;
const uint8_t ConfigRom_RDID = 0x9F; // Read ROM Identification registers For S256 the bytes are 0x0102194D
const uint8_t ConfigRom_RDSR1 = 0x05; // Read status register 1
const uint8_t ConfigRom_WRDI = 0x04; // Disable write to ROM non-Volatile memory
const uint8_t ConfigRom_WREN = 0x06; // Enable write to ROM non-Volatilde memory
const uint8_t ConfigRom_BE = 0x60; // BULK Erase
const uint8_t ConfigRom_PP4 = 0x12; // Write to ROM volatalile memory. Content store to ROM on rising edge of ROM CSN
const uint8_t ConfigRom_AREAD = 0X13; // Read FLASH Array Low memory then higher memory
const uint32_t ConfigRom_SR1V_WEL = 2; // Write Enable Latch 1= Can write to memory, registers
const uint32_t ConfigRom_SR1V_WIP = 1; // 1 = Write in progress
const uint32_t ConfigRomReadyForCommand = 0x2;
const uint32_t ConfigRomRebootFPGA = (1 << 11);
#define MAX_FW_SIZE 0x1800000
#define FAV3_FW_SIZE 0x1701DEC
#define FAV3_FIRMWARE_WAIT 200
#define VME_CONFIG6_ADR &FAV3p[id]->config_rom_control0
#define VME_CONFIG7_ADR &FAV3p[id]->config_rom_control1
#define VME_CONFIG8_ADR &FAV3p[id]->config_rom_control2
#define VME_STATUS5_ADR &FAV3p[id]->config_rom_status0
typedef struct {
char filename[256];
int32_t loaded;
uint32_t size;
uint32_t data[MAX_FW_SIZE>>2];
} faV3fw_t;
faV3fw_t *file_firmware = NULL;
faV3fw_t *rom_firmware = NULL;
VOIDFUNCPTR faV3UpdateWatcherRoutine = NULL;
faV3UpdateWatcherArgs_t faV3UpdateWatcherArgs;
/**
* @brief Wait for config rom to report ReadyForCmd
* @param[in] id faV3 slot ID
* @param[in] nwait Max number of tries
* @return If ready, number of tries before ready, otherwise ERROR.
*/
int32_t
faV3FirmwareWaitForReady(int32_t id, int32_t nwait, int32_t pflag)
{
int32_t rval = OK;
uint32_t regval = 0, iwait = 0;
CHECKID;
while( ((regval & ConfigRomReadyForCommand)==0) && (iwait++ < nwait) )
{
FAV3LOCK;
regval = vmeRead32(&FAV3p[id]->config_rom_status1);
FAV3UNLOCK;
}
if(regval & ConfigRomReadyForCommand)
{
rval = iwait;
}
else
{
printf("%s: ERROR: timeout after %d tries\n",
__func__, iwait);
rval = ERROR;
}
if(pflag)
{
printf("%s: INFO: Ready after %d tries\n",
__func__, iwait);
}
return rval;
}
/**
* @brief Wait for config rom to report write in progress is done
* @param[in] id faV3 slot ID
* @param[in] nwait Max number of tries
* @return If ready, number of tries before ready, otherwise ERROR.
*/
int32_t
faV3FirmwareWaitForWIP(int32_t id, int32_t nwait, int32_t pflag)
{
int32_t rval = OK;
uint32_t wipval = 0, iwait = 0;
faV3UpdateWatcherArgs_t updateArgs;
CHECKID;
wipval = faV3FirmwareRomStatus1(id) & ConfigRom_SR1V_WIP;
while((iwait++ < nwait) && (wipval != 0))
{
if(nwait > 1000)
{
updateArgs.step = FAV3_UPDATE_STEP_ERASE;
updateArgs.show = FAV3_ARGS_SHOW_PROGRESS;
faV3FirmwareUpdateWatcher(updateArgs);
}
usleep(1000);
wipval = faV3FirmwareRomStatus1(id) & ConfigRom_SR1V_WIP;
}
if(wipval == 0)
{
rval = iwait;
}
else
{
printf("%s: ERROR: timeout after %d tries\n",
__func__, iwait);
rval = ERROR;
}
if(nwait > 1000)
{
updateArgs.step = FAV3_UPDATE_STEP_ERASE;
updateArgs.show = FAV3_ARGS_SHOW_DONE;
faV3FirmwareUpdateWatcher(updateArgs);
}
if(pflag)
{
printf("%s: INFO: Ready after %d tries\n",
__func__, iwait);
}
return rval;
}
/**
* @brief Read ROM ID from ROM Chip
* @param[in] id faV3 Slot ID
* @return ROM ID, if successful.
*/
uint32_t
faV3FirmwareRomID(int32_t id)
{
uint32_t rval = 0;
uint32_t cmd, romadr, romdata = 0;
CHECKID;
WAITFORREADY;
cmd = ConfigRomHostEndOfCmd | ConfigRom_RDID;
FAV3LOCK;
cmd = ConfigRomHostExec | cmd;
vmeWrite32(VME_CONFIG6_ADR, cmd); // Execute Command
cmd = cmd & ~ConfigRomHostExec;
vmeWrite32(VME_CONFIG6_ADR, cmd); // Ready for Next Command
FAV3UNLOCK;
WAITFORREADY;
FAV3LOCK;
rval = vmeRead32(VME_STATUS5_ADR);
FAV3UNLOCK;
return rval;
}
/**
* @brief Read ROM STATUS1 register from ROM Chip
* @param[in] id faV3 Slot ID
* @return ROM STATUS1, if successful.
*/
uint32_t
faV3FirmwareRomStatus1(int32_t id)
{
uint32_t rval;
uint32_t cmd, romdata = 0;
CHECKID;
WAITFORREADY;
cmd = ConfigRomHostEndOfCmd | ConfigRom_RDSR1;
FAV3LOCK;
vmeWrite32(VME_CONFIG6_ADR, cmd); // Rom Command
cmd = ConfigRomHostExec | cmd;
vmeWrite32(VME_CONFIG6_ADR, cmd); // Execute Command
cmd = cmd & ~ConfigRomHostExec;
vmeWrite32(VME_CONFIG6_ADR, cmd); // Ready for Next Command
FAV3UNLOCK;
WAITFORREADY;
FAV3LOCK;
rval = vmeRead32(VME_STATUS5_ADR);
FAV3UNLOCK;
return rval;
}
/**
* @brief Enable or Disable Writing to ROM
* @param[in] id faV3 Slot ID
* @param[in] enable
* 0: disable
* 1: enable
* @return ROM Status1
*/
uint32_t
faV3FirmwareSetMemoryWrite(int32_t id, int32_t enable)
{
uint32_t rval;
uint32_t cmd, romdata = 0;
CHECKID;
WAITFORREADY;
if(enable)
cmd = ConfigRomHostEndOfCmd | ConfigRom_WREN;
else
cmd = ConfigRomHostEndOfCmd | ConfigRom_WRDI;
FAV3LOCK;
vmeWrite32(VME_CONFIG6_ADR, cmd); // Rom Command
cmd = ConfigRomHostExec | cmd;
vmeWrite32(VME_CONFIG6_ADR, cmd); // Execute Command
cmd = cmd & ~ConfigRomHostExec;
vmeWrite32(VME_CONFIG6_ADR, cmd); // Ready for Next Command
FAV3UNLOCK;
WAITFORREADY;
FAV3LOCK;
if(!enable)
rval = vmeRead32(VME_STATUS5_ADR);
FAV3UNLOCK;
if(enable)
rval = faV3FirmwareRomStatus1(id) & ConfigRom_SR1V_WEL;
return rval;
}
/**
* @brief Erase the ROM
* @param[in] id faV3 Slot ID
* @return OK if successful, otherwise ERROR
*/
int32_t
faV3FirmwareRomErase(int32_t id, int32_t waitforWIP)
{
int32_t rval;
uint32_t cmd;
CHECKID;
rval = faV3FirmwareSetMemoryWrite(id, 1);
if(rval == 0)
{
printf("%s: ERROR: Write not enabled\n",
__func__);
return -1;
}
WAITFORREADY;
cmd = ConfigRomHostEndOfCmd | ConfigRom_BE;
FAV3LOCK;
vmeWrite32(VME_CONFIG6_ADR, cmd); // Rom Command
cmd = ConfigRomHostExec | cmd;
vmeWrite32(VME_CONFIG6_ADR, cmd); // Execute Command
cmd = cmd & ~ConfigRomHostExec;
vmeWrite32(VME_CONFIG6_ADR, cmd); // Ready for Next Command
FAV3UNLOCK;
if(waitforWIP)
{
rval = faV3FirmwareWaitForWIP(id, 200000, 0);
if(rval < 0)
{
printf("%s: Failed to erase Config ROM. romstatus1 = 0x%08x\n",
__func__, faV3FirmwareRomStatus1(id));
return -1;
}
else
rval = 0;
}
else
rval = 0;
return rval;
}
/**
* @brief Read the contents of the ROM at specified address
* @param[in] id faV3 slot ID
* @param[in] romadr ROM Address
* @param[in] last Whether or not this is the end of the page
* @return Data from ROM, if successful
*/
int32_t
faV3FirmwareReadRomAdr(int32_t id, uint32_t romadr, int32_t last)
{
uint32_t rval;
uint32_t cmd, romdata = 0;
CHECKID;
WAITFORREADY;
cmd = ConfigRom_AREAD;
if(last)
cmd |= ConfigRomHostEndOfCmd;
FAV3LOCK;
vmeWrite32(VME_CONFIG6_ADR, cmd); // Rom Command
vmeWrite32(VME_CONFIG7_ADR, romadr); // Rom Address
cmd = ConfigRomHostExec | cmd;
vmeWrite32(VME_CONFIG6_ADR, cmd); // Execute Command
cmd = cmd & ~ConfigRomHostExec;
vmeWrite32(VME_CONFIG6_ADR, cmd); // Ready for Next Command
FAV3UNLOCK;
WAITFORREADY;
FAV3LOCK;
rval = vmeRead32(VME_STATUS5_ADR);
FAV3UNLOCK;
return rval;
}
/**
* @brief Write data to the ROM at specified address
* @param[in] id faV3 slot ID
* @param[in] romadr ROM Address
* @param[in] romdata Data to write
* @param[in] last Whether or not this is the end of the page
* @return 0
*/
int32_t
faV3FirmwareWriteRomAdr(int32_t id, uint32_t romadr, uint32_t romdata, int32_t last)
{
int32_t rval = 0;
uint32_t cmd;
CHECKID;
WAITFORREADY;
if((romadr & 0xff) == 0)
{
rval = faV3FirmwareSetMemoryWrite(id, 1);
if(rval == 0)
{
printf("%s: ERROR: Write not enabled for romadr = 0x%x\n",
__func__, romadr);
return -1;
}
}
cmd = ConfigRom_PP4;
if(last)
cmd |= ConfigRomHostEndOfCmd;
FAV3LOCK;
vmeWrite32(VME_CONFIG6_ADR, cmd); // Rom Command
vmeWrite32(VME_CONFIG7_ADR, romadr); // Rom Address
vmeWrite32(VME_CONFIG8_ADR, romdata); // Rom Data
cmd = ConfigRomHostExec | cmd;
vmeWrite32(VME_CONFIG6_ADR, cmd); // Execute Command
cmd = cmd & ~ConfigRomHostExec;
vmeWrite32(VME_CONFIG6_ADR, cmd); // Ready for Next Command
FAV3UNLOCK;
if(last)
{
faV3FirmwareWaitForWIP(id, 20, 0);
}
return rval;
}
/**
* @brief Download the contents of the ROM to local memory
* @param[in] id faV3 slot ID
* @param[in] size maximum size of local memory
* @return OK if successful
*/
int32_t
faV3FirmwareDownloadRom(int32_t id, int32_t size)
{
uint32_t rval = 0;
int32_t idata = 0, iword = 0, last_of_page = 0;
faV3UpdateWatcherArgs_t updateArgs;
CHECKID;
if(rom_firmware == NULL)
rom_firmware = (faV3fw_t *)malloc(sizeof(faV3fw_t));
else
memset(&rom_firmware->data, 0, (MAX_FW_SIZE>>2)*sizeof(uint32_t));
rom_firmware->loaded = 0;
updateArgs.step = FAV3_UPDATE_STEP_DOWNLOAD;
updateArgs.show = FAV3_ARGS_SHOW_PROGRESS;
while(idata < (size>>2))
{
if((idata & (256 >> 2)) == (256 >> 2))
last_of_page = 1;
else
last_of_page = 0;
rom_firmware->data[idata] = faV3FirmwareReadRomAdr(id, (idata << 2), last_of_page);
idata++;
faV3FirmwareUpdateWatcher(updateArgs);
}
updateArgs.show = FAV3_ARGS_SHOW_DONE;
faV3FirmwareUpdateWatcher(updateArgs);
rom_firmware->size = idata;
rom_firmware->loaded = 1;
return OK;
}
/**
* @brief Program the ROM with the firmware in local memory
* @param[in] id faV3 slot ID
* @return OK if successfull
*/
int32_t
faV3FirmwareProgramRom(int32_t id)
{
uint32_t rval = 0, romadr = 0;
int32_t idata = 0, iword = 0, last_of_page = 0;
faV3UpdateWatcherArgs_t updateArgs;
CHECKID;
if(file_firmware->loaded != 1)
{
printf("%s: ERROR : Firmware was not loaded\n", __func__);
return ERROR;
}
updateArgs.step = FAV3_UPDATE_STEP_PROGRAM;
updateArgs.show = FAV3_ARGS_SHOW_PROGRESS;
while(idata < file_firmware->size)
{
romadr = idata << 2;
if((romadr & 0xFC) == 0xFC)
last_of_page = 1;
else
last_of_page = 0;
faV3FirmwareWriteRomAdr(id, romadr, file_firmware->data[idata], last_of_page);
idata++;
faV3FirmwareUpdateWatcher(updateArgs);
}
romadr = idata << 2;
faV3FirmwareWriteRomAdr(id, romadr, 0xFFFFFFFF, 1);
updateArgs.show = FAV3_ARGS_SHOW_DONE;
faV3FirmwareUpdateWatcher(updateArgs);
return OK;
}
/**
* @brief Compare the local memory contents from FILE and ROM
* @return OK if successful, otherwise ERROR
*/
int32_t
faV3FirmwareCompare()
{
faV3UpdateWatcherArgs_t updateArgs;
if((file_firmware == NULL) || (file_firmware->loaded != 1))
{
printf("%s: ERROR : File Firmware was not loaded\n", __func__);
return ERROR;
}
if((rom_firmware == NULL) || (rom_firmware->loaded != 1))
{
printf("%s: ERROR : ROM Firmware was not loaded\n", __func__);
return ERROR;
}
if(file_firmware->size != rom_firmware->size)
{
printf("%s: ERROR: File size != Rom size (0x%x != 0x%x)\n",
__func__, file_firmware->size, rom_firmware->size);
return ERROR;
}
int32_t idata = 0, errorCount = 0;
updateArgs.step = FAV3_UPDATE_STEP_VERIFY;
updateArgs.show = FAV3_ARGS_SHOW_PROGRESS;
while(idata < file_firmware->size)
{
if(file_firmware->data[idata] != rom_firmware->data[idata])
{
errorCount++;
if(errorCount < 16)
{
printf("%s: ERROR: word 0x%x File 0x%08x ROM 0x%08x\n",
__func__, idata, file_firmware->data[idata], rom_firmware->data[idata]);
}
}
idata++;
faV3FirmwareUpdateWatcher(updateArgs);
}
if(errorCount)
{
printf("%s: errorCount = 0x%x (%d)\n", __func__, errorCount, errorCount);
return ERROR;
}
updateArgs.show = FAV3_ARGS_SHOW_DONE;
faV3FirmwareUpdateWatcher(updateArgs);
return OK;
}
int32_t
faV3FirmwareReboot(int32_t id)
{
int32_t rval = OK;
CHECKID;
FAV3LOCK;
vmeWrite32(VME_CONFIG6_ADR, ConfigRomRebootFPGA);
FAV3UNLOCK;
return rval;
}
/**
* @brief Wait for fav3 to reload firmware after reboot
* @param[in] id faV3 slot ID
* @param[in] nwait Max number of tries
* @return If ready, number of tries before ready, otherwise ERROR.
*/
int32_t
faV3FirmwareWaitForReboot(int32_t id, int32_t nwait, int32_t pflag)
{
int32_t rval = OK, res = 0;
uint32_t rdata = -1, iwait = 0;
faV3UpdateWatcherArgs_t updateArgs;
CHECKID;
updateArgs.step = FAV3_UPDATE_STEP_REBOOT;
updateArgs.show = FAV3_ARGS_SHOW_PROGRESS;
res = vmeMemProbe((char *) &FAV3p[id]->version, 4, (char *) &rdata);
while( (res < 0) && (iwait++ < nwait) )
{
FAV3LOCK;
res = vmeMemProbe((char *) &FAV3p[id]->version, 4, (char *) &rdata);
FAV3UNLOCK;
if(res >= 0)
if(rdata == -1) res = -1;
faV3FirmwareUpdateWatcher(updateArgs);
usleep(1000);
}
if(res >= 0)
{
rval = iwait;
updateArgs.show = FAV3_ARGS_SHOW_DONE;
faV3FirmwareUpdateWatcher(updateArgs);
}
else
{
printf("%s: ERROR: timeout after %d tries\n",
__func__, iwait);
rval = ERROR;
}
if(pflag)
{
printf("%s: INFO: Ready after %d tries\n",
__func__, iwait);
}
return rval;
}
typedef struct
{
int32_t skip;
int32_t passed;
int32_t stepfail;
} fwBoardUpdate_t;
static fwBoardUpdate_t fwStatus[FAV3_MAX_BOARDS + 1];
int
faV3FirmwarePassedMask()
{
uint32_t retMask = 0;
int32_t id, ifadc;
for(ifadc = 0; ifadc < nfaV3; ifadc++)
{
id = faV3ID[ifadc];
if(fwStatus[id].passed == 1)
retMask |= (1 << id);
}
return retMask;
}
/*************************************************************
* faV3FirmwareLoad
* - main routine to load up firmware for FADC with specific id
*
* NOTE: Make call to
* faV3FirmwareSetFilename(...);
* if not using firmware from the default
*/
int32_t
faV3FirmwareLoad(int32_t id, int32_t pFlag)
{
faV3UpdateWatcherArgs_t updateArgs;
CHECKID;
if(id==0) id = faV3Slot(id);
updateArgs.id = id;
updateArgs.step = FAV3_UPDATE_STEP_INIT;
/* Perform a hardware and software reset */
FAV3LOCK;
vmeWrite32(&FAV3p[id]->reset, 0xFFFF);
FAV3UNLOCK;
taskDelay(60);
updateArgs.show = FAV3_ARGS_SHOW_STRING;
sprintf(updateArgs.title, "Check if ready \n");
faV3FirmwareUpdateWatcher(updateArgs);
updateArgs.show = FAV3_ARGS_SHOW_ID;
faV3FirmwareUpdateWatcher(updateArgs);
/* Check for ROM Ready after reset */
if(faV3FirmwareWaitForReady(id, 60, 0) < OK)
{
updateArgs.show = FAV3_ARGS_SHOW_STRING;
sprintf(updateArgs.title,
"ERROR: FAV3 %2d not ready after reset\n", id);
faV3FirmwareUpdateWatcher(updateArgs);
return ERROR;
}
updateArgs.show = FAV3_ARGS_SHOW_DONE;
faV3FirmwareUpdateWatcher(updateArgs);
/* ERASE ROM */
updateArgs.step = FAV3_UPDATE_STEP_ERASE;
updateArgs.show = FAV3_ARGS_SHOW_STRING;
sprintf(updateArgs.title, "ERASE ROM \n");
faV3FirmwareUpdateWatcher(updateArgs);
updateArgs.show = FAV3_ARGS_SHOW_ID;
faV3FirmwareUpdateWatcher(updateArgs);
if(faV3FirmwareRomErase(id, 1) != OK)
{
printf("%s: ERROR: faV3 %2d Failed to erase ROM\n",
__func__, id);
updateArgs.show = FAV3_ARGS_SHOW_STRING;
sprintf(updateArgs.title,
"ERROR: FAV3 %2d FAILED ROM ERASE\n", id);
faV3FirmwareUpdateWatcher(updateArgs);
return ERROR;
}
/* Program ROM */
updateArgs.step = FAV3_UPDATE_STEP_PROGRAM;
updateArgs.show = FAV3_ARGS_SHOW_STRING;
sprintf(updateArgs.title, "Program ROM\n");
faV3FirmwareUpdateWatcher(updateArgs);
updateArgs.show = FAV3_ARGS_SHOW_ID;
faV3FirmwareUpdateWatcher(updateArgs);
if(faV3FirmwareProgramRom(id) != OK)
{
printf("%s: ERROR: faV3 %2d Failed to program ROM\n",
__func__, id);
updateArgs.show = FAV3_ARGS_SHOW_STRING;
sprintf(updateArgs.title,
"ERROR: FAV3 %2d FAILED ROM PROGRAM\n", id);
faV3FirmwareUpdateWatcher(updateArgs);
return ERROR;
}
/* Download ROM data */
updateArgs.step = FAV3_UPDATE_STEP_DOWNLOAD;
updateArgs.show = FAV3_ARGS_SHOW_STRING;
sprintf(updateArgs.title, "Download ROM data\n");
faV3FirmwareUpdateWatcher(updateArgs);
updateArgs.show = FAV3_ARGS_SHOW_ID;
faV3FirmwareUpdateWatcher(updateArgs);
if(faV3FirmwareDownload(id, 1) != OK)
{
printf("%s: ERROR: faV3 %2d Failed to download ROM data\n",
__func__, id);
updateArgs.show = FAV3_ARGS_SHOW_STRING;
sprintf(updateArgs.title,
"ERROR: FAV3 %2d FAILED ROM DATA DOWNLOAD\n", id);
faV3FirmwareUpdateWatcher(updateArgs);
return ERROR;
}
/* Verify ROM data with file */
updateArgs.step = FAV3_UPDATE_STEP_VERIFY;
updateArgs.show = FAV3_ARGS_SHOW_STRING;
sprintf(updateArgs.title, "Verify ROM data\n");
faV3FirmwareUpdateWatcher(updateArgs);
updateArgs.show = FAV3_ARGS_SHOW_ID;
faV3FirmwareUpdateWatcher(updateArgs);
if(faV3FirmwareVerify(id, 1) != OK)
{
printf("%s: ERROR: faV3 %2d ROM Data not verified\n",
__func__, id);
updateArgs.show = FAV3_ARGS_SHOW_STRING;
sprintf(updateArgs.title,
"ERROR: FAV3 %2d FAILED ROM DATA VERIFICATION\n", id);
faV3FirmwareUpdateWatcher(updateArgs);
return ERROR;
}
/* Reboot */
updateArgs.step = FAV3_UPDATE_STEP_REBOOT;
updateArgs.show = FAV3_ARGS_SHOW_STRING;
sprintf(updateArgs.title, "Reboot FPGA\n");
faV3FirmwareUpdateWatcher(updateArgs);
updateArgs.show = FAV3_ARGS_SHOW_ID;
faV3FirmwareUpdateWatcher(updateArgs);
if(faV3FirmwareReboot(id) != OK)
{
updateArgs.show = FAV3_ARGS_SHOW_STRING;
sprintf(updateArgs.title,
"ERROR: FAV3 %2d FAILED TO REBOOT FPGA\n", id);
faV3FirmwareUpdateWatcher(updateArgs);
return ERROR;
}
sleep(1);
if(faV3FirmwareWaitForReboot(id, 60000, 0) < OK) /* Wait til it's done */
{
updateArgs.show = FAV3_ARGS_SHOW_STRING;
sprintf(updateArgs.title,
"ERROR: FAV3 %2d TIMEOUT AFTER REBOOT FPGA\n", id);
faV3FirmwareUpdateWatcher(updateArgs);
return ERROR;
}
updateArgs.show = FAV3_ARGS_SHOW_STRING;
sprintf(updateArgs.title, "Done programming FADC %2d\n", id);
faV3FirmwareUpdateWatcher(updateArgs);
return OK;
}
int32_t
faV3FirmwareDownload(int32_t id, int32_t pFlag)
{
faV3UpdateWatcherArgs_t updateArgs;
CHECKID;
/* PROM to data */
taskDelay(1);
if(faV3FirmwareDownloadRom(id, FAV3_FW_SIZE) != OK)
{
printf("%s: ERROR: faV3 %2d Failed to download ROM\n",
__func__, id);
updateArgs.show = FAV3_ARGS_SHOW_STRING;
sprintf(updateArgs.title,
"ERROR: FAV3 %2d FAILED ROM DOWNLOAD\n", id);
faV3FirmwareUpdateWatcher(updateArgs);
return ERROR;
}
return OK;
}
int32_t
faV3FirmwareVerify(int32_t id, int32_t pFlag)
{
faV3UpdateWatcherArgs_t updateArgs;
CHECKID;
/* Verify ROM */
if(faV3FirmwareCompare() != OK)
{
printf("%s: ERROR: faV3 %d PROM data not verified\n", __func__, id);
updateArgs.show = FAV3_ARGS_SHOW_STRING;
sprintf(updateArgs.title,
"ERROR: FAV3 %2d FAILED ROM VERIFICATION\n", id);
faV3FirmwareUpdateWatcher(updateArgs);
return ERROR;
}
return OK;
}
int32_t
faV3FirmwareDone(int32_t pFlag)
{
if(rom_firmware)
free(rom_firmware);
if(file_firmware)
free(file_firmware);
return OK;
}
/*************************************************************
* faV3FirmwareGLoad
* - load up firmware for all initialized modules
*
* NOTE: Make call to
* faV3FirmwareSetFilename(...);
* if not using firmware from the default
*/
int32_t
faV3FirmwareGLoad(int32_t pFlag, int32_t force)
{
int32_t ifadc = 0, id = 0;
faV3UpdateWatcherArgs_t updateArgs;
memset(fwStatus, 0, sizeof(fwStatus));
if(force == 0)
{
/* Skip the modules that are already programmed correctly */
int32_t print_once = 1;
for(ifadc = 0; ifadc < nfaV3; ifadc++)
{
int ictrl, iproc, skip = 0;
uint32_t cfw = 0, ctrl = 0, proc = 0;
uint32_t supported_ctrl[FAV3_SUPPORTED_CTRL_FIRMWARE_NUMBER] = {FAV3_SUPPORTED_CTRL_FIRMWARE};
uint32_t supported_proc[FAV3_SUPPORTED_PROC_FIRMWARE_NUMBER] = {FAV3_SUPPORTED_PROC_FIRMWARE};
cfw = faV3GetFirmwareVersions(faV3Slot(ifadc), 0);
ctrl = cfw & 0xFFFF;
proc = (cfw >> 16) & 0xFFFF;
for(ictrl = 0; ictrl < FAV3_SUPPORTED_CTRL_FIRMWARE_NUMBER; ictrl++) {
if(ctrl == supported_ctrl[ictrl]) {
for(iproc = 0; iproc < FAV3_SUPPORTED_PROC_FIRMWARE_NUMBER; iproc++) {
if(proc == supported_proc[iproc]) {
if(print_once)
printf("Skip slot ");
print_once = 0;
fwStatus[id].skip = 1;
}
}
}
}
}
if(!print_once)
printf("\n");
}
/* Perform a hardware and software reset */
updateArgs.step = FAV3_UPDATE_STEP_INIT;
FAV3LOCK;
for(ifadc = 0; ifadc < nfaV3; ifadc++)
{
id = faV3Slot(ifadc);
if(fwStatus[id].skip)
continue;
if((id <= 0) || (id > 21) || (FAV3p[id] == NULL))
{
printf("%s: ERROR : ADC in slot %d is not initialized \n",
__func__, id);
fwStatus[id].passed = 0;
fwStatus[id].stepfail = updateArgs.step;
}
else
{
fwStatus[id].passed = 1;
vmeWrite32(&FAV3p[id]->reset, 0xFFFF);
}
}
FAV3UNLOCK;
taskDelay(60);
/* Check if FADC is Ready */
updateArgs.show = FAV3_ARGS_SHOW_STRING;
sprintf(updateArgs.title, "Check if ready \n");
faV3FirmwareUpdateWatcher(updateArgs);
for(ifadc = 0; ifadc < nfaV3; ifadc++)
{
id = faV3Slot(ifadc);
if(fwStatus[id].skip)
continue;
updateArgs.id = id;
updateArgs.show = FAV3_ARGS_SHOW_ID;
faV3FirmwareUpdateWatcher(updateArgs);
if(faV3FirmwareWaitForReady(id, 60, pFlag) < OK)
{
updateArgs.show = FAV3_ARGS_SHOW_STRING;
sprintf(updateArgs.title,
"ERROR: FAV3 %2d not ready after reset\n", id);
faV3FirmwareUpdateWatcher(updateArgs);
fwStatus[id].passed = 0;
fwStatus[id].stepfail = updateArgs.step;
}
else
{
updateArgs.show = FAV3_ARGS_SHOW_DONE;
faV3FirmwareUpdateWatcher(updateArgs);
}
}
/* ERASE ROM */