From: Nathael Pajani Date: Sun, 6 Sep 2015 19:36:29 +0000 (+0200) Subject: Split system.h, moving systick related parts to systick.h Add a function to systick... X-Git-Url: http://git.techno-innov.fr/?a=commitdiff_plain;h=0a12a84b0aea8f8dafcec13587b84ba24eb6d71d;p=soft%2Flpc122x%2Fcore Split system.h, moving systick related parts to systick.h Add a function to systick driver to get the current reload value for systick timer. Stop exporting internal sleep implementation functions. --- diff --git a/core/systick.c b/core/systick.c index 6e289bc..35adfb6 100644 --- a/core/systick.c +++ b/core/systick.c @@ -28,6 +28,7 @@ #include "core/lpc_regs_12xx.h" #include "core/lpc_core_cm0.h" #include "core/system.h" +#include "core/systick.h" /* Static variables */ @@ -145,12 +146,19 @@ void systick_reset(void) 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) @@ -253,21 +261,16 @@ void systick_timer_off(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) { diff --git a/drivers/rtc.c b/drivers/rtc.c index 14ffeef..80a134e 100644 --- a/drivers/rtc.c +++ b/drivers/rtc.c @@ -28,6 +28,7 @@ #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" diff --git a/extdrv/epaper.c b/extdrv/epaper.c index da1d0e6..9d18528 100644 --- a/extdrv/epaper.c +++ b/extdrv/epaper.c @@ -30,6 +30,7 @@ #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" diff --git a/include/core/system.h b/include/core/system.h index b4340aa..ef17e77 100644 --- a/include/core/system.h +++ b/include/core/system.h @@ -113,87 +113,11 @@ void clkout_on(uint32_t src, uint32_t div); 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); diff --git a/include/core/systick.h b/include/core/systick.h new file mode 100644 index 0000000..f36f05a --- /dev/null +++ b/include/core/systick.h @@ -0,0 +1,98 @@ +/**************************************************************************** + * core/systick.h + * + * System tick timer control + * + * Copyright 2012 Nathael Pajani + * + * + * 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 . + * + *************************************************************************** */ + +#ifndef CORE_SYSTICK_H +#define CORE_SYSTICK_H + +#include + +/***************************************************************************** */ +/* 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 */ diff --git a/lib/time.c b/lib/time.c index 8f428b1..053f8b5 100644 --- a/lib/time.c +++ b/lib/time.c @@ -23,6 +23,7 @@ #include #include "core/lpc_core_cm0.h" #include "core/system.h" +#include "core/systick.h" #include "lib/time.h" #include "lib/string.h"