MHVLib  20111011
An efficiency oriented runtime library for AVR microcontrollers
A:/eclipse/mhvlib/MHV_io.h File Reference
#include <avr/io.h>
#include <inttypes.h>
#include <stddef.h>
#include <util/atomic.h>

Go to the source code of this file.

Classes

struct  mhv_pin

Defines

#define MHV_IO_H_
#define NORETURN   __attribute__ ((noreturn))
#define PURE   __attribute__ ((pure))
#define GCC_VERSION   (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__)
#define mhv_make_pin(_mhv_port, _mhv_bit)   _mhv_make_pin(_mhv_port, _mhv_bit)
#define _mhv_make_pin(_mhv_port, _mhv_bit)   MHV_PIN_ ## _mhv_port ## _mhv_bit
#define mhv_pin(mhvParms)   _mhv_pin(mhvParms)
#define _mhv_pin(mhvDir, mhvOutput, mhvInput, mhvBit, mhvPCInt)   {mhvDir, mhvOutput, mhvInput, _BV(mhvBit), mhvPCInt}
#define mhv_out(mhvParms)   _mhv_out(mhvParms)
#define _mhv_out(mhvDir, mhvOutput, mhvInput, mhvBit, mhvPCInt)   mhvOutput
#define mhv_in(mhvParms)   _mhv_in(mhvParms)
#define _mhv_in(mhvDir, mhvOutput, mhvInput, mhvBit, mhvPCInt)   mhvInput
#define mhv_bit(mhvParms)   _mhv_bit(mhvParms)
#define _mhv_bit(mhvDir, mhvOutput, mhvInput, mhvBit, mhvPCInt)   mhvBit
#define mhv_dir(mhvParms)   _mhv_dir(mhvParms)
#define _mhv_dir(mhvDir, mhvOutput, mhvInput, mhvBit, mhvPCInt)   mhvDir
#define mhv_pcint(mhvParms)   _mhv_pcint(mhvParms)
#define _mhv_PCInt(mhvDir, mhvOutput, mhvInput, mhvBit, mhvPCInt)   mhvPCInt
#define mhv_declareExternalInterrupt(mhvInterruptParms, mhvFunction)   _mhv_declareExternalInterrupt(mhvInterruptParms, mhvFunction)
#define _mhv_declareExternalInterrupt(mhvInterruptHandler, mhvModeRegister, mhvModeBitshift, mhvFunction)   ISR(mhvInterruptHandler) mhvFunction
#define mhv_enableExternalInterrupt(mhvInterruptParms, mhvInterruptMode)
#define _mhv_enableExternalInterrupt(mhvInterruptHandler, mhvModeRegister, mhvModeBitshift, mhvInterruptMode)   *mhvModeRegister = (*mhvModeRegister & ~(0x03 << mhvModeBitshift)) | (mhvInterruptMode << mhvModeBitshift)

Typedefs

typedef struct mhv_pin MHV_PIN
typedef enum mhv_interruptMode MHV_INTERRUPTMODE

Enumerations

enum  mhv_interruptMode { MHV_INTERRUPT_LOW, MHV_INTERRUPT_CHANGE, MHV_INTERRUPT_FALLING, MHV_INTERRUPT_RISING }

Functions

void mhv_pinOn (MHV_PIN *pin)
void mhv_pinOnAtomic (MHV_PIN *pin)
void mhv_pinOn (volatile uint8_t *dir, volatile uint8_t *out, volatile uint8_t *in, uint8_t bit, int8_t pcInt)
void mhv_pinOnAtomic (volatile uint8_t *dir, volatile uint8_t *out, volatile uint8_t *in, uint8_t bit, int8_t pcInt)
void mhv_pinOff (MHV_PIN *pin)
void mhv_pinOffAtomic (MHV_PIN *pin)
void mhv_pinOff (volatile uint8_t *dir, volatile uint8_t *out, volatile uint8_t *in, uint8_t bit, int8_t pcInt)
void mhv_pinOffAtomic (volatile uint8_t *dir, volatile uint8_t *out, volatile uint8_t *in, uint8_t bit, int8_t pcInt)
void mhv_pinSet (volatile uint8_t *dir, volatile uint8_t *out, volatile uint8_t *in, uint8_t bit, int8_t pcInt, bool state)
void mhv_pinSetAtomic (volatile uint8_t *dir, volatile uint8_t *out, volatile uint8_t *in, uint8_t bit, int8_t pcInt, bool state)
void mhv_setOutput (MHV_PIN *pin)
void mhv_setOutputAtomic (MHV_PIN *pin)
void mhv_setOutput (volatile uint8_t *dir, volatile uint8_t *out, volatile uint8_t *in, uint8_t bit, int8_t pcInt)
void mhv_setOutputAtomic (volatile uint8_t *dir, volatile uint8_t *out, volatile uint8_t *in, uint8_t bit, int8_t pcInt)
void mhv_setInput (MHV_PIN *pin)
void mhv_setInputAtomic (MHV_PIN *pin)
void mhv_setInput (volatile uint8_t *dir, volatile uint8_t *out, volatile uint8_t *in, uint8_t bit, int8_t pcInt)
void mhv_setInputAtomic (volatile uint8_t *dir, volatile uint8_t *out, volatile uint8_t *in, uint8_t bit, int8_t pcInt)
void mhv_setInputPullup (MHV_PIN *pin)
void mhv_setInputPullupAtomic (MHV_PIN *pin)
void mhv_setInputPullup (volatile uint8_t *dir, volatile uint8_t *out, volatile uint8_t *in, uint8_t bit, int8_t pcInt)
void mhv_setInputPullupAtomic (volatile uint8_t *dir, volatile uint8_t *out, volatile uint8_t *in, uint8_t bit, int8_t pcInt)
void mhv_pinToggle (MHV_PIN *pin)
void mhv_pinToggleAtomic (MHV_PIN *pin)
void mhv_pinToggle (volatile uint8_t *dir, volatile uint8_t *out, volatile uint8_t *in, uint8_t bit, int8_t pcInt)
void mhv_pinToggleAtomic (volatile uint8_t *dir, volatile uint8_t *out, volatile uint8_t *in, uint8_t bit, int8_t pcInt)
bool mhv_pinRead (MHV_PIN *pin)
bool mhv_pinRead (volatile uint8_t *dir, volatile uint8_t *out, volatile uint8_t *in, uint8_t bit, int8_t pcInt)
void mhv_memClear (void *bufIn, uint8_t len, uint8_t count)
void mhv_memClear (void *bufIn, uint8_t len)

Define Documentation

#define _mhv_bit (   mhvDir,
  mhvOutput,
  mhvInput,
  mhvBit,
  mhvPCInt 
)    mhvBit

Definition at line 527 of file MHV_io.h.

#define _mhv_declareExternalInterrupt (   mhvInterruptHandler,
  mhvModeRegister,
  mhvModeBitshift,
  mhvFunction 
)    ISR(mhvInterruptHandler) mhvFunction

Definition at line 559 of file MHV_io.h.

#define _mhv_dir (   mhvDir,
  mhvOutput,
  mhvInput,
  mhvBit,
  mhvPCInt 
)    mhvDir

Definition at line 537 of file MHV_io.h.

#define _mhv_enableExternalInterrupt (   mhvInterruptHandler,
  mhvModeRegister,
  mhvModeBitshift,
  mhvInterruptMode 
)    *mhvModeRegister = (*mhvModeRegister & ~(0x03 << mhvModeBitshift)) | (mhvInterruptMode << mhvModeBitshift)

Definition at line 584 of file MHV_io.h.

#define _mhv_in (   mhvDir,
  mhvOutput,
  mhvInput,
  mhvBit,
  mhvPCInt 
)    mhvInput

Definition at line 517 of file MHV_io.h.

#define _mhv_make_pin (   _mhv_port,
  _mhv_bit 
)    MHV_PIN_ ## _mhv_port ## _mhv_bit

Definition at line 94 of file MHV_io.h.

#define _mhv_out (   mhvDir,
  mhvOutput,
  mhvInput,
  mhvBit,
  mhvPCInt 
)    mhvOutput

Definition at line 507 of file MHV_io.h.

#define _mhv_PCInt (   mhvDir,
  mhvOutput,
  mhvInput,
  mhvBit,
  mhvPCInt 
)    mhvPCInt

Definition at line 547 of file MHV_io.h.

#define _mhv_pin (   mhvDir,
  mhvOutput,
  mhvInput,
  mhvBit,
  mhvPCInt 
)    {mhvDir, mhvOutput, mhvInput, _BV(mhvBit), mhvPCInt}

Definition at line 104 of file MHV_io.h.

#define GCC_VERSION   (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__)

Definition at line 74 of file MHV_io.h.

#define mhv_bit (   mhvParms)    _mhv_bit(mhvParms)

Grab the bit offset of a pin declaration

Parameters:
mhvParmsA MHV_PIN_* Macro

Definition at line 524 of file MHV_io.h.

#define mhv_declareExternalInterrupt (   mhvInterruptParms,
  mhvFunction 
)    _mhv_declareExternalInterrupt(mhvInterruptParms, mhvFunction)

Assign a function to be triggered by an external interrupt

Parameters:
mhvInterruptParmsA MHV_INTERRUPT_* Macro
mhvFunctiona block to execute when the interrupt occurs

Definition at line 556 of file MHV_io.h.

#define mhv_dir (   mhvParms)    _mhv_dir(mhvParms)

Grab the direction register of a pin declaration

Parameters:
mhvParmsA MHV_PIN_* Macro

Definition at line 534 of file MHV_io.h.

#define mhv_enableExternalInterrupt (   mhvInterruptParms,
  mhvInterruptMode 
)
Value:
do { \
                _mhv_enableExternalInterrupt(mhvInterruptParms,mhvInterruptMode); \
        } while (0)

Enable an external interrupt

Parameters:
mhvInterruptParmsA MHV_INTERRUPT_* Macro
mhvInterruptModeWhen to raise the interrupt (see MHV_INTERRUPTMODE)

Definition at line 579 of file MHV_io.h.

#define mhv_in (   mhvParms)    _mhv_in(mhvParms)

Grab the input register of a pin declaration

Parameters:
mhvParmsa MHV_PIN_* macro

Definition at line 514 of file MHV_io.h.

#define MHV_IO_H_

Definition at line 44 of file MHV_io.h.

#define mhv_make_pin (   _mhv_port,
  _mhv_bit 
)    _mhv_make_pin(_mhv_port, _mhv_bit)

Convert a literal port and pin into a pin macro

Parameters:
_mhv_portthe port (eg, B)
_mhv_bitthe bit (eg, 3)

Definition at line 91 of file MHV_io.h.

#define mhv_out (   mhvParms)    _mhv_out(mhvParms)

Grab the output register of a pin declaration

Parameters:
mhvParmsa MHV_PIN_* macro

Definition at line 504 of file MHV_io.h.

#define mhv_pcint (   mhvParms)    _mhv_pcint(mhvParms)

Grab the pin change interrupt of a pin

Parameters:
mhvParmsA MHV_PIN_* Macro

Definition at line 544 of file MHV_io.h.

#define mhv_pin (   mhvParms)    _mhv_pin(mhvParms)

Convert a pin declaration to a pin struct

Parameters:
mhvParmsa MHV_PIN_* macro

Definition at line 101 of file MHV_io.h.

#define NORETURN   __attribute__ ((noreturn))

Definition at line 54 of file MHV_io.h.

#define PURE   __attribute__ ((pure))

Definition at line 57 of file MHV_io.h.


Typedef Documentation

Definition at line 571 of file MHV_io.h.

typedef struct mhv_pin MHV_PIN

Definition at line 84 of file MHV_io.h.


Enumeration Type Documentation

Situations that interrupts can be triggered on

Enumerator:
MHV_INTERRUPT_LOW 

MHV_INTERRUPT_LOW to level trigger when low.

MHV_INTERRUPT_CHANGE 

MHV_INTERRUPT_CHANGE to edge trigger on change.

MHV_INTERRUPT_FALLING 

MHV_INTERRUPT_FALLING to edge trigger when falling.

MHV_INTERRUPT_RISING 

MHV_INTERRUPT_RISING to edge trigger when rising.

Definition at line 565 of file MHV_io.h.


Function Documentation

void mhv_memClear ( void *  bufIn,
uint8_t  len,
uint8_t  count 
) [inline]

Cheap memset to 0

Parameters:
bufIna pointer to the buffer
lenthe length of an element in the buffer
countthe number of elements in the buffer

Definition at line 466 of file MHV_io.h.

void mhv_memClear ( void *  bufIn,
uint8_t  len 
) [inline]

Cheap memset to 0

Parameters:
bufIna pointer to the buffer
lenthe length of an element in the buffer

Definition at line 481 of file MHV_io.h.

void mhv_pinOff ( MHV_PIN pin) [inline]

Set an output pin off

Parameters:
pinthe pin to turn off

Definition at line 159 of file MHV_io.h.

void mhv_pinOff ( volatile uint8_t *  dir,
volatile uint8_t *  out,
volatile uint8_t *  in,
uint8_t  bit,
int8_t  pcInt 
) [inline]

Set an output pin off

Parameters:
dirA member of the MHV_PIN_* macro
outA member of the MHV_PIN_* macro
inA member of the MHV_PIN_* macro
bitA member of the MHV_PIN_* macro
pcIntA member of the MHV_PIN_* macro

Definition at line 182 of file MHV_io.h.

void mhv_pinOffAtomic ( MHV_PIN pin) [inline]

Set an output pin off (used if the state of a pin on the same port is altered in an interrupt handler)

Parameters:
pinthe pin to turn off

Definition at line 167 of file MHV_io.h.

void mhv_pinOffAtomic ( volatile uint8_t *  dir,
volatile uint8_t *  out,
volatile uint8_t *  in,
uint8_t  bit,
int8_t  pcInt 
) [inline]

Set an output pin off (used if the state of a pin on the same port is altered in an interrupt handler)

Parameters:
dirA member of the MHV_PIN_* macro
outA member of the MHV_PIN_* macro
inA member of the MHV_PIN_* macro
bitA member of the MHV_PIN_* macro
pcIntA member of the MHV_PIN_* macro

Definition at line 195 of file MHV_io.h.

void mhv_pinOn ( MHV_PIN pin) [inline]

Set an output pin on

Parameters:
pinthe pin to turn on

Definition at line 111 of file MHV_io.h.

void mhv_pinOn ( volatile uint8_t *  dir,
volatile uint8_t *  out,
volatile uint8_t *  in,
uint8_t  bit,
int8_t  pcInt 
) [inline]

Set an output pin on

Parameters:
dirA member of the MHV_PIN_* macro
outA member of the MHV_PIN_* macro
inA member of the MHV_PIN_* macro
bitA member of the MHV_PIN_* macro
pcIntA member of the MHV_PIN_* macro

Definition at line 134 of file MHV_io.h.

void mhv_pinOnAtomic ( MHV_PIN pin) [inline]

Set an output pin on atomically (used if the state of a pin on the same port is altered in an interrupt handler)

Parameters:
pinthe pin to turn on

Definition at line 119 of file MHV_io.h.

void mhv_pinOnAtomic ( volatile uint8_t *  dir,
volatile uint8_t *  out,
volatile uint8_t *  in,
uint8_t  bit,
int8_t  pcInt 
) [inline]

Set an output pin on (used if the state of a pin on the same port is altered in an interrupt handler)

Parameters:
dirA member of the MHV_PIN_* macro
outA member of the MHV_PIN_* macro
inA member of the MHV_PIN_* macro
bitA member of the MHV_PIN_* macro
pcIntA member of the MHV_PIN_* macro

Definition at line 147 of file MHV_io.h.

bool mhv_pinRead ( MHV_PIN pin) [inline]

Read a pin

Parameters:
pinthe pin to read

Definition at line 441 of file MHV_io.h.

bool mhv_pinRead ( volatile uint8_t *  dir,
volatile uint8_t *  out,
volatile uint8_t *  in,
uint8_t  bit,
int8_t  pcInt 
) [inline]

Read a pin

Parameters:
dirA member of the MHV_PIN_* macro
outA member of the MHV_PIN_* macro
inA member of the MHV_PIN_* macro
bitA member of the MHV_PIN_* macro
pcIntA member of the MHV_PIN_* macro

Definition at line 454 of file MHV_io.h.

void mhv_pinSet ( volatile uint8_t *  dir,
volatile uint8_t *  out,
volatile uint8_t *  in,
uint8_t  bit,
int8_t  pcInt,
bool  state 
) [inline]

Set an output pin on or off (state should really be constant for optimal performance)

Parameters:
dirA member of the MHV_PIN_* macro
outA member of the MHV_PIN_* macro
inA member of the MHV_PIN_* macro
bitA member of the MHV_PIN_* macro
pcIntA member of the MHV_PIN_* macro
statetrue to turn the pin on

Definition at line 212 of file MHV_io.h.

void mhv_pinSetAtomic ( volatile uint8_t *  dir,
volatile uint8_t *  out,
volatile uint8_t *  in,
uint8_t  bit,
int8_t  pcInt,
bool  state 
) [inline]

Set an output pin on or off (state should really be constant for optimal performance) (used if the state of a pin on the same port is altered in an interrupt handler)

Parameters:
dirA member of the MHV_PIN_* macro
outA member of the MHV_PIN_* macro
inA member of the MHV_PIN_* macro
bitA member of the MHV_PIN_* macro
pcIntA member of the MHV_PIN_* macro
statetrue to turn the pin on

Definition at line 231 of file MHV_io.h.

void mhv_pinToggle ( MHV_PIN pin) [inline]

Toggle a pin

Parameters:
pinthe pin to toggle

Definition at line 393 of file MHV_io.h.

void mhv_pinToggle ( volatile uint8_t *  dir,
volatile uint8_t *  out,
volatile uint8_t *  in,
uint8_t  bit,
int8_t  pcInt 
) [inline]

Toggle a pin

Parameters:
dirA member of the MHV_PIN_* macro
outA member of the MHV_PIN_* macro
inA member of the MHV_PIN_* macro
bitA member of the MHV_PIN_* macro
pcIntA member of the MHV_PIN_* macro

Definition at line 416 of file MHV_io.h.

void mhv_pinToggleAtomic ( MHV_PIN pin) [inline]

Toggle a pin (used if the state of a pin on the same port is altered in an interrupt handler)

Parameters:
pinthe pin to toggle

Definition at line 401 of file MHV_io.h.

void mhv_pinToggleAtomic ( volatile uint8_t *  dir,
volatile uint8_t *  out,
volatile uint8_t *  in,
uint8_t  bit,
int8_t  pcInt 
) [inline]

Toggle a pin (used if the direction of a pin on the same port is altered in an interrupt handler)

Parameters:
dirA member of the MHV_PIN_* macro
outA member of the MHV_PIN_* macro
inA member of the MHV_PIN_* macro
bitA member of the MHV_PIN_* macro
pcIntA member of the MHV_PIN_* macro

Definition at line 429 of file MHV_io.h.

void mhv_setInput ( MHV_PIN pin) [inline]

Set a pin to be an input

Parameters:
pinthe pin to become an output

Definition at line 292 of file MHV_io.h.

void mhv_setInput ( volatile uint8_t *  dir,
volatile uint8_t *  out,
volatile uint8_t *  in,
uint8_t  bit,
int8_t  pcInt 
) [inline]

Set a pin to be an input

Parameters:
dirA member of the MHV_PIN_* macro
outA member of the MHV_PIN_* macro
inA member of the MHV_PIN_* macro
bitA member of the MHV_PIN_* macro
pcIntA member of the MHV_PIN_* macro

Definition at line 316 of file MHV_io.h.

void mhv_setInputAtomic ( MHV_PIN pin) [inline]

Set a pin to be an input (used if the direction of a pin on the same port is altered in an interrupt handler)

Parameters:
pinthe pin to become an output

Definition at line 301 of file MHV_io.h.

void mhv_setInputAtomic ( volatile uint8_t *  dir,
volatile uint8_t *  out,
volatile uint8_t *  in,
uint8_t  bit,
int8_t  pcInt 
) [inline]

Set a pin to be an input (used if the direction of a pin on the same port is altered in an interrupt handler)

Parameters:
dirA member of the MHV_PIN_* macro
outA member of the MHV_PIN_* macro
inA member of the MHV_PIN_* macro
bitA member of the MHV_PIN_* macro
pcIntA member of the MHV_PIN_* macro

Definition at line 330 of file MHV_io.h.

void mhv_setInputPullup ( MHV_PIN pin) [inline]

Set a pin to be an input, with the internal pullup enabled

Parameters:
pinthe pin to become an output

Definition at line 343 of file MHV_io.h.

void mhv_setInputPullup ( volatile uint8_t *  dir,
volatile uint8_t *  out,
volatile uint8_t *  in,
uint8_t  bit,
int8_t  pcInt 
) [inline]

Set a pin to be an input, with the internal pullup enabled

Parameters:
dirA member of the MHV_PIN_* macro
outA member of the MHV_PIN_* macro
inA member of the MHV_PIN_* macro
bitA member of the MHV_PIN_* macro
pcIntA member of the MHV_PIN_* macro

Definition at line 368 of file MHV_io.h.

void mhv_setInputPullupAtomic ( MHV_PIN pin) [inline]

Set a pin to be an input, with the internal pullup enabled (used if the direction of a pin on the same port is altered in an interrupt handler)

Parameters:
pinthe pin to become an output

Definition at line 352 of file MHV_io.h.

void mhv_setInputPullupAtomic ( volatile uint8_t *  dir,
volatile uint8_t *  out,
volatile uint8_t *  in,
uint8_t  bit,
int8_t  pcInt 
) [inline]

Set a pin to be an input, with the internal pullup enabled (used if the direction of a pin on the same port is altered in an interrupt handler)

Parameters:
dirA member of the MHV_PIN_* macro
outA member of the MHV_PIN_* macro
inA member of the MHV_PIN_* macro
bitA member of the MHV_PIN_* macro
pcIntA member of the MHV_PIN_* macro

Definition at line 382 of file MHV_io.h.

void mhv_setOutput ( MHV_PIN pin) [inline]

Set a pin to be an output

Parameters:
pinthe pin to become an output

Definition at line 245 of file MHV_io.h.

void mhv_setOutput ( volatile uint8_t *  dir,
volatile uint8_t *  out,
volatile uint8_t *  in,
uint8_t  bit,
int8_t  pcInt 
) [inline]

Set a pin to be an output

Parameters:
dirA member of the MHV_PIN_* macro
outA member of the MHV_PIN_* macro
inA member of the MHV_PIN_* macro
bitA member of the MHV_PIN_* macro
pcIntA member of the MHV_PIN_* macro

Definition at line 268 of file MHV_io.h.

void mhv_setOutputAtomic ( MHV_PIN pin) [inline]

Set a pin to be an output (used if the direction of a pin on the same port is altered in an interrupt handler)

Parameters:
pinthe pin to become an output

Definition at line 253 of file MHV_io.h.

void mhv_setOutputAtomic ( volatile uint8_t *  dir,
volatile uint8_t *  out,
volatile uint8_t *  in,
uint8_t  bit,
int8_t  pcInt 
) [inline]

Set a pin to be an output (used if the direction of a pin on the same port is altered in an interrupt handler)

Parameters:
dirA member of the MHV_PIN_* macro
outA member of the MHV_PIN_* macro
inA member of the MHV_PIN_* macro
bitA member of the MHV_PIN_* macro
pcIntA member of the MHV_PIN_* macro

Definition at line 281 of file MHV_io.h.