AVR Z-LINKŪ


utilities.h File Reference


Detailed Description

Header files that defines interface to the defined support functions.

Application note:
AVR414: User's Guide - ATAVRRZ502 - Accessory Kit
Documentation
For comprehensive code documentation, supported compilers, compiler settings and supported devices see readme.html
Author:
Atmel Corporation: http://www.atmel.com
Support email: avr@atmel.com
Name
Revision
1.1
RCSfile
utilities.h,v
Date
2006/09/15 17:02:44

Definition in file utilities.h.

#include <stdint.h>
#include <stdbool.h>
#include "compiler.h"

Include dependency graph for utilities.h:

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Defines

#define END_OF_STRING   '\0'

Functions

bool htoi16 (uint8_t *hex, uint16_t *ret)
 Convert two byte hex value [0x0000 to 0xFFFF] to integer.
bool htoi8 (uint8_t *hex, uint8_t *ret)
 Convert two byte hex value [0x00 to 0xFF] to integer.
bool stringCompare (const uint8_t *str, const uint8_t __flash *fstr)
 Will compare two strings and ensure that they are identical.


Define Documentation

#define END_OF_STRING   '\0'

Definition at line 34 of file utilities.h.

Referenced by stringCompare().


Function Documentation

bool htoi16 ( uint8_t *  hex,
uint16_t *  ret 
)

Convert two byte hex value [0x0000 to 0xFFFF] to integer.

Note:
Only valid with capitol hex digits: A,B,C,D,E,F.
Parameters:
hex Ascii representation of two byte hex value.
ret Pointer to place the integer representation at.
Returns:
true if conversion was successful. False if hex was more than four bytes long, or non hexadecimal values were found.

Definition at line 150 of file utilities.c.

Referenced by handleNewCommand().

00150                                           {
00151         
00152         uint8_t i = 0x00;
00153         uint16_t radix = 1;
00154         *ret = 0x0000;
00155         
00156         //Run through and check that the length is valid.
00157         while( *hex != '\0' ){
00158                 
00159                 //Return with false with the ascii char is not in 
00160                 //the [0->F] range.
00161                 if( !( ( ( *hex >= '0' ) && ( *hex <= '9' ) ) || 
00162                      ( ( *hex >= 'A' ) && ( *hex <= 'F' ) ) ) ){
00163                         
00164                         return false;  
00165                 }
00166                 
00167                 hex++;
00168                 i++;
00169         }
00170         
00171         //Only Four or less digits. Valid conversion.
00172         if( i <= 0x04 ){
00173                 
00174                 hex--;
00175                 
00176                 //Do the actual conversion.
00177                 for( ; i > 0; i-- ){
00178                 
00179                         // 0->9
00180                         if( ( *hex >= '0' ) && ( *hex <= '9' ) ){
00181                 
00182                                 *ret += radix * ( *hex - '0' );  
00183                         }
00184                 
00185                         //A->F
00186                         else{
00187 
00188                                 *ret += radix * ( *hex - 'A' + 10 );                              
00189                         }
00190                 
00191                         hex--;
00192                         radix = radix << 4;
00193                 }
00194                 
00195                 return true;  
00196         }
00197         
00198         //Return with an error.
00199         else{
00200           
00201                 return false;
00202         }
00203 }

bool htoi8 ( uint8_t *  hex,
uint8_t *  ret 
)

Convert two byte hex value [0x00 to 0xFF] to integer.

Note:
Only valid with capitol hex digits: A,B,C,D,E,F.
Parameters:
hex Ascii representation of two byte hex value.
ret Pointer to place the integer representation at.
Returns:
true if conversion was successful. False if hex was more than two bytes long, or non hexadecimal values were found.

Definition at line 85 of file utilities.c.

Referenced by handleNewCommand().

00085                                         {
00086         
00087         uint8_t i = 0x00;
00088         uint8_t radix = 1;
00089         *ret = 0x00;
00090         
00091         //Run through and check that the length is valid.
00092         while( *hex != '\0' ){
00093                 
00094                 //Return with false with the ascii char is not in 
00095                 //the [0->F] range.
00096                 if( !( ( ( *hex >= '0' ) && ( *hex <= '9' ) ) || 
00097                      ( ( *hex >= 'A' ) && ( *hex <= 'F' ) ) ) ){
00098                         
00099                         return false;  
00100                 }
00101                 
00102                 hex++;
00103                 i++;
00104         }
00105         
00106         //Only two or less digits. Valid conversion.
00107         if( i <= 0x02 ){
00108                 
00109                 hex--;
00110                 
00111                 //Do the actual conversion.
00112                 for( ; i > 0; i-- ){
00113                 
00114                         // 0->9
00115                         if( ( *hex >= '0' ) && ( *hex <= '9' ) ){
00116                 
00117                                 *ret += radix * ( *hex - '0' );  
00118                         }
00119                 
00120                         //A->F
00121                         else{
00122 
00123                                 *ret += radix * ( *hex - 'A' + 10 );                              
00124                         }
00125                 
00126                         hex--;
00127                         radix = radix << 4; // Multiply by 16.
00128                 }
00129                 
00130                 return true;  
00131         }
00132         
00133         //Return with an error.
00134         else{
00135           
00136                 return false;
00137         }  
00138 }

bool stringCompare ( const uint8_t *  str,
const uint8_t __flash *  fstr 
)

Will compare two strings and ensure that they are identical.

str will be compared against fstr to see if they are identical. They must be of same length and contentent to be identical.

Parameters:
str String one.
fstr String to compare with.
Returns:
true if strings have identical content and length. False else.

Definition at line 47 of file utilities.c.

References END_OF_STRING.

Referenced by handleNewCommand().

00047                                                                      {
00048         
00049         //Run until one of the strings are terminated.
00050         while( !( ( *str == END_OF_STRING ) || ( *fstr == END_OF_STRING ) ) ){
00051                 
00052                 //If they are not equal before END_OF_STRING, return false.
00053                 if( *str != *fstr ){
00054                 
00055                         break;
00056                 }
00057                 
00058                 str++;
00059                 fstr++;
00060         }
00061         
00062         //Both strings equal and of same length.
00063         if( ( ( *str == END_OF_STRING ) && ( *fstr == END_OF_STRING ) ) ){
00064         
00065                 return true;  
00066         }
00067         
00068         //Equal, unequal or of different legth.
00069         else{
00070         
00071                 return false;
00072         }
00073 }

@DOC_TITLE@
Generated on Sat Dec 2 16:05:51 2006 for AVR414 User's Guide - ATAVRRZ502 - Accessory Kit by doxygen 1.4.7