- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hey guys!
I'm a new user with Cypress MCU and PSoC creator. I've built up a program for my demo board, it seems good.
but I got one question for the WDT code which I downloaded from the homepage. I copied the WDT code in the code source, and I think it is too big to put it in main function. So I wonder if there is some other ideas to simplify the WDT code and make the main function much more slim.
Can anybody help me to solve this problem?
thank you!
int main(void)
{
uint8 key=0,mot_ope=0;/* the mark used for key pressing and motor operation*/
uint8 mode=NORM_MODE;/*dfault mode is set to be normal mode*/
uint32 tempIloCounts = 0u;
/* Turn on Red LED for 2 seconds if reset caused by WDT */
if (CY_SYS_RESET_WDT == CySysGetResetReason(CY_SYS_RESET_WDT))
{
/* Update flag in order to clear WDT */
resetFlag = RESET_FLAG_ACTIVE;
/* Turn on Red LED */
UI_LOWBAT_Write(0);
CyDelay (500);
UI_LOWBAT_Write(1);
/* Make sure that interrupt is forwarded to the CPU */
CySysWdtUnmaskInterrupt();
}
else
{
/* Turn off Red LED */
UI_LOWBAT_Write(1);
/* Configure WDT to be 15-bit wraparound up-counter - 1 MSb is ignored */
CySysWdtSetIgnoreBits(1);
}
/* Configure WDT ISR */
WdtIsr_StartEx(WdtIsr);
/* Start the WDT */
CySysWdtEnable();
/* Starts the ILO accuracy/Trim measurement */
CySysClkIloStartMeasurement();
CyGlobalIntEnable; /* Enable global interrupts. */
ADC_1_Start();
ADC_1_StartConvert();
ADC_2_Start();
/* Place your initialization/startup code here (e.g. MyInst_Start()) */
for(;;)
{
CyDelay (5);
/* If the interrupt has occurred in the ISR */
if(SET == interruptFlag)
{
/* Clear the watchdog interrupt */
CySysWdtClearInterrupt();
/* Enable WDT interrupt */
CySysWdtUnmaskInterrupt();
/* WDT match value is updated in order to obtain periodic interrupts */
CySysWdtWriteMatch(CySysWdtReadMatch() + iloMatchCounts);
/* Clear the software interrupt flag */
interruptFlag = CLEAR;
}
/* Get the ILO compensated counts i.e. the actual counts for the desired ILO frequency
Trimming is done to improve ILO accuracy using IMO; ILO default accuracy is +/- 60% */
if(CYRET_SUCCESS == CySysClkIloCompensate(DESIRED_DELAY, &tempIloCounts))
{
iloMatchCounts = (uint32)tempIloCounts;
/* Once the counts are ready - stop the ILO measurement and put the device to deepsleep */
CySysClkIloStopMeasurement();
/* Start the ILO measurement after wake up */
CySysClkIloStartMeasurement();
}
/* Place your application code here. */
Solved! Go to Solution.
- Labels:
-
PSoC 4 MCU
- Tags:
- CY8C4125LQI-S423
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi @Kinrin ,
Most of the code is simple API calls, and these would be executed only if interruptFlag = SET. You may skip the ILO trimming operation to reduce your code, but I would recommend you retain it.
If this is concerned regarding the aesthetics of the code, then you may write a separate function for WDT operations, and invoke the same in the main() function.
Regards,
Nikhil
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi @Kinrin ,
Most of the code is simple API calls, and these would be executed only if interruptFlag = SET. You may skip the ILO trimming operation to reduce your code, but I would recommend you retain it.
If this is concerned regarding the aesthetics of the code, then you may write a separate function for WDT operations, and invoke the same in the main() function.
Regards,
Nikhil