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, ChibiOS/RT - Copyright (C) 2006-2013 Giovanni Di Sirio
2011,2012 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 http://www.apache.org/licenses/LICENSE-2.0
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, Unless required by applicable law or agreed to in writing, software
but WITHOUT ANY WARRANTY; without even the implied warranty of distributed under the License is distributed on an "AS IS" BASIS,
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
GNU General Public License for more details. See the License for the specific language governing permissions and
limitations under the License.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
/** /**
* @file templates/adc_lld.c * @file AVR/adc_lld.c
* @brief ADC Driver subsystem low level driver source template. * @brief ADC Driver subsystem low level driver source.
* *
* @addtogroup ADC * @addtogroup ADC
* @{ * @{
@ -50,12 +46,10 @@ ADCDriver ADCD1;
/* Driver local functions. */ /* Driver local functions. */
/*===========================================================================*/ /*===========================================================================*/
static size_t getAdcChannelNumberFromMask(uint8_t mask, uint8_t currentChannel) static size_t getAdcChannelNumberFromMask(uint8_t mask, uint8_t currentChannel) {
{
for(uint8_t i = 0; mask>0; i++) for (uint8_t i = 0; mask > 0; i++) {
{ if (mask & 0x01) {
if(mask & 0x01)
{
if (!currentChannel) if (!currentChannel)
return i; return i;
currentChannel--; currentChannel--;
@ -66,10 +60,12 @@ static size_t getAdcChannelNumberFromMask(uint8_t mask, uint8_t currentChannel)
/* error, should never reach this line */ /* error, should never reach this line */
} }
static void setAdcChannel(uint8_t channelNum) static void setAdcChannel(uint8_t channelNum) {
{
ADMUX = (ADMUX & 0xf8) | (channelNum & 0x07); ADMUX = (ADMUX & 0xf8) | (channelNum & 0x07);
} }
/*===========================================================================*/ /*===========================================================================*/
/* Driver interrupt handlers. */ /* Driver interrupt handlers. */
/*===========================================================================*/ /*===========================================================================*/
@ -89,19 +85,13 @@ CH_IRQ_HANDLER(ADC_vect) {
size_t bufferSize = ADCD1.depth * ADCD1.grpp->num_channels; size_t bufferSize = ADCD1.depth * ADCD1.grpp->num_channels;
size_t currentChannel = ADCD1.currentBufferPosition % ADCD1.grpp->num_channels; size_t currentChannel = ADCD1.currentBufferPosition % ADCD1.grpp->num_channels;
size_t currentIteration = 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) if (ADCD1.grpp->circular && currentChannel == 0 && currentIteration == ADCD1.depth/2) {
{
_adc_isr_half_code(&ADCD1); _adc_isr_half_code(&ADCD1);
} }
if(ADCD1.currentBufferPosition == bufferSize) if (ADCD1.currentBufferPosition == bufferSize) {
{
_adc_isr_full_code(&ADCD1); _adc_isr_full_code(&ADCD1);
} } else {
else
{
setAdcChannel(getAdcChannelNumberFromMask(ADCD1.grpp->channelsMask,currentChannel)); setAdcChannel(getAdcChannelNumberFromMask(ADCD1.grpp->channelsMask,currentChannel));
ADCSRA |= 1 << ADSC; ADCSRA |= 1 << ADSC;
} }
@ -119,12 +109,17 @@ CH_IRQ_HANDLER(ADC_vect) {
* @notapi * @notapi
*/ */
void adc_lld_init(void) { void adc_lld_init(void) {
adcObjectInit(&ADCD1); adcObjectInit(&ADCD1);
ADCSRA =(1<<ADPS2)|(1<<ADPS1)|(1<<ADPS0) | //prescaler 128, unico valore possibile a 20Mhz
(1<<ADIE) ; //interrupt //prescaler 128, only value possible at 20Mhz, interrupt
ADCSRA = (1 << ADPS2) | (1 << ADPS1) | (1 << ADPS0) | (1 << ADIE);
ADCSRB = 0; //single shot ADCSRB = 0; //single shot
ADMUX=(0<<REFS1)| (0<<REFS0); //uso aref, vale solo per arduino. arduino ha aref collegato
//uso aref, only valid for arduino. arduino ha aref collegato
ADMUX = (0 << REFS1) | (0 << REFS0);
} }
/** /**
@ -141,8 +136,7 @@ void adc_lld_start(ADCDriver *adcp) {
ADCSRA |= (1 << ADEN); ADCSRA |= (1 << ADEN);
} }
if (adcp->config != NULL) if (adcp->config != NULL) {
{
ADMUX = (adcp->config->analog_reference << REFS0); ADMUX = (adcp->config->analog_reference << REFS0);
} }
} }
@ -160,6 +154,7 @@ void adc_lld_stop(ADCDriver *adcp) {
/* Clock de-activation.*/ /* Clock de-activation.*/
ADCSRA &= ~(1 << ADEN); ADCSRA &= ~(1 << ADEN);
} }
} }
/** /**
@ -170,10 +165,12 @@ void adc_lld_stop(ADCDriver *adcp) {
* @notapi * @notapi
*/ */
void adc_lld_start_conversion(ADCDriver *adcp) { void adc_lld_start_conversion(ADCDriver *adcp) {
adcp->currentBufferPosition=0; adcp->currentBufferPosition=0;
setAdcChannel(getAdcChannelNumberFromMask(adcp->grpp->channelsMask,0)); setAdcChannel(getAdcChannelNumberFromMask(adcp->grpp->channelsMask,0));
ADCSRA |= 1 << ADSC; ADCSRA |= 1 << ADSC;
} }
/** /**
@ -184,7 +181,9 @@ void adc_lld_start_conversion(ADCDriver *adcp) {
* @notapi * @notapi
*/ */
void adc_lld_stop_conversion(ADCDriver *adcp) { void adc_lld_stop_conversion(ADCDriver *adcp) {
ADCSRA &= ~(1 << ADSC); ADCSRA &= ~(1 << ADSC);
} }
#endif /* HAL_USE_ADC */ #endif /* HAL_USE_ADC */

View File

@ -1,26 +1,22 @@
/* /*
ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010, ChibiOS/RT - Copyright (C) 2006-2013 Giovanni Di Sirio
2011,2012 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 http://www.apache.org/licenses/LICENSE-2.0
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, Unless required by applicable law or agreed to in writing, software
but WITHOUT ANY WARRANTY; without even the implied warranty of distributed under the License is distributed on an "AS IS" BASIS,
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
GNU General Public License for more details. See the License for the specific language governing permissions and
limitations under the License.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
/** /**
* @file templates/adc_lld.h * @file AVR/adc_lld.h
* @brief ADC Driver subsystem low level driver header template. * @brief ADC Driver subsystem low level driver source.
* *
* @addtogroup ADC * @addtogroup ADC
* @{ * @{
@ -40,8 +36,6 @@
#define ANALOG_REFERENCE_1V1 2 #define ANALOG_REFERENCE_1V1 2
#define ANALOG_REFERENCE_2V56 3 #define ANALOG_REFERENCE_2V56 3
/*===========================================================================*/ /*===========================================================================*/
/* Driver pre-compile time settings. */ /* Driver pre-compile time settings. */
/*===========================================================================*/ /*===========================================================================*/
@ -116,7 +110,9 @@ typedef struct {
* @note It could be empty on some architectures. * @note It could be empty on some architectures.
*/ */
typedef struct { typedef struct {
uint8_t analog_reference; uint8_t analog_reference;
} ADCConfig; } ADCConfig;
/** /**
@ -183,7 +179,6 @@ struct ADCDriver {
extern ADCDriver ADCD1; extern ADCDriver ADCD1;
#endif #endif
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
@ -196,8 +191,6 @@ extern "C" {
} }
#endif #endif
#endif /* HAL_USE_ADC */ #endif /* HAL_USE_ADC */
#endif /* _ADC_LLD_H_ */ #endif /* _ADC_LLD_H_ */