diff options
author | Clyne Sullivan <clyne@bitgloo.com> | 2021-01-22 21:43:36 -0500 |
---|---|---|
committer | Clyne Sullivan <clyne@bitgloo.com> | 2021-01-22 21:43:36 -0500 |
commit | 48026bb824fd2d9cfb00ecd040db6ef3a416bae9 (patch) | |
tree | c14713aedfe78ee8b34f2e1252408782e2e2ff5d /ChibiOS_20.3.2/os/hal/include | |
parent | e080a26651f90c88176140d63a74c93c2f4041a2 (diff) |
upload initial port
Diffstat (limited to 'ChibiOS_20.3.2/os/hal/include')
38 files changed, 10960 insertions, 0 deletions
diff --git a/ChibiOS_20.3.2/os/hal/include/hal.h b/ChibiOS_20.3.2/os/hal/include/hal.h new file mode 100644 index 0000000..44f7fe2 --- /dev/null +++ b/ChibiOS_20.3.2/os/hal/include/hal.h @@ -0,0 +1,267 @@ +/*
+ ChibiOS - Copyright (C) 2006..2018 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.h
+ * @brief HAL subsystem header.
+ *
+ * @addtogroup HAL
+ * @{
+ */
+
+#ifndef HAL_H
+#define HAL_H
+
+#include "osal.h"
+#include "board.h"
+#include "halconf.h"
+
+/* Error checks on the configuration header file.*/
+#if !defined(HAL_USE_PAL)
+#define HAL_USE_PAL FALSE
+#endif
+
+#if !defined(HAL_USE_ADC)
+#define HAL_USE_ADC FALSE
+#endif
+
+#if !defined(HAL_USE_CAN)
+#define HAL_USE_CAN FALSE
+#endif
+
+#if !defined(HAL_USE_CRY)
+#define HAL_USE_CRY FALSE
+#endif
+
+#if !defined(HAL_USE_DAC)
+#define HAL_USE_DAC FALSE
+#endif
+
+#if !defined(HAL_USE_EFL)
+#define HAL_USE_EFL FALSE
+#endif
+
+#if !defined(HAL_USE_GPT)
+#define HAL_USE_GPT FALSE
+#endif
+
+#if !defined(HAL_USE_I2C)
+#define HAL_USE_I2C FALSE
+#endif
+
+#if !defined(HAL_USE_I2S)
+#define HAL_USE_I2S FALSE
+#endif
+
+#if !defined(HAL_USE_ICU)
+#define HAL_USE_ICU FALSE
+#endif
+
+#if !defined(HAL_USE_MAC)
+#define HAL_USE_MAC FALSE
+#endif
+
+#if !defined(HAL_USE_PWM)
+#define HAL_USE_PWM FALSE
+#endif
+
+#if !defined(HAL_USE_RTC)
+#define HAL_USE_RTC FALSE
+#endif
+
+#if !defined(HAL_USE_SERIAL)
+#define HAL_USE_SERIAL FALSE
+#endif
+
+#if !defined(HAL_USE_SDC)
+#define HAL_USE_SDC FALSE
+#endif
+
+#if !defined(HAL_USE_SIO)
+#define HAL_USE_SIO FALSE
+#endif
+
+#if !defined(HAL_USE_SPI)
+#define HAL_USE_SPI FALSE
+#endif
+
+#if !defined(HAL_USE_TRNG)
+#define HAL_USE_TRNG FALSE
+#endif
+
+#if !defined(HAL_USE_UART)
+#define HAL_USE_UART FALSE
+#endif
+
+#if !defined(HAL_USE_USB)
+#define HAL_USE_USB FALSE
+#endif
+
+#if !defined(HAL_USE_WDG)
+#define HAL_USE_WDG FALSE
+#endif
+
+#if !defined(HAL_USE_WSPI)
+#define HAL_USE_WSPI FALSE
+#endif
+
+/* Low Level HAL support.*/
+#include "hal_lld.h"
+
+/* Abstract interfaces.*/
+#include "hal_objects.h"
+#include "hal_streams.h"
+#include "hal_channels.h"
+#include "hal_files.h"
+#include "hal_ioblock.h"
+#include "hal_mmcsd.h"
+#include "hal_persistent.h"
+#include "hal_flash.h"
+
+/* Shared headers.*/
+#include "hal_buffers.h"
+#include "hal_queues.h"
+
+/* Normal drivers.*/
+#include "hal_pal.h"
+#include "hal_adc.h"
+#include "hal_can.h"
+#include "hal_crypto.h"
+#include "hal_dac.h"
+#include "hal_efl.h"
+#include "hal_gpt.h"
+#include "hal_i2c.h"
+#include "hal_i2s.h"
+#include "hal_icu.h"
+#include "hal_mac.h"
+#include "hal_pwm.h"
+#include "hal_rtc.h"
+#include "hal_serial.h"
+#include "hal_sdc.h"
+#include "hal_sio.h"
+#include "hal_spi.h"
+#include "hal_trng.h"
+#include "hal_uart.h"
+#include "hal_usb.h"
+#include "hal_wdg.h"
+#include "hal_wspi.h"
+
+/*
+ * The ST driver is a special case, it is only included if the OSAL is
+ * configured to require it.
+ */
+#if OSAL_ST_MODE != OSAL_ST_MODE_NONE
+#include "hal_st.h"
+#endif
+
+/* Complex drivers.*/
+#include "hal_mmc_spi.h"
+#include "hal_serial_usb.h"
+
+/* Community drivers.*/
+#if defined(HAL_USE_COMMUNITY) || defined(__DOXYGEN__)
+#if (HAL_USE_COMMUNITY == TRUE) || defined(__DOXYGEN__)
+#include "hal_community.h"
+#endif
+#endif
+
+/*===========================================================================*/
+/* Driver constants. */
+/*===========================================================================*/
+
+/**
+ * @brief ChibiOS/HAL identification macro.
+ */
+#define _CHIBIOS_HAL_
+
+/**
+ * @brief Stable release flag.
+ */
+#define CH_HAL_STABLE 1
+
+/**
+ * @name ChibiOS/HAL version identification
+ * @{
+ */
+/**
+ * @brief HAL version string.
+ */
+#define HAL_VERSION "7.1.3"
+
+/**
+ * @brief HAL version major number.
+ */
+#define CH_HAL_MAJOR 7
+
+/**
+ * @brief HAL version minor number.
+ */
+#define CH_HAL_MINOR 1
+
+/**
+ * @brief HAL version patch number.
+ */
+#define CH_HAL_PATCH 3
+/** @} */
+
+/**
+ * @name Return codes
+ * @{
+ */
+#define HAL_SUCCESS false
+#define HAL_FAILED true
+/** @} */
+
+/*===========================================================================*/
+/* Driver pre-compile time settings. */
+/*===========================================================================*/
+
+/*===========================================================================*/
+/* Derived constants and error checks. */
+/*===========================================================================*/
+
+/* Configuration file checks.*/
+#if !defined(_CHIBIOS_HAL_CONF_)
+#error "invalid configuration file"
+#endif
+
+#if !defined(_CHIBIOS_HAL_CONF_VER_7_1_)
+#error "obsolete or unknown configuration file"
+#endif
+
+/*===========================================================================*/
+/* Driver data structures and types. */
+/*===========================================================================*/
+
+/*===========================================================================*/
+/* Driver macros. */
+/*===========================================================================*/
+
+/*===========================================================================*/
+/* External declarations. */
+/*===========================================================================*/
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+ void halInit(void);
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* HAL_H */
+
+/** @} */
diff --git a/ChibiOS_20.3.2/os/hal/include/hal_adc.h b/ChibiOS_20.3.2/os/hal/include/hal_adc.h new file mode 100644 index 0000000..8bc3066 --- /dev/null +++ b/ChibiOS_20.3.2/os/hal/include/hal_adc.h @@ -0,0 +1,416 @@ +/*
+ ChibiOS - Copyright (C) 2006..2018 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_adc.h
+ * @brief ADC Driver macros and structures.
+ *
+ * @addtogroup ADC
+ * @{
+ */
+
+#ifndef HAL_ADC_H
+#define HAL_ADC_H
+
+#if (HAL_USE_ADC == TRUE) || defined(__DOXYGEN__)
+
+/*===========================================================================*/
+/* Driver constants. */
+/*===========================================================================*/
+
+/*===========================================================================*/
+/* Driver pre-compile time settings. */
+/*===========================================================================*/
+
+/**
+ * @name ADC configuration options
+ * @{
+ */
+/**
+ * @brief Enables synchronous APIs.
+ * @note Disabling this option saves both code and data space.
+ */
+#if !defined(ADC_USE_WAIT) || defined(__DOXYGEN__)
+#define ADC_USE_WAIT TRUE
+#endif
+
+/**
+ * @brief Enables the @p adcAcquireBus() and @p adcReleaseBus() APIs.
+ * @note Disabling this option saves both code and data space.
+ */
+#if !defined(ADC_USE_MUTUAL_EXCLUSION) || defined(__DOXYGEN__)
+#define ADC_USE_MUTUAL_EXCLUSION TRUE
+#endif
+/** @} */
+
+/*===========================================================================*/
+/* Derived constants and error checks. */
+/*===========================================================================*/
+
+/*===========================================================================*/
+/* Driver data structures and types. */
+/*===========================================================================*/
+
+/**
+ * @brief Driver state machine possible states.
+ */
+typedef enum {
+ ADC_UNINIT = 0, /**< Not initialized. */
+ ADC_STOP = 1, /**< Stopped. */
+ ADC_READY = 2, /**< Ready. */
+ ADC_ACTIVE = 3, /**< Converting. */
+ ADC_COMPLETE = 4, /**< Conversion complete. */
+ ADC_ERROR = 5 /**< Conversion error. */
+} adcstate_t;
+
+/**
+ * @brief Type of a structure representing an ADC driver.
+ */
+typedef struct hal_adc_driver ADCDriver;
+
+/**
+ * @brief Type of a structure representing an ADC driver configuration.
+ */
+typedef struct hal_adc_config ADCConfig;
+
+/**
+ * @brief Conversion group configuration structure.
+ * @details This implementation-dependent structure describes a conversion
+ * operation.
+ * @note The use of this configuration structure requires knowledge of
+ * STM32 ADC cell registers interface, please refer to the STM32
+ * reference manual for details.
+ */
+typedef struct hal_adc_configuration_group ADCConversionGroup;
+
+/* Including the low level driver header, it exports information required
+ for completing types.*/
+#include "hal_adc_lld.h"
+
+/**
+ * @brief Type of an ADC notification callback.
+ *
+ * @param[in] adcp pointer to the @p ADCDriver object triggering the
+ * callback
+ */
+typedef void (*adccallback_t)(ADCDriver *adcp);
+
+/**
+ * @brief Type of an ADC error callback.
+ *
+ * @param[in] adcp pointer to the @p ADCDriver object triggering the
+ * callback
+ * @param[in] err ADC error code
+ */
+typedef void (*adcerrorcallback_t)(ADCDriver *adcp, adcerror_t err);
+
+/**
+ * @brief Conversion group configuration structure.
+ * @details This implementation-dependent structure describes a conversion
+ * operation.
+ * @note The use of this configuration structure requires knowledge of
+ * STM32 ADC cell registers interface, please refer to the STM32
+ * reference manual for details.
+ */
+struct hal_adc_configuration_group {
+ /**
+ * @brief Enables the circular buffer mode for the group.
+ */
+ bool circular;
+ /**
+ * @brief Number of the analog channels belonging to the conversion group.
+ */
+ adc_channels_num_t num_channels;
+ /**
+ * @brief Callback function associated to the group or @p NULL.
+ */
+ adccallback_t end_cb;
+ /**
+ * @brief Error callback or @p NULL.
+ */
+ adcerrorcallback_t error_cb;
+ /* End of the mandatory fields.*/
+ adc_lld_configuration_group_fields;
+};
+
+/**
+ * @brief Driver configuration structure.
+ */
+struct hal_adc_config {
+ /* End of the mandatory fields.*/
+ adc_lld_config_fields;
+};
+
+/**
+ * @brief Structure representing an ADC driver.
+ */
+struct hal_adc_driver {
+ /**
+ * @brief Driver state.
+ */
+ adcstate_t state;
+ /**
+ * @brief Current configuration data.
+ */
+ const ADCConfig *config;
+ /**
+ * @brief Current samples buffer pointer or @p NULL.
+ */
+ adcsample_t *samples;
+ /**
+ * @brief Current samples buffer depth or @p 0.
+ */
+ size_t depth;
+ /**
+ * @brief Current conversion group pointer or @p NULL.
+ */
+ const ADCConversionGroup *grpp;
+#if (ADC_USE_WAIT == TRUE) || defined(__DOXYGEN__)
+ /**
+ * @brief Waiting thread.
+ */
+ thread_reference_t thread;
+#endif /* ADC_USE_WAIT == TRUE */
+#if (ADC_USE_MUTUAL_EXCLUSION == TRUE) || defined(__DOXYGEN__)
+ /**
+ * @brief Mutex protecting the peripheral.
+ */
+ mutex_t mutex;
+#endif /* ADC_USE_MUTUAL_EXCLUSION == TRUE */
+#if defined(ADC_DRIVER_EXT_FIELDS)
+ ADC_DRIVER_EXT_FIELDS
+#endif
+ /* End of the mandatory fields.*/
+ adc_lld_driver_fields;
+};
+
+/*===========================================================================*/
+/* Driver macros. */
+/*===========================================================================*/
+
+/**
+ * @name Macro Functions
+ * @{
+ */
+/**
+ * @brief Buffer state.
+ * @note This function is meant to be called from the ADC callback only.
+ *
+ * @param[in] adcp pointer to the @p ADCDriver object
+ * @return The buffer state.
+ * @retval false if the driver filled/sent the first half of the
+ * buffer.
+ * @retval true if the driver filled/sent the second half of the
+ * buffer.
+ *
+ * @special
+ */
+#define adcIsBufferComplete(adcp) ((bool)((adcp)->state == ADC_COMPLETE))
+/** @} */
+
+/**
+ * @name Low level driver helper macros
+ * @{
+ */
+#if (ADC_USE_WAIT == TRUE) || defined(__DOXYGEN__)
+/**
+ * @brief Resumes a thread waiting for a conversion completion.
+ *
+ * @param[in] adcp pointer to the @p ADCDriver object
+ *
+ * @notapi
+ */
+#define _adc_reset_i(adcp) \
+ osalThreadResumeI(&(adcp)->thread, MSG_RESET)
+
+/**
+ * @brief Resumes a thread waiting for a conversion completion.
+ *
+ * @param[in] adcp pointer to the @p ADCDriver object
+ *
+ * @notapi
+ */
+#define _adc_reset_s(adcp) \
+ osalThreadResumeS(&(adcp)->thread, MSG_RESET)
+
+/**
+ * @brief Wakes up the waiting thread.
+ *
+ * @param[in] adcp pointer to the @p ADCDriver object
+ *
+ * @notapi
+ */
+#define _adc_wakeup_isr(adcp) { \
+ osalSysLockFromISR(); \
+ osalThreadResumeI(&(adcp)->thread, MSG_OK); \
+ osalSysUnlockFromISR(); \
+}
+
+/**
+ * @brief Wakes up the waiting thread with a timeout message.
+ *
+ * @param[in] adcp pointer to the @p ADCDriver object
+ *
+ * @notapi
+ */
+#define _adc_timeout_isr(adcp) { \
+ osalSysLockFromISR(); \
+ osalThreadResumeI(&(adcp)->thread, MSG_TIMEOUT); \
+ osalSysUnlockFromISR(); \
+}
+
+#else /* !ADC_USE_WAIT */
+#define _adc_reset_i(adcp)
+#define _adc_reset_s(adcp)
+#define _adc_wakeup_isr(adcp)
+#define _adc_timeout_isr(adcp)
+#endif /* !ADC_USE_WAIT */
+
+/**
+ * @brief Common ISR code, half buffer event.
+ * @details This code handles the portable part of the ISR code:
+ * - Callback invocation.
+ * .
+ * @note This macro is meant to be used in the low level drivers
+ * implementation only.
+ *
+ * @param[in] adcp pointer to the @p ADCDriver object
+ *
+ * @notapi
+ */
+#define _adc_isr_half_code(adcp) { \
+ if ((adcp)->grpp->end_cb != NULL) { \
+ (adcp)->grpp->end_cb(adcp); \
+ } \
+}
+
+/**
+ * @brief Common ISR code, full buffer event.
+ * @details This code handles the portable part of the ISR code:
+ * - Callback invocation.
+ * - Waiting thread wakeup, if any.
+ * - Driver state transitions.
+ * .
+ * @note This macro is meant to be used in the low level drivers
+ * implementation only.
+ *
+ * @param[in] adcp pointer to the @p ADCDriver object
+ *
+ * @notapi
+ */
+#define _adc_isr_full_code(adcp) { \
+ if ((adcp)->grpp->circular) { \
+ /* Callback handling.*/ \
+ if ((adcp)->grpp->end_cb != NULL) { \
+ (adcp)->state = ADC_COMPLETE; \
+ (adcp)->grpp->end_cb(adcp); \
+ if ((adcp)->state == ADC_COMPLETE) { \
+ (adcp)->state = ADC_ACTIVE; \
+ } \
+ } \
+ } \
+ else { \
+ /* End conversion.*/ \
+ adc_lld_stop_conversion(adcp); \
+ if ((adcp)->grpp->end_cb != NULL) { \
+ (adcp)->state = ADC_COMPLETE; \
+ (adcp)->grpp->end_cb(adcp); \
+ if ((adcp)->state == ADC_COMPLETE) { \
+ (adcp)->state = ADC_READY; \
+ (adcp)->grpp = NULL; \
+ } \
+ } \
+ else { \
+ (adcp)->state = ADC_READY; \
+ (adcp)->grpp = NULL; \
+ } \
+ _adc_wakeup_isr(adcp); \
+ } \
+}
+
+/**
+ * @brief Common ISR code, error event.
+ * @details This code handles the portable part of the ISR code:
+ * - Callback invocation.
+ * - Waiting thread timeout signaling, if any.
+ * - Driver state transitions.
+ * .
+ * @note This macro is meant to be used in the low level drivers
+ * implementation only.
+ *
+ * @param[in] adcp pointer to the @p ADCDriver object
+ * @param[in] err platform dependent error code
+ *
+ * @notapi
+ */
+#define _adc_isr_error_code(adcp, err) { \
+ adc_lld_stop_conversion(adcp); \
+ if ((adcp)->grpp->error_cb != NULL) { \
+ (adcp)->state = ADC_ERROR; \
+ (adcp)->grpp->error_cb(adcp, err); \
+ if ((adcp)->state == ADC_ERROR) { \
+ (adcp)->state = ADC_READY; \
+ (adcp)->grpp = NULL; \
+ } \
+ } \
+ else { \
+ (adcp)->state = ADC_READY; \
+ (adcp)->grpp = NULL; \
+ } \
+ _adc_timeout_isr(adcp); \
+}
+/** @} */
+
+/*===========================================================================*/
+/* External declarations. */
+/*===========================================================================*/
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+ void adcInit(void);
+ void adcObjectInit(ADCDriver *adcp);
+ void adcStart(ADCDriver *adcp, const ADCConfig *config);
+ void adcStop(ADCDriver *adcp);
+ void adcStartConversion(ADCDriver *adcp,
+ const ADCConversionGroup *grpp,
+ adcsample_t *samples,
+ size_t depth);
+ void adcStartConversionI(ADCDriver *adcp,
+ const ADCConversionGroup *grpp,
+ adcsample_t *samples,
+ size_t depth);
+ void adcStopConversion(ADCDriver *adcp);
+ void adcStopConversionI(ADCDriver *adcp);
+#if ADC_USE_WAIT == TRUE
+ msg_t adcConvert(ADCDriver *adcp,
+ const ADCConversionGroup *grpp,
+ adcsample_t *samples,
+ size_t depth);
+#endif
+#if ADC_USE_MUTUAL_EXCLUSION == TRUE
+ void adcAcquireBus(ADCDriver *adcp);
+ void adcReleaseBus(ADCDriver *adcp);
+#endif
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* HAL_USE_ADC == TRUE */
+
+#endif /* HAL_ADC_H */
+
+/** @} */
diff --git a/ChibiOS_20.3.2/os/hal/include/hal_buffers.h b/ChibiOS_20.3.2/os/hal/include/hal_buffers.h new file mode 100644 index 0000000..200c1b2 --- /dev/null +++ b/ChibiOS_20.3.2/os/hal/include/hal_buffers.h @@ -0,0 +1,345 @@ +/*
+ ChibiOS - Copyright (C) 2006..2018 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_buffers.h
+ * @brief I/O Buffers macros and structures.
+ *
+ * @addtogroup HAL_BUFFERS
+ * @{
+ */
+
+#ifndef HAL_BUFFERS_H
+#define HAL_BUFFERS_H
+
+/*===========================================================================*/
+/* Driver constants. */
+/*===========================================================================*/
+
+/*===========================================================================*/
+/* Driver pre-compile time settings. */
+/*===========================================================================*/
+
+/**
+ * @brief Maximum size of blocks copied in critical sections.
+ * @note Increasing this value increases performance at expense of
+ * IRQ servicing efficiency.
+ * @note It must be a power of two.
+ */
+#if !defined(BUFFERS_CHUNKS_SIZE) || defined(__DOXYGEN__)
+#define BUFFERS_CHUNKS_SIZE 64
+#endif
+
+/*===========================================================================*/
+/* Derived constants and error checks. */
+/*===========================================================================*/
+
+/*lint -save -e9027 [10.1] It is meant to be this way, not an error.*/
+#if (BUFFERS_CHUNKS_SIZE & (BUFFERS_CHUNKS_SIZE - 1)) != 0
+/*lint -restore*/
+#error "BUFFERS_CHUNKS_SIZE must be a power of two"
+#endif
+
+/*===========================================================================*/
+/* Driver data structures and types. */
+/*===========================================================================*/
+
+/**
+ * @brief Type of a generic queue of buffers.
+ */
+typedef struct io_buffers_queue io_buffers_queue_t;
+
+/**
+ * @brief Double buffer notification callback type.
+ *
+ * @param[in] iodbp the buffers queue pointer
+ */
+typedef void (*bqnotify_t)(io_buffers_queue_t *bqp);
+
+/**
+ * @brief Structure of a generic buffers queue.
+ */
+struct io_buffers_queue {
+ /**
+ * @brief Queue of waiting threads.
+ */
+ threads_queue_t waiting;
+ /**
+ * @brief Queue suspended state flag.
+ */
+ bool suspended;
+ /**
+ * @brief Active buffers counter.
+ */
+ volatile size_t bcounter;
+ /**
+ * @brief Buffer write pointer.
+ */
+ uint8_t *bwrptr;
+ /**
+ * @brief Buffer read pointer.
+ */
+ uint8_t *brdptr;
+ /**
+ * @brief Pointer to the buffers boundary.
+ */
+ uint8_t *btop;
+ /**
+ * @brief Size of buffers.
+ * @note The buffer size must be not lower than <tt>sizeof(size_t) + 2</tt>
+ * because the first bytes are used to store the used size of the
+ * buffer.
+ */
+ size_t bsize;
+ /**
+ * @brief Number of buffers.
+ */
+ size_t bn;
+ /**
+ * @brief Queue of buffer objects.
+ */
+ uint8_t *buffers;
+ /**
+ * @brief Pointer for R/W sequential access.
+ * @note It is @p NULL if a new buffer must be fetched from the queue.
+ */
+ uint8_t *ptr;
+ /**
+ * @brief Boundary for R/W sequential access.
+ */
+ uint8_t *top;
+ /**
+ * @brief Data notification callback.
+ */
+ bqnotify_t notify;
+ /**
+ * @brief Application defined field.
+ */
+ void *link;
+};
+
+/**
+ * @brief Type of an input buffers queue.
+ */
+typedef io_buffers_queue_t input_buffers_queue_t;
+
+/**
+ * @brief Type of an output buffers queue.
+ */
+typedef io_buffers_queue_t output_buffers_queue_t;
+
+/*===========================================================================*/
+/* Driver macros. */
+/*===========================================================================*/
+
+/**
+ * @brief Computes the size of a buffers queue buffer size.
+ *
+ * @param[in] n number of buffers in the queue
+ * @param[in] size size of the buffers
+ */
+#define BQ_BUFFER_SIZE(n, size) \
+ (((size_t)(size) + sizeof (size_t)) * (size_t)(n))
+
+/**
+ * @name Macro Functions
+ * @{
+ */
+/**
+ * @brief Returns the queue's number of buffers.
+ *
+ * @param[in] bqp pointer to an @p io_buffers_queue_t structure
+ * @return The number of buffers.
+ *
+ * @xclass
+ */
+#define bqSizeX(bqp) ((bqp)->bn)
+
+/**
+ * @brief Return the ready buffers number.
+ * @details Returns the number of filled buffers if used on an input queue
+ * or the number of empty buffers if used on an output queue.
+ *
+ * @param[in] bqp pointer to an @p io_buffers_queue_t structure
+ * @return The number of ready buffers.
+ *
+ * @iclass
+ */
+#define bqSpaceI(bqp) ((bqp)->bcounter)
+
+/**
+ * @brief Returns the queue application-defined link.
+ *
+ * @param[in] bqp pointer to an @p io_buffers_queue_t structure
+ * @return The application-defined link.
+ *
+ * @special
+ */
+#define bqGetLinkX(bqp) ((bqp)->link)
+
+/**
+ * @brief Sets the queue application-defined link.
+ *
+ * @param[in] bqp pointer to an @p io_buffers_queue_t structure
+ * @param[in] lk The application-defined link.
+ *
+ * @special
+ */
+#define bqSetLinkX(bqp, lk) ((bqp)->link = lk)
+
+/**
+ * @brief Return the suspended state of the queue.
+ *
+ * @param[in] bqp pointer to an @p io_buffers_queue_t structure
+ * @return The suspended state.
+ * @retval false if blocking access to the queue is enabled.
+ * @retval true if blocking access to the queue is suspended.
+ *
+ * @xclass
+ */
+#define bqIsSuspendedX(bqp) ((bqp)->suspended)
+
+/**
+ * @brief Puts the queue in suspended state.
+ * @details When the queue is put in suspended state all waiting threads are
+ * woken with message @p MSG_RESET and subsequent attempt at waiting
+ * on the queue will result in an immediate return with @p MSG_RESET
+ * message.
+ * @note The content of the queue is not altered, queues can be accessed
+ * is suspended state until a blocking operation is met then a
+ * @p MSG_RESET occurs.
+ *
+ * @param[in] bqp pointer to an @p io_buffers_queue_t structure
+ *
+ * @iclass
+ */
+#define bqSuspendI(bqp) { \
+ (bqp)->suspended = true; \
+ osalThreadDequeueAllI(&(bqp)->waiting, MSG_RESET); \
+}
+
+/**
+ * @brief Resumes normal queue operations.
+ *
+ * @param[in] bqp pointer to an @p io_buffers_queue_t structure
+ *
+ * @xclass
+ */
+#define bqResumeX(bqp) { \
+ (bqp)->suspended = false; \
+}
+
+/**
+ * @brief Evaluates to @p true if the specified input buffers queue is empty.
+ *
+ * @param[in] ibqp pointer to an @p input_buffers_queue_t structure
+ * @return The queue status.
+ * @retval false if the queue is not empty.
+ * @retval true if the queue is empty.
+ *
+ * @iclass
+ */
+#define ibqIsEmptyI(ibqp) ((bool)(bqSpaceI(ibqp) == 0U))
+
+/**
+ * @brief Evaluates to @p true if the specified input buffers queue is full.
+ *
+ * @param[in] ibqp pointer to an @p input_buffers_queue_t structure
+ * @return The queue status.
+ * @retval false if the queue is not full.
+ * @retval true if the queue is full.
+ *
+ * @iclass
+ */
+#define ibqIsFullI(ibqp) \
+ /*lint -save -e9007 [13.5] No side effects, a pointer is passed.*/ \
+ ((bool)(((ibqp)->bwrptr == (ibqp)->brdptr) && ((ibqp)->bcounter != 0U))) \
+ /*lint -restore*/
+
+/**
+ * @brief Evaluates to @p true if the specified output buffers queue is empty.
+ *
+ * @param[in] obqp pointer to an @p output_buffers_queue_t structure
+ * @return The queue status.
+ * @retval false if the queue is not empty.
+ * @retval true if the queue is empty.
+ *
+ * @iclass
+ */
+#define obqIsEmptyI(obqp) \
+ /*lint -save -e9007 [13.5] No side effects, a pointer is passed.*/ \
+ ((bool)(((obqp)->bwrptr == (obqp)->brdptr) && ((obqp)->bcounter != 0U))) \
+ /*lint -restore*/
+
+/**
+ * @brief Evaluates to @p true if the specified output buffers queue is full.
+ *
+ * @param[in] obqp pointer to an @p output_buffers_queue_t structure
+ * @return The queue status.
+ * @retval false if the queue is not full.
+ * @retval true if the queue is full.
+ *
+ * @iclass
+ */
+#define obqIsFullI(obqp) ((bool)(bqSpaceI(obqp) == 0U))
+/** @} */
+
+/*===========================================================================*/
+/* External declarations. */
+/*===========================================================================*/
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+ void ibqObjectInit(input_buffers_queue_t *ibqp, bool suspended, uint8_t *bp,
+ size_t size, size_t n, bqnotify_t infy, void *link);
+ void ibqResetI(input_buffers_queue_t *ibqp);
+ uint8_t *ibqGetEmptyBufferI(input_buffers_queue_t *ibqp);
+ void ibqPostFullBufferI(input_buffers_queue_t *ibqp, size_t size);
+ msg_t ibqGetFullBufferTimeout(input_buffers_queue_t *ibqp,
+ sysinterval_t timeout);
+ msg_t ibqGetFullBufferTimeoutS(input_buffers_queue_t *ibqp,
+ sysinterval_t timeout);
+ void ibqReleaseEmptyBuffer(input_buffers_queue_t *ibqp);
+ void ibqReleaseEmptyBufferS(input_buffers_queue_t *ibqp);
+ msg_t ibqGetTimeout(input_buffers_queue_t *ibqp, sysinterval_t timeout);
+ size_t ibqReadTimeout(input_buffers_queue_t *ibqp, uint8_t *bp,
+ size_t n, sysinterval_t timeout);
+ void obqObjectInit(output_buffers_queue_t *obqp, bool suspended, uint8_t *bp,
+ size_t size, size_t n, bqnotify_t onfy, void *link);
+ void obqResetI(output_buffers_queue_t *obqp);
+ uint8_t *obqGetFullBufferI(output_buffers_queue_t *obqp,
+ size_t *sizep);
+ void obqReleaseEmptyBufferI(output_buffers_queue_t *obqp);
+ msg_t obqGetEmptyBufferTimeout(output_buffers_queue_t *obqp,
+ sysinterval_t timeout);
+ msg_t obqGetEmptyBufferTimeoutS(output_buffers_queue_t *obqp,
+ sysinterval_t timeout);
+ void obqPostFullBuffer(output_buffers_queue_t *obqp, size_t size);
+ void obqPostFullBufferS(output_buffers_queue_t *obqp, size_t size);
+ msg_t obqPutTimeout(output_buffers_queue_t *obqp, uint8_t b,
+ sysinterval_t timeout);
+ size_t obqWriteTimeout(output_buffers_queue_t *obqp, const uint8_t *bp,
+ size_t n, sysinterval_t timeout);
+ bool obqTryFlushI(output_buffers_queue_t *obqp);
+ void obqFlush(output_buffers_queue_t *obqp);
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* HAL_BUFFERS_H */
+
+/** @} */
diff --git a/ChibiOS_20.3.2/os/hal/include/hal_can.h b/ChibiOS_20.3.2/os/hal/include/hal_can.h new file mode 100644 index 0000000..baf5b56 --- /dev/null +++ b/ChibiOS_20.3.2/os/hal/include/hal_can.h @@ -0,0 +1,257 @@ +/*
+ ChibiOS - Copyright (C) 2006..2018 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_can.h
+ * @brief CAN Driver macros and structures.
+ *
+ * @addtogroup CAN
+ * @{
+ */
+
+#ifndef HAL_CAN_H
+#define HAL_CAN_H
+
+#if (HAL_USE_CAN == TRUE) || defined(__DOXYGEN__)
+
+/*===========================================================================*/
+/* Driver constants. */
+/*===========================================================================*/
+
+/**
+ * @name CAN status flags
+ * @{
+ */
+/**
+ * @brief Errors rate warning.
+ */
+#define CAN_LIMIT_WARNING 1U
+/**
+ * @brief Errors rate error.
+ */
+#define CAN_LIMIT_ERROR 2U
+/**
+ * @brief Bus off condition reached.
+ */
+#define CAN_BUS_OFF_ERROR 4U
+/**
+ * @brief Framing error of some kind on the CAN bus.
+ */
+#define CAN_FRAMING_ERROR 8U
+/**
+ * @brief Overflow in receive queue.
+ */
+#define CAN_OVERFLOW_ERROR 16U
+/** @} */
+
+/**
+ * @brief Special mailbox identifier.
+ */
+#define CAN_ANY_MAILBOX 0U
+
+/*===========================================================================*/
+/* Driver pre-compile time settings. */
+/*===========================================================================*/
+
+/**
+ * @name CAN configuration options
+ * @{
+ */
+/**
+ * @brief Sleep mode related APIs inclusion switch.
+ * @details This option can only be enabled if the CAN implementation supports
+ * the sleep mode, see the macro @p CAN_SUPPORTS_SLEEP exported by
+ * the underlying implementation.
+ */
+#if !defined(CAN_USE_SLEEP_MODE) || defined(__DOXYGEN__)
+#define CAN_USE_SLEEP_MODE TRUE
+#endif
+
+/**
+ * @brief Enforces the driver to use direct callbacks rather than OSAL events.
+ */
+#if !defined(CAN_ENFORCE_USE_CALLBACKS) || defined(__DOXYGEN__)
+#define CAN_ENFORCE_USE_CALLBACKS FALSE
+#endif
+/** @} */
+
+/*===========================================================================*/
+/* Derived constants and error checks. */
+/*===========================================================================*/
+
+/*===========================================================================*/
+/* Driver data structures and types. */
+/*===========================================================================*/
+
+/**
+ * @brief Driver state machine possible states.
+ */
+typedef enum {
+ CAN_UNINIT = 0, /**< Not initialized. */
+ CAN_STOP = 1, /**< Stopped. */
+ CAN_STARTING = 2, /**< Starting. */
+ CAN_STOPPING = 3, /**< Stopping. */
+ CAN_READY = 4, /**< Ready. */
+ CAN_SLEEP = 5 /**< Sleep state. */
+} canstate_t;
+
+#include "hal_can_lld.h"
+
+/*===========================================================================*/
+/* Driver macros. */
+/*===========================================================================*/
+
+/**
+ * @name Macro Functions
+ * @{
+ */
+/**
+ * @brief Converts a mailbox index to a bit mask.
+ */
+#define CAN_MAILBOX_TO_MASK(mbx) (1U << ((mbx) - 1U))
+
+/**
+ * @brief Legacy name for @p canTransmitTimeout().
+ *
+ * @deprecated
+ */
+#define canTransmit(canp, mailbox, ctfp, timeout) \
+ canTransmitTimeout(canp, mailbox, ctfp, timeout)
+
+/**
+ * @brief Legacy name for @p canReceiveTimeout().
+ *
+ * @deprecated
+ */
+#define canReceive(canp, mailbox, crfp, timeout) \
+ canReceiveTimeout(canp, mailbox, crfp, timeout)
+/** @} */
+
+/**
+ * @name Low level driver helper macros
+ * @{
+ */
+#if (CAN_ENFORCE_USE_CALLBACKS == FALSE) || defined(__DOXYGEN__)
+/**
+ * @brief TX mailbox empty event.
+ */
+#define _can_tx_empty_isr(canp, flags) { \
+ osalSysLockFromISR(); \
+ osalThreadDequeueAllI(&(canp)->txqueue, MSG_OK); \
+ osalEventBroadcastFlagsI(&(canp)->txempty_event, flags); \
+ osalSysUnlockFromISR(); \
+}
+
+/**
+ * @brief RX mailbox empty full event.
+ */
+#define _can_rx_full_isr(canp, flags) { \
+ osalSysLockFromISR(); \
+ osalThreadDequeueAllI(&(canp)->rxqueue, MSG_OK); \
+ osalEventBroadcastFlagsI(&(canp)->rxfull_event, flags); \
+ osalSysUnlockFromISR(); \
+}
+
+/**
+ * @brief Wakeup event.
+ */
+#define _can_wakeup_isr(canp) { \
+ osalSysLockFromISR(); \
+ osalEventBroadcastFlagsI(&(canp)->wakeup_event, 0U); \
+ osalSysUnlockFromISR(); \
+}
+
+/**
+ * @brief Error event.
+ */
+#define _can_error_isr(canp, flags) { \
+ osalSysLockFromISR(); \
+ osalEventBroadcastFlagsI(&(canp)->error_event, flags); \
+ osalSysUnlockFromISR(); \
+}
+#else /* CAN_ENFORCE_USE_CALLBACKS == TRUE */
+#define _can_tx_empty_isr(canp, flags) { \
+ if ((canp)->txempty_cb != NULL) { \
+ (canp)->txempty_cb(canp, flags); \
+ } \
+ osalSysLockFromISR(); \
+ osalThreadDequeueAllI(&(canp)->txqueue, MSG_OK); \
+ osalSysUnlockFromISR(); \
+}
+
+#define _can_rx_full_isr(canp, flags) { \
+ if ((canp)->rxfull_cb != NULL) { \
+ (canp)->rxfull_cb(canp, flags); \
+ } \
+ osalSysLockFromISR(); \
+ osalThreadDequeueAllI(&(canp)->rxqueue, MSG_OK); \
+ osalSysUnlockFromISR(); \
+}
+
+#define _can_wakeup_isr(canp) { \
+ if ((canp)->wakeup_cb != NULL) { \
+ (canp)->wakeup_cb(canp, 0U); \
+ } \
+}
+
+#define _can_error_isr(canp, flags) { \
+ if ((canp)->error_cb != NULL) { \
+ (canp)->error_cb(canp, flags); \
+ } \
+}
+#endif /* CAN_ENFORCE_USE_CALLBACKS == TRUE */
+/** @} */
+
+/*===========================================================================*/
+/* External declarations. */
+/*===========================================================================*/
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+ void canInit(void);
+ void canObjectInit(CANDriver *canp);
+ void canStart(CANDriver *canp, const CANConfig *config);
+ void canStop(CANDriver *canp);
+ bool canTryTransmitI(CANDriver *canp,
+ canmbx_t mailbox,
+ const CANTxFrame *ctfp);
+ bool canTryReceiveI(CANDriver *canp,
+ canmbx_t mailbox,
+ CANRxFrame *crfp);
+ void canTryAbortX(CANDriver *canp,
+ canmbx_t mailbox);
+ msg_t canTransmitTimeout(CANDriver *canp,
+ canmbx_t mailbox,
+ const CANTxFrame *ctfp,
+ sysinterval_t timeout);
+ msg_t canReceiveTimeout(CANDriver *canp,
+ canmbx_t mailbox,
+ CANRxFrame *crfp,
+ sysinterval_t timeout);
+#if CAN_USE_SLEEP_MODE
+ void canSleep(CANDriver *canp);
+ void canWakeup(CANDriver *canp);
+#endif
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* HAL_USE_CAN == TRUE */
+
+#endif /* HAL_CAN_H */
+
+/** @} */
diff --git a/ChibiOS_20.3.2/os/hal/include/hal_channels.h b/ChibiOS_20.3.2/os/hal/include/hal_channels.h new file mode 100644 index 0000000..1ef25b0 --- /dev/null +++ b/ChibiOS_20.3.2/os/hal/include/hal_channels.h @@ -0,0 +1,315 @@ +/*
+ ChibiOS - Copyright (C) 2006..2018 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_channels.h
+ * @brief I/O channels access.
+ * @details This header defines an abstract interface useful to access generic
+ * I/O serial devices in a standardized way.
+ *
+ * @addtogroup IO_CHANNEL
+ * @details This module defines an abstract interface for I/O channels by
+ * extending the @p BaseSequentialStream interface.<br>
+ * Note that no code is present, I/O channels are just abstract
+ * interface like structures, you should look at the systems as
+ * to a set of abstract C++ classes (even if written in C).
+ * Specific device drivers can use/extend the interface and
+ * implement them.<br>
+ * This system has the advantage to make the access to channels
+ * independent from the implementation logic.
+ * @{
+ */
+
+#ifndef HAL_CHANNELS_H
+#define HAL_CHANNELS_H
+
+/**
+ * @name Default control operation codes.
+ * @{
+ */
+#define CHN_CTL_INVALID 0 /** @brief Invalid operation code. */
+#define CHN_CTL_NOP 1 /** @brief Does nothing. */
+#define CHN_CTL_TX_WAIT 2 /** @brief Wait for TX completion. */
+/** @} */
+
+/**
+ * @brief @p BaseChannel specific methods.
+ */
+#define _base_channel_methods \
+ _base_sequential_stream_methods \
+ /* Channel put method with timeout specification.*/ \
+ msg_t (*putt)(void *instance, uint8_t b, sysinterval_t time); \
+ /* Channel get method with timeout specification.*/ \
+ msg_t (*gett)(void *instance, sysinterval_t time); \
+ /* Channel write method with timeout specification.*/ \
+ size_t (*writet)(void *instance, const uint8_t *bp, \
+ size_t n, sysinterval_t time); \
+ /* Channel read method with timeout specification.*/ \
+ size_t (*readt)(void *instance, uint8_t *bp, size_t n, \
+ sysinterval_t time); \
+ /* Channel control method.*/ \
+ msg_t (*ctl)(void *instance, unsigned int operation, void *arg);
+
+/**
+ * @brief @p BaseChannel specific data.
+ * @note It is empty because @p BaseChannel is only an interface without
+ * implementation.
+ */
+#define _base_channel_data \
+ _base_sequential_stream_data
+
+/**
+ * @extends BaseSequentialStreamVMT
+ *
+ * @brief @p BaseChannel virtual methods table.
+ */
+struct BaseChannelVMT {
+ _base_channel_methods
+};
+
+/**
+ * @extends BaseSequentialStream
+ *
+ * @brief Base channel class.
+ * @details This class represents a generic, byte-wide, I/O channel. This class
+ * introduces generic I/O primitives with timeout specification.
+ */
+typedef struct {
+ /** @brief Virtual Methods Table.*/
+ const struct BaseChannelVMT *vmt;
+ _base_channel_data
+} BaseChannel;
+
+/**
+ * @name Macro Functions (BaseChannel)
+ * @{
+ */
+/**
+ * @brief Channel blocking byte write with timeout.
+ * @details This function writes a byte value to a channel. If the channel
+ * is not ready to accept data then the calling thread is suspended.
+ *
+ * @param[in] ip pointer to a @p BaseChannel or derived class
+ * @param[in] b the byte value to be written to the channel
+ * @param[in] time the number of ticks before the operation timeouts,
+ * the following special values are allowed:
+ * - @a TIME_IMMEDIATE immediate timeout.
+ * - @a TIME_INFINITE no timeout.
+ * .
+ * @return The operation status.
+ * @retval STM_OK if the operation succeeded.
+ * @retval STM_TIMEOUT if the specified time expired.
+ * @retval STM_RESET if the channel associated queue (if any) was reset.
+ *
+ * @api
+ */
+#define chnPutTimeout(ip, b, time) ((ip)->vmt->putt(ip, b, time))
+
+/**
+ * @brief Channel blocking byte read with timeout.
+ * @details This function reads a byte value from a channel. If the data
+ * is not available then the calling thread is suspended.
+ *
+ * @param[in] ip pointer to a @p BaseChannel or derived class
+ * @param[in] time the number of ticks before the operation timeouts,
+ * the following special values are allowed:
+ * - @a TIME_IMMEDIATE immediate timeout.
+ * - @a TIME_INFINITE no timeout.
+ * .
+ * @return A byte value from the queue.
+ * @retval STM_TIMEOUT if the specified time expired.
+ * @retval STM_RESET if the channel associated queue (if any) has been
+ * reset.
+ *
+ * @api
+ */
+#define chnGetTimeout(ip, time) ((ip)->vmt->gett(ip, time))
+
+/**
+ * @brief Channel blocking write.
+ * @details The function writes data from a buffer to a channel. If the channel
+ * is not ready to accept data then the calling thread is suspended.
+ *
+ * @param[in] ip pointer to a @p BaseChannel or derived class
+ * @param[out] bp pointer to the data buffer
+ * @param[in] n the maximum amount of data to be transferred
+ *
+ * @return The number of bytes transferred.
+ *
+ * @api
+ */
+#define chnWrite(ip, bp, n) streamWrite(ip, bp, n)
+
+/**
+ * @brief Channel blocking write with timeout.
+ * @details The function writes data from a buffer to a channel. If the channel
+ * is not ready to accept data then the calling thread is suspended.
+ *
+ * @param[in] ip pointer to a @p BaseChannel or derived class
+ * @param[out] bp pointer to the data buffer
+ * @param[in] n the maximum amount of data to be transferred
+ * @param[in] time the number of ticks before the operation timeouts,
+ * the following special values are allowed:
+ * - @a TIME_IMMEDIATE immediate timeout.
+ * - @a TIME_INFINITE no timeout.
+ * .
+ * @return The number of bytes transferred.
+ *
+ * @api
+ */
+#define chnWriteTimeout(ip, bp, n, time) ((ip)->vmt->writet(ip, bp, n, time))
+
+/**
+ * @brief Channel blocking read.
+ * @details The function reads data from a channel into a buffer. If the data
+ * is not available then the calling thread is suspended.
+ *
+ * @param[in] ip pointer to a @p BaseChannel or derived class
+ * @param[in] bp pointer to the data buffer
+ * @param[in] n the maximum amount of data to be transferred
+ *
+ * @return The number of bytes transferred.
+ *
+ * @api
+ */
+#define chnRead(ip, bp, n) streamRead(ip, bp, n)
+
+/**
+ * @brief Channel blocking read with timeout.
+ * @details The function reads data from a channel into a buffer. If the data
+ * is not available then the calling thread is suspended.
+ *
+ * @param[in] ip pointer to a @p BaseChannel or derived class
+ * @param[in] bp pointer to the data buffer
+ * @param[in] n the maximum amount of data to be transferred
+ * @param[in] time the number of ticks before the operation timeouts,
+ * the following special values are allowed:
+ * - @a TIME_IMMEDIATE immediate timeout.
+ * - @a TIME_INFINITE no timeout.
+ * .
+ * @return The number of bytes transferred.
+ *
+ * @api
+ */
+#define chnReadTimeout(ip, bp, n, time) ((ip)->vmt->readt(ip, bp, n, time))
+
+/**
+ * @brief Control operation on a channel.
+ *
+ * @param[in] ip pointer to a @p BaseChannel or derived class
+ * @param[in] operation control operation code
+ * @param[in,out] arg operation argument
+ *
+ * @return The control operation status.
+ * @retval MSG_OK in case of success.
+ * @retval MSG_TIMEOUT in case of operation timeout.
+ * @retval MSG_RESET in case of operation reset.
+ *
+ * @api
+ */
+#define chnControl(ip, operation, arg) ((ip)->vmt->ctl(ip, operation, arg))
+/** @} */
+
+/**
+ * @name I/O status flags added to the event listener
+ * @{
+ */
+/** @brief No pending conditions.*/
+#define CHN_NO_ERROR (eventflags_t)0
+/** @brief Connection happened.*/
+#define CHN_CONNECTED (eventflags_t)1
+/** @brief Disconnection happened.*/
+#define CHN_DISCONNECTED (eventflags_t)2
+/** @brief Data available in the input queue.*/
+#define CHN_INPUT_AVAILABLE (eventflags_t)4
+/** @brief Output queue empty.*/
+#define CHN_OUTPUT_EMPTY (eventflags_t)8
+/** @brief Transmission end.*/
+#define CHN_TRANSMISSION_END (eventflags_t)16
+/** @} */
+
+/**
+ * @brief @p BaseAsynchronousChannel specific methods.
+ */
+#define _base_asynchronous_channel_methods \
+ _base_channel_methods \
+
+/**
+ * @brief @p BaseAsynchronousChannel specific data.
+ */
+#define _base_asynchronous_channel_data \
+ _base_channel_data \
+ /* I/O condition event source.*/ \
+ event_source_t event;
+
+/**
+ * @extends BaseChannelVMT
+ *
+ * @brief @p BaseAsynchronousChannel virtual methods table.
+ */
+struct BaseAsynchronousChannelVMT {
+ _base_asynchronous_channel_methods
+};
+
+/**
+ * @extends BaseChannel
+ *
+ * @brief Base asynchronous channel class.
+ * @details This class extends @p BaseChannel by adding event sources fields
+ * for asynchronous I/O for use in an event-driven environment.
+ */
+typedef struct {
+ /** @brief Virtual Methods Table.*/
+ const struct BaseAsynchronousChannelVMT *vmt;
+ _base_asynchronous_channel_data
+} BaseAsynchronousChannel;
+
+/**
+ * @name Macro Functions (BaseAsynchronousChannel)
+ * @{
+ */
+/**
+ * @brief Returns the I/O condition event source.
+ * @details The event source is broadcasted when an I/O condition happens.
+ *
+ * @param[in] ip pointer to a @p BaseAsynchronousChannel or derived
+ * class
+ * @return A pointer to an @p EventSource object.
+ *
+ * @api
+ */
+#define chnGetEventSource(ip) (&((ip)->event))
+
+/**
+ * @brief Adds status flags to the listeners's flags mask.
+ * @details This function is usually called from the I/O ISRs in order to
+ * notify I/O conditions such as data events, errors, signal
+ * changes etc.
+ *
+ * @param[in] ip pointer to a @p BaseAsynchronousChannel or derived
+ * class
+ * @param[in] flags condition flags to be added to the listener flags mask
+ *
+ * @iclass
+ */
+#define chnAddFlagsI(ip, flags) { \
+ osalEventBroadcastFlagsI(&(ip)->event, flags); \
+}
+/** @} */
+
+#endif /* HAL_CHANNELS_H */
+
+/** @} */
diff --git a/ChibiOS_20.3.2/os/hal/include/hal_crypto.h b/ChibiOS_20.3.2/os/hal/include/hal_crypto.h new file mode 100644 index 0000000..5d477b8 --- /dev/null +++ b/ChibiOS_20.3.2/os/hal/include/hal_crypto.h @@ -0,0 +1,383 @@ +/*
+ ChibiOS - Copyright (C) 2006..2018 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_crypto.h
+ * @brief Cryptographic Driver macros and structures.
+ *
+ * @addtogroup CRYPTO
+ * @{
+ */
+
+#ifndef HAL_CRYPTO_H
+#define HAL_CRYPTO_H
+
+#if (HAL_USE_CRY == TRUE) || defined(__DOXYGEN__)
+
+/*===========================================================================*/
+/* Driver constants. */
+/*===========================================================================*/
+
+/*===========================================================================*/
+/* Driver pre-compile time settings. */
+/*===========================================================================*/
+
+/**
+ * @brief Enables the SW fall-back of the cryptographic driver.
+ * @details When enabled, this option, activates a fall-back software
+ * implementation for algorithms not supported by the underlying
+ * hardware.
+ * @note Fall-back implementations may not be present for all algorithms.
+ */
+#if !defined(HAL_CRY_USE_FALLBACK) || defined(__DOXYGEN__)
+#define HAL_CRY_USE_FALLBACK FALSE
+#endif
+
+/**
+ * @brief Makes the driver forcibly use the fall-back implementations.
+ * @note If enabled then the LLD driver is not included at all.
+ */
+#if !defined(HAL_CRY_ENFORCE_FALLBACK) || defined(__DOXYGEN__)
+#define HAL_CRY_ENFORCE_FALLBACK FALSE
+#endif
+
+/*===========================================================================*/
+/* Derived constants and error checks. */
+/*===========================================================================*/
+
+#if HAL_CRY_ENFORCE_FALLBACK == TRUE
+#undef HAL_CRY_USE_FALLBACK
+#define HAL_CRY_USE_FALLBACK TRUE
+#endif
+
+/*===========================================================================*/
+/* Driver data structures and types. */
+/*===========================================================================*/
+
+/**
+ * @brief Size, in bits, of a crypto field or message.
+ * @note It is assumed, for simplicity, that this type is equivalent to
+ * a @p size_t.
+ */
+typedef size_t bitsize_t;
+
+/**
+ * @brief Driver state machine possible states.
+ */
+typedef enum {
+ CRY_UNINIT = 0, /**< Not initialized. */
+ CRY_STOP = 1, /**< Stopped. */
+ CRY_READY = 2 /**< Ready. */
+} crystate_t;
+
+/**
+ * @brief Driver error codes.
+ */
+typedef enum {
+ CRY_NOERROR = 0, /**< No error. */
+ CRY_ERR_INV_ALGO = 1, /**< Invalid cypher/mode. */
+ CRY_ERR_INV_KEY_SIZE = 2, /**< Invalid key size. */
+ CRY_ERR_INV_KEY_TYPE = 3, /**< Invalid key type. */
+ CRY_ERR_INV_KEY_ID = 4, /**< Invalid key identifier. */
+ CRY_ERR_AUTH_FAILED = 5, /**< Failed authentication. */
+ CRY_ERR_OP_FAILURE = 6 /**< Failed operation. */
+} cryerror_t;
+
+/**
+ * @brief Type of an algorithm identifier.
+ * @note It is only used to determine the key required for operations.
+ */
+typedef enum {
+ cry_algo_none = 0,
+ cry_algo_aes, /**< AES 128, 192, 256 bits. */
+ cry_algo_des, /**< DES 56, TDES 112, 168 bits.*/
+ cry_algo_hmac /**< HMAC variable size. */
+} cryalgorithm_t;
+
+#if HAL_CRY_ENFORCE_FALLBACK == FALSE
+/* Use the defined low level driver.*/
+#include "hal_crypto_lld.h"
+
+#if !defined(CRY_LLD_SUPPORTS_AES) || \
+ !defined(CRY_LLD_SUPPORTS_AES_ECB) || \
+ !defined(CRY_LLD_SUPPORTS_AES_CBC) || \
+ !defined(CRY_LLD_SUPPORTS_AES_CFB) || \
+ !defined(CRY_LLD_SUPPORTS_AES_CTR) || \
+ !defined(CRY_LLD_SUPPORTS_AES_GCM) || \
+ !defined(CRY_LLD_SUPPORTS_DES) || \
+ !defined(CRY_LLD_SUPPORTS_DES_ECB) || \
+ !defined(CRY_LLD_SUPPORTS_DES_CBC) || \
+ !defined(CRY_LLD_SUPPORTS_SHA1) || \
+ !defined(CRY_LLD_SUPPORTS_SHA256) || \
+ !defined(CRY_LLD_SUPPORTS_SHA512) || \
+ !defined(CRY_LLD_SUPPORTS_HMAC_SHA256) || \
+ !defined(CRY_LLD_SUPPORTS_HMAC_SHA512)
+#error "CRYPTO LLD does not export the required switches"
+#endif
+
+#else /* HAL_CRY_ENFORCE_FALLBACK == TRUE */
+/* No LLD at all, using the standalone mode.*/
+
+#define CRY_LLD_SUPPORTS_AES FALSE
+#define CRY_LLD_SUPPORTS_AES_ECB FALSE
+#define CRY_LLD_SUPPORTS_AES_CBC FALSE
+#define CRY_LLD_SUPPORTS_AES_CFB FALSE
+#define CRY_LLD_SUPPORTS_AES_CTR FALSE
+#define CRY_LLD_SUPPORTS_AES_GCM FALSE
+#define CRY_LLD_SUPPORTS_DES FALSE
+#define CRY_LLD_SUPPORTS_DES_ECB FALSE
+#define CRY_LLD_SUPPORTS_DES_CBC FALSE
+#define CRY_LLD_SUPPORTS_SHA1 FALSE
+#define CRY_LLD_SUPPORTS_SHA256 FALSE
+#define CRY_LLD_SUPPORTS_SHA512 FALSE
+#define CRY_LLD_SUPPORTS_HMAC_SHA256 FALSE
+#define CRY_LLD_SUPPORTS_HMAC_SHA512 FALSE
+
+typedef uint_fast8_t crykey_t;
+
+typedef struct CRYDriver CRYDriver;
+
+typedef struct {
+ uint32_t dummy;
+} CRYConfig;
+
+struct CRYDriver {
+ crystate_t state;
+ const CRYConfig *config;
+};
+#endif /* HAL_CRY_ENFORCE_FALLBACK == TRUE */
+
+/* The fallback header is included only if required by settings.*/
+#if HAL_CRY_USE_FALLBACK == TRUE
+#include "hal_crypto_fallback.h"
+#endif
+
+#if (HAL_CRY_USE_FALLBACK == FALSE) && (CRY_LLD_SUPPORTS_SHA1 == FALSE)
+/* Stub @p SHA1Context structure type declaration. It is not provided by
+ the LLD and the fallback is not enabled.*/
+typedef struct {
+ uint32_t dummy;
+} SHA1Context;
+#endif
+
+#if (HAL_CRY_USE_FALLBACK == FALSE) && (CRY_LLD_SUPPORTS_SHA256 == FALSE)
+/* Stub @p SHA256Context structure type declaration. It is not provided by
+ the LLD and the fallback is not enabled.*/
+typedef struct {
+ uint32_t dummy;
+} SHA256Context;
+#endif
+
+#if (HAL_CRY_USE_FALLBACK == FALSE) && (CRY_LLD_SUPPORTS_SHA512 == FALSE)
+/* Stub @p SHA512Context structure type declaration. It is not provided by
+ the LLD and the fallback is not enabled.*/
+typedef struct {
+ uint32_t dummy;
+} SHA512Context;
+#endif
+
+#if (HAL_CRY_USE_FALLBACK == FALSE) && (CRY_LLD_SUPPORTS_HMAC_SHA256 == FALSE)
+/* Stub @p HMACSHA256Context structure type declaration. It is not provided by
+ the LLD and the fallback is not enabled.*/
+typedef struct {
+ uint32_t dummy;
+} HMACSHA256Context;
+#endif
+
+#if (HAL_CRY_USE_FALLBACK == FALSE) && (CRY_LLD_SUPPORTS_HMAC_SHA512 == FALSE)
+/* Stub @p HMACSHA512Context structure type declaration. It is not provided by
+ the LLD and the fallback is not enabled.*/
+typedef struct {
+ uint32_t dummy;
+} HMACSHA512Context;
+#endif
+
+/*===========================================================================*/
+/* Driver macros. */
+/*===========================================================================*/
+
+/**
+ * @name Low level driver helper macros
+ * @{
+ */
+/** @} */
+
+/*===========================================================================*/
+/* External declarations. */
+/*===========================================================================*/
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+ void cryInit(void);
+ void cryObjectInit(CRYDriver *cryp);
+ void cryStart(CRYDriver *cryp, const CRYConfig *config);
+ void cryStop(CRYDriver *cryp);
+ cryerror_t cryLoadAESTransientKey(CRYDriver *cryp,
+ size_t size,
+ const uint8_t *keyp);
+ cryerror_t cryEncryptAES(CRYDriver *cryp,
+ crykey_t key_id,
+ const uint8_t *in,
+ uint8_t *out);
+ cryerror_t cryDecryptAES(CRYDriver *cryp,
+ crykey_t key_id,
+ const uint8_t *in,
+ uint8_t *out);
+ cryerror_t cryEncryptAES_ECB(CRYDriver *cryp,
+ crykey_t key_id,
+ size_t size,
+ const uint8_t *in,
+ uint8_t *out);
+ cryerror_t cryDecryptAES_ECB(CRYDriver *cryp,
+ crykey_t key_id,
+ size_t size,
+ const uint8_t *in,
+ uint8_t *out);
+ cryerror_t cryEncryptAES_CBC(CRYDriver *cryp,
+ crykey_t key_id,
+ size_t size,
+ const uint8_t *in,
+ uint8_t *out,
+ const uint8_t *iv);
+ cryerror_t cryDecryptAES_CBC(CRYDriver *cryp,
+ crykey_t key_id,
+ size_t size,
+ const uint8_t *in,
+ uint8_t *out,
+ const uint8_t *iv);
+ cryerror_t cryEncryptAES_CFB(CRYDriver *cryp,
+ crykey_t key_id,
+ size_t size,
+ const uint8_t *in,
+ uint8_t *out,
+ const uint8_t *iv);
+ cryerror_t cryDecryptAES_CFB(CRYDriver *cryp,
+ crykey_t key_id,
+ size_t size,
+ const uint8_t *in,
+ uint8_t *out,
+ const uint8_t *iv);
+ cryerror_t cryEncryptAES_CTR(CRYDriver *cryp,
+ crykey_t key_id,
+ size_t size,
+ const uint8_t *in,
+ uint8_t *out,
+ const uint8_t *iv);
+ cryerror_t cryDecryptAES_CTR(CRYDriver *cryp,
+ crykey_t key_id,
+ size_t size,
+ const uint8_t *in,
+ uint8_t *out,
+ const uint8_t *iv);
+ cryerror_t cryEncryptAES_GCM(CRYDriver *cryp,
+ crykey_t key_id,
+ size_t auth_size,
+ const uint8_t *auth_in,
+ size_t text_size,
+ const uint8_t *text_in,
+ uint8_t *text_out,
+ const uint8_t *iv,
+ size_t tag_size,
+ uint8_t *tag_out);
+ cryerror_t cryDecryptAES_GCM(CRYDriver *cryp,
+ crykey_t key_id,
+ size_t auth_size,
+ const uint8_t *auth_in,
+ size_t text_size,
+ const uint8_t *text_in,
+ uint8_t *text_out,
+ const uint8_t *iv,
+ size_t tag_size,
+ const uint8_t *tag_in);
+ cryerror_t cryLoadDESTransientKey(CRYDriver *cryp,
+ size_t size,
+ const uint8_t *keyp);
+ cryerror_t cryEncryptDES(CRYDriver *cryp,
+ crykey_t key_id,
+ const uint8_t *in,
+ uint8_t *out);
+ cryerror_t cryDecryptDES(CRYDriver *cryp,
+ crykey_t key_id,
+ const uint8_t *in,
+ uint8_t *out);
+ cryerror_t cryEncryptDES_ECB(CRYDriver *cryp,
+ crykey_t key_id,
+ size_t size,
+ const uint8_t *in,
+ uint8_t *out);
+ cryerror_t cryDecryptDES_ECB(CRYDriver *cryp,
+ crykey_t key_id,
+ size_t size,
+ const uint8_t *in,
+ uint8_t *out);
+ cryerror_t cryEncryptDES_CBC(CRYDriver *cryp,
+ crykey_t key_id,
+ size_t size,
+ const uint8_t *in,
+ uint8_t *out,
+ const uint8_t *iv);
+ cryerror_t cryDecryptDES_CBC(CRYDriver *cryp,
+ crykey_t key_id,
+ size_t size,
+ const uint8_t *in,
+ uint8_t *out,
+ const uint8_t *iv);
+ cryerror_t crySHA1Init(CRYDriver *cryp, SHA1Context *sha1ctxp);
+ cryerror_t crySHA1Update(CRYDriver *cryp, SHA1Context *sha1ctxp,
+ size_t size, const uint8_t *in);
+ cryerror_t crySHA1Final(CRYDriver *cryp, SHA1Context *sha1ctxp,
+ uint8_t *out);
+ cryerror_t crySHA256Init(CRYDriver *cryp, SHA256Context *sha256ctxp);
+ cryerror_t crySHA256Update(CRYDriver *cryp, SHA256Context *sha256ctxp,
+ size_t size, const uint8_t *in);
+ cryerror_t crySHA256Final(CRYDriver *cryp, SHA256Context *sha256ctxp,
+ uint8_t *out);
+ cryerror_t crySHA512Init(CRYDriver *cryp, SHA512Context *sha512ctxp);
+ cryerror_t crySHA512Update(CRYDriver *cryp, SHA512Context *sha512ctxp,
+ size_t size, const uint8_t *in);
+ cryerror_t crySHA512Final(CRYDriver *cryp, SHA512Context *sha512ctxp,
+ uint8_t *out);
+ cryerror_t cryLoadHMACTransientKey(CRYDriver *cryp,
+ size_t size,
+ const uint8_t *keyp);
+ cryerror_t cryHMACSHA256Init(CRYDriver *cryp,
+ HMACSHA256Context *hmacsha256ctxp);
+ cryerror_t cryHMACSHA256Update(CRYDriver *cryp,
+ HMACSHA256Context *hmacsha256ctxp,
+ size_t size,
+ const uint8_t *in);
+ cryerror_t cryHMACSHA256Final(CRYDriver *cryp,
+ HMACSHA256Context *hmacsha256ctxp,
+ uint8_t *out);
+ cryerror_t cryHMACSHA512Init(CRYDriver *cryp,
+ HMACSHA512Context *hmacsha512ctxp);
+ cryerror_t cryHMACSHA512Update(CRYDriver *cryp,
+ HMACSHA512Context *hmacsha512ctxp,
+ size_t size,
+ const uint8_t *in);
+ cryerror_t cryHMACSHA512Final(CRYDriver *cryp,
+ HMACSHA512Context *hmacsha512ctxp,
+ uint8_t *out);
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* HAL_USE_CRYPTO == TRUE */
+
+#endif /* HAL_CRYPTO_H */
+
+/** @} */
diff --git a/ChibiOS_20.3.2/os/hal/include/hal_dac.h b/ChibiOS_20.3.2/os/hal/include/hal_dac.h new file mode 100644 index 0000000..b3624dc --- /dev/null +++ b/ChibiOS_20.3.2/os/hal/include/hal_dac.h @@ -0,0 +1,379 @@ +/*
+ ChibiOS - Copyright (C) 2006..2018 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_dac.h
+ * @brief DAC Driver macros and structures.
+ *
+ * @addtogroup DAC
+ * @{
+ */
+
+#ifndef HAL_DAC_H
+#define HAL_DAC_H
+
+#if (HAL_USE_DAC == TRUE) || defined(__DOXYGEN__)
+
+/*===========================================================================*/
+/* Driver constants. */
+/*===========================================================================*/
+
+/*===========================================================================*/
+/* Driver pre-compile time settings. */
+/*===========================================================================*/
+
+/**
+ * @name DAC configuration options
+ * @{
+ */
+/**
+ * @brief Enables synchronous APIs.
+ * @note Disabling this option saves both code and data space.
+ */
+#if !defined(DAC_USE_WAIT) || defined(__DOXYGEN__)
+#define DAC_USE_WAIT TRUE
+#endif
+
+/**
+ * @brief Enables the @p dacAcquireBus() and @p dacReleaseBus() APIs.
+ * @note Disabling this option saves both code and data space.
+ */
+#if !defined(DAC_USE_MUTUAL_EXCLUSION) || defined(__DOXYGEN__)
+#define DAC_USE_MUTUAL_EXCLUSION TRUE
+#endif
+/** @} */
+
+/*===========================================================================*/
+/* Derived constants and error checks. */
+/*===========================================================================*/
+
+/*===========================================================================*/
+/* Driver data structures and types. */
+/*===========================================================================*/
+
+/**
+ * @brief Driver state machine possible states.
+ */
+typedef enum {
+ DAC_UNINIT = 0, /**< Not initialized. */
+ DAC_STOP = 1, /**< Stopped. */
+ DAC_READY = 2, /**< Ready. */
+ DAC_ACTIVE = 3, /**< Exchanging data. */
+ DAC_COMPLETE = 4, /**< Asynchronous operation complete. */
+ DAC_ERROR = 5 /**< Error. */
+} dacstate_t;
+
+/**
+ * @brief Type of a structure representing an DAC driver.
+ */
+typedef struct hal_dac_driver DACDriver;
+
+/**
+ * @brief Type of a structure representing an DAC driver configuration.
+ */
+typedef struct hal_dac_config DACConfig;
+
+/**
+ * @brief Type of a DAC conversion group.
+ */
+typedef struct hal_dac_conversion_group DACConversionGroup;
+
+/* Including the low level driver header, it exports information required
+ for completing types.*/
+#include "hal_dac_lld.h"
+
+/**
+ * @brief DAC notification callback type.
+ *
+ * @param[in] dacp pointer to the @p DACDriver object triggering the
+ */
+typedef void (*daccallback_t)(DACDriver *dacp);
+
+/**
+ * @brief DAC error callback type.
+ *
+ * @param[in] dacp pointer to the @p DACDriver object triggering the
+ * callback
+ * @param[in] err DAC error code
+ */
+typedef void (*dacerrorcallback_t)(DACDriver *dacp, dacerror_t err);
+
+/**
+ * @brief DAC Conversion group structure.
+ */
+struct hal_dac_conversion_group {
+ /**
+ * @brief Number of DAC channels.
+ */
+ uint32_t num_channels;
+ /**
+ * @brief Operation complete callback or @p NULL.
+ */
+ daccallback_t end_cb;
+ /**
+ * @brief Error handling callback or @p NULL.
+ */
+ dacerrorcallback_t error_cb;
+ /* End of the mandatory fields.*/
+ dac_lld_conversion_group_fields;
+};
+
+/**
+ * @brief Driver configuration structure.
+ */
+struct hal_dac_config {
+ /* End of the mandatory fields.*/
+ dac_lld_config_fields;
+};
+
+/**
+ * @brief Structure representing a DAC driver.
+ */
+struct hal_dac_driver {
+ /**
+ * @brief Driver state.
+ */
+ dacstate_t state;
+ /**
+ * @brief Conversion group.
+ */
+ const DACConversionGroup *grpp;
+ /**
+ * @brief Samples buffer pointer.
+ */
+ dacsample_t *samples;
+ /**
+ * @brief Samples buffer size.
+ */
+ size_t depth;
+ /**
+ * @brief Current configuration data.
+ */
+ const DACConfig *config;
+#if (DAC_USE_WAIT == TRUE) || defined(__DOXYGEN__)
+ /**
+ * @brief Waiting thread.
+ */
+ thread_reference_t thread;
+#endif /* DAC_USE_WAIT */
+#if (DAC_USE_MUTUAL_EXCLUSION == TRUE) || defined(__DOXYGEN__)
+ /**
+ * @brief Mutex protecting the bus.
+ */
+ mutex_t mutex;
+#endif /* DAC_USE_MUTUAL_EXCLUSION */
+#if defined(DAC_DRIVER_EXT_FIELDS)
+ DAC_DRIVER_EXT_FIELDS
+#endif
+ /* End of the mandatory fields.*/
+ dac_lld_driver_fields;
+};
+
+/*===========================================================================*/
+/* Driver macros. */
+/*===========================================================================*/
+
+/**
+ * @name Low level driver helper macros
+ * @{
+ */
+/**
+ * @brief Buffer state.
+ * @note This function is meant to be called from the DAC callback only.
+ *
+ * @param[in] dacp pointer to the @p DACDriver object
+ * @return The buffer state.
+ * @retval false if the driver filled/sent the first half of the
+ * buffer.
+ * @retval true if the driver filled/sent the second half of the
+ * buffer.
+ *
+ * @special
+ */
+#define dacIsBufferComplete(dacp) ((bool)((dacp)->state == DAC_COMPLETE))
+
+#if (DAC_USE_WAIT == TRUE) || defined(__DOXYGEN__)
+/**
+ * @brief Waits for operation completion.
+ * @details This function waits for the driver to complete the current
+ * operation.
+ * @pre An operation must be running while the function is invoked.
+ * @note No more than one thread can wait on a DAC driver using
+ * this function.
+ *
+ * @param[in] dacp pointer to the @p DACDriver object
+ *
+ * @notapi
+ */
+#define _dac_wait_s(dacp) osalThreadSuspendS(&(dacp)->thread)
+
+/**
+ * @brief Resumes a thread waiting for a conversion completion.
+ *
+ * @param[in] dacp pointer to the @p DACDriver object
+ *
+ * @notapi
+ */
+#define _dac_reset_i(dacp) osalThreadResumeI(&(dacp)->thread, MSG_RESET)
+
+/**
+ * @brief Resumes a thread waiting for a conversion completion.
+ *
+ * @param[in] dacp pointer to the @p DACDriver object
+ *
+ * @notapi
+ */
+#define _dac_reset_s(dacp) osalThreadResumeS(&(dacp)->thread, MSG_RESET)
+
+/**
+ * @brief Wakes up the waiting thread.
+ *
+ * @param[in] dacp pointer to the @p DACDriver object
+ *
+ * @notapi
+ */
+#define _dac_wakeup_isr(dacp) { \
+ osalSysLockFromISR(); \
+ osalThreadResumeI(&(dacp)->thread, MSG_OK); \
+ osalSysUnlockFromISR(); \
+}
+
+/**
+ * @brief Wakes up the waiting thread with a timeout message.
+ *
+ * @param[in] dacp pointer to the @p DACDriver object
+ *
+ * @notapi
+ */
+#define _dac_timeout_isr(dacp) { \
+ osalSysLockFromISR(); \
+ osalThreadResumeI(&(dacp)->thread, MSG_TIMEOUT); \
+ osalSysUnlockFromISR(); \
+}
+
+#else /* !DAC_USE_WAIT */
+#define _dac_wait_s(dacp)
+#define _dac_reset_i(dacp)
+#define _dac_reset_s(dacp)
+#define _dac_wakeup_isr(dacp)
+#define _dac_timeout_isr(dacp)
+#endif /* !DAC_USE_WAIT */
+
+/**
+ * @brief Common ISR code, half buffer event.
+ * @details This code handles the portable part of the ISR code:
+ * - Callback invocation.
+ * .
+ * @note This macro is meant to be used in the low level drivers
+ * implementation only.
+ *
+ * @param[in] dacp pointer to the @p DACDriver object
+ *
+ * @notapi
+ */
+#define _dac_isr_half_code(dacp) { \
+ if ((dacp)->grpp->end_cb != NULL) { \
+ (dacp)->grpp->end_cb(dacp); \
+ } \
+}
+
+/**
+ * @brief Common ISR code, full buffer event.
+ * @details This code handles the portable part of the ISR code:
+ * - Callback invocation.
+ * - Driver state transitions.
+ * .
+ * @note This macro is meant to be used in the low level drivers
+ * implementation only.
+ *
+ * @param[in] dacp pointer to the @p DACDriver object
+ *
+ * @notapi
+ */
+#define _dac_isr_full_code(dacp) { \
+ if ((dacp)->grpp->end_cb) { \
+ (dacp)->state = DAC_COMPLETE; \
+ (dacp)->grpp->end_cb(dacp); \
+ if ((dacp)->state == DAC_COMPLETE) \
+ (dacp)->state = DAC_ACTIVE; \
+ } \
+}
+
+/**
+ * @brief Common ISR code, error event.
+ * @details This code handles the portable part of the ISR code:
+ * - Callback invocation.
+ * - Waiting thread timeout signaling, if any.
+ * - Driver state transitions.
+ * .
+ * @note This macro is meant to be used in the low level drivers
+ * implementation only.
+ *
+ * @param[in] dacp pointer to the @p DACDriver object
+ * @param[in] err platform dependent error code
+ *
+ * @notapi
+ */
+#define _dac_isr_error_code(dacp, err) { \
+ dac_lld_stop_conversion(dacp); \
+ if ((dacp)->grpp->error_cb != NULL) { \
+ (dacp)->state = DAC_ERROR; \
+ (dacp)->grpp->error_cb(dacp, err); \
+ if ((dacp)->state == DAC_ERROR) \
+ (dacp)->state = DAC_READY; \
+ } \
+ (dacp)->grpp = NULL; \
+ _dac_timeout_isr(dacp); \
+}
+/** @} */
+
+/*===========================================================================*/
+/* External declarations. */
+/*===========================================================================*/
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+ void dacInit(void);
+ void dacObjectInit(DACDriver *dacp);
+ void dacStart(DACDriver *dacp, const DACConfig *config);
+ void dacStop(DACDriver *dacp);
+ void dacPutChannelX(DACDriver *dacp,
+ dacchannel_t channel,
+ dacsample_t sample);
+ void dacStartConversion(DACDriver *dacp, const DACConversionGroup *grpp,
+ dacsample_t *samples, size_t depth);
+ void dacStartConversionI(DACDriver *dacp, const DACConversionGroup *grpp,
+ dacsample_t *samples, size_t depth);
+ void dacStopConversion(DACDriver *dacp);
+ void dacStopConversionI(DACDriver *dacp);
+#if DAC_USE_WAIT
+ msg_t dacConvert(DACDriver *dacp, const DACConversionGroup *grpp,
+ dacsample_t *samples, size_t depth);
+#endif
+#if DAC_USE_MUTUAL_EXCLUSION
+ void dacAcquireBus(DACDriver *dacp);
+ void dacReleaseBus(DACDriver *dacp);
+#endif
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* HAL_USE_DAC == TRUE */
+
+#endif /* HAL_DAC_H */
+
+/** @} */
diff --git a/ChibiOS_20.3.2/os/hal/include/hal_efl.h b/ChibiOS_20.3.2/os/hal/include/hal_efl.h new file mode 100644 index 0000000..f00517c --- /dev/null +++ b/ChibiOS_20.3.2/os/hal/include/hal_efl.h @@ -0,0 +1,130 @@ +/*
+ ChibiOS - Copyright (C) 2006..2018 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_efl.h
+ * @brief Embedded Flash Driver macros and structures.
+ *
+ * @addtogroup HAL_EFL
+ * @{
+ */
+
+#ifndef HAL_EFL_H
+#define HAL_EFL_H
+
+#if (HAL_USE_EFL == TRUE) || defined(__DOXYGEN__)
+
+/*===========================================================================*/
+/* Driver constants. */
+/*===========================================================================*/
+
+/*===========================================================================*/
+/* Driver pre-compile time settings. */
+/*===========================================================================*/
+
+/*===========================================================================*/
+/* Derived constants and error checks. */
+/*===========================================================================*/
+
+/*===========================================================================*/
+/* Driver data structures and types. */
+/*===========================================================================*/
+
+/**
+ * @extends BaseFlash
+ *
+ * @brief Type of external flash driver class.
+ */
+typedef struct hal_efl_driver EFlashDriver;
+
+#include "hal_efl_lld.h"
+
+/**
+ * @brief @p EFlashDriver specific methods.
+ */
+#define _efl_flash_methods_alone
+
+/**
+ * @brief @p EFlashDriver specific methods with inherited ones.
+ */
+#define _efl_flash_methods \
+ _base_flash_methods \
+ _efl_flash_methods_alone
+
+/**
+ * @brief @p EFlashDriver specific data.
+ */
+#define _efl_driver_data \
+ _base_flash_data \
+ /* Current configuration data.*/ \
+ const EFlashConfig *config;
+
+/**
+ * @extends BaseFlashVMT
+ *
+ * @brief @p EFlash virtual methods table.
+ */
+struct EFlashDriverVMT {
+ _efl_flash_methods
+};
+
+/**
+ * @brief Type of a structure representing a flash driver configuration.
+ */
+typedef struct hal_efl_config {
+ /* End of the mandatory fields.*/
+ efl_lld_config_fields;
+} EFlashConfig;
+
+/**
+ * @extends BaseFlash
+ *
+ * @brief Structure representing an embedded flash driver.
+ */
+struct hal_efl_driver {
+ /**
+ * @brief SNORDriver Virtual Methods Table.
+ */
+ const struct EFlashDriverVMT *vmt;
+ _efl_driver_data
+ /* End of the mandatory fields.*/
+ efl_lld_driver_fields;
+};
+
+/*===========================================================================*/
+/* Driver macros. */
+/*===========================================================================*/
+
+/*===========================================================================*/
+/* External declarations. */
+/*===========================================================================*/
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+ void eflInit(void);
+ void eflObjectInit(EFlashDriver *eflp);
+ void eflStart(EFlashDriver *eflp, const EFlashConfig *config);
+ void eflStop(EFlashDriver *eflp);
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* HAL_USE_EFL == TRUE */
+
+#endif /* HAL_EFL_H */
+
+/** @} */
diff --git a/ChibiOS_20.3.2/os/hal/include/hal_files.h b/ChibiOS_20.3.2/os/hal/include/hal_files.h new file mode 100644 index 0000000..63018ac --- /dev/null +++ b/ChibiOS_20.3.2/os/hal/include/hal_files.h @@ -0,0 +1,240 @@ +/*
+ ChibiOS - Copyright (C) 2006..2018 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_files.h
+ * @brief Data files.
+ * @details This header defines abstract interfaces useful to access generic
+ * data files in a standardized way.
+ *
+ * @addtogroup HAL_FILES
+ * @details This module define an abstract interface for generic data files by
+ * extending the @p BaseSequentialStream interface. Note that no code
+ * is present, data files are just abstract interface-like structures,
+ * you should look at the systems as to a set of abstract C++ classes
+ * (even if written in C). This system has the advantage to make the
+ * access to streams independent from the implementation logic.<br>
+ * The data files interface can be used as base class for high level
+ * object types such as an API for a File System implementation.
+ * @{
+ */
+
+#ifndef HAL_FILES_H
+#define HAL_FILES_H
+
+/**
+ * @name Files return codes
+ * @{
+ */
+/**
+ * @brief No error return code.
+ */
+#define FILE_OK STM_OK
+
+/**
+ * @brief Error code from the file stream methods.
+ */
+#define FILE_ERROR STM_TIMEOUT
+
+/**
+ * @brief End-of-file condition for file get/put methods.
+ */
+#define FILE_EOF STM_RESET
+/** @} */
+
+/**
+ * @brief File offset type.
+ */
+typedef uint32_t fileoffset_t;
+
+/**
+ * @brief FileStream specific methods.
+ */
+#define _file_stream_methods \
+ _base_sequential_stream_methods \
+ /* File close method.*/ \
+ msg_t (*close)(void *instance); \
+ /* Get last error code method.*/ \
+ msg_t (*geterror)(void *instance); \
+ /* File get size method.*/ \
+ msg_t (*getsize)(void *instance, fileoffset_t *offset); \
+ /* File get current position method.*/ \
+ msg_t (*getposition)(void *instance, fileoffset_t *offset); \
+ /* File set current position method.*/ \
+ msg_t (*setposition)(void *instance, fileoffset_t offset);
+
+/**
+ * @brief @p FileStream specific data.
+ * @note It is empty because @p FileStream is only an interface
+ * without implementation.
+ */
+#define _file_stream_data \
+ _base_sequential_stream_data
+
+/**
+ * @extends BaseSequentialStreamVMT
+ *
+ * @brief @p FileStream virtual methods table.
+ */
+struct FileStreamVMT {
+ _file_stream_methods
+};
+
+/**
+ * @extends BaseSequentialStream
+ *
+ * @brief Base file stream class.
+ * @details This class represents a generic file data stream.
+ */
+typedef struct {
+ /** @brief Virtual Methods Table.*/
+ const struct FileStreamVMT *vmt;
+ _file_stream_data
+} FileStream;
+
+/**
+ * @name Macro Functions (FileStream)
+ * @{
+ */
+/**
+ * @brief File stream write.
+ * @details The function writes data from a buffer to a file stream.
+ *
+ * @param[in] ip pointer to a @p FileStream or derived class
+ * @param[in] bp pointer to the data buffer
+ * @param[in] n the maximum amount of data to be transferred
+ * @return The number of bytes transferred. The return value can
+ * be less than the specified number of bytes if an
+ * end-of-file condition has been met.
+ * @retval FILE_ERROR operation failed.
+ *
+ * @api
+ */
+#define fileStreamWrite(ip, bp, n) streamWrite(ip, bp, n)
+
+/**
+ * @brief File stream read.
+ * @details The function reads data from a file stream into a buffer.
+ *
+ * @param[in] ip pointer to a @p FileStream or derived class
+ * @param[out] bp pointer to the data buffer
+ * @param[in] n the maximum amount of data to be transferred
+ * @return The number of bytes transferred. The return value can
+ * be less than the specified number of bytes if an
+ * end-of-file condition has been met.
+ * @retval FILE_ERROR operation failed.
+ *
+ * @api
+ */
+#define fileStreamRead(ip, bp, n) streamRead(ip, bp, n)
+
+/**
+ * @brief File stream blocking byte write.
+ * @details This function writes a byte value to a channel. If the channel
+ * is not ready to accept data then the calling thread is suspended.
+ *
+ * @param[in] ip pointer to a @p FileStream or derived class
+ * @param[in] b the byte value to be written to the channel
+ *
+ * @return The operation status.
+ * @retval FILE_OK if the operation succeeded.
+ * @retval FILE_ERROR operation failed.
+ * @retval FILE_EOF if an end-of-file condition has been met.
+ *
+ * @api
+ */
+#define fileStreamPut(ip, b) streamPut(ip, b)
+
+/**
+ * @brief File stream blocking byte read.
+ * @details This function reads a byte value from a channel. If the data
+ * is not available then the calling thread is suspended.
+ *
+ * @param[in] ip pointer to a @p FileStream or derived class
+ *
+ * @return A byte value from the queue.
+ * @retval FILE_ERROR operation failed.
+ * @retval FILE_EOF if an end-of-file condition has been met.
+ *
+ * @api
+ */
+#define fileStreamGet(ip) streamGet(ip)
+
+/**
+ * @brief File Stream close.
+ * @details The function closes a file stream.
+ *
+ * @param[in] ip pointer to a @p FileStream or derived class
+ * @return The operation status.
+ * @retval FILE_OK no error.
+ * @retval FILE_ERROR operation failed.
+ *
+ * @api
+ */
+#define fileStreamClose(ip) ((ip)->vmt->close(ip))
+
+/**
+ * @brief Returns an implementation dependent error code.
+ * @pre The previously called function must have returned @p FILE_ERROR.
+ *
+ * @param[in] ip pointer to a @p FileStream or derived class
+ * @return Implementation dependent error code.
+ *
+ * @api
+ */
+#define fileStreamGetError(ip) ((ip)->vmt->geterror(ip))
+
+/**
+ * @brief Returns the current file size.
+ *
+ * @param[in] ip pointer to a @p FileStream or derived class
+ * @param[out] offset current size of the file
+ * @return The file size.
+ * @retval FILE_ERROR operation failed.
+ *
+ * @api
+ */
+#define fileStreamGetSize(ip, offset) ((ip)->vmt->getsize(ip, offset))
+
+/**
+ * @brief Returns the current file pointer position.
+ *
+ * @param[in] ip pointer to a @p FileStream or derived class
+ * @param[out] offset current position in the file
+ * @return The current position inside the file.
+ * @retval FILE_ERROR operation failed.
+ *
+ * @api
+ */
+#define fileStreamGetPosition(ip, offset) ((ip)->vmt->getposition(ip, offset))
+
+/**
+ * @brief Moves the file current pointer to an absolute position.
+ *
+ * @param[in] ip pointer to a @p FileStream or derived class
+ * @param[in] offset new absolute position
+ * @return The operation status.
+ * @retval FILE_OK no error.
+ * @retval FILE_ERROR operation failed.
+ *
+ * @api
+ */
+#define fileStreamSetPosition(ip, offset) ((ip)->vmt->setposition(ip, offset))
+/** @} */
+
+#endif /* HAL_FILES_H */
+
+/** @} */
diff --git a/ChibiOS_20.3.2/os/hal/include/hal_flash.h b/ChibiOS_20.3.2/os/hal/include/hal_flash.h new file mode 100644 index 0000000..ba90a76 --- /dev/null +++ b/ChibiOS_20.3.2/os/hal/include/hal_flash.h @@ -0,0 +1,369 @@ +/*
+ ChibiOS - Copyright (C) 2006..2018 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_flash.h
+ * @brief Generic flash driver class header.
+ *
+ * @addtogroup HAL_FLASH
+ * @{
+ */
+
+#ifndef HAL_FLASH_H
+#define HAL_FLASH_H
+
+/*===========================================================================*/
+/* Driver constants. */
+/*===========================================================================*/
+
+/**
+ * @name Flash attributes
+ * @{
+ */
+/**
+ * @brief Defines one as the erased bit state.
+ */
+#define FLASH_ATTR_ERASED_IS_ONE 0x00000001U
+/**
+ * @brief The memory is accessible in a memory mapped mode.
+ */
+#define FLASH_ATTR_MEMORY_MAPPED 0x00000002U
+/**
+ * @brief Programmed pages can be programmed again.
+ * @note This is incompatible and alternative to @p FLASH_ATTR_ECC_CAPABLE.
+ */
+#define FLASH_ATTR_REWRITABLE 0x00000004U
+/**
+ * @brief The memory is protected by an ECC mechanism.
+ * @note This usually puts restrictions on the program operations.
+ * - Program operations can only happen at offsets aligned to
+ * write page boundaries.
+ * - The programmed data size must be a multiple of the write
+ * page size.
+ * - Programmed pages cannot be re-programmed.
+ * .
+ */
+#define FLASH_ATTR_ECC_CAPABLE 0x00000008U
+/**
+ * @brief The device is able to overwrite zero to a line.
+ * @note This attribute is only meaningful for those devices that support
+ * ECC, so also @p FLASH_ATTR_ECC_CAPABLE must be specified.
+ */
+#define FLASH_ATTR_ECC_ZERO_LINE_CAPABLE 0x00000010U
+/**
+ * @brief The device is able to suspend erase operations.
+ */
+#define FLASH_ATTR_SUSPEND_ERASE_CAPABLE 0x00000020U
+/** @} */
+
+/*===========================================================================*/
+/* Driver pre-compile time settings. */
+/*===========================================================================*/
+
+/*===========================================================================*/
+/* Derived constants and error checks. */
+/*===========================================================================*/
+
+/*===========================================================================*/
+/* Driver data structures and types. */
+/*===========================================================================*/
+
+/**
+ * @brief Driver state machine possible states.
+ */
+typedef enum {
+ FLASH_UNINIT = 0,
+ FLASH_STOP = 1,
+ FLASH_READY = 2,
+ FLASH_READ = 3,
+ FLASH_PGM = 4,
+ FLASH_ERASE = 5
+} flash_state_t;
+
+/**
+ * @brief Type of a flash error code.
+ */
+typedef enum {
+ FLASH_NO_ERROR = 0, /* No error. */
+ FLASH_BUSY_ERASING = 1, /* Erase operation in progress. */
+ FLASH_ERROR_READ = 2, /* ECC or other error during read operation.*/
+ FLASH_ERROR_PROGRAM = 3, /* Program operation failed. */
+ FLASH_ERROR_ERASE = 4, /* Erase operation failed. */
+ FLASH_ERROR_VERIFY = 5, /* Verify operation failed. */
+ FLASH_ERROR_HW_FAILURE = 6, /* Controller or communication error. */
+ FLASH_ERROR_UNIMPLEMENTED = 7 /* Unimplemented functionality. */
+} flash_error_t;
+
+/**
+ * @brief Type of a flash offset.
+ */
+typedef uint32_t flash_offset_t;
+
+/**
+ * @brief Type of a flash sector number.
+ */
+typedef uint32_t flash_sector_t;
+
+/**
+ * @brief Flash sector descriptor.
+ */
+typedef struct {
+ /**
+ * @brief Sector offset.
+ */
+ flash_offset_t offset;
+ /**
+ * @brief Sector size.
+ */
+ uint32_t size;
+} flash_sector_descriptor_t;
+
+/**
+ * @brief Type of a flash device descriptor.
+ */
+typedef struct {
+ /**
+ * @brief Device_attributes.
+ */
+ uint32_t attributes;
+ /**
+ * @brief Size of write page.
+ */
+ uint32_t page_size;
+ /**
+ * @brief Number of sectors in the device.
+ */
+ flash_sector_t sectors_count;
+ /**
+ * @brief List of sectors for devices with non-uniform sector sizes.
+ * @note If @p NULL then the device has uniform sectors size equal
+ * to @p sector_size.
+ */
+ const flash_sector_descriptor_t *sectors;
+ /**
+ * @brief Size of sectors for devices with uniform sector size.
+ * @note If zero then the device has non uniform sectors described
+ * by the @p sectors array.
+ */
+ uint32_t sectors_size;
+ /**
+ * @brief Flash address if memory mapped or zero.
+ * @note Conventionally, non memory mapped devices have address @p NULL.
+ */
+ uint8_t *address;
+ /**
+ * @brief Flash size.
+ */
+ uint32_t size;
+} flash_descriptor_t;
+
+/**
+ * @brief @p BaseFlash specific methods.
+ */
+#define _base_flash_methods_alone \
+ /* Get flash device attributes.*/ \
+ const flash_descriptor_t * (*get_descriptor)(void *instance); \
+ /* Read operation.*/ \
+ flash_error_t (*read)(void *instance, flash_offset_t offset, \
+ size_t n, uint8_t *rp); \
+ /* Program operation.*/ \
+ flash_error_t (*program)(void *instance, flash_offset_t offset, \
+ size_t n, const uint8_t *pp); \
+ /* Erase whole flash device.*/ \
+ flash_error_t (*start_erase_all)(void *instance); \
+ /* Erase single sector.*/ \
+ flash_error_t (*start_erase_sector)(void *instance, \
+ flash_sector_t sector); \
+ flash_error_t (*query_erase)(void *instance, uint32_t *wait_time); \
+ /* Verify erase single sector.*/ \
+ flash_error_t (*verify_erase)(void *instance, flash_sector_t sector);
+
+/**
+ * @brief @p BaseFlash specific methods with inherited ones.
+ */
+#define _base_flash_methods \
+ _base_object_methods \
+ _base_flash_methods_alone
+
+/**
+ * @brief @p BaseFlash virtual methods table.
+ */
+struct BaseFlashVMT {
+ _base_flash_methods
+};
+
+/**
+ * @brief @p BaseFlash specific data.
+ */
+#define _base_flash_data \
+ _base_object_data \
+ /* Driver state.*/ \
+ flash_state_t state;
+
+/**
+ * @extends BaseObject
+ *
+ * @brief Base flash class.
+ */
+typedef struct {
+ /** @brief Virtual Methods Table.*/
+ const struct BaseFlashVMT *vmt;
+ _base_flash_data
+} BaseFlash;
+
+/*===========================================================================*/
+/* Driver macros. */
+/*===========================================================================*/
+
+/**
+ * @name Macro Functions (BaseFlash)
+ * @{
+ */
+/**
+ * @brief Instance getter.
+ * @details This special method is used to get the instance of this class
+ * object from a derived class.
+ */
+#define getBaseFlash(ip) ((BaseFlash *)&(ip)->vmt)
+
+/**
+ * @brief Gets the flash descriptor structure.
+ *
+ * @param[in] ip pointer to a @p BaseFlash or derived class
+ * @return A flash device descriptor.
+ *
+ * @api
+ */
+#define flashGetDescriptor(ip) \
+ (ip)->vmt->get_descriptor(ip)
+
+/**
+ * @brief Read operation.
+ *
+ * @param[in] ip pointer to a @p BaseFlash or derived class
+ * @param[in] offset flash offset
+ * @param[in] n number of bytes to be read
+ * @param[out] rp pointer to the data buffer
+ * @return An error code.
+ * @retval FLASH_NO_ERROR if there is no erase operation in progress.
+ * @retval FLASH_BUSY_ERASING if there is an erase operation in progress.
+ * @retval FLASH_ERROR_READ if the read operation failed.
+ * @retval FLASH_ERROR_HW_FAILURE if access to the memory failed.
+ *
+ * @api
+ */
+#define flashRead(ip, offset, n, rp) \
+ (ip)->vmt->read(ip, offset, n, rp)
+
+/**
+ * @brief Program operation.
+ *
+ * @param[in] ip pointer to a @p BaseFlash or derived class
+ * @param[in] offset flash offset
+ * @param[in] n number of bytes to be programmed
+ * @param[in] pp pointer to the data buffer
+ * @return An error code.
+ * @retval FLASH_NO_ERROR if there is no erase operation in progress.
+ * @retval FLASH_BUSY_ERASING if there is an erase operation in progress.
+ * @retval FLASH_ERROR_PROGRAM if the program operation failed.
+ * @retval FLASH_ERROR_HW_FAILURE if access to the memory failed.
+ *
+ * @api
+ */
+#define flashProgram(ip, offset, n, pp) \
+ (ip)->vmt->program(ip, offset, n, pp)
+
+/**
+ * @brief Starts a whole-device erase operation.
+ *
+ * @param[in] ip pointer to a @p BaseFlash or derived class
+ * @return An error code.
+ * @retval FLASH_NO_ERROR if there is no erase operation in progress.
+ * @retval FLASH_BUSY_ERASING if there is an erase operation in progress.
+ * @retval FLASH_ERROR_HW_FAILURE if access to the memory failed.
+ *
+ * @api
+ */
+#define flashStartEraseAll(ip) \
+ (ip)->vmt->start_erase_all(ip)
+
+/**
+ * @brief Starts an sector erase operation.
+ *
+ * @param[in] ip pointer to a @p BaseFlash or derived class
+ * @param[in] sector sector to be erased
+ * @return An error code.
+ * @retval FLASH_NO_ERROR if there is no erase operation in progress.
+ * @retval FLASH_BUSY_ERASING if there is an erase operation in progress.
+ * @retval FLASH_ERROR_HW_FAILURE if access to the memory failed.
+ *
+ * @api
+ */
+#define flashStartEraseSector(ip, sector) \
+ (ip)->vmt->start_erase_sector(ip, sector)
+
+/**
+ * @brief Queries the driver for erase operation progress.
+ *
+ * @param[in] ip pointer to a @p BaseFlash or derived class
+ * @param[out] msec recommended time, in milliseconds, that
+ * should be spent before calling this
+ * function again, can be @p NULL
+ * @return An error code.
+ * @retval FLASH_NO_ERROR if there is no erase operation in progress.
+ * @retval FLASH_BUSY_ERASING if there is an erase operation in progress.
+ * @retval FLASH_ERROR_ERASE if the erase operation failed.
+ * @retval FLASH_ERROR_HW_FAILURE if access to the memory failed.
+ *
+ * @api
+ */
+#define flashQueryErase(ip, msec) \
+ (ip)->vmt->query_erase(ip, msec)
+
+/**
+ * @brief Returns the erase state of a sector.
+ *
+ * @param[in] ip pointer to a @p BaseFlash or derived class
+ * @param[in] sector sector to be verified
+ * @return An error code.
+ * @retval FLASH_NO_ERROR if the sector is erased.
+ * @retval FLASH_BUSY_ERASING if there is an erase operation in progress.
+ * @retval FLASH_ERROR_VERIFY if the verify operation failed.
+ * @retval FLASH_ERROR_HW_FAILURE if access to the memory failed.
+ *
+ * @api
+ */
+#define flashVerifyErase(ip, sector) \
+ (ip)->vmt->verify_erase(ip, sector)
+/** @} */
+
+/*===========================================================================*/
+/* External declarations. */
+/*===========================================================================*/
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+ flash_error_t flashWaitErase(BaseFlash *devp);
+ flash_offset_t flashGetSectorOffset(BaseFlash *devp, flash_sector_t sector);
+ uint32_t flashGetSectorSize(BaseFlash *devp, flash_sector_t sector);
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* HAL_FLASH_H */
+
+/** @} */
diff --git a/ChibiOS_20.3.2/os/hal/include/hal_gpt.h b/ChibiOS_20.3.2/os/hal/include/hal_gpt.h new file mode 100644 index 0000000..fd2b8fd --- /dev/null +++ b/ChibiOS_20.3.2/os/hal/include/hal_gpt.h @@ -0,0 +1,158 @@ +/*
+ ChibiOS - Copyright (C) 2006..2018 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_gpt.h
+ * @brief GPT Driver macros and structures.
+ *
+ * @addtogroup GPT
+ * @{
+ */
+
+#ifndef HAL_GPT_H
+#define HAL_GPT_H
+
+#if (HAL_USE_GPT == TRUE) || defined(__DOXYGEN__)
+
+/*===========================================================================*/
+/* Driver constants. */
+/*===========================================================================*/
+
+/*===========================================================================*/
+/* Driver pre-compile time settings. */
+/*===========================================================================*/
+
+/*===========================================================================*/
+/* Derived constants and error checks. */
+/*===========================================================================*/
+
+/*===========================================================================*/
+/* Driver data structures and types. */
+/*===========================================================================*/
+
+/**
+ * @brief Driver state machine possible states.
+ */
+typedef enum {
+ GPT_UNINIT = 0, /**< Not initialized. */
+ GPT_STOP = 1, /**< Stopped. */
+ GPT_READY = 2, /**< Ready. */
+ GPT_CONTINUOUS = 3, /**< Active in continuous mode. */
+ GPT_ONESHOT = 4 /**< Active in one shot mode. */
+} gptstate_t;
+
+/**
+ * @brief Type of a structure representing a GPT driver.
+ */
+typedef struct GPTDriver GPTDriver;
+
+/**
+ * @brief GPT notification callback type.
+ *
+ * @param[in] gptp pointer to a @p GPTDriver object
+ */
+typedef void (*gptcallback_t)(GPTDriver *gptp);
+
+#include "hal_gpt_lld.h"
+
+/*===========================================================================*/
+/* Driver macros. */
+/*===========================================================================*/
+
+/**
+ * @brief Changes the interval of GPT peripheral.
+ * @details This function changes the interval of a running GPT unit.
+ * @pre The GPT unit must be running in continuous mode.
+ * @post The GPT unit interval is changed to the new value.
+ *
+ * @param[in] gptp pointer to a @p GPTDriver object
+ * @param[in] interval new cycle time in timer ticks
+ *
+ * @iclass
+ */
+#define gptChangeIntervalI(gptp, interval) { \
+ gpt_lld_change_interval(gptp, interval); \
+}
+
+/**
+ * @brief Returns the interval of GPT peripheral.
+ * @pre The GPT unit must be running in continuous mode.
+ *
+ * @param[in] gptp pointer to a @p GPTDriver object
+ * @return The current interval.
+ *
+ * @xclass
+ */
+#define gptGetIntervalX(gptp) gpt_lld_get_interval(gptp)
+
+/**
+ * @brief Returns the counter value of GPT peripheral.
+ * @pre The GPT unit must be running in continuous mode.
+ * @note The nature of the counter is not defined, it may count upward
+ * or downward, it could be continuously running or not.
+ *
+ * @param[in] gptp pointer to a @p GPTDriver object
+ * @return The current counter value.
+ *
+ * @xclass
+ */
+#define gptGetCounterX(gptp) gpt_lld_get_counter(gptp)
+
+/**
+ * @brief Common ISR code, GPT period event.
+ *
+ * @param[in] gptp pointer to the @p GPTDriver object
+ *
+ * @notapi
+ */
+#define _gpt_isr_invoke_cb(gptp) do { \
+ if ((gptp)->state == GPT_ONESHOT) { \
+ (gptp)->state = GPT_READY; \
+ gpt_lld_stop_timer(gptp); \
+ } \
+ if ((gptp)->config->callback != NULL) { \
+ (gptp)->config->callback(gptp); \
+ } \
+} while (0)
+
+/*===========================================================================*/
+/* External declarations. */
+/*===========================================================================*/
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+ void gptInit(void);
+ void gptObjectInit(GPTDriver *gptp);
+ void gptStart(GPTDriver *gptp, const GPTConfig *config);
+ void gptStop(GPTDriver *gptp);
+ void gptStartContinuous(GPTDriver *gptp, gptcnt_t interval);
+ void gptStartContinuousI(GPTDriver *gptp, gptcnt_t interval);
+ void gptChangeInterval(GPTDriver *gptp, gptcnt_t interval);
+ void gptStartOneShot(GPTDriver *gptp, gptcnt_t interval);
+ void gptStartOneShotI(GPTDriver *gptp, gptcnt_t interval);
+ void gptStopTimer(GPTDriver *gptp);
+ void gptStopTimerI(GPTDriver *gptp);
+ void gptPolledDelay(GPTDriver *gptp, gptcnt_t interval);
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* HAL_USE_GPT == TRUE */
+
+#endif /* HAL_GPT_H */
+
+/** @} */
diff --git a/ChibiOS_20.3.2/os/hal/include/hal_i2c.h b/ChibiOS_20.3.2/os/hal/include/hal_i2c.h new file mode 100644 index 0000000..c5776d2 --- /dev/null +++ b/ChibiOS_20.3.2/os/hal/include/hal_i2c.h @@ -0,0 +1,166 @@ +/*
+ ChibiOS - Copyright (C) 2006..2018 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.
+*/
+/*
+ Concepts and parts of this file have been contributed by Uladzimir Pylinsky
+ aka barthess.
+ */
+
+/**
+ * @file hal_i2c.h
+ * @brief I2C Driver macros and structures.
+ *
+ * @addtogroup I2C
+ * @{
+ */
+
+#ifndef HAL_I2C_H
+#define HAL_I2C_H
+
+#if (HAL_USE_I2C == TRUE) || defined(__DOXYGEN__)
+
+/*===========================================================================*/
+/* Driver constants. */
+/*===========================================================================*/
+
+/* TODO: To be reviewed, too STM32-centric.*/
+/**
+ * @name I2C bus error conditions
+ * @{
+ */
+#define I2C_NO_ERROR 0x00 /**< @brief No error. */
+#define I2C_BUS_ERROR 0x01 /**< @brief Bus Error. */
+#define I2C_ARBITRATION_LOST 0x02 /**< @brief Arbitration Lost. */
+#define I2C_ACK_FAILURE 0x04 /**< @brief Acknowledge Failure. */
+#define I2C_OVERRUN 0x08 /**< @brief Overrun/Underrun. */
+#define I2C_PEC_ERROR 0x10 /**< @brief PEC Error in
+ reception. */
+#define I2C_TIMEOUT 0x20 /**< @brief Hardware timeout. */
+#define I2C_SMB_ALERT 0x40 /**< @brief SMBus Alert. */
+/** @} */
+
+/*===========================================================================*/
+/* Driver pre-compile time settings. */
+/*===========================================================================*/
+
+/**
+ * @brief Enables the mutual exclusion APIs on the I2C bus.
+ */
+#if !defined(I2C_USE_MUTUAL_EXCLUSION) || defined(__DOXYGEN__)
+#define I2C_USE_MUTUAL_EXCLUSION TRUE
+#endif
+
+/*===========================================================================*/
+/* Derived constants and error checks. */
+/*===========================================================================*/
+
+/*===========================================================================*/
+/* Driver data structures and types. */
+/*===========================================================================*/
+
+/**
+ * @brief Driver state machine possible states.
+ */
+typedef enum {
+ I2C_UNINIT = 0, /**< @brief Not initialized. */
+ I2C_STOP = 1, /**< @brief Stopped. */
+ I2C_READY = 2, /**< @brief Ready. */
+ I2C_ACTIVE_TX = 3, /**< @brief Transmitting. */
+ I2C_ACTIVE_RX = 4, /**< @brief Receiving. */
+ I2C_LOCKED = 5 /**< @brief Bus locked. */
+} i2cstate_t;
+
+#include "hal_i2c_lld.h"
+
+/*===========================================================================*/
+/* Driver macros. */
+/*===========================================================================*/
+
+/**
+ * @brief Wakes up the waiting thread notifying no errors.
+ *
+ * @param[in] i2cp pointer to the @p I2CDriver object
+ *
+ * @notapi
+ */
+#define _i2c_wakeup_isr(i2cp) do { \
+ osalSysLockFromISR(); \
+ osalThreadResumeI(&(i2cp)->thread, MSG_OK); \
+ osalSysUnlockFromISR(); \
+} while (0)
+
+/**
+ * @brief Wakes up the waiting thread notifying errors.
+ *
+ * @param[in] i2cp pointer to the @p I2CDriver object
+ *
+ * @notapi
+ */
+#define _i2c_wakeup_error_isr(i2cp) do { \
+ osalSysLockFromISR(); \
+ osalThreadResumeI(&(i2cp)->thread, MSG_RESET); \
+ osalSysUnlockFromISR(); \
+} while (0)
+
+/**
+ * @brief Wrap i2cMasterTransmitTimeout function with TIME_INFINITE timeout.
+ * @api
+ */
+#define i2cMasterTransmit(i2cp, addr, txbuf, txbytes, rxbuf, rxbytes) \
+ (i2cMasterTransmitTimeout(i2cp, addr, txbuf, txbytes, rxbuf, rxbytes, \
+ TIME_INFINITE))
+
+/**
+ * @brief Wrap i2cMasterReceiveTimeout function with TIME_INFINITE timeout.
+ * @api
+ */
+#define i2cMasterReceive(i2cp, addr, rxbuf, rxbytes) \
+ (i2cMasterReceiveTimeout(i2cp, addr, rxbuf, rxbytes, TIME_INFINITE))
+
+/*===========================================================================*/
+/* External declarations. */
+/*===========================================================================*/
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+ void i2cInit(void);
+ void i2cObjectInit(I2CDriver *i2cp);
+ void i2cStart(I2CDriver *i2cp, const I2CConfig *config);
+ void i2cStop(I2CDriver *i2cp);
+ i2cflags_t i2cGetErrors(I2CDriver *i2cp);
+ msg_t i2cMasterTransmitTimeout(I2CDriver *i2cp,
+ i2caddr_t addr,
+ const uint8_t *txbuf, size_t txbytes,
+ uint8_t *rxbuf, size_t rxbytes,
+ sysinterval_t timeout);
+ msg_t i2cMasterReceiveTimeout(I2CDriver *i2cp,
+ i2caddr_t addr,
+ uint8_t *rxbuf, size_t rxbytes,
+ sysinterval_t timeout);
+#if I2C_USE_MUTUAL_EXCLUSION == TRUE
+ void i2cAcquireBus(I2CDriver *i2cp);
+ void i2cReleaseBus(I2CDriver *i2cp);
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* HAL_USE_I2C == TRUE */
+
+#endif /* HAL_I2C_H */
+
+/** @} */
diff --git a/ChibiOS_20.3.2/os/hal/include/hal_i2s.h b/ChibiOS_20.3.2/os/hal/include/hal_i2s.h new file mode 100644 index 0000000..1dccaaa --- /dev/null +++ b/ChibiOS_20.3.2/os/hal/include/hal_i2s.h @@ -0,0 +1,240 @@ +/*
+ ChibiOS - Copyright (C) 2006..2018 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_i2s.h
+ * @brief I2S Driver macros and structures.
+ *
+ * @addtogroup I2S
+ * @{
+ */
+
+#ifndef HAL_I2S_H
+#define HAL_I2S_H
+
+#if (HAL_USE_I2S == TRUE) || defined(__DOXYGEN__)
+
+/*===========================================================================*/
+/* Driver constants. */
+/*===========================================================================*/
+
+/**
+ * @name I2S modes
+ * @{
+ */
+#define I2S_MODE_SLAVE 0
+#define I2S_MODE_MASTER 1
+/** @} */
+
+/*===========================================================================*/
+/* Driver pre-compile time settings. */
+/*===========================================================================*/
+
+/*===========================================================================*/
+/* Derived constants and error checks. */
+/*===========================================================================*/
+
+/*===========================================================================*/
+/* Driver data structures and types. */
+/*===========================================================================*/
+
+/**
+ * @brief Driver state machine possible states.
+ */
+typedef enum {
+ I2S_UNINIT = 0, /**< Not initialized. */
+ I2S_STOP = 1, /**< Stopped. */
+ I2S_READY = 2, /**< Ready. */
+ I2S_ACTIVE = 3, /**< Active. */
+ I2S_COMPLETE = 4 /**< Transmission complete. */
+} i2sstate_t;
+
+/**
+ * @brief Type of a structure representing an I2S driver.
+ */
+typedef struct hal_i2s_driver I2SDriver;
+
+/**
+ * @brief Type of a structure representing an I2S driver configuration.
+ */
+typedef struct hal_i2s_config I2SConfig;
+
+/**
+ * @brief I2S notification callback type.
+ *
+ * @param[in] i2sp pointer to the @p I2SDriver object
+ */
+typedef void (*i2scallback_t)(I2SDriver *i2sp);
+
+/* Including the low level driver header, it exports information required
+ for completing types.*/
+#include "hal_i2s_lld.h"
+
+/**
+ * @brief Structure representing an I2S driver.
+ */
+struct hal_i2s_driver {
+ /**
+ * @brief Driver state.
+ */
+ i2sstate_t state;
+ /**
+ * @brief Current configuration data.
+ */
+ const I2SConfig *config;
+ /* End of the mandatory fields.*/
+ i2s_lld_driver_fields;
+};
+
+/**
+ * @brief Driver configuration structure.
+ */
+struct hal_i2s_config {
+ /**
+ * @brief Transmission buffer pointer.
+ * @note Can be @p NULL if TX is not required.
+ */
+ const void *tx_buffer;
+ /**
+ * @brief Receive buffer pointer.
+ * @note Can be @p NULL if RX is not required.
+ */
+ void *rx_buffer;
+ /**
+ * @brief TX and RX buffers size as number of samples.
+ */
+ size_t size;
+ /**
+ * @brief Callback function called during streaming.
+ */
+ i2scallback_t end_cb;
+ /* End of the mandatory fields.*/
+ i2s_lld_config_fields;
+};
+
+/*===========================================================================*/
+/* Driver macros. */
+/*===========================================================================*/
+
+/**
+ * @name Macro Functions
+ * @{
+ */
+/**
+ * @brief Buffer state.
+ * @note This function is meant to be called from the SPI callback only.
+ *
+ * @param[in] i2sp pointer to the @p I2SDriver object
+ * @return The buffer state.
+ * @retval false if the driver filled/sent the first half of the
+ * buffer.
+ * @retval true if the driver filled/sent the second half of the
+ * buffer.
+ *
+ * @special
+ */
+#define i2sIsBufferComplete(i2sp) ((bool)((i2sp)->state == I2S_COMPLETE))
+
+/**
+ * @brief Starts a I2S data exchange.
+ *
+ * @param[in] i2sp pointer to the @p I2SDriver object
+ *
+ * @iclass
+ */
+#define i2sStartExchangeI(i2sp) { \
+ i2s_lld_start_exchange(i2sp); \
+ (i2sp)->state = I2S_ACTIVE; \
+}
+
+/**
+ * @brief Stops the ongoing data exchange.
+ * @details The ongoing data exchange, if any, is stopped, if the driver
+ * was not active the function does nothing.
+ *
+ * @param[in] i2sp pointer to the @p I2SDriver object
+ *
+ * @iclass
+ */
+#define i2sStopExchangeI(i2sp) { \
+ i2s_lld_stop_exchange(i2sp); \
+ (i2sp)->state = I2S_READY; \
+}
+
+/**
+ * @brief Common ISR code, half buffer event.
+ * @details This code handles the portable part of the ISR code:
+ * - Callback invocation.
+ * .
+ * @note This macro is meant to be used in the low level drivers
+ * implementation only.
+ *
+ * @param[in] i2sp pointer to the @p I2CDriver object
+ *
+ * @notapi
+ */
+#define _i2s_isr_half_code(i2sp) { \
+ if ((i2sp)->config->end_cb != NULL) { \
+ (i2sp)->config->end_cb(i2sp); \
+ } \
+}
+
+/**
+ * @brief Common ISR code.
+ * @details This code handles the portable part of the ISR code:
+ * - Callback invocation.
+ * - Driver state transitions.
+ * .
+ * @note This macro is meant to be used in the low level drivers
+ * implementation only.
+ *
+ * @param[in] i2sp pointer to the @p I2CDriver object
+ *
+ * @notapi
+ */
+#define _i2s_isr_full_code(i2sp) { \
+ if ((i2sp)->config->end_cb) { \
+ (i2sp)->state = I2S_COMPLETE; \
+ (i2sp)->config->end_cb(i2sp); \
+ if ((i2sp)->state == I2S_COMPLETE) { \
+ (i2sp)->state = I2S_ACTIVE; \
+ } \
+ } \
+}
+/** @} */
+
+/*===========================================================================*/
+/* External declarations. */
+/*===========================================================================*/
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+ void i2sInit(void);
+ void i2sObjectInit(I2SDriver *i2sp);
+ void i2sStart(I2SDriver *i2sp, const I2SConfig *config);
+ void i2sStop(I2SDriver *i2sp);
+ void i2sStartExchange(I2SDriver *i2sp);
+ void i2sStopExchange(I2SDriver *i2sp);
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* HAL_USE_I2S == TRUE */
+
+#endif /* HAL_I2S_H */
+
+/** @} */
diff --git a/ChibiOS_20.3.2/os/hal/include/hal_icu.h b/ChibiOS_20.3.2/os/hal/include/hal_icu.h new file mode 100644 index 0000000..89c4a62 --- /dev/null +++ b/ChibiOS_20.3.2/os/hal/include/hal_icu.h @@ -0,0 +1,240 @@ +/*
+ ChibiOS - Copyright (C) 2006..2018 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_icu.h
+ * @brief ICU Driver macros and structures.
+ *
+ * @addtogroup ICU
+ * @{
+ */
+
+#ifndef HAL_ICU_H
+#define HAL_ICU_H
+
+#if (HAL_USE_ICU == TRUE) || defined(__DOXYGEN__)
+
+/*===========================================================================*/
+/* Driver constants. */
+/*===========================================================================*/
+
+/*===========================================================================*/
+/* Driver pre-compile time settings. */
+/*===========================================================================*/
+
+/*===========================================================================*/
+/* Derived constants and error checks. */
+/*===========================================================================*/
+
+/*===========================================================================*/
+/* Driver data structures and types. */
+/*===========================================================================*/
+
+/**
+ * @brief Driver state machine possible states.
+ */
+typedef enum {
+ ICU_UNINIT = 0, /**< Not initialized. */
+ ICU_STOP = 1, /**< Stopped. */
+ ICU_READY = 2, /**< Ready. */
+ ICU_WAITING = 3, /**< Waiting for first front. */
+ ICU_ACTIVE = 4 /**< First front detected. */
+} icustate_t;
+
+/**
+ * @brief Type of a structure representing an ICU driver.
+ */
+typedef struct ICUDriver ICUDriver;
+
+/**
+ * @brief ICU notification callback type.
+ *
+ * @param[in] icup pointer to a @p ICUDriver object
+ */
+typedef void (*icucallback_t)(ICUDriver *icup);
+
+#include "hal_icu_lld.h"
+
+/*===========================================================================*/
+/* Driver macros. */
+/*===========================================================================*/
+
+/**
+ * @name Macro Functions
+ * @{
+ */
+/**
+ * @brief Starts the input capture.
+ *
+ * @param[in] icup pointer to the @p ICUDriver object
+ *
+ * @iclass
+ */
+#define icuStartCaptureI(icup) do { \
+ icu_lld_start_capture(icup); \
+ (icup)->state = ICU_WAITING; \
+} while (false)
+
+/**
+ * @brief Stops the input capture.
+ *
+ * @param[in] icup pointer to the @p ICUDriver object
+ *
+ * @iclass
+ */
+#define icuStopCaptureI(icup) do { \
+ icu_lld_stop_capture(icup); \
+ (icup)->state = ICU_READY; \
+} while (false)
+
+/**
+ * @brief Enables notifications.
+ * @pre The ICU unit must have been activated using @p icuStart() and the
+ * capture started using @p icuStartCapture().
+ * @note If the notification is already enabled then the call has no effect.
+ *
+ * @param[in] icup pointer to the @p ICUDriver object
+ *
+ * @iclass
+ */
+#define icuEnableNotificationsI(icup) icu_lld_enable_notifications(icup)
+
+/**
+ * @brief Disables notifications.
+ * @pre The ICU unit must have been activated using @p icuStart() and the
+ * capture started using @p icuStartCapture().
+ * @note If the notification is already disabled then the call has no effect.
+ *
+ * @param[in] icup pointer to the @p ICUDriver object
+ *
+ * @iclass
+ */
+#define icuDisableNotificationsI(icup) icu_lld_disable_notifications(icup)
+
+/**
+ * @brief Check on notifications status.
+ *
+ * @param[in] icup pointer to the @p ICUDriver object
+ * @return The notifications status.
+ * @retval false if notifications are not enabled.
+ * @retval true if notifications are enabled.
+ *
+ * @notapi
+ */
+#define icuAreNotificationsEnabledX(icup) \
+ icu_lld_are_notifications_enabled(icup)
+
+/**
+ * @brief Returns the width of the latest pulse.
+ * @details The pulse width is defined as number of ticks between the start
+ * edge and the stop edge.
+ * @note This function is meant to be invoked from the width capture
+ * callback.
+ *
+ * @param[in] icup pointer to the @p ICUDriver object
+ * @return The number of ticks.
+ *
+ * @xclass
+ */
+#define icuGetWidthX(icup) icu_lld_get_width(icup)
+
+/**
+ * @brief Returns the width of the latest cycle.
+ * @details The cycle width is defined as number of ticks between a start
+ * edge and the next start edge.
+ * @note This function is meant to be invoked from the width capture
+ * callback.
+ *
+ * @param[in] icup pointer to the @p ICUDriver object
+ * @return The number of ticks.
+ *
+ * @xclass
+ */
+#define icuGetPeriodX(icup) icu_lld_get_period(icup)
+/** @} */
+
+/**
+ * @name Low level driver helper macros
+ * @{
+ */
+/**
+ * @brief Common ISR code, ICU width event.
+ *
+ * @param[in] icup pointer to the @p ICUDriver object
+ *
+ * @notapi
+ */
+#define _icu_isr_invoke_width_cb(icup) do { \
+ if (((icup)->state == ICU_ACTIVE) && \
+ ((icup)->config->width_cb != NULL)) \
+ (icup)->config->width_cb(icup); \
+} while (0)
+
+/**
+ * @brief Common ISR code, ICU period event.
+ * @note A period event brings the driver into the @p ICU_ACTIVE state.
+ *
+ * @param[in] icup pointer to the @p ICUDriver object
+ *
+ * @notapi
+ */
+#define _icu_isr_invoke_period_cb(icup) do { \
+ if (((icup)->state == ICU_ACTIVE) && \
+ ((icup)->config->period_cb != NULL)) \
+ (icup)->config->period_cb(icup); \
+ (icup)->state = ICU_ACTIVE; \
+} while (0)
+
+/**
+ * @brief Common ISR code, ICU timer overflow event.
+ * @note An overflow always brings the driver back to the @p ICU_WAITING
+ * state.
+ *
+ * @param[in] icup pointer to the @p ICUDriver object
+ *
+ * @notapi
+ */
+#define _icu_isr_invoke_overflow_cb(icup) do { \
+ (icup)->config->overflow_cb(icup); \
+ (icup)->state = ICU_WAITING; \
+} while (0)
+/** @} */
+
+/*===========================================================================*/
+/* External declarations. */
+/*===========================================================================*/
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+ void icuInit(void);
+ void icuObjectInit(ICUDriver *icup);
+ void icuStart(ICUDriver *icup, const ICUConfig *config);
+ void icuStop(ICUDriver *icup);
+ void icuStartCapture(ICUDriver *icup);
+ bool icuWaitCapture(ICUDriver *icup);
+ void icuStopCapture(ICUDriver *icup);
+ void icuEnableNotifications(ICUDriver *icup);
+ void icuDisableNotifications(ICUDriver *icup);
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* HAL_USE_ICU == TRUE */
+
+#endif /* HAL_ICU_H */
+
+/** @} */
diff --git a/ChibiOS_20.3.2/os/hal/include/hal_ioblock.h b/ChibiOS_20.3.2/os/hal/include/hal_ioblock.h new file mode 100644 index 0000000..c720a4a --- /dev/null +++ b/ChibiOS_20.3.2/os/hal/include/hal_ioblock.h @@ -0,0 +1,269 @@ +/*
+ ChibiOS - Copyright (C) 2006..2018 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_ioblock.h
+ * @brief I/O block devices access.
+ * @details This header defines an abstract interface useful to access generic
+ * I/O block devices in a standardized way.
+ *
+ * @addtogroup IO_BLOCK
+ * @details This module defines an abstract interface for accessing generic
+ * block devices.<br>
+ * Note that no code is present, just abstract interfaces-like
+ * structures, you should look at the system as to a set of
+ * abstract C++ classes (even if written in C). This system
+ * has then advantage to make the access to block devices
+ * independent from the implementation logic.
+ * @{
+ */
+
+#ifndef HAL_IOBLOCK_H
+#define HAL_IOBLOCK_H
+
+/**
+ * @brief Driver state machine possible states.
+ */
+typedef enum {
+ BLK_UNINIT = 0, /**< Not initialized. */
+ BLK_STOP = 1, /**< Stopped. */
+ BLK_ACTIVE = 2, /**< Interface active. */
+ BLK_CONNECTING = 3, /**< Connection in progress. */
+ BLK_DISCONNECTING = 4, /**< Disconnection in progress. */
+ BLK_READY = 5, /**< Device ready. */
+ BLK_READING = 6, /**< Read operation in progress. */
+ BLK_WRITING = 7, /**< Write operation in progress. */
+ BLK_SYNCING = 8 /**< Sync. operation in progress. */
+} blkstate_t;
+
+/**
+ * @brief Block device info.
+ */
+typedef struct {
+ uint32_t blk_size; /**< @brief Block size in bytes. */
+ uint32_t blk_num; /**< @brief Total number of blocks. */
+} BlockDeviceInfo;
+
+/**
+ * @brief @p BaseBlockDevice specific methods.
+ */
+#define _base_block_device_methods \
+ _base_object_methods \
+ /* Removable media detection.*/ \
+ bool (*is_inserted)(void *instance); \
+ /* Removable write protection detection.*/ \
+ bool (*is_protected)(void *instance); \
+ /* Connection to the block device.*/ \
+ bool (*connect)(void *instance); \
+ /* Disconnection from the block device.*/ \
+ bool (*disconnect)(void *instance); \
+ /* Reads one or more blocks.*/ \
+ bool (*read)(void *instance, uint32_t startblk, \
+ uint8_t *buffer, uint32_t n); \
+ /* Writes one or more blocks.*/ \
+ bool (*write)(void *instance, uint32_t startblk, \
+ const uint8_t *buffer, uint32_t n); \
+ /* Write operations synchronization.*/ \
+ bool (*sync)(void *instance); \
+ /* Obtains info about the media.*/ \
+ bool (*get_info)(void *instance, BlockDeviceInfo *bdip);
+
+/**
+ * @brief @p BaseBlockDevice specific data.
+ */
+#define _base_block_device_data \
+ _base_object_data \
+ /* Driver state.*/ \
+ blkstate_t state;
+
+/**
+ * @brief @p BaseBlockDevice virtual methods table.
+ */
+struct BaseBlockDeviceVMT {
+ _base_block_device_methods
+};
+
+/**
+ * @extends BaseObject
+ *
+ * @brief Base block device class.
+ * @details This class represents a generic, block-accessible, device.
+ */
+typedef struct {
+ /** @brief Virtual Methods Table.*/
+ const struct BaseBlockDeviceVMT *vmt;
+ _base_block_device_data
+} BaseBlockDevice;
+
+/**
+ * @name Macro Functions (BaseBlockDevice)
+ * @{
+ */
+/**
+ * @brief Returns the driver state.
+ * @note Can be called in ISR context.
+ *
+ * @param[in] ip pointer to a @p BaseBlockDevice or derived class
+ *
+ * @return The driver state.
+ *
+ * @special
+ */
+#define blkGetDriverState(ip) ((ip)->state)
+
+/**
+ * @brief Determines if the device is transferring data.
+ * @note Can be called in ISR context.
+ *
+ * @param[in] ip pointer to a @p BaseBlockDevice or derived class
+ *
+ * @return The driver state.
+ * @retval false the device is not transferring data.
+ * @retval true the device not transferring data.
+ *
+ * @special
+ */
+#define blkIsTransferring(ip) ((((ip)->state) == BLK_CONNECTING) || \
+ (((ip)->state) == BLK_DISCONNECTING) || \
+ (((ip)->state) == BLK_READING) || \
+ (((ip)->state) == BLK_WRITING))
+
+/**
+ * @brief Returns the media insertion status.
+ * @note On some implementations this function can only be called if the
+ * device is not transferring data.
+ * The function @p blkIsTransferring() should be used before calling
+ * this function.
+ *
+ * @param[in] ip pointer to a @p BaseBlockDevice or derived class
+ *
+ * @return The media state.
+ * @retval false media not inserted.
+ * @retval true media inserted.
+ *
+ * @api
+ */
+#define blkIsInserted(ip) ((ip)->vmt->is_inserted(ip))
+
+/**
+ * @brief Returns the media write protection status.
+ *
+ * @param[in] ip pointer to a @p BaseBlockDevice or derived class
+ *
+ * @return The media state.
+ * @retval false writable media.
+ * @retval true non writable media.
+ *
+ * @api
+ */
+#define blkIsWriteProtected(ip) ((ip)->vmt->is_protected(ip))
+
+/**
+ * @brief Performs the initialization procedure on the block device.
+ * @details This function should be performed before I/O operations can be
+ * attempted on the block device and after insertion has been
+ * confirmed using @p blkIsInserted().
+ *
+ * @param[in] ip pointer to a @p BaseBlockDevice or derived class
+ *
+ * @return The operation status.
+ * @retval HAL_SUCCESS operation succeeded.
+ * @retval HAL_FAILED operation failed.
+ *
+ * @api
+ */
+#define blkConnect(ip) ((ip)->vmt->connect(ip))
+
+/**
+ * @brief Terminates operations on the block device.
+ * @details This operation safely terminates operations on the block device.
+ *
+ * @param[in] ip pointer to a @p BaseBlockDevice or derived class
+ *
+ * @return The operation status.
+ * @retval HAL_SUCCESS operation succeeded.
+ * @retval HAL_FAILED operation failed.
+ *
+ * @api
+ */
+#define blkDisconnect(ip) ((ip)->vmt->disconnect(ip))
+
+/**
+ * @brief Reads one or more blocks.
+ *
+ * @param[in] ip pointer to a @p BaseBlockDevice or derived class
+ * @param[in] startblk first block to read
+ * @param[out] buf pointer to the read buffer
+ * @param[in] n number of blocks to read
+ *
+ * @return The operation status.
+ * @retval HAL_SUCCESS operation succeeded.
+ * @retval HAL_FAILED operation failed.
+ *
+ * @api
+ */
+#define blkRead(ip, startblk, buf, n) \
+ ((ip)->vmt->read(ip, startblk, buf, n))
+
+/**
+ * @brief Writes one or more blocks.
+ *
+ * @param[in] ip pointer to a @p BaseBlockDevice or derived class
+ * @param[in] startblk first block to write
+ * @param[out] buf pointer to the write buffer
+ * @param[in] n number of blocks to write
+ *
+ * @return The operation status.
+ * @retval HAL_SUCCESS operation succeeded.
+ * @retval HAL_FAILED operation failed.
+ *
+ * @api
+ */
+#define blkWrite(ip, startblk, buf, n) \
+ ((ip)->vmt->write(ip, startblk, buf, n))
+
+/**
+ * @brief Ensures write synchronization.
+ *
+ * @param[in] ip pointer to a @p BaseBlockDevice or derived class
+ *
+ * @return The operation status.
+ * @retval HAL_SUCCESS operation succeeded.
+ * @retval HAL_FAILED operation failed.
+ *
+ * @api
+ */
+#define blkSync(ip) ((ip)->vmt->sync(ip))
+
+/**
+ * @brief Returns a media information structure.
+ *
+ * @param[in] ip pointer to a @p BaseBlockDevice or derived class
+ * @param[out] bdip pointer to a @p BlockDeviceInfo structure
+ *
+ * @return The operation status.
+ * @retval HAL_SUCCESS operation succeeded.
+ * @retval HAL_FAILED operation failed.
+ *
+ * @api
+ */
+#define blkGetInfo(ip, bdip) ((ip)->vmt->get_info(ip, bdip))
+
+/** @} */
+
+#endif /* HAL_IOBLOCK_H */
+
+/** @} */
diff --git a/ChibiOS_20.3.2/os/hal/include/hal_mac.h b/ChibiOS_20.3.2/os/hal/include/hal_mac.h new file mode 100644 index 0000000..00a73a8 --- /dev/null +++ b/ChibiOS_20.3.2/os/hal/include/hal_mac.h @@ -0,0 +1,202 @@ +/*
+ ChibiOS - Copyright (C) 2006..2018 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_mac.h
+ * @brief MAC Driver macros and structures.
+ * @addtogroup MAC
+ * @{
+ */
+
+#ifndef HAL_MAC_H
+#define HAL_MAC_H
+
+#if (HAL_USE_MAC == TRUE) || defined(__DOXYGEN__)
+
+/*===========================================================================*/
+/* Driver constants. */
+/*===========================================================================*/
+
+/*===========================================================================*/
+/* Driver pre-compile time settings. */
+/*===========================================================================*/
+
+/**
+ * @name MAC configuration options
+ * @{
+ */
+/**
+ * @brief Enables an event sources for incoming packets.
+ */
+#if !defined(MAC_USE_ZERO_COPY) || defined(__DOXYGEN__)
+#define MAC_USE_ZERO_COPY FALSE
+#endif
+
+/**
+ * @brief Enables an event sources for incoming packets.
+ */
+#if !defined(MAC_USE_EVENTS) || defined(__DOXYGEN__)
+#define MAC_USE_EVENTS TRUE
+#endif
+/** @} */
+
+/*===========================================================================*/
+/* Derived constants and error checks. */
+/*===========================================================================*/
+
+/*===========================================================================*/
+/* Driver data structures and types. */
+/*===========================================================================*/
+
+/**
+ * @brief Driver state machine possible states.
+ */
+typedef enum {
+ MAC_UNINIT = 0, /**< Not initialized. */
+ MAC_STOP = 1, /**< Stopped. */
+ MAC_ACTIVE = 2 /**< Active. */
+} macstate_t;
+
+/**
+ * @brief Type of a structure representing a MAC driver.
+ */
+typedef struct MACDriver MACDriver;
+
+#include "hal_mac_lld.h"
+
+/*===========================================================================*/
+/* Driver macros. */
+/*===========================================================================*/
+
+/**
+ * @name Macro Functions
+ * @{
+ */
+/**
+ * @brief Enables the zero-copy API.
+ *
+ * @param[in] macp pointer to the @p MACDriver object
+ * @return The pointer to the @p EventSource structure.
+ *
+ * @api
+ */
+#if (MAC_USE_EVENTS == TRUE) || defined(__DOXYGEN__)
+#define macGetReceiveEventSource(macp) (&(macp)->rdevent)
+#endif
+
+/**
+ * @brief Writes to a transmit descriptor's stream.
+ *
+ * @param[in] tdp pointer to a @p MACTransmitDescriptor structure
+ * @param[in] buf pointer to the buffer containing the data to be written
+ * @param[in] size number of bytes to be written
+ * @return The number of bytes written into the descriptor's
+ * stream, this value can be less than the amount
+ * specified in the parameter @p size if the maximum frame
+ * size is reached.
+ *
+ * @api
+ */
+#define macWriteTransmitDescriptor(tdp, buf, size) \
+ mac_lld_write_transmit_descriptor(tdp, buf, size)
+
+/**
+ * @brief Reads from a receive descriptor's stream.
+ *
+ * @param[in] rdp pointer to a @p MACReceiveDescriptor structure
+ * @param[in] buf pointer to the buffer that will receive the read data
+ * @param[in] size number of bytes to be read
+ * @return The number of bytes read from the descriptor's stream,
+ * this value can be less than the amount specified in the
+ * parameter @p size if there are no more bytes to read.
+ *
+ * @api
+ */
+#define macReadReceiveDescriptor(rdp, buf, size) \
+ mac_lld_read_receive_descriptor(rdp, buf, size)
+
+#if (MAC_USE_ZERO_COPY == TRUE) || defined(__DOXYGEN__)
+/**
+ * @brief Returns a pointer to the next transmit buffer in the descriptor
+ * chain.
+ * @note The API guarantees that enough buffers can be requested to fill
+ * a whole frame.
+ *
+ * @param[in] tdp pointer to a @p MACTransmitDescriptor structure
+ * @param[in] size size of the requested buffer. Specify the frame size
+ * on the first call then scale the value down subtracting
+ * the amount of data already copied into the previous
+ * buffers.
+ * @param[out] sizep pointer to variable receiving the real buffer size.
+ * The returned value can be less than the amount
+ * requested, this means that more buffers must be
+ * requested in order to fill the frame data entirely.
+ * @return Pointer to the returned buffer.
+ *
+ * @api
+ */
+#define macGetNextTransmitBuffer(tdp, size, sizep) \
+ mac_lld_get_next_transmit_buffer(tdp, size, sizep)
+
+/**
+ * @brief Returns a pointer to the next receive buffer in the descriptor
+ * chain.
+ * @note The API guarantees that the descriptor chain contains a whole
+ * frame.
+ *
+ * @param[in] rdp pointer to a @p MACReceiveDescriptor structure
+ * @param[out] sizep pointer to variable receiving the buffer size, it is
+ * zero when the last buffer has already been returned.
+ * @return Pointer to the returned buffer.
+ * @retval NULL if the buffer chain has been entirely scanned.
+ *
+ * @api
+ */
+#define macGetNextReceiveBuffer(rdp, sizep) \
+ mac_lld_get_next_receive_buffer(rdp, sizep)
+#endif /* MAC_USE_ZERO_COPY */
+/** @} */
+
+/*===========================================================================*/
+/* External declarations. */
+/*===========================================================================*/
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+ void macInit(void);
+ void macObjectInit(MACDriver *macp);
+ void macStart(MACDriver *macp, const MACConfig *config);
+ void macStop(MACDriver *macp);
+ void macSetAddress(MACDriver *macp, const uint8_t *p);
+ msg_t macWaitTransmitDescriptor(MACDriver *macp,
+ MACTransmitDescriptor *tdp,
+ sysinterval_t timeout);
+ void macReleaseTransmitDescriptor(MACTransmitDescriptor *tdp);
+ msg_t macWaitReceiveDescriptor(MACDriver *macp,
+ MACReceiveDescriptor *rdp,
+ sysinterval_t timeout);
+ void macReleaseReceiveDescriptor(MACReceiveDescriptor *rdp);
+ bool macPollLinkStatus(MACDriver *macp);
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* HAL_USE_MAC == TRUE */
+
+#endif /* HAL_MAC_H */
+
+/** @} */
diff --git a/ChibiOS_20.3.2/os/hal/include/hal_mii.h b/ChibiOS_20.3.2/os/hal/include/hal_mii.h new file mode 100644 index 0000000..80cbfd2 --- /dev/null +++ b/ChibiOS_20.3.2/os/hal/include/hal_mii.h @@ -0,0 +1,176 @@ +/*
+ ChibiOS - Copyright (C) 2006..2018 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_mii.h
+ * @brief MII macros and structures.
+ *
+ * @addtogroup MII
+ * @{
+ */
+
+#ifndef MII_H
+#define MII_H
+
+/**
+ * @name Generic MII registers
+ * @{
+ */
+#define MII_BMCR 0x00 /**< Basic mode control register. */
+#define MII_BMSR 0x01 /**< Basic mode status register. */
+#define MII_PHYSID1 0x02 /**< PHYS ID 1. */
+#define MII_PHYSID2 0x03 /**< PHYS ID 2. */
+#define MII_ADVERTISE 0x04 /**< Advertisement control reg. */
+#define MII_LPA 0x05 /**< Link partner ability reg. */
+#define MII_EXPANSION 0x06 /**< Expansion register. */
+#define MII_ANNPTR 0x07 /**< 1000BASE-T control. */
+#define MII_CTRL1000 0x09 /**< 1000BASE-T control. */
+#define MII_STAT1000 0x0a /**< 1000BASE-T status. */
+#define MII_ESTATUS 0x0f /**< Extended Status. */
+#define MII_PHYSTS 0x10 /**< PHY Status register. */
+#define MII_MICR 0x11 /**< MII Interrupt ctrl register. */
+#define MII_DCOUNTER 0x12 /**< Disconnect counter. */
+#define MII_FCSCOUNTER 0x13 /**< False carrier counter. */
+#define MII_NWAYTEST 0x14 /**< N-way auto-neg test reg. */
+#define MII_RERRCOUNTER 0x15 /**< Receive error counter. */
+#define MII_SREVISION 0x16 /**< Silicon revision. */
+#define MII_RESV1 0x17 /**< Reserved. */
+#define MII_LBRERROR 0x18 /**< Lpback, rx, bypass error. */
+#define MII_PHYADDR 0x19 /**< PHY address. */
+#define MII_RESV2 0x1a /**< Reserved. */
+#define MII_TPISTATUS 0x1b /**< TPI status for 10Mbps. */
+#define MII_NCONFIG 0x1c /**< Network interface config. */
+/** @} */
+
+/**
+ * @name Basic mode control register
+ * @{
+ */
+#define BMCR_RESV 0x007f /**< Unused. */
+#define BMCR_CTST 0x0080 /**< Collision test. */
+#define BMCR_FULLDPLX 0x0100 /**< Full duplex. */
+#define BMCR_ANRESTART 0x0200 /**< Auto negotiation restart. */
+#define BMCR_ISOLATE 0x0400 /**< Disconnect DP83840 from MII. */
+#define BMCR_PDOWN 0x0800 /**< Powerdown. */
+#define BMCR_ANENABLE 0x1000 /**< Enable auto negotiation. */
+#define BMCR_SPEED100 0x2000 /**< Select 100Mbps. */
+#define BMCR_LOOPBACK 0x4000 /**< TXD loopback bit. */
+#define BMCR_RESET 0x8000 /**< Reset. */
+/** @} */
+
+/**
+ * @name Basic mode status register
+ * @{
+ */
+#define BMSR_ERCAP 0x0001 /**< Ext-reg capability. */
+#define BMSR_JCD 0x0002 /**< Jabber detected. */
+#define BMSR_LSTATUS 0x0004 /**< Link status. */
+#define BMSR_ANEGCAPABLE 0x0008 /**< Able to do auto-negotiation. */
+#define BMSR_RFAULT 0x0010 /**< Remote fault detected. */
+#define BMSR_ANEGCOMPLETE 0x0020 /**< Auto-negotiation complete. */
+#define BMSR_MFPRESUPPCAP 0x0040 /**< Able to suppress preamble. */
+#define BMSR_RESV 0x0780 /**< Unused. */
+#define BMSR_10HALF 0x0800 /**< Can do 10mbps, half-duplex. */
+#define BMSR_10FULL 0x1000 /**< Can do 10mbps, full-duplex. */
+#define BMSR_100HALF 0x2000 /**< Can do 100mbps, half-duplex. */
+#define BMSR_100FULL 0x4000 /**< Can do 100mbps, full-duplex. */
+#define BMSR_100BASE4 0x8000 /**< Can do 100mbps, 4k packets. */
+/** @} */
+
+/**
+ * @name Advertisement control register
+ * @{
+ */
+#define ADVERTISE_SLCT 0x001f /**< Selector bits. */
+#define ADVERTISE_CSMA 0x0001 /**< Only selector supported. */
+#define ADVERTISE_10HALF 0x0020 /**< Try for 10mbps half-duplex. */
+#define ADVERTISE_10FULL 0x0040 /**< Try for 10mbps full-duplex. */
+#define ADVERTISE_100HALF 0x0080 /**< Try for 100mbps half-duplex. */
+#define ADVERTISE_100FULL 0x0100 /**< Try for 100mbps full-duplex. */
+#define ADVERTISE_100BASE4 0x0200 /**< Try for 100mbps 4k packets. */
+#define ADVERTISE_PAUSE_CAP 0x0400 /**< Try for pause. */
+#define ADVERTISE_PAUSE_ASYM 0x0800 /**< Try for asymetric pause. */
+#define ADVERTISE_RESV 0x1000 /**< Unused. */
+#define ADVERTISE_RFAULT 0x2000 /**< Say we can detect faults. */
+#define ADVERTISE_LPACK 0x4000 /**< Ack link partners response. */
+#define ADVERTISE_NPAGE 0x8000 /**< Next page bit. */
+
+#define ADVERTISE_FULL (ADVERTISE_100FULL | ADVERTISE_10FULL | \
+ ADVERTISE_CSMA)
+#define ADVERTISE_ALL (ADVERTISE_10HALF | ADVERTISE_10FULL | \
+ ADVERTISE_100HALF | ADVERTISE_100FULL)
+/** @} */
+
+/**
+ * @name Link partner ability register
+ * @{
+ */
+#define LPA_SLCT 0x001f /**< Same as advertise selector. */
+#define LPA_10HALF 0x0020 /**< Can do 10mbps half-duplex. */
+#define LPA_10FULL 0x0040 /**< Can do 10mbps full-duplex. */
+#define LPA_100HALF 0x0080 /**< Can do 100mbps half-duplex. */
+#define LPA_100FULL 0x0100 /**< Can do 100mbps full-duplex. */
+#define LPA_100BASE4 0x0200 /**< Can do 100mbps 4k packets. */
+#define LPA_PAUSE_CAP 0x0400 /**< Can pause. */
+#define LPA_PAUSE_ASYM 0x0800 /**< Can pause asymetrically. */
+#define LPA_RESV 0x1000 /**< Unused. */
+#define LPA_RFAULT 0x2000 /**< Link partner faulted. */
+#define LPA_LPACK 0x4000 /**< Link partner acked us. */
+#define LPA_NPAGE 0x8000 /**< Next page bit. */
+
+#define LPA_DUPLEX (LPA_10FULL | LPA_100FULL)
+#define LPA_100 (LPA_100FULL | LPA_100HALF | LPA_100BASE4)
+/** @} */
+
+/**
+ * @name Expansion register for auto-negotiation
+ * @{
+ */
+#define EXPANSION_NWAY 0x0001 /**< Can do N-way auto-nego. */
+#define EXPANSION_LCWP 0x0002 /**< Got new RX page code word. */
+#define EXPANSION_ENABLENPAGE 0x0004 /**< This enables npage words. */
+#define EXPANSION_NPCAPABLE 0x0008 /**< Link partner supports npage. */
+#define EXPANSION_MFAULTS 0x0010 /**< Multiple faults detected. */
+#define EXPANSION_RESV 0xffe0 /**< Unused. */
+/** @} */
+
+/**
+ * @name N-way test register
+ * @{
+ */
+#define NWAYTEST_RESV1 0x00ff /**< Unused. */
+#define NWAYTEST_LOOPBACK 0x0100 /**< Enable loopback for N-way. */
+#define NWAYTEST_RESV2 0xfe00 /**< Unused. */
+/** @} */
+
+/**
+ * @name PHY identifiers
+ * @{
+ */
+#define MII_DM9161_ID 0x0181b8a0
+#define MII_AM79C875_ID 0x00225540
+#define MII_KSZ8081_ID 0x00221560
+#define MII_KS8721_ID 0x00221610
+#define MII_STE101P_ID 0x00061C50
+#define MII_DP83848I_ID 0x20005C90
+#define MII_LAN8710A_ID 0x0007C0F1
+#define MII_LAN8720_ID 0x0007C0F0
+#define MII_LAN8742A_ID 0x0007C130
+/** @} */
+
+#endif /* MII_H */
+
+/** @} */
diff --git a/ChibiOS_20.3.2/os/hal/include/hal_mmc_spi.h b/ChibiOS_20.3.2/os/hal/include/hal_mmc_spi.h new file mode 100644 index 0000000..2d596db --- /dev/null +++ b/ChibiOS_20.3.2/os/hal/include/hal_mmc_spi.h @@ -0,0 +1,195 @@ +/*
+ ChibiOS - Copyright (C) 2006..2018 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_mmc_spi.h
+ * @brief MMC over SPI driver header.
+ *
+ * @addtogroup MMC_SPI
+ * @{
+ */
+
+#ifndef HAL_MMC_SPI_H
+#define HAL_MMC_SPI_H
+
+#if (HAL_USE_MMC_SPI == TRUE) || defined(__DOXYGEN__)
+
+/*===========================================================================*/
+/* Driver constants. */
+/*===========================================================================*/
+
+#define MMC_CMD0_RETRY 10U
+#define MMC_CMD1_RETRY 100U
+#define MMC_ACMD41_RETRY 100U
+#define MMC_WAIT_DATA 10000U
+
+/*===========================================================================*/
+/* Driver pre-compile time settings. */
+/*===========================================================================*/
+
+/**
+ * @name MMC_SPI configuration options
+ * @{
+ */
+/**
+ * @brief Delays insertions.
+ * @details If enabled this options inserts delays into the MMC waiting
+ * routines releasing some extra CPU time for the threads with
+ * lower priority, this may slow down the driver a bit however.
+ * This option is recommended also if the SPI driver does not
+ * use a DMA channel and heavily loads the CPU.
+ */
+#if !defined(MMC_NICE_WAITING) || defined(__DOXYGEN__)
+#define MMC_NICE_WAITING TRUE
+#endif
+/** @} */
+
+/*===========================================================================*/
+/* Derived constants and error checks. */
+/*===========================================================================*/
+
+#if (HAL_USE_SPI == FALSE) || (SPI_USE_WAIT == FALSE)
+#error "MMC_SPI driver requires HAL_USE_SPI and SPI_USE_WAIT"
+#endif
+
+/*===========================================================================*/
+/* Driver data structures and types. */
+/*===========================================================================*/
+
+/**
+ * @brief MMC/SD over SPI driver configuration structure.
+ */
+typedef struct {
+ /**
+ * @brief SPI driver associated to this MMC driver.
+ */
+ SPIDriver *spip;
+ /**
+ * @brief SPI low speed configuration used during initialization.
+ */
+ const SPIConfig *lscfg;
+ /**
+ * @brief SPI high speed configuration used during transfers.
+ */
+ const SPIConfig *hscfg;
+} MMCConfig;
+
+/**
+ * @brief @p MMCDriver specific methods.
+ */
+#define _mmc_driver_methods \
+ _mmcsd_block_device_methods
+
+/**
+ * @extends MMCSDBlockDeviceVMT
+ *
+ * @brief @p MMCDriver virtual methods table.
+ */
+struct MMCDriverVMT {
+ _mmc_driver_methods
+};
+
+/**
+ * @extends MMCSDBlockDevice
+ *
+ * @brief Structure representing a MMC/SD over SPI driver.
+ */
+typedef struct {
+ /**
+ * @brief Virtual Methods Table.
+ */
+ const struct MMCDriverVMT *vmt;
+ _mmcsd_block_device_data
+ /**
+ * @brief Current configuration data.
+ */
+ const MMCConfig *config;
+ /**
+ * @brief Addresses use blocks instead of bytes.
+ */
+ bool block_addresses;
+} MMCDriver;
+
+/*===========================================================================*/
+/* Driver macros. */
+/*===========================================================================*/
+
+/**
+ * @name Macro Functions
+ * @{
+ */
+/**
+ * @brief Returns the card insertion status.
+ * @note This macro wraps a low level function named
+ * @p sdc_lld_is_card_inserted(), this function must be
+ * provided by the application because it is not part of the
+ * SDC driver.
+ *
+ * @param[in] mmcp pointer to the @p MMCDriver object
+ * @return The card state.
+ * @retval false card not inserted.
+ * @retval true card inserted.
+ *
+ * @api
+ */
+#define mmcIsCardInserted(mmcp) mmc_lld_is_card_inserted(mmcp)
+
+/**
+ * @brief Returns the write protect status.
+ *
+ * @param[in] mmcp pointer to the @p MMCDriver object
+ * @return The card state.
+ * @retval false card not inserted.
+ * @retval true card inserted.
+ *
+ * @api
+ */
+#define mmcIsWriteProtected(mmcp) mmc_lld_is_write_protected(mmcp)
+/** @} */
+
+/*===========================================================================*/
+/* External declarations. */
+/*===========================================================================*/
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+ void mmcInit(void);
+ void mmcObjectInit(MMCDriver *mmcp);
+ void mmcStart(MMCDriver *mmcp, const MMCConfig *config);
+ void mmcStop(MMCDriver *mmcp);
+ bool mmcConnect(MMCDriver *mmcp);
+ bool mmcDisconnect(MMCDriver *mmcp);
+ bool mmcStartSequentialRead(MMCDriver *mmcp, uint32_t startblk);
+ bool mmcSequentialRead(MMCDriver *mmcp, uint8_t *buffer);
+ bool mmcStopSequentialRead(MMCDriver *mmcp);
+ bool mmcStartSequentialWrite(MMCDriver *mmcp, uint32_t startblk);
+ bool mmcSequentialWrite(MMCDriver *mmcp, const uint8_t *buffer);
+ bool mmcStopSequentialWrite(MMCDriver *mmcp);
+ bool mmcSync(MMCDriver *mmcp);
+ bool mmcGetInfo(MMCDriver *mmcp, BlockDeviceInfo *bdip);
+ bool mmcErase(MMCDriver *mmcp, uint32_t startblk, uint32_t endblk);
+ bool mmc_lld_is_card_inserted(MMCDriver *mmcp);
+ bool mmc_lld_is_write_protected(MMCDriver *mmcp);
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* HAL_USE_MMC_SPI == TRUE */
+
+#endif /* HAL_MMC_SPI_H */
+
+/** @} */
diff --git a/ChibiOS_20.3.2/os/hal/include/hal_mmcsd.h b/ChibiOS_20.3.2/os/hal/include/hal_mmcsd.h new file mode 100644 index 0000000..ac2701f --- /dev/null +++ b/ChibiOS_20.3.2/os/hal/include/hal_mmcsd.h @@ -0,0 +1,498 @@ +/*
+ ChibiOS - Copyright (C) 2006..2018 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_mmcsd.h
+ * @brief MMC/SD cards common header.
+ * @details This header defines an abstract interface useful to access MMC/SD
+ * I/O block devices in a standardized way.
+ *
+ * @addtogroup MMCSD
+ * @{
+ */
+
+#ifndef HAL_MMCSD_H
+#define HAL_MMCSD_H
+
+#if (HAL_USE_MMC_SPI == TRUE) || (HAL_USE_SDC == TRUE) || defined(__DOXYGEN__)
+
+/*===========================================================================*/
+/* Driver constants. */
+/*===========================================================================*/
+
+/**
+ * @brief Fixed block size for MMC/SD block devices.
+ */
+#define MMCSD_BLOCK_SIZE 512U
+
+/**
+ * @brief Mask of error bits in R1 responses.
+ */
+#define MMCSD_R1_ERROR_MASK 0xFDFFE008U
+
+/**
+ * @brief Fixed pattern for CMD8.
+ */
+#define MMCSD_CMD8_PATTERN 0x000001AAU
+
+/**
+ * @name SD/MMC status conditions
+ * @{
+ */
+#define MMCSD_STS_IDLE 0U
+#define MMCSD_STS_READY 1U
+#define MMCSD_STS_IDENT 2U
+#define MMCSD_STS_STBY 3U
+#define MMCSD_STS_TRAN 4U
+#define MMCSD_STS_DATA 5U
+#define MMCSD_STS_RCV 6U
+#define MMCSD_STS_PRG 7U
+#define MMCSD_STS_DIS 8U
+/** @} */
+
+/**
+ * @name SD/MMC commands
+ * @{
+ */
+#define MMCSD_CMD_GO_IDLE_STATE 0U
+#define MMCSD_CMD_INIT 1U
+#define MMCSD_CMD_ALL_SEND_CID 2U
+#define MMCSD_CMD_SEND_RELATIVE_ADDR 3U
+#define MMCSD_CMD_SET_BUS_WIDTH 6U
+#define MMCSD_CMD_SWITCH MMCSD_CMD_SET_BUS_WIDTH
+#define MMCSD_CMD_SEL_DESEL_CARD 7U
+#define MMCSD_CMD_SEND_IF_COND 8U
+#define MMCSD_CMD_SEND_EXT_CSD MMCSD_CMD_SEND_IF_COND
+#define MMCSD_CMD_SEND_CSD 9U
+#define MMCSD_CMD_SEND_CID 10U
+#define MMCSD_CMD_STOP_TRANSMISSION 12U
+#define MMCSD_CMD_SEND_STATUS 13U
+#define MMCSD_CMD_SET_BLOCKLEN 16U
+#define MMCSD_CMD_READ_SINGLE_BLOCK 17U
+#define MMCSD_CMD_READ_MULTIPLE_BLOCK 18U
+#define MMCSD_CMD_SET_BLOCK_COUNT 23U
+#define MMCSD_CMD_WRITE_BLOCK 24U
+#define MMCSD_CMD_WRITE_MULTIPLE_BLOCK 25U
+#define MMCSD_CMD_ERASE_RW_BLK_START 32U
+#define MMCSD_CMD_ERASE_RW_BLK_END 33U
+#define MMCSD_CMD_ERASE 38U
+#define MMCSD_CMD_APP_OP_COND 41U
+#define MMCSD_CMD_LOCK_UNLOCK 42U
+#define MMCSD_CMD_APP_CMD 55U
+#define MMCSD_CMD_READ_OCR 58U
+/** @} */
+
+/**
+ * @name CSD record offsets
+ */
+/**
+ * @brief Slice position of values in CSD register.
+ */
+/* CSD for MMC */
+#define MMCSD_CSD_MMC_CSD_STRUCTURE_SLICE 127U, 126U
+#define MMCSD_CSD_MMC_SPEC_VERS_SLICE 125U, 122U
+#define MMCSD_CSD_MMC_TAAC_SLICE 119U, 112U
+#define MMCSD_CSD_MMC_NSAC_SLICE 111U, 104U
+#define MMCSD_CSD_MMC_TRAN_SPEED_SLICE 103U, 96U
+#define MMCSD_CSD_MMC_CCC_SLICE 95U, 84U
+#define MMCSD_CSD_MMC_READ_BL_LEN_SLICE 83U, 80U
+#define MMCSD_CSD_MMC_READ_BL_PARTIAL_SLICE 79U, 79U
+#define MMCSD_CSD_MMC_WRITE_BLK_MISALIGN_SLICE 78U, 78U
+#define MMCSD_CSD_MMC_READ_BLK_MISALIGN_SLICE 77U, 77U
+#define MMCSD_CSD_MMC_DSR_IMP_SLICE 76U, 76U
+#define MMCSD_CSD_MMC_C_SIZE_SLICE 73U, 62U
+#define MMCSD_CSD_MMC_VDD_R_CURR_MIN_SLICE 61U, 59U
+#define MMCSD_CSD_MMC_VDD_R_CURR_MAX_SLICE 58U, 56U
+#define MMCSD_CSD_MMC_VDD_W_CURR_MIN_SLICE 55U, 53U
+#define MMCSD_CSD_MMC_VDD_W_CURR_MAX_SLICE 52U, 50U
+#define MMCSD_CSD_MMC_C_SIZE_MULT_SLICE 49U, 47U
+#define MMCSD_CSD_MMC_ERASE_GRP_SIZE_SLICE 46U, 42U
+#define MMCSD_CSD_MMC_ERASE_GRP_MULT_SLICE 41U, 37U
+#define MMCSD_CSD_MMC_WP_GRP_SIZE_SLICE 36U, 32U
+#define MMCSD_CSD_MMC_WP_GRP_ENABLE_SLICE 31U, 31U
+#define MMCSD_CSD_MMC_DEFAULT_ECC_SLICE 30U, 29U
+#define MMCSD_CSD_MMC_R2W_FACTOR_SLICE 28U, 26U
+#define MMCSD_CSD_MMC_WRITE_BL_LEN_SLICE 25U, 22U
+#define MMCSD_CSD_MMC_WRITE_BL_PARTIAL_SLICE 21U, 21U
+#define MMCSD_CSD_MMC_CONTENT_PROT_APP_SLICE 16U, 16U
+#define MMCSD_CSD_MMC_FILE_FORMAT_GRP_SLICE 15U, 15U
+#define MMCSD_CSD_MMC_COPY_SLICE 14U, 14U
+#define MMCSD_CSD_MMC_PERM_WRITE_PROTECT_SLICE 13U, 13U
+#define MMCSD_CSD_MMC_TMP_WRITE_PROTECT_SLICE 12U, 12U
+#define MMCSD_CSD_MMC_FILE_FORMAT_SLICE 11U, 10U
+#define MMCSD_CSD_MMC_ECC_SLICE 9U, 8U
+#define MMCSD_CSD_MMC_CRC_SLICE 7U, 1U
+
+/* CSD version 2.0 */
+#define MMCSD_CSD_20_CRC_SLICE 7U, 1U
+#define MMCSD_CSD_20_FILE_FORMAT_SLICE 11U, 10U
+#define MMCSD_CSD_20_TMP_WRITE_PROTECT_SLICE 12U, 12U
+#define MMCSD_CSD_20_PERM_WRITE_PROTECT_SLICE 13U, 13U
+#define MMCSD_CSD_20_COPY_SLICE 14U, 14U
+#define MMCSD_CSD_20_FILE_FORMAT_GRP_SLICE 15U, 15U
+#define MMCSD_CSD_20_WRITE_BL_PARTIAL_SLICE 21U, 21U
+#define MMCSD_CSD_20_WRITE_BL_LEN_SLICE 25U, 12U
+#define MMCSD_CSD_20_R2W_FACTOR_SLICE 28U, 26U
+#define MMCSD_CSD_20_WP_GRP_ENABLE_SLICE 31U, 31U
+#define MMCSD_CSD_20_WP_GRP_SIZE_SLICE 38U, 32U
+#define MMCSD_CSD_20_ERASE_SECTOR_SIZE_SLICE 45U, 39U
+#define MMCSD_CSD_20_ERASE_BLK_EN_SLICE 46U, 46U
+#define MMCSD_CSD_20_C_SIZE_SLICE 69U, 48U
+#define MMCSD_CSD_20_DSR_IMP_SLICE 76U, 76U
+#define MMCSD_CSD_20_READ_BLK_MISALIGN_SLICE 77U, 77U
+#define MMCSD_CSD_20_WRITE_BLK_MISALIGN_SLICE 78U, 78U
+#define MMCSD_CSD_20_READ_BL_PARTIAL_SLICE 79U, 79U
+#define MMCSD_CSD_20_READ_BL_LEN_SLICE 83U, 80U
+#define MMCSD_CSD_20_CCC_SLICE 95U, 84U
+#define MMCSD_CSD_20_TRANS_SPEED_SLICE 103U, 96U
+#define MMCSD_CSD_20_NSAC_SLICE 111U, 104U
+#define MMCSD_CSD_20_TAAC_SLICE 119U, 112U
+#define MMCSD_CSD_20_CSD_STRUCTURE_SLICE 127U, 126U
+
+/* CSD version 1.0 */
+#define MMCSD_CSD_10_CRC_SLICE MMCSD_CSD_20_CRC_SLICE
+#define MMCSD_CSD_10_FILE_FORMAT_SLICE MMCSD_CSD_20_FILE_FORMAT_SLICE
+#define MMCSD_CSD_10_TMP_WRITE_PROTECT_SLICE MMCSD_CSD_20_TMP_WRITE_PROTECT_SLICE
+#define MMCSD_CSD_10_PERM_WRITE_PROTECT_SLICE MMCSD_CSD_20_PERM_WRITE_PROTECT_SLICE
+#define MMCSD_CSD_10_COPY_SLICE MMCSD_CSD_20_COPY_SLICE
+#define MMCSD_CSD_10_FILE_FORMAT_GRP_SLICE MMCSD_CSD_20_FILE_FORMAT_GRP_SLICE
+#define MMCSD_CSD_10_WRITE_BL_PARTIAL_SLICE MMCSD_CSD_20_WRITE_BL_PARTIAL_SLICE
+#define MMCSD_CSD_10_WRITE_BL_LEN_SLICE MMCSD_CSD_20_WRITE_BL_LEN_SLICE
+#define MMCSD_CSD_10_R2W_FACTOR_SLICE MMCSD_CSD_20_R2W_FACTOR_SLICE
+#define MMCSD_CSD_10_WP_GRP_ENABLE_SLICE MMCSD_CSD_20_WP_GRP_ENABLE_SLICE
+#define MMCSD_CSD_10_WP_GRP_SIZE_SLICE MMCSD_CSD_20_WP_GRP_SIZE_SLICE
+#define MMCSD_CSD_10_ERASE_SECTOR_SIZE_SLICE MMCSD_CSD_20_ERASE_SECTOR_SIZE_SLICE
+#define MMCSD_CSD_10_ERASE_BLK_EN_SLICE MMCSD_CSD_20_ERASE_BLK_EN_SLICE
+#define MMCSD_CSD_10_C_SIZE_MULT_SLICE 49U, 47U
+#define MMCSD_CSD_10_VDD_W_CURR_MAX_SLICE 52U, 50U
+#define MMCSD_CSD_10_VDD_W_CURR_MIN_SLICE 55U, 53U
+#define MMCSD_CSD_10_VDD_R_CURR_MAX_SLICE 58U, 56U
+#define MMCSD_CSD_10_VDD_R_CURR_MIX_SLICE 61U, 59U
+#define MMCSD_CSD_10_C_SIZE_SLICE 73U, 62U
+#define MMCSD_CSD_10_DSR_IMP_SLICE MMCSD_CSD_20_DSR_IMP_SLICE
+#define MMCSD_CSD_10_READ_BLK_MISALIGN_SLICE MMCSD_CSD_20_READ_BLK_MISALIGN_SLICE
+#define MMCSD_CSD_10_WRITE_BLK_MISALIGN_SLICE MMCSD_CSD_20_WRITE_BLK_MISALIGN_SLICE
+#define MMCSD_CSD_10_READ_BL_PARTIAL_SLICE MMCSD_CSD_20_READ_BL_PARTIAL_SLICE
+#define MMCSD_CSD_10_READ_BL_LEN_SLICE 83U, 80U
+#define MMCSD_CSD_10_CCC_SLICE MMCSD_CSD_20_CCC_SLICE
+#define MMCSD_CSD_10_TRANS_SPEED_SLICE MMCSD_CSD_20_TRANS_SPEED_SLICE
+#define MMCSD_CSD_10_NSAC_SLICE MMCSD_CSD_20_NSAC_SLICE
+#define MMCSD_CSD_10_TAAC_SLICE MMCSD_CSD_20_TAAC_SLICE
+#define MMCSD_CSD_10_CSD_STRUCTURE_SLICE MMCSD_CSD_20_CSD_STRUCTURE_SLICE
+/** @} */
+
+/**
+ * @name CID record offsets
+ */
+/**
+ * @brief Slice position of values in CID register.
+ */
+/* CID for SDC */
+#define MMCSD_CID_SDC_CRC_SLICE 7U, 1U
+#define MMCSD_CID_SDC_MDT_M_SLICE 11U, 8U
+#define MMCSD_CID_SDC_MDT_Y_SLICE 19U, 12U
+#define MMCSD_CID_SDC_PSN_SLICE 55U, 24U
+#define MMCSD_CID_SDC_PRV_M_SLICE 59U, 56U
+#define MMCSD_CID_SDC_PRV_N_SLICE 63U, 60U
+#define MMCSD_CID_SDC_PNM0_SLICE 71U, 64U
+#define MMCSD_CID_SDC_PNM1_SLICE 79U, 72U
+#define MMCSD_CID_SDC_PNM2_SLICE 87U, 80U
+#define MMCSD_CID_SDC_PNM3_SLICE 95U, 88U
+#define MMCSD_CID_SDC_PNM4_SLICE 103U, 96U
+#define MMCSD_CID_SDC_OID_SLICE 119U, 104U
+#define MMCSD_CID_SDC_MID_SLICE 127U, 120U
+
+/* CID for MMC */
+#define MMCSD_CID_MMC_CRC_SLICE 7U, 1U
+#define MMCSD_CID_MMC_MDT_Y_SLICE 11U, 8U
+#define MMCSD_CID_MMC_MDT_M_SLICE 15U, 12U
+#define MMCSD_CID_MMC_PSN_SLICE 47U, 16U
+#define MMCSD_CID_MMC_PRV_M_SLICE 51U, 48U
+#define MMCSD_CID_MMC_PRV_N_SLICE 55U, 52U
+#define MMCSD_CID_MMC_PNM0_SLICE 63U, 56U
+#define MMCSD_CID_MMC_PNM1_SLICE 71U, 64U
+#define MMCSD_CID_MMC_PNM2_SLICE 79U, 72U
+#define MMCSD_CID_MMC_PNM3_SLICE 87U, 80U
+#define MMCSD_CID_MMC_PNM4_SLICE 95U, 88U
+#define MMCSD_CID_MMC_PNM5_SLICE 103U, 96U
+#define MMCSD_CID_MMC_OID_SLICE 119U, 104U
+#define MMCSD_CID_MMC_MID_SLICE 127U, 120U
+/** @} */
+
+/*===========================================================================*/
+/* Driver pre-compile time settings. */
+/*===========================================================================*/
+
+/*===========================================================================*/
+/* Derived constants and error checks. */
+/*===========================================================================*/
+
+/*===========================================================================*/
+/* Driver data structures and types. */
+/*===========================================================================*/
+
+/**
+ * @brief @p MMCSDBlockDevice specific methods.
+ */
+#define _mmcsd_block_device_methods \
+ _base_block_device_methods
+
+/**
+ * @brief @p MMCSDBlockDevice specific data.
+ * @note It is empty because @p MMCSDBlockDevice is only an interface
+ * without implementation.
+ */
+#define _mmcsd_block_device_data \
+ _base_block_device_data \
+ /* Card CID.*/ \
+ uint32_t cid[4]; \
+ /* Card CSD.*/ \
+ uint32_t csd[4]; \
+ /* Total number of blocks in card.*/ \
+ uint32_t capacity;
+
+/**
+ * @extends BaseBlockDeviceVMT
+ *
+ * @brief @p MMCSDBlockDevice virtual methods table.
+ */
+struct MMCSDBlockDeviceVMT {
+ _base_block_device_methods
+};
+
+/**
+ * @extends BaseBlockDevice
+ *
+ * @brief MCC/SD block device class.
+ * @details This class represents a, block-accessible, MMC/SD device.
+ */
+typedef struct {
+ /** @brief Virtual Methods Table.*/
+ const struct MMCSDBlockDeviceVMT *vmt;
+ _mmcsd_block_device_data
+} MMCSDBlockDevice;
+
+/**
+ * @brief Unpacked CID register from SDC.
+ */
+typedef struct {
+ uint8_t mid;
+ uint16_t oid;
+ char pnm[5];
+ uint8_t prv_n;
+ uint8_t prv_m;
+ uint32_t psn;
+ uint8_t mdt_m;
+ uint16_t mdt_y;
+ uint8_t crc;
+} unpacked_sdc_cid_t;
+
+/**
+ * @brief Unpacked CID register from MMC.
+ */
+typedef struct {
+ uint8_t mid;
+ uint16_t oid;
+ char pnm[6];
+ uint8_t prv_n;
+ uint8_t prv_m;
+ uint32_t psn;
+ uint8_t mdt_m;
+ uint16_t mdt_y;
+ uint8_t crc;
+} unpacked_mmc_cid_t;
+
+/**
+ * @brief Unpacked CSD v1.0 register from SDC.
+ */
+typedef struct {
+ uint8_t csd_structure;
+ uint8_t taac;
+ uint8_t nsac;
+ uint8_t tran_speed;
+ uint16_t ccc;
+ uint8_t read_bl_len;
+ uint8_t read_bl_partial;
+ uint8_t write_blk_misalign;
+ uint8_t read_blk_misalign;
+ uint8_t dsr_imp;
+ uint16_t c_size;
+ uint8_t vdd_r_curr_min;
+ uint8_t vdd_r_curr_max;
+ uint8_t vdd_w_curr_min;
+ uint8_t vdd_w_curr_max;
+ uint8_t c_size_mult;
+ uint8_t erase_blk_en;
+ uint8_t erase_sector_size;
+ uint8_t wp_grp_size;
+ uint8_t wp_grp_enable;
+ uint8_t r2w_factor;
+ uint8_t write_bl_len;
+ uint8_t write_bl_partial;
+ uint8_t file_format_grp;
+ uint8_t copy;
+ uint8_t perm_write_protect;
+ uint8_t tmp_write_protect;
+ uint8_t file_format;
+ uint8_t crc;
+} unpacked_sdc_csd_10_t;
+
+/**
+ * @brief Unpacked CSD v2.0 register from SDC.
+ */
+typedef struct {
+ uint8_t csd_structure;
+ uint8_t taac;
+ uint8_t nsac;
+ uint8_t tran_speed;
+ uint16_t ccc;
+ uint8_t read_bl_len;
+ uint8_t read_bl_partial;
+ uint8_t write_blk_misalign;
+ uint8_t read_blk_misalign;
+ uint8_t dsr_imp;
+ uint32_t c_size;
+ uint8_t erase_blk_en;
+ uint8_t erase_sector_size;
+ uint8_t wp_grp_size;
+ uint8_t wp_grp_enable;
+ uint8_t r2w_factor;
+ uint8_t write_bl_len;
+ uint8_t write_bl_partial;
+ uint8_t file_format_grp;
+ uint8_t copy;
+ uint8_t perm_write_protect;
+ uint8_t tmp_write_protect;
+ uint8_t file_format;
+ uint8_t crc;
+} unpacked_sdc_csd_20_t;
+
+/**
+ * @brief Unpacked CSD register from MMC.
+ */
+typedef struct {
+ uint8_t csd_structure;
+ uint8_t spec_vers;
+ uint8_t taac;
+ uint8_t nsac;
+ uint8_t tran_speed;
+ uint16_t ccc;
+ uint8_t read_bl_len;
+ uint8_t read_bl_partial;
+ uint8_t write_blk_misalign;
+ uint8_t read_blk_misalign;
+ uint8_t dsr_imp;
+ uint16_t c_size;
+ uint8_t vdd_r_curr_min;
+ uint8_t vdd_r_curr_max;
+ uint8_t vdd_w_curr_min;
+ uint8_t vdd_w_curr_max;
+ uint8_t c_size_mult;
+ uint8_t erase_grp_size;
+ uint8_t erase_grp_mult;
+ uint8_t wp_grp_size;
+ uint8_t wp_grp_enable;
+ uint8_t default_ecc;
+ uint8_t r2w_factor;
+ uint8_t write_bl_len;
+ uint8_t write_bl_partial;
+ uint8_t content_prot_app;
+ uint8_t file_format_grp;
+ uint8_t copy;
+ uint8_t perm_write_protect;
+ uint8_t tmp_write_protect;
+ uint8_t file_format;
+ uint8_t ecc;
+ uint8_t crc;
+} unpacked_mmc_csd_t;
+
+/*===========================================================================*/
+/* Driver macros. */
+/*===========================================================================*/
+
+/**
+ * @name R1 response utilities
+ * @{
+ */
+/**
+ * @brief Evaluates to @p true if the R1 response contains error flags.
+ *
+ * @param[in] r1 the r1 response
+ */
+#define MMCSD_R1_ERROR(r1) (((r1) & MMCSD_R1_ERROR_MASK) != 0U)
+
+/**
+ * @brief Returns the status field of an R1 response.
+ *
+ * @param[in] r1 the r1 response
+ */
+#define MMCSD_R1_STS(r1) (((r1) >> 9U) & 15U)
+
+/**
+ * @brief Evaluates to @p true if the R1 response indicates a locked card.
+ *
+ * @param[in] r1 the r1 response
+ */
+#define MMCSD_R1_IS_CARD_LOCKED(r1) ((((r1) >> 21U) & 1U) != 0U)
+/** @} */
+
+/**
+ * @name Macro Functions
+ * @{
+ */
+/**
+ * @brief Returns the card capacity in blocks.
+ *
+ * @param[in] ip pointer to a @p MMCSDBlockDevice or derived class
+ *
+ * @return The card capacity.
+ *
+ * @api
+ */
+#define mmcsdGetCardCapacity(ip) ((ip)->capacity)
+/** @} */
+
+/*===========================================================================*/
+/* External declarations. */
+/*===========================================================================*/
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+ uint32_t _mmcsd_get_slice(const uint32_t *data,
+ uint32_t end,
+ uint32_t start);
+ uint32_t _mmcsd_get_capacity(const uint32_t *csd);
+ uint32_t _mmcsd_get_capacity_ext(const uint8_t *ext_csd);
+ void _mmcsd_unpack_sdc_cid(const MMCSDBlockDevice *sdcp,
+ unpacked_sdc_cid_t *cidsdc);
+ void _mmcsd_unpack_mmc_cid(const MMCSDBlockDevice *sdcp,
+ unpacked_mmc_cid_t *cidmmc);
+ void _mmcsd_unpack_csd_mmc(const MMCSDBlockDevice *sdcp,
+ unpacked_mmc_csd_t *csdmmc);
+ void _mmcsd_unpack_csd_v10(const MMCSDBlockDevice *sdcp,
+ unpacked_sdc_csd_10_t *csd10);
+ void _mmcsd_unpack_csd_v20(const MMCSDBlockDevice *sdcp,
+ unpacked_sdc_csd_20_t *csd20);
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* HAL_USE_MMC_SPI == TRUE || HAL_USE_MMC_SDC == TRUE */
+
+#endif /* HAL_MMCSD_H */
+
+/** @} */
diff --git a/ChibiOS_20.3.2/os/hal/include/hal_objects.h b/ChibiOS_20.3.2/os/hal/include/hal_objects.h new file mode 100644 index 0000000..59c3884 --- /dev/null +++ b/ChibiOS_20.3.2/os/hal/include/hal_objects.h @@ -0,0 +1,86 @@ +/*
+ ChibiOS - Copyright (C) 2006..2018 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_objects.h
+ * @brief Base object.
+ * @details This header defines a base object that is the root for the
+ * inheritance system.
+ *
+ * @addtogroup HAL_BASE_OBJECT
+ * @details HAL uses concepts of Object Oriented Programming even if it
+ * is written in C. Things like simple inheritance, multiple
+ * inheritance and interfaces are used through the system.
+ * This module defines a "base object" that is the ancestor of
+ * all classes in the system.
+ * @{
+ */
+
+#ifndef HAL_OBJECTS_H
+#define HAL_OBJECTS_H
+
+/**
+ * @brief @p BaseObject specific methods.
+ * @note This object defines no methods.
+ */
+#define _base_object_methods \
+ /* Instance offset, used for multiple inheritance, normally zero. It
+ represents the offset between the current object and the container
+ object*/ \
+ size_t instance_offset;
+
+/**
+ * @brief @p BaseObject specific data.
+ * @note This object defines no data.
+ */
+#define _base_object_data
+
+/**
+ * @brief @p BaseObject virtual methods table.
+ */
+struct BaseObjectVMT {
+ _base_object_methods
+};
+
+/**
+ * @brief Base stream class.
+ * @details This class represents a generic blocking unbuffered sequential
+ * data stream.
+ */
+typedef struct {
+ /** @brief Virtual Methods Table.*/
+ const struct BaseObjectVMT *vmt;
+ _base_object_data
+} BaseObject;
+
+/**
+ * @name Macro Functions (BaseObject)
+ * @{
+ */
+/**
+ * @brief Returns the instance pointer starting from an interface pointer.
+ *
+ * @param[in] type the type of the instance pointer, it is used for casting
+ * @param[in] ip the interface pointer
+ * @return A pointer to the object implementing the interface
+ */
+#define objGetInstance(type, ip) \
+ (type)(((size_t)(ip)) - (ip)->vmt->instance_offset)
+/** @} */
+
+#endif /* HAL_OBJECTS_H */
+
+/** @} */
diff --git a/ChibiOS_20.3.2/os/hal/include/hal_pal.h b/ChibiOS_20.3.2/os/hal/include/hal_pal.h new file mode 100644 index 0000000..62a2131 --- /dev/null +++ b/ChibiOS_20.3.2/os/hal/include/hal_pal.h @@ -0,0 +1,1023 @@ +/*
+ ChibiOS - Copyright (C) 2006..2018 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_pal.h
+ * @brief I/O Ports Abstraction Layer macros, types and structures.
+ *
+ * @addtogroup PAL
+ * @{
+ */
+
+#ifndef HAL_PAL_H
+#define HAL_PAL_H
+
+#if (HAL_USE_PAL == TRUE) || defined(__DOXYGEN__)
+
+/*===========================================================================*/
+/* Driver constants. */
+/*===========================================================================*/
+
+/**
+ * @name Pads mode constants
+ * @{
+ */
+/**
+ * @brief After reset state.
+ * @details The state itself is not specified and is architecture dependent,
+ * it is guaranteed to be equal to the after-reset state. It is
+ * usually an input state.
+ */
+#define PAL_MODE_RESET 0U
+
+/**
+ * @brief Safe state for <b>unconnected</b> pads.
+ * @details The state itself is not specified and is architecture dependent,
+ * it may be mapped on @p PAL_MODE_INPUT_PULLUP,
+ * @p PAL_MODE_INPUT_PULLDOWN or @p PAL_MODE_OUTPUT_PUSHPULL for
+ * example.
+ */
+#define PAL_MODE_UNCONNECTED 1U
+
+/**
+ * @brief Regular input high-Z pad.
+ */
+#define PAL_MODE_INPUT 2U
+
+/**
+ * @brief Input pad with weak pull up resistor.
+ */
+#define PAL_MODE_INPUT_PULLUP 3U
+
+/**
+ * @brief Input pad with weak pull down resistor.
+ */
+#define PAL_MODE_INPUT_PULLDOWN 4U
+
+/**
+ * @brief Analog input mode.
+ */
+#define PAL_MODE_INPUT_ANALOG 5U
+
+/**
+ * @brief Push-pull output pad.
+ */
+#define PAL_MODE_OUTPUT_PUSHPULL 6U
+
+/**
+ * @brief Open-drain output pad.
+ */
+#define PAL_MODE_OUTPUT_OPENDRAIN 7U
+/** @} */
+
+/**
+ * @name Logic level constants
+ * @{
+ */
+/**
+ * @brief Logical low state.
+ */
+#define PAL_LOW 0U
+
+/**
+ * @brief Logical high state.
+ */
+#define PAL_HIGH 1U
+/** @} */
+
+/**
+ * @name PAL event modes
+ * @{
+ */
+#define PAL_EVENT_MODE_EDGES_MASK 3U /**< @brief Mask of edges field. */
+#define PAL_EVENT_MODE_DISABLED 0U /**< @brief Channel disabled. */
+#define PAL_EVENT_MODE_RISING_EDGE 1U /**< @brief Rising edge callback. */
+#define PAL_EVENT_MODE_FALLING_EDGE 2U /**< @brief Falling edge callback. */
+#define PAL_EVENT_MODE_BOTH_EDGES 3U /**< @brief Both edges callback. */
+/** @} */
+
+/*===========================================================================*/
+/* Driver pre-compile time settings. */
+/*===========================================================================*/
+
+/**
+ * @name PAL configuration options
+ * @{
+ */
+/**
+ * @brief Enables synchronous APIs.
+ * @note Disabling this option saves both code and data space.
+ */
+#if !defined(PAL_USE_CALLBACKS) || defined(__DOXYGEN__)
+#define PAL_USE_CALLBACKS TRUE
+#endif
+
+/**
+ * @brief Enables synchronous APIs.
+ * @note Disabling this option saves both code and data space.
+ */
+#if !defined(PAL_USE_WAIT) || defined(__DOXYGEN__)
+#define PAL_USE_WAIT TRUE
+#endif
+/** @} */
+
+/*===========================================================================*/
+/* Derived constants and error checks. */
+/*===========================================================================*/
+
+/*===========================================================================*/
+/* Driver data structures and types. */
+/*===========================================================================*/
+
+/**
+ * @brief Type of a PAL event callback.
+ */
+typedef void (*palcallback_t)(void *arg);
+
+#if (PAL_USE_WAIT == TRUE) || (PAL_USE_CALLBACKS == TRUE) || defined(__DOXYGEN__)
+/**
+ * @brief Type of a PAL event record.
+ */
+typedef struct {
+#if (PAL_USE_WAIT == TRUE) || defined(__DOXYGEN__)
+ /**
+ * @brief Threads queued for an event.
+ */
+ threads_queue_t threads;
+#endif
+#if (PAL_USE_CALLBACKS == TRUE) || defined(__DOXYGEN__)
+ /**
+ * @brief Event callback.
+ */
+ palcallback_t cb;
+ /**
+ * @brief Event callback argument.
+ */
+ void *arg;
+#endif
+} palevent_t;
+#endif
+
+#include "hal_pal_lld.h"
+
+/**
+ * @brief I/O bus descriptor.
+ * @details This structure describes a group of contiguous digital I/O lines
+ * that have to be handled as bus.
+ * @note I/O operations on a bus do not affect I/O lines on the same port but
+ * not belonging to the bus.
+ */
+typedef struct {
+ /**
+ * @brief Port identifier.
+ */
+ ioportid_t portid;
+ /**
+ * @brief Bus mask aligned to port bit 0.
+ * @note The bus mask implicitly define the bus width. A logic AND is
+ * performed on the bus data.
+ */
+ ioportmask_t mask;
+ /**
+ * @brief Offset, within the port, of the least significant bit of the bus.
+ */
+ uint_fast8_t offset;
+} IOBus;
+
+/*===========================================================================*/
+/* Driver macros. */
+/*===========================================================================*/
+
+/**
+ * @brief Port bit helper macro.
+ * @details This macro calculates the mask of a bit within a port.
+ *
+ * @param[in] n bit position within the port
+ * @return The bit mask.
+ */
+#if !defined(PAL_PORT_BIT) || defined(__DOXYGEN__)
+#define PAL_PORT_BIT(n) ((ioportmask_t)(1U << (n)))
+#endif
+
+/**
+ * @brief Bits group mask helper.
+ * @details This macro calculates the mask of a bits group.
+ *
+ * @param[in] width group width
+ * @return The group mask.
+ */
+#if !defined(PAL_GROUP_MASK) || defined(__DOXYGEN__)
+#define PAL_GROUP_MASK(width) ((ioportmask_t)(1U << (width)) - 1U)
+#endif
+
+/**
+ * @brief Data part of a static I/O bus initializer.
+ * @details This macro should be used when statically initializing an I/O bus
+ * that is part of a bigger structure.
+ *
+ * @param[in] name name of the IOBus variable
+ * @param[in] port I/O port descriptor
+ * @param[in] width bus width in bits
+ * @param[in] offset bus bit offset within the port
+ */
+#define _IOBUS_DATA(name, port, width, offset) \
+ {port, PAL_GROUP_MASK(width), offset}
+
+/**
+ * @brief Static I/O bus initializer.
+ *
+ * @param[in] name name of the IOBus variable
+ * @param[in] port I/O port descriptor
+ * @param[in] width bus width in bits
+ * @param[in] offset bus bit offset within the port
+ */
+#define IOBUS_DECL(name, port, width, offset) \
+ IOBus name = _IOBUS_DATA(name, port, width, offset)
+
+#if (PAL_USE_CALLBACKS == TRUE) || (PAL_USE_WAIT == TRUE) || \
+ defined(__DOXYGEN__)
+/**
+ * @name Low level driver helper macros
+ * @{
+ */
+#if ((PAL_USE_CALLBACKS == TRUE) && (PAL_USE_WAIT == TRUE)) || \
+ defined(__DOXYGEN__)
+/**
+ * @brief Initializes a PAL event object.
+ *
+ * @param[in] e event index
+ *
+ * @notapi
+ */
+#define _pal_init_event(e) \
+ do { \
+ osalThreadQueueObjectInit(&_pal_events[e].threads); \
+ _pal_events[e].cb = NULL; \
+ _pal_events[e].arg = NULL; \
+ } while (false)
+#endif /* (PAL_USE_CALLBACKS == TRUE) && (PAL_USE_WAIT == TRUE) */
+
+#if (PAL_USE_CALLBACKS == TRUE) && (PAL_USE_WAIT == FALSE)
+#define _pal_init_event(e) \
+ do { \
+ _pal_events[e].cb = NULL; \
+ _pal_events[e].arg = NULL; \
+ } while (false)
+#endif /* (PAL_USE_CALLBACKS == TRUE) && (PAL_USE_WAIT == FALSE) */
+
+#if (PAL_USE_CALLBACKS == FALSE) && (PAL_USE_WAIT == TRUE)
+#define _pal_init_event(e) \
+ do { \
+ osalThreadQueueObjectInit(&_pal_events[e].threads); \
+ } while (false)
+#endif /* (PAL_USE_CALLBACKS == FALSE) && (PAL_USE_WAIT == TRUE) */
+
+#if ((PAL_USE_CALLBACKS == TRUE) && (PAL_USE_WAIT == TRUE)) || defined(__DOXYGEN__)
+/**
+ * @brief Clears a PAL event object.
+ *
+ * @param[in] e event index
+ *
+ * @notapi
+ */
+#define _pal_clear_event(e) \
+ do { \
+ osalThreadDequeueAllI(&_pal_events[pad].threads, MSG_RESET); \
+ _pal_events[e].cb = NULL; \
+ _pal_events[e].arg = NULL; \
+ } while (false)
+#endif /* (PAL_USE_CALLBACKS == TRUE) && (PAL_USE_WAIT == TRUE) */
+
+#if (PAL_USE_CALLBACKS == TRUE) && (PAL_USE_WAIT == FALSE)
+#define _pal_clear_event(e) \
+ do { \
+ _pal_events[e].cb = NULL; \
+ _pal_events[e].arg = NULL; \
+ } while (false)
+#endif /* (PAL_USE_CALLBACKS == TRUE) && (PAL_USE_WAIT == FALSE) */
+
+#if (PAL_USE_CALLBACKS == FALSE) && (PAL_USE_WAIT == TRUE)
+#define _pal_clear_event(e) \
+ do { \
+ osalThreadDequeueAllI(&_pal_events[pad].threads, MSG_RESET); \
+ } while (false)
+#endif /* (PAL_USE_CALLBACKS == FALSE) && (PAL_USE_WAIT == TRUE) */
+
+/**
+ * @brief Common ISR code.
+ * @note This macro is meant to be used in the low level drivers
+ * implementation only.
+ *
+ * @param[in] e event index
+ *
+ * @notapi
+ */
+#if ((PAL_USE_CALLBACKS == TRUE) && (PAL_USE_WAIT == TRUE)) || \
+ defined(__DOXYGEN__)
+#define _pal_isr_code(e) do { \
+ if (_pal_events[e].cb != NULL) { \
+ _pal_events[e].cb(_pal_events[e].arg); \
+ } \
+ osalSysLockFromISR(); \
+ osalThreadDequeueAllI(&_pal_events[e].threads, MSG_OK); \
+ osalSysUnlockFromISR(); \
+} while (false)
+#endif /* (PAL_USE_CALLBACKS == TRUE) && (PAL_USE_WAIT == TRUE) */
+
+#if (PAL_USE_CALLBACKS == TRUE) && (PAL_USE_WAIT == FALSE)
+#define _pal_isr_code(e) do { \
+ if (_pal_events[e].cb != NULL) { \
+ _pal_events[e].cb(_pal_events[e].arg); \
+ } \
+} while (false)
+#endif /* (PAL_USE_CALLBACKS == TRUE) && (PAL_USE_WAIT == FALSE) */
+
+#if ((PAL_USE_CALLBACKS == FALSE) && (PAL_USE_WAIT == TRUE)) || \
+ defined(__DOXYGEN__)
+#define _pal_isr_code(e) do { \
+ osalSysLockFromISR(); \
+ osalThreadDequeueAllI(&_pal_events[e].threads, MSG_OK); \
+ osalSysUnlockFromISR(); \
+} while (false)
+#endif /* (PAL_USE_CALLBACKS == FALSE) && (PAL_USE_WAIT == TRUE) */
+
+/** @} */
+#endif /* (PAL_USE_CALLBACKS == TRUE) || (PAL_USE_WAIT == TRUE) */
+
+/**
+ * @name Macro Functions
+ * @{
+ */
+/**
+ * @brief PAL subsystem initialization.
+ * @note This function is implicitly invoked by @p halInit(), there is
+ * no need to explicitly initialize the driver.
+ *
+ * @init
+ */
+#if defined(PAL_NEW_INIT) || defined(__DOXYGEN__)
+#define palInit() pal_lld_init()
+#else
+#define palInit(config) pal_lld_init(config)
+#endif
+
+/**
+ * @brief Reads the physical I/O port states.
+ * @note The function can be called from any context.
+ *
+ * @param[in] port port identifier
+ * @return The port logic states.
+ *
+ * @special
+ */
+#if !defined(pal_lld_readport) || defined(__DOXYGEN__)
+#define palReadPort(port) ((void)(port), 0U)
+#else
+#define palReadPort(port) pal_lld_readport(port)
+#endif
+
+/**
+ * @brief Reads the output latch.
+ * @details The purpose of this function is to read back the latched output
+ * value.
+ * @note The function can be called from any context.
+ *
+ * @param[in] port port identifier
+ * @return The latched logic states.
+ *
+ * @special
+ */
+#if !defined(pal_lld_readlatch) || defined(__DOXYGEN__)
+#define palReadLatch(port) ((void)(port), 0U)
+#else
+#define palReadLatch(port) pal_lld_readlatch(port)
+#endif
+
+/**
+ * @brief Writes a bits mask on a I/O port.
+ * @note The function can be called from any context.
+ *
+ * @param[in] port port identifier
+ * @param[in] bits bits to be written on the specified port
+ *
+ * @special
+ */
+#if !defined(pal_lld_writeport) || defined(__DOXYGEN__)
+#define palWritePort(port, bits) ((void)(port), (void)(bits))
+#else
+#define palWritePort(port, bits) pal_lld_writeport(port, bits)
+#endif
+
+/**
+ * @brief Sets a bits mask on a I/O port.
+ * @note The operation is not guaranteed to be atomic on all the
+ * architectures, for atomicity and/or portability reasons you may
+ * need to enclose port I/O operations between @p osalSysLock() and
+ * @p osalSysUnlock().
+ * @note The function can be called from any context.
+ *
+ * @param[in] port port identifier
+ * @param[in] bits bits to be ORed on the specified port
+ *
+ * @special
+ */
+#if !defined(pal_lld_setport) || defined(__DOXYGEN__)
+#define palSetPort(port, bits) \
+ palWritePort(port, palReadLatch(port) | (bits))
+#else
+#define palSetPort(port, bits) pal_lld_setport(port, bits)
+#endif
+
+/**
+ * @brief Clears a bits mask on a I/O port.
+ * @note The operation is not guaranteed to be atomic on all the
+ * architectures, for atomicity and/or portability reasons you may
+ * need to enclose port I/O operations between @p osalSysLock() and
+ * @p osalSysUnlock().
+ * @note The function can be called from any context.
+ *
+ * @param[in] port port identifier
+ * @param[in] bits bits to be cleared on the specified port
+ *
+ * @special
+ */
+#if !defined(pal_lld_clearport) || defined(__DOXYGEN__)
+#define palClearPort(port, bits) \
+ palWritePort(port, palReadLatch(port) & ~(bits))
+#else
+#define palClearPort(port, bits) pal_lld_clearport(port, bits)
+#endif
+
+/**
+ * @brief Toggles a bits mask on a I/O port.
+ * @note The operation is not guaranteed to be atomic on all the
+ * architectures, for atomicity and/or portability reasons you may
+ * need to enclose port I/O operations between @p osalSysLock() and
+ * @p osalSysUnlock().
+ * @note The function can be called from any context.
+ *
+ * @param[in] port port identifier
+ * @param[in] bits bits to be XORed on the specified port
+ *
+ * @special
+ */
+#if !defined(pal_lld_toggleport) || defined(__DOXYGEN__)
+#define palTogglePort(port, bits) \
+ palWritePort(port, palReadLatch(port) ^ (bits))
+#else
+#define palTogglePort(port, bits) pal_lld_toggleport(port, bits)
+#endif
+
+/**
+ * @brief Reads a group of bits.
+ * @note The function can be called from any context.
+ *
+ * @param[in] port port identifier
+ * @param[in] mask group mask, a logic AND is performed on the input
+ * data
+ * @param[in] offset group bit offset within the port
+ * @return The group logic states.
+ *
+ * @special
+ */
+#if !defined(pal_lld_readgroup) || defined(__DOXYGEN__)
+#define palReadGroup(port, mask, offset) \
+ ((palReadPort(port) >> (offset)) & (mask))
+#else
+#define palReadGroup(port, mask, offset) pal_lld_readgroup(port, mask, offset)
+#endif
+
+/**
+ * @brief Writes a group of bits.
+ * @note The operation is not guaranteed to be atomic on all the
+ * architectures, for atomicity and/or portability reasons you may
+ * need to enclose port I/O operations between @p osalSysLock() and
+ * @p osalSysUnlock().
+ * @note The function can be called from any context.
+ *
+ * @param[in] port port identifier
+ * @param[in] mask group mask, a logic AND is performed on the
+ * output data
+ * @param[in] offset group bit offset within the port
+ * @param[in] bits bits to be written. Values exceeding the group
+ * width are masked.
+ *
+ * @special
+ */
+#if !defined(pal_lld_writegroup) || defined(__DOXYGEN__)
+#define palWriteGroup(port, mask, offset, bits) \
+ palWritePort(port, (palReadLatch(port) & ~((mask) << (offset))) | \
+ (((bits) & (mask)) << (offset)))
+#else
+#define palWriteGroup(port, mask, offset, bits) \
+ pal_lld_writegroup(port, mask, offset, bits)
+#endif
+
+/**
+ * @brief Pads group mode setup.
+ * @details This function programs a pads group belonging to the same port
+ * with the specified mode.
+ * @note The operation is not guaranteed to be atomic on all the
+ * architectures, for atomicity and/or portability reasons you may
+ * need to enclose port I/O operations between @p osalSysLock() and
+ * @p osalSysUnlock().
+ * @note Programming an unknown or unsupported mode is silently ignored.
+ * @note The function can be called from any context.
+ *
+ * @param[in] port port identifier
+ * @param[in] mask group mask
+ * @param[in] offset group bit offset within the port
+ * @param[in] mode group mode
+ *
+ * @special
+ */
+#if !defined(pal_lld_setgroupmode) || defined(__DOXYGEN__)
+#define palSetGroupMode(port, mask, offset, mode)
+#else
+#define palSetGroupMode(port, mask, offset, mode) \
+ pal_lld_setgroupmode(port, mask, offset, mode)
+#endif
+
+/**
+ * @brief Reads an input pad logic state.
+ * @note The function can be called from any context.
+ *
+ * @param[in] port port identifier
+ * @param[in] pad pad number within the port
+ * @return The logic state.
+ * @retval PAL_LOW low logic state.
+ * @retval PAL_HIGH high logic state.
+ *
+ * @special
+ */
+#if !defined(pal_lld_readpad) || defined(__DOXYGEN__)
+#define palReadPad(port, pad) ((palReadPort(port) >> (pad)) & 1U)
+#else
+#define palReadPad(port, pad) pal_lld_readpad(port, pad)
+#endif
+
+/**
+ * @brief Writes a logic state on an output pad.
+ * @note The operation is not guaranteed to be atomic on all the
+ * architectures, for atomicity and/or portability reasons you may
+ * need to enclose port I/O operations between @p osalSysLock() and
+ * @p osalSysUnlock().
+ * @note The function can be called from any context.
+ *
+ * @param[in] port port identifier
+ * @param[in] pad pad number within the port
+ * @param[in] bit logic value, the value must be @p PAL_LOW or
+ * @p PAL_HIGH
+ *
+ * @special
+ */
+#if !defined(pal_lld_writepad) || defined(__DOXYGEN__)
+#define palWritePad(port, pad, bit) \
+ palWritePort(port, (palReadLatch(port) & ~PAL_PORT_BIT(pad)) | \
+ (((bit) & 1U) << pad))
+#else
+#define palWritePad(port, pad, bit) pal_lld_writepad(port, pad, bit)
+#endif
+
+/**
+ * @brief Sets a pad logic state to @p PAL_HIGH.
+ * @note The operation is not guaranteed to be atomic on all the
+ * architectures, for atomicity and/or portability reasons you may
+ * need to enclose port I/O operations between @p osalSysLock() and
+ * @p osalSysUnlock().
+ * @note The function can be called from any context.
+ *
+ * @param[in] port port identifier
+ * @param[in] pad pad number within the port
+ *
+ * @special
+ */
+#if !defined(pal_lld_setpad) || defined(__DOXYGEN__)
+#define palSetPad(port, pad) palSetPort(port, PAL_PORT_BIT(pad))
+#else
+#define palSetPad(port, pad) pal_lld_setpad(port, pad)
+#endif
+
+/**
+ * @brief Clears a pad logic state to @p PAL_LOW.
+ * @note The operation is not guaranteed to be atomic on all the
+ * architectures, for atomicity and/or portability reasons you may
+ * need to enclose port I/O operations between @p osalSysLock() and
+ * @p osalSysUnlock().
+ * @note The function can be called from any context.
+ *
+ * @param[in] port port identifier
+ * @param[in] pad pad number within the port
+ *
+ * @special
+ */
+#if !defined(pal_lld_clearpad) || defined(__DOXYGEN__)
+#define palClearPad(port, pad) palClearPort(port, PAL_PORT_BIT(pad))
+#else
+#define palClearPad(port, pad) pal_lld_clearpad(port, pad)
+#endif
+
+/**
+ * @brief Toggles a pad logic state.
+ * @note The operation is not guaranteed to be atomic on all the
+ * architectures, for atomicity and/or portability reasons you may
+ * need to enclose port I/O operations between @p osalSysLock() and
+ * @p osalSysUnlock().
+ * @note The function can be called from any context.
+ *
+ * @param[in] port port identifier
+ * @param[in] pad pad number within the port
+ *
+ * @special
+ */
+#if !defined(pal_lld_togglepad) || defined(__DOXYGEN__)
+#define palTogglePad(port, pad) palTogglePort(port, PAL_PORT_BIT(pad))
+#else
+#define palTogglePad(port, pad) pal_lld_togglepad(port, pad)
+#endif
+
+/**
+ * @brief Pad mode setup.
+ * @details This function programs a pad with the specified mode.
+ * @note The operation is not guaranteed to be atomic on all the
+ * architectures, for atomicity and/or portability reasons you may
+ * need to enclose port I/O operations between @p osalSysLock() and
+ * @p osalSysUnlock().
+ * @note Programming an unknown or unsupported mode is silently ignored.
+ * @note The function can be called from any context.
+ *
+ * @param[in] port port identifier
+ * @param[in] pad pad number within the port
+ * @param[in] mode pad mode
+ *
+ * @special
+ */
+#if !defined(pal_lld_setpadmode) || defined(__DOXYGEN__)
+#define palSetPadMode(port, pad, mode) \
+ palSetGroupMode(port, PAL_PORT_BIT(pad), 0U, mode)
+#else
+#define palSetPadMode(port, pad, mode) pal_lld_setpadmode(port, pad, mode)
+#endif
+
+/**
+ * @brief Reads an input line logic state.
+ * @note The function can be called from any context.
+ *
+ * @param[in] line line identifier
+ * @return The logic state.
+ * @retval PAL_LOW low logic state.
+ * @retval PAL_HIGH high logic state.
+ *
+ * @special
+ */
+#if !defined(pal_lld_readline) || defined(__DOXYGEN__)
+#define palReadLine(line) palReadPad(PAL_PORT(line), PAL_PAD(line))
+#else
+#define palReadLine(line) pal_lld_readline(line)
+#endif
+
+/**
+ * @brief Writes a logic state on an output line.
+ * @note The operation is not guaranteed to be atomic on all the
+ * architectures, for atomicity and/or portability reasons you may
+ * need to enclose port I/O operations between @p osalSysLock() and
+ * @p osalSysUnlock().
+ * @note The function can be called from any context.
+ *
+ * @param[in] line line identifier
+ * @param[in] bit logic value, the value must be @p PAL_LOW or
+ * @p PAL_HIGH
+ *
+ * @special
+ */
+#if !defined(pal_lld_writeline) || defined(__DOXYGEN__)
+#define palWriteLine(line, bit) palWritePad(PAL_PORT(line), PAL_PAD(line), bit)
+#else
+#define palWriteLine(line, bit) pal_lld_writeline(line, bit)
+#endif
+
+/**
+ * @brief Sets a line logic state to @p PAL_HIGH.
+ * @note The operation is not guaranteed to be atomic on all the
+ * architectures, for atomicity and/or portability reasons you may
+ * need to enclose port I/O operations between @p osalSysLock() and
+ * @p osalSysUnlock().
+ * @note The function can be called from any context.
+ *
+ * @param[in] line line identifier
+ *
+ * @special
+ */
+#if !defined(pal_lld_setline) || defined(__DOXYGEN__)
+#define palSetLine(line) palSetPad(PAL_PORT(line), PAL_PAD(line))
+#else
+#define palSetLine(line) pal_lld_setline(line)
+#endif
+
+/**
+ * @brief Clears a line logic state to @p PAL_LOW.
+ * @note The operation is not guaranteed to be atomic on all the
+ * architectures, for atomicity and/or portability reasons you may
+ * need to enclose port I/O operations between @p osalSysLock() and
+ * @p osalSysUnlock().
+ * @note The function can be called from any context.
+ *
+ * @param[in] line line identifier
+ *
+ * @special
+ */
+#if !defined(pal_lld_clearline) || defined(__DOXYGEN__)
+#define palClearLine(line) palClearPad(PAL_PORT(line), PAL_PAD(line))
+#else
+#define palClearLine(line) pal_lld_clearline(line)
+#endif
+
+/**
+ * @brief Toggles a line logic state.
+ * @note The operation is not guaranteed to be atomic on all the
+ * architectures, for atomicity and/or portability reasons you may
+ * need to enclose port I/O operations between @p osalSysLock() and
+ * @p osalSysUnlock().
+ * @note The function can be called from any context.
+ *
+ * @param[in] line line identifier
+ *
+ * @special
+ */
+#if !defined(pal_lld_toggleline) || defined(__DOXYGEN__)
+#define palToggleLine(line) palTogglePad(PAL_PORT(line), PAL_PAD(line))
+#else
+#define palToggleLine(line) pal_lld_toggleline(line)
+#endif
+
+/**
+ * @brief Line mode setup.
+ * @note The operation is not guaranteed to be atomic on all the
+ * architectures, for atomicity and/or portability reasons you may
+ * need to enclose port I/O operations between @p osalSysLock() and
+ * @p osalSysUnlock().
+ * @note The function can be called from any context.
+ *
+ * @param[in] line line identifier
+ * @param[in] mode pad mode
+ *
+ * @special
+ */
+#if !defined(pal_lld_setlinemode) || defined(__DOXYGEN__)
+#define palSetLineMode(line, mode) \
+ palSetPadMode(PAL_PORT(line), PAL_PAD(line), mode)
+#else
+#define palSetLineMode(line, mode) pal_lld_setlinemode(line, mode)
+#endif
+
+#if (PAL_USE_CALLBACKS == TRUE) || (PAL_USE_WAIT == TRUE) || \
+ defined(__DOXYGEN__)
+/**
+ * @brief Pad event enable.
+ * @note Programming an unknown or unsupported mode is silently ignored.
+ *
+ * @param[in] port port identifier
+ * @param[in] pad pad number within the port
+ * @param[in] mode pad event mode
+ *
+ * @iclass
+ */
+#if !defined(pal_lld_enablepadevent) || defined(__DOXYGEN__)
+#define palEnablePadEventI(port, pad, mode)
+#else
+#define palEnablePadEventI(port, pad, mode) \
+ pal_lld_enablepadevent(port, pad, mode)
+#endif
+
+/**
+ * @brief Pad event disable.
+ * @details This function also disables previously programmed event callbacks.
+ *
+ * @param[in] port port identifier
+ * @param[in] pad pad number within the port
+ *
+ * @iclass
+ */
+#if !defined(pal_lld_disablepadevent) || defined(__DOXYGEN__)
+#define palDisablePadEventI(port, pad)
+#else
+#define palDisablePadEventI(port, pad) \
+ pal_lld_disablepadevent(port, pad)
+#endif
+
+/**
+ * @brief Pad event enable.
+ * @note Programming an unknown or unsupported mode is silently ignored.
+ *
+ * @param[in] port port identifier
+ * @param[in] pad pad number within the port
+ * @param[in] mode pad event mode
+ *
+ * @api
+ */
+#define palEnablePadEvent(port, pad, mode) \
+ do { \
+ osalSysLock(); \
+ palEnablePadEventI(port, pad, mode); \
+ osalSysUnlock(); \
+ } while (false)
+
+/**
+ * @brief Pad event disable.
+ * @details This function also disables previously programmed event callbacks.
+ *
+ * @param[in] port port identifier
+ * @param[in] pad pad number within the port
+ *
+ * @api
+ */
+#define palDisablePadEvent(port, pad) \
+ do { \
+ osalSysLock(); \
+ palDisablePadEventI(port, pad); \
+ osalSysUnlock(); \
+ } while (false)
+
+/**
+ * @brief Line event enable.
+ * @note Programming an unknown or unsupported mode is silently ignored.
+ *
+ * @param[in] line line identifier
+ * @param[in] mode line event mode
+ *
+ * @iclass
+ */
+#if !defined(pal_lld_enablelineevent) || defined(__DOXYGEN__)
+#define palEnableLineEventI(line, mode) \
+ palEnablePadEventI(PAL_PORT(line), PAL_PAD(line), mode)
+#else
+#define palEnableLineEventI(line, mode) \
+ pal_lld_enablelineevent(line, mode)
+#endif
+
+/**
+ * @brief Line event disable.
+ * @details This function also disables previously programmed event callbacks.
+ *
+ * @param[in] line line identifier
+ *
+ * @iclass
+ */
+#if !defined(pal_lld_disablelineevent) || defined(__DOXYGEN__)
+#define palDisableLineEventI(line) \
+ palDisablePadEventI(PAL_PORT(line), PAL_PAD(line))
+#else
+#define palDisableLineEventI(line) pal_lld_disablelineevent(line)
+#endif
+
+/**
+ * @brief Line event enable.
+ * @note Programming an unknown or unsupported mode is silently ignored.
+ *
+ * @param[in] line line identifier
+ * @param[in] mode line event mode
+ *
+ * @api
+ */
+#define palEnableLineEvent(line, mode) \
+ do { \
+ osalSysLock(); \
+ palEnableLineEventI(line, mode); \
+ osalSysUnlock(); \
+ } while (false)
+
+/**
+ * @brief Line event disable.
+ * @details This function also disables previously programmed event callbacks.
+ *
+ * @param[in] line line identifier
+ *
+ * @api
+ */
+#define palDisableLineEvent(line) \
+ do { \
+ osalSysLock(); \
+ palDisableLineEventI(line); \
+ osalSysUnlock(); \
+ } while (false)
+
+/**
+ * @brief Pad event enable check.
+ *
+ * @param[in] port port identifier
+ * @param[in] pad pad number within the port
+ * @return Pad event status.
+ * @retval false if the pad event is disabled.
+ * @retval true if the pad event is enabled.
+ *
+ * @xclass
+ */
+#if !defined(pal_lld_ispadeventenabled) || defined(__DOXYGEN__)
+#define palIsPadEventEnabledX(port, pad) false
+#else
+#define palIsPadEventEnabledX(port, pad) \
+ pal_lld_ispadeventenabled(port, pad)
+#endif
+
+/**
+ * @brief Line event enable check.
+ *
+ * @param[in] line line identifier
+ * @return Line event status.
+ * @retval false if the line event is disabled.
+ * @retval true if the line event is enabled.
+ *
+ * @xclass
+ */
+#if !defined(pal_lld_islineeventenabled) || defined(__DOXYGEN__)
+#define palIsLineEventEnabledX(line) \
+ pal_lld_ispadeventenabled(PAL_PORT(line), PAL_PAD(line))
+#else
+#define palIsLineEventEnabledX(line) \
+ pal_lld_islineeventenabled(line)
+#endif
+
+#endif /* PAL_USE_CALLBACKS || PAL_USE_WAIT */
+
+#if (PAL_USE_CALLBACKS == TRUE) || defined(__DOXYGEN__)
+/**
+ * @brief Associates a callback to a pad.
+ *
+ * @param[in] port port identifier
+ * @param[in] pad pad number within the port
+ * @param[in] cb event callback function
+ * @param[in] arg callback argument
+ *
+ * @api
+ */
+#define palSetPadCallback(port, pad, cb, arg) \
+ do { \
+ osalSysLock(); \
+ palSetPadCallbackI(port, pad, cb, arg); \
+ osalSysUnlock(); \
+ } while (false)
+
+/**
+ * @brief Associates a callback to a line.
+ *
+ * @param[in] line line identifier
+ * @param[in] cb event callback function
+ * @param[in] arg callback argument
+ *
+ * @api
+ */
+#define palSetLineCallback(line, cb, arg) \
+ do { \
+ osalSysLock(); \
+ palSetLineCallbackI(line, cb, arg); \
+ osalSysUnlock(); \
+ } while (false)
+#endif /* PAL_USE_CALLBACKS == TRUE */
+
+/** @} */
+
+/*===========================================================================*/
+/* External declarations. */
+/*===========================================================================*/
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+ ioportmask_t palReadBus(const IOBus *bus);
+ void palWriteBus(const IOBus *bus, ioportmask_t bits);
+ void palSetBusMode(const IOBus *bus, iomode_t mode);
+#if (PAL_USE_CALLBACKS == TRUE) || defined(__DOXYGEN__)
+ void palSetPadCallbackI(ioportid_t port, iopadid_t pad,
+ palcallback_t cb, void *arg);
+ void palSetLineCallbackI(ioline_t line, palcallback_t cb, void *arg);
+#endif /* PAL_USE_CALLBACKS == TRUE */
+#if (PAL_USE_WAIT == TRUE) || defined(__DOXYGEN__)
+ msg_t palWaitPadTimeoutS(ioportid_t port, iopadid_t pad,
+ sysinterval_t timeout);
+ msg_t palWaitPadTimeout(ioportid_t port, iopadid_t pad,
+ sysinterval_t timeout);
+ msg_t palWaitLineTimeoutS(ioline_t line, sysinterval_t timeout);
+ msg_t palWaitLineTimeout(ioline_t line, sysinterval_t timeout);
+#endif /* PAL_USE_WAIT == TRUE */
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* HAL_PAL_H */
+
+#endif /* HAL_USE_PAL == TRUE */
+
+/** @} */
diff --git a/ChibiOS_20.3.2/os/hal/include/hal_persistent.h b/ChibiOS_20.3.2/os/hal/include/hal_persistent.h new file mode 100644 index 0000000..6079e77 --- /dev/null +++ b/ChibiOS_20.3.2/os/hal/include/hal_persistent.h @@ -0,0 +1,184 @@ +/*
+ ChibiOS - Copyright (C) 2006..2018 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_persistent.h
+ * @brief Generic persistent storage class header.
+ *
+ * @addtogroup HAL_PERSISTENT
+ * @details This module define an abstract interface for generic persistent
+ * storage. Such storage has a fixed size and can be read and
+ * written.
+ * @{
+ */
+
+#ifndef HAL_PERSISTENT_H
+#define HAL_PERSISTENT_H
+
+/*===========================================================================*/
+/* Driver constants. */
+/*===========================================================================*/
+
+/*===========================================================================*/
+/* Driver pre-compile time settings. */
+/*===========================================================================*/
+
+/*===========================================================================*/
+/* Derived constants and error checks. */
+/*===========================================================================*/
+
+/*===========================================================================*/
+/* Driver data structures and types. */
+/*===========================================================================*/
+
+/**
+ * @brief Type of a persistent storage error code.
+ * @note Code values are kept equal to the equivalent codes in the flash
+ * interface, this is intentional.
+ */
+typedef enum {
+ PS_NO_ERROR = 0, /* No error. */
+ PS_ERROR_READ = 2, /* ECC or other error during read operation.*/
+ PS_ERROR_WRITE = 3, /* Program operation failed. */
+ PS_ERROR_VERIFY = 5, /* Verify operation failed. */
+ PS_ERROR_HW_FAILURE = 6 /* Controller or communication error. */
+} ps_error_t;
+
+/**
+ * @brief Type of a persistent storage offset.
+ */
+typedef uint32_t ps_offset_t;
+
+/**
+ * @brief @p BasePersistentStorage specific methods.
+ */
+#define _base_pers_storage_methods_alone \
+ /* Storage size.*/ \
+ size_t (*getsize)(void *instance); \
+ /* Read operation.*/ \
+ ps_error_t (*read)(void *instance, ps_offset_t offset, \
+ size_t n, uint8_t *rp); \
+ /* Write operation.*/ \
+ ps_error_t (*write)(void *instance, ps_offset_t offset, \
+ size_t n, const uint8_t *wp);
+
+/**
+ * @brief @p BasePersistentStorage specific methods with inherited ones.
+ */
+#define _base_pers_storage_methods \
+ _base_object_methods \
+ _base_pers_storage_methods_alone
+
+/**
+ * @brief @p BasePersistentStorage virtual methods table.
+ */
+struct BasePersistentStorageVMT {
+ _base_pers_storage_methods
+};
+
+/**
+ * @brief @p BasePersistentStorage specific data.
+ */
+#define _base_persistent_storage_data \
+ _base_object_data
+
+/**
+ * @extends BaseObject
+ *
+ * @brief Base persistent storage class.
+ */
+typedef struct {
+ /** @brief Virtual Methods Table.*/
+ const struct BasePersistentStorageVMT *vmt;
+ _base_persistent_storage_data
+} BasePersistentStorage;
+
+/*===========================================================================*/
+/* Driver macros. */
+/*===========================================================================*/
+
+/**
+ * @name Macro Functions (BasePersistentStorage)
+ * @{
+ */
+/**
+ * @brief Instance getter.
+ * @details This special method is used to get the instance of this class
+ * object from a derived class.
+ */
+#define getBasePersistentStorage(ip) ((BasePersistentStorage *)&(ip)->vmt)
+
+/**
+ * @brief Get storage size.
+ *
+ * @param[in] ip pointer to a @p BasePersistentStorage or derived class
+ * @return The storage size in bytes.
+ *
+ * @api
+ */
+#define psGetStorageSize(ip) \
+ (ip)->vmt->getsize(ip)
+
+/**
+ * @brief Read operation.
+ *
+ * @param[in] ip pointer to a @p BasePersistentStorage or derived class
+ * @param[in] offset persistent storage offset
+ * @param[in] n number of bytes to be read
+ * @param[out] rp pointer to the data buffer
+ * @return An error code.
+ * @retval PS_NO_ERROR if there is no erase operation in progress.
+ * @retval PS_ERROR_READ if the read operation failed.
+ * @retval PS_ERROR_HW_FAILURE if access to the memory failed.
+ *
+ * @api
+ */
+#define psRead(ip, offset, n, rp) \
+ (ip)->vmt->read(ip, offset, n, rp)
+
+/**
+ * @brief Write operation.
+ *
+ * @param[in] ip pointer to a @p BasePersistentStorage or derived class
+ * @param[in] offset persistent storage offset
+ * @param[in] n number of bytes to be written
+ * @param[in] wp pointer to the data buffer
+ * @return An error code.
+ * @retval PS_NO_ERROR if there is no erase operation in progress.
+ * @retval PS_ERROR_WRITE if the write operation failed.
+ * @retval PS_ERROR_HW_FAILURE if access to the memory failed.
+ *
+ * @api
+ */
+#define psWrite(ip, offset, n, wp) \
+ (ip)->vmt->write(ip, offset, n, wp)
+/** @} */
+
+/*===========================================================================*/
+/* External declarations. */
+/*===========================================================================*/
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* HAL_PERSISTENT_H */
+
+/** @} */
diff --git a/ChibiOS_20.3.2/os/hal/include/hal_pwm.h b/ChibiOS_20.3.2/os/hal/include/hal_pwm.h new file mode 100644 index 0000000..ee2d191 --- /dev/null +++ b/ChibiOS_20.3.2/os/hal/include/hal_pwm.h @@ -0,0 +1,308 @@ +/*
+ ChibiOS - Copyright (C) 2006..2018 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_pwm.h
+ * @brief PWM Driver macros and structures.
+ *
+ * @addtogroup PWM
+ * @{
+ */
+
+#ifndef HAL_PWM_H
+#define HAL_PWM_H
+
+#if (HAL_USE_PWM == TRUE) || defined(__DOXYGEN__)
+
+/*===========================================================================*/
+/* Driver constants. */
+/*===========================================================================*/
+
+/**
+ * @name PWM output mode macros
+ * @{
+ */
+/**
+ * @brief Standard output modes mask.
+ */
+#define PWM_OUTPUT_MASK 0x0FU
+
+/**
+ * @brief Output not driven, callback only.
+ */
+#define PWM_OUTPUT_DISABLED 0x00U
+
+/**
+ * @brief Positive PWM logic, active is logic level one.
+ */
+#define PWM_OUTPUT_ACTIVE_HIGH 0x01U
+
+/**
+ * @brief Inverse PWM logic, active is logic level zero.
+ */
+#define PWM_OUTPUT_ACTIVE_LOW 0x02U
+/** @} */
+
+/*===========================================================================*/
+/* Driver pre-compile time settings. */
+/*===========================================================================*/
+
+/*===========================================================================*/
+/* Derived constants and error checks. */
+/*===========================================================================*/
+
+/*===========================================================================*/
+/* Driver data structures and types. */
+/*===========================================================================*/
+
+/**
+ * @brief Driver state machine possible states.
+ */
+typedef enum {
+ PWM_UNINIT = 0, /**< Not initialized. */
+ PWM_STOP = 1, /**< Stopped. */
+ PWM_READY = 2 /**< Ready. */
+} pwmstate_t;
+
+/**
+ * @brief Type of a structure representing a PWM driver.
+ */
+typedef struct PWMDriver PWMDriver;
+
+/**
+ * @brief Type of a PWM notification callback.
+ *
+ * @param[in] pwmp pointer to a @p PWMDriver object
+ */
+typedef void (*pwmcallback_t)(PWMDriver *pwmp);
+
+#include "hal_pwm_lld.h"
+
+/*===========================================================================*/
+/* Driver macros. */
+/*===========================================================================*/
+
+/**
+ * @name PWM duty cycle conversion
+ * @{
+ */
+/**
+ * @brief Converts from fraction to pulse width.
+ * @note Be careful with rounding errors, this is integer math not magic.
+ * You can specify tenths of thousandth but make sure you have the
+ * proper hardware resolution by carefully choosing the clock source
+ * and prescaler settings, see @p PWM_COMPUTE_PSC.
+ *
+ * @param[in] pwmp pointer to a @p PWMDriver object
+ * @param[in] denominator denominator of the fraction
+ * @param[in] numerator numerator of the fraction
+ * @return The pulse width to be passed to @p pwmEnableChannel().
+ *
+ * @api
+ */
+#define PWM_FRACTION_TO_WIDTH(pwmp, denominator, numerator) \
+ ((pwmcnt_t)((((pwmcnt_t)(pwmp)->period) * \
+ (pwmcnt_t)(numerator)) / (pwmcnt_t)(denominator)))
+
+/**
+ * @brief Converts from degrees to pulse width.
+ * @note Be careful with rounding errors, this is integer math not magic.
+ * You can specify hundredths of degrees but make sure you have the
+ * proper hardware resolution by carefully choosing the clock source
+ * and prescaler settings, see @p PWM_COMPUTE_PSC.
+ *
+ * @param[in] pwmp pointer to a @p PWMDriver object
+ * @param[in] degrees degrees as an integer between 0 and 36000
+ * @return The pulse width to be passed to @p pwmEnableChannel().
+ *
+ * @api
+ */
+#define PWM_DEGREES_TO_WIDTH(pwmp, degrees) \
+ PWM_FRACTION_TO_WIDTH(pwmp, 36000, degrees)
+
+/**
+ * @brief Converts from percentage to pulse width.
+ * @note Be careful with rounding errors, this is integer math not magic.
+ * You can specify tenths of thousandth but make sure you have the
+ * proper hardware resolution by carefully choosing the clock source
+ * and prescaler settings, see @p PWM_COMPUTE_PSC.
+ *
+ * @param[in] pwmp pointer to a @p PWMDriver object
+ * @param[in] percentage percentage as an integer between 0 and 10000
+ * @return The pulse width to be passed to @p pwmEnableChannel().
+ *
+ * @api
+ */
+#define PWM_PERCENTAGE_TO_WIDTH(pwmp, percentage) \
+ PWM_FRACTION_TO_WIDTH(pwmp, 10000, percentage)
+/** @} */
+
+/**
+ * @name Macro Functions
+ * @{
+ */
+/**
+ * @brief Changes the period the PWM peripheral.
+ * @details This function changes the period of a PWM unit that has already
+ * been activated using @p pwmStart().
+ * @pre The PWM unit must have been activated using @p pwmStart().
+ * @post The PWM unit period is changed to the new value.
+ * @note If a period is specified that is shorter than the pulse width
+ * programmed in one of the channels then the behavior is not
+ * guaranteed.
+ *
+ * @param[in] pwmp pointer to a @p PWMDriver object
+ * @param[in] value new cycle time in ticks
+ *
+ * @iclass
+ */
+#define pwmChangePeriodI(pwmp, value) { \
+ (pwmp)->period = (value); \
+ pwm_lld_change_period(pwmp, value); \
+}
+
+/**
+ * @brief Enables a PWM channel.
+ * @pre The PWM unit must have been activated using @p pwmStart().
+ * @post The channel is active using the specified configuration.
+ * @note Depending on the hardware implementation this function has
+ * effect starting on the next cycle (recommended implementation)
+ * or immediately (fallback implementation).
+ *
+ * @param[in] pwmp pointer to a @p PWMDriver object
+ * @param[in] channel PWM channel identifier (0...channels-1)
+ * @param[in] width PWM pulse width as clock pulses number
+ *
+ * @iclass
+ */
+#define pwmEnableChannelI(pwmp, channel, width) do { \
+ (pwmp)->enabled |= ((pwmchnmsk_t)1U << (pwmchnmsk_t)(channel)); \
+ pwm_lld_enable_channel(pwmp, channel, width); \
+} while (false)
+
+/**
+ * @brief Disables a PWM channel.
+ * @pre The PWM unit must have been activated using @p pwmStart().
+ * @post The channel is disabled and its output line returned to the
+ * idle state.
+ * @note Depending on the hardware implementation this function has
+ * effect starting on the next cycle (recommended implementation)
+ * or immediately (fallback implementation).
+ *
+ * @param[in] pwmp pointer to a @p PWMDriver object
+ * @param[in] channel PWM channel identifier (0...channels-1)
+ *
+ * @iclass
+ */
+#define pwmDisableChannelI(pwmp, channel) do { \
+ (pwmp)->enabled &= ~((pwmchnmsk_t)1U << (pwmchnmsk_t)(channel)); \
+ pwm_lld_disable_channel(pwmp, channel); \
+} while (false)
+
+/**
+ * @brief Returns a PWM channel status.
+ * @pre The PWM unit must have been activated using @p pwmStart().
+ *
+ * @param[in] pwmp pointer to a @p PWMDriver object
+ * @param[in] channel PWM channel identifier (0...channels-1)
+ *
+ * @iclass
+ */
+#define pwmIsChannelEnabledI(pwmp, channel) \
+ (((pwmp)->enabled & ((pwmchnmsk_t)1U << (pwmchnmsk_t)(channel))) != 0U)
+
+/**
+ * @brief Enables the periodic activation edge notification.
+ * @pre The PWM unit must have been activated using @p pwmStart().
+ * @note If the notification is already enabled then the call has no effect.
+ *
+ * @param[in] pwmp pointer to a @p PWMDriver object
+ *
+ * @iclass
+ */
+#define pwmEnablePeriodicNotificationI(pwmp) \
+ pwm_lld_enable_periodic_notification(pwmp)
+
+/**
+ * @brief Disables the periodic activation edge notification.
+ * @pre The PWM unit must have been activated using @p pwmStart().
+ * @note If the notification is already disabled then the call has no effect.
+ *
+ * @param[in] pwmp pointer to a @p PWMDriver object
+ *
+ * @iclass
+ */
+#define pwmDisablePeriodicNotificationI(pwmp) \
+ pwm_lld_disable_periodic_notification(pwmp)
+
+/**
+ * @brief Enables a channel de-activation edge notification.
+ * @pre The PWM unit must have been activated using @p pwmStart().
+ * @pre The channel must have been activated using @p pwmEnableChannel().
+ * @note If the notification is already enabled then the call has no effect.
+ *
+ * @param[in] pwmp pointer to a @p PWMDriver object
+ * @param[in] channel PWM channel identifier (0...channels-1)
+ *
+ * @iclass
+ */
+#define pwmEnableChannelNotificationI(pwmp, channel) \
+ pwm_lld_enable_channel_notification(pwmp, channel)
+
+/**
+ * @brief Disables a channel de-activation edge notification.
+ * @pre The PWM unit must have been activated using @p pwmStart().
+ * @pre The channel must have been activated using @p pwmEnableChannel().
+ * @note If the notification is already disabled then the call has no effect.
+ *
+ * @param[in] pwmp pointer to a @p PWMDriver object
+ * @param[in] channel PWM channel identifier (0...channels-1)
+ *
+ * @iclass
+ */
+#define pwmDisableChannelNotificationI(pwmp, channel) \
+ pwm_lld_disable_channel_notification(pwmp, channel)
+/** @} */
+
+/*===========================================================================*/
+/* External declarations. */
+/*===========================================================================*/
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+ void pwmInit(void);
+ void pwmObjectInit(PWMDriver *pwmp);
+ void pwmStart(PWMDriver *pwmp, const PWMConfig *config);
+ void pwmStop(PWMDriver *pwmp);
+ void pwmChangePeriod(PWMDriver *pwmp, pwmcnt_t period);
+ void pwmEnableChannel(PWMDriver *pwmp,
+ pwmchannel_t channel,
+ pwmcnt_t width);
+ void pwmDisableChannel(PWMDriver *pwmp, pwmchannel_t channel);
+ void pwmEnablePeriodicNotification(PWMDriver *pwmp);
+ void pwmDisablePeriodicNotification(PWMDriver *pwmp);
+ void pwmEnableChannelNotification(PWMDriver *pwmp, pwmchannel_t channel);
+ void pwmDisableChannelNotification(PWMDriver *pwmp, pwmchannel_t channel);
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* HAL_USE_PWM == TRUE */
+
+#endif /* HAL_PWM_H */
+
+/** @} */
diff --git a/ChibiOS_20.3.2/os/hal/include/hal_queues.h b/ChibiOS_20.3.2/os/hal/include/hal_queues.h new file mode 100644 index 0000000..d85cb93 --- /dev/null +++ b/ChibiOS_20.3.2/os/hal/include/hal_queues.h @@ -0,0 +1,328 @@ +/*
+ ChibiOS - Copyright (C) 2006..2018 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_queues.h
+ * @brief I/O Queues macros and structures.
+ *
+ * @addtogroup HAL_QUEUES
+ * @{
+ */
+
+#ifndef HAL_QUEUES_H
+#define HAL_QUEUES_H
+
+/*===========================================================================*/
+/* Driver constants. */
+/*===========================================================================*/
+
+/**
+ * @name Queue functions returned status value
+ * @{
+ */
+#define Q_OK MSG_OK /**< @brief Operation successful. */
+#define Q_TIMEOUT MSG_TIMEOUT /**< @brief Timeout condition. */
+#define Q_RESET MSG_RESET /**< @brief Queue has been reset. */
+#define Q_EMPTY MSG_TIMEOUT /**< @brief Queue empty. */
+#define Q_FULL MSG_TIMEOUT /**< @brief Queue full, */
+/** @} */
+
+/*===========================================================================*/
+/* Driver pre-compile time settings. */
+/*===========================================================================*/
+
+/*===========================================================================*/
+/* Derived constants and error checks. */
+/*===========================================================================*/
+
+/*===========================================================================*/
+/* Driver data structures and types. */
+/*===========================================================================*/
+
+/**
+ * @brief Type of a generic I/O queue structure.
+ */
+typedef struct io_queue io_queue_t;
+
+/**
+ * @brief Queue notification callback type.
+ *
+ * @param[in] qp the queue pointer
+ */
+typedef void (*qnotify_t)(io_queue_t *qp);
+
+/**
+ * @brief Generic I/O queue structure.
+ * @details This structure represents a generic Input or Output asymmetrical
+ * queue. The queue is asymmetrical because one end is meant to be
+ * accessed from a thread context, and thus can be blocking, the other
+ * end is accessible from interrupt handlers or from within a kernel
+ * lock zone and is non-blocking.
+ */
+struct io_queue {
+ threads_queue_t q_waiting; /**< @brief Queue of waiting threads. */
+ volatile size_t q_counter; /**< @brief Resources counter. */
+ uint8_t *q_buffer; /**< @brief Pointer to the queue buffer.*/
+ uint8_t *q_top; /**< @brief Pointer to the first
+ location after the buffer. */
+ uint8_t *q_wrptr; /**< @brief Write pointer. */
+ uint8_t *q_rdptr; /**< @brief Read pointer. */
+ qnotify_t q_notify; /**< @brief Data notification callback. */
+ void *q_link; /**< @brief Application defined field. */
+};
+
+/**
+ * @extends io_queue_t
+ *
+ * @brief Type of an input queue structure.
+ * @details This structure represents a generic asymmetrical input queue.
+ * Writing to the queue is non-blocking and can be performed from
+ * interrupt handlers or from within a kernel lock zone.
+ * Reading the queue can be a blocking operation and is supposed to
+ * be performed by a system thread.
+ */
+typedef io_queue_t input_queue_t;
+
+/**
+ * @extends io_queue_t
+ *
+ * @brief Type of an output queue structure.
+ * @details This structure represents a generic asymmetrical output queue.
+ * Reading from the queue is non-blocking and can be performed from
+ * interrupt handlers or from within a kernel lock zone.
+ * Writing the queue can be a blocking operation and is supposed to
+ * be performed by a system thread.
+ */
+typedef io_queue_t output_queue_t;
+
+/*===========================================================================*/
+/* Driver macros. */
+/*===========================================================================*/
+
+/**
+ * @name Macro Functions
+ * @{
+ */
+/**
+ * @brief Returns the queue's buffer size.
+ *
+ * @param[in] qp pointer to a @p io_queue_t structure
+ * @return The buffer size.
+ *
+ * @xclass
+ */
+#define qSizeX(qp) \
+ /*lint -save -e9033 [10.8] The cast is safe.*/ \
+ ((size_t)((qp)->q_top - (qp)->q_buffer)) \
+ /*lint -restore*/
+
+/**
+ * @brief Queue space.
+ * @details Returns the used space if used on an input queue or the empty
+ * space if used on an output queue.
+ *
+ * @param[in] qp pointer to a @p io_queue_t structure
+ * @return The buffer space.
+ *
+ * @iclass
+ */
+#define qSpaceI(qp) ((qp)->q_counter)
+
+/**
+ * @brief Returns the queue application-defined link.
+ * @note This function can be called in any context.
+ *
+ * @param[in] qp pointer to a @p io_queue_t structure
+ * @return The application-defined link.
+ *
+ * @special
+ */
+#define qGetLink(qp) ((qp)->q_link)
+
+/**
+ * @brief Sets the queue application-defined link.
+ * @note This function can be called in any context.
+ *
+ * @param[in] qp pointer to a @p io_queue_t structure
+ * @param[in] lk The application-defined link.
+ *
+ * @special
+ */
+#define qSetLink(qp, lk) ((qp)->q_link = lk)
+
+/**
+ * @brief Returns the filled space into an input queue.
+ *
+ * @param[in] iqp pointer to an @p input_queue_t structure
+ * @return The number of full bytes in the queue.
+ * @retval 0 if the queue is empty.
+ *
+ * @iclass
+ */
+#define iqGetFullI(iqp) qSpaceI(iqp)
+
+/**
+ * @brief Returns the empty space into an input queue.
+ *
+ * @param[in] iqp pointer to an @p input_queue_t structure
+ * @return The number of empty bytes in the queue.
+ * @retval 0 if the queue is full.
+ *
+ * @iclass
+ */
+#define iqGetEmptyI(iqp) (qSizeX(iqp) - qSpaceI(iqp))
+
+/**
+ * @brief Evaluates to @p true if the specified input queue is empty.
+ *
+ * @param[in] iqp pointer to an @p input_queue_t structure
+ * @return The queue status.
+ * @retval false if the queue is not empty.
+ * @retval true if the queue is empty.
+ *
+ * @iclass
+ */
+#define iqIsEmptyI(iqp) ((bool)(qSpaceI(iqp) == 0U))
+
+/**
+ * @brief Evaluates to @p true if the specified input queue is full.
+ *
+ * @param[in] iqp pointer to an @p input_queue_t structure
+ * @return The queue status.
+ * @retval false if the queue is not full.
+ * @retval true if the queue is full.
+ *
+ * @iclass
+ */
+#define iqIsFullI(iqp) \
+ /*lint -save -e9007 [13.5] No side effects, a pointer is passed.*/ \
+ ((bool)(((iqp)->q_wrptr == (iqp)->q_rdptr) && ((iqp)->q_counter != 0U))) \
+ /*lint -restore*/
+
+/**
+ * @brief Input queue read.
+ * @details This function reads a byte value from an input queue. If the queue
+ * is empty then the calling thread is suspended until a byte arrives
+ * in the queue.
+ *
+ * @param[in] iqp pointer to an @p input_queue_t structure
+ * @return A byte value from the queue.
+ * @retval MSG_RESET if the queue has been reset.
+ *
+ * @api
+ */
+#define iqGet(iqp) iqGetTimeout(iqp, TIME_INFINITE)
+
+/**
+ * @brief Returns the filled space into an output queue.
+ *
+ * @param[in] oqp pointer to an @p output_queue_t structure
+ * @return The number of full bytes in the queue.
+ * @retval 0 if the queue is empty.
+ *
+ * @iclass
+ */
+#define oqGetFullI(oqp) (qSizeX(oqp) - qSpaceI(oqp))
+
+/**
+ * @brief Returns the empty space into an output queue.
+ *
+ * @param[in] oqp pointer to an @p output_queue_t structure
+ * @return The number of empty bytes in the queue.
+ * @retval 0 if the queue is full.
+ *
+ * @iclass
+ */
+#define oqGetEmptyI(oqp) qSpaceI(oqp)
+
+/**
+ * @brief Evaluates to @p true if the specified output queue is empty.
+ *
+ * @param[in] oqp pointer to an @p output_queue_t structure
+ * @return The queue status.
+ * @retval false if the queue is not empty.
+ * @retval true if the queue is empty.
+ *
+ * @iclass
+ */
+#define oqIsEmptyI(oqp) \
+ /*lint -save -e9007 [13.5] No side effects, a pointer is passed.*/ \
+ ((bool)(((oqp)->q_wrptr == (oqp)->q_rdptr) && ((oqp)->q_counter != 0U))) \
+ /*lint -restore*/
+
+/**
+ * @brief Evaluates to @p true if the specified output queue is full.
+ *
+ * @param[in] oqp pointer to an @p output_queue_t structure
+ * @return The queue status.
+ * @retval false if the queue is not full.
+ * @retval true if the queue is full.
+ *
+ * @iclass
+ */
+#define oqIsFullI(oqp) ((bool)(qSpaceI(oqp) == 0U))
+
+/**
+ * @brief Output queue write.
+ * @details This function writes a byte value to an output queue. If the queue
+ * is full then the calling thread is suspended until there is space
+ * in the queue.
+ *
+ * @param[in] oqp pointer to an @p output_queue_t structure
+ * @param[in] b the byte value to be written in the queue
+ * @return The operation status.
+ * @retval MSG_OK if the operation succeeded.
+ * @retval MSG_RESET if the queue has been reset.
+ *
+ * @api
+ */
+#define oqPut(oqp, b) oqPutTimeout(oqp, b, TIME_INFINITE)
+/** @} */
+
+/*===========================================================================*/
+/* External declarations. */
+/*===========================================================================*/
+ /** @} */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+ void iqObjectInit(input_queue_t *iqp, uint8_t *bp, size_t size,
+ qnotify_t infy, void *link);
+ void iqResetI(input_queue_t *iqp);
+ msg_t iqPutI(input_queue_t *iqp, uint8_t b);
+ msg_t iqGetI(input_queue_t *iqp);
+ msg_t iqGetTimeout(input_queue_t *iqp, sysinterval_t timeout);
+ size_t iqReadI(input_queue_t *iqp, uint8_t *bp, size_t n);
+ size_t iqReadTimeout(input_queue_t *iqp, uint8_t *bp,
+ size_t n, sysinterval_t timeout);
+
+ void oqObjectInit(output_queue_t *oqp, uint8_t *bp, size_t size,
+ qnotify_t onfy, void *link);
+ void oqResetI(output_queue_t *oqp);
+ msg_t oqPutI(output_queue_t *oqp, uint8_t b);
+ msg_t oqPutTimeout(output_queue_t *oqp, uint8_t b, sysinterval_t timeout);
+ msg_t oqGetI(output_queue_t *oqp);
+ size_t oqWriteI(output_queue_t *oqp, const uint8_t *bp, size_t n);
+ size_t oqWriteTimeout(output_queue_t *oqp, const uint8_t *bp,
+ size_t n, sysinterval_t timeout);
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* HAL_QUEUES_H */
+
+/** @} */
diff --git a/ChibiOS_20.3.2/os/hal/include/hal_rtc.h b/ChibiOS_20.3.2/os/hal/include/hal_rtc.h new file mode 100644 index 0000000..2003b53 --- /dev/null +++ b/ChibiOS_20.3.2/os/hal/include/hal_rtc.h @@ -0,0 +1,204 @@ +/*
+ ChibiOS - Copyright (C) 2006..2018 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.
+*/
+/*
+ Concepts and parts of this file have been contributed by Uladzimir Pylinsky
+ aka barthess.
+ */
+
+/**
+ * @file hal_rtc.h
+ * @brief RTC Driver macros and structures.
+ *
+ * @addtogroup RTC
+ * @{
+ */
+
+#ifndef HAL_RTC_H
+#define HAL_RTC_H
+
+#if (HAL_USE_RTC == TRUE) || defined(__DOXYGEN__)
+
+/*lint -save -e829 [21.10] The header is required.*/
+#include <time.h>
+/*lint -restore*/
+
+/*===========================================================================*/
+/* Driver constants. */
+/*===========================================================================*/
+
+/**
+ * @brief Base year of the calendar.
+ */
+#define RTC_BASE_YEAR 1980U
+
+/**
+ * @name Date/Time bit masks for FAT format
+ * @{
+ */
+#define RTC_FAT_TIME_SECONDS_MASK 0x0000001FU
+#define RTC_FAT_TIME_MINUTES_MASK 0x000007E0U
+#define RTC_FAT_TIME_HOURS_MASK 0x0000F800U
+#define RTC_FAT_DATE_DAYS_MASK 0x001F0000U
+#define RTC_FAT_DATE_MONTHS_MASK 0x01E00000U
+#define RTC_FAT_DATE_YEARS_MASK 0xFE000000U
+/** @} */
+
+/**
+ * @name Day of week encoding
+ * @{
+ */
+#define RTC_DAY_CATURDAY 0U
+#define RTC_DAY_MONDAY 1U
+#define RTC_DAY_TUESDAY 2U
+#define RTC_DAY_WEDNESDAY 3U
+#define RTC_DAY_THURSDAY 4U
+#define RTC_DAY_FRIDAY 5U
+#define RTC_DAY_SATURDAY 6U
+#define RTC_DAY_SUNDAY 7U
+/** @} */
+
+/*===========================================================================*/
+/* Driver pre-compile time settings. */
+/*===========================================================================*/
+
+/*===========================================================================*/
+/* Derived constants and error checks. */
+/*===========================================================================*/
+
+/*===========================================================================*/
+/* Driver data structures and types. */
+/*===========================================================================*/
+
+/**
+ * @brief Type of a structure representing an RTC driver.
+ */
+typedef struct RTCDriver RTCDriver;
+
+/**
+ * @brief Type of an RTC alarm number.
+ */
+typedef unsigned int rtcalarm_t;
+
+/**
+ * @brief Type of a structure representing an RTC date/time stamp.
+ */
+typedef struct {
+ /*lint -save -e46 [6.1] In this case uint32_t is fine.*/
+ uint32_t year: 8; /**< @brief Years since 1980. */
+ uint32_t month: 4; /**< @brief Months 1..12. */
+ uint32_t dstflag: 1; /**< @brief DST correction flag. */
+ uint32_t dayofweek: 3; /**< @brief Day of week 1..7. */
+ uint32_t day: 5; /**< @brief Day of the month 1..31. */
+ uint32_t millisecond: 27; /**< @brief Milliseconds since midnight.*/
+ /*lint -restore*/
+} RTCDateTime;
+
+/**
+ * @brief BasePersistentStorage specific methods.
+ */
+#define _rtc_driver_methods \
+ _base_pers_storage_methods
+
+#include "hal_rtc_lld.h"
+
+/* Some more checks, must happen after inclusion of the LLD header, this is
+ why are placed here.*/
+#if !defined(RTC_SUPPORTS_CALLBACKS)
+#error "RTC LLD does not define the required RTC_SUPPORTS_CALLBACKS macro"
+#endif
+
+#if !defined(RTC_ALARMS)
+#error "RTC LLD does not define the required RTC_ALARMS macro"
+#endif
+
+#if !defined(RTC_HAS_STORAGE)
+#error "RTC LLD does not define the required RTC_HAS_STORAGE macro"
+#endif
+
+#if (RTC_HAS_STORAGE == TRUE) || defined(__DOXYGEN__)
+/**
+ * @extends FileStream
+ *
+ * @brief @p RTCDriver virtual methods table.
+ */
+struct RTCDriverVMT {
+ _rtc_driver_methods
+};
+#endif
+
+/**
+ * @brief Structure representing an RTC driver.
+ */
+struct RTCDriver {
+#if (RTC_HAS_STORAGE == TRUE) || defined(__DOXYGEN__)
+ /**
+ * @brief Virtual Methods Table.
+ */
+ const struct RTCDriverVMT *vmt;
+#endif
+#if defined(RTC_DRIVER_EXT_FIELDS)
+ RTC_DRIVER_EXT_FIELDS
+#endif
+ /* End of the mandatory fields.*/
+ rtc_lld_driver_fields;
+};
+
+/*===========================================================================*/
+/* Driver macros. */
+/*===========================================================================*/
+
+/*===========================================================================*/
+/* External declarations. */
+/*===========================================================================*/
+
+#if !defined(__DOXYGEN__)
+extern RTCDriver RTCD1;
+#if RTC_HAS_STORAGE == TRUE
+extern struct RTCDriverVMT _rtc_lld_vmt;
+#endif
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+ void rtcInit(void);
+ void rtcObjectInit(RTCDriver *rtcp);
+ void rtcSetTime(RTCDriver *rtcp, const RTCDateTime *timespec);
+ void rtcGetTime(RTCDriver *rtcp, RTCDateTime *timespec);
+#if RTC_ALARMS > 0
+ void rtcSetAlarm(RTCDriver *rtcp,
+ rtcalarm_t alarm,
+ const RTCAlarm *alarmspec);
+ void rtcGetAlarm(RTCDriver *rtcp, rtcalarm_t alarm, RTCAlarm *alarmspec);
+#endif
+#if RTC_SUPPORTS_CALLBACKS == TRUE
+ void rtcSetCallback(RTCDriver *rtcp, rtccb_t callback);
+#endif
+ void rtcConvertDateTimeToStructTm(const RTCDateTime *timespec,
+ struct tm *timp,
+ uint32_t *tv_msec);
+ void rtcConvertStructTmToDateTime(const struct tm *timp,
+ uint32_t tv_msec,
+ RTCDateTime *timespec);
+ uint32_t rtcConvertDateTimeToFAT(const RTCDateTime *timespec);
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* HAL_USE_RTC == TRUE */
+#endif /* HAL_RTC_H */
+
+/** @} */
diff --git a/ChibiOS_20.3.2/os/hal/include/hal_sdc.h b/ChibiOS_20.3.2/os/hal/include/hal_sdc.h new file mode 100644 index 0000000..0273a5a --- /dev/null +++ b/ChibiOS_20.3.2/os/hal/include/hal_sdc.h @@ -0,0 +1,209 @@ +/*
+ ChibiOS - Copyright (C) 2006..2018 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_sdc.h
+ * @brief SDC Driver macros and structures.
+ *
+ * @addtogroup SDC
+ * @{
+ */
+
+#ifndef HAL_SDC_H
+#define HAL_SDC_H
+
+#if (HAL_USE_SDC == TRUE) || defined(__DOXYGEN__)
+
+/*===========================================================================*/
+/* Driver constants. */
+/*===========================================================================*/
+
+/**
+ * @name SD card types
+ * @{
+ */
+#define SDC_MODE_CARDTYPE_MASK 0xFU
+#define SDC_MODE_CARDTYPE_SDV11 0U
+#define SDC_MODE_CARDTYPE_SDV20 1U
+#define SDC_MODE_CARDTYPE_MMC 2U
+#define SDC_MODE_HIGH_CAPACITY 0x10U
+/** @} */
+
+/**
+ * @name SDC bus error conditions
+ * @{
+ */
+#define SDC_NO_ERROR 0U
+#define SDC_CMD_CRC_ERROR 1U
+#define SDC_DATA_CRC_ERROR 2U
+#define SDC_DATA_TIMEOUT 4U
+#define SDC_COMMAND_TIMEOUT 8U
+#define SDC_TX_UNDERRUN 16U
+#define SDC_RX_OVERRUN 32U
+#define SDC_STARTBIT_ERROR 64U
+#define SDC_OVERFLOW_ERROR 128U
+#define SDC_UNHANDLED_ERROR 0xFFFFFFFFU
+/** @} */
+
+/*===========================================================================*/
+/* Driver pre-compile time settings. */
+/*===========================================================================*/
+
+/**
+ * @name SDC configuration options
+ * @{
+ */
+/**
+ * @brief Number of initialization attempts before rejecting the card.
+ * @note Attempts are performed at 10mS intervals.
+ */
+#if !defined(SDC_INIT_RETRY) || defined(__DOXYGEN__)
+#define SDC_INIT_RETRY 100
+#endif
+
+/**
+ * @brief Include support for MMC cards.
+ * @note MMC support is not yet implemented so this option must be kept
+ * at @p FALSE.
+ */
+#if !defined(SDC_MMC_SUPPORT) || defined(__DOXYGEN__)
+#define SDC_MMC_SUPPORT FALSE
+#endif
+
+/**
+ * @brief Delays insertions.
+ * @details If enabled this options inserts delays into the MMC waiting
+ * routines releasing some extra CPU time for the threads with
+ * lower priority, this may slow down the driver a bit however.
+ */
+#if !defined(SDC_NICE_WAITING) || defined(__DOXYGEN__)
+#define SDC_NICE_WAITING TRUE
+#endif
+
+/**
+ * @brief OCR initialization constant for V20 cards.
+ */
+#if !defined(SDC_INIT_OCR_V20) || defined(__DOXYGEN__)
+#define SDC_INIT_OCR_V20 0x50FF8000U
+#endif
+
+/**
+ * @brief OCR initialization constant for non-V20 cards.
+ */
+#if !defined(SDC_INIT_OCR) || defined(__DOXYGEN__)
+#define SDC_INIT_OCR 0x80100000U
+#endif
+/** @} */
+
+/*===========================================================================*/
+/* Derived constants and error checks. */
+/*===========================================================================*/
+
+/*===========================================================================*/
+/* Driver data structures and types. */
+/*===========================================================================*/
+
+/**
+ * @brief Type of SDIO bus mode.
+ */
+typedef enum {
+ SDC_MODE_1BIT = 0,
+ SDC_MODE_4BIT,
+ SDC_MODE_8BIT
+} sdcbusmode_t;
+
+/**
+ * @brief Max supported clock.
+ */
+typedef enum {
+ SDC_CLK_25MHz = 0,
+ SDC_CLK_50MHz
+} sdcbusclk_t;
+
+#include "hal_sdc_lld.h"
+
+/*===========================================================================*/
+/* Driver macros. */
+/*===========================================================================*/
+
+/**
+ * @name Macro Functions
+ * @{
+ */
+/**
+ * @brief Returns the card insertion status.
+ * @note This macro wraps a low level function named
+ * @p sdc_lld_is_card_inserted(), this function must be
+ * provided by the application because it is not part of the
+ * SDC driver.
+ *
+ * @param[in] sdcp pointer to the @p SDCDriver object
+ * @return The card state.
+ * @retval false card not inserted.
+ * @retval true card inserted.
+ *
+ * @api
+ */
+#define sdcIsCardInserted(sdcp) (sdc_lld_is_card_inserted(sdcp))
+
+/**
+ * @brief Returns the write protect status.
+ * @note This macro wraps a low level function named
+ * @p sdc_lld_is_write_protected(), this function must be
+ * provided by the application because it is not part of the
+ * SDC driver.
+ *
+ * @param[in] sdcp pointer to the @p SDCDriver object
+ * @return The card state.
+ * @retval false not write protected.
+ * @retval true write protected.
+ *
+ * @api
+ */
+#define sdcIsWriteProtected(sdcp) (sdc_lld_is_write_protected(sdcp))
+/** @} */
+
+/*===========================================================================*/
+/* External declarations. */
+/*===========================================================================*/
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+ void sdcInit(void);
+ void sdcObjectInit(SDCDriver *sdcp);
+ void sdcStart(SDCDriver *sdcp, const SDCConfig *config);
+ void sdcStop(SDCDriver *sdcp);
+ bool sdcConnect(SDCDriver *sdcp);
+ bool sdcDisconnect(SDCDriver *sdcp);
+ bool sdcRead(SDCDriver *sdcp, uint32_t startblk,
+ uint8_t *buf, uint32_t n);
+ bool sdcWrite(SDCDriver *sdcp, uint32_t startblk,
+ const uint8_t *buf, uint32_t n);
+ sdcflags_t sdcGetAndClearErrors(SDCDriver *sdcp);
+ bool sdcSync(SDCDriver *sdcp);
+ bool sdcGetInfo(SDCDriver *sdcp, BlockDeviceInfo *bdip);
+ bool sdcErase(SDCDriver *sdcp, uint32_t startblk, uint32_t endblk);
+ bool _sdc_wait_for_transfer_state(SDCDriver *sdcp);
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* HAL_USE_SDC == TRUE */
+
+#endif /* HAL_SDC_H */
+
+/** @} */
diff --git a/ChibiOS_20.3.2/os/hal/include/hal_serial.h b/ChibiOS_20.3.2/os/hal/include/hal_serial.h new file mode 100644 index 0000000..d4309c2 --- /dev/null +++ b/ChibiOS_20.3.2/os/hal/include/hal_serial.h @@ -0,0 +1,312 @@ +/*
+ ChibiOS - Copyright (C) 2006..2018 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_serial.h
+ * @brief Serial Driver macros and structures.
+ *
+ * @addtogroup SERIAL
+ * @{
+ */
+
+#ifndef HAL_SERIAL_H
+#define HAL_SERIAL_H
+
+#if (HAL_USE_SERIAL == TRUE) || defined(__DOXYGEN__)
+
+/*===========================================================================*/
+/* Driver constants. */
+/*===========================================================================*/
+
+/**
+ * @name Serial status flags
+ * @{
+ */
+#define SD_PARITY_ERROR (eventflags_t)32 /**< @brief Parity. */
+#define SD_FRAMING_ERROR (eventflags_t)64 /**< @brief Framing. */
+#define SD_OVERRUN_ERROR (eventflags_t)128 /**< @brief Overflow. */
+#define SD_NOISE_ERROR (eventflags_t)256 /**< @brief Line noise. */
+#define SD_BREAK_DETECTED (eventflags_t)512 /**< @brief LIN Break. */
+#define SD_QUEUE_FULL_ERROR (eventflags_t)1024 /**< @brief Queue full. */
+/** @} */
+
+/*===========================================================================*/
+/* Driver pre-compile time settings. */
+/*===========================================================================*/
+
+/**
+ * @name Serial configuration options
+ * @{
+ */
+/**
+ * @brief Default bit rate.
+ * @details Configuration parameter, this is the baud rate selected for the
+ * default configuration.
+ */
+#if !defined(SERIAL_DEFAULT_BITRATE) || defined(__DOXYGEN__)
+#define SERIAL_DEFAULT_BITRATE 38400
+#endif
+
+/**
+ * @brief Serial buffers size.
+ * @details Configuration parameter, you can change the depth of the queue
+ * buffers depending on the requirements of your application.
+ * @note The default is 16 bytes for both the transmission and receive
+ * buffers.
+ * @note This is a global setting and it can be overridden by low level
+ * driver specific settings.
+ */
+#if !defined(SERIAL_BUFFERS_SIZE) || defined(__DOXYGEN__)
+#define SERIAL_BUFFERS_SIZE 16
+#endif
+/** @} */
+
+/*===========================================================================*/
+/* Derived constants and error checks. */
+/*===========================================================================*/
+
+/*===========================================================================*/
+/* Driver data structures and types. */
+/*===========================================================================*/
+
+/**
+ * @brief Driver state machine possible states.
+ */
+typedef enum {
+ SD_UNINIT = 0, /**< Not initialized. */
+ SD_STOP = 1, /**< Stopped. */
+ SD_READY = 2 /**< Ready. */
+} sdstate_t;
+
+/**
+ * @brief Structure representing a serial driver.
+ */
+typedef struct SerialDriver SerialDriver;
+
+#include "hal_serial_lld.h"
+
+/**
+ * @brief @p SerialDriver specific methods.
+ */
+#define _serial_driver_methods \
+ _base_asynchronous_channel_methods
+
+/**
+ * @extends BaseAsynchronousChannelVMT
+ *
+ * @brief @p SerialDriver virtual methods table.
+ */
+struct SerialDriverVMT {
+ _serial_driver_methods
+};
+
+/**
+ * @extends BaseAsynchronousChannel
+ *
+ * @brief Full duplex serial driver class.
+ * @details This class extends @p BaseAsynchronousChannel by adding physical
+ * I/O queues.
+ */
+struct SerialDriver {
+ /** @brief Virtual Methods Table.*/
+ const struct SerialDriverVMT *vmt;
+ _serial_driver_data
+};
+
+/*===========================================================================*/
+/* Driver macros. */
+/*===========================================================================*/
+
+/**
+ * @name Macro Functions
+ * @{
+ */
+/**
+ * @brief Direct write to a @p SerialDriver.
+ * @note This function bypasses the indirect access to the channel and
+ * writes directly on the output queue. This is faster but cannot
+ * be used to write to different channels implementations.
+ *
+ * @iclass
+ */
+#define sdPutI(sdp, b) oqPutI(&(sdp)->oqueue, b)
+
+/**
+ * @brief Direct write to a @p SerialDriver.
+ * @note This function bypasses the indirect access to the channel and
+ * writes directly on the output queue. This is faster but cannot
+ * be used to write to different channels implementations.
+ *
+ * @api
+ */
+#define sdPut(sdp, b) oqPut(&(sdp)->oqueue, b)
+
+/**
+ * @brief Direct write to a @p SerialDriver with timeout specification.
+ * @note This function bypasses the indirect access to the channel and
+ * writes directly on the output queue. This is faster but cannot
+ * be used to write to different channels implementations.
+ *
+ * @api
+ */
+#define sdPutTimeout(sdp, b, t) oqPutTimeout(&(sdp)->oqueue, b, t)
+
+/**
+ * @brief Direct read from a @p SerialDriver.
+ * @note This function bypasses the indirect access to the channel and
+ * reads directly from the input queue. This is faster but cannot
+ * be used to read from different channels implementations.
+ *
+ * @iclass
+ */
+#define sdGetI(sdp) iqGetI(&(sdp)->iqueue)
+
+/**
+ * @brief Direct read from a @p SerialDriver.
+ * @note This function bypasses the indirect access to the channel and
+ * reads directly from the input queue. This is faster but cannot
+ * be used to read from different channels implementations.
+ *
+ * @api
+ */
+#define sdGet(sdp) iqGet(&(sdp)->iqueue)
+
+/**
+ * @brief Direct read from a @p SerialDriver with timeout specification.
+ * @note This function bypasses the indirect access to the channel and
+ * reads directly from the input queue. This is faster but cannot
+ * be used to read from different channels implementations.
+ *
+ * @api
+ */
+#define sdGetTimeout(sdp, t) iqGetTimeout(&(sdp)->iqueue, t)
+
+/**
+ * @brief Direct blocking write to a @p SerialDriver.
+ * @note This function bypasses the indirect access to the channel and
+ * writes directly to the output queue. This is faster but cannot
+ * be used to write from different channels implementations.
+ *
+ * @iclass
+ */
+#define sdWriteI(sdp, b, n) oqWriteI(&(sdp)->oqueue, b, n)
+
+/**
+ * @brief Direct blocking write to a @p SerialDriver.
+ * @note This function bypasses the indirect access to the channel and
+ * writes directly to the output queue. This is faster but cannot
+ * be used to write from different channels implementations.
+ *
+ * @api
+ */
+#define sdWrite(sdp, b, n) oqWriteTimeout(&(sdp)->oqueue, b, n, TIME_INFINITE)
+
+/**
+ * @brief Direct blocking write to a @p SerialDriver with timeout
+ * specification.
+ * @note This function bypasses the indirect access to the channel and
+ * writes directly to the output queue. This is faster but cannot
+ * be used to write to different channels implementations.
+ *
+ * @api
+ */
+#define sdWriteTimeout(sdp, b, n, t) \
+ oqWriteTimeout(&(sdp)->oqueue, b, n, t)
+
+/**
+ * @brief Direct non-blocking write to a @p SerialDriver.
+ * @note This function bypasses the indirect access to the channel and
+ * writes directly to the output queue. This is faster but cannot
+ * be used to write to different channels implementations.
+ *
+ * @api
+ */
+#define sdAsynchronousWrite(sdp, b, n) \
+ oqWriteTimeout(&(sdp)->oqueue, b, n, TIME_IMMEDIATE)
+
+/**
+ * @brief Direct blocking read from a @p SerialDriver.
+ * @note This function bypasses the indirect access to the channel and
+ * reads directly from the input queue. This is faster but cannot
+ * be used to read from different channels implementations.
+ *
+ * @iclass
+ */
+#define sdReadI(sdp, b, n) iqReadI(&(sdp)->iqueue, b, n, TIME_INFINITE)
+
+/**
+ * @brief Direct blocking read from a @p SerialDriver.
+ * @note This function bypasses the indirect access to the channel and
+ * reads directly from the input queue. This is faster but cannot
+ * be used to read from different channels implementations.
+ *
+ * @api
+ */
+#define sdRead(sdp, b, n) iqReadTimeout(&(sdp)->iqueue, b, n, TIME_INFINITE)
+
+/**
+ * @brief Direct blocking read from a @p SerialDriver with timeout
+ * specification.
+ * @note This function bypasses the indirect access to the channel and
+ * reads directly from the input queue. This is faster but cannot
+ * be used to read from different channels implementations.
+ *
+ * @api
+ */
+#define sdReadTimeout(sdp, b, n, t) iqReadTimeout(&(sdp)->iqueue, b, n, t)
+
+/**
+ * @brief Direct non-blocking read from a @p SerialDriver.
+ * @note This function bypasses the indirect access to the channel and
+ * reads directly from the input queue. This is faster but cannot
+ * be used to read from different channels implementations.
+ *
+ * @api
+ */
+#define sdAsynchronousRead(sdp, b, n) \
+ iqReadTimeout(&(sdp)->iqueue, b, n, TIME_IMMEDIATE)
+/** @} */
+
+/*===========================================================================*/
+/* External declarations. */
+/*===========================================================================*/
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+ void sdInit(void);
+#if !defined(SERIAL_ADVANCED_BUFFERING_SUPPORT) || \
+ (SERIAL_ADVANCED_BUFFERING_SUPPORT == FALSE)
+ void sdObjectInit(SerialDriver *sdp, qnotify_t inotify, qnotify_t onotify);
+#else
+ void sdObjectInit(SerialDriver *sdp);
+#endif
+ void sdStart(SerialDriver *sdp, const SerialConfig *config);
+ void sdStop(SerialDriver *sdp);
+ void sdIncomingDataI(SerialDriver *sdp, uint8_t b);
+ msg_t sdRequestDataI(SerialDriver *sdp);
+ bool sdPutWouldBlock(SerialDriver *sdp);
+ bool sdGetWouldBlock(SerialDriver *sdp);
+ msg_t sdControl(SerialDriver *sdp, unsigned int operation, void *arg);
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* HAL_USE_SERIAL == TRUE */
+
+#endif /* HAL_SERIAL_H */
+
+/** @} */
diff --git a/ChibiOS_20.3.2/os/hal/include/hal_serial_usb.h b/ChibiOS_20.3.2/os/hal/include/hal_serial_usb.h new file mode 100644 index 0000000..0e32429 --- /dev/null +++ b/ChibiOS_20.3.2/os/hal/include/hal_serial_usb.h @@ -0,0 +1,197 @@ +/*
+ ChibiOS - Copyright (C) 2006..2018 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_serial_usb.h
+ * @brief Serial over USB Driver macros and structures.
+ *
+ * @addtogroup SERIAL_USB
+ * @{
+ */
+
+#ifndef HAL_SERIAL_USB_H
+#define HAL_SERIAL_USB_H
+
+#if (HAL_USE_SERIAL_USB == TRUE) || defined(__DOXYGEN__)
+
+#include "hal_usb_cdc.h"
+
+/*===========================================================================*/
+/* Driver constants. */
+/*===========================================================================*/
+
+/*===========================================================================*/
+/* Driver pre-compile time settings. */
+/*===========================================================================*/
+
+/**
+ * @name SERIAL_USB configuration options
+ * @{
+ */
+/**
+ * @brief Serial over USB buffers size.
+ * @details Configuration parameter, the buffer size must be a multiple of
+ * the USB data endpoint maximum packet size.
+ * @note The default is 256 bytes for both the transmission and receive
+ * buffers.
+ */
+#if !defined(SERIAL_USB_BUFFERS_SIZE) || defined(__DOXYGEN__)
+#define SERIAL_USB_BUFFERS_SIZE 256
+#endif
+
+/**
+ * @brief Serial over USB number of buffers.
+ * @note The default is 2 buffers.
+ */
+#if !defined(SERIAL_USB_BUFFERS_NUMBER) || defined(__DOXYGEN__)
+#define SERIAL_USB_BUFFERS_NUMBER 2
+#endif
+/** @} */
+
+/*===========================================================================*/
+/* Derived constants and error checks. */
+/*===========================================================================*/
+
+#if HAL_USE_USB == FALSE
+#error "Serial over USB Driver requires HAL_USE_USB"
+#endif
+
+/*===========================================================================*/
+/* Driver data structures and types. */
+/*===========================================================================*/
+
+/**
+ * @brief Driver state machine possible states.
+ */
+typedef enum {
+ SDU_UNINIT = 0, /**< Not initialized. */
+ SDU_STOP = 1, /**< Stopped. */
+ SDU_READY = 2 /**< Ready. */
+} sdustate_t;
+
+/**
+ * @brief Structure representing a serial over USB driver.
+ */
+typedef struct SerialUSBDriver SerialUSBDriver;
+
+/**
+ * @brief Serial over USB Driver configuration structure.
+ * @details An instance of this structure must be passed to @p sduStart()
+ * in order to configure and start the driver operations.
+ */
+typedef struct {
+ /**
+ * @brief USB driver to use.
+ */
+ USBDriver *usbp;
+ /**
+ * @brief Bulk IN endpoint used for outgoing data transfer.
+ */
+ usbep_t bulk_in;
+ /**
+ * @brief Bulk OUT endpoint used for incoming data transfer.
+ */
+ usbep_t bulk_out;
+ /**
+ * @brief Interrupt IN endpoint used for notifications.
+ * @note If set to zero then the INT endpoint is assumed to be not
+ * present, USB descriptors must be changed accordingly.
+ */
+ usbep_t int_in;
+} SerialUSBConfig;
+
+/**
+ * @brief @p SerialDriver specific data.
+ */
+#define _serial_usb_driver_data \
+ _base_asynchronous_channel_data \
+ /* Driver state.*/ \
+ sdustate_t state; \
+ /* Input buffers queue.*/ \
+ input_buffers_queue_t ibqueue; \
+ /* Output queue.*/ \
+ output_buffers_queue_t obqueue; \
+ /* Input buffer.*/ \
+ uint8_t ib[BQ_BUFFER_SIZE(SERIAL_USB_BUFFERS_NUMBER, \
+ SERIAL_USB_BUFFERS_SIZE)]; \
+ /* Output buffer.*/ \
+ uint8_t ob[BQ_BUFFER_SIZE(SERIAL_USB_BUFFERS_NUMBER, \
+ SERIAL_USB_BUFFERS_SIZE)]; \
+ /* End of the mandatory fields.*/ \
+ /* Current configuration data.*/ \
+ const SerialUSBConfig *config;
+
+/**
+ * @brief @p SerialUSBDriver specific methods.
+ */
+#define _serial_usb_driver_methods \
+ _base_asynchronous_channel_methods
+
+/**
+ * @extends BaseAsynchronousChannelVMT
+ *
+ * @brief @p SerialDriver virtual methods table.
+ */
+struct SerialUSBDriverVMT {
+ _serial_usb_driver_methods
+};
+
+/**
+ * @extends BaseAsynchronousChannel
+ *
+ * @brief Full duplex serial driver class.
+ * @details This class extends @p BaseAsynchronousChannel by adding physical
+ * I/O queues.
+ */
+struct SerialUSBDriver {
+ /** @brief Virtual Methods Table.*/
+ const struct SerialUSBDriverVMT *vmt;
+ _serial_usb_driver_data
+};
+
+/*===========================================================================*/
+/* Driver macros. */
+/*===========================================================================*/
+
+/*===========================================================================*/
+/* External declarations. */
+/*===========================================================================*/
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+ void sduInit(void);
+ void sduObjectInit(SerialUSBDriver *sdup);
+ void sduStart(SerialUSBDriver *sdup, const SerialUSBConfig *config);
+ void sduStop(SerialUSBDriver *sdup);
+ void sduSuspendHookI(SerialUSBDriver *sdup);
+ void sduWakeupHookI(SerialUSBDriver *sdup);
+ void sduConfigureHookI(SerialUSBDriver *sdup);
+ bool sduRequestsHook(USBDriver *usbp);
+ void sduSOFHookI(SerialUSBDriver *sdup);
+ void sduDataTransmitted(USBDriver *usbp, usbep_t ep);
+ void sduDataReceived(USBDriver *usbp, usbep_t ep);
+ void sduInterruptTransmitted(USBDriver *usbp, usbep_t ep);
+ msg_t sduControl(USBDriver *usbp, unsigned int operation, void *arg);
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* HAL_USE_SERIAL_USB == TRUE */
+
+#endif /* HAL_SERIAL_USB_H */
+
+/** @} */
diff --git a/ChibiOS_20.3.2/os/hal/include/hal_sio.h b/ChibiOS_20.3.2/os/hal/include/hal_sio.h new file mode 100644 index 0000000..e10efee --- /dev/null +++ b/ChibiOS_20.3.2/os/hal/include/hal_sio.h @@ -0,0 +1,208 @@ +/*
+ ChibiOS - Copyright (C) 2006..2018 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_sio.h
+ * @brief SIO Driver macros and structures.
+ *
+ * @addtogroup SIO
+ * @{
+ */
+
+#ifndef HAL_SIO_H
+#define HAL_SIO_H
+
+#if (HAL_USE_SIO == TRUE) || defined(__DOXYGEN__)
+
+/*===========================================================================*/
+/* Driver constants. */
+/*===========================================================================*/
+
+/**
+ * @name SIO status flags
+ * @{
+ */
+#define SIO_NO_ERROR 0 /**< @brief No pending conditions. */
+#define SIO_PARITY_ERROR 4 /**< @brief Parity error happened. */
+#define SIO_FRAMING_ERROR 8 /**< @brief Framing error happened. */
+#define SIO_OVERRUN_ERROR 16 /**< @brief Overflow happened. */
+#define SIO_NOISE_ERROR 32 /**< @brief Noise on the line. */
+#define SIO_BREAK_DETECTED 64 /**< @brief Break detected. */
+/** @} */
+
+/*===========================================================================*/
+/* Driver pre-compile time settings. */
+/*===========================================================================*/
+
+/**
+ * @name SIO configuration options
+ * @{
+ */
+
+/** @} */
+
+/*===========================================================================*/
+/* Derived constants and error checks. */
+/*===========================================================================*/
+
+/*===========================================================================*/
+/* Driver data structures and types. */
+/*===========================================================================*/
+
+/**
+ * @brief Type of structure representing a SIO driver.
+ */
+typedef struct hal_sio_driver SIODriver;
+
+/**
+ * @brief Type of structure representing a SIO configuration.
+ */
+typedef struct hal_sio_config SIOConfig;
+
+/**
+ * @brief Driver state machine possible states.
+ */
+typedef enum {
+ SIO_UNINIT = 0, /**< Not initialized. */
+ SIO_STOP = 1, /**< Stopped. */
+ SIO_READY = 2 /**< Ready. */
+} siostate_t;
+
+#include "hal_sio_lld.h"
+
+/*===========================================================================*/
+/* Driver macros. */
+/*===========================================================================*/
+
+/**
+ * @brief Returns the current set of flags and clears it.
+ */
+#define sioGetFlagsX(siop) sio_lld_get_flags(siop)
+
+/**
+ * @brief Determines the state of the RX FIFO.
+ *
+ * @param[in] siop pointer to the @p SIODriver object
+ * @return The RX FIFO state.
+ * @retval false if RX FIFO is not empty
+ * @retval true if RX FIFO is empty
+ *
+ * @xclass
+ */
+#define sioRXIsEmptyX(siop) sio_lld_rx_is_empty(siop)
+
+/**
+ * @brief Determines the state of the TX FIFO.
+ *
+ * @param[in] siop pointer to the @p SIODriver object
+ * @return The TX FIFO state.
+ * @retval false if TX FIFO is not full
+ * @retval true if TX FIFO is full
+ *
+ * @xclass
+ */
+#define sioTXIsFullX(siop) sio_lld_tx_is_full(siop)
+
+/**
+ * @brief Returns one frame from the RX FIFO.
+ * @note If the FIFO is empty then the returned value is unpredictable.
+ *
+ * @param[in] siop pointer to the @p SIODriver object
+ * @return The frame from RX FIFO.
+ *
+ * @xclass
+ */
+#define sioRXGetX(siop) sio_lld_rx_get(siop)
+
+/**
+ * @brief Pushes one frame into the TX FIFO.
+ * @note If the FIFO is full then the behavior is unpredictable.
+ *
+ * @param[in] siop pointer to the @p SIODriver object
+ * @param[in] data frame to be written
+ *
+ * @xclass
+ */
+#define sioTXPutX(siop, data) sio_lld_tx_put(siop, data)
+
+/**
+ * @brief Reads data from the RX FIFO.
+ * @details This function is non-blocking, data is read if present and the
+ * effective amount is returned.
+ * @note This function can be called from any context but it is meant to
+ * be called from the @p rxne_cb callback handler.
+ *
+ * @param[in] siop pointer to the @p SIODriver object
+ * @param[in] buffer buffer for the received data
+ * @param[in] size maximum number of frames to read
+ * @return The number of received frames.
+ *
+ * @xclass
+ */
+#define sioReadX(siop, buffer, size) sio_lld_read(siop, buffer, size)
+
+/**
+ * @brief Writes data into the TX FIFO.
+ * @details This function is non-blocking, data is written if there is space
+ * in the FIFO and the effective amount is returned.
+ * @note This function can be called from any context but it is meant to
+ * be called from the @p txnf_cb callback handler.
+ *
+ * @param[in] siop pointer to the @p SIODriver object
+ * @param[out] buffer buffer containing the data to be transmitted
+ * @param[in] size maximum number of frames to read
+ * @return The number of transmitted frames.
+ *
+ * @xclass
+ */
+#define sioWriteX(siop, buffer, size) sio_lld_write(siop, buffer, size)
+
+/**
+ * @brief Control operation on a serial port.
+ *
+ * @param[in] siop pointer to the @p SIODriver object
+ * @param[in] operation control operation code
+ * @param[in,out] arg operation argument
+ *
+ * @return The control operation status.
+ * @retval MSG_OK in case of success.
+ * @retval MSG_TIMEOUT in case of operation timeout.
+ * @retval MSG_RESET in case of operation reset.
+ *
+ * @xclass
+ */
+#define sioControlX(siop, operation, arg) sio_lld_control(siop, operation, arg)
+
+/*===========================================================================*/
+/* External declarations. */
+/*===========================================================================*/
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+ void sioInit(void);
+ void sioObjectInit(SIODriver *siop);
+ void sioStart(SIODriver *siop, const SIOConfig *config);
+ void sioStop(SIODriver *siop);
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* HAL_USE_SIO == TRUE */
+
+#endif /* HAL_SIO_H */
+
+/** @} */
diff --git a/ChibiOS_20.3.2/os/hal/include/hal_spi.h b/ChibiOS_20.3.2/os/hal/include/hal_spi.h new file mode 100644 index 0000000..35b42c9 --- /dev/null +++ b/ChibiOS_20.3.2/os/hal/include/hal_spi.h @@ -0,0 +1,532 @@ +/*
+ ChibiOS - Copyright (C) 2006..2018 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 SPI Driver macros and structures.
+ *
+ * @addtogroup SPI
+ * @{
+ */
+
+#ifndef HAL_SPI_H
+#define HAL_SPI_H
+
+#if (HAL_USE_SPI == TRUE) || defined(__DOXYGEN__)
+
+/*===========================================================================*/
+/* Driver constants. */
+/*===========================================================================*/
+
+/**
+ * @name Chip Select modes
+ * @{
+ */
+#define SPI_SELECT_MODE_NONE 0 /** @brief @p spiSelect() and
+ @p spiUnselect() do
+ nothing. */
+#define SPI_SELECT_MODE_PAD 1 /** @brief Legacy mode. */
+#define SPI_SELECT_MODE_PORT 2 /** @brief Fastest mode. */
+#define SPI_SELECT_MODE_LINE 3 /** @brief Packed mode. */
+#define SPI_SELECT_MODE_LLD 4 /** @brief LLD-defined mode.*/
+/** @} */
+
+/*===========================================================================*/
+/* Driver pre-compile time settings. */
+/*===========================================================================*/
+
+/**
+ * @name SPI configuration options
+ * @{
+ */
+/**
+ * @brief Enables synchronous APIs.
+ * @note Disabling this option saves both code and data space.
+ */
+#if !defined(SPI_USE_WAIT) || defined(__DOXYGEN__)
+#define SPI_USE_WAIT TRUE
+#endif
+
+/**
+ * @brief Enables circular transfers APIs.
+ * @note Disabling this option saves both code and data space.
+ */
+#if !defined(SPI_USE_CIRCULAR) || defined(__DOXYGEN__)
+#define SPI_USE_CIRCULAR FALSE
+#endif
+
+/**
+ * @brief Enables the @p spiAcquireBus() and @p spiReleaseBus() APIs.
+ * @note Disabling this option saves both code and data space.
+ */
+#if !defined(SPI_USE_MUTUAL_EXCLUSION) || defined(__DOXYGEN__)
+#define SPI_USE_MUTUAL_EXCLUSION TRUE
+#endif
+
+/**
+ * @brief Handling method for SPI CS line.
+ * @note Disabling this option saves both code and data space.
+ */
+#if !defined(SPI_SELECT_MODE) || defined(__DOXYGEN__)
+#define SPI_SELECT_MODE SPI_SELECT_MODE_PAD
+#endif
+/** @} */
+
+/*===========================================================================*/
+/* Derived constants and error checks. */
+/*===========================================================================*/
+
+#if (SPI_SELECT_MODE != SPI_SELECT_MODE_NONE) && \
+ (SPI_SELECT_MODE != SPI_SELECT_MODE_PAD) && \
+ (SPI_SELECT_MODE != SPI_SELECT_MODE_PORT) && \
+ (SPI_SELECT_MODE != SPI_SELECT_MODE_LINE) && \
+ (SPI_SELECT_MODE != SPI_SELECT_MODE_LLD)
+#error "invalid SPI_SELECT_MODE setting"
+#endif
+
+/* Some modes have a dependency on the PAL driver, making the required
+ checks here.*/
+#if ((SPI_SELECT_MODE != SPI_SELECT_MODE_PAD) || \
+ (SPI_SELECT_MODE != SPI_SELECT_MODE_PORT) || \
+ (SPI_SELECT_MODE != SPI_SELECT_MODE_LINE)) && \
+ (HAL_USE_PAL != TRUE)
+#error "current SPI_SELECT_MODE requires HAL_USE_PAL"
+#endif
+
+/*===========================================================================*/
+/* Driver data structures and types. */
+/*===========================================================================*/
+
+/**
+ * @brief Driver state machine possible states.
+ */
+typedef enum {
+ SPI_UNINIT = 0, /**< Not initialized. */
+ SPI_STOP = 1, /**< Stopped. */
+ SPI_READY = 2, /**< Ready. */
+ SPI_ACTIVE = 3, /**< Exchanging data. */
+ SPI_COMPLETE = 4 /**< Asynchronous operation complete. */
+} spistate_t;
+
+/**
+ * @brief Type of a structure representing an SPI driver.
+ */
+typedef struct hal_spi_driver SPIDriver;
+/**
+ * @brief Type of a SPI driver configuration structure.
+ */
+typedef struct hal_spi_config SPIConfig;
+
+/**
+ * @brief SPI notification callback type.
+ *
+ * @param[in] spip pointer to the @p SPIDriver object triggering the
+ * callback
+ */
+typedef void (*spicallback_t)(SPIDriver *spip);
+
+/* Including the low level driver header, it exports information required
+ for completing types.*/
+#include "hal_spi_lld.h"
+
+/**
+ * @brief Driver configuration structure.
+ */
+struct hal_spi_config {
+#if (SPI_SUPPORTS_CIRCULAR == TRUE) || defined(__DOXYGEN__)
+ /**
+ * @brief Enables the circular buffer mode.
+ */
+ bool circular;
+#endif
+ /**
+ * @brief Operation complete callback or @p NULL.
+ */
+ spicallback_t end_cb;
+#if (SPI_SELECT_MODE == SPI_SELECT_MODE_LINE) || defined(__DOXYGEN__)
+ /**
+ * @brief The chip select line.
+ */
+ ioline_t ssline;
+#endif
+#if (SPI_SELECT_MODE == SPI_SELECT_MODE_PORT) || defined(__DOXYGEN__)
+ /**
+ * @brief The chip select port.
+ */
+ ioportid_t ssport;
+ /**
+ * @brief The chip select port mask.
+ */
+ ioportmask_t ssmask;
+#endif
+#if (SPI_SELECT_MODE == SPI_SELECT_MODE_PAD) || defined(__DOXYGEN__)
+ /**
+ * @brief The chip select port.
+ */
+ ioportid_t ssport;
+ /**
+ * @brief The chip select pad number.
+ */
+ uint_fast8_t sspad;
+#endif
+ /* End of the mandatory fields.*/
+ spi_lld_config_fields;
+};
+
+/**
+ * @brief Structure representing an SPI driver.
+ */
+struct hal_spi_driver {
+ /**
+ * @brief Driver state.
+ */
+ spistate_t state;
+ /**
+ * @brief Current configuration data.
+ */
+ const SPIConfig *config;
+#if (SPI_USE_WAIT == TRUE) || defined(__DOXYGEN__)
+ /**
+ * @brief Waiting thread.
+ */
+ thread_reference_t thread;
+#endif /* SPI_USE_WAIT == TRUE */
+#if (SPI_USE_MUTUAL_EXCLUSION == TRUE) || defined(__DOXYGEN__)
+ /**
+ * @brief Mutex protecting the peripheral.
+ */
+ mutex_t mutex;
+#endif /* SPI_USE_MUTUAL_EXCLUSION == TRUE */
+#if defined(SPI_DRIVER_EXT_FIELDS)
+ SPI_DRIVER_EXT_FIELDS
+#endif
+ /* End of the mandatory fields.*/
+ spi_lld_driver_fields;
+};
+
+/*===========================================================================*/
+/* Driver macros. */
+/*===========================================================================*/
+
+/**
+ * @name Macro Functions
+ * @{
+ */
+/**
+ * @brief Buffer state.
+ * @note This function is meant to be called from the SPI callback only.
+ *
+ * @param[in] spip pointer to the @p SPIDriver object
+ * @return The buffer state.
+ * @retval false if the driver filled/sent the first half of the
+ * buffer.
+ * @retval true if the driver filled/sent the second half of the
+ * buffer.
+ *
+ * @special
+ */
+#define spiIsBufferComplete(spip) ((bool)((spip)->state == SPI_COMPLETE))
+
+#if (SPI_SELECT_MODE == SPI_SELECT_MODE_LLD) || defined(__DOXYGEN__)
+/**
+ * @brief Asserts the slave select signal and prepares for transfers.
+ *
+ * @param[in] spip pointer to the @p SPIDriver object
+ *
+ * @iclass
+ */
+#define spiSelectI(spip) \
+do { \
+ spi_lld_select(spip); \
+} while (false)
+
+/**
+ * @brief Deasserts the slave select signal.
+ * @details The previously selected peripheral is unselected.
+ *
+ * @param[in] spip pointer to the @p SPIDriver object
+ *
+ * @iclass
+ */
+#define spiUnselectI(spip) \
+do { \
+ spi_lld_unselect(spip); \
+} while (false)
+
+#elif SPI_SELECT_MODE == SPI_SELECT_MODE_LINE
+#define spiSelectI(spip) \
+do { \
+ palClearLine((spip)->config->ssline); \
+} while (false)
+
+#define spiUnselectI(spip) \
+do { \
+ palSetLine((spip)->config->ssline); \
+} while (false)
+
+#elif SPI_SELECT_MODE == SPI_SELECT_MODE_PORT
+#define spiSelectI(spip) \
+do { \
+ palClearPort((spip)->config->ssport, (spip)->config->ssmask); \
+} while (false)
+
+#define spiUnselectI(spip) \
+do { \
+ palSetPort((spip)->config->ssport, (spip)->config->ssmask); \
+} while (false)
+
+#elif SPI_SELECT_MODE == SPI_SELECT_MODE_PAD
+#define spiSelectI(spip) \
+do { \
+ palClearPad((spip)->config->ssport, (spip)->config->sspad); \
+} while (false)
+
+#define spiUnselectI(spip) \
+do { \
+ palSetPad((spip)->config->ssport, (spip)->config->sspad); \
+} while (false)
+
+#elif SPI_SELECT_MODE == SPI_SELECT_MODE_NONE
+#define spiSelectI(spip)
+
+#define spiUnselectI(spip)
+#endif
+
+/**
+ * @brief Ignores data on the SPI bus.
+ * @details This asynchronous function starts the transmission of a series of
+ * idle words on the SPI bus and ignores the received data.
+ * @pre A slave must have been selected using @p spiSelect() or
+ * @p spiSelectI().
+ * @post At the end of the operation the configured callback is invoked.
+ *
+ * @param[in] spip pointer to the @p SPIDriver object
+ * @param[in] n number of words to be ignored
+ *
+ * @iclass
+ */
+#define spiStartIgnoreI(spip, n) { \
+ (spip)->state = SPI_ACTIVE; \
+ spi_lld_ignore(spip, n); \
+}
+
+/**
+ * @brief Exchanges data on the SPI bus.
+ * @details This asynchronous function starts a simultaneous transmit/receive
+ * operation.
+ * @pre A slave must have been selected using @p spiSelect() or
+ * @p spiSelectI().
+ * @post At the end of the operation the configured callback is invoked.
+ * @note The buffers are organized as uint8_t arrays for data sizes below
+ * or equal to 8 bits else it is organized as uint16_t arrays.
+ *
+ * @param[in] spip pointer to the @p SPIDriver object
+ * @param[in] n number of words to be exchanged
+ * @param[in] txbuf the pointer to the transmit buffer
+ * @param[out] rxbuf the pointer to the receive buffer
+ *
+ * @iclass
+ */
+#define spiStartExchangeI(spip, n, txbuf, rxbuf) { \
+ (spip)->state = SPI_ACTIVE; \
+ spi_lld_exchange(spip, n, txbuf, rxbuf); \
+}
+
+/**
+ * @brief Sends data over the SPI bus.
+ * @details This asynchronous function starts a transmit operation.
+ * @pre A slave must have been selected using @p spiSelect() or
+ * @p spiSelectI().
+ * @post At the end of the operation the configured callback is invoked.
+ * @note The buffers are organized as uint8_t arrays for data sizes below
+ * or equal to 8 bits else it is organized as uint16_t arrays.
+ *
+ * @param[in] spip pointer to the @p SPIDriver object
+ * @param[in] n number of words to send
+ * @param[in] txbuf the pointer to the transmit buffer
+ *
+ * @iclass
+ */
+#define spiStartSendI(spip, n, txbuf) { \
+ (spip)->state = SPI_ACTIVE; \
+ spi_lld_send(spip, n, txbuf); \
+}
+
+/**
+ * @brief Receives data from the SPI bus.
+ * @details This asynchronous function starts a receive operation.
+ * @pre A slave must have been selected using @p spiSelect() or
+ * @p spiSelectI().
+ * @post At the end of the operation the configured callback is invoked.
+ * @note The buffers are organized as uint8_t arrays for data sizes below
+ * or equal to 8 bits else it is organized as uint16_t arrays.
+ *
+ * @param[in] spip pointer to the @p SPIDriver object
+ * @param[in] n number of words to receive
+ * @param[out] rxbuf the pointer to the receive buffer
+ *
+ * @iclass
+ */
+#define spiStartReceiveI(spip, n, rxbuf) { \
+ (spip)->state = SPI_ACTIVE; \
+ spi_lld_receive(spip, n, rxbuf); \
+}
+
+/**
+ * @brief Exchanges one frame using a polled wait.
+ * @details This synchronous function exchanges one frame using a polled
+ * synchronization method. This function is useful when exchanging
+ * small amount of data on high speed channels, usually in this
+ * situation is much more efficient just wait for completion using
+ * polling than suspending the thread waiting for an interrupt.
+ * @note This API is implemented as a macro in order to minimize latency.
+ *
+ * @param[in] spip pointer to the @p SPIDriver object
+ * @param[in] frame the data frame to send over the SPI bus
+ * @return The received data frame from the SPI bus.
+ */
+#define spiPolledExchange(spip, frame) spi_lld_polled_exchange(spip, frame)
+/** @} */
+
+/**
+ * @name Low level driver helper macros
+ * @{
+ */
+#if (SPI_USE_WAIT == TRUE) || defined(__DOXYGEN__)
+/**
+ * @brief Wakes up the waiting thread.
+ *
+ * @param[in] spip pointer to the @p SPIDriver object
+ *
+ * @notapi
+ */
+#define _spi_wakeup_isr(spip) { \
+ osalSysLockFromISR(); \
+ osalThreadResumeI(&(spip)->thread, MSG_OK); \
+ osalSysUnlockFromISR(); \
+}
+#else /* !SPI_USE_WAIT */
+#define _spi_wakeup_isr(spip)
+#endif /* !SPI_USE_WAIT */
+
+/**
+ * @brief Common ISR code when circular mode is not supported.
+ * @details This code handles the portable part of the ISR code:
+ * - Callback invocation.
+ * - Waiting thread wakeup, if any.
+ * - Driver state transitions.
+ * .
+ * @note This macro is meant to be used in the low level drivers
+ * implementation only.
+ *
+ * @param[in] spip pointer to the @p SPIDriver object
+ *
+ * @notapi
+ */
+#define _spi_isr_code(spip) { \
+ if ((spip)->config->end_cb) { \
+ (spip)->state = SPI_COMPLETE; \
+ (spip)->config->end_cb(spip); \
+ if ((spip)->state == SPI_COMPLETE) \
+ (spip)->state = SPI_READY; \
+ } \
+ else \
+ (spip)->state = SPI_READY; \
+ _spi_wakeup_isr(spip); \
+}
+
+/**
+ * @brief Half buffer filled ISR code in circular mode.
+ * @details This code handles the portable part of the ISR code:
+ * - Callback invocation.
+ * .
+ * @note This macro is meant to be used in the low level drivers
+ * implementation only.
+ *
+ * @param[in] spip pointer to the @p SPIDriver object
+ *
+ * @notapi
+ */
+#define _spi_isr_half_code(spip) { \
+ if ((spip)->config->end_cb) { \
+ (spip)->config->end_cb(spip); \
+ } \
+}
+
+/**
+ * @brief Full buffer filled ISR code in circular mode.
+ * @details This code handles the portable part of the ISR code:
+ * - Callback invocation.
+ * - Driver state transitions.
+ * .
+ * @note This macro is meant to be used in the low level drivers
+ * implementation only.
+ *
+ * @param[in] spip pointer to the @p SPIDriver object
+ *
+ * @notapi
+ */
+#define _spi_isr_full_code(spip) { \
+ if ((spip)->config->end_cb) { \
+ (spip)->state = SPI_COMPLETE; \
+ (spip)->config->end_cb(spip); \
+ if ((spip)->state == SPI_COMPLETE) \
+ (spip)->state = SPI_ACTIVE; \
+ } \
+}
+/** @} */
+
+/*===========================================================================*/
+/* External declarations. */
+/*===========================================================================*/
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+ void spiInit(void);
+ void spiObjectInit(SPIDriver *spip);
+ void spiStart(SPIDriver *spip, const SPIConfig *config);
+ void spiStop(SPIDriver *spip);
+ void spiSelect(SPIDriver *spip);
+ void spiUnselect(SPIDriver *spip);
+ void spiStartIgnore(SPIDriver *spip, size_t n);
+ void spiStartExchange(SPIDriver *spip, size_t n,
+ const void *txbuf, void *rxbuf);
+ void spiStartSend(SPIDriver *spip, size_t n, const void *txbuf);
+ void spiStartReceive(SPIDriver *spip, size_t n, void *rxbuf);
+#if SPI_SUPPORTS_CIRCULAR == TRUE
+ void spiAbortI(SPIDriver *spip);
+ void spiAbort(SPIDriver *spip);
+#endif
+#if SPI_USE_WAIT == TRUE
+ void spiIgnore(SPIDriver *spip, size_t n);
+ void spiExchange(SPIDriver *spip, size_t n, const void *txbuf, void *rxbuf);
+ void spiSend(SPIDriver *spip, size_t n, const void *txbuf);
+ void spiReceive(SPIDriver *spip, size_t n, void *rxbuf);
+#endif
+#if SPI_USE_MUTUAL_EXCLUSION == TRUE
+ void spiAcquireBus(SPIDriver *spip);
+ void spiReleaseBus(SPIDriver *spip);
+#endif
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* HAL_USE_SPI == TRUE */
+
+#endif /* HAL_SPI_H */
+
+/** @} */
diff --git a/ChibiOS_20.3.2/os/hal/include/hal_st.h b/ChibiOS_20.3.2/os/hal/include/hal_st.h new file mode 100644 index 0000000..ef8d985 --- /dev/null +++ b/ChibiOS_20.3.2/os/hal/include/hal_st.h @@ -0,0 +1,90 @@ +/*
+ ChibiOS - Copyright (C) 2006..2018 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_st.h
+ * @brief ST Driver macros and structures.
+ * @details This header is designed to be include-able without having to
+ * include other files from the HAL.
+ *
+ * @addtogroup ST
+ * @{
+ */
+
+#ifndef HAL_ST_H
+#define HAL_ST_H
+
+#include "hal_st_lld.h"
+
+/*===========================================================================*/
+/* Driver constants. */
+/*===========================================================================*/
+
+/*===========================================================================*/
+/* Driver pre-compile time settings. */
+/*===========================================================================*/
+
+/*===========================================================================*/
+/* Derived constants and error checks. */
+/*===========================================================================*/
+
+/* Compatibility with old LLDS.*/
+#if !defined(ST_LLD_NUM_ALARMS)
+#define ST_LLD_NUM_ALARMS 1
+#endif
+
+/*===========================================================================*/
+/* Driver data structures and types. */
+/*===========================================================================*/
+
+typedef void (*st_callback_t)(unsigned alarm);
+
+/*===========================================================================*/
+/* Driver macros. */
+/*===========================================================================*/
+
+/*===========================================================================*/
+/* External declarations. */
+/*===========================================================================*/
+
+#if (ST_LLD_NUM_ALARMS > 1) && !defined(__DOXYGEN__)
+extern st_callback_t st_callbacks[ST_LLD_NUM_ALARMS - 1];
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+ void stInit(void);
+ void stStartAlarm(systime_t abstime);
+ void stStopAlarm(void);
+ void stSetAlarm(systime_t abstime);
+ systime_t stGetAlarm(void);
+ systime_t stGetCounter(void);
+ bool stIsAlarmActive(void);
+#if ST_LLD_NUM_ALARMS > 1
+ bool stIsAlarmActiveN(unsigned alarm);
+ void stStartAlarmN(unsigned alarm, systime_t abstime, st_callback_t cb);
+ void stStopAlarmN(unsigned alarm);
+ void stSetAlarmN(unsigned alarm, systime_t abstime);
+ systime_t stGetAlarmN(unsigned alarm);
+#endif
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* HAL_ST_H */
+
+/** @} */
diff --git a/ChibiOS_20.3.2/os/hal/include/hal_streams.h b/ChibiOS_20.3.2/os/hal/include/hal_streams.h new file mode 100644 index 0000000..bbdc653 --- /dev/null +++ b/ChibiOS_20.3.2/os/hal/include/hal_streams.h @@ -0,0 +1,156 @@ +/*
+ ChibiOS - Copyright (C) 2006..2018 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_streams.h
+ * @brief Data streams.
+ * @details This header defines abstract interfaces useful to access generic
+ * data streams in a standardized way.
+ *
+ * @addtogroup HAL_STREAMS
+ * @details This module define an abstract interface for generic data streams.
+ * Note that no code is present, just abstract interfaces-like
+ * structures, you should look at the system as to a set of
+ * abstract C++ classes (even if written in C). This system
+ * has then advantage to make the access to data streams
+ * independent from the implementation logic.<br>
+ * The stream interface can be used as base class for high level
+ * object types such as files, sockets, serial ports, pipes etc.
+ * @{
+ */
+
+#ifndef HAL_STREAMS_H
+#define HAL_STREAMS_H
+
+/**
+ * @name Streams return codes
+ * @{
+ */
+#define STM_OK MSG_OK
+#define STM_TIMEOUT MSG_TIMEOUT
+#define STM_RESET MSG_RESET
+/** @} */
+
+/**
+ * @brief BaseSequentialStream specific methods.
+ */
+#define _base_sequential_stream_methods \
+ _base_object_methods \
+ /* Stream write buffer method.*/ \
+ size_t (*write)(void *instance, const uint8_t *bp, size_t n); \
+ /* Stream read buffer method.*/ \
+ size_t (*read)(void *instance, uint8_t *bp, size_t n); \
+ /* Channel put method, blocking.*/ \
+ msg_t (*put)(void *instance, uint8_t b); \
+ /* Channel get method, blocking.*/ \
+ msg_t (*get)(void *instance); \
+
+/**
+ * @brief @p BaseSequentialStream specific data.
+ * @note It is empty because @p BaseSequentialStream is only an interface
+ * without implementation.
+ */
+#define _base_sequential_stream_data \
+ _base_object_data
+
+/**
+ * @brief @p BaseSequentialStream virtual methods table.
+ */
+struct BaseSequentialStreamVMT {
+ _base_sequential_stream_methods
+};
+
+/**
+ * @extends BaseObject
+ *
+ * @brief Base stream class.
+ * @details This class represents a generic blocking unbuffered sequential
+ * data stream.
+ */
+typedef struct {
+ /** @brief Virtual Methods Table.*/
+ const struct BaseSequentialStreamVMT *vmt;
+ _base_sequential_stream_data
+} BaseSequentialStream;
+
+/**
+ * @name Macro Functions (BaseSequentialStream)
+ * @{
+ */
+/**
+ * @brief Sequential Stream write.
+ * @details The function writes data from a buffer to a stream.
+ *
+ * @param[in] ip pointer to a @p BaseSequentialStream or derived class
+ * @param[in] bp pointer to the data buffer
+ * @param[in] n the maximum amount of data to be transferred
+ * @return The number of bytes transferred. The return value can
+ * be less than the specified number of bytes if an
+ * end-of-file condition has been met.
+ *
+ * @api
+ */
+#define streamWrite(ip, bp, n) ((ip)->vmt->write(ip, bp, n))
+
+/**
+ * @brief Sequential Stream read.
+ * @details The function reads data from a stream into a buffer.
+ *
+ * @param[in] ip pointer to a @p BaseSequentialStream or derived class
+ * @param[out] bp pointer to the data buffer
+ * @param[in] n the maximum amount of data to be transferred
+ * @return The number of bytes transferred. The return value can
+ * be less than the specified number of bytes if an
+ * end-of-file condition has been met.
+ *
+ * @api
+ */
+#define streamRead(ip, bp, n) ((ip)->vmt->read(ip, bp, n))
+
+/**
+ * @brief Sequential Stream blocking byte write.
+ * @details This function writes a byte value to a channel. If the channel
+ * is not ready to accept data then the calling thread is suspended.
+ *
+ * @param[in] ip pointer to a @p BaseChannel or derived class
+ * @param[in] b the byte value to be written to the channel
+ *
+ * @return The operation status.
+ * @retval STM_OK if the operation succeeded.
+ * @retval STM_RESET if an end-of-file condition has been met.
+ *
+ * @api
+ */
+#define streamPut(ip, b) ((ip)->vmt->put(ip, b))
+
+/**
+ * @brief Sequential Stream blocking byte read.
+ * @details This function reads a byte value from a channel. If the data
+ * is not available then the calling thread is suspended.
+ *
+ * @param[in] ip pointer to a @p BaseChannel or derived class
+ *
+ * @return A byte value from the queue.
+ * @retval STM_RESET if an end-of-file condition has been met.
+ *
+ * @api
+ */
+#define streamGet(ip) ((ip)->vmt->get(ip))
+/** @} */
+
+#endif /* HAL_STREAMS_H */
+
+/** @} */
diff --git a/ChibiOS_20.3.2/os/hal/include/hal_trng.h b/ChibiOS_20.3.2/os/hal/include/hal_trng.h new file mode 100644 index 0000000..0e3648a --- /dev/null +++ b/ChibiOS_20.3.2/os/hal/include/hal_trng.h @@ -0,0 +1,122 @@ +/*
+ ChibiOS - Copyright (C) 2006..2018 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_trng.h
+ * @brief TRNG Driver macros and structures.
+ *
+ * @addtogroup TRNG
+ * @{
+ */
+
+#ifndef HAL_TRNG_H
+#define HAL_TRNG_H
+
+#if (HAL_USE_TRNG == TRUE) || defined(__DOXYGEN__)
+
+/*===========================================================================*/
+/* Driver constants. */
+/*===========================================================================*/
+
+/*===========================================================================*/
+/* Driver pre-compile time settings. */
+/*===========================================================================*/
+
+/*===========================================================================*/
+/* Derived constants and error checks. */
+/*===========================================================================*/
+
+/*===========================================================================*/
+/* Driver data structures and types. */
+/*===========================================================================*/
+
+/**
+ * @brief Driver state machine possible states.
+ */
+typedef enum {
+ TRNG_UNINIT = 0, /**< Not initialized. */
+ TRNG_STOP = 1, /**< Stopped. */
+ TRNG_READY = 2, /**< Ready. */
+ TRNG_RUNNING = 3 /**< Generating random number. */
+} trngstate_t;
+
+/**
+ * @brief Type of a structure representing a TRNG driver.
+ */
+typedef struct hal_trng_driver TRNGDriver;
+
+/**
+ * @brief Driver configuration structure.
+ * @note It could be empty on some architectures.
+ */
+typedef struct hal_trng_config TRNGConfig;
+
+/* Including the low level driver header, it exports information required
+ for completing types.*/
+#include "hal_trng_lld.h"
+
+/**
+ * @brief Driver configuration structure.
+ */
+struct hal_trng_config {
+ /* End of the mandatory fields.*/
+ trng_lld_config_fields;
+};
+
+/**
+ * @brief Structure representing a TRNG driver.
+ */
+struct hal_trng_driver {
+ /**
+ * @brief Driver state.
+ */
+ trngstate_t state;
+ /**
+ * @brief Current configuration data.
+ */
+ const TRNGConfig *config;
+#if defined(TRNG_DRIVER_EXT_FIELDS)
+ TRNG_DRIVER_EXT_FIELDS
+#endif
+ /* End of the mandatory fields.*/
+ trng_lld_driver_fields;
+};
+
+/*===========================================================================*/
+/* Driver macros. */
+/*===========================================================================*/
+
+/*===========================================================================*/
+/* External declarations. */
+/*===========================================================================*/
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+ void trngInit(void);
+ void trngObjectInit(TRNGDriver *trngp);
+ void trngStart(TRNGDriver *trngp, const TRNGConfig *config);
+ void trngStop(TRNGDriver *trngp);
+ bool trngGenerate(TRNGDriver *trngp, size_t size, uint8_t *out);
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* HAL_USE_TRNG == TRUE */
+
+#endif /* HAL_TRNG_H */
+
+/** @} */
diff --git a/ChibiOS_20.3.2/os/hal/include/hal_uart.h b/ChibiOS_20.3.2/os/hal/include/hal_uart.h new file mode 100644 index 0000000..a074649 --- /dev/null +++ b/ChibiOS_20.3.2/os/hal/include/hal_uart.h @@ -0,0 +1,425 @@ +/*
+ ChibiOS - Copyright (C) 2006..2018 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_uart.h
+ * @brief UART Driver macros and structures.
+ *
+ * @addtogroup UART
+ * @{
+ */
+
+#ifndef HAL_UART_H
+#define HAL_UART_H
+
+#if (HAL_USE_UART == TRUE) || defined(__DOXYGEN__)
+
+/*===========================================================================*/
+/* Driver constants. */
+/*===========================================================================*/
+
+/**
+ * @name UART status flags
+ * @{
+ */
+#define UART_NO_ERROR 0 /**< @brief No pending conditions. */
+#define UART_PARITY_ERROR 4 /**< @brief Parity error happened. */
+#define UART_FRAMING_ERROR 8 /**< @brief Framing error happened. */
+#define UART_OVERRUN_ERROR 16 /**< @brief Overflow happened. */
+#define UART_NOISE_ERROR 32 /**< @brief Noise on the line. */
+#define UART_BREAK_DETECTED 64 /**< @brief Break detected. */
+/** @} */
+
+/**
+ * @name UART error conditions
+ * @{
+ */
+#define UART_ERR_NOT_ACTIVE (size_t)-1
+/** @} */
+
+/*===========================================================================*/
+/* Driver pre-compile time settings. */
+/*===========================================================================*/
+
+/**
+ * @name UART configuration options
+ * @{
+ */
+/**
+ * @brief Enables synchronous APIs.
+ * @note Disabling this option saves both code and data space.
+ */
+#if !defined(UART_USE_WAIT) || defined(__DOXYGEN__)
+#define UART_USE_WAIT FALSE
+#endif
+
+/**
+ * @brief Enables the @p uartAcquireBus() and @p uartReleaseBus() APIs.
+ * @note Disabling this option saves both code and data space.
+ */
+#if !defined(UART_USE_MUTUAL_EXCLUSION) || defined(__DOXYGEN__)
+#define UART_USE_MUTUAL_EXCLUSION FALSE
+#endif
+/** @} */
+
+/*===========================================================================*/
+/* Derived constants and error checks. */
+/*===========================================================================*/
+
+/*===========================================================================*/
+/* Driver data structures and types. */
+/*===========================================================================*/
+
+/**
+ * @brief Driver state machine possible states.
+ */
+typedef enum {
+ UART_UNINIT = 0, /**< Not initialized. */
+ UART_STOP = 1, /**< Stopped. */
+ UART_READY = 2 /**< Ready. */
+} uartstate_t;
+
+/**
+ * @brief Transmitter state machine states.
+ */
+typedef enum {
+ UART_TX_IDLE = 0, /**< Not transmitting. */
+ UART_TX_ACTIVE = 1, /**< Transmitting. */
+ UART_TX_COMPLETE = 2 /**< Buffer complete. */
+} uarttxstate_t;
+
+/**
+ * @brief Receiver state machine states.
+ */
+typedef enum {
+ UART_RX_IDLE = 0, /**< Not receiving. */
+ UART_RX_ACTIVE = 1, /**< Receiving. */
+ UART_RX_COMPLETE = 2 /**< Buffer complete. */
+} uartrxstate_t;
+
+#include "hal_uart_lld.h"
+
+/*===========================================================================*/
+/* Driver macros. */
+/*===========================================================================*/
+
+/**
+ * @name Low level driver helper macros
+ * @{
+ */
+#if (UART_USE_WAIT == TRUE) || defined(__DOXYGEN__)
+/**
+ * @brief Wakes up the waiting thread in case of early TX complete.
+ *
+ * @param[in] uartp pointer to the @p UARTDriver object
+ *
+ * @notapi
+ */
+#define _uart_wakeup_tx1_isr(uartp) { \
+ if ((uartp)->early == true) { \
+ osalSysLockFromISR(); \
+ osalThreadResumeI(&(uartp)->threadtx, MSG_OK); \
+ osalSysUnlockFromISR(); \
+ } \
+}
+#else /* !UART_USE_WAIT */
+#define _uart_wakeup_tx1_isr(uartp)
+#endif /* !UART_USE_WAIT */
+
+#if (UART_USE_WAIT == TRUE) || defined(__DOXYGEN__)
+/**
+ * @brief Wakes up the waiting thread in case of late TX complete.
+ *
+ * @param[in] uartp pointer to the @p UARTDriver object
+ *
+ * @notapi
+ */
+#define _uart_wakeup_tx2_isr(uartp) { \
+ if ((uartp)->early == false) { \
+ osalSysLockFromISR(); \
+ osalThreadResumeI(&(uartp)->threadtx, MSG_OK); \
+ osalSysUnlockFromISR(); \
+ } \
+}
+#else /* !UART_USE_WAIT */
+#define _uart_wakeup_tx2_isr(uartp)
+#endif /* !UART_USE_WAIT */
+
+#if (UART_USE_WAIT == TRUE) || defined(__DOXYGEN__)
+/**
+ * @brief Wakes up the waiting thread in case of RX complete.
+ *
+ * @param[in] uartp pointer to the @p UARTDriver object
+ *
+ * @notapi
+ */
+#define _uart_wakeup_rx_complete_isr(uartp) { \
+ osalSysLockFromISR(); \
+ osalThreadResumeI(&(uartp)->threadrx, MSG_OK); \
+ osalSysUnlockFromISR(); \
+}
+#else /* !UART_USE_WAIT */
+#define _uart_wakeup_rx_complete_isr(uartp)
+#endif /* !UART_USE_WAIT */
+
+#if (UART_USE_WAIT == TRUE) || defined(__DOXYGEN__)
+/**
+ * @brief Wakes up the waiting thread in case of RX error.
+ *
+ * @param[in] uartp pointer to the @p UARTDriver object
+ *
+ * @notapi
+ */
+#define _uart_wakeup_rx_error_isr(uartp) { \
+ osalSysLockFromISR(); \
+ osalThreadResumeI(&(uartp)->threadrx, MSG_RESET); \
+ osalSysUnlockFromISR(); \
+}
+#else /* !UART_USE_WAIT */
+#define _uart_wakeup_rx_error_isr(uartp)
+#endif /* !UART_USE_WAIT */
+
+#if (UART_USE_WAIT == TRUE) || defined(__DOXYGEN__)
+/**
+ * @brief Wakes up the waiting thread in case of RX character match.
+ *
+ * @param[in] uartp pointer to the @p UARTDriver object
+ *
+ * @notapi
+ */
+#define _uart_wakeup_rx_cm_isr(uartp) { \
+ osalSysLockFromISR(); \
+ osalThreadResumeI(&(uartp)->threadrx, MSG_TIMEOUT); \
+ osalSysUnlockFromISR(); \
+}
+#else /* !UART_USE_WAIT */
+#define _uart_wakeup_rx_cm_isr(uartp)
+#endif /* !UART_USE_WAIT */
+
+#if (UART_USE_WAIT == TRUE) || defined(__DOXYGEN__)
+/**
+ * @brief Wakes up the waiting thread in case of RX timeout.
+ *
+ * @param[in] uartp pointer to the @p UARTDriver object
+ *
+ * @notapi
+ */
+#define _uart_wakeup_rx_timeout_isr(uartp) { \
+ osalSysLockFromISR(); \
+ osalThreadResumeI(&(uartp)->threadrx, MSG_TIMEOUT); \
+ osalSysUnlockFromISR(); \
+}
+#else /* !UART_USE_WAIT */
+#define _uart_wakeup_rx_timeout_isr(uartp)
+#endif /* !UART_USE_WAIT */
+
+/**
+ * @brief Common ISR code for early TX.
+ * @details This code handles the portable part of the ISR code:
+ * - Callback invocation.
+ * - Waiting thread wakeup, if any.
+ * - Driver state transitions.
+ * .
+ * @note This macro is meant to be used in the low level drivers
+ * implementation only.
+ *
+ * @param[in] uartp pointer to the @p UARTDriver object
+ *
+ * @notapi
+ */
+#define _uart_tx1_isr_code(uartp) { \
+ (uartp)->txstate = UART_TX_COMPLETE; \
+ if ((uartp)->config->txend1_cb != NULL) { \
+ (uartp)->config->txend1_cb(uartp); \
+ } \
+ if ((uartp)->txstate == UART_TX_COMPLETE) { \
+ (uartp)->txstate = UART_TX_IDLE; \
+ } \
+ _uart_wakeup_tx1_isr(uartp); \
+}
+
+/**
+ * @brief Common ISR code for late TX.
+ * @details This code handles the portable part of the ISR code:
+ * - Callback invocation.
+ * - Waiting thread wakeup, if any.
+ * - Driver state transitions.
+ * .
+ * @note This macro is meant to be used in the low level drivers
+ * implementation only.
+ *
+ * @param[in] uartp pointer to the @p UARTDriver object
+ *
+ * @notapi
+ */
+#define _uart_tx2_isr_code(uartp) { \
+ if ((uartp)->config->txend2_cb != NULL) { \
+ (uartp)->config->txend2_cb(uartp); \
+ } \
+ _uart_wakeup_tx2_isr(uartp); \
+}
+
+/**
+ * @brief Common ISR code for RX complete.
+ * @details This code handles the portable part of the ISR code:
+ * - Callback invocation.
+ * - Waiting thread wakeup, if any.
+ * - Driver state transitions.
+ * .
+ * @note This macro is meant to be used in the low level drivers
+ * implementation only.
+ *
+ * @param[in] uartp pointer to the @p UARTDriver object
+ *
+ * @notapi
+ */
+#define _uart_rx_complete_isr_code(uartp) { \
+ (uartp)->rxstate = UART_RX_COMPLETE; \
+ if ((uartp)->config->rxend_cb != NULL) { \
+ (uartp)->config->rxend_cb(uartp); \
+ } \
+ if ((uartp)->rxstate == UART_RX_COMPLETE) { \
+ (uartp)->rxstate = UART_RX_IDLE; \
+ uart_enter_rx_idle_loop(uartp); \
+ } \
+ _uart_wakeup_rx_complete_isr(uartp); \
+}
+
+/**
+ * @brief Common ISR code for RX error.
+ * @details This code handles the portable part of the ISR code:
+ * - Callback invocation.
+ * - Waiting thread wakeup, if any.
+ * - Driver state transitions.
+ * .
+ * @note This macro is meant to be used in the low level drivers
+ * implementation only.
+ *
+ * @param[in] uartp pointer to the @p UARTDriver object
+ * @param[in] errors mask of errors to be reported
+ *
+ * @notapi
+ */
+#define _uart_rx_error_isr_code(uartp, errors) { \
+ if ((uartp)->config->rxerr_cb != NULL) { \
+ (uartp)->config->rxerr_cb(uartp, errors); \
+ } \
+ _uart_wakeup_rx_error_isr(uartp); \
+}
+
+/**
+ * @brief Common ISR code for RX on idle.
+ * @details This code handles the portable part of the ISR code:
+ * - Callback invocation.
+ * - Waiting thread wakeup, if any.
+ * - Driver state transitions.
+ * .
+ * @note This macro is meant to be used in the low level drivers
+ * implementation only.
+ *
+ * @param[in] uartp pointer to the @p UARTDriver object
+ *
+ * @notapi
+ */
+#define _uart_rx_idle_code(uartp) { \
+ if ((uartp)->config->rxchar_cb != NULL) \
+ (uartp)->config->rxchar_cb(uartp, (uartp)->rxbuf); \
+}
+
+/**
+ * @brief Timeout ISR code for receiver.
+ * @details This code handles the portable part of the ISR code:
+ * - Callback invocation.
+ * - Waiting thread wakeup, if any.
+ * - Driver state transitions.
+ * .
+ * @note This macro is meant to be used in the low level drivers
+ * implementation only.
+ *
+ * @param[in] uartp pointer to the @p UARTDriver object
+ *
+ * @notapi
+ */
+#define _uart_timeout_isr_code(uartp) { \
+ if ((uartp)->config->timeout_cb != NULL) { \
+ (uartp)->config->timeout_cb(uartp); \
+ } \
+ _uart_wakeup_rx_timeout_isr(uartp); \
+}
+
+/**
+ * @brief Character match ISR code for receiver.
+ * @details This code handles the portable part of the ISR code:
+ * - Callback invocation.
+ * - Waiting thread wakeup, if any.
+ * - Driver state transitions.
+ * .
+ * @note This macro is meant to be used in the low level drivers
+ * implementation only.
+ *
+ * @param[in] uartp pointer to the @p UARTDriver object
+ *
+ * @notapi
+ */
+#define _uart_rx_char_match_isr_code(uartp) { \
+ if ((uartp)->config->rx_cm_cb != NULL) { \
+ (uartp)->config->rx_cm_cb(uartp); \
+ } \
+ _uart_wakeup_rx_cm_isr(uartp); \
+}
+
+/** @} */
+
+/*===========================================================================*/
+/* External declarations. */
+/*===========================================================================*/
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+ void uartInit(void);
+ void uartObjectInit(UARTDriver *uartp);
+ void uartStart(UARTDriver *uartp, const UARTConfig *config);
+ void uartStop(UARTDriver *uartp);
+ void uartStartSend(UARTDriver *uartp, size_t n, const void *txbuf);
+ void uartStartSendI(UARTDriver *uartp, size_t n, const void *txbuf);
+ size_t uartStopSend(UARTDriver *uartp);
+ size_t uartStopSendI(UARTDriver *uartp);
+ void uartStartReceive(UARTDriver *uartp, size_t n, void *rxbuf);
+ void uartStartReceiveI(UARTDriver *uartp, size_t n, void *rxbuf);
+ size_t uartStopReceive(UARTDriver *uartp);
+ size_t uartStopReceiveI(UARTDriver *uartp);
+#if UART_USE_WAIT == TRUE
+ msg_t uartSendTimeout(UARTDriver *uartp, size_t *np,
+ const void *txbuf, sysinterval_t timeout);
+ msg_t uartSendFullTimeout(UARTDriver *uartp, size_t *np,
+ const void *txbuf, sysinterval_t timeout);
+ msg_t uartReceiveTimeout(UARTDriver *uartp, size_t *np,
+ void *rxbuf, sysinterval_t timeout);
+#endif
+#if UART_USE_MUTUAL_EXCLUSION == TRUE
+ void uartAcquireBus(UARTDriver *uartp);
+ void uartReleaseBus(UARTDriver *uartp);
+#endif
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* HAL_USE_UART == TRUE */
+
+#endif /* HAL_UART_H */
+
+/** @} */
diff --git a/ChibiOS_20.3.2/os/hal/include/hal_usb.h b/ChibiOS_20.3.2/os/hal/include/hal_usb.h new file mode 100644 index 0000000..9fe67a6 --- /dev/null +++ b/ChibiOS_20.3.2/os/hal/include/hal_usb.h @@ -0,0 +1,638 @@ +/*
+ ChibiOS - Copyright (C) 2006..2018 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_usb.h
+ * @brief USB Driver macros and structures.
+ *
+ * @addtogroup USB
+ * @{
+ */
+
+#ifndef HAL_USB_H
+#define HAL_USB_H
+
+#if (HAL_USE_USB == TRUE) || defined(__DOXYGEN__)
+
+/*===========================================================================*/
+/* Driver constants. */
+/*===========================================================================*/
+
+#define USB_ENDPOINT_OUT(ep) (ep)
+#define USB_ENDPOINT_IN(ep) ((ep) | 0x80U)
+
+#define USB_RTYPE_DIR_MASK 0x80U
+#define USB_RTYPE_DIR_HOST2DEV 0x00U
+#define USB_RTYPE_DIR_DEV2HOST 0x80U
+#define USB_RTYPE_TYPE_MASK 0x60U
+#define USB_RTYPE_TYPE_STD 0x00U
+#define USB_RTYPE_TYPE_CLASS 0x20U
+#define USB_RTYPE_TYPE_VENDOR 0x40U
+#define USB_RTYPE_TYPE_RESERVED 0x60U
+#define USB_RTYPE_RECIPIENT_MASK 0x1FU
+#define USB_RTYPE_RECIPIENT_DEVICE 0x00U
+#define USB_RTYPE_RECIPIENT_INTERFACE 0x01U
+#define USB_RTYPE_RECIPIENT_ENDPOINT 0x02U
+#define USB_RTYPE_RECIPIENT_OTHER 0x03U
+
+#define USB_REQ_GET_STATUS 0U
+#define USB_REQ_CLEAR_FEATURE 1U
+#define USB_REQ_SET_FEATURE 3U
+#define USB_REQ_SET_ADDRESS 5U
+#define USB_REQ_GET_DESCRIPTOR 6U
+#define USB_REQ_SET_DESCRIPTOR 7U
+#define USB_REQ_GET_CONFIGURATION 8U
+#define USB_REQ_SET_CONFIGURATION 9U
+#define USB_REQ_GET_INTERFACE 10U
+#define USB_REQ_SET_INTERFACE 11U
+#define USB_REQ_SYNCH_FRAME 12U
+
+#define USB_DESCRIPTOR_DEVICE 1U
+#define USB_DESCRIPTOR_CONFIGURATION 2U
+#define USB_DESCRIPTOR_STRING 3U
+#define USB_DESCRIPTOR_INTERFACE 4U
+#define USB_DESCRIPTOR_ENDPOINT 5U
+#define USB_DESCRIPTOR_DEVICE_QUALIFIER 6U
+#define USB_DESCRIPTOR_OTHER_SPEED_CFG 7U
+#define USB_DESCRIPTOR_INTERFACE_POWER 8U
+#define USB_DESCRIPTOR_INTERFACE_ASSOCIATION 11U
+
+#define USB_FEATURE_ENDPOINT_HALT 0U
+#define USB_FEATURE_DEVICE_REMOTE_WAKEUP 1U
+#define USB_FEATURE_TEST_MODE 2U
+
+#define USB_EARLY_SET_ADDRESS 0
+#define USB_LATE_SET_ADDRESS 1
+
+#define USB_EP0_STATUS_STAGE_SW 0
+#define USB_EP0_STATUS_STAGE_HW 1
+
+#define USB_SET_ADDRESS_ACK_SW 0
+#define USB_SET_ADDRESS_ACK_HW 1
+
+/**
+ * @name Helper macros for USB descriptors
+ * @{
+ */
+/**
+ * @brief Helper macro for index values into descriptor strings.
+ */
+#define USB_DESC_INDEX(i) ((uint8_t)(i))
+
+/**
+ * @brief Helper macro for byte values into descriptor strings.
+ */
+#define USB_DESC_BYTE(b) ((uint8_t)(b))
+
+/**
+ * @brief Helper macro for word values into descriptor strings.
+ */
+#define USB_DESC_WORD(w) \
+ (uint8_t)((w) & 255U), \
+ (uint8_t)(((w) >> 8) & 255U)
+
+/**
+ * @brief Helper macro for BCD values into descriptor strings.
+ */
+#define USB_DESC_BCD(bcd) \
+ (uint8_t)((bcd) & 255U), \
+ (uint8_t)(((bcd) >> 8) & 255)
+
+/*
+ * @define Device Descriptor size.
+ */
+#define USB_DESC_DEVICE_SIZE 18U
+
+/**
+ * @brief Device Descriptor helper macro.
+ */
+#define USB_DESC_DEVICE(bcdUSB, bDeviceClass, bDeviceSubClass, \
+ bDeviceProtocol, bMaxPacketSize, idVendor, \
+ idProduct, bcdDevice, iManufacturer, \
+ iProduct, iSerialNumber, bNumConfigurations) \
+ USB_DESC_BYTE(USB_DESC_DEVICE_SIZE), \
+ USB_DESC_BYTE(USB_DESCRIPTOR_DEVICE), \
+ USB_DESC_BCD(bcdUSB), \
+ USB_DESC_BYTE(bDeviceClass), \
+ USB_DESC_BYTE(bDeviceSubClass), \
+ USB_DESC_BYTE(bDeviceProtocol), \
+ USB_DESC_BYTE(bMaxPacketSize), \
+ USB_DESC_WORD(idVendor), \
+ USB_DESC_WORD(idProduct), \
+ USB_DESC_BCD(bcdDevice), \
+ USB_DESC_INDEX(iManufacturer), \
+ USB_DESC_INDEX(iProduct), \
+ USB_DESC_INDEX(iSerialNumber), \
+ USB_DESC_BYTE(bNumConfigurations)
+
+/**
+ * @brief Configuration Descriptor size.
+ */
+#define USB_DESC_CONFIGURATION_SIZE 9U
+
+/**
+ * @brief Configuration Descriptor helper macro.
+ */
+#define USB_DESC_CONFIGURATION(wTotalLength, bNumInterfaces, \
+ bConfigurationValue, iConfiguration, \
+ bmAttributes, bMaxPower) \
+ USB_DESC_BYTE(USB_DESC_CONFIGURATION_SIZE), \
+ USB_DESC_BYTE(USB_DESCRIPTOR_CONFIGURATION), \
+ USB_DESC_WORD(wTotalLength), \
+ USB_DESC_BYTE(bNumInterfaces), \
+ USB_DESC_BYTE(bConfigurationValue), \
+ USB_DESC_INDEX(iConfiguration), \
+ USB_DESC_BYTE(bmAttributes), \
+ USB_DESC_BYTE(bMaxPower)
+
+/**
+ * @brief Interface Descriptor size.
+ */
+#define USB_DESC_INTERFACE_SIZE 9U
+
+/**
+ * @brief Interface Descriptor helper macro.
+ */
+#define USB_DESC_INTERFACE(bInterfaceNumber, bAlternateSetting, \
+ bNumEndpoints, bInterfaceClass, \
+ bInterfaceSubClass, bInterfaceProtocol, \
+ iInterface) \
+ USB_DESC_BYTE(USB_DESC_INTERFACE_SIZE), \
+ USB_DESC_BYTE(USB_DESCRIPTOR_INTERFACE), \
+ USB_DESC_BYTE(bInterfaceNumber), \
+ USB_DESC_BYTE(bAlternateSetting), \
+ USB_DESC_BYTE(bNumEndpoints), \
+ USB_DESC_BYTE(bInterfaceClass), \
+ USB_DESC_BYTE(bInterfaceSubClass), \
+ USB_DESC_BYTE(bInterfaceProtocol), \
+ USB_DESC_INDEX(iInterface)
+
+/**
+ * @brief Interface Association Descriptor size.
+ */
+#define USB_DESC_INTERFACE_ASSOCIATION_SIZE 8U
+
+/**
+ * @brief Interface Association Descriptor helper macro.
+ */
+#define USB_DESC_INTERFACE_ASSOCIATION(bFirstInterface, \
+ bInterfaceCount, bFunctionClass, \
+ bFunctionSubClass, bFunctionProcotol, \
+ iInterface) \
+ USB_DESC_BYTE(USB_DESC_INTERFACE_ASSOCIATION_SIZE), \
+ USB_DESC_BYTE(USB_DESCRIPTOR_INTERFACE_ASSOCIATION), \
+ USB_DESC_BYTE(bFirstInterface), \
+ USB_DESC_BYTE(bInterfaceCount), \
+ USB_DESC_BYTE(bFunctionClass), \
+ USB_DESC_BYTE(bFunctionSubClass), \
+ USB_DESC_BYTE(bFunctionProcotol), \
+ USB_DESC_INDEX(iInterface)
+
+/**
+ * @brief Endpoint Descriptor size.
+ */
+#define USB_DESC_ENDPOINT_SIZE 7U
+
+/**
+ * @brief Endpoint Descriptor helper macro.
+ */
+#define USB_DESC_ENDPOINT(bEndpointAddress, bmAttributes, wMaxPacketSize, \
+ bInterval) \
+ USB_DESC_BYTE(USB_DESC_ENDPOINT_SIZE), \
+ USB_DESC_BYTE(USB_DESCRIPTOR_ENDPOINT), \
+ USB_DESC_BYTE(bEndpointAddress), \
+ USB_DESC_BYTE(bmAttributes), \
+ USB_DESC_WORD(wMaxPacketSize), \
+ USB_DESC_BYTE(bInterval)
+/** @} */
+
+/**
+ * @name Endpoint types and settings
+ * @{
+ */
+#define USB_EP_MODE_TYPE 0x0003U /**< Endpoint type mask. */
+#define USB_EP_MODE_TYPE_CTRL 0x0000U /**< Control endpoint. */
+#define USB_EP_MODE_TYPE_ISOC 0x0001U /**< Isochronous endpoint. */
+#define USB_EP_MODE_TYPE_BULK 0x0002U /**< Bulk endpoint. */
+#define USB_EP_MODE_TYPE_INTR 0x0003U /**< Interrupt endpoint. */
+/** @} */
+
+#define USB_IN_STATE 0x08U
+#define USB_OUT_STATE 0x10U
+
+/*===========================================================================*/
+/* Driver pre-compile time settings. */
+/*===========================================================================*/
+
+/**
+ * @brief Enables synchronous APIs.
+ * @note Disabling this option saves both code and data space.
+ */
+#if !defined(USB_USE_WAIT) || defined(__DOXYGEN__)
+#define USB_USE_WAIT FALSE
+#endif
+
+/*===========================================================================*/
+/* Derived constants and error checks. */
+/*===========================================================================*/
+
+/*===========================================================================*/
+/* Driver data structures and types. */
+/*===========================================================================*/
+
+/**
+ * @brief Type of a structure representing an USB driver.
+ */
+typedef struct USBDriver USBDriver;
+
+/**
+ * @brief Type of an endpoint identifier.
+ */
+typedef uint8_t usbep_t;
+
+/**
+ * @brief Type of a driver state machine possible states.
+ */
+typedef enum {
+ USB_UNINIT = 0, /**< Not initialized. */
+ USB_STOP = 1, /**< Stopped. */
+ USB_READY = 2, /**< Ready, after bus reset. */
+ USB_SELECTED = 3, /**< Address assigned. */
+ USB_ACTIVE = 4, /**< Active, configuration selected.*/
+ USB_SUSPENDED = 5 /**< Suspended, low power mode. */
+} usbstate_t;
+
+/**
+ * @brief Type of an endpoint status.
+ */
+typedef enum {
+ EP_STATUS_DISABLED = 0, /**< Endpoint not active. */
+ EP_STATUS_STALLED = 1, /**< Endpoint opened but stalled. */
+ EP_STATUS_ACTIVE = 2 /**< Active endpoint. */
+} usbepstatus_t;
+
+/**
+ * @brief Type of an endpoint zero state machine states.
+ */
+typedef enum {
+ USB_EP0_STP_WAITING = 0U, /**< Waiting for SETUP data.*/
+ USB_EP0_IN_TX = USB_IN_STATE | 1U, /**< Transmitting. */
+ USB_EP0_IN_WAITING_TX0 = USB_IN_STATE | 2U, /**< Waiting transmit 0. */
+ USB_EP0_IN_SENDING_STS = USB_IN_STATE | 3U, /**< Sending status. */
+ USB_EP0_OUT_WAITING_STS = USB_OUT_STATE | 4U, /**< Waiting status. */
+ USB_EP0_OUT_RX = USB_OUT_STATE | 5U, /**< Receiving. */
+ USB_EP0_ERROR = 6U /**< Error, EP0 stalled. */
+} usbep0state_t;
+
+/**
+ * @brief Type of an enumeration of the possible USB events.
+ */
+typedef enum {
+ USB_EVENT_RESET = 0, /**< Driver has been reset by host. */
+ USB_EVENT_ADDRESS = 1, /**< Address assigned. */
+ USB_EVENT_CONFIGURED = 2, /**< Configuration selected. */
+ USB_EVENT_UNCONFIGURED = 3, /**< Configuration removed. */
+ USB_EVENT_SUSPEND = 4, /**< Entering suspend mode. */
+ USB_EVENT_WAKEUP = 5, /**< Leaving suspend mode. */
+ USB_EVENT_STALLED = 6 /**< Endpoint 0 error, stalled. */
+} usbevent_t;
+
+/**
+ * @brief Type of an USB descriptor.
+ */
+typedef struct {
+ /**
+ * @brief Descriptor size in unicode characters.
+ */
+ size_t ud_size;
+ /**
+ * @brief Pointer to the descriptor.
+ */
+ const uint8_t *ud_string;
+} USBDescriptor;
+
+/**
+ * @brief Type of an USB generic notification callback.
+ *
+ * @param[in] usbp pointer to the @p USBDriver object triggering the
+ * callback
+ */
+typedef void (*usbcallback_t)(USBDriver *usbp);
+
+/**
+ * @brief Type of an USB endpoint callback.
+ *
+ * @param[in] usbp pointer to the @p USBDriver object triggering the
+ * callback
+ * @param[in] ep endpoint number
+ */
+typedef void (*usbepcallback_t)(USBDriver *usbp, usbep_t ep);
+
+/**
+ * @brief Type of an USB event notification callback.
+ *
+ * @param[in] usbp pointer to the @p USBDriver object triggering the
+ * callback
+ * @param[in] event event type
+ */
+typedef void (*usbeventcb_t)(USBDriver *usbp, usbevent_t event);
+
+/**
+ * @brief Type of a requests handler callback.
+ * @details The request is encoded in the @p usb_setup buffer.
+ *
+ * @param[in] usbp pointer to the @p USBDriver object triggering the
+ * callback
+ * @return The request handling exit code.
+ * @retval false Request not recognized by the handler.
+ * @retval true Request handled.
+ */
+typedef bool (*usbreqhandler_t)(USBDriver *usbp);
+
+/**
+ * @brief Type of an USB descriptor-retrieving callback.
+ */
+typedef const USBDescriptor * (*usbgetdescriptor_t)(USBDriver *usbp,
+ uint8_t dtype,
+ uint8_t dindex,
+ uint16_t lang);
+
+#include "hal_usb_lld.h"
+
+/*===========================================================================*/
+/* Driver macros. */
+/*===========================================================================*/
+
+/**
+ * @name Macro Functions
+ * @{
+ */
+/**
+ * @brief Returns the driver state.
+ *
+ * @param[in] usbp pointer to the @p USBDriver object
+ * @return The driver state.
+ *
+ * @iclass
+ */
+#define usbGetDriverStateI(usbp) ((usbp)->state)
+
+/**
+ * @brief Connects the USB device.
+ *
+ * @param[in] usbp pointer to the @p USBDriver object
+ *
+ * @api
+ */
+#define usbConnectBus(usbp) usb_lld_connect_bus(usbp)
+
+/**
+ * @brief Disconnect the USB device.
+ *
+ * @param[in] usbp pointer to the @p USBDriver object
+ *
+ * @api
+ */
+#define usbDisconnectBus(usbp) usb_lld_disconnect_bus(usbp)
+
+/**
+ * @brief Returns the current frame number.
+ *
+ * @param[in] usbp pointer to the @p USBDriver object
+ * @return The current frame number.
+ *
+ * @xclass
+ */
+#define usbGetFrameNumberX(usbp) usb_lld_get_frame_number(usbp)
+
+/**
+ * @brief Returns the status of an IN endpoint.
+ *
+ * @param[in] usbp pointer to the @p USBDriver object
+ * @param[in] ep endpoint number
+ * @return The operation status.
+ * @retval false Endpoint ready.
+ * @retval true Endpoint transmitting.
+ *
+ * @iclass
+ */
+#define usbGetTransmitStatusI(usbp, ep) \
+ (((usbp)->transmitting & (uint16_t)((unsigned)1U << (unsigned)(ep))) != 0U)
+
+/**
+ * @brief Returns the status of an OUT endpoint.
+ *
+ * @param[in] usbp pointer to the @p USBDriver object
+ * @param[in] ep endpoint number
+ * @return The operation status.
+ * @retval false Endpoint ready.
+ * @retval true Endpoint receiving.
+ *
+ * @iclass
+ */
+#define usbGetReceiveStatusI(usbp, ep) \
+ (((usbp)->receiving & (uint16_t)((unsigned)1U << (unsigned)(ep))) != 0U)
+
+/**
+ * @brief Returns the exact size of a receive transaction.
+ * @details The received size can be different from the size specified in
+ * @p usbStartReceiveI() because the last packet could have a size
+ * different from the expected one.
+ *
+ * @param[in] usbp pointer to the @p USBDriver object
+ * @param[in] ep endpoint number
+ * @return Received data size.
+ *
+ * @xclass
+ */
+#define usbGetReceiveTransactionSizeX(usbp, ep) \
+ usb_lld_get_transaction_size(usbp, ep)
+
+/**
+ * @brief Request transfer setup.
+ * @details This macro is used by the request handling callbacks in order to
+ * prepare a transaction over the endpoint zero.
+ *
+ * @param[in] usbp pointer to the @p USBDriver object
+ * @param[in] buf pointer to a buffer for the transaction data
+ * @param[in] n number of bytes to be transferred
+ * @param[in] endcb callback to be invoked after the transfer or @p NULL
+ *
+ * @special
+ */
+#define usbSetupTransfer(usbp, buf, n, endcb) { \
+ (usbp)->ep0next = (buf); \
+ (usbp)->ep0n = (n); \
+ (usbp)->ep0endcb = (endcb); \
+}
+
+/**
+ * @brief Reads a setup packet from the dedicated packet buffer.
+ * @details This function must be invoked in the context of the @p setup_cb
+ * callback in order to read the received setup packet.
+ * @pre In order to use this function the endpoint must have been
+ * initialized as a control endpoint.
+ * @note This function can be invoked both in thread and IRQ context.
+ *
+ * @param[in] usbp pointer to the @p USBDriver object
+ * @param[in] ep endpoint number
+ * @param[out] buf buffer where to copy the packet data
+ *
+ * @special
+ */
+#define usbReadSetup(usbp, ep, buf) usb_lld_read_setup(usbp, ep, buf)
+/** @} */
+
+/**
+ * @name Low level driver helper macros
+ * @{
+ */
+/**
+ * @brief Common ISR code, usb event callback.
+ *
+ * @param[in] usbp pointer to the @p USBDriver object
+ * @param[in] evt USB event code
+ *
+ * @notapi
+ */
+#define _usb_isr_invoke_event_cb(usbp, evt) { \
+ if (((usbp)->config->event_cb) != NULL) { \
+ (usbp)->config->event_cb(usbp, evt); \
+ } \
+}
+
+/**
+ * @brief Common ISR code, SOF callback.
+ *
+ * @param[in] usbp pointer to the @p USBDriver object
+ *
+ * @notapi
+ */
+#define _usb_isr_invoke_sof_cb(usbp) { \
+ if (((usbp)->config->sof_cb) != NULL) { \
+ (usbp)->config->sof_cb(usbp); \
+ } \
+}
+
+/**
+ * @brief Common ISR code, setup packet callback.
+ *
+ * @param[in] usbp pointer to the @p USBDriver object
+ * @param[in] ep endpoint number
+ *
+ * @notapi
+ */
+#define _usb_isr_invoke_setup_cb(usbp, ep) { \
+ (usbp)->epc[ep]->setup_cb(usbp, ep); \
+}
+
+/**
+ * @brief Common ISR code, IN endpoint callback.
+ *
+ * @param[in] usbp pointer to the @p USBDriver object
+ * @param[in] ep endpoint number
+ *
+ * @notapi
+ */
+#if (USB_USE_WAIT == TRUE) || defined(__DOXYGEN__)
+#define _usb_isr_invoke_in_cb(usbp, ep) { \
+ (usbp)->transmitting &= ~(1 << (ep)); \
+ if ((usbp)->epc[ep]->in_cb != NULL) { \
+ (usbp)->epc[ep]->in_cb(usbp, ep); \
+ } \
+ osalSysLockFromISR(); \
+ osalThreadResumeI(&(usbp)->epc[ep]->in_state->thread, MSG_OK); \
+ osalSysUnlockFromISR(); \
+}
+#else
+#define _usb_isr_invoke_in_cb(usbp, ep) { \
+ (usbp)->transmitting &= ~(1 << (ep)); \
+ if ((usbp)->epc[ep]->in_cb != NULL) { \
+ (usbp)->epc[ep]->in_cb(usbp, ep); \
+ } \
+}
+#endif
+
+/**
+ * @brief Common ISR code, OUT endpoint event.
+ *
+ * @param[in] usbp pointer to the @p USBDriver object
+ * @param[in] ep endpoint number
+ *
+ * @notapi
+ */
+#if (USB_USE_WAIT == TRUE) || defined(__DOXYGEN__)
+#define _usb_isr_invoke_out_cb(usbp, ep) { \
+ (usbp)->receiving &= ~(1 << (ep)); \
+ if ((usbp)->epc[ep]->out_cb != NULL) { \
+ (usbp)->epc[ep]->out_cb(usbp, ep); \
+ } \
+ osalSysLockFromISR(); \
+ osalThreadResumeI(&(usbp)->epc[ep]->out_state->thread, \
+ usbGetReceiveTransactionSizeX(usbp, ep)); \
+ osalSysUnlockFromISR(); \
+}
+#else
+#define _usb_isr_invoke_out_cb(usbp, ep) { \
+ (usbp)->receiving &= ~(1 << (ep)); \
+ if ((usbp)->epc[ep]->out_cb != NULL) { \
+ (usbp)->epc[ep]->out_cb(usbp, ep); \
+ } \
+}
+#endif
+/** @} */
+
+/*===========================================================================*/
+/* External declarations. */
+/*===========================================================================*/
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+ void usbInit(void);
+ void usbObjectInit(USBDriver *usbp);
+ void usbStart(USBDriver *usbp, const USBConfig *config);
+ void usbStop(USBDriver *usbp);
+ void usbInitEndpointI(USBDriver *usbp, usbep_t ep,
+ const USBEndpointConfig *epcp);
+ void usbDisableEndpointsI(USBDriver *usbp);
+ void usbReadSetupI(USBDriver *usbp, usbep_t ep, uint8_t *buf);
+ void usbStartReceiveI(USBDriver *usbp, usbep_t ep,
+ uint8_t *buf, size_t n);
+ void usbStartTransmitI(USBDriver *usbp, usbep_t ep,
+ const uint8_t *buf, size_t n);
+#if USB_USE_WAIT == TRUE
+ msg_t usbReceive(USBDriver *usbp, usbep_t ep, uint8_t *buf, size_t n);
+ msg_t usbTransmit(USBDriver *usbp, usbep_t ep, const uint8_t *buf, size_t n);
+#endif
+ bool usbStallReceiveI(USBDriver *usbp, usbep_t ep);
+ bool usbStallTransmitI(USBDriver *usbp, usbep_t ep);
+ void usbWakeupHost(USBDriver *usbp);
+ void _usb_reset(USBDriver *usbp);
+ void _usb_suspend(USBDriver *usbp);
+ void _usb_wakeup(USBDriver *usbp);
+ void _usb_ep0setup(USBDriver *usbp, usbep_t ep);
+ void _usb_ep0in(USBDriver *usbp, usbep_t ep);
+ void _usb_ep0out(USBDriver *usbp, usbep_t ep);
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* HAL_USE_USB == TRUE */
+
+#endif /* HAL_USB_H */
+
+/** @} */
diff --git a/ChibiOS_20.3.2/os/hal/include/hal_usb_cdc.h b/ChibiOS_20.3.2/os/hal/include/hal_usb_cdc.h new file mode 100644 index 0000000..4eaf905 --- /dev/null +++ b/ChibiOS_20.3.2/os/hal/include/hal_usb_cdc.h @@ -0,0 +1,136 @@ +/*
+ ChibiOS - Copyright (C) 2006..2018 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_usb_cdc.h
+ * @brief USB CDC macros and structures.
+ *
+ * @addtogroup USB_CDC
+ * @{
+ */
+
+#ifndef USB_CDC_H
+#define USB_CDC_H
+
+/*===========================================================================*/
+/* Driver constants. */
+/*===========================================================================*/
+
+/**
+ * @name CDC specific messages.
+ * @{
+ */
+#define CDC_SEND_ENCAPSULATED_COMMAND 0x00U
+#define CDC_GET_ENCAPSULATED_RESPONSE 0x01U
+#define CDC_SET_COMM_FEATURE 0x02U
+#define CDC_GET_COMM_FEATURE 0x03U
+#define CDC_CLEAR_COMM_FEATURE 0x04U
+#define CDC_SET_AUX_LINE_STATE 0x10U
+#define CDC_SET_HOOK_STATE 0x11U
+#define CDC_PULSE_SETUP 0x12U
+#define CDC_SEND_PULSE 0x13U
+#define CDC_SET_PULSE_TIME 0x14U
+#define CDC_RING_AUX_JACK 0x15U
+#define CDC_SET_LINE_CODING 0x20U
+#define CDC_GET_LINE_CODING 0x21U
+#define CDC_SET_CONTROL_LINE_STATE 0x22U
+#define CDC_SEND_BREAK 0x23U
+#define CDC_SET_RINGER_PARMS 0x30U
+#define CDC_GET_RINGER_PARMS 0x31U
+#define CDC_SET_OPERATION_PARMS 0x32U
+#define CDC_GET_OPERATION_PARMS 0x33U
+/** @} */
+
+/**
+ * @name CDC classes
+ * @{
+ */
+#define CDC_COMMUNICATION_INTERFACE_CLASS 0x02U
+#define CDC_DATA_INTERFACE_CLASS 0x0AU
+/** @} */
+
+/**
+ * @name CDC subclasses
+ * @{
+ */
+#define CDC_ABSTRACT_CONTROL_MODEL 0x02U
+/** @} */
+
+/**
+ * @name CDC descriptors
+ * @{
+ */
+#define CDC_CS_INTERFACE 0x24U
+/** @} */
+
+/**
+ * @name CDC subdescriptors
+ * @{
+ */
+#define CDC_HEADER 0x00U
+#define CDC_CALL_MANAGEMENT 0x01U
+#define CDC_ABSTRACT_CONTROL_MANAGEMENT 0x02U
+#define CDC_UNION 0x06U
+/** @} */
+
+/**
+ * @name Line Control bit definitions.
+ * @{
+ */
+#define LC_STOP_1 0U
+#define LC_STOP_1P5 1U
+#define LC_STOP_2 2U
+
+#define LC_PARITY_NONE 0U
+#define LC_PARITY_ODD 1U
+#define LC_PARITY_EVEN 2U
+#define LC_PARITY_MARK 3U
+#define LC_PARITY_SPACE 4U
+/** @} */
+
+/*===========================================================================*/
+/* Driver pre-compile time settings. */
+/*===========================================================================*/
+
+/*===========================================================================*/
+/* Derived constants and error checks. */
+/*===========================================================================*/
+
+/*===========================================================================*/
+/* Driver data structures and types. */
+/*===========================================================================*/
+
+/**
+ * @brief Type of Line Coding structure.
+ */
+typedef struct {
+ uint8_t dwDTERate[4];
+ uint8_t bCharFormat;
+ uint8_t bParityType;
+ uint8_t bDataBits;
+} cdc_linecoding_t;
+
+/*===========================================================================*/
+/* Driver macros. */
+/*===========================================================================*/
+
+/*===========================================================================*/
+/* External declarations. */
+/*===========================================================================*/
+
+#endif /* USB_CDC_H */
+
+/** @} */
diff --git a/ChibiOS_20.3.2/os/hal/include/hal_wdg.h b/ChibiOS_20.3.2/os/hal/include/hal_wdg.h new file mode 100644 index 0000000..8513740 --- /dev/null +++ b/ChibiOS_20.3.2/os/hal/include/hal_wdg.h @@ -0,0 +1,89 @@ +/*
+ ChibiOS - Copyright (C) 2006..2018 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_wdg.h
+ * @brief WDG Driver macros and structures.
+ *
+ * @addtogroup WDG
+ * @{
+ */
+
+#ifndef HAL_WDG_H
+#define HAL_WDG_H
+
+#if (HAL_USE_WDG == TRUE) || defined(__DOXYGEN__)
+
+/*===========================================================================*/
+/* Driver constants. */
+/*===========================================================================*/
+
+/*===========================================================================*/
+/* Driver pre-compile time settings. */
+/*===========================================================================*/
+
+/*===========================================================================*/
+/* Derived constants and error checks. */
+/*===========================================================================*/
+
+/*===========================================================================*/
+/* Driver data structures and types. */
+/*===========================================================================*/
+
+/**
+ * @brief Driver state machine possible states.
+ */
+typedef enum {
+ WDG_UNINIT = 0, /**< Not initialized. */
+ WDG_STOP = 1, /**< Stopped. */
+ WDG_READY = 2 /**< Ready. */
+} wdgstate_t;
+
+#include "hal_wdg_lld.h"
+
+/*===========================================================================*/
+/* Driver macros. */
+/*===========================================================================*/
+
+/**
+ * @brief Resets WDG's counter.
+ *
+ * @param[in] wdgp pointer to the @p WDGDriver object
+ *
+ * @iclass
+ */
+#define wdgResetI(wdgp) wdg_lld_reset(wdgp)
+
+/*===========================================================================*/
+/* External declarations. */
+/*===========================================================================*/
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+ void wdgInit(void);
+ void wdgStart(WDGDriver *wdgp, const WDGConfig * config);
+ void wdgStop(WDGDriver *wdgp);
+ void wdgReset(WDGDriver *wdgp);
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* HAL_USE_WDG == TRUE */
+
+#endif /* HAL_WDG_H */
+
+/** @} */
diff --git a/ChibiOS_20.3.2/os/hal/include/hal_wspi.h b/ChibiOS_20.3.2/os/hal/include/hal_wspi.h new file mode 100644 index 0000000..d0a99c1 --- /dev/null +++ b/ChibiOS_20.3.2/os/hal/include/hal_wspi.h @@ -0,0 +1,468 @@ +/*
+ ChibiOS - Copyright (C) 2006..2018 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_wspi.h
+ * @brief WSPI Driver macros and structures.
+ *
+ * @addtogroup WSPI
+ * @{
+ */
+
+#ifndef HAL_WSPI_H
+#define HAL_WSPI_H
+
+#if (HAL_USE_WSPI == TRUE) || defined(__DOXYGEN__)
+
+/*===========================================================================*/
+/* Driver constants. */
+/*===========================================================================*/
+
+/*===========================================================================*/
+/* Driver pre-compile time settings. */
+/*===========================================================================*/
+
+/**
+ * @name WSPI configuration options
+ * @{
+ */
+/**
+ * @brief Enables synchronous APIs.
+ * @note Disabling this option saves both code and data space.
+ */
+#if !defined(WSPI_USE_WAIT) || defined(__DOXYGEN__)
+#define WSPI_USE_WAIT TRUE
+#endif
+
+/**
+ * @brief Enables the @p wspiAcquireBus() and @p wspiReleaseBus() APIs.
+ * @note Disabling this option saves both code and data space.
+ */
+#if !defined(WSPI_USE_MUTUAL_EXCLUSION) || defined(__DOXYGEN__)
+#define WSPI_USE_MUTUAL_EXCLUSION TRUE
+#endif
+/** @} */
+
+/*===========================================================================*/
+/* Derived constants and error checks. */
+/*===========================================================================*/
+
+/*===========================================================================*/
+/* Driver data structures and types. */
+/*===========================================================================*/
+
+/**
+ * @brief Driver state machine possible states.
+ */
+typedef enum {
+ WSPI_UNINIT = 0, /**< Not initialized. */
+ WSPI_STOP = 1, /**< Stopped. */
+ WSPI_READY = 2, /**< Ready. */
+ WSPI_SEND = 3, /**< Sending data. */
+ WSPI_RECEIVE = 4, /**< Receiving data. */
+ WSPI_COMPLETE = 5, /**< Asynchronous operation complete. */
+ WSPI_MEMMAP = 6 /**< In memory mapped mode. */
+} wspistate_t;
+
+/**
+ * @brief Type of a structure representing an WSPI driver.
+ */
+typedef struct hal_wspi_driver WSPIDriver;
+
+/**
+ * @brief Type of a structure representing an WSPI driver configuration.
+ */
+typedef struct hal_wspi_config WSPIConfig;
+
+/**
+ * @brief Type of a WSPI notification callback.
+ *
+ * @param[in] wspip pointer to the @p WSPIDriver object triggering the
+ * callback
+ */
+typedef void (*wspicallback_t)(WSPIDriver *wspip);
+
+/**
+ * @brief Type of a WSPI command descriptor.
+ */
+typedef struct {
+ /**
+ * @brief Transfer configuration field.
+ */
+ uint32_t cfg;
+ /**
+ * @brief Command phase data.
+ */
+ uint32_t cmd;
+ /**
+ * @brief Address phase data.
+ */
+ uint32_t addr;
+ /**
+ * @brief Alternate phase data.
+ */
+ uint32_t alt;
+ /**
+ * @brief Number of dummy cycles to be inserted.
+ */
+ uint32_t dummy;
+} wspi_command_t;
+
+/* Including the low level driver header, it exports information required
+ for completing types.*/
+#include "hal_wspi_lld.h"
+
+#if !defined(WSPI_SUPPORTS_MEMMAP)
+#error "low level does not define WSPI_SUPPORTS_MEMMAP"
+#endif
+
+#if !defined(WSPI_DEFAULT_CFG_MASKS)
+#error "low level does not define WSPI_DEFAULT_CFG_MASKS"
+#endif
+
+/**
+ * @brief Driver configuration structure.
+ */
+struct hal_wspi_config {
+ /**
+ * @brief Operation complete callback or @p NULL.
+ */
+ wspicallback_t end_cb;
+ /**
+ * @brief Operation error callback or @p NULL.
+ */
+ wspicallback_t error_cb;
+ /* End of the mandatory fields.*/
+ wspi_lld_config_fields;
+};
+
+/**
+ * @brief Structure representing an WSPI driver.
+ */
+struct hal_wspi_driver {
+ /**
+ * @brief Driver state.
+ */
+ wspistate_t state;
+ /**
+ * @brief Current configuration data.
+ */
+ const WSPIConfig *config;
+#if (WSPI_USE_WAIT == TRUE) || defined(__DOXYGEN__)
+ /**
+ * @brief Waiting thread.
+ */
+ thread_reference_t thread;
+#endif /* WSPI_USE_WAIT */
+#if (WSPI_USE_MUTUAL_EXCLUSION == TRUE) || defined(__DOXYGEN__)
+ /**
+ * @brief Mutex protecting the peripheral.
+ */
+ mutex_t mutex;
+#endif /* WSPI_USE_MUTUAL_EXCLUSION */
+#if defined(WSPI_DRIVER_EXT_FIELDS)
+ WSPI_DRIVER_EXT_FIELDS
+#endif
+ /* End of the mandatory fields.*/
+ wspi_lld_driver_fields;
+};
+
+/*===========================================================================*/
+/* Driver macros. */
+/*===========================================================================*/
+
+#if (WSPI_DEFAULT_CFG_MASKS == TRUE) || defined(__DOXYGEN__)
+/**
+ * @name Transfer options
+ * @note The low level driver has the option to override the following
+ * definitions and use its own ones. In must take care to use
+ * the same name for the same function or compatibility is not
+ * ensured.
+ * @{
+ */
+#define WSPI_CFG_CMD_MODE_MASK (7LU << 0LU)
+#define WSPI_CFG_CMD_MODE_NONE (0LU << 0LU)
+#define WSPI_CFG_CMD_MODE_ONE_LINE (1LU << 0LU)
+#define WSPI_CFG_CMD_MODE_TWO_LINES (2LU << 0LU)
+#define WSPI_CFG_CMD_MODE_FOUR_LINES (3LU << 0LU)
+#define WSPI_CFG_CMD_MODE_EIGHT_LINES (4LU << 0LU)
+
+#define WSPI_CFG_CMD_DTR (1LU << 3LU)
+
+#define WSPI_CFG_CMD_SIZE_MASK (3LU << 4LU)
+#define WSPI_CFG_CMD_SIZE_8 (0LU << 4LU)
+#define WSPI_CFG_CMD_SIZE_16 (1LU << 4LU)
+#define WSPI_CFG_CMD_SIZE_24 (2LU << 4LU)
+#define WSPI_CFG_CMD_SIZE_32 (3LU << 4LU)
+
+#define WSPI_CFG_ADDR_MODE_MASK (7LU << 8LU)
+#define WSPI_CFG_ADDR_MODE_NONE (0LU << 8LU)
+#define WSPI_CFG_ADDR_MODE_ONE_LINE (1LU << 8LU)
+#define WSPI_CFG_ADDR_MODE_TWO_LINES (2LU << 8LU)
+#define WSPI_CFG_ADDR_MODE_FOUR_LINES (3LU << 8LU)
+#define WSPI_CFG_ADDR_MODE_EIGHT_LINES (4LU << 8LU)
+
+#define WSPI_CFG_ADDR_DTR (1LU << 11LU)
+
+#define WSPI_CFG_ADDR_SIZE_MASK (3LU << 12LU)
+#define WSPI_CFG_ADDR_SIZE_8 (0LU << 12LU)
+#define WSPI_CFG_ADDR_SIZE_16 (1LU << 12LU)
+#define WSPI_CFG_ADDR_SIZE_24 (2LU << 12LU)
+#define WSPI_CFG_ADDR_SIZE_32 (3LU << 12LU)
+
+#define WSPI_CFG_ALT_MODE_MASK (7LU << 16LU)
+#define WSPI_CFG_ALT_MODE_NONE (0LU << 16LU)
+#define WSPI_CFG_ALT_MODE_ONE_LINE (1LU << 16LU)
+#define WSPI_CFG_ALT_MODE_TWO_LINES (2LU << 16LU)
+#define WSPI_CFG_ALT_MODE_FOUR_LINES (3LU << 16LU)
+#define WSPI_CFG_ALT_MODE_EIGHT_LINES (4LU << 16LU)
+
+#define WSPI_CFG_ALT_DTR (1LU << 19LU)
+
+#define WSPI_CFG_ALT_SIZE_MASK (3LU << 20LU)
+#define WSPI_CFG_ALT_SIZE_8 (0LU << 20LU)
+#define WSPI_CFG_ALT_SIZE_16 (1LU << 20LU)
+#define WSPI_CFG_ALT_SIZE_24 (2LU << 20LU)
+#define WSPI_CFG_ALT_SIZE_32 (3LU << 20LU)
+
+#define WSPI_CFG_DATA_MODE_MASK (7LU << 24LU)
+#define WSPI_CFG_DATA_MODE_NONE (0LU << 24LU)
+#define WSPI_CFG_DATA_MODE_ONE_LINE (1LU << 24LU)
+#define WSPI_CFG_DATA_MODE_TWO_LINES (2LU << 24LU)
+#define WSPI_CFG_DATA_MODE_FOUR_LINES (3LU << 24LU)
+#define WSPI_CFG_DATA_MODE_EIGHT_LINES (4LU << 24LU)
+
+#define WSPI_CFG_DATA_DTR (1LU << 27LU)
+
+#define WSPI_CFG_DQS_ENABLE (1LU << 29LU)
+
+#define WSPI_CFG_SIOO (1LU << 31LU)
+
+#define WSPI_CFG_ALL_DTR (WSPI_CFG_CMD_DTR | \
+ WSPI_CFG_ADDR_DTR | \
+ WSPI_CFG_ALT_DTR | \
+ WSPI_CFG_DATA_DTR)
+/** @} */
+#endif /* WSPI_USE_DEFAULT_CFG_MASKS == TRUE */
+
+/**
+ * @name Macro Functions
+ * @{
+ */
+/**
+ * @brief Sends a command without data phase.
+ * @post At the end of the operation the configured callback is invoked.
+ *
+ * @param[in] wspip pointer to the @p WSPIDriver object
+ * @param[in] cmdp pointer to the command descriptor
+ *
+ * @iclass
+ */
+#define wspiStartCommandI(wspip, cmdp) { \
+ osalDbgAssert(((cmdp)->cfg & WSPI_CFG_DATA_MODE_MASK) == \
+ WSPI_CFG_DATA_MODE_NONE, \
+ "data mode specified"); \
+ (wspip)->state = WSPI_SEND; \
+ wspi_lld_command(wspip, cmdp); \
+}
+
+/**
+ * @brief Sends data over the WSPI bus.
+ * @details This asynchronous function starts a transmit operation.
+ * @post At the end of the operation the configured callback is invoked.
+ *
+ * @param[in] wspip pointer to the @p WSPIDriver object
+ * @param[in] cmdp pointer to the command descriptor
+ * @param[in] n number of bytes to send or zero if no data phase
+ * @param[in] txbuf the pointer to the transmit buffer
+ *
+ * @iclass
+ */
+#define wspiStartSendI(wspip, cmdp, n, txbuf) { \
+ osalDbgAssert(((cmdp)->cfg & WSPI_CFG_DATA_MODE_MASK) != \
+ WSPI_CFG_DATA_MODE_NONE, \
+ "data mode required"); \
+ (wspip)->state = WSPI_SEND; \
+ wspi_lld_send(wspip, cmdp, n, txbuf); \
+}
+
+/**
+ * @brief Receives data from the WSPI bus.
+ * @details This asynchronous function starts a receive operation.
+ * @post At the end of the operation the configured callback is invoked.
+ *
+ * @param[in] wspip pointer to the @p WSPIDriver object
+ * @param[in] cmdp pointer to the command descriptor
+ * @param[in] n number of bytes to receive or zero if no data phase
+ * @param[out] rxbuf the pointer to the receive buffer
+ *
+ * @iclass
+ */
+#define wspiStartReceiveI(wspip, cmdp, n, rxbuf) { \
+ osalDbgAssert(((cmdp)->cfg & WSPI_CFG_DATA_MODE_MASK) != \
+ WSPI_CFG_DATA_MODE_NONE, \
+ "data mode required"); \
+ (wspip)->state = WSPI_RECEIVE; \
+ wspi_lld_receive(wspip, cmdp, n, rxbuf); \
+}
+
+#if (WSPI_SUPPORTS_MEMMAP == TRUE) || defined(__DOXYGEN__)
+/**
+ * @brief Maps in memory space a WSPI flash device.
+ * @pre The memory flash device must be initialized appropriately
+ * before mapping it in memory space.
+ *
+ * @param[in] wspip pointer to the @p WSPIDriver object
+ * @param[in] cmdp pointer to the command descriptor
+ * @param[out] addrp pointer to the memory start address of the mapped
+ * flash or @p NULL
+ *
+ * @iclass
+ */
+#define wspiMapFlashI(wspip, cmdp, addrp) \
+ wspi_lld_map_flash(wspip, cmdp, addrp)
+
+/**
+ * @brief Maps in memory space a WSPI flash device.
+ * @post The memory flash device must be re-initialized for normal
+ * commands exchange.
+ *
+ * @param[in] wspip pointer to the @p WSPIDriver object
+ *
+ * @iclass
+ */
+#define wspiUnmapFlashI(wspip) \
+ wspi_lld_unmap_flash(wspip)
+#endif /* WSPI_SUPPORTS_MEMMAP == TRUE */
+/** @} */
+
+/**
+ * @name Low level driver helper macros
+ * @{
+ */
+#if (WSPI_USE_WAIT == TRUE) || defined(__DOXYGEN__)
+/**
+ * @brief Wakes up the waiting thread.
+ *
+ * @param[in] wspip pointer to the @p WSPIDriver object
+ * @param[in] msg the wakeup message
+ *
+ * @notapi
+ */
+#define _wspi_wakeup_isr(wspip, msg) { \
+ osalSysLockFromISR(); \
+ osalThreadResumeI(&(wspip)->thread, msg); \
+ osalSysUnlockFromISR(); \
+}
+#else /* !WSPI_USE_WAIT */
+#define _wspi_wakeup_isr(wspip, msg)
+#endif /* !WSPI_USE_WAIT */
+
+/**
+ * @brief Common ISR code.
+ * @details This code handles the portable part of the ISR code:
+ * - Callback invocation.
+ * - Waiting thread wakeup, if any.
+ * - Driver state transitions.
+ * .
+ * @note This macro is meant to be used in the low level drivers
+ * implementation only.
+ *
+ * @param[in] wspip pointer to the @p WSPIDriver object
+ *
+ * @notapi
+ */
+#define _wspi_isr_code(wspip) { \
+ if ((wspip)->config->end_cb) { \
+ (wspip)->state = WSPI_COMPLETE; \
+ (wspip)->config->end_cb(wspip); \
+ if ((wspip)->state == WSPI_COMPLETE) \
+ (wspip)->state = WSPI_READY; \
+ } \
+ else \
+ (wspip)->state = WSPI_READY; \
+ _wspi_wakeup_isr(wspip, MSG_OK); \
+}
+
+/**
+ * @brief Common error ISR code.
+ * @details This code handles the portable part of the ISR code:
+ * - Callback invocation.
+ * - Waiting thread wakeup, if any.
+ * - Driver state transitions.
+ * .
+ * @note This macro is meant to be used in the low level drivers
+ * implementation only.
+ *
+ * @param[in] wspip pointer to the @p WSPIDriver object
+ *
+ * @notapi
+ */
+#define _wspi_error_code(wspip) { \
+ if ((wspip)->config->error_cb) { \
+ (wspip)->state = WSPI_COMPLETE; \
+ (wspip)->config->error_cb(wspip); \
+ if ((wspip)->state == WSPI_COMPLETE) \
+ (wspip)->state = WSPI_READY; \
+ } \
+ else \
+ (wspip)->state = WSPI_READY; \
+ _wspi_wakeup_isr(wspip, MSG_RESET); \
+}
+/** @} */
+
+/*===========================================================================*/
+/* External declarations. */
+/*===========================================================================*/
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+ void wspiInit(void);
+ void wspiObjectInit(WSPIDriver *wspip);
+ void wspiStart(WSPIDriver *wspip, const WSPIConfig *config);
+ void wspiStop(WSPIDriver *wspip);
+ void wspiStartCommand(WSPIDriver *wspip, const wspi_command_t *cmdp);
+ void wspiStartSend(WSPIDriver *wspip, const wspi_command_t *cmdp,
+ size_t n, const uint8_t *txbuf);
+ void wspiStartReceive(WSPIDriver *wspip, const wspi_command_t *cmdp,
+ size_t n, uint8_t *rxbuf);
+#if WSPI_USE_WAIT == TRUE
+ bool wspiCommand(WSPIDriver *wspip, const wspi_command_t *cmdp);
+ bool wspiSend(WSPIDriver *wspip, const wspi_command_t *cmdp,
+ size_t n, const uint8_t *txbuf);
+ bool wspiReceive(WSPIDriver *wspip, const wspi_command_t *cmdp,
+ size_t n, uint8_t *rxbuf);
+#endif
+#if WSPI_SUPPORTS_MEMMAP == TRUE
+void wspiMapFlash(WSPIDriver *wspip,
+ const wspi_command_t *cmdp,
+ uint8_t **addrp);
+void wspiUnmapFlash(WSPIDriver *wspip);
+#endif
+#if WSPI_USE_MUTUAL_EXCLUSION == TRUE
+ void wspiAcquireBus(WSPIDriver *wspip);
+ void wspiReleaseBus(WSPIDriver *wspip);
+#endif
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* HAL_USE_WSPI == TRUE */
+
+#endif /* HAL_WSPI_H */
+
+/** @} */
|