Add software
This commit is contained in:
316
Software/portapack-mayhem/firmware/chibios/os/hal/include/adc.h
Normal file
316
Software/portapack-mayhem/firmware/chibios/os/hal/include/adc.h
Normal file
@ -0,0 +1,316 @@
|
||||
/*
|
||||
ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010,
|
||||
2011,2012,2013 Giovanni Di Sirio.
|
||||
|
||||
This file is part of ChibiOS/RT.
|
||||
|
||||
ChibiOS/RT is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
ChibiOS/RT is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
---
|
||||
|
||||
A special exception to the GPL can be applied should you wish to distribute
|
||||
a combined work that includes ChibiOS/RT, without being obliged to provide
|
||||
the source code for any proprietary components. See the file exception.txt
|
||||
for full details of how and when the exception can be applied.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file adc.h
|
||||
* @brief ADC Driver macros and structures.
|
||||
*
|
||||
* @addtogroup ADC
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifndef _ADC_H_
|
||||
#define _ADC_H_
|
||||
|
||||
#if HAL_USE_ADC || 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. */
|
||||
/*===========================================================================*/
|
||||
|
||||
#if ADC_USE_MUTUAL_EXCLUSION && !CH_USE_MUTEXES && !CH_USE_SEMAPHORES
|
||||
#error "ADC_USE_MUTUAL_EXCLUSION requires CH_USE_MUTEXES and/or CH_USE_SEMAPHORES"
|
||||
#endif
|
||||
|
||||
/*===========================================================================*/
|
||||
/* 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 || 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) { \
|
||||
if ((adcp)->thread != NULL) { \
|
||||
Thread *tp = (adcp)->thread; \
|
||||
(adcp)->thread = NULL; \
|
||||
tp->p_u.rdymsg = RDY_RESET; \
|
||||
chSchReadyI(tp); \
|
||||
} \
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Resumes a thread waiting for a conversion completion.
|
||||
*
|
||||
* @param[in] adcp pointer to the @p ADCDriver object
|
||||
*
|
||||
* @notapi
|
||||
*/
|
||||
#define _adc_reset_s(adcp) { \
|
||||
if ((adcp)->thread != NULL) { \
|
||||
Thread *tp = (adcp)->thread; \
|
||||
(adcp)->thread = NULL; \
|
||||
chSchWakeupS(tp, RDY_RESET); \
|
||||
} \
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Wakes up the waiting thread.
|
||||
*
|
||||
* @param[in] adcp pointer to the @p ADCDriver object
|
||||
*
|
||||
* @notapi
|
||||
*/
|
||||
#define _adc_wakeup_isr(adcp) { \
|
||||
chSysLockFromIsr(); \
|
||||
if ((adcp)->thread != NULL) { \
|
||||
Thread *tp; \
|
||||
tp = (adcp)->thread; \
|
||||
(adcp)->thread = NULL; \
|
||||
tp->p_u.rdymsg = RDY_OK; \
|
||||
chSchReadyI(tp); \
|
||||
} \
|
||||
chSysUnlockFromIsr(); \
|
||||
}
|
||||
|
||||
/**
|
||||
* @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) { \
|
||||
chSysLockFromIsr(); \
|
||||
if ((adcp)->thread != NULL) { \
|
||||
Thread *tp; \
|
||||
tp = (adcp)->thread; \
|
||||
(adcp)->thread = NULL; \
|
||||
tp->p_u.rdymsg = RDY_TIMEOUT; \
|
||||
chSchReadyI(tp); \
|
||||
} \
|
||||
chSysUnlockFromIsr(); \
|
||||
}
|
||||
|
||||
#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
|
||||
msg_t adcConvert(ADCDriver *adcp,
|
||||
const ADCConversionGroup *grpp,
|
||||
adcsample_t *samples,
|
||||
size_t depth);
|
||||
#endif
|
||||
#if ADC_USE_MUTUAL_EXCLUSION || defined(__DOXYGEN__)
|
||||
void adcAcquireBus(ADCDriver *adcp);
|
||||
void adcReleaseBus(ADCDriver *adcp);
|
||||
#endif /* ADC_USE_MUTUAL_EXCLUSION */
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* HAL_USE_ADC */
|
||||
|
||||
#endif /* _ADC_H_ */
|
||||
|
||||
/** @} */
|
165
Software/portapack-mayhem/firmware/chibios/os/hal/include/can.h
Normal file
165
Software/portapack-mayhem/firmware/chibios/os/hal/include/can.h
Normal file
@ -0,0 +1,165 @@
|
||||
/*
|
||||
ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010,
|
||||
2011,2012,2013 Giovanni Di Sirio.
|
||||
|
||||
This file is part of ChibiOS/RT.
|
||||
|
||||
ChibiOS/RT is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
ChibiOS/RT is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
---
|
||||
|
||||
A special exception to the GPL can be applied should you wish to distribute
|
||||
a combined work that includes ChibiOS/RT, without being obliged to provide
|
||||
the source code for any proprietary components. See the file exception.txt
|
||||
for full details of how and when the exception can be applied.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file can.h
|
||||
* @brief CAN Driver macros and structures.
|
||||
*
|
||||
* @addtogroup CAN
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifndef _CAN_H_
|
||||
#define _CAN_H_
|
||||
|
||||
#if HAL_USE_CAN || defined(__DOXYGEN__)
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Driver constants. */
|
||||
/*===========================================================================*/
|
||||
|
||||
/**
|
||||
* @name CAN status flags
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* @brief Errors rate warning.
|
||||
*/
|
||||
#define CAN_LIMIT_WARNING 1
|
||||
/**
|
||||
* @brief Errors rate error.
|
||||
*/
|
||||
#define CAN_LIMIT_ERROR 2
|
||||
/**
|
||||
* @brief Bus off condition reached.
|
||||
*/
|
||||
#define CAN_BUS_OFF_ERROR 4
|
||||
/**
|
||||
* @brief Framing error of some kind on the CAN bus.
|
||||
*/
|
||||
#define CAN_FRAMING_ERROR 8
|
||||
/**
|
||||
* @brief Overflow in receive queue.
|
||||
*/
|
||||
#define CAN_OVERFLOW_ERROR 16
|
||||
/** @} */
|
||||
|
||||
/**
|
||||
* @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. */
|
||||
/*===========================================================================*/
|
||||
|
||||
#if !CH_USE_SEMAPHORES || !CH_USE_EVENTS
|
||||
#error "CAN driver requires CH_USE_SEMAPHORES and CH_USE_EVENTS"
|
||||
#endif
|
||||
|
||||
/*===========================================================================*/
|
||||
/* 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) (1 << ((mbx) - 1))
|
||||
/** @} */
|
||||
|
||||
/*===========================================================================*/
|
||||
/* 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);
|
||||
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 /* CAN_USE_SLEEP_MODE */
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* HAL_USE_CAN */
|
||||
|
||||
#endif /* _CAN_H_ */
|
||||
|
||||
/** @} */
|
161
Software/portapack-mayhem/firmware/chibios/os/hal/include/ext.h
Normal file
161
Software/portapack-mayhem/firmware/chibios/os/hal/include/ext.h
Normal file
@ -0,0 +1,161 @@
|
||||
/*
|
||||
ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010,
|
||||
2011,2012,2013 Giovanni Di Sirio.
|
||||
|
||||
This file is part of ChibiOS/RT.
|
||||
|
||||
ChibiOS/RT is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
ChibiOS/RT is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
---
|
||||
|
||||
A special exception to the GPL can be applied should you wish to distribute
|
||||
a combined work that includes ChibiOS/RT, without being obliged to provide
|
||||
the source code for any proprietary components. See the file exception.txt
|
||||
for full details of how and when the exception can be applied.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file ext.h
|
||||
* @brief EXT Driver macros and structures.
|
||||
*
|
||||
* @addtogroup EXT
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifndef _EXT_H_
|
||||
#define _EXT_H_
|
||||
|
||||
#if HAL_USE_EXT || defined(__DOXYGEN__)
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Driver constants. */
|
||||
/*===========================================================================*/
|
||||
|
||||
/**
|
||||
* @name EXT channel modes
|
||||
* @{
|
||||
*/
|
||||
#define EXT_CH_MODE_EDGES_MASK 3 /**< @brief Mask of edges field. */
|
||||
#define EXT_CH_MODE_DISABLED 0 /**< @brief Channel disabled. */
|
||||
#define EXT_CH_MODE_RISING_EDGE 1 /**< @brief Rising edge callback. */
|
||||
#define EXT_CH_MODE_FALLING_EDGE 2 /**< @brief Falling edge callback. */
|
||||
#define EXT_CH_MODE_BOTH_EDGES 3 /**< @brief Both edges callback. */
|
||||
|
||||
#define EXT_CH_MODE_AUTOSTART 4 /**< @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) { \
|
||||
chSysLock(); \
|
||||
extSetChannelModeI(extp, channel, extcp); \
|
||||
chSysUnlock(); \
|
||||
}
|
||||
|
||||
/** @} */
|
||||
|
||||
/*===========================================================================*/
|
||||
/* 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 */
|
||||
|
||||
#endif /* _EXT_H_ */
|
||||
|
||||
/** @} */
|
130
Software/portapack-mayhem/firmware/chibios/os/hal/include/gpt.h
Normal file
130
Software/portapack-mayhem/firmware/chibios/os/hal/include/gpt.h
Normal file
@ -0,0 +1,130 @@
|
||||
/*
|
||||
ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010,
|
||||
2011,2012,2013 Giovanni Di Sirio.
|
||||
|
||||
This file is part of ChibiOS/RT.
|
||||
|
||||
ChibiOS/RT is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
ChibiOS/RT is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
---
|
||||
|
||||
A special exception to the GPL can be applied should you wish to distribute
|
||||
a combined work that includes ChibiOS/RT, without being obliged to provide
|
||||
the source code for any proprietary components. See the file exception.txt
|
||||
for full details of how and when the exception can be applied.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file gpt.h
|
||||
* @brief GPT Driver macros and structures.
|
||||
*
|
||||
* @addtogroup GPT
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifndef _GPT_H_
|
||||
#define _GPT_H_
|
||||
|
||||
#if HAL_USE_GPT || 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 have been activated using @p gptStart().
|
||||
* @pre The GPT unit must have been running in continuous mode using
|
||||
* @p gptStartContinuous().
|
||||
* @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); \
|
||||
}
|
||||
|
||||
/*===========================================================================*/
|
||||
/* 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 */
|
||||
|
||||
#endif /* _GPT_H_ */
|
||||
|
||||
/** @} */
|
219
Software/portapack-mayhem/firmware/chibios/os/hal/include/hal.h
Normal file
219
Software/portapack-mayhem/firmware/chibios/os/hal/include/hal.h
Normal file
@ -0,0 +1,219 @@
|
||||
/*
|
||||
ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010,
|
||||
2011,2012,2013 Giovanni Di Sirio.
|
||||
|
||||
This file is part of ChibiOS/RT.
|
||||
|
||||
ChibiOS/RT is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
ChibiOS/RT is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
---
|
||||
|
||||
A special exception to the GPL can be applied should you wish to distribute
|
||||
a combined work that includes ChibiOS/RT, without being obliged to provide
|
||||
the source code for any proprietary components. See the file exception.txt
|
||||
for full details of how and when the exception can be applied.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file hal.h
|
||||
* @brief HAL subsystem header.
|
||||
*
|
||||
* @addtogroup HAL
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifndef _HAL_H_
|
||||
#define _HAL_H_
|
||||
|
||||
#include "ch.h"
|
||||
#include "board.h"
|
||||
#include "halconf.h"
|
||||
|
||||
#include "hal_lld.h"
|
||||
|
||||
/* Abstract interfaces.*/
|
||||
#include "io_channel.h"
|
||||
#include "io_block.h"
|
||||
|
||||
/* Shared headers.*/
|
||||
#include "mmcsd.h"
|
||||
|
||||
/* Layered drivers.*/
|
||||
#include "tm.h"
|
||||
#include "pal.h"
|
||||
#include "adc.h"
|
||||
#include "can.h"
|
||||
#include "ext.h"
|
||||
#include "gpt.h"
|
||||
#include "i2c.h"
|
||||
#include "icu.h"
|
||||
#include "mac.h"
|
||||
#include "pwm.h"
|
||||
#include "rtc.h"
|
||||
#include "serial.h"
|
||||
#include "sdc.h"
|
||||
#include "spi.h"
|
||||
#include "uart.h"
|
||||
#include "usb.h"
|
||||
|
||||
/* Complex drivers.*/
|
||||
#include "mmc_spi.h"
|
||||
#include "serial_usb.h"
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Driver constants. */
|
||||
/*===========================================================================*/
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Driver pre-compile time settings. */
|
||||
/*===========================================================================*/
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Derived constants and error checks. */
|
||||
/*===========================================================================*/
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Driver data structures and types. */
|
||||
/*===========================================================================*/
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Driver macros. */
|
||||
/*===========================================================================*/
|
||||
|
||||
#if HAL_IMPLEMENTS_COUNTERS || defined(__DOXYGEN__)
|
||||
/**
|
||||
* @name Time conversion utilities for the realtime counter
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* @brief Seconds to realtime ticks.
|
||||
* @details Converts from seconds to realtime ticks number.
|
||||
* @note The result is rounded upward to the next tick boundary.
|
||||
*
|
||||
* @param[in] sec number of seconds
|
||||
* @return The number of ticks.
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
#define S2RTT(sec) (halGetCounterFrequency() * (sec))
|
||||
|
||||
/**
|
||||
* @brief Milliseconds to realtime ticks.
|
||||
* @details Converts from milliseconds to realtime ticks number.
|
||||
* @note The result is rounded upward to the next tick boundary.
|
||||
*
|
||||
* @param[in] msec number of milliseconds
|
||||
* @return The number of ticks.
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
#define MS2RTT(msec) (((halGetCounterFrequency() + 999UL) / 1000UL) * (msec))
|
||||
|
||||
/**
|
||||
* @brief Microseconds to realtime ticks.
|
||||
* @details Converts from microseconds to realtime ticks number.
|
||||
* @note The result is rounded upward to the next tick boundary.
|
||||
*
|
||||
* @param[in] usec number of microseconds
|
||||
* @return The number of ticks.
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
#define US2RTT(usec) (((halGetCounterFrequency() + 999999UL) / 1000000UL) * \
|
||||
(usec))
|
||||
|
||||
/**
|
||||
* @brief Realtime ticks to seconds to.
|
||||
* @details Converts from realtime ticks number to seconds.
|
||||
*
|
||||
* @param[in] ticks number of ticks
|
||||
* @return The number of seconds.
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
#define RTT2S(ticks) ((ticks) / halGetCounterFrequency())
|
||||
|
||||
/**
|
||||
* @brief Realtime ticks to milliseconds.
|
||||
* @details Converts from realtime ticks number to milliseconds.
|
||||
*
|
||||
* @param[in] ticks number of ticks
|
||||
* @return The number of milliseconds.
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
#define RTT2MS(ticks) ((ticks) / (halGetCounterFrequency() / 1000UL))
|
||||
|
||||
/**
|
||||
* @brief Realtime ticks to microseconds.
|
||||
* @details Converts from realtime ticks number to microseconds.
|
||||
*
|
||||
* @param[in] ticks number of ticks
|
||||
* @return The number of microseconds.
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
#define RTT2US(ticks) ((ticks) / (halGetCounterFrequency() / 1000000UL))
|
||||
/** @} */
|
||||
|
||||
/**
|
||||
* @name Macro Functions
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* @brief Returns the current value of the system free running counter.
|
||||
* @note This is an optional service that could not be implemented in
|
||||
* all HAL implementations.
|
||||
* @note This function can be called from any context.
|
||||
*
|
||||
* @return The value of the system free running counter of
|
||||
* type halrtcnt_t.
|
||||
*
|
||||
* @special
|
||||
*/
|
||||
#define halGetCounterValue() hal_lld_get_counter_value()
|
||||
|
||||
/**
|
||||
* @brief Realtime counter frequency.
|
||||
* @note This is an optional service that could not be implemented in
|
||||
* all HAL implementations.
|
||||
* @note This function can be called from any context.
|
||||
*
|
||||
* @return The realtime counter frequency of type halclock_t.
|
||||
*
|
||||
* @special
|
||||
*/
|
||||
#define halGetCounterFrequency() hal_lld_get_counter_frequency()
|
||||
/** @} */
|
||||
#endif /* HAL_IMPLEMENTS_COUNTERS */
|
||||
|
||||
/*===========================================================================*/
|
||||
/* External declarations. */
|
||||
/*===========================================================================*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
void halInit(void);
|
||||
#if HAL_IMPLEMENTS_COUNTERS
|
||||
bool_t halIsCounterWithin(halrtcnt_t start, halrtcnt_t end);
|
||||
void halPolledDelay(halrtcnt_t ticks);
|
||||
#endif /* HAL_IMPLEMENTS_COUNTERS */
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _HAL_H_ */
|
||||
|
||||
/** @} */
|
154
Software/portapack-mayhem/firmware/chibios/os/hal/include/i2c.h
Normal file
154
Software/portapack-mayhem/firmware/chibios/os/hal/include/i2c.h
Normal file
@ -0,0 +1,154 @@
|
||||
/*
|
||||
ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010,
|
||||
2011,2012,2013 Giovanni Di Sirio.
|
||||
|
||||
This file is part of ChibiOS/RT.
|
||||
|
||||
ChibiOS/RT is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
ChibiOS/RT is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
---
|
||||
|
||||
A special exception to the GPL can be applied should you wish to distribute
|
||||
a combined work that includes ChibiOS/RT, without being obliged to provide
|
||||
the source code for any proprietary components. See the file exception.txt
|
||||
for full details of how and when the exception can be applied.
|
||||
*/
|
||||
/*
|
||||
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 || defined(__DOXYGEN__)
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Driver constants. */
|
||||
/*===========================================================================*/
|
||||
|
||||
/**
|
||||
* @name I2C bus error conditions
|
||||
* @{
|
||||
*/
|
||||
#define I2CD_NO_ERROR 0x00 /**< @brief No error. */
|
||||
#define I2CD_BUS_ERROR 0x01 /**< @brief Bus Error. */
|
||||
#define I2CD_ARBITRATION_LOST 0x02 /**< @brief Arbitration Lost. */
|
||||
#define I2CD_ACK_FAILURE 0x04 /**< @brief Acknowledge Failure. */
|
||||
#define I2CD_OVERRUN 0x08 /**< @brief Overrun/Underrun. */
|
||||
#define I2CD_PEC_ERROR 0x10 /**< @brief PEC Error in
|
||||
reception. */
|
||||
#define I2CD_TIMEOUT 0x20 /**< @brief Hardware timeout. */
|
||||
#define I2CD_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. */
|
||||
/*===========================================================================*/
|
||||
|
||||
#if I2C_USE_MUTUAL_EXCLUSION && !CH_USE_MUTEXES && !CH_USE_SEMAPHORES
|
||||
#error "I2C_USE_MUTUAL_EXCLUSION requires CH_USE_MUTEXES and/or CH_USE_SEMAPHORES"
|
||||
#endif
|
||||
|
||||
/*===========================================================================*/
|
||||
/* 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 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
|
||||
void i2cAcquireBus(I2CDriver *i2cp);
|
||||
void i2cReleaseBus(I2CDriver *i2cp);
|
||||
#endif /* I2C_USE_MUTUAL_EXCLUSION */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* HAL_USE_I2C */
|
||||
|
||||
#endif /* _I2C_H_ */
|
||||
|
||||
/** @} */
|
203
Software/portapack-mayhem/firmware/chibios/os/hal/include/icu.h
Normal file
203
Software/portapack-mayhem/firmware/chibios/os/hal/include/icu.h
Normal file
@ -0,0 +1,203 @@
|
||||
/*
|
||||
ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010,
|
||||
2011,2012,2013 Giovanni Di Sirio.
|
||||
|
||||
This file is part of ChibiOS/RT.
|
||||
|
||||
ChibiOS/RT is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
ChibiOS/RT is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
---
|
||||
|
||||
A special exception to the GPL can be applied should you wish to distribute
|
||||
a combined work that includes ChibiOS/RT, without being obliged to provide
|
||||
the source code for any proprietary components. See the file exception.txt
|
||||
for full details of how and when the exception can be applied.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file icu.h
|
||||
* @brief ICU Driver macros and structures.
|
||||
*
|
||||
* @addtogroup ICU
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifndef _ICU_H_
|
||||
#define _ICU_H_
|
||||
|
||||
#if HAL_USE_ICU || 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 first edge. */
|
||||
ICU_ACTIVE = 4, /**< Active cycle phase. */
|
||||
ICU_IDLE = 5, /**< Idle cycle phase. */
|
||||
} 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 Enables the input capture.
|
||||
*
|
||||
* @param[in] icup pointer to the @p ICUDriver object
|
||||
*
|
||||
* @iclass
|
||||
*/
|
||||
#define icuEnableI(icup) icu_lld_enable(icup)
|
||||
|
||||
/**
|
||||
* @brief Disables the input capture.
|
||||
*
|
||||
* @param[in] icup pointer to the @p ICUDriver object
|
||||
*
|
||||
* @iclass
|
||||
*/
|
||||
#define icuDisableI(icup) icu_lld_disable(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 only.
|
||||
*
|
||||
* @param[in] icup pointer to the @p ICUDriver object
|
||||
* @return The number of ticks.
|
||||
*
|
||||
* @special
|
||||
*/
|
||||
#define icuGetWidth(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 only.
|
||||
*
|
||||
* @param[in] icup pointer to the @p ICUDriver object
|
||||
* @return The number of ticks.
|
||||
*
|
||||
* @special
|
||||
*/
|
||||
#define icuGetPeriod(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) { \
|
||||
if ((icup)->state != ICU_WAITING) { \
|
||||
(icup)->state = ICU_IDLE; \
|
||||
(icup)->config->width_cb(icup); \
|
||||
} \
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Common ISR code, ICU period event.
|
||||
*
|
||||
* @param[in] icup pointer to the @p ICUDriver object
|
||||
*
|
||||
* @notapi
|
||||
*/
|
||||
#define _icu_isr_invoke_period_cb(icup) { \
|
||||
icustate_t previous_state = (icup)->state; \
|
||||
(icup)->state = ICU_ACTIVE; \
|
||||
if (previous_state != ICU_WAITING) \
|
||||
(icup)->config->period_cb(icup); \
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Common ISR code, ICU timer overflow event.
|
||||
*
|
||||
* @param[in] icup pointer to the @p ICUDriver object
|
||||
*
|
||||
* @notapi
|
||||
*/
|
||||
#define _icu_isr_invoke_overflow_cb(icup) { \
|
||||
(icup)->config->overflow_cb(icup); \
|
||||
}
|
||||
/** @} */
|
||||
|
||||
/*===========================================================================*/
|
||||
/* 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 icuEnable(ICUDriver *icup);
|
||||
void icuDisable(ICUDriver *icup);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* HAL_USE_ICU */
|
||||
|
||||
#endif /* _ICU_H_ */
|
||||
|
||||
/** @} */
|
@ -0,0 +1,276 @@
|
||||
/*
|
||||
ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010,
|
||||
2011,2012,2013 Giovanni Di Sirio.
|
||||
|
||||
This file is part of ChibiOS/RT.
|
||||
|
||||
ChibiOS/RT is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
ChibiOS/RT is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
---
|
||||
|
||||
A special exception to the GPL can be applied should you wish to distribute
|
||||
a combined work that includes ChibiOS/RT, without being obliged to provide
|
||||
the source code for any proprietary components. See the file exception.txt
|
||||
for full details of how and when the exception can be applied.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file io_block.h
|
||||
* @brief I/O block devices access.
|
||||
* @details This header defines an abstract interface useful to access generic
|
||||
* I/O block devices in a standardized way.
|
||||
*
|
||||
* @addtogroup IO_BLOCK
|
||||
* @details This module defines an abstract interface for accessing generic
|
||||
* block devices.<br>
|
||||
* Note that no code is present, just abstract interfaces-like
|
||||
* structures, you should look at the system as to a set of
|
||||
* abstract C++ classes (even if written in C). This system
|
||||
* has then advantage to make the access to block devices
|
||||
* independent from the implementation logic.
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifndef _IO_BLOCK_H_
|
||||
#define _IO_BLOCK_H_
|
||||
|
||||
/**
|
||||
* @brief Driver state machine possible states.
|
||||
*/
|
||||
typedef enum {
|
||||
BLK_UNINIT = 0, /**< Not initialized. */
|
||||
BLK_STOP = 1, /**< Stopped. */
|
||||
BLK_ACTIVE = 2, /**< Interface active. */
|
||||
BLK_CONNECTING = 3, /**< Connection in progress. */
|
||||
BLK_DISCONNECTING = 4, /**< Disconnection in progress. */
|
||||
BLK_READY = 5, /**< Device ready. */
|
||||
BLK_READING = 6, /**< Read operation in progress. */
|
||||
BLK_WRITING = 7, /**< Write operation in progress. */
|
||||
BLK_SYNCING = 8 /**< Sync. operation in progress. */
|
||||
} blkstate_t;
|
||||
|
||||
/**
|
||||
* @brief Block device info.
|
||||
*/
|
||||
typedef struct {
|
||||
uint32_t blk_size; /**< @brief Block size in bytes. */
|
||||
uint32_t blk_num; /**< @brief Total number of blocks. */
|
||||
} BlockDeviceInfo;
|
||||
|
||||
/**
|
||||
* @brief @p BaseBlockDevice specific methods.
|
||||
*/
|
||||
#define _base_block_device_methods \
|
||||
/* Removable media detection.*/ \
|
||||
bool_t (*is_inserted)(void *instance); \
|
||||
/* Removable write protection detection.*/ \
|
||||
bool_t (*is_protected)(void *instance); \
|
||||
/* Connection to the block device.*/ \
|
||||
bool_t (*connect)(void *instance); \
|
||||
/* Disconnection from the block device.*/ \
|
||||
bool_t (*disconnect)(void *instance); \
|
||||
/* Reads one or more blocks.*/ \
|
||||
bool_t (*read)(void *instance, uint32_t startblk, \
|
||||
uint8_t *buffer, uint32_t n); \
|
||||
/* Writes one or more blocks.*/ \
|
||||
bool_t (*write)(void *instance, uint32_t startblk, \
|
||||
const uint8_t *buffer, uint32_t n); \
|
||||
/* Write operations synchronization.*/ \
|
||||
bool_t (*sync)(void *instance); \
|
||||
/* Obtains info about the media.*/ \
|
||||
bool_t (*get_info)(void *instance, BlockDeviceInfo *bdip);
|
||||
|
||||
/**
|
||||
* @brief @p BaseBlockDevice specific data.
|
||||
*/
|
||||
#define _base_block_device_data \
|
||||
/* Driver state.*/ \
|
||||
blkstate_t state;
|
||||
|
||||
/**
|
||||
* @brief @p BaseBlockDevice virtual methods table.
|
||||
*/
|
||||
struct BaseBlockDeviceVMT {
|
||||
_base_block_device_methods
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Base block device class.
|
||||
* @details This class represents a generic, block-accessible, device.
|
||||
*/
|
||||
typedef struct {
|
||||
/** @brief Virtual Methods Table.*/
|
||||
const struct BaseBlockDeviceVMT *vmt;
|
||||
_base_block_device_data
|
||||
} BaseBlockDevice;
|
||||
|
||||
/**
|
||||
* @name Macro Functions (BaseBlockDevice)
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* @brief Returns the driver state.
|
||||
* @note Can be called in ISR context.
|
||||
*
|
||||
* @param[in] ip pointer to a @p BaseBlockDevice or derived class
|
||||
*
|
||||
* @return The driver state.
|
||||
*
|
||||
* @special
|
||||
*/
|
||||
#define blkGetDriverState(ip) ((ip)->state)
|
||||
|
||||
/**
|
||||
* @brief Determines if the device is transferring data.
|
||||
* @note Can be called in ISR context.
|
||||
*
|
||||
* @param[in] ip pointer to a @p BaseBlockDevice or derived class
|
||||
*
|
||||
* @return The driver state.
|
||||
* @retval FALSE the device is not transferring data.
|
||||
* @retval TRUE the device not transferring data.
|
||||
*
|
||||
* @special
|
||||
*/
|
||||
#define blkIsTransferring(ip) ((((ip)->state) == BLK_CONNECTING) || \
|
||||
(((ip)->state) == BLK_DISCONNECTING) || \
|
||||
(((ip)->state) == BLK_READING) || \
|
||||
(((ip)->state) == BLK_WRITING))
|
||||
|
||||
/**
|
||||
* @brief Returns the media insertion status.
|
||||
* @note On some implementations this function can only be called if the
|
||||
* device is not transferring data.
|
||||
* The function @p blkIsTransferring() should be used before calling
|
||||
* this function.
|
||||
*
|
||||
* @param[in] ip pointer to a @p BaseBlockDevice or derived class
|
||||
*
|
||||
* @return The media state.
|
||||
* @retval FALSE media not inserted.
|
||||
* @retval TRUE media inserted.
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
#define blkIsInserted(ip) ((ip)->vmt->is_inserted(ip))
|
||||
|
||||
/**
|
||||
* @brief Returns the media write protection status.
|
||||
*
|
||||
* @param[in] ip pointer to a @p BaseBlockDevice or derived class
|
||||
*
|
||||
* @return The media state.
|
||||
* @retval FALSE writable media.
|
||||
* @retval TRUE non writable media.
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
#define blkIsWriteProtected(ip) ((ip)->vmt->is_protected(ip))
|
||||
|
||||
/**
|
||||
* @brief Performs the initialization procedure on the block device.
|
||||
* @details This function should be performed before I/O operations can be
|
||||
* attempted on the block device and after insertion has been
|
||||
* confirmed using @p blkIsInserted().
|
||||
*
|
||||
* @param[in] ip pointer to a @p BaseBlockDevice or derived class
|
||||
*
|
||||
* @return The operation status.
|
||||
* @retval CH_SUCCESS operation succeeded.
|
||||
* @retval CH_FAILED operation failed.
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
#define blkConnect(ip) ((ip)->vmt->connect(ip))
|
||||
|
||||
/**
|
||||
* @brief Terminates operations on the block device.
|
||||
* @details This operation safely terminates operations on the block device.
|
||||
*
|
||||
* @param[in] ip pointer to a @p BaseBlockDevice or derived class
|
||||
*
|
||||
* @return The operation status.
|
||||
* @retval CH_SUCCESS operation succeeded.
|
||||
* @retval CH_FAILED operation failed.
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
#define blkDisconnect(ip) ((ip)->vmt->disconnect(ip))
|
||||
|
||||
/**
|
||||
* @brief Reads one or more blocks.
|
||||
*
|
||||
* @param[in] ip pointer to a @p BaseBlockDevice or derived class
|
||||
* @param[in] startblk first block to read
|
||||
* @param[out] buf pointer to the read buffer
|
||||
* @param[in] n number of blocks to read
|
||||
*
|
||||
* @return The operation status.
|
||||
* @retval CH_SUCCESS operation succeeded.
|
||||
* @retval CH_FAILED operation failed.
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
#define blkRead(ip, startblk, buf, n) \
|
||||
((ip)->vmt->read(ip, startblk, buf, n))
|
||||
|
||||
/**
|
||||
* @brief Writes one or more blocks.
|
||||
*
|
||||
* @param[in] ip pointer to a @p BaseBlockDevice or derived class
|
||||
* @param[in] startblk first block to write
|
||||
* @param[out] buf pointer to the write buffer
|
||||
* @param[in] n number of blocks to write
|
||||
*
|
||||
* @return The operation status.
|
||||
* @retval CH_SUCCESS operation succeeded.
|
||||
* @retval CH_FAILED operation failed.
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
#define blkWrite(ip, startblk, buf, n) \
|
||||
((ip)->vmt->write(ip, startblk, buf, n))
|
||||
|
||||
/**
|
||||
* @brief Ensures write synchronization.
|
||||
*
|
||||
* @param[in] ip pointer to a @p BaseBlockDevice or derived class
|
||||
*
|
||||
* @return The operation status.
|
||||
* @retval CH_SUCCESS operation succeeded.
|
||||
* @retval CH_FAILED operation failed.
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
#define blkSync(ip) ((ip)->vmt->sync(ip))
|
||||
|
||||
/**
|
||||
* @brief Returns a media information structure.
|
||||
*
|
||||
* @param[in] ip pointer to a @p BaseBlockDevice or derived class
|
||||
* @param[out] bdip pointer to a @p BlockDeviceInfo structure
|
||||
*
|
||||
* @return The operation status.
|
||||
* @retval CH_SUCCESS operation succeeded.
|
||||
* @retval CH_FAILED operation failed.
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
#define blkGetInfo(ip, bdip) ((ip)->vmt->get_info(ip, bdip))
|
||||
|
||||
/** @} */
|
||||
|
||||
#endif /* _IO_BLOCK_H_ */
|
||||
|
||||
/** @} */
|
@ -0,0 +1,301 @@
|
||||
/*
|
||||
ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010,
|
||||
2011,2012,2013 Giovanni Di Sirio.
|
||||
|
||||
This file is part of ChibiOS/RT.
|
||||
|
||||
ChibiOS/RT is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
ChibiOS/RT is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
---
|
||||
|
||||
A special exception to the GPL can be applied should you wish to distribute
|
||||
a combined work that includes ChibiOS/RT, without being obliged to provide
|
||||
the source code for any proprietary components. See the file exception.txt
|
||||
for full details of how and when the exception can be applied.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file io_channel.h
|
||||
* @brief I/O channels access.
|
||||
* @details This header defines an abstract interface useful to access generic
|
||||
* I/O serial devices in a standardized way.
|
||||
*
|
||||
* @addtogroup IO_CHANNEL
|
||||
* @details This module defines an abstract interface for I/O channels by
|
||||
* extending the @p BaseSequentialStream interface.<br>
|
||||
* Note that no code is present, I/O channels are just abstract
|
||||
* interface like structures, you should look at the systems as
|
||||
* to a set of abstract C++ classes (even if written in C).
|
||||
* Specific device drivers can use/extend the interface and
|
||||
* implement them.<br>
|
||||
* This system has the advantage to make the access to channels
|
||||
* independent from the implementation logic.
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifndef _IO_CHANNEL_H_
|
||||
#define _IO_CHANNEL_H_
|
||||
|
||||
/**
|
||||
* @brief @p BaseChannel specific methods.
|
||||
*/
|
||||
#define _base_channel_methods \
|
||||
_base_sequential_stream_methods \
|
||||
/* Channel put method with timeout specification.*/ \
|
||||
msg_t (*putt)(void *instance, uint8_t b, systime_t time); \
|
||||
/* Channel get method with timeout specification.*/ \
|
||||
msg_t (*gett)(void *instance, systime_t time); \
|
||||
/* Channel write method with timeout specification.*/ \
|
||||
size_t (*writet)(void *instance, const uint8_t *bp, \
|
||||
size_t n, systime_t time); \
|
||||
/* Channel read method with timeout specification.*/ \
|
||||
size_t (*readt)(void *instance, uint8_t *bp, size_t n, systime_t time);
|
||||
|
||||
/**
|
||||
* @brief @p BaseChannel specific data.
|
||||
* @note It is empty because @p BaseChannel is only an interface without
|
||||
* implementation.
|
||||
*/
|
||||
#define _base_channel_data \
|
||||
_base_sequential_stream_data
|
||||
|
||||
/**
|
||||
* @extends BaseSequentialStreamVMT
|
||||
*
|
||||
* @brief @p BaseChannel virtual methods table.
|
||||
*/
|
||||
struct BaseChannelVMT {
|
||||
_base_channel_methods
|
||||
};
|
||||
|
||||
/**
|
||||
* @extends BaseSequentialStream
|
||||
*
|
||||
* @brief Base channel class.
|
||||
* @details This class represents a generic, byte-wide, I/O channel. This class
|
||||
* introduces generic I/O primitives with timeout specification.
|
||||
*/
|
||||
typedef struct {
|
||||
/** @brief Virtual Methods Table.*/
|
||||
const struct BaseChannelVMT *vmt;
|
||||
_base_channel_data
|
||||
} BaseChannel;
|
||||
|
||||
/**
|
||||
* @name Macro Functions (BaseChannel)
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* @brief Channel blocking byte write with timeout.
|
||||
* @details This function writes a byte value to a channel. If the channel
|
||||
* is not ready to accept data then the calling thread is suspended.
|
||||
*
|
||||
* @param[in] ip pointer to a @p BaseChannel or derived class
|
||||
* @param[in] b the byte value to be written to the channel
|
||||
* @param[in] time the number of ticks before the operation timeouts,
|
||||
* the following special values are allowed:
|
||||
* - @a TIME_IMMEDIATE immediate timeout.
|
||||
* - @a TIME_INFINITE no timeout.
|
||||
* .
|
||||
* @return The operation status.
|
||||
* @retval Q_OK if the operation succeeded.
|
||||
* @retval Q_TIMEOUT if the specified time expired.
|
||||
* @retval Q_RESET if the channel associated queue (if any) was reset.
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
#define chnPutTimeout(ip, b, time) ((ip)->vmt->putt(ip, b, time))
|
||||
|
||||
/**
|
||||
* @brief Channel blocking byte read with timeout.
|
||||
* @details This function reads a byte value from a channel. If the data
|
||||
* is not available then the calling thread is suspended.
|
||||
*
|
||||
* @param[in] ip pointer to a @p BaseChannel or derived class
|
||||
* @param[in] time the number of ticks before the operation timeouts,
|
||||
* the following special values are allowed:
|
||||
* - @a TIME_IMMEDIATE immediate timeout.
|
||||
* - @a TIME_INFINITE no timeout.
|
||||
* .
|
||||
* @return A byte value from the queue.
|
||||
* @retval Q_TIMEOUT if the specified time expired.
|
||||
* @retval Q_RESET if the channel associated queue (if any) has been
|
||||
* reset.
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
#define chnGetTimeout(ip, time) ((ip)->vmt->gett(ip, time))
|
||||
|
||||
/**
|
||||
* @brief Channel blocking write.
|
||||
* @details The function writes data from a buffer to a channel. If the channel
|
||||
* is not ready to accept data then the calling thread is suspended.
|
||||
*
|
||||
* @param[in] ip pointer to a @p BaseChannel or derived class
|
||||
* @param[out] bp pointer to the data buffer
|
||||
* @param[in] n the maximum amount of data to be transferred
|
||||
*
|
||||
* @return The number of bytes transferred.
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
#define chnWrite(ip, bp, n) chSequentialStreamWrite(ip, bp, n)
|
||||
|
||||
/**
|
||||
* @brief Channel blocking write with timeout.
|
||||
* @details The function writes data from a buffer to a channel. If the channel
|
||||
* is not ready to accept data then the calling thread is suspended.
|
||||
*
|
||||
* @param[in] ip pointer to a @p BaseChannel or derived class
|
||||
* @param[out] bp pointer to the data buffer
|
||||
* @param[in] n the maximum amount of data to be transferred
|
||||
* @param[in] time the number of ticks before the operation timeouts,
|
||||
* the following special values are allowed:
|
||||
* - @a TIME_IMMEDIATE immediate timeout.
|
||||
* - @a TIME_INFINITE no timeout.
|
||||
* .
|
||||
* @return The number of bytes transferred.
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
#define chnWriteTimeout(ip, bp, n, time) ((ip)->vmt->writet(ip, bp, n, time))
|
||||
|
||||
/**
|
||||
* @brief Channel blocking read.
|
||||
* @details The function reads data from a channel into a buffer. If the data
|
||||
* is not available then the calling thread is suspended.
|
||||
*
|
||||
* @param[in] ip pointer to a @p BaseChannel or derived class
|
||||
* @param[in] bp pointer to the data buffer
|
||||
* @param[in] n the maximum amount of data to be transferred
|
||||
*
|
||||
* @return The number of bytes transferred.
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
#define chnRead(ip, bp, n) chSequentialStreamRead(ip, bp, n)
|
||||
|
||||
/**
|
||||
* @brief Channel blocking read with timeout.
|
||||
* @details The function reads data from a channel into a buffer. If the data
|
||||
* is not available then the calling thread is suspended.
|
||||
*
|
||||
* @param[in] ip pointer to a @p BaseChannel or derived class
|
||||
* @param[in] bp pointer to the data buffer
|
||||
* @param[in] n the maximum amount of data to be transferred
|
||||
* @param[in] time the number of ticks before the operation timeouts,
|
||||
* the following special values are allowed:
|
||||
* - @a TIME_IMMEDIATE immediate timeout.
|
||||
* - @a TIME_INFINITE no timeout.
|
||||
* .
|
||||
* @return The number of bytes transferred.
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
#define chnReadTimeout(ip, bp, n, time) ((ip)->vmt->readt(ip, bp, n, time))
|
||||
/** @} */
|
||||
|
||||
#if CH_USE_EVENTS || defined(__DOXYGEN__)
|
||||
/**
|
||||
* @name I/O status flags added to the event listener
|
||||
* @{
|
||||
*/
|
||||
/** @brief No pending conditions.*/
|
||||
#define CHN_NO_ERROR 0
|
||||
/** @brief Connection happened.*/
|
||||
#define CHN_CONNECTED 1
|
||||
/** @brief Disconnection happened.*/
|
||||
#define CHN_DISCONNECTED 2
|
||||
/** @brief Data available in the input queue.*/
|
||||
#define CHN_INPUT_AVAILABLE 4
|
||||
/** @brief Output queue empty.*/
|
||||
#define CHN_OUTPUT_EMPTY 8
|
||||
/** @brief Transmission end.*/
|
||||
#define CHN_TRANSMISSION_END 16
|
||||
/** @} */
|
||||
|
||||
/**
|
||||
* @brief @p BaseAsynchronousChannel specific methods.
|
||||
*/
|
||||
#define _base_asynchronous_channel_methods \
|
||||
_base_channel_methods \
|
||||
|
||||
/**
|
||||
* @brief @p BaseAsynchronousChannel specific data.
|
||||
*/
|
||||
#define _base_asynchronous_channel_data \
|
||||
_base_channel_data \
|
||||
/* I/O condition event source.*/ \
|
||||
EventSource event;
|
||||
|
||||
/**
|
||||
* @extends BaseChannelVMT
|
||||
*
|
||||
* @brief @p BaseAsynchronousChannel virtual methods table.
|
||||
*/
|
||||
struct BaseAsynchronousChannelVMT {
|
||||
_base_asynchronous_channel_methods
|
||||
};
|
||||
|
||||
/**
|
||||
* @extends BaseChannel
|
||||
*
|
||||
* @brief Base asynchronous channel class.
|
||||
* @details This class extends @p BaseChannel by adding event sources fields
|
||||
* for asynchronous I/O for use in an event-driven environment.
|
||||
*/
|
||||
typedef struct {
|
||||
/** @brief Virtual Methods Table.*/
|
||||
const struct BaseAsynchronousChannelVMT *vmt;
|
||||
_base_asynchronous_channel_data
|
||||
} BaseAsynchronousChannel;
|
||||
|
||||
/**
|
||||
* @name Macro Functions (BaseAsynchronousChannel)
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* @brief Returns the I/O condition event source.
|
||||
* @details The event source is broadcasted when an I/O condition happens.
|
||||
*
|
||||
* @param[in] ip pointer to a @p BaseAsynchronousChannel or derived
|
||||
* class
|
||||
* @return A pointer to an @p EventSource object.
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
#define chnGetEventSource(ip) (&((ip)->event))
|
||||
|
||||
/**
|
||||
* @brief Adds status flags to the listeners's flags mask.
|
||||
* @details This function is usually called from the I/O ISRs in order to
|
||||
* notify I/O conditions such as data events, errors, signal
|
||||
* changes etc.
|
||||
*
|
||||
* @param[in] ip pointer to a @p BaseAsynchronousChannel or derived
|
||||
* class
|
||||
* @param[in] flags condition flags to be added to the listener flags mask
|
||||
*
|
||||
* @iclass
|
||||
*/
|
||||
#define chnAddFlagsI(ip, flags) { \
|
||||
chEvtBroadcastFlagsI(&(ip)->event, flags); \
|
||||
}
|
||||
/** @} */
|
||||
|
||||
#endif /* CH_USE_EVENTS */
|
||||
|
||||
#endif /* _IO_CHANNEL_H_ */
|
||||
|
||||
/** @} */
|
221
Software/portapack-mayhem/firmware/chibios/os/hal/include/mac.h
Normal file
221
Software/portapack-mayhem/firmware/chibios/os/hal/include/mac.h
Normal file
@ -0,0 +1,221 @@
|
||||
/*
|
||||
ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010,
|
||||
2011,2012,2013 Giovanni Di Sirio.
|
||||
|
||||
This file is part of ChibiOS/RT.
|
||||
|
||||
ChibiOS/RT is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
ChibiOS/RT is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
---
|
||||
|
||||
A special exception to the GPL can be applied should you wish to distribute
|
||||
a combined work that includes ChibiOS/RT, without being obliged to provide
|
||||
the source code for any proprietary components. See the file exception.txt
|
||||
for full details of how and when the exception can be applied.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file mac.h
|
||||
* @brief MAC Driver macros and structures.
|
||||
* @addtogroup MAC
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifndef _MAC_H_
|
||||
#define _MAC_H_
|
||||
|
||||
#if HAL_USE_MAC || 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. */
|
||||
/*===========================================================================*/
|
||||
|
||||
#if !CH_USE_SEMAPHORES || !CH_USE_EVENTS
|
||||
#error "the MAC driver requires CH_USE_SEMAPHORES"
|
||||
#endif
|
||||
|
||||
#if MAC_USE_EVENTS && !CH_USE_EVENTS
|
||||
#error "the MAC driver requires CH_USE_EVENTS"
|
||||
#endif
|
||||
|
||||
/*===========================================================================*/
|
||||
/* 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 || 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 || 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 time);
|
||||
void macReleaseTransmitDescriptor(MACTransmitDescriptor *tdp);
|
||||
msg_t macWaitReceiveDescriptor(MACDriver *macp,
|
||||
MACReceiveDescriptor *rdp,
|
||||
systime_t time);
|
||||
void macReleaseReceiveDescriptor(MACReceiveDescriptor *rdp);
|
||||
bool_t macPollLinkStatus(MACDriver *macp);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* HAL_USE_MAC */
|
||||
|
||||
#endif /* _MAC_H_ */
|
||||
|
||||
/** @} */
|
169
Software/portapack-mayhem/firmware/chibios/os/hal/include/mii.h
Normal file
169
Software/portapack-mayhem/firmware/chibios/os/hal/include/mii.h
Normal file
@ -0,0 +1,169 @@
|
||||
/*
|
||||
ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010,
|
||||
2011,2012,2013 Giovanni Di Sirio.
|
||||
|
||||
This file is part of ChibiOS/RT.
|
||||
|
||||
ChibiOS/RT is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
ChibiOS/RT is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
---
|
||||
|
||||
A special exception to the GPL can be applied should you wish to distribute
|
||||
a combined work that includes ChibiOS/RT, without being obliged to provide
|
||||
the source code for any proprietary components. See the file exception.txt
|
||||
for full details of how and when the exception can be applied.
|
||||
*/
|
||||
|
||||
/*-*
|
||||
* @file mii.h
|
||||
* @brief MII Driver macros and structures.
|
||||
*
|
||||
* @addtogroup MII
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifndef _MII_H_
|
||||
#define _MII_H_
|
||||
|
||||
/*
|
||||
* Generic MII registers. Note, not all registers are present on all PHY
|
||||
* devices and some extra registers may be present.
|
||||
*/
|
||||
#define MII_BMCR 0x00 /**< Basic mode control register. */
|
||||
#define MII_BMSR 0x01 /**< Basic mode status register. */
|
||||
#define MII_PHYSID1 0x02 /**< PHYS ID 1. */
|
||||
#define MII_PHYSID2 0x03 /**< PHYS ID 2. */
|
||||
#define MII_ADVERTISE 0x04 /**< Advertisement control reg. */
|
||||
#define MII_LPA 0x05 /**< Link partner ability reg. */
|
||||
#define MII_EXPANSION 0x06 /**< Expansion register. */
|
||||
#define MII_ANNPTR 0x07 /**< 1000BASE-T control. */
|
||||
#define MII_CTRL1000 0x09 /**< 1000BASE-T control. */
|
||||
#define MII_STAT1000 0x0a /**< 1000BASE-T status. */
|
||||
#define MII_ESTATUS 0x0f /**< Extended Status. */
|
||||
#define MII_PHYSTS 0x10 /**< PHY Status register. */
|
||||
#define MII_MICR 0x11 /**< MII Interrupt ctrl register. */
|
||||
#define MII_DCOUNTER 0x12 /**< Disconnect counter. */
|
||||
#define MII_FCSCOUNTER 0x13 /**< False carrier counter. */
|
||||
#define MII_NWAYTEST 0x14 /**< N-way auto-neg test reg. */
|
||||
#define MII_RERRCOUNTER 0x15 /**< Receive error counter. */
|
||||
#define MII_SREVISION 0x16 /**< Silicon revision. */
|
||||
#define MII_RESV1 0x17 /**< Reserved. */
|
||||
#define MII_LBRERROR 0x18 /**< Lpback, rx, bypass error. */
|
||||
#define MII_PHYADDR 0x19 /**< PHY address. */
|
||||
#define MII_RESV2 0x1a /**< Reserved. */
|
||||
#define MII_TPISTATUS 0x1b /**< TPI status for 10Mbps. */
|
||||
#define MII_NCONFIG 0x1c /**< Network interface config. */
|
||||
|
||||
/*
|
||||
* Basic mode control register.
|
||||
*/
|
||||
#define BMCR_RESV 0x007f /**< Unused. */
|
||||
#define BMCR_CTST 0x0080 /**< Collision test. */
|
||||
#define BMCR_FULLDPLX 0x0100 /**< Full duplex. */
|
||||
#define BMCR_ANRESTART 0x0200 /**< Auto negotiation restart. */
|
||||
#define BMCR_ISOLATE 0x0400 /**< Disconnect DP83840 from MII. */
|
||||
#define BMCR_PDOWN 0x0800 /**< Powerdown. */
|
||||
#define BMCR_ANENABLE 0x1000 /**< Enable auto negotiation. */
|
||||
#define BMCR_SPEED100 0x2000 /**< Select 100Mbps. */
|
||||
#define BMCR_LOOPBACK 0x4000 /**< TXD loopback bit. */
|
||||
#define BMCR_RESET 0x8000 /**< Reset. */
|
||||
|
||||
/*
|
||||
* Basic mode status register.
|
||||
*/
|
||||
#define BMSR_ERCAP 0x0001 /**< Ext-reg capability. */
|
||||
#define BMSR_JCD 0x0002 /**< Jabber detected. */
|
||||
#define BMSR_LSTATUS 0x0004 /**< Link status. */
|
||||
#define BMSR_ANEGCAPABLE 0x0008 /**< Able to do auto-negotiation. */
|
||||
#define BMSR_RFAULT 0x0010 /**< Remote fault detected. */
|
||||
#define BMSR_ANEGCOMPLETE 0x0020 /**< Auto-negotiation complete. */
|
||||
#define BMSR_MFPRESUPPCAP 0x0040 /**< Able to suppress preamble. */
|
||||
#define BMSR_RESV 0x0780 /**< Unused. */
|
||||
#define BMSR_10HALF 0x0800 /**< Can do 10mbps, half-duplex. */
|
||||
#define BMSR_10FULL 0x1000 /**< Can do 10mbps, full-duplex. */
|
||||
#define BMSR_100HALF 0x2000 /**< Can do 100mbps, half-duplex. */
|
||||
#define BMSR_100FULL 0x4000 /**< Can do 100mbps, full-duplex. */
|
||||
#define BMSR_100BASE4 0x8000 /**< Can do 100mbps, 4k packets. */
|
||||
|
||||
/*
|
||||
* Advertisement control register.
|
||||
*/
|
||||
#define ADVERTISE_SLCT 0x001f /**< Selector bits. */
|
||||
#define ADVERTISE_CSMA 0x0001 /**< Only selector supported. */
|
||||
#define ADVERTISE_10HALF 0x0020 /**< Try for 10mbps half-duplex. */
|
||||
#define ADVERTISE_10FULL 0x0040 /**< Try for 10mbps full-duplex. */
|
||||
#define ADVERTISE_100HALF 0x0080 /**< Try for 100mbps half-duplex. */
|
||||
#define ADVERTISE_100FULL 0x0100 /**< Try for 100mbps full-duplex. */
|
||||
#define ADVERTISE_100BASE4 0x0200 /**< Try for 100mbps 4k packets. */
|
||||
#define ADVERTISE_PAUSE_CAP 0x0400 /**< Try for pause. */
|
||||
#define ADVERTISE_PAUSE_ASYM 0x0800 /**< Try for asymetric pause. */
|
||||
#define ADVERTISE_RESV 0x1000 /**< Unused. */
|
||||
#define ADVERTISE_RFAULT 0x2000 /**< Say we can detect faults. */
|
||||
#define ADVERTISE_LPACK 0x4000 /**< Ack link partners response. */
|
||||
#define ADVERTISE_NPAGE 0x8000 /**< Next page bit. */
|
||||
|
||||
#define ADVERTISE_FULL (ADVERTISE_100FULL | ADVERTISE_10FULL | \
|
||||
ADVERTISE_CSMA)
|
||||
#define ADVERTISE_ALL (ADVERTISE_10HALF | ADVERTISE_10FULL | \
|
||||
ADVERTISE_100HALF | ADVERTISE_100FULL)
|
||||
|
||||
/*
|
||||
* Link partner ability register.
|
||||
*/
|
||||
#define LPA_SLCT 0x001f /**< Same as advertise selector. */
|
||||
#define LPA_10HALF 0x0020 /**< Can do 10mbps half-duplex. */
|
||||
#define LPA_10FULL 0x0040 /**< Can do 10mbps full-duplex. */
|
||||
#define LPA_100HALF 0x0080 /**< Can do 100mbps half-duplex. */
|
||||
#define LPA_100FULL 0x0100 /**< Can do 100mbps full-duplex. */
|
||||
#define LPA_100BASE4 0x0200 /**< Can do 100mbps 4k packets. */
|
||||
#define LPA_PAUSE_CAP 0x0400 /**< Can pause. */
|
||||
#define LPA_PAUSE_ASYM 0x0800 /**< Can pause asymetrically. */
|
||||
#define LPA_RESV 0x1000 /**< Unused. */
|
||||
#define LPA_RFAULT 0x2000 /**< Link partner faulted. */
|
||||
#define LPA_LPACK 0x4000 /**< Link partner acked us. */
|
||||
#define LPA_NPAGE 0x8000 /**< Next page bit. */
|
||||
|
||||
#define LPA_DUPLEX (LPA_10FULL | LPA_100FULL)
|
||||
#define LPA_100 (LPA_100FULL | LPA_100HALF | LPA_100BASE4)
|
||||
|
||||
/*
|
||||
* Expansion register for auto-negotiation.
|
||||
*/
|
||||
#define EXPANSION_NWAY 0x0001 /**< Can do N-way auto-nego. */
|
||||
#define EXPANSION_LCWP 0x0002 /**< Got new RX page code word. */
|
||||
#define EXPANSION_ENABLENPAGE 0x0004 /**< This enables npage words. */
|
||||
#define EXPANSION_NPCAPABLE 0x0008 /**< Link partner supports npage. */
|
||||
#define EXPANSION_MFAULTS 0x0010 /**< Multiple faults detected. */
|
||||
#define EXPANSION_RESV 0xffe0 /**< Unused. */
|
||||
|
||||
/*
|
||||
* N-way test register.
|
||||
*/
|
||||
#define NWAYTEST_RESV1 0x00ff /**< Unused. */
|
||||
#define NWAYTEST_LOOPBACK 0x0100 /**< Enable loopback for N-way. */
|
||||
#define NWAYTEST_RESV2 0xfe00 /**< Unused. */
|
||||
|
||||
/*
|
||||
* PHY identifiers.
|
||||
*/
|
||||
#define MII_DM9161_ID 0x0181b8a0
|
||||
#define MII_AM79C875_ID 0x00225540
|
||||
#define MII_KS8721_ID 0x00221610
|
||||
#define MII_STE101P_ID 0x00061C50
|
||||
#define MII_DP83848I_ID 0x20005C90
|
||||
#define MII_LAN8710A_ID 0x0007C0F1
|
||||
|
||||
#endif /* _MII_H_ */
|
||||
|
||||
/** @} */
|
@ -0,0 +1,206 @@
|
||||
/*
|
||||
ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010,
|
||||
2011,2012,2013 Giovanni Di Sirio.
|
||||
|
||||
This file is part of ChibiOS/RT.
|
||||
|
||||
ChibiOS/RT is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
ChibiOS/RT is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
---
|
||||
|
||||
A special exception to the GPL can be applied should you wish to distribute
|
||||
a combined work that includes ChibiOS/RT, without being obliged to provide
|
||||
the source code for any proprietary components. See the file exception.txt
|
||||
for full details of how and when the exception can be applied.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @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 || defined(__DOXYGEN__)
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Driver constants. */
|
||||
/*===========================================================================*/
|
||||
|
||||
#define MMC_CMD0_RETRY 10
|
||||
#define MMC_CMD1_RETRY 100
|
||||
#define MMC_ACMD41_RETRY 100
|
||||
#define MMC_WAIT_DATA 10000
|
||||
|
||||
/*===========================================================================*/
|
||||
/* 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 || !SPI_USE_WAIT
|
||||
#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_t 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_t mmcConnect(MMCDriver *mmcp);
|
||||
bool_t mmcDisconnect(MMCDriver *mmcp);
|
||||
bool_t mmcStartSequentialRead(MMCDriver *mmcp, uint32_t startblk);
|
||||
bool_t mmcSequentialRead(MMCDriver *mmcp, uint8_t *buffer);
|
||||
bool_t mmcStopSequentialRead(MMCDriver *mmcp);
|
||||
bool_t mmcStartSequentialWrite(MMCDriver *mmcp, uint32_t startblk);
|
||||
bool_t mmcSequentialWrite(MMCDriver *mmcp, const uint8_t *buffer);
|
||||
bool_t mmcStopSequentialWrite(MMCDriver *mmcp);
|
||||
bool_t mmcSync(MMCDriver *mmcp);
|
||||
bool_t mmcGetInfo(MMCDriver *mmcp, BlockDeviceInfo *bdip);
|
||||
bool_t mmcErase(MMCDriver *mmcp, uint32_t startblk, uint32_t endblk);
|
||||
bool_t mmc_lld_is_card_inserted(MMCDriver *mmcp);
|
||||
bool_t mmc_lld_is_write_protected(MMCDriver *mmcp);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* HAL_USE_MMC_SPI */
|
||||
|
||||
#endif /* _MMC_SPI_H_ */
|
||||
|
||||
/** @} */
|
@ -0,0 +1,286 @@
|
||||
/*
|
||||
ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010,
|
||||
2011,2012,2013 Giovanni Di Sirio.
|
||||
|
||||
This file is part of ChibiOS/RT.
|
||||
|
||||
ChibiOS/RT is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
ChibiOS/RT is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
---
|
||||
|
||||
A special exception to the GPL can be applied should you wish to distribute
|
||||
a combined work that includes ChibiOS/RT, without being obliged to provide
|
||||
the source code for any proprietary components. See the file exception.txt
|
||||
for full details of how and when the exception can be applied.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file mmcsd.h
|
||||
* @brief MMC/SD cards common header.
|
||||
* @details This header defines an abstract interface useful to access MMC/SD
|
||||
* I/O block devices in a standardized way.
|
||||
*
|
||||
* @addtogroup MMCSD
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifndef _MMCSD_H_
|
||||
#define _MMCSD_H_
|
||||
|
||||
#if HAL_USE_MMC_SPI || HAL_USE_SDC || defined(__DOXYGEN__)
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Driver constants. */
|
||||
/*===========================================================================*/
|
||||
|
||||
/**
|
||||
* @brief Fixed block size for MMC/SD block devices.
|
||||
*/
|
||||
#define MMCSD_BLOCK_SIZE 512
|
||||
|
||||
/**
|
||||
* @brief Mask of error bits in R1 responses.
|
||||
*/
|
||||
#define MMCSD_R1_ERROR_MASK 0xFDFFE008
|
||||
|
||||
/**
|
||||
* @brief Fixed pattern for CMD8.
|
||||
*/
|
||||
#define MMCSD_CMD8_PATTERN 0x000001AA
|
||||
|
||||
/**
|
||||
* @name SD/MMC status conditions
|
||||
* @{
|
||||
*/
|
||||
#define MMCSD_STS_IDLE 0
|
||||
#define MMCSD_STS_READY 1
|
||||
#define MMCSD_STS_IDENT 2
|
||||
#define MMCSD_STS_STBY 3
|
||||
#define MMCSD_STS_TRAN 4
|
||||
#define MMCSD_STS_DATA 5
|
||||
#define MMCSD_STS_RCV 6
|
||||
#define MMCSD_STS_PRG 7
|
||||
#define MMCSD_STS_DIS 8
|
||||
/** @} */
|
||||
|
||||
/**
|
||||
* @name SD/MMC commands
|
||||
* @{
|
||||
*/
|
||||
#define MMCSD_CMD_GO_IDLE_STATE 0
|
||||
#define MMCSD_CMD_INIT 1
|
||||
#define MMCSD_CMD_ALL_SEND_CID 2
|
||||
#define MMCSD_CMD_SEND_RELATIVE_ADDR 3
|
||||
#define MMCSD_CMD_SET_BUS_WIDTH 6
|
||||
#define MMCSD_CMD_SEL_DESEL_CARD 7
|
||||
#define MMCSD_CMD_SEND_IF_COND 8
|
||||
#define MMCSD_CMD_SEND_CSD 9
|
||||
#define MMCSD_CMD_SEND_CID 10
|
||||
#define MMCSD_CMD_STOP_TRANSMISSION 12
|
||||
#define MMCSD_CMD_SEND_STATUS 13
|
||||
#define MMCSD_CMD_SET_BLOCKLEN 16
|
||||
#define MMCSD_CMD_READ_SINGLE_BLOCK 17
|
||||
#define MMCSD_CMD_READ_MULTIPLE_BLOCK 18
|
||||
#define MMCSD_CMD_SET_BLOCK_COUNT 23
|
||||
#define MMCSD_CMD_WRITE_BLOCK 24
|
||||
#define MMCSD_CMD_WRITE_MULTIPLE_BLOCK 25
|
||||
#define MMCSD_CMD_ERASE_RW_BLK_START 32
|
||||
#define MMCSD_CMD_ERASE_RW_BLK_END 33
|
||||
#define MMCSD_CMD_ERASE 38
|
||||
#define MMCSD_CMD_APP_OP_COND 41
|
||||
#define MMCSD_CMD_LOCK_UNLOCK 42
|
||||
#define MMCSD_CMD_APP_CMD 55
|
||||
#define MMCSD_CMD_READ_OCR 58
|
||||
/** @} */
|
||||
|
||||
/**
|
||||
* @name CSD record offsets
|
||||
*/
|
||||
/**
|
||||
* @brief Slice position of values in CSD register.
|
||||
*/
|
||||
/* CSD version 2.0 */
|
||||
#define MMCSD_CSD_20_CRC_SLICE 7,1
|
||||
#define MMCSD_CSD_20_FILE_FORMAT_SLICE 11,10
|
||||
#define MMCSD_CSD_20_TMP_WRITE_PROTECT_SLICE 12,12
|
||||
#define MMCSD_CSD_20_PERM_WRITE_PROTECT_SLICE 13,13
|
||||
#define MMCSD_CSD_20_COPY_SLICE 14,14
|
||||
#define MMCSD_CSD_20_FILE_FORMAT_GRP_SLICE 15,15
|
||||
#define MMCSD_CSD_20_WRITE_BL_PARTIAL_SLICE 21,21
|
||||
#define MMCSD_CSD_20_WRITE_BL_LEN_SLICE 25,12
|
||||
#define MMCSD_CSD_20_R2W_FACTOR_SLICE 28,26
|
||||
#define MMCSD_CSD_20_WP_GRP_ENABLE_SLICE 31,31
|
||||
#define MMCSD_CSD_20_WP_GRP_SIZE_SLICE 38,32
|
||||
#define MMCSD_CSD_20_ERASE_SECTOR_SIZE_SLICE 45,39
|
||||
#define MMCSD_CSD_20_ERASE_BLK_EN_SLICE 46,46
|
||||
#define MMCSD_CSD_20_C_SIZE_SLICE 69,48
|
||||
#define MMCSD_CSD_20_DSR_IMP_SLICE 76,76
|
||||
#define MMCSD_CSD_20_READ_BLK_MISALIGN_SLICE 77,77
|
||||
#define MMCSD_CSD_20_WRITE_BLK_MISALIGN_SLICE 78,78
|
||||
#define MMCSD_CSD_20_READ_BL_PARTIAL_SLICE 79,79
|
||||
#define MMCSD_CSD_20_READ_BL_LEN_SLICE 83,80
|
||||
#define MMCSD_CSD_20_CCC_SLICE 95,84
|
||||
#define MMCSD_CSD_20_TRANS_SPEED_SLICE 103,96
|
||||
#define MMCSD_CSD_20_NSAC_SLICE 111,104
|
||||
#define MMCSD_CSD_20_TAAC_SLICE 119,112
|
||||
#define MMCSD_CSD_20_STRUCTURE_SLICE 127,126
|
||||
|
||||
/* CSD version 1.0 */
|
||||
#define MMCSD_CSD_10_CRC_SLICE MMCSD_CSD_20_CRC_SLICE
|
||||
#define MMCSD_CSD_10_FILE_FORMAT_SLICE MMCSD_CSD_20_FILE_FORMAT_SLICE
|
||||
#define MMCSD_CSD_10_TMP_WRITE_PROTECT_SLICE MMCSD_CSD_20_TMP_WRITE_PROTECT_SLICE
|
||||
#define MMCSD_CSD_10_PERM_WRITE_PROTECT_SLICE MMCSD_CSD_20_PERM_WRITE_PROTECT_SLICE
|
||||
#define MMCSD_CSD_10_COPY_SLICE MMCSD_CSD_20_COPY_SLICE
|
||||
#define MMCSD_CSD_10_FILE_FORMAT_GRP_SLICE MMCSD_CSD_20_FILE_FORMAT_GRP_SLICE
|
||||
#define MMCSD_CSD_10_WRITE_BL_PARTIAL_SLICE MMCSD_CSD_20_WRITE_BL_PARTIAL_SLICE
|
||||
#define MMCSD_CSD_10_WRITE_BL_LEN_SLICE MMCSD_CSD_20_WRITE_BL_LEN_SLICE
|
||||
#define MMCSD_CSD_10_R2W_FACTOR_SLICE MMCSD_CSD_20_R2W_FACTOR_SLICE
|
||||
#define MMCSD_CSD_10_WP_GRP_ENABLE_SLICE MMCSD_CSD_20_WP_GRP_ENABLE_SLICE
|
||||
#define MMCSD_CSD_10_WP_GRP_SIZE_SLICE MMCSD_CSD_20_WP_GRP_SIZE_SLICE
|
||||
#define MMCSD_CSD_10_ERASE_SECTOR_SIZE_SLICE MMCSD_CSD_20_ERASE_SECTOR_SIZE_SLICE
|
||||
#define MMCSD_CSD_10_ERASE_BLK_EN_SLICE MMCSD_CSD_20_ERASE_BLK_EN_SLICE
|
||||
#define MMCSD_CSD_10_C_SIZE_MULT_SLICE 49,47
|
||||
#define MMCSD_CSD_10_VDD_W_CURR_MAX_SLICE 52,50
|
||||
#define MMCSD_CSD_10_VDD_W_CURR_MIN_SLICE 55,53
|
||||
#define MMCSD_CSD_10_VDD_R_CURR_MAX_SLICE 58,56
|
||||
#define MMCSD_CSD_10_VDD_R_CURR_MIX_SLICE 61,59
|
||||
#define MMCSD_CSD_10_C_SIZE_SLICE 73,62
|
||||
#define MMCSD_CSD_10_DSR_IMP_SLICE MMCSD_CSD_20_DSR_IMP_SLICE
|
||||
#define MMCSD_CSD_10_READ_BLK_MISALIGN_SLICE MMCSD_CSD_20_READ_BLK_MISALIGN_SLICE
|
||||
#define MMCSD_CSD_10_WRITE_BLK_MISALIGN_SLICE MMCSD_CSD_20_WRITE_BLK_MISALIGN_SLICE
|
||||
#define MMCSD_CSD_10_READ_BL_PARTIAL_SLICE MMCSD_CSD_20_READ_BL_PARTIAL_SLICE
|
||||
#define MMCSD_CSD_10_READ_BL_LEN_SLICE 83, 80
|
||||
#define MMCSD_CSD_10_CCC_SLICE MMCSD_CSD_20_CCC_SLICE
|
||||
#define MMCSD_CSD_10_TRANS_SPEED_SLICE MMCSD_CSD_20_TRANS_SPEED_SLICE
|
||||
#define MMCSD_CSD_10_NSAC_SLICE MMCSD_CSD_20_NSAC_SLICE
|
||||
#define MMCSD_CSD_10_TAAC_SLICE MMCSD_CSD_20_TAAC_SLICE
|
||||
#define MMCSD_CSD_10_STRUCTURE_SLICE MMCSD_CSD_20_STRUCTURE_SLICE
|
||||
/** @} */
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Driver pre-compile time settings. */
|
||||
/*===========================================================================*/
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Derived constants and error checks. */
|
||||
/*===========================================================================*/
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Driver data structures and types. */
|
||||
/*===========================================================================*/
|
||||
|
||||
/**
|
||||
* @brief @p MMCSDBlockDevice specific methods.
|
||||
*/
|
||||
#define _mmcsd_block_device_methods \
|
||||
_base_block_device_methods
|
||||
|
||||
/**
|
||||
* @brief @p MMCSDBlockDevice specific data.
|
||||
* @note It is empty because @p MMCSDBlockDevice is only an interface
|
||||
* without implementation.
|
||||
*/
|
||||
#define _mmcsd_block_device_data \
|
||||
_base_block_device_data \
|
||||
/* Card CID.*/ \
|
||||
uint32_t cid[4]; \
|
||||
/* Card CSD.*/ \
|
||||
uint32_t csd[4]; \
|
||||
/* Total number of blocks in card.*/ \
|
||||
uint32_t capacity;
|
||||
|
||||
/**
|
||||
* @extends BaseBlockDeviceVMT
|
||||
*
|
||||
* @brief @p MMCSDBlockDevice virtual methods table.
|
||||
*/
|
||||
struct MMCSDBlockDeviceVMT {
|
||||
_base_block_device_methods
|
||||
};
|
||||
|
||||
/**
|
||||
* @extends BaseBlockDevice
|
||||
*
|
||||
* @brief MCC/SD block device class.
|
||||
* @details This class represents a, block-accessible, MMC/SD device.
|
||||
*/
|
||||
typedef struct {
|
||||
/** @brief Virtual Methods Table.*/
|
||||
const struct MMCSDBlockDeviceVMT *vmt;
|
||||
_mmcsd_block_device_data
|
||||
} MMCSDBlockDevice;
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Driver macros. */
|
||||
/*===========================================================================*/
|
||||
|
||||
/**
|
||||
* @name R1 response utilities
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* @brief Evaluates to @p TRUE if the R1 response contains error flags.
|
||||
*
|
||||
* @param[in] r1 the r1 response
|
||||
*/
|
||||
#define MMCSD_R1_ERROR(r1) (((r1) & MMCSD_R1_ERROR_MASK) != 0)
|
||||
|
||||
/**
|
||||
* @brief Returns the status field of an R1 response.
|
||||
*
|
||||
* @param[in] r1 the r1 response
|
||||
*/
|
||||
#define MMCSD_R1_STS(r1) (((r1) >> 9) & 15)
|
||||
|
||||
/**
|
||||
* @brief Evaluates to @p TRUE if the R1 response indicates a locked card.
|
||||
*
|
||||
* @param[in] r1 the r1 response
|
||||
*/
|
||||
#define MMCSD_R1_IS_CARD_LOCKED(r1) (((r1) >> 21) & 1)
|
||||
/** @} */
|
||||
|
||||
/**
|
||||
* @name Macro Functions
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* @brief Returns the card capacity in blocks.
|
||||
*
|
||||
* @param[in] ip pointer to a @p MMCSDBlockDevice or derived class
|
||||
*
|
||||
* @return The card capacity.
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
#define mmcsdGetCardCapacity(ip) ((ip)->capacity)
|
||||
/** @} */
|
||||
|
||||
/*===========================================================================*/
|
||||
/* External declarations. */
|
||||
/*===========================================================================*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
uint32_t mmcsdGetCapacity(uint32_t csd[4]);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* HAL_USE_MMC_SPI || HAL_USE_MMC_SDC*/
|
||||
|
||||
#endif /* _MMCSD_H_ */
|
||||
|
||||
/** @} */
|
562
Software/portapack-mayhem/firmware/chibios/os/hal/include/pal.h
Normal file
562
Software/portapack-mayhem/firmware/chibios/os/hal/include/pal.h
Normal file
@ -0,0 +1,562 @@
|
||||
/*
|
||||
ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010,
|
||||
2011,2012,2013 Giovanni Di Sirio.
|
||||
|
||||
This file is part of ChibiOS/RT.
|
||||
|
||||
ChibiOS/RT is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
ChibiOS/RT is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
---
|
||||
|
||||
A special exception to the GPL can be applied should you wish to distribute
|
||||
a combined work that includes ChibiOS/RT, without being obliged to provide
|
||||
the source code for any proprietary components. See the file exception.txt
|
||||
for full details of how and when the exception can be applied.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @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 || 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 0
|
||||
|
||||
/**
|
||||
* @brief Safe state for <b>unconnected</b> pads.
|
||||
* @details The state itself is not specified and is architecture dependent,
|
||||
* it may be mapped on @p PAL_MODE_INPUT_PULLUP,
|
||||
* @p PAL_MODE_INPUT_PULLDOWN or @p PAL_MODE_OUTPUT_PUSHPULL for
|
||||
* example.
|
||||
*/
|
||||
#define PAL_MODE_UNCONNECTED 1
|
||||
|
||||
/**
|
||||
* @brief Regular input high-Z pad.
|
||||
*/
|
||||
#define PAL_MODE_INPUT 2
|
||||
|
||||
/**
|
||||
* @brief Input pad with weak pull up resistor.
|
||||
*/
|
||||
#define PAL_MODE_INPUT_PULLUP 3
|
||||
|
||||
/**
|
||||
* @brief Input pad with weak pull down resistor.
|
||||
*/
|
||||
#define PAL_MODE_INPUT_PULLDOWN 4
|
||||
|
||||
/**
|
||||
* @brief Analog input mode.
|
||||
*/
|
||||
#define PAL_MODE_INPUT_ANALOG 5
|
||||
|
||||
/**
|
||||
* @brief Push-pull output pad.
|
||||
*/
|
||||
#define PAL_MODE_OUTPUT_PUSHPULL 6
|
||||
|
||||
/**
|
||||
* @brief Open-drain output pad.
|
||||
*/
|
||||
#define PAL_MODE_OUTPUT_OPENDRAIN 7
|
||||
/** @} */
|
||||
|
||||
/**
|
||||
* @name Logic level constants
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* @brief Logical low state.
|
||||
*/
|
||||
#define PAL_LOW 0
|
||||
|
||||
/**
|
||||
* @brief Logical high state.
|
||||
*/
|
||||
#define PAL_HIGH 1
|
||||
/** @} */
|
||||
|
||||
/*===========================================================================*/
|
||||
/* 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 logical 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)(1 << (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)(1 << (width)) - 1)
|
||||
#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 logical states.
|
||||
*
|
||||
* @special
|
||||
*/
|
||||
#if !defined(pal_lld_readport) || defined(__DOXYGEN__)
|
||||
#define palReadPort(port) ((void)(port), 0)
|
||||
#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 logical states.
|
||||
*
|
||||
* @special
|
||||
*/
|
||||
#if !defined(pal_lld_readlatch) || defined(__DOXYGEN__)
|
||||
#define palReadLatch(port) ((void)(port), 0)
|
||||
#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 chSysLock() and
|
||||
* @p chSysUnlock().
|
||||
* @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 chSysLock() and
|
||||
* @p chSysUnlock().
|
||||
* @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 chSysLock() and
|
||||
* @p chSysUnlock().
|
||||
* @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 logical AND is performed on the input
|
||||
* data
|
||||
* @param[in] offset group bit offset within the port
|
||||
* @return The group logical 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 logical 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 logical 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 logical state.
|
||||
* @retval PAL_LOW low logical state.
|
||||
* @retval PAL_HIGH high logical state.
|
||||
*
|
||||
* @special
|
||||
*/
|
||||
#if !defined(pal_lld_readpad) || defined(__DOXYGEN__)
|
||||
#define palReadPad(port, pad) ((palReadPort(port) >> (pad)) & 1)
|
||||
#else
|
||||
#define palReadPad(port, pad) pal_lld_readpad(port, pad)
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Writes a logical 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 chSysLock() and
|
||||
* @p chSysUnlock().
|
||||
* @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 logical 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) & 1) << pad))
|
||||
#else
|
||||
#define palWritePad(port, pad, bit) pal_lld_writepad(port, pad, bit)
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Sets a pad logical 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 chSysLock() and
|
||||
* @p chSysUnlock().
|
||||
* @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 logical 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 chSysLock() and
|
||||
* @p chSysUnlock().
|
||||
* @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 logical 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 chSysLock() and
|
||||
* @p chSysUnlock().
|
||||
* @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), 0, mode)
|
||||
#else
|
||||
#define palSetPadMode(port, pad, mode) pal_lld_setpadmode(port, pad, 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 */
|
||||
|
||||
/** @} */
|
259
Software/portapack-mayhem/firmware/chibios/os/hal/include/pwm.h
Normal file
259
Software/portapack-mayhem/firmware/chibios/os/hal/include/pwm.h
Normal file
@ -0,0 +1,259 @@
|
||||
/*
|
||||
ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010,
|
||||
2011,2012,2013 Giovanni Di Sirio.
|
||||
|
||||
This file is part of ChibiOS/RT.
|
||||
|
||||
ChibiOS/RT is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
ChibiOS/RT is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
---
|
||||
|
||||
A special exception to the GPL can be applied should you wish to distribute
|
||||
a combined work that includes ChibiOS/RT, without being obliged to provide
|
||||
the source code for any proprietary components. See the file exception.txt
|
||||
for full details of how and when the exception can be applied.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file pwm.h
|
||||
* @brief PWM Driver macros and structures.
|
||||
*
|
||||
* @addtogroup PWM
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifndef _PWM_H_
|
||||
#define _PWM_H_
|
||||
|
||||
#if HAL_USE_PWM || defined(__DOXYGEN__)
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Driver constants. */
|
||||
/*===========================================================================*/
|
||||
|
||||
/**
|
||||
* @name PWM output mode macros
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* @brief Standard output modes mask.
|
||||
*/
|
||||
#define PWM_OUTPUT_MASK 0x0F
|
||||
|
||||
/**
|
||||
* @brief Output not driven, callback only.
|
||||
*/
|
||||
#define PWM_OUTPUT_DISABLED 0x00
|
||||
|
||||
/**
|
||||
* @brief Positive PWM logic, active is logic level one.
|
||||
*/
|
||||
#define PWM_OUTPUT_ACTIVE_HIGH 0x01
|
||||
|
||||
/**
|
||||
* @brief Inverse PWM logic, active is logic level zero.
|
||||
*/
|
||||
#define PWM_OUTPUT_ACTIVE_LOW 0x02
|
||||
/** @} */
|
||||
|
||||
/*===========================================================================*/
|
||||
/* 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 PWM notification callback type.
|
||||
*
|
||||
* @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...PWM_CHANNELS-1)
|
||||
* @param[in] width PWM pulse width as clock pulses number
|
||||
*
|
||||
* @iclass
|
||||
*/
|
||||
#define pwmEnableChannelI(pwmp, channel, width) \
|
||||
pwm_lld_enable_channel(pwmp, channel, width)
|
||||
|
||||
/**
|
||||
* @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...PWM_CHANNELS-1)
|
||||
*
|
||||
* @iclass
|
||||
*/
|
||||
#define pwmDisableChannelI(pwmp, channel) \
|
||||
pwm_lld_disable_channel(pwmp, channel)
|
||||
|
||||
/**
|
||||
* @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...PWM_CHANNELS-1)
|
||||
*
|
||||
* @iclass
|
||||
*/
|
||||
#define pwmIsChannelEnabledI(pwmp, channel) \
|
||||
pwm_lld_is_channel_enabled(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);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* HAL_USE_PWM */
|
||||
|
||||
#endif /* _PWM_H_ */
|
||||
|
||||
/** @} */
|
178
Software/portapack-mayhem/firmware/chibios/os/hal/include/rtc.h
Normal file
178
Software/portapack-mayhem/firmware/chibios/os/hal/include/rtc.h
Normal file
@ -0,0 +1,178 @@
|
||||
/*
|
||||
ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010,
|
||||
2011,2012,2013 Giovanni Di Sirio.
|
||||
|
||||
This file is part of ChibiOS/RT.
|
||||
|
||||
ChibiOS/RT is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
ChibiOS/RT is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
---
|
||||
|
||||
A special exception to the GPL can be applied should you wish to distribute
|
||||
a combined work that includes ChibiOS/RT, without being obliged to provide
|
||||
the source code for any proprietary components. See the file exception.txt
|
||||
for full details of how and when the exception can be applied.
|
||||
*/
|
||||
/*
|
||||
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 || defined(__DOXYGEN__)
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Driver constants. */
|
||||
/*===========================================================================*/
|
||||
|
||||
/**
|
||||
* @name Date/Time bit masks
|
||||
* @{
|
||||
*/
|
||||
#define RTC_TIME_SECONDS_MASK 0x0000001F /* @brief Seconds mask. */
|
||||
#define RTC_TIME_MINUTES_MASK 0x000007E0 /* @brief Minutes mask. */
|
||||
#define RTC_TIME_HOURS_MASK 0x0000F800 /* @brief Hours mask. */
|
||||
#define RTC_DATE_DAYS_MASK 0x001F0000 /* @brief Days mask. */
|
||||
#define RTC_DATE_MONTHS_MASK 0x01E00000 /* @brief Months mask. */
|
||||
#define RTC_DATE_YEARS_MASK 0xFE000000 /* @brief Years mask. */
|
||||
/** @} */
|
||||
|
||||
/*===========================================================================*/
|
||||
/* 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 time stamp.
|
||||
*/
|
||||
typedef struct RTCTime RTCTime;
|
||||
|
||||
#include "rtc_lld.h"
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Driver macros. */
|
||||
/*===========================================================================*/
|
||||
|
||||
/**
|
||||
* @brief Set current time.
|
||||
*
|
||||
* @param[in] rtcp pointer to RTC driver structure
|
||||
* @param[in] timespec pointer to a @p RTCTime structure
|
||||
*
|
||||
* @iclass
|
||||
*/
|
||||
#define rtcSetTimeI(rtcp, timespec) rtc_lld_set_time(rtcp, timespec)
|
||||
|
||||
/**
|
||||
* @brief Get current time.
|
||||
*
|
||||
* @param[in] rtcp pointer to RTC driver structure
|
||||
* @param[out] timespec pointer to a @p RTCTime structure
|
||||
*
|
||||
* @iclass
|
||||
*/
|
||||
#define rtcGetTimeI(rtcp, timespec) rtc_lld_get_time(rtcp, timespec)
|
||||
|
||||
#if (RTC_ALARMS > 0) || defined(__DOXYGEN__)
|
||||
/**
|
||||
* @brief Set alarm time.
|
||||
*
|
||||
* @param[in] rtcp pointer to RTC driver structure
|
||||
* @param[in] alarm alarm identifier
|
||||
* @param[in] alarmspec pointer to a @p RTCAlarm structure or @p NULL
|
||||
*
|
||||
* @iclass
|
||||
*/
|
||||
#define rtcSetAlarmI(rtcp, alarm, alarmspec) \
|
||||
rtc_lld_set_alarm(rtcp, alarm, alarmspec)
|
||||
|
||||
/**
|
||||
* @brief Get current alarm.
|
||||
* @note If an alarm has not been set then the returned alarm specification
|
||||
* is not meaningful.
|
||||
*
|
||||
* @param[in] rtcp pointer to RTC driver structure
|
||||
* @param[in] alarm alarm identifier
|
||||
* @param[out] alarmspec pointer to a @p RTCAlarm structure
|
||||
*
|
||||
* @iclass
|
||||
*/
|
||||
#define rtcGetAlarmI(rtcp, alarm, alarmspec) \
|
||||
rtc_lld_get_alarm(rtcp, alarm, alarmspec)
|
||||
#endif /* RTC_ALARMS > 0 */
|
||||
|
||||
#if RTC_SUPPORTS_CALLBACKS || defined(__DOXYGEN__)
|
||||
/**
|
||||
* @brief Enables or disables RTC callbacks.
|
||||
* @details This function enables or disables the callback, use a @p NULL
|
||||
* pointer in order to disable it.
|
||||
*
|
||||
* @param[in] rtcp pointer to RTC driver structure
|
||||
* @param[in] callback callback function pointer or @p NULL
|
||||
*
|
||||
* @iclass
|
||||
*/
|
||||
#define rtcSetCallbackI(rtcp, callback) rtc_lld_set_callback(rtcp, callback)
|
||||
#endif /* RTC_SUPPORTS_CALLBACKS */
|
||||
|
||||
/*===========================================================================*/
|
||||
/* External declarations. */
|
||||
/*===========================================================================*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
void rtcInit(void);
|
||||
void rtcSetTime(RTCDriver *rtcp, const RTCTime *timespec);
|
||||
void rtcGetTime(RTCDriver *rtcp, RTCTime *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
|
||||
uint32_t rtcGetTimeFat(RTCDriver *rtcp);
|
||||
#if RTC_SUPPORTS_CALLBACKS
|
||||
void rtcSetCallback(RTCDriver *rtcp, rtccb_t callback);
|
||||
#endif
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* HAL_USE_RTC */
|
||||
#endif /* _RTC_H_ */
|
||||
|
||||
/** @} */
|
189
Software/portapack-mayhem/firmware/chibios/os/hal/include/sdc.h
Normal file
189
Software/portapack-mayhem/firmware/chibios/os/hal/include/sdc.h
Normal file
@ -0,0 +1,189 @@
|
||||
/*
|
||||
ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010,
|
||||
2011,2012,2013 Giovanni Di Sirio.
|
||||
|
||||
This file is part of ChibiOS/RT.
|
||||
|
||||
ChibiOS/RT is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
ChibiOS/RT is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
---
|
||||
|
||||
A special exception to the GPL can be applied should you wish to distribute
|
||||
a combined work that includes ChibiOS/RT, without being obliged to provide
|
||||
the source code for any proprietary components. See the file exception.txt
|
||||
for full details of how and when the exception can be applied.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file sdc.h
|
||||
* @brief SDC Driver macros and structures.
|
||||
*
|
||||
* @addtogroup SDC
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifndef _SDC_H_
|
||||
#define _SDC_H_
|
||||
|
||||
#if HAL_USE_SDC || defined(__DOXYGEN__)
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Driver constants. */
|
||||
/*===========================================================================*/
|
||||
|
||||
/**
|
||||
* @name SD cart types
|
||||
* @{
|
||||
*/
|
||||
#define SDC_MODE_CARDTYPE_MASK 0xF /**< @brief Card type mask. */
|
||||
#define SDC_MODE_CARDTYPE_SDV11 0 /**< @brief Card is SD V1.1.*/
|
||||
#define SDC_MODE_CARDTYPE_SDV20 1 /**< @brief Card is SD V2.0.*/
|
||||
#define SDC_MODE_CARDTYPE_MMC 2 /**< @brief Card is MMC. */
|
||||
#define SDC_MODE_HIGH_CAPACITY 0x10 /**< @brief High cap.card. */
|
||||
/** @} */
|
||||
|
||||
/**
|
||||
* @name SDC bus error conditions
|
||||
* @{
|
||||
*/
|
||||
#define SDC_NO_ERROR 0 /**< @brief No error. */
|
||||
#define SDC_CMD_CRC_ERROR 1 /**< @brief Command CRC error. */
|
||||
#define SDC_DATA_CRC_ERROR 2 /**< @brief Data CRC error. */
|
||||
#define SDC_DATA_TIMEOUT 4 /**< @brief HW write timeout. */
|
||||
#define SDC_COMMAND_TIMEOUT 8 /**< @brief HW read timeout. */
|
||||
#define SDC_TX_UNDERRUN 16 /**< @brief TX buffer underrun. */
|
||||
#define SDC_RX_OVERRUN 32 /**< @brief RX buffer overrun. */
|
||||
#define SDC_STARTBIT_ERROR 64 /**< @brief Start bit missing. */
|
||||
#define SDC_OVERFLOW_ERROR 128 /**< @brief Card overflow error. */
|
||||
#define SDC_UNHANDLED_ERROR 0xFFFFFFFF
|
||||
/** @} */
|
||||
|
||||
/*===========================================================================*/
|
||||
/* 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. */
|
||||
/*===========================================================================*/
|
||||
|
||||
#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_t sdcConnect(SDCDriver *sdcp);
|
||||
bool_t sdcDisconnect(SDCDriver *sdcp);
|
||||
bool_t sdcRead(SDCDriver *sdcp, uint32_t startblk,
|
||||
uint8_t *buffer, uint32_t n);
|
||||
bool_t sdcWrite(SDCDriver *sdcp, uint32_t startblk,
|
||||
const uint8_t *buffer, uint32_t n);
|
||||
sdcflags_t sdcGetAndClearErrors(SDCDriver *sdcp);
|
||||
bool_t sdcSync(SDCDriver *sdcp);
|
||||
bool_t sdcGetInfo(SDCDriver *sdcp, BlockDeviceInfo *bdip);
|
||||
bool_t sdcErase(SDCDriver *mmcp, uint32_t startblk, uint32_t endblk);
|
||||
bool_t _sdc_wait_for_transfer_state(SDCDriver *sdcp);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* HAL_USE_SDC */
|
||||
|
||||
#endif /* _SDC_H_ */
|
||||
|
||||
/** @} */
|
@ -0,0 +1,323 @@
|
||||
/*
|
||||
ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010,
|
||||
2011,2012,2013 Giovanni Di Sirio.
|
||||
|
||||
This file is part of ChibiOS/RT.
|
||||
|
||||
ChibiOS/RT is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
ChibiOS/RT is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
---
|
||||
|
||||
A special exception to the GPL can be applied should you wish to distribute
|
||||
a combined work that includes ChibiOS/RT, without being obliged to provide
|
||||
the source code for any proprietary components. See the file exception.txt
|
||||
for full details of how and when the exception can be applied.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file serial.h
|
||||
* @brief Serial Driver macros and structures.
|
||||
*
|
||||
* @addtogroup SERIAL
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifndef _SERIAL_H_
|
||||
#define _SERIAL_H_
|
||||
|
||||
#if HAL_USE_SERIAL || defined(__DOXYGEN__)
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Driver constants. */
|
||||
/*===========================================================================*/
|
||||
|
||||
/**
|
||||
* @name Serial status flags
|
||||
* @{
|
||||
*/
|
||||
#define SD_PARITY_ERROR 32 /**< @brief Parity error happened. */
|
||||
#define SD_FRAMING_ERROR 64 /**< @brief Framing error happened. */
|
||||
#define SD_OVERRUN_ERROR 128 /**< @brief Overflow happened. */
|
||||
#define SD_NOISE_ERROR 256 /**< @brief Noise on the line. */
|
||||
#define SD_BREAK_DETECTED 512 /**< @brief Break detected. */
|
||||
/** @} */
|
||||
|
||||
/*===========================================================================*/
|
||||
/* 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. */
|
||||
/*===========================================================================*/
|
||||
|
||||
#if !CH_USE_QUEUES && !CH_USE_EVENTS
|
||||
#error "Serial Driver requires CH_USE_QUEUES and CH_USE_EVENTS"
|
||||
#endif
|
||||
|
||||
/*===========================================================================*/
|
||||
/* 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 output check on a @p SerialDriver.
|
||||
* @note This function bypasses the indirect access to the channel and
|
||||
* checks directly the output queue. This is faster but cannot
|
||||
* be used to check different channels implementations.
|
||||
*
|
||||
* @deprecated
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
#define sdPutWouldBlock(sdp) chOQIsFullI(&(sdp)->oqueue)
|
||||
|
||||
/**
|
||||
* @brief Direct input check on a @p SerialDriver.
|
||||
* @note This function bypasses the indirect access to the channel and
|
||||
* checks directly the input queue. This is faster but cannot
|
||||
* be used to check different channels implementations.
|
||||
*
|
||||
* @deprecated
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
#define sdGetWouldBlock(sdp) chIQIsEmptyI(&(sdp)->iqueue)
|
||||
|
||||
/**
|
||||
* @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) chOQPut(&(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) chOQPutTimeout(&(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) chIQGet(&(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) chIQGetTimeout(&(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) \
|
||||
chOQWriteTimeout(&(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) \
|
||||
chOQWriteTimeout(&(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) \
|
||||
chOQWriteTimeout(&(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) \
|
||||
chIQReadTimeout(&(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) \
|
||||
chIQReadTimeout(&(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) \
|
||||
chIQReadTimeout(&(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);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* HAL_USE_SERIAL */
|
||||
|
||||
#endif /* _SERIAL_H_ */
|
||||
|
||||
/** @} */
|
@ -0,0 +1,241 @@
|
||||
/*
|
||||
ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010,
|
||||
2011,2012,2013 Giovanni Di Sirio.
|
||||
|
||||
This file is part of ChibiOS/RT.
|
||||
|
||||
ChibiOS/RT is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
ChibiOS/RT is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
---
|
||||
|
||||
A special exception to the GPL can be applied should you wish to distribute
|
||||
a combined work that includes ChibiOS/RT, without being obliged to provide
|
||||
the source code for any proprietary components. See the file exception.txt
|
||||
for full details of how and when the exception can be applied.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @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 || defined(__DOXYGEN__)
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Driver constants. */
|
||||
/*===========================================================================*/
|
||||
|
||||
/**
|
||||
* @name CDC specific messages.
|
||||
* @{
|
||||
*/
|
||||
#define CDC_SEND_ENCAPSULATED_COMMAND 0x00
|
||||
#define CDC_GET_ENCAPSULATED_RESPONSE 0x01
|
||||
#define CDC_SET_COMM_FEATURE 0x02
|
||||
#define CDC_GET_COMM_FEATURE 0x03
|
||||
#define CDC_CLEAR_COMM_FEATURE 0x04
|
||||
#define CDC_SET_AUX_LINE_STATE 0x10
|
||||
#define CDC_SET_HOOK_STATE 0x11
|
||||
#define CDC_PULSE_SETUP 0x12
|
||||
#define CDC_SEND_PULSE 0x13
|
||||
#define CDC_SET_PULSE_TIME 0x14
|
||||
#define CDC_RING_AUX_JACK 0x15
|
||||
#define CDC_SET_LINE_CODING 0x20
|
||||
#define CDC_GET_LINE_CODING 0x21
|
||||
#define CDC_SET_CONTROL_LINE_STATE 0x22
|
||||
#define CDC_SEND_BREAK 0x23
|
||||
#define CDC_SET_RINGER_PARMS 0x30
|
||||
#define CDC_GET_RINGER_PARMS 0x31
|
||||
#define CDC_SET_OPERATION_PARMS 0x32
|
||||
#define CDC_GET_OPERATION_PARMS 0x33
|
||||
/** @} */
|
||||
|
||||
/**
|
||||
* @name Line Control bit definitions.
|
||||
* @{
|
||||
*/
|
||||
#define LC_STOP_1 0
|
||||
#define LC_STOP_1P5 1
|
||||
#define LC_STOP_2 2
|
||||
|
||||
#define LC_PARITY_NONE 0
|
||||
#define LC_PARITY_ODD 1
|
||||
#define LC_PARITY_EVEN 2
|
||||
#define LC_PARITY_MARK 3
|
||||
#define LC_PARITY_SPACE 4
|
||||
/** @} */
|
||||
|
||||
/*===========================================================================*/
|
||||
/* 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
|
||||
/** @} */
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Derived constants and error checks. */
|
||||
/*===========================================================================*/
|
||||
|
||||
#if !HAL_USE_USB || !CH_USE_QUEUES || !CH_USE_EVENTS
|
||||
#error "Serial over USB Driver requires HAL_USE_USB, CH_USE_QUEUES, "
|
||||
"CH_USE_EVENTS"
|
||||
#endif
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Driver data structures and types. */
|
||||
/*===========================================================================*/
|
||||
|
||||
/**
|
||||
* @brief Type of Line Coding structure.
|
||||
*/
|
||||
typedef struct {
|
||||
uint8_t dwDTERate[4];
|
||||
uint8_t bCharFormat;
|
||||
uint8_t bParityType;
|
||||
uint8_t bDataBits;
|
||||
} cdc_linecoding_t;
|
||||
|
||||
/**
|
||||
* @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.
|
||||
*/
|
||||
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 queue.*/ \
|
||||
InputQueue iqueue; \
|
||||
/* Output queue.*/ \
|
||||
OutputQueue oqueue; \
|
||||
/* Input buffer.*/ \
|
||||
uint8_t ib[SERIAL_USB_BUFFERS_SIZE]; \
|
||||
/* Output buffer.*/ \
|
||||
uint8_t ob[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 *sdp);
|
||||
void sduStart(SerialUSBDriver *sdup, const SerialUSBConfig *config);
|
||||
void sduStop(SerialUSBDriver *sdup);
|
||||
void sduConfigureHookI(SerialUSBDriver *sdup);
|
||||
bool_t sduRequestsHook(USBDriver *usbp);
|
||||
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 */
|
||||
|
||||
#endif /* _SERIAL_USB_H_ */
|
||||
|
||||
/** @} */
|
331
Software/portapack-mayhem/firmware/chibios/os/hal/include/spi.h
Normal file
331
Software/portapack-mayhem/firmware/chibios/os/hal/include/spi.h
Normal file
@ -0,0 +1,331 @@
|
||||
/*
|
||||
ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010,
|
||||
2011,2012,2013 Giovanni Di Sirio.
|
||||
|
||||
This file is part of ChibiOS/RT.
|
||||
|
||||
ChibiOS/RT is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
ChibiOS/RT is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
---
|
||||
|
||||
A special exception to the GPL can be applied should you wish to distribute
|
||||
a combined work that includes ChibiOS/RT, without being obliged to provide
|
||||
the source code for any proprietary components. See the file exception.txt
|
||||
for full details of how and when the exception can be applied.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file spi.h
|
||||
* @brief SPI Driver macros and structures.
|
||||
*
|
||||
* @addtogroup SPI
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifndef _SPI_H_
|
||||
#define _SPI_H_
|
||||
|
||||
#if HAL_USE_SPI || 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. */
|
||||
/*===========================================================================*/
|
||||
|
||||
#if SPI_USE_MUTUAL_EXCLUSION && !CH_USE_MUTEXES && !CH_USE_SEMAPHORES
|
||||
#error "SPI_USE_MUTUAL_EXCLUSION requires CH_USE_MUTEXES and/or CH_USE_SEMAPHORES"
|
||||
#endif
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Driver data structures and types. */
|
||||
/*===========================================================================*/
|
||||
|
||||
/**
|
||||
* @brief Driver state machine possible states.
|
||||
*/
|
||||
typedef enum {
|
||||
SPI_UNINIT = 0, /**< Not initialized. */
|
||||
SPI_STOP = 1, /**< Stopped. */
|
||||
SPI_READY = 2, /**< Ready. */
|
||||
SPI_ACTIVE = 3, /**< Exchanging data. */
|
||||
SPI_COMPLETE = 4 /**< Asynchronous operation complete. */
|
||||
} spistate_t;
|
||||
|
||||
#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 || 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 SPI driver using
|
||||
* this function.
|
||||
*
|
||||
* @param[in] spip pointer to the @p SPIDriver object
|
||||
*
|
||||
* @notapi
|
||||
*/
|
||||
#define _spi_wait_s(spip) { \
|
||||
chDbgAssert((spip)->thread == NULL, \
|
||||
"_spi_wait(), #1", "already waiting"); \
|
||||
(spip)->thread = chThdSelf(); \
|
||||
chSchGoSleepS(THD_STATE_SUSPENDED); \
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Wakes up the waiting thread.
|
||||
*
|
||||
* @param[in] spip pointer to the @p SPIDriver object
|
||||
*
|
||||
* @notapi
|
||||
*/
|
||||
#define _spi_wakeup_isr(spip) { \
|
||||
chSysLockFromIsr(); \
|
||||
if ((spip)->thread != NULL) { \
|
||||
Thread *tp = (spip)->thread; \
|
||||
(spip)->thread = NULL; \
|
||||
tp->p_u.rdymsg = RDY_OK; \
|
||||
chSchReadyI(tp); \
|
||||
} \
|
||||
chSysUnlockFromIsr(); \
|
||||
}
|
||||
#else /* !SPI_USE_WAIT */
|
||||
#define _spi_wait_s(spip)
|
||||
#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
|
||||
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 /* SPI_USE_WAIT */
|
||||
#if SPI_USE_MUTUAL_EXCLUSION
|
||||
void spiAcquireBus(SPIDriver *spip);
|
||||
void spiReleaseBus(SPIDriver *spip);
|
||||
#endif /* SPI_USE_MUTUAL_EXCLUSION */
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* HAL_USE_SPI */
|
||||
|
||||
#endif /* _SPI_H_ */
|
||||
|
||||
/** @} */
|
125
Software/portapack-mayhem/firmware/chibios/os/hal/include/tm.h
Normal file
125
Software/portapack-mayhem/firmware/chibios/os/hal/include/tm.h
Normal file
@ -0,0 +1,125 @@
|
||||
/*
|
||||
ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010,
|
||||
2011,2012,2013 Giovanni Di Sirio.
|
||||
|
||||
This file is part of ChibiOS/RT.
|
||||
|
||||
ChibiOS/RT is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
ChibiOS/RT is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
---
|
||||
|
||||
A special exception to the GPL can be applied should you wish to distribute
|
||||
a combined work that includes ChibiOS/RT, without being obliged to provide
|
||||
the source code for any proprietary components. See the file exception.txt
|
||||
for full details of how and when the exception can be applied.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file tm.h
|
||||
* @brief Time Measurement driver header.
|
||||
*
|
||||
* @addtogroup TM
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifndef _TM_H_
|
||||
#define _TM_H_
|
||||
|
||||
#if HAL_USE_TM || defined(__DOXYGEN__)
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Driver constants. */
|
||||
/*===========================================================================*/
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Driver pre-compile time settings. */
|
||||
/*===========================================================================*/
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Derived constants and error checks. */
|
||||
/*===========================================================================*/
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Driver data structures and types. */
|
||||
/*===========================================================================*/
|
||||
|
||||
/**
|
||||
* @brief Type of a Time Measurement object.
|
||||
* @note Start/stop of measurements is performed through the function
|
||||
* pointers in order to avoid inlining of those functions which
|
||||
* could compromise measurement accuracy.
|
||||
* @note The maximum measurable time period depends on the implementation
|
||||
* of the realtime counter in the HAL driver.
|
||||
* @note The measurement is not 100% cycle-accurate, it can be in excess
|
||||
* of few cycles depending on the compiler and target architecture.
|
||||
* @note Interrupts can affect measurement if the measurement is performed
|
||||
* with interrupts enabled.
|
||||
*/
|
||||
typedef struct TimeMeasurement TimeMeasurement;
|
||||
|
||||
/**
|
||||
* @brief Time Measurement structure.
|
||||
*/
|
||||
struct TimeMeasurement {
|
||||
void (*start)(TimeMeasurement *tmp); /**< @brief Starts a measurement. */
|
||||
void (*stop)(TimeMeasurement *tmp); /**< @brief Stops a measurement. */
|
||||
halrtcnt_t last; /**< @brief Last measurement. */
|
||||
halrtcnt_t worst; /**< @brief Worst measurement. */
|
||||
halrtcnt_t best; /**< @brief Best measurement. */
|
||||
};
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Driver macros. */
|
||||
/*===========================================================================*/
|
||||
|
||||
/**
|
||||
* @brief Starts a measurement.
|
||||
* @pre The @p TimeMeasurement must be initialized.
|
||||
* @note This function can be invoked in any context.
|
||||
*
|
||||
* @param[in,out] tmp pointer to a @p TimeMeasurement structure
|
||||
*
|
||||
* @special
|
||||
*/
|
||||
#define tmStartMeasurement(tmp) (tmp)->start(tmp)
|
||||
|
||||
/**
|
||||
* @brief Stops a measurement.
|
||||
* @pre The @p TimeMeasurement must be initialized.
|
||||
* @note This function can be invoked in any context.
|
||||
*
|
||||
* @param[in,out] tmp pointer to a @p TimeMeasurement structure
|
||||
*
|
||||
* @special
|
||||
*/
|
||||
#define tmStopMeasurement(tmp) (tmp)->stop(tmp)
|
||||
|
||||
/*===========================================================================*/
|
||||
/* External declarations. */
|
||||
/*===========================================================================*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
void tmInit(void);
|
||||
void tmObjectInit(TimeMeasurement *tmp);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* HAL_USE_TM */
|
||||
|
||||
#endif /* _TM_H_ */
|
||||
|
||||
/** @} */
|
129
Software/portapack-mayhem/firmware/chibios/os/hal/include/uart.h
Normal file
129
Software/portapack-mayhem/firmware/chibios/os/hal/include/uart.h
Normal file
@ -0,0 +1,129 @@
|
||||
/*
|
||||
ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010,
|
||||
2011,2012,2013 Giovanni Di Sirio.
|
||||
|
||||
This file is part of ChibiOS/RT.
|
||||
|
||||
ChibiOS/RT is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
ChibiOS/RT is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
---
|
||||
|
||||
A special exception to the GPL can be applied should you wish to distribute
|
||||
a combined work that includes ChibiOS/RT, without being obliged to provide
|
||||
the source code for any proprietary components. See the file exception.txt
|
||||
for full details of how and when the exception can be applied.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file uart.h
|
||||
* @brief UART Driver macros and structures.
|
||||
*
|
||||
* @addtogroup UART
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifndef _UART_H_
|
||||
#define _UART_H_
|
||||
|
||||
#if HAL_USE_UART || 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. */
|
||||
/*===========================================================================*/
|
||||
|
||||
/*===========================================================================*/
|
||||
/* 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. */
|
||||
/*===========================================================================*/
|
||||
|
||||
/*===========================================================================*/
|
||||
/* 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);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* HAL_USE_UART */
|
||||
|
||||
#endif /* _UART_H_ */
|
||||
|
||||
/** @} */
|
585
Software/portapack-mayhem/firmware/chibios/os/hal/include/usb.h
Normal file
585
Software/portapack-mayhem/firmware/chibios/os/hal/include/usb.h
Normal file
@ -0,0 +1,585 @@
|
||||
/*
|
||||
ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010,
|
||||
2011,2012,2013 Giovanni Di Sirio.
|
||||
|
||||
This file is part of ChibiOS/RT.
|
||||
|
||||
ChibiOS/RT is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
ChibiOS/RT is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
---
|
||||
|
||||
A special exception to the GPL can be applied should you wish to distribute
|
||||
a combined work that includes ChibiOS/RT, without being obliged to provide
|
||||
the source code for any proprietary components. See the file exception.txt
|
||||
for full details of how and when the exception can be applied.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file usb.h
|
||||
* @brief USB Driver macros and structures.
|
||||
*
|
||||
* @addtogroup USB
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifndef _USB_H_
|
||||
#define _USB_H_
|
||||
|
||||
#if HAL_USE_USB || defined(__DOXYGEN__)
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Driver constants. */
|
||||
/*===========================================================================*/
|
||||
|
||||
#define USB_RTYPE_DIR_MASK 0x80
|
||||
#define USB_RTYPE_DIR_HOST2DEV 0x00
|
||||
#define USB_RTYPE_DIR_DEV2HOST 0x80
|
||||
#define USB_RTYPE_TYPE_MASK 0x60
|
||||
#define USB_RTYPE_TYPE_STD 0x00
|
||||
#define USB_RTYPE_TYPE_CLASS 0x20
|
||||
#define USB_RTYPE_TYPE_VENDOR 0x40
|
||||
#define USB_RTYPE_TYPE_RESERVED 0x60
|
||||
#define USB_RTYPE_RECIPIENT_MASK 0x1F
|
||||
#define USB_RTYPE_RECIPIENT_DEVICE 0x00
|
||||
#define USB_RTYPE_RECIPIENT_INTERFACE 0x01
|
||||
#define USB_RTYPE_RECIPIENT_ENDPOINT 0x02
|
||||
#define USB_RTYPE_RECIPIENT_OTHER 0x03
|
||||
|
||||
#define USB_REQ_GET_STATUS 0
|
||||
#define USB_REQ_CLEAR_FEATURE 1
|
||||
#define USB_REQ_SET_FEATURE 3
|
||||
#define USB_REQ_SET_ADDRESS 5
|
||||
#define USB_REQ_GET_DESCRIPTOR 6
|
||||
#define USB_REQ_SET_DESCRIPTOR 7
|
||||
#define USB_REQ_GET_CONFIGURATION 8
|
||||
#define USB_REQ_SET_CONFIGURATION 9
|
||||
#define USB_REQ_GET_INTERFACE 10
|
||||
#define USB_REQ_SET_INTERFACE 11
|
||||
#define USB_REQ_SYNCH_FRAME 12
|
||||
|
||||
#define USB_DESCRIPTOR_DEVICE 1
|
||||
#define USB_DESCRIPTOR_CONFIGURATION 2
|
||||
#define USB_DESCRIPTOR_STRING 3
|
||||
#define USB_DESCRIPTOR_INTERFACE 4
|
||||
#define USB_DESCRIPTOR_ENDPOINT 5
|
||||
#define USB_DESCRIPTOR_DEVICE_QUALIFIER 6
|
||||
#define USB_DESCRIPTOR_OTHER_SPEED_CFG 7
|
||||
#define USB_DESCRIPTOR_INTERFACE_POWER 8
|
||||
#define USB_DESCRIPTOR_INTERFACE_ASSOCIATION 11
|
||||
|
||||
#define USB_FEATURE_ENDPOINT_HALT 0
|
||||
#define USB_FEATURE_DEVICE_REMOTE_WAKEUP 1
|
||||
#define USB_FEATURE_TEST_MODE 2
|
||||
|
||||
#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) & 255), \
|
||||
(uint8_t)(((w) >> 8) & 255)
|
||||
|
||||
/**
|
||||
* @brief Helper macro for BCD values into descriptor strings.
|
||||
*/
|
||||
#define USB_DESC_BCD(bcd) \
|
||||
(uint8_t)((bcd) & 255), \
|
||||
(uint8_t)(((bcd) >> 8) & 255)
|
||||
|
||||
/**
|
||||
* @brief Device Descriptor helper macro.
|
||||
*/
|
||||
#define USB_DESC_DEVICE(bcdUSB, bDeviceClass, bDeviceSubClass, \
|
||||
bDeviceProtocol, bMaxPacketSize, idVendor, \
|
||||
idProduct, bcdDevice, iManufacturer, \
|
||||
iProduct, iSerialNumber, bNumConfigurations) \
|
||||
USB_DESC_BYTE(18), \
|
||||
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 helper macro.
|
||||
*/
|
||||
#define USB_DESC_CONFIGURATION(wTotalLength, bNumInterfaces, \
|
||||
bConfigurationValue, iConfiguration, \
|
||||
bmAttributes, bMaxPower) \
|
||||
USB_DESC_BYTE(9), \
|
||||
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 helper macro.
|
||||
*/
|
||||
#define USB_DESC_INTERFACE(bInterfaceNumber, bAlternateSetting, \
|
||||
bNumEndpoints, bInterfaceClass, \
|
||||
bInterfaceSubClass, bInterfaceProtocol, \
|
||||
iInterface) \
|
||||
USB_DESC_BYTE(9), \
|
||||
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 helper macro.
|
||||
*/
|
||||
#define USB_DESC_INTERFACE_ASSOCIATION(bFirstInterface, \
|
||||
bInterfaceCount, bFunctionClass, \
|
||||
bFunctionSubClass, bFunctionProcotol, \
|
||||
iInterface) \
|
||||
USB_DESC_BYTE(8), \
|
||||
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 helper macro.
|
||||
*/
|
||||
#define USB_DESC_ENDPOINT(bEndpointAddress, bmAttributes, wMaxPacketSize, \
|
||||
bInterval) \
|
||||
USB_DESC_BYTE(7), \
|
||||
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 0x0003 /**< Endpoint type mask. */
|
||||
#define USB_EP_MODE_TYPE_CTRL 0x0000 /**< Control endpoint. */
|
||||
#define USB_EP_MODE_TYPE_ISOC 0x0001 /**< Isochronous endpoint. */
|
||||
#define USB_EP_MODE_TYPE_BULK 0x0002 /**< Bulk endpoint. */
|
||||
#define USB_EP_MODE_TYPE_INTR 0x0003 /**< Interrupt endpoint. */
|
||||
#define USB_EP_MODE_LINEAR_BUFFER 0x0000 /**< Linear buffer mode. */
|
||||
#define USB_EP_MODE_QUEUE_BUFFER 0x0010 /**< Queue buffer mode. */
|
||||
/** @} */
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Driver pre-compile time settings. */
|
||||
/*===========================================================================*/
|
||||
|
||||
/*===========================================================================*/
|
||||
/* 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.*/
|
||||
} 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_t (*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 Fetches a 16 bits word value from an USB message.
|
||||
*
|
||||
* @param[in] p pointer to the 16 bits word
|
||||
*
|
||||
* @notapi
|
||||
*/
|
||||
#define usbFetchWord(p) ((uint16_t)*(p) | ((uint16_t)*((p) + 1) << 8))
|
||||
|
||||
/**
|
||||
* @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.
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
#define usbGetFrameNumber(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 & (1 << (ep)))
|
||||
|
||||
/**
|
||||
* @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 & (1 << (ep)))
|
||||
|
||||
/**
|
||||
* @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.
|
||||
*
|
||||
* @iclass
|
||||
*/
|
||||
#define usbGetReceiveTransactionSizeI(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
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
#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
|
||||
*/
|
||||
#define _usb_isr_invoke_in_cb(usbp, ep) { \
|
||||
(usbp)->transmitting &= ~(1 << (ep)); \
|
||||
(usbp)->epc[ep]->in_cb(usbp, ep); \
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Common ISR code, OUT endpoint event.
|
||||
*
|
||||
* @param[in] usbp pointer to the @p USBDriver object
|
||||
* @param[in] ep endpoint number
|
||||
*
|
||||
* @notapi
|
||||
*/
|
||||
#define _usb_isr_invoke_out_cb(usbp, ep) { \
|
||||
(usbp)->receiving &= ~(1 << (ep)); \
|
||||
(usbp)->epc[ep]->out_cb(usbp, ep); \
|
||||
}
|
||||
/** @} */
|
||||
|
||||
/*===========================================================================*/
|
||||
/* 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 usbPrepareReceive(USBDriver *usbp, usbep_t ep,
|
||||
uint8_t *buf, size_t n);
|
||||
void usbPrepareTransmit(USBDriver *usbp, usbep_t ep,
|
||||
const uint8_t *buf, size_t n);
|
||||
void usbPrepareQueuedReceive(USBDriver *usbp, usbep_t ep,
|
||||
InputQueue *iqp, size_t n);
|
||||
void usbPrepareQueuedTransmit(USBDriver *usbp, usbep_t ep,
|
||||
OutputQueue *oqp, size_t n);
|
||||
bool_t usbStartReceiveI(USBDriver *usbp, usbep_t ep);
|
||||
bool_t usbStartTransmitI(USBDriver *usbp, usbep_t ep);
|
||||
bool_t usbStallReceiveI(USBDriver *usbp, usbep_t ep);
|
||||
bool_t usbStallTransmitI(USBDriver *usbp, usbep_t ep);
|
||||
void _usb_reset(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 */
|
||||
|
||||
#endif /* _USB_H_ */
|
||||
|
||||
/** @} */
|
Reference in New Issue
Block a user