aboutsummaryrefslogtreecommitdiffstats
path: root/libmaple/iwdg.c
diff options
context:
space:
mode:
authorMarti Bolivar <mbolivar@leaflabs.com>2011-05-09 16:43:27 -0400
committerMarti Bolivar <mbolivar@leaflabs.com>2011-05-09 16:49:08 -0400
commit19ea6ba4ea3f1ecb9830cf4d3e1366513f4f96e3 (patch)
treea43f7e0fb3650ca54f245b750a078a0e8c356504 /libmaple/iwdg.c
parent868fb1c273e562a1140abfa948022c9d4f55bccf (diff)
parent1e2e177f6dae62e040c674b617744c73be187062 (diff)
downloadlibrambutan-19ea6ba4ea3f1ecb9830cf4d3e1366513f4f96e3.tar.gz
librambutan-19ea6ba4ea3f1ecb9830cf4d3e1366513f4f96e3.zip
Merge branch 'refactor'
This merges the libmaple refactor work into master. The contents of libmaple proper (/libmaple/) are almost completely incompatible with previous APIs in master. See /docs/source/libmaple/overview.rst for more information on the new design. Wirish incompatibilities are limited to the HardwareTimer class; however, there are several new deprecations, most likely to be removed in 0.1.0.
Diffstat (limited to 'libmaple/iwdg.c')
-rw-r--r--libmaple/iwdg.c41
1 files changed, 22 insertions, 19 deletions
diff --git a/libmaple/iwdg.c b/libmaple/iwdg.c
index 82a0151..3d67ee8 100644
--- a/libmaple/iwdg.c
+++ b/libmaple/iwdg.c
@@ -23,34 +23,37 @@
*****************************************************************************/
/**
- * @file iwdg.c
- *
- * @brief Independent watchdog support
+ * @file iwdg.c
+ * @brief Independent watchdog (IWDG) support
*/
-#include "libmaple.h"
#include "iwdg.h"
-#define IWDG_UNLOCK 0x5555
-#define IWDG_START 0xCCCC
-#define IWDG_FEED 0xAAAA
-
/**
- * @brief Initialise and start the watchdog
+ * @brief Initialise and start the watchdog
+ *
+ * The prescaler and reload set the timeout. A prescaler of 3 divides
+ * the 40 kHz clock by 32 and gives roughly 1 ms per reload.
*
- * The prescaler and reload set the timeout. A prescaler of 3 divides
- * the 40 kHz clock by 32 and gives roughly 1 ms per reload.
+ * @param prescaler Prescaler for the 40 KHz IWDG clock.
+ * @param reload Independent watchdog counter reload value.
*/
-void iwdg_init(uint8 prescaler, uint16 reload) {
- __write(IWDG_KR, IWDG_UNLOCK);
- __write(IWDG_PR, prescaler);
- __write(IWDG_RLR, reload);
+void iwdg_init(iwdg_prescaler prescaler, uint16 reload) {
+ IWDG_BASE->KR = IWDG_KR_UNLOCK;
+ IWDG_BASE->PR = prescaler;
+ IWDG_BASE->RLR = reload;
- /* Start things off */
- __write(IWDG_KR, IWDG_START);
- __write(IWDG_KR, IWDG_FEED);
+ /* Start things off */
+ IWDG_BASE->KR = IWDG_KR_START;
+ iwdg_feed();
}
+/**
+ * @brief Reset the IWDG counter.
+ *
+ * Calling this function will cause the IWDG counter to be reset to
+ * its reload value.
+ */
void iwdg_feed(void) {
- __write(IWDG_KR, IWDG_FEED);
+ IWDG_BASE->KR = IWDG_KR_FEED;
}