]> rtime.felk.cvut.cz Git - pes-rpp/rpp-test-sw.git/blob - rpp/lib/rpp/src/sys/sys_startup.c
Yet another place to fix
[pes-rpp/rpp-test-sw.git] / rpp / lib / rpp / src / sys / sys_startup.c
1 /** @file sys_startup.c
2 *   @brief Startup Source File
3 *   @date 15.Mar.2012
4 *   @version 03.01.00
5 *
6 *   This file contains:
7 *   - Include Files
8 *   - Type Definitions
9 *   - External Functions
10 *   - VIM RAM Setup
11 *   - Startup Routine
12 *   .
13 *   which are relevant for the Startup.
14 */
15
16 /* (c) Texas Instruments 2009-2012, All rights reserved. */
17
18 /* USER CODE BEGIN (0) */
19 /* USER CODE END */
20
21
22 /* Include Files */
23
24 #include "base.h"
25 #include "sys/system.h"
26 #include "sys/sys_vim.h"
27 #include "sys/sys_core.h"
28 #include "sys/sys_selftest.h"
29 #include "sys/ti_drv_esm.h"
30
31
32 /* USER CODE BEGIN (1) */
33 /* USER CODE END */
34
35
36 /* Type Definitions */
37
38 typedef void (*handler_fptr)(const uint8_t *in, uint8_t *out);
39
40 /* USER CODE BEGIN (2) */
41 /* USER CODE END */
42
43
44 /* External Functions */
45
46 #pragma WEAK(__TI_Handler_Table_Base)
47 #pragma WEAK(__TI_Handler_Table_Limit)
48 #pragma WEAK(__TI_CINIT_Base)
49 #pragma WEAK(__TI_CINIT_Limit)
50
51 extern uint32_t   __TI_Handler_Table_Base;
52 extern uint32_t   __TI_Handler_Table_Limit;
53 extern uint32_t   __TI_CINIT_Base;
54 extern uint32_t   __TI_CINIT_Limit;
55 extern uint32_t   __TI_PINIT_Base;
56 extern uint32_t   __TI_PINIT_Limit;
57 extern uint32_t * __binit__;
58
59 extern void main(void);
60 extern void exit(void);
61
62 extern void muxInit(void);
63
64 /* USER CODE BEGIN (3) */
65 /* USER CODE END */
66
67
68 /* Vim Ram Definition */
69 /** @struct vimRam
70 *   @brief Vim Ram Definition
71 *
72 *   This type is used to access the Vim Ram.
73 */
74 /** @typedef vimRAM_t
75 *   @brief Vim Ram Type Definition
76 *
77 *   This type is used to access the Vim Ram.
78 */
79 typedef volatile struct vimRam
80 {
81     t_isrFuncPTR ISR[VIM_CHANNELS + 1];
82 } vimRAM_t;
83
84 #define vimRAM ((vimRAM_t *)0xFFF82000U)
85
86 static const t_isrFuncPTR s_vim_init[] =
87 {
88     &phantomInterrupt,
89     &esmHighInterrupt,      // 0
90     &phantomInterrupt,
91 #if FREERTOS_VERSION_NUMBER_MAYOR == 7 && \
92     FREERTOS_VERSION_NUMBER_MINOR == 0 && \
93     FREERTOS_VERSION_NUMBER_REV   == 2
94     &vPreemptiveTick,     // FreeRTOS 7.0.2
95 #else
96     &vPortPreemptiveTick, // FreeRTOS 7.4.0 and 7.4.2
97 #endif
98     &phantomInterrupt,
99     &phantomInterrupt,
100     &phantomInterrupt,      // 5
101     &phantomInterrupt,
102     &phantomInterrupt,
103     &phantomInterrupt,
104     &phantomInterrupt,
105     &phantomInterrupt,      // 10
106     &phantomInterrupt,
107     &mibspi1HighLevelInterrupt,
108     &linHighLevelInterrupt,
109     &phantomInterrupt,
110     &adc1Group1Interrupt,   // 15
111     &can1HighLevelInterrupt,
112     &spi2HighLevelInterrupt,
113     &phantomInterrupt,
114     &phantomInterrupt,
115     &phantomInterrupt,      // 20
116     &phantomInterrupt,
117     &phantomInterrupt,
118     &phantomInterrupt,
119     &phantomInterrupt,
120     &phantomInterrupt,      // 25
121     &mibspi1LowLevelInterrupt,
122     &phantomInterrupt,
123     &phantomInterrupt,
124     &phantomInterrupt,
125     &spi2LowLevelInterrupt, // 30
126     &phantomInterrupt,
127     &phantomInterrupt,
128     &phantomInterrupt,
129     &phantomInterrupt,
130     &can2HighLevelInterrupt,    // 35
131     &phantomInterrupt,
132     &mibspi3HighInterruptLevel,
133     &mibspi3LowLevelInterrupt,
134     &phantomInterrupt,
135     &phantomInterrupt,      // 40
136     &phantomInterrupt,
137     &phantomInterrupt,
138     &phantomInterrupt,
139     &phantomInterrupt,
140     &can3HighLevelInterrupt,    // 45
141     &phantomInterrupt,
142     &phantomInterrupt,
143     &phantomInterrupt,
144     &spi4HighLevelInterrupt,
145     &phantomInterrupt,      // 50
146     &adc2Group1Interrupt,
147     &phantomInterrupt,
148     &phantomInterrupt,
149     &spi4LowLevelInterrupt,
150     &phantomInterrupt,      // 55
151     &phantomInterrupt,
152     &phantomInterrupt,
153     &phantomInterrupt,
154     &phantomInterrupt,
155     &phantomInterrupt,      // 60
156     &phantomInterrupt,
157     &phantomInterrupt,
158     &phantomInterrupt,
159     &sciHighLevelInterrupt,
160     &phantomInterrupt,      // 65
161     &i2cInterrupt,
162     &phantomInterrupt,
163     &phantomInterrupt,
164     &phantomInterrupt,
165     &phantomInterrupt,      // 70
166     &phantomInterrupt,
167     &phantomInterrupt,
168     &phantomInterrupt,
169     &phantomInterrupt,
170     &phantomInterrupt,      // 75
171     &phantomInterrupt,
172     &EMACCore0TxIsr,
173     &phantomInterrupt,
174     &EMACCore0RxIsr,
175     &phantomInterrupt,      // 80
176     &phantomInterrupt,
177     &phantomInterrupt,
178     &phantomInterrupt,
179     &phantomInterrupt,
180     &phantomInterrupt,      // 85
181     &phantomInterrupt,
182     &phantomInterrupt,
183     &phantomInterrupt,
184     &phantomInterrupt,
185     &phantomInterrupt,      // 90
186     &phantomInterrupt,
187     &phantomInterrupt,
188     &phantomInterrupt,
189     &phantomInterrupt,
190     &phantomInterrupt,      // 95
191     &phantomInterrupt,
192     &phantomInterrupt,
193     &phantomInterrupt,
194     &phantomInterrupt,
195     &phantomInterrupt,      // 100
196     &phantomInterrupt,
197     &phantomInterrupt,
198     &phantomInterrupt,
199     &phantomInterrupt,
200     &phantomInterrupt,
201     &phantomInterrupt,
202     &phantomInterrupt,
203     &phantomInterrupt,
204     &phantomInterrupt,
205     &phantomInterrupt,
206     &phantomInterrupt,
207     &phantomInterrupt,
208     &phantomInterrupt,
209     &phantomInterrupt,
210     &phantomInterrupt,
211     &phantomInterrupt,
212     &phantomInterrupt,
213     &phantomInterrupt,
214     &phantomInterrupt,
215     &phantomInterrupt,
216     &phantomInterrupt,
217     &phantomInterrupt,
218     &phantomInterrupt,
219     &phantomInterrupt,
220     &phantomInterrupt,
221     &phantomInterrupt,
222     &phantomInterrupt,
223 };
224
225
226 /* Startup Routine */
227
228 /* USER CODE BEGIN (4) */
229 /* USER CODE END */
230
231 #pragma INTERRUPT(_c_int00, RESET)
232
233 void _c_int00()
234 {
235
236 /* USER CODE BEGIN (5) */
237 /* USER CODE END */
238
239     /* Initialize Core Registers to avoid CCM Error */
240     _coreInitRegisters_();
241
242 /* USER CODE BEGIN (6) */
243 /* USER CODE END */
244
245     /* Initialize Stack Pointers */
246     _coreInitStackPointer_();
247
248 /* USER CODE BEGIN (7) */
249 /* USER CODE END */
250
251     /* Implement work-around for CCM-R4 issue on silicon revision A */
252     if (DEVICE_ID_REV == 0x802AAD05)
253     {
254         _esmCcmErrorsClear_();
255     }
256
257 /* USER CODE BEGIN (8) */
258 /* USER CODE END */
259
260     /* Enable response to ECC errors indicated by CPU for accesses to flash */
261     flashWREG->FEDACCTRL1 = 0x000A060A;
262
263     /* Enable CPU Event Export */
264     /* This allows the CPU to signal any single-bit or double-bit errors detected
265      * by its ECC logic for accesses to program flash or data RAM.
266      */
267     _coreEnableEventBusExport_();
268
269     /* Enable CPU ECC checking for ATCM (flash accesses) */
270     _coreEnableFlashEcc_();
271
272 /* USER CODE BEGIN (9) */
273 /* USER CODE END */
274
275     /* Reset handler: the following instructions read from the system exception status register
276      * to identify the cause of the CPU reset.
277      */
278
279     /* check for power-on reset condition */
280     if ((SYS_EXCEPTION & POWERON_RESET) != 0)
281     {
282 /* USER CODE BEGIN (10) */
283 /* USER CODE END */
284
285         /* clear all reset status flags */
286         SYS_EXCEPTION = 0xFFFF;
287
288 /* USER CODE BEGIN (11) */
289 /* USER CODE END */
290
291         /* continue with normal start-up sequence */
292     }
293     else if ((SYS_EXCEPTION & OSC_FAILURE_RESET) != 0)
294     {
295         /* Reset caused due to oscillator failure.
296         Add user code here to handle oscillator failure */
297
298 /* USER CODE BEGIN (12) */
299 /* USER CODE END */
300     }
301     else if ((SYS_EXCEPTION & WATCHDOG_RESET) !=0 )
302     {
303         /* Reset caused due
304          *  1) windowed watchdog violation - Add user code here to handle watchdog violation.
305          *  2) ICEPICK Reset - After loading code via CCS / System Reset through CCS
306          */
307         /* Check the WatchDog Status register */
308         if(WATCHDOG_STATUS != 0U)
309         {
310             /* Add user code here to handle watchdog violation. */
311 /* USER CODE BEGIN (13) */
312 /* USER CODE END */
313
314             /* Clear the Watchdog reset flag in Exception Status register */
315             SYS_EXCEPTION = WATCHDOG_RESET;
316
317 /* USER CODE BEGIN (14) */
318 /* USER CODE END */
319         }
320         else
321         {
322             /* Clear the ICEPICK reset flag in Exception Status register */
323             SYS_EXCEPTION = ICEPICK_RESET;
324 /* USER CODE BEGIN (15) */
325 /* USER CODE END */
326         }
327     }
328     else if ((SYS_EXCEPTION & CPU_RESET) !=0 )
329     {
330         /* Reset caused due to CPU reset.
331         CPU reset can be caused by CPU self-test completion, or
332         by toggling the "CPU RESET" bit of the CPU Reset Control Register. */
333
334 /* USER CODE BEGIN (16) */
335 /* USER CODE END */
336
337         /* clear all reset status flags */
338         SYS_EXCEPTION = CPU_RESET;
339
340 /* USER CODE BEGIN (17) */
341 /* USER CODE END */
342
343     }
344     else if ((SYS_EXCEPTION & SW_RESET) != 0)
345     {
346         /* Reset caused due to software reset.
347         Add user code to handle software reset. */
348
349 /* USER CODE BEGIN (18) */
350 /* USER CODE END */
351     }
352     else
353     {
354         /* Reset caused by nRST being driven low externally.
355         Add user code to handle external reset. */
356
357 /* USER CODE BEGIN (19) */
358 /* USER CODE END */
359     }
360
361     /* Check if there were ESM group3 errors during power-up.
362      * These could occur during eFuse auto-load or during reads from flash OTP
363      * during power-up. Device operation is not reliable and not recommended
364      * in this case.
365      * An ESM group3 error only drives the nERROR pin low. An external circuit
366      * that monitors the nERROR pin must take the appropriate action to ensure that
367      * the system is placed in a safe state, as determined by the application.
368      */
369     if (esmREG->ESTATUS1[2])
370     {
371 /* USER CODE BEGIN (20) */
372 /* USER CODE END */
373         while(1);
374     }
375
376 /* USER CODE BEGIN (21) */
377 /* USER CODE END */
378
379     /* Initialize System - Clock, Flash settings with Efuse self check */
380     systemInit();
381
382
383 /* USER CODE BEGIN (24) */
384 /* USER CODE END */
385
386     /* Run a diagnostic check on the memory self-test controller.
387      * This function chooses a RAM test algorithm and runs it on an on-chip ROM.
388      * The memory self-test is expected to fail. The function ensures that the PBIST controller
389      * is capable of detecting and indicating a memory self-test failure.
390      */
391     pbistSelfCheck();
392
393 /* USER CODE BEGIN (26) */
394 /* USER CODE END */
395
396
397     /* Run PBIST on CPU RAM.
398      * The PBIST controller needs to be configured separately for single-port and dual-port SRAMs.
399      * The CPU RAM is a single-port memory. The actual "RAM Group" for all on-chip SRAMs is defined in the
400      * device datasheet.
401      */
402     pbistRun(0x08300020, /* ESRAM Single Port PBIST */
403              PBIST_March13N_SP);
404
405 /* USER CODE BEGIN (27) */
406 /* USER CODE END */
407
408     /* Wait for PBIST for CPU RAM to be completed */
409     while(!pbistIsTestCompleted());
410
411 /* USER CODE BEGIN (28) */
412 /* USER CODE END */
413
414     /* Check if CPU RAM passed the self-test */
415     if( pbistIsTestPassed() != TRUE)
416     {
417         /* CPU RAM failed the self-test.
418          * Need custom handler to check the memory failure
419          * and to take the appropriate next step.
420          */
421         if(pbistPortTestStatus(PBIST_PORT0) != TRUE)
422         {
423             memoryPort0TestFailNotification(pbistREG->RGS, pbistREG->RDS, pbistREG->FSRA0, pbistREG->FSRDL0);
424         }
425         else if(pbistPortTestStatus(PBIST_PORT1) != TRUE)
426         {
427             memoryPort1TestFailNotification(pbistREG->RGS, pbistREG->RDS, pbistREG->FSRA1, pbistREG->FSRDL1);
428         }
429         else
430         {
431            while(1);
432         }
433     }
434
435 /* USER CODE BEGIN (29) */
436 /* USER CODE END */
437
438     /* Disable PBIST clocks and disable memory self-test mode */
439     pbistStop();
440
441 /* USER CODE BEGIN (30) */
442 /* USER CODE END */
443
444     /* Initialize CPU RAM.
445      * This function uses the system module's hardware for auto-initialization of memories and their
446      * associated protection schemes. The CPU RAM is initialized by setting bit 0 of the MSIENA register.
447      * Hence the value 0x1 passed to the function.
448      * This function will initialize the entire CPU RAM and the corresponding ECC locations.
449      */
450     _memoryInit_(0x1);
451
452 /* USER CODE BEGIN (31) */
453 /* USER CODE END */
454
455     /* Enable ECC checking for TCRAM accesses.
456      * This function enables the CPU's ECC logic for accesses to B0TCM and B1TCM.
457      */
458     _coreEnableRamEcc_();
459
460 /* USER CODE BEGIN (32) */
461 /* USER CODE END */
462
463     /* Start PBIST on all dual-port memories */
464     pbistRun(  0x00000000    /*   EMAC Dual Port PBIST  */
465              | 0x00000000    /*   USB Dual Port PBIST for RMx / Reserved for TMS570x */
466              | 0x00000800    /*   DMA Dual Port PBIST  */
467              | 0x00000200    /*   VIM Dual Port PBIST  */
468              | 0x00000040    /*   MIBSPI1 Dual Port PBIST  */
469              | 0x00000080    /*   MIBSPI3 Dual Port PBIST  */
470              | 0x00000100    /*   MIBSPI5 Dual Port PBIST  */
471              | 0x00000004    /*   CAN1 Dual Port PBIST  */
472              | 0x00000008    /*   CAN2 Dual Port PBIST  */
473              | 0x00000010    /*   CAN3 Dual Port PBIST  */
474              | 0x00000400    /*   ADC1 Dual Port PBIST  */
475              | 0x00020000    /*   ADC2 Dual Port PBIST  */
476              | 0x00001000    /*   HET1 Dual Port PBIST  */
477              | 0x00040000    /*   HET2 Dual Port PBIST  */
478              | 0x00002000    /*   HTU1 Dual Port PBIST  */
479              | 0x00080000    /*   HTU2 Dual Port PBIST  */
480              | 0x00004000    /*   RTP Dual Port PBIST  */
481              | 0x00000000    /*   FTU Dual Port PBIST for TMS570x / Reserved for RMx */
482              | 0x00008000    /*   FRAY Dual Port PBIST for TMS570x / Reserved for RMx */
483              , PBIST_March13N_DP);
484
485 /* USER CODE BEGIN (33) */
486 /* USER CODE END */
487
488
489     /* Test the CPU ECC mechanism for RAM accesses.
490      * The checkBxRAMECC functions cause deliberate single-bit and double-bit errors in TCRAM accesses
491      * by corrupting 1 or 2 bits in the ECC. Reading from the TCRAM location with a 2-bit error
492      * in the ECC causes a data abort exception. The data abort handler is written to look for
493      * deliberately caused exception and to return the code execution to the instruction
494      * following the one that caused the abort.
495      */
496     checkB0RAMECC();
497     tcram1REG->RAMCTRL &= ~(0x00000100);                /* disable writes to ECC RAM */
498     tcram2REG->RAMCTRL &= ~(0x00000100);
499
500     checkB1RAMECC();
501     tcram1REG->RAMCTRL &= ~(0x00000100);                /* disable writes to ECC RAM */
502     tcram2REG->RAMCTRL &= ~(0x00000100);
503
504 /* USER CODE BEGIN (34) */
505 /* USER CODE END */
506
507
508     /* Test the CPU ECC mechanism for Flash accesses.
509      * The checkFlashECC function uses the flash interface module's diagnostic mode 7
510      * to create single-bit and double-bit errors in CPU accesses to the flash. A double-bit
511      * error on reading from flash causes a data abort exception.
512      * The data abort handler is written to look for deliberately caused exception and
513      * to return the code execution to the instruction following the one that was aborted.
514      *
515      */
516     checkFlashECC();
517     flashWREG->FDIAGCTRL = 0x000A0007;                  /* disable flash diagnostic mode */
518
519 /* USER CODE BEGIN (35) */
520 /* USER CODE END */
521
522 /* USER CODE BEGIN (36) */
523 /* USER CODE END */
524
525     /* Wait for PBIST for CPU RAM to be completed */
526     while(!pbistIsTestCompleted());
527
528 /* USER CODE BEGIN (37) */
529 /* USER CODE END */
530
531     /* Check if CPU RAM passed the self-test */
532     if( pbistIsTestPassed() != TRUE)
533     {
534
535 /* USER CODE BEGIN (38) */
536 /* USER CODE END */
537
538         /* CPU RAM failed the self-test.
539          * Need custom handler to check the memory failure
540          * and to take the appropriate next step.
541          */
542         if(pbistPortTestStatus(PBIST_PORT0) != TRUE)
543         {
544             memoryPort0TestFailNotification(pbistREG->RGS, pbistREG->RDS, pbistREG->FSRA0, pbistREG->FSRDL0);
545         }
546         else if(pbistPortTestStatus(PBIST_PORT1) != TRUE)
547         {
548             memoryPort1TestFailNotification(pbistREG->RGS, pbistREG->RDS, pbistREG->FSRA1, pbistREG->FSRDL1);
549         }
550         else
551         {
552            while(1);
553         }
554     }
555
556 /* USER CODE BEGIN (39) */
557 /* USER CODE END */
558
559     /* Disable PBIST clocks and disable memory self-test mode */
560     pbistStop();
561
562
563 /* USER CODE BEGIN (45) */
564 /* USER CODE END */
565
566     /* Release the MibSPI1 modules from local reset.
567      * This will cause the MibSPI1 RAMs to get initialized along with the parity memory.
568      */
569      mibspiREG1->GCR0 = 0x1;
570
571     /* Release the MibSPI3 modules from local reset.
572      * This will cause the MibSPI3 RAMs to get initialized along with the parity memory.
573      */
574     mibspiREG3->GCR0 = 0x1;
575
576     /* Release the MibSPI5 modules from local reset.
577      * This will cause the MibSPI5 RAMs to get initialized along with the parity memory.
578      */
579     mibspiREG5->GCR0 = 0x1;
580
581 /* USER CODE BEGIN (46) */
582 /* USER CODE END */
583
584     /* Initialize all on-chip SRAMs except for MibSPIx RAMs
585      * The MibSPIx modules have their own auto-initialization mechanism which is triggered
586      * as soon as the modules are brought out of local reset.
587      */
588     /* The system module auto-init will hang on the MibSPI RAM if the module is still in local reset.
589      */
590     _memoryInit_(  1 << 1    /*   DMA Memory Init  */
591                  | 1 << 2    /*   VIM Memory Init  */
592                  | 1 << 5    /*   CAN1 Memory Init  */
593                  | 1 << 6    /*   CAN2 Memory Init  */
594                  | 1 << 10    /*   CAN3 Memory Init  */
595                  | 1 << 8    /*   ADC1 Memory Init  */
596                  | 1 << 14    /*   ADC2 Memory Init  */
597                  | 1 << 3    /*   HET1 Memory Init  */
598                  | 1 << 4    /*   HTU1 Memory Init  */
599                  | 1 << 15    /*   HET2 Memory Init  */
600                  | 1 << 16    /*   HTU2 Memory Init  */
601                  | 1 << 13);    /*   Reserved for RMx Family / FTU Memory Init for TMS570x Family */
602
603     /* Test the parity protection mechanism for peripheral RAMs
604      * The following memories have parity protection that needs to be checked:
605      * VIM, DMA, ADC1, ADC2, NHET1, NHET2, HTU1, HTU2, FlexRay, FTU,
606      * MibSPI1, MibSPI3, MibSPI5, DCAN1, DCAN2, DCAN3 based on user selection
607      */
608
609 /* USER CODE BEGIN (47) */
610 /* USER CODE END */
611
612     het1ParityCheck();
613
614 /* USER CODE BEGIN (48) */
615 /* USER CODE END */
616
617     htu1ParityCheck();
618
619 /* USER CODE BEGIN (49) */
620 /* USER CODE END */
621
622     het2ParityCheck();
623
624 /* USER CODE BEGIN (50) */
625 /* USER CODE END */
626
627     htu2ParityCheck();
628
629 /* USER CODE BEGIN (51) */
630 /* USER CODE END */
631
632     adc1ParityCheck();
633
634 /* USER CODE BEGIN (52) */
635 /* USER CODE END */
636
637     adc2ParityCheck();
638
639 /* USER CODE BEGIN (53) */
640 /* USER CODE END */
641
642     can1ParityCheck();
643
644 /* USER CODE BEGIN (54) */
645 /* USER CODE END */
646
647     can2ParityCheck();
648
649 /* USER CODE BEGIN (55) */
650 /* USER CODE END */
651
652     can3ParityCheck();
653
654 /* USER CODE BEGIN (56) */
655 /* USER CODE END */
656
657     vimParityCheck();
658
659 /* USER CODE BEGIN (57) */
660 /* USER CODE END */
661
662     dmaParityCheck();
663
664
665 /* USER CODE BEGIN (58) */
666 /* USER CODE END */
667
668     while (mibspiREG1->BUFINIT);        /* wait for MibSPI1 RAM to complete initialization */
669     while (mibspiREG3->BUFINIT);        /* wait for MibSPI3 RAM to complete initialization */
670     while (mibspiREG5->BUFINIT);        /* wait for MibSPI5 RAM to complete initialization */
671
672 /* USER CODE BEGIN (59) */
673 /* USER CODE END */
674
675     mibspi1ParityCheck();
676
677 /* USER CODE BEGIN (60) */
678 /* USER CODE END */
679
680     mibspi3ParityCheck();
681
682 /* USER CODE BEGIN (61) */
683 /* USER CODE END */
684
685     mibspi5ParityCheck();
686
687
688 /* USER CODE BEGIN (62) */
689 /* USER CODE END */
690
691
692 /* USER CODE BEGIN (63) */
693 /* USER CODE END */
694
695
696     /* Initialize VIM table */
697     {
698         uint32_t i;
699
700         for (i = 0; i < (VIM_CHANNELS + 1); i++)
701         {
702             vimRAM->ISR[i] = s_vim_init[i];
703         }
704     }
705
706     /* set IRQ/FIQ priorities */
707     vimREG->FIRQPR0 =  SYS_FIQ
708                     | (SYS_FIQ <<  1U)
709                     | (SYS_IRQ <<  2U)
710                     | (SYS_IRQ <<  3U)
711                     | (SYS_IRQ <<  4U)
712                     | (SYS_IRQ <<  5U)
713                     | (SYS_IRQ <<  6U)
714                     | (SYS_IRQ <<  7U)
715                     | (SYS_IRQ <<  8U)
716                     | (SYS_IRQ <<  9U)
717                     | (SYS_IRQ << 10U)
718                     | (SYS_IRQ << 11U)
719                     | (SYS_IRQ << 12U)
720                     | (SYS_IRQ << 13U)
721                     | (SYS_IRQ << 14U)
722                     | (SYS_IRQ << 15U)
723                     | (SYS_IRQ << 16U)
724                     | (SYS_IRQ << 17U)
725                     | (SYS_IRQ << 18U)
726                     | (SYS_IRQ << 19U)
727                     | (SYS_IRQ << 20U)
728                     | (SYS_IRQ << 21U)
729                     | (SYS_IRQ << 22U)
730                     | (SYS_IRQ << 23U)
731                     | (SYS_IRQ << 24U)
732                     | (SYS_IRQ << 25U)
733                     | (SYS_IRQ << 26U)
734                     | (SYS_IRQ << 27U)
735                     | (SYS_IRQ << 28U)
736                     | (SYS_IRQ << 29U)
737                     | (SYS_IRQ << 30U)
738                     | (SYS_IRQ << 31U);
739
740     vimREG->FIRQPR1 =  SYS_IRQ
741                     | (SYS_IRQ <<  1U)
742                     | (SYS_IRQ <<  2U)
743                     | (SYS_IRQ <<  3U)
744                     | (SYS_IRQ <<  4U)
745                     | (SYS_IRQ <<  5U)
746                     | (SYS_IRQ <<  6U)
747                     | (SYS_IRQ <<  7U)
748                     | (SYS_IRQ <<  8U)
749                     | (SYS_IRQ <<  9U)
750                     | (SYS_IRQ << 10U)
751                     | (SYS_IRQ << 11U)
752                     | (SYS_IRQ << 12U)
753                     | (SYS_IRQ << 13U)
754                     | (SYS_IRQ << 14U)
755                     | (SYS_IRQ << 15U)
756                     | (SYS_IRQ << 16U)
757                     | (SYS_IRQ << 17U)
758                     | (SYS_IRQ << 18U)
759                     | (SYS_IRQ << 19U)
760                     | (SYS_IRQ << 20U)
761                     | (SYS_IRQ << 21U)
762                     | (SYS_IRQ << 22U)
763                     | (SYS_IRQ << 23U)
764                     | (SYS_IRQ << 24U)
765                     | (SYS_IRQ << 25U)
766                     | (SYS_IRQ << 26U)
767                     | (SYS_IRQ << 27U)
768                     | (SYS_IRQ << 28U)
769                     | (SYS_IRQ << 29U)
770                     | (SYS_IRQ << 30U)
771                     | (SYS_IRQ << 31U);
772
773
774     vimREG->FIRQPR2 =  SYS_IRQ
775                     | (SYS_IRQ << 1U)
776                     | (SYS_IRQ << 2U)
777                     | (SYS_IRQ << 3U)
778                     | (SYS_IRQ << 4U)
779                     | (SYS_IRQ << 5U)
780                     | (SYS_IRQ << 6U)
781                     | (SYS_IRQ << 7U)
782                     | (SYS_IRQ << 8U)
783                     | (SYS_IRQ << 9U)
784                     | (SYS_IRQ << 10U)
785                     | (SYS_IRQ << 11U)
786                     | (SYS_IRQ << 12U)
787                     | (SYS_FIQ << 13U)  // EMAC
788                     | (SYS_IRQ << 14U)
789                     | (SYS_FIQ << 15U)  // EMAC
790                     | (SYS_IRQ << 16U)
791                     | (SYS_IRQ << 17U)
792                     | (SYS_IRQ << 18U)
793                     | (SYS_IRQ << 19U)
794                     | (SYS_IRQ << 20U)
795                     | (SYS_IRQ << 21U)
796                     | (SYS_IRQ << 22U)
797                     | (SYS_IRQ << 23U)
798                     | (SYS_IRQ << 24U)
799                     | (SYS_IRQ << 25U)
800                     | (SYS_IRQ << 26U)
801                     | (SYS_IRQ << 27U)
802                     | (SYS_IRQ << 28U)
803                     | (SYS_IRQ << 29U)
804                     | (SYS_IRQ << 30U)
805                     | (SYS_IRQ << 31U);
806
807     vimREG->FIRQPR3 =  SYS_IRQ
808                     | (SYS_IRQ << 1U)
809                     | (SYS_IRQ << 2U)
810                     | (SYS_IRQ << 3U)
811                     | (SYS_IRQ << 4U)
812                     | (SYS_IRQ << 5U)
813                     | (SYS_IRQ << 6U)
814                     | (SYS_IRQ << 7U)
815                     | (SYS_IRQ << 8U)
816                     | (SYS_IRQ << 9U)
817                     | (SYS_IRQ << 10U)
818                     | (SYS_IRQ << 11U)
819                     | (SYS_IRQ << 12U)
820                     | (SYS_IRQ << 13U)
821                     | (SYS_IRQ << 14U)
822                     | (SYS_IRQ << 15U)
823                     | (SYS_IRQ << 16U)
824                     | (SYS_IRQ << 17U)
825                     | (SYS_IRQ << 18U)
826                     | (SYS_IRQ << 19U)
827                     | (SYS_IRQ << 20U)
828                     | (SYS_IRQ << 21U)
829                     | (SYS_IRQ << 22U)
830                     | (SYS_IRQ << 23U)
831                     | (SYS_IRQ << 24U)
832                     | (SYS_IRQ << 25U)
833                     | (SYS_IRQ << 26U)
834                     | (SYS_IRQ << 27U)
835                     | (SYS_IRQ << 28U)
836                     | (SYS_IRQ << 29U)
837                     | (SYS_IRQ << 30U)
838                     | (SYS_IRQ << 31U);
839
840
841     /* enable interrupts */
842     vimREG->REQMASKSET0 = 1U
843                         | (1U << 1U)
844                         | (1U << 2U)
845                         | (0U << 3U)
846                         | (0U << 4U)
847                         | (0U << 5U)
848                         | (0U << 6U)
849                         | (0U << 7U)
850                         | (0U << 8U)
851                         | (0U << 9U)
852                         | (0U << 10U)
853                         | (0U << 11U)
854                         | (1U << 12U)
855                         | (1U << 13U)
856                         | (0U << 14U)
857                         | (1U << 15U)
858                         | (1U << 16U)
859                         | (1U << 17U)
860                         | (0U << 18U)
861                         | (0U << 19U)
862                         | (0U << 20U)
863                         | (0U << 21U)
864                         | (0U << 22U)
865                         | (0U << 23U)
866                         | (0U << 24U)
867                         | (0U << 25U)
868                         | (1U << 26U)
869                         | (0U << 27U)
870                         | (0U << 28U)
871                         | (0U << 29U)
872                         | (1U << 30U)
873                         | (0U << 31U);
874
875     vimREG->REQMASKSET1 = 0U
876                         | (0U << 1U)
877                         | (0U << 2U)
878                         | (1U << 3U)
879                         | (0U << 4U)
880                         | (1U << 5U)
881                         | (1U << 6U)
882                         | (0U << 7U)
883                         | (0U << 8U)
884                         | (0U << 9U)
885                         | (0U << 10U)
886                         | (0U << 11U)
887                         | (0U << 12U)
888                         | (1U << 13U)
889                         | (0U << 14U)
890                         | (0U << 15U)
891                         | (0U << 16U)
892                         | (1U << 17U)
893                         | (0U << 18U)
894                         | (1U << 19U)
895                         | (0U << 20U)
896                         | (0U << 21U)
897                         | (1U << 22U)
898                         | (0U << 23U)
899                         | (0U << 24U)
900                         | (0U << 25U)
901                         | (0U << 26U)
902                         | (0U << 27U)
903                         | (0U << 28U)
904                         | (0U << 29U)
905                         | (0U << 30U)
906                         | (0U << 31U);
907
908     vimREG->REQMASKSET2 = 1U
909                         | (0U << 1U)
910                         | (0U << 2U)
911                         | (0U << 3U)
912                         | (0U << 4U)
913                         | (0U << 5U)
914                         | (0U << 6U)
915                         | (0U << 7U)
916                         | (0U << 8U)
917                         | (0U << 9U)
918                         | (0U << 10U)
919                         | (0U << 11U)
920                         | (0U << 12U)
921                         | (1U << 13U)       // EMACCore0TxIsr
922                         | (0U << 14U)
923                         | (1U << 15U)       // EMACCore0RxIsr
924                         | (0U << 16U)
925                         | (0U << 17U)
926                         | (0U << 18U)
927                         | (0U << 19U)
928                         | (0U << 20U)
929                         | (0U << 21U)
930                         | (0U << 22U)
931                         | (0U << 23U)
932                         | (0U << 24U)
933                         | (0U << 25U)
934                         | (0U << 26U)
935                         | (0U << 27U)
936                         | (0U << 28U)
937                         | (0U << 29U)
938                         | (0U << 30U)
939                         | (0U << 31U);
940
941     vimREG->REQMASKSET3 =  0U
942                         | (0U << 1U)
943                         | (0U << 2U)
944                         | (0U << 3U)
945                         | (0U << 4U)
946                         | (0U << 5U)
947                         | (0U << 6U)
948                         | (0U << 7U)
949                         | (0U << 8U)
950                         | (0U << 9U)
951                         | (0U << 10U)
952                         | (0U << 11U)
953                         | (0U << 12U)
954                         | (0U << 13U)
955                         | (0U << 14U)
956                         | (0U << 15U)
957                         | (0U << 16U)
958                         | (0U << 17U)
959                         | (0U << 18U)
960                         | (0U << 19U)
961                         | (0U << 20U)
962                         | (0U << 21U)
963                         | (0U << 22U)
964                         | (0U << 23U)
965                         | (0U << 24U)
966                         | (0U << 25U)
967                         | (0U << 26U)
968                         | (0U << 27U)
969                         | (0U << 28U)
970                         | (0U << 29U)
971                         | (0U << 30U)
972                         | (0U << 31U);
973
974 /* USER CODE BEGIN (64) */
975 /* USER CODE END */
976
977     /* Configure system response to error conditions signaled to the ESM group1 */
978     /* This function can be configured from the ESM tab of HALCoGen */
979     esmInit();
980
981     /* initalise copy table */
982     if ((uint32_t *)&__binit__ != (uint32_t *)0xFFFFFFFFU)
983     {
984         extern void copy_in(void *binit);
985         copy_in((void *)&__binit__);
986     }
987
988     /* initalise the C global variables */
989     if (&__TI_Handler_Table_Base < &__TI_Handler_Table_Limit)
990     {
991         uint8_t **tablePtr   = (uint8_t **)&__TI_CINIT_Base;
992         uint8_t **tableLimit = (uint8_t **)&__TI_CINIT_Limit;
993
994         while (tablePtr < tableLimit)
995         {
996             uint8_t *loadAdr = *tablePtr++;
997             uint8_t *runAdr  = *tablePtr++;
998             uint8_t  idx     = *loadAdr++;
999             handler_fptr   handler = (handler_fptr)(&__TI_Handler_Table_Base)[idx];
1000
1001             (*handler)((const uint8_t *)loadAdr, runAdr);
1002         }
1003     }
1004
1005     /* initalise contructors */
1006     if (__TI_PINIT_Base < __TI_PINIT_Limit)
1007     {
1008         void (**p0)() = (void *)__TI_PINIT_Base;
1009
1010         while ((uint32_t)p0 < __TI_PINIT_Limit)
1011         {
1012             void (*p)() = *p0++;
1013             p();
1014         }
1015     }
1016
1017 /* USER CODE BEGIN (65) */
1018 /* USER CODE END */
1019
1020     /* call the application */
1021     main();
1022
1023 /* USER CODE BEGIN (66) */
1024 /* USER CODE END */
1025
1026     exit();
1027 /* USER CODE BEGIN (67) */
1028 /* USER CODE END */
1029 }
1030
1031 /* USER CODE BEGIN (68) */
1032 /* USER CODE END */