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.h"
37#include BOARD_CONFIG
38#include <ch.h>
39#include "led.h"
40
42
43/*
44 * Sys_tick handler thread
45 */
46static void thd_sys_tick(void *arg);
48
49void sys_tick_handler(void);
50
53
55{
56
58
59 /* cpu ticks per desired sys_time timer step */
61
62 // Create thread (PRIO should be higher than AP threads
65
66}
67
83
99
110
119{
120 if (us < 1000) {
121 // for small time, use the polled version instead of thread sleep
122 chSysDisable();
124 chSysEnable();
125 } else {
127 }
128}
129
134
135/*
136 * Sys_tick thread
137 */
138static __attribute__((noreturn)) void thd_sys_tick(void *arg)
139{
140 (void) arg;
141 chRegSetThreadName("sys_tick_handler");
142
143 while (TRUE) {
147 }
148}
149
151{
153 /* current time in sys_ticks */
155 /* max time is 2^32 / CH_CFG_ST_FREQUENCY, i.e. around 10 days at 10kHz */
157 /* store high resolution counter for accurate timing */
159 /* increment secondes and remainder */
161#ifdef SYS_TIME_LED
162 if (sec > sys_time.nb_sec) {
164 }
165#endif
166 sys_time.nb_sec = sec;
168
169 /* advance virtual timers */
170 for (unsigned int i = 0; i < SYS_TIME_NB_TIMER; i++) {
171 if (sys_time.timer[i].in_use &&
175 /* call registered callbacks, WARNING: they will be executed in the sys_time thread! */
176 if (sys_time.timer[i].cb) {
177 sys_time.timer[i].cb(i);
178 }
179 }
180 }
182}
183
#define LED_TOGGLE(i)
Definition led_hw.h:53
void sys_time_msleep(uint32_t ms)
Sleep.
static uint32_t cpu_ticks
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.
static MUTEX_DECL(sys_time_mtx)
void sys_tick_handler(void)
#define CH_CFG_ST_FREQUENCY
System tick frequency.
Definition chconf.h:75
arch independent LED (Light Emitting Diodes) API
uint16_t foo
Definition main_demo5.c:58
#define TRUE
Definition std.h:4
Architecture independent timing functions.
volatile uint32_t nb_tick
SYS_TIME_TICKS since startup.
Definition sys_time.h:74
#define USEC_OF_SEC(sec)
Definition sys_time.h:249
#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:212
struct sys_time_timer timer[SYS_TIME_NB_TIMER]
Definition sys_time.h:75
volatile bool elapsed
Definition sys_time.h:66
Implementation of system time functions for ChibiOS arch.
unsigned int uint32_t
Typedef defining 32 bit unsigned int type.