Host driver/HAL to build a LoRa Picocell Gateway which communicates through USB with a concentrator board based on Semtech SX1308 multi-channel modem and SX1257/SX1255 RF transceivers.

Committer:
dgabino
Date:
Wed Apr 11 14:38:42 2018 +0000
Revision:
0:102b50f941d0
Initial commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
dgabino 0:102b50f941d0 1 /*
dgabino 0:102b50f941d0 2 / _____) _ | |
dgabino 0:102b50f941d0 3 ( (____ _____ ____ _| |_ _____ ____| |__
dgabino 0:102b50f941d0 4 \____ \| ___ | (_ _) ___ |/ ___) _ \
dgabino 0:102b50f941d0 5 _____) ) ____| | | || |_| ____( (___| | | |
dgabino 0:102b50f941d0 6 (______/|_____)_|_|_| \__)_____)\____)_| |_|
dgabino 0:102b50f941d0 7 (C)2017 Semtech-Cycleo
dgabino 0:102b50f941d0 8
dgabino 0:102b50f941d0 9 Description:
dgabino 0:102b50f941d0 10 LoRa concentrator HAL auxiliary functions
dgabino 0:102b50f941d0 11
dgabino 0:102b50f941d0 12 License: Revised BSD License, see LICENSE.TXT file include in the project
dgabino 0:102b50f941d0 13
dgabino 0:102b50f941d0 14 */
dgabino 0:102b50f941d0 15
dgabino 0:102b50f941d0 16
dgabino 0:102b50f941d0 17 /* -------------------------------------------------------------------------- */
dgabino 0:102b50f941d0 18 /* --- DEPENDANCIES --------------------------------------------------------- */
dgabino 0:102b50f941d0 19
dgabino 0:102b50f941d0 20 /* fix an issue between POSIX and C99 */
dgabino 0:102b50f941d0 21 #if __STDC_VERSION__ >= 199901L
dgabino 0:102b50f941d0 22 #define _XOPEN_SOURCE 600
dgabino 0:102b50f941d0 23 #else
dgabino 0:102b50f941d0 24 #define _XOPEN_SOURCE 500
dgabino 0:102b50f941d0 25 #endif
dgabino 0:102b50f941d0 26
dgabino 0:102b50f941d0 27 #include <stdio.h> /* printf fprintf */
dgabino 0:102b50f941d0 28 #include <time.h> /* clock_nanosleep */
dgabino 0:102b50f941d0 29
dgabino 0:102b50f941d0 30 /* -------------------------------------------------------------------------- */
dgabino 0:102b50f941d0 31 /* --- PRIVATE MACROS ------------------------------------------------------- */
dgabino 0:102b50f941d0 32
dgabino 0:102b50f941d0 33 #if DEBUG_AUX == 1
dgabino 0:102b50f941d0 34 #define DEBUG_MSG(str) fprintf(stderr, str)
dgabino 0:102b50f941d0 35 #define DEBUG_PRINTF(fmt, args...) fprintf(stderr,"%s:%d: "fmt, __FUNCTION__, __LINE__, args)
dgabino 0:102b50f941d0 36 #else
dgabino 0:102b50f941d0 37 #define DEBUG_MSG(str)
dgabino 0:102b50f941d0 38 #define DEBUG_PRINTF(fmt, args...)
dgabino 0:102b50f941d0 39 #endif
dgabino 0:102b50f941d0 40
dgabino 0:102b50f941d0 41 /* -------------------------------------------------------------------------- */
dgabino 0:102b50f941d0 42 /* --- PUBLIC FUNCTIONS DEFINITION ------------------------------------------ */
dgabino 0:102b50f941d0 43
dgabino 0:102b50f941d0 44 /* This implementation is POSIX-pecific and require a fix to be compatible with C99 */
dgabino 0:102b50f941d0 45
dgabino 0:102b50f941d0 46
dgabino 0:102b50f941d0 47 void wait_ms_linux(unsigned long a) {
dgabino 0:102b50f941d0 48 struct timespec dly;
dgabino 0:102b50f941d0 49 struct timespec rem;
dgabino 0:102b50f941d0 50
dgabino 0:102b50f941d0 51 dly.tv_sec = a / 1000;
dgabino 0:102b50f941d0 52 dly.tv_nsec = ((long)a % 1000) * 1000000;
dgabino 0:102b50f941d0 53
dgabino 0:102b50f941d0 54 DEBUG_PRINTF("NOTE dly: %ld sec %ld ns\n", dly.tv_sec, dly.tv_nsec);
dgabino 0:102b50f941d0 55
dgabino 0:102b50f941d0 56 if((dly.tv_sec > 0) || ((dly.tv_sec == 0) && (dly.tv_nsec > 100000))) {
dgabino 0:102b50f941d0 57 clock_nanosleep(CLOCK_MONOTONIC, 0, &dly, &rem);
dgabino 0:102b50f941d0 58 DEBUG_PRINTF("NOTE remain: %ld sec %ld ns\n", rem.tv_sec, rem.tv_nsec);
dgabino 0:102b50f941d0 59 }
dgabino 0:102b50f941d0 60 return;
dgabino 0:102b50f941d0 61 }
dgabino 0:102b50f941d0 62
dgabino 0:102b50f941d0 63 void wait_ns_linux(unsigned long a) {
dgabino 0:102b50f941d0 64 struct timespec dly;
dgabino 0:102b50f941d0 65 struct timespec rem;
dgabino 0:102b50f941d0 66
dgabino 0:102b50f941d0 67 dly.tv_sec = 0;
dgabino 0:102b50f941d0 68 dly.tv_nsec = a;
dgabino 0:102b50f941d0 69
dgabino 0:102b50f941d0 70 DEBUG_PRINTF("NOTE dly: %ld sec %ld ns\n", dly.tv_sec, dly.tv_nsec);
dgabino 0:102b50f941d0 71
dgabino 0:102b50f941d0 72 if((dly.tv_sec > 0) || ((dly.tv_sec == 0) && (dly.tv_nsec > 1))) {
dgabino 0:102b50f941d0 73 clock_nanosleep(CLOCK_MONOTONIC, 0, &dly, &rem);
dgabino 0:102b50f941d0 74 DEBUG_PRINTF("NOTE remain: %ld sec %ld ns\n", rem.tv_sec, rem.tv_nsec);
dgabino 0:102b50f941d0 75 }
dgabino 0:102b50f941d0 76 return;
dgabino 0:102b50f941d0 77 }
dgabino 0:102b50f941d0 78
dgabino 0:102b50f941d0 79 void wait_ms(unsigned long a) {
dgabino 0:102b50f941d0 80 #ifdef _WIN32
dgabino 0:102b50f941d0 81 return wait_ms_win(a) ;
dgabino 0:102b50f941d0 82 #elif __linux__
dgabino 0:102b50f941d0 83 return wait_ms_linux(a) ;
dgabino 0:102b50f941d0 84 #elif __APPLE__
dgabino 0:102b50f941d0 85 DEBUG_PRINTF("System is not recognized.");
dgabino 0:102b50f941d0 86 #elif __unix__
dgabino 0:102b50f941d0 87 DEBUG_PRINTF("System is not recognized.");
dgabino 0:102b50f941d0 88 #elif __posix__
dgabino 0:102b50f941d0 89 DEBUG_PRINTF("System is not recognized.");
dgabino 0:102b50f941d0 90 #else
dgabino 0:102b50f941d0 91 DEBUG_PRINTF("System is not recognized.");
dgabino 0:102b50f941d0 92 #endif
dgabino 0:102b50f941d0 93 }
dgabino 0:102b50f941d0 94 void wait_ns(unsigned long a) {
dgabino 0:102b50f941d0 95 #ifdef _WIN32
dgabino 0:102b50f941d0 96 return wait_ns_win(a) ;
dgabino 0:102b50f941d0 97 #elif __linux__
dgabino 0:102b50f941d0 98 return wait_ns_linux(a) ;
dgabino 0:102b50f941d0 99 #elif __APPLE__
dgabino 0:102b50f941d0 100 DEBUG_PRINTF("System is not recognized.");
dgabino 0:102b50f941d0 101 #elif __unix__
dgabino 0:102b50f941d0 102 DEBUG_PRINTF("System is not recognized.");
dgabino 0:102b50f941d0 103 #elif __posix__
dgabino 0:102b50f941d0 104 DEBUG_PRINTF("System is not recognized.");
dgabino 0:102b50f941d0 105 #else
dgabino 0:102b50f941d0 106 DEBUG_PRINTF("System is not recognized.");
dgabino 0:102b50f941d0 107 #endif
dgabino 0:102b50f941d0 108 }
dgabino 0:102b50f941d0 109
dgabino 0:102b50f941d0 110 /* --- EOF ------------------------------------------------------------------ */