From 9484875fef196decba3283c5ad6bbb6a9bd20fc9 Mon Sep 17 00:00:00 2001 From: Giovanni Di Sirio Date: Sat, 30 Apr 2022 09:57:04 +0000 Subject: [PATCH] Preparation for SB Virtual IRQs. Removed some obsolete code from SBs. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@15618 27425a3e-05d8-49a3-a47f-9c15f0e5edd8 --- .../cfg/sbconf.h | 7 ++ .../cfg/sbconf.h | 7 ++ .../cfg/sbconf.h | 7 ++ .../cfg/sbconf.h | 7 ++ os/sb/host/compilers/GCC/sbhost.mk | 1 + os/sb/host/sb.h | 5 ++ os/sb/host/sbapi.c | 76 ++++++++++-------- os/sb/host/sbapi.h | 56 +------------ os/sb/host/sbvrq.c | 58 ++++++++++++++ os/sb/host/sbvrq.h | 78 +++++++++++++++++++ 10 files changed, 216 insertions(+), 86 deletions(-) create mode 100644 os/sb/host/sbvrq.c create mode 100644 os/sb/host/sbvrq.h diff --git a/demos/STM32/RT-STM32G474RE-NUCLEO64-SB_HOST_DYNAMIC/cfg/sbconf.h b/demos/STM32/RT-STM32G474RE-NUCLEO64-SB_HOST_DYNAMIC/cfg/sbconf.h index cfd1a98f5..89c1e8c10 100644 --- a/demos/STM32/RT-STM32G474RE-NUCLEO64-SB_HOST_DYNAMIC/cfg/sbconf.h +++ b/demos/STM32/RT-STM32G474RE-NUCLEO64-SB_HOST_DYNAMIC/cfg/sbconf.h @@ -38,6 +38,13 @@ #define SB_CFG_NUM_REGIONS 2 #endif +/** + * @brief Enables support for sandbox Virtual IRQs. + */ +#if !defined(SB_CFG_ENABLE_VRQ) || defined(__DOXYGEN__) +#define SB_CFG_ENABLE_VRQ TRUE +#endif + /** * @brief Enables Posix API in sandboxes using VFS. */ diff --git a/demos/STM32/RT-STM32G474RE-NUCLEO64-SB_HOST_STATIC/cfg/sbconf.h b/demos/STM32/RT-STM32G474RE-NUCLEO64-SB_HOST_STATIC/cfg/sbconf.h index cfd1a98f5..89c1e8c10 100644 --- a/demos/STM32/RT-STM32G474RE-NUCLEO64-SB_HOST_STATIC/cfg/sbconf.h +++ b/demos/STM32/RT-STM32G474RE-NUCLEO64-SB_HOST_STATIC/cfg/sbconf.h @@ -38,6 +38,13 @@ #define SB_CFG_NUM_REGIONS 2 #endif +/** + * @brief Enables support for sandbox Virtual IRQs. + */ +#if !defined(SB_CFG_ENABLE_VRQ) || defined(__DOXYGEN__) +#define SB_CFG_ENABLE_VRQ TRUE +#endif + /** * @brief Enables Posix API in sandboxes using VFS. */ diff --git a/demos/STM32/RT-STM32L4R9-DISCOVERY-RAM_SB_HOST_DYNAMIC/cfg/sbconf.h b/demos/STM32/RT-STM32L4R9-DISCOVERY-RAM_SB_HOST_DYNAMIC/cfg/sbconf.h index cfd1a98f5..89c1e8c10 100644 --- a/demos/STM32/RT-STM32L4R9-DISCOVERY-RAM_SB_HOST_DYNAMIC/cfg/sbconf.h +++ b/demos/STM32/RT-STM32L4R9-DISCOVERY-RAM_SB_HOST_DYNAMIC/cfg/sbconf.h @@ -38,6 +38,13 @@ #define SB_CFG_NUM_REGIONS 2 #endif +/** + * @brief Enables support for sandbox Virtual IRQs. + */ +#if !defined(SB_CFG_ENABLE_VRQ) || defined(__DOXYGEN__) +#define SB_CFG_ENABLE_VRQ TRUE +#endif + /** * @brief Enables Posix API in sandboxes using VFS. */ diff --git a/demos/STM32/RT-STM32L4R9-DISCOVERY-SB_HOST_STATIC/cfg/sbconf.h b/demos/STM32/RT-STM32L4R9-DISCOVERY-SB_HOST_STATIC/cfg/sbconf.h index cfd1a98f5..89c1e8c10 100644 --- a/demos/STM32/RT-STM32L4R9-DISCOVERY-SB_HOST_STATIC/cfg/sbconf.h +++ b/demos/STM32/RT-STM32L4R9-DISCOVERY-SB_HOST_STATIC/cfg/sbconf.h @@ -38,6 +38,13 @@ #define SB_CFG_NUM_REGIONS 2 #endif +/** + * @brief Enables support for sandbox Virtual IRQs. + */ +#if !defined(SB_CFG_ENABLE_VRQ) || defined(__DOXYGEN__) +#define SB_CFG_ENABLE_VRQ TRUE +#endif + /** * @brief Enables Posix API in sandboxes using VFS. */ diff --git a/os/sb/host/compilers/GCC/sbhost.mk b/os/sb/host/compilers/GCC/sbhost.mk index 221b98bde..052fb8997 100644 --- a/os/sb/host/compilers/GCC/sbhost.mk +++ b/os/sb/host/compilers/GCC/sbhost.mk @@ -1,6 +1,7 @@ # List of the ChibiOS ARMv7-M sandbox host files. SBHOSTSRC = $(CHIBIOS)/os/sb/host/sbhost.c \ $(CHIBIOS)/os/sb/host/sbapi.c \ + $(CHIBIOS)/os/sb/host/sbvrq.c \ $(CHIBIOS)/os/sb/host/sbelf.c \ $(CHIBIOS)/os/sb/host/sbposix.c diff --git a/os/sb/host/sb.h b/os/sb/host/sb.h index 7e5abd47b..67634b3cf 100644 --- a/os/sb/host/sb.h +++ b/os/sb/host/sb.h @@ -94,6 +94,10 @@ #error "SB_CFG_NUM_REGIONS not defined in sbconf.h" #endif +#if !defined(SB_CFG_ENABLE_VRQ) || defined(__DOXYGEN__) +#error "SB_CFG_ENABLE_VRQ not defined in sbconf.h" +#endif + #if !defined(SB_CFG_ENABLE_VFS) || defined(__DOXYGEN__) #error "SB_CFG_ENABLE_VFS not defined in sbconf.h" #endif @@ -281,6 +285,7 @@ extern "C" { /*===========================================================================*/ #include "sbsysc.h" +#include "sbvrq.h" #include "sbelf.h" #include "sbposix.h" #include "sbapi.h" diff --git a/os/sb/host/sbapi.c b/os/sb/host/sbapi.c index a8a73e308..899579af6 100644 --- a/os/sb/host/sbapi.c +++ b/os/sb/host/sbapi.c @@ -36,6 +36,20 @@ /* Module local definitions. */ /*===========================================================================*/ +static void sb_api_stdio(struct port_extctx *ectxp); +static void sb_api_exit(struct port_extctx *ctxp); +static void sb_api_get_systime(struct port_extctx *ctxp); +static void sb_api_get_frequency(struct port_extctx *ctxp); +static void sb_api_sleep(struct port_extctx *ctxp); +static void sb_api_sleep_until_windowed(struct port_extctx *ctxp); +static void sb_api_wait_message(struct port_extctx *ctxp); +static void sb_api_reply_message(struct port_extctx *ctxp); +static void sb_api_wait_one_timeout(struct port_extctx *ctxp); +static void sb_api_wait_any_timeout(struct port_extctx *ctxp); +static void sb_api_wait_all_timeout(struct port_extctx *ctxp); +static void sb_api_broadcast_flags(struct port_extctx *ctxp); +static void sb_api_loadelf(struct port_extctx *ectxp); + /** * @name Standard API handlers * @{ @@ -960,26 +974,8 @@ static void sb_cleanup(void) { #endif } -/*===========================================================================*/ -/* Module exported functions. */ -/*===========================================================================*/ - -void __sb_abort(msg_t msg) { - - chSysUnlock(); - - sb_cleanup(); - - chSysLock(); -#if CH_CFG_USE_EVENTS == TRUE - chEvtBroadcastI(&sb.termination_es); -#endif - chThdExitS(msg); - chSysHalt("zombies"); -} - #if (SB_CFG_ENABLE_VFS == TRUE) || defined(__DOXYGEN__) -void sb_api_stdio(struct port_extctx *ectxp) { +static void sb_api_stdio(struct port_extctx *ectxp) { switch (ectxp->r0) { case SB_POSIX_OPEN: @@ -1052,7 +1048,7 @@ void sb_api_stdio(struct port_extctx *ectxp) { } #endif /* SB_CFG_ENABLE_VFS == TRUE */ -void sb_api_exit(struct port_extctx *ectxp) { +static void sb_api_exit(struct port_extctx *ectxp) { sb_cleanup(); @@ -1067,17 +1063,17 @@ void sb_api_exit(struct port_extctx *ectxp) { ectxp->r0 = CH_RET_ENOSYS; } -void sb_api_get_systime(struct port_extctx *ectxp) { +static void sb_api_get_systime(struct port_extctx *ectxp) { ectxp->r0 = (uint32_t)chVTGetSystemTimeX(); } -void sb_api_get_frequency(struct port_extctx *ectxp) { +static void sb_api_get_frequency(struct port_extctx *ectxp) { ectxp->r0 = (uint32_t)CH_CFG_ST_FREQUENCY; } -void sb_api_sleep(struct port_extctx *ectxp) { +static void sb_api_sleep(struct port_extctx *ectxp) { sysinterval_t interval = (sysinterval_t )ectxp->r0; if (interval != TIME_IMMEDIATE) { @@ -1087,14 +1083,14 @@ void sb_api_sleep(struct port_extctx *ectxp) { ectxp->r0 = CH_RET_SUCCESS; } -void sb_api_sleep_until_windowed(struct port_extctx *ectxp) { +static void sb_api_sleep_until_windowed(struct port_extctx *ectxp) { chThdSleepUntilWindowed((systime_t )ectxp->r0, (systime_t )ectxp->r1); ectxp->r0 = CH_RET_SUCCESS; } -void sb_api_wait_message(struct port_extctx *ectxp) { +static void sb_api_wait_message(struct port_extctx *ectxp) { #if CH_CFG_USE_MESSAGES == TRUE sb_class_t *sbp = (sb_class_t *)chThdGetSelfX()->ctx.syscall.p; @@ -1117,7 +1113,7 @@ void sb_api_wait_message(struct port_extctx *ectxp) { #endif } -void sb_api_reply_message(struct port_extctx *ectxp) { +static void sb_api_reply_message(struct port_extctx *ectxp) { #if CH_CFG_USE_MESSAGES == TRUE sb_class_t *sbp = (sb_class_t *)chThdGetSelfX()->ctx.syscall.p; @@ -1139,7 +1135,7 @@ void sb_api_reply_message(struct port_extctx *ectxp) { #endif } -void sb_api_wait_one_timeout(struct port_extctx *ectxp) { +static void sb_api_wait_one_timeout(struct port_extctx *ectxp) { #if CH_CFG_USE_EVENTS == TRUE ectxp->r0 = (uint32_t)chEvtWaitOneTimeout((eventmask_t )ectxp->r0, @@ -1149,7 +1145,7 @@ void sb_api_wait_one_timeout(struct port_extctx *ectxp) { #endif } -void sb_api_wait_any_timeout(struct port_extctx *ectxp) { +static void sb_api_wait_any_timeout(struct port_extctx *ectxp) { #if CH_CFG_USE_EVENTS == TRUE ectxp->r0 = (uint32_t)chEvtWaitAnyTimeout((eventmask_t )ectxp->r0, @@ -1159,7 +1155,7 @@ void sb_api_wait_any_timeout(struct port_extctx *ectxp) { #endif } -void sb_api_wait_all_timeout(struct port_extctx *ectxp) { +static void sb_api_wait_all_timeout(struct port_extctx *ectxp) { #if CH_CFG_USE_EVENTS == TRUE ectxp->r0 = (uint32_t)chEvtWaitAllTimeout((eventmask_t )ectxp->r0, @@ -1169,7 +1165,7 @@ void sb_api_wait_all_timeout(struct port_extctx *ectxp) { #endif } -void sb_api_broadcast_flags(struct port_extctx *ectxp) { +static void sb_api_broadcast_flags(struct port_extctx *ectxp) { #if CH_CFG_USE_EVENTS == TRUE sb_class_t *sbp = (sb_class_t *)chThdGetSelfX()->ctx.syscall.p; @@ -1180,7 +1176,7 @@ void sb_api_broadcast_flags(struct port_extctx *ectxp) { #endif } -void sb_api_loadelf(struct port_extctx *ectxp) { +static void sb_api_loadelf(struct port_extctx *ectxp) { #if (SB_CFG_ENABLE_VFS == TRUE) || defined(__DOXYGEN__) sb_class_t *sbp = (sb_class_t *)chThdGetSelfX()->ctx.syscall.p; const char *fname = (const char *)ectxp->r0; @@ -1202,4 +1198,22 @@ void sb_api_loadelf(struct port_extctx *ectxp) { #endif } +/*===========================================================================*/ +/* Module exported functions. */ +/*===========================================================================*/ + +void __sb_abort(msg_t msg) { + + chSysUnlock(); + + sb_cleanup(); + + chSysLock(); +#if CH_CFG_USE_EVENTS == TRUE + chEvtBroadcastI(&sb.termination_es); +#endif + chThdExitS(msg); + chSysHalt("zombies"); +} + /** @} */ diff --git a/os/sb/host/sbapi.h b/os/sb/host/sbapi.h index 5ac6cfac0..0939208fb 100644 --- a/os/sb/host/sbapi.h +++ b/os/sb/host/sbapi.h @@ -49,48 +49,6 @@ */ typedef void (*port_syscall_t)(struct port_extctx *ectx); -/** - * @brief Sandbox Stream interface methods. - * @note Is intentionally compatible with HAL streams but we have to - * duplicate is because we don't want dependencies with HAL in - * this subsystem. - */ -struct SandboxStreamVMT { - /** - * @brief Object instance offset. - */ - size_t instance_offset; - /** - * @brief Stream write buffer method. - */ - size_t (*write)(void *instance, const uint8_t *bp, size_t n); - /** - * @brief Stream read buffer method. - */ - size_t (*read)(void *instance, uint8_t *bp, size_t n); - /** - * @brief Channel put method, blocking. - */ - msg_t (*put)(void *instance, uint8_t b); - /** - * @brief Channel get method, blocking. - */ - msg_t (*get)(void *instance); -}; - -/** - * @brief Sandbox Stream class. - * @note Is intentionally compatible with HAL streams but we have to - * duplicate is because we don't want dependencies with HAL in - * this subsystem. - */ -typedef struct { - /** - * @brief Virtual Methods Table. - */ - const struct SandboxStreamVMT *vmt; -} SandboxStream; - /*===========================================================================*/ /* Module macros. */ /*===========================================================================*/ @@ -102,19 +60,7 @@ typedef struct { #ifdef __cplusplus extern "C" { #endif - void sb_api_stdio(struct port_extctx *ectxp); - void sb_api_exit(struct port_extctx *ctxp); - void sb_api_get_systime(struct port_extctx *ctxp); - void sb_api_get_frequency(struct port_extctx *ctxp); - void sb_api_sleep(struct port_extctx *ctxp); - void sb_api_sleep_until_windowed(struct port_extctx *ctxp); - void sb_api_wait_message(struct port_extctx *ctxp); - void sb_api_reply_message(struct port_extctx *ctxp); - void sb_api_wait_one_timeout(struct port_extctx *ctxp); - void sb_api_wait_any_timeout(struct port_extctx *ctxp); - void sb_api_wait_all_timeout(struct port_extctx *ctxp); - void sb_api_broadcast_flags(struct port_extctx *ctxp); - void sb_api_loadelf(struct port_extctx *ectxp); + #ifdef __cplusplus } #endif diff --git a/os/sb/host/sbvrq.c b/os/sb/host/sbvrq.c new file mode 100644 index 000000000..ec1644a0c --- /dev/null +++ b/os/sb/host/sbvrq.c @@ -0,0 +1,58 @@ +/* + ChibiOS - Copyright (C) 2006,2007,2008,2009,2010,2011,2012,2013,2014, + 2015,2016,2017,2018,2019,2020,2021 Giovanni Di Sirio. + + This file is part of ChibiOS. + + ChibiOS 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 version 3 of the License. + + ChibiOS 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, see . +*/ + +/** + * @file sb/host/sbvrq.c + * @brief ARM SandBox host Virtual IRQs code. + * + * @addtogroup ARM_SANDBOX_VRQ + * @{ + */ + +#include "sb.h" + +#if (SB_CFG_ENABLE_VRQ == TRUE) || defined(__DOXYGEN__) + +/*===========================================================================*/ +/* Module local definitions. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Module exported variables. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Module local types. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Module local variables. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Module local functions. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Module exported functions. */ +/*===========================================================================*/ + +#endif /* SB_CFG_ENABLE_VRQ == TRUE */ + +/** @} */ diff --git a/os/sb/host/sbvrq.h b/os/sb/host/sbvrq.h new file mode 100644 index 000000000..83077a765 --- /dev/null +++ b/os/sb/host/sbvrq.h @@ -0,0 +1,78 @@ +/* + ChibiOS - Copyright (C) 2006,2007,2008,2009,2010,2011,2012,2013,2014, + 2015,2016,2017,2018,2019,2020,2021 Giovanni Di Sirio. + + This file is part of ChibiOS. + + ChibiOS 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 version 3 of the License. + + ChibiOS 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, see . +*/ + +/** + * @file sb/host/sbvrq.h + * @brief ARM SandBox host Virtual IRQs macros and structures. + * + * @addtogroup ARM_SANDBOX_HOSTAPI + * @{ + */ + +#ifndef SBVRQ_H +#define SBVRQ_H + +#if (SB_CFG_ENABLE_VRQ == TRUE) || defined(__DOXYGEN__) + +/*===========================================================================*/ +/* Module constants. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Module pre-compile time settings. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Derived constants and error checks. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Module data structures and types. */ +/*===========================================================================*/ + +/** + * @brief Type of a mask of Virtual IRQs. + */ +typedef uint32_t sb_vrqmask_t; + +/*===========================================================================*/ +/* Module macros. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* External declarations. */ +/*===========================================================================*/ + +#ifdef __cplusplus +extern "C" { +#endif + void sbVRQPendI(sb_class_t *sbp, sb_vrqmask_t vmask); +#ifdef __cplusplus +} +#endif + +/*===========================================================================*/ +/* Module inline functions. */ +/*===========================================================================*/ + +#endif /* SB_CFG_ENABLE_VRQ == TRUE */ + +#endif /* SBVRQ_H */ + +/** @} */