git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@16304 27425a3e-05d8-49a3-a47f-9c15f0e5edd8
This commit is contained in:
parent
fa867f0f85
commit
68db9362ea
|
@ -163,7 +163,7 @@
|
||||||
* @brief Enables the SPI subsystem.
|
* @brief Enables the SPI subsystem.
|
||||||
*/
|
*/
|
||||||
#if !defined(HAL_USE_SPI) || defined(__DOXYGEN__)
|
#if !defined(HAL_USE_SPI) || defined(__DOXYGEN__)
|
||||||
#define HAL_USE_SPI FALSE
|
#define HAL_USE_SPI TRUE
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -325,7 +325,7 @@
|
||||||
* SPI driver system settings.
|
* SPI driver system settings.
|
||||||
*/
|
*/
|
||||||
#define STM32_SPI_USE_SPI1 FALSE
|
#define STM32_SPI_USE_SPI1 FALSE
|
||||||
#define STM32_SPI_USE_SPI2 FALSE
|
#define STM32_SPI_USE_SPI2 TRUE
|
||||||
#define STM32_SPI_USE_SPI3 FALSE
|
#define STM32_SPI_USE_SPI3 FALSE
|
||||||
#define STM32_SPI_USE_SPI4 FALSE
|
#define STM32_SPI_USE_SPI4 FALSE
|
||||||
#define STM32_SPI_SPI1_RX_DMA_STREAM STM32_DMA_STREAM_ID_ANY
|
#define STM32_SPI_SPI1_RX_DMA_STREAM STM32_DMA_STREAM_ID_ANY
|
||||||
|
|
|
@ -37,6 +37,13 @@
|
||||||
#define VIO_CFG_ENABLE_GPIO TRUE
|
#define VIO_CFG_ENABLE_GPIO TRUE
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Enables the Virtual SPI support.
|
||||||
|
*/
|
||||||
|
#if !defined(VIO_CFG_ENABLE_SPI) || defined(__DOXYGEN__)
|
||||||
|
#define VIO_CFG_ENABLE_SPI TRUE
|
||||||
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Enables the Virtual UART support.
|
* @brief Enables the Virtual UART support.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -106,6 +106,15 @@
|
||||||
#define SB_VGPIO_SETMODE 6
|
#define SB_VGPIO_SETMODE 6
|
||||||
/** @} */
|
/** @} */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @name Virtual SPI syscall sub-codes
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
#define SB_VSPI_INIT 0
|
||||||
|
#define SB_VSPI_DEINIT 1
|
||||||
|
#define SB_VSPI_SETCFG 0
|
||||||
|
/** @} */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @name Virtual UART syscall sub-codes
|
* @name Virtual UART syscall sub-codes
|
||||||
* @{
|
* @{
|
||||||
|
|
|
@ -32,6 +32,7 @@
|
||||||
|
|
||||||
#include "vioconf.h"
|
#include "vioconf.h"
|
||||||
#include "sbvio_gpio.h"
|
#include "sbvio_gpio.h"
|
||||||
|
#include "sbvio_spi.h"
|
||||||
#include "sbvio_uart.h"
|
#include "sbvio_uart.h"
|
||||||
|
|
||||||
/*===========================================================================*/
|
/*===========================================================================*/
|
||||||
|
@ -51,6 +52,10 @@
|
||||||
#error "VIO_CFG_ENABLE_GPIO not defined in vioconf.h"
|
#error "VIO_CFG_ENABLE_GPIO not defined in vioconf.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if !defined(VIO_CFG_ENABLE_SPI) || defined(__DOXYGEN__)
|
||||||
|
#error "VIO_CFG_ENABLE_SPI not defined in vioconf.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
#if !defined(VIO_CFG_ENABLE_UART) || defined(__DOXYGEN__)
|
#if !defined(VIO_CFG_ENABLE_UART) || defined(__DOXYGEN__)
|
||||||
#error "VIO_CFG_ENABLE_UART not defined in vioconf.h"
|
#error "VIO_CFG_ENABLE_UART not defined in vioconf.h"
|
||||||
#endif
|
#endif
|
||||||
|
@ -79,6 +84,16 @@ typedef struct vio_conf {
|
||||||
*/
|
*/
|
||||||
const vio_uart_configs_t *uartconfs;
|
const vio_uart_configs_t *uartconfs;
|
||||||
#endif
|
#endif
|
||||||
|
#if (VIO_CFG_ENABLE_SPI == TRUE) || defined(__DOXYGEN__)
|
||||||
|
/**
|
||||||
|
* @brief Virtual SPI units.
|
||||||
|
*/
|
||||||
|
const vio_spi_units_t *spis;
|
||||||
|
/**
|
||||||
|
* @brief Virtual SPI configurations.
|
||||||
|
*/
|
||||||
|
const vio_spi_configs_t *spiconfs;
|
||||||
|
#endif
|
||||||
} vio_conf_t;
|
} vio_conf_t;
|
||||||
|
|
||||||
/*===========================================================================*/
|
/*===========================================================================*/
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
# List of the ChibiOS sandbox VHAL files.
|
# List of the ChibiOS sandbox VHAL files.
|
||||||
SBVHALSRC = $(CHIBIOS)/os/sb/vio/sbvio.c \
|
SBVHALSRC = $(CHIBIOS)/os/sb/vio/sbvio.c \
|
||||||
$(CHIBIOS)/os/sb/vio/sbvio_gpio.c \
|
$(CHIBIOS)/os/sb/vio/sbvio_gpio.c \
|
||||||
|
$(CHIBIOS)/os/sb/vio/sbvio_spi.c \
|
||||||
$(CHIBIOS)/os/sb/vio/sbvio_uart.c
|
$(CHIBIOS)/os/sb/vio/sbvio_uart.c
|
||||||
|
|
||||||
SBVHALASM =
|
SBVHALASM =
|
||||||
|
|
|
@ -0,0 +1,156 @@
|
||||||
|
/*
|
||||||
|
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 <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @file sb/vhal/sbvio_spi.c
|
||||||
|
* @brief ARM SandBox host Virtual SPI code.
|
||||||
|
*
|
||||||
|
* @addtogroup ARM_SANDBOX_HOST_VIO_SPI
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "sb.h"
|
||||||
|
|
||||||
|
#if (VIO_CFG_ENABLE_SPI == TRUE) || defined(__DOXYGEN__)
|
||||||
|
|
||||||
|
/*===========================================================================*/
|
||||||
|
/* Module local definitions. */
|
||||||
|
/*===========================================================================*/
|
||||||
|
|
||||||
|
/*===========================================================================*/
|
||||||
|
/* Module exported variables. */
|
||||||
|
/*===========================================================================*/
|
||||||
|
|
||||||
|
/*===========================================================================*/
|
||||||
|
/* Module local types. */
|
||||||
|
/*===========================================================================*/
|
||||||
|
|
||||||
|
/*===========================================================================*/
|
||||||
|
/* Module local variables. */
|
||||||
|
/*===========================================================================*/
|
||||||
|
|
||||||
|
/*===========================================================================*/
|
||||||
|
/* Module local functions. */
|
||||||
|
/*===========================================================================*/
|
||||||
|
|
||||||
|
static void vspi_cb(void *ip) {
|
||||||
|
hal_sio_driver_c *siop = (hal_sio_driver_c *)ip;
|
||||||
|
const vio_spi_unit_t *unitp = (const vio_spi_unit_t *)drvGetArgumentX(siop);
|
||||||
|
|
||||||
|
sbVRQTriggerFromISR(unitp->vrqsb, unitp->vrqn);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*===========================================================================*/
|
||||||
|
/* Module exported functions. */
|
||||||
|
/*===========================================================================*/
|
||||||
|
|
||||||
|
void sb_sysc_vio_spi(struct port_extctx *ectxp) {
|
||||||
|
sb_class_t *sbp = (sb_class_t *)chThdGetSelfX()->ctx.syscall.p;
|
||||||
|
uint32_t sub = ectxp->r0;
|
||||||
|
uint32_t unit = ectxp->r1;
|
||||||
|
ectxp->r0 = (uint32_t)CH_RET_INNER_ERROR;
|
||||||
|
const vio_spi_unit_t *unitp;
|
||||||
|
|
||||||
|
if (unit >= sbp->config->vioconf->spis->n) {
|
||||||
|
ectxp->r0 = (uint32_t)HAL_RET_NO_RESOURCE;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
unitp = &sbp->config->vioconf->spis->units[unit];
|
||||||
|
|
||||||
|
switch (sub) {
|
||||||
|
case SB_VSPI_INIT:
|
||||||
|
{
|
||||||
|
msg_t msg;
|
||||||
|
|
||||||
|
/* Associating this virtual SPI to the SPI driver.*/
|
||||||
|
drvSetArgumentX(unitp->spip, (void *)unitp);
|
||||||
|
|
||||||
|
msg = drvStart(unitp->spip);
|
||||||
|
if (msg == HAL_RET_SUCCESS) {
|
||||||
|
|
||||||
|
/* Starting with disabled events, enabling the callback.*/
|
||||||
|
sioWriteEnableFlags(unitp->spip, SIO_EV_NONE);
|
||||||
|
drvSetCallbackX(unitp->spip, vspi_cb);
|
||||||
|
}
|
||||||
|
|
||||||
|
ectxp->r0 = (uint32_t)msg;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case SB_VSPI_DEINIT:
|
||||||
|
{
|
||||||
|
drvStop(unitp->spip);
|
||||||
|
|
||||||
|
ectxp->r0 = (uint32_t)HAL_RET_SUCCESS;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
ectxp->r0 = (uint32_t)CH_RET_ENOSYS;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void sb_fastc_vio_spi(struct port_extctx *ectxp) {
|
||||||
|
sb_class_t *sbp = (sb_class_t *)chThdGetSelfX()->ctx.syscall.p;
|
||||||
|
uint32_t sub = ectxp->r0;
|
||||||
|
uint32_t unit = ectxp->r1;
|
||||||
|
const vio_spi_unit_t *unitp;
|
||||||
|
|
||||||
|
/* Returned value in case of error or illegal sub-code.*/
|
||||||
|
ectxp->r0 = (uint32_t)-1;
|
||||||
|
|
||||||
|
if (unit >= sbp->config->vioconf->spis->n) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
unitp = &sbp->config->vioconf->spis->units[unit];
|
||||||
|
|
||||||
|
/* We don't want assertion or errors to be caused in host, making sure
|
||||||
|
all functions are called in the proper state.*/
|
||||||
|
if (unitp->spip->state != HAL_DRV_STATE_READY) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (sub) {
|
||||||
|
case SB_VSPI_SETCFG:
|
||||||
|
{
|
||||||
|
uint32_t conf = ectxp->r2;
|
||||||
|
const vio_spi_config_t *confp;
|
||||||
|
|
||||||
|
/* Check on configuration index.*/
|
||||||
|
if (conf >= sbp->config->vioconf->spis->n) {
|
||||||
|
ectxp->r0 = (uint32_t)HAL_RET_CONFIG_ERROR;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Specified VSPI configuration.*/
|
||||||
|
confp = &sbp->config->vioconf->spiconfs->cfgs[conf];
|
||||||
|
|
||||||
|
ectxp->r0 = (uint32_t)drvConfigureX(unitp->spip, confp->spicfgp);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
/* Silently ignored.*/
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* VIO_CFG_ENABLE_SPI == TRUE */
|
||||||
|
|
||||||
|
/** @} */
|
|
@ -0,0 +1,116 @@
|
||||||
|
/*
|
||||||
|
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 <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @file sb/vhal/sbvio_spi.h
|
||||||
|
* @brief ARM SandBox host Virtual SPI macros and structures.
|
||||||
|
*
|
||||||
|
* @addtogroup ARM_SANDBOX_HOST_VIO_SPI
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef SBVIO_SPI_H
|
||||||
|
#define SBVIO_SPI_H
|
||||||
|
|
||||||
|
#if (VIO_CFG_ENABLE_SPI == TRUE) || defined(__DOXYGEN__)
|
||||||
|
|
||||||
|
/*===========================================================================*/
|
||||||
|
/* Module constants. */
|
||||||
|
/*===========================================================================*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Fast API handler for VHAL SPI driver.
|
||||||
|
*/
|
||||||
|
#define SB_SVC98_HANDLER sb_fastc_vio_spi
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief API handler for VHAL SPI driver.
|
||||||
|
*/
|
||||||
|
#define SB_SVC226_HANDLER sb_sysc_vio_spi
|
||||||
|
|
||||||
|
/*===========================================================================*/
|
||||||
|
/* Module pre-compile time settings. */
|
||||||
|
/*===========================================================================*/
|
||||||
|
|
||||||
|
/*===========================================================================*/
|
||||||
|
/* Derived constants and error checks. */
|
||||||
|
/*===========================================================================*/
|
||||||
|
|
||||||
|
/*===========================================================================*/
|
||||||
|
/* Module data structures and types. */
|
||||||
|
/*===========================================================================*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Type of a VIO SPI unit representation.
|
||||||
|
*/
|
||||||
|
typedef struct vio_spi_unit {
|
||||||
|
hal_spi_driver_c *spip;
|
||||||
|
sb_class_t *vrqsb;
|
||||||
|
sb_vrqnum_t vrqn;
|
||||||
|
} vio_spi_unit_t;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Type of a VIO SPI units structure.
|
||||||
|
*/
|
||||||
|
typedef struct vio_spi_units {
|
||||||
|
uint32_t n;
|
||||||
|
vio_spi_unit_t units[];
|
||||||
|
} vio_spi_units_t;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Type of a VIO SPI configuration representation.
|
||||||
|
*/
|
||||||
|
typedef struct vio_spi_config {
|
||||||
|
SIOConfig *spicfgp;
|
||||||
|
} vio_spi_config_t;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Type of a VIO SPIs configuration structure.
|
||||||
|
*/
|
||||||
|
typedef struct vio_spi_configs {
|
||||||
|
uint32_t n;
|
||||||
|
vio_spi_config_t cfgs[];
|
||||||
|
} vio_spi_configs_t;
|
||||||
|
|
||||||
|
/*===========================================================================*/
|
||||||
|
/* Module macros. */
|
||||||
|
/*===========================================================================*/
|
||||||
|
|
||||||
|
/*===========================================================================*/
|
||||||
|
/* External declarations. */
|
||||||
|
/*===========================================================================*/
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
void sb_sysc_vio_spi(struct port_extctx *ectxp);
|
||||||
|
void sb_fastc_vio_spi(struct port_extctx *ectxp);
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*===========================================================================*/
|
||||||
|
/* Module inline functions. */
|
||||||
|
/*===========================================================================*/
|
||||||
|
|
||||||
|
#endif /* VIO_CFG_ENABLE_SPI == TRUE */
|
||||||
|
|
||||||
|
#endif /* SBVIO_SPI_H */
|
||||||
|
|
||||||
|
/** @} */
|
|
@ -60,7 +60,7 @@
|
||||||
* @brief Type of a VIO UART unit representation.
|
* @brief Type of a VIO UART unit representation.
|
||||||
*/
|
*/
|
||||||
typedef struct vio_uart_unit {
|
typedef struct vio_uart_unit {
|
||||||
SIODriver *siop;
|
hal_sio_driver_c *siop;
|
||||||
sb_class_t *vrqsb;
|
sb_class_t *vrqsb;
|
||||||
sb_vrqnum_t vrqn;
|
sb_vrqnum_t vrqn;
|
||||||
} vio_uart_unit_t;
|
} vio_uart_unit_t;
|
||||||
|
|
Loading…
Reference in New Issue