watcdogtimerrrrrrrrrr

Files at this revision

API Documentation at this revision

Comitter:
ryuna
Date:
Tue Feb 24 05:35:07 2015 +0000
Commit message:
aaaaaaaaaaaaa

Changed in this revision

WatchDogTimer.cpp Show annotated file Show diff for this revision Revisions of this file
WatchDogTimer.h Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r 2d7cdbcc260e WatchDogTimer.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/WatchDogTimer.cpp	Tue Feb 24 05:35:07 2015 +0000
@@ -0,0 +1,52 @@
+#include "mbed.h"
+#include "WatchDogTimer.h"
+
+/*--------------------------------------------------------------------------------------------------
+ Watchdogクラス
+--------------------------------------------------------------------------------------------------*/
+// WDT発生までの時間を秒数で指定する
+
+
+Watchdog::Watchdog()
+{          
+
+} 
+
+void Watchdog::kick(float s) 
+{
+    // WDTを動作可能にする P22
+    LPC_SYSCON->SYSAHBCLKCTRL |= (1<<15); 
+    // WDTクロックソースの選択
+    //    b00 IRC発振器
+    //    b01 メインクロック
+    //    b10 WDT発振器
+    LPC_SYSCON->WDTCLKSEL = 0x01;
+    // WDTクロックソース更新
+    LPC_SYSCON->WDTCLKUEN = 0;
+    LPC_SYSCON->WDTCLKUEN = 1;
+    while (!(LPC_SYSCON->WDTCLKUEN & 0x01));
+    // WDTレジスタの設定(SystemCoreClock=48MHzの場合) P276
+    LPC_SYSCON->WDTCLKDIV = 4;        // WDTクロック分周レジスタ(0=disable,1~255=分周値)
+    uint32_t clk = SystemCoreClock / 16;    // WD has a fixed /4 prescaler, PCLK default is /4 
+    LPC_WDT->TC = s * (float)clk;           // タイムアウト値を設定
+    Watchdog::enable();                  // Enabled and Reset and reload
+}
+// WDTカウンタリロード
+void Watchdog::kick(void) 
+{
+    //__disable_irq();
+    LPC_WDT->FEED = 0xAA;
+    LPC_WDT->FEED = 0x55;
+    //__enable_irq();
+}
+// WDT有効
+void Watchdog::enable(void) 
+{
+    LPC_WDT->MOD = 0x3;   // b1=resetを発生させる,b0=enable
+    kick();
+}
+// WDT無効(debug用)
+void Watchdog::disable() 
+{
+    LPC_WDT->MOD = 0x0;
+}
\ No newline at end of file
diff -r 000000000000 -r 2d7cdbcc260e WatchDogTimer.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/WatchDogTimer.h	Tue Feb 24 05:35:07 2015 +0000
@@ -0,0 +1,29 @@
+#ifndef MBED_WatchDogTimer_H
+#define MBED_WatchDogTimer_H
+
+
+#include "mbed.h"
+
+class Watchdog {
+  public:
+    /** Create a IRM2121 object connected to the specified InterruptIn pin
+    *
+    * @param IRM_PIN InterruptIn pin to connect to 
+    */
+    Watchdog();
+    void kick(float s); 
+    
+    // WDTカウンタリロード
+    void kick(void) ;
+    
+    // WDT有効
+    void enable(void) ;
+    
+    // WDT無効(debug用)
+    void disable();
+
+
+  };
+  
+
+#endif
\ No newline at end of file