Semtech stack for ELMO - ver. 4.1.0.

Dependencies:   SX1272lib mbed

Fork of LoRaWAN_Semtech_stack_v4.1 by Michal Leksinski

Committer:
mleksio
Date:
Fri Apr 22 07:37:04 2016 +0000
Revision:
5:cbb921e2a03b
Parent:
1:2be292bd43f9
Removed unused files.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mleksio 0:c58229885f95 1 /*
mleksio 0:c58229885f95 2 / _____) _ | |
mleksio 0:c58229885f95 3 ( (____ _____ ____ _| |_ _____ ____| |__
mleksio 0:c58229885f95 4 \____ \| ___ | (_ _) ___ |/ ___) _ \
mleksio 0:c58229885f95 5 _____) ) ____| | | || |_| ____( (___| | | |
mleksio 0:c58229885f95 6 (______/|_____)_|_|_| \__)_____)\____)_| |_|
mleksio 0:c58229885f95 7 (C)2013 Semtech
mleksio 0:c58229885f95 8 Description: Helper functions implementation
mleksio 0:c58229885f95 9 License: Revised BSD License, see LICENSE.TXT file include in the project
mleksio 0:c58229885f95 10 Maintainer: Miguel Luis and Gregory Cristian
mleksio 0:c58229885f95 11 */
mleksio 0:c58229885f95 12 #include <stdlib.h>
mleksio 0:c58229885f95 13 #include <stdio.h>
mleksio 0:c58229885f95 14 #include "utilities.h"
mleksio 0:c58229885f95 15
mleksio 0:c58229885f95 16 /*!
mleksio 0:c58229885f95 17 * Redefinition of rand() and srand() standard C functions.
mleksio 0:c58229885f95 18 * These functions are redefined in order to get the same behavior across
mleksio 0:c58229885f95 19 * different compiler toolchains implementations.
mleksio 0:c58229885f95 20 */
mleksio 0:c58229885f95 21 // Standard random functions redefinition start
mleksio 0:c58229885f95 22 #define RAND_LOCAL_MAX 2147483647L
mleksio 0:c58229885f95 23
mleksio 0:c58229885f95 24 static uint32_t next = 1;
mleksio 0:c58229885f95 25
mleksio 0:c58229885f95 26 int32_t rand1( void )
mleksio 0:c58229885f95 27 {
mleksio 0:c58229885f95 28 return ( ( next = next * 1103515245L + 12345L ) % RAND_LOCAL_MAX );
mleksio 0:c58229885f95 29 }
mleksio 0:c58229885f95 30
mleksio 0:c58229885f95 31 void srand1( uint32_t seed )
mleksio 0:c58229885f95 32 {
mleksio 0:c58229885f95 33 next = seed;
mleksio 0:c58229885f95 34 }
mleksio 0:c58229885f95 35 // Standard random functions redefinition end
mleksio 0:c58229885f95 36
mleksio 0:c58229885f95 37 int32_t randr( int32_t min, int32_t max )
mleksio 0:c58229885f95 38 {
mleksio 0:c58229885f95 39 return ( int32_t )rand1( ) % ( max - min + 1 ) + min;
mleksio 0:c58229885f95 40 }
mleksio 0:c58229885f95 41
mleksio 0:c58229885f95 42 void memcpy1( uint8_t *dst, const uint8_t *src, uint16_t size )
mleksio 0:c58229885f95 43 {
mleksio 0:c58229885f95 44 while( size-- )
mleksio 0:c58229885f95 45 {
mleksio 0:c58229885f95 46 *dst++ = *src++;
mleksio 0:c58229885f95 47 }
mleksio 0:c58229885f95 48 }
mleksio 0:c58229885f95 49
mleksio 1:2be292bd43f9 50 void memcpyr( uint8_t *dst, const uint8_t *src, uint16_t size )
mleksio 1:2be292bd43f9 51 {
mleksio 1:2be292bd43f9 52 dst = dst + ( size - 1 );
mleksio 1:2be292bd43f9 53 while( size-- )
mleksio 1:2be292bd43f9 54 {
mleksio 1:2be292bd43f9 55 *dst-- = *src++;
mleksio 1:2be292bd43f9 56 }
mleksio 1:2be292bd43f9 57 }
mleksio 1:2be292bd43f9 58
mleksio 0:c58229885f95 59 void memset1( uint8_t *dst, uint8_t value, uint16_t size )
mleksio 0:c58229885f95 60 {
mleksio 0:c58229885f95 61 while( size-- )
mleksio 0:c58229885f95 62 {
mleksio 0:c58229885f95 63 *dst++ = value;
mleksio 0:c58229885f95 64 }
mleksio 0:c58229885f95 65 }
mleksio 0:c58229885f95 66
mleksio 0:c58229885f95 67 int8_t Nibble2HexChar( uint8_t a )
mleksio 0:c58229885f95 68 {
mleksio 0:c58229885f95 69 if( a < 10 )
mleksio 0:c58229885f95 70 {
mleksio 0:c58229885f95 71 return '0' + a;
mleksio 0:c58229885f95 72 }
mleksio 0:c58229885f95 73 else if( a < 16 )
mleksio 0:c58229885f95 74 {
mleksio 0:c58229885f95 75 return 'A' + ( a - 10 );
mleksio 0:c58229885f95 76 }
mleksio 0:c58229885f95 77 else
mleksio 0:c58229885f95 78 {
mleksio 0:c58229885f95 79 return '?';
mleksio 0:c58229885f95 80 }
mleksio 0:c58229885f95 81 }