<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>LPC MicrocontrollersのトピックWWDT with WDRESET set to 0 (interrupt only)</title>
    <link>https://community.nxp.com/t5/LPC-Microcontrollers/WWDT-with-WDRESET-set-to-0-interrupt-only/m-p/514530#M748</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by miccio on Thu Feb 04 09:46:24 MST 2016&lt;/STRONG&gt;&lt;BR /&gt;&lt;SPAN&gt;Hello everyone,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I am experiencing two very different behaviors from the watchdog when testing my application. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I wrapped the watchdog handling in a class and wrote the following IRQ:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;I&gt;IRQ handler&lt;/I&gt;&lt;BR /&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD bgcolor="#cacaca"&gt; &lt;PRE&gt;
#ifdef __cplusplus
extern "C" {
#endif

void WDT_IRQHandler(void) {
WatchDog::instance().handleIRQ();
}

#ifdef __cplusplus
}
#endif

void WatchDog::handleIRQ() {
uint32_t wdt_status = Chip_WWDT_GetStatus(_reg);

// warning interrupt
if (wdt_status &amp;amp; WWDT_WDMOD_WDINT) {
if(_warning_fnc != NULL) {
_warning_fnc();
}
Chip_WWDT_ClearStatusFlag(_reg, WWDT_WDMOD_WDINT);
}

// timeout interrupt
if (wdt_status &amp;amp; WWDT_WDMOD_WDTOF) {
if(_timeout_fnc != NULL) {
_timeout_fnc();
}
Chip_WWDT_ClearStatusFlag(_reg, WWDT_WDMOD_WDTOF);
}
}
&lt;/PRE&gt; &lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;I&gt;callback function&lt;/I&gt;&lt;BR /&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD bgcolor="#cacaca"&gt; &lt;PRE&gt;
void wdt_wrn_irq() {
Debug::instance() &amp;lt;&amp;lt; "WDT warning " &amp;lt;&amp;lt; gbl_sw.elapsedMS() &amp;lt;&amp;lt; endl;
}
void wdt_rst_irq() {
Debug::instance() &amp;lt;&amp;lt; "WDT timeout " &amp;lt;&amp;lt; gbl_sw.elapsedMS() &amp;lt;&amp;lt; endl;
}
&lt;/PRE&gt; &lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;I&gt;usage in main code&lt;/I&gt;&lt;BR /&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD bgcolor="#cacaca"&gt; &lt;PRE&gt;
WatchDog&amp;amp; wdt = WatchDog::instance();
wdt.init();

wdt.setTimeOutFunction(wdt_rst_irq);
wdt.setTimeOutMode(WDT_TO_Interrupt);
wdt.setTimeOutMS(5000);

// wdt.setWarningUS(50000);
// wdt.setWarningFunction(wdt_wrn_irq);

if(wdt.start()) {
Debug::instance() &amp;lt;&amp;lt; "WDT started" &amp;lt;&amp;lt; endl;
}
&lt;/PRE&gt; &lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;In this way, I can set a callback function that handles a timeout and/or warning event. &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;When I just let the code run with no breakpoint, the function seems to never get hit and nothing gets printed on the screen; when i set a breakpoint at handleIRQ(), it would however stop there and succesfully print the message when resumed.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;It's also worth mentioning that the warning interrupt callback (represented by pointer &lt;/SPAN&gt;&lt;STRONG&gt;void (*_warning_fnc)()&lt;/STRONG&gt;&lt;SPAN&gt; ) gets executed regardless of whether I set breakpoints. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;And it gets even weirder: I will use a different setup in my main code in order to enable the warning interrupt, like this:&lt;/SPAN&gt;&lt;BR /&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD bgcolor="#cacaca"&gt; &lt;PRE&gt;
WatchDog&amp;amp; wdt = WatchDog::instance();
wdt.init();

wdt.setTimeOutMode(WDT_TO_Interrupt);
wdt.setTimeOutMS(5000);
wdt.setTimeOutFunction(wdt_rst_irq);

wdt.setWarningUS(50000);
wdt.setWarningFunction(wdt_wrn_irq);

if(wdt.start()) {
Debug::instance() &amp;lt;&amp;lt; "WDT started" &amp;lt;&amp;lt; endl;
}
&lt;/PRE&gt; &lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Now if I run with the usual breakpoint, the following will appear on screen:&lt;/SPAN&gt;&lt;BR /&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD bgcolor="#cacaca"&gt; &lt;PRE&gt;
WDT started
WDT warning 4711
WDT timeout 4713
&lt;/PRE&gt; &lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;BR /&gt;&lt;SPAN&gt;Please note that the breakpoint is only hit once, and both callbacks are called withing the same execution of the handler. In facts, reading LPC_WWDT-&amp;gt;MOD gives 1100 in binary. &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;This happens in spite of the value inside&amp;nbsp; LPC_WWDT-&amp;gt;WARNINT which is at its maximum of 1023 (so the warning should occur 8.1ms before the interrupt. Instead, they are triggered at the very same time.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;If I run it with no breakpoint, the following happens:&lt;/SPAN&gt;&lt;BR /&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD bgcolor="#cacaca"&gt; &lt;PRE&gt;
WDT started
WDT warning 4710
&lt;/PRE&gt; &lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;BR /&gt;&lt;SPAN&gt;As you can see in this case, the timeout doesn't even seem to occur!!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Any idea, anyone?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 15 Jun 2016 17:12:45 GMT</pubDate>
    <dc:creator>lpcware</dc:creator>
    <dc:date>2016-06-15T17:12:45Z</dc:date>
    <item>
      <title>WWDT with WDRESET set to 0 (interrupt only)</title>
      <link>https://community.nxp.com/t5/LPC-Microcontrollers/WWDT-with-WDRESET-set-to-0-interrupt-only/m-p/514530#M748</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by miccio on Thu Feb 04 09:46:24 MST 2016&lt;/STRONG&gt;&lt;BR /&gt;&lt;SPAN&gt;Hello everyone,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I am experiencing two very different behaviors from the watchdog when testing my application. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I wrapped the watchdog handling in a class and wrote the following IRQ:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;I&gt;IRQ handler&lt;/I&gt;&lt;BR /&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD bgcolor="#cacaca"&gt; &lt;PRE&gt;
#ifdef __cplusplus
extern "C" {
#endif

void WDT_IRQHandler(void) {
WatchDog::instance().handleIRQ();
}

#ifdef __cplusplus
}
#endif

void WatchDog::handleIRQ() {
uint32_t wdt_status = Chip_WWDT_GetStatus(_reg);

// warning interrupt
if (wdt_status &amp;amp; WWDT_WDMOD_WDINT) {
if(_warning_fnc != NULL) {
_warning_fnc();
}
Chip_WWDT_ClearStatusFlag(_reg, WWDT_WDMOD_WDINT);
}

// timeout interrupt
if (wdt_status &amp;amp; WWDT_WDMOD_WDTOF) {
if(_timeout_fnc != NULL) {
_timeout_fnc();
}
Chip_WWDT_ClearStatusFlag(_reg, WWDT_WDMOD_WDTOF);
}
}
&lt;/PRE&gt; &lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;I&gt;callback function&lt;/I&gt;&lt;BR /&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD bgcolor="#cacaca"&gt; &lt;PRE&gt;
void wdt_wrn_irq() {
Debug::instance() &amp;lt;&amp;lt; "WDT warning " &amp;lt;&amp;lt; gbl_sw.elapsedMS() &amp;lt;&amp;lt; endl;
}
void wdt_rst_irq() {
Debug::instance() &amp;lt;&amp;lt; "WDT timeout " &amp;lt;&amp;lt; gbl_sw.elapsedMS() &amp;lt;&amp;lt; endl;
}
&lt;/PRE&gt; &lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;I&gt;usage in main code&lt;/I&gt;&lt;BR /&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD bgcolor="#cacaca"&gt; &lt;PRE&gt;
WatchDog&amp;amp; wdt = WatchDog::instance();
wdt.init();

wdt.setTimeOutFunction(wdt_rst_irq);
wdt.setTimeOutMode(WDT_TO_Interrupt);
wdt.setTimeOutMS(5000);

// wdt.setWarningUS(50000);
// wdt.setWarningFunction(wdt_wrn_irq);

if(wdt.start()) {
Debug::instance() &amp;lt;&amp;lt; "WDT started" &amp;lt;&amp;lt; endl;
}
&lt;/PRE&gt; &lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;In this way, I can set a callback function that handles a timeout and/or warning event. &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;When I just let the code run with no breakpoint, the function seems to never get hit and nothing gets printed on the screen; when i set a breakpoint at handleIRQ(), it would however stop there and succesfully print the message when resumed.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;It's also worth mentioning that the warning interrupt callback (represented by pointer &lt;/SPAN&gt;&lt;STRONG&gt;void (*_warning_fnc)()&lt;/STRONG&gt;&lt;SPAN&gt; ) gets executed regardless of whether I set breakpoints. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;And it gets even weirder: I will use a different setup in my main code in order to enable the warning interrupt, like this:&lt;/SPAN&gt;&lt;BR /&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD bgcolor="#cacaca"&gt; &lt;PRE&gt;
WatchDog&amp;amp; wdt = WatchDog::instance();
wdt.init();

wdt.setTimeOutMode(WDT_TO_Interrupt);
wdt.setTimeOutMS(5000);
wdt.setTimeOutFunction(wdt_rst_irq);

wdt.setWarningUS(50000);
wdt.setWarningFunction(wdt_wrn_irq);

if(wdt.start()) {
Debug::instance() &amp;lt;&amp;lt; "WDT started" &amp;lt;&amp;lt; endl;
}
&lt;/PRE&gt; &lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Now if I run with the usual breakpoint, the following will appear on screen:&lt;/SPAN&gt;&lt;BR /&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD bgcolor="#cacaca"&gt; &lt;PRE&gt;
WDT started
WDT warning 4711
WDT timeout 4713
&lt;/PRE&gt; &lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;BR /&gt;&lt;SPAN&gt;Please note that the breakpoint is only hit once, and both callbacks are called withing the same execution of the handler. In facts, reading LPC_WWDT-&amp;gt;MOD gives 1100 in binary. &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;This happens in spite of the value inside&amp;nbsp; LPC_WWDT-&amp;gt;WARNINT which is at its maximum of 1023 (so the warning should occur 8.1ms before the interrupt. Instead, they are triggered at the very same time.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;If I run it with no breakpoint, the following happens:&lt;/SPAN&gt;&lt;BR /&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD bgcolor="#cacaca"&gt; &lt;PRE&gt;
WDT started
WDT warning 4710
&lt;/PRE&gt; &lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;BR /&gt;&lt;SPAN&gt;As you can see in this case, the timeout doesn't even seem to occur!!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Any idea, anyone?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Jun 2016 17:12:45 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPC-Microcontrollers/WWDT-with-WDRESET-set-to-0-interrupt-only/m-p/514530#M748</guid>
      <dc:creator>lpcware</dc:creator>
      <dc:date>2016-06-15T17:12:45Z</dc:date>
    </item>
  </channel>
</rss>

