COSA
An Object-Oriented Platform for Arduino Programming
Types.h File Reference
#include <avr/io.h>
#include <avr/sleep.h>
#include <avr/eeprom.h>
#include <avr/interrupt.h>
#include <avr/pgmspace.h>
#include <avr/sfr_defs.h>
#include <util/delay_basic.h>
#include <stdarg.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include "Cosa/Errno.h"
#include "Cosa/Board.hh"
#include "Cosa.h"
Include dependency graph for Types.h:

Go to the source code of this file.

Classes

union  univ16_t
 
union  univ32_t
 
struct  iovec_t
 

Macros

#define __UNIQUE(name)   __CONCAT(name,__LINE__)
 
#define ROUND(x, y)   (((x) + (y - 1)) / (y))
 
#define CHARBITS   8
 
#define BYTES(bits)   ROUND(bits, CHARBITS)
 
#define UINT8_MAX   ((uin8_t) 0xffU)
 
#define UINT16_MAX   ((uint16_t) 0xffffU)
 
#define UINT32_MAX   ((uint32_t) 0xffffffffUL)
 
#define INT_MIN   INT16_MIN
 
#define INT_MAX   INT16_MAX
 
#define INT8_MIN   ((int8_t) 0x80)
 
#define INT8_MAX   ((int8_t) 0x7f)
 
#define INT16_MIN   ((int16_t) 0x8000)
 
#define INT16_MAX   ((int16_t) 0x7fff)
 
#define INT32_MIN   ((int32_t) 0x80000000L)
 
#define INT32_MAX   ((int32_t) 0x7fffffffL)
 
#define NULL   ((void*) 0)
 
#define LIKELY(x)   __builtin_expect((x), true)
 
#define UNLIKELY(x)   __builtin_expect((x), false)
 
#define UNUSED(x)   (void) (x)
 
#define membersof(x)   (sizeof(x) / sizeof(x[0]))
 
#define __PROGMEM   PROGMEM
 
#define STR_P(s)
 
#define PSTR(s)   STR_P(s)
 
#define __PSTR(s)   STR_P(s)
 
#define static_assert(condition, message)
 
#define I_CPU   (F_CPU / 1000000L)
 
#define DELAY(us)   _delay_loop_2((us) * (F_CPU / 4000000L))
 
#define nop()   __asm__ __volatile__("nop")
 
#define barrier()   __asm__ __volatile__("" ::: "memory")
 
#define synchronized
 
#define ntoh   swap
 
#define hton   swap
 

Typedefs

typedef float float32_t
 
typedef univ16_t univ_t
 
typedef const class prog_str * str_P
 
typedef const void * void_P
 
typedef const void_P void_vec_P
 
typedef volatile bool condvar_t
 

Functions

char * strcat_P (char *s1, str_P s2)
 
str_P strchr_P (str_P s, int __val)
 
str_P strchrnul_P (str_P s, int __val)
 
int strcmp_P (const char *s1, str_P s2)
 
int strncmp_P (const char *s1, str_P s2, size_t n)
 
char * strcpy_P (char *s1, str_P s2)
 
int strcasecmp_P (const char *s1, str_P s2)
 
char * strcasestr_P (const char *s1, str_P s2)
 
size_t strlen_P (str_P s)
 
uint8_t lock ()
 
void unlock (uint8_t key)
 
void __unlock (uint8_t *key)
 
uint8_t lock (condvar_t &cond)
 
size_t iovec_size (const iovec_t *vec)
 
void iovec_arg (iovec_t *&vp, const void *buf, size_t size)
 
void iovec_end (iovec_t *&vp)
 
uint16_t swap (uint16_t value)
 
void swap (uint16_t *dest, const uint16_t *src, size_t size)
 
template<class T >
void swap (T *dest, const T *src)
 
void swap (uint16_t *buf, size_t size)
 
template<class T >
void swap (T *buf)
 
int16_t swap (int16_t value)
 
void swap (int16_t *dest, const int16_t *src, size_t size)
 
uint32_t swap (uint32_t value)
 
int32_t swap (int32_t value)
 
char tohex (uint8_t value)
 
char toHEX (uint8_t value)
 

Variables

void(* delay )(uint32_t ms)
 
void(* sleep )(uint16_t s)
 
void(* yield )()
 

Detailed Description

Version
1.0

License

Copyright (C) 2012-2015, Mikael Patel

This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.

This library 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 Lesser General Public License for more details.

Description

Common literals, data types and syntax abstractions.

This file is part of the Arduino Che Cosa project.

Definition in file Types.h.

Macro Definition Documentation

Definition at line 183 of file Types.h.

#define __PSTR (   s)    STR_P(s)

Definition at line 203 of file Types.h.

#define __UNIQUE (   name)    __CONCAT(name,__LINE__)

Create an unique symbol for macro from given name and line.

Definition at line 47 of file Types.h.

#define barrier ( )    __asm__ __volatile__("" ::: "memory")

Force compiler to store all values in memory at this point. Compiler may not reorder statements and sub-expression over barriers. This is an alternative to volatile declaration.

Definition at line 312 of file Types.h.

#define BYTES (   bits)    ROUND(bits, CHARBITS)

Number of bytes for given number of bits.

Definition at line 62 of file Types.h.

#define CHARBITS   8

Number of bits in a character.

Definition at line 57 of file Types.h.

#define DELAY (   us)    _delay_loop_2((us) * (F_CPU / 4000000L))

Macro for micro-second level delay.

Parameters
[in]usmicro-seconds.

Definition at line 280 of file Types.h.

#define hton   swap

Definition at line 584 of file Types.h.

#define I_CPU   (F_CPU / 1000000L)

Instruction clock cycles per micro-second. Assumes clock greater or equal to 1 MHz.

Definition at line 274 of file Types.h.

#define INT16_MAX   ((int16_t) 0x7fff)

Definition at line 86 of file Types.h.

#define INT16_MIN   ((int16_t) 0x8000)

Definition at line 85 of file Types.h.

#define INT32_MAX   ((int32_t) 0x7fffffffL)

Definition at line 90 of file Types.h.

#define INT32_MIN   ((int32_t) 0x80000000L)

Definition at line 89 of file Types.h.

#define INT8_MAX   ((int8_t) 0x7f)

Definition at line 82 of file Types.h.

#define INT8_MIN   ((int8_t) 0x80)

Definition at line 81 of file Types.h.

#define INT_MAX   INT16_MAX

Definition at line 78 of file Types.h.

#define INT_MIN   INT16_MIN

Definition at line 77 of file Types.h.

#define LIKELY (   x)    __builtin_expect((x), true)

Compiler branch prediction hinting. The AVR processor pipeline will stall for one cycle when a condition is not true and a branch is taken. UNLIKELY will help the compiler adjust the code generation so that the branch is not taken.

Definition at line 152 of file Types.h.

#define membersof (   x)    (sizeof(x) / sizeof(x[0]))

Macro for number of elements in a vector.

Parameters
[in]xvector.
Returns
number of elements.

Definition at line 165 of file Types.h.

#define nop ( )    __asm__ __volatile__("nop")

No-operation; 1 clock cycle delay.

Definition at line 305 of file Types.h.

#define ntoh   swap

Convert values between host and network byte order. AVR is littlendian and network is bigendian so byte swap.

Definition at line 583 of file Types.h.

#define NULL   ((void*) 0)

Standard null pointer

Definition at line 101 of file Types.h.

#define PSTR (   s)    STR_P(s)

Definition at line 202 of file Types.h.

#define ROUND (   x,
 
)    (((x) + (y - 1)) / (y))

Round integer division.

Definition at line 52 of file Types.h.

#define static_assert (   condition,
  message 
)

Definition at line 266 of file Types.h.

#define STR_P (   s)
Value:
(__extension__( \
{ \
static const char __c[] __PROGMEM = (s); \
(str_P) &__c[0]; \
} \
))
#define __PROGMEM
Definition: Types.h:183
const class prog_str * str_P
Definition: Types.h:187

Program string literal that may be used in macro. Is not unique.

Parameters
[in]sstring literal (at compile time).
Returns
string literal in program memory.

Definition at line 194 of file Types.h.

#define synchronized
Value:
for (uint8_t __key __attribute__((__cleanup__(__unlock))) = lock(), \
i = 1; i != 0; i--)
uint8_t lock()
Definition: Types.h:319
void __unlock(uint8_t *key)
Definition: Types.h:343

Syntactic sugar for synchronized block. Used in the form:

1 synchronized {
2  ...
3 }
4 label:

Interrupts are disabled in the block allowing secure update. All control structures are allowed (e.g. return, goto).

Definition at line 360 of file Types.h.

#define UINT16_MAX   ((uint16_t) 0xffffU)

Definition at line 71 of file Types.h.

#define UINT32_MAX   ((uint32_t) 0xffffffffUL)

Definition at line 74 of file Types.h.

#define UINT8_MAX   ((uin8_t) 0xffU)

Standard integer range

Definition at line 68 of file Types.h.

#define UNLIKELY (   x)    __builtin_expect((x), false)

Definition at line 153 of file Types.h.

#define UNUSED (   x)    (void) (x)

Compiler warning on unused varable.

Definition at line 158 of file Types.h.

Typedef Documentation

typedef volatile bool condvar_t

Conditional variable.

Definition at line 367 of file Types.h.

typedef float float32_t

Standard floating point number, 32-bit.

Definition at line 107 of file Types.h.

typedef const class prog_str* str_P

Unique data type for strings in program memory.

Definition at line 187 of file Types.h.

typedef univ16_t univ_t

Definition at line 124 of file Types.h.

typedef const void* void_P

Pointer table in program memory.

Definition at line 260 of file Types.h.

typedef const void_P void_vec_P

Definition at line 261 of file Types.h.

Function Documentation

void __unlock ( uint8_t *  key)
inline

Restore processor flags and possible enable of interrupts. Internal clean up function for synchronized block.

Parameters
[in]keyprocessor flags.

Definition at line 343 of file Types.h.

void iovec_arg ( iovec_t *&  vp,
const void *  buf,
size_t  size 
)
inline

Set next io-vector buffer. Used in to form:

1 iovec_t vec[N];
2 iovec_t* vp = vec;
3 iovec_arg(vp, buf, size);
4 ..
5 iovec_end(vp);
Parameters
[in,out]vpio vector pointer
[in]bufbuffer.
[in]sizenumber of bytes.

Definition at line 430 of file Types.h.

void iovec_end ( iovec_t *&  vp)
inline

Mark end of io-vector buffer at given index. Used in the form:

1 iovec_t vec[N];
2 iovec_t* vp = vec;
3 iovec_arg(vp, buf, size);
4 ..
5 iovec_end(vp);
Parameters
[in,out]vpio vector.

Definition at line 449 of file Types.h.

size_t iovec_size ( const iovec_t vec)
inline

Return total size of null terminated io buffer vector.

Parameters
[in]vpio vector pointer
Returns
size.

Definition at line 407 of file Types.h.

uint8_t lock ( )
inline

Disable interrupts and return flags.

Returns
processor flags.

Definition at line 319 of file Types.h.

uint8_t lock ( condvar_t cond)
inline

Wait until condition variable is true then disable interrupts and set condition variable to false and return flags.

Parameters
[in]condcondition variable.
Returns
processor flags.

Definition at line 376 of file Types.h.

int strcasecmp_P ( const char *  s1,
str_P  s2 
)
inline

Definition at line 242 of file Types.h.

char* strcasestr_P ( const char *  s1,
str_P  s2 
)
inline

Definition at line 248 of file Types.h.

char* strcat_P ( char *  s1,
str_P  s2 
)
inline

Definition at line 206 of file Types.h.

str_P strchr_P ( str_P  s,
int  __val 
)
inline

Definition at line 212 of file Types.h.

str_P strchrnul_P ( str_P  s,
int  __val 
)
inline

Definition at line 218 of file Types.h.

int strcmp_P ( const char *  s1,
str_P  s2 
)
inline

Definition at line 224 of file Types.h.

char* strcpy_P ( char *  s1,
str_P  s2 
)
inline

Definition at line 236 of file Types.h.

size_t strlen_P ( str_P  s)
inline

Definition at line 254 of file Types.h.

int strncmp_P ( const char *  s1,
str_P  s2,
size_t  n 
)
inline

Definition at line 230 of file Types.h.

uint16_t swap ( uint16_t  value)
inline

Swap bytes in 16-bit unsigned integer.

Parameters
[in]valueto byte swap.
Returns
new value.

Definition at line 461 of file Types.h.

void swap ( uint16_t *  dest,
const uint16_t *  src,
size_t  size 
)
inline

Swap bytes in 16-bit unsigned integer vector.

Parameters
[in]destdestination buffer.
[in]srcsource buffer.
[in]sizenumber of integers to swap.

Definition at line 478 of file Types.h.

template<class T >
void swap ( T *  dest,
const T *  src 
)

Swap bytes in 16-bit values in struct.

Parameters
[in]Ttype of struct.
[in]destdestination buffer.
[in]srcsource buffer.

Definition at line 493 of file Types.h.

void swap ( uint16_t *  buf,
size_t  size 
)
inline

Destructive swap bytes in 16-bit unsigned integer vector.

Parameters
[in]bufbuffer.
[in]sizenumber of integers to swap.

Definition at line 503 of file Types.h.

template<class T >
void swap ( T *  buf)

Destructive swap bytes in 16-bit integers in struct.

Parameters
[in]Ttype of struct.
[in]bufbuffer.

Definition at line 518 of file Types.h.

int16_t swap ( int16_t  value)
inline

Swap bytes in 16-bit signed integer.

Parameters
[in]valueto byte swap.
Returns
new value.

Definition at line 529 of file Types.h.

void swap ( int16_t *  dest,
const int16_t *  src,
size_t  size 
)
inline

Swap bytes in 16-bit integer vector.

Parameters
[in]destdestination buffer.
[in]srcsource buffer.
[in]sizenumber of integers to swap.

Definition at line 540 of file Types.h.

uint32_t swap ( uint32_t  value)
inline

Swap bytes in 32-bit unsigned integer.

Parameters
[in]valueto byte swap.
Returns
new value.

Definition at line 554 of file Types.h.

int32_t swap ( int32_t  value)
inline

Swap bytes in 32-bit signed integer.

Parameters
[in]valueto byte swap.
Returns
new value.

Definition at line 574 of file Types.h.

char tohex ( uint8_t  value)
inline

Convert 4-bit LSB value to hexadecimal character ('0'..'f').

Parameters
[in]value.
Returns
character.

Definition at line 592 of file Types.h.

char toHEX ( uint8_t  value)
inline

Convert 4-bit LSB value to hexadecimal character ('0'..'F').

Parameters
[in]value.
Returns
character.

Definition at line 606 of file Types.h.

void unlock ( uint8_t  key)
inline

Restore processor flags and possible enable of interrupts.

Parameters
[in]keyprocessor flags.

Definition at line 331 of file Types.h.

Variable Documentation

void(* delay) (uint32_t ms)

Delay given number of milli-seconds. This function pointer may be redefined to allow low-power and/or multi-tasking duing wait.

Parameters
[in]msmilli-seconds delay.
void(* sleep) (uint16_t s)

Sleep given number of seconds. This function pointer may be redefined to allow low-power and/or multi-tasking duing wait.

Parameters
[in]sseconds delay.
void(* yield) ()

Allow context switch to other tasks if available. The default implementation is a low-power sleep and wait for interrupt.