diff --git a/demos/STM32/RT-STM32G474RE-NUCLEO64-SB_HOST_STATIC/main.c b/demos/STM32/RT-STM32G474RE-NUCLEO64-SB_HOST_STATIC/main.c index d46e16b0f..69fdfd67f 100644 --- a/demos/STM32/RT-STM32G474RE-NUCLEO64-SB_HOST_STATIC/main.c +++ b/demos/STM32/RT-STM32G474RE-NUCLEO64-SB_HOST_STATIC/main.c @@ -26,6 +26,10 @@ #include "startup_defs.h" + +/* Sandbox objects.*/ +sb_class_t sbx1, sbx2; + /*===========================================================================*/ /* VHAL-related. */ /*===========================================================================*/ @@ -45,7 +49,11 @@ static vio_gpio_units_t gpio_units1 = { static vio_uart_units_t uart_units1 = { .n = 1U, .units = { - [0] = {&LPSIOD1} + [0] = { + .siop = &LPSIOD1, + .vrqsb = &sbx1, + .vrqn = 8 + } } }; @@ -162,9 +170,6 @@ static const char *sbx2_envp[] = { NULL }; -/* Sandbox objects.*/ -sb_class_t sbx1, sbx2; - static THD_WORKING_AREA(waUnprivileged1, 512); static THD_WORKING_AREA(waUnprivileged2, 512); diff --git a/os/hal/ports/sandbox/hal_sio_lld.c b/os/hal/ports/sandbox/hal_sio_lld.c index 6a24abf8a..da7ea15b7 100644 --- a/os/hal/ports/sandbox/hal_sio_lld.c +++ b/os/hal/ports/sandbox/hal_sio_lld.c @@ -432,10 +432,20 @@ msg_t sio_lld_control(SIODriver *siop, unsigned int operation, void *arg) { * @notapi */ void sio_lld_serve_interrupt(SIODriver *siop) { + sioevents_t events; - /* The callback is simply invoked. Letting the driver on the host side - decide how to manipulate IRQ sources.*/ - __sio_callback(siop); + __syscall2rr(201, SB_VUART_GCEVT, siop->nvuart); + osalDbgAssert((msg_t)r0 == HAL_RET_SUCCESS, "unexpected failure"); + + /* Only processing enabled events.*/ + events = (sioevents_t)r1; + + /* Processing events, if any.*/ + if (events != (sioevents_t)0) { + + /* The callback is finally invoked.*/ + __sio_callback(siop); + } } #endif /* HAL_USE_SIO == TRUE */ diff --git a/os/sb/host/sb.h b/os/sb/host/sb.h index 3f787f8f1..37ddabeaf 100644 --- a/os/sb/host/sb.h +++ b/os/sb/host/sb.h @@ -36,10 +36,6 @@ #include "sbsysc.h" #include "sbconf.h" -#if (SB_CFG_ENABLE_VIO == TRUE) || defined (__DOXYGEN__) -#include "sbvio.h" -#endif - /*===========================================================================*/ /* Module constants. */ /*===========================================================================*/ @@ -172,11 +168,25 @@ /* Module data structures and types. */ /*===========================================================================*/ + +/** + * @brief Type of a sandbox object. + */ +typedef struct sb_class sb_class_t; + /** * @brief Type of a mask of Virtual IRQs. */ typedef uint32_t sb_vrqmask_t; +#if (SB_CFG_ENABLE_VRQ == TRUE) || defined (__DOXYGEN__) +#include "sbvrq.h" +#endif + +#if (SB_CFG_ENABLE_VIO == TRUE) || defined (__DOXYGEN__) +#include "sbvio.h" +#endif + /** * @brief Type of a sandbox manager global structure. */ @@ -262,9 +272,9 @@ typedef struct { } sb_config_t; /** - * @brief Type of a sandbox object. + * @brief Structure representing a sandbox object. */ -typedef struct { +struct sb_class { /** * @brief Pointer to the sandbox configuration data. */ @@ -317,7 +327,7 @@ typedef struct { */ sb_ioblock_t io; #endif -} sb_class_t; +}; /*===========================================================================*/ /* Module macros. */ @@ -339,10 +349,6 @@ extern "C" { /* Module inline functions. */ /*===========================================================================*/ -#if (SB_CFG_ENABLE_VRQ == TRUE) || defined (__DOXYGEN__) -#include "sbvrq.h" -#endif - #include "sbelf.h" #include "sbposix.h" #include "sbapi.h" diff --git a/os/sb/vio/sbvio_uart.c b/os/sb/vio/sbvio_uart.c index 4ce6861a6..b95958ed4 100644 --- a/os/sb/vio/sbvio_uart.c +++ b/os/sb/vio/sbvio_uart.c @@ -50,9 +50,9 @@ /*===========================================================================*/ static void vuart_cb(SIODriver *siop) { - sb_class_t *sbp = (sb_class_t *)siop->arg; + const vio_uart_unit_t *unitp = (const vio_uart_unit_t *)siop->arg; - sbVRQTriggerFromISR(sbp, 1U << SB_CFG_ALARM_VRQ); + sbVRQTriggerFromISR(unitp->vrqsb, 1U << unitp->vrqn); } /*===========================================================================*/ @@ -86,12 +86,14 @@ void sb_api_vio_uart(struct port_extctx *ectxp) { return; } + /* Specified VUART configuration.*/ confp = &sbp->config->vioconf->uartconfs->cfgs[conf]; + /* Associating this virtual UART to the SIO driver.*/ + unitp->siop->arg = (void *)unitp; + msg = sioStart(unitp->siop, confp->siocfgp); if (msg == HAL_RET_SUCCESS) { - /* Associating this SIO to the sandbox.*/ - unitp->siop->arg = (sb_class_t *)sbp; /* Starting with disabled events, enabling the callback.*/ sioWriteEnableFlags(unitp->siop, SIO_FL_NONE); diff --git a/os/sb/vio/sbvio_uart.h b/os/sb/vio/sbvio_uart.h index c7bf97641..616b531bd 100644 --- a/os/sb/vio/sbvio_uart.h +++ b/os/sb/vio/sbvio_uart.h @@ -56,6 +56,8 @@ */ typedef struct vio_uart_unit { SIODriver *siop; + sb_class_t *vrqsb; + unsigned vrqn; } vio_uart_unit_t; /**