Question: Please explain What the code below is doing line by line: #include //Exact-width integer types #include //Driver library #define DCO_FREQ 48e6 //unit: Hz; DCO nominal
Please explain What the code below is doing line by line:
#include
#include
#define DCO_FREQ 48e6 //unit: Hz; DCO nominal frequencies: 1.5, 3, 6, 12, 24,
48 MHz.
#define TIMER0_FREQ 1 //unit: Hz
//function prototypes
void initDevice(void);
void initTimer(void);
void initGPIO(void);
//global variables
uint32_t clockMCLK;
void main(void)
{
initDevice();
initTimer();
initGPIO();
//Enable interrupts
Interrupt_enableSleepOnIsrExit();
Interrupt_enableMaster();
Timer32_startTimer(TIMER32_0_BASE, false);
while(1)
{
PCM_gotoLPM0();
}
}
void initDevice(void)
{
WDT_A_holdTimer(); //stop Watchdog timer
//Change VCORE to 1 to support a frequency higher than 24MHz.
//See data sheet for Flash wait-state requirement for a given frequency.
PCM_setPowerState(PCM_AM_LDO_VCORE1);
FlashCtl_setWaitState(FLASH_BANK0, 1);
FlashCtl_setWaitState(FLASH_BANK1, 1);
//Enable FPU for DCO Frequency calculation.
FPU_enableModule();
FPU_enableLazyStacking(); // Required to use FPU within ISR.
//Only use DCO nominal frequencies: 1.5, 3, 6, 12, 24, 48MHz.
CS_setDCOFrequency(DCO_FREQ);
//Divider: 1, 2, 4, 8, 16, 32, 64, or 128.
//SMCLK used by UART and ADC14.
CS_initClockSignal(CS_MCLK, CS_DCOCLK_SELECT, CS_CLOCK_DIVIDER_1);
CS_initClockSignal(CS_HSMCLK, CS_DCOCLK_SELECT, CS_CLOCK_DIVIDER_8);
CS_initClockSignal(CS_SMCLK, CS_DCOCLK_SELECT, CS_CLOCK_DIVIDER_16);
clockMCLK = CS_getMCLK();
}
void initTimer(void)
{
Timer32_initModule(TIMER32_0_BASE, TIMER32_PRESCALER_1, TIMER32_32BIT,
TIMER32_PERIODIC_MODE);
Timer32_setCount(TIMER32_0_BASE, clockMCLK/TIMER0_FREQ);
Timer32_enableInterrupt(TIMER32_0_BASE);
Interrupt_enableInterrupt(INT_T32_INT1); //Enable Timer32_0 interrupt in the
interrupt controller.
}
void initGPIO(void)
{
//Configure P1.0 as output.
//P1.0 is connected to a red LED on LaunchPad.
GPIO_setAsOutputPin(GPIO_PORT_P1, GPIO_PIN0);
}
//Timer32_0 ISR
void T32_INT1_IRQHandler(void)
{
Timer32_clearInterruptFlag(TIMER32_0_BASE);
GPIO_toggleOutputOnPin(GPIO_PORT_P1, GPIO_PIN0);
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
