16FXlib
Generic helper functions (util.h)

Detailed Description

#include "util.h"
Overview
Generic helper functions and macros

Functions

void delay (uint16_t del)
 
void delay_us (uint16_t us)
 
void delay_ms (uint16_t ms)
 
void delay_s (uint16_t s)
 
int sgn (int x)
 
void intToStr (uint32_t val, uint8_t digits, uint8_t fuellChar, char *dest)
 
void intToHex (uint32_t val, uint8_t digits, uint8_t fuellchar, char *dest)
 
void random_init (void)
 
uint32_t random (void)
 

Macros

#define _BV(bit)   (1l << (bit))
 
#define RETURN_ERROR(value, max)   if ((value) > (max)) return 0;
 
#define RANDOM_INIT_PIN_COUNT   5
 
#define RANDOM_INIT_PIN_START   3
 
#define PRESCALER_MS   1993l
 

Function Documentation

void delay ( uint16_t  del)

Delays for some CPU cycles

Parameters
delDelay loop count

Definition at line 28 of file util.c.

void delay_us ( uint16_t  us)

Delays for N microseconds

Parameters
usNumber of microseconds to delay
Note
Uses Reload Timer 3!

Definition at line 34 of file util.c.

void delay_ms ( uint16_t  ms)

Delays for N milliseconds based on delay_us

Parameters
msNumber of milliseconds to delay

Definition at line 41 of file util.c.

void delay_s ( uint16_t  s)

Delays for N seconds based on delay_ms

Parameters
sNumber of seconds to delay

Definition at line 46 of file util.c.

int sgn ( int  x)

Returns 1 for values greater 0, 0 for 0, -1 for values lower 0

Parameters
xValue to check
Returns
Signum value of X

Definition at line 51 of file util.c.

void intToStr ( uint32_t  val,
uint8_t  digits,
uint8_t  fuellChar,
char *  dest 
)

Convert the given integer value (up to 32 bits, unsigned) to the string representing its decimal value.

Parameters
valInteger to convert
digitsNumber of digits the output string should have (1 - 10)
fuellCharThe character used for digits in front of the value
destPointer to stringbuffer, 0 on errror

Definition at line 55 of file util.c.

void intToHex ( uint32_t  val,
uint8_t  digits,
uint8_t  fuellchar,
char *  dest 
)

Convert the given integer value (up to 32 bits, unsigned) to the string representing its hexadecimal value.

Parameters
valInteger to convert
digitsNumber of digits the output string should have (1 - 8)
fuellcharThe character used for digits in front of the value
destPointer to stringbuffer, 0 on errror

Definition at line 78 of file util.c.

void random_init ( void  )

Initialize the random number generator.

Definition at line 107 of file util.c.

uint32_t random ( void  )

Get a random byte value. The initialization vector is created by reading out up to 4 ADC pins.

Returns
Random value
Note
random_init has to be called before the first call to random!

Definition at line 120 of file util.c.

Macro Definition Documentation

#define _BV (   bit)    (1l << (bit))

Sets the n-th bit of a byte

Parameters
bitbit to set

Definition at line 39 of file util.h.

#define RETURN_ERROR (   value,
  max 
)    if ((value) > (max)) return 0;

Returns 0 if the given value is greater than the given maximal value

Parameters
valueValue to check
maxMaximum value allowed

Definition at line 46 of file util.h.

#define RANDOM_INIT_PIN_COUNT   5

Number of ADC pins used for initialization of the RNG.

Definition at line 117 of file util.h.

#define RANDOM_INIT_PIN_START   3

First of the ADC pins used for initialization of the RNG.

Definition at line 122 of file util.h.

#define PRESCALER_MS   1993l

Prescaler used by the delay_ms routine to get loops of one millisecond each

Definition at line 127 of file util.h.