Skip to content

Instantly share code, notes, and snippets.

@jitomesky
Created December 17, 2014 08:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jitomesky/140fc82b1aab7c9cd5ae to your computer and use it in GitHub Desktop.
Save jitomesky/140fc82b1aab7c9cd5ae to your computer and use it in GitHub Desktop.
mbed LPC1768でWatchDogTimerの動作を確認するコード
#include "mbed.h"
#include <stdint.h>
class Watchdog {
public:
// clock souce
enum SRCCLK
{
CLKSRC_IRC = 0,
CLKSRC_PCLK = 1,
CLKSRC_RTC = 2
};
enum RESET
{
RESET_DIS = 0,
RESET_EN = 1
};
void start(RESET reset){
LPC_WDT->WDMOD = 0x01;
if(reset == RESET_EN){
LPC_WDT->WDMOD = 0x02;
}
}
void kick() {
LPC_WDT->WDFEED = 0xAA;
LPC_WDT->WDFEED = 0x55;
}
void setCounter_Raw(uint32_t cnt){
LPC_WDT->WDTC = cnt;
}
uint32_t getCounterValue(void){
return LPC_WDT->WDTV;
}
void setClockSource(SRCCLK src){
LPC_WDT->WDCLKSEL = src;
}
};
// Setup the watchdog timer
Watchdog wdt;
int main() {
printf("reset\n");
// クロックソースを内蔵RCオシレータに設定
wdt.setClockSource(wdt.CLKSRC_IRC);
// カウンタ値を0xffffffff(最大値)に設定
wdt.setCounter_Raw(0xffffffff);
// WDTをリセット
wdt.start(wdt.RESET_EN);
// カウンタ値を反映
wdt.kick();
// 3秒後のWDTカウンタ値を確認
wait(3.0);
printf("0x%08x\n",wdt.getCounterValue());
wdt.setCounter_Raw(0xffffffff);
wdt.kick();
// 0.5秒後のWDTカウンタ値を確認
wait(0.5);
printf("0x%08x\n",wdt.getCounterValue());
// 無限ループに落としてWDTの動作を確認
printf("set WDTC = 0xFF and goto endless loop\n\n");
wdt.setCounter_Raw(0xffff);
wdt.kick();
while(1);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment