Espotel / Mbed 2 deprecated LoRaWAN_Semtech_stack

Dependencies:   SX1272lib mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers utilities.cpp Source File

utilities.cpp

00001 /*
00002  / _____)             _              | |
00003 ( (____  _____ ____ _| |_ _____  ____| |__
00004  \____ \| ___ |    (_   _) ___ |/ ___)  _ \
00005  _____) ) ____| | | || |_| ____( (___| | | |
00006 (______/|_____)_|_|_| \__)_____)\____)_| |_|
00007     (C)2013 Semtech
00008 Description: Helper functions implementation
00009 License: Revised BSD License, see LICENSE.TXT file include in the project
00010 Maintainer: Miguel Luis and Gregory Cristian
00011 */
00012 #include <stdlib.h>
00013 #include <stdio.h>
00014 //#include "board.h"
00015 #include "mbed.h"
00016 #include "utilities.h"
00017 
00018 /*!
00019  * Redefinition of rand() and srand() standard C functions.
00020  * These functions are redefined in order to get the same behavior across
00021  * different compiler toolchains implementations.
00022  */
00023 // Standard random functions redefinition start
00024 #define RAND_LOCAL_MAX 2147483647L
00025 
00026 static uint32_t next = 1;
00027 
00028 int32_t rand1( void )
00029 {
00030     return ( ( next = next * 1103515245L + 12345L ) % RAND_LOCAL_MAX );
00031 }
00032 
00033 void srand1( uint32_t seed )
00034 {
00035     next = seed;
00036 }
00037 // Standard random functions redefinition end
00038 
00039 int32_t randr( int32_t min, int32_t max )
00040 {
00041     return ( int32_t )rand1( ) % ( max - min + 1 ) + min;
00042 }
00043 
00044 void memcpy1( uint8_t *dst, const uint8_t *src, uint16_t size )
00045 {
00046     while( size-- )
00047     {
00048         *dst++ = *src++;
00049     }
00050 }
00051 
00052 void memset1( uint8_t *dst, uint8_t value, uint16_t size )
00053 {
00054     while( size-- )
00055     {
00056         *dst++ = value;
00057     }
00058 }
00059 
00060 int8_t Nibble2HexChar( uint8_t a )
00061 {
00062     if( a < 10 )
00063     {
00064         return '0' + a;
00065     }
00066     else if( a < 16 )
00067     {
00068         return 'A' + ( a - 10 );
00069     }
00070     else
00071     {
00072         return '?';
00073     }
00074 }