From abee34e551d59a0070c66c7d21ee8e8ad8eb904c Mon Sep 17 00:00:00 2001 From: James Cotton Date: Thu, 21 Jul 2011 12:50:15 -0500 Subject: [PATCH] Getting posix simulation compatible with init and receiver changes --- flight/OpenPilot/Makefile.posix | 2 + .../OpenPilot/System/inc/pios_config_posix.h | 3 + flight/OpenPilot/System/pios_board_posix.c | 11 ++ flight/PiOS.posix/inc/pios_initcall.h | 12 ++- flight/PiOS.posix/inc/pios_rcvr.h | 54 ++++++++++ flight/PiOS.posix/inc/pios_rcvr_priv.h | 48 +++++++++ flight/PiOS.posix/pios.h | 1 + flight/PiOS.posix/posix/pios_rcvr.c | 100 ++++++++++++++++++ 8 files changed, 230 insertions(+), 1 deletion(-) create mode 100644 flight/PiOS.posix/inc/pios_rcvr.h create mode 100644 flight/PiOS.posix/inc/pios_rcvr_priv.h create mode 100644 flight/PiOS.posix/posix/pios_rcvr.c diff --git a/flight/OpenPilot/Makefile.posix b/flight/OpenPilot/Makefile.posix index e349f368f..f93e93644 100644 --- a/flight/OpenPilot/Makefile.posix +++ b/flight/OpenPilot/Makefile.posix @@ -173,6 +173,8 @@ SRC += $(PIOSPOSIX)/pios_servo.c SRC += $(PIOSPOSIX)/pios_wdg.c SRC += $(PIOSPOSIX)/pios_debug.c +SRC += $(PIOSPOSIX)/pios_rcvr.c + ## Libraries for flight calculations #SRC += $(FLIGHTLIB)/fifo_buffer.c SRC += $(FLIGHTLIB)/WorldMagModel.c diff --git a/flight/OpenPilot/System/inc/pios_config_posix.h b/flight/OpenPilot/System/inc/pios_config_posix.h index 136e264c3..99505c55d 100644 --- a/flight/OpenPilot/System/inc/pios_config_posix.h +++ b/flight/OpenPilot/System/inc/pios_config_posix.h @@ -38,7 +38,10 @@ #define PIOS_INCLUDE_COM #define PIOS_INCLUDE_UDP #define PIOS_INCLUDE_SERVO +#define PIOS_INCLUDE_RCVR +#define PIOS_RCVR_MAX_CHANNELS 12 +#define PIOS_RCVR_MAX_DEVS 3 /* Defaults for Logging */ #define LOG_FILENAME "PIOS.LOG" diff --git a/flight/OpenPilot/System/pios_board_posix.c b/flight/OpenPilot/System/pios_board_posix.c index 87d8e7402..07cb6868d 100644 --- a/flight/OpenPilot/System/pios_board_posix.c +++ b/flight/OpenPilot/System/pios_board_posix.c @@ -29,6 +29,17 @@ #include #include +#include "pios_rcvr_priv.h" + +struct pios_rcvr_channel_map pios_rcvr_channel_to_id_map[PIOS_RCVR_MAX_CHANNELS]; +uint32_t pios_rcvr_max_channel; + +void Stack_Change() { +} + +void Stack_Change_Weak() { +} + /** * PIOS_Board_Init() * initializes all the core systems on this specific hardware diff --git a/flight/PiOS.posix/inc/pios_initcall.h b/flight/PiOS.posix/inc/pios_initcall.h index 32b3f7475..deb6e0eb6 100644 --- a/flight/PiOS.posix/inc/pios_initcall.h +++ b/flight/PiOS.posix/inc/pios_initcall.h @@ -38,11 +38,21 @@ * and we cannot define a linker script for each of them atm */ + +typedef int32_t (*initcall_t)(void); +typedef struct { + initcall_t fn_minit; + initcall_t fn_tinit; +} initmodule_t; + +/* Init module section */ +extern initmodule_t __module_initcall_start[], __module_initcall_end[]; + extern void InitModules(); extern void StartModules(); #define UAVOBJ_INITCALL(fn) -#define MODULE_INITCALL(ifn, iparam, sfn, sparam, flags) +#define MODULE_INITCALL(ifn, sfn) #define MODULE_TASKCREATE_ALL { \ /* Start all module threads */ \ diff --git a/flight/PiOS.posix/inc/pios_rcvr.h b/flight/PiOS.posix/inc/pios_rcvr.h new file mode 100644 index 000000000..a32160894 --- /dev/null +++ b/flight/PiOS.posix/inc/pios_rcvr.h @@ -0,0 +1,54 @@ +/** + ****************************************************************************** + * @addtogroup PIOS PIOS Core hardware abstraction layer + * @{ + * @addtogroup PIOS_RCVR RCVR layer functions + * @brief Hardware communication layer + * @{ + * + * @file pios_rcvr.h + * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. + * @brief RCVR layer functions header + * @see The GNU Public License (GPL) Version 3 + * + *****************************************************************************/ +/* + * 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 3 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, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef PIOS_RCVR_H +#define PIOS_RCVR_H + +struct pios_rcvr_channel_map { + uint32_t id; + uint8_t channel; +}; + +extern struct pios_rcvr_channel_map pios_rcvr_channel_to_id_map[]; + +struct pios_rcvr_driver { + void (*init)(uint32_t id); + int32_t (*read)(uint32_t id, uint8_t channel); +}; + +/* Public Functions */ +extern int32_t PIOS_RCVR_Read(uint32_t rcvr_id, uint8_t channel); + +#endif /* PIOS_RCVR_H */ + +/** + * @} + * @} + */ diff --git a/flight/PiOS.posix/inc/pios_rcvr_priv.h b/flight/PiOS.posix/inc/pios_rcvr_priv.h new file mode 100644 index 000000000..968dc2116 --- /dev/null +++ b/flight/PiOS.posix/inc/pios_rcvr_priv.h @@ -0,0 +1,48 @@ +/** + ****************************************************************************** + * @addtogroup PIOS PIOS Core hardware abstraction layer + * @{ + * @addtogroup PIOS_RCVR RCVR Functions + * @brief PIOS interface for RCVR drivers + * @{ + * + * @file pios_rcvr_priv.h + * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. + * Parts by Thorsten Klose (tk@midibox.org) + * @brief USART private definitions. + * @see The GNU Public License (GPL) Version 3 + * + *****************************************************************************/ +/* + * 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 3 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, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef PIOS_RCVR_PRIV_H +#define PIOS_RCVR_PRIV_H + +#include + +extern uint32_t pios_rcvr_max_channel; + +extern int32_t PIOS_RCVR_Init(uint32_t * rcvr_id, const struct pios_rcvr_driver * driver, const uint32_t lower_id); + +extern void PIOS_RCVR_IRQ_Handler(uint32_t rcvr_id); + +#endif /* PIOS_RCVR_PRIV_H */ + +/** + * @} + * @} + */ diff --git a/flight/PiOS.posix/pios.h b/flight/PiOS.posix/pios.h index a82d13b81..12c26c64d 100644 --- a/flight/PiOS.posix/pios.h +++ b/flight/PiOS.posix/pios.h @@ -65,6 +65,7 @@ #include #include #include +#include #define NELEMENTS(x) (sizeof(x) / sizeof(*(x))) diff --git a/flight/PiOS.posix/posix/pios_rcvr.c b/flight/PiOS.posix/posix/pios_rcvr.c new file mode 100644 index 000000000..652730547 --- /dev/null +++ b/flight/PiOS.posix/posix/pios_rcvr.c @@ -0,0 +1,100 @@ +/* Project Includes */ +#include "pios.h" + +#if defined(PIOS_INCLUDE_RCVR) + +#include + +enum pios_rcvr_dev_magic { + PIOS_RCVR_DEV_MAGIC = 0x99aabbcc, +}; + +struct pios_rcvr_dev { + enum pios_rcvr_dev_magic magic; + uint32_t lower_id; + const struct pios_rcvr_driver * driver; +}; + +static bool PIOS_RCVR_validate(struct pios_rcvr_dev * rcvr_dev) +{ + return (rcvr_dev->magic == PIOS_RCVR_DEV_MAGIC); +} + +#if defined(PIOS_INCLUDE_FREERTOS) && 0 +static struct pios_rcvr_dev * PIOS_RCVR_alloc(void) +{ + struct pios_rcvr_dev * rcvr_dev; + + rcvr_dev = (struct pios_rcvr_dev *)malloc(sizeof(*rcvr_dev)); + if (!rcvr_dev) return (NULL); + + rcvr_dev->magic = PIOS_RCVR_DEV_MAGIC; + return(rcvr_dev); +} +#else +static struct pios_rcvr_dev pios_rcvr_devs[PIOS_RCVR_MAX_DEVS]; +static uint8_t pios_rcvr_num_devs; +static struct pios_rcvr_dev * PIOS_RCVR_alloc(void) +{ + struct pios_rcvr_dev * rcvr_dev; + + if (pios_rcvr_num_devs >= PIOS_RCVR_MAX_DEVS) { + return (NULL); + } + + rcvr_dev = &pios_rcvr_devs[pios_rcvr_num_devs++]; + rcvr_dev->magic = PIOS_RCVR_DEV_MAGIC; + + return (rcvr_dev); +} +#endif + +/** + * Initialises RCVR layer + * \param[out] handle + * \param[in] driver + * \param[in] id + * \return < 0 if initialisation failed + */ +int32_t PIOS_RCVR_Init(uint32_t * rcvr_id, const struct pios_rcvr_driver * driver, const uint32_t lower_id) +{ + PIOS_DEBUG_Assert(rcvr_id); + PIOS_DEBUG_Assert(driver); + + struct pios_rcvr_dev * rcvr_dev; + + rcvr_dev = (struct pios_rcvr_dev *) PIOS_RCVR_alloc(); + if (!rcvr_dev) goto out_fail; + + rcvr_dev->driver = driver; + rcvr_dev->lower_id = lower_id; + + + *rcvr_id = pios_rcvr_num_devs - 1; + + return(0); + +out_fail: + return(-1); +} + +int32_t PIOS_RCVR_Read(uint32_t rcvr_id, uint8_t channel) +{ + struct pios_rcvr_dev * rcvr_dev = &pios_rcvr_devs[rcvr_id]; + + if (!PIOS_RCVR_validate(rcvr_dev)) { + /* Undefined RCVR port for this board (see pios_board.c) */ + PIOS_DEBUG_Assert(0); + } + + PIOS_DEBUG_Assert(rcvr_dev->driver->read); + + return rcvr_dev->driver->read(rcvr_dev->lower_id, channel); +} + +#endif + +/** + * @} + * @} + */