mirror of
https://github.com/paparazzi/paparazzi.git
synced 2026-06-04 22:17:01 +08:00
fix jsbsim simulation with new sys_time stuff
This commit is contained in:
@@ -56,8 +56,9 @@ $(TARGET).CFLAGS += -DTRAFFIC_INFO
|
|||||||
#
|
#
|
||||||
# LEDs
|
# LEDs
|
||||||
#
|
#
|
||||||
|
ifneq ($(ARCH), jsbsim)
|
||||||
$(TARGET).CFLAGS += -DUSE_LED
|
$(TARGET).CFLAGS += -DUSE_LED
|
||||||
|
endif
|
||||||
ifneq ($(ARCH), lpc21)
|
ifneq ($(ARCH), lpc21)
|
||||||
ifneq ($(ARCH), jsbsim)
|
ifneq ($(ARCH), jsbsim)
|
||||||
$(TARGET).srcs += $(SRC_ARCH)/led_hw.c
|
$(TARGET).srcs += $(SRC_ARCH)/led_hw.c
|
||||||
@@ -72,6 +73,7 @@ PERIODIC_FREQUENCY = 60
|
|||||||
endif
|
endif
|
||||||
$(TARGET).CFLAGS += -DPERIODIC_FREQUENCY=$(PERIODIC_FREQUENCY)
|
$(TARGET).CFLAGS += -DPERIODIC_FREQUENCY=$(PERIODIC_FREQUENCY)
|
||||||
$(TARGET).srcs += mcu_periph/sys_time.c $(SRC_ARCH)/mcu_periph/sys_time_arch.c
|
$(TARGET).srcs += mcu_periph/sys_time.c $(SRC_ARCH)/mcu_periph/sys_time_arch.c
|
||||||
|
$(TARGET).CFLAGS += -DUSE_SYS_TIME -DSYS_TIME_RESOLUTION='(1./$(PERIODIC_FREQUENCY).)'
|
||||||
|
|
||||||
#
|
#
|
||||||
# InterMCU & Commands
|
# InterMCU & Commands
|
||||||
@@ -123,11 +125,6 @@ ifneq ($(SYS_TIME_LED),none)
|
|||||||
ns_CFLAGS += -DSYS_TIME_LED=$(SYS_TIME_LED)
|
ns_CFLAGS += -DSYS_TIME_LED=$(SYS_TIME_LED)
|
||||||
endif
|
endif
|
||||||
|
|
||||||
#
|
|
||||||
# Sys-time
|
|
||||||
#
|
|
||||||
ns_CFLAGS += -DUSE_SYS_TIME -DSYS_TIME_RESOLUTION='(1./$(PERIODIC_FREQUENCY).)'
|
|
||||||
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# UARTS
|
# UARTS
|
||||||
|
|||||||
@@ -26,3 +26,21 @@
|
|||||||
void sys_time_arch_init( void ) {
|
void sys_time_arch_init( void ) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void sys_tick_handler( void ) {
|
||||||
|
|
||||||
|
sys_time.nb_tick++;
|
||||||
|
sys_time.nb_sec_rem += SYS_TIME_RESOLUTION_CPU_TICKS;
|
||||||
|
if (sys_time.nb_sec_rem >= CPU_TICKS_PER_SEC) {
|
||||||
|
sys_time.nb_sec_rem -= CPU_TICKS_PER_SEC;
|
||||||
|
sys_time.nb_sec++;
|
||||||
|
}
|
||||||
|
for (unsigned int i=0; i<SYS_TIME_NB_TIMER; i++) {
|
||||||
|
if (sys_time.timer[i].in_use &&
|
||||||
|
sys_time.nb_tick >= sys_time.timer[i].end_time) {
|
||||||
|
sys_time.timer[i].end_time += sys_time.timer[i].duration;
|
||||||
|
sys_time.timer[i].elapsed = TRUE;
|
||||||
|
if (sys_time.timer[i].cb) sys_time.timer[i].cb(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -21,22 +21,24 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/** @file arch/sim/mcu_periph/sys_time_arch.h
|
||||||
*\brief simulator dummy timing functions
|
* Simulator timing functions
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef SYS_TIME_ARCH_H
|
#ifndef SYS_TIME_ARCH_H
|
||||||
#define SYS_TIME_ARCH_H
|
#define SYS_TIME_ARCH_H
|
||||||
|
|
||||||
#include <unistd.h>
|
#include "std.h"
|
||||||
|
|
||||||
#define CPU_TICKS_OF_SEC(x) (x)
|
extern void sys_tick_handler(void);
|
||||||
#define SIGNED_CPU_TICKS_OF_SEC(x) (x)
|
|
||||||
|
|
||||||
#define SEC_OF_CPU_TICKS(st) (st)
|
// simulate 1us cpu ticks
|
||||||
#define MSEC_OF_CPU_TICKS(st) (st)
|
#define CPU_TICKS_OF_SEC(s) (uint32_t)((s) * 1e6 + 0.5)
|
||||||
#define USEC_OF_CPU_TICKS(st) (st)
|
#define SIGNED_CPU_TICKS_OF_SEC(s) (int32_t)((s) * 1e6 + 0.5)
|
||||||
|
|
||||||
|
#define SEC_OF_CPU_TICKS(t) ((t) / 1e6)
|
||||||
|
#define MSEC_OF_CPU_TICKS(t) ((t) / 1e3)
|
||||||
|
#define USEC_OF_CPU_TICKS(t) (t)
|
||||||
|
|
||||||
#define SysTimeTimerStart(_t) { }
|
#define SysTimeTimerStart(_t) { }
|
||||||
#define SysTimeTimer(_t) (_t)
|
#define SysTimeTimer(_t) (_t)
|
||||||
|
|||||||
@@ -78,8 +78,8 @@ void autopilot_init(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void autopilot_periodic_task(void) {
|
void autopilot_periodic_task(void) {
|
||||||
periodic_task_ap();
|
handle_periodic_tasks_ap();
|
||||||
periodic_task_fbw();
|
handle_periodic_tasks_fbw();
|
||||||
}
|
}
|
||||||
|
|
||||||
void autopilot_event_task(void) {
|
void autopilot_event_task(void) {
|
||||||
|
|||||||
@@ -80,6 +80,9 @@ static void sim_init(void) {
|
|||||||
// main AP init (feed the sensors once before ?)
|
// main AP init (feed the sensors once before ?)
|
||||||
autopilot_init();
|
autopilot_init();
|
||||||
|
|
||||||
|
printf("sys_time resolution: %f\n", SYS_TIME_RESOLUTION);
|
||||||
|
printf("sys_time period in msec: %d\n", SYSTIME_PERIOD);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean sim_periodic(gpointer data __attribute__ ((unused))) {
|
static gboolean sim_periodic(gpointer data __attribute__ ((unused))) {
|
||||||
@@ -116,6 +119,11 @@ static gboolean sim_periodic(gpointer data __attribute__ ((unused))) {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static gboolean systime_periodic(gpointer data __attribute__ ((unused))) {
|
||||||
|
sys_tick_handler();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
int main ( int argc, char** argv) {
|
int main ( int argc, char** argv) {
|
||||||
|
|
||||||
@@ -129,6 +137,7 @@ int main ( int argc, char** argv) {
|
|||||||
GMainLoop *ml = g_main_loop_new(NULL, FALSE);
|
GMainLoop *ml = g_main_loop_new(NULL, FALSE);
|
||||||
|
|
||||||
g_timeout_add(JSBSIM_PERIOD, sim_periodic, NULL);
|
g_timeout_add(JSBSIM_PERIOD, sim_periodic, NULL);
|
||||||
|
g_timeout_add(SYSTIME_PERIOD, systime_periodic, NULL);
|
||||||
|
|
||||||
g_main_loop_run(ml);
|
g_main_loop_run(ml);
|
||||||
|
|
||||||
|
|||||||
@@ -32,6 +32,7 @@
|
|||||||
#include "std.h"
|
#include "std.h"
|
||||||
#include "generated/airframe.h"
|
#include "generated/airframe.h"
|
||||||
#include "generated/flight_plan.h"
|
#include "generated/flight_plan.h"
|
||||||
|
#include "mcu_periph/sys_time.h"
|
||||||
|
|
||||||
#include <Ivy/ivy.h>
|
#include <Ivy/ivy.h>
|
||||||
|
|
||||||
@@ -43,6 +44,8 @@
|
|||||||
#endif
|
#endif
|
||||||
#define DT (JSBSIM_PERIOD*1e-3) ///< JSBSim timestep in seconds
|
#define DT (JSBSIM_PERIOD*1e-3) ///< JSBSim timestep in seconds
|
||||||
|
|
||||||
|
#define SYSTIME_PERIOD ((uint32_t)(SYS_TIME_RESOLUTION * 1000)) ///< in msec
|
||||||
|
|
||||||
#define RAD2DEG 57.29578
|
#define RAD2DEG 57.29578
|
||||||
#define FT2M 0.3048
|
#define FT2M 0.3048
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user