#include "core/lpc_regs_12xx.h"
#include "core/lpc_core_cm0.h"
#include "core/system.h"
+#include "core/systick.h"
/* Static variables */
global_wrapping_system_clock_cycles = tick_reload;
}
-/* Get system tick timer current value (counts at get_main_clock() !) */
+/* Get system tick timer current value (counts at get_main_clock() !)
+ * systick_get_timer_val returns a value between 0 and systick_get_timer_reload_val()
+ */
uint32_t systick_get_timer_val(void)
{
struct lpc_system_tick* systick = LPC_SYSTICK;
return systick->value;
}
+/* Get system tick timer reload value */
+uint32_t systick_get_timer_reload_val(void)
+{
+ return tick_reload;
+}
/* Check if systick is running (return 1) or not (return 0) */
uint32_t is_systick_running(void)
* Note that calls to this function while a sleep() has been initiated will change the
* sleep duration ....
*/
-void set_sleep(uint32_t ticks)
+static inline void set_sleep(uint32_t ticks)
{
sleep_count = ticks;
}
-/* Return current sleep count_down counter */
-uint32_t get_sleep(void)
-{
- return sleep_count;
-}
/* Actual sleep function, checks that system tick counter is configured to generate
- * an interrupt to move sleep_count down to 0
+ * an interrupt and to move sleep_count down to 0
*/
#define SYSTICK_CAN_SLEEP (LPC_SYSTICK_CTRL_TICKINT | LPC_SYSTICK_CTRL_ENABLE)
-uint32_t sleep(void)
+static uint32_t sleep(void)
{
struct lpc_system_tick* systick = LPC_SYSTICK;
if ((systick->control & SYSTICK_CAN_SLEEP) != SYSTICK_CAN_SLEEP) {
#include "core/lpc_regs_12xx.h"
#include "core/lpc_core_cm0.h"
#include "core/system.h"
+#include "core/systick.h"
#include "core/pio.h"
#include "drivers/rtc.h"
#include "core/lpc_regs_12xx.h"
#include "core/lpc_core_cm0.h"
#include "core/system.h"
+#include "core/systick.h"
#include "core/pio.h"
#include "lib/stdio.h"
#include "drivers/gpio.h"
void clkout_off(void);
-
-/***************************************************************************** */
-/* System Tick Timer */
-/***************************************************************************** */
-
-/* Start the system tick timer
- * Starting the systick timer also resets the internal tick counters.
- * If you need a value that goes beyond one start/stop cycle and accross resets,
- * then it's up to you to keep track of this using systick_get_tick_count() and/or
- * systick_get_clock_cycles().
- */
-void systick_start(void);
-
-/* Stop the system tick timer */
-void systick_stop(void);
-
-/* Reset the system tick timer, making it count down from the reload value again
- * Reseting the systick timer also resets the internal tick counters.
- * If you need a value that goes beyond one start/stop cycle and accross resets,
- * then it's up to you to keep track of this using systick_get_tick_count() and/or
- * systick_get_clock_cycles().
- */
-void systick_reset(void);
-
-/* Get system tick timer current value (counts at get_main_clock() !) */
-uint32_t systick_get_timer_val(void);
-
-/* Check if systick is running (return 1) or not (return 0) */
-uint32_t is_systick_running(void);
-
-/* Get the system tick period in ms
- * A vaue of 0 means the system tick timer has not been configured.
- * Note : calls to msleep() or usleep() will configure the system tick timer
- * with a value of 1ms if it was not configured yet.
- */
-uint32_t systick_get_tick_ms_period(void);
-
-/* Get the number of system ticks ... since last wrapping of the counter, which
- * is about 50 days with a 1ms system tick. */
-uint32_t systick_get_tick_count(void);
-
-/* Get the number of clock cycles ... since last wrapping of the counter. */
-uint32_t systick_get_clock_cycles(void);
-
-/* Power up the system tick timer.
- * ms is the interval between system tick timer interrupts. If set to 0, the default
- * value is used, which should provide a 1ms period.
- */
-void systick_timer_on(uint32_t ms);
-
-/* Removes the main clock from the selected timer block */
-void systick_timer_off(void);
-
-/* Register a callback to be called every 'period' system ticks.
- * returns the callback number if registration was OK.
- * returns negative value on error.
- * The callback will get the "global_wrapping_system_ticks" as argument, which wraps every 50 days
- * or so with a 1ms tick
- */
-#define MAX_SYSTICK_CALLBACKS 4
-int add_systick_callback(void (*callback) (uint32_t), uint16_t period);
-/* Remove a registered callback, given the callback address used to register it. */
-int remove_systick_callback(void (*callback) (uint32_t));
-
/***************************************************************************** */
-/* Sleeping functions : these use systick */
-
-/* Set the sleep countdown value
- * A sleep will end when this value reaches 0
- * Note that calls to this function while a sleep() has been initiated will change the
- * sleep duration ....
+/* Sleeping functions : these use systick if the systick code is kept. Otherwise
+ * it will use a decrementing while loop which is (badly) calibrated for a 24MHz
+ * main clock.
*/
-void set_sleep(uint32_t ticks);
-/* Return current sleep count_down counter */
-uint32_t get_sleep(void);
-
-/* Actual sleep function, checks that system tick counter is configured to generate
- * an interrupt to move sleep_count down to 0
- */
-uint32_t sleep(void);
-
void msleep(uint32_t ms);
void usleep(uint32_t us);
--- /dev/null
+/****************************************************************************
+ * core/systick.h
+ *
+ * System tick timer control
+ *
+ * Copyright 2012 Nathael Pajani <nathael.pajani@ed3l.fr>
+ *
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ *************************************************************************** */
+
+#ifndef CORE_SYSTICK_H
+#define CORE_SYSTICK_H
+
+#include <stdint.h>
+
+/***************************************************************************** */
+/* System Tick Timer */
+/***************************************************************************** */
+
+/* Start the system tick timer
+ * Starting the systick timer also resets the internal tick counters.
+ * If you need a value that goes beyond one start/stop cycle and accross resets,
+ * then it's up to you to keep track of this using systick_get_tick_count() and/or
+ * systick_get_clock_cycles().
+ */
+void systick_start(void);
+
+/* Stop the system tick timer */
+void systick_stop(void);
+
+/* Reset the system tick timer, making it count down from the reload value again
+ * Reseting the systick timer also resets the internal tick counters.
+ * If you need a value that goes beyond one start/stop cycle and accross resets,
+ * then it's up to you to keep track of this using systick_get_tick_count() and/or
+ * systick_get_clock_cycles().
+ */
+void systick_reset(void);
+
+/* Get system tick timer current value (counts at get_main_clock() !)
+ * systick_get_timer_val returns a value between 0 and systick_get_timer_reload_val()
+ */
+uint32_t systick_get_timer_val(void);
+
+/* Get system tick timer reload value */
+uint32_t systick_get_timer_reload_val(void);
+
+/* Check if systick is running (return 1) or not (return 0) */
+uint32_t is_systick_running(void);
+
+/* Get the system tick period in ms
+ * A vaue of 0 means the system tick timer has not been configured.
+ * Note : calls to msleep() or usleep() will configure the system tick timer
+ * with a value of 1ms if it was not configured yet.
+ */
+uint32_t systick_get_tick_ms_period(void);
+
+/* Get the number of system ticks ... since last wrapping of the counter, which
+ * is about 50 days with a 1ms system tick. */
+uint32_t systick_get_tick_count(void);
+
+/* Get the number of clock cycles ... since last wrapping of the counter. */
+uint32_t systick_get_clock_cycles(void);
+
+/* Power up the system tick timer.
+ * ms is the interval between system tick timer interrupts. If set to 0, the default
+ * value is used, which should provide a 1ms period.
+ */
+void systick_timer_on(uint32_t ms);
+
+/* Removes the main clock from the selected timer block */
+void systick_timer_off(void);
+
+/* Register a callback to be called every 'period' system ticks.
+ * returns the callback number if registration was OK.
+ * returns negative value on error.
+ * The callback will get the "global_wrapping_system_ticks" as argument, which wraps every 50 days
+ * or so with a 1ms tick
+ */
+#define MAX_SYSTICK_CALLBACKS 4
+int add_systick_callback(void (*callback) (uint32_t), uint16_t period);
+/* Remove a registered callback, given the callback address used to register it. */
+int remove_systick_callback(void (*callback) (uint32_t));
+
+
+#endif /* CORE_SYSTEM_H */
#include <stdint.h>
#include "core/lpc_core_cm0.h"
#include "core/system.h"
+#include "core/systick.h"
#include "lib/time.h"
#include "lib/string.h"