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