summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Schodet2013-03-14 00:07:55 +0100
committerNicolas Schodet2013-03-14 23:53:39 +0100
commit5d1e60854945bd192f0720ebc3408b1aab68d2f8 (patch)
tree904383abe6760c39e85ce5165de5a6522929035a
parentb99da12d6a5b79320e1c7db49b09e020c1cba6cc (diff)
digital/io-hub/src/apbirthday: add cycle timer
-rw-r--r--digital/io-hub/src/apbirthday/hardware.hh2
-rw-r--r--digital/io-hub/src/apbirthday/hardware.host.cc7
-rw-r--r--digital/io-hub/src/apbirthday/hardware.stm32.cc15
3 files changed, 24 insertions, 0 deletions
diff --git a/digital/io-hub/src/apbirthday/hardware.hh b/digital/io-hub/src/apbirthday/hardware.hh
index 04801c4c..89b162a2 100644
--- a/digital/io-hub/src/apbirthday/hardware.hh
+++ b/digital/io-hub/src/apbirthday/hardware.hh
@@ -56,6 +56,8 @@ struct Hardware
ucoo::HostStream usb;
#endif
Hardware ();
+ // Wait until next cycle.
+ void wait ();
};
#endif // hardware_hh
diff --git a/digital/io-hub/src/apbirthday/hardware.host.cc b/digital/io-hub/src/apbirthday/hardware.host.cc
index 7f62670d..e3cf00b0 100644
--- a/digital/io-hub/src/apbirthday/hardware.host.cc
+++ b/digital/io-hub/src/apbirthday/hardware.host.cc
@@ -34,3 +34,10 @@ Hardware::Hardware ()
{
}
+void
+Hardware::wait ()
+{
+ ucoo::mex::Node &node = host.get_node ();
+ node.wait (node.date () + 4);
+}
+
diff --git a/digital/io-hub/src/apbirthday/hardware.stm32.cc b/digital/io-hub/src/apbirthday/hardware.stm32.cc
index 86ff37f9..8546441d 100644
--- a/digital/io-hub/src/apbirthday/hardware.stm32.cc
+++ b/digital/io-hub/src/apbirthday/hardware.stm32.cc
@@ -24,6 +24,7 @@
#include "hardware.hh"
#include <libopencm3/stm32/f4/rcc.h>
+#include <libopencm3/stm32/f4/timer.h>
#include "ucoolib/hal/gpio/gpio.hh"
Hardware::Hardware ()
@@ -42,5 +43,19 @@ Hardware::Hardware ()
gpio_mode_setup (GPIOD, GPIO_MODE_AF, GPIO_PUPD_NONE, GPIO8 | GPIO9);
gpio_set_af (GPIOD, GPIO_AF7, GPIO8 | GPIO9);
zb_uart.enable (38400, ucoo::Uart::EVEN, 1);
+ // Cycle timer, 4 ms period.
+ rcc_peripheral_enable_clock (&RCC_APB1ENR, RCC_APB1ENR_TIM3EN);
+ TIM3_CR1 = TIM_CR1_CEN;
+ TIM3_PSC = 2 * rcc_ppre1_frequency / 1000000 - 1; // 1 ┬Ás prescaler
+ TIM3_ARR = 4000 - 1;
+ TIM3_EGR = TIM_EGR_UG;
+}
+
+void
+Hardware::wait ()
+{
+ while (!(TIM3_SR & TIM_SR_UIF))
+ ;
+ TIM3_SR = ~TIM_SR_UIF;
}