Fix style and license for AVR ADC driver

git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@5897 35acf78f-673a-0410-8e92-d51de3d6d3f4
This commit is contained in:
utzig 2013-06-27 12:44:01 +00:00
parent 48dfd4e898
commit cf4c8b5281
2 changed files with 97 additions and 105 deletions

View File

@ -1,26 +1,22 @@
/*
ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010,
2011,2012 Giovanni Di Sirio.
ChibiOS/RT - Copyright (C) 2006-2013 Giovanni Di Sirio
This file is part of ChibiOS/RT.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
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.
http://www.apache.org/licenses/LICENSE-2.0
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/>.
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/**
* @file templates/adc_lld.c
* @brief ADC Driver subsystem low level driver source template.
* @file AVR/adc_lld.c
* @brief ADC Driver subsystem low level driver source.
*
* @addtogroup ADC
* @{
@ -50,26 +46,26 @@ ADCDriver ADCD1;
/* Driver local functions. */
/*===========================================================================*/
static size_t getAdcChannelNumberFromMask(uint8_t mask, uint8_t currentChannel)
{
for(uint8_t i = 0; mask>0; i++)
{
if(mask & 0x01)
{
if(!currentChannel)
return i;
currentChannel--;
}
mask >>= 1;
static size_t getAdcChannelNumberFromMask(uint8_t mask, uint8_t currentChannel) {
for (uint8_t i = 0; mask > 0; i++) {
if (mask & 0x01) {
if (!currentChannel)
return i;
currentChannel--;
}
/* error, should never reach this line */
mask >>= 1;
}
/* error, should never reach this line */
}
static void setAdcChannel(uint8_t channelNum)
{
ADMUX = (ADMUX & 0xf8) | (channelNum & 0x07);
static void setAdcChannel(uint8_t channelNum) {
ADMUX = (ADMUX & 0xf8) | (channelNum & 0x07);
}
/*===========================================================================*/
/* Driver interrupt handlers. */
/*===========================================================================*/
@ -77,35 +73,29 @@ static void setAdcChannel(uint8_t channelNum)
#include <util/delay.h>
CH_IRQ_HANDLER(ADC_vect) {
CH_IRQ_PROLOGUE();
uint8_t low = ADCL;
uint8_t high = ADCH;
uint16_t result = (high << 8) | low;
ADCD1.samples[ADCD1.currentBufferPosition] = result;
ADCD1.currentBufferPosition++;
size_t bufferSize = ADCD1.depth * ADCD1.grpp->num_channels;
size_t currentChannel = ADCD1.currentBufferPosition % ADCD1.grpp->num_channels;
size_t currentIteration = ADCD1.currentBufferPosition / ADCD1.grpp->num_channels;
if(ADCD1.grpp-> circular && currentChannel == 0 && currentIteration == ADCD1.depth/2)
{
_adc_isr_half_code(&ADCD1);
}
if(ADCD1.currentBufferPosition == bufferSize)
{
_adc_isr_full_code(&ADCD1);
}
else
{
setAdcChannel(getAdcChannelNumberFromMask(ADCD1.grpp->channelsMask,currentChannel));
ADCSRA |= 1<<ADSC;
}
uint8_t low = ADCL;
uint8_t high = ADCH;
uint16_t result = (high << 8) | low;
ADCD1.samples[ADCD1.currentBufferPosition] = result;
ADCD1.currentBufferPosition++;
size_t bufferSize = ADCD1.depth * ADCD1.grpp->num_channels;
size_t currentChannel = ADCD1.currentBufferPosition % ADCD1.grpp->num_channels;
size_t currentIteration = ADCD1.currentBufferPosition / ADCD1.grpp->num_channels;
if (ADCD1.grpp->circular && currentChannel == 0 && currentIteration == ADCD1.depth/2) {
_adc_isr_half_code(&ADCD1);
}
if (ADCD1.currentBufferPosition == bufferSize) {
_adc_isr_full_code(&ADCD1);
} else {
setAdcChannel(getAdcChannelNumberFromMask(ADCD1.grpp->channelsMask,currentChannel));
ADCSRA |= 1 << ADSC;
}
CH_IRQ_EPILOGUE();
}
@ -119,12 +109,17 @@ CH_IRQ_HANDLER(ADC_vect) {
* @notapi
*/
void adc_lld_init(void) {
adcObjectInit(&ADCD1);
ADCSRA =(1<<ADPS2)|(1<<ADPS1)|(1<<ADPS0) | //prescaler 128, unico valore possibile a 20Mhz
(1<<ADIE) ; //interrupt
ADCSRB=0; //single shot
ADMUX=(0<<REFS1)| (0<<REFS0); //uso aref, vale solo per arduino. arduino ha aref collegato
adcObjectInit(&ADCD1);
//prescaler 128, only value possible at 20Mhz, interrupt
ADCSRA = (1 << ADPS2) | (1 << ADPS1) | (1 << ADPS0) | (1 << ADIE);
ADCSRB = 0; //single shot
//uso aref, only valid for arduino. arduino ha aref collegato
ADMUX = (0 << REFS1) | (0 << REFS0);
}
/**
@ -138,12 +133,11 @@ void adc_lld_start(ADCDriver *adcp) {
if (adcp->state == ADC_STOP) {
/* Clock activation.*/
ADCSRA |= (1<<ADEN);
ADCSRA |= (1 << ADEN);
}
if (adcp->config != NULL)
{
ADMUX = (adcp->config->analog_reference << REFS0);
if (adcp->config != NULL) {
ADMUX = (adcp->config->analog_reference << REFS0);
}
}
@ -158,8 +152,9 @@ void adc_lld_stop(ADCDriver *adcp) {
if (adcp->state == ADC_READY) {
/* Clock de-activation.*/
ADCSRA &= ~(1<<ADEN);
ADCSRA &= ~(1 << ADEN);
}
}
/**
@ -170,10 +165,12 @@ void adc_lld_stop(ADCDriver *adcp) {
* @notapi
*/
void adc_lld_start_conversion(ADCDriver *adcp) {
adcp->currentBufferPosition=0;
setAdcChannel(getAdcChannelNumberFromMask(adcp->grpp->channelsMask,0));
ADCSRA |= 1<<ADSC;
adcp->currentBufferPosition=0;
setAdcChannel(getAdcChannelNumberFromMask(adcp->grpp->channelsMask,0));
ADCSRA |= 1 << ADSC;
}
/**
@ -184,7 +181,9 @@ void adc_lld_start_conversion(ADCDriver *adcp) {
* @notapi
*/
void adc_lld_stop_conversion(ADCDriver *adcp) {
ADCSRA &= ~(1<<ADSC);
ADCSRA &= ~(1 << ADSC);
}
#endif /* HAL_USE_ADC */

View File

@ -1,26 +1,22 @@
/*
ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010,
2011,2012 Giovanni Di Sirio.
ChibiOS/RT - Copyright (C) 2006-2013 Giovanni Di Sirio
This file is part of ChibiOS/RT.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
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.
http://www.apache.org/licenses/LICENSE-2.0
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/>.
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/**
* @file templates/adc_lld.h
* @brief ADC Driver subsystem low level driver header template.
* @file AVR/adc_lld.h
* @brief ADC Driver subsystem low level driver source.
*
* @addtogroup ADC
* @{
@ -35,12 +31,10 @@
/* Driver constants. */
/*===========================================================================*/
#define ANALOG_REFERENCE_AREF 0
#define ANALOG_REFERENCE_AVCC 1
#define ANALOG_REFERENCE_1V1 2
#define ANALOG_REFERENCE_2V56 3
#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. */
@ -104,9 +98,9 @@ typedef struct {
*/
adccallback_t end_cb;
/* End of the mandatory fields.*/
uint8_t channelsMask;
uint8_t channelsMask;
} ADCConversionGroup;
/**
@ -116,7 +110,9 @@ typedef struct {
* @note It could be empty on some architectures.
*/
typedef struct {
uint8_t analog_reference;
uint8_t analog_reference;
} ADCConfig;
/**
@ -183,7 +179,6 @@ struct ADCDriver {
extern ADCDriver ADCD1;
#endif
#ifdef __cplusplus
extern "C" {
#endif
@ -196,8 +191,6 @@ extern "C" {
}
#endif
#endif /* HAL_USE_ADC */
#endif /* _ADC_LLD_H_ */