// Functions that will be run from RAM need to be assigned to // a different section. This section will then be mapped using // the linker cmd file. #pragma CODE_SECTION(ecap2_isr, "ramfuncs"); #pragma CODE_SECTION(cpu_timer0_isr, "ramfuncs"); #pragma CODE_SECTION(InitAdc, "ramfuncs"); // Prototype statements for functions found within this file. interrupt void ecap2_isr(void); interrupt void cpu_timer0_isr(void); void InitECapture(void); void InitEPwmTimer(void); void InitMessage(void); void GetADC(void); void InitGenGpio(void); void Start_Motor (void); void Stop(void); void Fail(void); void ReceiveCANMsg(void); void SendCANMsg(void); Uint16 crc16(Uint32, Uint16); // Global variables Uint16 CRC; // These are defined by the linker (see F2808.cmd) extern Uint16 RamfuncsLoadStart; extern Uint16 RamfuncsLoadEnd; extern Uint16 RamfuncsRunStart; void main(void) { // CAN stuff struct ECAN_MBOXES MBoxesShadow; struct ECAN_REGS ECanaShadow; // CRC test // FlashAddr = &Flash; CRC = crc16(FLASH_BASE, FLASH_SIZE); // if (CRC != CRC) // { // Fail(); // } // Step 1. Initialize System Control: // PLL, WatchDog, enable Peripheral Clocks // This example function is found in the DSP280x_SysCtrl.c file. InitSysCtrl(); // Specific clock setting for this example: EALLOW; SysCtrlRegs.HISPCP.all = ADC_MODCLK; // HSPCLK = SYSCLKOUT/ADC_MODCLK EDIS; // Step 2. Initalize GPIO: InitEPwm3Gpio(); InitECap2Gpio(); InitGenGpio(); InitECanaGpio(); InitMessage(); // Step 3. Clear all interrupts and initialize PIE vector table: // Disable CPU interrupts DINT; // Initialize the PIE control registers to their default state. // The default state is all PIE interrupts disabled and flags // are cleared. // This function is found in the DSP280x_PieCtrl.c file. // XIntruptRegs.XNMICR.bit.ENABLE = 1; // XIntruptRegs.XNMICR.bit.SELECT = 0; InitPieCtrl(); // Disable CPU interrupts and clear all CPU interrupt flags: IER = 0x0000; IFR = 0x0000; // Initialize the PIE vector table with pointers to the shell Interrupt // Service Routines (ISR). // This will populate the entire table, even if the interrupt // is not used in this example. This is useful for debug purposes. // The shell ISR routines are found in DSP280x_DefaultIsr.c. // This function is found in DSP280x_PieVect.c. InitPieVectTable(); // Interrupts that are used in this example are re-mapped to // ISR functions found within this file. EALLOW; // This is needed to write to EALLOW protected registers PieVectTable.ECAP2_INT = &ecap2_isr; PieVectTable.TINT0 = &cpu_timer0_isr; PieVectTable.SEQ1INT = &SEQ1INT_ISR; PieVectTable.SEQ2INT = &SEQ2INT_ISR; PieVectTable.ADCINT = &ADCINT_ISR; EDIS; // This is needed to disable write to EALLOW protected registers // Step 4. Initialize all the Device Peripherals: // This function is found in DSP280x_InitPeripherals.c InitEPwmTimer(); InitECapture(); InitAdc(); InitECana(); InitCpuTimers(); // Copy time critical code and Flash setup code to RAM // This includes the following ISR functions: epwm1_timer_isr(), epwm2_timer_isr() // epwm3_timer_isr and and InitFlash(); // The RamfuncsLoadStart, RamfuncsLoadEnd, and RamfuncsRunStart // symbols are created by the linker. Refer to the F2808.cmd file. MemCopy(&RamfuncsLoadStart, &RamfuncsLoadEnd, &RamfuncsRunStart); // Call Flash Initialization to setup flash waitstates // This function must reside in RAM InitFlash(); ...