Paparazzi UAS v7.1_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
41#if HAL_USE_RTC
42#include <hal_rtc.h>
43#include <time.h>
44#endif
45
47
48/*
49 * Sys_tick handler thread
50 */
51static void thd_sys_tick(void *arg);
53
54void sys_tick_handler(void);
55
58
60{
61
63
64 /* cpu ticks per desired sys_time timer step */
66
67 // Create thread (PRIO should be higher than AP threads
70
71}
72
88
104
115
124{
125 if (us < 1000) {
126 // for small time, use the polled version instead of thread sleep
127 chSysDisable();
129 chSysEnable();
130 } else {
132 }
133}
134
139
140/*
141 * Sys_tick thread
142 */
143static __attribute__((noreturn)) void thd_sys_tick(void *arg)
144{
145 (void) arg;
146 chRegSetThreadName("sys_tick_handler");
147
148 while (TRUE) {
152 }
153}
154
156{
158 /* current time in sys_ticks */
160 /* max time is 2^32 / CH_CFG_ST_FREQUENCY, i.e. around 10 days at 10kHz */
162 /* store high resolution counter for accurate timing */
164 /* increment secondes and remainder */
166#ifdef SYS_TIME_LED
167 if (sec > sys_time.nb_sec) {
169 }
170#endif
171 sys_time.nb_sec = sec;
173
174 /* advance virtual timers */
175 for (unsigned int i = 0; i < SYS_TIME_NB_TIMER; i++) {
176 if (sys_time.timer[i].in_use &&
180 /* call registered callbacks, WARNING: they will be executed in the sys_time thread! */
181 if (sys_time.timer[i].cb) {
182 sys_time.timer[i].cb(i);
183 }
184 }
185 }
187}
188
189
191#if HAL_USE_RTC
194 return timespec.millisecond;
195#else
196 return 0;
197#endif
198}
#define LED_TOGGLE(i)
Definition led_hw.h:53
void sys_time_msleep(uint32_t ms)
Sleep.
static uint32_t cpu_ticks
uint32_t sys_time_rtc_millisecond()
Get the RTC time in milliseconds since midnight.
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:255
#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:218
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.