collab/pb-hal
git clone https://git.julia.blue/collab/pb-hal
1dbe808
control
1//***************************************************************************** 2// 3// Startup.c - Startup code for use on RASLib supported compilers 4// 5// THIS SOFTWARE IS PROVIDED "AS IS" AND WITH ALL FAULTS. 6// NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT 7// NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 8// A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. THE AUTHORS OF THIS FILE 9// SHALL NOT, UNDER ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, 10// OR CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER. 11// 12// This is part of RASLib Rev0 of the RASWare2013 package. 13// 14// Written by: 15// The student branch of the 16// IEEE - Robotics and Automation Society 17// at the University of Texas at Austin 18// 19// Website: ras.ece.utexas.edu 20// Contact: ut.ieee.ras@gmail.com 21// 22//***************************************************************************** 23 24#include <StellarisWare/inc/hw_nvic.h> 25#include <StellarisWare/inc/hw_types.h> 26 27// Initialization entry point for RASLib 28extern void InitializeMCU (void ); 29 30// The entry point for the application 31extern int main (void ); 32 33// Forward declaration of the default fault handlers 34void ResetHandler (void ); 35void NmiHandler (void ); 36void FaultHandler (void ); 37void IntDefaultHandler (void ); 38 39// Declaration of interrupt service routines 40extern void PanicHandler (void ); 41extern void ADC0SS0Handler (void ); 42extern void ADC0SS1Handler (void ); 43extern void ADC1SS0Handler (void ); 44extern void ADC1SS1Handler (void ); 45extern void PortAHandler (void ); 46extern void PortBHandler (void ); 47extern void PortCHandler (void ); 48extern void PortDHandler (void ); 49extern void PortEHandler (void ); 50extern void PortFHandler (void ); 51extern void SysTickHandler (void ); 52extern void WTimer0AHandler (void ); 53extern void WTimer0BHandler (void ); 54extern void WTimer1AHandler (void ); 55extern void WTimer1BHandler (void ); 56extern void WTimer2AHandler (void ); 57extern void WTimer2BHandler (void ); 58extern void WTimer3AHandler (void ); 59extern void WTimer3BHandler (void ); 60extern void WTimer4AHandler (void ); 61extern void WTimer4BHandler (void ); 62extern void WTimer5Handler (void ); 63extern void I2C0Handler (void ); 64extern void I2C1Handler (void ); 65extern void I2C2Handler (void ); 66extern void I2C3Handler (void ); 67extern void I2C4Handler (void ); 68extern void I2C5Handler (void ); 69 70 71// The vector table. Note that the proper constructs must be placed on this to 72// ensure that it ends up at physical address 0x00000000 73__attribute__((section (".isr_vector" ))) 74void (* const __Vectors [])(void )= { 75 (void (* )())(0x20008000 ),// The initial stack pointer 76ResetHandler ,// The reset handler 77NmiHandler ,// The NMI handler 78FaultHandler ,// The hard fault handler 79IntDefaultHandler ,// The MPU fault handler 80IntDefaultHandler ,// The bus fault handler 81IntDefaultHandler ,// The usage fault handler 820 ,// Reserved 830 ,// Reserved 840 ,// Reserved 850 ,// Reserved 86IntDefaultHandler ,// SVCall handler 87IntDefaultHandler ,// Debug monitor handler 880 ,// Reserved 89IntDefaultHandler ,// The PendSV handler 90SysTickHandler ,// The SysTick handler 91PortAHandler ,// GPIO Port A 92PortBHandler ,// GPIO Port B 93PortCHandler ,// GPIO Port C 94PortDHandler ,// GPIO Port D 95PortEHandler ,// GPIO Port E 96IntDefaultHandler ,// UART0 Rx and Tx 97IntDefaultHandler ,// UART1 Rx and Tx 98IntDefaultHandler ,// SSI0 Rx and Tx 99I2C0Handler ,// I2C0 Master and Slave 100IntDefaultHandler ,// PWM Fault 101IntDefaultHandler ,// PWM Generator 0 102IntDefaultHandler ,// PWM Generator 1 103IntDefaultHandler ,// PWM Generator 2 104IntDefaultHandler ,// Quadrature Encoder 0 105ADC0SS0Handler ,// ADC Sequence 0 106ADC0SS1Handler ,// ADC Sequence 1 107IntDefaultHandler ,// ADC Sequence 2 108IntDefaultHandler ,// ADC Sequence 3 109IntDefaultHandler ,// Watchdog timer 110IntDefaultHandler ,// Timer 0 subtimer A 111IntDefaultHandler ,// Timer 0 subtimer B 112IntDefaultHandler ,// Timer 1 subtimer A 113IntDefaultHandler ,// Timer 1 subtimer B 114IntDefaultHandler ,// Timer 2 subtimer A 115IntDefaultHandler ,// Timer 2 subtimer B 116IntDefaultHandler ,// Analog Comparator 0 117IntDefaultHandler ,// Analog Comparator 1 118IntDefaultHandler ,// Analog Comparator 2 119IntDefaultHandler ,// System Control (PLL, OSC, BO) 120IntDefaultHandler ,// FLASH Control 121PortFHandler ,// GPIO Port F 122IntDefaultHandler ,// GPIO Port G 123IntDefaultHandler ,// GPIO Port H 124IntDefaultHandler ,// UART2 Rx and Tx 125IntDefaultHandler ,// SSI1 Rx and Tx 126IntDefaultHandler ,// Timer 3 subtimer A 127IntDefaultHandler ,// Timer 3 subtimer B 128I2C1Handler ,// I2C1 Master and Slave 129IntDefaultHandler ,// Quadrature Encoder 1 130IntDefaultHandler ,// CAN0 131IntDefaultHandler ,// CAN1 132IntDefaultHandler ,// CAN2 133IntDefaultHandler ,// Ethernet 134IntDefaultHandler ,// Hibernate 135IntDefaultHandler ,// USB0 136IntDefaultHandler ,// PWM Generator 3 137IntDefaultHandler ,// uDMA Software Transfer 138IntDefaultHandler ,// uDMA Error 139ADC1SS0Handler ,// ADC1 Sequence 0 140ADC1SS1Handler ,// ADC1 Sequence 1 141IntDefaultHandler ,// ADC1 Sequence 2 142IntDefaultHandler ,// ADC1 Sequence 3 143IntDefaultHandler ,// I2S0 144IntDefaultHandler ,// External Bus Interface 0 145IntDefaultHandler ,// GPIO Port J 146IntDefaultHandler ,// GPIO Port K 147IntDefaultHandler ,// GPIO Port L 148IntDefaultHandler ,// SSI2 Rx and Tx 149IntDefaultHandler ,// SSI3 Rx and Tx 150IntDefaultHandler ,// UART3 Rx and Tx 151IntDefaultHandler ,// UART4 Rx and Tx 152IntDefaultHandler ,// UART5 Rx and Tx 153IntDefaultHandler ,// UART6 Rx and Tx 154IntDefaultHandler ,// UART7 Rx and Tx 1550 ,// Reserved 1560 ,// Reserved 1570 ,// Reserved 1580 ,// Reserved 159I2C2Handler ,// I2C2 Master and Slave 160I2C3Handler ,// I2C3 Master and Slave 161IntDefaultHandler ,// Timer 4 subtimer A 162IntDefaultHandler ,// Timer 4 subtimer B 1630 ,// Reserved 1640 ,// Reserved 1650 ,// Reserved 1660 ,// Reserved 1670 ,// Reserved 1680 ,// Reserved 1690 ,// Reserved 1700 ,// Reserved 1710 ,// Reserved 1720 ,// Reserved 1730 ,// Reserved 1740 ,// Reserved 1750 ,// Reserved 1760 ,// Reserved 1770 ,// Reserved 1780 ,// Reserved 1790 ,// Reserved 1800 ,// Reserved 1810 ,// Reserved 1820 ,// Reserved 183IntDefaultHandler ,// Timer 5 subtimer A 184IntDefaultHandler ,// Timer 5 subtimer B 185WTimer0AHandler ,// Wide Timer 0 subtimer A 186WTimer0BHandler ,// Wide Timer 0 subtimer B 187WTimer1AHandler ,// Wide Timer 1 subtimer A 188WTimer1BHandler ,// Wide Timer 1 subtimer B 189WTimer2AHandler ,// Wide Timer 2 subtimer A 190WTimer2BHandler ,// Wide Timer 2 subtimer B 191WTimer3AHandler ,// Wide Timer 3 subtimer A 192WTimer3BHandler ,// Wide Timer 3 subtimer B 193WTimer4AHandler ,// Wide Timer 4 subtimer A 194WTimer4BHandler ,// Wide Timer 4 subtimer B 195WTimer5Handler ,// Wide Timer 5 subtimer A 196IntDefaultHandler ,// Wide Timer 5 subtimer B 197IntDefaultHandler ,// FPU 198IntDefaultHandler ,// PECI 0 199IntDefaultHandler ,// LPC 0 200I2C4Handler ,// I2C4 Master and Slave 201I2C5Handler ,// I2C5 Master and Slave 202IntDefaultHandler ,// GPIO Port M 203IntDefaultHandler ,// GPIO Port N 204IntDefaultHandler ,// Quadrature Encoder 2 205IntDefaultHandler ,// Fan 0 2060 ,// Reserved 207IntDefaultHandler ,// GPIO Port P (Summary or P0) 208IntDefaultHandler ,// GPIO Port P1 209IntDefaultHandler ,// GPIO Port P2 210IntDefaultHandler ,// GPIO Port P3 211IntDefaultHandler ,// GPIO Port P4 212IntDefaultHandler ,// GPIO Port P5 213IntDefaultHandler ,// GPIO Port P6 214IntDefaultHandler ,// GPIO Port P7 215IntDefaultHandler ,// GPIO Port Q (Summary or Q0) 216IntDefaultHandler ,// GPIO Port Q1 217IntDefaultHandler ,// GPIO Port Q2 218IntDefaultHandler ,// GPIO Port Q3 219IntDefaultHandler ,// GPIO Port Q4 220IntDefaultHandler ,// GPIO Port Q5 221IntDefaultHandler ,// GPIO Port Q6 222IntDefaultHandler ,// GPIO Port Q7 223IntDefaultHandler ,// GPIO Port R 224IntDefaultHandler ,// GPIO Port S 225IntDefaultHandler ,// PWM 1 Generator 0 226IntDefaultHandler ,// PWM 1 Generator 1 227IntDefaultHandler ,// PWM 1 Generator 2 228IntDefaultHandler ,// PWM 1 Generator 3 229IntDefaultHandler // PWM 1 Fault 230}; 231 232 233// The following are constructs created by the linker, indicating where the 234// the "data" and "bss" segments reside in memory. The initializers for the 235// for the "data" segment resides immediately following the "text" segment and 236// the RO and RW memory is garunteed to be sequential. 237// The actual definitions are linker dependent and use the preprocessor to select. 238#ifdef __CC_ARM 239extern unsigned long Load$$ER_RW$$RW$$Base ; 240extern unsigned long Image$$ER_RW$$RW$$Base ; 241extern unsigned long Image$$ER_RW$$RW$$Limit ; 242extern unsigned long Image$$ER_ZI$$ZI$$Base ; 243extern unsigned long Image$$ER_ZI$$ZI$$Limit ; 244 245#define DATA_LOAD &(Load$$ER_RW$$RW$$Base) 246#define DATA_START &(Image$$ER_RW$$RW$$Base) 247#define DATA_END &(Image$$ER_RW$$RW$$Limit) 248#define BSS_START &(Image$$ER_ZI$$ZI$$Base) 249#define BSS_END &(Image$$ER_ZI$$ZI$$Limit) 250#else 251extern unsigned long _sidata ; 252extern unsigned long _data ; 253extern unsigned long _edata ; 254extern unsigned long _bss ; 255extern unsigned long _ebss ; 256 257#define DATA_LOAD &_sidata 258#define DATA_START &_data 259#define DATA_END &_edata 260#define BSS_START &_bss 261#define BSS_END &_ebss 262#endif 263 264 265// This is the code that gets called when the processor first starts execution 266// following a reset event. Only the absolutely necessary set is performed, 267// after which the application supplied entry() routine is called. Any fancy 268// actions (such as making decisions based on the reset cause register, and 269// resetting the bits in that register) are left solely in the hands of the 270// application. 271void ResetHandler (void ) { 272 registerunsigned long * src ; 273 registerunsigned long * dest ; 274 275// Copy the data segment initializers from flash to SRAM. 276src = DATA_LOAD ; 277dest = DATA_START ; 278while (dest < DATA_END ) { 279* dest ++ = * src ++ ; 280 } 281 282// Zero fill the bss segment. 283dest = BSS_START ; 284while (dest < BSS_END ) { 285* dest ++ = 0 ; 286 } 287 288// Enable the floating-point unit. This must be done here to handle the 289// case where main() uses floating-point and the function prologue saves 290// floating-point registers (which will fault if floating-point is not 291// enabled). Any configuration of the floating-point unit using DriverLib 292// APIs must be done here prior to the floating-point unit being enabled. 293// 294// Note that this does not use DriverLib since it might not be included in 295// this project. 296HWREG (NVIC_CPAC )= ((HWREG (NVIC_CPAC )& 297 ~(NVIC_CPAC_CP10_M |NVIC_CPAC_CP11_M )) | 298NVIC_CPAC_CP10_FULL |NVIC_CPAC_CP11_FULL ); 299 300// Initialize RASLib 301InitializeMCU (); 302 303// Call the application's entry point. 304main (); 305 306// Enter an infinite loop if we leave main 307while (1 ) {} 308} 309 310// This is the code that gets called when the processor receives a NMI. This 311// must pass through to avoid a race condition during startup 312void NmiHandler (void ) { 313// Pass through 314} 315 316// This is the code that gets called when the processor receives a fault 317// interrupt. This simply enters an infinite loop, preserving the system state 318// for examination by a debugger. 319void FaultHandler (void ) { 320// Panic 321PanicHandler (); 322// Enter an infinite loop 323while (1 ) {} 324} 325 326// This is the code that gets called when the processor receives an unexpected 327// interrupt. This simply enters an infinite loop, preserving the system state 328// for examination by a debugger. 329void IntDefaultHandler (void ) { 330// Panic 331PanicHandler (); 332// Go into an infinite loop 333while (1 ) {} 334}