* Initial release for SX1302 CoreCell Reference Design.
This commit is contained in:
Michael Coracin 2019-07-12 15:40:13 +02:00
commit 4c61c5d48e
79 changed files with 30157 additions and 0 deletions

83
util_chip_id/Makefile Normal file
View file

@ -0,0 +1,83 @@
### get external defined data
include ../target.cfg
### User defined build options
ARCH ?=
CROSS_COMPILE ?=
BUILD_MODE := release
OBJDIR = obj
### ----- AVOID MODIFICATIONS BELLOW ------ AVOID MODIFICATIONS BELLOW ----- ###
ifeq '$(BUILD_MODE)' 'alpha'
$(warning /\/\/\/ Building in 'alpha' mode \/\/\/\)
WARN_CFLAGS :=
OPT_CFLAGS := -O0
DEBUG_CFLAGS := -g
LDFLAGS :=
else ifeq '$(BUILD_MODE)' 'debug'
$(warning /\/\/\/ Building in 'debug' mode \/\/\/\)
WARN_CFLAGS := -Wall -Wextra
OPT_CFLAGS := -O2
DEBUG_CFLAGS := -g
LDFLAGS :=
else ifeq '$(BUILD_MODE)' 'release'
$(warning /\/\/\/ Building in 'release' mode \/\/\/\)
WARN_CFLAGS := -Wall -Wextra
OPT_CFLAGS := -O2 -ffunction-sections -fdata-sections
DEBUG_CFLAGS :=
LDFLAGS := -Wl,--gc-sections
else
$(error BUILD_MODE must be set to either 'alpha', 'debug' or 'release')
endif
### Application-specific variables
APP_NAME := chip_id
APP_LIBS := -lloragw -lm -ltinymt32 -lrt
### Environment constants
LIB_PATH := ../libloragw
### Expand build options
CFLAGS := -std=c99 $(WARN_CFLAGS) $(OPT_CFLAGS) $(DEBUG_CFLAGS)
CC := $(CROSS_COMPILE)gcc
AR := $(CROSS_COMPILE)ar
### General build targets
all: $(APP_NAME)
clean:
rm -f obj/*.o
rm -f $(APP_NAME)
install:
ifneq ($(strip $(TARGET_IP)),)
ifneq ($(strip $(TARGET_DIR)),)
ifneq ($(strip $(TARGET_USR)),)
@echo "---- Copying chip_id files to $(TARGET_IP):$(TARGET_DIR)"
@ssh $(TARGET_USR)@$(TARGET_IP) "mkdir -p $(TARGET_DIR)"
@scp chip_id $(TARGET_USR)@$(TARGET_IP):$(TARGET_DIR)
else
@echo "ERROR: TARGET_USR is not configured in target.cfg"
endif
else
@echo "ERROR: TARGET_DIR is not configured in target.cfg"
endif
else
@echo "ERROR: TARGET_IP is not configured in target.cfg"
endif
$(OBJDIR):
mkdir -p $(OBJDIR)
### Compile main program
$(OBJDIR)/$(APP_NAME).o: src/$(APP_NAME).c | $(OBJDIR)
$(CC) -c $< -o $@ $(CFLAGS) -Iinc -I../libloragw/inc
### Link everything together
$(APP_NAME): $(OBJDIR)/$(APP_NAME).o
$(CC) -L$(LIB_PATH) -L../libtools $^ -o $@ $(LDFLAGS) $(APP_LIBS)
### EOF

53
util_chip_id/readme.md Normal file
View file

@ -0,0 +1,53 @@
______ _
/ _____) _ | |
( (____ _____ ____ _| |_ _____ ____| |__
\____ \| ___ | (_ _) ___ |/ ___) _ \
_____) ) ____| | | || |_| ____( (___| | | |
(______/|_____)_|_|_| \__)_____)\____)_| |_|
(C)2019 Semtech
Utility to get SX1302 chip EUI
==============================
## 1. Introduction
This utility configures the SX1302 to be able to retrieve its EUI.
It can then be used as a Gateway ID.
## 2. Command line options
### 2.1. General options ###
`-h`
will display a short help and version informations.
### 2.2. SPI options ###
`-d filename`
use the Linux SPI device driver, but with an explicit path, for systems with
several SPI device drivers, or uncommon numbering scheme.
## 3. Legal notice
The information presented in this project documentation does not form part of
any quotation or contract, is believed to be accurate and reliable and may be
changed without notice. No liability will be accepted by the publisher for any
consequence of its use. Publication thereof does not convey nor imply any
license under patent or other industrial or intellectual property rights.
Semtech assumes no responsibility or liability whatsoever for any failure or
unexpected operation resulting from misuse, neglect improper installation,
repair or improper handling or unusual physical or electrical stress
including, but not limited to, exposure to parameters beyond the specified
maximum ratings or operation outside the specified range.
SEMTECH PRODUCTS ARE NOT DESIGNED, INTENDED, AUTHORIZED OR WARRANTED TO BE
SUITABLE FOR USE IN LIFE-SUPPORT APPLICATIONS, DEVICES OR SYSTEMS OR OTHER
CRITICAL APPLICATIONS. INCLUSION OF SEMTECH PRODUCTS IN SUCH APPLICATIONS IS
UNDERSTOOD TO BE UNDERTAKEN SOLELY AT THE CUSTOMER'S OWN RISK. Should a
customer purchase or use Semtech products for any such unauthorized
application, the customer shall indemnify and hold Semtech and its officers,
employees, subsidiaries, affiliates, and distributors harmless against all
claims, costs damages and attorney fees which could arise.
*EOF*

209
util_chip_id/src/chip_id.c Normal file
View file

@ -0,0 +1,209 @@
/*
______ _
/ _____) _ | |
( (____ _____ ____ _| |_ _____ ____| |__
\____ \| ___ | (_ _) ___ |/ ___) _ \
_____) ) ____| | | || |_| ____( (___| | | |
(______/|_____)_|_|_| \__)_____)\____)_| |_|
(C)2019 Semtech
Description:
Utility to get SX1302 chip EUI
License: Revised BSD License, see LICENSE.TXT file include in the project
*/
/* -------------------------------------------------------------------------- */
/* --- DEPENDANCIES --------------------------------------------------------- */
/* fix an issue between POSIX and C99 */
#if __STDC_VERSION__ >= 199901L
#define _XOPEN_SOURCE 600
#else
#define _XOPEN_SOURCE 500
#endif
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <math.h>
#include <signal.h> /* sigaction */
#include <getopt.h> /* getopt_long */
#include "loragw_hal.h"
#include "loragw_reg.h"
#include "loragw_aux.h"
/* -------------------------------------------------------------------------- */
/* --- PRIVATE MACROS ------------------------------------------------------- */
#define RAND_RANGE(min, max) (rand() % (max + 1 - min) + min)
/* -------------------------------------------------------------------------- */
/* --- PRIVATE CONSTANTS ---------------------------------------------------- */
#define LINUXDEV_PATH_DEFAULT "/dev/spidev0.0"
#define DEFAULT_CLK_SRC 0
#define DEFAULT_FREQ_HZ 868500000U
/* -------------------------------------------------------------------------- */
/* --- PRIVATE VARIABLES ---------------------------------------------------- */
/* -------------------------------------------------------------------------- */
/* --- PRIVATE FUNCTIONS ---------------------------------------------------- */
/* describe command line options */
void usage(void) {
printf("Library version information: %s\n", lgw_version_info());
printf("Available options:\n");
printf(" -h print this help\n");
printf(" -d [path] Path the spidev file (ex: /dev/spidev0.0)\n");
printf(" -k <uint> Concentrator clock source (Radio A or Radio B) [0..1]\n");
printf(" -r <uint> Radio type (1255, 1257, 1250)\n");
}
/* -------------------------------------------------------------------------- */
/* --- MAIN FUNCTION -------------------------------------------------------- */
int main(int argc, char **argv)
{
int i, x;
unsigned int arg_u;
uint8_t clocksource = 0;
lgw_radio_type_t radio_type = LGW_RADIO_TYPE_SX1250;
struct lgw_conf_board_s boardconf;
struct lgw_conf_rxrf_s rfconf;
uint64_t eui;
/* SPI interfaces */
const char spidev_path_default[] = LINUXDEV_PATH_DEFAULT;
const char * spidev_path = spidev_path_default;
/* Parameter parsing */
int option_index = 0;
static struct option long_options[] = {
{0, 0, 0, 0}
};
/* parse command line options */
while ((i = getopt_long (argc, argv, "hd:", long_options, &option_index)) != -1) {
switch (i) {
case 'h':
usage();
return -1;
break;
case 'd':
spidev_path = optarg;
break;
case 'r': /* <uint> Radio type */
i = sscanf(optarg, "%u", &arg_u);
if ((i != 1) || ((arg_u != 1255) && (arg_u != 1257) && (arg_u != 1250))) {
printf("ERROR: argument parsing of -r argument. Use -h to print help\n");
return EXIT_FAILURE;
} else {
switch (arg_u) {
case 1255:
radio_type = LGW_RADIO_TYPE_SX1255;
break;
case 1257:
radio_type = LGW_RADIO_TYPE_SX1257;
break;
default: /* 1250 */
radio_type = LGW_RADIO_TYPE_SX1250;
break;
}
}
break;
case 'k': /* <uint> Clock Source */
i = sscanf(optarg, "%u", &arg_u);
if ((i != 1) || (arg_u > 1)) {
printf("ERROR: argument parsing of -k argument. Use -h to print help\n");
return EXIT_FAILURE;
} else {
clocksource = (uint8_t)arg_u;
}
break;
default:
printf("ERROR: argument parsing\n");
usage();
return -1;
}
}
/* Board reset */
if (system("./reset_lgw.sh start") != 0) {
printf("ERROR: failed to reset SX1302, check your reset_lgw.sh script\n");
exit(EXIT_FAILURE);
}
/* Configure the gateway */
memset( &boardconf, 0, sizeof boardconf);
boardconf.lorawan_public = true;
boardconf.clksrc = clocksource;
boardconf.full_duplex = false;
strncpy(boardconf.spidev_path, spidev_path, sizeof boardconf.spidev_path);
if (lgw_board_setconf(&boardconf) != LGW_HAL_SUCCESS) {
printf("ERROR: failed to configure board\n");
return EXIT_FAILURE;
}
memset( &rfconf, 0, sizeof rfconf);
rfconf.enable = true; /* rf chain 0 needs to be enabled for calibration to work on sx1257 */
rfconf.freq_hz = 868500000; /* dummy */
rfconf.type = radio_type;
rfconf.tx_enable = false;
if (lgw_rxrf_setconf(0, &rfconf) != LGW_HAL_SUCCESS) {
printf("ERROR: failed to configure rxrf 0\n");
return EXIT_FAILURE;
}
memset( &rfconf, 0, sizeof rfconf);
rfconf.enable = (clocksource == 1) ? true : false;
rfconf.freq_hz = 868500000; /* dummy */
rfconf.type = radio_type;
rfconf.tx_enable = false;
if (lgw_rxrf_setconf(1, &rfconf) != LGW_HAL_SUCCESS) {
printf("ERROR: failed to configure rxrf 1\n");
return EXIT_FAILURE;
}
x = lgw_start();
if (x != 0) {
printf("ERROR: failed to start the gateway\n");
return EXIT_FAILURE;
}
/* get the concentrator EUI */
x = lgw_get_eui(&eui);
if (x != LGW_HAL_SUCCESS) {
printf("ERROR: failed to get concentrator EUI\n");
} else {
printf("\nINFO: concentrator EUI: 0x%016llX\n\n", eui);
}
/* Stop the gateway */
x = lgw_stop();
if (x != 0) {
printf("ERROR: failed to stop the gateway\n");
return EXIT_FAILURE;
}
/* Board reset */
if (system("./reset_lgw.sh stop") != 0) {
printf("ERROR: failed to reset SX1302, check your reset_lgw.sh script\n");
exit(EXIT_FAILURE);
}
return 0;
}
/* --- EOF ------------------------------------------------------------------ */