AVR: Cleanup code source.
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@11377 35acf78f-673a-0410-8e92-d51de3d6d3f4
This commit is contained in:
parent
386f0d66f7
commit
282bc3a8f0
|
@ -15,7 +15,7 @@
|
|||
*/
|
||||
|
||||
/**
|
||||
* @file hal_lld.c
|
||||
* @file ATMEGAxx/hal_lld.c
|
||||
* @brief AVR HAL subsystem low level driver code.
|
||||
*
|
||||
* @addtogroup HAL
|
||||
|
@ -24,25 +24,25 @@
|
|||
|
||||
#include "hal.h"
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Driver exported variables. */
|
||||
/*===========================================================================*/
|
||||
/*==========================================================================*/
|
||||
/* Driver exported variables. */
|
||||
/*==========================================================================*/
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Driver local variables and types. */
|
||||
/*===========================================================================*/
|
||||
/*==========================================================================*/
|
||||
/* Driver local variables and types. */
|
||||
/*==========================================================================*/
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Driver local functions. */
|
||||
/*===========================================================================*/
|
||||
/*==========================================================================*/
|
||||
/* Driver local functions. */
|
||||
/*==========================================================================*/
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Driver interrupt handlers. */
|
||||
/*===========================================================================*/
|
||||
/*==========================================================================*/
|
||||
/* Driver interrupt handlers. */
|
||||
/*==========================================================================*/
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Driver exported functions. */
|
||||
/*===========================================================================*/
|
||||
/*==========================================================================*/
|
||||
/* Driver exported functions. */
|
||||
/*==========================================================================*/
|
||||
|
||||
/**
|
||||
* @brief Low level HAL driver initialization.
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
*/
|
||||
|
||||
/**
|
||||
* @file hal_lld.h
|
||||
* @file ATMEGAxx/hal_lld.h
|
||||
* @brief AVR HAL subsystem low level driver header.
|
||||
*
|
||||
* @addtogroup HAL
|
||||
|
@ -25,9 +25,9 @@
|
|||
#ifndef HAL_LLD_H
|
||||
#define HAL_LLD_H
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Driver constants. */
|
||||
/*===========================================================================*/
|
||||
/*==========================================================================*/
|
||||
/* Driver constants. */
|
||||
/*==========================================================================*/
|
||||
|
||||
/**
|
||||
* @brief Defines the support for realtime counters in the HAL.
|
||||
|
@ -39,25 +39,25 @@
|
|||
*/
|
||||
#define PLATFORM_NAME "AVR"
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Driver pre-compile time settings. */
|
||||
/*===========================================================================*/
|
||||
/*==========================================================================*/
|
||||
/* Driver pre-compile time settings. */
|
||||
/*==========================================================================*/
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Derived constants and error checks. */
|
||||
/*===========================================================================*/
|
||||
/*==========================================================================*/
|
||||
/* Derived constants and error checks. */
|
||||
/*==========================================================================*/
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Driver data structures and types. */
|
||||
/*===========================================================================*/
|
||||
/*==========================================================================*/
|
||||
/* Driver data structures and types. */
|
||||
/*==========================================================================*/
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Driver macros. */
|
||||
/*===========================================================================*/
|
||||
/*==========================================================================*/
|
||||
/* Driver macros. */
|
||||
/*==========================================================================*/
|
||||
|
||||
/*===========================================================================*/
|
||||
/* External declarations. */
|
||||
/*===========================================================================*/
|
||||
/*==========================================================================*/
|
||||
/* External declarations. */
|
||||
/*==========================================================================*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
|
|
@ -26,26 +26,36 @@
|
|||
|
||||
#if HAL_USE_ADC || defined(__DOXYGEN__)
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Driver local definitions. */
|
||||
/*===========================================================================*/
|
||||
/*==========================================================================*/
|
||||
/* Driver local definitions. */
|
||||
/*==========================================================================*/
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Driver exported variables. */
|
||||
/*===========================================================================*/
|
||||
/*==========================================================================*/
|
||||
/* Driver exported variables. */
|
||||
/*==========================================================================*/
|
||||
/** @brief ADC1 driver identifier.*/
|
||||
#if AVR_ADC_USE_ADC1 || defined(__DOXYGEN__)
|
||||
ADCDriver ADCD1;
|
||||
#endif
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Driver local variables. */
|
||||
/*===========================================================================*/
|
||||
/*==========================================================================*/
|
||||
/* Driver local variables. */
|
||||
/*==========================================================================*/
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Driver local functions. */
|
||||
/*===========================================================================*/
|
||||
/*==========================================================================*/
|
||||
/* Driver local functions. */
|
||||
/*==========================================================================*/
|
||||
|
||||
/**
|
||||
* @brief Get the ADC channel.
|
||||
*
|
||||
* @param[in] mask the mask containing the channel number
|
||||
* @param[in] currentChannel the current channel.
|
||||
*
|
||||
* @return the channel number.
|
||||
* @retval ADC channel number
|
||||
* @retval -1 in case of error.
|
||||
*/
|
||||
static size_t getAdcChannelNumberFromMask(uint8_t mask,
|
||||
uint8_t currentChannel) {
|
||||
|
||||
|
@ -59,17 +69,22 @@ static size_t getAdcChannelNumberFromMask(uint8_t mask,
|
|||
}
|
||||
|
||||
/* error, should never reach this line */
|
||||
return -1; // To check
|
||||
return -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Configure the ADC channel.
|
||||
*
|
||||
* @param[in] channelNum the channel number to set.
|
||||
*/
|
||||
static void setAdcChannel(uint8_t channelNum) {
|
||||
|
||||
ADMUX = (ADMUX & 0xf8) | (channelNum & 0x07);
|
||||
}
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Driver interrupt handlers. */
|
||||
/*===========================================================================*/
|
||||
/*==========================================================================*/
|
||||
/* Driver interrupt handlers. */
|
||||
/*==========================================================================*/
|
||||
|
||||
#include <util/delay.h>
|
||||
|
||||
|
@ -101,9 +116,9 @@ OSAL_IRQ_HANDLER(ADC_vect) {
|
|||
OSAL_IRQ_EPILOGUE();
|
||||
}
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Driver exported functions. */
|
||||
/*===========================================================================*/
|
||||
/*==========================================================================*/
|
||||
/* Driver exported functions. */
|
||||
/*==========================================================================*/
|
||||
|
||||
/**
|
||||
* @brief Low level ADC driver initialization.
|
||||
|
@ -114,10 +129,10 @@ void adc_lld_init(void) {
|
|||
|
||||
adcObjectInit(&ADCD1);
|
||||
|
||||
//prescaler 128, only value possible at 20Mhz, interrupt
|
||||
/* Prescaler 128, only value possible at 20Mhz, interrupt. */
|
||||
ADCSRA = (1 << ADPS2) | (1 << ADPS1) | (1 << ADPS0) | (1 << ADIE);
|
||||
|
||||
//uso aref, only valid for arduino. arduino ha aref collegato
|
||||
/* uso aref, only valid for arduino. arduino ha aref collegato. */
|
||||
ADMUX = (0 << REFS1) | (0 << REFS0);
|
||||
}
|
||||
|
||||
|
@ -131,7 +146,7 @@ void adc_lld_init(void) {
|
|||
void adc_lld_start(ADCDriver *adcp) {
|
||||
|
||||
if (adcp->state == ADC_STOP) {
|
||||
/* Clock activation.*/
|
||||
/* Clock activation. */
|
||||
ADCSRA |= (1 << ADEN);
|
||||
}
|
||||
|
||||
|
@ -150,7 +165,7 @@ void adc_lld_start(ADCDriver *adcp) {
|
|||
void adc_lld_stop(ADCDriver *adcp) {
|
||||
|
||||
if (adcp->state == ADC_READY) {
|
||||
/* Clock de-activation.*/
|
||||
/* Clock de-activation. */
|
||||
ADCSRA &= ~(1 << ADEN);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,30 +27,30 @@
|
|||
|
||||
#if HAL_USE_ADC || defined(__DOXYGEN__)
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Driver constants. */
|
||||
/*===========================================================================*/
|
||||
/*==========================================================================*/
|
||||
/* Driver constants. */
|
||||
/*==========================================================================*/
|
||||
|
||||
#define ANALOG_REFERENCE_AREF 0
|
||||
#define ANALOG_REFERENCE_AVCC 1
|
||||
#define ANALOG_REFERENCE_1V1 2
|
||||
#define ANALOG_REFERENCE_2V56 3
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Driver pre-compile time settings. */
|
||||
/*===========================================================================*/
|
||||
/*==========================================================================*/
|
||||
/* Driver pre-compile time settings. */
|
||||
/*==========================================================================*/
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Derived constants and error checks. */
|
||||
/*===========================================================================*/
|
||||
/*==========================================================================*/
|
||||
/* Derived constants and error checks. */
|
||||
/*==========================================================================*/
|
||||
|
||||
#if !CH_CFG_USE_SEMAPHORES
|
||||
#error "the ADC driver requires CH_CFG_USE_SEMAPHORES"
|
||||
#endif
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Driver data structures and types. */
|
||||
/*===========================================================================*/
|
||||
/*==========================================================================*/
|
||||
/* Driver data structures and types. */
|
||||
/*==========================================================================*/
|
||||
|
||||
/**
|
||||
* @brief ADC sample data type.
|
||||
|
@ -167,13 +167,13 @@ struct ADCDriver {
|
|||
size_t currentBufferPosition;
|
||||
};
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Driver macros. */
|
||||
/*===========================================================================*/
|
||||
/*==========================================================================*/
|
||||
/* Driver macros. */
|
||||
/*==========================================================================*/
|
||||
|
||||
/*===========================================================================*/
|
||||
/* External declarations. */
|
||||
/*===========================================================================*/
|
||||
/*==========================================================================*/
|
||||
/* External declarations. */
|
||||
/*==========================================================================*/
|
||||
|
||||
#if AVR_ADC_USE_ADC1 && !defined(__DOXYGEN__)
|
||||
extern ADCDriver ADCD1;
|
||||
|
|
|
@ -26,26 +26,26 @@
|
|||
|
||||
#if HAL_USE_EXT || defined(__DOXYGEN__)
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Driver local definitions. */
|
||||
/*===========================================================================*/
|
||||
/*==========================================================================*/
|
||||
/* Driver local definitions. */
|
||||
/*==========================================================================*/
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Driver exported variables. */
|
||||
/*===========================================================================*/
|
||||
/*==========================================================================*/
|
||||
/* Driver exported variables. */
|
||||
/*==========================================================================*/
|
||||
|
||||
/**
|
||||
* @brief EXTD1 driver identifier.
|
||||
*/
|
||||
EXTDriver EXTD1;
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Driver local variables and types. */
|
||||
/*===========================================================================*/
|
||||
/*==========================================================================*/
|
||||
/* Driver local variables and types. */
|
||||
/*==========================================================================*/
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Driver local functions. */
|
||||
/*===========================================================================*/
|
||||
/*==========================================================================*/
|
||||
/* Driver local functions. */
|
||||
/*==========================================================================*/
|
||||
|
||||
/**
|
||||
* @brief Set the INTx interrupt trigger front or state.
|
||||
|
@ -159,9 +159,9 @@ void ext_lld_set_intx_edges(expchannel_t channel, uint8_t edge) {
|
|||
#endif
|
||||
}
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Driver interrupt handlers. */
|
||||
/*===========================================================================*/
|
||||
/*==========================================================================*/
|
||||
/* Driver interrupt handlers. */
|
||||
/*==========================================================================*/
|
||||
|
||||
#if AVR_EXT_USE_INT0 || defined(__DOXYGEN__)
|
||||
/**
|
||||
|
@ -236,9 +236,9 @@ OSAL_IRQ_HANDLER(INT5_vect) {
|
|||
}
|
||||
#endif
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Driver functions. */
|
||||
/*===========================================================================*/
|
||||
/*==========================================================================*/
|
||||
/* Driver functions. */
|
||||
/*==========================================================================*/
|
||||
|
||||
/**
|
||||
* @brief Enables an EXT channel.
|
||||
|
@ -331,7 +331,7 @@ void ext_lld_channel_disable(EXTDriver *extp, expchannel_t channel) {
|
|||
*/
|
||||
void ext_lld_init(void) {
|
||||
|
||||
/* Driver initialization.*/
|
||||
/* Driver initialization. */
|
||||
extObjectInit(&EXTD1);
|
||||
}
|
||||
|
||||
|
|
|
@ -27,31 +27,31 @@
|
|||
|
||||
#if HAL_USE_EXT || defined(__DOXYGEN__)
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Driver constants. */
|
||||
/*===========================================================================*/
|
||||
/*==========================================================================*/
|
||||
/* Driver constants. */
|
||||
/*==========================================================================*/
|
||||
|
||||
/**
|
||||
* @brief Maximum number of EXT channels.
|
||||
*/
|
||||
#define AVR_INT_NUM_LINES 6 /**< INT0 to INT5 */
|
||||
#define AVR_INT_NUM_LINES 6 /**< INT0 to INT5. */
|
||||
|
||||
/**
|
||||
* @brief Available number of EXT channels.
|
||||
*/
|
||||
#define EXT_MAX_CHANNELS AVR_INT_NUM_LINES
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Driver pre-compile time settings. */
|
||||
/*===========================================================================*/
|
||||
/*==========================================================================*/
|
||||
/* Driver pre-compile time settings. */
|
||||
/*==========================================================================*/
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Derived constants and error checks. */
|
||||
/*===========================================================================*/
|
||||
/*==========================================================================*/
|
||||
/* Derived constants and error checks. */
|
||||
/*==========================================================================*/
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Driver data structures and types. */
|
||||
/*===========================================================================*/
|
||||
/*==========================================================================*/
|
||||
/* Driver data structures and types. */
|
||||
/*==========================================================================*/
|
||||
|
||||
/**
|
||||
* @brief EXT channel identifier.
|
||||
|
@ -89,7 +89,7 @@ typedef struct {
|
|||
* @brief Channel configurations.
|
||||
*/
|
||||
EXTChannelConfig channels[EXT_MAX_CHANNELS];
|
||||
/* End of the mandatory fields.*/
|
||||
/* End of the mandatory fields. */
|
||||
} EXTConfig;
|
||||
|
||||
/**
|
||||
|
@ -105,16 +105,16 @@ struct EXTDriver {
|
|||
* @brief Current configuration data.
|
||||
*/
|
||||
const EXTConfig *config;
|
||||
/* End of the mandatory fields.*/
|
||||
/* End of the mandatory fields. */
|
||||
};
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Driver macros. */
|
||||
/*===========================================================================*/
|
||||
/*==========================================================================*/
|
||||
/* Driver macros. */
|
||||
/*==========================================================================*/
|
||||
|
||||
/*===========================================================================*/
|
||||
/* External declarations. */
|
||||
/*===========================================================================*/
|
||||
/*==========================================================================*/
|
||||
/* External declarations. */
|
||||
/*==========================================================================*/
|
||||
extern EXTDriver EXTD1;
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
|
|
@ -26,29 +26,29 @@
|
|||
|
||||
#if HAL_USE_PAL || defined(__DOXYGEN__)
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Driver exported variables. */
|
||||
/*===========================================================================*/
|
||||
/*==========================================================================*/
|
||||
/* Driver exported variables. */
|
||||
/*==========================================================================*/
|
||||
/**
|
||||
* @brief Event records for the 16 GPIO EXTI channels.
|
||||
*/
|
||||
palevent_t _pal_events[16];
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Driver local variables and types. */
|
||||
/*===========================================================================*/
|
||||
/*==========================================================================*/
|
||||
/* Driver local variables and types. */
|
||||
/*==========================================================================*/
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Driver local functions. */
|
||||
/*===========================================================================*/
|
||||
/*==========================================================================*/
|
||||
/* Driver local functions. */
|
||||
/*==========================================================================*/
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Driver interrupt handlers. */
|
||||
/*===========================================================================*/
|
||||
/*==========================================================================*/
|
||||
/* Driver interrupt handlers. */
|
||||
/*==========================================================================*/
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Driver exported functions. */
|
||||
/*===========================================================================*/
|
||||
/*==========================================================================*/
|
||||
/* Driver exported functions. */
|
||||
/*==========================================================================*/
|
||||
|
||||
/**
|
||||
* @brief AVR GPIO ports configuration.
|
||||
|
@ -180,13 +180,6 @@ void _pal_lld_enablepadevent(ioportid_t port,
|
|||
(void)arg;
|
||||
|
||||
/* TODO: Implement the interruption here. */
|
||||
/*
|
||||
#if (port == IOPORT4)
|
||||
#elif (port == IOPORT5)
|
||||
#else
|
||||
#error The selected port dont have an EXT INTx pin.
|
||||
*/
|
||||
//}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -29,16 +29,16 @@
|
|||
|
||||
#if HAL_USE_PAL || defined(__DOXYGEN__)
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Unsupported modes and specific modes. */
|
||||
/*===========================================================================*/
|
||||
/*==========================================================================*/
|
||||
/* Unsupported modes and specific modes. */
|
||||
/*==========================================================================*/
|
||||
|
||||
#undef PAL_MODE_INPUT_PULLDOWN
|
||||
#undef PAL_MODE_OUTPUT_OPENDRAIN
|
||||
|
||||
/*===========================================================================*/
|
||||
/* I/O Ports Types and constants. */
|
||||
/*===========================================================================*/
|
||||
/*==========================================================================*/
|
||||
/* I/O Ports Types and constants. */
|
||||
/*==========================================================================*/
|
||||
|
||||
/**
|
||||
* @brief Width, in bits, of an I/O port.
|
||||
|
@ -179,9 +179,9 @@ typedef struct {
|
|||
*/
|
||||
typedef uint8_t ioeventmode_t;
|
||||
|
||||
/*===========================================================================*/
|
||||
/* I/O Ports Identifiers. */
|
||||
/*===========================================================================*/
|
||||
/*==========================================================================*/
|
||||
/* I/O Ports Identifiers. */
|
||||
/*==========================================================================*/
|
||||
|
||||
#if defined(PORTA) || defined(__DOXYGEN__)
|
||||
/**
|
||||
|
@ -274,10 +274,10 @@ typedef uint8_t ioeventmode_t;
|
|||
#define IOPORTSPI1 ((volatile avr_gpio_registers_t *)&PIN_SPI1)
|
||||
#endif
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Implementation, some of the following macros could be implemented as */
|
||||
/* functions, if so please put them in hal_pal_lld.c. */
|
||||
/*===========================================================================*/
|
||||
/*==========================================================================*/
|
||||
/* Implementation, some of the following macros could be implemented as */
|
||||
/* functions, if so please put them in hal_pal_lld.c. */
|
||||
/*==========================================================================*/
|
||||
|
||||
/**
|
||||
* @brief Low level PAL subsystem initialization.
|
||||
|
|
|
@ -26,30 +26,30 @@
|
|||
|
||||
#if HAL_USE_I2C || defined(__DOXYGEN__)
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Driver local definitions. */
|
||||
/*===========================================================================*/
|
||||
/*==========================================================================*/
|
||||
/* Driver local definitions. */
|
||||
/*==========================================================================*/
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Driver exported variables. */
|
||||
/*===========================================================================*/
|
||||
/*==========================================================================*/
|
||||
/* Driver exported variables. */
|
||||
/*==========================================================================*/
|
||||
|
||||
/** @brief I2C driver identifier.*/
|
||||
/** @brief I2C driver identifier. */
|
||||
#if AVR_I2C_USE_I2C1 || defined(__DOXYGEN__)
|
||||
I2CDriver I2CD1;
|
||||
#endif
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Driver local variables and types. */
|
||||
/*===========================================================================*/
|
||||
/*==========================================================================*/
|
||||
/* Driver local variables and types. */
|
||||
/*==========================================================================*/
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Driver local functions. */
|
||||
/*===========================================================================*/
|
||||
/*==========================================================================*/
|
||||
/* Driver local functions. */
|
||||
/*==========================================================================*/
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Driver interrupt handlers. */
|
||||
/*===========================================================================*/
|
||||
/*==========================================================================*/
|
||||
/* Driver interrupt handlers. */
|
||||
/*==========================================================================*/
|
||||
|
||||
#if AVR_I2C_USE_I2C1 || defined(__DOXYGEN__)
|
||||
/**
|
||||
|
@ -120,7 +120,7 @@ OSAL_IRQ_HANDLER(TWI_vect) {
|
|||
i2cp->errors |= I2C_BUS_ERROR;
|
||||
break;
|
||||
default:
|
||||
/* FIXME: only gets here if there are other MASTERs in the bus */
|
||||
/* FIXME: only gets here if there are other MASTERs in the bus. */
|
||||
TWCR = ((1 << TWSTO) | (1 << TWINT) | (1 << TWEN));
|
||||
_i2c_wakeup_error_isr(i2cp);
|
||||
}
|
||||
|
@ -134,9 +134,9 @@ OSAL_IRQ_HANDLER(TWI_vect) {
|
|||
}
|
||||
#endif /* AVR_I2C_USE_I2C1 */
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Driver exported functions. */
|
||||
/*===========================================================================*/
|
||||
/*==========================================================================*/
|
||||
/* Driver exported functions. */
|
||||
/*==========================================================================*/
|
||||
|
||||
/**
|
||||
* @brief Low level I2C driver initialization.
|
||||
|
@ -160,15 +160,15 @@ void i2c_lld_start(I2CDriver *i2cp) {
|
|||
|
||||
uint32_t clock_speed = 100000;
|
||||
|
||||
/* TODO: Test TWI without external pull-ups (use internal) */
|
||||
/* TODO: Test TWI without external pull-ups (use internal). */
|
||||
|
||||
/* Configure prescaler to 1 */
|
||||
/* Configure prescaler to 1. */
|
||||
TWSR &= 0xF8;
|
||||
|
||||
if (i2cp->config != NULL)
|
||||
clock_speed = i2cp->config->clock_speed;
|
||||
|
||||
/* Configure baudrate */
|
||||
/* Configure baudrate. */
|
||||
TWBR = ((F_CPU / clock_speed) - 16) / 2;
|
||||
}
|
||||
|
||||
|
@ -182,7 +182,7 @@ void i2c_lld_start(I2CDriver *i2cp) {
|
|||
void i2c_lld_stop(I2CDriver *i2cp) {
|
||||
|
||||
if (i2cp->state != I2C_STOP) {
|
||||
/* Disable TWI subsystem and stop all operations */
|
||||
/* Disable TWI subsystem and stop all operations. */
|
||||
TWCR &= ~(1 << TWEN);
|
||||
}
|
||||
}
|
||||
|
@ -196,7 +196,7 @@ void i2c_lld_stop(I2CDriver *i2cp) {
|
|||
* @param[in] rxbytes number of bytes to be received
|
||||
* @param[in] timeout the number of ticks before the operation timeouts,
|
||||
* the following special values are allowed:
|
||||
* - @a TIME_INFINITE no timeout.
|
||||
* - @a TIME_INFINITE no timeout
|
||||
*
|
||||
* @return The operation status.
|
||||
* @retval MSG_OK if the function succeeded.
|
||||
|
@ -221,7 +221,7 @@ msg_t i2c_lld_master_receive_timeout(I2CDriver *i2cp, i2caddr_t addr,
|
|||
i2cp->rxbytes = rxbytes;
|
||||
i2cp->rxidx = 0;
|
||||
|
||||
/* Send START */
|
||||
/* Send START. */
|
||||
TWCR = ((1 << TWSTA) | (1 << TWINT) | (1 << TWEN) | (1 << TWIE));
|
||||
|
||||
return osalThreadSuspendTimeoutS(&i2cp->thread, TIME_INFINITE);
|
||||
|
@ -238,7 +238,7 @@ msg_t i2c_lld_master_receive_timeout(I2CDriver *i2cp, i2caddr_t addr,
|
|||
* @param[in] rxbytes number of bytes to be received
|
||||
* @param[in] timeout the number of ticks before the operation timeouts,
|
||||
* the following special values are allowed:
|
||||
* - @a TIME_INFINITE no timeout.
|
||||
* - @a TIME_INFINITE no timeout
|
||||
*
|
||||
* @return The operation status.
|
||||
* @retval MSG_OK if the function succeeded.
|
||||
|
|
|
@ -27,40 +27,40 @@
|
|||
|
||||
#if HAL_USE_I2C || defined(__DOXYGEN__)
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Driver constants. */
|
||||
/*===========================================================================*/
|
||||
/*==========================================================================*/
|
||||
/* Driver constants. */
|
||||
/*==========================================================================*/
|
||||
|
||||
/** @brief START transmitted.*/
|
||||
/** @brief START transmitted. */
|
||||
#define TWI_START 0x08
|
||||
/** @brief Repeated START transmitted.*/
|
||||
/** @brief Repeated START transmitted. */
|
||||
#define TWI_REPEAT_START 0x10
|
||||
/** @brief Arbitration Lost.*/
|
||||
/** @brief Arbitration Lost. */
|
||||
#define TWI_ARBITRATION_LOST 0x38
|
||||
/** @brief Bus errors.*/
|
||||
/** @brief Bus errors. */
|
||||
#define TWI_BUS_ERROR 0x00
|
||||
|
||||
/** @brief SLA+W transmitted with ACK response.*/
|
||||
/** @brief SLA+W transmitted with ACK response. */
|
||||
#define TWI_MASTER_TX_ADDR_ACK 0x18
|
||||
/** @brief SLA+W transmitted with NACK response.*/
|
||||
/** @brief SLA+W transmitted with NACK response. */
|
||||
#define TWI_MASTER_TX_ADDR_NACK 0x20
|
||||
/** @brief DATA transmitted with ACK response.*/
|
||||
/** @brief DATA transmitted with ACK response. */
|
||||
#define TWI_MASTER_TX_DATA_ACK 0x28
|
||||
/** @brief DATA transmitted with NACK response.*/
|
||||
/** @brief DATA transmitted with NACK response. */
|
||||
#define TWI_MASTER_TX_DATA_NACK 0x30
|
||||
|
||||
/** @brief SLA+R transmitted with ACK response.*/
|
||||
/** @brief SLA+R transmitted with ACK response. */
|
||||
#define TWI_MASTER_RX_ADDR_ACK 0x40
|
||||
/** @brief SLA+R transmitted with NACK response.*/
|
||||
/** @brief SLA+R transmitted with NACK response. */
|
||||
#define TWI_MASTER_RX_ADDR_NACK 0x48
|
||||
/** @brief DATA received with ACK response.*/
|
||||
/** @brief DATA received with ACK response. */
|
||||
#define TWI_MASTER_RX_DATA_ACK 0x50
|
||||
/** @brief DATA received with NACK response.*/
|
||||
/** @brief DATA received with NACK response. */
|
||||
#define TWI_MASTER_RX_DATA_NACK 0x58
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Driver pre-compile time settings. */
|
||||
/*===========================================================================*/
|
||||
/*==========================================================================*/
|
||||
/* Driver pre-compile time settings. */
|
||||
/*==========================================================================*/
|
||||
|
||||
/**
|
||||
* @name Configuration options
|
||||
|
@ -76,13 +76,13 @@
|
|||
#endif
|
||||
/** @} */
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Derived constants and error checks. */
|
||||
/*===========================================================================*/
|
||||
/*==========================================================================*/
|
||||
/* Derived constants and error checks. */
|
||||
/*==========================================================================*/
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Driver data structures and types. */
|
||||
/*===========================================================================*/
|
||||
/*==========================================================================*/
|
||||
/* Driver data structures and types. */
|
||||
/*==========================================================================*/
|
||||
|
||||
/**
|
||||
* @brief Type representing I2C address.
|
||||
|
@ -133,7 +133,7 @@ struct I2CDriver {
|
|||
#if defined(I2C_DRIVER_EXT_FIELDS)
|
||||
I2C_DRIVER_EXT_FIELDS
|
||||
#endif
|
||||
/* End of the mandatory fields.*/
|
||||
/* End of the mandatory fields. */
|
||||
/**
|
||||
* @brief Thread waiting for I/O completion.
|
||||
*/
|
||||
|
@ -173,9 +173,9 @@ struct I2CDriver {
|
|||
*/
|
||||
typedef struct I2CDriver I2CDriver;
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Driver macros. */
|
||||
/*===========================================================================*/
|
||||
/*==========================================================================*/
|
||||
/* Driver macros. */
|
||||
/*==========================================================================*/
|
||||
|
||||
/**
|
||||
* @brief Get errors from I2C driver.
|
||||
|
@ -186,9 +186,9 @@ typedef struct I2CDriver I2CDriver;
|
|||
*/
|
||||
#define i2c_lld_get_errors(i2cp) ((i2cp)->errors)
|
||||
|
||||
/*===========================================================================*/
|
||||
/* External declarations. */
|
||||
/*===========================================================================*/
|
||||
/*==========================================================================*/
|
||||
/* External declarations. */
|
||||
/*==========================================================================*/
|
||||
|
||||
#if !defined(__DOXYGEN__)
|
||||
#if AVR_I2C_USE_I2C1
|
||||
|
|
|
@ -26,15 +26,15 @@
|
|||
|
||||
#if HAL_USE_SPI || defined(__DOXYGEN__)
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Driver local definitions. */
|
||||
/*===========================================================================*/
|
||||
/*==========================================================================*/
|
||||
/* Driver local definitions. */
|
||||
/*==========================================================================*/
|
||||
|
||||
#define DUMMY_SPI_SEND_VALUE 0xFF
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Driver exported variables. */
|
||||
/*===========================================================================*/
|
||||
/*==========================================================================*/
|
||||
/* Driver exported variables. */
|
||||
/*==========================================================================*/
|
||||
|
||||
/**
|
||||
* @brief SPI1 driver identifier.
|
||||
|
@ -43,17 +43,17 @@
|
|||
SPIDriver SPID1;
|
||||
#endif
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Driver local variables and types. */
|
||||
/*===========================================================================*/
|
||||
/*==========================================================================*/
|
||||
/* Driver local variables and types. */
|
||||
/*==========================================================================*/
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Driver local functions. */
|
||||
/*===========================================================================*/
|
||||
/*==========================================================================*/
|
||||
/* Driver local functions. */
|
||||
/*==========================================================================*/
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Driver interrupt handlers. */
|
||||
/*===========================================================================*/
|
||||
/*==========================================================================*/
|
||||
/* Driver interrupt handlers. */
|
||||
/*==========================================================================*/
|
||||
|
||||
#if AVR_SPI_USE_SPI1 || defined(__DOXYGEN__)
|
||||
/**
|
||||
|
@ -66,16 +66,16 @@ OSAL_IRQ_HANDLER(SPI_STC_vect) {
|
|||
|
||||
SPIDriver *spip = &SPID1;
|
||||
|
||||
/* a new value has arrived, store it if we are interested in it */
|
||||
/* A new value has arrived, store it if we are interested in it. */
|
||||
if (spip->rxbuf) spip->rxbuf[spip->exidx] = SPDR;
|
||||
|
||||
/* check if we are done */
|
||||
/* Check if we are done. */
|
||||
if (++(spip->exidx) >= spip->exbytes) {
|
||||
_spi_isr_code(spip);
|
||||
} else { /* if not done send the next byte */
|
||||
if (spip->txbuf) { /* if there is a buffer with values to be send then use it*/
|
||||
} else { /* If not done send the next byte. */
|
||||
if (spip->txbuf) { /* If there is a buffer with values to be send then use it. */
|
||||
SPDR = spip->txbuf[spip->exidx];
|
||||
} else { /* if there isn't a buffer with values to be send then send a the dummy value*/
|
||||
} else { /* If there isn't a buffer with values to be send then send a the dummy value. */
|
||||
SPDR = DUMMY_SPI_SEND_VALUE;
|
||||
}
|
||||
}
|
||||
|
@ -95,7 +95,7 @@ OSAL_IRQ_HANDLER(SPI_STC_vect) {
|
|||
void spi_lld_init(void) {
|
||||
|
||||
#if AVR_SPI_USE_SPI1
|
||||
/* Driver initialization.*/
|
||||
/* Driver initialization. */
|
||||
spiObjectInit(&SPID1);
|
||||
#endif /* AVR_SPI_USE_SPI1 */
|
||||
}
|
||||
|
@ -112,10 +112,10 @@ void spi_lld_start(SPIDriver *spip) {
|
|||
uint8_t dummy;
|
||||
|
||||
if (spip->state == SPI_STOP) {
|
||||
/* Enables the peripheral.*/
|
||||
/* Enables the peripheral. */
|
||||
#if AVR_SPI_USE_SPI1
|
||||
if (&SPID1 == spip) {
|
||||
/* Enable SPI clock using Power Reduction Register */
|
||||
/* Enable SPI clock using Power Reduction Register. */
|
||||
#if defined(PRR0)
|
||||
PRR0 &= ~(1 << PRSPI);
|
||||
#elif defined(PRR)
|
||||
|
@ -127,20 +127,20 @@ void spi_lld_start(SPIDriver *spip) {
|
|||
|
||||
#if AVR_SPI_USE_SPI1
|
||||
if (&SPID1 == spip) {
|
||||
/* Configures the peripheral.*/
|
||||
/* Configures the peripheral. */
|
||||
/* Note that some bits are forced:
|
||||
SPI interrupt disabled,
|
||||
SPI enabled,
|
||||
SPI master enabled */
|
||||
SPI master enabled. */
|
||||
SPCR = (spip->config->spcr & ~(SPI_CR_SPIE)) | SPI_CR_MSTR | SPI_CR_SPE;
|
||||
SPSR = spip->config->spsr;
|
||||
|
||||
/* dummy reads before enabling interrupt */
|
||||
/* Dummy reads before enabling interrupt. */
|
||||
dummy = SPSR;
|
||||
dummy = SPDR;
|
||||
(void) dummy; /* suppress warning about unused variable */
|
||||
(void) dummy; /* Suppress warning about unused variable. */
|
||||
|
||||
/* Enable SPI interrupts */
|
||||
/* Enable SPI interrupts. */
|
||||
SPCR |= SPI_CR_SPIE;
|
||||
}
|
||||
#endif /* AVR_SPI_USE_SPI1 */
|
||||
|
@ -156,14 +156,14 @@ void spi_lld_start(SPIDriver *spip) {
|
|||
void spi_lld_stop(SPIDriver *spip) {
|
||||
|
||||
if (spip->state == SPI_READY) {
|
||||
/* Resets the peripheral.*/
|
||||
/* Resets the peripheral. */
|
||||
|
||||
/* Disables the peripheral.*/
|
||||
/* Disables the peripheral. */
|
||||
#if AVR_SPI_USE_SPI1
|
||||
if (&SPID1 == spip) {
|
||||
SPCR &= (SPI_CR_SPIE | SPI_CR_SPE);
|
||||
}
|
||||
/* Disable SPI clock using Power Reduction Register */
|
||||
/* Disable SPI clock using Power Reduction Register. */
|
||||
#if defined(PRR0)
|
||||
PRR0 |= (1 << PRSPI);
|
||||
#elif defined(PRR)
|
||||
|
@ -251,7 +251,7 @@ uint16_t spi_lld_polled_exchange(SPIDriver *spip, uint16_t frame) {
|
|||
uint8_t dummy;
|
||||
(void)spip;
|
||||
|
||||
/* disable interrupt */
|
||||
/* Disable interrupt. */
|
||||
SPCR &= ~(SPI_CR_SPIE);
|
||||
|
||||
SPDR = frame >> 8;
|
||||
|
@ -264,7 +264,7 @@ uint16_t spi_lld_polled_exchange(SPIDriver *spip, uint16_t frame) {
|
|||
|
||||
dummy = SPSR;
|
||||
dummy = SPDR;
|
||||
(void) dummy; /* suppress warning about unused variable */
|
||||
(void) dummy; /* Suppress warning about unused variable. */
|
||||
SPCR |= SPI_CR_SPIE;
|
||||
|
||||
return spdr;
|
||||
|
@ -276,7 +276,7 @@ uint8_t spi_lld_polled_exchange(SPIDriver *spip, uint8_t frame) {
|
|||
uint8_t dummy;
|
||||
(void)spip;
|
||||
|
||||
/* disable interrupt */
|
||||
/* Disable interrupt. */
|
||||
SPCR &= ~(SPI_CR_SPIE);
|
||||
|
||||
SPDR = frame;
|
||||
|
@ -285,7 +285,7 @@ uint8_t spi_lld_polled_exchange(SPIDriver *spip, uint8_t frame) {
|
|||
|
||||
dummy = SPSR;
|
||||
dummy = SPDR;
|
||||
(void) dummy; /* suppress warning about unused variable */
|
||||
(void) dummy; /* Suppress warning about unused variable. */
|
||||
SPCR |= SPI_CR_SPIE;
|
||||
|
||||
return spdr;
|
||||
|
|
|
@ -27,9 +27,9 @@
|
|||
|
||||
#if HAL_USE_SPI || defined(__DOXYGEN__)
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Driver constants. */
|
||||
/*===========================================================================*/
|
||||
/*==========================================================================*/
|
||||
/* Driver constants. */
|
||||
/*==========================================================================*/
|
||||
|
||||
/**
|
||||
* @name SPI Configuration Register
|
||||
|
@ -72,9 +72,9 @@
|
|||
#define SPI_SR_SCK_FOSC_128 (0 << SPI2X)
|
||||
/** @} */
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Driver pre-compile time settings. */
|
||||
/*===========================================================================*/
|
||||
/*==========================================================================*/
|
||||
/* Driver pre-compile time settings. */
|
||||
/*==========================================================================*/
|
||||
|
||||
/**
|
||||
* @name Configuration options
|
||||
|
@ -89,13 +89,13 @@
|
|||
#endif
|
||||
/** @} */
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Derived constants and error checks. */
|
||||
/*===========================================================================*/
|
||||
/*==========================================================================*/
|
||||
/* Derived constants and error checks. */
|
||||
/*==========================================================================*/
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Driver data structures and types. */
|
||||
/*===========================================================================*/
|
||||
/*==========================================================================*/
|
||||
/* Driver data structures and types. */
|
||||
/*==========================================================================*/
|
||||
|
||||
/**
|
||||
* @brief Type of a structure representing an SPI driver.
|
||||
|
@ -120,7 +120,7 @@ typedef struct {
|
|||
* @brief Operation complete callback.
|
||||
*/
|
||||
spicallback_t end_cb;
|
||||
/* End of the mandatory fields.*/
|
||||
/* End of the mandatory fields. */
|
||||
/**
|
||||
* @brief Port used of Slave Select
|
||||
*/
|
||||
|
@ -168,7 +168,7 @@ struct SPIDriver {
|
|||
#if defined(SPI_DRIVER_EXT_FIELDS)
|
||||
SPI_DRIVER_EXT_FIELDS
|
||||
#endif
|
||||
/* End of the mandatory fields.*/
|
||||
/* End of the mandatory fields. */
|
||||
/**
|
||||
* @brief Pointer to the buffer with data to send.
|
||||
*/
|
||||
|
@ -187,9 +187,9 @@ struct SPIDriver {
|
|||
size_t exidx;
|
||||
};
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Driver macros. */
|
||||
/*===========================================================================*/
|
||||
/*==========================================================================*/
|
||||
/* Driver macros. */
|
||||
/*==========================================================================*/
|
||||
|
||||
/**
|
||||
* @brief Ignores data on the SPI bus.
|
||||
|
@ -234,9 +234,9 @@ struct SPIDriver {
|
|||
*/
|
||||
#define spi_lld_receive(spip, n, rxbuf) spi_lld_exchange(spip, n, NULL, rxbuf)
|
||||
|
||||
/*===========================================================================*/
|
||||
/* External declarations. */
|
||||
/*===========================================================================*/
|
||||
/*==========================================================================*/
|
||||
/* External declarations. */
|
||||
/*==========================================================================*/
|
||||
|
||||
#if AVR_SPI_USE_SPI1 && !defined(__DOXYGEN__)
|
||||
extern SPIDriver SPID1;
|
||||
|
|
|
@ -26,25 +26,25 @@
|
|||
|
||||
#if HAL_USE_PAL || defined(__DOXYGEN__)
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Driver exported variables. */
|
||||
/*===========================================================================*/
|
||||
/*==========================================================================*/
|
||||
/* Driver exported variables. */
|
||||
/*==========================================================================*/
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Driver local variables and types. */
|
||||
/*===========================================================================*/
|
||||
/*==========================================================================*/
|
||||
/* Driver local variables and types. */
|
||||
/*==========================================================================*/
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Driver local functions. */
|
||||
/*===========================================================================*/
|
||||
/*==========================================================================*/
|
||||
/* Driver local functions. */
|
||||
/*==========================================================================*/
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Driver interrupt handlers. */
|
||||
/*===========================================================================*/
|
||||
/*==========================================================================*/
|
||||
/* Driver interrupt handlers. */
|
||||
/*==========================================================================*/
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Driver exported functions. */
|
||||
/*===========================================================================*/
|
||||
/*==========================================================================*/
|
||||
/* Driver exported functions. */
|
||||
/*==========================================================================*/
|
||||
|
||||
/**
|
||||
* @brief AVR GPIO ports configuration.
|
||||
|
@ -117,9 +117,9 @@ void _pal_lld_init(const PALConfig *config) {
|
|||
* @details This function programs a pads group belonging to the same port
|
||||
* with the specified mode.
|
||||
*
|
||||
* @param[in] port the port identifier
|
||||
* @param[in] mask the group mask
|
||||
* @param[in] mode the mode
|
||||
* @param[in] port the port identifier
|
||||
* @param[in] mask the group mask
|
||||
* @param[in] mode the mode
|
||||
*
|
||||
* @note This function is not meant to be invoked directly by the application
|
||||
* code.
|
||||
|
@ -129,9 +129,9 @@ void _pal_lld_init(const PALConfig *config) {
|
|||
*
|
||||
* @notapi
|
||||
*/
|
||||
void _pal_lld_setgroupmode(ioportid_t port,
|
||||
void _pal_lld_setgroupmode(ioportid_t port,
|
||||
ioportmask_t mask,
|
||||
iomode_t mode) {
|
||||
iomode_t mode) {
|
||||
|
||||
switch (mode) {
|
||||
case PAL_MODE_RESET:
|
||||
|
|
|
@ -282,7 +282,7 @@ typedef uint8_t ioeventmode_t;
|
|||
/**
|
||||
* @brief Low level PAL subsystem initialization.
|
||||
*
|
||||
* @param[in] config the architecture-dependent ports configuration
|
||||
* @param[in] config the architecture-dependent ports configuration
|
||||
*
|
||||
* @notapi
|
||||
*/
|
||||
|
|
|
@ -161,7 +161,7 @@ OSAL_IRQ_HANDLER(TIMER1_COMPA_vect) {
|
|||
|
||||
OSAL_IRQ_PROLOGUE();
|
||||
|
||||
// TODO: reset status if required
|
||||
/* TODO: reset status if required. */
|
||||
|
||||
osalSysLockFromISR();
|
||||
osalOsTimerHandlerI();
|
||||
|
@ -189,15 +189,15 @@ void st_lld_init(void) {
|
|||
* Periodic mode uses Timer 1 (16 bit).
|
||||
*/
|
||||
|
||||
/* CTC mode, no clock source */
|
||||
/* CTC mode, no clock source. */
|
||||
TCCR1A = 0;
|
||||
TCCR1B = _BV(WGM12);
|
||||
|
||||
/* start disabled */
|
||||
/* Start disabled. */
|
||||
TCCR1C = 0;
|
||||
OCR1A = 0;
|
||||
TCNT1 = 0;
|
||||
TIFR_REG = _BV(OCF1A); /* Reset pending. */
|
||||
TIFR_REG = _BV(OCF1A); /* Reset pending. */
|
||||
TIMSK_REG = 0;
|
||||
TCCR1B = PRESCALER;
|
||||
|
||||
|
@ -208,38 +208,39 @@ void st_lld_init(void) {
|
|||
/*
|
||||
* Periodic mode uses Timer 0 (8 bit).
|
||||
*/
|
||||
#if defined(TCCR0B) /* Timer has multiple output comparators */
|
||||
TCCR0A = (1 << WGM01) | (0 << WGM00) | /* CTC mode. */
|
||||
(0 << COM0A1) | (0 << COM0A0); /* OC0A disabled. */
|
||||
//(0 << COM0B1) | (0 << COM0B0); /* OC0B disabled. */
|
||||
// FIXME: See if the line bellow must be delate or recoded.
|
||||
//TCCR0B = (0 << WGM02) | AVR_TIMER_PRESCALER_BITS; /* CTC mode. */
|
||||
#if defined(TCCR0B) /* Timer has multiple output comparators. */
|
||||
TCCR0A = (1 << WGM01) | (0 << WGM00) | /* CTC mode. */
|
||||
(0 << COM0A1) | (0 << COM0A0); /* OC0A disabled. */
|
||||
//(0 << COM0B1) | (0 << COM0B0); /* OC0B disabled. */
|
||||
/* FIXME: See if the line bellow must be delate or recoded. */
|
||||
//TCCR0B = (0 << WGM02) | AVR_TIMER_PRESCALER_BITS; /* CTC mode. */
|
||||
OCR0A = AVR_TIMER_COUNTER - 1;
|
||||
TCNT0 = 0; /* Reset counter. */
|
||||
TCNT0 = 0; /* Reset counter. */
|
||||
#if defined(__AVR_ATtiny85__)
|
||||
TIFR = (1 << OCF0A); /* Reset pending. */
|
||||
TIMSK = (1 << OCIE0A); /* IRQ on compare. */
|
||||
TIFR = (1 << OCF0A); /* Reset pending. */
|
||||
TIMSK = (1 << OCIE0A); /* IRQ on compare. */
|
||||
#else
|
||||
TIFR0 = (1 << OCF0A); /* Reset pending. */
|
||||
TIMSK0 = (1 << OCIE0A); /* IRQ on compare. */
|
||||
TIFR0 = (1 << OCF0A); /* Reset pending. */
|
||||
TIMSK0 = (1 << OCIE0A); /* IRQ on compare. */
|
||||
#endif
|
||||
|
||||
#elif defined(TCCR0A) /* AT90CAN doesn't have TCCR0B and slightly different TCCR0A */
|
||||
TCCR0A = (1 << WGM01) | (0 << WGM00) | /* CTC mode. */
|
||||
(0 << COM0A1) | (0 << COM0A0); /* OC0A disabled. */
|
||||
#elif defined(TCCR0A) /* AT90CAN doesn't have TCCR0B and slightly different */
|
||||
/* TCCR0A. */
|
||||
TCCR0A = (1 << WGM01) | (0 << WGM00) | /* CTC mode. */
|
||||
(0 << COM0A1) | (0 << COM0A0); /* OC0A disabled. */
|
||||
OCR0A = AVR_TIMER_COUNTER - 1;
|
||||
TCNT0 = 0; /* Reset counter. */
|
||||
TIFR0 = (1 << OCF0A); /* Reset pending. */
|
||||
TIMSK0 = (1 << OCIE0A); /* IRQ on compare. */
|
||||
TCNT0 = 0; /* Reset counter. */
|
||||
TIFR0 = (1 << OCF0A); /* Reset pending. */
|
||||
TIMSK0 = (1 << OCIE0A); /* IRQ on compare. */
|
||||
|
||||
#elif defined(TCCR0) /* Timer has single output comparator */
|
||||
TCCR0 = (1 << WGM01) | (0 << WGM00) | /* CTC mode. */
|
||||
(0 << COM01) | (0 << COM00) | /* OC0A disabled. */
|
||||
#elif defined(TCCR0) /* Timer has single output comparator */
|
||||
TCCR0 = (1 << WGM01) | (0 << WGM00) | /* CTC mode. */
|
||||
(0 << COM01) | (0 << COM00) | /* OC0A disabled. */
|
||||
AVR_TIMER_PRESCALER_BITS;
|
||||
OCR0 = AVR_TIMER_COUNTER - 1;
|
||||
TCNT0 = 0; /* Reset counter. */
|
||||
TIFR = (1 << OCF0); /* Reset pending. */
|
||||
TIMSK = (1 << OCIE0); /* IRQ on compare. */
|
||||
TCNT0 = 0; /* Reset counter. */
|
||||
TIFR = (1 << OCF0); /* Reset pending. */
|
||||
TIMSK = (1 << OCIE0); /* IRQ on compare. */
|
||||
#else
|
||||
#error "Neither TCCR0A nor TCCR0 registers are defined"
|
||||
#endif
|
||||
|
|
|
@ -29,38 +29,33 @@
|
|||
|
||||
#include <avr/io.h>
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Driver constants. */
|
||||
/*===========================================================================*/
|
||||
/*==========================================================================*/
|
||||
/* Driver constants. */
|
||||
/*==========================================================================*/
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Driver pre-compile time settings. */
|
||||
/*===========================================================================*/
|
||||
/*==========================================================================*/
|
||||
/* Driver pre-compile time settings. */
|
||||
/*==========================================================================*/
|
||||
|
||||
/*
|
||||
* TODO: for models that have many timers,
|
||||
* could add AVR_ST_USE_TIMER
|
||||
*/
|
||||
/* TODO: for models that have many timers, could add AVR_ST_USE_TIMER. */
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Derived constants and error checks. */
|
||||
/*===========================================================================*/
|
||||
/*==========================================================================*/
|
||||
/* Derived constants and error checks. */
|
||||
/*==========================================================================*/
|
||||
|
||||
/*
|
||||
* TODO: error checks for valid timer selected
|
||||
*/
|
||||
/* TODO: error checks for valid timer selected. */
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Driver data structures and types. */
|
||||
/*===========================================================================*/
|
||||
/*==========================================================================*/
|
||||
/* Driver data structures and types. */
|
||||
/*==========================================================================*/
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Driver macros. */
|
||||
/*===========================================================================*/
|
||||
/*==========================================================================*/
|
||||
/* Driver macros. */
|
||||
/*==========================================================================*/
|
||||
|
||||
/*===========================================================================*/
|
||||
/* External declarations. */
|
||||
/*===========================================================================*/
|
||||
/*==========================================================================*/
|
||||
/* External declarations. */
|
||||
/*==========================================================================*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
@ -79,9 +74,9 @@ extern "C" {
|
|||
#define TIMSK_REG TIMSK1
|
||||
#endif
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Driver inline functions. */
|
||||
/*===========================================================================*/
|
||||
/*==========================================================================*/
|
||||
/* Driver inline functions. */
|
||||
/*==========================================================================*/
|
||||
|
||||
/**
|
||||
* @brief Returns the time counter value.
|
||||
|
@ -154,7 +149,7 @@ static inline systime_t st_lld_get_alarm(void) {
|
|||
*
|
||||
* @return The alarm status.
|
||||
* @retval false if the alarm is not active.
|
||||
* @retval true is the alarm is active
|
||||
* @retval true is the alarm is active.
|
||||
*
|
||||
* @notapi
|
||||
*/
|
||||
|
|
|
@ -31,13 +31,13 @@
|
|||
/*==========================================================================*/
|
||||
#define UBRR(b) (((F_CPU / b) >> 5) - 1)
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Driver local definitions. */
|
||||
/*===========================================================================*/
|
||||
/*==========================================================================*/
|
||||
/* Driver local definitions. */
|
||||
/*==========================================================================*/
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Driver exported variables. */
|
||||
/*===========================================================================*/
|
||||
/*==========================================================================*/
|
||||
/* Driver exported variables. */
|
||||
/*==========================================================================*/
|
||||
|
||||
/** @brief USART1 UART driver identifier.*/
|
||||
#if AVR_UART_USE_USART1 || defined(__DOXYGEN__)
|
||||
|
@ -49,13 +49,13 @@ UARTDriver UARTD1;
|
|||
UARTDriver UARTD2;
|
||||
#endif
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Driver local variables and types. */
|
||||
/*===========================================================================*/
|
||||
/*==========================================================================*/
|
||||
/* Driver local variables and types. */
|
||||
/*==========================================================================*/
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Driver local functions. */
|
||||
/*===========================================================================*/
|
||||
/*==========================================================================*/
|
||||
/* Driver local functions. */
|
||||
/*==========================================================================*/
|
||||
|
||||
/**
|
||||
* @brief USART de-initialization.
|
||||
|
@ -94,9 +94,9 @@ static void usart_start(UARTDriver *uartp) {
|
|||
#endif
|
||||
}
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Driver interrupt handlers. */
|
||||
/*===========================================================================*/
|
||||
/*==========================================================================*/
|
||||
/* Driver interrupt handlers. */
|
||||
/*==========================================================================*/
|
||||
|
||||
#if AVR_UART_USE_USART1 || defined(__DOXYGEN__)
|
||||
/**
|
||||
|
@ -108,15 +108,15 @@ OSAL_IRQ_HANDLER(LIN_TC_vect) {
|
|||
|
||||
OSAL_IRQ_PROLOGUE();
|
||||
|
||||
// TODO: Manage the UART IRQ.
|
||||
/* TODO: Manage the UART IRQ. */
|
||||
|
||||
OSAL_IRQ_EPILOGUE();
|
||||
}
|
||||
#endif /* AVR_UART_USE_USART1 */
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Driver exported functions. */
|
||||
/*===========================================================================*/
|
||||
/*==========================================================================*/
|
||||
/* Driver exported functions. */
|
||||
/*==========================================================================*/
|
||||
|
||||
/**
|
||||
* @brief Low level UART driver initialization.
|
||||
|
@ -196,7 +196,7 @@ void uart_lld_start_send(UARTDriver *uartp, size_t n, const uint8_t *txbuf) {
|
|||
#if AVR_UART_USE_USART1
|
||||
if (&UARTD1 == uartp) {
|
||||
/* Starting transfer.*/
|
||||
while(n--) {
|
||||
while (n--) {
|
||||
while (LINSIR & (1 << LBUSY));
|
||||
LINDAT = *txbuf;
|
||||
txbuf++;
|
||||
|
@ -219,7 +219,7 @@ void uart_lld_start_send(UARTDriver *uartp, size_t n, const uint8_t *txbuf) {
|
|||
void uart_lld_start_receive(UARTDriver *uartp, size_t n, void *rxbuf) {
|
||||
|
||||
/* Stopping previous activity (idle state).*/
|
||||
// TODO: Implement this function.
|
||||
/* TODO: Implement this function. */
|
||||
}
|
||||
|
||||
#endif /* HAL_USE_UART */
|
||||
|
|
|
@ -25,9 +25,9 @@
|
|||
#ifndef HAL_LLD_H
|
||||
#define HAL_LLD_H
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Driver constants. */
|
||||
/*===========================================================================*/
|
||||
/*==========================================================================*/
|
||||
/* Driver constants. */
|
||||
/*==========================================================================*/
|
||||
|
||||
/**
|
||||
* @brief Defines the support for realtime counters in the HAL.
|
||||
|
@ -39,25 +39,25 @@
|
|||
*/
|
||||
#define PLATFORM_NAME "AVR XMEGA"
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Driver pre-compile time settings. */
|
||||
/*===========================================================================*/
|
||||
/*==========================================================================*/
|
||||
/* Driver pre-compile time settings. */
|
||||
/*==========================================================================*/
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Derived constants and error checks. */
|
||||
/*===========================================================================*/
|
||||
/*==========================================================================*/
|
||||
/* Derived constants and error checks. */
|
||||
/*==========================================================================*/
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Driver data structures and types. */
|
||||
/*===========================================================================*/
|
||||
/*==========================================================================*/
|
||||
/* Driver data structures and types. */
|
||||
/*==========================================================================*/
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Driver macros. */
|
||||
/*===========================================================================*/
|
||||
/*==========================================================================*/
|
||||
/* Driver macros. */
|
||||
/*==========================================================================*/
|
||||
|
||||
/*===========================================================================*/
|
||||
/* External declarations. */
|
||||
/*===========================================================================*/
|
||||
/*==========================================================================*/
|
||||
/* External declarations. */
|
||||
/*==========================================================================*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
|
|
@ -26,25 +26,25 @@
|
|||
|
||||
#if HAL_USE_PAL || defined(__DOXYGEN__)
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Driver exported variables. */
|
||||
/*===========================================================================*/
|
||||
/*==========================================================================*/
|
||||
/* Driver exported variables. */
|
||||
/*==========================================================================*/
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Driver local variables and types. */
|
||||
/*===========================================================================*/
|
||||
/*==========================================================================*/
|
||||
/* Driver local variables and types. */
|
||||
/*==========================================================================*/
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Driver local functions. */
|
||||
/*===========================================================================*/
|
||||
/*==========================================================================*/
|
||||
/* Driver local functions. */
|
||||
/*==========================================================================*/
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Driver interrupt handlers. */
|
||||
/*===========================================================================*/
|
||||
/*==========================================================================*/
|
||||
/* Driver interrupt handlers. */
|
||||
/*==========================================================================*/
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Driver exported functions. */
|
||||
/*===========================================================================*/
|
||||
/*==========================================================================*/
|
||||
/* Driver exported functions. */
|
||||
/*==========================================================================*/
|
||||
|
||||
/**
|
||||
* @brief AVR GPIO ports configuration.
|
||||
|
|
|
@ -27,16 +27,16 @@
|
|||
|
||||
#if HAL_USE_PAL || defined(__DOXYGEN__)
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Unsupported modes and specific modes. */
|
||||
/*===========================================================================*/
|
||||
/*==========================================================================*/
|
||||
/* Unsupported modes and specific modes. */
|
||||
/*==========================================================================*/
|
||||
|
||||
#undef PAL_MODE_INPUT_PULLDOWN
|
||||
#undef PAL_MODE_OUTPUT_OPENDRAIN
|
||||
|
||||
/*===========================================================================*/
|
||||
/* I/O Ports Types and constants. */
|
||||
/*===========================================================================*/
|
||||
/*==========================================================================*/
|
||||
/* I/O Ports Types and constants. */
|
||||
/*==========================================================================*/
|
||||
|
||||
/**
|
||||
* @brief Width, in bits, of an I/O port.
|
||||
|
@ -177,9 +177,9 @@ typedef struct {
|
|||
*/
|
||||
typedef uint8_t ioeventmode_t;
|
||||
|
||||
/*===========================================================================*/
|
||||
/* I/O Ports Identifiers. */
|
||||
/*===========================================================================*/
|
||||
/*==========================================================================*/
|
||||
/* I/O Ports Identifiers. */
|
||||
/*==========================================================================*/
|
||||
|
||||
#if defined(PORTA) || defined(__DOXYGEN__)
|
||||
/**
|
||||
|
@ -258,10 +258,10 @@ typedef uint8_t ioeventmode_t;
|
|||
#define IOPORT11 (&PORTL)
|
||||
#endif
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Implementation, some of the following macros could be implemented as */
|
||||
/* functions, if so please put them in hal_pal_lld.c. */
|
||||
/*===========================================================================*/
|
||||
/*==========================================================================*/
|
||||
/* Implementation, some of the following macros could be implemented as */
|
||||
/* functions, if so please put them in hal_pal_lld.c. */
|
||||
/*==========================================================================*/
|
||||
|
||||
/**
|
||||
* @brief Low level PAL subsystem initialization.
|
||||
|
|
|
@ -26,29 +26,29 @@
|
|||
|
||||
#if (OSAL_ST_MODE != OSAL_ST_MODE_NONE) || defined(__DOXYGEN__)
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Driver local definitions. */
|
||||
/*===========================================================================*/
|
||||
/*==========================================================================*/
|
||||
/* Driver local definitions. */
|
||||
/*==========================================================================*/
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Driver exported variables. */
|
||||
/*===========================================================================*/
|
||||
/*==========================================================================*/
|
||||
/* Driver exported variables. */
|
||||
/*==========================================================================*/
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Driver local types. */
|
||||
/*===========================================================================*/
|
||||
/*==========================================================================*/
|
||||
/* Driver local types. */
|
||||
/*==========================================================================*/
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Driver local variables and types. */
|
||||
/*===========================================================================*/
|
||||
/*==========================================================================*/
|
||||
/* Driver local variables and types. */
|
||||
/*==========================================================================*/
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Driver local functions. */
|
||||
/*===========================================================================*/
|
||||
/*==========================================================================*/
|
||||
/* Driver local functions. */
|
||||
/*==========================================================================*/
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Driver interrupt handlers. */
|
||||
/*===========================================================================*/
|
||||
/*==========================================================================*/
|
||||
/* Driver interrupt handlers. */
|
||||
/*==========================================================================*/
|
||||
|
||||
#if (OSAL_ST_MODE == OSAL_ST_MODE_PERIODIC) || defined(__DOXYGEN__)
|
||||
|
||||
|
|
|
@ -29,38 +29,36 @@
|
|||
|
||||
#include <avr/io.h>
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Driver constants. */
|
||||
/*===========================================================================*/
|
||||
/*==========================================================================*/
|
||||
/* Driver constants. */
|
||||
/*==========================================================================*/
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Driver pre-compile time settings. */
|
||||
/*===========================================================================*/
|
||||
/*==========================================================================*/
|
||||
/* Driver pre-compile time settings. */
|
||||
/*==========================================================================*/
|
||||
|
||||
/*
|
||||
* TODO: for models that have many timers,
|
||||
* could add AVR_XMEGA_ST_USE_TIMER
|
||||
* could add AVR_XMEGA_ST_USE_TIMER.
|
||||
*/
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Derived constants and error checks. */
|
||||
/*===========================================================================*/
|
||||
/*==========================================================================*/
|
||||
/* Derived constants and error checks. */
|
||||
/*==========================================================================*/
|
||||
|
||||
/*
|
||||
* TODO: error checks for valid timer selected
|
||||
*/
|
||||
/* TODO: error checks for valid timer selected. */
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Driver data structures and types. */
|
||||
/*===========================================================================*/
|
||||
/*==========================================================================*/
|
||||
/* Driver data structures and types. */
|
||||
/*==========================================================================*/
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Driver macros. */
|
||||
/*===========================================================================*/
|
||||
/*==========================================================================*/
|
||||
/* Driver macros. */
|
||||
/*==========================================================================*/
|
||||
|
||||
/*===========================================================================*/
|
||||
/* External declarations. */
|
||||
/*===========================================================================*/
|
||||
/*==========================================================================*/
|
||||
/* External declarations. */
|
||||
/*==========================================================================*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
@ -72,9 +70,9 @@ extern "C" {
|
|||
|
||||
#define TIFR_REG TCC0.INTFLAGS
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Driver inline functions. */
|
||||
/*===========================================================================*/
|
||||
/*==========================================================================*/
|
||||
/* Driver inline functions. */
|
||||
/*==========================================================================*/
|
||||
|
||||
/**
|
||||
* @brief Returns the time counter value.
|
||||
|
@ -142,7 +140,7 @@ static inline systime_t st_lld_get_alarm(void) {
|
|||
*
|
||||
* @return The alarm status.
|
||||
* @retval false if the alarm is not active.
|
||||
* @retval true is the alarm is active
|
||||
* @retval true is the alarm is active.
|
||||
*
|
||||
* @notapi
|
||||
*/
|
||||
|
|
Loading…
Reference in New Issue