From 4edc5aeca7251e69dfa772dfdd5b2e012375a809 Mon Sep 17 00:00:00 2001 From: Giovanni Di Sirio Date: Wed, 23 Mar 2016 12:36:05 +0000 Subject: Mass renaming of HAL files. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@9151 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/include/adc.h | 278 ----------------- os/hal/include/can.h | 156 ---------- os/hal/include/dac.h | 267 ----------------- os/hal/include/ext.h | 150 ---------- os/hal/include/gpt.h | 141 --------- os/hal/include/hal.h | 49 ++- os/hal/include/hal_adc.h | 278 +++++++++++++++++ os/hal/include/hal_can.h | 156 ++++++++++ os/hal/include/hal_dac.h | 267 +++++++++++++++++ os/hal/include/hal_ext.h | 150 ++++++++++ os/hal/include/hal_gpt.h | 141 +++++++++ os/hal/include/hal_i2c.h | 166 +++++++++++ os/hal/include/hal_i2s.h | 167 +++++++++++ os/hal/include/hal_icu.h | 238 +++++++++++++++ os/hal/include/hal_mac.h | 204 +++++++++++++ os/hal/include/hal_mmc_spi.h | 195 ++++++++++++ os/hal/include/hal_pal.h | 642 ++++++++++++++++++++++++++++++++++++++++ os/hal/include/hal_pwm.h | 308 +++++++++++++++++++ os/hal/include/hal_rtc.h | 144 +++++++++ os/hal/include/hal_sdc.h | 195 ++++++++++++ os/hal/include/hal_serial.h | 286 ++++++++++++++++++ os/hal/include/hal_serial_usb.h | 195 ++++++++++++ os/hal/include/hal_spi.h | 291 ++++++++++++++++++ os/hal/include/hal_st.h | 97 ++++++ os/hal/include/hal_uart.h | 342 +++++++++++++++++++++ os/hal/include/hal_usb.h | 633 +++++++++++++++++++++++++++++++++++++++ os/hal/include/hal_wdg.h | 89 ++++++ os/hal/include/i2c.h | 166 ----------- os/hal/include/i2s.h | 167 ----------- os/hal/include/icu.h | 238 --------------- os/hal/include/mac.h | 202 ------------- os/hal/include/mmc_spi.h | 195 ------------ os/hal/include/pal.h | 642 ---------------------------------------- os/hal/include/pwm.h | 308 ------------------- os/hal/include/rtc.h | 144 --------- os/hal/include/sdc.h | 195 ------------ os/hal/include/serial.h | 286 ------------------ os/hal/include/serial_usb.h | 195 ------------ os/hal/include/spi.h | 291 ------------------ os/hal/include/st.h | 97 ------ os/hal/include/uart.h | 342 --------------------- os/hal/include/usb.h | 633 --------------------------------------- os/hal/include/wdg.h | 89 ------ 43 files changed, 5208 insertions(+), 5207 deletions(-) delete mode 100644 os/hal/include/adc.h delete mode 100644 os/hal/include/can.h delete mode 100644 os/hal/include/dac.h delete mode 100644 os/hal/include/ext.h delete mode 100644 os/hal/include/gpt.h create mode 100644 os/hal/include/hal_adc.h create mode 100644 os/hal/include/hal_can.h create mode 100644 os/hal/include/hal_dac.h create mode 100644 os/hal/include/hal_ext.h create mode 100644 os/hal/include/hal_gpt.h create mode 100644 os/hal/include/hal_i2c.h create mode 100644 os/hal/include/hal_i2s.h create mode 100644 os/hal/include/hal_icu.h create mode 100644 os/hal/include/hal_mac.h create mode 100644 os/hal/include/hal_mmc_spi.h create mode 100644 os/hal/include/hal_pal.h create mode 100644 os/hal/include/hal_pwm.h create mode 100644 os/hal/include/hal_rtc.h create mode 100644 os/hal/include/hal_sdc.h create mode 100644 os/hal/include/hal_serial.h create mode 100644 os/hal/include/hal_serial_usb.h create mode 100644 os/hal/include/hal_spi.h create mode 100644 os/hal/include/hal_st.h create mode 100644 os/hal/include/hal_uart.h create mode 100644 os/hal/include/hal_usb.h create mode 100644 os/hal/include/hal_wdg.h delete mode 100644 os/hal/include/i2c.h delete mode 100644 os/hal/include/i2s.h delete mode 100644 os/hal/include/icu.h delete mode 100644 os/hal/include/mac.h delete mode 100644 os/hal/include/mmc_spi.h delete mode 100644 os/hal/include/pal.h delete mode 100644 os/hal/include/pwm.h delete mode 100644 os/hal/include/rtc.h delete mode 100644 os/hal/include/sdc.h delete mode 100644 os/hal/include/serial.h delete mode 100644 os/hal/include/serial_usb.h delete mode 100644 os/hal/include/spi.h delete mode 100644 os/hal/include/st.h delete mode 100644 os/hal/include/uart.h delete mode 100644 os/hal/include/usb.h delete mode 100644 os/hal/include/wdg.h (limited to 'os/hal/include') diff --git a/os/hal/include/adc.h b/os/hal/include/adc.h deleted file mode 100644 index 142ddfda7..000000000 --- a/os/hal/include/adc.h +++ /dev/null @@ -1,278 +0,0 @@ -/* - ChibiOS - Copyright (C) 2006..2016 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 adc.h - * @brief ADC Driver macros and structures. - * - * @addtogroup ADC - * @{ - */ - -#ifndef _ADC_H_ -#define _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 complete. */ -} adcstate_t; - -#include "adc_lld.h" - -/*===========================================================================*/ -/* Driver macros. */ -/*===========================================================================*/ - -/** - * @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, (adcp)->samples, (adcp)->depth / 2); \ - } \ -} - -/** - * @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) { \ - if ((adcp)->depth > 1) { \ - /* Invokes the callback passing the 2nd half of the buffer.*/ \ - size_t half = (adcp)->depth / 2; \ - size_t half_index = half * (adcp)->grpp->num_channels; \ - (adcp)->grpp->end_cb(adcp, (adcp)->samples + half_index, half); \ - } \ - else { \ - /* Invokes the callback passing the whole buffer.*/ \ - (adcp)->grpp->end_cb(adcp, (adcp)->samples, (adcp)->depth); \ - } \ - } \ - } \ - else { \ - /* End conversion.*/ \ - adc_lld_stop_conversion(adcp); \ - if ((adcp)->grpp->end_cb != NULL) { \ - (adcp)->state = ADC_COMPLETE; \ - /* Invoke the callback passing the whole buffer.*/ \ - (adcp)->grpp->end_cb(adcp, (adcp)->samples, (adcp)->depth); \ - 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; \ - _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 /* _ADC_H_ */ - -/** @} */ diff --git a/os/hal/include/can.h b/os/hal/include/can.h deleted file mode 100644 index 9947b9960..000000000 --- a/os/hal/include/can.h +++ /dev/null @@ -1,156 +0,0 @@ -/* - ChibiOS - Copyright (C) 2006..2016 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 can.h - * @brief CAN Driver macros and structures. - * - * @addtogroup CAN - * @{ - */ - -#ifndef _CAN_H_ -#define _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 0 - -/*===========================================================================*/ -/* 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 -/** @} */ - -/*===========================================================================*/ -/* 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_READY = 3, /**< Ready. */ - CAN_SLEEP = 4 /**< Sleep state. */ -} canstate_t; - -#include "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)) -/** @} */ - -/*===========================================================================*/ -/* 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); - msg_t canTransmit(CANDriver *canp, - canmbx_t mailbox, - const CANTxFrame *ctfp, - systime_t timeout); - msg_t canReceive(CANDriver *canp, - canmbx_t mailbox, - CANRxFrame *crfp, - systime_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 /* _CAN_H_ */ - -/** @} */ diff --git a/os/hal/include/dac.h b/os/hal/include/dac.h deleted file mode 100644 index 19325b61d..000000000 --- a/os/hal/include/dac.h +++ /dev/null @@ -1,267 +0,0 @@ -/* - ChibiOS - Copyright (C) 2006..2016 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 dac.h - * @brief DAC Driver macros and structures. - * - * @addtogroup DAC - * @{ - */ - -#ifndef _DAC_H_ -#define _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; - -#include "dac_lld.h" - -/*===========================================================================*/ -/* Driver macros. */ -/*===========================================================================*/ - -/** - * @name Low level driver helper macros - * @{ - */ -#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, (dacp)->samples, (dacp)->depth / 2); \ - } \ -} - -/** - * @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] dacp pointer to the @p DACDriver object - * - * @notapi - */ -#define _dac_isr_full_code(dacp) { \ - if ((dacp)->grpp->end_cb != NULL) { \ - if ((dacp)->depth > 1) { \ - /* Invokes the callback passing the 2nd half of the buffer.*/ \ - size_t half = (dacp)->depth / 2; \ - size_t half_index = half * (dacp)->grpp->num_channels; \ - (dacp)->grpp->end_cb(dacp, (dacp)->samples + half_index, half); \ - } \ - else { \ - /* Invokes the callback passing the whole buffer.*/ \ - (dacp)->grpp->end_cb(dacp, (dacp)->samples, (dacp)->depth); \ - } \ - } \ -} - -/** - * @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, - const dacsample_t *samples, size_t depth); - void dacStartConversionI(DACDriver *dacp, const DACConversionGroup *grpp, - const 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, - const 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 /* _DAC_H_ */ - -/** @} */ diff --git a/os/hal/include/ext.h b/os/hal/include/ext.h deleted file mode 100644 index 282178e79..000000000 --- a/os/hal/include/ext.h +++ /dev/null @@ -1,150 +0,0 @@ -/* - ChibiOS - Copyright (C) 2006..2016 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 ext.h - * @brief EXT Driver macros and structures. - * - * @addtogroup EXT - * @{ - */ - -#ifndef _EXT_H_ -#define _EXT_H_ - -#if (HAL_USE_EXT == TRUE) || defined(__DOXYGEN__) - -/*===========================================================================*/ -/* Driver constants. */ -/*===========================================================================*/ - -/** - * @name EXT channel modes - * @{ - */ -#define EXT_CH_MODE_EDGES_MASK 3U /**< @brief Mask of edges field. */ -#define EXT_CH_MODE_DISABLED 0U /**< @brief Channel disabled. */ -#define EXT_CH_MODE_RISING_EDGE 1U /**< @brief Rising edge callback. */ -#define EXT_CH_MODE_FALLING_EDGE 2U /**< @brief Falling edge callback. */ -#define EXT_CH_MODE_BOTH_EDGES 3U /**< @brief Both edges callback. */ - -#define EXT_CH_MODE_AUTOSTART 4U /**< @brief Channel started - automatically on driver start. */ -/** @} */ - -/*===========================================================================*/ -/* Driver pre-compile time settings. */ -/*===========================================================================*/ - -/*===========================================================================*/ -/* Derived constants and error checks. */ -/*===========================================================================*/ - -/*===========================================================================*/ -/* Driver data structures and types. */ -/*===========================================================================*/ - -/** - * @brief Driver state machine possible states. - */ -typedef enum { - EXT_UNINIT = 0, /**< Not initialized. */ - EXT_STOP = 1, /**< Stopped. */ - EXT_ACTIVE = 2 /**< Active. */ -} extstate_t; - -/** - * @brief Type of a structure representing a EXT driver. - */ -typedef struct EXTDriver EXTDriver; - -#include "ext_lld.h" - -/*===========================================================================*/ -/* Driver macros. */ -/*===========================================================================*/ - -/** - * @name Macro Functions - * @{ - */ -/** - * @brief Enables an EXT channel. - * - * @param[in] extp pointer to the @p EXTDriver object - * @param[in] channel channel to be enabled - * - * @iclass - */ -#define extChannelEnableI(extp, channel) ext_lld_channel_enable(extp, channel) - -/** - * @brief Disables an EXT channel. - * - * @param[in] extp pointer to the @p EXTDriver object - * @param[in] channel channel to be disabled - * - * @iclass - */ -#define extChannelDisableI(extp, channel) ext_lld_channel_disable(extp, channel) - -/** - * @brief Changes the operation mode of a channel. - * @note This function attempts to write over the current configuration - * structure that must have been not declared constant. This - * violates the @p const qualifier in @p extStart() but it is - * intentional. This function cannot be used if the configuration - * structure is declared @p const. - * - * @param[in] extp pointer to the @p EXTDriver object - * @param[in] channel channel to be changed - * @param[in] extcp new configuration for the channel - * - * @api - */ -#define extSetChannelMode(extp, channel, extcp) { \ - osalSysLock(); \ - extSetChannelModeI(extp, channel, extcp); \ - osalSysUnlock(); \ -} - -/** @} */ - -/*===========================================================================*/ -/* External declarations. */ -/*===========================================================================*/ - -#ifdef __cplusplus -extern "C" { -#endif - void extInit(void); - void extObjectInit(EXTDriver *extp); - void extStart(EXTDriver *extp, const EXTConfig *config); - void extStop(EXTDriver *extp); - void extChannelEnable(EXTDriver *extp, expchannel_t channel); - void extChannelDisable(EXTDriver *extp, expchannel_t channel); - void extSetChannelModeI(EXTDriver *extp, - expchannel_t channel, - const EXTChannelConfig *extcp); -#ifdef __cplusplus -} -#endif - -#endif /* HAL_USE_EXT == TRUE */ - -#endif /* _EXT_H_ */ - -/** @} */ diff --git a/os/hal/include/gpt.h b/os/hal/include/gpt.h deleted file mode 100644 index 38e906bd3..000000000 --- a/os/hal/include/gpt.h +++ /dev/null @@ -1,141 +0,0 @@ -/* - ChibiOS - Copyright (C) 2006..2016 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 gpt.h - * @brief GPT Driver macros and structures. - * - * @addtogroup GPT - * @{ - */ - -#ifndef _GPT_H_ -#define _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 "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) - -/*===========================================================================*/ -/* 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 /* _GPT_H_ */ - -/** @} */ diff --git a/os/hal/include/hal.h b/os/hal/include/hal.h index 2ffd9ab0d..ba7c2c591 100644 --- a/os/hal/include/hal.h +++ b/os/hal/include/hal.h @@ -43,37 +43,36 @@ #include "hal_queues.h" /* Normal drivers.*/ -#include "pal.h" -#include "adc.h" -#include "can.h" -#include "dac.h" -#include "ext.h" -#include "gpt.h" -#include "i2c.h" -#include "i2s.h" -#include "icu.h" -#include "mac.h" -#include "mii.h" -#include "pwm.h" -#include "rtc.h" -#include "serial.h" -#include "sdc.h" -#include "spi.h" -#include "uart.h" -#include "usb.h" -#include "wdg.h" +#include "hal_pal.h" +#include "hal_adc.h" +#include "hal_can.h" +#include "hal_dac.h" +#include "hal_ext.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_spi.h" +#include "hal_uart.h" +#include "hal_usb.h" +#include "hal_wdg.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 "st.h" +#include "hal_st.h" #endif /* Complex drivers.*/ -#include "mmc_spi.h" -#include "serial_usb.h" +#include "hal_mmc_spi.h" +#include "hal_serial_usb.h" /* Community drivers.*/ #if defined(HAL_USE_COMMUNITY) || defined(__DOXYGEN__) @@ -103,17 +102,17 @@ /** * @brief HAL version string. */ -#define HAL_VERSION "4.1.0" +#define HAL_VERSION "5.0.0" /** * @brief HAL version major number. */ -#define CH_HAL_MAJOR 4 +#define CH_HAL_MAJOR 5 /** * @brief HAL version minor number. */ -#define CH_HAL_MINOR 1 +#define CH_HAL_MINOR 0 /** * @brief HAL version patch number. diff --git a/os/hal/include/hal_adc.h b/os/hal/include/hal_adc.h new file mode 100644 index 000000000..142ddfda7 --- /dev/null +++ b/os/hal/include/hal_adc.h @@ -0,0 +1,278 @@ +/* + ChibiOS - Copyright (C) 2006..2016 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 adc.h + * @brief ADC Driver macros and structures. + * + * @addtogroup ADC + * @{ + */ + +#ifndef _ADC_H_ +#define _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 complete. */ +} adcstate_t; + +#include "adc_lld.h" + +/*===========================================================================*/ +/* Driver macros. */ +/*===========================================================================*/ + +/** + * @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, (adcp)->samples, (adcp)->depth / 2); \ + } \ +} + +/** + * @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) { \ + if ((adcp)->depth > 1) { \ + /* Invokes the callback passing the 2nd half of the buffer.*/ \ + size_t half = (adcp)->depth / 2; \ + size_t half_index = half * (adcp)->grpp->num_channels; \ + (adcp)->grpp->end_cb(adcp, (adcp)->samples + half_index, half); \ + } \ + else { \ + /* Invokes the callback passing the whole buffer.*/ \ + (adcp)->grpp->end_cb(adcp, (adcp)->samples, (adcp)->depth); \ + } \ + } \ + } \ + else { \ + /* End conversion.*/ \ + adc_lld_stop_conversion(adcp); \ + if ((adcp)->grpp->end_cb != NULL) { \ + (adcp)->state = ADC_COMPLETE; \ + /* Invoke the callback passing the whole buffer.*/ \ + (adcp)->grpp->end_cb(adcp, (adcp)->samples, (adcp)->depth); \ + 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; \ + _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 /* _ADC_H_ */ + +/** @} */ diff --git a/os/hal/include/hal_can.h b/os/hal/include/hal_can.h new file mode 100644 index 000000000..9947b9960 --- /dev/null +++ b/os/hal/include/hal_can.h @@ -0,0 +1,156 @@ +/* + ChibiOS - Copyright (C) 2006..2016 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 can.h + * @brief CAN Driver macros and structures. + * + * @addtogroup CAN + * @{ + */ + +#ifndef _CAN_H_ +#define _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 0 + +/*===========================================================================*/ +/* 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 +/** @} */ + +/*===========================================================================*/ +/* 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_READY = 3, /**< Ready. */ + CAN_SLEEP = 4 /**< Sleep state. */ +} canstate_t; + +#include "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)) +/** @} */ + +/*===========================================================================*/ +/* 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); + msg_t canTransmit(CANDriver *canp, + canmbx_t mailbox, + const CANTxFrame *ctfp, + systime_t timeout); + msg_t canReceive(CANDriver *canp, + canmbx_t mailbox, + CANRxFrame *crfp, + systime_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 /* _CAN_H_ */ + +/** @} */ diff --git a/os/hal/include/hal_dac.h b/os/hal/include/hal_dac.h new file mode 100644 index 000000000..19325b61d --- /dev/null +++ b/os/hal/include/hal_dac.h @@ -0,0 +1,267 @@ +/* + ChibiOS - Copyright (C) 2006..2016 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 dac.h + * @brief DAC Driver macros and structures. + * + * @addtogroup DAC + * @{ + */ + +#ifndef _DAC_H_ +#define _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; + +#include "dac_lld.h" + +/*===========================================================================*/ +/* Driver macros. */ +/*===========================================================================*/ + +/** + * @name Low level driver helper macros + * @{ + */ +#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, (dacp)->samples, (dacp)->depth / 2); \ + } \ +} + +/** + * @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] dacp pointer to the @p DACDriver object + * + * @notapi + */ +#define _dac_isr_full_code(dacp) { \ + if ((dacp)->grpp->end_cb != NULL) { \ + if ((dacp)->depth > 1) { \ + /* Invokes the callback passing the 2nd half of the buffer.*/ \ + size_t half = (dacp)->depth / 2; \ + size_t half_index = half * (dacp)->grpp->num_channels; \ + (dacp)->grpp->end_cb(dacp, (dacp)->samples + half_index, half); \ + } \ + else { \ + /* Invokes the callback passing the whole buffer.*/ \ + (dacp)->grpp->end_cb(dacp, (dacp)->samples, (dacp)->depth); \ + } \ + } \ +} + +/** + * @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, + const dacsample_t *samples, size_t depth); + void dacStartConversionI(DACDriver *dacp, const DACConversionGroup *grpp, + const 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, + const 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 /* _DAC_H_ */ + +/** @} */ diff --git a/os/hal/include/hal_ext.h b/os/hal/include/hal_ext.h new file mode 100644 index 000000000..282178e79 --- /dev/null +++ b/os/hal/include/hal_ext.h @@ -0,0 +1,150 @@ +/* + ChibiOS - Copyright (C) 2006..2016 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 ext.h + * @brief EXT Driver macros and structures. + * + * @addtogroup EXT + * @{ + */ + +#ifndef _EXT_H_ +#define _EXT_H_ + +#if (HAL_USE_EXT == TRUE) || defined(__DOXYGEN__) + +/*===========================================================================*/ +/* Driver constants. */ +/*===========================================================================*/ + +/** + * @name EXT channel modes + * @{ + */ +#define EXT_CH_MODE_EDGES_MASK 3U /**< @brief Mask of edges field. */ +#define EXT_CH_MODE_DISABLED 0U /**< @brief Channel disabled. */ +#define EXT_CH_MODE_RISING_EDGE 1U /**< @brief Rising edge callback. */ +#define EXT_CH_MODE_FALLING_EDGE 2U /**< @brief Falling edge callback. */ +#define EXT_CH_MODE_BOTH_EDGES 3U /**< @brief Both edges callback. */ + +#define EXT_CH_MODE_AUTOSTART 4U /**< @brief Channel started + automatically on driver start. */ +/** @} */ + +/*===========================================================================*/ +/* Driver pre-compile time settings. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Derived constants and error checks. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Driver data structures and types. */ +/*===========================================================================*/ + +/** + * @brief Driver state machine possible states. + */ +typedef enum { + EXT_UNINIT = 0, /**< Not initialized. */ + EXT_STOP = 1, /**< Stopped. */ + EXT_ACTIVE = 2 /**< Active. */ +} extstate_t; + +/** + * @brief Type of a structure representing a EXT driver. + */ +typedef struct EXTDriver EXTDriver; + +#include "ext_lld.h" + +/*===========================================================================*/ +/* Driver macros. */ +/*===========================================================================*/ + +/** + * @name Macro Functions + * @{ + */ +/** + * @brief Enables an EXT channel. + * + * @param[in] extp pointer to the @p EXTDriver object + * @param[in] channel channel to be enabled + * + * @iclass + */ +#define extChannelEnableI(extp, channel) ext_lld_channel_enable(extp, channel) + +/** + * @brief Disables an EXT channel. + * + * @param[in] extp pointer to the @p EXTDriver object + * @param[in] channel channel to be disabled + * + * @iclass + */ +#define extChannelDisableI(extp, channel) ext_lld_channel_disable(extp, channel) + +/** + * @brief Changes the operation mode of a channel. + * @note This function attempts to write over the current configuration + * structure that must have been not declared constant. This + * violates the @p const qualifier in @p extStart() but it is + * intentional. This function cannot be used if the configuration + * structure is declared @p const. + * + * @param[in] extp pointer to the @p EXTDriver object + * @param[in] channel channel to be changed + * @param[in] extcp new configuration for the channel + * + * @api + */ +#define extSetChannelMode(extp, channel, extcp) { \ + osalSysLock(); \ + extSetChannelModeI(extp, channel, extcp); \ + osalSysUnlock(); \ +} + +/** @} */ + +/*===========================================================================*/ +/* External declarations. */ +/*===========================================================================*/ + +#ifdef __cplusplus +extern "C" { +#endif + void extInit(void); + void extObjectInit(EXTDriver *extp); + void extStart(EXTDriver *extp, const EXTConfig *config); + void extStop(EXTDriver *extp); + void extChannelEnable(EXTDriver *extp, expchannel_t channel); + void extChannelDisable(EXTDriver *extp, expchannel_t channel); + void extSetChannelModeI(EXTDriver *extp, + expchannel_t channel, + const EXTChannelConfig *extcp); +#ifdef __cplusplus +} +#endif + +#endif /* HAL_USE_EXT == TRUE */ + +#endif /* _EXT_H_ */ + +/** @} */ diff --git a/os/hal/include/hal_gpt.h b/os/hal/include/hal_gpt.h new file mode 100644 index 000000000..38e906bd3 --- /dev/null +++ b/os/hal/include/hal_gpt.h @@ -0,0 +1,141 @@ +/* + ChibiOS - Copyright (C) 2006..2016 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 gpt.h + * @brief GPT Driver macros and structures. + * + * @addtogroup GPT + * @{ + */ + +#ifndef _GPT_H_ +#define _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 "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) + +/*===========================================================================*/ +/* 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 /* _GPT_H_ */ + +/** @} */ diff --git a/os/hal/include/hal_i2c.h b/os/hal/include/hal_i2c.h new file mode 100644 index 000000000..fb8cabad7 --- /dev/null +++ b/os/hal/include/hal_i2c.h @@ -0,0 +1,166 @@ +/* + ChibiOS - Copyright (C) 2006..2016 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 i2c.h + * @brief I2C Driver macros and structures. + * + * @addtogroup I2C + * @{ + */ + +#ifndef _I2C_H_ +#define _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, /**< Not initialized. */ + I2C_STOP = 1, /**< Stopped. */ + I2C_READY = 2, /**< Ready. */ + I2C_ACTIVE_TX = 3, /**< Transmitting. */ + I2C_ACTIVE_RX = 4, /**< Receiving. */ + I2C_LOCKED = 5 /**> Bus or driver locked. */ +} i2cstate_t; + +#include "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, + systime_t timeout); + msg_t i2cMasterReceiveTimeout(I2CDriver *i2cp, + i2caddr_t addr, + uint8_t *rxbuf, size_t rxbytes, + systime_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 /* _I2C_H_ */ + +/** @} */ diff --git a/os/hal/include/hal_i2s.h b/os/hal/include/hal_i2s.h new file mode 100644 index 000000000..a759b8455 --- /dev/null +++ b/os/hal/include/hal_i2s.h @@ -0,0 +1,167 @@ +/* + ChibiOS - Copyright (C) 2006..2016 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 i2s.h + * @brief I2S Driver macros and structures. + * + * @addtogroup I2S + * @{ + */ + +#ifndef _I2S_H_ +#define _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; + +#include "i2s_lld.h" + +/*===========================================================================*/ +/* Driver macros. */ +/*===========================================================================*/ + +/** + * @name Macro Functions + * @{ + */ +/** + * @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, 0, (i2sp)->config->size / 2); \ + } \ +} + +/** + * @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, \ + (i2sp)->config->size / 2, \ + (i2sp)->config->size / 2); \ + if ((i2sp)->state == I2S_COMPLETE) \ + (i2sp)->state = I2S_READY; \ + } \ + else \ + (i2sp)->state = I2S_READY; \ +} +/** @} */ + +/*===========================================================================*/ +/* 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 /* _I2S_H_ */ + +/** @} */ diff --git a/os/hal/include/hal_icu.h b/os/hal/include/hal_icu.h new file mode 100644 index 000000000..262b646fd --- /dev/null +++ b/os/hal/include/hal_icu.h @@ -0,0 +1,238 @@ +/* + ChibiOS - Copyright (C) 2006..2016 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 icu.h + * @brief ICU Driver macros and structures. + * + * @addtogroup ICU + * @{ + */ + +#ifndef _ICU_H_ +#define _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 "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(). + * @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(). + * @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 /* _ICU_H_ */ + +/** @} */ diff --git a/os/hal/include/hal_mac.h b/os/hal/include/hal_mac.h new file mode 100644 index 000000000..b5c49d01c --- /dev/null +++ b/os/hal/include/hal_mac.h @@ -0,0 +1,204 @@ +/* + ChibiOS - Copyright (C) 2006..2016 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 mac.h + * @brief MAC Driver macros and structures. + * @addtogroup MAC + * @{ + */ + +#ifndef _MAC_H_ +#define _MAC_H_ + +#if (HAL_USE_MAC == TRUE) || defined(__DOXYGEN__) + +#include "mii.h" + +/*===========================================================================*/ +/* 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 "mac_lld.h" + +/*===========================================================================*/ +/* Driver macros. */ +/*===========================================================================*/ + +/** + * @name Macro Functions + * @{ + */ +/** + * @brief Returns the received frames event source. + * + * @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, + systime_t timeout); + void macReleaseTransmitDescriptor(MACTransmitDescriptor *tdp); + msg_t macWaitReceiveDescriptor(MACDriver *macp, + MACReceiveDescriptor *rdp, + systime_t timeout); + void macReleaseReceiveDescriptor(MACReceiveDescriptor *rdp); + bool macPollLinkStatus(MACDriver *macp); +#ifdef __cplusplus +} +#endif + +#endif /* HAL_USE_MAC == TRUE */ + +#endif /* _MAC_H_ */ + +/** @} */ diff --git a/os/hal/include/hal_mmc_spi.h b/os/hal/include/hal_mmc_spi.h new file mode 100644 index 000000000..7c9a60cae --- /dev/null +++ b/os/hal/include/hal_mmc_spi.h @@ -0,0 +1,195 @@ +/* + ChibiOS - Copyright (C) 2006..2016 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 mmc_spi.h + * @brief MMC over SPI driver header. + * + * @addtogroup MMC_SPI + * @{ + */ + +#ifndef _MMC_SPI_H_ +#define _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 /* _MMC_SPI_H_ */ + +/** @} */ diff --git a/os/hal/include/hal_pal.h b/os/hal/include/hal_pal.h new file mode 100644 index 000000000..df22f3e94 --- /dev/null +++ b/os/hal/include/hal_pal.h @@ -0,0 +1,642 @@ +/* + ChibiOS - Copyright (C) 2006..2016 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 pal.h + * @brief I/O Ports Abstraction Layer macros, types and structures. + * + * @addtogroup PAL + * @{ + */ + +#ifndef _PAL_H_ +#define _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 unconnected 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 +/** @} */ + +/*===========================================================================*/ +/* Driver pre-compile time settings. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Derived constants and error checks. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Driver data structures and types. */ +/*===========================================================================*/ + +#include "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) + +/** + * @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. + * + * @param[in] config pointer to an architecture specific configuration + * structure. This structure is defined in the low level driver + * header. + * + * @init + */ +#define palInit(config) pal_lld_init(config) + +/** + * @brief Reads the physical I/O port states. + * @note The default implementation always return zero and computes the + * parameter eventual side effects. + * @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 default implementation always return zero and computes the + * parameter eventual side effects. + * @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 default implementation does nothing except computing the + * parameters eventual side effects. + * @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 default implementation is non atomic and not necessarily + * optimal. Low level drivers may optimize the function by using + * specific hardware or coding. + * @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 default implementation is non atomic and not necessarily + * optimal. Low level drivers may optimize the function by using + * specific hardware or coding. + * @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 default implementation is non atomic and not necessarily + * optimal. Low level drivers may optimize the function by using + * specific hardware or coding. + * @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 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 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 default implementation not necessarily optimal. Low level + * drivers may optimize the function by using specific hardware + * or coding. + * @note The default implementation internally uses the @p palReadPort(). + * @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 default implementation is non atomic and not necessarily + * optimal. Low level drivers may optimize the function by using + * specific hardware or coding. + * @note The default implementation internally uses the @p palReadLatch() + * and @p palWritePort(). + * @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 default implementation is non atomic and not necessarily + * optimal. Low level drivers may optimize the function by using + * specific hardware or coding. + * @note The default implementation internally uses the @p palSetPort(). + * @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 default implementation is non atomic and not necessarily + * optimal. Low level drivers may optimize the function by using + * specific hardware or coding. + * @note The default implementation internally uses the @p palClearPort(). + * @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 default implementation is non atomic and not necessarily + * optimal. Low level drivers may optimize the function by using + * specific hardware or coding. + * @note The default implementation internally uses the @p palTogglePort(). + * @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 default implementation not necessarily optimal. Low level + * drivers may optimize the function by using specific hardware + * or coding. + * @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 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 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 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 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 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 +/** @} */ + +/*===========================================================================*/ +/* External declarations. */ +/*===========================================================================*/ + +#ifdef __cplusplus +extern "C" { +#endif + ioportmask_t palReadBus(IOBus *bus); + void palWriteBus(IOBus *bus, ioportmask_t bits); + void palSetBusMode(IOBus *bus, iomode_t mode); +#ifdef __cplusplus +} +#endif + +#endif /* _PAL_H_ */ + +#endif /* HAL_USE_PAL == TRUE */ + +/** @} */ diff --git a/os/hal/include/hal_pwm.h b/os/hal/include/hal_pwm.h new file mode 100644 index 000000000..5704b40bc --- /dev/null +++ b/os/hal/include/hal_pwm.h @@ -0,0 +1,308 @@ +/* + ChibiOS - Copyright (C) 2006..2016 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 pwm.h + * @brief PWM Driver macros and structures. + * + * @addtogroup PWM + * @{ + */ + +#ifndef _PWM_H_ +#define _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 "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 /* _PWM_H_ */ + +/** @} */ diff --git a/os/hal/include/hal_rtc.h b/os/hal/include/hal_rtc.h new file mode 100644 index 000000000..e4c32ba64 --- /dev/null +++ b/os/hal/include/hal_rtc.h @@ -0,0 +1,144 @@ +/* + ChibiOS - Copyright (C) 2006..2016 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 rtc.h + * @brief RTC Driver macros and structures. + * + * @addtogroup RTC + * @{ + */ + +#ifndef _RTC_H_ +#define _RTC_H_ + +#if (HAL_USE_RTC == TRUE) || defined(__DOXYGEN__) + +/*lint -save -e829 [21.10] The header is required.*/ +#include +/*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 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; + +#include "rtc_lld.h" + +/*===========================================================================*/ +/* Driver macros. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* External declarations. */ +/*===========================================================================*/ + +#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 /* _RTC_H_ */ + +/** @} */ diff --git a/os/hal/include/hal_sdc.h b/os/hal/include/hal_sdc.h new file mode 100644 index 000000000..954688658 --- /dev/null +++ b/os/hal/include/hal_sdc.h @@ -0,0 +1,195 @@ +/* + ChibiOS - Copyright (C) 2006..2016 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 sdc.h + * @brief SDC Driver macros and structures. + * + * @addtogroup SDC + * @{ + */ + +#ifndef _SDC_H_ +#define _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 +/** @} */ + +/*===========================================================================*/ +/* 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 "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 /* _SDC_H_ */ + +/** @} */ diff --git a/os/hal/include/hal_serial.h b/os/hal/include/hal_serial.h new file mode 100644 index 000000000..814d54569 --- /dev/null +++ b/os/hal/include/hal_serial.h @@ -0,0 +1,286 @@ +/* + ChibiOS - Copyright (C) 2006..2016 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 serial.h + * @brief Serial Driver macros and structures. + * + * @addtogroup SERIAL + * @{ + */ + +#ifndef _SERIAL_H_ +#define _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. */ +/** @} */ + +/*===========================================================================*/ +/* 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. + */ +#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 "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. + * + * @see chnPutTimeout() + * + * @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. + * + * @see chnPutTimeout() + * + * @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. + * + * @see chnGetTimeout() + * + * @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. + * + * @see chnGetTimeout() + * + * @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. + * + * @see chnWrite() + * + * @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. + * + * @see chnWriteTimeout() + * + * @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. + * + * @see chnWriteTimeout() + * + * @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. + * + * @see chnRead() + * + * @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. + * + * @see chnReadTimeout() + * + * @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. + * + * @see chnReadTimeout() + * + * @api + */ +#define sdAsynchronousRead(sdp, b, n) \ + iqReadTimeout(&(sdp)->iqueue, b, n, TIME_IMMEDIATE) +/** @} */ + +/*===========================================================================*/ +/* External declarations. */ +/*===========================================================================*/ + +#ifdef __cplusplus +extern "C" { +#endif + void sdInit(void); + void sdObjectInit(SerialDriver *sdp, qnotify_t inotify, qnotify_t onotify); + 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); +#ifdef __cplusplus +} +#endif + +#endif /* HAL_USE_SERIAL == TRUE */ + +#endif /* _SERIAL_H_ */ + +/** @} */ diff --git a/os/hal/include/hal_serial_usb.h b/os/hal/include/hal_serial_usb.h new file mode 100644 index 000000000..d4a1a1b57 --- /dev/null +++ b/os/hal/include/hal_serial_usb.h @@ -0,0 +1,195 @@ +/* + ChibiOS - Copyright (C) 2006..2016 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 serial_usb.h + * @brief Serial over USB Driver macros and structures. + * + * @addtogroup SERIAL_USB + * @{ + */ + +#ifndef _SERIAL_USB_H_ +#define _SERIAL_USB_H_ + +#if (HAL_USE_SERIAL_USB == TRUE) || defined(__DOXYGEN__) + +#include "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 sduDisconnectI(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); +#ifdef __cplusplus +} +#endif + +#endif /* HAL_USE_SERIAL_USB == TRUE */ + +#endif /* _SERIAL_USB_H_ */ + +/** @} */ diff --git a/os/hal/include/hal_spi.h b/os/hal/include/hal_spi.h new file mode 100644 index 000000000..45dd0880b --- /dev/null +++ b/os/hal/include/hal_spi.h @@ -0,0 +1,291 @@ +/* + ChibiOS - Copyright (C) 2006..2016 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 spi.h + * @brief SPI Driver macros and structures. + * + * @addtogroup SPI + * @{ + */ + +#ifndef _SPI_H_ +#define _SPI_H_ + +#if (HAL_USE_SPI == TRUE) || defined(__DOXYGEN__) + +/*===========================================================================*/ +/* Driver constants. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* 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 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 +/** @} */ + +/*===========================================================================*/ +/* Derived constants and error checks. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* 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; + +#include "spi_lld.h" + +/*===========================================================================*/ +/* Driver macros. */ +/*===========================================================================*/ + +/** + * @name Macro Functions + * @{ + */ +/** + * @brief Asserts the slave select signal and prepares for transfers. + * + * @param[in] spip pointer to the @p SPIDriver object + * + * @iclass + */ +#define spiSelectI(spip) { \ + spi_lld_select(spip); \ +} + +/** + * @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) { \ + spi_lld_unselect(spip); \ +} + +/** + * @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. + * @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); \ +} +/** @} */ + +/*===========================================================================*/ +/* 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_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 /* _SPI_H_ */ + +/** @} */ diff --git a/os/hal/include/hal_st.h b/os/hal/include/hal_st.h new file mode 100644 index 000000000..3bd50e854 --- /dev/null +++ b/os/hal/include/hal_st.h @@ -0,0 +1,97 @@ +/* + ChibiOS - Copyright (C) 2006..2016 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 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 _ST_H_ +#define _ST_H_ + +/*===========================================================================*/ +/* Driver constants. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Driver pre-compile time settings. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Derived constants and error checks. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Driver data structures and types. */ +/*===========================================================================*/ + +#include "st_lld.h" + +/*===========================================================================*/ +/* Driver macros. */ +/*===========================================================================*/ + +/** + * @name Macro Functions + * @{ + */ +/** + * @brief Returns the time counter value. + * @note This functionality is only available in free running mode, the + * behaviour in periodic mode is undefined. + * + * @return The counter value. + * + * @api + */ +#define stGetCounter() st_lld_get_counter() + +/** + * @brief Determines if the alarm is active. + * + * @return The alarm status. + * @retval false if the alarm is not active. + * @retval true is the alarm is active + * + * @api + */ +#define stIsAlarmActive() st_lld_is_alarm_active() +/** @} */ + +/*===========================================================================*/ +/* External declarations. */ +/*===========================================================================*/ + +#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); +#ifdef __cplusplus +} +#endif + +#endif /* _ST_H_ */ + +/** @} */ diff --git a/os/hal/include/hal_uart.h b/os/hal/include/hal_uart.h new file mode 100644 index 000000000..a0a8eecdf --- /dev/null +++ b/os/hal/include/hal_uart.h @@ -0,0 +1,342 @@ +/* + ChibiOS - Copyright (C) 2006..2016 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 uart.h + * @brief UART Driver macros and structures. + * + * @addtogroup UART + * @{ + */ + +#ifndef _UART_H_ +#define _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. */ +/** @} */ + +/*===========================================================================*/ +/* 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 "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 */ + +/** + * @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); \ +} +/** @} */ + +/*===========================================================================*/ +/* 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, systime_t timeout); + msg_t uartSendFullTimeout(UARTDriver *uartp, size_t *np, + const void *txbuf, systime_t timeout); + msg_t uartReceiveTimeout(UARTDriver *uartp, size_t *np, + void *rxbuf, systime_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 /* _UART_H_ */ + +/** @} */ diff --git a/os/hal/include/hal_usb.h b/os/hal/include/hal_usb.h new file mode 100644 index 000000000..15d72cc43 --- /dev/null +++ b/os/hal/include/hal_usb.h @@ -0,0 +1,633 @@ +/* + ChibiOS - Copyright (C) 2006..2016 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 usb.h + * @brief USB Driver macros and structures. + * + * @addtogroup USB + * @{ + */ + +#ifndef _USB_H_ +#define _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. */ +/** @} */ + +/*===========================================================================*/ +/* 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_WAITING_SETUP, /**< Waiting for SETUP data. */ + USB_EP0_TX, /**< Transmitting. */ + USB_EP0_WAITING_TX0, /**< Waiting transmit 0. */ + USB_EP0_WAITING_STS, /**< Waiting status. */ + USB_EP0_RX, /**< Receiving. */ + USB_EP0_SENDING_STS, /**< Sending status. */ + USB_EP0_ERROR /**< 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_SUSPEND = 3, /**< Entering suspend mode. */ + USB_EVENT_WAKEUP = 4, /**< Leaving suspend mode. */ + USB_EVENT_STALLED = 5 /**< 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 "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 _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 /* _USB_H_ */ + +/** @} */ diff --git a/os/hal/include/hal_wdg.h b/os/hal/include/hal_wdg.h new file mode 100644 index 000000000..d10b4a73f --- /dev/null +++ b/os/hal/include/hal_wdg.h @@ -0,0 +1,89 @@ +/* + ChibiOS - Copyright (C) 2006..2016 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 wdg.h + * @brief WDG Driver macros and structures. + * + * @addtogroup WDG + * @{ + */ + +#ifndef _WDG_H_ +#define _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 "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 /* _WDG_H_ */ + +/** @} */ diff --git a/os/hal/include/i2c.h b/os/hal/include/i2c.h deleted file mode 100644 index fb8cabad7..000000000 --- a/os/hal/include/i2c.h +++ /dev/null @@ -1,166 +0,0 @@ -/* - ChibiOS - Copyright (C) 2006..2016 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 i2c.h - * @brief I2C Driver macros and structures. - * - * @addtogroup I2C - * @{ - */ - -#ifndef _I2C_H_ -#define _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, /**< Not initialized. */ - I2C_STOP = 1, /**< Stopped. */ - I2C_READY = 2, /**< Ready. */ - I2C_ACTIVE_TX = 3, /**< Transmitting. */ - I2C_ACTIVE_RX = 4, /**< Receiving. */ - I2C_LOCKED = 5 /**> Bus or driver locked. */ -} i2cstate_t; - -#include "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, - systime_t timeout); - msg_t i2cMasterReceiveTimeout(I2CDriver *i2cp, - i2caddr_t addr, - uint8_t *rxbuf, size_t rxbytes, - systime_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 /* _I2C_H_ */ - -/** @} */ diff --git a/os/hal/include/i2s.h b/os/hal/include/i2s.h deleted file mode 100644 index a759b8455..000000000 --- a/os/hal/include/i2s.h +++ /dev/null @@ -1,167 +0,0 @@ -/* - ChibiOS - Copyright (C) 2006..2016 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 i2s.h - * @brief I2S Driver macros and structures. - * - * @addtogroup I2S - * @{ - */ - -#ifndef _I2S_H_ -#define _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; - -#include "i2s_lld.h" - -/*===========================================================================*/ -/* Driver macros. */ -/*===========================================================================*/ - -/** - * @name Macro Functions - * @{ - */ -/** - * @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, 0, (i2sp)->config->size / 2); \ - } \ -} - -/** - * @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, \ - (i2sp)->config->size / 2, \ - (i2sp)->config->size / 2); \ - if ((i2sp)->state == I2S_COMPLETE) \ - (i2sp)->state = I2S_READY; \ - } \ - else \ - (i2sp)->state = I2S_READY; \ -} -/** @} */ - -/*===========================================================================*/ -/* 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 /* _I2S_H_ */ - -/** @} */ diff --git a/os/hal/include/icu.h b/os/hal/include/icu.h deleted file mode 100644 index 262b646fd..000000000 --- a/os/hal/include/icu.h +++ /dev/null @@ -1,238 +0,0 @@ -/* - ChibiOS - Copyright (C) 2006..2016 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 icu.h - * @brief ICU Driver macros and structures. - * - * @addtogroup ICU - * @{ - */ - -#ifndef _ICU_H_ -#define _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 "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(). - * @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(). - * @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 /* _ICU_H_ */ - -/** @} */ diff --git a/os/hal/include/mac.h b/os/hal/include/mac.h deleted file mode 100644 index 44bfcafab..000000000 --- a/os/hal/include/mac.h +++ /dev/null @@ -1,202 +0,0 @@ -/* - ChibiOS - Copyright (C) 2006..2016 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 mac.h - * @brief MAC Driver macros and structures. - * @addtogroup MAC - * @{ - */ - -#ifndef _MAC_H_ -#define _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 "mac_lld.h" - -/*===========================================================================*/ -/* Driver macros. */ -/*===========================================================================*/ - -/** - * @name Macro Functions - * @{ - */ -/** - * @brief Returns the received frames event source. - * - * @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, - systime_t timeout); - void macReleaseTransmitDescriptor(MACTransmitDescriptor *tdp); - msg_t macWaitReceiveDescriptor(MACDriver *macp, - MACReceiveDescriptor *rdp, - systime_t timeout); - void macReleaseReceiveDescriptor(MACReceiveDescriptor *rdp); - bool macPollLinkStatus(MACDriver *macp); -#ifdef __cplusplus -} -#endif - -#endif /* HAL_USE_MAC == TRUE */ - -#endif /* _MAC_H_ */ - -/** @} */ diff --git a/os/hal/include/mmc_spi.h b/os/hal/include/mmc_spi.h deleted file mode 100644 index 7c9a60cae..000000000 --- a/os/hal/include/mmc_spi.h +++ /dev/null @@ -1,195 +0,0 @@ -/* - ChibiOS - Copyright (C) 2006..2016 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 mmc_spi.h - * @brief MMC over SPI driver header. - * - * @addtogroup MMC_SPI - * @{ - */ - -#ifndef _MMC_SPI_H_ -#define _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 /* _MMC_SPI_H_ */ - -/** @} */ diff --git a/os/hal/include/pal.h b/os/hal/include/pal.h deleted file mode 100644 index df22f3e94..000000000 --- a/os/hal/include/pal.h +++ /dev/null @@ -1,642 +0,0 @@ -/* - ChibiOS - Copyright (C) 2006..2016 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 pal.h - * @brief I/O Ports Abstraction Layer macros, types and structures. - * - * @addtogroup PAL - * @{ - */ - -#ifndef _PAL_H_ -#define _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 unconnected 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 -/** @} */ - -/*===========================================================================*/ -/* Driver pre-compile time settings. */ -/*===========================================================================*/ - -/*===========================================================================*/ -/* Derived constants and error checks. */ -/*===========================================================================*/ - -/*===========================================================================*/ -/* Driver data structures and types. */ -/*===========================================================================*/ - -#include "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) - -/** - * @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. - * - * @param[in] config pointer to an architecture specific configuration - * structure. This structure is defined in the low level driver - * header. - * - * @init - */ -#define palInit(config) pal_lld_init(config) - -/** - * @brief Reads the physical I/O port states. - * @note The default implementation always return zero and computes the - * parameter eventual side effects. - * @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 default implementation always return zero and computes the - * parameter eventual side effects. - * @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 default implementation does nothing except computing the - * parameters eventual side effects. - * @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 default implementation is non atomic and not necessarily - * optimal. Low level drivers may optimize the function by using - * specific hardware or coding. - * @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 default implementation is non atomic and not necessarily - * optimal. Low level drivers may optimize the function by using - * specific hardware or coding. - * @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 default implementation is non atomic and not necessarily - * optimal. Low level drivers may optimize the function by using - * specific hardware or coding. - * @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 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 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 default implementation not necessarily optimal. Low level - * drivers may optimize the function by using specific hardware - * or coding. - * @note The default implementation internally uses the @p palReadPort(). - * @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 default implementation is non atomic and not necessarily - * optimal. Low level drivers may optimize the function by using - * specific hardware or coding. - * @note The default implementation internally uses the @p palReadLatch() - * and @p palWritePort(). - * @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 default implementation is non atomic and not necessarily - * optimal. Low level drivers may optimize the function by using - * specific hardware or coding. - * @note The default implementation internally uses the @p palSetPort(). - * @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 default implementation is non atomic and not necessarily - * optimal. Low level drivers may optimize the function by using - * specific hardware or coding. - * @note The default implementation internally uses the @p palClearPort(). - * @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 default implementation is non atomic and not necessarily - * optimal. Low level drivers may optimize the function by using - * specific hardware or coding. - * @note The default implementation internally uses the @p palTogglePort(). - * @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 default implementation not necessarily optimal. Low level - * drivers may optimize the function by using specific hardware - * or coding. - * @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 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 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 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 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 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 -/** @} */ - -/*===========================================================================*/ -/* External declarations. */ -/*===========================================================================*/ - -#ifdef __cplusplus -extern "C" { -#endif - ioportmask_t palReadBus(IOBus *bus); - void palWriteBus(IOBus *bus, ioportmask_t bits); - void palSetBusMode(IOBus *bus, iomode_t mode); -#ifdef __cplusplus -} -#endif - -#endif /* _PAL_H_ */ - -#endif /* HAL_USE_PAL == TRUE */ - -/** @} */ diff --git a/os/hal/include/pwm.h b/os/hal/include/pwm.h deleted file mode 100644 index 5704b40bc..000000000 --- a/os/hal/include/pwm.h +++ /dev/null @@ -1,308 +0,0 @@ -/* - ChibiOS - Copyright (C) 2006..2016 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 pwm.h - * @brief PWM Driver macros and structures. - * - * @addtogroup PWM - * @{ - */ - -#ifndef _PWM_H_ -#define _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 "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 /* _PWM_H_ */ - -/** @} */ diff --git a/os/hal/include/rtc.h b/os/hal/include/rtc.h deleted file mode 100644 index e4c32ba64..000000000 --- a/os/hal/include/rtc.h +++ /dev/null @@ -1,144 +0,0 @@ -/* - ChibiOS - Copyright (C) 2006..2016 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 rtc.h - * @brief RTC Driver macros and structures. - * - * @addtogroup RTC - * @{ - */ - -#ifndef _RTC_H_ -#define _RTC_H_ - -#if (HAL_USE_RTC == TRUE) || defined(__DOXYGEN__) - -/*lint -save -e829 [21.10] The header is required.*/ -#include -/*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 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; - -#include "rtc_lld.h" - -/*===========================================================================*/ -/* Driver macros. */ -/*===========================================================================*/ - -/*===========================================================================*/ -/* External declarations. */ -/*===========================================================================*/ - -#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 /* _RTC_H_ */ - -/** @} */ diff --git a/os/hal/include/sdc.h b/os/hal/include/sdc.h deleted file mode 100644 index 954688658..000000000 --- a/os/hal/include/sdc.h +++ /dev/null @@ -1,195 +0,0 @@ -/* - ChibiOS - Copyright (C) 2006..2016 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 sdc.h - * @brief SDC Driver macros and structures. - * - * @addtogroup SDC - * @{ - */ - -#ifndef _SDC_H_ -#define _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 -/** @} */ - -/*===========================================================================*/ -/* 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 "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 /* _SDC_H_ */ - -/** @} */ diff --git a/os/hal/include/serial.h b/os/hal/include/serial.h deleted file mode 100644 index 814d54569..000000000 --- a/os/hal/include/serial.h +++ /dev/null @@ -1,286 +0,0 @@ -/* - ChibiOS - Copyright (C) 2006..2016 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 serial.h - * @brief Serial Driver macros and structures. - * - * @addtogroup SERIAL - * @{ - */ - -#ifndef _SERIAL_H_ -#define _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. */ -/** @} */ - -/*===========================================================================*/ -/* 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. - */ -#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 "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. - * - * @see chnPutTimeout() - * - * @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. - * - * @see chnPutTimeout() - * - * @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. - * - * @see chnGetTimeout() - * - * @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. - * - * @see chnGetTimeout() - * - * @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. - * - * @see chnWrite() - * - * @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. - * - * @see chnWriteTimeout() - * - * @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. - * - * @see chnWriteTimeout() - * - * @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. - * - * @see chnRead() - * - * @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. - * - * @see chnReadTimeout() - * - * @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. - * - * @see chnReadTimeout() - * - * @api - */ -#define sdAsynchronousRead(sdp, b, n) \ - iqReadTimeout(&(sdp)->iqueue, b, n, TIME_IMMEDIATE) -/** @} */ - -/*===========================================================================*/ -/* External declarations. */ -/*===========================================================================*/ - -#ifdef __cplusplus -extern "C" { -#endif - void sdInit(void); - void sdObjectInit(SerialDriver *sdp, qnotify_t inotify, qnotify_t onotify); - 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); -#ifdef __cplusplus -} -#endif - -#endif /* HAL_USE_SERIAL == TRUE */ - -#endif /* _SERIAL_H_ */ - -/** @} */ diff --git a/os/hal/include/serial_usb.h b/os/hal/include/serial_usb.h deleted file mode 100644 index d4a1a1b57..000000000 --- a/os/hal/include/serial_usb.h +++ /dev/null @@ -1,195 +0,0 @@ -/* - ChibiOS - Copyright (C) 2006..2016 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 serial_usb.h - * @brief Serial over USB Driver macros and structures. - * - * @addtogroup SERIAL_USB - * @{ - */ - -#ifndef _SERIAL_USB_H_ -#define _SERIAL_USB_H_ - -#if (HAL_USE_SERIAL_USB == TRUE) || defined(__DOXYGEN__) - -#include "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 sduDisconnectI(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); -#ifdef __cplusplus -} -#endif - -#endif /* HAL_USE_SERIAL_USB == TRUE */ - -#endif /* _SERIAL_USB_H_ */ - -/** @} */ diff --git a/os/hal/include/spi.h b/os/hal/include/spi.h deleted file mode 100644 index 45dd0880b..000000000 --- a/os/hal/include/spi.h +++ /dev/null @@ -1,291 +0,0 @@ -/* - ChibiOS - Copyright (C) 2006..2016 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 spi.h - * @brief SPI Driver macros and structures. - * - * @addtogroup SPI - * @{ - */ - -#ifndef _SPI_H_ -#define _SPI_H_ - -#if (HAL_USE_SPI == TRUE) || defined(__DOXYGEN__) - -/*===========================================================================*/ -/* Driver constants. */ -/*===========================================================================*/ - -/*===========================================================================*/ -/* 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 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 -/** @} */ - -/*===========================================================================*/ -/* Derived constants and error checks. */ -/*===========================================================================*/ - -/*===========================================================================*/ -/* 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; - -#include "spi_lld.h" - -/*===========================================================================*/ -/* Driver macros. */ -/*===========================================================================*/ - -/** - * @name Macro Functions - * @{ - */ -/** - * @brief Asserts the slave select signal and prepares for transfers. - * - * @param[in] spip pointer to the @p SPIDriver object - * - * @iclass - */ -#define spiSelectI(spip) { \ - spi_lld_select(spip); \ -} - -/** - * @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) { \ - spi_lld_unselect(spip); \ -} - -/** - * @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. - * @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); \ -} -/** @} */ - -/*===========================================================================*/ -/* 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_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 /* _SPI_H_ */ - -/** @} */ diff --git a/os/hal/include/st.h b/os/hal/include/st.h deleted file mode 100644 index 3bd50e854..000000000 --- a/os/hal/include/st.h +++ /dev/null @@ -1,97 +0,0 @@ -/* - ChibiOS - Copyright (C) 2006..2016 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 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 _ST_H_ -#define _ST_H_ - -/*===========================================================================*/ -/* Driver constants. */ -/*===========================================================================*/ - -/*===========================================================================*/ -/* Driver pre-compile time settings. */ -/*===========================================================================*/ - -/*===========================================================================*/ -/* Derived constants and error checks. */ -/*===========================================================================*/ - -/*===========================================================================*/ -/* Driver data structures and types. */ -/*===========================================================================*/ - -#include "st_lld.h" - -/*===========================================================================*/ -/* Driver macros. */ -/*===========================================================================*/ - -/** - * @name Macro Functions - * @{ - */ -/** - * @brief Returns the time counter value. - * @note This functionality is only available in free running mode, the - * behaviour in periodic mode is undefined. - * - * @return The counter value. - * - * @api - */ -#define stGetCounter() st_lld_get_counter() - -/** - * @brief Determines if the alarm is active. - * - * @return The alarm status. - * @retval false if the alarm is not active. - * @retval true is the alarm is active - * - * @api - */ -#define stIsAlarmActive() st_lld_is_alarm_active() -/** @} */ - -/*===========================================================================*/ -/* External declarations. */ -/*===========================================================================*/ - -#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); -#ifdef __cplusplus -} -#endif - -#endif /* _ST_H_ */ - -/** @} */ diff --git a/os/hal/include/uart.h b/os/hal/include/uart.h deleted file mode 100644 index a0a8eecdf..000000000 --- a/os/hal/include/uart.h +++ /dev/null @@ -1,342 +0,0 @@ -/* - ChibiOS - Copyright (C) 2006..2016 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 uart.h - * @brief UART Driver macros and structures. - * - * @addtogroup UART - * @{ - */ - -#ifndef _UART_H_ -#define _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. */ -/** @} */ - -/*===========================================================================*/ -/* 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 "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 */ - -/** - * @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); \ -} -/** @} */ - -/*===========================================================================*/ -/* 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, systime_t timeout); - msg_t uartSendFullTimeout(UARTDriver *uartp, size_t *np, - const void *txbuf, systime_t timeout); - msg_t uartReceiveTimeout(UARTDriver *uartp, size_t *np, - void *rxbuf, systime_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 /* _UART_H_ */ - -/** @} */ diff --git a/os/hal/include/usb.h b/os/hal/include/usb.h deleted file mode 100644 index 15d72cc43..000000000 --- a/os/hal/include/usb.h +++ /dev/null @@ -1,633 +0,0 @@ -/* - ChibiOS - Copyright (C) 2006..2016 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 usb.h - * @brief USB Driver macros and structures. - * - * @addtogroup USB - * @{ - */ - -#ifndef _USB_H_ -#define _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. */ -/** @} */ - -/*===========================================================================*/ -/* 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_WAITING_SETUP, /**< Waiting for SETUP data. */ - USB_EP0_TX, /**< Transmitting. */ - USB_EP0_WAITING_TX0, /**< Waiting transmit 0. */ - USB_EP0_WAITING_STS, /**< Waiting status. */ - USB_EP0_RX, /**< Receiving. */ - USB_EP0_SENDING_STS, /**< Sending status. */ - USB_EP0_ERROR /**< 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_SUSPEND = 3, /**< Entering suspend mode. */ - USB_EVENT_WAKEUP = 4, /**< Leaving suspend mode. */ - USB_EVENT_STALLED = 5 /**< 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 "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 _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 /* _USB_H_ */ - -/** @} */ diff --git a/os/hal/include/wdg.h b/os/hal/include/wdg.h deleted file mode 100644 index d10b4a73f..000000000 --- a/os/hal/include/wdg.h +++ /dev/null @@ -1,89 +0,0 @@ -/* - ChibiOS - Copyright (C) 2006..2016 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 wdg.h - * @brief WDG Driver macros and structures. - * - * @addtogroup WDG - * @{ - */ - -#ifndef _WDG_H_ -#define _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 "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 /* _WDG_H_ */ - -/** @} */ -- cgit v1.2.3