MHVLib  20111227
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 UNREACHABLE   __builtin_unreachable();
#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_DECLARE_PIN(_mhvPrefix)
#define MHV_PIN_PARMS(_mhvPrefix)   _mhvPrefix ## Dir, _mhvPrefix ## Out, _mhvPrefix ## In, _mhvPrefix ## Pin, _mhvPrefix ## PinchangeInterrupt
#define mhv_pin(mhvParms)   _mhv_pin(mhvParms)
#define _mhv_pin(mhvDir, mhvOutput, mhvInput, mhvBit, mhvPCInt)   {mhvDir, mhvOutput, mhvInput, _BV(mhvBit), mhvPCInt}
#define MHV_BYTESIZEOF(_mhvItem)   (uint8_t)(sizeof(_mhvItem))
#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 (MHV_DECLARE_PIN(pin))
void mhv_pinOnAtomic (MHV_DECLARE_PIN(pin))
void mhv_pinOff (MHV_PIN *pin)
void mhv_pinOffAtomic (MHV_PIN *pin)
void mhv_pinOff (MHV_DECLARE_PIN(pin))
void mhv_pinOffAtomic (MHV_DECLARE_PIN(pin))
void mhv_pinSet (MHV_DECLARE_PIN(pin), bool state)
void mhv_pinSetAtomic (MHV_DECLARE_PIN(pin), bool state)
void mhv_setOutput (MHV_PIN *pin)
void mhv_setOutputAtomic (MHV_PIN *pin)
void mhv_setOutput (MHV_DECLARE_PIN(pin))
void mhv_setOutputAtomic (MHV_DECLARE_PIN(pin))
void mhv_setInput (MHV_PIN *pin)
void mhv_setInputAtomic (MHV_PIN *pin)
void mhv_setInput (MHV_DECLARE_PIN(pin))
void mhv_setInputAtomic (MHV_DECLARE_PIN(pin))
void mhv_setInputPullup (MHV_PIN *pin)
void mhv_setInputPullupAtomic (MHV_PIN *pin)
void mhv_setInputPullup (MHV_DECLARE_PIN(pin))
void mhv_setInputPullupAtomic (MHV_DECLARE_PIN(pin))
void mhv_pinToggle (MHV_PIN *pin)
void mhv_pinToggleAtomic (MHV_PIN *pin)
void mhv_pinToggle (MHV_DECLARE_PIN(pin))
void mhv_pinToggleAtomic (MHV_DECLARE_PIN(pin))
bool mhv_pinRead (MHV_PIN *pin)
bool mhv_pinRead (MHV_DECLARE_PIN(pin))
void mhv_memClear (void *bufIn, uint8_t len, uint8_t count)
void mhv_memClear (void *bufIn, uint8_t len)
void mhv_memClear (void *bufIn, uint8_t len, uint16_t count)
void mhv_memClear (void *bufIn, uint16_t len)
void mhv_memcpy (void *bufOut, void *bufIn, uint8_t len, uint8_t count)
void mhv_memcpy (void *bufOut, void *bufIn, uint8_t len)
void mhv_memcpy (void *bufOut, void *bufIn, uint8_t len, uint16_t count)
void mhv_memcpy (void *bufOut, void *bufIn, uint16_t len)
void mhv_memcpyTailFirst (void *bufOut, void *bufIn, uint8_t len, uint8_t count)
void mhv_memcpyTailFirst (void *bufOut, void *bufIn, uint8_t len)
void mhv_memcpyTailFirst (void *bufOut, void *bufIn, uint8_t len, uint16_t count)
void mhv_memcpyTailFirst (void *bufOut, void *bufIn, uint16_t len)

Define Documentation

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

Definition at line 643 of file MHV_io.h.

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

Definition at line 675 of file MHV_io.h.

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

Definition at line 653 of file MHV_io.h.

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

Definition at line 700 of file MHV_io.h.

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

Definition at line 633 of file MHV_io.h.

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

Definition at line 97 of file MHV_io.h.

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

Definition at line 623 of file MHV_io.h.

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

Definition at line 663 of file MHV_io.h.

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

Definition at line 123 of file MHV_io.h.

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

Definition at line 77 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 640 of file MHV_io.h.

#define MHV_BYTESIZEOF (   _mhvItem)    (uint8_t)(sizeof(_mhvItem))

Get the size of an item as a byte

Parameters:
_mhvItemthe item to get the size of
Returns:
the size of the item

Definition at line 407 of file MHV_io.h.

#define MHV_DECLARE_PIN (   _mhvPrefix)
Value:
volatile uint8_t *_mhvPrefix ## Dir, volatile uint8_t *_mhvPrefix ## Out, \
        volatile uint8_t *_mhvPrefix ## In, uint8_t _mhvPrefix ## Pin, \
        int8_t _mhvPrefix ## PinchangeInterrupt

Get the list of parms for a pin declaration

Parameters:
_mhvPrefixthe prefix to use for the variable names

Definition at line 104 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 672 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 650 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 695 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 630 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 94 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 620 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 660 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 120 of file MHV_io.h.

#define MHV_PIN_PARMS (   _mhvPrefix)    _mhvPrefix ## Dir, _mhvPrefix ## Out, _mhvPrefix ## In, _mhvPrefix ## Pin, _mhvPrefix ## PinchangeInterrupt

Get the parameter list for a pin

Parameters:
_mhvPrefixthe prefix to use for the variable names

Definition at line 113 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 60 of file MHV_io.h.

#define UNREACHABLE   __builtin_unreachable();

Definition at line 57 of file MHV_io.h.


Typedef Documentation

Definition at line 687 of file MHV_io.h.

typedef struct mhv_pin MHV_PIN

Definition at line 87 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 681 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 415 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 the buffer

Definition at line 430 of file MHV_io.h.

void mhv_memClear ( void *  bufIn,
uint8_t  len,
uint16_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 445 of file MHV_io.h.

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

Cheap memset to 0

Parameters:
bufIna pointer to the buffer
lenthe length of the buffer

Definition at line 460 of file MHV_io.h.

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

Cheap memcpy

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

Definition at line 476 of file MHV_io.h.

void mhv_memcpy ( void *  bufOut,
void *  bufIn,
uint8_t  len 
) [inline]

Cheap memcpy

Parameters:
bufOuta pointer to the destination buffer
bufIna pointer to the source buffer
lenthe length of the buffer

Definition at line 493 of file MHV_io.h.

void mhv_memcpy ( void *  bufOut,
void *  bufIn,
uint8_t  len,
uint16_t  count 
) [inline]

Cheap memcpy

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

Definition at line 510 of file MHV_io.h.

void mhv_memcpy ( void *  bufOut,
void *  bufIn,
uint16_t  len 
) [inline]

Cheap memcpy

Parameters:
bufOuta pointer to the destination buffer
bufIna pointer to the source buffer
lenthe length of the buffer

Definition at line 527 of file MHV_io.h.

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

Cheap memcpy, starting from the tail

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

Definition at line 543 of file MHV_io.h.

void mhv_memcpyTailFirst ( void *  bufOut,
void *  bufIn,
uint8_t  len 
) [inline]

Cheap memcpy, starting from the tail

Parameters:
bufOuta pointer to the destination buffer
bufIna pointer to the source buffer
lenthe length of the buffer

Definition at line 561 of file MHV_io.h.

void mhv_memcpyTailFirst ( void *  bufOut,
void *  bufIn,
uint8_t  len,
uint16_t  count 
) [inline]

Cheap memcpy, starting from the tail

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

Definition at line 578 of file MHV_io.h.

void mhv_memcpyTailFirst ( void *  bufOut,
void *  bufIn,
uint16_t  len 
) [inline]

Cheap memcpy, starting from the tail

Parameters:
bufOuta pointer to the destination buffer
bufIna pointer to the source buffer
lenthe length of the buffer

Definition at line 596 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 168 of file MHV_io.h.

void mhv_pinOff ( MHV_DECLARE_PIN(pin)  ) [inline]

Set an output pin off

Parameters:
pinan MHV_PIN_* macro

Definition at line 187 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 176 of file MHV_io.h.

void mhv_pinOffAtomic ( MHV_DECLARE_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:
pinan 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 130 of file MHV_io.h.

void mhv_pinOn ( MHV_DECLARE_PIN(pin)  ) [inline]

Set an output pin on

Parameters:
pinan MHV_PIN_* macro

Definition at line 149 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 138 of file MHV_io.h.

void mhv_pinOnAtomic ( MHV_DECLARE_PIN(pin)  ) [inline]

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

Parameters:
pinan MHV_PIN_* macro

Definition at line 157 of file MHV_io.h.

bool mhv_pinRead ( MHV_PIN *  pin) [inline]

Read a pin

Parameters:
pinthe pin to read

Definition at line 388 of file MHV_io.h.

bool mhv_pinRead ( MHV_DECLARE_PIN(pin)  ) [inline]

Read a pin

Parameters:
pinan MHV_PIN_* macro

Definition at line 397 of file MHV_io.h.

void mhv_pinSet ( MHV_DECLARE_PIN(pin)  ,
bool  state 
) [inline]

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

Parameters:
pinan MHV_PIN_* macro
statetrue to turn the pin on

Definition at line 207 of file MHV_io.h.

void mhv_pinSetAtomic ( MHV_DECLARE_PIN(pin)  ,
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:
pinan MHV_PIN_* macro
statetrue to turn the pin on

Definition at line 221 of file MHV_io.h.

void mhv_pinToggle ( MHV_PIN *  pin) [inline]

Toggle a pin

Parameters:
pinthe pin to toggle

Definition at line 350 of file MHV_io.h.

void mhv_pinToggle ( MHV_DECLARE_PIN(pin)  ) [inline]

Toggle a pin

Parameters:
pinan MHV_PIN_* macro

Definition at line 369 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 358 of file MHV_io.h.

void mhv_pinToggleAtomic ( MHV_DECLARE_PIN(pin)  ) [inline]

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

Parameters:
pinan MHV_PIN_* macro

Definition at line 377 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 271 of file MHV_io.h.

void mhv_setInput ( MHV_DECLARE_PIN(pin)  ) [inline]

Set a pin to be an input

Parameters:
pinan MHV_PIN_* macro

Definition at line 290 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 280 of file MHV_io.h.

void mhv_setInputAtomic ( MHV_DECLARE_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:
pinan MHV_PIN_* macro

Definition at line 299 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 310 of file MHV_io.h.

void mhv_setInputPullup ( MHV_DECLARE_PIN(pin)  ) [inline]

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

Parameters:
pinan MHV_PIN_* macro

Definition at line 330 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 319 of file MHV_io.h.

void mhv_setInputPullupAtomic ( MHV_DECLARE_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:
pinan MHV_PIN_* macro

Definition at line 339 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 234 of file MHV_io.h.

void mhv_setOutput ( MHV_DECLARE_PIN(pin)  ) [inline]

Set a pin to be an output

Parameters:
pinan MHV_PIN_* macro

Definition at line 253 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 242 of file MHV_io.h.

void mhv_setOutputAtomic ( MHV_DECLARE_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:
pinan MHV_PIN_* macro

Definition at line 261 of file MHV_io.h.