/** * This file is part of license combination gpl version 3 license and eCos. * The corresponding license terms are below. * * gpl version 3 Licence: * * The file were developed during the student thesis "Datensammlung in Wireless * Sensor Networks fuer Autonomic Home NetworkingÒ of Thomas Kothmayr and is * included in the dissertation "Secure Data Transmission in Wireless * Sensor Networks" by Corinna Schmitt during employment at the Technische * UniversitŠt MŸnchen, Department Computer Science, Chair Network * Architectures and Services (Germany). * Copyright (C) 2013 * Authors: Thomas Kothmayr and Corinna Schmitt (schmitt[at]net.in.tum.de) * * This program 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, version 3 of the License * * This program 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 . * * * eCos Licence: (http://ecos.sourceware.org) * * This file is part of eCos, the Embedded Configurable Operating System. * Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, * 2007, 2008, 2009 Free Software Foundation, Inc. * * eCos 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 any later version. * * eCos 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 eCos; if not, write to the Free Software Foundation, Inc., 51 * Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * * As a special exception, if other files instantiate templates or use * macros or inline functions from this file, or you compile this file and * link it with other works to produce a work based on this file, this file * does not by itself cause the resulting work to be covered by the GNU * General Public License. However the source code for this file must still * be made available in accordance with section (3) of the GNU General * Public License v2. * * This exception does not invalidate any other reasons why a work based on * this file might be covered by the GNU General Public License. * */ Interface: tos.chips.atm128.adc.HplAtm128Adc

Interface: tos.chips.atm128.adc.HplAtm128Adc

interface HplAtm128Adc

HPL interface to the Atmega128 A/D conversion subsystem. Please see the Atmega128 manual for full details on the functioning of this subsystem.

A word of warning: the Atmega128 SLEEP instruction initiates an A/D conversion when the ADC and ADC interrupt are enabled.

Author:
Martin Turon <mturon@xbow.com>
Hu Siquan <husq@xbow.com>
David Gay

Commands
command bool cancel() Cancel A/D conversion and any pending A/D interrupt.
command void disableAdc() Disable ADC sampling
command void disableInterruption() Disable ADC interrupt
command void enableAdc() Enable ADC sampling
command void enableInterruption() Enable ADC interrupt
command Atm128Adcsra_t getAdcsra() Read the ADCSRA (ADC control) register
command Atm128Admux_t getAdmux() Read the ADMUX (ADC selection) register
command uint16_t getValue() Read the latest A/D conversion result
command bool isComplete() Is A/D conversion complete? Note that this flag is automatically cleared when an A/D interrupt occurs.
command bool isEnabled() Is ADC enabled?
command bool isStarted() Is A/D conversion in progress?
command void resetInterrupt() Clear the ADC interrupt flag
command void setAdcsra(Atm128Adcsra_t adcsra) Set the ADCSRA (ADC control) register
command void setAdmux(Atm128Admux_t admux) Set the ADMUX (ADC selection) register
command void setContinuous() Enable continuous sampling
command void setPrescaler(uint8_t scale) Set ADC prescaler selection bits
command void setSingle() Disable continuous sampling
command void startConversion() Start ADC conversion.

Events
event void dataReady(uint16_t data) A/D interrupt occured

Commands - Details

cancel

command bool cancel()

Cancel A/D conversion and any pending A/D interrupt. Also disables the ADC interruption (otherwise a sample might start at the next sleep instruction). This command can assume that the A/D converter is enabled.

Returns:
TRUE if an A/D conversion was in progress or an A/D interrupt was pending, FALSE otherwise. In single conversion mode, a return of TRUE implies that the dataReady event will not be signaled.

disableAdc

command void disableAdc()

Disable ADC sampling

disableInterruption

command void disableInterruption()

Disable ADC interrupt

enableAdc

command void enableAdc()

Enable ADC sampling

enableInterruption

command void enableInterruption()

Enable ADC interrupt

getAdcsra

command Atm128Adcsra_t getAdcsra()

Read the ADCSRA (ADC control) register

Returns:
Current ADCSRA value

getAdmux

command Atm128Admux_t getAdmux()

Read the ADMUX (ADC selection) register

Returns:
Current ADMUX value

getValue

command uint16_t getValue()

Read the latest A/D conversion result

Returns:
A/D value

isComplete

command bool isComplete()

Is A/D conversion complete? Note that this flag is automatically cleared when an A/D interrupt occurs.

Returns:
TRUE if the A/D conversion is complete, FALSE otherwise

isEnabled

command bool isEnabled()

Is ADC enabled?

Returns:
TRUE if the ADC is enabled, FALSE otherwise

isStarted

command bool isStarted()

Is A/D conversion in progress?

Returns:
TRUE if the A/D conversion is in progress, FALSE otherwise

resetInterrupt

command void resetInterrupt()

Clear the ADC interrupt flag

setAdcsra

command void setAdcsra(Atm128Adcsra_t adcsra)

Set the ADCSRA (ADC control) register

Parameters:
adcsra - New ADCSRA value

setAdmux

command void setAdmux(Atm128Admux_t admux)

Set the ADMUX (ADC selection) register

Parameters:
admux - New ADMUX value

setContinuous

command void setContinuous()

Enable continuous sampling

setPrescaler

command void setPrescaler(uint8_t scale)

Set ADC prescaler selection bits

Parameters:
scale - New ADC prescaler. Must be one of the ATM128_ADC_PRESCALE_xxx values from Atm128Adc.h

setSingle

command void setSingle()

Disable continuous sampling

startConversion

command void startConversion()

Start ADC conversion. If ADC interrupts are enabled, the dataReady event will be signaled once (in non-continuous mode) or repeatedly (in continuous mode).

Events - Details

dataReady

event void dataReady(uint16_t data)

A/D interrupt occured

Parameters:
data - Latest A/D conversion result