aboutsummaryrefslogtreecommitdiff
path: root/cc3200/hal
diff options
context:
space:
mode:
authorDamien George2017-02-06 11:14:16 +1100
committerDamien George2017-02-06 11:14:16 +1100
commitb7d27e31e8c5d34aaba7e2a7070bb3b6fb082d28 (patch)
tree1912f20bf1c46a7c8acc3cef25e09b9051baecbe /cc3200/hal
parenta4a439caa3f352f8bbbb1d0c79923270561869d3 (diff)
cc3200: Refactor "ticks" functions to use common extmod implementation.
The port now uses the common mp_utime_ticks_{ms,us,cpu,add,diff} functions from extmod/utime_mphal.c. The mp_utime_sleep_XXX functions are still cc3200-specific because they handle the GIL differently to the ones in extmod. The files misc/mpsystick.[ch] have been removed because they contain 2 unused functions, and the other remaining function is renamed to mp_hal_ticks_us and moved to hal/cc3200_hal.c.
Diffstat (limited to 'cc3200/hal')
-rw-r--r--cc3200/hal/cc3200_hal.c14
-rw-r--r--cc3200/hal/cc3200_hal.h6
2 files changed, 19 insertions, 1 deletions
diff --git a/cc3200/hal/cc3200_hal.c b/cc3200/hal/cc3200_hal.c
index 37026db14..5c0e9c30f 100644
--- a/cc3200/hal/cc3200_hal.c
+++ b/cc3200/hal/cc3200_hal.c
@@ -108,6 +108,19 @@ mp_uint_t mp_hal_ticks_ms(void) {
return HAL_tickCount;
}
+// The SysTick timer counts down at HAL_FCPU_HZ, so we can use that knowledge
+// to grab a microsecond counter.
+mp_uint_t mp_hal_ticks_us(void) {
+ mp_uint_t irq_state = disable_irq();
+ uint32_t counter = SysTickValueGet();
+ uint32_t milliseconds = mp_hal_ticks_ms();
+ enable_irq(irq_state);
+
+ uint32_t load = SysTickPeriodGet();
+ counter = load - counter; // Convert from decrementing to incrementing
+ return (milliseconds * 1000) + ((counter * 1000) / load);
+}
+
void mp_hal_delay_ms(mp_uint_t delay) {
// only if we are not within interrupt context and interrupts are enabled
if ((HAL_NVIC_INT_CTRL_REG & HAL_VECTACTIVE_MASK) == 0 && query_irq() == IRQ_STATE_ENABLED) {
@@ -211,4 +224,3 @@ static void hal_TickInit (void) {
MAP_SysTickEnable();
}
#endif
-
diff --git a/cc3200/hal/cc3200_hal.h b/cc3200/hal/cc3200_hal.h
index 9715096b6..fcb85b292 100644
--- a/cc3200/hal/cc3200_hal.h
+++ b/cc3200/hal/cc3200_hal.h
@@ -30,6 +30,9 @@
#include <stdint.h>
#include <stdbool.h>
+#include "hal/utils.h"
+#include "hal/systick.h"
+
/******************************************************************************
DEFINE CONSTANTS
******************************************************************************/
@@ -64,4 +67,7 @@ extern void HAL_SystemDeInit (void);
extern void HAL_IncrementTick(void);
extern void mp_hal_set_interrupt_char (int c);
+#define mp_hal_delay_us(usec) UtilsDelay(UTILS_DELAY_US_TO_COUNT(usec))
+#define mp_hal_ticks_cpu() (SysTickPeriodGet() - SysTickValueGet())
+
#endif /* CC3200_LAUNCHXL_HAL_CC3200_HAL_H_ */