XHAL SPI driver, unfinished.

git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@16280 27425a3e-05d8-49a3-a47f-9c15f0e5edd8
This commit is contained in:
Giovanni Di Sirio 2023-06-13 13:12:40 +00:00
parent 942ce8c780
commit f74f12ff56
8 changed files with 967 additions and 3 deletions

View File

@ -17,7 +17,8 @@
<define name="HAL_DRV_STATE_STARTING" value="3U" />
<define name="HAL_DRV_STATE_READY" value="4U" />
<define name="HAL_DRV_STATE_ACTIVE" value="5U" />
<define name="HAL_DRV_STATE_ERROR" value="6U" />
<define name="HAL_DRV_STATE_COMPLETE" value="6U" />
<define name="HAL_DRV_STATE_ERROR" value="7U" />
</group>
</definitions_early>
<configs>

230
os/xhal/codegen/hal_spi.xml Normal file
View File

@ -0,0 +1,230 @@
<?xml version="1.0" encoding="UTF-8"?>
<module xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://www.chibios.org/xml/schema/ccode/modules.xsd"
name="hal_spi" descr="SPI Driver" check="HAL_USE_SPI == TRUE" editcode="false">
<brief>SPI Driver macros and structures.</brief>
<imports>
<import>hal_cb_driver.xml</import>
</imports>
<public>
<definitions_early>
<group description="SPI CS modes">
<define name="SPI_SELECT_MODE_NONE" value="0" >
<brief>@p spiSelect() and @p spiUnselect() do nothing.</brief>
</define>
<define name="SPI_SELECT_MODE_PAD" value="1" >
<brief>Selection by PAL port and pad number.</brief>
</define>
<define name="SPI_SELECT_MODE_PORT" value="2" >
<brief>Selection by port and port mask.</brief>
</define>
<define name="SPI_SELECT_MODE_LINE" value="3" >
<brief>Selection by PAL line identifier.</brief>
</define>
<define name="SPI_SELECT_MODE_LLD" value="4" >
<brief>Selection by LLD-defined mode.</brief>
</define>
</group>
</definitions_early>
<configs>
<config name="SPI_USE_SYNCHRONIZATION" default="TRUE">
<brief>Support for thread synchronization API.</brief>
<assert invalid="($N != FALSE) &amp;&amp; ($N != TRUE)" />
</config>
<config name="SPI_SELECT_MODE"
default="SPI_SELECT_MODE_PAD">
<brief>Handling method for SPI CS line.</brief>
<assert invalid="($N &lt; SPI_SELECT_MODE_NONE) || ($N &gt; SPI_SELECT_MODE_LLD)" />
</config>
</configs>
<types>
<typedef name="hal_spi_config_t">
<brief>Type of structure representing a SPI configuration.</brief>
<basetype ctype="struct hal_spi_config" />
</typedef>
<typedef name="SPIConfig">
<brief>Type of structure representing a SPI configuration
(legacy).
</brief>
<basetype ctype="struct hal_spi_config" />
</typedef>
<typedef name="SPIDriver">
<brief>Type of structure representing a SPI driver (legacy).</brief>
<basetype ctype="struct hal_spi_driver" />
</typedef>
<verbatim><![CDATA[
/* Inclusion of LLD header.*/
#include "hal_spi_lld.h"
#if !defined(SPI_SUPPORTS_CIRCULAR)
#error "SPI_SUPPORTS_CIRCULAR not defined in SPI LLD driver"
#endif
#if !defined(SPI_SUPPORTS_SLAVE_MODE)
#error "SPI_SUPPORTS_SLAVE_MODE not defined in SPI LLD driver"
#endif]]></verbatim>
<struct name="hal_spi_config">
<brief>Driver configuration structure.</brief>
<note>Implementations may extend this structure to contain more,
architecture dependent, fields.
</note>
<fields>
<condition check="SPI_SUPPORTS_CIRCULAR == TRUE">
<field name="circular" ctype="bool">
<brief>Enables the circular buffer mode.</brief>
</field>
</condition>
<condition check="SPI_SUPPORTS_SLAVE_MODE == TRUE">
<field name="slave" ctype="bool">
<brief>Enables the slave mode.</brief>
</field>
</condition>
<condition check="SPI_SELECT_MODE == SPI_SELECT_MODE_LINE">
<field name="ssline" ctype="ioline_t">
<brief>The chip select line.</brief>
<note>Only used in master mode.</note>
</field>
</condition>
<condition check="SPI_SELECT_MODE == SPI_SELECT_MODE_PORT">
<field name="ssport" ctype="ioportid_t">
<brief>The chip select port.</brief>
<note>Only used in master mode.</note>
</field>
<field name="ssmask" ctype="ioportmask_t">
<brief>The chip select port mask.</brief>
<note>Only used in master mode.</note>
</field>
</condition>
<condition check="SPI_SELECT_MODE == SPI_SELECT_MODE_PAD">
<field name="ssport" ctype="ioportid_t">
<brief>The chip select port.</brief>
<note>Only used in master mode.</note>
</field>
<field name="sspad" ctype="ioportmask_t">
<brief>The chip select pad number.</brief>
<note>Only used in master mode.</note>
</field>
</condition>
<verbatim><![CDATA[
/* End of the mandatory fields.*/
spi_lld_config_fields;]]></verbatim>
<condition check="defined(SPI_CONFIG_EXT_FIELS)">
<verbatim><![CDATA[
SPI_CONFIG_EXT_FIELDS]]></verbatim>
</condition>
</fields>
</struct>
<class type="regular" name="hal_spi_driver" namespace="spi"
ancestorname="hal_cb_driver" descr="SPI driver">
<brief>Class of a SPI driver.</brief>
<fields>
<verbatim><![CDATA[
#if defined(SPI_DRIVER_EXT_FIELS)
SPI_DRIVER_EXT_FIELDS
#endif
/* End of the mandatory fields.*/
spi_lld_driver_fields;]]></verbatim>
</fields>
<methods>
<objinit callsuper="true">
<implementation><![CDATA[
/* Optional, user-defined initializer.*/
#if defined(SPI_DRIVER_EXT_INIT_HOOK)
SPI_DRIVER_EXT_INIT_HOOK(self);
#endif]]></implementation>
</objinit>
<dispose>
<implementation><![CDATA[ ]]></implementation>
</dispose>
</methods>
</class>
<class name="hal_buffered_spi" type="regular" namespace="bspi"
descr="buffered SPI wrapper" ancestorname="hal_buffered_serial">
<brief>This class implements a buffered channel interface on top of SPI.</brief>
<fields>
<field name="spip" ctype="hal_spi_driver_c$I*">
<brief>Pointer to the associated @p hal_spi_driver_c instance.</brief>
</field>
</fields>
<methods>
<objinit callsuper="false">
<param name="spip" ctype="hal_spi_driver_c *" dir="in">Pointer to
the @p hal_spi_driver_c object.</param>
<param name="ib" ctype="uint8_t *" dir="in">Pointer to the input buffer.</param>
<param name="ibsize" ctype="size_t" dir="in">Size of the input buffer.</param>
<param name="ob" ctype="uint8_t *" dir="in">Pointer to the output buffer.</param>
<param name="obsize" ctype="size_t" dir="in">Size of the output buffer.</param>
<implementation><![CDATA[
__bs_objinit_impl((void *)self, vmt,
ib, ibsize, NULL, NULL,
ob, obsize, __bspi_onotify, (void *)self);
drvSetArgumentX(spip, self);
self->spip = spip;]]></implementation>
</objinit>
<dispose>
<implementation><![CDATA[
]]></implementation>
</dispose>
<override>
<method shortname="start">
<implementation><![CDATA[
msg_t msg;
/* Start is a slow operation in this driver, we need to switch to the
HAL_DRV_STATE_STARTING state.*/
self->state = HAL_DRV_STATE_STARTING;
osalSysUnlock();
/* Starting the undelying SPI driver.*/
msg = drvStart(self->spip);
if (msg == HAL_RET_SUCCESS) {
spiSetCallbackX(self->spip, &__bspi_default_cb);
spiWriteEnableFlagsX(self->spip, SPI_EV_ALL_EVENTS);
}
/* Back into the critical section and return.*/
osalSysLock();
return msg;]]></implementation>
</method>
<method shortname="stop">
<implementation><![CDATA[
/* Start is a slow operation in this driver, we need to switch to the
HAL_DRV_STATE_STOPPING state.*/
self->state = HAL_DRV_STATE_STOPPING;
osalSysUnlock();
drvStop(self->spip);
/* Back into the critical section and return.*/
osalSysLock();]]></implementation>
</method>
<method shortname="configure">
<implementation><![CDATA[
return drvConfigureX(self->spip, config);]]></implementation>
</method>
</override>
</methods>
</class>
</types>
<functions>
<function name="spiInit" ctype="void">
<brief>SPI Driver initialization.</brief>
<note>
This function is implicitly invoked by @p halInit(), there is no
need to explicitly initialize the driver.
</note>
<init />
<implementation><![CDATA[
spi_lld_init();]]></implementation>
</function>
</functions>
</public>
<private>
<includes_always>
<include style="regular">hal.h</include>
</includes_always>
</private>
</module>

View File

@ -6,6 +6,7 @@
<!ENTITY hal_block_io SYSTEM "hal_block_io.xml">
<!ENTITY hal_buffered_serial SYSTEM "hal_buffered_serial.xml">
<!ENTITY hal_sio SYSTEM "hal_sio.xml">
<!ENTITY hal_spi SYSTEM "hal_spi.xml">
]>
<instance xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://www.chibios.org/xml/schema/ccode/modules.xsd">
@ -19,5 +20,6 @@
&hal_block_io;
&hal_buffered_serial;
&hal_sio;
&hal_spi;
</modules>
</instance>

View File

@ -15,6 +15,7 @@ HALCONF := $(strip $(shell cat $(HALCONFDIR)/halconf.h | egrep -e "\#define"))
HALSRC := $(CHIBIOS)/os/xhal/src/hal.c \
$(CHIBIOS)/os/xhal/src/hal_base_driver.c \
$(CHIBIOS)/os/xhal/src/hal_cb_driver.c \
$(CHIBIOS)/os/xhal/src/hal_st.c \
$(CHIBIOS)/os/xhal/src/hal_buffered_serial.c \
$(CHIBIOS)/os/xhal/src/hal_queues.c
@ -24,6 +25,9 @@ endif
ifneq ($(findstring HAL_USE_SIO TRUE,$(HALCONF)),)
HALSRC += $(CHIBIOS)/os/xhal/src/hal_sio.c
endif
ifneq ($(findstring HAL_USE_SPI TRUE,$(HALCONF)),)
HALSRC += $(CHIBIOS)/os/xhal/src/hal_spi.c
endif
else
HALSRC = $(CHIBIOS)/os/xhal/src/hal.c \
$(CHIBIOS)/os/xhal/src/hal_base_driver.c \
@ -31,6 +35,7 @@ HALSRC = $(CHIBIOS)/os/xhal/src/hal.c \
$(CHIBIOS)/os/xhal/src/hal_queues.c \
$(CHIBIOS)/os/xhal/src/hal_pal.c \
$(CHIBIOS)/os/xhal/src/hal_sio.c
$(CHIBIOS)/os/xhal/src/hal_spi.c
endif
# Required include directories

View File

@ -321,7 +321,7 @@ static inline halfreq_t halClockGetPointX(halclkpt_t clkpt) {
//#include "hal_serial.h"
//#include "hal_sdc.h"
#include "hal_sio.h"
//#include "hal_spi.h"
#include "hal_spi.h"
//#include "hal_trng.h"
//#include "hal_uart.h"
//#include "hal_usb.h"

View File

@ -43,7 +43,8 @@
#define HAL_DRV_STATE_STARTING 3U
#define HAL_DRV_STATE_READY 4U
#define HAL_DRV_STATE_ACTIVE 5U
#define HAL_DRV_STATE_ERROR 6U
#define HAL_DRV_STATE_COMPLETE 6U
#define HAL_DRV_STATE_ERROR 7U
/** @} */
/*===========================================================================*/

447
os/xhal/include/hal_spi.h Normal file
View File

@ -0,0 +1,447 @@
/*
ChibiOS - Copyright (C) 2006..2023 Giovanni Di Sirio
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/**
* @file hal_spi.h
* @brief Generated SPI Driver header.
* @note This is a generated file, do not edit directly.
*
* @addtogroup HAL_SPI
* @brief SPI Driver macros and structures.
* @{
*/
#ifndef HAL_SPI_H
#define HAL_SPI_H
#if (HAL_USE_SPI == TRUE) || defined(__DOXYGEN__)
/*===========================================================================*/
/* Module constants. */
/*===========================================================================*/
/**
* @name SPI CS modes
* @{
*/
/**
* @brief @p spiSelect() and @p spiUnselect() do nothing.
*/
#define SPI_SELECT_MODE_NONE 0
/**
* @brief Selection by PAL port and pad number.
*/
#define SPI_SELECT_MODE_PAD 1
/**
* @brief Selection by port and port mask.
*/
#define SPI_SELECT_MODE_PORT 2
/**
* @brief Selection by PAL line identifier.
*/
#define SPI_SELECT_MODE_LINE 3
/**
* @brief Selection by LLD-defined mode.
*/
#define SPI_SELECT_MODE_LLD 4
/** @} */
/*===========================================================================*/
/* Module pre-compile time settings. */
/*===========================================================================*/
/**
* @name Configuration options
* @{
*/
/**
* @brief Support for thread synchronization API.
*/
#if !defined(SPI_USE_SYNCHRONIZATION) || defined(__DOXYGEN__)
#define SPI_USE_SYNCHRONIZATION TRUE
#endif
/**
* @brief Handling method for SPI CS line.
*/
#if !defined(SPI_SELECT_MODE) || defined(__DOXYGEN__)
#define SPI_SELECT_MODE SPI_SELECT_MODE_PAD
#endif
/** @} */
/*===========================================================================*/
/* Derived constants and error checks. */
/*===========================================================================*/
/* Checks on SPI_USE_SYNCHRONIZATION configuration.*/
#if (SPI_USE_SYNCHRONIZATION != FALSE) && (SPI_USE_SYNCHRONIZATION != TRUE)
#error "invalid SPI_USE_SYNCHRONIZATION value"
#endif
/* Checks on SPI_SELECT_MODE configuration.*/
#if (SPI_SELECT_MODE < SPI_SELECT_MODE_NONE) || (SPI_SELECT_MODE > SPI_SELECT_MODE_LLD)
#error "invalid SPI_SELECT_MODE value"
#endif
/*===========================================================================*/
/* Module macros. */
/*===========================================================================*/
/*===========================================================================*/
/* Module data structures and types. */
/*===========================================================================*/
/**
* @brief Type of structure representing a SPI configuration.
*/
typedef struct hal_spi_config hal_spi_config_t;
/**
* @brief Type of structure representing a SPI configuration (legacy).
*/
typedef struct hal_spi_config SPIConfig;
/**
* @brief Type of structure representing a SPI driver (legacy).
*/
typedef struct hal_spi_driver SPIDriver;
/* Inclusion of LLD header.*/
#include "hal_spi_lld.h"
#if !defined(SPI_SUPPORTS_CIRCULAR)
#error "SPI_SUPPORTS_CIRCULAR not defined in SPI LLD driver"
#endif
#if !defined(SPI_SUPPORTS_SLAVE_MODE)
#error "SPI_SUPPORTS_SLAVE_MODE not defined in SPI LLD driver"
#endif
/**
* @brief Driver configuration structure.
* @note Implementations may extend this structure to contain more,
* architecture dependent, fields.
*/
struct hal_spi_config {
#if (SPI_SUPPORTS_CIRCULAR == TRUE) || defined (__DOXYGEN__)
/**
* @brief Enables the circular buffer mode.
*/
bool circular;
#endif /* SPI_SUPPORTS_CIRCULAR == TRUE */
#if (SPI_SUPPORTS_SLAVE_MODE == TRUE) || defined (__DOXYGEN__)
/**
* @brief Enables the slave mode.
*/
bool slave;
#endif /* SPI_SUPPORTS_SLAVE_MODE == TRUE */
#if (SPI_SELECT_MODE == SPI_SELECT_MODE_LINE) || defined (__DOXYGEN__)
/**
* @brief The chip select line.
* @note Only used in master mode.
*/
ioline_t ssline;
#endif /* SPI_SELECT_MODE == SPI_SELECT_MODE_LINE */
#if (SPI_SELECT_MODE == SPI_SELECT_MODE_PORT) || defined (__DOXYGEN__)
/**
* @brief The chip select port.
* @note Only used in master mode.
*/
ioportid_t ssport;
/**
* @brief The chip select port mask.
* @note Only used in master mode.
*/
ioportmask_t ssmask;
#endif /* SPI_SELECT_MODE == SPI_SELECT_MODE_PORT */
#if (SPI_SELECT_MODE == SPI_SELECT_MODE_PAD) || defined (__DOXYGEN__)
/**
* @brief The chip select port.
* @note Only used in master mode.
*/
ioportid_t ssport;
/**
* @brief The chip select pad number.
* @note Only used in master mode.
*/
ioportmask_t sspad;
#endif /* SPI_SELECT_MODE == SPI_SELECT_MODE_PAD */
/* End of the mandatory fields.*/
spi_lld_config_fields;
#if (defined(SPI_CONFIG_EXT_FIELS)) || defined (__DOXYGEN__)
SPI_CONFIG_EXT_FIELDS
#endif /* defined(SPI_CONFIG_EXT_FIELS) */
};
/**
* @class hal_spi_driver_c
* @extends base_object_c, hal_base_driver_c, hal_cb_driver_c.
*
* @brief Class of a SPI driver.
*
* @name Class @p hal_spi_driver_c structures
* @{
*/
/**
* @brief Type of a SPI driver class.
*/
typedef struct hal_spi_driver hal_spi_driver_c;
/**
* @brief Class @p hal_spi_driver_c virtual methods table.
*/
struct hal_spi_driver_vmt {
/* From base_object_c.*/
void (*dispose)(void *ip);
/* From hal_base_driver_c.*/
msg_t (*start)(void *ip);
void (*stop)(void *ip);
msg_t (*configure)(void *ip, const void *config);
/* From hal_cb_driver_c.*/
/* From hal_spi_driver_c.*/
};
/**
* @brief Structure representing a SPI driver class.
*/
struct hal_spi_driver {
/**
* @brief Virtual Methods Table.
*/
const struct hal_spi_driver_vmt *vmt;
/**
* @brief Driver state.
*/
driver_state_t state;
/**
* @brief Driver argument.
*/
void *arg;
#if (HAL_USE_MUTUAL_EXCLUSION == TRUE) || defined (__DOXYGEN__)
/**
* @brief Driver mutex.
*/
mutex_t mutex;
#endif /* HAL_USE_MUTUAL_EXCLUSION == TRUE */
#if (HAL_USE_REGISTRY == TRUE) || defined (__DOXYGEN__)
/**
* @brief Driver identifier.
*/
unsigned int id;
/**
* @brief Driver name.
*/
const char *name;
/**
* @brief Registry link structure.
*/
hal_regent_t regent;
#endif /* HAL_USE_REGISTRY == TRUE */
/**
* @brief Driver callback.
* @note Can be @p NULL.
*/
hal_cb_t cb;
#if defined(SPI_DRIVER_EXT_FIELS)
SPI_DRIVER_EXT_FIELDS
#endif
/* End of the mandatory fields.*/
spi_lld_driver_fields;
};
/** @} */
/**
* @class hal_buffered_spi_c
* @extends base_object_c, hal_base_driver_c, hal_buffered_serial_c.
*
* @brief This class implements a buffered channel interface on top of
* SPI.
*
* @name Class @p hal_buffered_spi_c structures
* @{
*/
/**
* @brief Type of a buffered SPI wrapper class.
*/
typedef struct hal_buffered_spi hal_buffered_spi_c;
/**
* @brief Class @p hal_buffered_spi_c virtual methods table.
*/
struct hal_buffered_spi_vmt {
/* From base_object_c.*/
void (*dispose)(void *ip);
/* From hal_base_driver_c.*/
msg_t (*start)(void *ip);
void (*stop)(void *ip);
msg_t (*configure)(void *ip, const void *config);
/* From hal_buffered_serial_c.*/
/* From hal_buffered_spi_c.*/
};
/**
* @brief Structure representing a buffered SPI wrapper class.
*/
struct hal_buffered_spi {
/**
* @brief Virtual Methods Table.
*/
const struct hal_buffered_spi_vmt *vmt;
/**
* @brief Driver state.
*/
driver_state_t state;
/**
* @brief Driver argument.
*/
void *arg;
#if (HAL_USE_MUTUAL_EXCLUSION == TRUE) || defined (__DOXYGEN__)
/**
* @brief Driver mutex.
*/
mutex_t mutex;
#endif /* HAL_USE_MUTUAL_EXCLUSION == TRUE */
#if (HAL_USE_REGISTRY == TRUE) || defined (__DOXYGEN__)
/**
* @brief Driver identifier.
*/
unsigned int id;
/**
* @brief Driver name.
*/
const char *name;
/**
* @brief Registry link structure.
*/
hal_regent_t regent;
#endif /* HAL_USE_REGISTRY == TRUE */
/**
* @brief Implemented interface @p asynchronous_channel_i.
*/
asynchronous_channel_i chn;
/**
* @brief Input queue.
*/
input_queue_t iqueue;
/**
* @brief Output queue.
*/
output_queue_t oqueue;
/**
* @brief I/O condition event source.
*/
event_source_t event;
/**
* @brief Pointer to the associated @p hal_spi_driver_c instance.
*/
hal_spi_driver_c *spip;
};
/** @} */
/*===========================================================================*/
/* External declarations. */
/*===========================================================================*/
#ifdef __cplusplus
extern "C" {
#endif
/* Methods of hal_spi_driver_c.*/
void *__spi_objinit_impl(void *ip, const void *vmt);
void __spi_dispose_impl(void *ip);
/* Methods of hal_buffered_spi_c.*/
void *__bspi_objinit_impl(void *ip, const void *vmt, hal_spi_driver_c *spip,
uint8_t *ib, size_t ibsize, uint8_t *ob,
size_t obsize);
void __bspi_dispose_impl(void *ip);
msg_t __bspi_start_impl(void *ip);
void __bspi_stop_impl(void *ip);
msg_t __bspi_configure_impl(void *ip, const void *config);
/* Regular functions.*/
void spiInit(void);
#ifdef __cplusplus
}
#endif
/*===========================================================================*/
/* Module inline functions. */
/*===========================================================================*/
/**
* @name Default constructor of hal_spi_driver_c
* @{
*/
/**
* @memberof hal_spi_driver_c
*
* @brief Default initialization function of @p hal_spi_driver_c.
*
* @param[out] self Pointer to a @p hal_spi_driver_c instance to be
* initialized.
* @return Pointer to the initialized object.
*
* @objinit
*/
CC_FORCE_INLINE
static inline hal_spi_driver_c *spiObjectInit(hal_spi_driver_c *self) {
extern const struct hal_spi_driver_vmt __hal_spi_driver_vmt;
return __spi_objinit_impl(self, &__hal_spi_driver_vmt);
}
/** @} */
/**
* @name Default constructor of hal_buffered_spi_c
* @{
*/
/**
* @memberof hal_buffered_spi_c
*
* @brief Default initialization function of @p hal_buffered_spi_c.
*
* @param[out] self Pointer to a @p hal_buffered_spi_c instance to
* be initialized.
* @param[in] spip Pointer to the @p hal_spi_driver_c object.
* @param[in] ib Pointer to the input buffer.
* @param[in] ibsize Size of the input buffer.
* @param[in] ob Pointer to the output buffer.
* @param[in] obsize Size of the output buffer.
* @return Pointer to the initialized object.
*
* @objinit
*/
CC_FORCE_INLINE
static inline hal_buffered_spi_c *bspiObjectInit(hal_buffered_spi_c *self,
hal_spi_driver_c *spip,
uint8_t *ib, size_t ibsize,
uint8_t *ob, size_t obsize) {
extern const struct hal_buffered_spi_vmt __hal_buffered_spi_vmt;
return __bspi_objinit_impl(self, &__hal_buffered_spi_vmt, spip, ib, ibsize,
ob, obsize);
}
/** @} */
#endif /* HAL_USE_SPI == TRUE */
#endif /* HAL_SPI_H */
/** @} */

278
os/xhal/src/hal_spi.c Normal file
View File

@ -0,0 +1,278 @@
/*
ChibiOS - Copyright (C) 2006..2023 Giovanni Di Sirio
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/**
* @file hal_spi.c
* @brief Generated SPI Driver source.
* @note This is a generated file, do not edit directly.
*
* @addtogroup HAL_SPI
* @{
*/
#include "hal.h"
#if (HAL_USE_SPI == TRUE) || defined(__DOXYGEN__)
/*===========================================================================*/
/* Module local definitions. */
/*===========================================================================*/
/*===========================================================================*/
/* Module local macros. */
/*===========================================================================*/
/*===========================================================================*/
/* Module exported variables. */
/*===========================================================================*/
/*===========================================================================*/
/* Module local types. */
/*===========================================================================*/
/*===========================================================================*/
/* Module local variables. */
/*===========================================================================*/
/*===========================================================================*/
/* Module local functions. */
/*===========================================================================*/
/*===========================================================================*/
/* Module exported functions. */
/*===========================================================================*/
/**
* @brief SPI Driver initialization.
* @note This function is implicitly invoked by @p halInit(), there is
* no need to explicitly initialize the driver.
*
* @init
*/
void spiInit(void) {
spi_lld_init();
}
/*===========================================================================*/
/* Module class "hal_spi_driver_c" methods. */
/*===========================================================================*/
/**
* @name Methods implementations of hal_spi_driver_c
* @{
*/
/**
* @memberof hal_spi_driver_c
* @protected
*
* @brief Implementation of object creation.
* @note This function is meant to be used by derived classes.
*
* @param[out] ip Pointer to a @p hal_spi_driver_c instance to be
* initialized.
* @param[in] vmt VMT pointer for the new object.
* @return A new reference to the object.
*/
void *__spi_objinit_impl(void *ip, const void *vmt) {
hal_spi_driver_c *self = (hal_spi_driver_c *)ip;
/* Initialization of the ancestors-defined parts.*/
__cbdrv_objinit_impl(self, vmt);
/* Initialization code.*/
/* Optional, user-defined initializer.*/
#if defined(SPI_DRIVER_EXT_INIT_HOOK)
SPI_DRIVER_EXT_INIT_HOOK(self);
#endif
return self;
}
/**
* @memberof hal_spi_driver_c
* @protected
*
* @brief Implementation of object finalization.
* @note This function is meant to be used by derived classes.
*
* @param[in,out] ip Pointer to a @p hal_spi_driver_c instance to be
* disposed.
*/
void __spi_dispose_impl(void *ip) {
hal_spi_driver_c *self = (hal_spi_driver_c *)ip;
/* No finalization code.*/
(void)self;
/* Finalization of the ancestors-defined parts.*/
__cbdrv_dispose_impl(self);
}
/** @} */
/**
* @brief VMT structure of SPI driver class.
* @note It is public because accessed by the inlined constructor.
*/
const struct hal_spi_driver_vmt __hal_spi_driver_vmt = {
.dispose = __spi_dispose_impl,
.start = NULL /* Method not found.*/,
.stop = NULL /* Method not found.*/,
.configure = NULL /* Method not found.*/
};
/*===========================================================================*/
/* Module class "hal_buffered_spi_c" methods. */
/*===========================================================================*/
/**
* @name Methods implementations of hal_buffered_spi_c
* @{
*/
/**
* @memberof hal_buffered_spi_c
* @protected
*
* @brief Implementation of object creation.
* @note This function is meant to be used by derived classes.
*
* @param[out] ip Pointer to a @p hal_buffered_spi_c instance to
* be initialized.
* @param[in] vmt VMT pointer for the new object.
* @param[in] spip Pointer to the @p hal_spi_driver_c object.
* @param[in] ib Pointer to the input buffer.
* @param[in] ibsize Size of the input buffer.
* @param[in] ob Pointer to the output buffer.
* @param[in] obsize Size of the output buffer.
* @return A new reference to the object.
*/
void *__bspi_objinit_impl(void *ip, const void *vmt, hal_spi_driver_c *spip,
uint8_t *ib, size_t ibsize, uint8_t *ob,
size_t obsize) {
hal_buffered_spi_c *self = (hal_buffered_spi_c *)ip;
/* Initialization code.*/
__bs_objinit_impl((void *)self, vmt,
ib, ibsize, NULL, NULL,
ob, obsize, __bspi_onotify, (void *)self);
drvSetArgumentX(spip, self);
self->spip = spip;
return self;
}
/**
* @memberof hal_buffered_spi_c
* @protected
*
* @brief Implementation of object finalization.
* @note This function is meant to be used by derived classes.
*
* @param[in,out] ip Pointer to a @p hal_buffered_spi_c instance to
* be disposed.
*/
void __bspi_dispose_impl(void *ip) {
hal_buffered_spi_c *self = (hal_buffered_spi_c *)ip;
/* No finalization code.*/
(void)self;
/* Finalization of the ancestors-defined parts.*/
__bs_dispose_impl(self);
}
/**
* @memberof hal_buffered_spi_c
* @protected
*
* @brief Override of method @p __drv_start().
*
* @param[in,out] ip Pointer to a @p hal_buffered_spi_c instance.
* @return The operation status.
*/
msg_t __bspi_start_impl(void *ip) {
hal_buffered_spi_c *self = (hal_buffered_spi_c *)ip;
msg_t msg;
/* Start is a slow operation in this driver, we need to switch to the
HAL_DRV_STATE_STARTING state.*/
self->state = HAL_DRV_STATE_STARTING;
osalSysUnlock();
/* Starting the undelying SPI driver.*/
msg = drvStart(self->spip);
if (msg == HAL_RET_SUCCESS) {
spiSetCallbackX(self->spip, &__bspi_default_cb);
spiWriteEnableFlagsX(self->spip, SPI_EV_ALL_EVENTS);
}
/* Back into the critical section and return.*/
osalSysLock();
return msg;
}
/**
* @memberof hal_buffered_spi_c
* @protected
*
* @brief Override of method @p __drv_stop().
*
* @param[in,out] ip Pointer to a @p hal_buffered_spi_c instance.
*/
void __bspi_stop_impl(void *ip) {
hal_buffered_spi_c *self = (hal_buffered_spi_c *)ip;
/* Start is a slow operation in this driver, we need to switch to the
HAL_DRV_STATE_STOPPING state.*/
self->state = HAL_DRV_STATE_STOPPING;
osalSysUnlock();
drvStop(self->spip);
/* Back into the critical section and return.*/
osalSysLock();
}
/**
* @memberof hal_buffered_spi_c
* @protected
*
* @brief Override of method @p drvConfigureX().
*
* @param[in,out] ip Pointer to a @p hal_buffered_spi_c instance.
* @param[in] config New driver configuration.
*/
msg_t __bspi_configure_impl(void *ip, const void *config) {
hal_buffered_spi_c *self = (hal_buffered_spi_c *)ip;
return drvConfigureX(self->spip, config);
}
/** @} */
/**
* @brief VMT structure of buffered SPI wrapper class.
* @note It is public because accessed by the inlined constructor.
*/
const struct hal_buffered_spi_vmt __hal_buffered_spi_vmt = {
.dispose = __bspi_dispose_impl,
.start = __bspi_start_impl,
.stop = __bspi_stop_impl,
.configure = __bspi_configure_impl
};
#endif /* HAL_USE_SPI == TRUE */
/** @} */