Advertisement
Guest User

startup_gcc.c

a guest
Sep 27th, 2014
271
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 15.87 KB | None | 0 0
  1. //*****************************************************************************
  2. //
  3. // startup_gcc.c - Startup code for use with GNU tools.
  4. //
  5. // Copyright (c) 2012 Texas Instruments Incorporated.  All rights reserved.
  6. // Software License Agreement
  7. //
  8. // Texas Instruments (TI) is supplying this software for use solely and
  9. // exclusively on TI's microcontroller products. The software is owned by
  10. // TI and/or its suppliers, and is protected under applicable copyright
  11. // laws. You may not combine this software with "viral" open-source
  12. // software in order to form a larger program.
  13. //
  14. // THIS SOFTWARE IS PROVIDED "AS IS" AND WITH ALL FAULTS.
  15. // NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT
  16. // NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  17. // A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. TI SHALL NOT, UNDER ANY
  18. // CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR CONSEQUENTIAL
  19. // DAMAGES, FOR ANY REASON WHATSOEVER.
  20. //
  21. // This is part of revision 9453 of the EK-LM4F120XL Firmware Package.
  22. //
  23. //*****************************************************************************
  24.  
  25. #include "inc/hw_nvic.h"
  26. #include "inc/hw_types.h"
  27.  
  28. //*****************************************************************************
  29. //
  30. // Forward declaration of the default fault handlers.
  31. //
  32. //*****************************************************************************
  33. void ResetISR(void);
  34. static void NmiSR(void);
  35. static void FaultISR(void);
  36. static void IntDefaultHandler(void);
  37.  
  38. //*****************************************************************************
  39. //
  40. // The entry point for the application.
  41. //
  42. //*****************************************************************************
  43. extern int main(void);
  44.  
  45. //*****************************************************************************
  46. //
  47. // Reserve space for the system stack.
  48. //
  49. //*****************************************************************************
  50. static unsigned long pulStack[64];
  51.  
  52. //*****************************************************************************
  53. //
  54. // The vector table.  Note that the proper constructs must be placed on this to
  55. // ensure that it ends up at physical address 0x0000.0000.
  56. //
  57. //*****************************************************************************
  58. __attribute__ ((section(".isr_vector")))
  59. void (* const g_pfnVectors[])(void) =
  60. {
  61.     (void (*)(void))((unsigned long)pulStack + sizeof(pulStack)),
  62.                                             // The initial stack pointer
  63.     ResetISR,                               // The reset handler
  64.     NmiSR,                                  // The NMI handler
  65.     FaultISR,                               // The hard fault handler
  66.     IntDefaultHandler,                      // The MPU fault handler
  67.     IntDefaultHandler,                      // The bus fault handler
  68.     IntDefaultHandler,                      // The usage fault handler
  69.     0,                                      // Reserved
  70.     0,                                      // Reserved
  71.     0,                                      // Reserved
  72.     0,                                      // Reserved
  73.     IntDefaultHandler,                      // SVCall handler
  74.     IntDefaultHandler,                      // Debug monitor handler
  75.     0,                                      // Reserved
  76.     IntDefaultHandler,                      // The PendSV handler
  77.     IntDefaultHandler,                      // The SysTick handler
  78.     IntDefaultHandler,                      // GPIO Port A
  79.     IntDefaultHandler,                      // GPIO Port B
  80.     IntDefaultHandler,                      // GPIO Port C
  81.     IntDefaultHandler,                      // GPIO Port D
  82.     IntDefaultHandler,                      // GPIO Port E
  83.     IntDefaultHandler,                      // UART0 Rx and Tx
  84.     IntDefaultHandler,                      // UART1 Rx and Tx
  85.     IntDefaultHandler,                      // SSI0 Rx and Tx
  86.     IntDefaultHandler,                      // I2C0 Master and Slave
  87.     IntDefaultHandler,                      // PWM Fault
  88.     IntDefaultHandler,                      // PWM Generator 0
  89.     IntDefaultHandler,                      // PWM Generator 1
  90.     IntDefaultHandler,                      // PWM Generator 2
  91.     IntDefaultHandler,                      // Quadrature Encoder 0
  92.     IntDefaultHandler,                      // ADC Sequence 0
  93.     IntDefaultHandler,                      // ADC Sequence 1
  94.     IntDefaultHandler,                      // ADC Sequence 2
  95.     IntDefaultHandler,                      // ADC Sequence 3
  96.     IntDefaultHandler,                      // Watchdog timer
  97.     IntDefaultHandler,                      // Timer 0 subtimer A
  98.     IntDefaultHandler,                      // Timer 0 subtimer B
  99.     IntDefaultHandler,                      // Timer 1 subtimer A
  100.     IntDefaultHandler,                      // Timer 1 subtimer B
  101.     IntDefaultHandler,                      // Timer 2 subtimer A
  102.     IntDefaultHandler,                      // Timer 2 subtimer B
  103.     IntDefaultHandler,                      // Analog Comparator 0
  104.     IntDefaultHandler,                      // Analog Comparator 1
  105.     IntDefaultHandler,                      // Analog Comparator 2
  106.     IntDefaultHandler,                      // System Control (PLL, OSC, BO)
  107.     IntDefaultHandler,                      // FLASH Control
  108.     IntDefaultHandler,                      // GPIO Port F
  109.     IntDefaultHandler,                      // GPIO Port G
  110.     IntDefaultHandler,                      // GPIO Port H
  111.     IntDefaultHandler,                      // UART2 Rx and Tx
  112.     IntDefaultHandler,                      // SSI1 Rx and Tx
  113.     IntDefaultHandler,                      // Timer 3 subtimer A
  114.     IntDefaultHandler,                      // Timer 3 subtimer B
  115.     IntDefaultHandler,                      // I2C1 Master and Slave
  116.     IntDefaultHandler,                      // Quadrature Encoder 1
  117.     IntDefaultHandler,                      // CAN0
  118.     IntDefaultHandler,                      // CAN1
  119.     IntDefaultHandler,                      // CAN2
  120.     IntDefaultHandler,                      // Ethernet
  121.     IntDefaultHandler,                      // Hibernate
  122.     IntDefaultHandler,                      // USB0
  123.     IntDefaultHandler,                      // PWM Generator 3
  124.     IntDefaultHandler,                      // uDMA Software Transfer
  125.     IntDefaultHandler,                      // uDMA Error
  126.     IntDefaultHandler,                      // ADC1 Sequence 0
  127.     IntDefaultHandler,                      // ADC1 Sequence 1
  128.     IntDefaultHandler,                      // ADC1 Sequence 2
  129.     IntDefaultHandler,                      // ADC1 Sequence 3
  130.     IntDefaultHandler,                      // I2S0
  131.     IntDefaultHandler,                      // External Bus Interface 0
  132.     IntDefaultHandler,                      // GPIO Port J
  133.     IntDefaultHandler,                      // GPIO Port K
  134.     IntDefaultHandler,                      // GPIO Port L
  135.     IntDefaultHandler,                      // SSI2 Rx and Tx
  136.     IntDefaultHandler,                      // SSI3 Rx and Tx
  137.     IntDefaultHandler,                      // UART3 Rx and Tx
  138.     IntDefaultHandler,                      // UART4 Rx and Tx
  139.     IntDefaultHandler,                      // UART5 Rx and Tx
  140.     IntDefaultHandler,                      // UART6 Rx and Tx
  141.     IntDefaultHandler,                      // UART7 Rx and Tx
  142.     0,                                      // Reserved
  143.     0,                                      // Reserved
  144.     0,                                      // Reserved
  145.     0,                                      // Reserved
  146.     IntDefaultHandler,                      // I2C2 Master and Slave
  147.     IntDefaultHandler,                      // I2C3 Master and Slave
  148.     IntDefaultHandler,                      // Timer 4 subtimer A
  149.     IntDefaultHandler,                      // Timer 4 subtimer B
  150.     0,                                      // Reserved
  151.     0,                                      // Reserved
  152.     0,                                      // Reserved
  153.     0,                                      // Reserved
  154.     0,                                      // Reserved
  155.     0,                                      // Reserved
  156.     0,                                      // Reserved
  157.     0,                                      // Reserved
  158.     0,                                      // Reserved
  159.     0,                                      // Reserved
  160.     0,                                      // Reserved
  161.     0,                                      // Reserved
  162.     0,                                      // Reserved
  163.     0,                                      // Reserved
  164.     0,                                      // Reserved
  165.     0,                                      // Reserved
  166.     0,                                      // Reserved
  167.     0,                                      // Reserved
  168.     0,                                      // Reserved
  169.     0,                                      // Reserved
  170.     IntDefaultHandler,                      // Timer 5 subtimer A
  171.     IntDefaultHandler,                      // Timer 5 subtimer B
  172.     IntDefaultHandler,                      // Wide Timer 0 subtimer A
  173.     IntDefaultHandler,                      // Wide Timer 0 subtimer B
  174.     IntDefaultHandler,                      // Wide Timer 1 subtimer A
  175.     IntDefaultHandler,                      // Wide Timer 1 subtimer B
  176.     IntDefaultHandler,                      // Wide Timer 2 subtimer A
  177.     IntDefaultHandler,                      // Wide Timer 2 subtimer B
  178.     IntDefaultHandler,                      // Wide Timer 3 subtimer A
  179.     IntDefaultHandler,                      // Wide Timer 3 subtimer B
  180.     IntDefaultHandler,                      // Wide Timer 4 subtimer A
  181.     IntDefaultHandler,                      // Wide Timer 4 subtimer B
  182.     IntDefaultHandler,                      // Wide Timer 5 subtimer A
  183.     IntDefaultHandler,                      // Wide Timer 5 subtimer B
  184.     IntDefaultHandler,                      // FPU
  185.     IntDefaultHandler,                      // PECI 0
  186.     IntDefaultHandler,                      // LPC 0
  187.     IntDefaultHandler,                      // I2C4 Master and Slave
  188.     IntDefaultHandler,                      // I2C5 Master and Slave
  189.     IntDefaultHandler,                      // GPIO Port M
  190.     IntDefaultHandler,                      // GPIO Port N
  191.     IntDefaultHandler,                      // Quadrature Encoder 2
  192.     IntDefaultHandler,                      // Fan 0
  193.     0,                                      // Reserved
  194.     IntDefaultHandler,                      // GPIO Port P (Summary or P0)
  195.     IntDefaultHandler,                      // GPIO Port P1
  196.     IntDefaultHandler,                      // GPIO Port P2
  197.     IntDefaultHandler,                      // GPIO Port P3
  198.     IntDefaultHandler,                      // GPIO Port P4
  199.     IntDefaultHandler,                      // GPIO Port P5
  200.     IntDefaultHandler,                      // GPIO Port P6
  201.     IntDefaultHandler,                      // GPIO Port P7
  202.     IntDefaultHandler,                      // GPIO Port Q (Summary or Q0)
  203.     IntDefaultHandler,                      // GPIO Port Q1
  204.     IntDefaultHandler,                      // GPIO Port Q2
  205.     IntDefaultHandler,                      // GPIO Port Q3
  206.     IntDefaultHandler,                      // GPIO Port Q4
  207.     IntDefaultHandler,                      // GPIO Port Q5
  208.     IntDefaultHandler,                      // GPIO Port Q6
  209.     IntDefaultHandler,                      // GPIO Port Q7
  210.     IntDefaultHandler,                      // GPIO Port R
  211.     IntDefaultHandler,                      // GPIO Port S
  212.     IntDefaultHandler,                      // PWM 1 Generator 0
  213.     IntDefaultHandler,                      // PWM 1 Generator 1
  214.     IntDefaultHandler,                      // PWM 1 Generator 2
  215.     IntDefaultHandler,                      // PWM 1 Generator 3
  216.     IntDefaultHandler                       // PWM 1 Fault
  217. };
  218.  
  219. //*****************************************************************************
  220. //
  221. // The following are constructs created by the linker, indicating where the
  222. // the "data" and "bss" segments reside in memory.  The initializers for the
  223. // for the "data" segment resides immediately following the "text" segment.
  224. //
  225. //*****************************************************************************
  226. extern unsigned long _etext;
  227. extern unsigned long _data;
  228. extern unsigned long _edata;
  229. extern unsigned long _bss;
  230. extern unsigned long _ebss;
  231.  
  232. //*****************************************************************************
  233. //
  234. // This is the code that gets called when the processor first starts execution
  235. // following a reset event.  Only the absolutely necessary set is performed,
  236. // after which the application supplied entry() routine is called.  Any fancy
  237. // actions (such as making decisions based on the reset cause register, and
  238. // resetting the bits in that register) are left solely in the hands of the
  239. // application.
  240. //
  241. //*****************************************************************************
  242. void
  243. ResetISR(void)
  244. {
  245.     unsigned long *pulSrc, *pulDest;
  246.  
  247.     //
  248.     // Copy the data segment initializers from flash to SRAM.
  249.     //
  250.     pulSrc = &_etext;
  251.     for(pulDest = &_data; pulDest < &_edata; )
  252.     {
  253.         *pulDest++ = *pulSrc++;
  254.     }
  255.  
  256.     //
  257.     // Zero fill the bss segment.
  258.     //
  259.     __asm("    ldr     r0, =_bss\n"
  260.           "    ldr     r1, =_ebss\n"
  261.           "    mov     r2, #0\n"
  262.           "    .thumb_func\n"
  263.           "zero_loop:\n"
  264.           "        cmp     r0, r1\n"
  265.           "        it      lt\n"
  266.           "        strlt   r2, [r0], #4\n"
  267.           "        blt     zero_loop");
  268.  
  269.     //
  270.     // Enable the floating-point unit.  This must be done here to handle the
  271.     // case where main() uses floating-point and the function prologue saves
  272.     // floating-point registers (which will fault if floating-point is not
  273.     // enabled).  Any configuration of the floating-point unit using DriverLib
  274.     // APIs must be done here prior to the floating-point unit being enabled.
  275.     //
  276.     // Note that this does not use DriverLib since it might not be included in
  277.     // this project.
  278.     //
  279.     HWREG(NVIC_CPAC) = ((HWREG(NVIC_CPAC) &
  280.                          ~(NVIC_CPAC_CP10_M | NVIC_CPAC_CP11_M)) |
  281.                         NVIC_CPAC_CP10_FULL | NVIC_CPAC_CP11_FULL);
  282.  
  283.     //
  284.     // Call the application's entry point.
  285.     //
  286.     main();
  287. }
  288.  
  289. //*****************************************************************************
  290. //
  291. // This is the code that gets called when the processor receives a NMI.  This
  292. // simply enters an infinite loop, preserving the system state for examination
  293. // by a debugger.
  294. //
  295. //*****************************************************************************
  296. static void
  297. NmiSR(void)
  298. {
  299.     //
  300.     // Enter an infinite loop.
  301.     //
  302.     while(1)
  303.     {
  304.     }
  305. }
  306.  
  307. //*****************************************************************************
  308. //
  309. // This is the code that gets called when the processor receives a fault
  310. // interrupt.  This simply enters an infinite loop, preserving the system state
  311. // for examination by a debugger.
  312. //
  313. //*****************************************************************************
  314. static void
  315. FaultISR(void)
  316. {
  317.     //
  318.     // Enter an infinite loop.
  319.     //
  320.     while(1)
  321.     {
  322.     }
  323. }
  324.  
  325. //*****************************************************************************
  326. //
  327. // This is the code that gets called when the processor receives an unexpected
  328. // interrupt.  This simply enters an infinite loop, preserving the system state
  329. // for examination by a debugger.
  330. //
  331. //*****************************************************************************
  332. static void
  333. IntDefaultHandler(void)
  334. {
  335.     //
  336.     // Go into an infinite loop.
  337.     //
  338.     while(1)
  339.     {
  340.     }
  341. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement