light sensor

Dependencies:   X_NUCLEO_IKS01A1 LoRaWAN-lib SX1276Lib mbed

Fork of LoRaWAN-SX1276-Application-Demo by Uttam Bhat

Committer:
ubhat
Date:
Fri Aug 26 19:36:35 2016 +0000
Revision:
0:42863a11464a
SX1276 Shield based Applications

Who changed what in which revision?

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