void LED_init(void) { // init GPIO1 port GPIO_initPort(GPIO1); // init GPIO1.21-24 pins GPIO_initPin(GPIO1,USER_LED0); GPIO_initPin(GPIO1,USER_LED1); GPIO_initPin(GPIO1,USER_LED2); GPIO_initPin(GPIO1,USER_LED3); // set GPIO1.21-24 as OUTPUT GPIO_setDirection(GPIO1,USER_LED0,OUTPUT); GPIO_setDirection(GPIO1,USER_LED1,OUTPUT); GPIO_setDirection(GPIO1,USER_LED2,OUTPUT); GPIO_setDirection(GPIO1,USER_LED3,OUTPUT); // clear on init GPIO_clrPin(GPIO1,USER_LED0); GPIO_clrPin(GPIO1,USER_LED1); GPIO_clrPin(GPIO1,USER_LED2); GPIO_clrPin(GPIO1,USER_LED3); }
void main(void) { CPU_Handle myCpu; PLL_Handle myPll; WDOG_Handle myWDog; // Initialize all the handles needed for this application myClk = CLK_init((void *)CLK_BASE_ADDR, sizeof(CLK_Obj)); myCpu = CPU_init((void *)NULL, sizeof(CPU_Obj)); myFlash = FLASH_init((void *)FLASH_BASE_ADDR, sizeof(FLASH_Obj)); myGpio = GPIO_init((void *)GPIO_BASE_ADDR, sizeof(GPIO_Obj)); myPie = PIE_init((void *)PIE_BASE_ADDR, sizeof(PIE_Obj)); myPll = PLL_init((void *)PLL_BASE_ADDR, sizeof(PLL_Obj)); myPwm1 = PWM_init((void *)PWM_ePWM1_BASE_ADDR, sizeof(PWM_Obj)); myPwm2 = PWM_init((void *)PWM_ePWM2_BASE_ADDR, sizeof(PWM_Obj)); myPwm3 = PWM_init((void *)PWM_ePWM3_BASE_ADDR, sizeof(PWM_Obj)); myWDog = WDOG_init((void *)WDOG_BASE_ADDR, sizeof(WDOG_Obj)); // Perform basic system initialization WDOG_disable(myWDog); CLK_enableAdcClock(myClk); (*Device_cal)(); CLK_disableAdcClock(myClk); //Select the internal oscillator 1 as the clock source CLK_setOscSrc(myClk, CLK_OscSrc_Internal); // Setup the PLL for x10 /2 which will yield 50Mhz = 10Mhz * 10 / 2 PLL_setup(myPll, PLL_Multiplier_10, PLL_DivideSelect_ClkIn_by_2); // Disable the PIE and all interrupts PIE_disable(myPie); PIE_disableAllInts(myPie); CPU_disableGlobalInts(myCpu); CPU_clearIntFlags(myCpu); // Setup a debug vector table and enable the PIE PIE_setDebugIntVectorTable(myPie); PIE_enable(myPie); // Register interrupt handlers in the PIE vector table PIE_registerPieIntHandler(myPie, PIE_GroupNumber_3, PIE_SubGroupNumber_1, (intVec_t)&EPwm1_timer_isr); PIE_registerPieIntHandler(myPie, PIE_GroupNumber_3, PIE_SubGroupNumber_2, (intVec_t)&EPwm2_timer_isr); PIE_registerPieIntHandler(myPie, PIE_GroupNumber_3, PIE_SubGroupNumber_3, (intVec_t)&EPwm3_timer_isr); // Initialize the EPwm Timers used in this example InitEPwmTimer(); #ifdef _FLASH // Copy time critical code and Flash setup code to RAM // This includes the following ISR functions: EPwm1_timer_isr(), EPwm2_timer_isr() // and FLASH_setup(); // The RamfuncsLoadStart, RamfuncsLoadSize, and RamfuncsRunStart // symbols are created by the linker. Refer to the F2280270.cmd file. memcpy(&RamfuncsRunStart, &RamfuncsLoadStart, (size_t)&RamfuncsLoadSize); // Call Flash Initialization to setup flash waitstates // This function must reside in RAM FLASH_setup(myFlash); #endif // end #ifdef _FLASH // Initalize counters: EPwm1TimerIntCount = 0; EPwm2TimerIntCount = 0; EPwm3TimerIntCount = 0; LoopCount = 0; // Enable CPU INT3 which is connected to EPwm1-3 INT: CPU_enableInt(myCpu, CPU_IntNumber_3); // Enable EPwm INTn in the PIE: Group 3 interrupt 1-3. PIE_enablePwmInt(myPie, PWM_Number_1); PIE_enablePwmInt(myPie, PWM_Number_2); PIE_enablePwmInt(myPie, PWM_Number_3); // Enable global Interrupts and higher priority real-time debug events CPU_enableGlobalInts(myCpu); CPU_enableDebugInt(myCpu); // Configure GPIO so it can toggle in the idle loop GPIO_setMode(myGpio, GPIO_Number_34, GPIO_34_Mode_GeneralPurpose); GPIO_setDirection(myGpio, GPIO_Number_34, GPIO_Direction_Output); for(;;) { // This loop will be interrupted, so the overall // delay between pin toggles will be longer. DELAY_US(DELAY); LoopCount++; // Toggle GPIO GPIO_toggle(myGpio, GPIO_Number_34); } }