From 4977430ef31fb52994fed42b9cb180930ed943d0 Mon Sep 17 00:00:00 2001 From: Sylvain Miermont Date: Tue, 22 Oct 2013 18:23:52 +0200 Subject: Beta 8 - API: lgw_receive now return info on RX frequency and RF path for each packet (no need to keep track of RF/IF settings) - Unified some portion of the code with the 470 MHz variant of the HAL (use SX1255 radios instead of SX1257) - Improved AGC and ARB firmwares - Adding -Wall -Wextra for compilation, fixing all the new warnings for cleaner code - Fixed bugs in handling of FSK datarate - test_loragw_hal now dumps the content of all Lora registers after configuration in reg_dump.log --- loragw_spi_stress/LICENSE.TXT | 8 + loragw_spi_stress/Makefile | 34 ++++ loragw_spi_stress/README.TXT | 64 +++++++ loragw_spi_stress/obj/.gitkeep | 0 loragw_spi_stress/src/loragw_spi_stress.c | 288 ++++++++++++++++++++++++++++++ 5 files changed, 394 insertions(+) create mode 100644 loragw_spi_stress/LICENSE.TXT create mode 100644 loragw_spi_stress/Makefile create mode 100644 loragw_spi_stress/README.TXT create mode 100644 loragw_spi_stress/obj/.gitkeep create mode 100644 loragw_spi_stress/src/loragw_spi_stress.c (limited to 'loragw_spi_stress') diff --git a/loragw_spi_stress/LICENSE.TXT b/loragw_spi_stress/LICENSE.TXT new file mode 100644 index 0000000..e406dcb --- /dev/null +++ b/loragw_spi_stress/LICENSE.TXT @@ -0,0 +1,8 @@ +Copyright (C) 2013 SEMTECH S.A. + + THE FOLLOWING SOFTWARE IS PROVIDED: (1) "AS IS" WITH NO WARRANTY; AND +(2)TO ENABLE ACCESS TO CODING INFORMATION TO GUIDE AND FACILITATE CUSTOMER. +CONSEQUENTLY, SEMTECH SHALL NOT BE HELD LIABLE FOR ANY DIRECT, INDIRECT OR +CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE CONTENT +OF SUCH SOFTWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING INFORMATION +CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. diff --git a/loragw_spi_stress/Makefile b/loragw_spi_stress/Makefile new file mode 100644 index 0000000..d2fe09d --- /dev/null +++ b/loragw_spi_stress/Makefile @@ -0,0 +1,34 @@ +### Application-specific constants + +APP_NAME=loragw_spi_stress + +### constant symbols + +CC=gcc +CFLAGS=-O2 -Wall -Wextra -Iinc +C99FLAGS=-O2 -Wall -Wextra -std=c99 -Iinc +FLAG_AUX= + +### constants for Lora Gateway HAL library + +LGW_PATH=../loragw_hal +LGW_INC=-I$(LGW_PATH)/inc +#LGW_LNK=-lloragw -lrt +LGW_LNK=-lloragw -lrt -lmpsse +# add libmpsse or not, depending on what option you compiled the libloragw with + +### general build targets + +all: $(APP_NAME) + +clean: + rm -f obj/*.o + rm -f $(APP_NAME) + +### main program compilation and assembly + +obj/$(APP_NAME).o: src/$(APP_NAME).c + $(CC) -c $(C99FLAGS) -o obj/$(APP_NAME).o $(LGW_INC) src/$(APP_NAME).c $(FLAG_AUX) + +$(APP_NAME): $(LGW_PATH)/libloragw.a obj/$(APP_NAME).o + $(CC) -o $(APP_NAME) obj/$(APP_NAME).o -L$(LGW_PATH) $(LGW_LNK) diff --git a/loragw_spi_stress/README.TXT b/loragw_spi_stress/README.TXT new file mode 100644 index 0000000..fa73da1 --- /dev/null +++ b/loragw_spi_stress/README.TXT @@ -0,0 +1,64 @@ + / _____) _ | | + ( (____ _____ ____ _| |_ _____ ____| |__ + \____ \| ___ | (_ _) ___ |/ ___) _ \ + _____) ) ____| | | || |_| ____( (___| | | | + (______/|_____)_|_|_| \__)_____)\____)_| |_| + ©2013 Semtech-Cycleo + +Lora Gateway SPI stress test +============================= + +1. Introduction +---------------- + +This software is used to check the reliability of the link between the host +platform (on which the program is run) and the Lora concentrator register file +that is the interface through which all interaction with the Lora concentrator +happens. + +2. Dependencies +---------------- + +This program only access the Lora gateway HAL library through its loragw_reg +"named registers" access sub-module. + +It was tested with beta8 of the libloragw library, and should be compatible +with any later version of the library and the hardware, assuming the registers +used for the tests are still present. + +The registers used are: +LGW_VERSION +LGW_IMPLICIT_PAYLOAD_LENGHT +LGW_FSK_REF_PATTERN_LSB +LGW_RX_DATA_BUF_ADDR +LGW_RX_DATA_BUF_DATA +A data buffer accessible through the 2 registers above must be implemented. + +3. Usage +--------- + +The tests run forever or until an error is detected. +Press Ctrl+C to stop the application. + +When an error is detected, diagnosis information are displayed. Please refer to +the source code for more details on what is displayed for diagnosis. + +All tests use pseudo-random data generated by the rand() function. The random +generator is not seeded, and the same sequence of data will be use each time the +program is launched. + +Basically, some random data is written, read back and then compared to the +initial written data. Some "useless" read on others registers might be inserted +to be sure that the data read back is coming from the hardware, and not from the +internal buffer(s) of the software driver(s). + +Test 1 > R/W on a simple 8-bit register +Test 2 > R/W on a simple 8-bit register with interstitial reads on VERSION +Test 3 > R/W on a 32-bit register (short SPI bursts access) +Test 4 > data buffer R/W (long SPI bursts access) + +4. Changelog +------------- + +2013-10-18, beta 1 +Initial version. diff --git a/loragw_spi_stress/obj/.gitkeep b/loragw_spi_stress/obj/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/loragw_spi_stress/src/loragw_spi_stress.c b/loragw_spi_stress/src/loragw_spi_stress.c new file mode 100644 index 0000000..45d445f --- /dev/null +++ b/loragw_spi_stress/src/loragw_spi_stress.c @@ -0,0 +1,288 @@ +/* + / _____) _ | | +( (____ _____ ____ _| |_ _____ ____| |__ + \____ \| ___ | (_ _) ___ |/ ___) _ \ + _____) ) ____| | | || |_| ____( (___| | | | +(______/|_____)_|_|_| \__)_____)\____)_| |_| + ©2013 Semtech-Cycleo + +Description: + SPI stress test +*/ + + +/* -------------------------------------------------------------------------- */ +/* --- DEPENDANCIES --------------------------------------------------------- */ + +/* fix an issue between POSIX and C99 */ +#if __STDC_VERSION__ >= 199901L + #define _XOPEN_SOURCE 600 +#else + #define _XOPEN_SOURCE 500 +#endif + +#include /* C99 types */ +#include /* bool type */ +#include /* printf fprintf sprintf fopen fputs */ + +#include /* sigaction */ +#include /* getopt access */ +#include /* rand */ + +#include "loragw_reg.h" + +/* -------------------------------------------------------------------------- */ +/* --- PRIVATE MACROS ------------------------------------------------------- */ + +#define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0])) +#define MSG(args...) fprintf(stderr, args) /* message that is destined to the user */ + +/* -------------------------------------------------------------------------- */ +/* --- PRIVATE CONSTANTS ---------------------------------------------------- */ + +#define VERS 103 +#define READS_WHEN_ERROR 16 /* number of times a read is repeated if there is a read error */ +#define BUFF_SIZE 1024 + +/* -------------------------------------------------------------------------- */ +/* --- PRIVATE VARIABLES (GLOBAL) ------------------------------------------- */ + +/* signal handling variables */ +struct sigaction sigact; /* SIGQUIT&SIGINT&SIGTERM signal handling */ +static int exit_sig = 0; /* 1 -> application terminates cleanly (shut down hardware, close open files, etc) */ +static int quit_sig = 0; /* 1 -> application terminates without shutting down the hardware */ + +/* -------------------------------------------------------------------------- */ +/* --- PRIVATE FUNCTIONS DECLARATION ---------------------------------------- */ + +static void sig_handler(int sigio); + +void usage (void); + +/* -------------------------------------------------------------------------- */ +/* --- PRIVATE FUNCTIONS DEFINITION ----------------------------------------- */ + +static void sig_handler(int sigio) { + if (sigio == SIGQUIT) { + quit_sig = 1;; + } else if ((sigio == SIGINT) || (sigio == SIGTERM)) { + exit_sig = 1; + } +} + +/* describe command line options */ +void usage(void) { + MSG( "Available options:\n"); + MSG( " -h print this help\n"); + MSG( " -t specify which test you want to run (1-4)\n"); +} + +/* -------------------------------------------------------------------------- */ +/* --- MAIN FUNCTION -------------------------------------------------------- */ + +int main(int argc, char **argv) +{ + int i; + int xi = 0; + + /* application option */ + int test_number = 1; + int cycle_number = 0; + int repeats_per_cycle = 1000; + bool error = false; + + /* in/out variables */ + int32_t test_value; + int32_t read_value; + int32_t rb1, rb2, rb3; /* interstitial readbacks, to flush buffers if needed */ + + /* data buffer */ + int32_t test_addr; + uint8_t test_buff[BUFF_SIZE]; + uint8_t read_buff[BUFF_SIZE]; + + /* parse command line options */ + while ((i = getopt (argc, argv, "ht:")) != -1) { + switch (i) { + case 'h': + usage(); + return EXIT_FAILURE; + break; + + case 't': + i = sscanf(optarg, "%i", &xi); + if ((i != 1) || (xi < 1) || (xi > 4)) { + MSG("ERROR: invalid test number\n"); + return EXIT_FAILURE; + } else { + test_number = xi; + } + break; + + default: + MSG("ERROR: argument parsing use -h option for help\n"); + usage(); + return EXIT_FAILURE; + } + } + MSG("INFO: Starting Lora concentrator SPI stress-test number %i\n", test_number); + + /* configure signal handling */ + sigemptyset(&sigact.sa_mask); + sigact.sa_flags = 0; + sigact.sa_handler = sig_handler; + sigaction(SIGQUIT, &sigact, NULL); + sigaction(SIGINT, &sigact, NULL); + sigaction(SIGTERM, &sigact, NULL); + + /* start SPI link */ + i = lgw_connect(); + if (i != LGW_REG_SUCCESS) { + MSG("ERROR: lgw_connect() did not return SUCCESS"); + return EXIT_FAILURE; + } + + if (test_number == 1) { + /* single 8b register R/W stress test */ + while ((quit_sig != 1) && (exit_sig != 1)) { + printf("Cycle %i > ", cycle_number); + for (i=0; i ", cycle_number); + for (i=0; i ", cycle_number); + for (i=0; i ", cycle_number); + test_addr = rand() & 0xFFFF; + lgw_reg_w(LGW_RX_DATA_BUF_ADDR, test_addr); /* write at random offset in memory */ + lgw_reg_wb(LGW_RX_DATA_BUF_DATA, test_buff, BUFF_SIZE); + lgw_reg_w(LGW_RX_DATA_BUF_ADDR, test_addr); /* go back to start of segment */ + lgw_reg_rb(LGW_RX_DATA_BUF_DATA, read_buff, BUFF_SIZE); + for (i=0; ((i