Paparazzi UAS v7.0_unstable
Paparazzi is a free software Unmanned Aircraft System.
Loading...
Searching...
No Matches
sys_time_arch.c
Go to the documentation of this file.
1/*
2 * Copyright (C) 2013 AggieAir, A Remote Sensing Unmanned Aerial System for Scientific Applications
3 * Utah State University, http://aggieair.usu.edu/
4 *
5 * Michal Podhradsky (michal.podhradsky@aggiemail.usu.edu)
6 * Calvin Coopmans (c.r.coopmans@ieee.org)
7 *
8 * Copyright (C) 2015 Gautier Hattenberger <gautier.hattenberger@enac.fr>
9 *
10 * This file is part of paparazzi.
11 *
12 * paparazzi is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2, or (at your option)
15 * any later version.
16 *
17 * paparazzi is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with paparazzi; see the file COPYING. If not, write to
24 * the Free Software Foundation, 59 Temple Place - Suite 330,
25 * Boston, MA 02111-1307, USA.
26 */
27
35#include "mcu_periph/sys_time_arch.h"
36#include BOARD_CONFIG
37#include <ch.h>
38#include "led.h"
39
41
42/*
43 * Sys_tick handler thread
44 */
45static void thd_sys_tick(void *arg);
47static void sys_tick_handler(void);
48
51
53{
54
56
57 /* cpu ticks per desired sys_time timer step */
59
60 // Create thread (PRIO should be higher than AP threads
63
64}
65
81
97
108
117{
118 if (us < 1000) {
119 // for small time, use the polled version instead of thread sleep
120 chSysDisable();
122 chSysEnable();
123 } else {
125 }
126}
127
132
137
138
139/*
140 * Sys_tick thread
141 */
142static __attribute__((noreturn)) void thd_sys_tick(void *arg)
143{
144 (void) arg;
145 chRegSetThreadName("sys_tick_handler");
146
147 while (TRUE) {
151 }
152}
153
154static void sys_tick_handler(void)
155{
157 /* current time in sys_ticks */
159 /* max time is 2^32 / CH_CFG_ST_FREQUENCY, i.e. around 10 days at 10kHz */
161 /* store high resolution counter for accurate timing */
163 /* increment secondes and remainder */
165#ifdef SYS_TIME_LED
166 if (sec > sys_time.nb_sec) {
168 }
169#endif
170 sys_time.nb_sec = sec;
172
173 /* advance virtual timers */
174 for (unsigned int i = 0; i < SYS_TIME_NB_TIMER; i++) {
175 if (sys_time.timer[i].in_use &&
179 /* call registered callbacks, WARNING: they will be executed in the sys_time thread! */
180 if (sys_time.timer[i].cb) {
181 sys_time.timer[i].cb(i);
182 }
183 }
184 }
186}
187
#define LED_TOGGLE(i)
Definition led_hw.h:53
void sys_time_msleep(uint16_t ms)
static uint32_t cpu_ticks
static void sys_tick_handler(void)
static void thd_sys_tick(void *arg)
void sys_time_usleep(uint32_t us)
sys_time_usleep(uint32_t us)
static uint32_t cpu_counter
uint32_t get_sys_time_usec100(void)
Get the time in microseconds divided by 100 since startup.
uint32_t get_sys_time_usec(void)
Get the time in microseconds since startup.
static THD_WORKING_AREA(wa_thd_sys_tick, 1024)
void sys_time_arch_init(void)
uint32_t get_sys_time_msec(void)
Get the time in milliseconds since startup.
void sys_time_ssleep(uint8_t s)
static MUTEX_DECL(sys_time_mtx)
#define STM32_SYSCLK
#define CH_CFG_ST_FREQUENCY
System tick frequency.
Definition chconf.h:75
arch independent LED (Light Emitting Diodes) API
static uint32_t s
uint16_t foo
Definition main_demo5.c:58
#define TRUE
Definition std.h:4
volatile uint32_t nb_tick
SYS_TIME_TICKS since startup.
Definition sys_time.h:74
#define USEC_OF_SEC(sec)
Definition sys_time.h:219
#define SYS_TIME_FREQUENCY
(Default) sys_time timer frequency in Hz.
Definition sys_time.h:56
volatile uint32_t nb_sec
full seconds since startup
Definition sys_time.h:72
uint32_t cpu_ticks_per_sec
cpu ticks per second
Definition sys_time.h:80
uint32_t duration
in SYS_TIME_TICKS
Definition sys_time.h:68
uint32_t resolution_cpu_ticks
sys_time_timer resolution in cpu ticks
Definition sys_time.h:79
volatile uint32_t nb_sec_rem
remainder of seconds since startup in CPU_TICKS
Definition sys_time.h:73
float resolution
sys_time_timer resolution in seconds
Definition sys_time.h:77
sys_time_cb cb
Definition sys_time.h:65
#define SYS_TIME_NB_TIMER
Definition sys_time.h:44
uint32_t end_time
in SYS_TIME_TICKS
Definition sys_time.h:67
static uint32_t cpu_ticks_of_sec(float seconds)
Definition sys_time.h:182
struct sys_time_timer timer[SYS_TIME_NB_TIMER]
Definition sys_time.h:75
volatile bool elapsed
Definition sys_time.h:66
unsigned short uint16_t
Typedef defining 16 bit unsigned short type.
unsigned int uint32_t
Typedef defining 32 bit unsigned int type.
unsigned char uint8_t
Typedef defining 8 bit unsigned char type.