Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: EALib EthernetInterface_vz mbed-rtos mbed
Fork of header_main_colinas_V0-20-09-14 by
utils.cpp
- Committer:
- klauss
- Date:
- 2014-12-16
- Revision:
- 78:1353744f01e1
- Parent:
- 74:81c47fff88a5
- Child:
- 81:3656f00ab3db
File content as of revision 78:1353744f01e1:
#include "utils.h"
int ls_comp( const void * a, const void * b ){ return( *( int * )a - *( int * )b ); }
void reverse( char str[], int length ){
int start = 0;
int end = length -1;
while (start < end){
swap(*(str+start), *(str+end));
start++;
end--;
}
}
char* itoa(int num, char* str, int base){
int i = 0;
bool isNegative = false;
if( num == 0 ){
str[i++] = '0';
str[i] = '\0';
return str;
}
if( num < 0 && base == 10 ){
isNegative = true;
num = -num;
}
while( num != 0 ){
int rem = num % base;
str[i++] = (rem > 9)? (rem-10) + 'a' : rem + '0';
num = num/base;
}
if( isNegative )
str[i++] = '-';
str[i] = '\0'; // Append string terminator
reverse( str, i );
return( str );
}
void reset_leds( void ){ led1 = led2 = 1; led3 = led4 = 0; }
int convert_ext_to_port( int ext ){
if( ext < 1000 ) return ext;
else{
int aux = 0;
aux = ( ext / 1000 ) * 1000;
ext -= aux;
aux += ext % 100;
return( aux );
}
}
void xstrcpy(uint8_t * dest, const uint8_t * src ){
while (*src) *dest++ = *src++;
*dest = 0;
}
void xmemcpy(uint8_t * dest, const uint8_t * src, uint16_t size ){
while (size--) *dest++ = *src++;
}
void xmemcpy32(uint32_t * dest, uint32_t * src, uint16_t size){
size >>= 2;
while (size--) *dest++ = *src++;
}
uint8_t xstrmatch(const uint8_t * s1, const uint8_t * s2){
while (*s1) {
if (*s1++ != *s2++) return 0; /* does not match */
}
if ( *s2 == 0 )
return 1; /* matches */
else
return 0; /* does not match */
}
