Simple LoRaWAN Demo (SX1272 Radio)
Dependencies: mbed LoRaWAN-lib SX1272Lib
Fork of LoRaWAN-demo-72 by
system/utilities.cpp@8:421371b1777a, 2017-10-19 (annotated)
- Committer:
- joshcurry
- Date:
- Thu Oct 19 13:26:21 2017 +0000
- Revision:
- 8:421371b1777a
- Parent:
- 0:45496a70a8a5
Working as of 19th october.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mluis | 0:45496a70a8a5 | 1 | /* |
mluis | 0:45496a70a8a5 | 2 | / _____) _ | | |
mluis | 0:45496a70a8a5 | 3 | ( (____ _____ ____ _| |_ _____ ____| |__ |
mluis | 0:45496a70a8a5 | 4 | \____ \| ___ | (_ _) ___ |/ ___) _ \ |
mluis | 0:45496a70a8a5 | 5 | _____) ) ____| | | || |_| ____( (___| | | | |
mluis | 0:45496a70a8a5 | 6 | (______/|_____)_|_|_| \__)_____)\____)_| |_| |
mluis | 0:45496a70a8a5 | 7 | (C)2013 Semtech |
mluis | 0:45496a70a8a5 | 8 | |
mluis | 0:45496a70a8a5 | 9 | Description: Helper functions implementation |
mluis | 0:45496a70a8a5 | 10 | |
mluis | 0:45496a70a8a5 | 11 | License: Revised BSD License, see LICENSE.TXT file include in the project |
mluis | 0:45496a70a8a5 | 12 | |
mluis | 0:45496a70a8a5 | 13 | Maintainer: Miguel Luis and Gregory Cristian |
mluis | 0:45496a70a8a5 | 14 | */ |
mluis | 0:45496a70a8a5 | 15 | #include <stdlib.h> |
mluis | 0:45496a70a8a5 | 16 | #include <stdio.h> |
mluis | 0:45496a70a8a5 | 17 | #include "board.h" |
mluis | 0:45496a70a8a5 | 18 | #include "utilities.h" |
mluis | 0:45496a70a8a5 | 19 | |
mluis | 0:45496a70a8a5 | 20 | /*! |
mluis | 0:45496a70a8a5 | 21 | * Redefinition of rand() and srand() standard C functions. |
mluis | 0:45496a70a8a5 | 22 | * These functions are redefined in order to get the same behavior across |
mluis | 0:45496a70a8a5 | 23 | * different compiler toolchains implementations. |
mluis | 0:45496a70a8a5 | 24 | */ |
mluis | 0:45496a70a8a5 | 25 | // Standard random functions redefinition start |
mluis | 0:45496a70a8a5 | 26 | #define RAND_LOCAL_MAX 2147483647L |
mluis | 0:45496a70a8a5 | 27 | |
mluis | 0:45496a70a8a5 | 28 | static uint32_t next = 1; |
mluis | 0:45496a70a8a5 | 29 | |
mluis | 0:45496a70a8a5 | 30 | int32_t rand1( void ) |
mluis | 0:45496a70a8a5 | 31 | { |
mluis | 0:45496a70a8a5 | 32 | return ( ( next = next * 1103515245L + 12345L ) % RAND_LOCAL_MAX ); |
mluis | 0:45496a70a8a5 | 33 | } |
mluis | 0:45496a70a8a5 | 34 | |
mluis | 0:45496a70a8a5 | 35 | void srand1( uint32_t seed ) |
mluis | 0:45496a70a8a5 | 36 | { |
mluis | 0:45496a70a8a5 | 37 | next = seed; |
mluis | 0:45496a70a8a5 | 38 | } |
mluis | 0:45496a70a8a5 | 39 | // Standard random functions redefinition end |
mluis | 0:45496a70a8a5 | 40 | |
mluis | 0:45496a70a8a5 | 41 | int32_t randr( int32_t min, int32_t max ) |
mluis | 0:45496a70a8a5 | 42 | { |
mluis | 0:45496a70a8a5 | 43 | return ( int32_t )rand1( ) % ( max - min + 1 ) + min; |
mluis | 0:45496a70a8a5 | 44 | } |
mluis | 0:45496a70a8a5 | 45 | |
mluis | 0:45496a70a8a5 | 46 | void memcpy1( uint8_t *dst, const uint8_t *src, uint16_t size ) |
mluis | 0:45496a70a8a5 | 47 | { |
mluis | 0:45496a70a8a5 | 48 | while( size-- ) |
mluis | 0:45496a70a8a5 | 49 | { |
mluis | 0:45496a70a8a5 | 50 | *dst++ = *src++; |
mluis | 0:45496a70a8a5 | 51 | } |
mluis | 0:45496a70a8a5 | 52 | } |
mluis | 0:45496a70a8a5 | 53 | |
mluis | 0:45496a70a8a5 | 54 | void memcpyr( uint8_t *dst, const uint8_t *src, uint16_t size ) |
mluis | 0:45496a70a8a5 | 55 | { |
mluis | 0:45496a70a8a5 | 56 | dst = dst + ( size - 1 ); |
mluis | 0:45496a70a8a5 | 57 | while( size-- ) |
mluis | 0:45496a70a8a5 | 58 | { |
mluis | 0:45496a70a8a5 | 59 | *dst-- = *src++; |
mluis | 0:45496a70a8a5 | 60 | } |
mluis | 0:45496a70a8a5 | 61 | } |
mluis | 0:45496a70a8a5 | 62 | |
mluis | 0:45496a70a8a5 | 63 | void memset1( uint8_t *dst, uint8_t value, uint16_t size ) |
mluis | 0:45496a70a8a5 | 64 | { |
mluis | 0:45496a70a8a5 | 65 | while( size-- ) |
mluis | 0:45496a70a8a5 | 66 | { |
mluis | 0:45496a70a8a5 | 67 | *dst++ = value; |
mluis | 0:45496a70a8a5 | 68 | } |
mluis | 0:45496a70a8a5 | 69 | } |
mluis | 0:45496a70a8a5 | 70 | |
mluis | 0:45496a70a8a5 | 71 | int8_t Nibble2HexChar( uint8_t a ) |
mluis | 0:45496a70a8a5 | 72 | { |
mluis | 0:45496a70a8a5 | 73 | if( a < 10 ) |
mluis | 0:45496a70a8a5 | 74 | { |
mluis | 0:45496a70a8a5 | 75 | return '0' + a; |
mluis | 0:45496a70a8a5 | 76 | } |
mluis | 0:45496a70a8a5 | 77 | else if( a < 16 ) |
mluis | 0:45496a70a8a5 | 78 | { |
mluis | 0:45496a70a8a5 | 79 | return 'A' + ( a - 10 ); |
mluis | 0:45496a70a8a5 | 80 | } |
mluis | 0:45496a70a8a5 | 81 | else |
mluis | 0:45496a70a8a5 | 82 | { |
mluis | 0:45496a70a8a5 | 83 | return '?'; |
mluis | 0:45496a70a8a5 | 84 | } |
mluis | 0:45496a70a8a5 | 85 | } |