custom one..irr_shared
| @@ -1,28 +1,28 @@ | |||||
| lst/ | |||||
| obj/ | |||||
| bin/ | |||||
| build/ | |||||
| tmp/ | |||||
| *.bin | |||||
| .kdev4 | |||||
| *.log | |||||
| *.dep | |||||
| *.uvgui.* | |||||
| *.uvgui_*.bak | |||||
| *.uvguix.* | |||||
| *.uvguix_*.bak | |||||
| *_uvopt.bak | |||||
| *_uvoptx.bak | |||||
| *_uvproj.bak | |||||
| *_uvprojx.bak | |||||
| *.ctx | |||||
| *.dbi | |||||
| *.xdb | |||||
| *.svn | |||||
| *.pbxproj | |||||
| *.cogui | |||||
| *.comarker | |||||
| .directory | |||||
| .vscode/launch.json | |||||
| .cmaketools.json | |||||
| ipch/ | |||||
| lst/ | |||||
| obj/ | |||||
| bin/ | |||||
| build/ | |||||
| tmp/ | |||||
| *.bin | |||||
| .kdev4 | |||||
| *.log | |||||
| *.dep | |||||
| *.uvgui.* | |||||
| *.uvgui_*.bak | |||||
| *.uvguix.* | |||||
| *.uvguix_*.bak | |||||
| *_uvopt.bak | |||||
| *_uvoptx.bak | |||||
| *_uvproj.bak | |||||
| *_uvprojx.bak | |||||
| *.ctx | |||||
| *.dbi | |||||
| *.xdb | |||||
| *.svn | |||||
| *.pbxproj | |||||
| *.cogui | |||||
| *.comarker | |||||
| .directory | |||||
| .vscode/launch.json | |||||
| .cmaketools.json | |||||
| ipch/ | |||||
| @@ -15,4 +15,4 @@ | |||||
| } | } | ||||
| ], | ], | ||||
| "version": 4 | "version": 4 | ||||
| } | |||||
| } | |||||
| @@ -1,83 +1,83 @@ | |||||
| // Place your settings in this file to overwrite default and user settings. | |||||
| { | |||||
| "cmake.configureSettings": { | |||||
| // In case your GNU ARM-Toolchain is not installed under the default | |||||
| // path: | |||||
| // Windows : No default path. Specify the path where the | |||||
| // toolchain is installed. i.e: | |||||
| // "C:/PROGRA~2/GNUTOO~1/92019-~1". | |||||
| // Linux : /usr | |||||
| // OSX : /usr/local | |||||
| // It is required to uncomment and to fill the following line. | |||||
| //"TOOLCHAIN_PREFIX":"/path/to/toolchain", | |||||
| // In case your OpenOCD is not installed under the default path: | |||||
| // Windows : C:/openocd/bin/openocd.exe | |||||
| // Linux : /usr/bin/openocd | |||||
| // OSX : /usr/local/bin/openocd | |||||
| // Please uncomment the following line and fill it accordingly. | |||||
| //"OPENOCD_BIN":"C:/openocd/bin/openocd.exe", | |||||
| // Specifies the path to the CMAKE toolchain file. | |||||
| "CMAKE_TOOLCHAIN_FILE":"cmake/toolchain-arm-none-eabi.cmake", | |||||
| // Determines the application. You can choose between: | |||||
| // LoRaMac (Default), ping-pong, rx-sensi, tx-cw. | |||||
| "APPLICATION":"LoRaMac", | |||||
| // Select LoRaMac sub project. You can choose between: | |||||
| // periodic-uplink-lpp, fuota-test-01. | |||||
| "SUB_PROJECT":"periodic-uplink-lpp", | |||||
| // Switch for Class B support of LoRaMac: | |||||
| "CLASSB_ENABLED":"ON", | |||||
| // Select the active region for which the stack will be initialized. | |||||
| // You can choose between: | |||||
| // LORAMAC_REGION_EU868, LORAMAC_REGION_US915, .. | |||||
| "ACTIVE_REGION":"LORAMAC_REGION_EU868", | |||||
| // Select the type of modulation, applicable to the ping-pong or | |||||
| // rx-sensi applications. You can choose between: | |||||
| // LORA or FSK | |||||
| "MODULATION":"LORA", | |||||
| // Target board, the following boards are supported: | |||||
| // NAMote72, NucleoL073 (Default), NucleoL152, NucleoL476, SAMR34, SKiM880B, SKiM980A, SKiM881AXL, B-L072Z-LRWAN1. | |||||
| "BOARD":"NucleoL073", | |||||
| // MBED Radio shield selection. (Applies only to Nucleo platforms) | |||||
| // The following shields are supported: | |||||
| // SX1272MB2DAS, SX1276MB1LAS, SX1276MB1MAS, SX1261MBXBAS(Default), SX1262MBXCAS, SX1262MBXDAS, LR1110MB1XXS. | |||||
| "MBED_RADIO_SHIELD":"SX1261MBXBAS", | |||||
| // Secure element type selection the following are supported | |||||
| // SOFT_SE(Default), LR1110_SE, ATECC608A_TNGLORA_SE | |||||
| "SECURE_ELEMENT":"SOFT_SE", | |||||
| // Secure element is pre-provisioned | |||||
| "SECURE_ELEMENT_PRE_PROVISIONED":"ON", | |||||
| // Region support activation, Select the ones you want to support. | |||||
| // By default only REGION_EU868 support is enabled. | |||||
| "REGION_EU868":"ON", | |||||
| "REGION_US915":"OFF", | |||||
| "REGION_CN779":"OFF", | |||||
| "REGION_EU433":"OFF", | |||||
| "REGION_AU915":"OFF", | |||||
| "REGION_CN470":"OFF", | |||||
| "REGION_AS923":"OFF", | |||||
| "REGION_KR920":"OFF", | |||||
| "REGION_IN865":"OFF", | |||||
| "REGION_RU864":"OFF", | |||||
| // Default channel plan for region AS923. Possible selections: | |||||
| // CHANNEL_PLAN_GROUP_AS923_1, CHANNEL_PLAN_GROUP_AS923_2, CHANNEL_PLAN_GROUP_AS923_3, CHANNEL_PLAN_GROUP_AS923_1_JP | |||||
| "REGION_AS923_DEFAULT_CHANNEL_PLAN":"CHANNEL_PLAN_GROUP_AS923_1", | |||||
| // Default channel plan for region CN470. Possible selections: | |||||
| // CHANNEL_PLAN_20MHZ_TYPE_A, CHANNEL_PLAN_20MHZ_TYPE_B, CHANNEL_PLAN_26MHZ_TYPE_A, CHANNEL_PLAN_26MHZ_TYPE_B | |||||
| "REGION_CN470_DEFAULT_CHANNEL_PLAN":"CHANNEL_PLAN_20MHZ_TYPE_A" | |||||
| } | |||||
| } | |||||
| // Place your settings in this file to overwrite default and user settings. | |||||
| { | |||||
| "cmake.configureSettings": { | |||||
| // In case your GNU ARM-Toolchain is not installed under the default | |||||
| // path: | |||||
| // Windows : No default path. Specify the path where the | |||||
| // toolchain is installed. i.e: | |||||
| // "C:/PROGRA~2/GNUTOO~1/92019-~1". | |||||
| // Linux : /usr | |||||
| // OSX : /usr/local | |||||
| // It is required to uncomment and to fill the following line. | |||||
| //"TOOLCHAIN_PREFIX":"/path/to/toolchain", | |||||
| // In case your OpenOCD is not installed under the default path: | |||||
| // Windows : C:/openocd/bin/openocd.exe | |||||
| // Linux : /usr/bin/openocd | |||||
| // OSX : /usr/local/bin/openocd | |||||
| // Please uncomment the following line and fill it accordingly. | |||||
| //"OPENOCD_BIN":"C:/openocd/bin/openocd.exe", | |||||
| // Specifies the path to the CMAKE toolchain file. | |||||
| "CMAKE_TOOLCHAIN_FILE":"cmake/toolchain-arm-none-eabi.cmake", | |||||
| // Determines the application. You can choose between: | |||||
| // LoRaMac (Default), ping-pong, rx-sensi, tx-cw. | |||||
| "APPLICATION":"LoRaMac", | |||||
| // Select LoRaMac sub project. You can choose between: | |||||
| // periodic-uplink-lpp, fuota-test-01. | |||||
| "SUB_PROJECT":"periodic-uplink-lpp", | |||||
| // Switch for Class B support of LoRaMac: | |||||
| "CLASSB_ENABLED":"ON", | |||||
| // Select the active region for which the stack will be initialized. | |||||
| // You can choose between: | |||||
| // LORAMAC_REGION_EU868, LORAMAC_REGION_US915, .. | |||||
| "ACTIVE_REGION":"LORAMAC_REGION_EU868", | |||||
| // Select the type of modulation, applicable to the ping-pong or | |||||
| // rx-sensi applications. You can choose between: | |||||
| // LORA or FSK | |||||
| "MODULATION":"LORA", | |||||
| // Target board, the following boards are supported: | |||||
| // NAMote72, NucleoL073 (Default), NucleoL152, NucleoL476, SAMR34, SKiM880B, SKiM980A, SKiM881AXL, B-L072Z-LRWAN1. | |||||
| "BOARD":"NucleoL073", | |||||
| // MBED Radio shield selection. (Applies only to Nucleo platforms) | |||||
| // The following shields are supported: | |||||
| // SX1272MB2DAS, SX1276MB1LAS, SX1276MB1MAS, SX1261MBXBAS(Default), SX1262MBXCAS, SX1262MBXDAS, LR1110MB1XXS. | |||||
| "MBED_RADIO_SHIELD":"SX1261MBXBAS", | |||||
| // Secure element type selection the following are supported | |||||
| // SOFT_SE(Default), LR1110_SE, ATECC608A_TNGLORA_SE | |||||
| "SECURE_ELEMENT":"SOFT_SE", | |||||
| // Secure element is pre-provisioned | |||||
| "SECURE_ELEMENT_PRE_PROVISIONED":"ON", | |||||
| // Region support activation, Select the ones you want to support. | |||||
| // By default only REGION_EU868 support is enabled. | |||||
| "REGION_EU868":"ON", | |||||
| "REGION_US915":"OFF", | |||||
| "REGION_CN779":"OFF", | |||||
| "REGION_EU433":"OFF", | |||||
| "REGION_AU915":"OFF", | |||||
| "REGION_CN470":"OFF", | |||||
| "REGION_AS923":"OFF", | |||||
| "REGION_KR920":"OFF", | |||||
| "REGION_IN865":"OFF", | |||||
| "REGION_RU864":"OFF", | |||||
| // Default channel plan for region AS923. Possible selections: | |||||
| // CHANNEL_PLAN_GROUP_AS923_1, CHANNEL_PLAN_GROUP_AS923_2, CHANNEL_PLAN_GROUP_AS923_3, CHANNEL_PLAN_GROUP_AS923_1_JP | |||||
| "REGION_AS923_DEFAULT_CHANNEL_PLAN":"CHANNEL_PLAN_GROUP_AS923_1", | |||||
| // Default channel plan for region CN470. Possible selections: | |||||
| // CHANNEL_PLAN_20MHZ_TYPE_A, CHANNEL_PLAN_20MHZ_TYPE_B, CHANNEL_PLAN_26MHZ_TYPE_A, CHANNEL_PLAN_26MHZ_TYPE_B | |||||
| "REGION_CN470_DEFAULT_CHANNEL_PLAN":"CHANNEL_PLAN_20MHZ_TYPE_A" | |||||
| } | |||||
| } | |||||
| @@ -1,21 +1,21 @@ | |||||
| ## | |||||
| ## ______ _ | |||||
| ## / _____) _ | | | |||||
| ## ( (____ _____ ____ _| |_ _____ ____| |__ | |||||
| ## \____ \| ___ | (_ _) ___ |/ ___) _ \ | |||||
| ## _____) ) ____| | | || |_| ____( (___| | | | | |||||
| ## (______/|_____)_|_|_| \__)_____)\____)_| |_| | |||||
| ## (C)2013-2017 Semtech | |||||
| ## ___ _____ _ ___ _ _____ ___ ___ ___ ___ | |||||
| ## / __|_ _/_\ / __| |/ / __/ _ \| _ \/ __| __| | |||||
| ## \__ \ | |/ _ \ (__| ' <| _| (_) | / (__| _| | |||||
| ## |___/ |_/_/ \_\___|_|\_\_| \___/|_|_\\___|___| | |||||
| ## embedded.connectivity.solutions.============== | |||||
| ## | |||||
| ## License: Revised BSD License, see LICENSE.TXT file included in the project | |||||
| ## Authors: Johannes Bruder (STACKFORCE), Miguel Luis (Semtech) | |||||
| ## | |||||
| project(loramac-node) | |||||
| cmake_minimum_required(VERSION 3.6) | |||||
| add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/src) | |||||
| ## | |||||
| ## ______ _ | |||||
| ## / _____) _ | | | |||||
| ## ( (____ _____ ____ _| |_ _____ ____| |__ | |||||
| ## \____ \| ___ | (_ _) ___ |/ ___) _ \ | |||||
| ## _____) ) ____| | | || |_| ____( (___| | | | | |||||
| ## (______/|_____)_|_|_| \__)_____)\____)_| |_| | |||||
| ## (C)2013-2017 Semtech | |||||
| ## ___ _____ _ ___ _ _____ ___ ___ ___ ___ | |||||
| ## / __|_ _/_\ / __| |/ / __/ _ \| _ \/ __| __| | |||||
| ## \__ \ | |/ _ \ (__| ' <| _| (_) | / (__| _| | |||||
| ## |___/ |_/_/ \_\___|_|\_\_| \___/|_|_\\___|___| | |||||
| ## embedded.connectivity.solutions.============== | |||||
| ## | |||||
| ## License: Revised BSD License, see LICENSE.TXT file included in the project | |||||
| ## Authors: Johannes Bruder (STACKFORCE), Miguel Luis (Semtech) | |||||
| ## | |||||
| project(loramac-node) | |||||
| cmake_minimum_required(VERSION 3.6) | |||||
| add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/src) | |||||
| @@ -1,24 +1,24 @@ | |||||
| Revised BSD License | |||||
| Copyright Semtech Corporation 2013. All rights reserved. | |||||
| Redistribution and use in source and binary forms, with or without | |||||
| modification, are permitted provided that the following conditions are met: | |||||
| * Redistributions of source code must retain the above copyright | |||||
| notice, this list of conditions and the following disclaimer. | |||||
| * Redistributions in binary form must reproduce the above copyright | |||||
| notice, this list of conditions and the following disclaimer in the | |||||
| documentation and/or other materials provided with the distribution. | |||||
| * Neither the name of the Semtech corporation nor the | |||||
| names of its contributors may be used to endorse or promote products | |||||
| derived from this software without specific prior written permission. | |||||
| THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | |||||
| AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |||||
| IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |||||
| ARE DISCLAIMED. IN NO EVENT SHALL SEMTECH CORPORATION BE LIABLE FOR ANY DIRECT, | |||||
| INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | |||||
| (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | |||||
| LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | |||||
| ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |||||
| (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | |||||
| SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |||||
| Revised BSD License | |||||
| Copyright Semtech Corporation 2013. All rights reserved. | |||||
| Redistribution and use in source and binary forms, with or without | |||||
| modification, are permitted provided that the following conditions are met: | |||||
| * Redistributions of source code must retain the above copyright | |||||
| notice, this list of conditions and the following disclaimer. | |||||
| * Redistributions in binary form must reproduce the above copyright | |||||
| notice, this list of conditions and the following disclaimer in the | |||||
| documentation and/or other materials provided with the distribution. | |||||
| * Neither the name of the Semtech corporation nor the | |||||
| names of its contributors may be used to endorse or promote products | |||||
| derived from this software without specific prior written permission. | |||||
| THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | |||||
| AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |||||
| IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |||||
| ARE DISCLAIMED. IN NO EVENT SHALL SEMTECH CORPORATION BE LIABLE FOR ANY DIRECT, | |||||
| INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | |||||
| (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | |||||
| LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | |||||
| ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |||||
| (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | |||||
| SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |||||
| @@ -1,50 +1,50 @@ | |||||
| ## | |||||
| ## ______ _ | |||||
| ## / _____) _ | | | |||||
| ## ( (____ _____ ____ _| |_ _____ ____| |__ | |||||
| ## \____ \| ___ | (_ _) ___ |/ ___) _ \ | |||||
| ## _____) ) ____| | | || |_| ____( (___| | | | | |||||
| ## (______/|_____)_|_|_| \__)_____)\____)_| |_| | |||||
| ## (C)2013-2017 Semtech | |||||
| ## ___ _____ _ ___ _ _____ ___ ___ ___ ___ | |||||
| ## / __|_ _/_\ / __| |/ / __/ _ \| _ \/ __| __| | |||||
| ## \__ \ | |/ _ \ (__| ' <| _| (_) | / (__| _| | |||||
| ## |___/ |_/_/ \_\___|_|\_\_| \___/|_|_\\___|___| | |||||
| ## embedded.connectivity.solutions.============== | |||||
| ## | |||||
| ## License: Revised BSD License, see LICENSE.TXT file included in the project | |||||
| ## Authors: Johannes Bruder ( STACKFORCE ), Miguel Luis ( Semtech ) | |||||
| ## | |||||
| ## | |||||
| ## CMake arm-none-eabi binutils integration and helper functions | |||||
| ## | |||||
| #--------------------------------------------------------------------------------------- | |||||
| # Set tools | |||||
| #--------------------------------------------------------------------------------------- | |||||
| set(CMAKE_OBJCOPY ${TOOLCHAIN_BIN_DIR}/${TOOLCHAIN}-objcopy${TOOLCHAIN_EXT}) | |||||
| set(CMAKE_OBJDUMP ${TOOLCHAIN_BIN_DIR}/${TOOLCHAIN}-objdump${TOOLCHAIN_EXT}) | |||||
| set(CMAKE_SIZE ${TOOLCHAIN_BIN_DIR}/${TOOLCHAIN}-size${TOOLCHAIN_EXT}) | |||||
| #--------------------------------------------------------------------------------------- | |||||
| # Prints the section sizes | |||||
| #--------------------------------------------------------------------------------------- | |||||
| function(print_section_sizes TARGET) | |||||
| add_custom_command(TARGET ${TARGET} POST_BUILD COMMAND ${CMAKE_SIZE} ${TARGET}) | |||||
| endfunction() | |||||
| #--------------------------------------------------------------------------------------- | |||||
| # Creates output in hex format | |||||
| #--------------------------------------------------------------------------------------- | |||||
| function(create_hex_output TARGET) | |||||
| add_custom_target(${TARGET}.hex ALL DEPENDS ${TARGET} COMMAND ${CMAKE_OBJCOPY} -Oihex ${TARGET} ${TARGET}.hex) | |||||
| endfunction() | |||||
| #--------------------------------------------------------------------------------------- | |||||
| # Creates output in binary format | |||||
| #--------------------------------------------------------------------------------------- | |||||
| function(create_bin_output TARGET) | |||||
| add_custom_target(${TARGET}.bin ALL DEPENDS ${TARGET} COMMAND ${CMAKE_OBJCOPY} -Obinary ${TARGET} ${TARGET}.bin) | |||||
| endfunction() | |||||
| ## | |||||
| ## ______ _ | |||||
| ## / _____) _ | | | |||||
| ## ( (____ _____ ____ _| |_ _____ ____| |__ | |||||
| ## \____ \| ___ | (_ _) ___ |/ ___) _ \ | |||||
| ## _____) ) ____| | | || |_| ____( (___| | | | | |||||
| ## (______/|_____)_|_|_| \__)_____)\____)_| |_| | |||||
| ## (C)2013-2017 Semtech | |||||
| ## ___ _____ _ ___ _ _____ ___ ___ ___ ___ | |||||
| ## / __|_ _/_\ / __| |/ / __/ _ \| _ \/ __| __| | |||||
| ## \__ \ | |/ _ \ (__| ' <| _| (_) | / (__| _| | |||||
| ## |___/ |_/_/ \_\___|_|\_\_| \___/|_|_\\___|___| | |||||
| ## embedded.connectivity.solutions.============== | |||||
| ## | |||||
| ## License: Revised BSD License, see LICENSE.TXT file included in the project | |||||
| ## Authors: Johannes Bruder ( STACKFORCE ), Miguel Luis ( Semtech ) | |||||
| ## | |||||
| ## | |||||
| ## CMake arm-none-eabi binutils integration and helper functions | |||||
| ## | |||||
| #--------------------------------------------------------------------------------------- | |||||
| # Set tools | |||||
| #--------------------------------------------------------------------------------------- | |||||
| set(CMAKE_OBJCOPY ${TOOLCHAIN_BIN_DIR}/${TOOLCHAIN}-objcopy${TOOLCHAIN_EXT}) | |||||
| set(CMAKE_OBJDUMP ${TOOLCHAIN_BIN_DIR}/${TOOLCHAIN}-objdump${TOOLCHAIN_EXT}) | |||||
| set(CMAKE_SIZE ${TOOLCHAIN_BIN_DIR}/${TOOLCHAIN}-size${TOOLCHAIN_EXT}) | |||||
| #--------------------------------------------------------------------------------------- | |||||
| # Prints the section sizes | |||||
| #--------------------------------------------------------------------------------------- | |||||
| function(print_section_sizes TARGET) | |||||
| add_custom_command(TARGET ${TARGET} POST_BUILD COMMAND ${CMAKE_SIZE} ${TARGET}) | |||||
| endfunction() | |||||
| #--------------------------------------------------------------------------------------- | |||||
| # Creates output in hex format | |||||
| #--------------------------------------------------------------------------------------- | |||||
| function(create_hex_output TARGET) | |||||
| add_custom_target(${TARGET}.hex ALL DEPENDS ${TARGET} COMMAND ${CMAKE_OBJCOPY} -Oihex ${TARGET} ${TARGET}.hex) | |||||
| endfunction() | |||||
| #--------------------------------------------------------------------------------------- | |||||
| # Creates output in binary format | |||||
| #--------------------------------------------------------------------------------------- | |||||
| function(create_bin_output TARGET) | |||||
| add_custom_target(${TARGET}.bin ALL DEPENDS ${TARGET} COMMAND ${CMAKE_OBJCOPY} -Obinary ${TARGET} ${TARGET}.bin) | |||||
| endfunction() | |||||
| @@ -1,101 +1,101 @@ | |||||
| ## | |||||
| ## ______ _ | |||||
| ## / _____) _ | | | |||||
| ## ( (____ _____ ____ _| |_ _____ ____| |__ | |||||
| ## \____ \| ___ | (_ _) ___ |/ ___) _ \ | |||||
| ## _____) ) ____| | | || |_| ____( (___| | | | | |||||
| ## (______/|_____)_|_|_| \__)_____)\____)_| |_| | |||||
| ## (C)2013-2017 Semtech | |||||
| ## ___ _____ _ ___ _ _____ ___ ___ ___ ___ | |||||
| ## / __|_ _/_\ / __| |/ / __/ _ \| _ \/ __| __| | |||||
| ## \__ \ | |/ _ \ (__| ' <| _| (_) | / (__| _| | |||||
| ## |___/ |_/_/ \_\___|_|\_\_| \___/|_|_\\___|___| | |||||
| ## embedded.connectivity.solutions.============== | |||||
| ## | |||||
| ## License: Revised BSD License, see LICENSE.TXT file included in the project | |||||
| ## Authors: Johannes Bruder ( STACKFORCE ), Miguel Luis ( Semtech ) | |||||
| ## | |||||
| ## Collection of functions to generate different GDB debugging configurations | |||||
| ## | |||||
| # Get the path of this module | |||||
| set(CURRENT_MODULE_DIR ${CMAKE_CURRENT_LIST_DIR}) | |||||
| #--------------------------------------------------------------------------------------- | |||||
| # Set tools | |||||
| #--------------------------------------------------------------------------------------- | |||||
| set(GDB_BIN ${TOOLCHAIN_BIN_DIR}/${TOOLCHAIN}-gdb${TOOLCHAIN_EXT}) | |||||
| if(NOT OPENOCD_BIN) | |||||
| if(CMAKE_HOST_SYSTEM_NAME STREQUAL Linux) | |||||
| set(OPENOCD_BIN "/usr/bin/openocd" CACHE STRING "OpenOCD executable") | |||||
| elseif(CMAKE_HOST_SYSTEM_NAME STREQUAL Darwin) | |||||
| set(OPENOCD_BIN "/usr/local/bin/openocd" CACHE STRING "OpenOCD executable") | |||||
| elseif(CMAKE_HOST_SYSTEM_NAME STREQUAL Windows) | |||||
| set(OPENOCD_BIN "C:/openocd/bin/openocd.exe" CACHE STRING "OpenOCD executable") | |||||
| endif() | |||||
| endif() | |||||
| #--------------------------------------------------------------------------------------- | |||||
| # Generates a GDB run script for debugging with STLINKv1/v2/v2-1 programmer and texane stlink tool. | |||||
| # More infos check: https://github.com/texane/stlink | |||||
| #--------------------------------------------------------------------------------------- | |||||
| function(generate_run_gdb_stlink TARGET) | |||||
| get_target_property( TARGET_NAME ${TARGET} NAME ) | |||||
| configure_file(${CURRENT_MODULE_DIR}/stlink-run.gdb.in ${PROJECT_BINARY_DIR}/stlink-run.gdb @ONLY) | |||||
| endfunction() | |||||
| #--------------------------------------------------------------------------------------- | |||||
| # Generates a GDB run script for debugging with any supported programmer and openOCD. | |||||
| #--------------------------------------------------------------------------------------- | |||||
| function(generate_run_gdb_openocd TARGET) | |||||
| get_target_property( TARGET_NAME ${TARGET} NAME ) | |||||
| configure_file(${CURRENT_MODULE_DIR}/openocd-run.gdb.in ${PROJECT_BINARY_DIR}/openocd-run.gdb @ONLY) | |||||
| endfunction() | |||||
| #--------------------------------------------------------------------------------------- | |||||
| # Generates a Visual Studio Code launch configuration for debugging with openOCD. | |||||
| #--------------------------------------------------------------------------------------- | |||||
| function(generate_vscode_launch_openocd TARGET) | |||||
| get_target_property( TARGET_NAME ${TARGET} NAME ) | |||||
| # Available OpenOCD interfaces | |||||
| # Use stlink-v2-1.cfg when stlink interface is built in. Otherwise use stlink-v2.cfg | |||||
| set(OPENOCD_INTERFACE_LIST stlink-v2-1.cfg stlink-v2.cfg) | |||||
| set(OPENOCD_INTERFACE stlink-v2.cfg CACHE STRING "Default OPENOCD Interface is stlink-v2.cfg") | |||||
| set_property(CACHE OPENOCD_INTERFACE PROPERTY STRINGS ${OPENOCD_INTERFACE_LIST}) | |||||
| # Available OpenOCD targets | |||||
| set(OPENOCD_TARGET_LIST stm32l0.cfg stm32l1.cfg) | |||||
| set(OPENOCD_TARGET stm32l1.cfg CACHE STRING "Default OPENOCD Target is stm32l1.cfg") | |||||
| set_property(CACHE OPENOCD_TARGET PROPERTY STRINGS ${OPENOCD_TARGET_LIST}) | |||||
| # Available OpenOCD targets | |||||
| set(OPENOCD_BOARD_LIST atmel_saml21_xplained_pro.cfg ) | |||||
| set(OPENOCD_BOARD atmel_saml21_xplained_pro.cfg CACHE STRING "Default OPENOCD board is atmel_saml21_xplained_pro.cfg") | |||||
| set_property(CACHE OPENOCD_BOARD PROPERTY STRINGS ${OPENOCD_BOARD_LIST}) | |||||
| # Set the OPENOCD_TARGET and OPENOCD_INTERFACE variables according to BOARD | |||||
| if(BOARD STREQUAL NAMote72 OR BOARD STREQUAL NucleoL152) | |||||
| set(OPENOCD_INTERFACE stlink-v2-1.cfg) | |||||
| set(OPENOCD_TARGET stm32l1.cfg) | |||||
| elseif(BOARD STREQUAL NucleoL073 OR BOARD STREQUAL B-L072Z-LRWAN1) | |||||
| set(OPENOCD_INTERFACE stlink-v2-1.cfg) | |||||
| set(OPENOCD_TARGET stm32l0.cfg) | |||||
| elseif(BOARD STREQUAL NucleoL476) | |||||
| set(OPENOCD_INTERFACE stlink-v2-1.cfg) | |||||
| set(OPENOCD_TARGET stm32l4x.cfg) | |||||
| elseif(BOARD STREQUAL SKiM880B OR BOARD STREQUAL SKiM980A) | |||||
| set(OPENOCD_INTERFACE stlink-v2.cfg) | |||||
| set(OPENOCD_TARGET stm32l1.cfg) | |||||
| elseif(BOARD STREQUAL SKiM881AXL) | |||||
| set(OPENOCD_INTERFACE stlink-v2.cfg) | |||||
| set(OPENOCD_TARGET stm32l0.cfg) | |||||
| elseif(BOARD STREQUAL SAMR34) | |||||
| set(OPENOCD_INTERFACE cmsis-dap.cfg) | |||||
| set(OPENOCD_TARGET at91samdXX.cfg) | |||||
| endif() | |||||
| configure_file(${CURRENT_MODULE_DIR}/launch.json.in ${CMAKE_SOURCE_DIR}/.vscode/launch.json @ONLY) | |||||
| endfunction() | |||||
| ## | |||||
| ## ______ _ | |||||
| ## / _____) _ | | | |||||
| ## ( (____ _____ ____ _| |_ _____ ____| |__ | |||||
| ## \____ \| ___ | (_ _) ___ |/ ___) _ \ | |||||
| ## _____) ) ____| | | || |_| ____( (___| | | | | |||||
| ## (______/|_____)_|_|_| \__)_____)\____)_| |_| | |||||
| ## (C)2013-2017 Semtech | |||||
| ## ___ _____ _ ___ _ _____ ___ ___ ___ ___ | |||||
| ## / __|_ _/_\ / __| |/ / __/ _ \| _ \/ __| __| | |||||
| ## \__ \ | |/ _ \ (__| ' <| _| (_) | / (__| _| | |||||
| ## |___/ |_/_/ \_\___|_|\_\_| \___/|_|_\\___|___| | |||||
| ## embedded.connectivity.solutions.============== | |||||
| ## | |||||
| ## License: Revised BSD License, see LICENSE.TXT file included in the project | |||||
| ## Authors: Johannes Bruder ( STACKFORCE ), Miguel Luis ( Semtech ) | |||||
| ## | |||||
| ## Collection of functions to generate different GDB debugging configurations | |||||
| ## | |||||
| # Get the path of this module | |||||
| set(CURRENT_MODULE_DIR ${CMAKE_CURRENT_LIST_DIR}) | |||||
| #--------------------------------------------------------------------------------------- | |||||
| # Set tools | |||||
| #--------------------------------------------------------------------------------------- | |||||
| set(GDB_BIN ${TOOLCHAIN_BIN_DIR}/${TOOLCHAIN}-gdb${TOOLCHAIN_EXT}) | |||||
| if(NOT OPENOCD_BIN) | |||||
| if(CMAKE_HOST_SYSTEM_NAME STREQUAL Linux) | |||||
| set(OPENOCD_BIN "/usr/bin/openocd" CACHE STRING "OpenOCD executable") | |||||
| elseif(CMAKE_HOST_SYSTEM_NAME STREQUAL Darwin) | |||||
| set(OPENOCD_BIN "/usr/local/bin/openocd" CACHE STRING "OpenOCD executable") | |||||
| elseif(CMAKE_HOST_SYSTEM_NAME STREQUAL Windows) | |||||
| set(OPENOCD_BIN "C:/openocd/bin/openocd.exe" CACHE STRING "OpenOCD executable") | |||||
| endif() | |||||
| endif() | |||||
| #--------------------------------------------------------------------------------------- | |||||
| # Generates a GDB run script for debugging with STLINKv1/v2/v2-1 programmer and texane stlink tool. | |||||
| # More infos check: https://github.com/texane/stlink | |||||
| #--------------------------------------------------------------------------------------- | |||||
| function(generate_run_gdb_stlink TARGET) | |||||
| get_target_property( TARGET_NAME ${TARGET} NAME ) | |||||
| configure_file(${CURRENT_MODULE_DIR}/stlink-run.gdb.in ${PROJECT_BINARY_DIR}/stlink-run.gdb @ONLY) | |||||
| endfunction() | |||||
| #--------------------------------------------------------------------------------------- | |||||
| # Generates a GDB run script for debugging with any supported programmer and openOCD. | |||||
| #--------------------------------------------------------------------------------------- | |||||
| function(generate_run_gdb_openocd TARGET) | |||||
| get_target_property( TARGET_NAME ${TARGET} NAME ) | |||||
| configure_file(${CURRENT_MODULE_DIR}/openocd-run.gdb.in ${PROJECT_BINARY_DIR}/openocd-run.gdb @ONLY) | |||||
| endfunction() | |||||
| #--------------------------------------------------------------------------------------- | |||||
| # Generates a Visual Studio Code launch configuration for debugging with openOCD. | |||||
| #--------------------------------------------------------------------------------------- | |||||
| function(generate_vscode_launch_openocd TARGET) | |||||
| get_target_property( TARGET_NAME ${TARGET} NAME ) | |||||
| # Available OpenOCD interfaces | |||||
| # Use stlink-v2-1.cfg when stlink interface is built in. Otherwise use stlink-v2.cfg | |||||
| set(OPENOCD_INTERFACE_LIST stlink-v2-1.cfg stlink-v2.cfg) | |||||
| set(OPENOCD_INTERFACE stlink-v2.cfg CACHE STRING "Default OPENOCD Interface is stlink-v2.cfg") | |||||
| set_property(CACHE OPENOCD_INTERFACE PROPERTY STRINGS ${OPENOCD_INTERFACE_LIST}) | |||||
| # Available OpenOCD targets | |||||
| set(OPENOCD_TARGET_LIST stm32l0.cfg stm32l1.cfg) | |||||
| set(OPENOCD_TARGET stm32l1.cfg CACHE STRING "Default OPENOCD Target is stm32l1.cfg") | |||||
| set_property(CACHE OPENOCD_TARGET PROPERTY STRINGS ${OPENOCD_TARGET_LIST}) | |||||
| # Available OpenOCD targets | |||||
| set(OPENOCD_BOARD_LIST atmel_saml21_xplained_pro.cfg ) | |||||
| set(OPENOCD_BOARD atmel_saml21_xplained_pro.cfg CACHE STRING "Default OPENOCD board is atmel_saml21_xplained_pro.cfg") | |||||
| set_property(CACHE OPENOCD_BOARD PROPERTY STRINGS ${OPENOCD_BOARD_LIST}) | |||||
| # Set the OPENOCD_TARGET and OPENOCD_INTERFACE variables according to BOARD | |||||
| if(BOARD STREQUAL NAMote72 OR BOARD STREQUAL NucleoL152) | |||||
| set(OPENOCD_INTERFACE stlink-v2-1.cfg) | |||||
| set(OPENOCD_TARGET stm32l1.cfg) | |||||
| elseif(BOARD STREQUAL NucleoL073 OR BOARD STREQUAL B-L072Z-LRWAN1) | |||||
| set(OPENOCD_INTERFACE stlink-v2-1.cfg) | |||||
| set(OPENOCD_TARGET stm32l0.cfg) | |||||
| elseif(BOARD STREQUAL NucleoL476) | |||||
| set(OPENOCD_INTERFACE stlink-v2-1.cfg) | |||||
| set(OPENOCD_TARGET stm32l4x.cfg) | |||||
| elseif(BOARD STREQUAL SKiM880B OR BOARD STREQUAL SKiM980A) | |||||
| set(OPENOCD_INTERFACE stlink-v2.cfg) | |||||
| set(OPENOCD_TARGET stm32l1.cfg) | |||||
| elseif(BOARD STREQUAL SKiM881AXL) | |||||
| set(OPENOCD_INTERFACE stlink-v2.cfg) | |||||
| set(OPENOCD_TARGET stm32l0.cfg) | |||||
| elseif(BOARD STREQUAL SAMR34) | |||||
| set(OPENOCD_INTERFACE cmsis-dap.cfg) | |||||
| set(OPENOCD_TARGET at91samdXX.cfg) | |||||
| endif() | |||||
| configure_file(${CURRENT_MODULE_DIR}/launch.json.in ${CMAKE_SOURCE_DIR}/.vscode/launch.json @ONLY) | |||||
| endfunction() | |||||
| @@ -1,40 +1,40 @@ | |||||
| { | |||||
| "version": "0.2.0", | |||||
| "configurations": [ | |||||
| { | |||||
| "name": "Debug-@TARGET_NAME@", | |||||
| "type": "cppdbg", | |||||
| "request": "launch", | |||||
| "program": "${workspaceRoot}/build/src/apps/@APPLICATION@/@TARGET_NAME@", | |||||
| "args": [], | |||||
| "stopAtEntry": true, | |||||
| "cwd": "${workspaceRoot}", | |||||
| "environment": [], | |||||
| "externalConsole": false, | |||||
| "debugServerArgs": "-f interface/@OPENOCD_INTERFACE@ -f target/@OPENOCD_TARGET@", | |||||
| "serverLaunchTimeout": 20000, | |||||
| "filterStderr": true, | |||||
| "filterStdout": false, | |||||
| "serverStarted": "Info\\ :\\ [\\w\\d\\.]*:\\ hardware", | |||||
| "setupCommands": [ | |||||
| { "text": "cd ${workspaceRoot}/build" }, | |||||
| { "text": "file src/apps/@APPLICATION@/@TARGET_NAME@", "description": "load file", "ignoreFailures": false}, | |||||
| { "text": "target extended-remote localhost:3333", "description": "connect to target", "ignoreFailures": false }, | |||||
| { "text": "monitor reset halt", "description": "perform a reset and halt the target", "ignoreFailures": false }, | |||||
| { "text": "load", "description": "flash target", "ignoreFailures": false }, | |||||
| { "text": "monitor reset init", "description": "perform a reset and init the target", "ignoreFailures": false }, | |||||
| { "text": "set output-radix 16", "description": "set the default numeric base to 16", "ignoreFailures": false } | |||||
| ], | |||||
| "logging": { | |||||
| "moduleLoad": true, | |||||
| "trace": true, | |||||
| "engineLogging": true, | |||||
| "programOutput": true, | |||||
| "exceptions": true | |||||
| }, | |||||
| "MIMode": "gdb", | |||||
| "miDebuggerPath": "@GDB_BIN@", | |||||
| "debugServerPath": "@OPENOCD_BIN@" | |||||
| } | |||||
| ] | |||||
| } | |||||
| { | |||||
| "version": "0.2.0", | |||||
| "configurations": [ | |||||
| { | |||||
| "name": "Debug-@TARGET_NAME@", | |||||
| "type": "cppdbg", | |||||
| "request": "launch", | |||||
| "program": "${workspaceRoot}/build/src/apps/@APPLICATION@/@TARGET_NAME@", | |||||
| "args": [], | |||||
| "stopAtEntry": true, | |||||
| "cwd": "${workspaceRoot}", | |||||
| "environment": [], | |||||
| "externalConsole": false, | |||||
| "debugServerArgs": "-f interface/@OPENOCD_INTERFACE@ -f target/@OPENOCD_TARGET@", | |||||
| "serverLaunchTimeout": 20000, | |||||
| "filterStderr": true, | |||||
| "filterStdout": false, | |||||
| "serverStarted": "Info\\ :\\ [\\w\\d\\.]*:\\ hardware", | |||||
| "setupCommands": [ | |||||
| { "text": "cd ${workspaceRoot}/build" }, | |||||
| { "text": "file src/apps/@APPLICATION@/@TARGET_NAME@", "description": "load file", "ignoreFailures": false}, | |||||
| { "text": "target extended-remote localhost:3333", "description": "connect to target", "ignoreFailures": false }, | |||||
| { "text": "monitor reset halt", "description": "perform a reset and halt the target", "ignoreFailures": false }, | |||||
| { "text": "load", "description": "flash target", "ignoreFailures": false }, | |||||
| { "text": "monitor reset init", "description": "perform a reset and init the target", "ignoreFailures": false }, | |||||
| { "text": "set output-radix 16", "description": "set the default numeric base to 16", "ignoreFailures": false } | |||||
| ], | |||||
| "logging": { | |||||
| "moduleLoad": true, | |||||
| "trace": true, | |||||
| "engineLogging": true, | |||||
| "programOutput": true, | |||||
| "exceptions": true | |||||
| }, | |||||
| "MIMode": "gdb", | |||||
| "miDebuggerPath": "@GDB_BIN@", | |||||
| "debugServerPath": "@OPENOCD_BIN@" | |||||
| } | |||||
| ] | |||||
| } | |||||
| @@ -1,5 +1,5 @@ | |||||
| file @TARGET_NAME@ | |||||
| target extended-remote localhost:3333 | |||||
| monitor reset halt | |||||
| load | |||||
| thbreak main | |||||
| file @TARGET_NAME@ | |||||
| target extended-remote localhost:3333 | |||||
| monitor reset halt | |||||
| load | |||||
| thbreak main | |||||
| @@ -1,41 +1,41 @@ | |||||
| ## | |||||
| ## ______ _ | |||||
| ## / _____) _ | | | |||||
| ## ( (____ _____ ____ _| |_ _____ ____| |__ | |||||
| ## \____ \| ___ | (_ _) ___ |/ ___) _ \ | |||||
| ## _____) ) ____| | | || |_| ____( (___| | | | | |||||
| ## (______/|_____)_|_|_| \__)_____)\____)_| |_| | |||||
| ## (C)2013-2017 Semtech | |||||
| ## ___ _____ _ ___ _ _____ ___ ___ ___ ___ | |||||
| ## / __|_ _/_\ / __| |/ / __/ _ \| _ \/ __| __| | |||||
| ## \__ \ | |/ _ \ (__| ' <| _| (_) | / (__| _| | |||||
| ## |___/ |_/_/ \_\___|_|\_\_| \___/|_|_\\___|___| | |||||
| ## embedded.connectivity.solutions.============== | |||||
| ## | |||||
| ## License: Revised BSD License, see LICENSE.TXT file included in the project | |||||
| ## Authors: Johannes Bruder ( STACKFORCE ), Miguel Luis ( Semtech ), | |||||
| ## Marten Lootsma(TWTG) on behalf of Microchip/Atmel (c)2017 | |||||
| ## | |||||
| ## | |||||
| ## SAMR34 target specific CMake file | |||||
| ## | |||||
| if(NOT DEFINED LINKER_SCRIPT) | |||||
| message(FATAL_ERROR "No linker script defined") | |||||
| endif(NOT DEFINED LINKER_SCRIPT) | |||||
| message("Linker script: ${LINKER_SCRIPT}") | |||||
| #--------------------------------------------------------------------------------------- | |||||
| # Set compiler/linker flags | |||||
| #--------------------------------------------------------------------------------------- | |||||
| # Object build options | |||||
| set(OBJECT_GEN_FLAGS "-Og -g -mthumb -g2 -fno-builtin -mcpu=cortex-m0plus -Wall -ffunction-sections -fdata-sections -fomit-frame-pointer -mabi=aapcs -fno-unroll-loops -ffast-math -ftree-vectorize -mlong-calls") | |||||
| set(CMAKE_C_FLAGS "${OBJECT_GEN_FLAGS} -std=gnu99 " CACHE INTERNAL "C Compiler options") | |||||
| set(CMAKE_CXX_FLAGS "${OBJECT_GEN_FLAGS} -std=c++11 " CACHE INTERNAL "C++ Compiler options") | |||||
| set(CMAKE_ASM_FLAGS "${OBJECT_GEN_FLAGS} -x assembler-with-cpp " CACHE INTERNAL "ASM Compiler options") | |||||
| # Linker flags | |||||
| set(CMAKE_EXE_LINKER_FLAGS "-Wl,--gc-sections --specs=nano.specs --specs=nosys.specs -mthumb -g2 -mcpu=cortex-m0plus -mabi=aapcs -T${LINKER_SCRIPT} -Wl,-Map=${CMAKE_PROJECT_NAME}.map" CACHE INTERNAL "Linker options") | |||||
| ## | |||||
| ## ______ _ | |||||
| ## / _____) _ | | | |||||
| ## ( (____ _____ ____ _| |_ _____ ____| |__ | |||||
| ## \____ \| ___ | (_ _) ___ |/ ___) _ \ | |||||
| ## _____) ) ____| | | || |_| ____( (___| | | | | |||||
| ## (______/|_____)_|_|_| \__)_____)\____)_| |_| | |||||
| ## (C)2013-2017 Semtech | |||||
| ## ___ _____ _ ___ _ _____ ___ ___ ___ ___ | |||||
| ## / __|_ _/_\ / __| |/ / __/ _ \| _ \/ __| __| | |||||
| ## \__ \ | |/ _ \ (__| ' <| _| (_) | / (__| _| | |||||
| ## |___/ |_/_/ \_\___|_|\_\_| \___/|_|_\\___|___| | |||||
| ## embedded.connectivity.solutions.============== | |||||
| ## | |||||
| ## License: Revised BSD License, see LICENSE.TXT file included in the project | |||||
| ## Authors: Johannes Bruder ( STACKFORCE ), Miguel Luis ( Semtech ), | |||||
| ## Marten Lootsma(TWTG) on behalf of Microchip/Atmel (c)2017 | |||||
| ## | |||||
| ## | |||||
| ## SAMR34 target specific CMake file | |||||
| ## | |||||
| if(NOT DEFINED LINKER_SCRIPT) | |||||
| message(FATAL_ERROR "No linker script defined") | |||||
| endif(NOT DEFINED LINKER_SCRIPT) | |||||
| message("Linker script: ${LINKER_SCRIPT}") | |||||
| #--------------------------------------------------------------------------------------- | |||||
| # Set compiler/linker flags | |||||
| #--------------------------------------------------------------------------------------- | |||||
| # Object build options | |||||
| set(OBJECT_GEN_FLAGS "-Og -g -mthumb -g2 -fno-builtin -mcpu=cortex-m0plus -Wall -ffunction-sections -fdata-sections -fomit-frame-pointer -mabi=aapcs -fno-unroll-loops -ffast-math -ftree-vectorize -mlong-calls") | |||||
| set(CMAKE_C_FLAGS "${OBJECT_GEN_FLAGS} -std=gnu99 " CACHE INTERNAL "C Compiler options") | |||||
| set(CMAKE_CXX_FLAGS "${OBJECT_GEN_FLAGS} -std=c++11 " CACHE INTERNAL "C++ Compiler options") | |||||
| set(CMAKE_ASM_FLAGS "${OBJECT_GEN_FLAGS} -x assembler-with-cpp " CACHE INTERNAL "ASM Compiler options") | |||||
| # Linker flags | |||||
| set(CMAKE_EXE_LINKER_FLAGS "-Wl,--gc-sections --specs=nano.specs --specs=nosys.specs -mthumb -g2 -mcpu=cortex-m0plus -mabi=aapcs -T${LINKER_SCRIPT} -Wl,-Map=${CMAKE_PROJECT_NAME}.map" CACHE INTERNAL "Linker options") | |||||
| @@ -1,6 +1,6 @@ | |||||
| file @TARGET_NAME@ | |||||
| target extended localhost:4242 | |||||
| monitor reset halt | |||||
| shell sleep 1 | |||||
| load | |||||
| thbreak main | |||||
| file @TARGET_NAME@ | |||||
| target extended localhost:4242 | |||||
| monitor reset halt | |||||
| shell sleep 1 | |||||
| load | |||||
| thbreak main | |||||
| @@ -1,40 +1,40 @@ | |||||
| ## | |||||
| ## ______ _ | |||||
| ## / _____) _ | | | |||||
| ## ( (____ _____ ____ _| |_ _____ ____| |__ | |||||
| ## \____ \| ___ | (_ _) ___ |/ ___) _ \ | |||||
| ## _____) ) ____| | | || |_| ____( (___| | | | | |||||
| ## (______/|_____)_|_|_| \__)_____)\____)_| |_| | |||||
| ## (C)2013-2017 Semtech | |||||
| ## ___ _____ _ ___ _ _____ ___ ___ ___ ___ | |||||
| ## / __|_ _/_\ / __| |/ / __/ _ \| _ \/ __| __| | |||||
| ## \__ \ | |/ _ \ (__| ' <| _| (_) | / (__| _| | |||||
| ## |___/ |_/_/ \_\___|_|\_\_| \___/|_|_\\___|___| | |||||
| ## embedded.connectivity.solutions.============== | |||||
| ## | |||||
| ## License: Revised BSD License, see LICENSE.TXT file included in the project | |||||
| ## Authors: Johannes Bruder ( STACKFORCE ), Miguel Luis ( Semtech ) | |||||
| ## | |||||
| ## | |||||
| ## STM32L0 target specific CMake file | |||||
| ## | |||||
| if(NOT DEFINED LINKER_SCRIPT) | |||||
| message(FATAL_ERROR "No linker script defined") | |||||
| endif(NOT DEFINED LINKER_SCRIPT) | |||||
| message("Linker script: ${LINKER_SCRIPT}") | |||||
| #--------------------------------------------------------------------------------------- | |||||
| # Set compiler/linker flags | |||||
| #--------------------------------------------------------------------------------------- | |||||
| # Object build options | |||||
| set(OBJECT_GEN_FLAGS "-Og -g -mthumb -g2 -fno-builtin -mcpu=cortex-m0plus -Wall -Wextra -pedantic -Wno-unused-parameter -ffunction-sections -fdata-sections -fomit-frame-pointer -mabi=aapcs -fno-unroll-loops -ffast-math -ftree-vectorize") | |||||
| set(CMAKE_C_FLAGS "${OBJECT_GEN_FLAGS} -std=gnu99 " CACHE INTERNAL "C Compiler options") | |||||
| set(CMAKE_CXX_FLAGS "${OBJECT_GEN_FLAGS} -std=c++11 " CACHE INTERNAL "C++ Compiler options") | |||||
| set(CMAKE_ASM_FLAGS "${OBJECT_GEN_FLAGS} -x assembler-with-cpp " CACHE INTERNAL "ASM Compiler options") | |||||
| # Linker flags | |||||
| set(CMAKE_EXE_LINKER_FLAGS "-Wl,--gc-sections --specs=nano.specs --specs=nosys.specs -mthumb -g2 -mcpu=cortex-m0plus -mabi=aapcs -T${LINKER_SCRIPT} -Wl,-Map=${CMAKE_PROJECT_NAME}.map" CACHE INTERNAL "Linker options") | |||||
| ## | |||||
| ## ______ _ | |||||
| ## / _____) _ | | | |||||
| ## ( (____ _____ ____ _| |_ _____ ____| |__ | |||||
| ## \____ \| ___ | (_ _) ___ |/ ___) _ \ | |||||
| ## _____) ) ____| | | || |_| ____( (___| | | | | |||||
| ## (______/|_____)_|_|_| \__)_____)\____)_| |_| | |||||
| ## (C)2013-2017 Semtech | |||||
| ## ___ _____ _ ___ _ _____ ___ ___ ___ ___ | |||||
| ## / __|_ _/_\ / __| |/ / __/ _ \| _ \/ __| __| | |||||
| ## \__ \ | |/ _ \ (__| ' <| _| (_) | / (__| _| | |||||
| ## |___/ |_/_/ \_\___|_|\_\_| \___/|_|_\\___|___| | |||||
| ## embedded.connectivity.solutions.============== | |||||
| ## | |||||
| ## License: Revised BSD License, see LICENSE.TXT file included in the project | |||||
| ## Authors: Johannes Bruder ( STACKFORCE ), Miguel Luis ( Semtech ) | |||||
| ## | |||||
| ## | |||||
| ## STM32L0 target specific CMake file | |||||
| ## | |||||
| if(NOT DEFINED LINKER_SCRIPT) | |||||
| message(FATAL_ERROR "No linker script defined") | |||||
| endif(NOT DEFINED LINKER_SCRIPT) | |||||
| message("Linker script: ${LINKER_SCRIPT}") | |||||
| #--------------------------------------------------------------------------------------- | |||||
| # Set compiler/linker flags | |||||
| #--------------------------------------------------------------------------------------- | |||||
| # Object build options | |||||
| set(OBJECT_GEN_FLAGS "-Og -g -mthumb -g2 -fno-builtin -mcpu=cortex-m0plus -Wall -Wextra -pedantic -Wno-unused-parameter -ffunction-sections -fdata-sections -fomit-frame-pointer -mabi=aapcs -fno-unroll-loops -ffast-math -ftree-vectorize") | |||||
| set(CMAKE_C_FLAGS "${OBJECT_GEN_FLAGS} -std=gnu99 " CACHE INTERNAL "C Compiler options") | |||||
| set(CMAKE_CXX_FLAGS "${OBJECT_GEN_FLAGS} -std=c++11 " CACHE INTERNAL "C++ Compiler options") | |||||
| set(CMAKE_ASM_FLAGS "${OBJECT_GEN_FLAGS} -x assembler-with-cpp " CACHE INTERNAL "ASM Compiler options") | |||||
| # Linker flags | |||||
| set(CMAKE_EXE_LINKER_FLAGS "-Wl,--gc-sections --specs=nano.specs --specs=nosys.specs -mthumb -g2 -mcpu=cortex-m0plus -mabi=aapcs -T${LINKER_SCRIPT} -Wl,-Map=${CMAKE_PROJECT_NAME}.map" CACHE INTERNAL "Linker options") | |||||
| @@ -1,40 +1,40 @@ | |||||
| ## | |||||
| ## ______ _ | |||||
| ## / _____) _ | | | |||||
| ## ( (____ _____ ____ _| |_ _____ ____| |__ | |||||
| ## \____ \| ___ | (_ _) ___ |/ ___) _ \ | |||||
| ## _____) ) ____| | | || |_| ____( (___| | | | | |||||
| ## (______/|_____)_|_|_| \__)_____)\____)_| |_| | |||||
| ## (C)2013-2017 Semtech | |||||
| ## ___ _____ _ ___ _ _____ ___ ___ ___ ___ | |||||
| ## / __|_ _/_\ / __| |/ / __/ _ \| _ \/ __| __| | |||||
| ## \__ \ | |/ _ \ (__| ' <| _| (_) | / (__| _| | |||||
| ## |___/ |_/_/ \_\___|_|\_\_| \___/|_|_\\___|___| | |||||
| ## embedded.connectivity.solutions.============== | |||||
| ## | |||||
| ## License: Revised BSD License, see LICENSE.TXT file included in the project | |||||
| ## Authors: Johannes Bruder ( STACKFORCE ), Miguel Luis ( Semtech ) | |||||
| ## | |||||
| ## | |||||
| ## STM32L1 target specific CMake file | |||||
| ## | |||||
| if(NOT DEFINED LINKER_SCRIPT) | |||||
| message(FATAL_ERROR "No linker script defined") | |||||
| endif(NOT DEFINED LINKER_SCRIPT) | |||||
| message("Linker script: ${LINKER_SCRIPT}") | |||||
| #--------------------------------------------------------------------------------------- | |||||
| # Set compiler/linker flags | |||||
| #--------------------------------------------------------------------------------------- | |||||
| # Object build options | |||||
| set(OBJECT_GEN_FLAGS "-Og -g -mthumb -g2 -fno-builtin -mcpu=cortex-m3 -Wall -Wextra -pedantic -Wno-unused-parameter -ffunction-sections -fdata-sections -fomit-frame-pointer -mabi=aapcs -fno-unroll-loops -ffast-math -ftree-vectorize") | |||||
| set(CMAKE_C_FLAGS "${OBJECT_GEN_FLAGS} -std=gnu99 " CACHE INTERNAL "C Compiler options") | |||||
| set(CMAKE_CXX_FLAGS "${OBJECT_GEN_FLAGS} -std=c++11 " CACHE INTERNAL "C++ Compiler options") | |||||
| set(CMAKE_ASM_FLAGS "${OBJECT_GEN_FLAGS} -x assembler-with-cpp " CACHE INTERNAL "ASM Compiler options") | |||||
| # Linker flags | |||||
| set(CMAKE_EXE_LINKER_FLAGS "-Wl,--gc-sections --specs=nano.specs --specs=nosys.specs -mthumb -g2 -mcpu=cortex-m3 -mabi=aapcs -T${LINKER_SCRIPT} -Wl,-Map=${CMAKE_PROJECT_NAME}.map" CACHE INTERNAL "Linker options") | |||||
| ## | |||||
| ## ______ _ | |||||
| ## / _____) _ | | | |||||
| ## ( (____ _____ ____ _| |_ _____ ____| |__ | |||||
| ## \____ \| ___ | (_ _) ___ |/ ___) _ \ | |||||
| ## _____) ) ____| | | || |_| ____( (___| | | | | |||||
| ## (______/|_____)_|_|_| \__)_____)\____)_| |_| | |||||
| ## (C)2013-2017 Semtech | |||||
| ## ___ _____ _ ___ _ _____ ___ ___ ___ ___ | |||||
| ## / __|_ _/_\ / __| |/ / __/ _ \| _ \/ __| __| | |||||
| ## \__ \ | |/ _ \ (__| ' <| _| (_) | / (__| _| | |||||
| ## |___/ |_/_/ \_\___|_|\_\_| \___/|_|_\\___|___| | |||||
| ## embedded.connectivity.solutions.============== | |||||
| ## | |||||
| ## License: Revised BSD License, see LICENSE.TXT file included in the project | |||||
| ## Authors: Johannes Bruder ( STACKFORCE ), Miguel Luis ( Semtech ) | |||||
| ## | |||||
| ## | |||||
| ## STM32L1 target specific CMake file | |||||
| ## | |||||
| if(NOT DEFINED LINKER_SCRIPT) | |||||
| message(FATAL_ERROR "No linker script defined") | |||||
| endif(NOT DEFINED LINKER_SCRIPT) | |||||
| message("Linker script: ${LINKER_SCRIPT}") | |||||
| #--------------------------------------------------------------------------------------- | |||||
| # Set compiler/linker flags | |||||
| #--------------------------------------------------------------------------------------- | |||||
| # Object build options | |||||
| set(OBJECT_GEN_FLAGS "-Og -g -mthumb -g2 -fno-builtin -mcpu=cortex-m3 -Wall -Wextra -pedantic -Wno-unused-parameter -ffunction-sections -fdata-sections -fomit-frame-pointer -mabi=aapcs -fno-unroll-loops -ffast-math -ftree-vectorize") | |||||
| set(CMAKE_C_FLAGS "${OBJECT_GEN_FLAGS} -std=gnu99 " CACHE INTERNAL "C Compiler options") | |||||
| set(CMAKE_CXX_FLAGS "${OBJECT_GEN_FLAGS} -std=c++11 " CACHE INTERNAL "C++ Compiler options") | |||||
| set(CMAKE_ASM_FLAGS "${OBJECT_GEN_FLAGS} -x assembler-with-cpp " CACHE INTERNAL "ASM Compiler options") | |||||
| # Linker flags | |||||
| set(CMAKE_EXE_LINKER_FLAGS "-Wl,--gc-sections --specs=nano.specs --specs=nosys.specs -mthumb -g2 -mcpu=cortex-m3 -mabi=aapcs -T${LINKER_SCRIPT} -Wl,-Map=${CMAKE_PROJECT_NAME}.map" CACHE INTERNAL "Linker options") | |||||
| @@ -1,40 +1,40 @@ | |||||
| ## | |||||
| ## ______ _ | |||||
| ## / _____) _ | | | |||||
| ## ( (____ _____ ____ _| |_ _____ ____| |__ | |||||
| ## \____ \| ___ | (_ _) ___ |/ ___) _ \ | |||||
| ## _____) ) ____| | | || |_| ____( (___| | | | | |||||
| ## (______/|_____)_|_|_| \__)_____)\____)_| |_| | |||||
| ## (C)2013-2018 Semtech | |||||
| ## ___ _____ _ ___ _ _____ ___ ___ ___ ___ | |||||
| ## / __|_ _/_\ / __| |/ / __/ _ \| _ \/ __| __| | |||||
| ## \__ \ | |/ _ \ (__| ' <| _| (_) | / (__| _| | |||||
| ## |___/ |_/_/ \_\___|_|\_\_| \___/|_|_\\___|___| | |||||
| ## embedded.connectivity.solutions.============== | |||||
| ## | |||||
| ## License: Revised BSD License, see LICENSE.TXT file included in the project | |||||
| ## Authors: Johannes Bruder ( STACKFORCE ), Miguel Luis ( Semtech ) | |||||
| ## | |||||
| ## | |||||
| ## STM32L4 target specific CMake file | |||||
| ## | |||||
| if(NOT DEFINED LINKER_SCRIPT) | |||||
| message(FATAL_ERROR "No linker script defined") | |||||
| endif(NOT DEFINED LINKER_SCRIPT) | |||||
| message("Linker script: ${LINKER_SCRIPT}") | |||||
| #--------------------------------------------------------------------------------------- | |||||
| # Set compiler/linker flags | |||||
| #--------------------------------------------------------------------------------------- | |||||
| # Object build options | |||||
| set(OBJECT_GEN_FLAGS "-Og -g -mthumb -g2 -fno-builtin -mcpu=cortex-m4 -mfpu=fpv4-sp-d16 -mfloat-abi=softfp -Wall -Wextra -pedantic -Wno-unused-parameter -ffunction-sections -fdata-sections -fomit-frame-pointer -mabi=aapcs -fno-unroll-loops -ffast-math -ftree-vectorize") | |||||
| set(CMAKE_C_FLAGS "${OBJECT_GEN_FLAGS} -std=gnu99 " CACHE INTERNAL "C Compiler options") | |||||
| set(CMAKE_CXX_FLAGS "${OBJECT_GEN_FLAGS} -std=c++11 " CACHE INTERNAL "C++ Compiler options") | |||||
| set(CMAKE_ASM_FLAGS "${OBJECT_GEN_FLAGS} -x assembler-with-cpp " CACHE INTERNAL "ASM Compiler options") | |||||
| # Linker flags | |||||
| set(CMAKE_EXE_LINKER_FLAGS "-Wl,--gc-sections --specs=nano.specs --specs=nosys.specs -mthumb -g2 -mcpu=cortex-m4 -mfpu=fpv4-sp-d16 -mfloat-abi=softfp -mabi=aapcs -T${LINKER_SCRIPT} -Wl,-Map=${CMAKE_PROJECT_NAME}.map" CACHE INTERNAL "Linker options") | |||||
| ## | |||||
| ## ______ _ | |||||
| ## / _____) _ | | | |||||
| ## ( (____ _____ ____ _| |_ _____ ____| |__ | |||||
| ## \____ \| ___ | (_ _) ___ |/ ___) _ \ | |||||
| ## _____) ) ____| | | || |_| ____( (___| | | | | |||||
| ## (______/|_____)_|_|_| \__)_____)\____)_| |_| | |||||
| ## (C)2013-2018 Semtech | |||||
| ## ___ _____ _ ___ _ _____ ___ ___ ___ ___ | |||||
| ## / __|_ _/_\ / __| |/ / __/ _ \| _ \/ __| __| | |||||
| ## \__ \ | |/ _ \ (__| ' <| _| (_) | / (__| _| | |||||
| ## |___/ |_/_/ \_\___|_|\_\_| \___/|_|_\\___|___| | |||||
| ## embedded.connectivity.solutions.============== | |||||
| ## | |||||
| ## License: Revised BSD License, see LICENSE.TXT file included in the project | |||||
| ## Authors: Johannes Bruder ( STACKFORCE ), Miguel Luis ( Semtech ) | |||||
| ## | |||||
| ## | |||||
| ## STM32L4 target specific CMake file | |||||
| ## | |||||
| if(NOT DEFINED LINKER_SCRIPT) | |||||
| message(FATAL_ERROR "No linker script defined") | |||||
| endif(NOT DEFINED LINKER_SCRIPT) | |||||
| message("Linker script: ${LINKER_SCRIPT}") | |||||
| #--------------------------------------------------------------------------------------- | |||||
| # Set compiler/linker flags | |||||
| #--------------------------------------------------------------------------------------- | |||||
| # Object build options | |||||
| set(OBJECT_GEN_FLAGS "-Og -g -mthumb -g2 -fno-builtin -mcpu=cortex-m4 -mfpu=fpv4-sp-d16 -mfloat-abi=softfp -Wall -Wextra -pedantic -Wno-unused-parameter -ffunction-sections -fdata-sections -fomit-frame-pointer -mabi=aapcs -fno-unroll-loops -ffast-math -ftree-vectorize") | |||||
| set(CMAKE_C_FLAGS "${OBJECT_GEN_FLAGS} -std=gnu99 " CACHE INTERNAL "C Compiler options") | |||||
| set(CMAKE_CXX_FLAGS "${OBJECT_GEN_FLAGS} -std=c++11 " CACHE INTERNAL "C++ Compiler options") | |||||
| set(CMAKE_ASM_FLAGS "${OBJECT_GEN_FLAGS} -x assembler-with-cpp " CACHE INTERNAL "ASM Compiler options") | |||||
| # Linker flags | |||||
| set(CMAKE_EXE_LINKER_FLAGS "-Wl,--gc-sections --specs=nano.specs --specs=nosys.specs -mthumb -g2 -mcpu=cortex-m4 -mfpu=fpv4-sp-d16 -mfloat-abi=softfp -mabi=aapcs -T${LINKER_SCRIPT} -Wl,-Map=${CMAKE_PROJECT_NAME}.map" CACHE INTERNAL "Linker options") | |||||
| @@ -1,90 +1,90 @@ | |||||
| ## | |||||
| ## ______ _ | |||||
| ## / _____) _ | | | |||||
| ## ( (____ _____ ____ _| |_ _____ ____| |__ | |||||
| ## \____ \| ___ | (_ _) ___ |/ ___) _ \ | |||||
| ## _____) ) ____| | | || |_| ____( (___| | | | | |||||
| ## (______/|_____)_|_|_| \__)_____)\____)_| |_| | |||||
| ## (C)2013-2017 Semtech | |||||
| ## ___ _____ _ ___ _ _____ ___ ___ ___ ___ | |||||
| ## / __|_ _/_\ / __| |/ / __/ _ \| _ \/ __| __| | |||||
| ## \__ \ | |/ _ \ (__| ' <| _| (_) | / (__| _| | |||||
| ## |___/ |_/_/ \_\___|_|\_\_| \___/|_|_\\___|___| | |||||
| ## embedded.connectivity.solutions.============== | |||||
| ## | |||||
| ## License: Revised BSD License, see LICENSE.TXT file included in the project | |||||
| ## Authors: Johannes Bruder ( STACKFORCE ), Miguel Luis ( Semtech ) | |||||
| ## | |||||
| ## | |||||
| ## CMake arm-none-eabi toolchain file | |||||
| ## | |||||
| # Append current directory to CMAKE_MODULE_PATH for making device specific cmake modules visible | |||||
| list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}) | |||||
| # Target definition | |||||
| set(CMAKE_SYSTEM_NAME Generic) | |||||
| set(CMAKE_SYSTEM_PROCESSOR ARM) | |||||
| #--------------------------------------------------------------------------------------- | |||||
| # Set toolchain paths | |||||
| #--------------------------------------------------------------------------------------- | |||||
| set(TOOLCHAIN arm-none-eabi) | |||||
| if(NOT DEFINED TOOLCHAIN_PREFIX) | |||||
| if(CMAKE_HOST_SYSTEM_NAME STREQUAL Linux) | |||||
| set(TOOLCHAIN_PREFIX "/usr") | |||||
| elseif(CMAKE_HOST_SYSTEM_NAME STREQUAL Darwin) | |||||
| set(TOOLCHAIN_PREFIX "/usr/local") | |||||
| elseif(CMAKE_HOST_SYSTEM_NAME STREQUAL Windows) | |||||
| message(STATUS "Please specify the TOOLCHAIN_PREFIX !\n For example: -DTOOLCHAIN_PREFIX=\"C:/Program Files/GNU Tools ARM Embedded\" ") | |||||
| else() | |||||
| set(TOOLCHAIN_PREFIX "/usr") | |||||
| message(STATUS "No TOOLCHAIN_PREFIX specified, using default: " ${TOOLCHAIN_PREFIX}) | |||||
| endif() | |||||
| endif() | |||||
| set(TOOLCHAIN_BIN_DIR ${TOOLCHAIN_PREFIX}/bin) | |||||
| set(TOOLCHAIN_INC_DIR ${TOOLCHAIN_PREFIX}/${TOOLCHAIN}/include) | |||||
| set(TOOLCHAIN_LIB_DIR ${TOOLCHAIN_PREFIX}/${TOOLCHAIN}/lib) | |||||
| # Set system depended extensions | |||||
| if(WIN32) | |||||
| set(TOOLCHAIN_EXT ".exe" ) | |||||
| else() | |||||
| set(TOOLCHAIN_EXT "" ) | |||||
| endif() | |||||
| # Perform compiler test with static library | |||||
| set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY) | |||||
| #--------------------------------------------------------------------------------------- | |||||
| # Preset some general GCC Options | |||||
| #--------------------------------------------------------------------------------------- | |||||
| # Options for DEBUG build | |||||
| # -Og enables optimizations that do not interfere with debugging | |||||
| # -g produce debugging information in the operating system’s native format | |||||
| set(CMAKE_C_FLAGS_DEBUG "-Og -g -DDEBUG" CACHE INTERNAL "C Compiler options for debug build type") | |||||
| set(CMAKE_CXX_FLAGS_DEBUG "-Og -g -DDEBUG" CACHE INTERNAL "C++ Compiler options for debug build type") | |||||
| set(CMAKE_ASM_FLAGS_DEBUG "-g" CACHE INTERNAL "ASM Compiler options for debug build type") | |||||
| set(CMAKE_EXE_LINKER_FLAGS_DEBUG "" CACHE INTERNAL "Linker options for debug build type") | |||||
| # Options for RELEASE build | |||||
| # -Os Optimize for size. -Os enables all -O2 optimizations | |||||
| set(CMAKE_C_FLAGS_RELEASE "-Os" CACHE INTERNAL "C Compiler options for release build type") | |||||
| set(CMAKE_CXX_FLAGS_RELEASE "-Os" CACHE INTERNAL "C++ Compiler options for release build type") | |||||
| set(CMAKE_ASM_FLAGS_RELEASE "" CACHE INTERNAL "ASM Compiler options for release build type") | |||||
| set(CMAKE_EXE_LINKER_FLAGS_RELEASE "" CACHE INTERNAL "Linker options for release build type") | |||||
| #--------------------------------------------------------------------------------------- | |||||
| # Set compilers | |||||
| #--------------------------------------------------------------------------------------- | |||||
| set(CMAKE_C_COMPILER ${TOOLCHAIN_BIN_DIR}/${TOOLCHAIN}-gcc${TOOLCHAIN_EXT} CACHE INTERNAL "C Compiler") | |||||
| set(CMAKE_CXX_COMPILER ${TOOLCHAIN_BIN_DIR}/${TOOLCHAIN}-g++${TOOLCHAIN_EXT} CACHE INTERNAL "C++ Compiler") | |||||
| set(CMAKE_ASM_COMPILER ${TOOLCHAIN_BIN_DIR}/${TOOLCHAIN}-gcc${TOOLCHAIN_EXT} CACHE INTERNAL "ASM Compiler") | |||||
| set(CMAKE_FIND_ROOT_PATH ${TOOLCHAIN_PREFIX}/${${TOOLCHAIN}} ${CMAKE_PREFIX_PATH}) | |||||
| set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) | |||||
| set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) | |||||
| set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) | |||||
| set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY) | |||||
| ## | |||||
| ## ______ _ | |||||
| ## / _____) _ | | | |||||
| ## ( (____ _____ ____ _| |_ _____ ____| |__ | |||||
| ## \____ \| ___ | (_ _) ___ |/ ___) _ \ | |||||
| ## _____) ) ____| | | || |_| ____( (___| | | | | |||||
| ## (______/|_____)_|_|_| \__)_____)\____)_| |_| | |||||
| ## (C)2013-2017 Semtech | |||||
| ## ___ _____ _ ___ _ _____ ___ ___ ___ ___ | |||||
| ## / __|_ _/_\ / __| |/ / __/ _ \| _ \/ __| __| | |||||
| ## \__ \ | |/ _ \ (__| ' <| _| (_) | / (__| _| | |||||
| ## |___/ |_/_/ \_\___|_|\_\_| \___/|_|_\\___|___| | |||||
| ## embedded.connectivity.solutions.============== | |||||
| ## | |||||
| ## License: Revised BSD License, see LICENSE.TXT file included in the project | |||||
| ## Authors: Johannes Bruder ( STACKFORCE ), Miguel Luis ( Semtech ) | |||||
| ## | |||||
| ## | |||||
| ## CMake arm-none-eabi toolchain file | |||||
| ## | |||||
| # Append current directory to CMAKE_MODULE_PATH for making device specific cmake modules visible | |||||
| list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}) | |||||
| # Target definition | |||||
| set(CMAKE_SYSTEM_NAME Generic) | |||||
| set(CMAKE_SYSTEM_PROCESSOR ARM) | |||||
| #--------------------------------------------------------------------------------------- | |||||
| # Set toolchain paths | |||||
| #--------------------------------------------------------------------------------------- | |||||
| set(TOOLCHAIN arm-none-eabi) | |||||
| if(NOT DEFINED TOOLCHAIN_PREFIX) | |||||
| if(CMAKE_HOST_SYSTEM_NAME STREQUAL Linux) | |||||
| set(TOOLCHAIN_PREFIX "/usr") | |||||
| elseif(CMAKE_HOST_SYSTEM_NAME STREQUAL Darwin) | |||||
| set(TOOLCHAIN_PREFIX "/usr/local") | |||||
| elseif(CMAKE_HOST_SYSTEM_NAME STREQUAL Windows) | |||||
| message(STATUS "Please specify the TOOLCHAIN_PREFIX !\n For example: -DTOOLCHAIN_PREFIX=\"C:/Program Files/GNU Tools ARM Embedded\" ") | |||||
| else() | |||||
| set(TOOLCHAIN_PREFIX "/usr") | |||||
| message(STATUS "No TOOLCHAIN_PREFIX specified, using default: " ${TOOLCHAIN_PREFIX}) | |||||
| endif() | |||||
| endif() | |||||
| set(TOOLCHAIN_BIN_DIR ${TOOLCHAIN_PREFIX}/bin) | |||||
| set(TOOLCHAIN_INC_DIR ${TOOLCHAIN_PREFIX}/${TOOLCHAIN}/include) | |||||
| set(TOOLCHAIN_LIB_DIR ${TOOLCHAIN_PREFIX}/${TOOLCHAIN}/lib) | |||||
| # Set system depended extensions | |||||
| if(WIN32) | |||||
| set(TOOLCHAIN_EXT ".exe" ) | |||||
| else() | |||||
| set(TOOLCHAIN_EXT "" ) | |||||
| endif() | |||||
| # Perform compiler test with static library | |||||
| set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY) | |||||
| #--------------------------------------------------------------------------------------- | |||||
| # Preset some general GCC Options | |||||
| #--------------------------------------------------------------------------------------- | |||||
| # Options for DEBUG build | |||||
| # -Og enables optimizations that do not interfere with debugging | |||||
| # -g produce debugging information in the operating system’s native format | |||||
| set(CMAKE_C_FLAGS_DEBUG "-Og -g -DDEBUG" CACHE INTERNAL "C Compiler options for debug build type") | |||||
| set(CMAKE_CXX_FLAGS_DEBUG "-Og -g -DDEBUG" CACHE INTERNAL "C++ Compiler options for debug build type") | |||||
| set(CMAKE_ASM_FLAGS_DEBUG "-g" CACHE INTERNAL "ASM Compiler options for debug build type") | |||||
| set(CMAKE_EXE_LINKER_FLAGS_DEBUG "" CACHE INTERNAL "Linker options for debug build type") | |||||
| # Options for RELEASE build | |||||
| # -Os Optimize for size. -Os enables all -O2 optimizations | |||||
| set(CMAKE_C_FLAGS_RELEASE "-Os" CACHE INTERNAL "C Compiler options for release build type") | |||||
| set(CMAKE_CXX_FLAGS_RELEASE "-Os" CACHE INTERNAL "C++ Compiler options for release build type") | |||||
| set(CMAKE_ASM_FLAGS_RELEASE "" CACHE INTERNAL "ASM Compiler options for release build type") | |||||
| set(CMAKE_EXE_LINKER_FLAGS_RELEASE "" CACHE INTERNAL "Linker options for release build type") | |||||
| #--------------------------------------------------------------------------------------- | |||||
| # Set compilers | |||||
| #--------------------------------------------------------------------------------------- | |||||
| set(CMAKE_C_COMPILER ${TOOLCHAIN_BIN_DIR}/${TOOLCHAIN}-gcc${TOOLCHAIN_EXT} CACHE INTERNAL "C Compiler") | |||||
| set(CMAKE_CXX_COMPILER ${TOOLCHAIN_BIN_DIR}/${TOOLCHAIN}-g++${TOOLCHAIN_EXT} CACHE INTERNAL "C++ Compiler") | |||||
| set(CMAKE_ASM_COMPILER ${TOOLCHAIN_BIN_DIR}/${TOOLCHAIN}-gcc${TOOLCHAIN_EXT} CACHE INTERNAL "ASM Compiler") | |||||
| set(CMAKE_FIND_ROOT_PATH ${TOOLCHAIN_PREFIX}/${${TOOLCHAIN}} ${CMAKE_PREFIX_PATH}) | |||||
| set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) | |||||
| set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) | |||||
| set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) | |||||
| set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY) | |||||
| @@ -1,222 +1,222 @@ | |||||
| ## | |||||
| ## ______ _ | |||||
| ## / _____) _ | | | |||||
| ## ( (____ _____ ____ _| |_ _____ ____| |__ | |||||
| ## \____ \| ___ | (_ _) ___ |/ ___) _ \ | |||||
| ## _____) ) ____| | | || |_| ____( (___| | | | | |||||
| ## (______/|_____)_|_|_| \__)_____)\____)_| |_| | |||||
| ## (C)2013-2017 Semtech | |||||
| ## ___ _____ _ ___ _ _____ ___ ___ ___ ___ | |||||
| ## / __|_ _/_\ / __| |/ / __/ _ \| _ \/ __| __| | |||||
| ## \__ \ | |/ _ \ (__| ' <| _| (_) | / (__| _| | |||||
| ## |___/ |_/_/ \_\___|_|\_\_| \___/|_|_\\___|___| | |||||
| ## embedded.connectivity.solutions.============== | |||||
| ## | |||||
| ## License: Revised BSD License, see LICENSE.TXT file included in the project | |||||
| ## Authors: Johannes Bruder (STACKFORCE), Miguel Luis (Semtech) | |||||
| ## | |||||
| project(lora-mac) | |||||
| cmake_minimum_required(VERSION 3.6) | |||||
| #--------------------------------------------------------------------------------------- | |||||
| # Options | |||||
| #--------------------------------------------------------------------------------------- | |||||
| # Allow switching of target platform | |||||
| set(BOARD_LIST NAMote72 NucleoL073 NucleoL152 NucleoL476 SAMR34 SKiM880B SKiM980A SKiM881AXL B-L072Z-LRWAN1) | |||||
| set(BOARD NucleoL073 CACHE STRING "Default target platform is NucleoL073") | |||||
| set_property(CACHE BOARD PROPERTY STRINGS ${BOARD_LIST}) | |||||
| # Allow switching of MBED shields | |||||
| set(MBED_RADIO_SHIELD_LIST SX1272MB2DAS SX1276MB1LAS SX1276MB1MAS SX1261MBXBAS SX1262MBXCAS SX1262MBXDAS ) | |||||
| set(MBED_RADIO_SHIELD SX1261MBXBAS CACHE STRING "Default MBED radio shield is SX1261MBXBAS") | |||||
| set_property(CACHE MBED_RADIO_SHIELD PROPERTY STRINGS ${MBED_RADIO_SHIELD_LIST}) | |||||
| # Allow switching of secure-elements | |||||
| set(SECURE_ELEMENT_LIST SOFT_SE LR1110_SE) | |||||
| set(SECURE_ELEMENT SOFT_SE CACHE STRING "Default secure element is SOFT_SE") | |||||
| set_property(CACHE SECURE_ELEMENT PROPERTY STRINGS ${SECURE_ELEMENT_LIST}) | |||||
| # Allow switching of Applications | |||||
| set(APPLICATION_LIST LoRaMac ping-pong rx-sensi tx-cw ) | |||||
| set(APPLICATION LoRaMac CACHE STRING "Default Application is LoRaMac") | |||||
| set_property(CACHE APPLICATION PROPERTY STRINGS ${APPLICATION_LIST}) | |||||
| # Switch for USB-Uart support, enable it for some Applications who needs it. | |||||
| option(USE_USB_CDC "Use USB-Uart" OFF) | |||||
| # Switch for debugger support. | |||||
| option(USE_DEBUGGER "Use Debugger" ON) | |||||
| # Switch for Class B support of LoRaMac. | |||||
| option(CLASSB_ENABLED "Class B support of LoRaMac" OFF) | |||||
| #--------------------------------------------------------------------------------------- | |||||
| # Target Boards | |||||
| #--------------------------------------------------------------------------------------- | |||||
| if(BOARD STREQUAL NAMote72) | |||||
| # Configure toolchain for NAMote72 | |||||
| set(LINKER_SCRIPT ${CMAKE_CURRENT_SOURCE_DIR}/boards/NAMote72/cmsis/arm-gcc/stm32l152xc_flash.ld) | |||||
| include(stm32l1) | |||||
| # Build platform specific board implementation | |||||
| add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/boards/NAMote72) | |||||
| # Configure radio | |||||
| set(RADIO sx1272 CACHE INTERNAL "Radio sx1272 selected") | |||||
| elseif(BOARD STREQUAL NucleoL073) | |||||
| # Configure toolchain for NucleoL073 | |||||
| set(LINKER_SCRIPT ${CMAKE_CURRENT_SOURCE_DIR}/boards/NucleoL073/cmsis/arm-gcc/stm32l073xx_flash.ld) | |||||
| include(stm32l0) | |||||
| # Build platform specific board implementation | |||||
| add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/boards/NucleoL073) | |||||
| # Configure radio | |||||
| if(MBED_RADIO_SHIELD STREQUAL SX1272MB2DAS) | |||||
| set(RADIO sx1272 CACHE INTERNAL "Radio sx1272 selected") | |||||
| elseif(MBED_RADIO_SHIELD STREQUAL SX1276MB1LAS OR MBED_RADIO_SHIELD STREQUAL SX1276MB1MAS) | |||||
| set(RADIO sx1276 CACHE INTERNAL "Radio sx1276 selected") | |||||
| elseif(MBED_RADIO_SHIELD STREQUAL SX1261MBXBAS OR MBED_RADIO_SHIELD STREQUAL SX1262MBXCAS OR MBED_RADIO_SHIELD STREQUAL SX1262MBXDAS) | |||||
| set(RADIO sx126x CACHE INTERNAL "Radio sx126x selected") | |||||
| elseif(MBED_RADIO_SHIELD STREQUAL LR1110MB1XXS) | |||||
| set(RADIO lr1110 CACHE INTERNAL "Radio lr1110 selected") | |||||
| else() | |||||
| message(STATUS "Please specify the MBED_RADIO_SHIELD!\nPossible values are: SX1272MB2DAS, SX1276MB1LAS, SX1276MB1MAS, SX1261MBXBAS, SX1262MBXCAS, SX1262MBXDAS and LR1110MB1XXS.") | |||||
| endif() | |||||
| elseif(BOARD STREQUAL NucleoL152) | |||||
| # Configure toolchain for NucleoL152 | |||||
| set(LINKER_SCRIPT ${CMAKE_CURRENT_SOURCE_DIR}/boards/NucleoL152/cmsis/arm-gcc/stm32l152xe_flash.ld) | |||||
| include(stm32l1) | |||||
| # Build platform specific board implementation | |||||
| add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/boards/NucleoL152) | |||||
| # Configure radio | |||||
| if(MBED_RADIO_SHIELD STREQUAL SX1272MB2DAS) | |||||
| set(RADIO sx1272 CACHE INTERNAL "Radio sx1272 selected") | |||||
| elseif(MBED_RADIO_SHIELD STREQUAL SX1276MB1LAS OR MBED_RADIO_SHIELD STREQUAL SX1276MB1MAS) | |||||
| set(RADIO sx1276 CACHE INTERNAL "Radio sx1276 selected") | |||||
| elseif(MBED_RADIO_SHIELD STREQUAL SX1261MBXBAS OR MBED_RADIO_SHIELD STREQUAL SX1262MBXCAS OR MBED_RADIO_SHIELD STREQUAL SX1262MBXDAS) | |||||
| set(RADIO sx126x CACHE INTERNAL "Radio sx126x selected") | |||||
| elseif(MBED_RADIO_SHIELD STREQUAL LR1110MB1XXS) | |||||
| set(RADIO lr1110 CACHE INTERNAL "Radio lr1110 selected") | |||||
| else() | |||||
| message(STATUS "Please specify the MBED_RADIO_SHIELD!\nPossible values are: SX1272MB2DAS, SX1276MB1LAS, SX1276MB1MAS, SX1261MBXBAS, SX1262MBXCAS, SX1262MBXDAS and LR1110MB1XXS.") | |||||
| endif() | |||||
| elseif(BOARD STREQUAL NucleoL476) | |||||
| # Configure toolchain for NucleoL476 | |||||
| set(LINKER_SCRIPT ${CMAKE_CURRENT_SOURCE_DIR}/boards/NucleoL476/cmsis/arm-gcc/stm32l476rgtx_flash.ld) | |||||
| include(stm32l4) | |||||
| # Build platform specific board implementation | |||||
| add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/boards/NucleoL476) | |||||
| # Configure radio | |||||
| if(MBED_RADIO_SHIELD STREQUAL SX1272MB2DAS) | |||||
| set(RADIO sx1272 CACHE INTERNAL "Radio sx1272 selected") | |||||
| elseif(MBED_RADIO_SHIELD STREQUAL SX1276MB1LAS OR MBED_RADIO_SHIELD STREQUAL SX1276MB1MAS) | |||||
| set(RADIO sx1276 CACHE INTERNAL "Radio sx1276 selected") | |||||
| elseif(MBED_RADIO_SHIELD STREQUAL SX1261MBXBAS OR MBED_RADIO_SHIELD STREQUAL SX1262MBXCAS OR MBED_RADIO_SHIELD STREQUAL SX1262MBXDAS) | |||||
| set(RADIO sx126x CACHE INTERNAL "Radio sx126x selected") | |||||
| elseif(MBED_RADIO_SHIELD STREQUAL LR1110MB1XXS) | |||||
| set(RADIO lr1110 CACHE INTERNAL "Radio lr1110 selected") | |||||
| else() | |||||
| message(STATUS "Please specify the MBED_RADIO_SHIELD!\nPossible values are: SX1272MB2DAS, SX1276MB1LAS, SX1276MB1MAS, SX1261MBXBAS, SX1262MBXCAS, SX1262MBXDAS and LR1110MB1XXS.") | |||||
| endif() | |||||
| elseif(BOARD STREQUAL SAMR34) | |||||
| # Configure toolchain for SAMR34 | |||||
| set(LINKER_SCRIPT ${CMAKE_CURRENT_SOURCE_DIR}/boards/mcu/saml21/saml21b/gcc/gcc/saml21j18b_flash.ld) | |||||
| include(samr34) | |||||
| # Build platform specific board implementation | |||||
| add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/boards/SAMR34) | |||||
| # Configure radio | |||||
| set(RADIO sx1276 CACHE INTERNAL "Radio sx1276 selected") | |||||
| elseif(BOARD STREQUAL SKiM880B) | |||||
| # Configure toolchain for SKiM881AXL | |||||
| set(LINKER_SCRIPT ${CMAKE_CURRENT_SOURCE_DIR}/boards/SKiM880B/cmsis/arm-gcc/stm32l151xba_flash.ld) | |||||
| include(stm32l1) | |||||
| # Build platform specific board implementation | |||||
| add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/boards/SKiM880B) | |||||
| # Configure radio | |||||
| set(RADIO sx1272 CACHE INTERNAL "Radio sx1272 selected") | |||||
| elseif(BOARD STREQUAL SKiM980A) | |||||
| # Configure toolchain for SKiM881AXL | |||||
| set(LINKER_SCRIPT ${CMAKE_CURRENT_SOURCE_DIR}/boards/SKiM980A/cmsis/arm-gcc/stm32l151xba_flash.ld) | |||||
| include(stm32l1) | |||||
| # Build platform specific board implementation | |||||
| add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/boards/SKiM980A) | |||||
| # Configure radio | |||||
| set(RADIO sx1272 CACHE INTERNAL "Radio sx1272 selected") | |||||
| elseif(BOARD STREQUAL SKiM881AXL) | |||||
| # Configure toolchain for SKiM881AXL | |||||
| set(LINKER_SCRIPT ${CMAKE_CURRENT_SOURCE_DIR}/boards/SKiM881AXL/cmsis/arm-gcc/stm32l081xx_flash.ld) | |||||
| include(stm32l0) | |||||
| # Build platform specific board implementation | |||||
| add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/boards/SKiM881AXL) | |||||
| # Configure radio | |||||
| set(RADIO sx1272 CACHE INTERNAL "Radio sx1272 selected") | |||||
| elseif(BOARD STREQUAL B-L072Z-LRWAN1) | |||||
| # Configure toolchain for B-L072Z-LRWAN1 | |||||
| set(LINKER_SCRIPT ${CMAKE_CURRENT_SOURCE_DIR}/boards/B-L072Z-LRWAN1/cmsis/arm-gcc/stm32l072xx_flash.ld) | |||||
| include(stm32l0) | |||||
| # Build platform specific board implementation | |||||
| add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/boards/B-L072Z-LRWAN1) | |||||
| # Configure radio | |||||
| set(RADIO sx1276 CACHE INTERNAL "Radio sx1276 selected") | |||||
| endif() | |||||
| #--------------------------------------------------------------------------------------- | |||||
| # General Components | |||||
| #--------------------------------------------------------------------------------------- | |||||
| add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/boards) | |||||
| add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/radio) | |||||
| add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/system) | |||||
| add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/mac) | |||||
| add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/peripherals) | |||||
| #--------------------------------------------------------------------------------------- | |||||
| # Applications | |||||
| #--------------------------------------------------------------------------------------- | |||||
| if(APPLICATION STREQUAL LoRaMac) | |||||
| add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/apps/LoRaMac) | |||||
| elseif(APPLICATION STREQUAL ping-pong) | |||||
| add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/apps/ping-pong) | |||||
| elseif(APPLICATION STREQUAL rx-sensi) | |||||
| add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/apps/rx-sensi) | |||||
| elseif(APPLICATION STREQUAL tx-cw) | |||||
| add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/apps/tx-cw) | |||||
| endif() | |||||
| ## | |||||
| ## ______ _ | |||||
| ## / _____) _ | | | |||||
| ## ( (____ _____ ____ _| |_ _____ ____| |__ | |||||
| ## \____ \| ___ | (_ _) ___ |/ ___) _ \ | |||||
| ## _____) ) ____| | | || |_| ____( (___| | | | | |||||
| ## (______/|_____)_|_|_| \__)_____)\____)_| |_| | |||||
| ## (C)2013-2017 Semtech | |||||
| ## ___ _____ _ ___ _ _____ ___ ___ ___ ___ | |||||
| ## / __|_ _/_\ / __| |/ / __/ _ \| _ \/ __| __| | |||||
| ## \__ \ | |/ _ \ (__| ' <| _| (_) | / (__| _| | |||||
| ## |___/ |_/_/ \_\___|_|\_\_| \___/|_|_\\___|___| | |||||
| ## embedded.connectivity.solutions.============== | |||||
| ## | |||||
| ## License: Revised BSD License, see LICENSE.TXT file included in the project | |||||
| ## Authors: Johannes Bruder (STACKFORCE), Miguel Luis (Semtech) | |||||
| ## | |||||
| project(lora-mac) | |||||
| cmake_minimum_required(VERSION 3.6) | |||||
| #--------------------------------------------------------------------------------------- | |||||
| # Options | |||||
| #--------------------------------------------------------------------------------------- | |||||
| # Allow switching of target platform | |||||
| set(BOARD_LIST NAMote72 NucleoL073 NucleoL152 NucleoL476 SAMR34 SKiM880B SKiM980A SKiM881AXL B-L072Z-LRWAN1) | |||||
| set(BOARD NucleoL073 CACHE STRING "Default target platform is NucleoL073") | |||||
| set_property(CACHE BOARD PROPERTY STRINGS ${BOARD_LIST}) | |||||
| # Allow switching of MBED shields | |||||
| set(MBED_RADIO_SHIELD_LIST SX1272MB2DAS SX1276MB1LAS SX1276MB1MAS SX1261MBXBAS SX1262MBXCAS SX1262MBXDAS ) | |||||
| set(MBED_RADIO_SHIELD SX1261MBXBAS CACHE STRING "Default MBED radio shield is SX1261MBXBAS") | |||||
| set_property(CACHE MBED_RADIO_SHIELD PROPERTY STRINGS ${MBED_RADIO_SHIELD_LIST}) | |||||
| # Allow switching of secure-elements | |||||
| set(SECURE_ELEMENT_LIST SOFT_SE LR1110_SE) | |||||
| set(SECURE_ELEMENT SOFT_SE CACHE STRING "Default secure element is SOFT_SE") | |||||
| set_property(CACHE SECURE_ELEMENT PROPERTY STRINGS ${SECURE_ELEMENT_LIST}) | |||||
| # Allow switching of Applications | |||||
| set(APPLICATION_LIST LoRaMac ping-pong rx-sensi tx-cw ) | |||||
| set(APPLICATION LoRaMac CACHE STRING "Default Application is LoRaMac") | |||||
| set_property(CACHE APPLICATION PROPERTY STRINGS ${APPLICATION_LIST}) | |||||
| # Switch for USB-Uart support, enable it for some Applications who needs it. | |||||
| option(USE_USB_CDC "Use USB-Uart" OFF) | |||||
| # Switch for debugger support. | |||||
| option(USE_DEBUGGER "Use Debugger" ON) | |||||
| # Switch for Class B support of LoRaMac. | |||||
| option(CLASSB_ENABLED "Class B support of LoRaMac" OFF) | |||||
| #--------------------------------------------------------------------------------------- | |||||
| # Target Boards | |||||
| #--------------------------------------------------------------------------------------- | |||||
| if(BOARD STREQUAL NAMote72) | |||||
| # Configure toolchain for NAMote72 | |||||
| set(LINKER_SCRIPT ${CMAKE_CURRENT_SOURCE_DIR}/boards/NAMote72/cmsis/arm-gcc/stm32l152xc_flash.ld) | |||||
| include(stm32l1) | |||||
| # Build platform specific board implementation | |||||
| add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/boards/NAMote72) | |||||
| # Configure radio | |||||
| set(RADIO sx1272 CACHE INTERNAL "Radio sx1272 selected") | |||||
| elseif(BOARD STREQUAL NucleoL073) | |||||
| # Configure toolchain for NucleoL073 | |||||
| set(LINKER_SCRIPT ${CMAKE_CURRENT_SOURCE_DIR}/boards/NucleoL073/cmsis/arm-gcc/stm32l073xx_flash.ld) | |||||
| include(stm32l0) | |||||
| # Build platform specific board implementation | |||||
| add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/boards/NucleoL073) | |||||
| # Configure radio | |||||
| if(MBED_RADIO_SHIELD STREQUAL SX1272MB2DAS) | |||||
| set(RADIO sx1272 CACHE INTERNAL "Radio sx1272 selected") | |||||
| elseif(MBED_RADIO_SHIELD STREQUAL SX1276MB1LAS OR MBED_RADIO_SHIELD STREQUAL SX1276MB1MAS) | |||||
| set(RADIO sx1276 CACHE INTERNAL "Radio sx1276 selected") | |||||
| elseif(MBED_RADIO_SHIELD STREQUAL SX1261MBXBAS OR MBED_RADIO_SHIELD STREQUAL SX1262MBXCAS OR MBED_RADIO_SHIELD STREQUAL SX1262MBXDAS) | |||||
| set(RADIO sx126x CACHE INTERNAL "Radio sx126x selected") | |||||
| elseif(MBED_RADIO_SHIELD STREQUAL LR1110MB1XXS) | |||||
| set(RADIO lr1110 CACHE INTERNAL "Radio lr1110 selected") | |||||
| else() | |||||
| message(STATUS "Please specify the MBED_RADIO_SHIELD!\nPossible values are: SX1272MB2DAS, SX1276MB1LAS, SX1276MB1MAS, SX1261MBXBAS, SX1262MBXCAS, SX1262MBXDAS and LR1110MB1XXS.") | |||||
| endif() | |||||
| elseif(BOARD STREQUAL NucleoL152) | |||||
| # Configure toolchain for NucleoL152 | |||||
| set(LINKER_SCRIPT ${CMAKE_CURRENT_SOURCE_DIR}/boards/NucleoL152/cmsis/arm-gcc/stm32l152xe_flash.ld) | |||||
| include(stm32l1) | |||||
| # Build platform specific board implementation | |||||
| add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/boards/NucleoL152) | |||||
| # Configure radio | |||||
| if(MBED_RADIO_SHIELD STREQUAL SX1272MB2DAS) | |||||
| set(RADIO sx1272 CACHE INTERNAL "Radio sx1272 selected") | |||||
| elseif(MBED_RADIO_SHIELD STREQUAL SX1276MB1LAS OR MBED_RADIO_SHIELD STREQUAL SX1276MB1MAS) | |||||
| set(RADIO sx1276 CACHE INTERNAL "Radio sx1276 selected") | |||||
| elseif(MBED_RADIO_SHIELD STREQUAL SX1261MBXBAS OR MBED_RADIO_SHIELD STREQUAL SX1262MBXCAS OR MBED_RADIO_SHIELD STREQUAL SX1262MBXDAS) | |||||
| set(RADIO sx126x CACHE INTERNAL "Radio sx126x selected") | |||||
| elseif(MBED_RADIO_SHIELD STREQUAL LR1110MB1XXS) | |||||
| set(RADIO lr1110 CACHE INTERNAL "Radio lr1110 selected") | |||||
| else() | |||||
| message(STATUS "Please specify the MBED_RADIO_SHIELD!\nPossible values are: SX1272MB2DAS, SX1276MB1LAS, SX1276MB1MAS, SX1261MBXBAS, SX1262MBXCAS, SX1262MBXDAS and LR1110MB1XXS.") | |||||
| endif() | |||||
| elseif(BOARD STREQUAL NucleoL476) | |||||
| # Configure toolchain for NucleoL476 | |||||
| set(LINKER_SCRIPT ${CMAKE_CURRENT_SOURCE_DIR}/boards/NucleoL476/cmsis/arm-gcc/stm32l476rgtx_flash.ld) | |||||
| include(stm32l4) | |||||
| # Build platform specific board implementation | |||||
| add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/boards/NucleoL476) | |||||
| # Configure radio | |||||
| if(MBED_RADIO_SHIELD STREQUAL SX1272MB2DAS) | |||||
| set(RADIO sx1272 CACHE INTERNAL "Radio sx1272 selected") | |||||
| elseif(MBED_RADIO_SHIELD STREQUAL SX1276MB1LAS OR MBED_RADIO_SHIELD STREQUAL SX1276MB1MAS) | |||||
| set(RADIO sx1276 CACHE INTERNAL "Radio sx1276 selected") | |||||
| elseif(MBED_RADIO_SHIELD STREQUAL SX1261MBXBAS OR MBED_RADIO_SHIELD STREQUAL SX1262MBXCAS OR MBED_RADIO_SHIELD STREQUAL SX1262MBXDAS) | |||||
| set(RADIO sx126x CACHE INTERNAL "Radio sx126x selected") | |||||
| elseif(MBED_RADIO_SHIELD STREQUAL LR1110MB1XXS) | |||||
| set(RADIO lr1110 CACHE INTERNAL "Radio lr1110 selected") | |||||
| else() | |||||
| message(STATUS "Please specify the MBED_RADIO_SHIELD!\nPossible values are: SX1272MB2DAS, SX1276MB1LAS, SX1276MB1MAS, SX1261MBXBAS, SX1262MBXCAS, SX1262MBXDAS and LR1110MB1XXS.") | |||||
| endif() | |||||
| elseif(BOARD STREQUAL SAMR34) | |||||
| # Configure toolchain for SAMR34 | |||||
| set(LINKER_SCRIPT ${CMAKE_CURRENT_SOURCE_DIR}/boards/mcu/saml21/saml21b/gcc/gcc/saml21j18b_flash.ld) | |||||
| include(samr34) | |||||
| # Build platform specific board implementation | |||||
| add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/boards/SAMR34) | |||||
| # Configure radio | |||||
| set(RADIO sx1276 CACHE INTERNAL "Radio sx1276 selected") | |||||
| elseif(BOARD STREQUAL SKiM880B) | |||||
| # Configure toolchain for SKiM881AXL | |||||
| set(LINKER_SCRIPT ${CMAKE_CURRENT_SOURCE_DIR}/boards/SKiM880B/cmsis/arm-gcc/stm32l151xba_flash.ld) | |||||
| include(stm32l1) | |||||
| # Build platform specific board implementation | |||||
| add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/boards/SKiM880B) | |||||
| # Configure radio | |||||
| set(RADIO sx1272 CACHE INTERNAL "Radio sx1272 selected") | |||||
| elseif(BOARD STREQUAL SKiM980A) | |||||
| # Configure toolchain for SKiM881AXL | |||||
| set(LINKER_SCRIPT ${CMAKE_CURRENT_SOURCE_DIR}/boards/SKiM980A/cmsis/arm-gcc/stm32l151xba_flash.ld) | |||||
| include(stm32l1) | |||||
| # Build platform specific board implementation | |||||
| add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/boards/SKiM980A) | |||||
| # Configure radio | |||||
| set(RADIO sx1272 CACHE INTERNAL "Radio sx1272 selected") | |||||
| elseif(BOARD STREQUAL SKiM881AXL) | |||||
| # Configure toolchain for SKiM881AXL | |||||
| set(LINKER_SCRIPT ${CMAKE_CURRENT_SOURCE_DIR}/boards/SKiM881AXL/cmsis/arm-gcc/stm32l081xx_flash.ld) | |||||
| include(stm32l0) | |||||
| # Build platform specific board implementation | |||||
| add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/boards/SKiM881AXL) | |||||
| # Configure radio | |||||
| set(RADIO sx1272 CACHE INTERNAL "Radio sx1272 selected") | |||||
| elseif(BOARD STREQUAL B-L072Z-LRWAN1) | |||||
| # Configure toolchain for B-L072Z-LRWAN1 | |||||
| set(LINKER_SCRIPT ${CMAKE_CURRENT_SOURCE_DIR}/boards/B-L072Z-LRWAN1/cmsis/arm-gcc/stm32l072xx_flash.ld) | |||||
| include(stm32l0) | |||||
| # Build platform specific board implementation | |||||
| add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/boards/B-L072Z-LRWAN1) | |||||
| # Configure radio | |||||
| set(RADIO sx1276 CACHE INTERNAL "Radio sx1276 selected") | |||||
| endif() | |||||
| #--------------------------------------------------------------------------------------- | |||||
| # General Components | |||||
| #--------------------------------------------------------------------------------------- | |||||
| add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/boards) | |||||
| add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/radio) | |||||
| add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/system) | |||||
| add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/mac) | |||||
| add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/peripherals) | |||||
| #--------------------------------------------------------------------------------------- | |||||
| # Applications | |||||
| #--------------------------------------------------------------------------------------- | |||||
| if(APPLICATION STREQUAL LoRaMac) | |||||
| add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/apps/LoRaMac) | |||||
| elseif(APPLICATION STREQUAL ping-pong) | |||||
| add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/apps/ping-pong) | |||||
| elseif(APPLICATION STREQUAL rx-sensi) | |||||
| add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/apps/rx-sensi) | |||||
| elseif(APPLICATION STREQUAL tx-cw) | |||||
| add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/apps/tx-cw) | |||||
| endif() | |||||
| @@ -1,170 +1,170 @@ | |||||
| ## | |||||
| ## ______ _ | |||||
| ## / _____) _ | | | |||||
| ## ( (____ _____ ____ _| |_ _____ ____| |__ | |||||
| ## \____ \| ___ | (_ _) ___ |/ ___) _ \ | |||||
| ## _____) ) ____| | | || |_| ____( (___| | | | | |||||
| ## (______/|_____)_|_|_| \__)_____)\____)_| |_| | |||||
| ## (C)2013-2017 Semtech | |||||
| ## ___ _____ _ ___ _ _____ ___ ___ ___ ___ | |||||
| ## / __|_ _/_\ / __| |/ / __/ _ \| _ \/ __| __| | |||||
| ## \__ \ | |/ _ \ (__| ' <| _| (_) | / (__| _| | |||||
| ## |___/ |_/_/ \_\___|_|\_\_| \___/|_|_\\___|___| | |||||
| ## embedded.connectivity.solutions.============== | |||||
| ## | |||||
| ## License: Revised BSD License, see LICENSE.TXT file included in the project | |||||
| ## Authors: Johannes Bruder (STACKFORCE), Miguel Luis (Semtech) | |||||
| ## | |||||
| project(LoRaMac) | |||||
| cmake_minimum_required(VERSION 3.6) | |||||
| #--------------------------------------------------------------------------------------- | |||||
| # Options | |||||
| #--------------------------------------------------------------------------------------- | |||||
| # Allow switching of sub projects | |||||
| set(SUB_PROJECT_LIST periodic-uplink-lpp fuota-test-01) | |||||
| set(SUB_PROJECT periodic-uplink-lpp CACHE STRING "Default sub project is periodic-uplink-lpp") | |||||
| set_property(CACHE SUB_PROJECT PROPERTY STRINGS ${SUB_PROJECT_LIST}) | |||||
| # Allow switching of active region | |||||
| set(ACTIVE_REGION_LIST LORAMAC_REGION_EU868 LORAMAC_REGION_US915 LORAMAC_REGION_CN779 | |||||
| LORAMAC_REGION_EU433 LORAMAC_REGION_AU915 LORAMAC_REGION_AS923 LORAMAC_REGION_CN470 | |||||
| LORAMAC_REGION_KR920 LORAMAC_REGION_IN865 LORAMAC_REGION_RU864 | |||||
| ) | |||||
| set(ACTIVE_REGION LORAMAC_REGION_EU868 CACHE STRING "Default active region is EU868") | |||||
| set_property(CACHE ACTIVE_REGION PROPERTY STRINGS ${ACTIVE_REGION_LIST}) | |||||
| if((SUB_PROJECT STREQUAL periodic-uplink-lpp OR SUB_PROJECT STREQUAL fuota-test-01) AND NOT CLASSB_ENABLED ) | |||||
| message(FATAL_ERROR "Please turn on Class B support of LoRaMac ( CLASSB_ENABLED=ON ) to use periodic-uplink-lpp, fuota-test-01 sub projects") | |||||
| endif() | |||||
| # Allow selection of secure-element provisioning method | |||||
| option(SECURE_ELEMENT_PRE_PROVISIONED "Secure-element pre-provisioning" ON) | |||||
| if(SUB_PROJECT STREQUAL periodic-uplink-lpp) | |||||
| #--------------------------------------------------------------------------------------- | |||||
| # Application common features handling | |||||
| #--------------------------------------------------------------------------------------- | |||||
| list(APPEND ${PROJECT_NAME}_COMMON | |||||
| "${CMAKE_CURRENT_LIST_DIR}/common/CayenneLpp.c" | |||||
| "${CMAKE_CURRENT_LIST_DIR}/common/cli.c" | |||||
| "${CMAKE_CURRENT_LIST_DIR}/common/LmHandlerMsgDisplay.c" | |||||
| "${CMAKE_CURRENT_LIST_DIR}/common/NvmDataMgmt.c" | |||||
| ) | |||||
| #--------------------------------------------------------------------------------------- | |||||
| # Application LoRaMac handler | |||||
| #--------------------------------------------------------------------------------------- | |||||
| list(APPEND ${PROJECT_NAME}_LMH | |||||
| "${CMAKE_CURRENT_LIST_DIR}/common/LmHandler/LmHandler.c" | |||||
| ) | |||||
| #--------------------------------------------------------------------------------------- | |||||
| # LoRaMac handler applicative packages | |||||
| #--------------------------------------------------------------------------------------- | |||||
| list(APPEND ${PROJECT_NAME}_LMHP | |||||
| "${CMAKE_CURRENT_LIST_DIR}/common/LmHandler/packages/FragDecoder.c" | |||||
| "${CMAKE_CURRENT_LIST_DIR}/common/LmHandler/packages/LmhpClockSync.c" | |||||
| "${CMAKE_CURRENT_LIST_DIR}/common/LmHandler/packages/LmhpCompliance.c" | |||||
| "${CMAKE_CURRENT_LIST_DIR}/common/LmHandler/packages/LmhpFragmentation.c" | |||||
| "${CMAKE_CURRENT_LIST_DIR}/common/LmHandler/packages/LmhpRemoteMcastSetup.c" | |||||
| ) | |||||
| elseif(SUB_PROJECT STREQUAL fuota-test-01) | |||||
| #--------------------------------------------------------------------------------------- | |||||
| # Application common features handling | |||||
| #--------------------------------------------------------------------------------------- | |||||
| list(APPEND ${PROJECT_NAME}_COMMON | |||||
| "${CMAKE_CURRENT_LIST_DIR}/common/cli.c" | |||||
| "${CMAKE_CURRENT_LIST_DIR}/common/LmHandlerMsgDisplay.c" | |||||
| "${CMAKE_CURRENT_LIST_DIR}/common/NvmDataMgmt.c" | |||||
| ) | |||||
| #--------------------------------------------------------------------------------------- | |||||
| # Application LoRaMac handler | |||||
| #--------------------------------------------------------------------------------------- | |||||
| list(APPEND ${PROJECT_NAME}_LMH | |||||
| "${CMAKE_CURRENT_LIST_DIR}/common/LmHandler/LmHandler.c" | |||||
| ) | |||||
| #--------------------------------------------------------------------------------------- | |||||
| # LoRaMac handler applicative packages | |||||
| #--------------------------------------------------------------------------------------- | |||||
| list(APPEND ${PROJECT_NAME}_LMHP | |||||
| "${CMAKE_CURRENT_LIST_DIR}/common/LmHandler/packages/FragDecoder.c" | |||||
| "${CMAKE_CURRENT_LIST_DIR}/common/LmHandler/packages/LmhpClockSync.c" | |||||
| "${CMAKE_CURRENT_LIST_DIR}/common/LmHandler/packages/LmhpCompliance.c" | |||||
| "${CMAKE_CURRENT_LIST_DIR}/common/LmHandler/packages/LmhpFragmentation.c" | |||||
| "${CMAKE_CURRENT_LIST_DIR}/common/LmHandler/packages/LmhpRemoteMcastSetup.c" | |||||
| ) | |||||
| else() | |||||
| message(FATAL_ERROR "Unknown SUB_PROJECT") | |||||
| endif() | |||||
| #--------------------------------------------------------------------------------------- | |||||
| # Application | |||||
| #--------------------------------------------------------------------------------------- | |||||
| file(GLOB ${PROJECT_NAME}_SOURCES "${CMAKE_CURRENT_LIST_DIR}/${SUB_PROJECT}/${BOARD}/*.c") | |||||
| add_executable(${PROJECT_NAME}-${SUB_PROJECT} | |||||
| ${${PROJECT_NAME}_COMMON} | |||||
| ${${PROJECT_NAME}_LMH} | |||||
| ${${PROJECT_NAME}_LMHP} | |||||
| ${${PROJECT_NAME}_SOURCES} | |||||
| $<TARGET_OBJECTS:mac> | |||||
| $<TARGET_OBJECTS:system> | |||||
| $<TARGET_OBJECTS:radio> | |||||
| $<TARGET_OBJECTS:peripherals> | |||||
| $<TARGET_OBJECTS:${BOARD}> | |||||
| ) | |||||
| target_compile_definitions(${PROJECT_NAME}-${SUB_PROJECT} PRIVATE $<$<BOOL:${CLASSB_ENABLED}>:LORAMAC_CLASSB_ENABLED>) | |||||
| target_compile_definitions(${PROJECT_NAME}-${SUB_PROJECT} PRIVATE ACTIVE_REGION=${ACTIVE_REGION}) | |||||
| if(${SECURE_ELEMENT_PRE_PROVISIONED} MATCHES ON) | |||||
| target_compile_definitions(${PROJECT_NAME}-${SUB_PROJECT} PRIVATE -DSECURE_ELEMENT_PRE_PROVISIONED) | |||||
| endif() | |||||
| if(${SECURE_ELEMENT} MATCHES SOFT_SE) | |||||
| target_compile_definitions(${PROJECT_NAME}-${SUB_PROJECT} PRIVATE -DSOFT_SE) | |||||
| endif() | |||||
| target_compile_definitions(${PROJECT_NAME}-${SUB_PROJECT} PUBLIC | |||||
| $<BUILD_INTERFACE:$<TARGET_PROPERTY:mac,INTERFACE_COMPILE_DEFINITIONS>> | |||||
| ) | |||||
| target_include_directories(${PROJECT_NAME}-${SUB_PROJECT} PUBLIC | |||||
| ${CMAKE_CURRENT_SOURCE_DIR}/common | |||||
| ${CMAKE_CURRENT_SOURCE_DIR}/common/LmHandler | |||||
| ${CMAKE_CURRENT_SOURCE_DIR}/common/LmHandler/packages | |||||
| ${CMAKE_CURRENT_SOURCE_DIR}/${SUB_PROJECT}/${BOARD} | |||||
| $<BUILD_INTERFACE:$<TARGET_PROPERTY:mac,INTERFACE_INCLUDE_DIRECTORIES>> | |||||
| $<BUILD_INTERFACE:$<TARGET_PROPERTY:system,INTERFACE_INCLUDE_DIRECTORIES>> | |||||
| $<BUILD_INTERFACE:$<TARGET_PROPERTY:radio,INTERFACE_INCLUDE_DIRECTORIES>> | |||||
| $<BUILD_INTERFACE:$<TARGET_PROPERTY:peripherals,INTERFACE_INCLUDE_DIRECTORIES>> | |||||
| $<BUILD_INTERFACE:$<TARGET_PROPERTY:${BOARD},INTERFACE_INCLUDE_DIRECTORIES>> | |||||
| ) | |||||
| set_property(TARGET ${PROJECT_NAME}-${SUB_PROJECT} PROPERTY C_STANDARD 11) | |||||
| target_link_libraries(${PROJECT_NAME}-${SUB_PROJECT} m) | |||||
| #--------------------------------------------------------------------------------------- | |||||
| # Debugging and Binutils | |||||
| #--------------------------------------------------------------------------------------- | |||||
| include(gdb-helper) | |||||
| include(binutils-arm-none-eabi) | |||||
| # Generate debugger configurations | |||||
| generate_run_gdb_stlink(${PROJECT_NAME}-${SUB_PROJECT}) | |||||
| generate_run_gdb_openocd(${PROJECT_NAME}-${SUB_PROJECT}) | |||||
| generate_vscode_launch_openocd(${PROJECT_NAME}-${SUB_PROJECT}) | |||||
| # Print section sizes of target | |||||
| print_section_sizes(${PROJECT_NAME}-${SUB_PROJECT}) | |||||
| # Create output in hex and binary format | |||||
| create_bin_output(${PROJECT_NAME}-${SUB_PROJECT}) | |||||
| create_hex_output(${PROJECT_NAME}-${SUB_PROJECT}) | |||||
| ## | |||||
| ## ______ _ | |||||
| ## / _____) _ | | | |||||
| ## ( (____ _____ ____ _| |_ _____ ____| |__ | |||||
| ## \____ \| ___ | (_ _) ___ |/ ___) _ \ | |||||
| ## _____) ) ____| | | || |_| ____( (___| | | | | |||||
| ## (______/|_____)_|_|_| \__)_____)\____)_| |_| | |||||
| ## (C)2013-2017 Semtech | |||||
| ## ___ _____ _ ___ _ _____ ___ ___ ___ ___ | |||||
| ## / __|_ _/_\ / __| |/ / __/ _ \| _ \/ __| __| | |||||
| ## \__ \ | |/ _ \ (__| ' <| _| (_) | / (__| _| | |||||
| ## |___/ |_/_/ \_\___|_|\_\_| \___/|_|_\\___|___| | |||||
| ## embedded.connectivity.solutions.============== | |||||
| ## | |||||
| ## License: Revised BSD License, see LICENSE.TXT file included in the project | |||||
| ## Authors: Johannes Bruder (STACKFORCE), Miguel Luis (Semtech) | |||||
| ## | |||||
| project(LoRaMac) | |||||
| cmake_minimum_required(VERSION 3.6) | |||||
| #--------------------------------------------------------------------------------------- | |||||
| # Options | |||||
| #--------------------------------------------------------------------------------------- | |||||
| # Allow switching of sub projects | |||||
| set(SUB_PROJECT_LIST periodic-uplink-lpp fuota-test-01) | |||||
| set(SUB_PROJECT periodic-uplink-lpp CACHE STRING "Default sub project is periodic-uplink-lpp") | |||||
| set_property(CACHE SUB_PROJECT PROPERTY STRINGS ${SUB_PROJECT_LIST}) | |||||
| # Allow switching of active region | |||||
| set(ACTIVE_REGION_LIST LORAMAC_REGION_EU868 LORAMAC_REGION_US915 LORAMAC_REGION_CN779 | |||||
| LORAMAC_REGION_EU433 LORAMAC_REGION_AU915 LORAMAC_REGION_AS923 LORAMAC_REGION_CN470 | |||||
| LORAMAC_REGION_KR920 LORAMAC_REGION_IN865 LORAMAC_REGION_RU864 | |||||
| ) | |||||
| set(ACTIVE_REGION LORAMAC_REGION_EU868 CACHE STRING "Default active region is EU868") | |||||
| set_property(CACHE ACTIVE_REGION PROPERTY STRINGS ${ACTIVE_REGION_LIST}) | |||||
| if((SUB_PROJECT STREQUAL periodic-uplink-lpp OR SUB_PROJECT STREQUAL fuota-test-01) AND NOT CLASSB_ENABLED ) | |||||
| message(FATAL_ERROR "Please turn on Class B support of LoRaMac ( CLASSB_ENABLED=ON ) to use periodic-uplink-lpp, fuota-test-01 sub projects") | |||||
| endif() | |||||
| # Allow selection of secure-element provisioning method | |||||
| option(SECURE_ELEMENT_PRE_PROVISIONED "Secure-element pre-provisioning" ON) | |||||
| if(SUB_PROJECT STREQUAL periodic-uplink-lpp) | |||||
| #--------------------------------------------------------------------------------------- | |||||
| # Application common features handling | |||||
| #--------------------------------------------------------------------------------------- | |||||
| list(APPEND ${PROJECT_NAME}_COMMON | |||||
| "${CMAKE_CURRENT_LIST_DIR}/common/CayenneLpp.c" | |||||
| "${CMAKE_CURRENT_LIST_DIR}/common/cli.c" | |||||
| "${CMAKE_CURRENT_LIST_DIR}/common/LmHandlerMsgDisplay.c" | |||||
| "${CMAKE_CURRENT_LIST_DIR}/common/NvmDataMgmt.c" | |||||
| ) | |||||
| #--------------------------------------------------------------------------------------- | |||||
| # Application LoRaMac handler | |||||
| #--------------------------------------------------------------------------------------- | |||||
| list(APPEND ${PROJECT_NAME}_LMH | |||||
| "${CMAKE_CURRENT_LIST_DIR}/common/LmHandler/LmHandler.c" | |||||
| ) | |||||
| #--------------------------------------------------------------------------------------- | |||||
| # LoRaMac handler applicative packages | |||||
| #--------------------------------------------------------------------------------------- | |||||
| list(APPEND ${PROJECT_NAME}_LMHP | |||||
| "${CMAKE_CURRENT_LIST_DIR}/common/LmHandler/packages/FragDecoder.c" | |||||
| "${CMAKE_CURRENT_LIST_DIR}/common/LmHandler/packages/LmhpClockSync.c" | |||||
| "${CMAKE_CURRENT_LIST_DIR}/common/LmHandler/packages/LmhpCompliance.c" | |||||
| "${CMAKE_CURRENT_LIST_DIR}/common/LmHandler/packages/LmhpFragmentation.c" | |||||
| "${CMAKE_CURRENT_LIST_DIR}/common/LmHandler/packages/LmhpRemoteMcastSetup.c" | |||||
| ) | |||||
| elseif(SUB_PROJECT STREQUAL fuota-test-01) | |||||
| #--------------------------------------------------------------------------------------- | |||||
| # Application common features handling | |||||
| #--------------------------------------------------------------------------------------- | |||||
| list(APPEND ${PROJECT_NAME}_COMMON | |||||
| "${CMAKE_CURRENT_LIST_DIR}/common/cli.c" | |||||
| "${CMAKE_CURRENT_LIST_DIR}/common/LmHandlerMsgDisplay.c" | |||||
| "${CMAKE_CURRENT_LIST_DIR}/common/NvmDataMgmt.c" | |||||
| ) | |||||
| #--------------------------------------------------------------------------------------- | |||||
| # Application LoRaMac handler | |||||
| #--------------------------------------------------------------------------------------- | |||||
| list(APPEND ${PROJECT_NAME}_LMH | |||||
| "${CMAKE_CURRENT_LIST_DIR}/common/LmHandler/LmHandler.c" | |||||
| ) | |||||
| #--------------------------------------------------------------------------------------- | |||||
| # LoRaMac handler applicative packages | |||||
| #--------------------------------------------------------------------------------------- | |||||
| list(APPEND ${PROJECT_NAME}_LMHP | |||||
| "${CMAKE_CURRENT_LIST_DIR}/common/LmHandler/packages/FragDecoder.c" | |||||
| "${CMAKE_CURRENT_LIST_DIR}/common/LmHandler/packages/LmhpClockSync.c" | |||||
| "${CMAKE_CURRENT_LIST_DIR}/common/LmHandler/packages/LmhpCompliance.c" | |||||
| "${CMAKE_CURRENT_LIST_DIR}/common/LmHandler/packages/LmhpFragmentation.c" | |||||
| "${CMAKE_CURRENT_LIST_DIR}/common/LmHandler/packages/LmhpRemoteMcastSetup.c" | |||||
| ) | |||||
| else() | |||||
| message(FATAL_ERROR "Unknown SUB_PROJECT") | |||||
| endif() | |||||
| #--------------------------------------------------------------------------------------- | |||||
| # Application | |||||
| #--------------------------------------------------------------------------------------- | |||||
| file(GLOB ${PROJECT_NAME}_SOURCES "${CMAKE_CURRENT_LIST_DIR}/${SUB_PROJECT}/${BOARD}/*.c") | |||||
| add_executable(${PROJECT_NAME}-${SUB_PROJECT} | |||||
| ${${PROJECT_NAME}_COMMON} | |||||
| ${${PROJECT_NAME}_LMH} | |||||
| ${${PROJECT_NAME}_LMHP} | |||||
| ${${PROJECT_NAME}_SOURCES} | |||||
| $<TARGET_OBJECTS:mac> | |||||
| $<TARGET_OBJECTS:system> | |||||
| $<TARGET_OBJECTS:radio> | |||||
| $<TARGET_OBJECTS:peripherals> | |||||
| $<TARGET_OBJECTS:${BOARD}> | |||||
| ) | |||||
| target_compile_definitions(${PROJECT_NAME}-${SUB_PROJECT} PRIVATE $<$<BOOL:${CLASSB_ENABLED}>:LORAMAC_CLASSB_ENABLED>) | |||||
| target_compile_definitions(${PROJECT_NAME}-${SUB_PROJECT} PRIVATE ACTIVE_REGION=${ACTIVE_REGION}) | |||||
| if(${SECURE_ELEMENT_PRE_PROVISIONED} MATCHES ON) | |||||
| target_compile_definitions(${PROJECT_NAME}-${SUB_PROJECT} PRIVATE -DSECURE_ELEMENT_PRE_PROVISIONED) | |||||
| endif() | |||||
| if(${SECURE_ELEMENT} MATCHES SOFT_SE) | |||||
| target_compile_definitions(${PROJECT_NAME}-${SUB_PROJECT} PRIVATE -DSOFT_SE) | |||||
| endif() | |||||
| target_compile_definitions(${PROJECT_NAME}-${SUB_PROJECT} PUBLIC | |||||
| $<BUILD_INTERFACE:$<TARGET_PROPERTY:mac,INTERFACE_COMPILE_DEFINITIONS>> | |||||
| ) | |||||
| target_include_directories(${PROJECT_NAME}-${SUB_PROJECT} PUBLIC | |||||
| ${CMAKE_CURRENT_SOURCE_DIR}/common | |||||
| ${CMAKE_CURRENT_SOURCE_DIR}/common/LmHandler | |||||
| ${CMAKE_CURRENT_SOURCE_DIR}/common/LmHandler/packages | |||||
| ${CMAKE_CURRENT_SOURCE_DIR}/${SUB_PROJECT}/${BOARD} | |||||
| $<BUILD_INTERFACE:$<TARGET_PROPERTY:mac,INTERFACE_INCLUDE_DIRECTORIES>> | |||||
| $<BUILD_INTERFACE:$<TARGET_PROPERTY:system,INTERFACE_INCLUDE_DIRECTORIES>> | |||||
| $<BUILD_INTERFACE:$<TARGET_PROPERTY:radio,INTERFACE_INCLUDE_DIRECTORIES>> | |||||
| $<BUILD_INTERFACE:$<TARGET_PROPERTY:peripherals,INTERFACE_INCLUDE_DIRECTORIES>> | |||||
| $<BUILD_INTERFACE:$<TARGET_PROPERTY:${BOARD},INTERFACE_INCLUDE_DIRECTORIES>> | |||||
| ) | |||||
| set_property(TARGET ${PROJECT_NAME}-${SUB_PROJECT} PROPERTY C_STANDARD 11) | |||||
| target_link_libraries(${PROJECT_NAME}-${SUB_PROJECT} m) | |||||
| #--------------------------------------------------------------------------------------- | |||||
| # Debugging and Binutils | |||||
| #--------------------------------------------------------------------------------------- | |||||
| include(gdb-helper) | |||||
| include(binutils-arm-none-eabi) | |||||
| # Generate debugger configurations | |||||
| generate_run_gdb_stlink(${PROJECT_NAME}-${SUB_PROJECT}) | |||||
| generate_run_gdb_openocd(${PROJECT_NAME}-${SUB_PROJECT}) | |||||
| generate_vscode_launch_openocd(${PROJECT_NAME}-${SUB_PROJECT}) | |||||
| # Print section sizes of target | |||||
| print_section_sizes(${PROJECT_NAME}-${SUB_PROJECT}) | |||||
| # Create output in hex and binary format | |||||
| create_bin_output(${PROJECT_NAME}-${SUB_PROJECT}) | |||||
| create_hex_output(${PROJECT_NAME}-${SUB_PROJECT}) | |||||
| @@ -1,257 +1,257 @@ | |||||
| /*! | |||||
| * \file CayenneLpp.c | |||||
| * | |||||
| * \brief Implements the Cayenne Low Power Protocol | |||||
| * | |||||
| * \copyright Revised BSD License, see section \ref LICENSE. | |||||
| * | |||||
| * \code | |||||
| * ______ _ | |||||
| * / _____) _ | | | |||||
| * ( (____ _____ ____ _| |_ _____ ____| |__ | |||||
| * \____ \| ___ | (_ _) ___ |/ ___) _ \ | |||||
| * _____) ) ____| | | || |_| ____( (___| | | | | |||||
| * (______/|_____)_|_|_| \__)_____)\____)_| |_| | |||||
| * (C)2013-2018 Semtech | |||||
| * | |||||
| * \endcode | |||||
| * | |||||
| * \author Miguel Luis ( Semtech ) | |||||
| */ | |||||
| #include <stdint.h> | |||||
| #include "utilities.h" | |||||
| #include "CayenneLpp.h" | |||||
| #define CAYENNE_LPP_MAXBUFFER_SIZE 242 | |||||
| static uint8_t CayenneLppBuffer[CAYENNE_LPP_MAXBUFFER_SIZE]; | |||||
| static uint8_t CayenneLppCursor = 0; | |||||
| void CayenneLppInit( void ) | |||||
| { | |||||
| CayenneLppCursor = 0; | |||||
| } | |||||
| void CayenneLppReset( void ) | |||||
| { | |||||
| CayenneLppCursor = 0; | |||||
| } | |||||
| uint8_t CayenneLppGetSize( void ) | |||||
| { | |||||
| return CayenneLppCursor; | |||||
| } | |||||
| uint8_t* CayenneLppGetBuffer( void ) | |||||
| { | |||||
| return CayenneLppBuffer; | |||||
| } | |||||
| uint8_t CayenneLppCopy( uint8_t* dst ) | |||||
| { | |||||
| memcpy1( dst, CayenneLppBuffer, CayenneLppCursor ); | |||||
| return CayenneLppCursor; | |||||
| } | |||||
| uint8_t CayenneLppAddDigitalInput( uint8_t channel, uint8_t value ) | |||||
| { | |||||
| if( ( CayenneLppCursor + LPP_DIGITAL_INPUT_SIZE ) > CAYENNE_LPP_MAXBUFFER_SIZE ) | |||||
| { | |||||
| return 0; | |||||
| } | |||||
| CayenneLppBuffer[CayenneLppCursor++] = channel; | |||||
| CayenneLppBuffer[CayenneLppCursor++] = LPP_DIGITAL_INPUT; | |||||
| CayenneLppBuffer[CayenneLppCursor++] = value; | |||||
| return CayenneLppCursor; | |||||
| } | |||||
| uint8_t CayenneLppAddDigitalOutput( uint8_t channel, uint8_t value ) | |||||
| { | |||||
| if( ( CayenneLppCursor + LPP_DIGITAL_OUTPUT_SIZE ) > CAYENNE_LPP_MAXBUFFER_SIZE ) | |||||
| { | |||||
| return 0; | |||||
| } | |||||
| CayenneLppBuffer[CayenneLppCursor++] = channel; | |||||
| CayenneLppBuffer[CayenneLppCursor++] = LPP_DIGITAL_OUTPUT; | |||||
| CayenneLppBuffer[CayenneLppCursor++] = value; | |||||
| return CayenneLppCursor; | |||||
| } | |||||
| uint8_t CayenneLppAddAnalogInput( uint8_t channel, float value ) | |||||
| { | |||||
| if( ( CayenneLppCursor + LPP_ANALOG_INPUT_SIZE ) > CAYENNE_LPP_MAXBUFFER_SIZE ) | |||||
| { | |||||
| return 0; | |||||
| } | |||||
| int16_t val = ( int16_t ) ( value * 100 ); | |||||
| CayenneLppBuffer[CayenneLppCursor++] = channel; | |||||
| CayenneLppBuffer[CayenneLppCursor++] = LPP_ANALOG_INPUT; | |||||
| CayenneLppBuffer[CayenneLppCursor++] = val >> 8; | |||||
| CayenneLppBuffer[CayenneLppCursor++] = val; | |||||
| return CayenneLppCursor; | |||||
| } | |||||
| uint8_t CayenneLppAddAnalogOutput( uint8_t channel, float value ) | |||||
| { | |||||
| if( ( CayenneLppCursor + LPP_ANALOG_OUTPUT_SIZE ) > CAYENNE_LPP_MAXBUFFER_SIZE ) | |||||
| { | |||||
| return 0; | |||||
| } | |||||
| int16_t val = ( int16_t ) ( value * 100 ); | |||||
| CayenneLppBuffer[CayenneLppCursor++] = channel; | |||||
| CayenneLppBuffer[CayenneLppCursor++] = LPP_ANALOG_OUTPUT; | |||||
| CayenneLppBuffer[CayenneLppCursor++] = val >> 8; | |||||
| CayenneLppBuffer[CayenneLppCursor++] = val; | |||||
| return CayenneLppCursor; | |||||
| } | |||||
| uint8_t CayenneLppAddLuminosity( uint8_t channel, uint16_t lux ) | |||||
| { | |||||
| if( ( CayenneLppCursor + LPP_LUMINOSITY_SIZE ) > CAYENNE_LPP_MAXBUFFER_SIZE ) | |||||
| { | |||||
| return 0; | |||||
| } | |||||
| CayenneLppBuffer[CayenneLppCursor++] = channel; | |||||
| CayenneLppBuffer[CayenneLppCursor++] = LPP_LUMINOSITY; | |||||
| CayenneLppBuffer[CayenneLppCursor++] = lux >> 8; | |||||
| CayenneLppBuffer[CayenneLppCursor++] = lux; | |||||
| return CayenneLppCursor; | |||||
| } | |||||
| uint8_t CayenneLppAddPresence( uint8_t channel, uint8_t value ) | |||||
| { | |||||
| if( ( CayenneLppCursor + LPP_PRESENCE_SIZE ) > CAYENNE_LPP_MAXBUFFER_SIZE ) | |||||
| { | |||||
| return 0; | |||||
| } | |||||
| CayenneLppBuffer[CayenneLppCursor++] = channel; | |||||
| CayenneLppBuffer[CayenneLppCursor++] = LPP_PRESENCE; | |||||
| CayenneLppBuffer[CayenneLppCursor++] = value; | |||||
| return CayenneLppCursor; | |||||
| } | |||||
| uint8_t CayenneLppAddTemperature( uint8_t channel, float celsius ) | |||||
| { | |||||
| if( ( CayenneLppCursor + LPP_TEMPERATURE_SIZE ) > CAYENNE_LPP_MAXBUFFER_SIZE ) | |||||
| { | |||||
| return 0; | |||||
| } | |||||
| int16_t val = ( int16_t) ( celsius * 10 ); | |||||
| CayenneLppBuffer[CayenneLppCursor++] = channel; | |||||
| CayenneLppBuffer[CayenneLppCursor++] = LPP_TEMPERATURE; | |||||
| CayenneLppBuffer[CayenneLppCursor++] = val >> 8; | |||||
| CayenneLppBuffer[CayenneLppCursor++] = val; | |||||
| return CayenneLppCursor; | |||||
| } | |||||
| uint8_t CayenneLppAddRelativeHumidity( uint8_t channel, float rh ) | |||||
| { | |||||
| if( ( CayenneLppCursor + LPP_RELATIVE_HUMIDITY_SIZE ) > CAYENNE_LPP_MAXBUFFER_SIZE ) | |||||
| { | |||||
| return 0; | |||||
| } | |||||
| CayenneLppBuffer[CayenneLppCursor++] = channel; | |||||
| CayenneLppBuffer[CayenneLppCursor++] = LPP_RELATIVE_HUMIDITY; | |||||
| CayenneLppBuffer[CayenneLppCursor++] = (uint8_t ) ( rh * 2 ); | |||||
| return CayenneLppCursor; | |||||
| } | |||||
| uint8_t CayenneLppAddAccelerometer( uint8_t channel, float x, float y, float z ) | |||||
| { | |||||
| if( ( CayenneLppCursor + LPP_ACCELEROMETER_SIZE ) > CAYENNE_LPP_MAXBUFFER_SIZE ) | |||||
| { | |||||
| return 0; | |||||
| } | |||||
| int16_t vx = ( int16_t ) ( x * 1000 ); | |||||
| int16_t vy = ( int16_t ) ( y * 1000 ); | |||||
| int16_t vz = ( int16_t ) ( z * 1000 ); | |||||
| CayenneLppBuffer[CayenneLppCursor++] = channel; | |||||
| CayenneLppBuffer[CayenneLppCursor++] = LPP_ACCELEROMETER; | |||||
| CayenneLppBuffer[CayenneLppCursor++] = vx >> 8; | |||||
| CayenneLppBuffer[CayenneLppCursor++] = vx; | |||||
| CayenneLppBuffer[CayenneLppCursor++] = vy >> 8; | |||||
| CayenneLppBuffer[CayenneLppCursor++] = vy; | |||||
| CayenneLppBuffer[CayenneLppCursor++] = vz >> 8; | |||||
| CayenneLppBuffer[CayenneLppCursor++] = vz; | |||||
| return CayenneLppCursor; | |||||
| } | |||||
| uint8_t CayenneLppAddBarometricPressure( uint8_t channel, float hpa ) | |||||
| { | |||||
| if( ( CayenneLppCursor + LPP_BAROMETRIC_PRESSURE_SIZE ) > CAYENNE_LPP_MAXBUFFER_SIZE ) | |||||
| { | |||||
| return 0; | |||||
| } | |||||
| int16_t val = ( int16_t ) ( hpa * 10 ); | |||||
| CayenneLppBuffer[CayenneLppCursor++] = channel; | |||||
| CayenneLppBuffer[CayenneLppCursor++] = LPP_BAROMETRIC_PRESSURE; | |||||
| CayenneLppBuffer[CayenneLppCursor++] = val >> 8; | |||||
| CayenneLppBuffer[CayenneLppCursor++] = val; | |||||
| return CayenneLppCursor; | |||||
| } | |||||
| uint8_t CayenneLppAddGyrometer( uint8_t channel, float x, float y, float z ) | |||||
| { | |||||
| if( ( CayenneLppCursor + LPP_GYROMETER_SIZE ) > CAYENNE_LPP_MAXBUFFER_SIZE ) | |||||
| { | |||||
| return 0; | |||||
| } | |||||
| int16_t vx = ( int16_t ) ( x * 100 ); | |||||
| int16_t vy = ( int16_t ) ( y * 100 ); | |||||
| int16_t vz = ( int16_t ) ( z * 100 ); | |||||
| CayenneLppBuffer[CayenneLppCursor++] = channel; | |||||
| CayenneLppBuffer[CayenneLppCursor++] = LPP_GYROMETER; | |||||
| CayenneLppBuffer[CayenneLppCursor++] = vx >> 8; | |||||
| CayenneLppBuffer[CayenneLppCursor++] = vx; | |||||
| CayenneLppBuffer[CayenneLppCursor++] = vy >> 8; | |||||
| CayenneLppBuffer[CayenneLppCursor++] = vy; | |||||
| CayenneLppBuffer[CayenneLppCursor++] = vz >> 8; | |||||
| CayenneLppBuffer[CayenneLppCursor++] = vz; | |||||
| return CayenneLppCursor; | |||||
| } | |||||
| uint8_t CayenneLppAddGps( uint8_t channel, float latitude, float longitude, float meters ) | |||||
| { | |||||
| if( ( CayenneLppCursor + LPP_GPS_SIZE ) > CAYENNE_LPP_MAXBUFFER_SIZE ) | |||||
| { | |||||
| return 0; | |||||
| } | |||||
| int32_t lat = ( int32_t ) ( latitude * 10000 ); | |||||
| int32_t lon = ( int32_t ) ( longitude * 10000 ); | |||||
| int32_t alt = ( int32_t ) ( meters * 100 ); | |||||
| CayenneLppBuffer[CayenneLppCursor++] = channel; | |||||
| CayenneLppBuffer[CayenneLppCursor++] = LPP_GPS; | |||||
| CayenneLppBuffer[CayenneLppCursor++] = lat >> 16; | |||||
| CayenneLppBuffer[CayenneLppCursor++] = lat >> 8; | |||||
| CayenneLppBuffer[CayenneLppCursor++] = lat; | |||||
| CayenneLppBuffer[CayenneLppCursor++] = lon >> 16; | |||||
| CayenneLppBuffer[CayenneLppCursor++] = lon >> 8; | |||||
| CayenneLppBuffer[CayenneLppCursor++] = lon; | |||||
| CayenneLppBuffer[CayenneLppCursor++] = alt >> 16; | |||||
| CayenneLppBuffer[CayenneLppCursor++] = alt >> 8; | |||||
| CayenneLppBuffer[CayenneLppCursor++] = alt; | |||||
| return CayenneLppCursor; | |||||
| } | |||||
| /*! | |||||
| * \file CayenneLpp.c | |||||
| * | |||||
| * \brief Implements the Cayenne Low Power Protocol | |||||
| * | |||||
| * \copyright Revised BSD License, see section \ref LICENSE. | |||||
| * | |||||
| * \code | |||||
| * ______ _ | |||||
| * / _____) _ | | | |||||
| * ( (____ _____ ____ _| |_ _____ ____| |__ | |||||
| * \____ \| ___ | (_ _) ___ |/ ___) _ \ | |||||
| * _____) ) ____| | | || |_| ____( (___| | | | | |||||
| * (______/|_____)_|_|_| \__)_____)\____)_| |_| | |||||
| * (C)2013-2018 Semtech | |||||
| * | |||||
| * \endcode | |||||
| * | |||||
| * \author Miguel Luis ( Semtech ) | |||||
| */ | |||||
| #include <stdint.h> | |||||
| #include "utilities.h" | |||||
| #include "CayenneLpp.h" | |||||
| #define CAYENNE_LPP_MAXBUFFER_SIZE 242 | |||||
| static uint8_t CayenneLppBuffer[CAYENNE_LPP_MAXBUFFER_SIZE]; | |||||
| static uint8_t CayenneLppCursor = 0; | |||||
| void CayenneLppInit( void ) | |||||
| { | |||||
| CayenneLppCursor = 0; | |||||
| } | |||||
| void CayenneLppReset( void ) | |||||
| { | |||||
| CayenneLppCursor = 0; | |||||
| } | |||||
| uint8_t CayenneLppGetSize( void ) | |||||
| { | |||||
| return CayenneLppCursor; | |||||
| } | |||||
| uint8_t* CayenneLppGetBuffer( void ) | |||||
| { | |||||
| return CayenneLppBuffer; | |||||
| } | |||||
| uint8_t CayenneLppCopy( uint8_t* dst ) | |||||
| { | |||||
| memcpy1( dst, CayenneLppBuffer, CayenneLppCursor ); | |||||
| return CayenneLppCursor; | |||||
| } | |||||
| uint8_t CayenneLppAddDigitalInput( uint8_t channel, uint8_t value ) | |||||
| { | |||||
| if( ( CayenneLppCursor + LPP_DIGITAL_INPUT_SIZE ) > CAYENNE_LPP_MAXBUFFER_SIZE ) | |||||
| { | |||||
| return 0; | |||||
| } | |||||
| CayenneLppBuffer[CayenneLppCursor++] = channel; | |||||
| CayenneLppBuffer[CayenneLppCursor++] = LPP_DIGITAL_INPUT; | |||||
| CayenneLppBuffer[CayenneLppCursor++] = value; | |||||
| return CayenneLppCursor; | |||||
| } | |||||
| uint8_t CayenneLppAddDigitalOutput( uint8_t channel, uint8_t value ) | |||||
| { | |||||
| if( ( CayenneLppCursor + LPP_DIGITAL_OUTPUT_SIZE ) > CAYENNE_LPP_MAXBUFFER_SIZE ) | |||||
| { | |||||
| return 0; | |||||
| } | |||||
| CayenneLppBuffer[CayenneLppCursor++] = channel; | |||||
| CayenneLppBuffer[CayenneLppCursor++] = LPP_DIGITAL_OUTPUT; | |||||
| CayenneLppBuffer[CayenneLppCursor++] = value; | |||||
| return CayenneLppCursor; | |||||
| } | |||||
| uint8_t CayenneLppAddAnalogInput( uint8_t channel, float value ) | |||||
| { | |||||
| if( ( CayenneLppCursor + LPP_ANALOG_INPUT_SIZE ) > CAYENNE_LPP_MAXBUFFER_SIZE ) | |||||
| { | |||||
| return 0; | |||||
| } | |||||
| int16_t val = ( int16_t ) ( value * 100 ); | |||||
| CayenneLppBuffer[CayenneLppCursor++] = channel; | |||||
| CayenneLppBuffer[CayenneLppCursor++] = LPP_ANALOG_INPUT; | |||||
| CayenneLppBuffer[CayenneLppCursor++] = val >> 8; | |||||
| CayenneLppBuffer[CayenneLppCursor++] = val; | |||||
| return CayenneLppCursor; | |||||
| } | |||||
| uint8_t CayenneLppAddAnalogOutput( uint8_t channel, float value ) | |||||
| { | |||||
| if( ( CayenneLppCursor + LPP_ANALOG_OUTPUT_SIZE ) > CAYENNE_LPP_MAXBUFFER_SIZE ) | |||||
| { | |||||
| return 0; | |||||
| } | |||||
| int16_t val = ( int16_t ) ( value * 100 ); | |||||
| CayenneLppBuffer[CayenneLppCursor++] = channel; | |||||
| CayenneLppBuffer[CayenneLppCursor++] = LPP_ANALOG_OUTPUT; | |||||
| CayenneLppBuffer[CayenneLppCursor++] = val >> 8; | |||||
| CayenneLppBuffer[CayenneLppCursor++] = val; | |||||
| return CayenneLppCursor; | |||||
| } | |||||
| uint8_t CayenneLppAddLuminosity( uint8_t channel, uint16_t lux ) | |||||
| { | |||||
| if( ( CayenneLppCursor + LPP_LUMINOSITY_SIZE ) > CAYENNE_LPP_MAXBUFFER_SIZE ) | |||||
| { | |||||
| return 0; | |||||
| } | |||||
| CayenneLppBuffer[CayenneLppCursor++] = channel; | |||||
| CayenneLppBuffer[CayenneLppCursor++] = LPP_LUMINOSITY; | |||||
| CayenneLppBuffer[CayenneLppCursor++] = lux >> 8; | |||||
| CayenneLppBuffer[CayenneLppCursor++] = lux; | |||||
| return CayenneLppCursor; | |||||
| } | |||||
| uint8_t CayenneLppAddPresence( uint8_t channel, uint8_t value ) | |||||
| { | |||||
| if( ( CayenneLppCursor + LPP_PRESENCE_SIZE ) > CAYENNE_LPP_MAXBUFFER_SIZE ) | |||||
| { | |||||
| return 0; | |||||
| } | |||||
| CayenneLppBuffer[CayenneLppCursor++] = channel; | |||||
| CayenneLppBuffer[CayenneLppCursor++] = LPP_PRESENCE; | |||||
| CayenneLppBuffer[CayenneLppCursor++] = value; | |||||
| return CayenneLppCursor; | |||||
| } | |||||
| uint8_t CayenneLppAddTemperature( uint8_t channel, float celsius ) | |||||
| { | |||||
| if( ( CayenneLppCursor + LPP_TEMPERATURE_SIZE ) > CAYENNE_LPP_MAXBUFFER_SIZE ) | |||||
| { | |||||
| return 0; | |||||
| } | |||||
| int16_t val = ( int16_t) ( celsius * 10 ); | |||||
| CayenneLppBuffer[CayenneLppCursor++] = channel; | |||||
| CayenneLppBuffer[CayenneLppCursor++] = LPP_TEMPERATURE; | |||||
| CayenneLppBuffer[CayenneLppCursor++] = val >> 8; | |||||
| CayenneLppBuffer[CayenneLppCursor++] = val; | |||||
| return CayenneLppCursor; | |||||
| } | |||||
| uint8_t CayenneLppAddRelativeHumidity( uint8_t channel, float rh ) | |||||
| { | |||||
| if( ( CayenneLppCursor + LPP_RELATIVE_HUMIDITY_SIZE ) > CAYENNE_LPP_MAXBUFFER_SIZE ) | |||||
| { | |||||
| return 0; | |||||
| } | |||||
| CayenneLppBuffer[CayenneLppCursor++] = channel; | |||||
| CayenneLppBuffer[CayenneLppCursor++] = LPP_RELATIVE_HUMIDITY; | |||||
| CayenneLppBuffer[CayenneLppCursor++] = (uint8_t ) ( rh * 2 ); | |||||
| return CayenneLppCursor; | |||||
| } | |||||
| uint8_t CayenneLppAddAccelerometer( uint8_t channel, float x, float y, float z ) | |||||
| { | |||||
| if( ( CayenneLppCursor + LPP_ACCELEROMETER_SIZE ) > CAYENNE_LPP_MAXBUFFER_SIZE ) | |||||
| { | |||||
| return 0; | |||||
| } | |||||
| int16_t vx = ( int16_t ) ( x * 1000 ); | |||||
| int16_t vy = ( int16_t ) ( y * 1000 ); | |||||
| int16_t vz = ( int16_t ) ( z * 1000 ); | |||||
| CayenneLppBuffer[CayenneLppCursor++] = channel; | |||||
| CayenneLppBuffer[CayenneLppCursor++] = LPP_ACCELEROMETER; | |||||
| CayenneLppBuffer[CayenneLppCursor++] = vx >> 8; | |||||
| CayenneLppBuffer[CayenneLppCursor++] = vx; | |||||
| CayenneLppBuffer[CayenneLppCursor++] = vy >> 8; | |||||
| CayenneLppBuffer[CayenneLppCursor++] = vy; | |||||
| CayenneLppBuffer[CayenneLppCursor++] = vz >> 8; | |||||
| CayenneLppBuffer[CayenneLppCursor++] = vz; | |||||
| return CayenneLppCursor; | |||||
| } | |||||
| uint8_t CayenneLppAddBarometricPressure( uint8_t channel, float hpa ) | |||||
| { | |||||
| if( ( CayenneLppCursor + LPP_BAROMETRIC_PRESSURE_SIZE ) > CAYENNE_LPP_MAXBUFFER_SIZE ) | |||||
| { | |||||
| return 0; | |||||
| } | |||||
| int16_t val = ( int16_t ) ( hpa * 10 ); | |||||
| CayenneLppBuffer[CayenneLppCursor++] = channel; | |||||
| CayenneLppBuffer[CayenneLppCursor++] = LPP_BAROMETRIC_PRESSURE; | |||||
| CayenneLppBuffer[CayenneLppCursor++] = val >> 8; | |||||
| CayenneLppBuffer[CayenneLppCursor++] = val; | |||||
| return CayenneLppCursor; | |||||
| } | |||||
| uint8_t CayenneLppAddGyrometer( uint8_t channel, float x, float y, float z ) | |||||
| { | |||||
| if( ( CayenneLppCursor + LPP_GYROMETER_SIZE ) > CAYENNE_LPP_MAXBUFFER_SIZE ) | |||||
| { | |||||
| return 0; | |||||
| } | |||||
| int16_t vx = ( int16_t ) ( x * 100 ); | |||||
| int16_t vy = ( int16_t ) ( y * 100 ); | |||||
| int16_t vz = ( int16_t ) ( z * 100 ); | |||||
| CayenneLppBuffer[CayenneLppCursor++] = channel; | |||||
| CayenneLppBuffer[CayenneLppCursor++] = LPP_GYROMETER; | |||||
| CayenneLppBuffer[CayenneLppCursor++] = vx >> 8; | |||||
| CayenneLppBuffer[CayenneLppCursor++] = vx; | |||||
| CayenneLppBuffer[CayenneLppCursor++] = vy >> 8; | |||||
| CayenneLppBuffer[CayenneLppCursor++] = vy; | |||||
| CayenneLppBuffer[CayenneLppCursor++] = vz >> 8; | |||||
| CayenneLppBuffer[CayenneLppCursor++] = vz; | |||||
| return CayenneLppCursor; | |||||
| } | |||||
| uint8_t CayenneLppAddGps( uint8_t channel, float latitude, float longitude, float meters ) | |||||
| { | |||||
| if( ( CayenneLppCursor + LPP_GPS_SIZE ) > CAYENNE_LPP_MAXBUFFER_SIZE ) | |||||
| { | |||||
| return 0; | |||||
| } | |||||
| int32_t lat = ( int32_t ) ( latitude * 10000 ); | |||||
| int32_t lon = ( int32_t ) ( longitude * 10000 ); | |||||
| int32_t alt = ( int32_t ) ( meters * 100 ); | |||||
| CayenneLppBuffer[CayenneLppCursor++] = channel; | |||||
| CayenneLppBuffer[CayenneLppCursor++] = LPP_GPS; | |||||
| CayenneLppBuffer[CayenneLppCursor++] = lat >> 16; | |||||
| CayenneLppBuffer[CayenneLppCursor++] = lat >> 8; | |||||
| CayenneLppBuffer[CayenneLppCursor++] = lat; | |||||
| CayenneLppBuffer[CayenneLppCursor++] = lon >> 16; | |||||
| CayenneLppBuffer[CayenneLppCursor++] = lon >> 8; | |||||
| CayenneLppBuffer[CayenneLppCursor++] = lon; | |||||
| CayenneLppBuffer[CayenneLppCursor++] = alt >> 16; | |||||
| CayenneLppBuffer[CayenneLppCursor++] = alt >> 8; | |||||
| CayenneLppBuffer[CayenneLppCursor++] = alt; | |||||
| return CayenneLppCursor; | |||||
| } | |||||
| @@ -1,76 +1,76 @@ | |||||
| /*! | |||||
| * \file CayenneLpp.h | |||||
| * | |||||
| * \brief Implements the Cayenne Low Power Protocol | |||||
| * | |||||
| * \copyright Revised BSD License, see section \ref LICENSE. | |||||
| * | |||||
| * \code | |||||
| * ______ _ | |||||
| * / _____) _ | | | |||||
| * ( (____ _____ ____ _| |_ _____ ____| |__ | |||||
| * \____ \| ___ | (_ _) ___ |/ ___) _ \ | |||||
| * _____) ) ____| | | || |_| ____( (___| | | | | |||||
| * (______/|_____)_|_|_| \__)_____)\____)_| |_| | |||||
| * (C)2013-2018 Semtech | |||||
| * | |||||
| * \endcode | |||||
| * | |||||
| * \author Miguel Luis ( Semtech ) | |||||
| */ | |||||
| #ifndef __CAYENNE_LPP_H__ | |||||
| #define __CAYENNE_LPP_H__ | |||||
| #include <stdint.h> | |||||
| #define LPP_DIGITAL_INPUT 0 // 1 byte | |||||
| #define LPP_DIGITAL_OUTPUT 1 // 1 byte | |||||
| #define LPP_ANALOG_INPUT 2 // 2 bytes, 0.01 signed | |||||
| #define LPP_ANALOG_OUTPUT 3 // 2 bytes, 0.01 signed | |||||
| #define LPP_LUMINOSITY 101 // 2 bytes, 1 lux unsigned | |||||
| #define LPP_PRESENCE 102 // 1 byte, 1 | |||||
| #define LPP_TEMPERATURE 103 // 2 bytes, 0.1°C signed | |||||
| #define LPP_RELATIVE_HUMIDITY 104 // 1 byte, 0.5% unsigned | |||||
| #define LPP_ACCELEROMETER 113 // 2 bytes per axis, 0.001G | |||||
| #define LPP_BAROMETRIC_PRESSURE 115 // 2 bytes 0.1 hPa Unsigned | |||||
| #define LPP_GYROMETER 134 // 2 bytes per axis, 0.01 °/s | |||||
| #define LPP_GPS 136 // 3 byte lon/lat 0.0001 °, 3 bytes alt 0.01m | |||||
| // Data ID + Data Type + Data Size | |||||
| #define LPP_DIGITAL_INPUT_SIZE 3 | |||||
| #define LPP_DIGITAL_OUTPUT_SIZE 3 | |||||
| #define LPP_ANALOG_INPUT_SIZE 4 | |||||
| #define LPP_ANALOG_OUTPUT_SIZE 4 | |||||
| #define LPP_LUMINOSITY_SIZE 4 | |||||
| #define LPP_PRESENCE_SIZE 3 | |||||
| #define LPP_TEMPERATURE_SIZE 4 | |||||
| #define LPP_RELATIVE_HUMIDITY_SIZE 3 | |||||
| #define LPP_ACCELEROMETER_SIZE 8 | |||||
| #define LPP_BAROMETRIC_PRESSURE_SIZE 4 | |||||
| #define LPP_GYROMETER_SIZE 8 | |||||
| #define LPP_GPS_SIZE 11 | |||||
| void CayenneLppInit( void ); | |||||
| void CayenneLppReset( void ); | |||||
| uint8_t CayenneLppGetSize( void ); | |||||
| uint8_t* CayenneLppGetBuffer( void ); | |||||
| uint8_t CayenneLppCopy( uint8_t* buffer ); | |||||
| uint8_t CayenneLppAddDigitalInput( uint8_t channel, uint8_t value ); | |||||
| uint8_t CayenneLppAddDigitalOutput( uint8_t channel, uint8_t value ); | |||||
| uint8_t CayenneLppAddAnalogInput( uint8_t channel, float value ); | |||||
| uint8_t CayenneLppAddAnalogOutput( uint8_t channel, float value ); | |||||
| uint8_t CayenneLppAddLuminosity( uint8_t channel, uint16_t lux ); | |||||
| uint8_t CayenneLppAddPresence( uint8_t channel, uint8_t value ); | |||||
| uint8_t CayenneLppAddTemperature( uint8_t channel, float celsius ); | |||||
| uint8_t CayenneLppAddRelativeHumidity( uint8_t channel, float rh ); | |||||
| uint8_t CayenneLppAddAccelerometer( uint8_t channel, float x, float y, float z ); | |||||
| uint8_t CayenneLppAddBarometricPressure( uint8_t channel, float hpa ); | |||||
| uint8_t CayenneLppAddGyrometer( uint8_t channel, float x, float y, float z ); | |||||
| uint8_t CayenneLppAddGps( uint8_t channel, float latitude, float longitude, float meters ); | |||||
| #endif // __CAYENNE_LPP_H__ | |||||
| /*! | |||||
| * \file CayenneLpp.h | |||||
| * | |||||
| * \brief Implements the Cayenne Low Power Protocol | |||||
| * | |||||
| * \copyright Revised BSD License, see section \ref LICENSE. | |||||
| * | |||||
| * \code | |||||
| * ______ _ | |||||
| * / _____) _ | | | |||||
| * ( (____ _____ ____ _| |_ _____ ____| |__ | |||||
| * \____ \| ___ | (_ _) ___ |/ ___) _ \ | |||||
| * _____) ) ____| | | || |_| ____( (___| | | | | |||||
| * (______/|_____)_|_|_| \__)_____)\____)_| |_| | |||||
| * (C)2013-2018 Semtech | |||||
| * | |||||
| * \endcode | |||||
| * | |||||
| * \author Miguel Luis ( Semtech ) | |||||
| */ | |||||
| #ifndef __CAYENNE_LPP_H__ | |||||
| #define __CAYENNE_LPP_H__ | |||||
| #include <stdint.h> | |||||
| #define LPP_DIGITAL_INPUT 0 // 1 byte | |||||
| #define LPP_DIGITAL_OUTPUT 1 // 1 byte | |||||
| #define LPP_ANALOG_INPUT 2 // 2 bytes, 0.01 signed | |||||
| #define LPP_ANALOG_OUTPUT 3 // 2 bytes, 0.01 signed | |||||
| #define LPP_LUMINOSITY 101 // 2 bytes, 1 lux unsigned | |||||
| #define LPP_PRESENCE 102 // 1 byte, 1 | |||||
| #define LPP_TEMPERATURE 103 // 2 bytes, 0.1°C signed | |||||
| #define LPP_RELATIVE_HUMIDITY 104 // 1 byte, 0.5% unsigned | |||||
| #define LPP_ACCELEROMETER 113 // 2 bytes per axis, 0.001G | |||||
| #define LPP_BAROMETRIC_PRESSURE 115 // 2 bytes 0.1 hPa Unsigned | |||||
| #define LPP_GYROMETER 134 // 2 bytes per axis, 0.01 °/s | |||||
| #define LPP_GPS 136 // 3 byte lon/lat 0.0001 °, 3 bytes alt 0.01m | |||||
| // Data ID + Data Type + Data Size | |||||
| #define LPP_DIGITAL_INPUT_SIZE 3 | |||||
| #define LPP_DIGITAL_OUTPUT_SIZE 3 | |||||
| #define LPP_ANALOG_INPUT_SIZE 4 | |||||
| #define LPP_ANALOG_OUTPUT_SIZE 4 | |||||
| #define LPP_LUMINOSITY_SIZE 4 | |||||
| #define LPP_PRESENCE_SIZE 3 | |||||
| #define LPP_TEMPERATURE_SIZE 4 | |||||
| #define LPP_RELATIVE_HUMIDITY_SIZE 3 | |||||
| #define LPP_ACCELEROMETER_SIZE 8 | |||||
| #define LPP_BAROMETRIC_PRESSURE_SIZE 4 | |||||
| #define LPP_GYROMETER_SIZE 8 | |||||
| #define LPP_GPS_SIZE 11 | |||||
| void CayenneLppInit( void ); | |||||
| void CayenneLppReset( void ); | |||||
| uint8_t CayenneLppGetSize( void ); | |||||
| uint8_t* CayenneLppGetBuffer( void ); | |||||
| uint8_t CayenneLppCopy( uint8_t* buffer ); | |||||
| uint8_t CayenneLppAddDigitalInput( uint8_t channel, uint8_t value ); | |||||
| uint8_t CayenneLppAddDigitalOutput( uint8_t channel, uint8_t value ); | |||||
| uint8_t CayenneLppAddAnalogInput( uint8_t channel, float value ); | |||||
| uint8_t CayenneLppAddAnalogOutput( uint8_t channel, float value ); | |||||
| uint8_t CayenneLppAddLuminosity( uint8_t channel, uint16_t lux ); | |||||
| uint8_t CayenneLppAddPresence( uint8_t channel, uint8_t value ); | |||||
| uint8_t CayenneLppAddTemperature( uint8_t channel, float celsius ); | |||||
| uint8_t CayenneLppAddRelativeHumidity( uint8_t channel, float rh ); | |||||
| uint8_t CayenneLppAddAccelerometer( uint8_t channel, float x, float y, float z ); | |||||
| uint8_t CayenneLppAddBarometricPressure( uint8_t channel, float hpa ); | |||||
| uint8_t CayenneLppAddGyrometer( uint8_t channel, float x, float y, float z ); | |||||
| uint8_t CayenneLppAddGps( uint8_t channel, float latitude, float longitude, float meters ); | |||||
| #endif // __CAYENNE_LPP_H__ | |||||
| @@ -1,63 +1,63 @@ | |||||
| /*! | |||||
| * \file Commissioning.h | |||||
| * | |||||
| * \brief End-device commissioning parameters | |||||
| * | |||||
| * \copyright Revised BSD License, see section \ref LICENSE. | |||||
| * | |||||
| * \code | |||||
| * ______ _ | |||||
| * / _____) _ | | | |||||
| * ( (____ _____ ____ _| |_ _____ ____| |__ | |||||
| * \____ \| ___ | (_ _) ___ |/ ___) _ \ | |||||
| * _____) ) ____| | | || |_| ____( (___| | | | | |||||
| * (______/|_____)_|_|_| \__)_____)\____)_| |_| | |||||
| * (C)2013-2020 Semtech | |||||
| * | |||||
| * \endcode | |||||
| */ | |||||
| #ifndef __COMMISSIONING_H__ | |||||
| #define __COMMISSIONING_H__ | |||||
| /*! | |||||
| ****************************************************************************** | |||||
| ********************************** WARNING *********************************** | |||||
| ****************************************************************************** | |||||
| The LoRaWAN AES128 keys are stored and provisionned on secure-elements. | |||||
| This project providdes a software emulated secure-element. | |||||
| The LoRaWAN AES128 keys SHALL be updated under | |||||
| src/peripherals/<secure-element name>-se\se-identity.h file. | |||||
| ****************************************************************************** | |||||
| ****************************************************************************** | |||||
| ****************************************************************************** | |||||
| */ | |||||
| #include "se-identity.h" | |||||
| /*! | |||||
| * When set to 1 the application uses the Over-the-Air activation procedure | |||||
| * When set to 0 the application uses the Personalization activation procedure | |||||
| */ | |||||
| #define OVER_THE_AIR_ACTIVATION 1 | |||||
| /*! | |||||
| * When using ABP activation the MAC layer must know in advance to which server | |||||
| * version it will be connected. | |||||
| */ | |||||
| #define ABP_ACTIVATION_LRWAN_VERSION_V10x 0x01000400 // 1.0.4.0 | |||||
| #define ABP_ACTIVATION_LRWAN_VERSION ABP_ACTIVATION_LRWAN_VERSION_V10x | |||||
| /*! | |||||
| * Indicates if the end-device is to be connected to a private or public network | |||||
| */ | |||||
| #define LORAWAN_PUBLIC_NETWORK true | |||||
| /*! | |||||
| * Current network ID | |||||
| */ | |||||
| #define LORAWAN_NETWORK_ID ( uint32_t )0 | |||||
| #endif // __COMMISSIONING_H__ | |||||
| /*! | |||||
| * \file Commissioning.h | |||||
| * | |||||
| * \brief End-device commissioning parameters | |||||
| * | |||||
| * \copyright Revised BSD License, see section \ref LICENSE. | |||||
| * | |||||
| * \code | |||||
| * ______ _ | |||||
| * / _____) _ | | | |||||
| * ( (____ _____ ____ _| |_ _____ ____| |__ | |||||
| * \____ \| ___ | (_ _) ___ |/ ___) _ \ | |||||
| * _____) ) ____| | | || |_| ____( (___| | | | | |||||
| * (______/|_____)_|_|_| \__)_____)\____)_| |_| | |||||
| * (C)2013-2020 Semtech | |||||
| * | |||||
| * \endcode | |||||
| */ | |||||
| #ifndef __COMMISSIONING_H__ | |||||
| #define __COMMISSIONING_H__ | |||||
| /*! | |||||
| ****************************************************************************** | |||||
| ********************************** WARNING *********************************** | |||||
| ****************************************************************************** | |||||
| The LoRaWAN AES128 keys are stored and provisionned on secure-elements. | |||||
| This project providdes a software emulated secure-element. | |||||
| The LoRaWAN AES128 keys SHALL be updated under | |||||
| src/peripherals/<secure-element name>-se\se-identity.h file. | |||||
| ****************************************************************************** | |||||
| ****************************************************************************** | |||||
| ****************************************************************************** | |||||
| */ | |||||
| #include "se-identity.h" | |||||
| /*! | |||||
| * When set to 1 the application uses the Over-the-Air activation procedure | |||||
| * When set to 0 the application uses the Personalization activation procedure | |||||
| */ | |||||
| #define OVER_THE_AIR_ACTIVATION 1 | |||||
| /*! | |||||
| * When using ABP activation the MAC layer must know in advance to which server | |||||
| * version it will be connected. | |||||
| */ | |||||
| #define ABP_ACTIVATION_LRWAN_VERSION_V10x 0x01000400 // 1.0.4.0 | |||||
| #define ABP_ACTIVATION_LRWAN_VERSION ABP_ACTIVATION_LRWAN_VERSION_V10x | |||||
| /*! | |||||
| * Indicates if the end-device is to be connected to a private or public network | |||||
| */ | |||||
| #define LORAWAN_PUBLIC_NETWORK true | |||||
| /*! | |||||
| * Current network ID | |||||
| */ | |||||
| #define LORAWAN_NETWORK_ID ( uint32_t )0 | |||||
| #endif // __COMMISSIONING_H__ | |||||
| @@ -1,349 +1,349 @@ | |||||
| /*! | |||||
| * \file LmHandler.h | |||||
| * | |||||
| * \brief Implements the LoRaMac layer handling. | |||||
| * Provides the possibility to register applicative packages. | |||||
| * | |||||
| * \remark Inspired by the examples provided on the en.i-cube_lrwan fork. | |||||
| * MCD Application Team ( STMicroelectronics International ) | |||||
| * | |||||
| * \copyright Revised BSD License, see section \ref LICENSE. | |||||
| * | |||||
| * \code | |||||
| * ______ _ | |||||
| * / _____) _ | | | |||||
| * ( (____ _____ ____ _| |_ _____ ____| |__ | |||||
| * \____ \| ___ | (_ _) ___ |/ ___) _ \ | |||||
| * _____) ) ____| | | || |_| ____( (___| | | | | |||||
| * (______/|_____)_|_|_| \__)_____)\____)_| |_| | |||||
| * (C)2013-2018 Semtech | |||||
| * | |||||
| * \endcode | |||||
| * | |||||
| * \author Miguel Luis ( Semtech ) | |||||
| */ | |||||
| #ifndef __LORAMAC_HANDLER_H__ | |||||
| #define __LORAMAC_HANDLER_H__ | |||||
| #ifdef __cplusplus | |||||
| extern "C" | |||||
| { | |||||
| #endif | |||||
| #include "LmHandlerTypes.h" | |||||
| typedef struct LmHandlerJoinParams_s | |||||
| { | |||||
| CommissioningParams_t *CommissioningParams; | |||||
| int8_t Datarate; | |||||
| LmHandlerErrorStatus_t Status; | |||||
| }LmHandlerJoinParams_t; | |||||
| typedef struct LmHandlerTxParams_s | |||||
| { | |||||
| uint8_t IsMcpsConfirm; | |||||
| LoRaMacEventInfoStatus_t Status; | |||||
| CommissioningParams_t *CommissioningParams; | |||||
| LmHandlerMsgTypes_t MsgType; | |||||
| uint8_t AckReceived; | |||||
| int8_t Datarate; | |||||
| uint32_t UplinkCounter; | |||||
| LmHandlerAppData_t AppData; | |||||
| int8_t TxPower; | |||||
| uint8_t Channel; | |||||
| }LmHandlerTxParams_t; | |||||
| typedef struct LmHandlerRxParams_s | |||||
| { | |||||
| uint8_t IsMcpsIndication; | |||||
| LoRaMacEventInfoStatus_t Status; | |||||
| CommissioningParams_t *CommissioningParams; | |||||
| int8_t Datarate; | |||||
| int8_t Rssi; | |||||
| int8_t Snr; | |||||
| uint32_t DownlinkCounter; | |||||
| int8_t RxSlot; | |||||
| }LmHandlerRxParams_t; | |||||
| typedef struct LoRaMacHandlerBeaconParams_s | |||||
| { | |||||
| LoRaMacEventInfoStatus_t Status; | |||||
| LmHandlerBeaconState_t State; | |||||
| BeaconInfo_t Info; | |||||
| }LoRaMacHandlerBeaconParams_t; | |||||
| typedef struct LmHandlerParams_s | |||||
| { | |||||
| /*! | |||||
| * Region | |||||
| */ | |||||
| LoRaMacRegion_t Region; | |||||
| /*! | |||||
| * Holds the ADR state | |||||
| */ | |||||
| bool AdrEnable; | |||||
| /*! | |||||
| * Uplink frame type | |||||
| */ | |||||
| LmHandlerMsgTypes_t IsTxConfirmed; | |||||
| /*! | |||||
| * Uplink datarate, when \ref AdrEnable is OFF | |||||
| */ | |||||
| int8_t TxDatarate; | |||||
| /*! | |||||
| * Enables/Disables a public network usage | |||||
| */ | |||||
| bool PublicNetworkEnable; | |||||
| /*! | |||||
| * LoRaWAN ETSI duty cycle control enable/disable | |||||
| * | |||||
| * \remark Please note that ETSI mandates duty cycled transmissions. Use only for test purposes | |||||
| */ | |||||
| bool DutyCycleEnabled; | |||||
| /*! | |||||
| * Application data buffer maximum size | |||||
| */ | |||||
| uint8_t DataBufferMaxSize; | |||||
| /*! | |||||
| * Application data buffer pointer | |||||
| */ | |||||
| uint8_t *DataBuffer; | |||||
| /*! | |||||
| * Class B ping-slot periodicity. | |||||
| */ | |||||
| bool PingSlotPeriodicity; | |||||
| }LmHandlerParams_t; | |||||
| typedef struct LmHandlerCallbacks_s | |||||
| { | |||||
| /*! | |||||
| * Get the current battery level | |||||
| * | |||||
| * \retval value Battery level ( 0: very low, 254: fully charged ) | |||||
| */ | |||||
| uint8_t ( *GetBatteryLevel )( void ); | |||||
| /*! | |||||
| * Get the current temperature | |||||
| * | |||||
| * \retval value Temperature in degree Celsius | |||||
| */ | |||||
| float ( *GetTemperature )( void ); | |||||
| /*! | |||||
| * Returns a pseudo random seed generated using the MCU Unique ID | |||||
| * | |||||
| * \retval seed Generated pseudo random seed | |||||
| */ | |||||
| uint32_t ( *GetRandomSeed )( void ); | |||||
| /*! | |||||
| *\brief Will be called each time a Radio IRQ is handled by the MAC | |||||
| * layer. | |||||
| * | |||||
| *\warning Runs in a IRQ context. Should only change variables state. | |||||
| */ | |||||
| void ( *OnMacProcess )( void ); | |||||
| /*! | |||||
| * Notifies the upper layer that the NVM context has changed | |||||
| * | |||||
| * \param [IN] state Indicates if we are storing (true) or | |||||
| * restoring (false) the NVM context | |||||
| * | |||||
| * \param [IN] size Number of data bytes which were stored or restored. | |||||
| */ | |||||
| void ( *OnNvmDataChange )( LmHandlerNvmContextStates_t state, uint16_t size ); | |||||
| /*! | |||||
| * Notifies the upper layer that a network parameters have been set | |||||
| * | |||||
| * \param [IN] params notification parameters | |||||
| */ | |||||
| void ( *OnNetworkParametersChange )( CommissioningParams_t *params ); | |||||
| /*! | |||||
| * Notifies the upper layer that a MCPS request has been made to the MAC layer | |||||
| * | |||||
| * \param [IN] status - Request returned status | |||||
| * \param [IN] mcpsRequest - Performed MCPS-Request. Refer to \ref McpsReq_t. | |||||
| * \param [IN] nextTxDelay - Time to wait until another TX is possible. | |||||
| */ | |||||
| void ( *OnMacMcpsRequest )( LoRaMacStatus_t status, McpsReq_t *mcpsReq, TimerTime_t nextTxDelay ); | |||||
| /*! | |||||
| * Notifies the upper layer that a MLME request has been made to the MAC layer | |||||
| * | |||||
| * \param [IN] status - Request returned status | |||||
| * \param [IN] mlmeRequest - Performed MLME-Request. Refer to \ref MlmeReq_t. | |||||
| * \param [IN] nextTxDelay - Time to wait until another TX is possible. | |||||
| */ | |||||
| void ( *OnMacMlmeRequest )( LoRaMacStatus_t status, MlmeReq_t *mlmeReq, TimerTime_t nextTxDelay ); | |||||
| /*! | |||||
| * Notifies the upper layer that a network has been joined | |||||
| * | |||||
| * \param [IN] params notification parameters | |||||
| */ | |||||
| void ( *OnJoinRequest )( LmHandlerJoinParams_t *params ); | |||||
| /*! | |||||
| * Notifies upper layer that a frame has been transmitted | |||||
| * | |||||
| * \param [IN] params notification parameters | |||||
| */ | |||||
| void ( *OnTxData )( LmHandlerTxParams_t *params ); | |||||
| /*! | |||||
| * Notifies the upper layer that an applicative frame has been received | |||||
| * | |||||
| * \param [IN] appData Received applicative data | |||||
| * \param [IN] params notification parameters | |||||
| */ | |||||
| void ( *OnRxData )( LmHandlerAppData_t *appData, LmHandlerRxParams_t *params ); | |||||
| /*! | |||||
| * Confirms the LoRaWAN device class change | |||||
| * | |||||
| * \param [IN] deviceClass New end-device class | |||||
| */ | |||||
| void ( *OnClassChange )( DeviceClass_t deviceClass ); | |||||
| /*! | |||||
| * Notifies the upper layer that the beacon status has changed | |||||
| * | |||||
| * \param [IN] params notification parameters | |||||
| */ | |||||
| void ( *OnBeaconStatusChange )( LoRaMacHandlerBeaconParams_t *params ); | |||||
| #if( LMH_SYS_TIME_UPDATE_NEW_API == 1 ) | |||||
| /*! | |||||
| * Notifies the upper layer that the system time has been updated. | |||||
| * | |||||
| * \param [in] isSynchronized Indicates if the system time is synchronized in the range +/-1 second | |||||
| * \param [in] timeCorrection Received time correction value | |||||
| */ | |||||
| void ( *OnSysTimeUpdate )( bool isSynchronized, int32_t timeCorrection ); | |||||
| #else | |||||
| /*! | |||||
| * Notifies the upper layer that the system time has been updated. | |||||
| */ | |||||
| void ( *OnSysTimeUpdate )( void ); | |||||
| #endif | |||||
| }LmHandlerCallbacks_t; | |||||
| /*! | |||||
| * LoRaMac handler initialisation | |||||
| * | |||||
| * \param [IN] callbacks LoRaMac handler callbacks | |||||
| * \param [IN] handlerParams LoRaMac handler parameters | |||||
| * | |||||
| * \retval none | |||||
| */ | |||||
| LmHandlerErrorStatus_t LmHandlerInit( LmHandlerCallbacks_t *callbacks, | |||||
| LmHandlerParams_t *handlerParams ); | |||||
| /*! | |||||
| * Indicates if the LoRaMacHandler is busy | |||||
| * | |||||
| * \retval status [true] Busy, [false] free | |||||
| */ | |||||
| bool LmHandlerIsBusy( void ); | |||||
| /*! | |||||
| * Processes the LoRaMac and Radio events. | |||||
| * When no pendig operation asks to go in low power mode. | |||||
| * | |||||
| * \remark This function must be called in the main loop. | |||||
| */ | |||||
| void LmHandlerProcess( void ); | |||||
| /*! | |||||
| * Gets current duty-cycle wait time | |||||
| * | |||||
| * \retval time to wait in ms | |||||
| */ | |||||
| TimerTime_t LmHandlerGetDutyCycleWaitTime( void ); | |||||
| /*! | |||||
| * Instructs the MAC layer to send a ClassA uplink | |||||
| * | |||||
| * \param [IN] appData Data to be sent | |||||
| * \param [IN] isTxConfirmed Indicates if the uplink requires an acknowledgement | |||||
| * | |||||
| * \retval status Returns \ref LORAMAC_HANDLER_SUCCESS if request has been | |||||
| * processed else \ref LORAMAC_HANDLER_ERROR | |||||
| */ | |||||
| LmHandlerErrorStatus_t LmHandlerSend( LmHandlerAppData_t *appData, LmHandlerMsgTypes_t isTxConfirmed ); | |||||
| /*! | |||||
| * Join a LoRa Network in classA | |||||
| * | |||||
| * \Note if the device is ABP, this is a pass through function | |||||
| */ | |||||
| void LmHandlerJoin( void ); | |||||
| /*! | |||||
| * Check whether the Device is joined to the network | |||||
| * | |||||
| * \param [IN] none | |||||
| * | |||||
| * \retval status Returns \ref LORAMAC_HANDLER_SET if joined else \ref LORAMAC_HANDLER_RESET | |||||
| */ | |||||
| LmHandlerFlagStatus_t LmHandlerJoinStatus( void ); | |||||
| /*! | |||||
| * Informs the server on the ping-slot periodicity to use | |||||
| * | |||||
| * \param [IN] periodicity Is equal to 2^periodicity seconds. | |||||
| * Example: 2^3 = 8 seconds. The end-device will open an Rx slot every 8 seconds. | |||||
| * | |||||
| * \retval status Returns \ref LORAMAC_HANDLER_SUCCESS if request has been | |||||
| * processed else \ref LORAMAC_HANDLER_ERROR | |||||
| */ | |||||
| LmHandlerErrorStatus_t LmHandlerPingSlotReq( uint8_t periodicity ); | |||||
| /*! | |||||
| * Request the MAC layer to change LoRaWAN class | |||||
| * | |||||
| * \Note Callback \ref LmHandlerConfirmClass informs upper layer that the change has occurred | |||||
| * \Note Only switch from class A to class B/C OR from class B/C to class A is allowed | |||||
| * | |||||
| * \param [IN] newClass New class to be requested | |||||
| * | |||||
| * \retval status Returns \ref LORAMAC_HANDLER_SUCCESS if request has been | |||||
| * processed else \ref LORAMAC_HANDLER_ERROR | |||||
| */ | |||||
| LmHandlerErrorStatus_t LmHandlerRequestClass( DeviceClass_t newClass ); | |||||
| /*! | |||||
| * Gets the current LoRaWAN class | |||||
| * | |||||
| * \retval currentClass Current LoRaWAN class | |||||
| */ | |||||
| DeviceClass_t LmHandlerGetCurrentClass( void ); | |||||
| /*! | |||||
| * Gets the current datarate | |||||
| * | |||||
| * \retval currentDatarate Current datarate | |||||
| */ | |||||
| int8_t LmHandlerGetCurrentDatarate( void ); | |||||
| /*! | |||||
| * Gets the current active region | |||||
| * | |||||
| * \retval currentRegion Current active region | |||||
| */ | |||||
| LoRaMacRegion_t LmHandlerGetActiveRegion( void ); | |||||
| /*! | |||||
| * Set system maximum tolerated rx error in milliseconds | |||||
| * | |||||
| * \param [IN] maxErrorInMs Maximum tolerated error in milliseconds | |||||
| * | |||||
| * \retval status Returns \ref LORAMAC_HANDLER_SUCCESS if request has been | |||||
| * processed else \ref LORAMAC_HANDLER_ERROR | |||||
| */ | |||||
| LmHandlerErrorStatus_t LmHandlerSetSystemMaxRxError( uint32_t maxErrorInMs ); | |||||
| /* | |||||
| *============================================================================= | |||||
| * PACKAGES HANDLING | |||||
| *============================================================================= | |||||
| */ | |||||
| LmHandlerErrorStatus_t LmHandlerPackageRegister( uint8_t id, void *params ); | |||||
| bool LmHandlerPackageIsInitialized( uint8_t id ); | |||||
| #ifdef __cplusplus | |||||
| } | |||||
| #endif | |||||
| #endif // __LORAMAC_HANDLER_H__ | |||||
| /*! | |||||
| * \file LmHandler.h | |||||
| * | |||||
| * \brief Implements the LoRaMac layer handling. | |||||
| * Provides the possibility to register applicative packages. | |||||
| * | |||||
| * \remark Inspired by the examples provided on the en.i-cube_lrwan fork. | |||||
| * MCD Application Team ( STMicroelectronics International ) | |||||
| * | |||||
| * \copyright Revised BSD License, see section \ref LICENSE. | |||||
| * | |||||
| * \code | |||||
| * ______ _ | |||||
| * / _____) _ | | | |||||
| * ( (____ _____ ____ _| |_ _____ ____| |__ | |||||
| * \____ \| ___ | (_ _) ___ |/ ___) _ \ | |||||
| * _____) ) ____| | | || |_| ____( (___| | | | | |||||
| * (______/|_____)_|_|_| \__)_____)\____)_| |_| | |||||
| * (C)2013-2018 Semtech | |||||
| * | |||||
| * \endcode | |||||
| * | |||||
| * \author Miguel Luis ( Semtech ) | |||||
| */ | |||||
| #ifndef __LORAMAC_HANDLER_H__ | |||||
| #define __LORAMAC_HANDLER_H__ | |||||
| #ifdef __cplusplus | |||||
| extern "C" | |||||
| { | |||||
| #endif | |||||
| #include "LmHandlerTypes.h" | |||||
| typedef struct LmHandlerJoinParams_s | |||||
| { | |||||
| CommissioningParams_t *CommissioningParams; | |||||
| int8_t Datarate; | |||||
| LmHandlerErrorStatus_t Status; | |||||
| }LmHandlerJoinParams_t; | |||||
| typedef struct LmHandlerTxParams_s | |||||
| { | |||||
| uint8_t IsMcpsConfirm; | |||||
| LoRaMacEventInfoStatus_t Status; | |||||
| CommissioningParams_t *CommissioningParams; | |||||
| LmHandlerMsgTypes_t MsgType; | |||||
| uint8_t AckReceived; | |||||
| int8_t Datarate; | |||||
| uint32_t UplinkCounter; | |||||
| LmHandlerAppData_t AppData; | |||||
| int8_t TxPower; | |||||
| uint8_t Channel; | |||||
| }LmHandlerTxParams_t; | |||||
| typedef struct LmHandlerRxParams_s | |||||
| { | |||||
| uint8_t IsMcpsIndication; | |||||
| LoRaMacEventInfoStatus_t Status; | |||||
| CommissioningParams_t *CommissioningParams; | |||||
| int8_t Datarate; | |||||
| int8_t Rssi; | |||||
| int8_t Snr; | |||||
| uint32_t DownlinkCounter; | |||||
| int8_t RxSlot; | |||||
| }LmHandlerRxParams_t; | |||||
| typedef struct LoRaMacHandlerBeaconParams_s | |||||
| { | |||||
| LoRaMacEventInfoStatus_t Status; | |||||
| LmHandlerBeaconState_t State; | |||||
| BeaconInfo_t Info; | |||||
| }LoRaMacHandlerBeaconParams_t; | |||||
| typedef struct LmHandlerParams_s | |||||
| { | |||||
| /*! | |||||
| * Region | |||||
| */ | |||||
| LoRaMacRegion_t Region; | |||||
| /*! | |||||
| * Holds the ADR state | |||||
| */ | |||||
| bool AdrEnable; | |||||
| /*! | |||||
| * Uplink frame type | |||||
| */ | |||||
| LmHandlerMsgTypes_t IsTxConfirmed; | |||||
| /*! | |||||
| * Uplink datarate, when \ref AdrEnable is OFF | |||||
| */ | |||||
| int8_t TxDatarate; | |||||
| /*! | |||||
| * Enables/Disables a public network usage | |||||
| */ | |||||
| bool PublicNetworkEnable; | |||||
| /*! | |||||
| * LoRaWAN ETSI duty cycle control enable/disable | |||||
| * | |||||
| * \remark Please note that ETSI mandates duty cycled transmissions. Use only for test purposes | |||||
| */ | |||||
| bool DutyCycleEnabled; | |||||
| /*! | |||||
| * Application data buffer maximum size | |||||
| */ | |||||
| uint8_t DataBufferMaxSize; | |||||
| /*! | |||||
| * Application data buffer pointer | |||||
| */ | |||||
| uint8_t *DataBuffer; | |||||
| /*! | |||||
| * Class B ping-slot periodicity. | |||||
| */ | |||||
| bool PingSlotPeriodicity; | |||||
| }LmHandlerParams_t; | |||||
| typedef struct LmHandlerCallbacks_s | |||||
| { | |||||
| /*! | |||||
| * Get the current battery level | |||||
| * | |||||
| * \retval value Battery level ( 0: very low, 254: fully charged ) | |||||
| */ | |||||
| uint8_t ( *GetBatteryLevel )( void ); | |||||
| /*! | |||||
| * Get the current temperature | |||||
| * | |||||
| * \retval value Temperature in degree Celsius | |||||
| */ | |||||
| float ( *GetTemperature )( void ); | |||||
| /*! | |||||
| * Returns a pseudo random seed generated using the MCU Unique ID | |||||
| * | |||||
| * \retval seed Generated pseudo random seed | |||||
| */ | |||||
| uint32_t ( *GetRandomSeed )( void ); | |||||
| /*! | |||||
| *\brief Will be called each time a Radio IRQ is handled by the MAC | |||||
| * layer. | |||||
| * | |||||
| *\warning Runs in a IRQ context. Should only change variables state. | |||||
| */ | |||||
| void ( *OnMacProcess )( void ); | |||||
| /*! | |||||
| * Notifies the upper layer that the NVM context has changed | |||||
| * | |||||
| * \param [IN] state Indicates if we are storing (true) or | |||||
| * restoring (false) the NVM context | |||||
| * | |||||
| * \param [IN] size Number of data bytes which were stored or restored. | |||||
| */ | |||||
| void ( *OnNvmDataChange )( LmHandlerNvmContextStates_t state, uint16_t size ); | |||||
| /*! | |||||
| * Notifies the upper layer that a network parameters have been set | |||||
| * | |||||
| * \param [IN] params notification parameters | |||||
| */ | |||||
| void ( *OnNetworkParametersChange )( CommissioningParams_t *params ); | |||||
| /*! | |||||
| * Notifies the upper layer that a MCPS request has been made to the MAC layer | |||||
| * | |||||
| * \param [IN] status - Request returned status | |||||
| * \param [IN] mcpsRequest - Performed MCPS-Request. Refer to \ref McpsReq_t. | |||||
| * \param [IN] nextTxDelay - Time to wait until another TX is possible. | |||||
| */ | |||||
| void ( *OnMacMcpsRequest )( LoRaMacStatus_t status, McpsReq_t *mcpsReq, TimerTime_t nextTxDelay ); | |||||
| /*! | |||||
| * Notifies the upper layer that a MLME request has been made to the MAC layer | |||||
| * | |||||
| * \param [IN] status - Request returned status | |||||
| * \param [IN] mlmeRequest - Performed MLME-Request. Refer to \ref MlmeReq_t. | |||||
| * \param [IN] nextTxDelay - Time to wait until another TX is possible. | |||||
| */ | |||||
| void ( *OnMacMlmeRequest )( LoRaMacStatus_t status, MlmeReq_t *mlmeReq, TimerTime_t nextTxDelay ); | |||||
| /*! | |||||
| * Notifies the upper layer that a network has been joined | |||||
| * | |||||
| * \param [IN] params notification parameters | |||||
| */ | |||||
| void ( *OnJoinRequest )( LmHandlerJoinParams_t *params ); | |||||
| /*! | |||||
| * Notifies upper layer that a frame has been transmitted | |||||
| * | |||||
| * \param [IN] params notification parameters | |||||
| */ | |||||
| void ( *OnTxData )( LmHandlerTxParams_t *params ); | |||||
| /*! | |||||
| * Notifies the upper layer that an applicative frame has been received | |||||
| * | |||||
| * \param [IN] appData Received applicative data | |||||
| * \param [IN] params notification parameters | |||||
| */ | |||||
| void ( *OnRxData )( LmHandlerAppData_t *appData, LmHandlerRxParams_t *params ); | |||||
| /*! | |||||
| * Confirms the LoRaWAN device class change | |||||
| * | |||||
| * \param [IN] deviceClass New end-device class | |||||
| */ | |||||
| void ( *OnClassChange )( DeviceClass_t deviceClass ); | |||||
| /*! | |||||
| * Notifies the upper layer that the beacon status has changed | |||||
| * | |||||
| * \param [IN] params notification parameters | |||||
| */ | |||||
| void ( *OnBeaconStatusChange )( LoRaMacHandlerBeaconParams_t *params ); | |||||
| #if( LMH_SYS_TIME_UPDATE_NEW_API == 1 ) | |||||
| /*! | |||||
| * Notifies the upper layer that the system time has been updated. | |||||
| * | |||||
| * \param [in] isSynchronized Indicates if the system time is synchronized in the range +/-1 second | |||||
| * \param [in] timeCorrection Received time correction value | |||||
| */ | |||||
| void ( *OnSysTimeUpdate )( bool isSynchronized, int32_t timeCorrection ); | |||||
| #else | |||||
| /*! | |||||
| * Notifies the upper layer that the system time has been updated. | |||||
| */ | |||||
| void ( *OnSysTimeUpdate )( void ); | |||||
| #endif | |||||
| }LmHandlerCallbacks_t; | |||||
| /*! | |||||
| * LoRaMac handler initialisation | |||||
| * | |||||
| * \param [IN] callbacks LoRaMac handler callbacks | |||||
| * \param [IN] handlerParams LoRaMac handler parameters | |||||
| * | |||||
| * \retval none | |||||
| */ | |||||
| LmHandlerErrorStatus_t LmHandlerInit( LmHandlerCallbacks_t *callbacks, | |||||
| LmHandlerParams_t *handlerParams ); | |||||
| /*! | |||||
| * Indicates if the LoRaMacHandler is busy | |||||
| * | |||||
| * \retval status [true] Busy, [false] free | |||||
| */ | |||||
| bool LmHandlerIsBusy( void ); | |||||
| /*! | |||||
| * Processes the LoRaMac and Radio events. | |||||
| * When no pendig operation asks to go in low power mode. | |||||
| * | |||||
| * \remark This function must be called in the main loop. | |||||
| */ | |||||
| void LmHandlerProcess( void ); | |||||
| /*! | |||||
| * Gets current duty-cycle wait time | |||||
| * | |||||
| * \retval time to wait in ms | |||||
| */ | |||||
| TimerTime_t LmHandlerGetDutyCycleWaitTime( void ); | |||||
| /*! | |||||
| * Instructs the MAC layer to send a ClassA uplink | |||||
| * | |||||
| * \param [IN] appData Data to be sent | |||||
| * \param [IN] isTxConfirmed Indicates if the uplink requires an acknowledgement | |||||
| * | |||||
| * \retval status Returns \ref LORAMAC_HANDLER_SUCCESS if request has been | |||||
| * processed else \ref LORAMAC_HANDLER_ERROR | |||||
| */ | |||||
| LmHandlerErrorStatus_t LmHandlerSend( LmHandlerAppData_t *appData, LmHandlerMsgTypes_t isTxConfirmed ); | |||||
| /*! | |||||
| * Join a LoRa Network in classA | |||||
| * | |||||
| * \Note if the device is ABP, this is a pass through function | |||||
| */ | |||||
| void LmHandlerJoin( void ); | |||||
| /*! | |||||
| * Check whether the Device is joined to the network | |||||
| * | |||||
| * \param [IN] none | |||||
| * | |||||
| * \retval status Returns \ref LORAMAC_HANDLER_SET if joined else \ref LORAMAC_HANDLER_RESET | |||||
| */ | |||||
| LmHandlerFlagStatus_t LmHandlerJoinStatus( void ); | |||||
| /*! | |||||
| * Informs the server on the ping-slot periodicity to use | |||||
| * | |||||
| * \param [IN] periodicity Is equal to 2^periodicity seconds. | |||||
| * Example: 2^3 = 8 seconds. The end-device will open an Rx slot every 8 seconds. | |||||
| * | |||||
| * \retval status Returns \ref LORAMAC_HANDLER_SUCCESS if request has been | |||||
| * processed else \ref LORAMAC_HANDLER_ERROR | |||||
| */ | |||||
| LmHandlerErrorStatus_t LmHandlerPingSlotReq( uint8_t periodicity ); | |||||
| /*! | |||||
| * Request the MAC layer to change LoRaWAN class | |||||
| * | |||||
| * \Note Callback \ref LmHandlerConfirmClass informs upper layer that the change has occurred | |||||
| * \Note Only switch from class A to class B/C OR from class B/C to class A is allowed | |||||
| * | |||||
| * \param [IN] newClass New class to be requested | |||||
| * | |||||
| * \retval status Returns \ref LORAMAC_HANDLER_SUCCESS if request has been | |||||
| * processed else \ref LORAMAC_HANDLER_ERROR | |||||
| */ | |||||
| LmHandlerErrorStatus_t LmHandlerRequestClass( DeviceClass_t newClass ); | |||||
| /*! | |||||
| * Gets the current LoRaWAN class | |||||
| * | |||||
| * \retval currentClass Current LoRaWAN class | |||||
| */ | |||||
| DeviceClass_t LmHandlerGetCurrentClass( void ); | |||||
| /*! | |||||
| * Gets the current datarate | |||||
| * | |||||
| * \retval currentDatarate Current datarate | |||||
| */ | |||||
| int8_t LmHandlerGetCurrentDatarate( void ); | |||||
| /*! | |||||
| * Gets the current active region | |||||
| * | |||||
| * \retval currentRegion Current active region | |||||
| */ | |||||
| LoRaMacRegion_t LmHandlerGetActiveRegion( void ); | |||||
| /*! | |||||
| * Set system maximum tolerated rx error in milliseconds | |||||
| * | |||||
| * \param [IN] maxErrorInMs Maximum tolerated error in milliseconds | |||||
| * | |||||
| * \retval status Returns \ref LORAMAC_HANDLER_SUCCESS if request has been | |||||
| * processed else \ref LORAMAC_HANDLER_ERROR | |||||
| */ | |||||
| LmHandlerErrorStatus_t LmHandlerSetSystemMaxRxError( uint32_t maxErrorInMs ); | |||||
| /* | |||||
| *============================================================================= | |||||
| * PACKAGES HANDLING | |||||
| *============================================================================= | |||||
| */ | |||||
| LmHandlerErrorStatus_t LmHandlerPackageRegister( uint8_t id, void *params ); | |||||
| bool LmHandlerPackageIsInitialized( uint8_t id ); | |||||
| #ifdef __cplusplus | |||||
| } | |||||
| #endif | |||||
| #endif // __LORAMAC_HANDLER_H__ | |||||
| @@ -1,124 +1,124 @@ | |||||
| /*! | |||||
| * \file LmHandlerTypes.h | |||||
| * | |||||
| * \brief Defines the types used by LmHandler | |||||
| * | |||||
| * \copyright Revised BSD License, see section \ref LICENSE. | |||||
| * | |||||
| * \code | |||||
| * ______ _ | |||||
| * / _____) _ | | | |||||
| * ( (____ _____ ____ _| |_ _____ ____| |__ | |||||
| * \____ \| ___ | (_ _) ___ |/ ___) _ \ | |||||
| * _____) ) ____| | | || |_| ____( (___| | | | | |||||
| * (______/|_____)_|_|_| \__)_____)\____)_| |_| | |||||
| * (C)2013-2018 Semtech | |||||
| * | |||||
| * \endcode | |||||
| * | |||||
| * \author Miguel Luis ( Semtech ) | |||||
| */ | |||||
| #ifndef __LORAMAC_HANDLER_TYPES_H__ | |||||
| #define __LORAMAC_HANDLER_TYPES_H__ | |||||
| #include "LoRaMac.h" | |||||
| /*! | |||||
| * If set to 1 the new API defining \ref OnSysTimeUpdate callback is used. | |||||
| */ | |||||
| #define LMH_SYS_TIME_UPDATE_NEW_API 1 | |||||
| /*! | |||||
| * | |||||
| */ | |||||
| typedef enum | |||||
| { | |||||
| LORAMAC_HANDLER_ADR_OFF = 0, | |||||
| LORAMAC_HANDLER_ADR_ON = !LORAMAC_HANDLER_ADR_OFF | |||||
| }LmHandlerAdrStates_t; | |||||
| /*! | |||||
| * | |||||
| */ | |||||
| typedef enum | |||||
| { | |||||
| LORAMAC_HANDLER_RESET = 0, | |||||
| LORAMAC_HANDLER_SET = !LORAMAC_HANDLER_RESET | |||||
| }LmHandlerFlagStatus_t; | |||||
| /*! | |||||
| * | |||||
| */ | |||||
| typedef enum | |||||
| { | |||||
| LORAMAC_HANDLER_ERROR = -1, | |||||
| LORAMAC_HANDLER_SUCCESS = 0 | |||||
| }LmHandlerErrorStatus_t; | |||||
| /*! | |||||
| * | |||||
| */ | |||||
| typedef enum | |||||
| { | |||||
| LORAMAC_HANDLER_UNCONFIRMED_MSG = 0, | |||||
| LORAMAC_HANDLER_CONFIRMED_MSG = !LORAMAC_HANDLER_UNCONFIRMED_MSG | |||||
| }LmHandlerMsgTypes_t; | |||||
| /*! | |||||
| * | |||||
| */ | |||||
| typedef enum | |||||
| { | |||||
| LORAMAC_HANDLER_FALSE = 0, | |||||
| LORAMAC_HANDLER_TRUE = !LORAMAC_HANDLER_FALSE | |||||
| }LmHandlerBoolean_t; | |||||
| typedef enum | |||||
| { | |||||
| LORAMAC_HANDLER_BEACON_ACQUIRING, | |||||
| LORAMAC_HANDLER_BEACON_LOST, | |||||
| LORAMAC_HANDLER_BEACON_RX, | |||||
| LORAMAC_HANDLER_BEACON_NRX | |||||
| }LmHandlerBeaconState_t; | |||||
| typedef enum | |||||
| { | |||||
| LORAMAC_HANDLER_NVM_RESTORE, | |||||
| LORAMAC_HANDLER_NVM_STORE, | |||||
| }LmHandlerNvmContextStates_t; | |||||
| /*! | |||||
| * Commissioning parameters | |||||
| */ | |||||
| typedef struct CommissioningParams_s | |||||
| { | |||||
| bool IsOtaaActivation; | |||||
| uint8_t DevEui[8]; | |||||
| uint8_t JoinEui[8]; | |||||
| uint8_t SePin[4]; | |||||
| uint32_t NetworkId; | |||||
| uint32_t DevAddr; | |||||
| }CommissioningParams_t; | |||||
| /*! | |||||
| * Application data structure | |||||
| */ | |||||
| typedef struct LmHandlerAppData_s | |||||
| { | |||||
| uint8_t Port; | |||||
| uint8_t BufferSize; | |||||
| uint8_t *Buffer; | |||||
| }LmHandlerAppData_t; | |||||
| typedef struct LmHandlerRequestParams_s | |||||
| { | |||||
| uint8_t IsMcpsRequest; | |||||
| LoRaMacStatus_t Status; | |||||
| union | |||||
| { | |||||
| Mcps_t Mcps; | |||||
| Mlme_t Mlme; | |||||
| }RequestType; | |||||
| }LmHandlerRequestParams_t; | |||||
| #endif // __LORAMAC_HANDLER_TYPES_H__ | |||||
| /*! | |||||
| * \file LmHandlerTypes.h | |||||
| * | |||||
| * \brief Defines the types used by LmHandler | |||||
| * | |||||
| * \copyright Revised BSD License, see section \ref LICENSE. | |||||
| * | |||||
| * \code | |||||
| * ______ _ | |||||
| * / _____) _ | | | |||||
| * ( (____ _____ ____ _| |_ _____ ____| |__ | |||||
| * \____ \| ___ | (_ _) ___ |/ ___) _ \ | |||||
| * _____) ) ____| | | || |_| ____( (___| | | | | |||||
| * (______/|_____)_|_|_| \__)_____)\____)_| |_| | |||||
| * (C)2013-2018 Semtech | |||||
| * | |||||
| * \endcode | |||||
| * | |||||
| * \author Miguel Luis ( Semtech ) | |||||
| */ | |||||
| #ifndef __LORAMAC_HANDLER_TYPES_H__ | |||||
| #define __LORAMAC_HANDLER_TYPES_H__ | |||||
| #include "LoRaMac.h" | |||||
| /*! | |||||
| * If set to 1 the new API defining \ref OnSysTimeUpdate callback is used. | |||||
| */ | |||||
| #define LMH_SYS_TIME_UPDATE_NEW_API 1 | |||||
| /*! | |||||
| * | |||||
| */ | |||||
| typedef enum | |||||
| { | |||||
| LORAMAC_HANDLER_ADR_OFF = 0, | |||||
| LORAMAC_HANDLER_ADR_ON = !LORAMAC_HANDLER_ADR_OFF | |||||
| }LmHandlerAdrStates_t; | |||||
| /*! | |||||
| * | |||||
| */ | |||||
| typedef enum | |||||
| { | |||||
| LORAMAC_HANDLER_RESET = 0, | |||||
| LORAMAC_HANDLER_SET = !LORAMAC_HANDLER_RESET | |||||
| }LmHandlerFlagStatus_t; | |||||
| /*! | |||||
| * | |||||
| */ | |||||
| typedef enum | |||||
| { | |||||
| LORAMAC_HANDLER_ERROR = -1, | |||||
| LORAMAC_HANDLER_SUCCESS = 0 | |||||
| }LmHandlerErrorStatus_t; | |||||
| /*! | |||||
| * | |||||
| */ | |||||
| typedef enum | |||||
| { | |||||
| LORAMAC_HANDLER_UNCONFIRMED_MSG = 0, | |||||
| LORAMAC_HANDLER_CONFIRMED_MSG = !LORAMAC_HANDLER_UNCONFIRMED_MSG | |||||
| }LmHandlerMsgTypes_t; | |||||
| /*! | |||||
| * | |||||
| */ | |||||
| typedef enum | |||||
| { | |||||
| LORAMAC_HANDLER_FALSE = 0, | |||||
| LORAMAC_HANDLER_TRUE = !LORAMAC_HANDLER_FALSE | |||||
| }LmHandlerBoolean_t; | |||||
| typedef enum | |||||
| { | |||||
| LORAMAC_HANDLER_BEACON_ACQUIRING, | |||||
| LORAMAC_HANDLER_BEACON_LOST, | |||||
| LORAMAC_HANDLER_BEACON_RX, | |||||
| LORAMAC_HANDLER_BEACON_NRX | |||||
| }LmHandlerBeaconState_t; | |||||
| typedef enum | |||||
| { | |||||
| LORAMAC_HANDLER_NVM_RESTORE, | |||||
| LORAMAC_HANDLER_NVM_STORE, | |||||
| }LmHandlerNvmContextStates_t; | |||||
| /*! | |||||
| * Commissioning parameters | |||||
| */ | |||||
| typedef struct CommissioningParams_s | |||||
| { | |||||
| bool IsOtaaActivation; | |||||
| uint8_t DevEui[8]; | |||||
| uint8_t JoinEui[8]; | |||||
| uint8_t SePin[4]; | |||||
| uint32_t NetworkId; | |||||
| uint32_t DevAddr; | |||||
| }CommissioningParams_t; | |||||
| /*! | |||||
| * Application data structure | |||||
| */ | |||||
| typedef struct LmHandlerAppData_s | |||||
| { | |||||
| uint8_t Port; | |||||
| uint8_t BufferSize; | |||||
| uint8_t *Buffer; | |||||
| }LmHandlerAppData_t; | |||||
| typedef struct LmHandlerRequestParams_s | |||||
| { | |||||
| uint8_t IsMcpsRequest; | |||||
| LoRaMacStatus_t Status; | |||||
| union | |||||
| { | |||||
| Mcps_t Mcps; | |||||
| Mlme_t Mlme; | |||||
| }RequestType; | |||||
| }LmHandlerRequestParams_t; | |||||
| #endif // __LORAMAC_HANDLER_TYPES_H__ | |||||
| @@ -1,143 +1,143 @@ | |||||
| /*! | |||||
| * \file FragDecoder.h | |||||
| * | |||||
| * \brief Implements the LoRa-Alliance fragmentation decoder | |||||
| * Specification: https://lora-alliance.org/sites/default/files/2018-09/fragmented_data_block_transport_v1.0.0.pdf | |||||
| * | |||||
| * \copyright Revised BSD License, see section \ref LICENSE. | |||||
| * | |||||
| * \code | |||||
| * ______ _ | |||||
| * / _____) _ | | | |||||
| * ( (____ _____ ____ _| |_ _____ ____| |__ | |||||
| * \____ \| ___ | (_ _) ___ |/ ___) _ \ | |||||
| * _____) ) ____| | | || |_| ____( (___| | | | | |||||
| * (______/|_____)_|_|_| \__)_____)\____)_| |_| | |||||
| * (C)2013-2018 Semtech | |||||
| * | |||||
| * \endcode | |||||
| * | |||||
| * \author Fabien Holin ( Semtech ) | |||||
| * \author Miguel Luis ( Semtech ) | |||||
| */ | |||||
| #ifndef __FRAG_DECODER_H__ | |||||
| #define __FRAG_DECODER_H__ | |||||
| #include <stdint.h> | |||||
| /*! | |||||
| * If set to 1 the new API defining \ref FragDecoderWrite and | |||||
| * \ref FragDecoderReadfunction callbacks is used. | |||||
| */ | |||||
| #define FRAG_DECODER_FILE_HANDLING_NEW_API 1 | |||||
| /*! | |||||
| * Maximum number of fragment that can be handled. | |||||
| * | |||||
| * \remark This parameter has an impact on the memory footprint. | |||||
| */ | |||||
| #define FRAG_MAX_NB 21 | |||||
| /*! | |||||
| * Maximum fragment size that can be handled. | |||||
| * | |||||
| * \remark This parameter has an impact on the memory footprint. | |||||
| */ | |||||
| #define FRAG_MAX_SIZE 50 | |||||
| /*! | |||||
| * Maximum number of extra frames that can be handled. | |||||
| * | |||||
| * \remark This parameter has an impact on the memory footprint. | |||||
| */ | |||||
| #define FRAG_MAX_REDUNDANCY 5 | |||||
| #define FRAG_SESSION_FINISHED ( int32_t )0 | |||||
| #define FRAG_SESSION_NOT_STARTED ( int32_t )-2 | |||||
| #define FRAG_SESSION_ONGOING ( int32_t )-1 | |||||
| typedef struct sFragDecoderStatus | |||||
| { | |||||
| uint16_t FragNbRx; | |||||
| uint16_t FragNbLost; | |||||
| uint16_t FragNbLastRx; | |||||
| uint8_t MatrixError; | |||||
| }FragDecoderStatus_t; | |||||
| #if( FRAG_DECODER_FILE_HANDLING_NEW_API == 1 ) | |||||
| typedef struct sFragDecoderCallbacks | |||||
| { | |||||
| /*! | |||||
| * Writes `data` buffer of `size` starting at address `addr` | |||||
| * | |||||
| * \param [IN] addr Address start index to write to. | |||||
| * \param [IN] data Data buffer to be written. | |||||
| * \param [IN] size Size of data buffer to be written. | |||||
| * | |||||
| * \retval status Write operation status [0: Success, -1 Fail] | |||||
| */ | |||||
| int8_t ( *FragDecoderWrite )( uint32_t addr, uint8_t *data, uint32_t size ); | |||||
| /*! | |||||
| * Reads `data` buffer of `size` starting at address `addr` | |||||
| * | |||||
| * \param [IN] addr Address start index to read from. | |||||
| * \param [IN] data Data buffer to be read. | |||||
| * \param [IN] size Size of data buffer to be read. | |||||
| * | |||||
| * \retval status Read operation status [0: Success, -1 Fail] | |||||
| */ | |||||
| int8_t ( *FragDecoderRead )( uint32_t addr, uint8_t *data, uint32_t size ); | |||||
| }FragDecoderCallbacks_t; | |||||
| #endif | |||||
| #if( FRAG_DECODER_FILE_HANDLING_NEW_API == 1 ) | |||||
| /*! | |||||
| * \brief Initializes the fragmentation decoder | |||||
| * | |||||
| * \param [IN] fragNb Number of expected fragments (without redundancy packets) | |||||
| * \param [IN] fragSize Size of a fragment | |||||
| * \param [IN] callbacks Pointer to the Write/Read functions. | |||||
| */ | |||||
| void FragDecoderInit( uint16_t fragNb, uint8_t fragSize, FragDecoderCallbacks_t *callbacks ); | |||||
| #else | |||||
| /*! | |||||
| * \brief Initializes the fragmentation decoder | |||||
| * | |||||
| * \param [IN] fragNb Number of expected fragments (without redundancy packets) | |||||
| * \param [IN] fragSize Size of a fragment | |||||
| * \param [IN] file Pointer to file buffer size | |||||
| * \param [IN] fileSize File buffer size | |||||
| */ | |||||
| void FragDecoderInit( uint16_t fragNb, uint8_t fragSize, uint8_t *file, uint32_t fileSize ); | |||||
| #endif | |||||
| #if( FRAG_DECODER_FILE_HANDLING_NEW_API == 1 ) | |||||
| /*! | |||||
| * \brief Gets the maximum file size that can be received | |||||
| * | |||||
| * \retval size FileSize | |||||
| */ | |||||
| uint32_t FragDecoderGetMaxFileSize( void ); | |||||
| #endif | |||||
| /*! | |||||
| * \brief Function to decode and reconstruct the binary file | |||||
| * Called for each receive frame | |||||
| * | |||||
| * \param [IN] fragCounter Fragment counter [1..(FragDecoder.FragNb + FragDecoder.Redundancy)] | |||||
| * \param [IN] rawData Pointer to the fragment to be processed (length = FragDecoder.FragSize) | |||||
| * | |||||
| * \retval status Process status. [FRAG_SESSION_ONGOING, | |||||
| * FRAG_SESSION_FINISHED or | |||||
| * FragDecoder.Status.FragNbLost] | |||||
| */ | |||||
| int32_t FragDecoderProcess( uint16_t fragCounter, uint8_t *rawData ); | |||||
| /*! | |||||
| * \brief Gets the current fragmentation status | |||||
| * | |||||
| * \retval status Fragmentation decoder status | |||||
| */ | |||||
| FragDecoderStatus_t FragDecoderGetStatus( void ); | |||||
| #endif // __FRAG_DECODER_H__ | |||||
| /*! | |||||
| * \file FragDecoder.h | |||||
| * | |||||
| * \brief Implements the LoRa-Alliance fragmentation decoder | |||||
| * Specification: https://lora-alliance.org/sites/default/files/2018-09/fragmented_data_block_transport_v1.0.0.pdf | |||||
| * | |||||
| * \copyright Revised BSD License, see section \ref LICENSE. | |||||
| * | |||||
| * \code | |||||
| * ______ _ | |||||
| * / _____) _ | | | |||||
| * ( (____ _____ ____ _| |_ _____ ____| |__ | |||||
| * \____ \| ___ | (_ _) ___ |/ ___) _ \ | |||||
| * _____) ) ____| | | || |_| ____( (___| | | | | |||||
| * (______/|_____)_|_|_| \__)_____)\____)_| |_| | |||||
| * (C)2013-2018 Semtech | |||||
| * | |||||
| * \endcode | |||||
| * | |||||
| * \author Fabien Holin ( Semtech ) | |||||
| * \author Miguel Luis ( Semtech ) | |||||
| */ | |||||
| #ifndef __FRAG_DECODER_H__ | |||||
| #define __FRAG_DECODER_H__ | |||||
| #include <stdint.h> | |||||
| /*! | |||||
| * If set to 1 the new API defining \ref FragDecoderWrite and | |||||
| * \ref FragDecoderReadfunction callbacks is used. | |||||
| */ | |||||
| #define FRAG_DECODER_FILE_HANDLING_NEW_API 1 | |||||
| /*! | |||||
| * Maximum number of fragment that can be handled. | |||||
| * | |||||
| * \remark This parameter has an impact on the memory footprint. | |||||
| */ | |||||
| #define FRAG_MAX_NB 21 | |||||
| /*! | |||||
| * Maximum fragment size that can be handled. | |||||
| * | |||||
| * \remark This parameter has an impact on the memory footprint. | |||||
| */ | |||||
| #define FRAG_MAX_SIZE 50 | |||||
| /*! | |||||
| * Maximum number of extra frames that can be handled. | |||||
| * | |||||
| * \remark This parameter has an impact on the memory footprint. | |||||
| */ | |||||
| #define FRAG_MAX_REDUNDANCY 5 | |||||
| #define FRAG_SESSION_FINISHED ( int32_t )0 | |||||
| #define FRAG_SESSION_NOT_STARTED ( int32_t )-2 | |||||
| #define FRAG_SESSION_ONGOING ( int32_t )-1 | |||||
| typedef struct sFragDecoderStatus | |||||
| { | |||||
| uint16_t FragNbRx; | |||||
| uint16_t FragNbLost; | |||||
| uint16_t FragNbLastRx; | |||||
| uint8_t MatrixError; | |||||
| }FragDecoderStatus_t; | |||||
| #if( FRAG_DECODER_FILE_HANDLING_NEW_API == 1 ) | |||||
| typedef struct sFragDecoderCallbacks | |||||
| { | |||||
| /*! | |||||
| * Writes `data` buffer of `size` starting at address `addr` | |||||
| * | |||||
| * \param [IN] addr Address start index to write to. | |||||
| * \param [IN] data Data buffer to be written. | |||||
| * \param [IN] size Size of data buffer to be written. | |||||
| * | |||||
| * \retval status Write operation status [0: Success, -1 Fail] | |||||
| */ | |||||
| int8_t ( *FragDecoderWrite )( uint32_t addr, uint8_t *data, uint32_t size ); | |||||
| /*! | |||||
| * Reads `data` buffer of `size` starting at address `addr` | |||||
| * | |||||
| * \param [IN] addr Address start index to read from. | |||||
| * \param [IN] data Data buffer to be read. | |||||
| * \param [IN] size Size of data buffer to be read. | |||||
| * | |||||
| * \retval status Read operation status [0: Success, -1 Fail] | |||||
| */ | |||||
| int8_t ( *FragDecoderRead )( uint32_t addr, uint8_t *data, uint32_t size ); | |||||
| }FragDecoderCallbacks_t; | |||||
| #endif | |||||
| #if( FRAG_DECODER_FILE_HANDLING_NEW_API == 1 ) | |||||
| /*! | |||||
| * \brief Initializes the fragmentation decoder | |||||
| * | |||||
| * \param [IN] fragNb Number of expected fragments (without redundancy packets) | |||||
| * \param [IN] fragSize Size of a fragment | |||||
| * \param [IN] callbacks Pointer to the Write/Read functions. | |||||
| */ | |||||
| void FragDecoderInit( uint16_t fragNb, uint8_t fragSize, FragDecoderCallbacks_t *callbacks ); | |||||
| #else | |||||
| /*! | |||||
| * \brief Initializes the fragmentation decoder | |||||
| * | |||||
| * \param [IN] fragNb Number of expected fragments (without redundancy packets) | |||||
| * \param [IN] fragSize Size of a fragment | |||||
| * \param [IN] file Pointer to file buffer size | |||||
| * \param [IN] fileSize File buffer size | |||||
| */ | |||||
| void FragDecoderInit( uint16_t fragNb, uint8_t fragSize, uint8_t *file, uint32_t fileSize ); | |||||
| #endif | |||||
| #if( FRAG_DECODER_FILE_HANDLING_NEW_API == 1 ) | |||||
| /*! | |||||
| * \brief Gets the maximum file size that can be received | |||||
| * | |||||
| * \retval size FileSize | |||||
| */ | |||||
| uint32_t FragDecoderGetMaxFileSize( void ); | |||||
| #endif | |||||
| /*! | |||||
| * \brief Function to decode and reconstruct the binary file | |||||
| * Called for each receive frame | |||||
| * | |||||
| * \param [IN] fragCounter Fragment counter [1..(FragDecoder.FragNb + FragDecoder.Redundancy)] | |||||
| * \param [IN] rawData Pointer to the fragment to be processed (length = FragDecoder.FragSize) | |||||
| * | |||||
| * \retval status Process status. [FRAG_SESSION_ONGOING, | |||||
| * FRAG_SESSION_FINISHED or | |||||
| * FragDecoder.Status.FragNbLost] | |||||
| */ | |||||
| int32_t FragDecoderProcess( uint16_t fragCounter, uint8_t *rawData ); | |||||
| /*! | |||||
| * \brief Gets the current fragmentation status | |||||
| * | |||||
| * \retval status Fragmentation decoder status | |||||
| */ | |||||
| FragDecoderStatus_t FragDecoderGetStatus( void ); | |||||
| #endif // __FRAG_DECODER_H__ | |||||
| @@ -1,146 +1,146 @@ | |||||
| /*! | |||||
| * \file LmPackage.h | |||||
| * | |||||
| * \brief Defines the packages API | |||||
| * | |||||
| * \copyright Revised BSD License, see section \ref LICENSE. | |||||
| * | |||||
| * \code | |||||
| * ______ _ | |||||
| * / _____) _ | | | |||||
| * ( (____ _____ ____ _| |_ _____ ____| |__ | |||||
| * \____ \| ___ | (_ _) ___ |/ ___) _ \ | |||||
| * _____) ) ____| | | || |_| ____( (___| | | | | |||||
| * (______/|_____)_|_|_| \__)_____)\____)_| |_| | |||||
| * (C)2013-2018 Semtech | |||||
| * | |||||
| * \endcode | |||||
| * | |||||
| * \author Miguel Luis ( Semtech ) | |||||
| */ | |||||
| #ifndef __LMH_PACKAGE_H__ | |||||
| #define __LMH_PACKAGE_H__ | |||||
| #include <stdint.h> | |||||
| #include <stdbool.h> | |||||
| #include "LmHandlerTypes.h" | |||||
| /*! | |||||
| * Maximum number of packages | |||||
| */ | |||||
| #define PKG_MAX_NUMBER 4 | |||||
| typedef struct LmhPackage_s | |||||
| { | |||||
| uint8_t Port; | |||||
| /* | |||||
| *========================================================================= | |||||
| * Below callbacks must be initialized in package variable declaration | |||||
| *========================================================================= | |||||
| */ | |||||
| /*! | |||||
| * Initializes the package with provided parameters | |||||
| * | |||||
| * \param [IN] params Pointer to the package parameters | |||||
| * \param [IN] dataBuffer Pointer to main application buffer | |||||
| * \param [IN] dataBufferMaxSize Main application buffer maximum size | |||||
| */ | |||||
| void ( *Init )( void *params, uint8_t *dataBuffer, uint8_t dataBufferMaxSize ); | |||||
| /*! | |||||
| * Returns the current package initialization status. | |||||
| * | |||||
| * \retval status Package initialization status | |||||
| * [true: Initialized, false: Not initialized] | |||||
| */ | |||||
| bool ( *IsInitialized )( void ); | |||||
| /*! | |||||
| * Returns if a package transmission is pending or not. | |||||
| * | |||||
| * \retval status Package transmission status | |||||
| * [true: pending, false: Not pending] | |||||
| */ | |||||
| bool ( *IsTxPending )( void ); | |||||
| /*! | |||||
| * Processes the internal package events. | |||||
| */ | |||||
| void ( *Process )( void ); | |||||
| /*! | |||||
| * Processes the MCSP Confirm | |||||
| * | |||||
| * \param [IN] mcpsConfirm MCPS confirmation primitive data | |||||
| */ | |||||
| void ( *OnMcpsConfirmProcess )( McpsConfirm_t *mcpsConfirm ); | |||||
| /*! | |||||
| * Processes the MCPS Indication | |||||
| * | |||||
| * \param [IN] mcpsIndication MCPS indication primitive data | |||||
| */ | |||||
| void ( *OnMcpsIndicationProcess )( McpsIndication_t *mcpsIndication ); | |||||
| /*! | |||||
| * Processes the MLME Confirm | |||||
| * | |||||
| * \param [IN] mlmeConfirm MLME confirmation primitive data | |||||
| */ | |||||
| void ( *OnMlmeConfirmProcess )( MlmeConfirm_t *mlmeConfirm ); | |||||
| /*! | |||||
| * Processes the MLME Indication | |||||
| * | |||||
| * \param [IN] mlmeIndication MLME indication primitive data | |||||
| */ | |||||
| void ( *OnMlmeIndicationProcess )( MlmeIndication_t *mlmeIndication ); | |||||
| /* | |||||
| *========================================================================= | |||||
| * Below callbacks must be initialized in LmHandler initialization with | |||||
| * provideded LmHandlerSend and OnMacRequest functions | |||||
| *========================================================================= | |||||
| */ | |||||
| /*! | |||||
| * Notifies the upper layer that a MCPS request has been made to the MAC layer | |||||
| * | |||||
| * \param [IN] status - Request returned status | |||||
| * \param [IN] mcpsRequest - Performed MCPS-Request. Refer to \ref McpsReq_t. | |||||
| * \param [IN] nextTxDelay - Time to wait until another TX is possible. | |||||
| */ | |||||
| void ( *OnMacMcpsRequest )( LoRaMacStatus_t status, McpsReq_t *mcpsReq, TimerTime_t nextTxDelay ); | |||||
| /*! | |||||
| * Notifies the upper layer that a MLME request has been made to the MAC layer | |||||
| * | |||||
| * \param [IN] status - Request returned status | |||||
| * \param [IN] mlmeRequest - Performed MLME-Request. Refer to \ref MlmeReq_t. | |||||
| * \param [IN] nextTxDelay - Time to wait until another TX is possible. | |||||
| */ | |||||
| void ( *OnMacMlmeRequest )( LoRaMacStatus_t status, MlmeReq_t *mlmeReq, TimerTime_t nextTxDelay ); | |||||
| /*! | |||||
| * Join a LoRa Network in classA | |||||
| * | |||||
| * \Note if the device is ABP, this is a pass through function | |||||
| * | |||||
| * \param [IN] isOtaa Indicates which activation mode must be used | |||||
| */ | |||||
| void ( *OnJoinRequest )( bool isOtaa ); | |||||
| /*! | |||||
| * Requests network server time update | |||||
| * | |||||
| * \retval status Returns \ref LORAMAC_HANDLER_SET if joined else \ref LORAMAC_HANDLER_RESET | |||||
| */ | |||||
| LmHandlerErrorStatus_t ( *OnDeviceTimeRequest )( void ); | |||||
| #if( LMH_SYS_TIME_UPDATE_NEW_API == 1 ) | |||||
| /*! | |||||
| * Notifies the upper layer that the system time has been updated. | |||||
| * | |||||
| * \param [in] isSynchronized Indicates if the system time is synchronized in the range +/-1 second | |||||
| * \param [in] timeCorrection Received time correction value | |||||
| */ | |||||
| void ( *OnSysTimeUpdate )( bool isSynchronized, int32_t timeCorrection ); | |||||
| #else | |||||
| /*! | |||||
| * Notifies the upper layer that the system time has been updated. | |||||
| */ | |||||
| void ( *OnSysTimeUpdate )( void ); | |||||
| #endif | |||||
| }LmhPackage_t; | |||||
| #endif // __LMH_PACKAGE_H__ | |||||
| /*! | |||||
| * \file LmPackage.h | |||||
| * | |||||
| * \brief Defines the packages API | |||||
| * | |||||
| * \copyright Revised BSD License, see section \ref LICENSE. | |||||
| * | |||||
| * \code | |||||
| * ______ _ | |||||
| * / _____) _ | | | |||||
| * ( (____ _____ ____ _| |_ _____ ____| |__ | |||||
| * \____ \| ___ | (_ _) ___ |/ ___) _ \ | |||||
| * _____) ) ____| | | || |_| ____( (___| | | | | |||||
| * (______/|_____)_|_|_| \__)_____)\____)_| |_| | |||||
| * (C)2013-2018 Semtech | |||||
| * | |||||
| * \endcode | |||||
| * | |||||
| * \author Miguel Luis ( Semtech ) | |||||
| */ | |||||
| #ifndef __LMH_PACKAGE_H__ | |||||
| #define __LMH_PACKAGE_H__ | |||||
| #include <stdint.h> | |||||
| #include <stdbool.h> | |||||
| #include "LmHandlerTypes.h" | |||||
| /*! | |||||
| * Maximum number of packages | |||||
| */ | |||||
| #define PKG_MAX_NUMBER 4 | |||||
| typedef struct LmhPackage_s | |||||
| { | |||||
| uint8_t Port; | |||||
| /* | |||||
| *========================================================================= | |||||
| * Below callbacks must be initialized in package variable declaration | |||||
| *========================================================================= | |||||
| */ | |||||
| /*! | |||||
| * Initializes the package with provided parameters | |||||
| * | |||||
| * \param [IN] params Pointer to the package parameters | |||||
| * \param [IN] dataBuffer Pointer to main application buffer | |||||
| * \param [IN] dataBufferMaxSize Main application buffer maximum size | |||||
| */ | |||||
| void ( *Init )( void *params, uint8_t *dataBuffer, uint8_t dataBufferMaxSize ); | |||||
| /*! | |||||
| * Returns the current package initialization status. | |||||
| * | |||||
| * \retval status Package initialization status | |||||
| * [true: Initialized, false: Not initialized] | |||||
| */ | |||||
| bool ( *IsInitialized )( void ); | |||||
| /*! | |||||
| * Returns if a package transmission is pending or not. | |||||
| * | |||||
| * \retval status Package transmission status | |||||
| * [true: pending, false: Not pending] | |||||
| */ | |||||
| bool ( *IsTxPending )( void ); | |||||
| /*! | |||||
| * Processes the internal package events. | |||||
| */ | |||||
| void ( *Process )( void ); | |||||
| /*! | |||||
| * Processes the MCSP Confirm | |||||
| * | |||||
| * \param [IN] mcpsConfirm MCPS confirmation primitive data | |||||
| */ | |||||
| void ( *OnMcpsConfirmProcess )( McpsConfirm_t *mcpsConfirm ); | |||||
| /*! | |||||
| * Processes the MCPS Indication | |||||
| * | |||||
| * \param [IN] mcpsIndication MCPS indication primitive data | |||||
| */ | |||||
| void ( *OnMcpsIndicationProcess )( McpsIndication_t *mcpsIndication ); | |||||
| /*! | |||||
| * Processes the MLME Confirm | |||||
| * | |||||
| * \param [IN] mlmeConfirm MLME confirmation primitive data | |||||
| */ | |||||
| void ( *OnMlmeConfirmProcess )( MlmeConfirm_t *mlmeConfirm ); | |||||
| /*! | |||||
| * Processes the MLME Indication | |||||
| * | |||||
| * \param [IN] mlmeIndication MLME indication primitive data | |||||
| */ | |||||
| void ( *OnMlmeIndicationProcess )( MlmeIndication_t *mlmeIndication ); | |||||
| /* | |||||
| *========================================================================= | |||||
| * Below callbacks must be initialized in LmHandler initialization with | |||||
| * provideded LmHandlerSend and OnMacRequest functions | |||||
| *========================================================================= | |||||
| */ | |||||
| /*! | |||||
| * Notifies the upper layer that a MCPS request has been made to the MAC layer | |||||
| * | |||||
| * \param [IN] status - Request returned status | |||||
| * \param [IN] mcpsRequest - Performed MCPS-Request. Refer to \ref McpsReq_t. | |||||
| * \param [IN] nextTxDelay - Time to wait until another TX is possible. | |||||
| */ | |||||
| void ( *OnMacMcpsRequest )( LoRaMacStatus_t status, McpsReq_t *mcpsReq, TimerTime_t nextTxDelay ); | |||||
| /*! | |||||
| * Notifies the upper layer that a MLME request has been made to the MAC layer | |||||
| * | |||||
| * \param [IN] status - Request returned status | |||||
| * \param [IN] mlmeRequest - Performed MLME-Request. Refer to \ref MlmeReq_t. | |||||
| * \param [IN] nextTxDelay - Time to wait until another TX is possible. | |||||
| */ | |||||
| void ( *OnMacMlmeRequest )( LoRaMacStatus_t status, MlmeReq_t *mlmeReq, TimerTime_t nextTxDelay ); | |||||
| /*! | |||||
| * Join a LoRa Network in classA | |||||
| * | |||||
| * \Note if the device is ABP, this is a pass through function | |||||
| * | |||||
| * \param [IN] isOtaa Indicates which activation mode must be used | |||||
| */ | |||||
| void ( *OnJoinRequest )( bool isOtaa ); | |||||
| /*! | |||||
| * Requests network server time update | |||||
| * | |||||
| * \retval status Returns \ref LORAMAC_HANDLER_SET if joined else \ref LORAMAC_HANDLER_RESET | |||||
| */ | |||||
| LmHandlerErrorStatus_t ( *OnDeviceTimeRequest )( void ); | |||||
| #if( LMH_SYS_TIME_UPDATE_NEW_API == 1 ) | |||||
| /*! | |||||
| * Notifies the upper layer that the system time has been updated. | |||||
| * | |||||
| * \param [in] isSynchronized Indicates if the system time is synchronized in the range +/-1 second | |||||
| * \param [in] timeCorrection Received time correction value | |||||
| */ | |||||
| void ( *OnSysTimeUpdate )( bool isSynchronized, int32_t timeCorrection ); | |||||
| #else | |||||
| /*! | |||||
| * Notifies the upper layer that the system time has been updated. | |||||
| */ | |||||
| void ( *OnSysTimeUpdate )( void ); | |||||
| #endif | |||||
| }LmhPackage_t; | |||||
| #endif // __LMH_PACKAGE_H__ | |||||
| @@ -1,372 +1,372 @@ | |||||
| /*! | |||||
| * \file LmhpClockSync.c | |||||
| * | |||||
| * \brief Implements the LoRa-Alliance clock synchronization package | |||||
| * Specification: https://lora-alliance.org/sites/default/files/2018-09/application_layer_clock_synchronization_v1.0.0.pdf | |||||
| * | |||||
| * \copyright Revised BSD License, see section \ref LICENSE. | |||||
| * | |||||
| * \code | |||||
| * ______ _ | |||||
| * / _____) _ | | | |||||
| * ( (____ _____ ____ _| |_ _____ ____| |__ | |||||
| * \____ \| ___ | (_ _) ___ |/ ___) _ \ | |||||
| * _____) ) ____| | | || |_| ____( (___| | | | | |||||
| * (______/|_____)_|_|_| \__)_____)\____)_| |_| | |||||
| * (C)2013-2018 Semtech | |||||
| * | |||||
| * \endcode | |||||
| * | |||||
| * \author Miguel Luis ( Semtech ) | |||||
| */ | |||||
| #include "LmHandler.h" | |||||
| #include "LmhpClockSync.h" | |||||
| /*! | |||||
| * LoRaWAN Application Layer Clock Synchronization Specification | |||||
| */ | |||||
| #define CLOCK_SYNC_PORT 202 | |||||
| #define CLOCK_SYNC_ID 1 | |||||
| #define CLOCK_SYNC_VERSION 1 | |||||
| /*! | |||||
| * Package current context | |||||
| */ | |||||
| typedef struct LmhpClockSyncState_s | |||||
| { | |||||
| bool Initialized; | |||||
| bool IsTxPending; | |||||
| uint8_t DataBufferMaxSize; | |||||
| uint8_t *DataBuffer; | |||||
| union | |||||
| { | |||||
| uint8_t Value; | |||||
| struct | |||||
| { | |||||
| uint8_t TokenReq: 4; | |||||
| uint8_t AnsRequired: 1; | |||||
| uint8_t RFU: 3; | |||||
| }Fields; | |||||
| }TimeReqParam; | |||||
| bool AppTimeReqPending; | |||||
| bool AdrEnabledPrev; | |||||
| uint8_t NbTransPrev; | |||||
| uint8_t DataratePrev; | |||||
| uint8_t NbTransmissions; | |||||
| }LmhpClockSyncState_t; | |||||
| typedef enum LmhpClockSyncMoteCmd_e | |||||
| { | |||||
| CLOCK_SYNC_PKG_VERSION_ANS = 0x00, | |||||
| CLOCK_SYNC_APP_TIME_REQ = 0x01, | |||||
| CLOCK_SYNC_APP_TIME_PERIOD_ANS = 0x02, | |||||
| CLOCK_SYNC_FORCE_RESYNC_ANS = 0x03, | |||||
| }LmhpClockSyncMoteCmd_t; | |||||
| typedef enum LmhpClockSyncSrvCmd_e | |||||
| { | |||||
| CLOCK_SYNC_PKG_VERSION_REQ = 0x00, | |||||
| CLOCK_SYNC_APP_TIME_ANS = 0x01, | |||||
| CLOCK_SYNC_APP_TIME_PERIOD_REQ = 0x02, | |||||
| CLOCK_SYNC_FORCE_RESYNC_REQ = 0x03, | |||||
| }LmhpClockSyncSrvCmd_t; | |||||
| /*! | |||||
| * Initializes the package with provided parameters | |||||
| * | |||||
| * \param [IN] params Pointer to the package parameters | |||||
| * \param [IN] dataBuffer Pointer to main application buffer | |||||
| * \param [IN] dataBufferMaxSize Main application buffer maximum size | |||||
| */ | |||||
| static void LmhpClockSyncInit( void *params, uint8_t *dataBuffer, uint8_t dataBufferMaxSize ); | |||||
| /*! | |||||
| * Returns the current package initialization status. | |||||
| * | |||||
| * \retval status Package initialization status | |||||
| * [true: Initialized, false: Not initialized] | |||||
| */ | |||||
| static bool LmhpClockSyncIsInitialized( void ); | |||||
| /*! | |||||
| * Returns if a package transmission is pending or not. | |||||
| * | |||||
| * \retval status Package transmission status | |||||
| * [true: pending, false: Not pending] | |||||
| */ | |||||
| static bool LmhpClockSyncIsTxPending( void ); | |||||
| /*! | |||||
| * Processes the internal package events. | |||||
| */ | |||||
| static void LmhpClockSyncProcess( void ); | |||||
| /*! | |||||
| * Processes the MCSP Confirm | |||||
| * | |||||
| * \param [IN] mcpsConfirm MCPS confirmation primitive data | |||||
| */ | |||||
| static void LmhpClockSyncOnMcpsConfirm( McpsConfirm_t *mcpsConfirm ); | |||||
| /*! | |||||
| * Processes the MCPS Indication | |||||
| * | |||||
| * \param [IN] mcpsIndication MCPS indication primitive data | |||||
| */ | |||||
| static void LmhpClockSyncOnMcpsIndication( McpsIndication_t *mcpsIndication ); | |||||
| static LmhpClockSyncState_t LmhpClockSyncState = | |||||
| { | |||||
| .Initialized = false, | |||||
| .IsTxPending = false, | |||||
| .TimeReqParam.Value = 0, | |||||
| .AppTimeReqPending = false, | |||||
| .AdrEnabledPrev = false, | |||||
| .NbTransPrev = 0, | |||||
| .NbTransmissions = 0, | |||||
| }; | |||||
| static LmhPackage_t LmhpClockSyncPackage = | |||||
| { | |||||
| .Port = CLOCK_SYNC_PORT, | |||||
| .Init = LmhpClockSyncInit, | |||||
| .IsInitialized = LmhpClockSyncIsInitialized, | |||||
| .IsTxPending = LmhpClockSyncIsTxPending, | |||||
| .Process = LmhpClockSyncProcess, | |||||
| .OnMcpsConfirmProcess = LmhpClockSyncOnMcpsConfirm, | |||||
| .OnMcpsIndicationProcess = LmhpClockSyncOnMcpsIndication, | |||||
| .OnMlmeConfirmProcess = NULL, // Not used in this package | |||||
| .OnMlmeIndicationProcess = NULL, // Not used in this package | |||||
| .OnMacMcpsRequest = NULL, // To be initialized by LmHandler | |||||
| .OnMacMlmeRequest = NULL, // To be initialized by LmHandler | |||||
| .OnJoinRequest = NULL, // To be initialized by LmHandler | |||||
| .OnDeviceTimeRequest = NULL, // To be initialized by LmHandler | |||||
| .OnSysTimeUpdate = NULL, // To be initialized by LmHandler | |||||
| }; | |||||
| LmhPackage_t *LmphClockSyncPackageFactory( void ) | |||||
| { | |||||
| return &LmhpClockSyncPackage; | |||||
| } | |||||
| static void LmhpClockSyncInit( void * params, uint8_t *dataBuffer, uint8_t dataBufferMaxSize ) | |||||
| { | |||||
| if( dataBuffer != NULL ) | |||||
| { | |||||
| LmhpClockSyncState.DataBuffer = dataBuffer; | |||||
| LmhpClockSyncState.DataBufferMaxSize = dataBufferMaxSize; | |||||
| LmhpClockSyncState.Initialized = true; | |||||
| } | |||||
| else | |||||
| { | |||||
| LmhpClockSyncState.Initialized = false; | |||||
| } | |||||
| LmhpClockSyncState.IsTxPending = false; | |||||
| } | |||||
| static bool LmhpClockSyncIsInitialized( void ) | |||||
| { | |||||
| return LmhpClockSyncState.Initialized; | |||||
| } | |||||
| static bool LmhpClockSyncIsTxPending( void ) | |||||
| { | |||||
| return LmhpClockSyncState.IsTxPending; | |||||
| } | |||||
| static void LmhpClockSyncProcess( void ) | |||||
| { | |||||
| if( LmhpClockSyncState.NbTransmissions > 0 ) | |||||
| { | |||||
| if( LmhpClockSyncAppTimeReq( ) == LORAMAC_HANDLER_SUCCESS ) | |||||
| { | |||||
| LmhpClockSyncState.NbTransmissions--; | |||||
| } | |||||
| } | |||||
| } | |||||
| static void LmhpClockSyncOnMcpsConfirm( McpsConfirm_t *mcpsConfirm ) | |||||
| { | |||||
| MibRequestConfirm_t mibReq; | |||||
| if( LmhpClockSyncState.AppTimeReqPending == true ) | |||||
| { | |||||
| // Revert ADR setting | |||||
| mibReq.Type = MIB_ADR; | |||||
| mibReq.Param.AdrEnable = LmhpClockSyncState.AdrEnabledPrev; | |||||
| LoRaMacMibSetRequestConfirm( &mibReq ); | |||||
| // Revert NbTrans setting | |||||
| mibReq.Type = MIB_CHANNELS_NB_TRANS; | |||||
| mibReq.Param.ChannelsNbTrans = LmhpClockSyncState.NbTransPrev; | |||||
| LoRaMacMibSetRequestConfirm( &mibReq ); | |||||
| // Revert data rate setting | |||||
| mibReq.Type = MIB_CHANNELS_DATARATE; | |||||
| mibReq.Param.ChannelsDatarate = LmhpClockSyncState.DataratePrev; | |||||
| LoRaMacMibSetRequestConfirm( &mibReq ); | |||||
| LmhpClockSyncState.AppTimeReqPending = false; | |||||
| } | |||||
| } | |||||
| static void LmhpClockSyncOnMcpsIndication( McpsIndication_t *mcpsIndication ) | |||||
| { | |||||
| uint8_t cmdIndex = 0; | |||||
| uint8_t dataBufferIndex = 0; | |||||
| if( mcpsIndication->Port != CLOCK_SYNC_PORT ) | |||||
| { | |||||
| return; | |||||
| } | |||||
| while( cmdIndex < mcpsIndication->BufferSize ) | |||||
| { | |||||
| switch( mcpsIndication->Buffer[cmdIndex++] ) | |||||
| { | |||||
| case CLOCK_SYNC_PKG_VERSION_REQ: | |||||
| { | |||||
| LmhpClockSyncState.DataBuffer[dataBufferIndex++] = CLOCK_SYNC_PKG_VERSION_ANS; | |||||
| LmhpClockSyncState.DataBuffer[dataBufferIndex++] = CLOCK_SYNC_ID; | |||||
| LmhpClockSyncState.DataBuffer[dataBufferIndex++] = CLOCK_SYNC_VERSION; | |||||
| break; | |||||
| } | |||||
| case CLOCK_SYNC_APP_TIME_ANS: | |||||
| { | |||||
| LmhpClockSyncState.NbTransmissions = 0; | |||||
| // Check if a more precise time correction has been received. | |||||
| // If yes then don't process and ignore this answer. | |||||
| if( mcpsIndication->DeviceTimeAnsReceived == true ) | |||||
| { | |||||
| cmdIndex += 5; | |||||
| break; | |||||
| } | |||||
| int32_t timeCorrection = 0; | |||||
| timeCorrection = ( mcpsIndication->Buffer[cmdIndex++] << 0 ) & 0x000000FF; | |||||
| timeCorrection += ( mcpsIndication->Buffer[cmdIndex++] << 8 ) & 0x0000FF00; | |||||
| timeCorrection += ( mcpsIndication->Buffer[cmdIndex++] << 16 ) & 0x00FF0000; | |||||
| timeCorrection += ( mcpsIndication->Buffer[cmdIndex++] << 24 ) & 0xFF000000; | |||||
| if( ( mcpsIndication->Buffer[cmdIndex++] & 0x0F ) == LmhpClockSyncState.TimeReqParam.Fields.TokenReq ) | |||||
| { | |||||
| SysTime_t curTime = { .Seconds = 0, .SubSeconds = 0 }; | |||||
| curTime = SysTimeGet( ); | |||||
| curTime.Seconds += timeCorrection; | |||||
| SysTimeSet( curTime ); | |||||
| LmhpClockSyncState.TimeReqParam.Fields.TokenReq = ( LmhpClockSyncState.TimeReqParam.Fields.TokenReq + 1 ) & 0x0F; | |||||
| if( LmhpClockSyncPackage.OnSysTimeUpdate != NULL ) | |||||
| { | |||||
| #if( LMH_SYS_TIME_UPDATE_NEW_API == 1 ) | |||||
| LmhpClockSyncPackage.OnSysTimeUpdate( | |||||
| ( timeCorrection >= -1 ) && ( timeCorrection <= 1 ), | |||||
| timeCorrection ); | |||||
| #else | |||||
| if( ( timeCorrection >= -1 ) && ( timeCorrection <= 1 ) ) | |||||
| { | |||||
| LmhpClockSyncPackage.OnSysTimeUpdate( ); | |||||
| } | |||||
| #endif | |||||
| } | |||||
| } | |||||
| break; | |||||
| } | |||||
| case CLOCK_SYNC_APP_TIME_PERIOD_REQ: | |||||
| { | |||||
| // Increment index | |||||
| cmdIndex++; | |||||
| // TODO implement command prosessing and handling | |||||
| LmhpClockSyncState.DataBuffer[dataBufferIndex++] = CLOCK_SYNC_APP_TIME_PERIOD_ANS; | |||||
| // Answer status not supported. | |||||
| LmhpClockSyncState.DataBuffer[dataBufferIndex++] = 0x01; | |||||
| SysTime_t curTime = SysTimeGet( ); | |||||
| // Substract Unix to Gps epcoh offset. The system time is based on Unix time. | |||||
| curTime.Seconds -= UNIX_GPS_EPOCH_OFFSET; | |||||
| LmhpClockSyncState.DataBuffer[dataBufferIndex++] = ( curTime.Seconds >> 0 ) & 0xFF; | |||||
| LmhpClockSyncState.DataBuffer[dataBufferIndex++] = ( curTime.Seconds >> 8 ) & 0xFF; | |||||
| LmhpClockSyncState.DataBuffer[dataBufferIndex++] = ( curTime.Seconds >> 16 ) & 0xFF; | |||||
| LmhpClockSyncState.DataBuffer[dataBufferIndex++] = ( curTime.Seconds >> 24 ) & 0xFF; | |||||
| break; | |||||
| } | |||||
| case CLOCK_SYNC_FORCE_RESYNC_REQ: | |||||
| { | |||||
| LmhpClockSyncState.NbTransmissions = mcpsIndication->Buffer[cmdIndex++] & 0X07; | |||||
| break; | |||||
| } | |||||
| } | |||||
| } | |||||
| if( dataBufferIndex != 0 ) | |||||
| { | |||||
| // Answer commands | |||||
| LmHandlerAppData_t appData = | |||||
| { | |||||
| .Buffer = LmhpClockSyncState.DataBuffer, | |||||
| .BufferSize = dataBufferIndex, | |||||
| .Port = CLOCK_SYNC_PORT | |||||
| }; | |||||
| LmHandlerSend( &appData, LORAMAC_HANDLER_UNCONFIRMED_MSG ); | |||||
| } | |||||
| } | |||||
| LmHandlerErrorStatus_t LmhpClockSyncAppTimeReq( void ) | |||||
| { | |||||
| if( LmHandlerIsBusy( ) == true ) | |||||
| { | |||||
| return LORAMAC_HANDLER_ERROR; | |||||
| } | |||||
| if( LmhpClockSyncState.AppTimeReqPending == false ) | |||||
| { | |||||
| MibRequestConfirm_t mibReq; | |||||
| // Disable ADR | |||||
| mibReq.Type = MIB_ADR; | |||||
| LoRaMacMibGetRequestConfirm( &mibReq ); | |||||
| LmhpClockSyncState.AdrEnabledPrev = mibReq.Param.AdrEnable; | |||||
| mibReq.Param.AdrEnable = false; | |||||
| LoRaMacMibSetRequestConfirm( &mibReq ); | |||||
| // Set NbTrans = 1 | |||||
| mibReq.Type = MIB_CHANNELS_NB_TRANS; | |||||
| LoRaMacMibGetRequestConfirm( &mibReq ); | |||||
| LmhpClockSyncState.NbTransPrev = mibReq.Param.ChannelsNbTrans; | |||||
| mibReq.Param.ChannelsNbTrans = 1; | |||||
| LoRaMacMibSetRequestConfirm( &mibReq ); | |||||
| // Store data rate | |||||
| mibReq.Type = MIB_CHANNELS_DATARATE; | |||||
| LoRaMacMibGetRequestConfirm( &mibReq ); | |||||
| LmhpClockSyncState.DataratePrev = mibReq.Param.ChannelsDatarate; | |||||
| // Add DeviceTimeReq MAC command. | |||||
| // In case the network server supports this more precise command | |||||
| // this package will use DeviceTimeAns answer as clock synchronization | |||||
| // mechanism. | |||||
| LmhpClockSyncPackage.OnDeviceTimeRequest( ); | |||||
| } | |||||
| SysTime_t curTime = SysTimeGet( ); | |||||
| uint8_t dataBufferIndex = 0; | |||||
| // Substract Unix to Gps epcoh offset. The system time is based on Unix time. | |||||
| curTime.Seconds -= UNIX_GPS_EPOCH_OFFSET; | |||||
| LmhpClockSyncState.DataBuffer[dataBufferIndex++] = CLOCK_SYNC_APP_TIME_REQ; | |||||
| LmhpClockSyncState.DataBuffer[dataBufferIndex++] = ( curTime.Seconds >> 0 ) & 0xFF; | |||||
| LmhpClockSyncState.DataBuffer[dataBufferIndex++] = ( curTime.Seconds >> 8 ) & 0xFF; | |||||
| LmhpClockSyncState.DataBuffer[dataBufferIndex++] = ( curTime.Seconds >> 16 ) & 0xFF; | |||||
| LmhpClockSyncState.DataBuffer[dataBufferIndex++] = ( curTime.Seconds >> 24 ) & 0xFF; | |||||
| LmhpClockSyncState.TimeReqParam.Fields.AnsRequired = 0; | |||||
| LmhpClockSyncState.DataBuffer[dataBufferIndex++] = LmhpClockSyncState.TimeReqParam.Value; | |||||
| LmHandlerAppData_t appData = | |||||
| { | |||||
| .Buffer = LmhpClockSyncState.DataBuffer, | |||||
| .BufferSize = dataBufferIndex, | |||||
| .Port = CLOCK_SYNC_PORT | |||||
| }; | |||||
| LmhpClockSyncState.AppTimeReqPending = true; | |||||
| return LmHandlerSend( &appData, LORAMAC_HANDLER_UNCONFIRMED_MSG ); | |||||
| } | |||||
| /*! | |||||
| * \file LmhpClockSync.c | |||||
| * | |||||
| * \brief Implements the LoRa-Alliance clock synchronization package | |||||
| * Specification: https://lora-alliance.org/sites/default/files/2018-09/application_layer_clock_synchronization_v1.0.0.pdf | |||||
| * | |||||
| * \copyright Revised BSD License, see section \ref LICENSE. | |||||
| * | |||||
| * \code | |||||
| * ______ _ | |||||
| * / _____) _ | | | |||||
| * ( (____ _____ ____ _| |_ _____ ____| |__ | |||||
| * \____ \| ___ | (_ _) ___ |/ ___) _ \ | |||||
| * _____) ) ____| | | || |_| ____( (___| | | | | |||||
| * (______/|_____)_|_|_| \__)_____)\____)_| |_| | |||||
| * (C)2013-2018 Semtech | |||||
| * | |||||
| * \endcode | |||||
| * | |||||
| * \author Miguel Luis ( Semtech ) | |||||
| */ | |||||
| #include "LmHandler.h" | |||||
| #include "LmhpClockSync.h" | |||||
| /*! | |||||
| * LoRaWAN Application Layer Clock Synchronization Specification | |||||
| */ | |||||
| #define CLOCK_SYNC_PORT 202 | |||||
| #define CLOCK_SYNC_ID 1 | |||||
| #define CLOCK_SYNC_VERSION 1 | |||||
| /*! | |||||
| * Package current context | |||||
| */ | |||||
| typedef struct LmhpClockSyncState_s | |||||
| { | |||||
| bool Initialized; | |||||
| bool IsTxPending; | |||||
| uint8_t DataBufferMaxSize; | |||||
| uint8_t *DataBuffer; | |||||
| union | |||||
| { | |||||
| uint8_t Value; | |||||
| struct | |||||
| { | |||||
| uint8_t TokenReq: 4; | |||||
| uint8_t AnsRequired: 1; | |||||
| uint8_t RFU: 3; | |||||
| }Fields; | |||||
| }TimeReqParam; | |||||
| bool AppTimeReqPending; | |||||
| bool AdrEnabledPrev; | |||||
| uint8_t NbTransPrev; | |||||
| uint8_t DataratePrev; | |||||
| uint8_t NbTransmissions; | |||||
| }LmhpClockSyncState_t; | |||||
| typedef enum LmhpClockSyncMoteCmd_e | |||||
| { | |||||
| CLOCK_SYNC_PKG_VERSION_ANS = 0x00, | |||||
| CLOCK_SYNC_APP_TIME_REQ = 0x01, | |||||
| CLOCK_SYNC_APP_TIME_PERIOD_ANS = 0x02, | |||||
| CLOCK_SYNC_FORCE_RESYNC_ANS = 0x03, | |||||
| }LmhpClockSyncMoteCmd_t; | |||||
| typedef enum LmhpClockSyncSrvCmd_e | |||||
| { | |||||
| CLOCK_SYNC_PKG_VERSION_REQ = 0x00, | |||||
| CLOCK_SYNC_APP_TIME_ANS = 0x01, | |||||
| CLOCK_SYNC_APP_TIME_PERIOD_REQ = 0x02, | |||||
| CLOCK_SYNC_FORCE_RESYNC_REQ = 0x03, | |||||
| }LmhpClockSyncSrvCmd_t; | |||||
| /*! | |||||
| * Initializes the package with provided parameters | |||||
| * | |||||
| * \param [IN] params Pointer to the package parameters | |||||
| * \param [IN] dataBuffer Pointer to main application buffer | |||||
| * \param [IN] dataBufferMaxSize Main application buffer maximum size | |||||
| */ | |||||
| static void LmhpClockSyncInit( void *params, uint8_t *dataBuffer, uint8_t dataBufferMaxSize ); | |||||
| /*! | |||||
| * Returns the current package initialization status. | |||||
| * | |||||
| * \retval status Package initialization status | |||||
| * [true: Initialized, false: Not initialized] | |||||
| */ | |||||
| static bool LmhpClockSyncIsInitialized( void ); | |||||
| /*! | |||||
| * Returns if a package transmission is pending or not. | |||||
| * | |||||
| * \retval status Package transmission status | |||||
| * [true: pending, false: Not pending] | |||||
| */ | |||||
| static bool LmhpClockSyncIsTxPending( void ); | |||||
| /*! | |||||
| * Processes the internal package events. | |||||
| */ | |||||
| static void LmhpClockSyncProcess( void ); | |||||
| /*! | |||||
| * Processes the MCSP Confirm | |||||
| * | |||||
| * \param [IN] mcpsConfirm MCPS confirmation primitive data | |||||
| */ | |||||
| static void LmhpClockSyncOnMcpsConfirm( McpsConfirm_t *mcpsConfirm ); | |||||
| /*! | |||||
| * Processes the MCPS Indication | |||||
| * | |||||
| * \param [IN] mcpsIndication MCPS indication primitive data | |||||
| */ | |||||
| static void LmhpClockSyncOnMcpsIndication( McpsIndication_t *mcpsIndication ); | |||||
| static LmhpClockSyncState_t LmhpClockSyncState = | |||||
| { | |||||
| .Initialized = false, | |||||
| .IsTxPending = false, | |||||
| .TimeReqParam.Value = 0, | |||||
| .AppTimeReqPending = false, | |||||
| .AdrEnabledPrev = false, | |||||
| .NbTransPrev = 0, | |||||
| .NbTransmissions = 0, | |||||
| }; | |||||
| static LmhPackage_t LmhpClockSyncPackage = | |||||
| { | |||||
| .Port = CLOCK_SYNC_PORT, | |||||
| .Init = LmhpClockSyncInit, | |||||
| .IsInitialized = LmhpClockSyncIsInitialized, | |||||
| .IsTxPending = LmhpClockSyncIsTxPending, | |||||
| .Process = LmhpClockSyncProcess, | |||||
| .OnMcpsConfirmProcess = LmhpClockSyncOnMcpsConfirm, | |||||
| .OnMcpsIndicationProcess = LmhpClockSyncOnMcpsIndication, | |||||
| .OnMlmeConfirmProcess = NULL, // Not used in this package | |||||
| .OnMlmeIndicationProcess = NULL, // Not used in this package | |||||
| .OnMacMcpsRequest = NULL, // To be initialized by LmHandler | |||||
| .OnMacMlmeRequest = NULL, // To be initialized by LmHandler | |||||
| .OnJoinRequest = NULL, // To be initialized by LmHandler | |||||
| .OnDeviceTimeRequest = NULL, // To be initialized by LmHandler | |||||
| .OnSysTimeUpdate = NULL, // To be initialized by LmHandler | |||||
| }; | |||||
| LmhPackage_t *LmphClockSyncPackageFactory( void ) | |||||
| { | |||||
| return &LmhpClockSyncPackage; | |||||
| } | |||||
| static void LmhpClockSyncInit( void * params, uint8_t *dataBuffer, uint8_t dataBufferMaxSize ) | |||||
| { | |||||
| if( dataBuffer != NULL ) | |||||
| { | |||||
| LmhpClockSyncState.DataBuffer = dataBuffer; | |||||
| LmhpClockSyncState.DataBufferMaxSize = dataBufferMaxSize; | |||||
| LmhpClockSyncState.Initialized = true; | |||||
| } | |||||
| else | |||||
| { | |||||
| LmhpClockSyncState.Initialized = false; | |||||
| } | |||||
| LmhpClockSyncState.IsTxPending = false; | |||||
| } | |||||
| static bool LmhpClockSyncIsInitialized( void ) | |||||
| { | |||||
| return LmhpClockSyncState.Initialized; | |||||
| } | |||||
| static bool LmhpClockSyncIsTxPending( void ) | |||||
| { | |||||
| return LmhpClockSyncState.IsTxPending; | |||||
| } | |||||
| static void LmhpClockSyncProcess( void ) | |||||
| { | |||||
| if( LmhpClockSyncState.NbTransmissions > 0 ) | |||||
| { | |||||
| if( LmhpClockSyncAppTimeReq( ) == LORAMAC_HANDLER_SUCCESS ) | |||||
| { | |||||
| LmhpClockSyncState.NbTransmissions--; | |||||
| } | |||||
| } | |||||
| } | |||||
| static void LmhpClockSyncOnMcpsConfirm( McpsConfirm_t *mcpsConfirm ) | |||||
| { | |||||
| MibRequestConfirm_t mibReq; | |||||
| if( LmhpClockSyncState.AppTimeReqPending == true ) | |||||
| { | |||||
| // Revert ADR setting | |||||
| mibReq.Type = MIB_ADR; | |||||
| mibReq.Param.AdrEnable = LmhpClockSyncState.AdrEnabledPrev; | |||||
| LoRaMacMibSetRequestConfirm( &mibReq ); | |||||
| // Revert NbTrans setting | |||||
| mibReq.Type = MIB_CHANNELS_NB_TRANS; | |||||
| mibReq.Param.ChannelsNbTrans = LmhpClockSyncState.NbTransPrev; | |||||
| LoRaMacMibSetRequestConfirm( &mibReq ); | |||||
| // Revert data rate setting | |||||
| mibReq.Type = MIB_CHANNELS_DATARATE; | |||||
| mibReq.Param.ChannelsDatarate = LmhpClockSyncState.DataratePrev; | |||||
| LoRaMacMibSetRequestConfirm( &mibReq ); | |||||
| LmhpClockSyncState.AppTimeReqPending = false; | |||||
| } | |||||
| } | |||||
| static void LmhpClockSyncOnMcpsIndication( McpsIndication_t *mcpsIndication ) | |||||
| { | |||||
| uint8_t cmdIndex = 0; | |||||
| uint8_t dataBufferIndex = 0; | |||||
| if( mcpsIndication->Port != CLOCK_SYNC_PORT ) | |||||
| { | |||||
| return; | |||||
| } | |||||
| while( cmdIndex < mcpsIndication->BufferSize ) | |||||
| { | |||||
| switch( mcpsIndication->Buffer[cmdIndex++] ) | |||||
| { | |||||
| case CLOCK_SYNC_PKG_VERSION_REQ: | |||||
| { | |||||
| LmhpClockSyncState.DataBuffer[dataBufferIndex++] = CLOCK_SYNC_PKG_VERSION_ANS; | |||||
| LmhpClockSyncState.DataBuffer[dataBufferIndex++] = CLOCK_SYNC_ID; | |||||
| LmhpClockSyncState.DataBuffer[dataBufferIndex++] = CLOCK_SYNC_VERSION; | |||||
| break; | |||||
| } | |||||
| case CLOCK_SYNC_APP_TIME_ANS: | |||||
| { | |||||
| LmhpClockSyncState.NbTransmissions = 0; | |||||
| // Check if a more precise time correction has been received. | |||||
| // If yes then don't process and ignore this answer. | |||||
| if( mcpsIndication->DeviceTimeAnsReceived == true ) | |||||
| { | |||||
| cmdIndex += 5; | |||||
| break; | |||||
| } | |||||
| int32_t timeCorrection = 0; | |||||
| timeCorrection = ( mcpsIndication->Buffer[cmdIndex++] << 0 ) & 0x000000FF; | |||||
| timeCorrection += ( mcpsIndication->Buffer[cmdIndex++] << 8 ) & 0x0000FF00; | |||||
| timeCorrection += ( mcpsIndication->Buffer[cmdIndex++] << 16 ) & 0x00FF0000; | |||||
| timeCorrection += ( mcpsIndication->Buffer[cmdIndex++] << 24 ) & 0xFF000000; | |||||
| if( ( mcpsIndication->Buffer[cmdIndex++] & 0x0F ) == LmhpClockSyncState.TimeReqParam.Fields.TokenReq ) | |||||
| { | |||||
| SysTime_t curTime = { .Seconds = 0, .SubSeconds = 0 }; | |||||
| curTime = SysTimeGet( ); | |||||
| curTime.Seconds += timeCorrection; | |||||
| SysTimeSet( curTime ); | |||||
| LmhpClockSyncState.TimeReqParam.Fields.TokenReq = ( LmhpClockSyncState.TimeReqParam.Fields.TokenReq + 1 ) & 0x0F; | |||||
| if( LmhpClockSyncPackage.OnSysTimeUpdate != NULL ) | |||||
| { | |||||
| #if( LMH_SYS_TIME_UPDATE_NEW_API == 1 ) | |||||
| LmhpClockSyncPackage.OnSysTimeUpdate( | |||||
| ( timeCorrection >= -1 ) && ( timeCorrection <= 1 ), | |||||
| timeCorrection ); | |||||
| #else | |||||
| if( ( timeCorrection >= -1 ) && ( timeCorrection <= 1 ) ) | |||||
| { | |||||
| LmhpClockSyncPackage.OnSysTimeUpdate( ); | |||||
| } | |||||
| #endif | |||||
| } | |||||
| } | |||||
| break; | |||||
| } | |||||
| case CLOCK_SYNC_APP_TIME_PERIOD_REQ: | |||||
| { | |||||
| // Increment index | |||||
| cmdIndex++; | |||||
| // TODO implement command prosessing and handling | |||||
| LmhpClockSyncState.DataBuffer[dataBufferIndex++] = CLOCK_SYNC_APP_TIME_PERIOD_ANS; | |||||
| // Answer status not supported. | |||||
| LmhpClockSyncState.DataBuffer[dataBufferIndex++] = 0x01; | |||||
| SysTime_t curTime = SysTimeGet( ); | |||||
| // Substract Unix to Gps epcoh offset. The system time is based on Unix time. | |||||
| curTime.Seconds -= UNIX_GPS_EPOCH_OFFSET; | |||||
| LmhpClockSyncState.DataBuffer[dataBufferIndex++] = ( curTime.Seconds >> 0 ) & 0xFF; | |||||
| LmhpClockSyncState.DataBuffer[dataBufferIndex++] = ( curTime.Seconds >> 8 ) & 0xFF; | |||||
| LmhpClockSyncState.DataBuffer[dataBufferIndex++] = ( curTime.Seconds >> 16 ) & 0xFF; | |||||
| LmhpClockSyncState.DataBuffer[dataBufferIndex++] = ( curTime.Seconds >> 24 ) & 0xFF; | |||||
| break; | |||||
| } | |||||
| case CLOCK_SYNC_FORCE_RESYNC_REQ: | |||||
| { | |||||
| LmhpClockSyncState.NbTransmissions = mcpsIndication->Buffer[cmdIndex++] & 0X07; | |||||
| break; | |||||
| } | |||||
| } | |||||
| } | |||||
| if( dataBufferIndex != 0 ) | |||||
| { | |||||
| // Answer commands | |||||
| LmHandlerAppData_t appData = | |||||
| { | |||||
| .Buffer = LmhpClockSyncState.DataBuffer, | |||||
| .BufferSize = dataBufferIndex, | |||||
| .Port = CLOCK_SYNC_PORT | |||||
| }; | |||||
| LmHandlerSend( &appData, LORAMAC_HANDLER_UNCONFIRMED_MSG ); | |||||
| } | |||||
| } | |||||
| LmHandlerErrorStatus_t LmhpClockSyncAppTimeReq( void ) | |||||
| { | |||||
| if( LmHandlerIsBusy( ) == true ) | |||||
| { | |||||
| return LORAMAC_HANDLER_ERROR; | |||||
| } | |||||
| if( LmhpClockSyncState.AppTimeReqPending == false ) | |||||
| { | |||||
| MibRequestConfirm_t mibReq; | |||||
| // Disable ADR | |||||
| mibReq.Type = MIB_ADR; | |||||
| LoRaMacMibGetRequestConfirm( &mibReq ); | |||||
| LmhpClockSyncState.AdrEnabledPrev = mibReq.Param.AdrEnable; | |||||
| mibReq.Param.AdrEnable = false; | |||||
| LoRaMacMibSetRequestConfirm( &mibReq ); | |||||
| // Set NbTrans = 1 | |||||
| mibReq.Type = MIB_CHANNELS_NB_TRANS; | |||||
| LoRaMacMibGetRequestConfirm( &mibReq ); | |||||
| LmhpClockSyncState.NbTransPrev = mibReq.Param.ChannelsNbTrans; | |||||
| mibReq.Param.ChannelsNbTrans = 1; | |||||
| LoRaMacMibSetRequestConfirm( &mibReq ); | |||||
| // Store data rate | |||||
| mibReq.Type = MIB_CHANNELS_DATARATE; | |||||
| LoRaMacMibGetRequestConfirm( &mibReq ); | |||||
| LmhpClockSyncState.DataratePrev = mibReq.Param.ChannelsDatarate; | |||||
| // Add DeviceTimeReq MAC command. | |||||
| // In case the network server supports this more precise command | |||||
| // this package will use DeviceTimeAns answer as clock synchronization | |||||
| // mechanism. | |||||
| LmhpClockSyncPackage.OnDeviceTimeRequest( ); | |||||
| } | |||||
| SysTime_t curTime = SysTimeGet( ); | |||||
| uint8_t dataBufferIndex = 0; | |||||
| // Substract Unix to Gps epcoh offset. The system time is based on Unix time. | |||||
| curTime.Seconds -= UNIX_GPS_EPOCH_OFFSET; | |||||
| LmhpClockSyncState.DataBuffer[dataBufferIndex++] = CLOCK_SYNC_APP_TIME_REQ; | |||||
| LmhpClockSyncState.DataBuffer[dataBufferIndex++] = ( curTime.Seconds >> 0 ) & 0xFF; | |||||
| LmhpClockSyncState.DataBuffer[dataBufferIndex++] = ( curTime.Seconds >> 8 ) & 0xFF; | |||||
| LmhpClockSyncState.DataBuffer[dataBufferIndex++] = ( curTime.Seconds >> 16 ) & 0xFF; | |||||
| LmhpClockSyncState.DataBuffer[dataBufferIndex++] = ( curTime.Seconds >> 24 ) & 0xFF; | |||||
| LmhpClockSyncState.TimeReqParam.Fields.AnsRequired = 0; | |||||
| LmhpClockSyncState.DataBuffer[dataBufferIndex++] = LmhpClockSyncState.TimeReqParam.Value; | |||||
| LmHandlerAppData_t appData = | |||||
| { | |||||
| .Buffer = LmhpClockSyncState.DataBuffer, | |||||
| .BufferSize = dataBufferIndex, | |||||
| .Port = CLOCK_SYNC_PORT | |||||
| }; | |||||
| LmhpClockSyncState.AppTimeReqPending = true; | |||||
| return LmHandlerSend( &appData, LORAMAC_HANDLER_UNCONFIRMED_MSG ); | |||||
| } | |||||
| @@ -1,49 +1,49 @@ | |||||
| /*! | |||||
| * \file LmhpClockSync.h | |||||
| * | |||||
| * \brief Implements the LoRa-Alliance clock synchronization package | |||||
| * Specification: https://lora-alliance.org/sites/default/files/2018-09/application_layer_clock_synchronization_v1.0.0.pdf | |||||
| * | |||||
| * \copyright Revised BSD License, see section \ref LICENSE. | |||||
| * | |||||
| * \code | |||||
| * ______ _ | |||||
| * / _____) _ | | | |||||
| * ( (____ _____ ____ _| |_ _____ ____| |__ | |||||
| * \____ \| ___ | (_ _) ___ |/ ___) _ \ | |||||
| * _____) ) ____| | | || |_| ____( (___| | | | | |||||
| * (______/|_____)_|_|_| \__)_____)\____)_| |_| | |||||
| * (C)2013-2018 Semtech | |||||
| * | |||||
| * \endcode | |||||
| * | |||||
| * \author Miguel Luis ( Semtech ) | |||||
| */ | |||||
| #ifndef __LMHP_CLOCK_SYNC_H__ | |||||
| #define __LMHP_CLOCK_SYNC_H__ | |||||
| #include "LoRaMac.h" | |||||
| #include "LmHandlerTypes.h" | |||||
| #include "LmhPackage.h" | |||||
| /*! | |||||
| * Clock sync package identifier. | |||||
| * | |||||
| * \remark This value must be unique amongst the packages | |||||
| */ | |||||
| #define PACKAGE_ID_CLOCK_SYNC 1 | |||||
| /*! | |||||
| * Clock sync package parameters | |||||
| * | |||||
| * This package doesn't require parameters | |||||
| */ | |||||
| //typedef struct LmphClockSyncParams_s | |||||
| //{ | |||||
| //}LmphClockSyncParams_t; | |||||
| LmhPackage_t *LmphClockSyncPackageFactory( void ); | |||||
| LmHandlerErrorStatus_t LmhpClockSyncAppTimeReq( void ); | |||||
| #endif // __LMHP_CLOCK_SYNC_H__ | |||||
| /*! | |||||
| * \file LmhpClockSync.h | |||||
| * | |||||
| * \brief Implements the LoRa-Alliance clock synchronization package | |||||
| * Specification: https://lora-alliance.org/sites/default/files/2018-09/application_layer_clock_synchronization_v1.0.0.pdf | |||||
| * | |||||
| * \copyright Revised BSD License, see section \ref LICENSE. | |||||
| * | |||||
| * \code | |||||
| * ______ _ | |||||
| * / _____) _ | | | |||||
| * ( (____ _____ ____ _| |_ _____ ____| |__ | |||||
| * \____ \| ___ | (_ _) ___ |/ ___) _ \ | |||||
| * _____) ) ____| | | || |_| ____( (___| | | | | |||||
| * (______/|_____)_|_|_| \__)_____)\____)_| |_| | |||||
| * (C)2013-2018 Semtech | |||||
| * | |||||
| * \endcode | |||||
| * | |||||
| * \author Miguel Luis ( Semtech ) | |||||
| */ | |||||
| #ifndef __LMHP_CLOCK_SYNC_H__ | |||||
| #define __LMHP_CLOCK_SYNC_H__ | |||||
| #include "LoRaMac.h" | |||||
| #include "LmHandlerTypes.h" | |||||
| #include "LmhPackage.h" | |||||
| /*! | |||||
| * Clock sync package identifier. | |||||
| * | |||||
| * \remark This value must be unique amongst the packages | |||||
| */ | |||||
| #define PACKAGE_ID_CLOCK_SYNC 1 | |||||
| /*! | |||||
| * Clock sync package parameters | |||||
| * | |||||
| * This package doesn't require parameters | |||||
| */ | |||||
| //typedef struct LmphClockSyncParams_s | |||||
| //{ | |||||
| //}LmphClockSyncParams_t; | |||||
| LmhPackage_t *LmphClockSyncPackageFactory( void ); | |||||
| LmHandlerErrorStatus_t LmhpClockSyncAppTimeReq( void ); | |||||
| #endif // __LMHP_CLOCK_SYNC_H__ | |||||
| @@ -1,60 +1,60 @@ | |||||
| /*! | |||||
| * \file LmhpCompliance.h | |||||
| * | |||||
| * \brief Implements the LoRa-Alliance certification protocol handling | |||||
| * | |||||
| * \copyright Revised BSD License, see section \ref LICENSE. | |||||
| * | |||||
| * \code | |||||
| * ______ _ | |||||
| * / _____) _ | | | |||||
| * ( (____ _____ ____ _| |_ _____ ____| |__ | |||||
| * \____ \| ___ | (_ _) ___ |/ ___) _ \ | |||||
| * _____) ) ____| | | || |_| ____( (___| | | | | |||||
| * (______/|_____)_|_|_| \__)_____)\____)_| |_| | |||||
| * (C)2013-2018 Semtech | |||||
| * | |||||
| * \endcode | |||||
| * | |||||
| * \author Miguel Luis ( Semtech ) | |||||
| */ | |||||
| #ifndef __LMHP_COMPLIANCE__ | |||||
| #define __LMHP_COMPLIANCE__ | |||||
| #include "LoRaMac.h" | |||||
| #include "LmHandlerTypes.h" | |||||
| #include "LmhPackage.h" | |||||
| /*! | |||||
| * Compliance package identifier. | |||||
| * | |||||
| * \remark This value must be unique amongst the packages | |||||
| */ | |||||
| #define PACKAGE_ID_COMPLIANCE 0 | |||||
| /*! | |||||
| * Compliance test protocol handler parameters | |||||
| */ | |||||
| typedef struct LmhpComplianceParams_s | |||||
| { | |||||
| /*! | |||||
| * Current firmware version | |||||
| */ | |||||
| Version_t FwVersion; | |||||
| /*! | |||||
| * | |||||
| */ | |||||
| void ( *OnTxPeriodicityChanged )( uint32_t periodicity ); | |||||
| /*! | |||||
| * | |||||
| */ | |||||
| void ( *OnTxFrameCtrlChanged )( LmHandlerMsgTypes_t isTxConfirmed ); | |||||
| /*! | |||||
| * | |||||
| */ | |||||
| void ( *OnPingSlotPeriodicityChanged )( uint8_t pingSlotPeriodicity ); | |||||
| }LmhpComplianceParams_t; | |||||
| LmhPackage_t *LmphCompliancePackageFactory( void ); | |||||
| #endif // __LMHP_COMPLIANCE__ | |||||
| /*! | |||||
| * \file LmhpCompliance.h | |||||
| * | |||||
| * \brief Implements the LoRa-Alliance certification protocol handling | |||||
| * | |||||
| * \copyright Revised BSD License, see section \ref LICENSE. | |||||
| * | |||||
| * \code | |||||
| * ______ _ | |||||
| * / _____) _ | | | |||||
| * ( (____ _____ ____ _| |_ _____ ____| |__ | |||||
| * \____ \| ___ | (_ _) ___ |/ ___) _ \ | |||||
| * _____) ) ____| | | || |_| ____( (___| | | | | |||||
| * (______/|_____)_|_|_| \__)_____)\____)_| |_| | |||||
| * (C)2013-2018 Semtech | |||||
| * | |||||
| * \endcode | |||||
| * | |||||
| * \author Miguel Luis ( Semtech ) | |||||
| */ | |||||
| #ifndef __LMHP_COMPLIANCE__ | |||||
| #define __LMHP_COMPLIANCE__ | |||||
| #include "LoRaMac.h" | |||||
| #include "LmHandlerTypes.h" | |||||
| #include "LmhPackage.h" | |||||
| /*! | |||||
| * Compliance package identifier. | |||||
| * | |||||
| * \remark This value must be unique amongst the packages | |||||
| */ | |||||
| #define PACKAGE_ID_COMPLIANCE 0 | |||||
| /*! | |||||
| * Compliance test protocol handler parameters | |||||
| */ | |||||
| typedef struct LmhpComplianceParams_s | |||||
| { | |||||
| /*! | |||||
| * Current firmware version | |||||
| */ | |||||
| Version_t FwVersion; | |||||
| /*! | |||||
| * | |||||
| */ | |||||
| void ( *OnTxPeriodicityChanged )( uint32_t periodicity ); | |||||
| /*! | |||||
| * | |||||
| */ | |||||
| void ( *OnTxFrameCtrlChanged )( LmHandlerMsgTypes_t isTxConfirmed ); | |||||
| /*! | |||||
| * | |||||
| */ | |||||
| void ( *OnPingSlotPeriodicityChanged )( uint8_t pingSlotPeriodicity ); | |||||
| }LmhpComplianceParams_t; | |||||
| LmhPackage_t *LmphCompliancePackageFactory( void ); | |||||
| #endif // __LMHP_COMPLIANCE__ | |||||
| @@ -1,92 +1,92 @@ | |||||
| /*! | |||||
| * \file LmhpFragmentation.h | |||||
| * | |||||
| * \brief Implements the LoRa-Alliance fragmented data block transport package | |||||
| * Specification: https://lora-alliance.org/sites/default/files/2018-09/fragmented_data_block_transport_v1.0.0.pdf | |||||
| * | |||||
| * \copyright Revised BSD License, see section \ref LICENSE. | |||||
| * | |||||
| * \code | |||||
| * ______ _ | |||||
| * / _____) _ | | | |||||
| * ( (____ _____ ____ _| |_ _____ ____| |__ | |||||
| * \____ \| ___ | (_ _) ___ |/ ___) _ \ | |||||
| * _____) ) ____| | | || |_| ____( (___| | | | | |||||
| * (______/|_____)_|_|_| \__)_____)\____)_| |_| | |||||
| * (C)2013-2018 Semtech | |||||
| * | |||||
| * \endcode | |||||
| * | |||||
| * \author Miguel Luis ( Semtech ) | |||||
| */ | |||||
| #ifndef __LMHP_FRAGMENTATION_H__ | |||||
| #define __LMHP_FRAGMENTATION_H__ | |||||
| #include "LoRaMac.h" | |||||
| #include "LmHandlerTypes.h" | |||||
| #include "LmhPackage.h" | |||||
| #include "FragDecoder.h" | |||||
| /*! | |||||
| * Fragmentation data block transport package identifier. | |||||
| * | |||||
| * \remark This value must be unique amongst the packages | |||||
| */ | |||||
| #define PACKAGE_ID_FRAGMENTATION 3 | |||||
| /*! | |||||
| * Fragmentation package parameters | |||||
| */ | |||||
| typedef struct LmhpFragmentationParams_s | |||||
| { | |||||
| #if( FRAG_DECODER_FILE_HANDLING_NEW_API == 1 ) | |||||
| /*! | |||||
| * FragDecoder Write/Read function callbacks | |||||
| */ | |||||
| FragDecoderCallbacks_t DecoderCallbacks; | |||||
| #else | |||||
| /*! | |||||
| * Pointer to the un-fragmented received buffer. | |||||
| */ | |||||
| uint8_t *Buffer; | |||||
| /*! | |||||
| * Size of the un-fragmented received buffer. | |||||
| */ | |||||
| uint32_t BufferSize; | |||||
| #endif | |||||
| /*! | |||||
| * Notifies the progress of the current fragmentation session | |||||
| * | |||||
| * \param [IN] fragCounter Fragment counter | |||||
| * \param [IN] fragNb Number of fragments | |||||
| * \param [IN] fragSize Size of fragments | |||||
| * \param [IN] fragNbLost Number of lost fragments | |||||
| */ | |||||
| void ( *OnProgress )( uint16_t fragCounter, uint16_t fragNb, uint8_t fragSize, uint16_t fragNbLost ); | |||||
| #if( FRAG_DECODER_FILE_HANDLING_NEW_API == 1 ) | |||||
| /*! | |||||
| * Notifies that the fragmentation session is finished | |||||
| * | |||||
| * \param [IN] status Fragmentation session status [FRAG_SESSION_ONGOING, | |||||
| * FRAG_SESSION_FINISHED or | |||||
| * FragDecoder.Status.FragNbLost] | |||||
| * \param [IN] size Received file size | |||||
| */ | |||||
| void ( *OnDone )( int32_t status, uint32_t size ); | |||||
| #else | |||||
| /*! | |||||
| * Notifies that the fragmentation session is finished | |||||
| * | |||||
| * \param [IN] status Fragmentation session status [FRAG_SESSION_ONGOING, | |||||
| * FRAG_SESSION_FINISHED or | |||||
| * FragDecoder.Status.FragNbLost] | |||||
| * \param [IN] file Pointer to the reception file buffer | |||||
| * \param [IN] size Received file size | |||||
| */ | |||||
| void ( *OnDone )( int32_t status, uint8_t *file, uint32_t size ); | |||||
| #endif | |||||
| }LmhpFragmentationParams_t; | |||||
| LmhPackage_t *LmhpFragmentationPackageFactory( void ); | |||||
| #endif // __LMHP_FRAGMENTATION_H__ | |||||
| /*! | |||||
| * \file LmhpFragmentation.h | |||||
| * | |||||
| * \brief Implements the LoRa-Alliance fragmented data block transport package | |||||
| * Specification: https://lora-alliance.org/sites/default/files/2018-09/fragmented_data_block_transport_v1.0.0.pdf | |||||
| * | |||||
| * \copyright Revised BSD License, see section \ref LICENSE. | |||||
| * | |||||
| * \code | |||||
| * ______ _ | |||||
| * / _____) _ | | | |||||
| * ( (____ _____ ____ _| |_ _____ ____| |__ | |||||
| * \____ \| ___ | (_ _) ___ |/ ___) _ \ | |||||
| * _____) ) ____| | | || |_| ____( (___| | | | | |||||
| * (______/|_____)_|_|_| \__)_____)\____)_| |_| | |||||
| * (C)2013-2018 Semtech | |||||
| * | |||||
| * \endcode | |||||
| * | |||||
| * \author Miguel Luis ( Semtech ) | |||||
| */ | |||||
| #ifndef __LMHP_FRAGMENTATION_H__ | |||||
| #define __LMHP_FRAGMENTATION_H__ | |||||
| #include "LoRaMac.h" | |||||
| #include "LmHandlerTypes.h" | |||||
| #include "LmhPackage.h" | |||||
| #include "FragDecoder.h" | |||||
| /*! | |||||
| * Fragmentation data block transport package identifier. | |||||
| * | |||||
| * \remark This value must be unique amongst the packages | |||||
| */ | |||||
| #define PACKAGE_ID_FRAGMENTATION 3 | |||||
| /*! | |||||
| * Fragmentation package parameters | |||||
| */ | |||||
| typedef struct LmhpFragmentationParams_s | |||||
| { | |||||
| #if( FRAG_DECODER_FILE_HANDLING_NEW_API == 1 ) | |||||
| /*! | |||||
| * FragDecoder Write/Read function callbacks | |||||
| */ | |||||
| FragDecoderCallbacks_t DecoderCallbacks; | |||||
| #else | |||||
| /*! | |||||
| * Pointer to the un-fragmented received buffer. | |||||
| */ | |||||
| uint8_t *Buffer; | |||||
| /*! | |||||
| * Size of the un-fragmented received buffer. | |||||
| */ | |||||
| uint32_t BufferSize; | |||||
| #endif | |||||
| /*! | |||||
| * Notifies the progress of the current fragmentation session | |||||
| * | |||||
| * \param [IN] fragCounter Fragment counter | |||||
| * \param [IN] fragNb Number of fragments | |||||
| * \param [IN] fragSize Size of fragments | |||||
| * \param [IN] fragNbLost Number of lost fragments | |||||
| */ | |||||
| void ( *OnProgress )( uint16_t fragCounter, uint16_t fragNb, uint8_t fragSize, uint16_t fragNbLost ); | |||||
| #if( FRAG_DECODER_FILE_HANDLING_NEW_API == 1 ) | |||||
| /*! | |||||
| * Notifies that the fragmentation session is finished | |||||
| * | |||||
| * \param [IN] status Fragmentation session status [FRAG_SESSION_ONGOING, | |||||
| * FRAG_SESSION_FINISHED or | |||||
| * FragDecoder.Status.FragNbLost] | |||||
| * \param [IN] size Received file size | |||||
| */ | |||||
| void ( *OnDone )( int32_t status, uint32_t size ); | |||||
| #else | |||||
| /*! | |||||
| * Notifies that the fragmentation session is finished | |||||
| * | |||||
| * \param [IN] status Fragmentation session status [FRAG_SESSION_ONGOING, | |||||
| * FRAG_SESSION_FINISHED or | |||||
| * FragDecoder.Status.FragNbLost] | |||||
| * \param [IN] file Pointer to the reception file buffer | |||||
| * \param [IN] size Received file size | |||||
| */ | |||||
| void ( *OnDone )( int32_t status, uint8_t *file, uint32_t size ); | |||||
| #endif | |||||
| }LmhpFragmentationParams_t; | |||||
| LmhPackage_t *LmhpFragmentationPackageFactory( void ); | |||||
| #endif // __LMHP_FRAGMENTATION_H__ | |||||
| @@ -1,457 +1,457 @@ | |||||
| /*! | |||||
| * \file LmhpRemoteMcastSetup.c | |||||
| * | |||||
| * \brief Implements the LoRa-Alliance remote multicast setup package | |||||
| * Specification: https://lora-alliance.org/sites/default/files/2018-09/remote_multicast_setup_v1.0.0.pdf | |||||
| * | |||||
| * \copyright Revised BSD License, see section \ref LICENSE. | |||||
| * | |||||
| * \code | |||||
| * ______ _ | |||||
| * / _____) _ | | | |||||
| * ( (____ _____ ____ _| |_ _____ ____| |__ | |||||
| * \____ \| ___ | (_ _) ___ |/ ___) _ \ | |||||
| * _____) ) ____| | | || |_| ____( (___| | | | | |||||
| * (______/|_____)_|_|_| \__)_____)\____)_| |_| | |||||
| * (C)2013-2018 Semtech | |||||
| * | |||||
| * \endcode | |||||
| * | |||||
| * \author Miguel Luis ( Semtech ) | |||||
| */ | |||||
| #include "LmHandler.h" | |||||
| #include "LmhpRemoteMcastSetup.h" | |||||
| #define DBG_TRACE 1 | |||||
| #if DBG_TRACE == 1 | |||||
| #include <stdio.h> | |||||
| /*! | |||||
| * Works in the same way as the printf function does. | |||||
| */ | |||||
| #define DBG( ... ) \ | |||||
| do \ | |||||
| { \ | |||||
| printf( __VA_ARGS__ ); \ | |||||
| }while( 0 ) | |||||
| #else | |||||
| #define DBG( ... ) | |||||
| #endif | |||||
| /*! | |||||
| * LoRaWAN Application Layer Remote multicast setup Specification | |||||
| */ | |||||
| #define REMOTE_MCAST_SETUP_PORT 200 | |||||
| #define REMOTE_MCAST_SETUP_ID 2 | |||||
| #define REMOTE_MCAST_SETUP_VERSION 1 | |||||
| typedef enum LmhpRemoteMcastSetupSessionStates_e | |||||
| { | |||||
| REMOTE_MCAST_SETUP_SESSION_STATE_IDLE, | |||||
| REMOTE_MCAST_SETUP_SESSION_STATE_START, | |||||
| REMOTE_MCAST_SETUP_SESSION_STATE_STOP, | |||||
| }LmhpRemoteMcastSetupSessionStates_t; | |||||
| /*! | |||||
| * Package current context | |||||
| */ | |||||
| typedef struct LmhpRemoteMcastSetupState_s | |||||
| { | |||||
| bool Initialized; | |||||
| bool IsTxPending; | |||||
| LmhpRemoteMcastSetupSessionStates_t SessionState; | |||||
| uint8_t DataBufferMaxSize; | |||||
| uint8_t *DataBuffer; | |||||
| }LmhpRemoteMcastSetupState_t; | |||||
| typedef enum LmhpRemoteMcastSetupMoteCmd_e | |||||
| { | |||||
| REMOTE_MCAST_SETUP_PKG_VERSION_ANS = 0x00, | |||||
| REMOTE_MCAST_SETUP_MC_GROUP_STATUS_ANS = 0x01, | |||||
| REMOTE_MCAST_SETUP_MC_GROUP_SETUP_ANS = 0x02, | |||||
| REMOTE_MCAST_SETUP_MC_GROUP_DELETE_ANS = 0x03, | |||||
| REMOTE_MCAST_SETUP_MC_GROUP_CLASS_C_SESSION_ANS = 0x04, | |||||
| REMOTE_MCAST_SETUP_MC_GROUP_CLASS_B_SESSION_ANS = 0x05, | |||||
| }LmhpRemoteMcastSetupMoteCmd_t; | |||||
| typedef enum LmhpRemoteMcastSetupSrvCmd_e | |||||
| { | |||||
| REMOTE_MCAST_SETUP_PKG_VERSION_REQ = 0x00, | |||||
| REMOTE_MCAST_SETUP_MC_GROUP_STATUS_REQ = 0x01, | |||||
| REMOTE_MCAST_SETUP_MC_GROUP_SETUP_REQ = 0x02, | |||||
| REMOTE_MCAST_SETUP_MC_GROUP_DELETE_REQ = 0x03, | |||||
| REMOTE_MCAST_SETUP_MC_GROUP_CLASS_C_SESSION_REQ = 0x04, | |||||
| REMOTE_MCAST_SETUP_MC_GROUP_CLASS_B_SESSION_REQ = 0x05, | |||||
| }LmhpRemoteMcastSetupSrvCmd_t; | |||||
| /*! | |||||
| * Initializes the package with provided parameters | |||||
| * | |||||
| * \param [IN] params Pointer to the package parameters | |||||
| * \param [IN] dataBuffer Pointer to main application buffer | |||||
| * \param [IN] dataBufferMaxSize Main application buffer maximum size | |||||
| */ | |||||
| static void LmhpRemoteMcastSetupInit( void *params, uint8_t *dataBuffer, uint8_t dataBufferMaxSize ); | |||||
| /*! | |||||
| * Returns the current package initialization status. | |||||
| * | |||||
| * \retval status Package initialization status | |||||
| * [true: Initialized, false: Not initialized] | |||||
| */ | |||||
| static bool LmhpRemoteMcastSetupIsInitialized( void ); | |||||
| /*! | |||||
| * Returns if a package transmission is pending or not. | |||||
| * | |||||
| * \retval status Package transmission status | |||||
| * [true: pending, false: Not pending] | |||||
| */ | |||||
| static bool LmhpRemoteMcastSetupIsTxPending( void ); | |||||
| /*! | |||||
| * Processes the internal package events. | |||||
| */ | |||||
| static void LmhpRemoteMcastSetupProcess( void ); | |||||
| /*! | |||||
| * Processes the MCPS Indication | |||||
| * | |||||
| * \param [IN] mcpsIndication MCPS indication primitive data | |||||
| */ | |||||
| static void LmhpRemoteMcastSetupOnMcpsIndication( McpsIndication_t *mcpsIndication ); | |||||
| static void OnSessionStartTimer( void *context ); | |||||
| static void OnSessionStopTimer( void *context ); | |||||
| static LmhpRemoteMcastSetupState_t LmhpRemoteMcastSetupState = | |||||
| { | |||||
| .Initialized = false, | |||||
| .IsTxPending = false, | |||||
| .SessionState = REMOTE_MCAST_SETUP_SESSION_STATE_IDLE, | |||||
| }; | |||||
| typedef struct McGroupData_s | |||||
| { | |||||
| union | |||||
| { | |||||
| uint8_t Value; | |||||
| struct | |||||
| { | |||||
| uint8_t McGroupId: 2; | |||||
| uint8_t RFU: 6; | |||||
| }Fields; | |||||
| }IdHeader; | |||||
| uint32_t McAddr; | |||||
| uint8_t McKeyEncrypted[16]; | |||||
| uint32_t McFCountMin; | |||||
| uint32_t McFCountMax; | |||||
| }McGroupData_t; | |||||
| typedef enum eSessionState | |||||
| { | |||||
| SESSION_STOPED, | |||||
| SESSION_STARTED | |||||
| }SessionState_t; | |||||
| typedef struct McSessionData_s | |||||
| { | |||||
| McGroupData_t McGroupData; | |||||
| SessionState_t SessionState; | |||||
| uint32_t SessionTime; | |||||
| uint8_t SessionTimeout; | |||||
| McRxParams_t RxParams; | |||||
| }McSessionData_t; | |||||
| McSessionData_t McSessionData[LORAMAC_MAX_MC_CTX]; | |||||
| /*! | |||||
| * Session start timer | |||||
| */ | |||||
| static TimerEvent_t SessionStartTimer; | |||||
| /*! | |||||
| * Session start timer | |||||
| */ | |||||
| static TimerEvent_t SessionStopTimer; | |||||
| static LmhPackage_t LmhpRemoteMcastSetupPackage = | |||||
| { | |||||
| .Port = REMOTE_MCAST_SETUP_PORT, | |||||
| .Init = LmhpRemoteMcastSetupInit, | |||||
| .IsInitialized = LmhpRemoteMcastSetupIsInitialized, | |||||
| .IsTxPending = LmhpRemoteMcastSetupIsTxPending, | |||||
| .Process = LmhpRemoteMcastSetupProcess, | |||||
| .OnMcpsConfirmProcess = NULL, // Not used in this package | |||||
| .OnMcpsIndicationProcess = LmhpRemoteMcastSetupOnMcpsIndication, | |||||
| .OnMlmeConfirmProcess = NULL, // Not used in this package | |||||
| .OnMlmeIndicationProcess = NULL, // Not used in this package | |||||
| .OnMacMcpsRequest = NULL, // To be initialized by LmHandler | |||||
| .OnMacMlmeRequest = NULL, // To be initialized by LmHandler | |||||
| .OnJoinRequest = NULL, // To be initialized by LmHandler | |||||
| .OnDeviceTimeRequest = NULL, // To be initialized by LmHandler | |||||
| .OnSysTimeUpdate = NULL, // To be initialized by LmHandler | |||||
| }; | |||||
| LmhPackage_t *LmhpRemoteMcastSetupPackageFactory( void ) | |||||
| { | |||||
| return &LmhpRemoteMcastSetupPackage; | |||||
| } | |||||
| static void LmhpRemoteMcastSetupInit( void * params, uint8_t *dataBuffer, uint8_t dataBufferMaxSize ) | |||||
| { | |||||
| if( dataBuffer != NULL ) | |||||
| { | |||||
| LmhpRemoteMcastSetupState.DataBuffer = dataBuffer; | |||||
| LmhpRemoteMcastSetupState.DataBufferMaxSize = dataBufferMaxSize; | |||||
| LmhpRemoteMcastSetupState.Initialized = true; | |||||
| TimerInit( &SessionStartTimer, OnSessionStartTimer ); | |||||
| TimerInit( &SessionStopTimer, OnSessionStopTimer ); | |||||
| } | |||||
| else | |||||
| { | |||||
| LmhpRemoteMcastSetupState.Initialized = false; | |||||
| } | |||||
| LmhpRemoteMcastSetupState.IsTxPending = false; | |||||
| } | |||||
| static bool LmhpRemoteMcastSetupIsInitialized( void ) | |||||
| { | |||||
| return LmhpRemoteMcastSetupState.Initialized; | |||||
| } | |||||
| static bool LmhpRemoteMcastSetupIsTxPending( void ) | |||||
| { | |||||
| return LmhpRemoteMcastSetupState.IsTxPending; | |||||
| } | |||||
| static void LmhpRemoteMcastSetupProcess( void ) | |||||
| { | |||||
| LmhpRemoteMcastSetupSessionStates_t state; | |||||
| CRITICAL_SECTION_BEGIN( ); | |||||
| state = LmhpRemoteMcastSetupState.SessionState; | |||||
| LmhpRemoteMcastSetupState.SessionState = REMOTE_MCAST_SETUP_SESSION_STATE_IDLE; | |||||
| CRITICAL_SECTION_END( ); | |||||
| switch( state ) | |||||
| { | |||||
| case REMOTE_MCAST_SETUP_SESSION_STATE_START: | |||||
| // Switch to Class C | |||||
| LmHandlerRequestClass( CLASS_C ); | |||||
| TimerSetValue( &SessionStopTimer, ( 1 << McSessionData[0].SessionTimeout ) * 1000 ); | |||||
| TimerStart( &SessionStopTimer ); | |||||
| break; | |||||
| case REMOTE_MCAST_SETUP_SESSION_STATE_STOP: | |||||
| // Switch back to Class A | |||||
| LmHandlerRequestClass( CLASS_A ); | |||||
| break; | |||||
| case REMOTE_MCAST_SETUP_SESSION_STATE_IDLE: | |||||
| // Intentional fall through | |||||
| default: | |||||
| // Nothing to do. | |||||
| break; | |||||
| } | |||||
| } | |||||
| static void LmhpRemoteMcastSetupOnMcpsIndication( McpsIndication_t *mcpsIndication ) | |||||
| { | |||||
| uint8_t cmdIndex = 0; | |||||
| uint8_t dataBufferIndex = 0; | |||||
| if( mcpsIndication->Port != REMOTE_MCAST_SETUP_PORT ) | |||||
| { | |||||
| return; | |||||
| } | |||||
| while( cmdIndex < mcpsIndication->BufferSize ) | |||||
| { | |||||
| switch( mcpsIndication->Buffer[cmdIndex++] ) | |||||
| { | |||||
| case REMOTE_MCAST_SETUP_PKG_VERSION_REQ: | |||||
| { | |||||
| LmhpRemoteMcastSetupState.DataBuffer[dataBufferIndex++] = REMOTE_MCAST_SETUP_PKG_VERSION_ANS; | |||||
| LmhpRemoteMcastSetupState.DataBuffer[dataBufferIndex++] = REMOTE_MCAST_SETUP_ID; | |||||
| LmhpRemoteMcastSetupState.DataBuffer[dataBufferIndex++] = REMOTE_MCAST_SETUP_VERSION; | |||||
| break; | |||||
| } | |||||
| case REMOTE_MCAST_SETUP_MC_GROUP_STATUS_REQ: | |||||
| { | |||||
| // TODO implement command prosessing and handling | |||||
| break; | |||||
| } | |||||
| case REMOTE_MCAST_SETUP_MC_GROUP_SETUP_REQ: | |||||
| { | |||||
| uint8_t id = mcpsIndication->Buffer[cmdIndex++]; | |||||
| McSessionData[id].McGroupData.IdHeader.Value = id; | |||||
| McSessionData[id].McGroupData.McAddr = ( mcpsIndication->Buffer[cmdIndex++] << 0 ) & 0x000000FF; | |||||
| McSessionData[id].McGroupData.McAddr += ( mcpsIndication->Buffer[cmdIndex++] << 8 ) & 0x0000FF00; | |||||
| McSessionData[id].McGroupData.McAddr += ( mcpsIndication->Buffer[cmdIndex++] << 16 ) & 0x00FF0000; | |||||
| McSessionData[id].McGroupData.McAddr += ( mcpsIndication->Buffer[cmdIndex++] << 24 ) & 0xFF000000; | |||||
| for( int8_t i = 0; i < 16; i++ ) | |||||
| { | |||||
| McSessionData[id].McGroupData.McKeyEncrypted[i] = mcpsIndication->Buffer[cmdIndex++]; | |||||
| } | |||||
| McSessionData[id].McGroupData.McFCountMin = ( mcpsIndication->Buffer[cmdIndex++] << 0 ) & 0x000000FF; | |||||
| McSessionData[id].McGroupData.McFCountMin += ( mcpsIndication->Buffer[cmdIndex++] << 8 ) & 0x0000FF00; | |||||
| McSessionData[id].McGroupData.McFCountMin += ( mcpsIndication->Buffer[cmdIndex++] << 16 ) & 0x00FF0000; | |||||
| McSessionData[id].McGroupData.McFCountMin += ( mcpsIndication->Buffer[cmdIndex++] << 24 ) & 0xFF000000; | |||||
| McSessionData[id].McGroupData.McFCountMax = ( mcpsIndication->Buffer[cmdIndex++] << 0 ) & 0x000000FF; | |||||
| McSessionData[id].McGroupData.McFCountMax += ( mcpsIndication->Buffer[cmdIndex++] << 8 ) & 0x0000FF00; | |||||
| McSessionData[id].McGroupData.McFCountMax += ( mcpsIndication->Buffer[cmdIndex++] << 16 ) & 0x00FF0000; | |||||
| McSessionData[id].McGroupData.McFCountMax += ( mcpsIndication->Buffer[cmdIndex++] << 24 ) & 0xFF000000; | |||||
| McChannelParams_t channel = | |||||
| { | |||||
| .IsRemotelySetup = true, | |||||
| .Class = CLASS_C, // Field not used for multicast channel setup. Must be initialized to something | |||||
| .IsEnabled = true, | |||||
| .GroupID = ( AddressIdentifier_t )McSessionData[id].McGroupData.IdHeader.Fields.McGroupId, | |||||
| .Address = McSessionData[id].McGroupData.McAddr, | |||||
| .McKeys.McKeyE = McSessionData[id].McGroupData.McKeyEncrypted, | |||||
| .FCountMin = McSessionData[id].McGroupData.McFCountMin, | |||||
| .FCountMax = McSessionData[id].McGroupData.McFCountMax, | |||||
| .RxParams.ClassC = // Field not used for multicast channel setup. Must be initialized to something | |||||
| { | |||||
| .Frequency = 0, | |||||
| .Datarate = 0 | |||||
| } | |||||
| }; | |||||
| uint8_t idError = 0x01; // One bit value | |||||
| if( LoRaMacMcChannelSetup( &channel ) == LORAMAC_STATUS_OK ) | |||||
| { | |||||
| idError = 0x00; | |||||
| } | |||||
| LmhpRemoteMcastSetupState.DataBuffer[dataBufferIndex++] = REMOTE_MCAST_SETUP_MC_GROUP_SETUP_ANS; | |||||
| LmhpRemoteMcastSetupState.DataBuffer[dataBufferIndex++] = ( idError << 2 ) | McSessionData[id].McGroupData.IdHeader.Fields.McGroupId; | |||||
| break; | |||||
| } | |||||
| case REMOTE_MCAST_SETUP_MC_GROUP_DELETE_REQ: | |||||
| { | |||||
| uint8_t status = 0x00; | |||||
| uint8_t id = mcpsIndication->Buffer[cmdIndex++] & 0x03; | |||||
| status = id; | |||||
| LmhpRemoteMcastSetupState.DataBuffer[dataBufferIndex++] = REMOTE_MCAST_SETUP_MC_GROUP_DELETE_ANS; | |||||
| if( LoRaMacMcChannelDelete( ( AddressIdentifier_t )id ) != LORAMAC_STATUS_OK ) | |||||
| { | |||||
| status |= 0x04; // McGroupUndefined bit set | |||||
| } | |||||
| LmhpRemoteMcastSetupState.DataBuffer[dataBufferIndex++] = status; | |||||
| break; | |||||
| } | |||||
| case REMOTE_MCAST_SETUP_MC_GROUP_CLASS_C_SESSION_REQ: | |||||
| { | |||||
| uint8_t status = 0x00; | |||||
| uint8_t id = mcpsIndication->Buffer[cmdIndex++] & 0x03; | |||||
| McSessionData[id].SessionTime = ( mcpsIndication->Buffer[cmdIndex++] << 0 ) & 0x000000FF; | |||||
| McSessionData[id].SessionTime += ( mcpsIndication->Buffer[cmdIndex++] << 8 ) & 0x0000FF00; | |||||
| McSessionData[id].SessionTime += ( mcpsIndication->Buffer[cmdIndex++] << 16 ) & 0x00FF0000; | |||||
| McSessionData[id].SessionTime += ( mcpsIndication->Buffer[cmdIndex++] << 24 ) & 0xFF000000; | |||||
| // Add Unix to Gps epcoh offset. The system time is based on Unix time. | |||||
| McSessionData[id].SessionTime += UNIX_GPS_EPOCH_OFFSET; | |||||
| McSessionData[id].SessionTimeout = mcpsIndication->Buffer[cmdIndex++] & 0x0F; | |||||
| McSessionData[id].RxParams.ClassC.Frequency = ( mcpsIndication->Buffer[cmdIndex++] << 0 ) & 0x000000FF; | |||||
| McSessionData[id].RxParams.ClassC.Frequency |= ( mcpsIndication->Buffer[cmdIndex++] << 8 ) & 0x0000FF00; | |||||
| McSessionData[id].RxParams.ClassC.Frequency |= ( mcpsIndication->Buffer[cmdIndex++] << 16 ) & 0x00FF0000; | |||||
| McSessionData[id].RxParams.ClassC.Frequency *= 100; | |||||
| McSessionData[id].RxParams.ClassC.Datarate = mcpsIndication->Buffer[cmdIndex++]; | |||||
| LmhpRemoteMcastSetupState.DataBuffer[dataBufferIndex++] = REMOTE_MCAST_SETUP_MC_GROUP_CLASS_C_SESSION_ANS; | |||||
| if( LoRaMacMcChannelSetupRxParams( ( AddressIdentifier_t )id, &McSessionData[id].RxParams, &status ) == LORAMAC_STATUS_OK ) | |||||
| { | |||||
| SysTime_t curTime = { .Seconds = 0, .SubSeconds = 0 }; | |||||
| curTime = SysTimeGet( ); | |||||
| int32_t timeToSessionStart = McSessionData[id].SessionTime - curTime.Seconds; | |||||
| if( timeToSessionStart > 0 ) | |||||
| { | |||||
| // Start session start timer | |||||
| TimerSetValue( &SessionStartTimer, timeToSessionStart * 1000 ); | |||||
| TimerStart( &SessionStartTimer ); | |||||
| DBG( "Time2SessionStart: %ld ms\n", timeToSessionStart * 1000 ); | |||||
| LmhpRemoteMcastSetupState.DataBuffer[dataBufferIndex++] = status; | |||||
| LmhpRemoteMcastSetupState.DataBuffer[dataBufferIndex++] = ( timeToSessionStart >> 0 ) & 0xFF; | |||||
| LmhpRemoteMcastSetupState.DataBuffer[dataBufferIndex++] = ( timeToSessionStart >> 8 ) & 0xFF; | |||||
| LmhpRemoteMcastSetupState.DataBuffer[dataBufferIndex++] = ( timeToSessionStart >> 16 ) & 0xFF; | |||||
| break; | |||||
| } | |||||
| else | |||||
| { | |||||
| // Session start time before current device time | |||||
| status |= 0x10; | |||||
| } | |||||
| } | |||||
| LmhpRemoteMcastSetupState.DataBuffer[dataBufferIndex++] = status; | |||||
| break; | |||||
| } | |||||
| case REMOTE_MCAST_SETUP_MC_GROUP_CLASS_B_SESSION_REQ: | |||||
| { | |||||
| // TODO implement command prosessing and handling | |||||
| break; | |||||
| } | |||||
| default: | |||||
| { | |||||
| break; | |||||
| } | |||||
| } | |||||
| } | |||||
| if( dataBufferIndex != 0 ) | |||||
| { | |||||
| // Answer commands | |||||
| LmHandlerAppData_t appData = | |||||
| { | |||||
| .Buffer = LmhpRemoteMcastSetupState.DataBuffer, | |||||
| .BufferSize = dataBufferIndex, | |||||
| .Port = REMOTE_MCAST_SETUP_PORT | |||||
| }; | |||||
| LmHandlerSend( &appData, LORAMAC_HANDLER_UNCONFIRMED_MSG ); | |||||
| DBG( "ID : %d\n", McSessionData[0].McGroupData.IdHeader.Fields.McGroupId ); | |||||
| DBG( "McAddr : %08lX\n", McSessionData[0].McGroupData.McAddr ); | |||||
| DBG( "McKey : %02X", McSessionData[0].McGroupData.McKeyEncrypted[0] ); | |||||
| for( int i = 1; i < 16; i++ ) | |||||
| { | |||||
| DBG( "-%02X", McSessionData[0].McGroupData.McKeyEncrypted[i] ); | |||||
| } | |||||
| DBG( "\n" ); | |||||
| DBG( "McFCountMin : %lu\n", McSessionData[0].McGroupData.McFCountMin ); | |||||
| DBG( "McFCountMax : %lu\n", McSessionData[0].McGroupData.McFCountMax ); | |||||
| DBG( "SessionTime : %lu\n", McSessionData[0].SessionTime ); | |||||
| DBG( "SessionTimeT: %d\n", McSessionData[0].SessionTimeout ); | |||||
| DBG( "Rx Freq : %lu\n", McSessionData[0].RxParams.ClassC.Frequency ); | |||||
| DBG( "Rx DR : DR_%d\n", McSessionData[0].RxParams.ClassC.Datarate ); | |||||
| } | |||||
| } | |||||
| static void OnSessionStartTimer( void *context ) | |||||
| { | |||||
| TimerStop( &SessionStartTimer ); | |||||
| LmhpRemoteMcastSetupState.SessionState = REMOTE_MCAST_SETUP_SESSION_STATE_START; | |||||
| } | |||||
| static void OnSessionStopTimer( void *context ) | |||||
| { | |||||
| TimerStop( &SessionStopTimer ); | |||||
| LmhpRemoteMcastSetupState.SessionState = REMOTE_MCAST_SETUP_SESSION_STATE_STOP; | |||||
| } | |||||
| /*! | |||||
| * \file LmhpRemoteMcastSetup.c | |||||
| * | |||||
| * \brief Implements the LoRa-Alliance remote multicast setup package | |||||
| * Specification: https://lora-alliance.org/sites/default/files/2018-09/remote_multicast_setup_v1.0.0.pdf | |||||
| * | |||||
| * \copyright Revised BSD License, see section \ref LICENSE. | |||||
| * | |||||
| * \code | |||||
| * ______ _ | |||||
| * / _____) _ | | | |||||
| * ( (____ _____ ____ _| |_ _____ ____| |__ | |||||
| * \____ \| ___ | (_ _) ___ |/ ___) _ \ | |||||
| * _____) ) ____| | | || |_| ____( (___| | | | | |||||
| * (______/|_____)_|_|_| \__)_____)\____)_| |_| | |||||
| * (C)2013-2018 Semtech | |||||
| * | |||||
| * \endcode | |||||
| * | |||||
| * \author Miguel Luis ( Semtech ) | |||||
| */ | |||||
| #include "LmHandler.h" | |||||
| #include "LmhpRemoteMcastSetup.h" | |||||
| #define DBG_TRACE 1 | |||||
| #if DBG_TRACE == 1 | |||||
| #include <stdio.h> | |||||
| /*! | |||||
| * Works in the same way as the printf function does. | |||||
| */ | |||||
| #define DBG( ... ) \ | |||||
| do \ | |||||
| { \ | |||||
| printf( __VA_ARGS__ ); \ | |||||
| }while( 0 ) | |||||
| #else | |||||
| #define DBG( ... ) | |||||
| #endif | |||||
| /*! | |||||
| * LoRaWAN Application Layer Remote multicast setup Specification | |||||
| */ | |||||
| #define REMOTE_MCAST_SETUP_PORT 200 | |||||
| #define REMOTE_MCAST_SETUP_ID 2 | |||||
| #define REMOTE_MCAST_SETUP_VERSION 1 | |||||
| typedef enum LmhpRemoteMcastSetupSessionStates_e | |||||
| { | |||||
| REMOTE_MCAST_SETUP_SESSION_STATE_IDLE, | |||||
| REMOTE_MCAST_SETUP_SESSION_STATE_START, | |||||
| REMOTE_MCAST_SETUP_SESSION_STATE_STOP, | |||||
| }LmhpRemoteMcastSetupSessionStates_t; | |||||
| /*! | |||||
| * Package current context | |||||
| */ | |||||
| typedef struct LmhpRemoteMcastSetupState_s | |||||
| { | |||||
| bool Initialized; | |||||
| bool IsTxPending; | |||||
| LmhpRemoteMcastSetupSessionStates_t SessionState; | |||||
| uint8_t DataBufferMaxSize; | |||||
| uint8_t *DataBuffer; | |||||
| }LmhpRemoteMcastSetupState_t; | |||||
| typedef enum LmhpRemoteMcastSetupMoteCmd_e | |||||
| { | |||||
| REMOTE_MCAST_SETUP_PKG_VERSION_ANS = 0x00, | |||||
| REMOTE_MCAST_SETUP_MC_GROUP_STATUS_ANS = 0x01, | |||||
| REMOTE_MCAST_SETUP_MC_GROUP_SETUP_ANS = 0x02, | |||||
| REMOTE_MCAST_SETUP_MC_GROUP_DELETE_ANS = 0x03, | |||||
| REMOTE_MCAST_SETUP_MC_GROUP_CLASS_C_SESSION_ANS = 0x04, | |||||
| REMOTE_MCAST_SETUP_MC_GROUP_CLASS_B_SESSION_ANS = 0x05, | |||||
| }LmhpRemoteMcastSetupMoteCmd_t; | |||||
| typedef enum LmhpRemoteMcastSetupSrvCmd_e | |||||
| { | |||||
| REMOTE_MCAST_SETUP_PKG_VERSION_REQ = 0x00, | |||||
| REMOTE_MCAST_SETUP_MC_GROUP_STATUS_REQ = 0x01, | |||||
| REMOTE_MCAST_SETUP_MC_GROUP_SETUP_REQ = 0x02, | |||||
| REMOTE_MCAST_SETUP_MC_GROUP_DELETE_REQ = 0x03, | |||||
| REMOTE_MCAST_SETUP_MC_GROUP_CLASS_C_SESSION_REQ = 0x04, | |||||
| REMOTE_MCAST_SETUP_MC_GROUP_CLASS_B_SESSION_REQ = 0x05, | |||||
| }LmhpRemoteMcastSetupSrvCmd_t; | |||||
| /*! | |||||
| * Initializes the package with provided parameters | |||||
| * | |||||
| * \param [IN] params Pointer to the package parameters | |||||
| * \param [IN] dataBuffer Pointer to main application buffer | |||||
| * \param [IN] dataBufferMaxSize Main application buffer maximum size | |||||
| */ | |||||
| static void LmhpRemoteMcastSetupInit( void *params, uint8_t *dataBuffer, uint8_t dataBufferMaxSize ); | |||||
| /*! | |||||
| * Returns the current package initialization status. | |||||
| * | |||||
| * \retval status Package initialization status | |||||
| * [true: Initialized, false: Not initialized] | |||||
| */ | |||||
| static bool LmhpRemoteMcastSetupIsInitialized( void ); | |||||
| /*! | |||||
| * Returns if a package transmission is pending or not. | |||||
| * | |||||
| * \retval status Package transmission status | |||||
| * [true: pending, false: Not pending] | |||||
| */ | |||||
| static bool LmhpRemoteMcastSetupIsTxPending( void ); | |||||
| /*! | |||||
| * Processes the internal package events. | |||||
| */ | |||||
| static void LmhpRemoteMcastSetupProcess( void ); | |||||
| /*! | |||||
| * Processes the MCPS Indication | |||||
| * | |||||
| * \param [IN] mcpsIndication MCPS indication primitive data | |||||
| */ | |||||
| static void LmhpRemoteMcastSetupOnMcpsIndication( McpsIndication_t *mcpsIndication ); | |||||
| static void OnSessionStartTimer( void *context ); | |||||
| static void OnSessionStopTimer( void *context ); | |||||
| static LmhpRemoteMcastSetupState_t LmhpRemoteMcastSetupState = | |||||
| { | |||||
| .Initialized = false, | |||||
| .IsTxPending = false, | |||||
| .SessionState = REMOTE_MCAST_SETUP_SESSION_STATE_IDLE, | |||||
| }; | |||||
| typedef struct McGroupData_s | |||||
| { | |||||
| union | |||||
| { | |||||
| uint8_t Value; | |||||
| struct | |||||
| { | |||||
| uint8_t McGroupId: 2; | |||||
| uint8_t RFU: 6; | |||||
| }Fields; | |||||
| }IdHeader; | |||||
| uint32_t McAddr; | |||||
| uint8_t McKeyEncrypted[16]; | |||||
| uint32_t McFCountMin; | |||||
| uint32_t McFCountMax; | |||||
| }McGroupData_t; | |||||
| typedef enum eSessionState | |||||
| { | |||||
| SESSION_STOPED, | |||||
| SESSION_STARTED | |||||
| }SessionState_t; | |||||
| typedef struct McSessionData_s | |||||
| { | |||||
| McGroupData_t McGroupData; | |||||
| SessionState_t SessionState; | |||||
| uint32_t SessionTime; | |||||
| uint8_t SessionTimeout; | |||||
| McRxParams_t RxParams; | |||||
| }McSessionData_t; | |||||
| McSessionData_t McSessionData[LORAMAC_MAX_MC_CTX]; | |||||
| /*! | |||||
| * Session start timer | |||||
| */ | |||||
| static TimerEvent_t SessionStartTimer; | |||||
| /*! | |||||
| * Session start timer | |||||
| */ | |||||
| static TimerEvent_t SessionStopTimer; | |||||
| static LmhPackage_t LmhpRemoteMcastSetupPackage = | |||||
| { | |||||
| .Port = REMOTE_MCAST_SETUP_PORT, | |||||
| .Init = LmhpRemoteMcastSetupInit, | |||||
| .IsInitialized = LmhpRemoteMcastSetupIsInitialized, | |||||
| .IsTxPending = LmhpRemoteMcastSetupIsTxPending, | |||||
| .Process = LmhpRemoteMcastSetupProcess, | |||||
| .OnMcpsConfirmProcess = NULL, // Not used in this package | |||||
| .OnMcpsIndicationProcess = LmhpRemoteMcastSetupOnMcpsIndication, | |||||
| .OnMlmeConfirmProcess = NULL, // Not used in this package | |||||
| .OnMlmeIndicationProcess = NULL, // Not used in this package | |||||
| .OnMacMcpsRequest = NULL, // To be initialized by LmHandler | |||||
| .OnMacMlmeRequest = NULL, // To be initialized by LmHandler | |||||
| .OnJoinRequest = NULL, // To be initialized by LmHandler | |||||
| .OnDeviceTimeRequest = NULL, // To be initialized by LmHandler | |||||
| .OnSysTimeUpdate = NULL, // To be initialized by LmHandler | |||||
| }; | |||||
| LmhPackage_t *LmhpRemoteMcastSetupPackageFactory( void ) | |||||
| { | |||||
| return &LmhpRemoteMcastSetupPackage; | |||||
| } | |||||
| static void LmhpRemoteMcastSetupInit( void * params, uint8_t *dataBuffer, uint8_t dataBufferMaxSize ) | |||||
| { | |||||
| if( dataBuffer != NULL ) | |||||
| { | |||||
| LmhpRemoteMcastSetupState.DataBuffer = dataBuffer; | |||||
| LmhpRemoteMcastSetupState.DataBufferMaxSize = dataBufferMaxSize; | |||||
| LmhpRemoteMcastSetupState.Initialized = true; | |||||
| TimerInit( &SessionStartTimer, OnSessionStartTimer ); | |||||
| TimerInit( &SessionStopTimer, OnSessionStopTimer ); | |||||
| } | |||||
| else | |||||
| { | |||||
| LmhpRemoteMcastSetupState.Initialized = false; | |||||
| } | |||||
| LmhpRemoteMcastSetupState.IsTxPending = false; | |||||
| } | |||||
| static bool LmhpRemoteMcastSetupIsInitialized( void ) | |||||
| { | |||||
| return LmhpRemoteMcastSetupState.Initialized; | |||||
| } | |||||
| static bool LmhpRemoteMcastSetupIsTxPending( void ) | |||||
| { | |||||
| return LmhpRemoteMcastSetupState.IsTxPending; | |||||
| } | |||||
| static void LmhpRemoteMcastSetupProcess( void ) | |||||
| { | |||||
| LmhpRemoteMcastSetupSessionStates_t state; | |||||
| CRITICAL_SECTION_BEGIN( ); | |||||
| state = LmhpRemoteMcastSetupState.SessionState; | |||||
| LmhpRemoteMcastSetupState.SessionState = REMOTE_MCAST_SETUP_SESSION_STATE_IDLE; | |||||
| CRITICAL_SECTION_END( ); | |||||
| switch( state ) | |||||
| { | |||||
| case REMOTE_MCAST_SETUP_SESSION_STATE_START: | |||||
| // Switch to Class C | |||||
| LmHandlerRequestClass( CLASS_C ); | |||||
| TimerSetValue( &SessionStopTimer, ( 1 << McSessionData[0].SessionTimeout ) * 1000 ); | |||||
| TimerStart( &SessionStopTimer ); | |||||
| break; | |||||
| case REMOTE_MCAST_SETUP_SESSION_STATE_STOP: | |||||
| // Switch back to Class A | |||||
| LmHandlerRequestClass( CLASS_A ); | |||||
| break; | |||||
| case REMOTE_MCAST_SETUP_SESSION_STATE_IDLE: | |||||
| // Intentional fall through | |||||
| default: | |||||
| // Nothing to do. | |||||
| break; | |||||
| } | |||||
| } | |||||
| static void LmhpRemoteMcastSetupOnMcpsIndication( McpsIndication_t *mcpsIndication ) | |||||
| { | |||||
| uint8_t cmdIndex = 0; | |||||
| uint8_t dataBufferIndex = 0; | |||||
| if( mcpsIndication->Port != REMOTE_MCAST_SETUP_PORT ) | |||||
| { | |||||
| return; | |||||
| } | |||||
| while( cmdIndex < mcpsIndication->BufferSize ) | |||||
| { | |||||
| switch( mcpsIndication->Buffer[cmdIndex++] ) | |||||
| { | |||||
| case REMOTE_MCAST_SETUP_PKG_VERSION_REQ: | |||||
| { | |||||
| LmhpRemoteMcastSetupState.DataBuffer[dataBufferIndex++] = REMOTE_MCAST_SETUP_PKG_VERSION_ANS; | |||||
| LmhpRemoteMcastSetupState.DataBuffer[dataBufferIndex++] = REMOTE_MCAST_SETUP_ID; | |||||
| LmhpRemoteMcastSetupState.DataBuffer[dataBufferIndex++] = REMOTE_MCAST_SETUP_VERSION; | |||||
| break; | |||||
| } | |||||
| case REMOTE_MCAST_SETUP_MC_GROUP_STATUS_REQ: | |||||
| { | |||||
| // TODO implement command prosessing and handling | |||||
| break; | |||||
| } | |||||
| case REMOTE_MCAST_SETUP_MC_GROUP_SETUP_REQ: | |||||
| { | |||||
| uint8_t id = mcpsIndication->Buffer[cmdIndex++]; | |||||
| McSessionData[id].McGroupData.IdHeader.Value = id; | |||||
| McSessionData[id].McGroupData.McAddr = ( mcpsIndication->Buffer[cmdIndex++] << 0 ) & 0x000000FF; | |||||
| McSessionData[id].McGroupData.McAddr += ( mcpsIndication->Buffer[cmdIndex++] << 8 ) & 0x0000FF00; | |||||
| McSessionData[id].McGroupData.McAddr += ( mcpsIndication->Buffer[cmdIndex++] << 16 ) & 0x00FF0000; | |||||
| McSessionData[id].McGroupData.McAddr += ( mcpsIndication->Buffer[cmdIndex++] << 24 ) & 0xFF000000; | |||||
| for( int8_t i = 0; i < 16; i++ ) | |||||
| { | |||||
| McSessionData[id].McGroupData.McKeyEncrypted[i] = mcpsIndication->Buffer[cmdIndex++]; | |||||
| } | |||||
| McSessionData[id].McGroupData.McFCountMin = ( mcpsIndication->Buffer[cmdIndex++] << 0 ) & 0x000000FF; | |||||
| McSessionData[id].McGroupData.McFCountMin += ( mcpsIndication->Buffer[cmdIndex++] << 8 ) & 0x0000FF00; | |||||
| McSessionData[id].McGroupData.McFCountMin += ( mcpsIndication->Buffer[cmdIndex++] << 16 ) & 0x00FF0000; | |||||
| McSessionData[id].McGroupData.McFCountMin += ( mcpsIndication->Buffer[cmdIndex++] << 24 ) & 0xFF000000; | |||||
| McSessionData[id].McGroupData.McFCountMax = ( mcpsIndication->Buffer[cmdIndex++] << 0 ) & 0x000000FF; | |||||
| McSessionData[id].McGroupData.McFCountMax += ( mcpsIndication->Buffer[cmdIndex++] << 8 ) & 0x0000FF00; | |||||
| McSessionData[id].McGroupData.McFCountMax += ( mcpsIndication->Buffer[cmdIndex++] << 16 ) & 0x00FF0000; | |||||
| McSessionData[id].McGroupData.McFCountMax += ( mcpsIndication->Buffer[cmdIndex++] << 24 ) & 0xFF000000; | |||||
| McChannelParams_t channel = | |||||
| { | |||||
| .IsRemotelySetup = true, | |||||
| .Class = CLASS_C, // Field not used for multicast channel setup. Must be initialized to something | |||||
| .IsEnabled = true, | |||||
| .GroupID = ( AddressIdentifier_t )McSessionData[id].McGroupData.IdHeader.Fields.McGroupId, | |||||
| .Address = McSessionData[id].McGroupData.McAddr, | |||||
| .McKeys.McKeyE = McSessionData[id].McGroupData.McKeyEncrypted, | |||||
| .FCountMin = McSessionData[id].McGroupData.McFCountMin, | |||||
| .FCountMax = McSessionData[id].McGroupData.McFCountMax, | |||||
| .RxParams.ClassC = // Field not used for multicast channel setup. Must be initialized to something | |||||
| { | |||||
| .Frequency = 0, | |||||
| .Datarate = 0 | |||||
| } | |||||
| }; | |||||
| uint8_t idError = 0x01; // One bit value | |||||
| if( LoRaMacMcChannelSetup( &channel ) == LORAMAC_STATUS_OK ) | |||||
| { | |||||
| idError = 0x00; | |||||
| } | |||||
| LmhpRemoteMcastSetupState.DataBuffer[dataBufferIndex++] = REMOTE_MCAST_SETUP_MC_GROUP_SETUP_ANS; | |||||
| LmhpRemoteMcastSetupState.DataBuffer[dataBufferIndex++] = ( idError << 2 ) | McSessionData[id].McGroupData.IdHeader.Fields.McGroupId; | |||||
| break; | |||||
| } | |||||
| case REMOTE_MCAST_SETUP_MC_GROUP_DELETE_REQ: | |||||
| { | |||||
| uint8_t status = 0x00; | |||||
| uint8_t id = mcpsIndication->Buffer[cmdIndex++] & 0x03; | |||||
| status = id; | |||||
| LmhpRemoteMcastSetupState.DataBuffer[dataBufferIndex++] = REMOTE_MCAST_SETUP_MC_GROUP_DELETE_ANS; | |||||
| if( LoRaMacMcChannelDelete( ( AddressIdentifier_t )id ) != LORAMAC_STATUS_OK ) | |||||
| { | |||||
| status |= 0x04; // McGroupUndefined bit set | |||||
| } | |||||
| LmhpRemoteMcastSetupState.DataBuffer[dataBufferIndex++] = status; | |||||
| break; | |||||
| } | |||||
| case REMOTE_MCAST_SETUP_MC_GROUP_CLASS_C_SESSION_REQ: | |||||
| { | |||||
| uint8_t status = 0x00; | |||||
| uint8_t id = mcpsIndication->Buffer[cmdIndex++] & 0x03; | |||||
| McSessionData[id].SessionTime = ( mcpsIndication->Buffer[cmdIndex++] << 0 ) & 0x000000FF; | |||||
| McSessionData[id].SessionTime += ( mcpsIndication->Buffer[cmdIndex++] << 8 ) & 0x0000FF00; | |||||
| McSessionData[id].SessionTime += ( mcpsIndication->Buffer[cmdIndex++] << 16 ) & 0x00FF0000; | |||||
| McSessionData[id].SessionTime += ( mcpsIndication->Buffer[cmdIndex++] << 24 ) & 0xFF000000; | |||||
| // Add Unix to Gps epcoh offset. The system time is based on Unix time. | |||||
| McSessionData[id].SessionTime += UNIX_GPS_EPOCH_OFFSET; | |||||
| McSessionData[id].SessionTimeout = mcpsIndication->Buffer[cmdIndex++] & 0x0F; | |||||
| McSessionData[id].RxParams.ClassC.Frequency = ( mcpsIndication->Buffer[cmdIndex++] << 0 ) & 0x000000FF; | |||||
| McSessionData[id].RxParams.ClassC.Frequency |= ( mcpsIndication->Buffer[cmdIndex++] << 8 ) & 0x0000FF00; | |||||
| McSessionData[id].RxParams.ClassC.Frequency |= ( mcpsIndication->Buffer[cmdIndex++] << 16 ) & 0x00FF0000; | |||||
| McSessionData[id].RxParams.ClassC.Frequency *= 100; | |||||
| McSessionData[id].RxParams.ClassC.Datarate = mcpsIndication->Buffer[cmdIndex++]; | |||||
| LmhpRemoteMcastSetupState.DataBuffer[dataBufferIndex++] = REMOTE_MCAST_SETUP_MC_GROUP_CLASS_C_SESSION_ANS; | |||||
| if( LoRaMacMcChannelSetupRxParams( ( AddressIdentifier_t )id, &McSessionData[id].RxParams, &status ) == LORAMAC_STATUS_OK ) | |||||
| { | |||||
| SysTime_t curTime = { .Seconds = 0, .SubSeconds = 0 }; | |||||
| curTime = SysTimeGet( ); | |||||
| int32_t timeToSessionStart = McSessionData[id].SessionTime - curTime.Seconds; | |||||
| if( timeToSessionStart > 0 ) | |||||
| { | |||||
| // Start session start timer | |||||
| TimerSetValue( &SessionStartTimer, timeToSessionStart * 1000 ); | |||||
| TimerStart( &SessionStartTimer ); | |||||
| DBG( "Time2SessionStart: %ld ms\n", timeToSessionStart * 1000 ); | |||||
| LmhpRemoteMcastSetupState.DataBuffer[dataBufferIndex++] = status; | |||||
| LmhpRemoteMcastSetupState.DataBuffer[dataBufferIndex++] = ( timeToSessionStart >> 0 ) & 0xFF; | |||||
| LmhpRemoteMcastSetupState.DataBuffer[dataBufferIndex++] = ( timeToSessionStart >> 8 ) & 0xFF; | |||||
| LmhpRemoteMcastSetupState.DataBuffer[dataBufferIndex++] = ( timeToSessionStart >> 16 ) & 0xFF; | |||||
| break; | |||||
| } | |||||
| else | |||||
| { | |||||
| // Session start time before current device time | |||||
| status |= 0x10; | |||||
| } | |||||
| } | |||||
| LmhpRemoteMcastSetupState.DataBuffer[dataBufferIndex++] = status; | |||||
| break; | |||||
| } | |||||
| case REMOTE_MCAST_SETUP_MC_GROUP_CLASS_B_SESSION_REQ: | |||||
| { | |||||
| // TODO implement command prosessing and handling | |||||
| break; | |||||
| } | |||||
| default: | |||||
| { | |||||
| break; | |||||
| } | |||||
| } | |||||
| } | |||||
| if( dataBufferIndex != 0 ) | |||||
| { | |||||
| // Answer commands | |||||
| LmHandlerAppData_t appData = | |||||
| { | |||||
| .Buffer = LmhpRemoteMcastSetupState.DataBuffer, | |||||
| .BufferSize = dataBufferIndex, | |||||
| .Port = REMOTE_MCAST_SETUP_PORT | |||||
| }; | |||||
| LmHandlerSend( &appData, LORAMAC_HANDLER_UNCONFIRMED_MSG ); | |||||
| DBG( "ID : %d\n", McSessionData[0].McGroupData.IdHeader.Fields.McGroupId ); | |||||
| DBG( "McAddr : %08lX\n", McSessionData[0].McGroupData.McAddr ); | |||||
| DBG( "McKey : %02X", McSessionData[0].McGroupData.McKeyEncrypted[0] ); | |||||
| for( int i = 1; i < 16; i++ ) | |||||
| { | |||||
| DBG( "-%02X", McSessionData[0].McGroupData.McKeyEncrypted[i] ); | |||||
| } | |||||
| DBG( "\n" ); | |||||
| DBG( "McFCountMin : %lu\n", McSessionData[0].McGroupData.McFCountMin ); | |||||
| DBG( "McFCountMax : %lu\n", McSessionData[0].McGroupData.McFCountMax ); | |||||
| DBG( "SessionTime : %lu\n", McSessionData[0].SessionTime ); | |||||
| DBG( "SessionTimeT: %d\n", McSessionData[0].SessionTimeout ); | |||||
| DBG( "Rx Freq : %lu\n", McSessionData[0].RxParams.ClassC.Frequency ); | |||||
| DBG( "Rx DR : DR_%d\n", McSessionData[0].RxParams.ClassC.Datarate ); | |||||
| } | |||||
| } | |||||
| static void OnSessionStartTimer( void *context ) | |||||
| { | |||||
| TimerStop( &SessionStartTimer ); | |||||
| LmhpRemoteMcastSetupState.SessionState = REMOTE_MCAST_SETUP_SESSION_STATE_START; | |||||
| } | |||||
| static void OnSessionStopTimer( void *context ) | |||||
| { | |||||
| TimerStop( &SessionStopTimer ); | |||||
| LmhpRemoteMcastSetupState.SessionState = REMOTE_MCAST_SETUP_SESSION_STATE_STOP; | |||||
| } | |||||
| @@ -1,47 +1,47 @@ | |||||
| /*! | |||||
| * \file LmhpRemoteMcastSetup.h | |||||
| * | |||||
| * \brief Implements the LoRa-Alliance remote multicast setup package | |||||
| * Specification: https://lora-alliance.org/sites/default/files/2018-09/remote_multicast_setup_v1.0.0.pdf | |||||
| * | |||||
| * \copyright Revised BSD License, see section \ref LICENSE. | |||||
| * | |||||
| * \code | |||||
| * ______ _ | |||||
| * / _____) _ | | | |||||
| * ( (____ _____ ____ _| |_ _____ ____| |__ | |||||
| * \____ \| ___ | (_ _) ___ |/ ___) _ \ | |||||
| * _____) ) ____| | | || |_| ____( (___| | | | | |||||
| * (______/|_____)_|_|_| \__)_____)\____)_| |_| | |||||
| * (C)2013-2018 Semtech | |||||
| * | |||||
| * \endcode | |||||
| * | |||||
| * \author Miguel Luis ( Semtech ) | |||||
| */ | |||||
| #ifndef __LMHP_REMOTE_MCAST_SETUP_H__ | |||||
| #define __LMHP_REMOTE_MCAST_SETUP_H__ | |||||
| #include "LoRaMac.h" | |||||
| #include "LmHandlerTypes.h" | |||||
| #include "LmhPackage.h" | |||||
| /*! | |||||
| * Remote multicast setup package identifier. | |||||
| * | |||||
| * \remark This value must be unique amongst the packages | |||||
| */ | |||||
| #define PACKAGE_ID_REMOTE_MCAST_SETUP 2 | |||||
| /*! | |||||
| * Remote multicast setup package parameters | |||||
| * | |||||
| * This package doesn't require parameters | |||||
| */ | |||||
| //typedef struct LmhpRemoteMcastSetupParams_s | |||||
| //{ | |||||
| //}LmhpRemoteMcastSetupParams_t; | |||||
| LmhPackage_t *LmhpRemoteMcastSetupPackageFactory( void ); | |||||
| #endif // __LMHP_REMOTE_MCAST_SETUP_H__ | |||||
| /*! | |||||
| * \file LmhpRemoteMcastSetup.h | |||||
| * | |||||
| * \brief Implements the LoRa-Alliance remote multicast setup package | |||||
| * Specification: https://lora-alliance.org/sites/default/files/2018-09/remote_multicast_setup_v1.0.0.pdf | |||||
| * | |||||
| * \copyright Revised BSD License, see section \ref LICENSE. | |||||
| * | |||||
| * \code | |||||
| * ______ _ | |||||
| * / _____) _ | | | |||||
| * ( (____ _____ ____ _| |_ _____ ____| |__ | |||||
| * \____ \| ___ | (_ _) ___ |/ ___) _ \ | |||||
| * _____) ) ____| | | || |_| ____( (___| | | | | |||||
| * (______/|_____)_|_|_| \__)_____)\____)_| |_| | |||||
| * (C)2013-2018 Semtech | |||||
| * | |||||
| * \endcode | |||||
| * | |||||
| * \author Miguel Luis ( Semtech ) | |||||
| */ | |||||
| #ifndef __LMHP_REMOTE_MCAST_SETUP_H__ | |||||
| #define __LMHP_REMOTE_MCAST_SETUP_H__ | |||||
| #include "LoRaMac.h" | |||||
| #include "LmHandlerTypes.h" | |||||
| #include "LmhPackage.h" | |||||
| /*! | |||||
| * Remote multicast setup package identifier. | |||||
| * | |||||
| * \remark This value must be unique amongst the packages | |||||
| */ | |||||
| #define PACKAGE_ID_REMOTE_MCAST_SETUP 2 | |||||
| /*! | |||||
| * Remote multicast setup package parameters | |||||
| * | |||||
| * This package doesn't require parameters | |||||
| */ | |||||
| //typedef struct LmhpRemoteMcastSetupParams_s | |||||
| //{ | |||||
| //}LmhpRemoteMcastSetupParams_t; | |||||
| LmhPackage_t *LmhpRemoteMcastSetupPackageFactory( void ); | |||||
| #endif // __LMHP_REMOTE_MCAST_SETUP_H__ | |||||
| @@ -1,428 +1,428 @@ | |||||
| /*! | |||||
| * \file LmHandlerMsgDisplay.h | |||||
| * | |||||
| * \brief Common set of functions to display default messages from | |||||
| * LoRaMacHandler. | |||||
| * | |||||
| * \copyright Revised BSD License, see section \ref LICENSE. | |||||
| * | |||||
| * \code | |||||
| * ______ _ | |||||
| * / _____) _ | | | |||||
| * ( (____ _____ ____ _| |_ _____ ____| |__ | |||||
| * \____ \| ___ | (_ _) ___ |/ ___) _ \ | |||||
| * _____) ) ____| | | || |_| ____( (___| | | | | |||||
| * (______/|_____)_|_|_| \__)_____)\____)_| |_| | |||||
| * (C)2013-2019 Semtech | |||||
| * | |||||
| * \endcode | |||||
| * | |||||
| * \author Miguel Luis ( Semtech ) | |||||
| */ | |||||
| #include <stdlib.h> | |||||
| #include <stdint.h> | |||||
| #include <stdbool.h> | |||||
| #include <stdio.h> | |||||
| #include "utilities.h" | |||||
| #include "timer.h" | |||||
| #include "LmHandlerMsgDisplay.h" | |||||
| /*! | |||||
| * MAC status strings | |||||
| */ | |||||
| const char* MacStatusStrings[] = | |||||
| { | |||||
| "OK", // LORAMAC_STATUS_OK | |||||
| "Busy", // LORAMAC_STATUS_BUSY | |||||
| "Service unknown", // LORAMAC_STATUS_SERVICE_UNKNOWN | |||||
| "Parameter invalid", // LORAMAC_STATUS_PARAMETER_INVALID | |||||
| "Frequency invalid", // LORAMAC_STATUS_FREQUENCY_INVALID | |||||
| "Datarate invalid", // LORAMAC_STATUS_DATARATE_INVALID | |||||
| "Frequency or datarate invalid", // LORAMAC_STATUS_FREQ_AND_DR_INVALID | |||||
| "No network joined", // LORAMAC_STATUS_NO_NETWORK_JOINED | |||||
| "Length error", // LORAMAC_STATUS_LENGTH_ERROR | |||||
| "Region not supported", // LORAMAC_STATUS_REGION_NOT_SUPPORTED | |||||
| "Skipped APP data", // LORAMAC_STATUS_SKIPPED_APP_DATA | |||||
| "Duty-cycle restricted", // LORAMAC_STATUS_DUTYCYCLE_RESTRICTED | |||||
| "No channel found", // LORAMAC_STATUS_NO_CHANNEL_FOUND | |||||
| "No free channel found", // LORAMAC_STATUS_NO_FREE_CHANNEL_FOUND | |||||
| "Busy beacon reserved time", // LORAMAC_STATUS_BUSY_BEACON_RESERVED_TIME | |||||
| "Busy ping-slot window time", // LORAMAC_STATUS_BUSY_PING_SLOT_WINDOW_TIME | |||||
| "Busy uplink collision", // LORAMAC_STATUS_BUSY_UPLINK_COLLISION | |||||
| "Crypto error", // LORAMAC_STATUS_CRYPTO_ERROR | |||||
| "FCnt handler error", // LORAMAC_STATUS_FCNT_HANDLER_ERROR | |||||
| "MAC command error", // LORAMAC_STATUS_MAC_COMMAD_ERROR | |||||
| "ClassB error", // LORAMAC_STATUS_CLASS_B_ERROR | |||||
| "Confirm queue error", // LORAMAC_STATUS_CONFIRM_QUEUE_ERROR | |||||
| "Multicast group undefined", // LORAMAC_STATUS_MC_GROUP_UNDEFINED | |||||
| "Unknown error", // LORAMAC_STATUS_ERROR | |||||
| }; | |||||
| /*! | |||||
| * MAC event info status strings. | |||||
| */ | |||||
| const char* EventInfoStatusStrings[] = | |||||
| { | |||||
| "OK", // LORAMAC_EVENT_INFO_STATUS_OK | |||||
| "Error", // LORAMAC_EVENT_INFO_STATUS_ERROR | |||||
| "Tx timeout", // LORAMAC_EVENT_INFO_STATUS_TX_TIMEOUT | |||||
| "Rx 1 timeout", // LORAMAC_EVENT_INFO_STATUS_RX1_TIMEOUT | |||||
| "Rx 2 timeout", // LORAMAC_EVENT_INFO_STATUS_RX2_TIMEOUT | |||||
| "Rx1 error", // LORAMAC_EVENT_INFO_STATUS_RX1_ERROR | |||||
| "Rx2 error", // LORAMAC_EVENT_INFO_STATUS_RX2_ERROR | |||||
| "Join failed", // LORAMAC_EVENT_INFO_STATUS_JOIN_FAIL | |||||
| "Downlink repeated", // LORAMAC_EVENT_INFO_STATUS_DOWNLINK_REPEATED | |||||
| "Tx DR payload size error", // LORAMAC_EVENT_INFO_STATUS_TX_DR_PAYLOAD_SIZE_ERROR | |||||
| "Address fail", // LORAMAC_EVENT_INFO_STATUS_ADDRESS_FAIL | |||||
| "MIC fail", // LORAMAC_EVENT_INFO_STATUS_MIC_FAIL | |||||
| "Multicast fail", // LORAMAC_EVENT_INFO_STATUS_MULTICAST_FAIL | |||||
| "Beacon locked", // LORAMAC_EVENT_INFO_STATUS_BEACON_LOCKED | |||||
| "Beacon lost", // LORAMAC_EVENT_INFO_STATUS_BEACON_LOST | |||||
| "Beacon not found" // LORAMAC_EVENT_INFO_STATUS_BEACON_NOT_FOUND | |||||
| }; | |||||
| /*! | |||||
| * Prints the provided buffer in HEX | |||||
| * | |||||
| * \param buffer Buffer to be printed | |||||
| * \param size Buffer size to be printed | |||||
| */ | |||||
| void PrintHexBuffer( uint8_t *buffer, uint8_t size ) | |||||
| { | |||||
| uint8_t newline = 0; | |||||
| for( uint8_t i = 0; i < size; i++ ) | |||||
| { | |||||
| if( newline != 0 ) | |||||
| { | |||||
| printf( "\n" ); | |||||
| newline = 0; | |||||
| } | |||||
| printf( "%02X ", buffer[i] ); | |||||
| if( ( ( i + 1 ) % 16 ) == 0 ) | |||||
| { | |||||
| newline = 1; | |||||
| } | |||||
| } | |||||
| printf( "\n" ); | |||||
| } | |||||
| void DisplayNvmDataChange( LmHandlerNvmContextStates_t state, uint16_t size ) | |||||
| { | |||||
| if( state == LORAMAC_HANDLER_NVM_STORE ) | |||||
| { | |||||
| printf( "\n###### ============ CTXS STORED ============ ######\n" ); | |||||
| } | |||||
| else | |||||
| { | |||||
| printf( "\n###### =========== CTXS RESTORED =========== ######\n" ); | |||||
| } | |||||
| printf( "Size : %i\n\n", size ); | |||||
| } | |||||
| void DisplayNetworkParametersUpdate( CommissioningParams_t *commissioningParams ) | |||||
| { | |||||
| printf( "DevEui : %02X", commissioningParams->DevEui[0] ); | |||||
| for( int i = 1; i < 8; i++ ) | |||||
| { | |||||
| printf( "-%02X", commissioningParams->DevEui[i] ); | |||||
| } | |||||
| printf( "\n" ); | |||||
| printf( "JoinEui : %02X", commissioningParams->JoinEui[0] ); | |||||
| for( int i = 1; i < 8; i++ ) | |||||
| { | |||||
| printf( "-%02X", commissioningParams->JoinEui[i] ); | |||||
| } | |||||
| printf( "\n" ); | |||||
| printf( "Pin : %02X", commissioningParams->SePin[0] ); | |||||
| for( int i = 1; i < 4; i++ ) | |||||
| { | |||||
| printf( "-%02X", commissioningParams->SePin[i] ); | |||||
| } | |||||
| printf( "\n\n" ); | |||||
| } | |||||
| void DisplayMacMcpsRequestUpdate( LoRaMacStatus_t status, McpsReq_t *mcpsReq, TimerTime_t nextTxIn ) | |||||
| { | |||||
| switch( mcpsReq->Type ) | |||||
| { | |||||
| case MCPS_CONFIRMED: | |||||
| { | |||||
| printf( "\n###### =========== MCPS-Request ============ ######\n" ); | |||||
| printf( "###### MCPS_CONFIRMED ######\n"); | |||||
| printf( "###### ===================================== ######\n"); | |||||
| break; | |||||
| } | |||||
| case MCPS_UNCONFIRMED: | |||||
| { | |||||
| printf( "\n###### =========== MCPS-Request ============ ######\n" ); | |||||
| printf( "###### MCPS_UNCONFIRMED ######\n"); | |||||
| printf( "###### ===================================== ######\n"); | |||||
| break; | |||||
| } | |||||
| case MCPS_PROPRIETARY: | |||||
| { | |||||
| printf( "\n###### =========== MCPS-Request ============ ######\n" ); | |||||
| printf( "###### MCPS_PROPRIETARY ######\n"); | |||||
| printf( "###### ===================================== ######\n"); | |||||
| break; | |||||
| } | |||||
| default: | |||||
| { | |||||
| printf( "\n###### =========== MCPS-Request ============ ######\n" ); | |||||
| printf( "###### MCPS_ERROR ######\n"); | |||||
| printf( "###### ===================================== ######\n"); | |||||
| break; | |||||
| } | |||||
| } | |||||
| printf( "STATUS : %s\n", MacStatusStrings[status] ); | |||||
| if( status == LORAMAC_STATUS_DUTYCYCLE_RESTRICTED ) | |||||
| { | |||||
| printf( "Next Tx in : %lu [ms]\n", nextTxIn ); | |||||
| } | |||||
| } | |||||
| void DisplayMacMlmeRequestUpdate( LoRaMacStatus_t status, MlmeReq_t *mlmeReq, TimerTime_t nextTxIn ) | |||||
| { | |||||
| switch( mlmeReq->Type ) | |||||
| { | |||||
| case MLME_JOIN: | |||||
| { | |||||
| printf( "\n###### =========== MLME-Request ============ ######\n" ); | |||||
| printf( "###### MLME_JOIN ######\n"); | |||||
| printf( "###### ===================================== ######\n"); | |||||
| break; | |||||
| } | |||||
| case MLME_LINK_CHECK: | |||||
| { | |||||
| printf( "\n###### =========== MLME-Request ============ ######\n" ); | |||||
| printf( "###### MLME_LINK_CHECK ######\n"); | |||||
| printf( "###### ===================================== ######\n"); | |||||
| break; | |||||
| } | |||||
| case MLME_DEVICE_TIME: | |||||
| { | |||||
| printf( "\n###### =========== MLME-Request ============ ######\n" ); | |||||
| printf( "###### MLME_DEVICE_TIME ######\n"); | |||||
| printf( "###### ===================================== ######\n"); | |||||
| break; | |||||
| } | |||||
| case MLME_TXCW: | |||||
| { | |||||
| printf( "\n###### =========== MLME-Request ============ ######\n" ); | |||||
| printf( "###### MLME_TXCW ######\n"); | |||||
| printf( "###### ===================================== ######\n"); | |||||
| break; | |||||
| } | |||||
| default: | |||||
| { | |||||
| printf( "\n###### =========== MLME-Request ============ ######\n" ); | |||||
| printf( "###### MLME_UNKNOWN ######\n"); | |||||
| printf( "###### ===================================== ######\n"); | |||||
| break; | |||||
| } | |||||
| } | |||||
| printf( "STATUS : %s\n", MacStatusStrings[status] ); | |||||
| if( status == LORAMAC_STATUS_DUTYCYCLE_RESTRICTED ) | |||||
| { | |||||
| printf( "Next Tx in : %lu [ms]\n", nextTxIn ); | |||||
| } | |||||
| } | |||||
| void DisplayJoinRequestUpdate( LmHandlerJoinParams_t *params ) | |||||
| { | |||||
| if( params->CommissioningParams->IsOtaaActivation == true ) | |||||
| { | |||||
| if( params->Status == LORAMAC_HANDLER_SUCCESS ) | |||||
| { | |||||
| printf( "###### =========== JOINED ============ ######\n" ); | |||||
| printf( "\nOTAA\n\n" ); | |||||
| printf( "DevAddr : %08lX\n", params->CommissioningParams->DevAddr ); | |||||
| printf( "\n\n" ); | |||||
| printf( "DATA RATE : DR_%d\n\n", params->Datarate ); | |||||
| } | |||||
| } | |||||
| #if ( OVER_THE_AIR_ACTIVATION == 0 ) | |||||
| else | |||||
| { | |||||
| printf( "###### =========== JOINED ============ ######\n" ); | |||||
| printf( "\nABP\n\n" ); | |||||
| printf( "DevAddr : %08lX\n", params->CommissioningParams->DevAddr ); | |||||
| printf( "\n\n" ); | |||||
| } | |||||
| #endif | |||||
| } | |||||
| void DisplayTxUpdate( LmHandlerTxParams_t *params ) | |||||
| { | |||||
| MibRequestConfirm_t mibGet; | |||||
| if( params->IsMcpsConfirm == 0 ) | |||||
| { | |||||
| printf( "\n###### =========== MLME-Confirm ============ ######\n" ); | |||||
| printf( "STATUS : %s\n", EventInfoStatusStrings[params->Status] ); | |||||
| return; | |||||
| } | |||||
| printf( "\n###### =========== MCPS-Confirm ============ ######\n" ); | |||||
| printf( "STATUS : %s\n", EventInfoStatusStrings[params->Status] ); | |||||
| printf( "\n###### ===== UPLINK FRAME %8lu ===== ######\n", params->UplinkCounter ); | |||||
| printf( "\n" ); | |||||
| printf( "CLASS : %c\n", "ABC"[LmHandlerGetCurrentClass( )] ); | |||||
| printf( "\n" ); | |||||
| printf( "TX PORT : %d\n", params->AppData.Port ); | |||||
| if( params->AppData.BufferSize != 0 ) | |||||
| { | |||||
| printf( "TX DATA : " ); | |||||
| if( params->MsgType == LORAMAC_HANDLER_CONFIRMED_MSG ) | |||||
| { | |||||
| printf( "CONFIRMED - %s\n", ( params->AckReceived != 0 ) ? "ACK" : "NACK" ); | |||||
| } | |||||
| else | |||||
| { | |||||
| printf( "UNCONFIRMED\n" ); | |||||
| } | |||||
| PrintHexBuffer( params->AppData.Buffer, params->AppData.BufferSize ); | |||||
| } | |||||
| printf( "\n" ); | |||||
| printf( "DATA RATE : DR_%d\n", params->Datarate ); | |||||
| mibGet.Type = MIB_CHANNELS; | |||||
| if( LoRaMacMibGetRequestConfirm( &mibGet ) == LORAMAC_STATUS_OK ) | |||||
| { | |||||
| printf( "U/L FREQ : %lu\n", mibGet.Param.ChannelList[params->Channel].Frequency ); | |||||
| } | |||||
| printf( "TX POWER : %d\n", params->TxPower ); | |||||
| mibGet.Type = MIB_CHANNELS_MASK; | |||||
| if( LoRaMacMibGetRequestConfirm( &mibGet ) == LORAMAC_STATUS_OK ) | |||||
| { | |||||
| printf("CHANNEL MASK: "); | |||||
| switch( LmHandlerGetActiveRegion( ) ) | |||||
| { | |||||
| case LORAMAC_REGION_AS923: | |||||
| case LORAMAC_REGION_CN779: | |||||
| case LORAMAC_REGION_EU868: | |||||
| case LORAMAC_REGION_IN865: | |||||
| case LORAMAC_REGION_KR920: | |||||
| case LORAMAC_REGION_EU433: | |||||
| case LORAMAC_REGION_RU864: | |||||
| { | |||||
| printf( "%04X ", mibGet.Param.ChannelsMask[0] ); | |||||
| break; | |||||
| } | |||||
| case LORAMAC_REGION_AU915: | |||||
| case LORAMAC_REGION_CN470: | |||||
| case LORAMAC_REGION_US915: | |||||
| { | |||||
| for( uint8_t i = 0; i < 5; i++) | |||||
| { | |||||
| printf( "%04X ", mibGet.Param.ChannelsMask[i] ); | |||||
| } | |||||
| break; | |||||
| } | |||||
| default: | |||||
| { | |||||
| printf( "\n###### ========= Unknown Region ============ ######" ); | |||||
| break; | |||||
| } | |||||
| } | |||||
| printf("\n"); | |||||
| } | |||||
| printf( "\n" ); | |||||
| } | |||||
| void DisplayRxUpdate( LmHandlerAppData_t *appData, LmHandlerRxParams_t *params ) | |||||
| { | |||||
| const char *slotStrings[] = { "1", "2", "C", "C Multicast", "B Ping-Slot", "B Multicast Ping-Slot" }; | |||||
| if( params->IsMcpsIndication == 0 ) | |||||
| { | |||||
| printf( "\n###### ========== MLME-Indication ========== ######\n" ); | |||||
| printf( "STATUS : %s\n", EventInfoStatusStrings[params->Status] ); | |||||
| return; | |||||
| } | |||||
| printf( "\n###### ========== MCPS-Indication ========== ######\n" ); | |||||
| printf( "STATUS : %s\n", EventInfoStatusStrings[params->Status] ); | |||||
| printf( "\n###### ===== DOWNLINK FRAME %8lu ===== ######\n", params->DownlinkCounter ); | |||||
| printf( "RX WINDOW : %s\n", slotStrings[params->RxSlot] ); | |||||
| printf( "RX PORT : %d\n", appData->Port ); | |||||
| if( appData->BufferSize != 0 ) | |||||
| { | |||||
| printf( "RX DATA : \n" ); | |||||
| PrintHexBuffer( appData->Buffer, appData->BufferSize ); | |||||
| } | |||||
| printf( "\n" ); | |||||
| printf( "DATA RATE : DR_%d\n", params->Datarate ); | |||||
| printf( "RX RSSI : %d\n", params->Rssi ); | |||||
| printf( "RX SNR : %d\n", params->Snr ); | |||||
| printf( "\n" ); | |||||
| } | |||||
| void DisplayBeaconUpdate( LoRaMacHandlerBeaconParams_t *params ) | |||||
| { | |||||
| switch( params->State ) | |||||
| { | |||||
| default: | |||||
| case LORAMAC_HANDLER_BEACON_ACQUIRING: | |||||
| { | |||||
| printf( "\n###### ========= BEACON ACQUIRING ========== ######\n" ); | |||||
| break; | |||||
| } | |||||
| case LORAMAC_HANDLER_BEACON_LOST: | |||||
| { | |||||
| printf( "\n###### ============ BEACON LOST ============ ######\n" ); | |||||
| break; | |||||
| } | |||||
| case LORAMAC_HANDLER_BEACON_RX: | |||||
| { | |||||
| printf( "\n###### ===== BEACON %8lu ==== ######\n", params->Info.Time.Seconds ); | |||||
| printf( "GW DESC : %d\n", params->Info.GwSpecific.InfoDesc ); | |||||
| printf( "GW INFO : " ); | |||||
| PrintHexBuffer( params->Info.GwSpecific.Info, 6 ); | |||||
| printf( "\n" ); | |||||
| printf( "FREQ : %lu\n", params->Info.Frequency ); | |||||
| printf( "DATA RATE : DR_%d\n", params->Info.Datarate ); | |||||
| printf( "RX RSSI : %d\n", params->Info.Rssi ); | |||||
| printf( "RX SNR : %d\n", params->Info.Snr ); | |||||
| printf( "\n" ); | |||||
| break; | |||||
| } | |||||
| case LORAMAC_HANDLER_BEACON_NRX: | |||||
| { | |||||
| printf( "\n###### ======== BEACON NOT RECEIVED ======== ######\n" ); | |||||
| break; | |||||
| } | |||||
| } | |||||
| } | |||||
| void DisplayClassUpdate( DeviceClass_t deviceClass ) | |||||
| { | |||||
| printf( "\n\n###### ===== Switch to Class %c done. ===== ######\n\n", "ABC"[deviceClass] ); | |||||
| } | |||||
| void DisplayAppInfo( const char* appName, const Version_t* appVersion, const Version_t* gitHubVersion ) | |||||
| { | |||||
| printf( "\n###### ===================================== ######\n\n" ); | |||||
| printf( "Application name : %s\n", appName ); | |||||
| printf( "Application version: %d.%d.%d\n", appVersion->Fields.Major, appVersion->Fields.Minor, appVersion->Fields.Patch ); | |||||
| printf( "GitHub base version: %d.%d.%d\n", gitHubVersion->Fields.Major, gitHubVersion->Fields.Minor, gitHubVersion->Fields.Patch ); | |||||
| printf( "\n###### ===================================== ######\n\n" ); | |||||
| } | |||||
| /*! | |||||
| * \file LmHandlerMsgDisplay.h | |||||
| * | |||||
| * \brief Common set of functions to display default messages from | |||||
| * LoRaMacHandler. | |||||
| * | |||||
| * \copyright Revised BSD License, see section \ref LICENSE. | |||||
| * | |||||
| * \code | |||||
| * ______ _ | |||||
| * / _____) _ | | | |||||
| * ( (____ _____ ____ _| |_ _____ ____| |__ | |||||
| * \____ \| ___ | (_ _) ___ |/ ___) _ \ | |||||
| * _____) ) ____| | | || |_| ____( (___| | | | | |||||
| * (______/|_____)_|_|_| \__)_____)\____)_| |_| | |||||
| * (C)2013-2019 Semtech | |||||
| * | |||||
| * \endcode | |||||
| * | |||||
| * \author Miguel Luis ( Semtech ) | |||||
| */ | |||||
| #include <stdlib.h> | |||||
| #include <stdint.h> | |||||
| #include <stdbool.h> | |||||
| #include <stdio.h> | |||||
| #include "utilities.h" | |||||
| #include "timer.h" | |||||
| #include "LmHandlerMsgDisplay.h" | |||||
| /*! | |||||
| * MAC status strings | |||||
| */ | |||||
| const char* MacStatusStrings[] = | |||||
| { | |||||
| "OK", // LORAMAC_STATUS_OK | |||||
| "Busy", // LORAMAC_STATUS_BUSY | |||||
| "Service unknown", // LORAMAC_STATUS_SERVICE_UNKNOWN | |||||
| "Parameter invalid", // LORAMAC_STATUS_PARAMETER_INVALID | |||||
| "Frequency invalid", // LORAMAC_STATUS_FREQUENCY_INVALID | |||||
| "Datarate invalid", // LORAMAC_STATUS_DATARATE_INVALID | |||||
| "Frequency or datarate invalid", // LORAMAC_STATUS_FREQ_AND_DR_INVALID | |||||
| "No network joined", // LORAMAC_STATUS_NO_NETWORK_JOINED | |||||
| "Length error", // LORAMAC_STATUS_LENGTH_ERROR | |||||
| "Region not supported", // LORAMAC_STATUS_REGION_NOT_SUPPORTED | |||||
| "Skipped APP data", // LORAMAC_STATUS_SKIPPED_APP_DATA | |||||
| "Duty-cycle restricted", // LORAMAC_STATUS_DUTYCYCLE_RESTRICTED | |||||
| "No channel found", // LORAMAC_STATUS_NO_CHANNEL_FOUND | |||||
| "No free channel found", // LORAMAC_STATUS_NO_FREE_CHANNEL_FOUND | |||||
| "Busy beacon reserved time", // LORAMAC_STATUS_BUSY_BEACON_RESERVED_TIME | |||||
| "Busy ping-slot window time", // LORAMAC_STATUS_BUSY_PING_SLOT_WINDOW_TIME | |||||
| "Busy uplink collision", // LORAMAC_STATUS_BUSY_UPLINK_COLLISION | |||||
| "Crypto error", // LORAMAC_STATUS_CRYPTO_ERROR | |||||
| "FCnt handler error", // LORAMAC_STATUS_FCNT_HANDLER_ERROR | |||||
| "MAC command error", // LORAMAC_STATUS_MAC_COMMAD_ERROR | |||||
| "ClassB error", // LORAMAC_STATUS_CLASS_B_ERROR | |||||
| "Confirm queue error", // LORAMAC_STATUS_CONFIRM_QUEUE_ERROR | |||||
| "Multicast group undefined", // LORAMAC_STATUS_MC_GROUP_UNDEFINED | |||||
| "Unknown error", // LORAMAC_STATUS_ERROR | |||||
| }; | |||||
| /*! | |||||
| * MAC event info status strings. | |||||
| */ | |||||
| const char* EventInfoStatusStrings[] = | |||||
| { | |||||
| "OK", // LORAMAC_EVENT_INFO_STATUS_OK | |||||
| "Error", // LORAMAC_EVENT_INFO_STATUS_ERROR | |||||
| "Tx timeout", // LORAMAC_EVENT_INFO_STATUS_TX_TIMEOUT | |||||
| "Rx 1 timeout", // LORAMAC_EVENT_INFO_STATUS_RX1_TIMEOUT | |||||
| "Rx 2 timeout", // LORAMAC_EVENT_INFO_STATUS_RX2_TIMEOUT | |||||
| "Rx1 error", // LORAMAC_EVENT_INFO_STATUS_RX1_ERROR | |||||
| "Rx2 error", // LORAMAC_EVENT_INFO_STATUS_RX2_ERROR | |||||
| "Join failed", // LORAMAC_EVENT_INFO_STATUS_JOIN_FAIL | |||||
| "Downlink repeated", // LORAMAC_EVENT_INFO_STATUS_DOWNLINK_REPEATED | |||||
| "Tx DR payload size error", // LORAMAC_EVENT_INFO_STATUS_TX_DR_PAYLOAD_SIZE_ERROR | |||||
| "Address fail", // LORAMAC_EVENT_INFO_STATUS_ADDRESS_FAIL | |||||
| "MIC fail", // LORAMAC_EVENT_INFO_STATUS_MIC_FAIL | |||||
| "Multicast fail", // LORAMAC_EVENT_INFO_STATUS_MULTICAST_FAIL | |||||
| "Beacon locked", // LORAMAC_EVENT_INFO_STATUS_BEACON_LOCKED | |||||
| "Beacon lost", // LORAMAC_EVENT_INFO_STATUS_BEACON_LOST | |||||
| "Beacon not found" // LORAMAC_EVENT_INFO_STATUS_BEACON_NOT_FOUND | |||||
| }; | |||||
| /*! | |||||
| * Prints the provided buffer in HEX | |||||
| * | |||||
| * \param buffer Buffer to be printed | |||||
| * \param size Buffer size to be printed | |||||
| */ | |||||
| void PrintHexBuffer( uint8_t *buffer, uint8_t size ) | |||||
| { | |||||
| uint8_t newline = 0; | |||||
| for( uint8_t i = 0; i < size; i++ ) | |||||
| { | |||||
| if( newline != 0 ) | |||||
| { | |||||
| printf( "\n" ); | |||||
| newline = 0; | |||||
| } | |||||
| printf( "%02X ", buffer[i] ); | |||||
| if( ( ( i + 1 ) % 16 ) == 0 ) | |||||
| { | |||||
| newline = 1; | |||||
| } | |||||
| } | |||||
| printf( "\n" ); | |||||
| } | |||||
| void DisplayNvmDataChange( LmHandlerNvmContextStates_t state, uint16_t size ) | |||||
| { | |||||
| if( state == LORAMAC_HANDLER_NVM_STORE ) | |||||
| { | |||||
| printf( "\n###### ============ CTXS STORED ============ ######\n" ); | |||||
| } | |||||
| else | |||||
| { | |||||
| printf( "\n###### =========== CTXS RESTORED =========== ######\n" ); | |||||
| } | |||||
| printf( "Size : %i\n\n", size ); | |||||
| } | |||||
| void DisplayNetworkParametersUpdate( CommissioningParams_t *commissioningParams ) | |||||
| { | |||||
| printf( "DevEui : %02X", commissioningParams->DevEui[0] ); | |||||
| for( int i = 1; i < 8; i++ ) | |||||
| { | |||||
| printf( "-%02X", commissioningParams->DevEui[i] ); | |||||
| } | |||||
| printf( "\n" ); | |||||
| printf( "JoinEui : %02X", commissioningParams->JoinEui[0] ); | |||||
| for( int i = 1; i < 8; i++ ) | |||||
| { | |||||
| printf( "-%02X", commissioningParams->JoinEui[i] ); | |||||
| } | |||||
| printf( "\n" ); | |||||
| printf( "Pin : %02X", commissioningParams->SePin[0] ); | |||||
| for( int i = 1; i < 4; i++ ) | |||||
| { | |||||
| printf( "-%02X", commissioningParams->SePin[i] ); | |||||
| } | |||||
| printf( "\n\n" ); | |||||
| } | |||||
| void DisplayMacMcpsRequestUpdate( LoRaMacStatus_t status, McpsReq_t *mcpsReq, TimerTime_t nextTxIn ) | |||||
| { | |||||
| switch( mcpsReq->Type ) | |||||
| { | |||||
| case MCPS_CONFIRMED: | |||||
| { | |||||
| printf( "\n###### =========== MCPS-Request ============ ######\n" ); | |||||
| printf( "###### MCPS_CONFIRMED ######\n"); | |||||
| printf( "###### ===================================== ######\n"); | |||||
| break; | |||||
| } | |||||
| case MCPS_UNCONFIRMED: | |||||
| { | |||||
| printf( "\n###### =========== MCPS-Request ============ ######\n" ); | |||||
| printf( "###### MCPS_UNCONFIRMED ######\n"); | |||||
| printf( "###### ===================================== ######\n"); | |||||
| break; | |||||
| } | |||||
| case MCPS_PROPRIETARY: | |||||
| { | |||||
| printf( "\n###### =========== MCPS-Request ============ ######\n" ); | |||||
| printf( "###### MCPS_PROPRIETARY ######\n"); | |||||
| printf( "###### ===================================== ######\n"); | |||||
| break; | |||||
| } | |||||
| default: | |||||
| { | |||||
| printf( "\n###### =========== MCPS-Request ============ ######\n" ); | |||||
| printf( "###### MCPS_ERROR ######\n"); | |||||
| printf( "###### ===================================== ######\n"); | |||||
| break; | |||||
| } | |||||
| } | |||||
| printf( "STATUS : %s\n", MacStatusStrings[status] ); | |||||
| if( status == LORAMAC_STATUS_DUTYCYCLE_RESTRICTED ) | |||||
| { | |||||
| printf( "Next Tx in : %lu [ms]\n", nextTxIn ); | |||||
| } | |||||
| } | |||||
| void DisplayMacMlmeRequestUpdate( LoRaMacStatus_t status, MlmeReq_t *mlmeReq, TimerTime_t nextTxIn ) | |||||
| { | |||||
| switch( mlmeReq->Type ) | |||||
| { | |||||
| case MLME_JOIN: | |||||
| { | |||||
| printf( "\n###### =========== MLME-Request ============ ######\n" ); | |||||
| printf( "###### MLME_JOIN ######\n"); | |||||
| printf( "###### ===================================== ######\n"); | |||||
| break; | |||||
| } | |||||
| case MLME_LINK_CHECK: | |||||
| { | |||||
| printf( "\n###### =========== MLME-Request ============ ######\n" ); | |||||
| printf( "###### MLME_LINK_CHECK ######\n"); | |||||
| printf( "###### ===================================== ######\n"); | |||||
| break; | |||||
| } | |||||
| case MLME_DEVICE_TIME: | |||||
| { | |||||
| printf( "\n###### =========== MLME-Request ============ ######\n" ); | |||||
| printf( "###### MLME_DEVICE_TIME ######\n"); | |||||
| printf( "###### ===================================== ######\n"); | |||||
| break; | |||||
| } | |||||
| case MLME_TXCW: | |||||
| { | |||||
| printf( "\n###### =========== MLME-Request ============ ######\n" ); | |||||
| printf( "###### MLME_TXCW ######\n"); | |||||
| printf( "###### ===================================== ######\n"); | |||||
| break; | |||||
| } | |||||
| default: | |||||
| { | |||||
| printf( "\n###### =========== MLME-Request ============ ######\n" ); | |||||
| printf( "###### MLME_UNKNOWN ######\n"); | |||||
| printf( "###### ===================================== ######\n"); | |||||
| break; | |||||
| } | |||||
| } | |||||
| printf( "STATUS : %s\n", MacStatusStrings[status] ); | |||||
| if( status == LORAMAC_STATUS_DUTYCYCLE_RESTRICTED ) | |||||
| { | |||||
| printf( "Next Tx in : %lu [ms]\n", nextTxIn ); | |||||
| } | |||||
| } | |||||
| void DisplayJoinRequestUpdate( LmHandlerJoinParams_t *params ) | |||||
| { | |||||
| if( params->CommissioningParams->IsOtaaActivation == true ) | |||||
| { | |||||
| if( params->Status == LORAMAC_HANDLER_SUCCESS ) | |||||
| { | |||||
| printf( "###### =========== JOINED ============ ######\n" ); | |||||
| printf( "\nOTAA\n\n" ); | |||||
| printf( "DevAddr : %08lX\n", params->CommissioningParams->DevAddr ); | |||||
| printf( "\n\n" ); | |||||
| printf( "DATA RATE : DR_%d\n\n", params->Datarate ); | |||||
| } | |||||
| } | |||||
| #if ( OVER_THE_AIR_ACTIVATION == 0 ) | |||||
| else | |||||
| { | |||||
| printf( "###### =========== JOINED ============ ######\n" ); | |||||
| printf( "\nABP\n\n" ); | |||||
| printf( "DevAddr : %08lX\n", params->CommissioningParams->DevAddr ); | |||||
| printf( "\n\n" ); | |||||
| } | |||||
| #endif | |||||
| } | |||||
| void DisplayTxUpdate( LmHandlerTxParams_t *params ) | |||||
| { | |||||
| MibRequestConfirm_t mibGet; | |||||
| if( params->IsMcpsConfirm == 0 ) | |||||
| { | |||||
| printf( "\n###### =========== MLME-Confirm ============ ######\n" ); | |||||
| printf( "STATUS : %s\n", EventInfoStatusStrings[params->Status] ); | |||||
| return; | |||||
| } | |||||
| printf( "\n###### =========== MCPS-Confirm ============ ######\n" ); | |||||
| printf( "STATUS : %s\n", EventInfoStatusStrings[params->Status] ); | |||||
| printf( "\n###### ===== UPLINK FRAME %8lu ===== ######\n", params->UplinkCounter ); | |||||
| printf( "\n" ); | |||||
| printf( "CLASS : %c\n", "ABC"[LmHandlerGetCurrentClass( )] ); | |||||
| printf( "\n" ); | |||||
| printf( "TX PORT : %d\n", params->AppData.Port ); | |||||
| if( params->AppData.BufferSize != 0 ) | |||||
| { | |||||
| printf( "TX DATA : " ); | |||||
| if( params->MsgType == LORAMAC_HANDLER_CONFIRMED_MSG ) | |||||
| { | |||||
| printf( "CONFIRMED - %s\n", ( params->AckReceived != 0 ) ? "ACK" : "NACK" ); | |||||
| } | |||||
| else | |||||
| { | |||||
| printf( "UNCONFIRMED\n" ); | |||||
| } | |||||
| PrintHexBuffer( params->AppData.Buffer, params->AppData.BufferSize ); | |||||
| } | |||||
| printf( "\n" ); | |||||
| printf( "DATA RATE : DR_%d\n", params->Datarate ); | |||||
| mibGet.Type = MIB_CHANNELS; | |||||
| if( LoRaMacMibGetRequestConfirm( &mibGet ) == LORAMAC_STATUS_OK ) | |||||
| { | |||||
| printf( "U/L FREQ : %lu\n", mibGet.Param.ChannelList[params->Channel].Frequency ); | |||||
| } | |||||
| printf( "TX POWER : %d\n", params->TxPower ); | |||||
| mibGet.Type = MIB_CHANNELS_MASK; | |||||
| if( LoRaMacMibGetRequestConfirm( &mibGet ) == LORAMAC_STATUS_OK ) | |||||
| { | |||||
| printf("CHANNEL MASK: "); | |||||
| switch( LmHandlerGetActiveRegion( ) ) | |||||
| { | |||||
| case LORAMAC_REGION_AS923: | |||||
| case LORAMAC_REGION_CN779: | |||||
| case LORAMAC_REGION_EU868: | |||||
| case LORAMAC_REGION_IN865: | |||||
| case LORAMAC_REGION_KR920: | |||||
| case LORAMAC_REGION_EU433: | |||||
| case LORAMAC_REGION_RU864: | |||||
| { | |||||
| printf( "%04X ", mibGet.Param.ChannelsMask[0] ); | |||||
| break; | |||||
| } | |||||
| case LORAMAC_REGION_AU915: | |||||
| case LORAMAC_REGION_CN470: | |||||
| case LORAMAC_REGION_US915: | |||||
| { | |||||
| for( uint8_t i = 0; i < 5; i++) | |||||
| { | |||||
| printf( "%04X ", mibGet.Param.ChannelsMask[i] ); | |||||
| } | |||||
| break; | |||||
| } | |||||
| default: | |||||
| { | |||||
| printf( "\n###### ========= Unknown Region ============ ######" ); | |||||
| break; | |||||
| } | |||||
| } | |||||
| printf("\n"); | |||||
| } | |||||
| printf( "\n" ); | |||||
| } | |||||
| void DisplayRxUpdate( LmHandlerAppData_t *appData, LmHandlerRxParams_t *params ) | |||||
| { | |||||
| const char *slotStrings[] = { "1", "2", "C", "C Multicast", "B Ping-Slot", "B Multicast Ping-Slot" }; | |||||
| if( params->IsMcpsIndication == 0 ) | |||||
| { | |||||
| printf( "\n###### ========== MLME-Indication ========== ######\n" ); | |||||
| printf( "STATUS : %s\n", EventInfoStatusStrings[params->Status] ); | |||||
| return; | |||||
| } | |||||
| printf( "\n###### ========== MCPS-Indication ========== ######\n" ); | |||||
| printf( "STATUS : %s\n", EventInfoStatusStrings[params->Status] ); | |||||
| printf( "\n###### ===== DOWNLINK FRAME %8lu ===== ######\n", params->DownlinkCounter ); | |||||
| printf( "RX WINDOW : %s\n", slotStrings[params->RxSlot] ); | |||||
| printf( "RX PORT : %d\n", appData->Port ); | |||||
| if( appData->BufferSize != 0 ) | |||||
| { | |||||
| printf( "RX DATA : \n" ); | |||||
| PrintHexBuffer( appData->Buffer, appData->BufferSize ); | |||||
| } | |||||
| printf( "\n" ); | |||||
| printf( "DATA RATE : DR_%d\n", params->Datarate ); | |||||
| printf( "RX RSSI : %d\n", params->Rssi ); | |||||
| printf( "RX SNR : %d\n", params->Snr ); | |||||
| printf( "\n" ); | |||||
| } | |||||
| void DisplayBeaconUpdate( LoRaMacHandlerBeaconParams_t *params ) | |||||
| { | |||||
| switch( params->State ) | |||||
| { | |||||
| default: | |||||
| case LORAMAC_HANDLER_BEACON_ACQUIRING: | |||||
| { | |||||
| printf( "\n###### ========= BEACON ACQUIRING ========== ######\n" ); | |||||
| break; | |||||
| } | |||||
| case LORAMAC_HANDLER_BEACON_LOST: | |||||
| { | |||||
| printf( "\n###### ============ BEACON LOST ============ ######\n" ); | |||||
| break; | |||||
| } | |||||
| case LORAMAC_HANDLER_BEACON_RX: | |||||
| { | |||||
| printf( "\n###### ===== BEACON %8lu ==== ######\n", params->Info.Time.Seconds ); | |||||
| printf( "GW DESC : %d\n", params->Info.GwSpecific.InfoDesc ); | |||||
| printf( "GW INFO : " ); | |||||
| PrintHexBuffer( params->Info.GwSpecific.Info, 6 ); | |||||
| printf( "\n" ); | |||||
| printf( "FREQ : %lu\n", params->Info.Frequency ); | |||||
| printf( "DATA RATE : DR_%d\n", params->Info.Datarate ); | |||||
| printf( "RX RSSI : %d\n", params->Info.Rssi ); | |||||
| printf( "RX SNR : %d\n", params->Info.Snr ); | |||||
| printf( "\n" ); | |||||
| break; | |||||
| } | |||||
| case LORAMAC_HANDLER_BEACON_NRX: | |||||
| { | |||||
| printf( "\n###### ======== BEACON NOT RECEIVED ======== ######\n" ); | |||||
| break; | |||||
| } | |||||
| } | |||||
| } | |||||
| void DisplayClassUpdate( DeviceClass_t deviceClass ) | |||||
| { | |||||
| printf( "\n\n###### ===== Switch to Class %c done. ===== ######\n\n", "ABC"[deviceClass] ); | |||||
| } | |||||
| void DisplayAppInfo( const char* appName, const Version_t* appVersion, const Version_t* gitHubVersion ) | |||||
| { | |||||
| printf( "\n###### ===================================== ######\n\n" ); | |||||
| printf( "Application name : %s\n", appName ); | |||||
| printf( "Application version: %d.%d.%d\n", appVersion->Fields.Major, appVersion->Fields.Minor, appVersion->Fields.Patch ); | |||||
| printf( "GitHub base version: %d.%d.%d\n", gitHubVersion->Fields.Major, gitHubVersion->Fields.Minor, gitHubVersion->Fields.Patch ); | |||||
| printf( "\n###### ===================================== ######\n\n" ); | |||||
| } | |||||
| @@ -1,104 +1,104 @@ | |||||
| /*! | |||||
| * \file LmHandlerMsgDisplay.h | |||||
| * | |||||
| * \brief Common set of functions to display default messages from | |||||
| * LoRaMacHandler. | |||||
| * | |||||
| * \copyright Revised BSD License, see section \ref LICENSE. | |||||
| * | |||||
| * \code | |||||
| * ______ _ | |||||
| * / _____) _ | | | |||||
| * ( (____ _____ ____ _| |_ _____ ____| |__ | |||||
| * \____ \| ___ | (_ _) ___ |/ ___) _ \ | |||||
| * _____) ) ____| | | || |_| ____( (___| | | | | |||||
| * (______/|_____)_|_|_| \__)_____)\____)_| |_| | |||||
| * (C)2013-2019 Semtech | |||||
| * | |||||
| * \endcode | |||||
| * | |||||
| * \author Miguel Luis ( Semtech ) | |||||
| */ | |||||
| #ifndef __LMHANDLER_MSG_DISPLAY_H__ | |||||
| #define __LMHANDLER_MSG_DISPLAY_H__ | |||||
| #include "utilities.h" | |||||
| #include "LmHandler.h" | |||||
| /*! | |||||
| * \brief Displays NVM context operation state | |||||
| * | |||||
| * \param [IN] state Indicates if we are storing (true) or | |||||
| * restoring (false) the NVM context | |||||
| * | |||||
| * \param [IN] size Number of data bytes which were stored or restored. | |||||
| */ | |||||
| void DisplayNvmDataChange( LmHandlerNvmContextStates_t state, uint16_t size ); | |||||
| /*! | |||||
| * \brief Displays updated network parameters | |||||
| * | |||||
| * \param [IN] commissioningParams Commissioning provided parameters | |||||
| */ | |||||
| void DisplayNetworkParametersUpdate( CommissioningParams_t* commissioningParams ); | |||||
| /*! | |||||
| * \brief Displays updated McpsRequest | |||||
| * | |||||
| * \param [IN] status McpsRequest execution status | |||||
| * \param [IN] mcpsReq McpsRequest command executed | |||||
| * \param [IN] nextTxIn Time to wait for the next uplink transmission | |||||
| */ | |||||
| void DisplayMacMcpsRequestUpdate( LoRaMacStatus_t status, McpsReq_t *mcpsReq, TimerTime_t nextTxIn ); | |||||
| /*! | |||||
| * \brief Displays updated MlmeRequest | |||||
| * | |||||
| * \param [IN] status MlmeRequest execution status | |||||
| * \param [IN] mlmeReq MlmeRequest command executed | |||||
| * \param [IN] nextTxIn Time to wait for the next uplink transmission | |||||
| */ | |||||
| void DisplayMacMlmeRequestUpdate( LoRaMacStatus_t status, MlmeReq_t *mlmeReq, TimerTime_t nextTxIn ); | |||||
| /*! | |||||
| * \brief Displays updated JoinRequest | |||||
| * | |||||
| * \param [IN] params Executed JoinRequest parameters | |||||
| */ | |||||
| void DisplayJoinRequestUpdate( LmHandlerJoinParams_t* params ); | |||||
| /*! | |||||
| * \brief Displays Tx params | |||||
| * | |||||
| * \param [IN] params Tx parameters | |||||
| */ | |||||
| void DisplayTxUpdate( LmHandlerTxParams_t* params ); | |||||
| /*! | |||||
| * \brief Displays Rx params | |||||
| * | |||||
| * \param [IN] appData Receive data payload and port number | |||||
| * \param [IN] params Rx parameters | |||||
| */ | |||||
| void DisplayRxUpdate( LmHandlerAppData_t* appData, LmHandlerRxParams_t* params ); | |||||
| /*! | |||||
| * \brief Displays beacon status update | |||||
| * | |||||
| * \param [IN] params Beacon parameters | |||||
| */ | |||||
| void DisplayBeaconUpdate( LoRaMacHandlerBeaconParams_t* params ); | |||||
| /*! | |||||
| * \brief Displays end-device class update | |||||
| * | |||||
| * \param [IN] deviceClass Current end-device class | |||||
| */ | |||||
| void DisplayClassUpdate( DeviceClass_t deviceClass ); | |||||
| /*! | |||||
| * \brief Displays application information | |||||
| */ | |||||
| void DisplayAppInfo( const char* appName, const Version_t* appVersion, const Version_t* gitHubVersion ); | |||||
| #endif // __LMHANDLER_MSG_DISPLAY_H__ | |||||
| /*! | |||||
| * \file LmHandlerMsgDisplay.h | |||||
| * | |||||
| * \brief Common set of functions to display default messages from | |||||
| * LoRaMacHandler. | |||||
| * | |||||
| * \copyright Revised BSD License, see section \ref LICENSE. | |||||
| * | |||||
| * \code | |||||
| * ______ _ | |||||
| * / _____) _ | | | |||||
| * ( (____ _____ ____ _| |_ _____ ____| |__ | |||||
| * \____ \| ___ | (_ _) ___ |/ ___) _ \ | |||||
| * _____) ) ____| | | || |_| ____( (___| | | | | |||||
| * (______/|_____)_|_|_| \__)_____)\____)_| |_| | |||||
| * (C)2013-2019 Semtech | |||||
| * | |||||
| * \endcode | |||||
| * | |||||
| * \author Miguel Luis ( Semtech ) | |||||
| */ | |||||
| #ifndef __LMHANDLER_MSG_DISPLAY_H__ | |||||
| #define __LMHANDLER_MSG_DISPLAY_H__ | |||||
| #include "utilities.h" | |||||
| #include "LmHandler.h" | |||||
| /*! | |||||
| * \brief Displays NVM context operation state | |||||
| * | |||||
| * \param [IN] state Indicates if we are storing (true) or | |||||
| * restoring (false) the NVM context | |||||
| * | |||||
| * \param [IN] size Number of data bytes which were stored or restored. | |||||
| */ | |||||
| void DisplayNvmDataChange( LmHandlerNvmContextStates_t state, uint16_t size ); | |||||
| /*! | |||||
| * \brief Displays updated network parameters | |||||
| * | |||||
| * \param [IN] commissioningParams Commissioning provided parameters | |||||
| */ | |||||
| void DisplayNetworkParametersUpdate( CommissioningParams_t* commissioningParams ); | |||||
| /*! | |||||
| * \brief Displays updated McpsRequest | |||||
| * | |||||
| * \param [IN] status McpsRequest execution status | |||||
| * \param [IN] mcpsReq McpsRequest command executed | |||||
| * \param [IN] nextTxIn Time to wait for the next uplink transmission | |||||
| */ | |||||
| void DisplayMacMcpsRequestUpdate( LoRaMacStatus_t status, McpsReq_t *mcpsReq, TimerTime_t nextTxIn ); | |||||
| /*! | |||||
| * \brief Displays updated MlmeRequest | |||||
| * | |||||
| * \param [IN] status MlmeRequest execution status | |||||
| * \param [IN] mlmeReq MlmeRequest command executed | |||||
| * \param [IN] nextTxIn Time to wait for the next uplink transmission | |||||
| */ | |||||
| void DisplayMacMlmeRequestUpdate( LoRaMacStatus_t status, MlmeReq_t *mlmeReq, TimerTime_t nextTxIn ); | |||||
| /*! | |||||
| * \brief Displays updated JoinRequest | |||||
| * | |||||
| * \param [IN] params Executed JoinRequest parameters | |||||
| */ | |||||
| void DisplayJoinRequestUpdate( LmHandlerJoinParams_t* params ); | |||||
| /*! | |||||
| * \brief Displays Tx params | |||||
| * | |||||
| * \param [IN] params Tx parameters | |||||
| */ | |||||
| void DisplayTxUpdate( LmHandlerTxParams_t* params ); | |||||
| /*! | |||||
| * \brief Displays Rx params | |||||
| * | |||||
| * \param [IN] appData Receive data payload and port number | |||||
| * \param [IN] params Rx parameters | |||||
| */ | |||||
| void DisplayRxUpdate( LmHandlerAppData_t* appData, LmHandlerRxParams_t* params ); | |||||
| /*! | |||||
| * \brief Displays beacon status update | |||||
| * | |||||
| * \param [IN] params Beacon parameters | |||||
| */ | |||||
| void DisplayBeaconUpdate( LoRaMacHandlerBeaconParams_t* params ); | |||||
| /*! | |||||
| * \brief Displays end-device class update | |||||
| * | |||||
| * \param [IN] deviceClass Current end-device class | |||||
| */ | |||||
| void DisplayClassUpdate( DeviceClass_t deviceClass ); | |||||
| /*! | |||||
| * \brief Displays application information | |||||
| */ | |||||
| void DisplayAppInfo( const char* appName, const Version_t* appVersion, const Version_t* gitHubVersion ); | |||||
| #endif // __LMHANDLER_MSG_DISPLAY_H__ | |||||
| @@ -1,272 +1,272 @@ | |||||
| /*! | |||||
| * \file NvmDataMgmt.c | |||||
| * | |||||
| * \brief NVM context management implementation | |||||
| * | |||||
| * \copyright Revised BSD License, see section \ref LICENSE. | |||||
| * | |||||
| * \code | |||||
| * ______ _ | |||||
| * / _____) _ | | | |||||
| * ( (____ _____ ____ _| |_ _____ ____| |__ | |||||
| * \____ \| ___ | (_ _) ___ |/ ___) _ \ | |||||
| * _____) ) ____| | | || |_| ____( (___| | | | | |||||
| * (______/|_____)_|_|_| \__)_____)\____)_| |_| | |||||
| * (C)2013-2017 Semtech | |||||
| * | |||||
| * ___ _____ _ ___ _ _____ ___ ___ ___ ___ | |||||
| * / __|_ _/_\ / __| |/ / __/ _ \| _ \/ __| __| | |||||
| * \__ \ | |/ _ \ (__| ' <| _| (_) | / (__| _| | |||||
| * |___/ |_/_/ \_\___|_|\_\_| \___/|_|_\\___|___| | |||||
| * embedded.connectivity.solutions=============== | |||||
| * | |||||
| * \endcode | |||||
| * | |||||
| * \author Miguel Luis ( Semtech ) | |||||
| * | |||||
| * \author Gregory Cristian ( Semtech ) | |||||
| * | |||||
| * \author Daniel Jaeckle ( STACKFORCE ) | |||||
| * | |||||
| * \author Johannes Bruder ( STACKFORCE ) | |||||
| */ | |||||
| #include <stdio.h> | |||||
| #include "utilities.h" | |||||
| #include "nvmm.h" | |||||
| #include "LoRaMac.h" | |||||
| #include "NvmDataMgmt.h" | |||||
| /*! | |||||
| * Enables/Disables the context storage management storage. | |||||
| * Must be enabled for LoRaWAN 1.0.4 or later. | |||||
| */ | |||||
| #ifndef CONTEXT_MANAGEMENT_ENABLED | |||||
| #define CONTEXT_MANAGEMENT_ENABLED 1 | |||||
| #endif | |||||
| static uint16_t NvmNotifyFlags = 0; | |||||
| void NvmDataMgmtEvent( uint16_t notifyFlags ) | |||||
| { | |||||
| NvmNotifyFlags = notifyFlags; | |||||
| } | |||||
| uint16_t NvmDataMgmtStore( void ) | |||||
| { | |||||
| #if( CONTEXT_MANAGEMENT_ENABLED == 1 ) | |||||
| uint16_t offset = 0; | |||||
| uint16_t dataSize = 0; | |||||
| MibRequestConfirm_t mibReq; | |||||
| mibReq.Type = MIB_NVM_CTXS; | |||||
| LoRaMacMibGetRequestConfirm( &mibReq ); | |||||
| LoRaMacNvmData_t* nvm = mibReq.Param.Contexts; | |||||
| // Input checks | |||||
| if( NvmNotifyFlags == LORAMAC_NVM_NOTIFY_FLAG_NONE ) | |||||
| { | |||||
| // There was no update. | |||||
| return 0; | |||||
| } | |||||
| if( LoRaMacStop( ) != LORAMAC_STATUS_OK ) | |||||
| { | |||||
| return 0; | |||||
| } | |||||
| // Crypto | |||||
| if( ( NvmNotifyFlags & LORAMAC_NVM_NOTIFY_FLAG_CRYPTO ) == | |||||
| LORAMAC_NVM_NOTIFY_FLAG_CRYPTO ) | |||||
| { | |||||
| dataSize += NvmmWrite( ( uint8_t* ) &nvm->Crypto, sizeof( nvm->Crypto ), | |||||
| offset ); | |||||
| } | |||||
| offset += sizeof( nvm->Crypto ); | |||||
| // MacGroup1 | |||||
| if( ( NvmNotifyFlags & LORAMAC_NVM_NOTIFY_FLAG_MAC_GROUP1 ) == | |||||
| LORAMAC_NVM_NOTIFY_FLAG_MAC_GROUP1 ) | |||||
| { | |||||
| dataSize += NvmmWrite( ( uint8_t* ) &nvm->MacGroup1, | |||||
| sizeof( nvm->MacGroup1 ), offset ); | |||||
| } | |||||
| offset += sizeof( nvm->MacGroup1 ); | |||||
| // MacGroup2 | |||||
| if( ( NvmNotifyFlags & LORAMAC_NVM_NOTIFY_FLAG_MAC_GROUP2 ) == | |||||
| LORAMAC_NVM_NOTIFY_FLAG_MAC_GROUP2 ) | |||||
| { | |||||
| dataSize += NvmmWrite( ( uint8_t* ) &nvm->MacGroup2, | |||||
| sizeof( nvm->MacGroup2 ), offset ); | |||||
| } | |||||
| offset += sizeof( nvm->MacGroup2 ); | |||||
| // Secure element | |||||
| if( ( NvmNotifyFlags & LORAMAC_NVM_NOTIFY_FLAG_SECURE_ELEMENT ) == | |||||
| LORAMAC_NVM_NOTIFY_FLAG_SECURE_ELEMENT ) | |||||
| { | |||||
| dataSize += NvmmWrite( ( uint8_t* ) &nvm->SecureElement, sizeof( nvm->SecureElement ), | |||||
| offset ); | |||||
| } | |||||
| offset += sizeof( nvm->SecureElement ); | |||||
| // Region group 1 | |||||
| if( ( NvmNotifyFlags & LORAMAC_NVM_NOTIFY_FLAG_REGION_GROUP1 ) == | |||||
| LORAMAC_NVM_NOTIFY_FLAG_REGION_GROUP1 ) | |||||
| { | |||||
| dataSize += NvmmWrite( ( uint8_t* ) &nvm->RegionGroup1, | |||||
| sizeof( nvm->RegionGroup1 ), offset ); | |||||
| } | |||||
| offset += sizeof( nvm->RegionGroup1 ); | |||||
| // Region group 2 | |||||
| if( ( NvmNotifyFlags & LORAMAC_NVM_NOTIFY_FLAG_REGION_GROUP2 ) == | |||||
| LORAMAC_NVM_NOTIFY_FLAG_REGION_GROUP2 ) | |||||
| { | |||||
| dataSize += NvmmWrite( ( uint8_t* ) &nvm->RegionGroup2, | |||||
| sizeof( nvm->RegionGroup2 ), offset ); | |||||
| } | |||||
| offset += sizeof( nvm->RegionGroup2 ); | |||||
| // Class b | |||||
| if( ( NvmNotifyFlags & LORAMAC_NVM_NOTIFY_FLAG_CLASS_B ) == | |||||
| LORAMAC_NVM_NOTIFY_FLAG_CLASS_B ) | |||||
| { | |||||
| dataSize += NvmmWrite( ( uint8_t* ) &nvm->ClassB, sizeof( nvm->ClassB ), | |||||
| offset ); | |||||
| } | |||||
| offset += sizeof( nvm->ClassB ); | |||||
| // Reset notification flags | |||||
| NvmNotifyFlags = LORAMAC_NVM_NOTIFY_FLAG_NONE; | |||||
| // Resume LoRaMac | |||||
| LoRaMacStart( ); | |||||
| return dataSize; | |||||
| #else | |||||
| return 0; | |||||
| #endif | |||||
| } | |||||
| uint16_t NvmDataMgmtRestore( void ) | |||||
| { | |||||
| #if( CONTEXT_MANAGEMENT_ENABLED == 1 ) | |||||
| MibRequestConfirm_t mibReq; | |||||
| mibReq.Type = MIB_NVM_CTXS; | |||||
| LoRaMacMibGetRequestConfirm( &mibReq ); | |||||
| LoRaMacNvmData_t* nvm = mibReq.Param.Contexts; | |||||
| uint16_t offset = 0; | |||||
| // Crypto | |||||
| if( NvmmCrc32Check( sizeof( LoRaMacCryptoNvmData_t ), offset ) == false ) | |||||
| { | |||||
| return 0; | |||||
| } | |||||
| offset += sizeof( LoRaMacCryptoNvmData_t ); | |||||
| // Mac Group 1 | |||||
| if( NvmmCrc32Check( sizeof( LoRaMacNvmDataGroup1_t ), offset ) == false ) | |||||
| { | |||||
| return 0; | |||||
| } | |||||
| offset += sizeof( LoRaMacNvmDataGroup1_t ); | |||||
| // Mac Group 2 | |||||
| if( NvmmCrc32Check( sizeof( LoRaMacNvmDataGroup2_t ), offset ) == false ) | |||||
| { | |||||
| return 0; | |||||
| } | |||||
| offset += sizeof( LoRaMacNvmDataGroup2_t ); | |||||
| // Secure element | |||||
| if( NvmmCrc32Check( sizeof( SecureElementNvmData_t ), offset ) == false ) | |||||
| { | |||||
| return 0; | |||||
| } | |||||
| offset += sizeof( SecureElementNvmData_t ); | |||||
| // Region group 1 | |||||
| if( NvmmCrc32Check( sizeof( RegionNvmDataGroup1_t ), offset ) == false ) | |||||
| { | |||||
| return 0; | |||||
| } | |||||
| offset += sizeof( RegionNvmDataGroup1_t ); | |||||
| // Region group 2 | |||||
| if( NvmmCrc32Check( sizeof( RegionNvmDataGroup2_t ), offset ) == false ) | |||||
| { | |||||
| return 0; | |||||
| } | |||||
| offset += sizeof( RegionNvmDataGroup2_t ); | |||||
| // Class b | |||||
| if( NvmmCrc32Check( sizeof( LoRaMacClassBNvmData_t ), offset ) == false ) | |||||
| { | |||||
| return 0; | |||||
| } | |||||
| offset += sizeof( LoRaMacClassBNvmData_t ); | |||||
| if( NvmmRead( ( uint8_t* ) nvm, sizeof( LoRaMacNvmData_t ), 0 ) == | |||||
| sizeof( LoRaMacNvmData_t ) ) | |||||
| { | |||||
| return sizeof( LoRaMacNvmData_t ); | |||||
| } | |||||
| #endif | |||||
| return 0; | |||||
| } | |||||
| bool NvmDataMgmtFactoryReset( void ) | |||||
| { | |||||
| uint16_t offset = 0; | |||||
| #if( CONTEXT_MANAGEMENT_ENABLED == 1 ) | |||||
| // Crypto | |||||
| if( NvmmReset( sizeof( LoRaMacCryptoNvmData_t ), offset ) == false ) | |||||
| { | |||||
| return false; | |||||
| } | |||||
| offset += sizeof( LoRaMacCryptoNvmData_t ); | |||||
| // Mac Group 1 | |||||
| if( NvmmReset( sizeof( LoRaMacNvmDataGroup1_t ), offset ) == false ) | |||||
| { | |||||
| return false; | |||||
| } | |||||
| offset += sizeof( LoRaMacNvmDataGroup1_t ); | |||||
| // Mac Group 2 | |||||
| if( NvmmReset( sizeof( LoRaMacNvmDataGroup2_t ), offset ) == false ) | |||||
| { | |||||
| return false; | |||||
| } | |||||
| offset += sizeof( LoRaMacNvmDataGroup2_t ); | |||||
| // Secure element | |||||
| if( NvmmReset( sizeof( SecureElementNvmData_t ), offset ) == false ) | |||||
| { | |||||
| return false; | |||||
| } | |||||
| offset += sizeof( SecureElementNvmData_t ); | |||||
| // Region group 1 | |||||
| if( NvmmReset( sizeof( RegionNvmDataGroup1_t ), offset ) == false ) | |||||
| { | |||||
| return false; | |||||
| } | |||||
| offset += sizeof( RegionNvmDataGroup1_t ); | |||||
| // Region group 2 | |||||
| if( NvmmReset( sizeof( RegionNvmDataGroup2_t ), offset ) == false ) | |||||
| { | |||||
| return false; | |||||
| } | |||||
| offset += sizeof( RegionNvmDataGroup2_t ); | |||||
| // Class b | |||||
| if( NvmmReset( sizeof( LoRaMacClassBNvmData_t ), offset ) == false ) | |||||
| { | |||||
| return false; | |||||
| } | |||||
| offset += sizeof( LoRaMacClassBNvmData_t ); | |||||
| #endif | |||||
| return true; | |||||
| } | |||||
| /*! | |||||
| * \file NvmDataMgmt.c | |||||
| * | |||||
| * \brief NVM context management implementation | |||||
| * | |||||
| * \copyright Revised BSD License, see section \ref LICENSE. | |||||
| * | |||||
| * \code | |||||
| * ______ _ | |||||
| * / _____) _ | | | |||||
| * ( (____ _____ ____ _| |_ _____ ____| |__ | |||||
| * \____ \| ___ | (_ _) ___ |/ ___) _ \ | |||||
| * _____) ) ____| | | || |_| ____( (___| | | | | |||||
| * (______/|_____)_|_|_| \__)_____)\____)_| |_| | |||||
| * (C)2013-2017 Semtech | |||||
| * | |||||
| * ___ _____ _ ___ _ _____ ___ ___ ___ ___ | |||||
| * / __|_ _/_\ / __| |/ / __/ _ \| _ \/ __| __| | |||||
| * \__ \ | |/ _ \ (__| ' <| _| (_) | / (__| _| | |||||
| * |___/ |_/_/ \_\___|_|\_\_| \___/|_|_\\___|___| | |||||
| * embedded.connectivity.solutions=============== | |||||
| * | |||||
| * \endcode | |||||
| * | |||||
| * \author Miguel Luis ( Semtech ) | |||||
| * | |||||
| * \author Gregory Cristian ( Semtech ) | |||||
| * | |||||
| * \author Daniel Jaeckle ( STACKFORCE ) | |||||
| * | |||||
| * \author Johannes Bruder ( STACKFORCE ) | |||||
| */ | |||||
| #include <stdio.h> | |||||
| #include "utilities.h" | |||||
| #include "nvmm.h" | |||||
| #include "LoRaMac.h" | |||||
| #include "NvmDataMgmt.h" | |||||
| /*! | |||||
| * Enables/Disables the context storage management storage. | |||||
| * Must be enabled for LoRaWAN 1.0.4 or later. | |||||
| */ | |||||
| #ifndef CONTEXT_MANAGEMENT_ENABLED | |||||
| #define CONTEXT_MANAGEMENT_ENABLED 1 | |||||
| #endif | |||||
| static uint16_t NvmNotifyFlags = 0; | |||||
| void NvmDataMgmtEvent( uint16_t notifyFlags ) | |||||
| { | |||||
| NvmNotifyFlags = notifyFlags; | |||||
| } | |||||
| uint16_t NvmDataMgmtStore( void ) | |||||
| { | |||||
| #if( CONTEXT_MANAGEMENT_ENABLED == 1 ) | |||||
| uint16_t offset = 0; | |||||
| uint16_t dataSize = 0; | |||||
| MibRequestConfirm_t mibReq; | |||||
| mibReq.Type = MIB_NVM_CTXS; | |||||
| LoRaMacMibGetRequestConfirm( &mibReq ); | |||||
| LoRaMacNvmData_t* nvm = mibReq.Param.Contexts; | |||||
| // Input checks | |||||
| if( NvmNotifyFlags == LORAMAC_NVM_NOTIFY_FLAG_NONE ) | |||||
| { | |||||
| // There was no update. | |||||
| return 0; | |||||
| } | |||||
| if( LoRaMacStop( ) != LORAMAC_STATUS_OK ) | |||||
| { | |||||
| return 0; | |||||
| } | |||||
| // Crypto | |||||
| if( ( NvmNotifyFlags & LORAMAC_NVM_NOTIFY_FLAG_CRYPTO ) == | |||||
| LORAMAC_NVM_NOTIFY_FLAG_CRYPTO ) | |||||
| { | |||||
| dataSize += NvmmWrite( ( uint8_t* ) &nvm->Crypto, sizeof( nvm->Crypto ), | |||||
| offset ); | |||||
| } | |||||
| offset += sizeof( nvm->Crypto ); | |||||
| // MacGroup1 | |||||
| if( ( NvmNotifyFlags & LORAMAC_NVM_NOTIFY_FLAG_MAC_GROUP1 ) == | |||||
| LORAMAC_NVM_NOTIFY_FLAG_MAC_GROUP1 ) | |||||
| { | |||||
| dataSize += NvmmWrite( ( uint8_t* ) &nvm->MacGroup1, | |||||
| sizeof( nvm->MacGroup1 ), offset ); | |||||
| } | |||||
| offset += sizeof( nvm->MacGroup1 ); | |||||
| // MacGroup2 | |||||
| if( ( NvmNotifyFlags & LORAMAC_NVM_NOTIFY_FLAG_MAC_GROUP2 ) == | |||||
| LORAMAC_NVM_NOTIFY_FLAG_MAC_GROUP2 ) | |||||
| { | |||||
| dataSize += NvmmWrite( ( uint8_t* ) &nvm->MacGroup2, | |||||
| sizeof( nvm->MacGroup2 ), offset ); | |||||
| } | |||||
| offset += sizeof( nvm->MacGroup2 ); | |||||
| // Secure element | |||||
| if( ( NvmNotifyFlags & LORAMAC_NVM_NOTIFY_FLAG_SECURE_ELEMENT ) == | |||||
| LORAMAC_NVM_NOTIFY_FLAG_SECURE_ELEMENT ) | |||||
| { | |||||
| dataSize += NvmmWrite( ( uint8_t* ) &nvm->SecureElement, sizeof( nvm->SecureElement ), | |||||
| offset ); | |||||
| } | |||||
| offset += sizeof( nvm->SecureElement ); | |||||
| // Region group 1 | |||||
| if( ( NvmNotifyFlags & LORAMAC_NVM_NOTIFY_FLAG_REGION_GROUP1 ) == | |||||
| LORAMAC_NVM_NOTIFY_FLAG_REGION_GROUP1 ) | |||||
| { | |||||
| dataSize += NvmmWrite( ( uint8_t* ) &nvm->RegionGroup1, | |||||
| sizeof( nvm->RegionGroup1 ), offset ); | |||||
| } | |||||
| offset += sizeof( nvm->RegionGroup1 ); | |||||
| // Region group 2 | |||||
| if( ( NvmNotifyFlags & LORAMAC_NVM_NOTIFY_FLAG_REGION_GROUP2 ) == | |||||
| LORAMAC_NVM_NOTIFY_FLAG_REGION_GROUP2 ) | |||||
| { | |||||
| dataSize += NvmmWrite( ( uint8_t* ) &nvm->RegionGroup2, | |||||
| sizeof( nvm->RegionGroup2 ), offset ); | |||||
| } | |||||
| offset += sizeof( nvm->RegionGroup2 ); | |||||
| // Class b | |||||
| if( ( NvmNotifyFlags & LORAMAC_NVM_NOTIFY_FLAG_CLASS_B ) == | |||||
| LORAMAC_NVM_NOTIFY_FLAG_CLASS_B ) | |||||
| { | |||||
| dataSize += NvmmWrite( ( uint8_t* ) &nvm->ClassB, sizeof( nvm->ClassB ), | |||||
| offset ); | |||||
| } | |||||
| offset += sizeof( nvm->ClassB ); | |||||
| // Reset notification flags | |||||
| NvmNotifyFlags = LORAMAC_NVM_NOTIFY_FLAG_NONE; | |||||
| // Resume LoRaMac | |||||
| LoRaMacStart( ); | |||||
| return dataSize; | |||||
| #else | |||||
| return 0; | |||||
| #endif | |||||
| } | |||||
| uint16_t NvmDataMgmtRestore( void ) | |||||
| { | |||||
| #if( CONTEXT_MANAGEMENT_ENABLED == 1 ) | |||||
| MibRequestConfirm_t mibReq; | |||||
| mibReq.Type = MIB_NVM_CTXS; | |||||
| LoRaMacMibGetRequestConfirm( &mibReq ); | |||||
| LoRaMacNvmData_t* nvm = mibReq.Param.Contexts; | |||||
| uint16_t offset = 0; | |||||
| // Crypto | |||||
| if( NvmmCrc32Check( sizeof( LoRaMacCryptoNvmData_t ), offset ) == false ) | |||||
| { | |||||
| return 0; | |||||
| } | |||||
| offset += sizeof( LoRaMacCryptoNvmData_t ); | |||||
| // Mac Group 1 | |||||
| if( NvmmCrc32Check( sizeof( LoRaMacNvmDataGroup1_t ), offset ) == false ) | |||||
| { | |||||
| return 0; | |||||
| } | |||||
| offset += sizeof( LoRaMacNvmDataGroup1_t ); | |||||
| // Mac Group 2 | |||||
| if( NvmmCrc32Check( sizeof( LoRaMacNvmDataGroup2_t ), offset ) == false ) | |||||
| { | |||||
| return 0; | |||||
| } | |||||
| offset += sizeof( LoRaMacNvmDataGroup2_t ); | |||||
| // Secure element | |||||
| if( NvmmCrc32Check( sizeof( SecureElementNvmData_t ), offset ) == false ) | |||||
| { | |||||
| return 0; | |||||
| } | |||||
| offset += sizeof( SecureElementNvmData_t ); | |||||
| // Region group 1 | |||||
| if( NvmmCrc32Check( sizeof( RegionNvmDataGroup1_t ), offset ) == false ) | |||||
| { | |||||
| return 0; | |||||
| } | |||||
| offset += sizeof( RegionNvmDataGroup1_t ); | |||||
| // Region group 2 | |||||
| if( NvmmCrc32Check( sizeof( RegionNvmDataGroup2_t ), offset ) == false ) | |||||
| { | |||||
| return 0; | |||||
| } | |||||
| offset += sizeof( RegionNvmDataGroup2_t ); | |||||
| // Class b | |||||
| if( NvmmCrc32Check( sizeof( LoRaMacClassBNvmData_t ), offset ) == false ) | |||||
| { | |||||
| return 0; | |||||
| } | |||||
| offset += sizeof( LoRaMacClassBNvmData_t ); | |||||
| if( NvmmRead( ( uint8_t* ) nvm, sizeof( LoRaMacNvmData_t ), 0 ) == | |||||
| sizeof( LoRaMacNvmData_t ) ) | |||||
| { | |||||
| return sizeof( LoRaMacNvmData_t ); | |||||
| } | |||||
| #endif | |||||
| return 0; | |||||
| } | |||||
| bool NvmDataMgmtFactoryReset( void ) | |||||
| { | |||||
| uint16_t offset = 0; | |||||
| #if( CONTEXT_MANAGEMENT_ENABLED == 1 ) | |||||
| // Crypto | |||||
| if( NvmmReset( sizeof( LoRaMacCryptoNvmData_t ), offset ) == false ) | |||||
| { | |||||
| return false; | |||||
| } | |||||
| offset += sizeof( LoRaMacCryptoNvmData_t ); | |||||
| // Mac Group 1 | |||||
| if( NvmmReset( sizeof( LoRaMacNvmDataGroup1_t ), offset ) == false ) | |||||
| { | |||||
| return false; | |||||
| } | |||||
| offset += sizeof( LoRaMacNvmDataGroup1_t ); | |||||
| // Mac Group 2 | |||||
| if( NvmmReset( sizeof( LoRaMacNvmDataGroup2_t ), offset ) == false ) | |||||
| { | |||||
| return false; | |||||
| } | |||||
| offset += sizeof( LoRaMacNvmDataGroup2_t ); | |||||
| // Secure element | |||||
| if( NvmmReset( sizeof( SecureElementNvmData_t ), offset ) == false ) | |||||
| { | |||||
| return false; | |||||
| } | |||||
| offset += sizeof( SecureElementNvmData_t ); | |||||
| // Region group 1 | |||||
| if( NvmmReset( sizeof( RegionNvmDataGroup1_t ), offset ) == false ) | |||||
| { | |||||
| return false; | |||||
| } | |||||
| offset += sizeof( RegionNvmDataGroup1_t ); | |||||
| // Region group 2 | |||||
| if( NvmmReset( sizeof( RegionNvmDataGroup2_t ), offset ) == false ) | |||||
| { | |||||
| return false; | |||||
| } | |||||
| offset += sizeof( RegionNvmDataGroup2_t ); | |||||
| // Class b | |||||
| if( NvmmReset( sizeof( LoRaMacClassBNvmData_t ), offset ) == false ) | |||||
| { | |||||
| return false; | |||||
| } | |||||
| offset += sizeof( LoRaMacClassBNvmData_t ); | |||||
| #endif | |||||
| return true; | |||||
| } | |||||
| @@ -1,71 +1,71 @@ | |||||
| /*! | |||||
| * \file NvmDataMgmt.h | |||||
| * | |||||
| * \brief NVM context management implementation | |||||
| * | |||||
| * \copyright Revised BSD License, see section \ref LICENSE. | |||||
| * | |||||
| * \code | |||||
| * ______ _ | |||||
| * / _____) _ | | | |||||
| * ( (____ _____ ____ _| |_ _____ ____| |__ | |||||
| * \____ \| ___ | (_ _) ___ |/ ___) _ \ | |||||
| * _____) ) ____| | | || |_| ____( (___| | | | | |||||
| * (______/|_____)_|_|_| \__)_____)\____)_| |_| | |||||
| * (C)2013-2017 Semtech | |||||
| * | |||||
| * ___ _____ _ ___ _ _____ ___ ___ ___ ___ | |||||
| * / __|_ _/_\ / __| |/ / __/ _ \| _ \/ __| __| | |||||
| * \__ \ | |/ _ \ (__| ' <| _| (_) | / (__| _| | |||||
| * |___/ |_/_/ \_\___|_|\_\_| \___/|_|_\\___|___| | |||||
| * embedded.connectivity.solutions=============== | |||||
| * | |||||
| * \endcode | |||||
| * | |||||
| * \author Miguel Luis ( Semtech ) | |||||
| * | |||||
| * \author Gregory Cristian ( Semtech ) | |||||
| * | |||||
| * \author Daniel Jaeckle ( STACKFORCE ) | |||||
| * | |||||
| * \author Johannes Bruder ( STACKFORCE ) | |||||
| * | |||||
| * \defgroup NVMDATAMGMT NVM context management implementation | |||||
| * This module implements the NVM context handling | |||||
| * \{ | |||||
| */ | |||||
| #ifndef __NVMDATAMGMT_H__ | |||||
| #define __NVMDATAMGMT_H__ | |||||
| /*! | |||||
| * \brief NVM Management event. | |||||
| * | |||||
| * \param [IN] notifyFlags Bitmap which contains the information about modules that | |||||
| * changed. | |||||
| */ | |||||
| void NvmDataMgmtEvent( uint16_t notifyFlags ); | |||||
| /*! | |||||
| * \brief Function which stores the MAC data into NVM, if required. | |||||
| * | |||||
| * \retval Number of bytes which were stored. | |||||
| */ | |||||
| uint16_t NvmDataMgmtStore( void ); | |||||
| /*! | |||||
| * \brief Function which restores the MAC data from NVM, if required. | |||||
| * | |||||
| * \retval Number of bytes which were restored. | |||||
| */ | |||||
| uint16_t NvmDataMgmtRestore(void ); | |||||
| /*! | |||||
| * \brief Resets the NVM data. | |||||
| * | |||||
| * \retval Returns true, if successful. | |||||
| */ | |||||
| bool NvmDataMgmtFactoryReset( void ); | |||||
| /* \} */ | |||||
| #endif // __NVMDATAMGMT_H__ | |||||
| /*! | |||||
| * \file NvmDataMgmt.h | |||||
| * | |||||
| * \brief NVM context management implementation | |||||
| * | |||||
| * \copyright Revised BSD License, see section \ref LICENSE. | |||||
| * | |||||
| * \code | |||||
| * ______ _ | |||||
| * / _____) _ | | | |||||
| * ( (____ _____ ____ _| |_ _____ ____| |__ | |||||
| * \____ \| ___ | (_ _) ___ |/ ___) _ \ | |||||
| * _____) ) ____| | | || |_| ____( (___| | | | | |||||
| * (______/|_____)_|_|_| \__)_____)\____)_| |_| | |||||
| * (C)2013-2017 Semtech | |||||
| * | |||||
| * ___ _____ _ ___ _ _____ ___ ___ ___ ___ | |||||
| * / __|_ _/_\ / __| |/ / __/ _ \| _ \/ __| __| | |||||
| * \__ \ | |/ _ \ (__| ' <| _| (_) | / (__| _| | |||||
| * |___/ |_/_/ \_\___|_|\_\_| \___/|_|_\\___|___| | |||||
| * embedded.connectivity.solutions=============== | |||||
| * | |||||
| * \endcode | |||||
| * | |||||
| * \author Miguel Luis ( Semtech ) | |||||
| * | |||||
| * \author Gregory Cristian ( Semtech ) | |||||
| * | |||||
| * \author Daniel Jaeckle ( STACKFORCE ) | |||||
| * | |||||
| * \author Johannes Bruder ( STACKFORCE ) | |||||
| * | |||||
| * \defgroup NVMDATAMGMT NVM context management implementation | |||||
| * This module implements the NVM context handling | |||||
| * \{ | |||||
| */ | |||||
| #ifndef __NVMDATAMGMT_H__ | |||||
| #define __NVMDATAMGMT_H__ | |||||
| /*! | |||||
| * \brief NVM Management event. | |||||
| * | |||||
| * \param [IN] notifyFlags Bitmap which contains the information about modules that | |||||
| * changed. | |||||
| */ | |||||
| void NvmDataMgmtEvent( uint16_t notifyFlags ); | |||||
| /*! | |||||
| * \brief Function which stores the MAC data into NVM, if required. | |||||
| * | |||||
| * \retval Number of bytes which were stored. | |||||
| */ | |||||
| uint16_t NvmDataMgmtStore( void ); | |||||
| /*! | |||||
| * \brief Function which restores the MAC data from NVM, if required. | |||||
| * | |||||
| * \retval Number of bytes which were restored. | |||||
| */ | |||||
| uint16_t NvmDataMgmtRestore(void ); | |||||
| /*! | |||||
| * \brief Resets the NVM data. | |||||
| * | |||||
| * \retval Returns true, if successful. | |||||
| */ | |||||
| bool NvmDataMgmtFactoryReset( void ); | |||||
| /* \} */ | |||||
| #endif // __NVMDATAMGMT_H__ | |||||
| @@ -53,4 +53,4 @@ void CliProcess( Uart_t* uart ) | |||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| } | |||||
| } | |||||
| @@ -1,369 +1,369 @@ | |||||
| /*! | |||||
| * \file main.c | |||||
| * | |||||
| * \brief Ping-Pong implementation | |||||
| * | |||||
| * \copyright Revised BSD License, see section \ref LICENSE. | |||||
| * | |||||
| * \code | |||||
| * ______ _ | |||||
| * / _____) _ | | | |||||
| * ( (____ _____ ____ _| |_ _____ ____| |__ | |||||
| * \____ \| ___ | (_ _) ___ |/ ___) _ \ | |||||
| * _____) ) ____| | | || |_| ____( (___| | | | | |||||
| * (______/|_____)_|_|_| \__)_____)\____)_| |_| | |||||
| * (C)2013-2017 Semtech | |||||
| * | |||||
| * \endcode | |||||
| * | |||||
| * \author Miguel Luis ( Semtech ) | |||||
| * | |||||
| * \author Gregory Cristian ( Semtech ) | |||||
| */ | |||||
| #include <string.h> | |||||
| #include "board.h" | |||||
| #include "gpio.h" | |||||
| #include "delay.h" | |||||
| #include "timer.h" | |||||
| #include "radio.h" | |||||
| #if defined( REGION_AS923 ) | |||||
| #define RF_FREQUENCY 923000000 // Hz | |||||
| #elif defined( REGION_AU915 ) | |||||
| #define RF_FREQUENCY 915000000 // Hz | |||||
| #elif defined( REGION_CN470 ) | |||||
| #define RF_FREQUENCY 470000000 // Hz | |||||
| #elif defined( REGION_CN779 ) | |||||
| #define RF_FREQUENCY 779000000 // Hz | |||||
| #elif defined( REGION_EU433 ) | |||||
| #define RF_FREQUENCY 433000000 // Hz | |||||
| #elif defined( REGION_EU868 ) | |||||
| #define RF_FREQUENCY 868000000 // Hz | |||||
| #elif defined( REGION_KR920 ) | |||||
| #define RF_FREQUENCY 920000000 // Hz | |||||
| #elif defined( REGION_IN865 ) | |||||
| #define RF_FREQUENCY 865000000 // Hz | |||||
| #elif defined( REGION_US915 ) | |||||
| #define RF_FREQUENCY 915000000 // Hz | |||||
| #elif defined( REGION_RU864 ) | |||||
| #define RF_FREQUENCY 864000000 // Hz | |||||
| #else | |||||
| #error "Please define a frequency band in the compiler options." | |||||
| #endif | |||||
| #define TX_OUTPUT_POWER 14 // dBm | |||||
| #if defined( USE_MODEM_LORA ) | |||||
| #define LORA_BANDWIDTH 0 // [0: 125 kHz, | |||||
| // 1: 250 kHz, | |||||
| // 2: 500 kHz, | |||||
| // 3: Reserved] | |||||
| #define LORA_SPREADING_FACTOR 7 // [SF7..SF12] | |||||
| #define LORA_CODINGRATE 1 // [1: 4/5, | |||||
| // 2: 4/6, | |||||
| // 3: 4/7, | |||||
| // 4: 4/8] | |||||
| #define LORA_PREAMBLE_LENGTH 8 // Same for Tx and Rx | |||||
| #define LORA_SYMBOL_TIMEOUT 5 // Symbols | |||||
| #define LORA_FIX_LENGTH_PAYLOAD_ON false | |||||
| #define LORA_IQ_INVERSION_ON false | |||||
| #elif defined( USE_MODEM_FSK ) | |||||
| #define FSK_FDEV 25000 // Hz | |||||
| #define FSK_DATARATE 50000 // bps | |||||
| #define FSK_BANDWIDTH 50000 // Hz | |||||
| #define FSK_AFC_BANDWIDTH 83333 // Hz | |||||
| #define FSK_PREAMBLE_LENGTH 5 // Same for Tx and Rx | |||||
| #define FSK_FIX_LENGTH_PAYLOAD_ON false | |||||
| #else | |||||
| #error "Please define a modem in the compiler options." | |||||
| #endif | |||||
| typedef enum | |||||
| { | |||||
| LOWPOWER, | |||||
| RX, | |||||
| RX_TIMEOUT, | |||||
| RX_ERROR, | |||||
| TX, | |||||
| TX_TIMEOUT, | |||||
| }States_t; | |||||
| #define RX_TIMEOUT_VALUE 1000 | |||||
| #define BUFFER_SIZE 64 // Define the payload size here | |||||
| const uint8_t PingMsg[] = "PING"; | |||||
| const uint8_t PongMsg[] = "PONG"; | |||||
| uint16_t BufferSize = BUFFER_SIZE; | |||||
| uint8_t Buffer[BUFFER_SIZE]; | |||||
| States_t State = LOWPOWER; | |||||
| int8_t RssiValue = 0; | |||||
| int8_t SnrValue = 0; | |||||
| /*! | |||||
| * Radio events function pointer | |||||
| */ | |||||
| static RadioEvents_t RadioEvents; | |||||
| /*! | |||||
| * LED GPIO pins objects | |||||
| */ | |||||
| extern Gpio_t Led1; | |||||
| extern Gpio_t Led2; | |||||
| /*! | |||||
| * \brief Function to be executed on Radio Tx Done event | |||||
| */ | |||||
| void OnTxDone( void ); | |||||
| /*! | |||||
| * \brief Function to be executed on Radio Rx Done event | |||||
| */ | |||||
| void OnRxDone( uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr ); | |||||
| /*! | |||||
| * \brief Function executed on Radio Tx Timeout event | |||||
| */ | |||||
| void OnTxTimeout( void ); | |||||
| /*! | |||||
| * \brief Function executed on Radio Rx Timeout event | |||||
| */ | |||||
| void OnRxTimeout( void ); | |||||
| /*! | |||||
| * \brief Function executed on Radio Rx Error event | |||||
| */ | |||||
| void OnRxError( void ); | |||||
| /** | |||||
| * Main application entry point. | |||||
| */ | |||||
| int main( void ) | |||||
| { | |||||
| bool isMaster = true; | |||||
| uint8_t i; | |||||
| // Target board initialization | |||||
| BoardInitMcu( ); | |||||
| BoardInitPeriph( ); | |||||
| // Radio initialization | |||||
| RadioEvents.TxDone = OnTxDone; | |||||
| RadioEvents.RxDone = OnRxDone; | |||||
| RadioEvents.TxTimeout = OnTxTimeout; | |||||
| RadioEvents.RxTimeout = OnRxTimeout; | |||||
| RadioEvents.RxError = OnRxError; | |||||
| Radio.Init( &RadioEvents ); | |||||
| Radio.SetChannel( RF_FREQUENCY ); | |||||
| #if defined( USE_MODEM_LORA ) | |||||
| Radio.SetTxConfig( MODEM_LORA, TX_OUTPUT_POWER, 0, LORA_BANDWIDTH, | |||||
| LORA_SPREADING_FACTOR, LORA_CODINGRATE, | |||||
| LORA_PREAMBLE_LENGTH, LORA_FIX_LENGTH_PAYLOAD_ON, | |||||
| true, 0, 0, LORA_IQ_INVERSION_ON, 3000 ); | |||||
| Radio.SetRxConfig( MODEM_LORA, LORA_BANDWIDTH, LORA_SPREADING_FACTOR, | |||||
| LORA_CODINGRATE, 0, LORA_PREAMBLE_LENGTH, | |||||
| LORA_SYMBOL_TIMEOUT, LORA_FIX_LENGTH_PAYLOAD_ON, | |||||
| 0, true, 0, 0, LORA_IQ_INVERSION_ON, true ); | |||||
| Radio.SetMaxPayloadLength( MODEM_LORA, BUFFER_SIZE ); | |||||
| #elif defined( USE_MODEM_FSK ) | |||||
| Radio.SetTxConfig( MODEM_FSK, TX_OUTPUT_POWER, FSK_FDEV, 0, | |||||
| FSK_DATARATE, 0, | |||||
| FSK_PREAMBLE_LENGTH, FSK_FIX_LENGTH_PAYLOAD_ON, | |||||
| true, 0, 0, 0, 3000 ); | |||||
| Radio.SetRxConfig( MODEM_FSK, FSK_BANDWIDTH, FSK_DATARATE, | |||||
| 0, FSK_AFC_BANDWIDTH, FSK_PREAMBLE_LENGTH, | |||||
| 0, FSK_FIX_LENGTH_PAYLOAD_ON, 0, true, | |||||
| 0, 0,false, true ); | |||||
| Radio.SetMaxPayloadLength( MODEM_FSK, BUFFER_SIZE ); | |||||
| #else | |||||
| #error "Please define a frequency band in the compiler options." | |||||
| #endif | |||||
| Radio.Rx( RX_TIMEOUT_VALUE ); | |||||
| while( 1 ) | |||||
| { | |||||
| switch( State ) | |||||
| { | |||||
| case RX: | |||||
| if( isMaster == true ) | |||||
| { | |||||
| if( BufferSize > 0 ) | |||||
| { | |||||
| if( strncmp( ( const char* )Buffer, ( const char* )PongMsg, 4 ) == 0 ) | |||||
| { | |||||
| // Indicates on a LED that the received frame is a PONG | |||||
| GpioWrite( &Led1, GpioRead( &Led1 ) ^ 1 ); | |||||
| // Send the next PING frame | |||||
| Buffer[0] = 'P'; | |||||
| Buffer[1] = 'I'; | |||||
| Buffer[2] = 'N'; | |||||
| Buffer[3] = 'G'; | |||||
| // We fill the buffer with numbers for the payload | |||||
| for( i = 4; i < BufferSize; i++ ) | |||||
| { | |||||
| Buffer[i] = i - 4; | |||||
| } | |||||
| DelayMs( 1 ); | |||||
| Radio.Send( Buffer, BufferSize ); | |||||
| } | |||||
| else if( strncmp( ( const char* )Buffer, ( const char* )PingMsg, 4 ) == 0 ) | |||||
| { // A master already exists then become a slave | |||||
| isMaster = false; | |||||
| GpioWrite( &Led2, 1 ); // Set LED off | |||||
| Radio.Rx( RX_TIMEOUT_VALUE ); | |||||
| } | |||||
| else // valid reception but neither a PING or a PONG message | |||||
| { // Set device as master ans start again | |||||
| isMaster = true; | |||||
| Radio.Rx( RX_TIMEOUT_VALUE ); | |||||
| } | |||||
| } | |||||
| } | |||||
| else | |||||
| { | |||||
| if( BufferSize > 0 ) | |||||
| { | |||||
| if( strncmp( ( const char* )Buffer, ( const char* )PingMsg, 4 ) == 0 ) | |||||
| { | |||||
| // Indicates on a LED that the received frame is a PING | |||||
| GpioWrite( &Led1, GpioRead( &Led1 ) ^ 1 ); | |||||
| // Send the reply to the PONG string | |||||
| Buffer[0] = 'P'; | |||||
| Buffer[1] = 'O'; | |||||
| Buffer[2] = 'N'; | |||||
| Buffer[3] = 'G'; | |||||
| // We fill the buffer with numbers for the payload | |||||
| for( i = 4; i < BufferSize; i++ ) | |||||
| { | |||||
| Buffer[i] = i - 4; | |||||
| } | |||||
| DelayMs( 1 ); | |||||
| Radio.Send( Buffer, BufferSize ); | |||||
| } | |||||
| else // valid reception but not a PING as expected | |||||
| { // Set device as master and start again | |||||
| isMaster = true; | |||||
| Radio.Rx( RX_TIMEOUT_VALUE ); | |||||
| } | |||||
| } | |||||
| } | |||||
| State = LOWPOWER; | |||||
| break; | |||||
| case TX: | |||||
| // Indicates on a LED that we have sent a PING [Master] | |||||
| // Indicates on a LED that we have sent a PONG [Slave] | |||||
| GpioWrite( &Led2, GpioRead( &Led2 ) ^ 1 ); | |||||
| Radio.Rx( RX_TIMEOUT_VALUE ); | |||||
| State = LOWPOWER; | |||||
| break; | |||||
| case RX_TIMEOUT: | |||||
| case RX_ERROR: | |||||
| if( isMaster == true ) | |||||
| { | |||||
| // Send the next PING frame | |||||
| Buffer[0] = 'P'; | |||||
| Buffer[1] = 'I'; | |||||
| Buffer[2] = 'N'; | |||||
| Buffer[3] = 'G'; | |||||
| for( i = 4; i < BufferSize; i++ ) | |||||
| { | |||||
| Buffer[i] = i - 4; | |||||
| } | |||||
| DelayMs( 1 ); | |||||
| Radio.Send( Buffer, BufferSize ); | |||||
| } | |||||
| else | |||||
| { | |||||
| Radio.Rx( RX_TIMEOUT_VALUE ); | |||||
| } | |||||
| State = LOWPOWER; | |||||
| break; | |||||
| case TX_TIMEOUT: | |||||
| Radio.Rx( RX_TIMEOUT_VALUE ); | |||||
| State = LOWPOWER; | |||||
| break; | |||||
| case LOWPOWER: | |||||
| default: | |||||
| // Set low power | |||||
| break; | |||||
| } | |||||
| BoardLowPowerHandler( ); | |||||
| } | |||||
| } | |||||
| void OnTxDone( void ) | |||||
| { | |||||
| Radio.Sleep( ); | |||||
| State = TX; | |||||
| } | |||||
| void OnRxDone( uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr ) | |||||
| { | |||||
| Radio.Sleep( ); | |||||
| BufferSize = size; | |||||
| memcpy( Buffer, payload, BufferSize ); | |||||
| RssiValue = rssi; | |||||
| SnrValue = snr; | |||||
| State = RX; | |||||
| } | |||||
| void OnTxTimeout( void ) | |||||
| { | |||||
| Radio.Sleep( ); | |||||
| State = TX_TIMEOUT; | |||||
| } | |||||
| void OnRxTimeout( void ) | |||||
| { | |||||
| Radio.Sleep( ); | |||||
| State = RX_TIMEOUT; | |||||
| } | |||||
| void OnRxError( void ) | |||||
| { | |||||
| Radio.Sleep( ); | |||||
| State = RX_ERROR; | |||||
| } | |||||
| /*! | |||||
| * \file main.c | |||||
| * | |||||
| * \brief Ping-Pong implementation | |||||
| * | |||||
| * \copyright Revised BSD License, see section \ref LICENSE. | |||||
| * | |||||
| * \code | |||||
| * ______ _ | |||||
| * / _____) _ | | | |||||
| * ( (____ _____ ____ _| |_ _____ ____| |__ | |||||
| * \____ \| ___ | (_ _) ___ |/ ___) _ \ | |||||
| * _____) ) ____| | | || |_| ____( (___| | | | | |||||
| * (______/|_____)_|_|_| \__)_____)\____)_| |_| | |||||
| * (C)2013-2017 Semtech | |||||
| * | |||||
| * \endcode | |||||
| * | |||||
| * \author Miguel Luis ( Semtech ) | |||||
| * | |||||
| * \author Gregory Cristian ( Semtech ) | |||||
| */ | |||||
| #include <string.h> | |||||
| #include "board.h" | |||||
| #include "gpio.h" | |||||
| #include "delay.h" | |||||
| #include "timer.h" | |||||
| #include "radio.h" | |||||
| #if defined( REGION_AS923 ) | |||||
| #define RF_FREQUENCY 923000000 // Hz | |||||
| #elif defined( REGION_AU915 ) | |||||
| #define RF_FREQUENCY 915000000 // Hz | |||||
| #elif defined( REGION_CN470 ) | |||||
| #define RF_FREQUENCY 470000000 // Hz | |||||
| #elif defined( REGION_CN779 ) | |||||
| #define RF_FREQUENCY 779000000 // Hz | |||||
| #elif defined( REGION_EU433 ) | |||||
| #define RF_FREQUENCY 433000000 // Hz | |||||
| #elif defined( REGION_EU868 ) | |||||
| #define RF_FREQUENCY 868000000 // Hz | |||||
| #elif defined( REGION_KR920 ) | |||||
| #define RF_FREQUENCY 920000000 // Hz | |||||
| #elif defined( REGION_IN865 ) | |||||
| #define RF_FREQUENCY 865000000 // Hz | |||||
| #elif defined( REGION_US915 ) | |||||
| #define RF_FREQUENCY 915000000 // Hz | |||||
| #elif defined( REGION_RU864 ) | |||||
| #define RF_FREQUENCY 864000000 // Hz | |||||
| #else | |||||
| #error "Please define a frequency band in the compiler options." | |||||
| #endif | |||||
| #define TX_OUTPUT_POWER 14 // dBm | |||||
| #if defined( USE_MODEM_LORA ) | |||||
| #define LORA_BANDWIDTH 0 // [0: 125 kHz, | |||||
| // 1: 250 kHz, | |||||
| // 2: 500 kHz, | |||||
| // 3: Reserved] | |||||
| #define LORA_SPREADING_FACTOR 7 // [SF7..SF12] | |||||
| #define LORA_CODINGRATE 1 // [1: 4/5, | |||||
| // 2: 4/6, | |||||
| // 3: 4/7, | |||||
| // 4: 4/8] | |||||
| #define LORA_PREAMBLE_LENGTH 8 // Same for Tx and Rx | |||||
| #define LORA_SYMBOL_TIMEOUT 5 // Symbols | |||||
| #define LORA_FIX_LENGTH_PAYLOAD_ON false | |||||
| #define LORA_IQ_INVERSION_ON false | |||||
| #elif defined( USE_MODEM_FSK ) | |||||
| #define FSK_FDEV 25000 // Hz | |||||
| #define FSK_DATARATE 50000 // bps | |||||
| #define FSK_BANDWIDTH 50000 // Hz | |||||
| #define FSK_AFC_BANDWIDTH 83333 // Hz | |||||
| #define FSK_PREAMBLE_LENGTH 5 // Same for Tx and Rx | |||||
| #define FSK_FIX_LENGTH_PAYLOAD_ON false | |||||
| #else | |||||
| #error "Please define a modem in the compiler options." | |||||
| #endif | |||||
| typedef enum | |||||
| { | |||||
| LOWPOWER, | |||||
| RX, | |||||
| RX_TIMEOUT, | |||||
| RX_ERROR, | |||||
| TX, | |||||
| TX_TIMEOUT, | |||||
| }States_t; | |||||
| #define RX_TIMEOUT_VALUE 1000 | |||||
| #define BUFFER_SIZE 64 // Define the payload size here | |||||
| const uint8_t PingMsg[] = "PING"; | |||||
| const uint8_t PongMsg[] = "PONG"; | |||||
| uint16_t BufferSize = BUFFER_SIZE; | |||||
| uint8_t Buffer[BUFFER_SIZE]; | |||||
| States_t State = LOWPOWER; | |||||
| int8_t RssiValue = 0; | |||||
| int8_t SnrValue = 0; | |||||
| /*! | |||||
| * Radio events function pointer | |||||
| */ | |||||
| static RadioEvents_t RadioEvents; | |||||
| /*! | |||||
| * LED GPIO pins objects | |||||
| */ | |||||
| extern Gpio_t Led1; | |||||
| extern Gpio_t Led2; | |||||
| /*! | |||||
| * \brief Function to be executed on Radio Tx Done event | |||||
| */ | |||||
| void OnTxDone( void ); | |||||
| /*! | |||||
| * \brief Function to be executed on Radio Rx Done event | |||||
| */ | |||||
| void OnRxDone( uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr ); | |||||
| /*! | |||||
| * \brief Function executed on Radio Tx Timeout event | |||||
| */ | |||||
| void OnTxTimeout( void ); | |||||
| /*! | |||||
| * \brief Function executed on Radio Rx Timeout event | |||||
| */ | |||||
| void OnRxTimeout( void ); | |||||
| /*! | |||||
| * \brief Function executed on Radio Rx Error event | |||||
| */ | |||||
| void OnRxError( void ); | |||||
| /** | |||||
| * Main application entry point. | |||||
| */ | |||||
| int main( void ) | |||||
| { | |||||
| bool isMaster = true; | |||||
| uint8_t i; | |||||
| // Target board initialization | |||||
| BoardInitMcu( ); | |||||
| BoardInitPeriph( ); | |||||
| // Radio initialization | |||||
| RadioEvents.TxDone = OnTxDone; | |||||
| RadioEvents.RxDone = OnRxDone; | |||||
| RadioEvents.TxTimeout = OnTxTimeout; | |||||
| RadioEvents.RxTimeout = OnRxTimeout; | |||||
| RadioEvents.RxError = OnRxError; | |||||
| Radio.Init( &RadioEvents ); | |||||
| Radio.SetChannel( RF_FREQUENCY ); | |||||
| #if defined( USE_MODEM_LORA ) | |||||
| Radio.SetTxConfig( MODEM_LORA, TX_OUTPUT_POWER, 0, LORA_BANDWIDTH, | |||||
| LORA_SPREADING_FACTOR, LORA_CODINGRATE, | |||||
| LORA_PREAMBLE_LENGTH, LORA_FIX_LENGTH_PAYLOAD_ON, | |||||
| true, 0, 0, LORA_IQ_INVERSION_ON, 3000 ); | |||||
| Radio.SetRxConfig( MODEM_LORA, LORA_BANDWIDTH, LORA_SPREADING_FACTOR, | |||||
| LORA_CODINGRATE, 0, LORA_PREAMBLE_LENGTH, | |||||
| LORA_SYMBOL_TIMEOUT, LORA_FIX_LENGTH_PAYLOAD_ON, | |||||
| 0, true, 0, 0, LORA_IQ_INVERSION_ON, true ); | |||||
| Radio.SetMaxPayloadLength( MODEM_LORA, BUFFER_SIZE ); | |||||
| #elif defined( USE_MODEM_FSK ) | |||||
| Radio.SetTxConfig( MODEM_FSK, TX_OUTPUT_POWER, FSK_FDEV, 0, | |||||
| FSK_DATARATE, 0, | |||||
| FSK_PREAMBLE_LENGTH, FSK_FIX_LENGTH_PAYLOAD_ON, | |||||
| true, 0, 0, 0, 3000 ); | |||||
| Radio.SetRxConfig( MODEM_FSK, FSK_BANDWIDTH, FSK_DATARATE, | |||||
| 0, FSK_AFC_BANDWIDTH, FSK_PREAMBLE_LENGTH, | |||||
| 0, FSK_FIX_LENGTH_PAYLOAD_ON, 0, true, | |||||
| 0, 0,false, true ); | |||||
| Radio.SetMaxPayloadLength( MODEM_FSK, BUFFER_SIZE ); | |||||
| #else | |||||
| #error "Please define a frequency band in the compiler options." | |||||
| #endif | |||||
| Radio.Rx( RX_TIMEOUT_VALUE ); | |||||
| while( 1 ) | |||||
| { | |||||
| switch( State ) | |||||
| { | |||||
| case RX: | |||||
| if( isMaster == true ) | |||||
| { | |||||
| if( BufferSize > 0 ) | |||||
| { | |||||
| if( strncmp( ( const char* )Buffer, ( const char* )PongMsg, 4 ) == 0 ) | |||||
| { | |||||
| // Indicates on a LED that the received frame is a PONG | |||||
| GpioWrite( &Led1, GpioRead( &Led1 ) ^ 1 ); | |||||
| // Send the next PING frame | |||||
| Buffer[0] = 'P'; | |||||
| Buffer[1] = 'I'; | |||||
| Buffer[2] = 'N'; | |||||
| Buffer[3] = 'G'; | |||||
| // We fill the buffer with numbers for the payload | |||||
| for( i = 4; i < BufferSize; i++ ) | |||||
| { | |||||
| Buffer[i] = i - 4; | |||||
| } | |||||
| DelayMs( 1 ); | |||||
| Radio.Send( Buffer, BufferSize ); | |||||
| } | |||||
| else if( strncmp( ( const char* )Buffer, ( const char* )PingMsg, 4 ) == 0 ) | |||||
| { // A master already exists then become a slave | |||||
| isMaster = false; | |||||
| GpioWrite( &Led2, 1 ); // Set LED off | |||||
| Radio.Rx( RX_TIMEOUT_VALUE ); | |||||
| } | |||||
| else // valid reception but neither a PING or a PONG message | |||||
| { // Set device as master ans start again | |||||
| isMaster = true; | |||||
| Radio.Rx( RX_TIMEOUT_VALUE ); | |||||
| } | |||||
| } | |||||
| } | |||||
| else | |||||
| { | |||||
| if( BufferSize > 0 ) | |||||
| { | |||||
| if( strncmp( ( const char* )Buffer, ( const char* )PingMsg, 4 ) == 0 ) | |||||
| { | |||||
| // Indicates on a LED that the received frame is a PING | |||||
| GpioWrite( &Led1, GpioRead( &Led1 ) ^ 1 ); | |||||
| // Send the reply to the PONG string | |||||
| Buffer[0] = 'P'; | |||||
| Buffer[1] = 'O'; | |||||
| Buffer[2] = 'N'; | |||||
| Buffer[3] = 'G'; | |||||
| // We fill the buffer with numbers for the payload | |||||
| for( i = 4; i < BufferSize; i++ ) | |||||
| { | |||||
| Buffer[i] = i - 4; | |||||
| } | |||||
| DelayMs( 1 ); | |||||
| Radio.Send( Buffer, BufferSize ); | |||||
| } | |||||
| else // valid reception but not a PING as expected | |||||
| { // Set device as master and start again | |||||
| isMaster = true; | |||||
| Radio.Rx( RX_TIMEOUT_VALUE ); | |||||
| } | |||||
| } | |||||
| } | |||||
| State = LOWPOWER; | |||||
| break; | |||||
| case TX: | |||||
| // Indicates on a LED that we have sent a PING [Master] | |||||
| // Indicates on a LED that we have sent a PONG [Slave] | |||||
| GpioWrite( &Led2, GpioRead( &Led2 ) ^ 1 ); | |||||
| Radio.Rx( RX_TIMEOUT_VALUE ); | |||||
| State = LOWPOWER; | |||||
| break; | |||||
| case RX_TIMEOUT: | |||||
| case RX_ERROR: | |||||
| if( isMaster == true ) | |||||
| { | |||||
| // Send the next PING frame | |||||
| Buffer[0] = 'P'; | |||||
| Buffer[1] = 'I'; | |||||
| Buffer[2] = 'N'; | |||||
| Buffer[3] = 'G'; | |||||
| for( i = 4; i < BufferSize; i++ ) | |||||
| { | |||||
| Buffer[i] = i - 4; | |||||
| } | |||||
| DelayMs( 1 ); | |||||
| Radio.Send( Buffer, BufferSize ); | |||||
| } | |||||
| else | |||||
| { | |||||
| Radio.Rx( RX_TIMEOUT_VALUE ); | |||||
| } | |||||
| State = LOWPOWER; | |||||
| break; | |||||
| case TX_TIMEOUT: | |||||
| Radio.Rx( RX_TIMEOUT_VALUE ); | |||||
| State = LOWPOWER; | |||||
| break; | |||||
| case LOWPOWER: | |||||
| default: | |||||
| // Set low power | |||||
| break; | |||||
| } | |||||
| BoardLowPowerHandler( ); | |||||
| } | |||||
| } | |||||
| void OnTxDone( void ) | |||||
| { | |||||
| Radio.Sleep( ); | |||||
| State = TX; | |||||
| } | |||||
| void OnRxDone( uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr ) | |||||
| { | |||||
| Radio.Sleep( ); | |||||
| BufferSize = size; | |||||
| memcpy( Buffer, payload, BufferSize ); | |||||
| RssiValue = rssi; | |||||
| SnrValue = snr; | |||||
| State = RX; | |||||
| } | |||||
| void OnTxTimeout( void ) | |||||
| { | |||||
| Radio.Sleep( ); | |||||
| State = TX_TIMEOUT; | |||||
| } | |||||
| void OnRxTimeout( void ) | |||||
| { | |||||
| Radio.Sleep( ); | |||||
| State = RX_TIMEOUT; | |||||
| } | |||||
| void OnRxError( void ) | |||||
| { | |||||
| Radio.Sleep( ); | |||||
| State = RX_ERROR; | |||||
| } | |||||
| @@ -1,105 +1,105 @@ | |||||
| ## | |||||
| ## ______ _ | |||||
| ## / _____) _ | | | |||||
| ## ( (____ _____ ____ _| |_ _____ ____| |__ | |||||
| ## \____ \| ___ | (_ _) ___ |/ ___) _ \ | |||||
| ## _____) ) ____| | | || |_| ____( (___| | | | | |||||
| ## (______/|_____)_|_|_| \__)_____)\____)_| |_| | |||||
| ## (C)2013-2017 Semtech | |||||
| ## ___ _____ _ ___ _ _____ ___ ___ ___ ___ | |||||
| ## / __|_ _/_\ / __| |/ / __/ _ \| _ \/ __| __| | |||||
| ## \__ \ | |/ _ \ (__| ' <| _| (_) | / (__| _| | |||||
| ## |___/ |_/_/ \_\___|_|\_\_| \___/|_|_\\___|___| | |||||
| ## embedded.connectivity.solutions.============== | |||||
| ## | |||||
| ## License: Revised BSD License, see LICENSE.TXT file included in the project | |||||
| ## Authors: Johannes Bruder (STACKFORCE), Miguel Luis (Semtech) | |||||
| ## | |||||
| project(ping-pong) | |||||
| cmake_minimum_required(VERSION 3.6) | |||||
| #--------------------------------------------------------------------------------------- | |||||
| # Options | |||||
| #--------------------------------------------------------------------------------------- | |||||
| # Allow selection of region | |||||
| option(REGION_EU868 "Region EU868" ON) | |||||
| option(REGION_US915 "Region US915" OFF) | |||||
| option(REGION_CN779 "Region CN779" OFF) | |||||
| option(REGION_EU433 "Region EU433" OFF) | |||||
| option(REGION_AU915 "Region AU915" OFF) | |||||
| option(REGION_AS923 "Region AS923" OFF) | |||||
| option(REGION_CN470 "Region CN470" OFF) | |||||
| option(REGION_KR920 "Region KR920" OFF) | |||||
| option(REGION_IN865 "Region IN865" OFF) | |||||
| option(REGION_RU864 "Region RU864" OFF) | |||||
| set(REGION_LIST REGION_EU868 REGION_US915 REGION_CN779 REGION_EU433 REGION_AU915 REGION_AS923 REGION_CN470 REGION_KR920 REGION_IN865 REGION_RU864) | |||||
| # Allow switching of modulation | |||||
| set(MODULATION_LIST LORA FSK) | |||||
| set(MODULATION LORA CACHE STRING "Default modulation is LoRa") | |||||
| set_property(CACHE MODULATION PROPERTY STRINGS ${MODEM_LIST}) | |||||
| #--------------------------------------------------------------------------------------- | |||||
| # Target | |||||
| #--------------------------------------------------------------------------------------- | |||||
| file(GLOB ${PROJECT_NAME}_SOURCES "${CMAKE_CURRENT_LIST_DIR}/${BOARD}/*.c") | |||||
| add_executable(${PROJECT_NAME} | |||||
| ${${PROJECT_NAME}_SOURCES} | |||||
| $<TARGET_OBJECTS:system> | |||||
| $<TARGET_OBJECTS:radio> | |||||
| $<TARGET_OBJECTS:peripherals> | |||||
| $<TARGET_OBJECTS:${BOARD}> | |||||
| ) | |||||
| # Loops through all regions and add compile time definitions for the enabled ones. | |||||
| foreach( REGION ${REGION_LIST} ) | |||||
| if(${REGION}) | |||||
| target_compile_definitions(${PROJECT_NAME} PUBLIC -D"${REGION}") | |||||
| endif() | |||||
| endforeach() | |||||
| if(MODULATION STREQUAL LORA) | |||||
| target_compile_definitions(${PROJECT_NAME} PRIVATE USE_MODEM_LORA) | |||||
| elseif(MODULATION STREQUAL FSK) | |||||
| target_compile_definitions(${PROJECT_NAME} PRIVATE USE_MODEM_FSK) | |||||
| endif() | |||||
| # Add compile time definition for the mbed shield if set. | |||||
| target_compile_definitions(${PROJECT_NAME} PUBLIC -D${MBED_RADIO_SHIELD}) | |||||
| target_compile_definitions(${PROJECT_NAME} PUBLIC | |||||
| $<BUILD_INTERFACE:$<TARGET_PROPERTY:mac,INTERFACE_COMPILE_DEFINITIONS>> | |||||
| ) | |||||
| target_include_directories(${PROJECT_NAME} PUBLIC | |||||
| $<BUILD_INTERFACE:$<TARGET_PROPERTY:system,INTERFACE_INCLUDE_DIRECTORIES>> | |||||
| $<BUILD_INTERFACE:$<TARGET_PROPERTY:radio,INTERFACE_INCLUDE_DIRECTORIES>> | |||||
| $<BUILD_INTERFACE:$<TARGET_PROPERTY:peripherals,INTERFACE_INCLUDE_DIRECTORIES>> | |||||
| $<BUILD_INTERFACE:$<TARGET_PROPERTY:${BOARD},INTERFACE_INCLUDE_DIRECTORIES>> | |||||
| ) | |||||
| set_property(TARGET ${PROJECT_NAME} PROPERTY C_STANDARD 11) | |||||
| target_link_libraries(${PROJECT_NAME} m) | |||||
| #--------------------------------------------------------------------------------------- | |||||
| # Debugging and Binutils | |||||
| #--------------------------------------------------------------------------------------- | |||||
| include(gdb-helper) | |||||
| include(binutils-arm-none-eabi) | |||||
| # Generate debugger configurations | |||||
| generate_run_gdb_stlink(${PROJECT_NAME}) | |||||
| generate_run_gdb_openocd(${PROJECT_NAME}) | |||||
| generate_vscode_launch_openocd(${PROJECT_NAME}) | |||||
| # Print section sizes of target | |||||
| print_section_sizes(${PROJECT_NAME}) | |||||
| # Create output in hex and binary format | |||||
| create_bin_output(${PROJECT_NAME}) | |||||
| create_hex_output(${PROJECT_NAME}) | |||||
| ## | |||||
| ## ______ _ | |||||
| ## / _____) _ | | | |||||
| ## ( (____ _____ ____ _| |_ _____ ____| |__ | |||||
| ## \____ \| ___ | (_ _) ___ |/ ___) _ \ | |||||
| ## _____) ) ____| | | || |_| ____( (___| | | | | |||||
| ## (______/|_____)_|_|_| \__)_____)\____)_| |_| | |||||
| ## (C)2013-2017 Semtech | |||||
| ## ___ _____ _ ___ _ _____ ___ ___ ___ ___ | |||||
| ## / __|_ _/_\ / __| |/ / __/ _ \| _ \/ __| __| | |||||
| ## \__ \ | |/ _ \ (__| ' <| _| (_) | / (__| _| | |||||
| ## |___/ |_/_/ \_\___|_|\_\_| \___/|_|_\\___|___| | |||||
| ## embedded.connectivity.solutions.============== | |||||
| ## | |||||
| ## License: Revised BSD License, see LICENSE.TXT file included in the project | |||||
| ## Authors: Johannes Bruder (STACKFORCE), Miguel Luis (Semtech) | |||||
| ## | |||||
| project(ping-pong) | |||||
| cmake_minimum_required(VERSION 3.6) | |||||
| #--------------------------------------------------------------------------------------- | |||||
| # Options | |||||
| #--------------------------------------------------------------------------------------- | |||||
| # Allow selection of region | |||||
| option(REGION_EU868 "Region EU868" ON) | |||||
| option(REGION_US915 "Region US915" OFF) | |||||
| option(REGION_CN779 "Region CN779" OFF) | |||||
| option(REGION_EU433 "Region EU433" OFF) | |||||
| option(REGION_AU915 "Region AU915" OFF) | |||||
| option(REGION_AS923 "Region AS923" OFF) | |||||
| option(REGION_CN470 "Region CN470" OFF) | |||||
| option(REGION_KR920 "Region KR920" OFF) | |||||
| option(REGION_IN865 "Region IN865" OFF) | |||||
| option(REGION_RU864 "Region RU864" OFF) | |||||
| set(REGION_LIST REGION_EU868 REGION_US915 REGION_CN779 REGION_EU433 REGION_AU915 REGION_AS923 REGION_CN470 REGION_KR920 REGION_IN865 REGION_RU864) | |||||
| # Allow switching of modulation | |||||
| set(MODULATION_LIST LORA FSK) | |||||
| set(MODULATION LORA CACHE STRING "Default modulation is LoRa") | |||||
| set_property(CACHE MODULATION PROPERTY STRINGS ${MODEM_LIST}) | |||||
| #--------------------------------------------------------------------------------------- | |||||
| # Target | |||||
| #--------------------------------------------------------------------------------------- | |||||
| file(GLOB ${PROJECT_NAME}_SOURCES "${CMAKE_CURRENT_LIST_DIR}/${BOARD}/*.c") | |||||
| add_executable(${PROJECT_NAME} | |||||
| ${${PROJECT_NAME}_SOURCES} | |||||
| $<TARGET_OBJECTS:system> | |||||
| $<TARGET_OBJECTS:radio> | |||||
| $<TARGET_OBJECTS:peripherals> | |||||
| $<TARGET_OBJECTS:${BOARD}> | |||||
| ) | |||||
| # Loops through all regions and add compile time definitions for the enabled ones. | |||||
| foreach( REGION ${REGION_LIST} ) | |||||
| if(${REGION}) | |||||
| target_compile_definitions(${PROJECT_NAME} PUBLIC -D"${REGION}") | |||||
| endif() | |||||
| endforeach() | |||||
| if(MODULATION STREQUAL LORA) | |||||
| target_compile_definitions(${PROJECT_NAME} PRIVATE USE_MODEM_LORA) | |||||
| elseif(MODULATION STREQUAL FSK) | |||||
| target_compile_definitions(${PROJECT_NAME} PRIVATE USE_MODEM_FSK) | |||||
| endif() | |||||
| # Add compile time definition for the mbed shield if set. | |||||
| target_compile_definitions(${PROJECT_NAME} PUBLIC -D${MBED_RADIO_SHIELD}) | |||||
| target_compile_definitions(${PROJECT_NAME} PUBLIC | |||||
| $<BUILD_INTERFACE:$<TARGET_PROPERTY:mac,INTERFACE_COMPILE_DEFINITIONS>> | |||||
| ) | |||||
| target_include_directories(${PROJECT_NAME} PUBLIC | |||||
| $<BUILD_INTERFACE:$<TARGET_PROPERTY:system,INTERFACE_INCLUDE_DIRECTORIES>> | |||||
| $<BUILD_INTERFACE:$<TARGET_PROPERTY:radio,INTERFACE_INCLUDE_DIRECTORIES>> | |||||
| $<BUILD_INTERFACE:$<TARGET_PROPERTY:peripherals,INTERFACE_INCLUDE_DIRECTORIES>> | |||||
| $<BUILD_INTERFACE:$<TARGET_PROPERTY:${BOARD},INTERFACE_INCLUDE_DIRECTORIES>> | |||||
| ) | |||||
| set_property(TARGET ${PROJECT_NAME} PROPERTY C_STANDARD 11) | |||||
| target_link_libraries(${PROJECT_NAME} m) | |||||
| #--------------------------------------------------------------------------------------- | |||||
| # Debugging and Binutils | |||||
| #--------------------------------------------------------------------------------------- | |||||
| include(gdb-helper) | |||||
| include(binutils-arm-none-eabi) | |||||
| # Generate debugger configurations | |||||
| generate_run_gdb_stlink(${PROJECT_NAME}) | |||||
| generate_run_gdb_openocd(${PROJECT_NAME}) | |||||
| generate_vscode_launch_openocd(${PROJECT_NAME}) | |||||
| # Print section sizes of target | |||||
| print_section_sizes(${PROJECT_NAME}) | |||||
| # Create output in hex and binary format | |||||
| create_bin_output(${PROJECT_NAME}) | |||||
| create_hex_output(${PROJECT_NAME}) | |||||
| @@ -1,362 +1,362 @@ | |||||
| /*! | |||||
| * \file main.c | |||||
| * | |||||
| * \brief Ping-Pong implementation | |||||
| * | |||||
| * \copyright Revised BSD License, see section \ref LICENSE. | |||||
| * | |||||
| * \code | |||||
| * ______ _ | |||||
| * / _____) _ | | | |||||
| * ( (____ _____ ____ _| |_ _____ ____| |__ | |||||
| * \____ \| ___ | (_ _) ___ |/ ___) _ \ | |||||
| * _____) ) ____| | | || |_| ____( (___| | | | | |||||
| * (______/|_____)_|_|_| \__)_____)\____)_| |_| | |||||
| * (C)2013-2017 Semtech | |||||
| * | |||||
| * \endcode | |||||
| * | |||||
| * \author Miguel Luis ( Semtech ) | |||||
| * | |||||
| * \author Gregory Cristian ( Semtech ) | |||||
| */ | |||||
| #include <string.h> | |||||
| #include "board-config.h" | |||||
| #include "board.h" | |||||
| #include "gpio.h" | |||||
| #include "delay.h" | |||||
| #include "timer.h" | |||||
| #include "radio.h" | |||||
| #if defined( REGION_AS923 ) | |||||
| #define RF_FREQUENCY 923000000 // Hz | |||||
| #elif defined( REGION_AU915 ) | |||||
| #define RF_FREQUENCY 915000000 // Hz | |||||
| #elif defined( REGION_CN779 ) | |||||
| #define RF_FREQUENCY 779000000 // Hz | |||||
| #elif defined( REGION_EU868 ) | |||||
| #define RF_FREQUENCY 868000000 // Hz | |||||
| #elif defined( REGION_KR920 ) | |||||
| #define RF_FREQUENCY 920000000 // Hz | |||||
| #elif defined( REGION_IN865 ) | |||||
| #define RF_FREQUENCY 865000000 // Hz | |||||
| #elif defined( REGION_US915 ) | |||||
| #define RF_FREQUENCY 915000000 // Hz | |||||
| #elif defined( REGION_RU864 ) | |||||
| #define RF_FREQUENCY 864000000 // Hz | |||||
| #else | |||||
| #error "Please define a frequency band in the compiler options." | |||||
| #endif | |||||
| #define TX_OUTPUT_POWER 14 // dBm | |||||
| #if defined( USE_MODEM_LORA ) | |||||
| #define LORA_BANDWIDTH 0 // [0: 125 kHz, | |||||
| // 1: 250 kHz, | |||||
| // 2: 500 kHz, | |||||
| // 3: Reserved] | |||||
| #define LORA_SPREADING_FACTOR 7 // [SF7..SF12] | |||||
| #define LORA_CODINGRATE 1 // [1: 4/5, | |||||
| // 2: 4/6, | |||||
| // 3: 4/7, | |||||
| // 4: 4/8] | |||||
| #define LORA_PREAMBLE_LENGTH 8 // Same for Tx and Rx | |||||
| #define LORA_SYMBOL_TIMEOUT 5 // Symbols | |||||
| #define LORA_FIX_LENGTH_PAYLOAD_ON false | |||||
| #define LORA_IQ_INVERSION_ON false | |||||
| #elif defined( USE_MODEM_FSK ) | |||||
| #define FSK_FDEV 25000 // Hz | |||||
| #define FSK_DATARATE 50000 // bps | |||||
| #define FSK_BANDWIDTH 50000 // Hz | |||||
| #define FSK_AFC_BANDWIDTH 83333 // Hz | |||||
| #define FSK_PREAMBLE_LENGTH 5 // Same for Tx and Rx | |||||
| #define FSK_FIX_LENGTH_PAYLOAD_ON false | |||||
| #else | |||||
| #error "Please define a modem in the compiler options." | |||||
| #endif | |||||
| typedef enum | |||||
| { | |||||
| LOWPOWER, | |||||
| RX, | |||||
| RX_TIMEOUT, | |||||
| RX_ERROR, | |||||
| TX, | |||||
| TX_TIMEOUT, | |||||
| }States_t; | |||||
| #define RX_TIMEOUT_VALUE 1000 | |||||
| #define BUFFER_SIZE 64 // Define the payload size here | |||||
| const uint8_t PingMsg[] = "PING"; | |||||
| const uint8_t PongMsg[] = "PONG"; | |||||
| uint16_t BufferSize = BUFFER_SIZE; | |||||
| uint8_t Buffer[BUFFER_SIZE]; | |||||
| States_t State = LOWPOWER; | |||||
| int8_t RssiValue = 0; | |||||
| int8_t SnrValue = 0; | |||||
| /*! | |||||
| * Radio events function pointer | |||||
| */ | |||||
| static RadioEvents_t RadioEvents; | |||||
| /*! | |||||
| * LED GPIO pins objects | |||||
| */ | |||||
| extern Gpio_t Led1; | |||||
| extern Gpio_t Led2; | |||||
| /*! | |||||
| * \brief Function to be executed on Radio Tx Done event | |||||
| */ | |||||
| void OnTxDone( void ); | |||||
| /*! | |||||
| * \brief Function to be executed on Radio Rx Done event | |||||
| */ | |||||
| void OnRxDone( uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr ); | |||||
| /*! | |||||
| * \brief Function executed on Radio Tx Timeout event | |||||
| */ | |||||
| void OnTxTimeout( void ); | |||||
| /*! | |||||
| * \brief Function executed on Radio Rx Timeout event | |||||
| */ | |||||
| void OnRxTimeout( void ); | |||||
| /*! | |||||
| * \brief Function executed on Radio Rx Error event | |||||
| */ | |||||
| void OnRxError( void ); | |||||
| /** | |||||
| * Main application entry point. | |||||
| */ | |||||
| int main( void ) | |||||
| { | |||||
| bool isMaster = true; | |||||
| uint8_t i; | |||||
| // Target board initialization | |||||
| BoardInitMcu( ); | |||||
| BoardInitPeriph( ); | |||||
| // Radio initialization | |||||
| RadioEvents.TxDone = OnTxDone; | |||||
| RadioEvents.RxDone = OnRxDone; | |||||
| RadioEvents.TxTimeout = OnTxTimeout; | |||||
| RadioEvents.RxTimeout = OnRxTimeout; | |||||
| RadioEvents.RxError = OnRxError; | |||||
| Radio.Init( &RadioEvents ); | |||||
| Radio.SetChannel( RF_FREQUENCY ); | |||||
| #if defined( USE_MODEM_LORA ) | |||||
| Radio.SetTxConfig( MODEM_LORA, TX_OUTPUT_POWER, 0, LORA_BANDWIDTH, | |||||
| LORA_SPREADING_FACTOR, LORA_CODINGRATE, | |||||
| LORA_PREAMBLE_LENGTH, LORA_FIX_LENGTH_PAYLOAD_ON, | |||||
| true, 0, 0, LORA_IQ_INVERSION_ON, 3000 ); | |||||
| Radio.SetRxConfig( MODEM_LORA, LORA_BANDWIDTH, LORA_SPREADING_FACTOR, | |||||
| LORA_CODINGRATE, 0, LORA_PREAMBLE_LENGTH, | |||||
| LORA_SYMBOL_TIMEOUT, LORA_FIX_LENGTH_PAYLOAD_ON, | |||||
| 0, true, 0, 0, LORA_IQ_INVERSION_ON, true ); | |||||
| Radio.SetMaxPayloadLength( MODEM_LORA, BUFFER_SIZE ); | |||||
| #elif defined( USE_MODEM_FSK ) | |||||
| Radio.SetTxConfig( MODEM_FSK, TX_OUTPUT_POWER, FSK_FDEV, 0, | |||||
| FSK_DATARATE, 0, | |||||
| FSK_PREAMBLE_LENGTH, FSK_FIX_LENGTH_PAYLOAD_ON, | |||||
| true, 0, 0, 0, 3000 ); | |||||
| Radio.SetRxConfig( MODEM_FSK, FSK_BANDWIDTH, FSK_DATARATE, | |||||
| 0, FSK_AFC_BANDWIDTH, FSK_PREAMBLE_LENGTH, | |||||
| 0, FSK_FIX_LENGTH_PAYLOAD_ON, 0, true, | |||||
| 0, 0,false, true ); | |||||
| Radio.SetMaxPayloadLength( MODEM_FSK, BUFFER_SIZE ); | |||||
| #else | |||||
| #error "Please define a frequency band in the compiler options." | |||||
| #endif | |||||
| Radio.Rx( RX_TIMEOUT_VALUE ); | |||||
| while( 1 ) | |||||
| { | |||||
| switch( State ) | |||||
| { | |||||
| case RX: | |||||
| if( isMaster == true ) | |||||
| { | |||||
| if( BufferSize > 0 ) | |||||
| { | |||||
| if( strncmp( ( const char* )Buffer, ( const char* )PongMsg, 4 ) == 0 ) | |||||
| { | |||||
| // Indicates on a LED that the received frame is a PONG | |||||
| GpioWrite( &Led1, GpioRead( &Led1 ) ^ 1 ); | |||||
| // Send the next PING frame | |||||
| Buffer[0] = 'P'; | |||||
| Buffer[1] = 'I'; | |||||
| Buffer[2] = 'N'; | |||||
| Buffer[3] = 'G'; | |||||
| // We fill the buffer with numbers for the payload | |||||
| for( i = 4; i < BufferSize; i++ ) | |||||
| { | |||||
| Buffer[i] = i - 4; | |||||
| } | |||||
| DelayMs( 1 ); | |||||
| Radio.Send( Buffer, BufferSize ); | |||||
| } | |||||
| else if( strncmp( ( const char* )Buffer, ( const char* )PingMsg, 4 ) == 0 ) | |||||
| { // A master already exists then become a slave | |||||
| isMaster = false; | |||||
| GpioWrite( &Led2, 1 ); // Set LED off | |||||
| Radio.Rx( RX_TIMEOUT_VALUE ); | |||||
| } | |||||
| else // valid reception but neither a PING or a PONG message | |||||
| { // Set device as master ans start again | |||||
| isMaster = true; | |||||
| Radio.Rx( RX_TIMEOUT_VALUE ); | |||||
| } | |||||
| } | |||||
| } | |||||
| else | |||||
| { | |||||
| if( BufferSize > 0 ) | |||||
| { | |||||
| if( strncmp( ( const char* )Buffer, ( const char* )PingMsg, 4 ) == 0 ) | |||||
| { | |||||
| // Indicates on a LED that the received frame is a PING | |||||
| GpioWrite( &Led1, GpioRead( &Led1 ) ^ 1 ); | |||||
| // Send the reply to the PONG string | |||||
| Buffer[0] = 'P'; | |||||
| Buffer[1] = 'O'; | |||||
| Buffer[2] = 'N'; | |||||
| Buffer[3] = 'G'; | |||||
| // We fill the buffer with numbers for the payload | |||||
| for( i = 4; i < BufferSize; i++ ) | |||||
| { | |||||
| Buffer[i] = i - 4; | |||||
| } | |||||
| DelayMs( 1 ); | |||||
| Radio.Send( Buffer, BufferSize ); | |||||
| } | |||||
| else // valid reception but not a PING as expected | |||||
| { // Set device as master and start again | |||||
| isMaster = true; | |||||
| Radio.Rx( RX_TIMEOUT_VALUE ); | |||||
| } | |||||
| } | |||||
| } | |||||
| State = LOWPOWER; | |||||
| break; | |||||
| case TX: | |||||
| // Indicates on a LED that we have sent a PING [Master] | |||||
| // Indicates on a LED that we have sent a PONG [Slave] | |||||
| GpioWrite( &Led2, GpioRead( &Led2 ) ^ 1 ); | |||||
| Radio.Rx( RX_TIMEOUT_VALUE ); | |||||
| State = LOWPOWER; | |||||
| break; | |||||
| case RX_TIMEOUT: | |||||
| case RX_ERROR: | |||||
| if( isMaster == true ) | |||||
| { | |||||
| // Send the next PING frame | |||||
| Buffer[0] = 'P'; | |||||
| Buffer[1] = 'I'; | |||||
| Buffer[2] = 'N'; | |||||
| Buffer[3] = 'G'; | |||||
| for( i = 4; i < BufferSize; i++ ) | |||||
| { | |||||
| Buffer[i] = i - 4; | |||||
| } | |||||
| DelayMs( 1 ); | |||||
| Radio.Send( Buffer, BufferSize ); | |||||
| } | |||||
| else | |||||
| { | |||||
| Radio.Rx( RX_TIMEOUT_VALUE ); | |||||
| } | |||||
| State = LOWPOWER; | |||||
| break; | |||||
| case TX_TIMEOUT: | |||||
| Radio.Rx( RX_TIMEOUT_VALUE ); | |||||
| State = LOWPOWER; | |||||
| break; | |||||
| case LOWPOWER: | |||||
| default: | |||||
| // Set low power | |||||
| break; | |||||
| } | |||||
| BoardLowPowerHandler( ); | |||||
| } | |||||
| } | |||||
| void OnTxDone( void ) | |||||
| { | |||||
| Radio.Sleep( ); | |||||
| State = TX; | |||||
| } | |||||
| void OnRxDone( uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr ) | |||||
| { | |||||
| Radio.Sleep( ); | |||||
| BufferSize = size; | |||||
| memcpy( Buffer, payload, BufferSize ); | |||||
| RssiValue = rssi; | |||||
| SnrValue = snr; | |||||
| State = RX; | |||||
| } | |||||
| void OnTxTimeout( void ) | |||||
| { | |||||
| Radio.Sleep( ); | |||||
| State = TX_TIMEOUT; | |||||
| } | |||||
| void OnRxTimeout( void ) | |||||
| { | |||||
| Radio.Sleep( ); | |||||
| State = RX_TIMEOUT; | |||||
| } | |||||
| void OnRxError( void ) | |||||
| { | |||||
| Radio.Sleep( ); | |||||
| State = RX_ERROR; | |||||
| } | |||||
| /*! | |||||
| * \file main.c | |||||
| * | |||||
| * \brief Ping-Pong implementation | |||||
| * | |||||
| * \copyright Revised BSD License, see section \ref LICENSE. | |||||
| * | |||||
| * \code | |||||
| * ______ _ | |||||
| * / _____) _ | | | |||||
| * ( (____ _____ ____ _| |_ _____ ____| |__ | |||||
| * \____ \| ___ | (_ _) ___ |/ ___) _ \ | |||||
| * _____) ) ____| | | || |_| ____( (___| | | | | |||||
| * (______/|_____)_|_|_| \__)_____)\____)_| |_| | |||||
| * (C)2013-2017 Semtech | |||||
| * | |||||
| * \endcode | |||||
| * | |||||
| * \author Miguel Luis ( Semtech ) | |||||
| * | |||||
| * \author Gregory Cristian ( Semtech ) | |||||
| */ | |||||
| #include <string.h> | |||||
| #include "board-config.h" | |||||
| #include "board.h" | |||||
| #include "gpio.h" | |||||
| #include "delay.h" | |||||
| #include "timer.h" | |||||
| #include "radio.h" | |||||
| #if defined( REGION_AS923 ) | |||||
| #define RF_FREQUENCY 923000000 // Hz | |||||
| #elif defined( REGION_AU915 ) | |||||
| #define RF_FREQUENCY 915000000 // Hz | |||||
| #elif defined( REGION_CN779 ) | |||||
| #define RF_FREQUENCY 779000000 // Hz | |||||
| #elif defined( REGION_EU868 ) | |||||
| #define RF_FREQUENCY 868000000 // Hz | |||||
| #elif defined( REGION_KR920 ) | |||||
| #define RF_FREQUENCY 920000000 // Hz | |||||
| #elif defined( REGION_IN865 ) | |||||
| #define RF_FREQUENCY 865000000 // Hz | |||||
| #elif defined( REGION_US915 ) | |||||
| #define RF_FREQUENCY 915000000 // Hz | |||||
| #elif defined( REGION_RU864 ) | |||||
| #define RF_FREQUENCY 864000000 // Hz | |||||
| #else | |||||
| #error "Please define a frequency band in the compiler options." | |||||
| #endif | |||||
| #define TX_OUTPUT_POWER 14 // dBm | |||||
| #if defined( USE_MODEM_LORA ) | |||||
| #define LORA_BANDWIDTH 0 // [0: 125 kHz, | |||||
| // 1: 250 kHz, | |||||
| // 2: 500 kHz, | |||||
| // 3: Reserved] | |||||
| #define LORA_SPREADING_FACTOR 7 // [SF7..SF12] | |||||
| #define LORA_CODINGRATE 1 // [1: 4/5, | |||||
| // 2: 4/6, | |||||
| // 3: 4/7, | |||||
| // 4: 4/8] | |||||
| #define LORA_PREAMBLE_LENGTH 8 // Same for Tx and Rx | |||||
| #define LORA_SYMBOL_TIMEOUT 5 // Symbols | |||||
| #define LORA_FIX_LENGTH_PAYLOAD_ON false | |||||
| #define LORA_IQ_INVERSION_ON false | |||||
| #elif defined( USE_MODEM_FSK ) | |||||
| #define FSK_FDEV 25000 // Hz | |||||
| #define FSK_DATARATE 50000 // bps | |||||
| #define FSK_BANDWIDTH 50000 // Hz | |||||
| #define FSK_AFC_BANDWIDTH 83333 // Hz | |||||
| #define FSK_PREAMBLE_LENGTH 5 // Same for Tx and Rx | |||||
| #define FSK_FIX_LENGTH_PAYLOAD_ON false | |||||
| #else | |||||
| #error "Please define a modem in the compiler options." | |||||
| #endif | |||||
| typedef enum | |||||
| { | |||||
| LOWPOWER, | |||||
| RX, | |||||
| RX_TIMEOUT, | |||||
| RX_ERROR, | |||||
| TX, | |||||
| TX_TIMEOUT, | |||||
| }States_t; | |||||
| #define RX_TIMEOUT_VALUE 1000 | |||||
| #define BUFFER_SIZE 64 // Define the payload size here | |||||
| const uint8_t PingMsg[] = "PING"; | |||||
| const uint8_t PongMsg[] = "PONG"; | |||||
| uint16_t BufferSize = BUFFER_SIZE; | |||||
| uint8_t Buffer[BUFFER_SIZE]; | |||||
| States_t State = LOWPOWER; | |||||
| int8_t RssiValue = 0; | |||||
| int8_t SnrValue = 0; | |||||
| /*! | |||||
| * Radio events function pointer | |||||
| */ | |||||
| static RadioEvents_t RadioEvents; | |||||
| /*! | |||||
| * LED GPIO pins objects | |||||
| */ | |||||
| extern Gpio_t Led1; | |||||
| extern Gpio_t Led2; | |||||
| /*! | |||||
| * \brief Function to be executed on Radio Tx Done event | |||||
| */ | |||||
| void OnTxDone( void ); | |||||
| /*! | |||||
| * \brief Function to be executed on Radio Rx Done event | |||||
| */ | |||||
| void OnRxDone( uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr ); | |||||
| /*! | |||||
| * \brief Function executed on Radio Tx Timeout event | |||||
| */ | |||||
| void OnTxTimeout( void ); | |||||
| /*! | |||||
| * \brief Function executed on Radio Rx Timeout event | |||||
| */ | |||||
| void OnRxTimeout( void ); | |||||
| /*! | |||||
| * \brief Function executed on Radio Rx Error event | |||||
| */ | |||||
| void OnRxError( void ); | |||||
| /** | |||||
| * Main application entry point. | |||||
| */ | |||||
| int main( void ) | |||||
| { | |||||
| bool isMaster = true; | |||||
| uint8_t i; | |||||
| // Target board initialization | |||||
| BoardInitMcu( ); | |||||
| BoardInitPeriph( ); | |||||
| // Radio initialization | |||||
| RadioEvents.TxDone = OnTxDone; | |||||
| RadioEvents.RxDone = OnRxDone; | |||||
| RadioEvents.TxTimeout = OnTxTimeout; | |||||
| RadioEvents.RxTimeout = OnRxTimeout; | |||||
| RadioEvents.RxError = OnRxError; | |||||
| Radio.Init( &RadioEvents ); | |||||
| Radio.SetChannel( RF_FREQUENCY ); | |||||
| #if defined( USE_MODEM_LORA ) | |||||
| Radio.SetTxConfig( MODEM_LORA, TX_OUTPUT_POWER, 0, LORA_BANDWIDTH, | |||||
| LORA_SPREADING_FACTOR, LORA_CODINGRATE, | |||||
| LORA_PREAMBLE_LENGTH, LORA_FIX_LENGTH_PAYLOAD_ON, | |||||
| true, 0, 0, LORA_IQ_INVERSION_ON, 3000 ); | |||||
| Radio.SetRxConfig( MODEM_LORA, LORA_BANDWIDTH, LORA_SPREADING_FACTOR, | |||||
| LORA_CODINGRATE, 0, LORA_PREAMBLE_LENGTH, | |||||
| LORA_SYMBOL_TIMEOUT, LORA_FIX_LENGTH_PAYLOAD_ON, | |||||
| 0, true, 0, 0, LORA_IQ_INVERSION_ON, true ); | |||||
| Radio.SetMaxPayloadLength( MODEM_LORA, BUFFER_SIZE ); | |||||
| #elif defined( USE_MODEM_FSK ) | |||||
| Radio.SetTxConfig( MODEM_FSK, TX_OUTPUT_POWER, FSK_FDEV, 0, | |||||
| FSK_DATARATE, 0, | |||||
| FSK_PREAMBLE_LENGTH, FSK_FIX_LENGTH_PAYLOAD_ON, | |||||
| true, 0, 0, 0, 3000 ); | |||||
| Radio.SetRxConfig( MODEM_FSK, FSK_BANDWIDTH, FSK_DATARATE, | |||||
| 0, FSK_AFC_BANDWIDTH, FSK_PREAMBLE_LENGTH, | |||||
| 0, FSK_FIX_LENGTH_PAYLOAD_ON, 0, true, | |||||
| 0, 0,false, true ); | |||||
| Radio.SetMaxPayloadLength( MODEM_FSK, BUFFER_SIZE ); | |||||
| #else | |||||
| #error "Please define a frequency band in the compiler options." | |||||
| #endif | |||||
| Radio.Rx( RX_TIMEOUT_VALUE ); | |||||
| while( 1 ) | |||||
| { | |||||
| switch( State ) | |||||
| { | |||||
| case RX: | |||||
| if( isMaster == true ) | |||||
| { | |||||
| if( BufferSize > 0 ) | |||||
| { | |||||
| if( strncmp( ( const char* )Buffer, ( const char* )PongMsg, 4 ) == 0 ) | |||||
| { | |||||
| // Indicates on a LED that the received frame is a PONG | |||||
| GpioWrite( &Led1, GpioRead( &Led1 ) ^ 1 ); | |||||
| // Send the next PING frame | |||||
| Buffer[0] = 'P'; | |||||
| Buffer[1] = 'I'; | |||||
| Buffer[2] = 'N'; | |||||
| Buffer[3] = 'G'; | |||||
| // We fill the buffer with numbers for the payload | |||||
| for( i = 4; i < BufferSize; i++ ) | |||||
| { | |||||
| Buffer[i] = i - 4; | |||||
| } | |||||
| DelayMs( 1 ); | |||||
| Radio.Send( Buffer, BufferSize ); | |||||
| } | |||||
| else if( strncmp( ( const char* )Buffer, ( const char* )PingMsg, 4 ) == 0 ) | |||||
| { // A master already exists then become a slave | |||||
| isMaster = false; | |||||
| GpioWrite( &Led2, 1 ); // Set LED off | |||||
| Radio.Rx( RX_TIMEOUT_VALUE ); | |||||
| } | |||||
| else // valid reception but neither a PING or a PONG message | |||||
| { // Set device as master ans start again | |||||
| isMaster = true; | |||||
| Radio.Rx( RX_TIMEOUT_VALUE ); | |||||
| } | |||||
| } | |||||
| } | |||||
| else | |||||
| { | |||||
| if( BufferSize > 0 ) | |||||
| { | |||||
| if( strncmp( ( const char* )Buffer, ( const char* )PingMsg, 4 ) == 0 ) | |||||
| { | |||||
| // Indicates on a LED that the received frame is a PING | |||||
| GpioWrite( &Led1, GpioRead( &Led1 ) ^ 1 ); | |||||
| // Send the reply to the PONG string | |||||
| Buffer[0] = 'P'; | |||||
| Buffer[1] = 'O'; | |||||
| Buffer[2] = 'N'; | |||||
| Buffer[3] = 'G'; | |||||
| // We fill the buffer with numbers for the payload | |||||
| for( i = 4; i < BufferSize; i++ ) | |||||
| { | |||||
| Buffer[i] = i - 4; | |||||
| } | |||||
| DelayMs( 1 ); | |||||
| Radio.Send( Buffer, BufferSize ); | |||||
| } | |||||
| else // valid reception but not a PING as expected | |||||
| { // Set device as master and start again | |||||
| isMaster = true; | |||||
| Radio.Rx( RX_TIMEOUT_VALUE ); | |||||
| } | |||||
| } | |||||
| } | |||||
| State = LOWPOWER; | |||||
| break; | |||||
| case TX: | |||||
| // Indicates on a LED that we have sent a PING [Master] | |||||
| // Indicates on a LED that we have sent a PONG [Slave] | |||||
| GpioWrite( &Led2, GpioRead( &Led2 ) ^ 1 ); | |||||
| Radio.Rx( RX_TIMEOUT_VALUE ); | |||||
| State = LOWPOWER; | |||||
| break; | |||||
| case RX_TIMEOUT: | |||||
| case RX_ERROR: | |||||
| if( isMaster == true ) | |||||
| { | |||||
| // Send the next PING frame | |||||
| Buffer[0] = 'P'; | |||||
| Buffer[1] = 'I'; | |||||
| Buffer[2] = 'N'; | |||||
| Buffer[3] = 'G'; | |||||
| for( i = 4; i < BufferSize; i++ ) | |||||
| { | |||||
| Buffer[i] = i - 4; | |||||
| } | |||||
| DelayMs( 1 ); | |||||
| Radio.Send( Buffer, BufferSize ); | |||||
| } | |||||
| else | |||||
| { | |||||
| Radio.Rx( RX_TIMEOUT_VALUE ); | |||||
| } | |||||
| State = LOWPOWER; | |||||
| break; | |||||
| case TX_TIMEOUT: | |||||
| Radio.Rx( RX_TIMEOUT_VALUE ); | |||||
| State = LOWPOWER; | |||||
| break; | |||||
| case LOWPOWER: | |||||
| default: | |||||
| // Set low power | |||||
| break; | |||||
| } | |||||
| BoardLowPowerHandler( ); | |||||
| } | |||||
| } | |||||
| void OnTxDone( void ) | |||||
| { | |||||
| Radio.Sleep( ); | |||||
| State = TX; | |||||
| } | |||||
| void OnRxDone( uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr ) | |||||
| { | |||||
| Radio.Sleep( ); | |||||
| BufferSize = size; | |||||
| memcpy( Buffer, payload, BufferSize ); | |||||
| RssiValue = rssi; | |||||
| SnrValue = snr; | |||||
| State = RX; | |||||
| } | |||||
| void OnTxTimeout( void ) | |||||
| { | |||||
| Radio.Sleep( ); | |||||
| State = TX_TIMEOUT; | |||||
| } | |||||
| void OnRxTimeout( void ) | |||||
| { | |||||
| Radio.Sleep( ); | |||||
| State = RX_TIMEOUT; | |||||
| } | |||||
| void OnRxError( void ) | |||||
| { | |||||
| Radio.Sleep( ); | |||||
| State = RX_ERROR; | |||||
| } | |||||
| @@ -1,373 +1,373 @@ | |||||
| /*! | |||||
| * \file main.c | |||||
| * | |||||
| * \brief Ping-Pong implementation | |||||
| * | |||||
| * \copyright Revised BSD License, see section \ref LICENSE. | |||||
| * | |||||
| * \code | |||||
| * ______ _ | |||||
| * / _____) _ | | | |||||
| * ( (____ _____ ____ _| |_ _____ ____| |__ | |||||
| * \____ \| ___ | (_ _) ___ |/ ___) _ \ | |||||
| * _____) ) ____| | | || |_| ____( (___| | | | | |||||
| * (______/|_____)_|_|_| \__)_____)\____)_| |_| | |||||
| * (C)2013-2017 Semtech | |||||
| * | |||||
| * \endcode | |||||
| * | |||||
| * \author Miguel Luis ( Semtech ) | |||||
| * | |||||
| * \author Gregory Cristian ( Semtech ) | |||||
| */ | |||||
| #include <string.h> | |||||
| #include "board.h" | |||||
| #include "gpio.h" | |||||
| #include "delay.h" | |||||
| #include "timer.h" | |||||
| #include "radio.h" | |||||
| #if defined( REGION_AS923 ) | |||||
| #define RF_FREQUENCY 923000000 // Hz | |||||
| #elif defined( REGION_AU915 ) | |||||
| #define RF_FREQUENCY 915000000 // Hz | |||||
| #elif defined( REGION_CN470 ) | |||||
| #define RF_FREQUENCY 470000000 // Hz | |||||
| #elif defined( REGION_CN779 ) | |||||
| #define RF_FREQUENCY 779000000 // Hz | |||||
| #elif defined( REGION_EU433 ) | |||||
| #define RF_FREQUENCY 433000000 // Hz | |||||
| #elif defined( REGION_EU868 ) | |||||
| #define RF_FREQUENCY 868000000 // Hz | |||||
| #elif defined( REGION_KR920 ) | |||||
| #define RF_FREQUENCY 920000000 // Hz | |||||
| #elif defined( REGION_IN865 ) | |||||
| #define RF_FREQUENCY 865000000 // Hz | |||||
| #elif defined( REGION_US915 ) | |||||
| #define RF_FREQUENCY 915000000 // Hz | |||||
| #elif defined( REGION_RU864 ) | |||||
| #define RF_FREQUENCY 864000000 // Hz | |||||
| #else | |||||
| #error "Please define a frequency band in the compiler options." | |||||
| #endif | |||||
| #define TX_OUTPUT_POWER 14 // dBm | |||||
| #if defined( USE_MODEM_LORA ) | |||||
| #define LORA_BANDWIDTH 0 // [0: 125 kHz, | |||||
| // 1: 250 kHz, | |||||
| // 2: 500 kHz, | |||||
| // 3: Reserved] | |||||
| #define LORA_SPREADING_FACTOR 7 // [SF7..SF12] | |||||
| #define LORA_CODINGRATE 1 // [1: 4/5, | |||||
| // 2: 4/6, | |||||
| // 3: 4/7, | |||||
| // 4: 4/8] | |||||
| #define LORA_PREAMBLE_LENGTH 8 // Same for Tx and Rx | |||||
| #define LORA_SYMBOL_TIMEOUT 5 // Symbols | |||||
| #define LORA_FIX_LENGTH_PAYLOAD_ON false | |||||
| #define LORA_IQ_INVERSION_ON false | |||||
| #elif defined( USE_MODEM_FSK ) | |||||
| #define FSK_FDEV 25000 // Hz | |||||
| #define FSK_DATARATE 50000 // bps | |||||
| #define FSK_BANDWIDTH 50000 // Hz | |||||
| #define FSK_AFC_BANDWIDTH 83333 // Hz | |||||
| #define FSK_PREAMBLE_LENGTH 5 // Same for Tx and Rx | |||||
| #define FSK_FIX_LENGTH_PAYLOAD_ON false | |||||
| #else | |||||
| #error "Please define a modem in the compiler options." | |||||
| #endif | |||||
| typedef enum | |||||
| { | |||||
| LOWPOWER, | |||||
| RX, | |||||
| RX_TIMEOUT, | |||||
| RX_ERROR, | |||||
| TX, | |||||
| TX_TIMEOUT, | |||||
| }States_t; | |||||
| #define RX_TIMEOUT_VALUE 1000 | |||||
| #define BUFFER_SIZE 64 // Define the payload size here | |||||
| const uint8_t PingMsg[] = "PING"; | |||||
| const uint8_t PongMsg[] = "PONG"; | |||||
| uint16_t BufferSize = BUFFER_SIZE; | |||||
| uint8_t Buffer[BUFFER_SIZE]; | |||||
| States_t State = LOWPOWER; | |||||
| int8_t RssiValue = 0; | |||||
| int8_t SnrValue = 0; | |||||
| /*! | |||||
| * Radio events function pointer | |||||
| */ | |||||
| static RadioEvents_t RadioEvents; | |||||
| /*! | |||||
| * LED GPIO pins objects | |||||
| */ | |||||
| extern Gpio_t Led1; | |||||
| extern Gpio_t Led2; | |||||
| /*! | |||||
| * \brief Function to be executed on Radio Tx Done event | |||||
| */ | |||||
| void OnTxDone( void ); | |||||
| /*! | |||||
| * \brief Function to be executed on Radio Rx Done event | |||||
| */ | |||||
| void OnRxDone( uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr ); | |||||
| /*! | |||||
| * \brief Function executed on Radio Tx Timeout event | |||||
| */ | |||||
| void OnTxTimeout( void ); | |||||
| /*! | |||||
| * \brief Function executed on Radio Rx Timeout event | |||||
| */ | |||||
| void OnRxTimeout( void ); | |||||
| /*! | |||||
| * \brief Function executed on Radio Rx Error event | |||||
| */ | |||||
| void OnRxError( void ); | |||||
| /** | |||||
| * Main application entry point. | |||||
| */ | |||||
| int main( void ) | |||||
| { | |||||
| bool isMaster = true; | |||||
| uint8_t i; | |||||
| // Target board initialization | |||||
| BoardInitMcu( ); | |||||
| BoardInitPeriph( ); | |||||
| // Radio initialization | |||||
| RadioEvents.TxDone = OnTxDone; | |||||
| RadioEvents.RxDone = OnRxDone; | |||||
| RadioEvents.TxTimeout = OnTxTimeout; | |||||
| RadioEvents.RxTimeout = OnRxTimeout; | |||||
| RadioEvents.RxError = OnRxError; | |||||
| Radio.Init( &RadioEvents ); | |||||
| Radio.SetChannel( RF_FREQUENCY ); | |||||
| #if defined( USE_MODEM_LORA ) | |||||
| Radio.SetTxConfig( MODEM_LORA, TX_OUTPUT_POWER, 0, LORA_BANDWIDTH, | |||||
| LORA_SPREADING_FACTOR, LORA_CODINGRATE, | |||||
| LORA_PREAMBLE_LENGTH, LORA_FIX_LENGTH_PAYLOAD_ON, | |||||
| true, 0, 0, LORA_IQ_INVERSION_ON, 3000 ); | |||||
| Radio.SetRxConfig( MODEM_LORA, LORA_BANDWIDTH, LORA_SPREADING_FACTOR, | |||||
| LORA_CODINGRATE, 0, LORA_PREAMBLE_LENGTH, | |||||
| LORA_SYMBOL_TIMEOUT, LORA_FIX_LENGTH_PAYLOAD_ON, | |||||
| 0, true, 0, 0, LORA_IQ_INVERSION_ON, true ); | |||||
| Radio.SetMaxPayloadLength( MODEM_LORA, BUFFER_SIZE ); | |||||
| #elif defined( USE_MODEM_FSK ) | |||||
| Radio.SetTxConfig( MODEM_FSK, TX_OUTPUT_POWER, FSK_FDEV, 0, | |||||
| FSK_DATARATE, 0, | |||||
| FSK_PREAMBLE_LENGTH, FSK_FIX_LENGTH_PAYLOAD_ON, | |||||
| true, 0, 0, 0, 3000 ); | |||||
| Radio.SetRxConfig( MODEM_FSK, FSK_BANDWIDTH, FSK_DATARATE, | |||||
| 0, FSK_AFC_BANDWIDTH, FSK_PREAMBLE_LENGTH, | |||||
| 0, FSK_FIX_LENGTH_PAYLOAD_ON, 0, true, | |||||
| 0, 0,false, true ); | |||||
| Radio.SetMaxPayloadLength( MODEM_FSK, BUFFER_SIZE ); | |||||
| #else | |||||
| #error "Please define a frequency band in the compiler options." | |||||
| #endif | |||||
| Radio.Rx( RX_TIMEOUT_VALUE ); | |||||
| while( 1 ) | |||||
| { | |||||
| switch( State ) | |||||
| { | |||||
| case RX: | |||||
| if( isMaster == true ) | |||||
| { | |||||
| if( BufferSize > 0 ) | |||||
| { | |||||
| if( strncmp( ( const char* )Buffer, ( const char* )PongMsg, 4 ) == 0 ) | |||||
| { | |||||
| // Indicates on a LED that the received frame is a PONG | |||||
| GpioToggle( &Led1 ); | |||||
| // Send the next PING frame | |||||
| Buffer[0] = 'P'; | |||||
| Buffer[1] = 'I'; | |||||
| Buffer[2] = 'N'; | |||||
| Buffer[3] = 'G'; | |||||
| // We fill the buffer with numbers for the payload | |||||
| for( i = 4; i < BufferSize; i++ ) | |||||
| { | |||||
| Buffer[i] = i - 4; | |||||
| } | |||||
| DelayMs( 1 ); | |||||
| Radio.Send( Buffer, BufferSize ); | |||||
| } | |||||
| else if( strncmp( ( const char* )Buffer, ( const char* )PingMsg, 4 ) == 0 ) | |||||
| { // A master already exists then become a slave | |||||
| isMaster = false; | |||||
| GpioToggle( &Led2 ); // Set LED off | |||||
| Radio.Rx( RX_TIMEOUT_VALUE ); | |||||
| } | |||||
| else // valid reception but neither a PING or a PONG message | |||||
| { // Set device as master ans start again | |||||
| isMaster = true; | |||||
| Radio.Rx( RX_TIMEOUT_VALUE ); | |||||
| } | |||||
| } | |||||
| } | |||||
| else | |||||
| { | |||||
| if( BufferSize > 0 ) | |||||
| { | |||||
| if( strncmp( ( const char* )Buffer, ( const char* )PingMsg, 4 ) == 0 ) | |||||
| { | |||||
| // Indicates on a LED that the received frame is a PING | |||||
| GpioToggle( &Led1 ); | |||||
| // Send the reply to the PONG string | |||||
| Buffer[0] = 'P'; | |||||
| Buffer[1] = 'O'; | |||||
| Buffer[2] = 'N'; | |||||
| Buffer[3] = 'G'; | |||||
| // We fill the buffer with numbers for the payload | |||||
| for( i = 4; i < BufferSize; i++ ) | |||||
| { | |||||
| Buffer[i] = i - 4; | |||||
| } | |||||
| DelayMs( 1 ); | |||||
| Radio.Send( Buffer, BufferSize ); | |||||
| } | |||||
| else // valid reception but not a PING as expected | |||||
| { // Set device as master and start again | |||||
| isMaster = true; | |||||
| Radio.Rx( RX_TIMEOUT_VALUE ); | |||||
| } | |||||
| } | |||||
| } | |||||
| State = LOWPOWER; | |||||
| break; | |||||
| case TX: | |||||
| // Indicates on a LED that we have sent a PING [Master] | |||||
| // Indicates on a LED that we have sent a PONG [Slave] | |||||
| GpioToggle( &Led2 ); | |||||
| Radio.Rx( RX_TIMEOUT_VALUE ); | |||||
| State = LOWPOWER; | |||||
| break; | |||||
| case RX_TIMEOUT: | |||||
| case RX_ERROR: | |||||
| if( isMaster == true ) | |||||
| { | |||||
| // Send the next PING frame | |||||
| Buffer[0] = 'P'; | |||||
| Buffer[1] = 'I'; | |||||
| Buffer[2] = 'N'; | |||||
| Buffer[3] = 'G'; | |||||
| for( i = 4; i < BufferSize; i++ ) | |||||
| { | |||||
| Buffer[i] = i - 4; | |||||
| } | |||||
| DelayMs( 1 ); | |||||
| Radio.Send( Buffer, BufferSize ); | |||||
| } | |||||
| else | |||||
| { | |||||
| Radio.Rx( RX_TIMEOUT_VALUE ); | |||||
| } | |||||
| State = LOWPOWER; | |||||
| break; | |||||
| case TX_TIMEOUT: | |||||
| Radio.Rx( RX_TIMEOUT_VALUE ); | |||||
| State = LOWPOWER; | |||||
| break; | |||||
| case LOWPOWER: | |||||
| default: | |||||
| // Set low power | |||||
| break; | |||||
| } | |||||
| BoardLowPowerHandler( ); | |||||
| // Process Radio IRQ | |||||
| if( Radio.IrqProcess != NULL ) | |||||
| { | |||||
| Radio.IrqProcess( ); | |||||
| } | |||||
| } | |||||
| } | |||||
| void OnTxDone( void ) | |||||
| { | |||||
| Radio.Sleep( ); | |||||
| State = TX; | |||||
| } | |||||
| void OnRxDone( uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr ) | |||||
| { | |||||
| Radio.Sleep( ); | |||||
| BufferSize = size; | |||||
| memcpy( Buffer, payload, BufferSize ); | |||||
| RssiValue = rssi; | |||||
| SnrValue = snr; | |||||
| State = RX; | |||||
| } | |||||
| void OnTxTimeout( void ) | |||||
| { | |||||
| Radio.Sleep( ); | |||||
| State = TX_TIMEOUT; | |||||
| } | |||||
| void OnRxTimeout( void ) | |||||
| { | |||||
| Radio.Sleep( ); | |||||
| State = RX_TIMEOUT; | |||||
| } | |||||
| void OnRxError( void ) | |||||
| { | |||||
| Radio.Sleep( ); | |||||
| State = RX_ERROR; | |||||
| } | |||||
| /*! | |||||
| * \file main.c | |||||
| * | |||||
| * \brief Ping-Pong implementation | |||||
| * | |||||
| * \copyright Revised BSD License, see section \ref LICENSE. | |||||
| * | |||||
| * \code | |||||
| * ______ _ | |||||
| * / _____) _ | | | |||||
| * ( (____ _____ ____ _| |_ _____ ____| |__ | |||||
| * \____ \| ___ | (_ _) ___ |/ ___) _ \ | |||||
| * _____) ) ____| | | || |_| ____( (___| | | | | |||||
| * (______/|_____)_|_|_| \__)_____)\____)_| |_| | |||||
| * (C)2013-2017 Semtech | |||||
| * | |||||
| * \endcode | |||||
| * | |||||
| * \author Miguel Luis ( Semtech ) | |||||
| * | |||||
| * \author Gregory Cristian ( Semtech ) | |||||
| */ | |||||
| #include <string.h> | |||||
| #include "board.h" | |||||
| #include "gpio.h" | |||||
| #include "delay.h" | |||||
| #include "timer.h" | |||||
| #include "radio.h" | |||||
| #if defined( REGION_AS923 ) | |||||
| #define RF_FREQUENCY 923000000 // Hz | |||||
| #elif defined( REGION_AU915 ) | |||||
| #define RF_FREQUENCY 915000000 // Hz | |||||
| #elif defined( REGION_CN470 ) | |||||
| #define RF_FREQUENCY 470000000 // Hz | |||||
| #elif defined( REGION_CN779 ) | |||||
| #define RF_FREQUENCY 779000000 // Hz | |||||
| #elif defined( REGION_EU433 ) | |||||
| #define RF_FREQUENCY 433000000 // Hz | |||||
| #elif defined( REGION_EU868 ) | |||||
| #define RF_FREQUENCY 868000000 // Hz | |||||
| #elif defined( REGION_KR920 ) | |||||
| #define RF_FREQUENCY 920000000 // Hz | |||||
| #elif defined( REGION_IN865 ) | |||||
| #define RF_FREQUENCY 865000000 // Hz | |||||
| #elif defined( REGION_US915 ) | |||||
| #define RF_FREQUENCY 915000000 // Hz | |||||
| #elif defined( REGION_RU864 ) | |||||
| #define RF_FREQUENCY 864000000 // Hz | |||||
| #else | |||||
| #error "Please define a frequency band in the compiler options." | |||||
| #endif | |||||
| #define TX_OUTPUT_POWER 14 // dBm | |||||
| #if defined( USE_MODEM_LORA ) | |||||
| #define LORA_BANDWIDTH 0 // [0: 125 kHz, | |||||
| // 1: 250 kHz, | |||||
| // 2: 500 kHz, | |||||
| // 3: Reserved] | |||||
| #define LORA_SPREADING_FACTOR 7 // [SF7..SF12] | |||||
| #define LORA_CODINGRATE 1 // [1: 4/5, | |||||
| // 2: 4/6, | |||||
| // 3: 4/7, | |||||
| // 4: 4/8] | |||||
| #define LORA_PREAMBLE_LENGTH 8 // Same for Tx and Rx | |||||
| #define LORA_SYMBOL_TIMEOUT 5 // Symbols | |||||
| #define LORA_FIX_LENGTH_PAYLOAD_ON false | |||||
| #define LORA_IQ_INVERSION_ON false | |||||
| #elif defined( USE_MODEM_FSK ) | |||||
| #define FSK_FDEV 25000 // Hz | |||||
| #define FSK_DATARATE 50000 // bps | |||||
| #define FSK_BANDWIDTH 50000 // Hz | |||||
| #define FSK_AFC_BANDWIDTH 83333 // Hz | |||||
| #define FSK_PREAMBLE_LENGTH 5 // Same for Tx and Rx | |||||
| #define FSK_FIX_LENGTH_PAYLOAD_ON false | |||||
| #else | |||||
| #error "Please define a modem in the compiler options." | |||||
| #endif | |||||
| typedef enum | |||||
| { | |||||
| LOWPOWER, | |||||
| RX, | |||||
| RX_TIMEOUT, | |||||
| RX_ERROR, | |||||
| TX, | |||||
| TX_TIMEOUT, | |||||
| }States_t; | |||||
| #define RX_TIMEOUT_VALUE 1000 | |||||
| #define BUFFER_SIZE 64 // Define the payload size here | |||||
| const uint8_t PingMsg[] = "PING"; | |||||
| const uint8_t PongMsg[] = "PONG"; | |||||
| uint16_t BufferSize = BUFFER_SIZE; | |||||
| uint8_t Buffer[BUFFER_SIZE]; | |||||
| States_t State = LOWPOWER; | |||||
| int8_t RssiValue = 0; | |||||
| int8_t SnrValue = 0; | |||||
| /*! | |||||
| * Radio events function pointer | |||||
| */ | |||||
| static RadioEvents_t RadioEvents; | |||||
| /*! | |||||
| * LED GPIO pins objects | |||||
| */ | |||||
| extern Gpio_t Led1; | |||||
| extern Gpio_t Led2; | |||||
| /*! | |||||
| * \brief Function to be executed on Radio Tx Done event | |||||
| */ | |||||
| void OnTxDone( void ); | |||||
| /*! | |||||
| * \brief Function to be executed on Radio Rx Done event | |||||
| */ | |||||
| void OnRxDone( uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr ); | |||||
| /*! | |||||
| * \brief Function executed on Radio Tx Timeout event | |||||
| */ | |||||
| void OnTxTimeout( void ); | |||||
| /*! | |||||
| * \brief Function executed on Radio Rx Timeout event | |||||
| */ | |||||
| void OnRxTimeout( void ); | |||||
| /*! | |||||
| * \brief Function executed on Radio Rx Error event | |||||
| */ | |||||
| void OnRxError( void ); | |||||
| /** | |||||
| * Main application entry point. | |||||
| */ | |||||
| int main( void ) | |||||
| { | |||||
| bool isMaster = true; | |||||
| uint8_t i; | |||||
| // Target board initialization | |||||
| BoardInitMcu( ); | |||||
| BoardInitPeriph( ); | |||||
| // Radio initialization | |||||
| RadioEvents.TxDone = OnTxDone; | |||||
| RadioEvents.RxDone = OnRxDone; | |||||
| RadioEvents.TxTimeout = OnTxTimeout; | |||||
| RadioEvents.RxTimeout = OnRxTimeout; | |||||
| RadioEvents.RxError = OnRxError; | |||||
| Radio.Init( &RadioEvents ); | |||||
| Radio.SetChannel( RF_FREQUENCY ); | |||||
| #if defined( USE_MODEM_LORA ) | |||||
| Radio.SetTxConfig( MODEM_LORA, TX_OUTPUT_POWER, 0, LORA_BANDWIDTH, | |||||
| LORA_SPREADING_FACTOR, LORA_CODINGRATE, | |||||
| LORA_PREAMBLE_LENGTH, LORA_FIX_LENGTH_PAYLOAD_ON, | |||||
| true, 0, 0, LORA_IQ_INVERSION_ON, 3000 ); | |||||
| Radio.SetRxConfig( MODEM_LORA, LORA_BANDWIDTH, LORA_SPREADING_FACTOR, | |||||
| LORA_CODINGRATE, 0, LORA_PREAMBLE_LENGTH, | |||||
| LORA_SYMBOL_TIMEOUT, LORA_FIX_LENGTH_PAYLOAD_ON, | |||||
| 0, true, 0, 0, LORA_IQ_INVERSION_ON, true ); | |||||
| Radio.SetMaxPayloadLength( MODEM_LORA, BUFFER_SIZE ); | |||||
| #elif defined( USE_MODEM_FSK ) | |||||
| Radio.SetTxConfig( MODEM_FSK, TX_OUTPUT_POWER, FSK_FDEV, 0, | |||||
| FSK_DATARATE, 0, | |||||
| FSK_PREAMBLE_LENGTH, FSK_FIX_LENGTH_PAYLOAD_ON, | |||||
| true, 0, 0, 0, 3000 ); | |||||
| Radio.SetRxConfig( MODEM_FSK, FSK_BANDWIDTH, FSK_DATARATE, | |||||
| 0, FSK_AFC_BANDWIDTH, FSK_PREAMBLE_LENGTH, | |||||
| 0, FSK_FIX_LENGTH_PAYLOAD_ON, 0, true, | |||||
| 0, 0,false, true ); | |||||
| Radio.SetMaxPayloadLength( MODEM_FSK, BUFFER_SIZE ); | |||||
| #else | |||||
| #error "Please define a frequency band in the compiler options." | |||||
| #endif | |||||
| Radio.Rx( RX_TIMEOUT_VALUE ); | |||||
| while( 1 ) | |||||
| { | |||||
| switch( State ) | |||||
| { | |||||
| case RX: | |||||
| if( isMaster == true ) | |||||
| { | |||||
| if( BufferSize > 0 ) | |||||
| { | |||||
| if( strncmp( ( const char* )Buffer, ( const char* )PongMsg, 4 ) == 0 ) | |||||
| { | |||||
| // Indicates on a LED that the received frame is a PONG | |||||
| GpioToggle( &Led1 ); | |||||
| // Send the next PING frame | |||||
| Buffer[0] = 'P'; | |||||
| Buffer[1] = 'I'; | |||||
| Buffer[2] = 'N'; | |||||
| Buffer[3] = 'G'; | |||||
| // We fill the buffer with numbers for the payload | |||||
| for( i = 4; i < BufferSize; i++ ) | |||||
| { | |||||
| Buffer[i] = i - 4; | |||||
| } | |||||
| DelayMs( 1 ); | |||||
| Radio.Send( Buffer, BufferSize ); | |||||
| } | |||||
| else if( strncmp( ( const char* )Buffer, ( const char* )PingMsg, 4 ) == 0 ) | |||||
| { // A master already exists then become a slave | |||||
| isMaster = false; | |||||
| GpioToggle( &Led2 ); // Set LED off | |||||
| Radio.Rx( RX_TIMEOUT_VALUE ); | |||||
| } | |||||
| else // valid reception but neither a PING or a PONG message | |||||
| { // Set device as master ans start again | |||||
| isMaster = true; | |||||
| Radio.Rx( RX_TIMEOUT_VALUE ); | |||||
| } | |||||
| } | |||||
| } | |||||
| else | |||||
| { | |||||
| if( BufferSize > 0 ) | |||||
| { | |||||
| if( strncmp( ( const char* )Buffer, ( const char* )PingMsg, 4 ) == 0 ) | |||||
| { | |||||
| // Indicates on a LED that the received frame is a PING | |||||
| GpioToggle( &Led1 ); | |||||
| // Send the reply to the PONG string | |||||
| Buffer[0] = 'P'; | |||||
| Buffer[1] = 'O'; | |||||
| Buffer[2] = 'N'; | |||||
| Buffer[3] = 'G'; | |||||
| // We fill the buffer with numbers for the payload | |||||
| for( i = 4; i < BufferSize; i++ ) | |||||
| { | |||||
| Buffer[i] = i - 4; | |||||
| } | |||||
| DelayMs( 1 ); | |||||
| Radio.Send( Buffer, BufferSize ); | |||||
| } | |||||
| else // valid reception but not a PING as expected | |||||
| { // Set device as master and start again | |||||
| isMaster = true; | |||||
| Radio.Rx( RX_TIMEOUT_VALUE ); | |||||
| } | |||||
| } | |||||
| } | |||||
| State = LOWPOWER; | |||||
| break; | |||||
| case TX: | |||||
| // Indicates on a LED that we have sent a PING [Master] | |||||
| // Indicates on a LED that we have sent a PONG [Slave] | |||||
| GpioToggle( &Led2 ); | |||||
| Radio.Rx( RX_TIMEOUT_VALUE ); | |||||
| State = LOWPOWER; | |||||
| break; | |||||
| case RX_TIMEOUT: | |||||
| case RX_ERROR: | |||||
| if( isMaster == true ) | |||||
| { | |||||
| // Send the next PING frame | |||||
| Buffer[0] = 'P'; | |||||
| Buffer[1] = 'I'; | |||||
| Buffer[2] = 'N'; | |||||
| Buffer[3] = 'G'; | |||||
| for( i = 4; i < BufferSize; i++ ) | |||||
| { | |||||
| Buffer[i] = i - 4; | |||||
| } | |||||
| DelayMs( 1 ); | |||||
| Radio.Send( Buffer, BufferSize ); | |||||
| } | |||||
| else | |||||
| { | |||||
| Radio.Rx( RX_TIMEOUT_VALUE ); | |||||
| } | |||||
| State = LOWPOWER; | |||||
| break; | |||||
| case TX_TIMEOUT: | |||||
| Radio.Rx( RX_TIMEOUT_VALUE ); | |||||
| State = LOWPOWER; | |||||
| break; | |||||
| case LOWPOWER: | |||||
| default: | |||||
| // Set low power | |||||
| break; | |||||
| } | |||||
| BoardLowPowerHandler( ); | |||||
| // Process Radio IRQ | |||||
| if( Radio.IrqProcess != NULL ) | |||||
| { | |||||
| Radio.IrqProcess( ); | |||||
| } | |||||
| } | |||||
| } | |||||
| void OnTxDone( void ) | |||||
| { | |||||
| Radio.Sleep( ); | |||||
| State = TX; | |||||
| } | |||||
| void OnRxDone( uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr ) | |||||
| { | |||||
| Radio.Sleep( ); | |||||
| BufferSize = size; | |||||
| memcpy( Buffer, payload, BufferSize ); | |||||
| RssiValue = rssi; | |||||
| SnrValue = snr; | |||||
| State = RX; | |||||
| } | |||||
| void OnTxTimeout( void ) | |||||
| { | |||||
| Radio.Sleep( ); | |||||
| State = TX_TIMEOUT; | |||||
| } | |||||
| void OnRxTimeout( void ) | |||||
| { | |||||
| Radio.Sleep( ); | |||||
| State = RX_TIMEOUT; | |||||
| } | |||||
| void OnRxError( void ) | |||||
| { | |||||
| Radio.Sleep( ); | |||||
| State = RX_ERROR; | |||||
| } | |||||
| @@ -1,373 +1,373 @@ | |||||
| /*! | |||||
| * \file main.c | |||||
| * | |||||
| * \brief Ping-Pong implementation | |||||
| * | |||||
| * \copyright Revised BSD License, see section \ref LICENSE. | |||||
| * | |||||
| * \code | |||||
| * ______ _ | |||||
| * / _____) _ | | | |||||
| * ( (____ _____ ____ _| |_ _____ ____| |__ | |||||
| * \____ \| ___ | (_ _) ___ |/ ___) _ \ | |||||
| * _____) ) ____| | | || |_| ____( (___| | | | | |||||
| * (______/|_____)_|_|_| \__)_____)\____)_| |_| | |||||
| * (C)2013-2017 Semtech | |||||
| * | |||||
| * \endcode | |||||
| * | |||||
| * \author Miguel Luis ( Semtech ) | |||||
| * | |||||
| * \author Gregory Cristian ( Semtech ) | |||||
| */ | |||||
| #include <string.h> | |||||
| #include "board.h" | |||||
| #include "gpio.h" | |||||
| #include "delay.h" | |||||
| #include "timer.h" | |||||
| #include "radio.h" | |||||
| #if defined( REGION_AS923 ) | |||||
| #define RF_FREQUENCY 923000000 // Hz | |||||
| #elif defined( REGION_AU915 ) | |||||
| #define RF_FREQUENCY 915000000 // Hz | |||||
| #elif defined( REGION_CN470 ) | |||||
| #define RF_FREQUENCY 470000000 // Hz | |||||
| #elif defined( REGION_CN779 ) | |||||
| #define RF_FREQUENCY 779000000 // Hz | |||||
| #elif defined( REGION_EU433 ) | |||||
| #define RF_FREQUENCY 433000000 // Hz | |||||
| #elif defined( REGION_EU868 ) | |||||
| #define RF_FREQUENCY 868000000 // Hz | |||||
| #elif defined( REGION_KR920 ) | |||||
| #define RF_FREQUENCY 920000000 // Hz | |||||
| #elif defined( REGION_IN865 ) | |||||
| #define RF_FREQUENCY 865000000 // Hz | |||||
| #elif defined( REGION_US915 ) | |||||
| #define RF_FREQUENCY 915000000 // Hz | |||||
| #elif defined( REGION_RU864 ) | |||||
| #define RF_FREQUENCY 864000000 // Hz | |||||
| #else | |||||
| #error "Please define a frequency band in the compiler options." | |||||
| #endif | |||||
| #define TX_OUTPUT_POWER 14 // dBm | |||||
| #if defined( USE_MODEM_LORA ) | |||||
| #define LORA_BANDWIDTH 0 // [0: 125 kHz, | |||||
| // 1: 250 kHz, | |||||
| // 2: 500 kHz, | |||||
| // 3: Reserved] | |||||
| #define LORA_SPREADING_FACTOR 7 // [SF7..SF12] | |||||
| #define LORA_CODINGRATE 1 // [1: 4/5, | |||||
| // 2: 4/6, | |||||
| // 3: 4/7, | |||||
| // 4: 4/8] | |||||
| #define LORA_PREAMBLE_LENGTH 8 // Same for Tx and Rx | |||||
| #define LORA_SYMBOL_TIMEOUT 5 // Symbols | |||||
| #define LORA_FIX_LENGTH_PAYLOAD_ON false | |||||
| #define LORA_IQ_INVERSION_ON false | |||||
| #elif defined( USE_MODEM_FSK ) | |||||
| #define FSK_FDEV 25000 // Hz | |||||
| #define FSK_DATARATE 50000 // bps | |||||
| #define FSK_BANDWIDTH 50000 // Hz | |||||
| #define FSK_AFC_BANDWIDTH 83333 // Hz | |||||
| #define FSK_PREAMBLE_LENGTH 5 // Same for Tx and Rx | |||||
| #define FSK_FIX_LENGTH_PAYLOAD_ON false | |||||
| #else | |||||
| #error "Please define a modem in the compiler options." | |||||
| #endif | |||||
| typedef enum | |||||
| { | |||||
| LOWPOWER, | |||||
| RX, | |||||
| RX_TIMEOUT, | |||||
| RX_ERROR, | |||||
| TX, | |||||
| TX_TIMEOUT, | |||||
| }States_t; | |||||
| #define RX_TIMEOUT_VALUE 1000 | |||||
| #define BUFFER_SIZE 64 // Define the payload size here | |||||
| const uint8_t PingMsg[] = "PING"; | |||||
| const uint8_t PongMsg[] = "PONG"; | |||||
| uint16_t BufferSize = BUFFER_SIZE; | |||||
| uint8_t Buffer[BUFFER_SIZE]; | |||||
| States_t State = LOWPOWER; | |||||
| int8_t RssiValue = 0; | |||||
| int8_t SnrValue = 0; | |||||
| /*! | |||||
| * Radio events function pointer | |||||
| */ | |||||
| static RadioEvents_t RadioEvents; | |||||
| /*! | |||||
| * LED GPIO pins objects | |||||
| */ | |||||
| extern Gpio_t Led1; | |||||
| extern Gpio_t Led2; | |||||
| /*! | |||||
| * \brief Function to be executed on Radio Tx Done event | |||||
| */ | |||||
| void OnTxDone( void ); | |||||
| /*! | |||||
| * \brief Function to be executed on Radio Rx Done event | |||||
| */ | |||||
| void OnRxDone( uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr ); | |||||
| /*! | |||||
| * \brief Function executed on Radio Tx Timeout event | |||||
| */ | |||||
| void OnTxTimeout( void ); | |||||
| /*! | |||||
| * \brief Function executed on Radio Rx Timeout event | |||||
| */ | |||||
| void OnRxTimeout( void ); | |||||
| /*! | |||||
| * \brief Function executed on Radio Rx Error event | |||||
| */ | |||||
| void OnRxError( void ); | |||||
| /** | |||||
| * Main application entry point. | |||||
| */ | |||||
| int main( void ) | |||||
| { | |||||
| bool isMaster = true; | |||||
| uint8_t i; | |||||
| // Target board initialization | |||||
| BoardInitMcu( ); | |||||
| BoardInitPeriph( ); | |||||
| // Radio initialization | |||||
| RadioEvents.TxDone = OnTxDone; | |||||
| RadioEvents.RxDone = OnRxDone; | |||||
| RadioEvents.TxTimeout = OnTxTimeout; | |||||
| RadioEvents.RxTimeout = OnRxTimeout; | |||||
| RadioEvents.RxError = OnRxError; | |||||
| Radio.Init( &RadioEvents ); | |||||
| Radio.SetChannel( RF_FREQUENCY ); | |||||
| #if defined( USE_MODEM_LORA ) | |||||
| Radio.SetTxConfig( MODEM_LORA, TX_OUTPUT_POWER, 0, LORA_BANDWIDTH, | |||||
| LORA_SPREADING_FACTOR, LORA_CODINGRATE, | |||||
| LORA_PREAMBLE_LENGTH, LORA_FIX_LENGTH_PAYLOAD_ON, | |||||
| true, 0, 0, LORA_IQ_INVERSION_ON, 3000 ); | |||||
| Radio.SetRxConfig( MODEM_LORA, LORA_BANDWIDTH, LORA_SPREADING_FACTOR, | |||||
| LORA_CODINGRATE, 0, LORA_PREAMBLE_LENGTH, | |||||
| LORA_SYMBOL_TIMEOUT, LORA_FIX_LENGTH_PAYLOAD_ON, | |||||
| 0, true, 0, 0, LORA_IQ_INVERSION_ON, true ); | |||||
| Radio.SetMaxPayloadLength( MODEM_LORA, BUFFER_SIZE ); | |||||
| #elif defined( USE_MODEM_FSK ) | |||||
| Radio.SetTxConfig( MODEM_FSK, TX_OUTPUT_POWER, FSK_FDEV, 0, | |||||
| FSK_DATARATE, 0, | |||||
| FSK_PREAMBLE_LENGTH, FSK_FIX_LENGTH_PAYLOAD_ON, | |||||
| true, 0, 0, 0, 3000 ); | |||||
| Radio.SetRxConfig( MODEM_FSK, FSK_BANDWIDTH, FSK_DATARATE, | |||||
| 0, FSK_AFC_BANDWIDTH, FSK_PREAMBLE_LENGTH, | |||||
| 0, FSK_FIX_LENGTH_PAYLOAD_ON, 0, true, | |||||
| 0, 0,false, true ); | |||||
| Radio.SetMaxPayloadLength( MODEM_FSK, BUFFER_SIZE ); | |||||
| #else | |||||
| #error "Please define a frequency band in the compiler options." | |||||
| #endif | |||||
| Radio.Rx( RX_TIMEOUT_VALUE ); | |||||
| while( 1 ) | |||||
| { | |||||
| switch( State ) | |||||
| { | |||||
| case RX: | |||||
| if( isMaster == true ) | |||||
| { | |||||
| if( BufferSize > 0 ) | |||||
| { | |||||
| if( strncmp( ( const char* )Buffer, ( const char* )PongMsg, 4 ) == 0 ) | |||||
| { | |||||
| // Indicates on a LED that the received frame is a PONG | |||||
| GpioToggle( &Led1 ); | |||||
| // Send the next PING frame | |||||
| Buffer[0] = 'P'; | |||||
| Buffer[1] = 'I'; | |||||
| Buffer[2] = 'N'; | |||||
| Buffer[3] = 'G'; | |||||
| // We fill the buffer with numbers for the payload | |||||
| for( i = 4; i < BufferSize; i++ ) | |||||
| { | |||||
| Buffer[i] = i - 4; | |||||
| } | |||||
| DelayMs( 1 ); | |||||
| Radio.Send( Buffer, BufferSize ); | |||||
| } | |||||
| else if( strncmp( ( const char* )Buffer, ( const char* )PingMsg, 4 ) == 0 ) | |||||
| { // A master already exists then become a slave | |||||
| isMaster = false; | |||||
| GpioToggle( &Led2 ); // Set LED off | |||||
| Radio.Rx( RX_TIMEOUT_VALUE ); | |||||
| } | |||||
| else // valid reception but neither a PING or a PONG message | |||||
| { // Set device as master ans start again | |||||
| isMaster = true; | |||||
| Radio.Rx( RX_TIMEOUT_VALUE ); | |||||
| } | |||||
| } | |||||
| } | |||||
| else | |||||
| { | |||||
| if( BufferSize > 0 ) | |||||
| { | |||||
| if( strncmp( ( const char* )Buffer, ( const char* )PingMsg, 4 ) == 0 ) | |||||
| { | |||||
| // Indicates on a LED that the received frame is a PING | |||||
| GpioToggle( &Led1 ); | |||||
| // Send the reply to the PONG string | |||||
| Buffer[0] = 'P'; | |||||
| Buffer[1] = 'O'; | |||||
| Buffer[2] = 'N'; | |||||
| Buffer[3] = 'G'; | |||||
| // We fill the buffer with numbers for the payload | |||||
| for( i = 4; i < BufferSize; i++ ) | |||||
| { | |||||
| Buffer[i] = i - 4; | |||||
| } | |||||
| DelayMs( 1 ); | |||||
| Radio.Send( Buffer, BufferSize ); | |||||
| } | |||||
| else // valid reception but not a PING as expected | |||||
| { // Set device as master and start again | |||||
| isMaster = true; | |||||
| Radio.Rx( RX_TIMEOUT_VALUE ); | |||||
| } | |||||
| } | |||||
| } | |||||
| State = LOWPOWER; | |||||
| break; | |||||
| case TX: | |||||
| // Indicates on a LED that we have sent a PING [Master] | |||||
| // Indicates on a LED that we have sent a PONG [Slave] | |||||
| GpioToggle( &Led2 ); | |||||
| Radio.Rx( RX_TIMEOUT_VALUE ); | |||||
| State = LOWPOWER; | |||||
| break; | |||||
| case RX_TIMEOUT: | |||||
| case RX_ERROR: | |||||
| if( isMaster == true ) | |||||
| { | |||||
| // Send the next PING frame | |||||
| Buffer[0] = 'P'; | |||||
| Buffer[1] = 'I'; | |||||
| Buffer[2] = 'N'; | |||||
| Buffer[3] = 'G'; | |||||
| for( i = 4; i < BufferSize; i++ ) | |||||
| { | |||||
| Buffer[i] = i - 4; | |||||
| } | |||||
| DelayMs( 1 ); | |||||
| Radio.Send( Buffer, BufferSize ); | |||||
| } | |||||
| else | |||||
| { | |||||
| Radio.Rx( RX_TIMEOUT_VALUE ); | |||||
| } | |||||
| State = LOWPOWER; | |||||
| break; | |||||
| case TX_TIMEOUT: | |||||
| Radio.Rx( RX_TIMEOUT_VALUE ); | |||||
| State = LOWPOWER; | |||||
| break; | |||||
| case LOWPOWER: | |||||
| default: | |||||
| // Set low power | |||||
| break; | |||||
| } | |||||
| BoardLowPowerHandler( ); | |||||
| // Process Radio IRQ | |||||
| if( Radio.IrqProcess != NULL ) | |||||
| { | |||||
| Radio.IrqProcess( ); | |||||
| } | |||||
| } | |||||
| } | |||||
| void OnTxDone( void ) | |||||
| { | |||||
| Radio.Sleep( ); | |||||
| State = TX; | |||||
| } | |||||
| void OnRxDone( uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr ) | |||||
| { | |||||
| Radio.Sleep( ); | |||||
| BufferSize = size; | |||||
| memcpy( Buffer, payload, BufferSize ); | |||||
| RssiValue = rssi; | |||||
| SnrValue = snr; | |||||
| State = RX; | |||||
| } | |||||
| void OnTxTimeout( void ) | |||||
| { | |||||
| Radio.Sleep( ); | |||||
| State = TX_TIMEOUT; | |||||
| } | |||||
| void OnRxTimeout( void ) | |||||
| { | |||||
| Radio.Sleep( ); | |||||
| State = RX_TIMEOUT; | |||||
| } | |||||
| void OnRxError( void ) | |||||
| { | |||||
| Radio.Sleep( ); | |||||
| State = RX_ERROR; | |||||
| } | |||||
| /*! | |||||
| * \file main.c | |||||
| * | |||||
| * \brief Ping-Pong implementation | |||||
| * | |||||
| * \copyright Revised BSD License, see section \ref LICENSE. | |||||
| * | |||||
| * \code | |||||
| * ______ _ | |||||
| * / _____) _ | | | |||||
| * ( (____ _____ ____ _| |_ _____ ____| |__ | |||||
| * \____ \| ___ | (_ _) ___ |/ ___) _ \ | |||||
| * _____) ) ____| | | || |_| ____( (___| | | | | |||||
| * (______/|_____)_|_|_| \__)_____)\____)_| |_| | |||||
| * (C)2013-2017 Semtech | |||||
| * | |||||
| * \endcode | |||||
| * | |||||
| * \author Miguel Luis ( Semtech ) | |||||
| * | |||||
| * \author Gregory Cristian ( Semtech ) | |||||
| */ | |||||
| #include <string.h> | |||||
| #include "board.h" | |||||
| #include "gpio.h" | |||||
| #include "delay.h" | |||||
| #include "timer.h" | |||||
| #include "radio.h" | |||||
| #if defined( REGION_AS923 ) | |||||
| #define RF_FREQUENCY 923000000 // Hz | |||||
| #elif defined( REGION_AU915 ) | |||||
| #define RF_FREQUENCY 915000000 // Hz | |||||
| #elif defined( REGION_CN470 ) | |||||
| #define RF_FREQUENCY 470000000 // Hz | |||||
| #elif defined( REGION_CN779 ) | |||||
| #define RF_FREQUENCY 779000000 // Hz | |||||
| #elif defined( REGION_EU433 ) | |||||
| #define RF_FREQUENCY 433000000 // Hz | |||||
| #elif defined( REGION_EU868 ) | |||||
| #define RF_FREQUENCY 868000000 // Hz | |||||
| #elif defined( REGION_KR920 ) | |||||
| #define RF_FREQUENCY 920000000 // Hz | |||||
| #elif defined( REGION_IN865 ) | |||||
| #define RF_FREQUENCY 865000000 // Hz | |||||
| #elif defined( REGION_US915 ) | |||||
| #define RF_FREQUENCY 915000000 // Hz | |||||
| #elif defined( REGION_RU864 ) | |||||
| #define RF_FREQUENCY 864000000 // Hz | |||||
| #else | |||||
| #error "Please define a frequency band in the compiler options." | |||||
| #endif | |||||
| #define TX_OUTPUT_POWER 14 // dBm | |||||
| #if defined( USE_MODEM_LORA ) | |||||
| #define LORA_BANDWIDTH 0 // [0: 125 kHz, | |||||
| // 1: 250 kHz, | |||||
| // 2: 500 kHz, | |||||
| // 3: Reserved] | |||||
| #define LORA_SPREADING_FACTOR 7 // [SF7..SF12] | |||||
| #define LORA_CODINGRATE 1 // [1: 4/5, | |||||
| // 2: 4/6, | |||||
| // 3: 4/7, | |||||
| // 4: 4/8] | |||||
| #define LORA_PREAMBLE_LENGTH 8 // Same for Tx and Rx | |||||
| #define LORA_SYMBOL_TIMEOUT 5 // Symbols | |||||
| #define LORA_FIX_LENGTH_PAYLOAD_ON false | |||||
| #define LORA_IQ_INVERSION_ON false | |||||
| #elif defined( USE_MODEM_FSK ) | |||||
| #define FSK_FDEV 25000 // Hz | |||||
| #define FSK_DATARATE 50000 // bps | |||||
| #define FSK_BANDWIDTH 50000 // Hz | |||||
| #define FSK_AFC_BANDWIDTH 83333 // Hz | |||||
| #define FSK_PREAMBLE_LENGTH 5 // Same for Tx and Rx | |||||
| #define FSK_FIX_LENGTH_PAYLOAD_ON false | |||||
| #else | |||||
| #error "Please define a modem in the compiler options." | |||||
| #endif | |||||
| typedef enum | |||||
| { | |||||
| LOWPOWER, | |||||
| RX, | |||||
| RX_TIMEOUT, | |||||
| RX_ERROR, | |||||
| TX, | |||||
| TX_TIMEOUT, | |||||
| }States_t; | |||||
| #define RX_TIMEOUT_VALUE 1000 | |||||
| #define BUFFER_SIZE 64 // Define the payload size here | |||||
| const uint8_t PingMsg[] = "PING"; | |||||
| const uint8_t PongMsg[] = "PONG"; | |||||
| uint16_t BufferSize = BUFFER_SIZE; | |||||
| uint8_t Buffer[BUFFER_SIZE]; | |||||
| States_t State = LOWPOWER; | |||||
| int8_t RssiValue = 0; | |||||
| int8_t SnrValue = 0; | |||||
| /*! | |||||
| * Radio events function pointer | |||||
| */ | |||||
| static RadioEvents_t RadioEvents; | |||||
| /*! | |||||
| * LED GPIO pins objects | |||||
| */ | |||||
| extern Gpio_t Led1; | |||||
| extern Gpio_t Led2; | |||||
| /*! | |||||
| * \brief Function to be executed on Radio Tx Done event | |||||
| */ | |||||
| void OnTxDone( void ); | |||||
| /*! | |||||
| * \brief Function to be executed on Radio Rx Done event | |||||
| */ | |||||
| void OnRxDone( uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr ); | |||||
| /*! | |||||
| * \brief Function executed on Radio Tx Timeout event | |||||
| */ | |||||
| void OnTxTimeout( void ); | |||||
| /*! | |||||
| * \brief Function executed on Radio Rx Timeout event | |||||
| */ | |||||
| void OnRxTimeout( void ); | |||||
| /*! | |||||
| * \brief Function executed on Radio Rx Error event | |||||
| */ | |||||
| void OnRxError( void ); | |||||
| /** | |||||
| * Main application entry point. | |||||
| */ | |||||
| int main( void ) | |||||
| { | |||||
| bool isMaster = true; | |||||
| uint8_t i; | |||||
| // Target board initialization | |||||
| BoardInitMcu( ); | |||||
| BoardInitPeriph( ); | |||||
| // Radio initialization | |||||
| RadioEvents.TxDone = OnTxDone; | |||||
| RadioEvents.RxDone = OnRxDone; | |||||
| RadioEvents.TxTimeout = OnTxTimeout; | |||||
| RadioEvents.RxTimeout = OnRxTimeout; | |||||
| RadioEvents.RxError = OnRxError; | |||||
| Radio.Init( &RadioEvents ); | |||||
| Radio.SetChannel( RF_FREQUENCY ); | |||||
| #if defined( USE_MODEM_LORA ) | |||||
| Radio.SetTxConfig( MODEM_LORA, TX_OUTPUT_POWER, 0, LORA_BANDWIDTH, | |||||
| LORA_SPREADING_FACTOR, LORA_CODINGRATE, | |||||
| LORA_PREAMBLE_LENGTH, LORA_FIX_LENGTH_PAYLOAD_ON, | |||||
| true, 0, 0, LORA_IQ_INVERSION_ON, 3000 ); | |||||
| Radio.SetRxConfig( MODEM_LORA, LORA_BANDWIDTH, LORA_SPREADING_FACTOR, | |||||
| LORA_CODINGRATE, 0, LORA_PREAMBLE_LENGTH, | |||||
| LORA_SYMBOL_TIMEOUT, LORA_FIX_LENGTH_PAYLOAD_ON, | |||||
| 0, true, 0, 0, LORA_IQ_INVERSION_ON, true ); | |||||
| Radio.SetMaxPayloadLength( MODEM_LORA, BUFFER_SIZE ); | |||||
| #elif defined( USE_MODEM_FSK ) | |||||
| Radio.SetTxConfig( MODEM_FSK, TX_OUTPUT_POWER, FSK_FDEV, 0, | |||||
| FSK_DATARATE, 0, | |||||
| FSK_PREAMBLE_LENGTH, FSK_FIX_LENGTH_PAYLOAD_ON, | |||||
| true, 0, 0, 0, 3000 ); | |||||
| Radio.SetRxConfig( MODEM_FSK, FSK_BANDWIDTH, FSK_DATARATE, | |||||
| 0, FSK_AFC_BANDWIDTH, FSK_PREAMBLE_LENGTH, | |||||
| 0, FSK_FIX_LENGTH_PAYLOAD_ON, 0, true, | |||||
| 0, 0,false, true ); | |||||
| Radio.SetMaxPayloadLength( MODEM_FSK, BUFFER_SIZE ); | |||||
| #else | |||||
| #error "Please define a frequency band in the compiler options." | |||||
| #endif | |||||
| Radio.Rx( RX_TIMEOUT_VALUE ); | |||||
| while( 1 ) | |||||
| { | |||||
| switch( State ) | |||||
| { | |||||
| case RX: | |||||
| if( isMaster == true ) | |||||
| { | |||||
| if( BufferSize > 0 ) | |||||
| { | |||||
| if( strncmp( ( const char* )Buffer, ( const char* )PongMsg, 4 ) == 0 ) | |||||
| { | |||||
| // Indicates on a LED that the received frame is a PONG | |||||
| GpioToggle( &Led1 ); | |||||
| // Send the next PING frame | |||||
| Buffer[0] = 'P'; | |||||
| Buffer[1] = 'I'; | |||||
| Buffer[2] = 'N'; | |||||
| Buffer[3] = 'G'; | |||||
| // We fill the buffer with numbers for the payload | |||||
| for( i = 4; i < BufferSize; i++ ) | |||||
| { | |||||
| Buffer[i] = i - 4; | |||||
| } | |||||
| DelayMs( 1 ); | |||||
| Radio.Send( Buffer, BufferSize ); | |||||
| } | |||||
| else if( strncmp( ( const char* )Buffer, ( const char* )PingMsg, 4 ) == 0 ) | |||||
| { // A master already exists then become a slave | |||||
| isMaster = false; | |||||
| GpioToggle( &Led2 ); // Set LED off | |||||
| Radio.Rx( RX_TIMEOUT_VALUE ); | |||||
| } | |||||
| else // valid reception but neither a PING or a PONG message | |||||
| { // Set device as master ans start again | |||||
| isMaster = true; | |||||
| Radio.Rx( RX_TIMEOUT_VALUE ); | |||||
| } | |||||
| } | |||||
| } | |||||
| else | |||||
| { | |||||
| if( BufferSize > 0 ) | |||||
| { | |||||
| if( strncmp( ( const char* )Buffer, ( const char* )PingMsg, 4 ) == 0 ) | |||||
| { | |||||
| // Indicates on a LED that the received frame is a PING | |||||
| GpioToggle( &Led1 ); | |||||
| // Send the reply to the PONG string | |||||
| Buffer[0] = 'P'; | |||||
| Buffer[1] = 'O'; | |||||
| Buffer[2] = 'N'; | |||||
| Buffer[3] = 'G'; | |||||
| // We fill the buffer with numbers for the payload | |||||
| for( i = 4; i < BufferSize; i++ ) | |||||
| { | |||||
| Buffer[i] = i - 4; | |||||
| } | |||||
| DelayMs( 1 ); | |||||
| Radio.Send( Buffer, BufferSize ); | |||||
| } | |||||
| else // valid reception but not a PING as expected | |||||
| { // Set device as master and start again | |||||
| isMaster = true; | |||||
| Radio.Rx( RX_TIMEOUT_VALUE ); | |||||
| } | |||||
| } | |||||
| } | |||||
| State = LOWPOWER; | |||||
| break; | |||||
| case TX: | |||||
| // Indicates on a LED that we have sent a PING [Master] | |||||
| // Indicates on a LED that we have sent a PONG [Slave] | |||||
| GpioToggle( &Led2 ); | |||||
| Radio.Rx( RX_TIMEOUT_VALUE ); | |||||
| State = LOWPOWER; | |||||
| break; | |||||
| case RX_TIMEOUT: | |||||
| case RX_ERROR: | |||||
| if( isMaster == true ) | |||||
| { | |||||
| // Send the next PING frame | |||||
| Buffer[0] = 'P'; | |||||
| Buffer[1] = 'I'; | |||||
| Buffer[2] = 'N'; | |||||
| Buffer[3] = 'G'; | |||||
| for( i = 4; i < BufferSize; i++ ) | |||||
| { | |||||
| Buffer[i] = i - 4; | |||||
| } | |||||
| DelayMs( 1 ); | |||||
| Radio.Send( Buffer, BufferSize ); | |||||
| } | |||||
| else | |||||
| { | |||||
| Radio.Rx( RX_TIMEOUT_VALUE ); | |||||
| } | |||||
| State = LOWPOWER; | |||||
| break; | |||||
| case TX_TIMEOUT: | |||||
| Radio.Rx( RX_TIMEOUT_VALUE ); | |||||
| State = LOWPOWER; | |||||
| break; | |||||
| case LOWPOWER: | |||||
| default: | |||||
| // Set low power | |||||
| break; | |||||
| } | |||||
| BoardLowPowerHandler( ); | |||||
| // Process Radio IRQ | |||||
| if( Radio.IrqProcess != NULL ) | |||||
| { | |||||
| Radio.IrqProcess( ); | |||||
| } | |||||
| } | |||||
| } | |||||
| void OnTxDone( void ) | |||||
| { | |||||
| Radio.Sleep( ); | |||||
| State = TX; | |||||
| } | |||||
| void OnRxDone( uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr ) | |||||
| { | |||||
| Radio.Sleep( ); | |||||
| BufferSize = size; | |||||
| memcpy( Buffer, payload, BufferSize ); | |||||
| RssiValue = rssi; | |||||
| SnrValue = snr; | |||||
| State = RX; | |||||
| } | |||||
| void OnTxTimeout( void ) | |||||
| { | |||||
| Radio.Sleep( ); | |||||
| State = TX_TIMEOUT; | |||||
| } | |||||
| void OnRxTimeout( void ) | |||||
| { | |||||
| Radio.Sleep( ); | |||||
| State = RX_TIMEOUT; | |||||
| } | |||||
| void OnRxError( void ) | |||||
| { | |||||
| Radio.Sleep( ); | |||||
| State = RX_ERROR; | |||||
| } | |||||
| @@ -1,373 +1,373 @@ | |||||
| /*! | |||||
| * \file main.c | |||||
| * | |||||
| * \brief Ping-Pong implementation | |||||
| * | |||||
| * \copyright Revised BSD License, see section \ref LICENSE. | |||||
| * | |||||
| * \code | |||||
| * ______ _ | |||||
| * / _____) _ | | | |||||
| * ( (____ _____ ____ _| |_ _____ ____| |__ | |||||
| * \____ \| ___ | (_ _) ___ |/ ___) _ \ | |||||
| * _____) ) ____| | | || |_| ____( (___| | | | | |||||
| * (______/|_____)_|_|_| \__)_____)\____)_| |_| | |||||
| * (C)2013-2017 Semtech | |||||
| * | |||||
| * \endcode | |||||
| * | |||||
| * \author Miguel Luis ( Semtech ) | |||||
| * | |||||
| * \author Gregory Cristian ( Semtech ) | |||||
| */ | |||||
| #include <string.h> | |||||
| #include "board.h" | |||||
| #include "gpio.h" | |||||
| #include "delay.h" | |||||
| #include "timer.h" | |||||
| #include "radio.h" | |||||
| #if defined( REGION_AS923 ) | |||||
| #define RF_FREQUENCY 923000000 // Hz | |||||
| #elif defined( REGION_AU915 ) | |||||
| #define RF_FREQUENCY 915000000 // Hz | |||||
| #elif defined( REGION_CN470 ) | |||||
| #define RF_FREQUENCY 470000000 // Hz | |||||
| #elif defined( REGION_CN779 ) | |||||
| #define RF_FREQUENCY 779000000 // Hz | |||||
| #elif defined( REGION_EU433 ) | |||||
| #define RF_FREQUENCY 433000000 // Hz | |||||
| #elif defined( REGION_EU868 ) | |||||
| #define RF_FREQUENCY 868000000 // Hz | |||||
| #elif defined( REGION_KR920 ) | |||||
| #define RF_FREQUENCY 920000000 // Hz | |||||
| #elif defined( REGION_IN865 ) | |||||
| #define RF_FREQUENCY 865000000 // Hz | |||||
| #elif defined( REGION_US915 ) | |||||
| #define RF_FREQUENCY 915000000 // Hz | |||||
| #elif defined( REGION_RU864 ) | |||||
| #define RF_FREQUENCY 864000000 // Hz | |||||
| #else | |||||
| #error "Please define a frequency band in the compiler options." | |||||
| #endif | |||||
| #define TX_OUTPUT_POWER 14 // dBm | |||||
| #if defined( USE_MODEM_LORA ) | |||||
| #define LORA_BANDWIDTH 0 // [0: 125 kHz, | |||||
| // 1: 250 kHz, | |||||
| // 2: 500 kHz, | |||||
| // 3: Reserved] | |||||
| #define LORA_SPREADING_FACTOR 7 // [SF7..SF12] | |||||
| #define LORA_CODINGRATE 1 // [1: 4/5, | |||||
| // 2: 4/6, | |||||
| // 3: 4/7, | |||||
| // 4: 4/8] | |||||
| #define LORA_PREAMBLE_LENGTH 8 // Same for Tx and Rx | |||||
| #define LORA_SYMBOL_TIMEOUT 5 // Symbols | |||||
| #define LORA_FIX_LENGTH_PAYLOAD_ON false | |||||
| #define LORA_IQ_INVERSION_ON false | |||||
| #elif defined( USE_MODEM_FSK ) | |||||
| #define FSK_FDEV 25000 // Hz | |||||
| #define FSK_DATARATE 50000 // bps | |||||
| #define FSK_BANDWIDTH 50000 // Hz | |||||
| #define FSK_AFC_BANDWIDTH 83333 // Hz | |||||
| #define FSK_PREAMBLE_LENGTH 5 // Same for Tx and Rx | |||||
| #define FSK_FIX_LENGTH_PAYLOAD_ON false | |||||
| #else | |||||
| #error "Please define a modem in the compiler options." | |||||
| #endif | |||||
| typedef enum | |||||
| { | |||||
| LOWPOWER, | |||||
| RX, | |||||
| RX_TIMEOUT, | |||||
| RX_ERROR, | |||||
| TX, | |||||
| TX_TIMEOUT, | |||||
| }States_t; | |||||
| #define RX_TIMEOUT_VALUE 1000 | |||||
| #define BUFFER_SIZE 64 // Define the payload size here | |||||
| const uint8_t PingMsg[] = "PING"; | |||||
| const uint8_t PongMsg[] = "PONG"; | |||||
| uint16_t BufferSize = BUFFER_SIZE; | |||||
| uint8_t Buffer[BUFFER_SIZE]; | |||||
| States_t State = LOWPOWER; | |||||
| int8_t RssiValue = 0; | |||||
| int8_t SnrValue = 0; | |||||
| /*! | |||||
| * Radio events function pointer | |||||
| */ | |||||
| static RadioEvents_t RadioEvents; | |||||
| /*! | |||||
| * LED GPIO pins objects | |||||
| */ | |||||
| extern Gpio_t Led1; | |||||
| extern Gpio_t Led2; | |||||
| /*! | |||||
| * \brief Function to be executed on Radio Tx Done event | |||||
| */ | |||||
| void OnTxDone( void ); | |||||
| /*! | |||||
| * \brief Function to be executed on Radio Rx Done event | |||||
| */ | |||||
| void OnRxDone( uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr ); | |||||
| /*! | |||||
| * \brief Function executed on Radio Tx Timeout event | |||||
| */ | |||||
| void OnTxTimeout( void ); | |||||
| /*! | |||||
| * \brief Function executed on Radio Rx Timeout event | |||||
| */ | |||||
| void OnRxTimeout( void ); | |||||
| /*! | |||||
| * \brief Function executed on Radio Rx Error event | |||||
| */ | |||||
| void OnRxError( void ); | |||||
| /** | |||||
| * Main application entry point. | |||||
| */ | |||||
| int main( void ) | |||||
| { | |||||
| bool isMaster = true; | |||||
| uint8_t i; | |||||
| // Target board initialization | |||||
| BoardInitMcu( ); | |||||
| BoardInitPeriph( ); | |||||
| // Radio initialization | |||||
| RadioEvents.TxDone = OnTxDone; | |||||
| RadioEvents.RxDone = OnRxDone; | |||||
| RadioEvents.TxTimeout = OnTxTimeout; | |||||
| RadioEvents.RxTimeout = OnRxTimeout; | |||||
| RadioEvents.RxError = OnRxError; | |||||
| Radio.Init( &RadioEvents ); | |||||
| Radio.SetChannel( RF_FREQUENCY ); | |||||
| #if defined( USE_MODEM_LORA ) | |||||
| Radio.SetTxConfig( MODEM_LORA, TX_OUTPUT_POWER, 0, LORA_BANDWIDTH, | |||||
| LORA_SPREADING_FACTOR, LORA_CODINGRATE, | |||||
| LORA_PREAMBLE_LENGTH, LORA_FIX_LENGTH_PAYLOAD_ON, | |||||
| true, 0, 0, LORA_IQ_INVERSION_ON, 3000 ); | |||||
| Radio.SetRxConfig( MODEM_LORA, LORA_BANDWIDTH, LORA_SPREADING_FACTOR, | |||||
| LORA_CODINGRATE, 0, LORA_PREAMBLE_LENGTH, | |||||
| LORA_SYMBOL_TIMEOUT, LORA_FIX_LENGTH_PAYLOAD_ON, | |||||
| 0, true, 0, 0, LORA_IQ_INVERSION_ON, true ); | |||||
| Radio.SetMaxPayloadLength( MODEM_LORA, BUFFER_SIZE ); | |||||
| #elif defined( USE_MODEM_FSK ) | |||||
| Radio.SetTxConfig( MODEM_FSK, TX_OUTPUT_POWER, FSK_FDEV, 0, | |||||
| FSK_DATARATE, 0, | |||||
| FSK_PREAMBLE_LENGTH, FSK_FIX_LENGTH_PAYLOAD_ON, | |||||
| true, 0, 0, 0, 3000 ); | |||||
| Radio.SetRxConfig( MODEM_FSK, FSK_BANDWIDTH, FSK_DATARATE, | |||||
| 0, FSK_AFC_BANDWIDTH, FSK_PREAMBLE_LENGTH, | |||||
| 0, FSK_FIX_LENGTH_PAYLOAD_ON, 0, true, | |||||
| 0, 0,false, true ); | |||||
| Radio.SetMaxPayloadLength( MODEM_FSK, BUFFER_SIZE ); | |||||
| #else | |||||
| #error "Please define a frequency band in the compiler options." | |||||
| #endif | |||||
| Radio.Rx( RX_TIMEOUT_VALUE ); | |||||
| while( 1 ) | |||||
| { | |||||
| switch( State ) | |||||
| { | |||||
| case RX: | |||||
| if( isMaster == true ) | |||||
| { | |||||
| if( BufferSize > 0 ) | |||||
| { | |||||
| if( strncmp( ( const char* )Buffer, ( const char* )PongMsg, 4 ) == 0 ) | |||||
| { | |||||
| // Indicates on a LED that the received frame is a PONG | |||||
| GpioToggle( &Led1 ); | |||||
| // Send the next PING frame | |||||
| Buffer[0] = 'P'; | |||||
| Buffer[1] = 'I'; | |||||
| Buffer[2] = 'N'; | |||||
| Buffer[3] = 'G'; | |||||
| // We fill the buffer with numbers for the payload | |||||
| for( i = 4; i < BufferSize; i++ ) | |||||
| { | |||||
| Buffer[i] = i - 4; | |||||
| } | |||||
| DelayMs( 1 ); | |||||
| Radio.Send( Buffer, BufferSize ); | |||||
| } | |||||
| else if( strncmp( ( const char* )Buffer, ( const char* )PingMsg, 4 ) == 0 ) | |||||
| { // A master already exists then become a slave | |||||
| isMaster = false; | |||||
| GpioToggle( &Led2 ); // Set LED off | |||||
| Radio.Rx( RX_TIMEOUT_VALUE ); | |||||
| } | |||||
| else // valid reception but neither a PING or a PONG message | |||||
| { // Set device as master ans start again | |||||
| isMaster = true; | |||||
| Radio.Rx( RX_TIMEOUT_VALUE ); | |||||
| } | |||||
| } | |||||
| } | |||||
| else | |||||
| { | |||||
| if( BufferSize > 0 ) | |||||
| { | |||||
| if( strncmp( ( const char* )Buffer, ( const char* )PingMsg, 4 ) == 0 ) | |||||
| { | |||||
| // Indicates on a LED that the received frame is a PING | |||||
| GpioToggle( &Led1 ); | |||||
| // Send the reply to the PONG string | |||||
| Buffer[0] = 'P'; | |||||
| Buffer[1] = 'O'; | |||||
| Buffer[2] = 'N'; | |||||
| Buffer[3] = 'G'; | |||||
| // We fill the buffer with numbers for the payload | |||||
| for( i = 4; i < BufferSize; i++ ) | |||||
| { | |||||
| Buffer[i] = i - 4; | |||||
| } | |||||
| DelayMs( 1 ); | |||||
| Radio.Send( Buffer, BufferSize ); | |||||
| } | |||||
| else // valid reception but not a PING as expected | |||||
| { // Set device as master and start again | |||||
| isMaster = true; | |||||
| Radio.Rx( RX_TIMEOUT_VALUE ); | |||||
| } | |||||
| } | |||||
| } | |||||
| State = LOWPOWER; | |||||
| break; | |||||
| case TX: | |||||
| // Indicates on a LED that we have sent a PING [Master] | |||||
| // Indicates on a LED that we have sent a PONG [Slave] | |||||
| GpioToggle( &Led2 ); | |||||
| Radio.Rx( RX_TIMEOUT_VALUE ); | |||||
| State = LOWPOWER; | |||||
| break; | |||||
| case RX_TIMEOUT: | |||||
| case RX_ERROR: | |||||
| if( isMaster == true ) | |||||
| { | |||||
| // Send the next PING frame | |||||
| Buffer[0] = 'P'; | |||||
| Buffer[1] = 'I'; | |||||
| Buffer[2] = 'N'; | |||||
| Buffer[3] = 'G'; | |||||
| for( i = 4; i < BufferSize; i++ ) | |||||
| { | |||||
| Buffer[i] = i - 4; | |||||
| } | |||||
| DelayMs( 1 ); | |||||
| Radio.Send( Buffer, BufferSize ); | |||||
| } | |||||
| else | |||||
| { | |||||
| Radio.Rx( RX_TIMEOUT_VALUE ); | |||||
| } | |||||
| State = LOWPOWER; | |||||
| break; | |||||
| case TX_TIMEOUT: | |||||
| Radio.Rx( RX_TIMEOUT_VALUE ); | |||||
| State = LOWPOWER; | |||||
| break; | |||||
| case LOWPOWER: | |||||
| default: | |||||
| // Set low power | |||||
| break; | |||||
| } | |||||
| BoardLowPowerHandler( ); | |||||
| // Process Radio IRQ | |||||
| if( Radio.IrqProcess != NULL ) | |||||
| { | |||||
| Radio.IrqProcess( ); | |||||
| } | |||||
| } | |||||
| } | |||||
| void OnTxDone( void ) | |||||
| { | |||||
| Radio.Sleep( ); | |||||
| State = TX; | |||||
| } | |||||
| void OnRxDone( uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr ) | |||||
| { | |||||
| Radio.Sleep( ); | |||||
| BufferSize = size; | |||||
| memcpy( Buffer, payload, BufferSize ); | |||||
| RssiValue = rssi; | |||||
| SnrValue = snr; | |||||
| State = RX; | |||||
| } | |||||
| void OnTxTimeout( void ) | |||||
| { | |||||
| Radio.Sleep( ); | |||||
| State = TX_TIMEOUT; | |||||
| } | |||||
| void OnRxTimeout( void ) | |||||
| { | |||||
| Radio.Sleep( ); | |||||
| State = RX_TIMEOUT; | |||||
| } | |||||
| void OnRxError( void ) | |||||
| { | |||||
| Radio.Sleep( ); | |||||
| State = RX_ERROR; | |||||
| } | |||||
| /*! | |||||
| * \file main.c | |||||
| * | |||||
| * \brief Ping-Pong implementation | |||||
| * | |||||
| * \copyright Revised BSD License, see section \ref LICENSE. | |||||
| * | |||||
| * \code | |||||
| * ______ _ | |||||
| * / _____) _ | | | |||||
| * ( (____ _____ ____ _| |_ _____ ____| |__ | |||||
| * \____ \| ___ | (_ _) ___ |/ ___) _ \ | |||||
| * _____) ) ____| | | || |_| ____( (___| | | | | |||||
| * (______/|_____)_|_|_| \__)_____)\____)_| |_| | |||||
| * (C)2013-2017 Semtech | |||||
| * | |||||
| * \endcode | |||||
| * | |||||
| * \author Miguel Luis ( Semtech ) | |||||
| * | |||||
| * \author Gregory Cristian ( Semtech ) | |||||
| */ | |||||
| #include <string.h> | |||||
| #include "board.h" | |||||
| #include "gpio.h" | |||||
| #include "delay.h" | |||||
| #include "timer.h" | |||||
| #include "radio.h" | |||||
| #if defined( REGION_AS923 ) | |||||
| #define RF_FREQUENCY 923000000 // Hz | |||||
| #elif defined( REGION_AU915 ) | |||||
| #define RF_FREQUENCY 915000000 // Hz | |||||
| #elif defined( REGION_CN470 ) | |||||
| #define RF_FREQUENCY 470000000 // Hz | |||||
| #elif defined( REGION_CN779 ) | |||||
| #define RF_FREQUENCY 779000000 // Hz | |||||
| #elif defined( REGION_EU433 ) | |||||
| #define RF_FREQUENCY 433000000 // Hz | |||||
| #elif defined( REGION_EU868 ) | |||||
| #define RF_FREQUENCY 868000000 // Hz | |||||
| #elif defined( REGION_KR920 ) | |||||
| #define RF_FREQUENCY 920000000 // Hz | |||||
| #elif defined( REGION_IN865 ) | |||||
| #define RF_FREQUENCY 865000000 // Hz | |||||
| #elif defined( REGION_US915 ) | |||||
| #define RF_FREQUENCY 915000000 // Hz | |||||
| #elif defined( REGION_RU864 ) | |||||
| #define RF_FREQUENCY 864000000 // Hz | |||||
| #else | |||||
| #error "Please define a frequency band in the compiler options." | |||||
| #endif | |||||
| #define TX_OUTPUT_POWER 14 // dBm | |||||
| #if defined( USE_MODEM_LORA ) | |||||
| #define LORA_BANDWIDTH 0 // [0: 125 kHz, | |||||
| // 1: 250 kHz, | |||||
| // 2: 500 kHz, | |||||
| // 3: Reserved] | |||||
| #define LORA_SPREADING_FACTOR 7 // [SF7..SF12] | |||||
| #define LORA_CODINGRATE 1 // [1: 4/5, | |||||
| // 2: 4/6, | |||||
| // 3: 4/7, | |||||
| // 4: 4/8] | |||||
| #define LORA_PREAMBLE_LENGTH 8 // Same for Tx and Rx | |||||
| #define LORA_SYMBOL_TIMEOUT 5 // Symbols | |||||
| #define LORA_FIX_LENGTH_PAYLOAD_ON false | |||||
| #define LORA_IQ_INVERSION_ON false | |||||
| #elif defined( USE_MODEM_FSK ) | |||||
| #define FSK_FDEV 25000 // Hz | |||||
| #define FSK_DATARATE 50000 // bps | |||||
| #define FSK_BANDWIDTH 50000 // Hz | |||||
| #define FSK_AFC_BANDWIDTH 83333 // Hz | |||||
| #define FSK_PREAMBLE_LENGTH 5 // Same for Tx and Rx | |||||
| #define FSK_FIX_LENGTH_PAYLOAD_ON false | |||||
| #else | |||||
| #error "Please define a modem in the compiler options." | |||||
| #endif | |||||
| typedef enum | |||||
| { | |||||
| LOWPOWER, | |||||
| RX, | |||||
| RX_TIMEOUT, | |||||
| RX_ERROR, | |||||
| TX, | |||||
| TX_TIMEOUT, | |||||
| }States_t; | |||||
| #define RX_TIMEOUT_VALUE 1000 | |||||
| #define BUFFER_SIZE 64 // Define the payload size here | |||||
| const uint8_t PingMsg[] = "PING"; | |||||
| const uint8_t PongMsg[] = "PONG"; | |||||
| uint16_t BufferSize = BUFFER_SIZE; | |||||
| uint8_t Buffer[BUFFER_SIZE]; | |||||
| States_t State = LOWPOWER; | |||||
| int8_t RssiValue = 0; | |||||
| int8_t SnrValue = 0; | |||||
| /*! | |||||
| * Radio events function pointer | |||||
| */ | |||||
| static RadioEvents_t RadioEvents; | |||||
| /*! | |||||
| * LED GPIO pins objects | |||||
| */ | |||||
| extern Gpio_t Led1; | |||||
| extern Gpio_t Led2; | |||||
| /*! | |||||
| * \brief Function to be executed on Radio Tx Done event | |||||
| */ | |||||
| void OnTxDone( void ); | |||||
| /*! | |||||
| * \brief Function to be executed on Radio Rx Done event | |||||
| */ | |||||
| void OnRxDone( uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr ); | |||||
| /*! | |||||
| * \brief Function executed on Radio Tx Timeout event | |||||
| */ | |||||
| void OnTxTimeout( void ); | |||||
| /*! | |||||
| * \brief Function executed on Radio Rx Timeout event | |||||
| */ | |||||
| void OnRxTimeout( void ); | |||||
| /*! | |||||
| * \brief Function executed on Radio Rx Error event | |||||
| */ | |||||
| void OnRxError( void ); | |||||
| /** | |||||
| * Main application entry point. | |||||
| */ | |||||
| int main( void ) | |||||
| { | |||||
| bool isMaster = true; | |||||
| uint8_t i; | |||||
| // Target board initialization | |||||
| BoardInitMcu( ); | |||||
| BoardInitPeriph( ); | |||||
| // Radio initialization | |||||
| RadioEvents.TxDone = OnTxDone; | |||||
| RadioEvents.RxDone = OnRxDone; | |||||
| RadioEvents.TxTimeout = OnTxTimeout; | |||||
| RadioEvents.RxTimeout = OnRxTimeout; | |||||
| RadioEvents.RxError = OnRxError; | |||||
| Radio.Init( &RadioEvents ); | |||||
| Radio.SetChannel( RF_FREQUENCY ); | |||||
| #if defined( USE_MODEM_LORA ) | |||||
| Radio.SetTxConfig( MODEM_LORA, TX_OUTPUT_POWER, 0, LORA_BANDWIDTH, | |||||
| LORA_SPREADING_FACTOR, LORA_CODINGRATE, | |||||
| LORA_PREAMBLE_LENGTH, LORA_FIX_LENGTH_PAYLOAD_ON, | |||||
| true, 0, 0, LORA_IQ_INVERSION_ON, 3000 ); | |||||
| Radio.SetRxConfig( MODEM_LORA, LORA_BANDWIDTH, LORA_SPREADING_FACTOR, | |||||
| LORA_CODINGRATE, 0, LORA_PREAMBLE_LENGTH, | |||||
| LORA_SYMBOL_TIMEOUT, LORA_FIX_LENGTH_PAYLOAD_ON, | |||||
| 0, true, 0, 0, LORA_IQ_INVERSION_ON, true ); | |||||
| Radio.SetMaxPayloadLength( MODEM_LORA, BUFFER_SIZE ); | |||||
| #elif defined( USE_MODEM_FSK ) | |||||
| Radio.SetTxConfig( MODEM_FSK, TX_OUTPUT_POWER, FSK_FDEV, 0, | |||||
| FSK_DATARATE, 0, | |||||
| FSK_PREAMBLE_LENGTH, FSK_FIX_LENGTH_PAYLOAD_ON, | |||||
| true, 0, 0, 0, 3000 ); | |||||
| Radio.SetRxConfig( MODEM_FSK, FSK_BANDWIDTH, FSK_DATARATE, | |||||
| 0, FSK_AFC_BANDWIDTH, FSK_PREAMBLE_LENGTH, | |||||
| 0, FSK_FIX_LENGTH_PAYLOAD_ON, 0, true, | |||||
| 0, 0,false, true ); | |||||
| Radio.SetMaxPayloadLength( MODEM_FSK, BUFFER_SIZE ); | |||||
| #else | |||||
| #error "Please define a frequency band in the compiler options." | |||||
| #endif | |||||
| Radio.Rx( RX_TIMEOUT_VALUE ); | |||||
| while( 1 ) | |||||
| { | |||||
| switch( State ) | |||||
| { | |||||
| case RX: | |||||
| if( isMaster == true ) | |||||
| { | |||||
| if( BufferSize > 0 ) | |||||
| { | |||||
| if( strncmp( ( const char* )Buffer, ( const char* )PongMsg, 4 ) == 0 ) | |||||
| { | |||||
| // Indicates on a LED that the received frame is a PONG | |||||
| GpioToggle( &Led1 ); | |||||
| // Send the next PING frame | |||||
| Buffer[0] = 'P'; | |||||
| Buffer[1] = 'I'; | |||||
| Buffer[2] = 'N'; | |||||
| Buffer[3] = 'G'; | |||||
| // We fill the buffer with numbers for the payload | |||||
| for( i = 4; i < BufferSize; i++ ) | |||||
| { | |||||
| Buffer[i] = i - 4; | |||||
| } | |||||
| DelayMs( 1 ); | |||||
| Radio.Send( Buffer, BufferSize ); | |||||
| } | |||||
| else if( strncmp( ( const char* )Buffer, ( const char* )PingMsg, 4 ) == 0 ) | |||||
| { // A master already exists then become a slave | |||||
| isMaster = false; | |||||
| GpioToggle( &Led2 ); // Set LED off | |||||
| Radio.Rx( RX_TIMEOUT_VALUE ); | |||||
| } | |||||
| else // valid reception but neither a PING or a PONG message | |||||
| { // Set device as master ans start again | |||||
| isMaster = true; | |||||
| Radio.Rx( RX_TIMEOUT_VALUE ); | |||||
| } | |||||
| } | |||||
| } | |||||
| else | |||||
| { | |||||
| if( BufferSize > 0 ) | |||||
| { | |||||
| if( strncmp( ( const char* )Buffer, ( const char* )PingMsg, 4 ) == 0 ) | |||||
| { | |||||
| // Indicates on a LED that the received frame is a PING | |||||
| GpioToggle( &Led1 ); | |||||
| // Send the reply to the PONG string | |||||
| Buffer[0] = 'P'; | |||||
| Buffer[1] = 'O'; | |||||
| Buffer[2] = 'N'; | |||||
| Buffer[3] = 'G'; | |||||
| // We fill the buffer with numbers for the payload | |||||
| for( i = 4; i < BufferSize; i++ ) | |||||
| { | |||||
| Buffer[i] = i - 4; | |||||
| } | |||||
| DelayMs( 1 ); | |||||
| Radio.Send( Buffer, BufferSize ); | |||||
| } | |||||
| else // valid reception but not a PING as expected | |||||
| { // Set device as master and start again | |||||
| isMaster = true; | |||||
| Radio.Rx( RX_TIMEOUT_VALUE ); | |||||
| } | |||||
| } | |||||
| } | |||||
| State = LOWPOWER; | |||||
| break; | |||||
| case TX: | |||||
| // Indicates on a LED that we have sent a PING [Master] | |||||
| // Indicates on a LED that we have sent a PONG [Slave] | |||||
| GpioToggle( &Led2 ); | |||||
| Radio.Rx( RX_TIMEOUT_VALUE ); | |||||
| State = LOWPOWER; | |||||
| break; | |||||
| case RX_TIMEOUT: | |||||
| case RX_ERROR: | |||||
| if( isMaster == true ) | |||||
| { | |||||
| // Send the next PING frame | |||||
| Buffer[0] = 'P'; | |||||
| Buffer[1] = 'I'; | |||||
| Buffer[2] = 'N'; | |||||
| Buffer[3] = 'G'; | |||||
| for( i = 4; i < BufferSize; i++ ) | |||||
| { | |||||
| Buffer[i] = i - 4; | |||||
| } | |||||
| DelayMs( 1 ); | |||||
| Radio.Send( Buffer, BufferSize ); | |||||
| } | |||||
| else | |||||
| { | |||||
| Radio.Rx( RX_TIMEOUT_VALUE ); | |||||
| } | |||||
| State = LOWPOWER; | |||||
| break; | |||||
| case TX_TIMEOUT: | |||||
| Radio.Rx( RX_TIMEOUT_VALUE ); | |||||
| State = LOWPOWER; | |||||
| break; | |||||
| case LOWPOWER: | |||||
| default: | |||||
| // Set low power | |||||
| break; | |||||
| } | |||||
| BoardLowPowerHandler( ); | |||||
| // Process Radio IRQ | |||||
| if( Radio.IrqProcess != NULL ) | |||||
| { | |||||
| Radio.IrqProcess( ); | |||||
| } | |||||
| } | |||||
| } | |||||
| void OnTxDone( void ) | |||||
| { | |||||
| Radio.Sleep( ); | |||||
| State = TX; | |||||
| } | |||||
| void OnRxDone( uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr ) | |||||
| { | |||||
| Radio.Sleep( ); | |||||
| BufferSize = size; | |||||
| memcpy( Buffer, payload, BufferSize ); | |||||
| RssiValue = rssi; | |||||
| SnrValue = snr; | |||||
| State = RX; | |||||
| } | |||||
| void OnTxTimeout( void ) | |||||
| { | |||||
| Radio.Sleep( ); | |||||
| State = TX_TIMEOUT; | |||||
| } | |||||
| void OnRxTimeout( void ) | |||||
| { | |||||
| Radio.Sleep( ); | |||||
| State = RX_TIMEOUT; | |||||
| } | |||||
| void OnRxError( void ) | |||||
| { | |||||
| Radio.Sleep( ); | |||||
| State = RX_ERROR; | |||||
| } | |||||
| @@ -1,371 +1,371 @@ | |||||
| /*! | |||||
| * \file main.c | |||||
| * | |||||
| * \brief Ping-Pong implementation | |||||
| * | |||||
| * \copyright Revised BSD License, see section \ref LICENSE. | |||||
| * | |||||
| * \code | |||||
| * ______ _ | |||||
| * / _____) _ | | | |||||
| * ( (____ _____ ____ _| |_ _____ ____| |__ | |||||
| * \____ \| ___ | (_ _) ___ |/ ___) _ \ | |||||
| * _____) ) ____| | | || |_| ____( (___| | | | | |||||
| * (______/|_____)_|_|_| \__)_____)\____)_| |_| | |||||
| * (C)2013-2017 Semtech | |||||
| * | |||||
| * \endcode | |||||
| * | |||||
| * \author Miguel Luis ( Semtech ) | |||||
| * | |||||
| * \author Gregory Cristian ( Semtech ) | |||||
| * | |||||
| * \author Marten Lootsma(TWTG) on behalf of Microchip/Atmel (c)2017 | |||||
| */ | |||||
| #include <string.h> | |||||
| #include "board.h" | |||||
| #include "gpio.h" | |||||
| #include "delay.h" | |||||
| #include "timer.h" | |||||
| #include "radio.h" | |||||
| #if defined( REGION_AS923 ) | |||||
| #define RF_FREQUENCY 923000000 // Hz | |||||
| #elif defined( REGION_AU915 ) | |||||
| #define RF_FREQUENCY 915000000 // Hz | |||||
| #elif defined( REGION_CN470 ) | |||||
| #define RF_FREQUENCY 470000000 // Hz | |||||
| #elif defined( REGION_CN779 ) | |||||
| #define RF_FREQUENCY 779000000 // Hz | |||||
| #elif defined( REGION_EU433 ) | |||||
| #define RF_FREQUENCY 433000000 // Hz | |||||
| #elif defined( REGION_EU868 ) | |||||
| #define RF_FREQUENCY 868000000 // Hz | |||||
| #elif defined( REGION_KR920 ) | |||||
| #define RF_FREQUENCY 920000000 // Hz | |||||
| #elif defined( REGION_IN865 ) | |||||
| #define RF_FREQUENCY 865000000 // Hz | |||||
| #elif defined( REGION_US915 ) | |||||
| #define RF_FREQUENCY 915000000 // Hz | |||||
| #elif defined( REGION_RU864 ) | |||||
| #define RF_FREQUENCY 864000000 // Hz | |||||
| #else | |||||
| #error "Please define a frequency band in the compiler options." | |||||
| #endif | |||||
| #define TX_OUTPUT_POWER 14 // dBm | |||||
| #if defined( USE_MODEM_LORA ) | |||||
| #define LORA_BANDWIDTH 0 // [0: 125 kHz, | |||||
| // 1: 250 kHz, | |||||
| // 2: 500 kHz, | |||||
| // 3: Reserved] | |||||
| #define LORA_SPREADING_FACTOR 7 // [SF7..SF12] | |||||
| #define LORA_CODINGRATE 1 // [1: 4/5, | |||||
| // 2: 4/6, | |||||
| // 3: 4/7, | |||||
| // 4: 4/8] | |||||
| #define LORA_PREAMBLE_LENGTH 8 // Same for Tx and Rx | |||||
| #define LORA_SYMBOL_TIMEOUT 5 // Symbols | |||||
| #define LORA_FIX_LENGTH_PAYLOAD_ON false | |||||
| #define LORA_IQ_INVERSION_ON false | |||||
| #elif defined( USE_MODEM_FSK ) | |||||
| #define FSK_FDEV 25000 // Hz | |||||
| #define FSK_DATARATE 50000 // bps | |||||
| #define FSK_BANDWIDTH 50000 // Hz | |||||
| #define FSK_AFC_BANDWIDTH 83333 // Hz | |||||
| #define FSK_PREAMBLE_LENGTH 5 // Same for Tx and Rx | |||||
| #define FSK_FIX_LENGTH_PAYLOAD_ON false | |||||
| #else | |||||
| #error "Please define a modem in the compiler options." | |||||
| #endif | |||||
| typedef enum | |||||
| { | |||||
| LOWPOWER, | |||||
| RX, | |||||
| RX_TIMEOUT, | |||||
| RX_ERROR, | |||||
| TX, | |||||
| TX_TIMEOUT, | |||||
| }States_t; | |||||
| #define RX_TIMEOUT_VALUE 1000 | |||||
| #define BUFFER_SIZE 64 // Define the payload size here | |||||
| const uint8_t PingMsg[] = "PING"; | |||||
| const uint8_t PongMsg[] = "PONG"; | |||||
| uint16_t BufferSize = BUFFER_SIZE; | |||||
| uint8_t Buffer[BUFFER_SIZE]; | |||||
| States_t State = LOWPOWER; | |||||
| int8_t RssiValue = 0; | |||||
| int8_t SnrValue = 0; | |||||
| /*! | |||||
| * Radio events function pointer | |||||
| */ | |||||
| static RadioEvents_t RadioEvents; | |||||
| /*! | |||||
| * LED GPIO pins objects | |||||
| */ | |||||
| extern Gpio_t Led1; | |||||
| /*! | |||||
| * \brief Function to be executed on Radio Tx Done event | |||||
| */ | |||||
| void OnTxDone( void ); | |||||
| /*! | |||||
| * \brief Function to be executed on Radio Rx Done event | |||||
| */ | |||||
| void OnRxDone( uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr ); | |||||
| /*! | |||||
| * \brief Function executed on Radio Tx Timeout event | |||||
| */ | |||||
| void OnTxTimeout( void ); | |||||
| /*! | |||||
| * \brief Function executed on Radio Rx Timeout event | |||||
| */ | |||||
| void OnRxTimeout( void ); | |||||
| /*! | |||||
| * \brief Function executed on Radio Rx Error event | |||||
| */ | |||||
| void OnRxError( void ); | |||||
| /** | |||||
| * Main application entry point. | |||||
| */ | |||||
| int main( void ) | |||||
| { | |||||
| bool isMaster = true; | |||||
| uint8_t i; | |||||
| // Target board initialization | |||||
| BoardInitMcu( ); | |||||
| BoardInitPeriph( ); | |||||
| // Radio initialization | |||||
| RadioEvents.TxDone = OnTxDone; | |||||
| RadioEvents.RxDone = OnRxDone; | |||||
| RadioEvents.TxTimeout = OnTxTimeout; | |||||
| RadioEvents.RxTimeout = OnRxTimeout; | |||||
| RadioEvents.RxError = OnRxError; | |||||
| Radio.Init( &RadioEvents ); | |||||
| Radio.SetChannel( RF_FREQUENCY ); | |||||
| #if defined( USE_MODEM_LORA ) | |||||
| Radio.SetTxConfig( MODEM_LORA, TX_OUTPUT_POWER, 0, LORA_BANDWIDTH, | |||||
| LORA_SPREADING_FACTOR, LORA_CODINGRATE, | |||||
| LORA_PREAMBLE_LENGTH, LORA_FIX_LENGTH_PAYLOAD_ON, | |||||
| true, 0, 0, LORA_IQ_INVERSION_ON, 3000 ); | |||||
| Radio.SetRxConfig( MODEM_LORA, LORA_BANDWIDTH, LORA_SPREADING_FACTOR, | |||||
| LORA_CODINGRATE, 0, LORA_PREAMBLE_LENGTH, | |||||
| LORA_SYMBOL_TIMEOUT, LORA_FIX_LENGTH_PAYLOAD_ON, | |||||
| 0, true, 0, 0, LORA_IQ_INVERSION_ON, true ); | |||||
| Radio.SetMaxPayloadLength( MODEM_LORA, BUFFER_SIZE ); | |||||
| #elif defined( USE_MODEM_FSK ) | |||||
| Radio.SetTxConfig( MODEM_FSK, TX_OUTPUT_POWER, FSK_FDEV, 0, | |||||
| FSK_DATARATE, 0, | |||||
| FSK_PREAMBLE_LENGTH, FSK_FIX_LENGTH_PAYLOAD_ON, | |||||
| true, 0, 0, 0, 3000 ); | |||||
| Radio.SetRxConfig( MODEM_FSK, FSK_BANDWIDTH, FSK_DATARATE, | |||||
| 0, FSK_AFC_BANDWIDTH, FSK_PREAMBLE_LENGTH, | |||||
| 0, FSK_FIX_LENGTH_PAYLOAD_ON, 0, true, | |||||
| 0, 0,false, true ); | |||||
| Radio.SetMaxPayloadLength( MODEM_FSK, BUFFER_SIZE ); | |||||
| #else | |||||
| #error "Please define a frequency band in the compiler options." | |||||
| #endif | |||||
| Radio.Rx( RX_TIMEOUT_VALUE ); | |||||
| while( 1 ) | |||||
| { | |||||
| // Tick the RTC to execute callback in context of the main loop (in stead of the IRQ) | |||||
| TimerProcess( ); | |||||
| switch( State ) | |||||
| { | |||||
| case RX: | |||||
| if( isMaster == true ) | |||||
| { | |||||
| if( BufferSize > 0 ) | |||||
| { | |||||
| if( strncmp( ( const char* )Buffer, ( const char* )PongMsg, 4 ) == 0 ) | |||||
| { | |||||
| // Indicates on a LED that the received frame is a PONG | |||||
| GpioWrite( &Led1, GpioRead( &Led1 ) ^ 1 ); | |||||
| // Send the next PING frame | |||||
| Buffer[0] = 'P'; | |||||
| Buffer[1] = 'I'; | |||||
| Buffer[2] = 'N'; | |||||
| Buffer[3] = 'G'; | |||||
| // We fill the buffer with numbers for the payload | |||||
| for( i = 4; i < BufferSize; i++ ) | |||||
| { | |||||
| Buffer[i] = i - 4; | |||||
| } | |||||
| DelayMs( 1 ); | |||||
| Radio.Send( Buffer, BufferSize ); | |||||
| } | |||||
| else if( strncmp( ( const char* )Buffer, ( const char* )PingMsg, 4 ) == 0 ) | |||||
| { // A master already exists then become a slave | |||||
| isMaster = false; | |||||
| Radio.Rx( RX_TIMEOUT_VALUE ); | |||||
| } | |||||
| else // valid reception but neither a PING or a PONG message | |||||
| { // Set device as master ans start again | |||||
| isMaster = true; | |||||
| Radio.Rx( RX_TIMEOUT_VALUE ); | |||||
| } | |||||
| } | |||||
| } | |||||
| else | |||||
| { | |||||
| if( BufferSize > 0 ) | |||||
| { | |||||
| if( strncmp( ( const char* )Buffer, ( const char* )PingMsg, 4 ) == 0 ) | |||||
| { | |||||
| // Indicates on a LED that the received frame is a PING | |||||
| GpioWrite( &Led1, GpioRead( &Led1 ) ^ 1 ); | |||||
| // Send the reply to the PONG string | |||||
| Buffer[0] = 'P'; | |||||
| Buffer[1] = 'O'; | |||||
| Buffer[2] = 'N'; | |||||
| Buffer[3] = 'G'; | |||||
| // We fill the buffer with numbers for the payload | |||||
| for( i = 4; i < BufferSize; i++ ) | |||||
| { | |||||
| Buffer[i] = i - 4; | |||||
| } | |||||
| DelayMs( 1 ); | |||||
| Radio.Send( Buffer, BufferSize ); | |||||
| } | |||||
| else // valid reception but not a PING as expected | |||||
| { // Set device as master and start again | |||||
| isMaster = true; | |||||
| Radio.Rx( RX_TIMEOUT_VALUE ); | |||||
| } | |||||
| } | |||||
| } | |||||
| State = LOWPOWER; | |||||
| break; | |||||
| case TX: | |||||
| // Indicates on a LED that we have sent a PING [Master] | |||||
| // Indicates on a LED that we have sent a PONG [Slave] | |||||
| Radio.Rx( RX_TIMEOUT_VALUE ); | |||||
| State = LOWPOWER; | |||||
| break; | |||||
| case RX_TIMEOUT: | |||||
| case RX_ERROR: | |||||
| if( isMaster == true ) | |||||
| { | |||||
| // Send the next PING frame | |||||
| Buffer[0] = 'P'; | |||||
| Buffer[1] = 'I'; | |||||
| Buffer[2] = 'N'; | |||||
| Buffer[3] = 'G'; | |||||
| for( i = 4; i < BufferSize; i++ ) | |||||
| { | |||||
| Buffer[i] = i - 4; | |||||
| } | |||||
| DelayMs( 1 ); | |||||
| Radio.Send( Buffer, BufferSize ); | |||||
| } | |||||
| else | |||||
| { | |||||
| Radio.Rx( RX_TIMEOUT_VALUE ); | |||||
| } | |||||
| State = LOWPOWER; | |||||
| break; | |||||
| case TX_TIMEOUT: | |||||
| Radio.Rx( RX_TIMEOUT_VALUE ); | |||||
| State = LOWPOWER; | |||||
| break; | |||||
| case LOWPOWER: | |||||
| default: | |||||
| // Set low power | |||||
| break; | |||||
| } | |||||
| BoardLowPowerHandler( ); | |||||
| } | |||||
| } | |||||
| void OnTxDone( void ) | |||||
| { | |||||
| Radio.Sleep( ); | |||||
| State = TX; | |||||
| } | |||||
| void OnRxDone( uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr ) | |||||
| { | |||||
| Radio.Sleep( ); | |||||
| BufferSize = size; | |||||
| memcpy( Buffer, payload, BufferSize ); | |||||
| RssiValue = rssi; | |||||
| SnrValue = snr; | |||||
| State = RX; | |||||
| } | |||||
| void OnTxTimeout( void ) | |||||
| { | |||||
| Radio.Sleep( ); | |||||
| State = TX_TIMEOUT; | |||||
| } | |||||
| void OnRxTimeout( void ) | |||||
| { | |||||
| Radio.Sleep( ); | |||||
| State = RX_TIMEOUT; | |||||
| } | |||||
| void OnRxError( void ) | |||||
| { | |||||
| Radio.Sleep( ); | |||||
| State = RX_ERROR; | |||||
| } | |||||
| /*! | |||||
| * \file main.c | |||||
| * | |||||
| * \brief Ping-Pong implementation | |||||
| * | |||||
| * \copyright Revised BSD License, see section \ref LICENSE. | |||||
| * | |||||
| * \code | |||||
| * ______ _ | |||||
| * / _____) _ | | | |||||
| * ( (____ _____ ____ _| |_ _____ ____| |__ | |||||
| * \____ \| ___ | (_ _) ___ |/ ___) _ \ | |||||
| * _____) ) ____| | | || |_| ____( (___| | | | | |||||
| * (______/|_____)_|_|_| \__)_____)\____)_| |_| | |||||
| * (C)2013-2017 Semtech | |||||
| * | |||||
| * \endcode | |||||
| * | |||||
| * \author Miguel Luis ( Semtech ) | |||||
| * | |||||
| * \author Gregory Cristian ( Semtech ) | |||||
| * | |||||
| * \author Marten Lootsma(TWTG) on behalf of Microchip/Atmel (c)2017 | |||||
| */ | |||||
| #include <string.h> | |||||
| #include "board.h" | |||||
| #include "gpio.h" | |||||
| #include "delay.h" | |||||
| #include "timer.h" | |||||
| #include "radio.h" | |||||
| #if defined( REGION_AS923 ) | |||||
| #define RF_FREQUENCY 923000000 // Hz | |||||
| #elif defined( REGION_AU915 ) | |||||
| #define RF_FREQUENCY 915000000 // Hz | |||||
| #elif defined( REGION_CN470 ) | |||||
| #define RF_FREQUENCY 470000000 // Hz | |||||
| #elif defined( REGION_CN779 ) | |||||
| #define RF_FREQUENCY 779000000 // Hz | |||||
| #elif defined( REGION_EU433 ) | |||||
| #define RF_FREQUENCY 433000000 // Hz | |||||
| #elif defined( REGION_EU868 ) | |||||
| #define RF_FREQUENCY 868000000 // Hz | |||||
| #elif defined( REGION_KR920 ) | |||||
| #define RF_FREQUENCY 920000000 // Hz | |||||
| #elif defined( REGION_IN865 ) | |||||
| #define RF_FREQUENCY 865000000 // Hz | |||||
| #elif defined( REGION_US915 ) | |||||
| #define RF_FREQUENCY 915000000 // Hz | |||||
| #elif defined( REGION_RU864 ) | |||||
| #define RF_FREQUENCY 864000000 // Hz | |||||
| #else | |||||
| #error "Please define a frequency band in the compiler options." | |||||
| #endif | |||||
| #define TX_OUTPUT_POWER 14 // dBm | |||||
| #if defined( USE_MODEM_LORA ) | |||||
| #define LORA_BANDWIDTH 0 // [0: 125 kHz, | |||||
| // 1: 250 kHz, | |||||
| // 2: 500 kHz, | |||||
| // 3: Reserved] | |||||
| #define LORA_SPREADING_FACTOR 7 // [SF7..SF12] | |||||
| #define LORA_CODINGRATE 1 // [1: 4/5, | |||||
| // 2: 4/6, | |||||
| // 3: 4/7, | |||||
| // 4: 4/8] | |||||
| #define LORA_PREAMBLE_LENGTH 8 // Same for Tx and Rx | |||||
| #define LORA_SYMBOL_TIMEOUT 5 // Symbols | |||||
| #define LORA_FIX_LENGTH_PAYLOAD_ON false | |||||
| #define LORA_IQ_INVERSION_ON false | |||||
| #elif defined( USE_MODEM_FSK ) | |||||
| #define FSK_FDEV 25000 // Hz | |||||
| #define FSK_DATARATE 50000 // bps | |||||
| #define FSK_BANDWIDTH 50000 // Hz | |||||
| #define FSK_AFC_BANDWIDTH 83333 // Hz | |||||
| #define FSK_PREAMBLE_LENGTH 5 // Same for Tx and Rx | |||||
| #define FSK_FIX_LENGTH_PAYLOAD_ON false | |||||
| #else | |||||
| #error "Please define a modem in the compiler options." | |||||
| #endif | |||||
| typedef enum | |||||
| { | |||||
| LOWPOWER, | |||||
| RX, | |||||
| RX_TIMEOUT, | |||||
| RX_ERROR, | |||||
| TX, | |||||
| TX_TIMEOUT, | |||||
| }States_t; | |||||
| #define RX_TIMEOUT_VALUE 1000 | |||||
| #define BUFFER_SIZE 64 // Define the payload size here | |||||
| const uint8_t PingMsg[] = "PING"; | |||||
| const uint8_t PongMsg[] = "PONG"; | |||||
| uint16_t BufferSize = BUFFER_SIZE; | |||||
| uint8_t Buffer[BUFFER_SIZE]; | |||||
| States_t State = LOWPOWER; | |||||
| int8_t RssiValue = 0; | |||||
| int8_t SnrValue = 0; | |||||
| /*! | |||||
| * Radio events function pointer | |||||
| */ | |||||
| static RadioEvents_t RadioEvents; | |||||
| /*! | |||||
| * LED GPIO pins objects | |||||
| */ | |||||
| extern Gpio_t Led1; | |||||
| /*! | |||||
| * \brief Function to be executed on Radio Tx Done event | |||||
| */ | |||||
| void OnTxDone( void ); | |||||
| /*! | |||||
| * \brief Function to be executed on Radio Rx Done event | |||||
| */ | |||||
| void OnRxDone( uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr ); | |||||
| /*! | |||||
| * \brief Function executed on Radio Tx Timeout event | |||||
| */ | |||||
| void OnTxTimeout( void ); | |||||
| /*! | |||||
| * \brief Function executed on Radio Rx Timeout event | |||||
| */ | |||||
| void OnRxTimeout( void ); | |||||
| /*! | |||||
| * \brief Function executed on Radio Rx Error event | |||||
| */ | |||||
| void OnRxError( void ); | |||||
| /** | |||||
| * Main application entry point. | |||||
| */ | |||||
| int main( void ) | |||||
| { | |||||
| bool isMaster = true; | |||||
| uint8_t i; | |||||
| // Target board initialization | |||||
| BoardInitMcu( ); | |||||
| BoardInitPeriph( ); | |||||
| // Radio initialization | |||||
| RadioEvents.TxDone = OnTxDone; | |||||
| RadioEvents.RxDone = OnRxDone; | |||||
| RadioEvents.TxTimeout = OnTxTimeout; | |||||
| RadioEvents.RxTimeout = OnRxTimeout; | |||||
| RadioEvents.RxError = OnRxError; | |||||
| Radio.Init( &RadioEvents ); | |||||
| Radio.SetChannel( RF_FREQUENCY ); | |||||
| #if defined( USE_MODEM_LORA ) | |||||
| Radio.SetTxConfig( MODEM_LORA, TX_OUTPUT_POWER, 0, LORA_BANDWIDTH, | |||||
| LORA_SPREADING_FACTOR, LORA_CODINGRATE, | |||||
| LORA_PREAMBLE_LENGTH, LORA_FIX_LENGTH_PAYLOAD_ON, | |||||
| true, 0, 0, LORA_IQ_INVERSION_ON, 3000 ); | |||||
| Radio.SetRxConfig( MODEM_LORA, LORA_BANDWIDTH, LORA_SPREADING_FACTOR, | |||||
| LORA_CODINGRATE, 0, LORA_PREAMBLE_LENGTH, | |||||
| LORA_SYMBOL_TIMEOUT, LORA_FIX_LENGTH_PAYLOAD_ON, | |||||
| 0, true, 0, 0, LORA_IQ_INVERSION_ON, true ); | |||||
| Radio.SetMaxPayloadLength( MODEM_LORA, BUFFER_SIZE ); | |||||
| #elif defined( USE_MODEM_FSK ) | |||||
| Radio.SetTxConfig( MODEM_FSK, TX_OUTPUT_POWER, FSK_FDEV, 0, | |||||
| FSK_DATARATE, 0, | |||||
| FSK_PREAMBLE_LENGTH, FSK_FIX_LENGTH_PAYLOAD_ON, | |||||
| true, 0, 0, 0, 3000 ); | |||||
| Radio.SetRxConfig( MODEM_FSK, FSK_BANDWIDTH, FSK_DATARATE, | |||||
| 0, FSK_AFC_BANDWIDTH, FSK_PREAMBLE_LENGTH, | |||||
| 0, FSK_FIX_LENGTH_PAYLOAD_ON, 0, true, | |||||
| 0, 0,false, true ); | |||||
| Radio.SetMaxPayloadLength( MODEM_FSK, BUFFER_SIZE ); | |||||
| #else | |||||
| #error "Please define a frequency band in the compiler options." | |||||
| #endif | |||||
| Radio.Rx( RX_TIMEOUT_VALUE ); | |||||
| while( 1 ) | |||||
| { | |||||
| // Tick the RTC to execute callback in context of the main loop (in stead of the IRQ) | |||||
| TimerProcess( ); | |||||
| switch( State ) | |||||
| { | |||||
| case RX: | |||||
| if( isMaster == true ) | |||||
| { | |||||
| if( BufferSize > 0 ) | |||||
| { | |||||
| if( strncmp( ( const char* )Buffer, ( const char* )PongMsg, 4 ) == 0 ) | |||||
| { | |||||
| // Indicates on a LED that the received frame is a PONG | |||||
| GpioWrite( &Led1, GpioRead( &Led1 ) ^ 1 ); | |||||
| // Send the next PING frame | |||||
| Buffer[0] = 'P'; | |||||
| Buffer[1] = 'I'; | |||||
| Buffer[2] = 'N'; | |||||
| Buffer[3] = 'G'; | |||||
| // We fill the buffer with numbers for the payload | |||||
| for( i = 4; i < BufferSize; i++ ) | |||||
| { | |||||
| Buffer[i] = i - 4; | |||||
| } | |||||
| DelayMs( 1 ); | |||||
| Radio.Send( Buffer, BufferSize ); | |||||
| } | |||||
| else if( strncmp( ( const char* )Buffer, ( const char* )PingMsg, 4 ) == 0 ) | |||||
| { // A master already exists then become a slave | |||||
| isMaster = false; | |||||
| Radio.Rx( RX_TIMEOUT_VALUE ); | |||||
| } | |||||
| else // valid reception but neither a PING or a PONG message | |||||
| { // Set device as master ans start again | |||||
| isMaster = true; | |||||
| Radio.Rx( RX_TIMEOUT_VALUE ); | |||||
| } | |||||
| } | |||||
| } | |||||
| else | |||||
| { | |||||
| if( BufferSize > 0 ) | |||||
| { | |||||
| if( strncmp( ( const char* )Buffer, ( const char* )PingMsg, 4 ) == 0 ) | |||||
| { | |||||
| // Indicates on a LED that the received frame is a PING | |||||
| GpioWrite( &Led1, GpioRead( &Led1 ) ^ 1 ); | |||||
| // Send the reply to the PONG string | |||||
| Buffer[0] = 'P'; | |||||
| Buffer[1] = 'O'; | |||||
| Buffer[2] = 'N'; | |||||
| Buffer[3] = 'G'; | |||||
| // We fill the buffer with numbers for the payload | |||||
| for( i = 4; i < BufferSize; i++ ) | |||||
| { | |||||
| Buffer[i] = i - 4; | |||||
| } | |||||
| DelayMs( 1 ); | |||||
| Radio.Send( Buffer, BufferSize ); | |||||
| } | |||||
| else // valid reception but not a PING as expected | |||||
| { // Set device as master and start again | |||||
| isMaster = true; | |||||
| Radio.Rx( RX_TIMEOUT_VALUE ); | |||||
| } | |||||
| } | |||||
| } | |||||
| State = LOWPOWER; | |||||
| break; | |||||
| case TX: | |||||
| // Indicates on a LED that we have sent a PING [Master] | |||||
| // Indicates on a LED that we have sent a PONG [Slave] | |||||
| Radio.Rx( RX_TIMEOUT_VALUE ); | |||||
| State = LOWPOWER; | |||||
| break; | |||||
| case RX_TIMEOUT: | |||||
| case RX_ERROR: | |||||
| if( isMaster == true ) | |||||
| { | |||||
| // Send the next PING frame | |||||
| Buffer[0] = 'P'; | |||||
| Buffer[1] = 'I'; | |||||
| Buffer[2] = 'N'; | |||||
| Buffer[3] = 'G'; | |||||
| for( i = 4; i < BufferSize; i++ ) | |||||
| { | |||||
| Buffer[i] = i - 4; | |||||
| } | |||||
| DelayMs( 1 ); | |||||
| Radio.Send( Buffer, BufferSize ); | |||||
| } | |||||
| else | |||||
| { | |||||
| Radio.Rx( RX_TIMEOUT_VALUE ); | |||||
| } | |||||
| State = LOWPOWER; | |||||
| break; | |||||
| case TX_TIMEOUT: | |||||
| Radio.Rx( RX_TIMEOUT_VALUE ); | |||||
| State = LOWPOWER; | |||||
| break; | |||||
| case LOWPOWER: | |||||
| default: | |||||
| // Set low power | |||||
| break; | |||||
| } | |||||
| BoardLowPowerHandler( ); | |||||
| } | |||||
| } | |||||
| void OnTxDone( void ) | |||||
| { | |||||
| Radio.Sleep( ); | |||||
| State = TX; | |||||
| } | |||||
| void OnRxDone( uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr ) | |||||
| { | |||||
| Radio.Sleep( ); | |||||
| BufferSize = size; | |||||
| memcpy( Buffer, payload, BufferSize ); | |||||
| RssiValue = rssi; | |||||
| SnrValue = snr; | |||||
| State = RX; | |||||
| } | |||||
| void OnTxTimeout( void ) | |||||
| { | |||||
| Radio.Sleep( ); | |||||
| State = TX_TIMEOUT; | |||||
| } | |||||
| void OnRxTimeout( void ) | |||||
| { | |||||
| Radio.Sleep( ); | |||||
| State = RX_TIMEOUT; | |||||
| } | |||||
| void OnRxError( void ) | |||||
| { | |||||
| Radio.Sleep( ); | |||||
| State = RX_ERROR; | |||||
| } | |||||
| @@ -1,361 +1,361 @@ | |||||
| /*! | |||||
| * \file main.c | |||||
| * | |||||
| * \brief Ping-Pong implementation | |||||
| * | |||||
| * \copyright Revised BSD License, see section \ref LICENSE. | |||||
| * | |||||
| * \code | |||||
| * ______ _ | |||||
| * / _____) _ | | | |||||
| * ( (____ _____ ____ _| |_ _____ ____| |__ | |||||
| * \____ \| ___ | (_ _) ___ |/ ___) _ \ | |||||
| * _____) ) ____| | | || |_| ____( (___| | | | | |||||
| * (______/|_____)_|_|_| \__)_____)\____)_| |_| | |||||
| * (C)2013-2017 Semtech | |||||
| * | |||||
| * \endcode | |||||
| * | |||||
| * \author Miguel Luis ( Semtech ) | |||||
| * | |||||
| * \author Gregory Cristian ( Semtech ) | |||||
| */ | |||||
| #include <string.h> | |||||
| #include "board.h" | |||||
| #include "gpio.h" | |||||
| #include "delay.h" | |||||
| #include "timer.h" | |||||
| #include "radio.h" | |||||
| #if defined( REGION_AS923 ) | |||||
| #define RF_FREQUENCY 923000000 // Hz | |||||
| #elif defined( REGION_AU915 ) | |||||
| #define RF_FREQUENCY 915000000 // Hz | |||||
| #elif defined( REGION_CN779 ) | |||||
| #define RF_FREQUENCY 779000000 // Hz | |||||
| #elif defined( REGION_EU868 ) | |||||
| #define RF_FREQUENCY 868000000 // Hz | |||||
| #elif defined( REGION_KR920 ) | |||||
| #define RF_FREQUENCY 920000000 // Hz | |||||
| #elif defined( REGION_IN865 ) | |||||
| #define RF_FREQUENCY 865000000 // Hz | |||||
| #elif defined( REGION_US915 ) | |||||
| #define RF_FREQUENCY 915000000 // Hz | |||||
| #elif defined( REGION_RU864 ) | |||||
| #define RF_FREQUENCY 864000000 // Hz | |||||
| #else | |||||
| #error "Please define a frequency band in the compiler options." | |||||
| #endif | |||||
| #define TX_OUTPUT_POWER 14 // dBm | |||||
| #if defined( USE_MODEM_LORA ) | |||||
| #define LORA_BANDWIDTH 0 // [0: 125 kHz, | |||||
| // 1: 250 kHz, | |||||
| // 2: 500 kHz, | |||||
| // 3: Reserved] | |||||
| #define LORA_SPREADING_FACTOR 7 // [SF7..SF12] | |||||
| #define LORA_CODINGRATE 1 // [1: 4/5, | |||||
| // 2: 4/6, | |||||
| // 3: 4/7, | |||||
| // 4: 4/8] | |||||
| #define LORA_PREAMBLE_LENGTH 8 // Same for Tx and Rx | |||||
| #define LORA_SYMBOL_TIMEOUT 5 // Symbols | |||||
| #define LORA_FIX_LENGTH_PAYLOAD_ON false | |||||
| #define LORA_IQ_INVERSION_ON false | |||||
| #elif defined( USE_MODEM_FSK ) | |||||
| #define FSK_FDEV 25000 // Hz | |||||
| #define FSK_DATARATE 50000 // bps | |||||
| #define FSK_BANDWIDTH 50000 // Hz | |||||
| #define FSK_AFC_BANDWIDTH 83333 // Hz | |||||
| #define FSK_PREAMBLE_LENGTH 5 // Same for Tx and Rx | |||||
| #define FSK_FIX_LENGTH_PAYLOAD_ON false | |||||
| #else | |||||
| #error "Please define a modem in the compiler options." | |||||
| #endif | |||||
| typedef enum | |||||
| { | |||||
| LOWPOWER, | |||||
| RX, | |||||
| RX_TIMEOUT, | |||||
| RX_ERROR, | |||||
| TX, | |||||
| TX_TIMEOUT, | |||||
| }States_t; | |||||
| #define RX_TIMEOUT_VALUE 1000 | |||||
| #define BUFFER_SIZE 64 // Define the payload size here | |||||
| const uint8_t PingMsg[] = "PING"; | |||||
| const uint8_t PongMsg[] = "PONG"; | |||||
| uint16_t BufferSize = BUFFER_SIZE; | |||||
| uint8_t Buffer[BUFFER_SIZE]; | |||||
| States_t State = LOWPOWER; | |||||
| int8_t RssiValue = 0; | |||||
| int8_t SnrValue = 0; | |||||
| /*! | |||||
| * Radio events function pointer | |||||
| */ | |||||
| static RadioEvents_t RadioEvents; | |||||
| /*! | |||||
| * LED GPIO pins objects | |||||
| */ | |||||
| extern Gpio_t Led3; | |||||
| extern Gpio_t Led4; | |||||
| /*! | |||||
| * \brief Function to be executed on Radio Tx Done event | |||||
| */ | |||||
| void OnTxDone( void ); | |||||
| /*! | |||||
| * \brief Function to be executed on Radio Rx Done event | |||||
| */ | |||||
| void OnRxDone( uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr ); | |||||
| /*! | |||||
| * \brief Function executed on Radio Tx Timeout event | |||||
| */ | |||||
| void OnTxTimeout( void ); | |||||
| /*! | |||||
| * \brief Function executed on Radio Rx Timeout event | |||||
| */ | |||||
| void OnRxTimeout( void ); | |||||
| /*! | |||||
| * \brief Function executed on Radio Rx Error event | |||||
| */ | |||||
| void OnRxError( void ); | |||||
| /** | |||||
| * Main application entry point. | |||||
| */ | |||||
| int main( void ) | |||||
| { | |||||
| bool isMaster = true; | |||||
| uint8_t i; | |||||
| // Target board initialization | |||||
| BoardInitMcu( ); | |||||
| BoardInitPeriph( ); | |||||
| // Radio initialization | |||||
| RadioEvents.TxDone = OnTxDone; | |||||
| RadioEvents.RxDone = OnRxDone; | |||||
| RadioEvents.TxTimeout = OnTxTimeout; | |||||
| RadioEvents.RxTimeout = OnRxTimeout; | |||||
| RadioEvents.RxError = OnRxError; | |||||
| Radio.Init( &RadioEvents ); | |||||
| Radio.SetChannel( RF_FREQUENCY ); | |||||
| #if defined( USE_MODEM_LORA ) | |||||
| Radio.SetTxConfig( MODEM_LORA, TX_OUTPUT_POWER, 0, LORA_BANDWIDTH, | |||||
| LORA_SPREADING_FACTOR, LORA_CODINGRATE, | |||||
| LORA_PREAMBLE_LENGTH, LORA_FIX_LENGTH_PAYLOAD_ON, | |||||
| true, 0, 0, LORA_IQ_INVERSION_ON, 3000 ); | |||||
| Radio.SetRxConfig( MODEM_LORA, LORA_BANDWIDTH, LORA_SPREADING_FACTOR, | |||||
| LORA_CODINGRATE, 0, LORA_PREAMBLE_LENGTH, | |||||
| LORA_SYMBOL_TIMEOUT, LORA_FIX_LENGTH_PAYLOAD_ON, | |||||
| 0, true, 0, 0, LORA_IQ_INVERSION_ON, true ); | |||||
| Radio.SetMaxPayloadLength( MODEM_LORA, BUFFER_SIZE ); | |||||
| #elif defined( USE_MODEM_FSK ) | |||||
| Radio.SetTxConfig( MODEM_FSK, TX_OUTPUT_POWER, FSK_FDEV, 0, | |||||
| FSK_DATARATE, 0, | |||||
| FSK_PREAMBLE_LENGTH, FSK_FIX_LENGTH_PAYLOAD_ON, | |||||
| true, 0, 0, 0, 3000 ); | |||||
| Radio.SetRxConfig( MODEM_FSK, FSK_BANDWIDTH, FSK_DATARATE, | |||||
| 0, FSK_AFC_BANDWIDTH, FSK_PREAMBLE_LENGTH, | |||||
| 0, FSK_FIX_LENGTH_PAYLOAD_ON, 0, true, | |||||
| 0, 0,false, true ); | |||||
| Radio.SetMaxPayloadLength( MODEM_FSK, BUFFER_SIZE ); | |||||
| #else | |||||
| #error "Please define a frequency band in the compiler options." | |||||
| #endif | |||||
| Radio.Rx( RX_TIMEOUT_VALUE ); | |||||
| while( 1 ) | |||||
| { | |||||
| switch( State ) | |||||
| { | |||||
| case RX: | |||||
| if( isMaster == true ) | |||||
| { | |||||
| if( BufferSize > 0 ) | |||||
| { | |||||
| if( strncmp( ( const char* )Buffer, ( const char* )PongMsg, 4 ) == 0 ) | |||||
| { | |||||
| // Indicates on a LED that the received frame is a PONG | |||||
| GpioToggle( &Led4 ); | |||||
| // Send the next PING frame | |||||
| Buffer[0] = 'P'; | |||||
| Buffer[1] = 'I'; | |||||
| Buffer[2] = 'N'; | |||||
| Buffer[3] = 'G'; | |||||
| // We fill the buffer with numbers for the payload | |||||
| for( i = 4; i < BufferSize; i++ ) | |||||
| { | |||||
| Buffer[i] = i - 4; | |||||
| } | |||||
| DelayMs( 1 ); | |||||
| Radio.Send( Buffer, BufferSize ); | |||||
| } | |||||
| else if( strncmp( ( const char* )Buffer, ( const char* )PingMsg, 4 ) == 0 ) | |||||
| { // A master already exists then become a slave | |||||
| isMaster = false; | |||||
| GpioToggle( &Led3 ); // Set LED off | |||||
| Radio.Rx( RX_TIMEOUT_VALUE ); | |||||
| } | |||||
| else // valid reception but neither a PING or a PONG message | |||||
| { // Set device as master ans start again | |||||
| isMaster = true; | |||||
| Radio.Rx( RX_TIMEOUT_VALUE ); | |||||
| } | |||||
| } | |||||
| } | |||||
| else | |||||
| { | |||||
| if( BufferSize > 0 ) | |||||
| { | |||||
| if( strncmp( ( const char* )Buffer, ( const char* )PingMsg, 4 ) == 0 ) | |||||
| { | |||||
| // Indicates on a LED that the received frame is a PING | |||||
| GpioToggle( &Led4 ); | |||||
| // Send the reply to the PONG string | |||||
| Buffer[0] = 'P'; | |||||
| Buffer[1] = 'O'; | |||||
| Buffer[2] = 'N'; | |||||
| Buffer[3] = 'G'; | |||||
| // We fill the buffer with numbers for the payload | |||||
| for( i = 4; i < BufferSize; i++ ) | |||||
| { | |||||
| Buffer[i] = i - 4; | |||||
| } | |||||
| DelayMs( 1 ); | |||||
| Radio.Send( Buffer, BufferSize ); | |||||
| } | |||||
| else // valid reception but not a PING as expected | |||||
| { // Set device as master and start again | |||||
| isMaster = true; | |||||
| Radio.Rx( RX_TIMEOUT_VALUE ); | |||||
| } | |||||
| } | |||||
| } | |||||
| State = LOWPOWER; | |||||
| break; | |||||
| case TX: | |||||
| // Indicates on a LED that we have sent a PING [Master] | |||||
| // Indicates on a LED that we have sent a PONG [Slave] | |||||
| GpioToggle( &Led3 ); | |||||
| Radio.Rx( RX_TIMEOUT_VALUE ); | |||||
| State = LOWPOWER; | |||||
| break; | |||||
| case RX_TIMEOUT: | |||||
| case RX_ERROR: | |||||
| if( isMaster == true ) | |||||
| { | |||||
| // Send the next PING frame | |||||
| Buffer[0] = 'P'; | |||||
| Buffer[1] = 'I'; | |||||
| Buffer[2] = 'N'; | |||||
| Buffer[3] = 'G'; | |||||
| for( i = 4; i < BufferSize; i++ ) | |||||
| { | |||||
| Buffer[i] = i - 4; | |||||
| } | |||||
| DelayMs( 1 ); | |||||
| Radio.Send( Buffer, BufferSize ); | |||||
| } | |||||
| else | |||||
| { | |||||
| Radio.Rx( RX_TIMEOUT_VALUE ); | |||||
| } | |||||
| State = LOWPOWER; | |||||
| break; | |||||
| case TX_TIMEOUT: | |||||
| Radio.Rx( RX_TIMEOUT_VALUE ); | |||||
| State = LOWPOWER; | |||||
| break; | |||||
| case LOWPOWER: | |||||
| default: | |||||
| // Set low power | |||||
| break; | |||||
| } | |||||
| BoardLowPowerHandler( ); | |||||
| } | |||||
| } | |||||
| void OnTxDone( void ) | |||||
| { | |||||
| Radio.Sleep( ); | |||||
| State = TX; | |||||
| } | |||||
| void OnRxDone( uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr ) | |||||
| { | |||||
| Radio.Sleep( ); | |||||
| BufferSize = size; | |||||
| memcpy( Buffer, payload, BufferSize ); | |||||
| RssiValue = rssi; | |||||
| SnrValue = snr; | |||||
| State = RX; | |||||
| } | |||||
| void OnTxTimeout( void ) | |||||
| { | |||||
| Radio.Sleep( ); | |||||
| State = TX_TIMEOUT; | |||||
| } | |||||
| void OnRxTimeout( void ) | |||||
| { | |||||
| Radio.Sleep( ); | |||||
| State = RX_TIMEOUT; | |||||
| } | |||||
| void OnRxError( void ) | |||||
| { | |||||
| Radio.Sleep( ); | |||||
| State = RX_ERROR; | |||||
| } | |||||
| /*! | |||||
| * \file main.c | |||||
| * | |||||
| * \brief Ping-Pong implementation | |||||
| * | |||||
| * \copyright Revised BSD License, see section \ref LICENSE. | |||||
| * | |||||
| * \code | |||||
| * ______ _ | |||||
| * / _____) _ | | | |||||
| * ( (____ _____ ____ _| |_ _____ ____| |__ | |||||
| * \____ \| ___ | (_ _) ___ |/ ___) _ \ | |||||
| * _____) ) ____| | | || |_| ____( (___| | | | | |||||
| * (______/|_____)_|_|_| \__)_____)\____)_| |_| | |||||
| * (C)2013-2017 Semtech | |||||
| * | |||||
| * \endcode | |||||
| * | |||||
| * \author Miguel Luis ( Semtech ) | |||||
| * | |||||
| * \author Gregory Cristian ( Semtech ) | |||||
| */ | |||||
| #include <string.h> | |||||
| #include "board.h" | |||||
| #include "gpio.h" | |||||
| #include "delay.h" | |||||
| #include "timer.h" | |||||
| #include "radio.h" | |||||
| #if defined( REGION_AS923 ) | |||||
| #define RF_FREQUENCY 923000000 // Hz | |||||
| #elif defined( REGION_AU915 ) | |||||
| #define RF_FREQUENCY 915000000 // Hz | |||||
| #elif defined( REGION_CN779 ) | |||||
| #define RF_FREQUENCY 779000000 // Hz | |||||
| #elif defined( REGION_EU868 ) | |||||
| #define RF_FREQUENCY 868000000 // Hz | |||||
| #elif defined( REGION_KR920 ) | |||||
| #define RF_FREQUENCY 920000000 // Hz | |||||
| #elif defined( REGION_IN865 ) | |||||
| #define RF_FREQUENCY 865000000 // Hz | |||||
| #elif defined( REGION_US915 ) | |||||
| #define RF_FREQUENCY 915000000 // Hz | |||||
| #elif defined( REGION_RU864 ) | |||||
| #define RF_FREQUENCY 864000000 // Hz | |||||
| #else | |||||
| #error "Please define a frequency band in the compiler options." | |||||
| #endif | |||||
| #define TX_OUTPUT_POWER 14 // dBm | |||||
| #if defined( USE_MODEM_LORA ) | |||||
| #define LORA_BANDWIDTH 0 // [0: 125 kHz, | |||||
| // 1: 250 kHz, | |||||
| // 2: 500 kHz, | |||||
| // 3: Reserved] | |||||
| #define LORA_SPREADING_FACTOR 7 // [SF7..SF12] | |||||
| #define LORA_CODINGRATE 1 // [1: 4/5, | |||||
| // 2: 4/6, | |||||
| // 3: 4/7, | |||||
| // 4: 4/8] | |||||
| #define LORA_PREAMBLE_LENGTH 8 // Same for Tx and Rx | |||||
| #define LORA_SYMBOL_TIMEOUT 5 // Symbols | |||||
| #define LORA_FIX_LENGTH_PAYLOAD_ON false | |||||
| #define LORA_IQ_INVERSION_ON false | |||||
| #elif defined( USE_MODEM_FSK ) | |||||
| #define FSK_FDEV 25000 // Hz | |||||
| #define FSK_DATARATE 50000 // bps | |||||
| #define FSK_BANDWIDTH 50000 // Hz | |||||
| #define FSK_AFC_BANDWIDTH 83333 // Hz | |||||
| #define FSK_PREAMBLE_LENGTH 5 // Same for Tx and Rx | |||||
| #define FSK_FIX_LENGTH_PAYLOAD_ON false | |||||
| #else | |||||
| #error "Please define a modem in the compiler options." | |||||
| #endif | |||||
| typedef enum | |||||
| { | |||||
| LOWPOWER, | |||||
| RX, | |||||
| RX_TIMEOUT, | |||||
| RX_ERROR, | |||||
| TX, | |||||
| TX_TIMEOUT, | |||||
| }States_t; | |||||
| #define RX_TIMEOUT_VALUE 1000 | |||||
| #define BUFFER_SIZE 64 // Define the payload size here | |||||
| const uint8_t PingMsg[] = "PING"; | |||||
| const uint8_t PongMsg[] = "PONG"; | |||||
| uint16_t BufferSize = BUFFER_SIZE; | |||||
| uint8_t Buffer[BUFFER_SIZE]; | |||||
| States_t State = LOWPOWER; | |||||
| int8_t RssiValue = 0; | |||||
| int8_t SnrValue = 0; | |||||
| /*! | |||||
| * Radio events function pointer | |||||
| */ | |||||
| static RadioEvents_t RadioEvents; | |||||
| /*! | |||||
| * LED GPIO pins objects | |||||
| */ | |||||
| extern Gpio_t Led3; | |||||
| extern Gpio_t Led4; | |||||
| /*! | |||||
| * \brief Function to be executed on Radio Tx Done event | |||||
| */ | |||||
| void OnTxDone( void ); | |||||
| /*! | |||||
| * \brief Function to be executed on Radio Rx Done event | |||||
| */ | |||||
| void OnRxDone( uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr ); | |||||
| /*! | |||||
| * \brief Function executed on Radio Tx Timeout event | |||||
| */ | |||||
| void OnTxTimeout( void ); | |||||
| /*! | |||||
| * \brief Function executed on Radio Rx Timeout event | |||||
| */ | |||||
| void OnRxTimeout( void ); | |||||
| /*! | |||||
| * \brief Function executed on Radio Rx Error event | |||||
| */ | |||||
| void OnRxError( void ); | |||||
| /** | |||||
| * Main application entry point. | |||||
| */ | |||||
| int main( void ) | |||||
| { | |||||
| bool isMaster = true; | |||||
| uint8_t i; | |||||
| // Target board initialization | |||||
| BoardInitMcu( ); | |||||
| BoardInitPeriph( ); | |||||
| // Radio initialization | |||||
| RadioEvents.TxDone = OnTxDone; | |||||
| RadioEvents.RxDone = OnRxDone; | |||||
| RadioEvents.TxTimeout = OnTxTimeout; | |||||
| RadioEvents.RxTimeout = OnRxTimeout; | |||||
| RadioEvents.RxError = OnRxError; | |||||
| Radio.Init( &RadioEvents ); | |||||
| Radio.SetChannel( RF_FREQUENCY ); | |||||
| #if defined( USE_MODEM_LORA ) | |||||
| Radio.SetTxConfig( MODEM_LORA, TX_OUTPUT_POWER, 0, LORA_BANDWIDTH, | |||||
| LORA_SPREADING_FACTOR, LORA_CODINGRATE, | |||||
| LORA_PREAMBLE_LENGTH, LORA_FIX_LENGTH_PAYLOAD_ON, | |||||
| true, 0, 0, LORA_IQ_INVERSION_ON, 3000 ); | |||||
| Radio.SetRxConfig( MODEM_LORA, LORA_BANDWIDTH, LORA_SPREADING_FACTOR, | |||||
| LORA_CODINGRATE, 0, LORA_PREAMBLE_LENGTH, | |||||
| LORA_SYMBOL_TIMEOUT, LORA_FIX_LENGTH_PAYLOAD_ON, | |||||
| 0, true, 0, 0, LORA_IQ_INVERSION_ON, true ); | |||||
| Radio.SetMaxPayloadLength( MODEM_LORA, BUFFER_SIZE ); | |||||
| #elif defined( USE_MODEM_FSK ) | |||||
| Radio.SetTxConfig( MODEM_FSK, TX_OUTPUT_POWER, FSK_FDEV, 0, | |||||
| FSK_DATARATE, 0, | |||||
| FSK_PREAMBLE_LENGTH, FSK_FIX_LENGTH_PAYLOAD_ON, | |||||
| true, 0, 0, 0, 3000 ); | |||||
| Radio.SetRxConfig( MODEM_FSK, FSK_BANDWIDTH, FSK_DATARATE, | |||||
| 0, FSK_AFC_BANDWIDTH, FSK_PREAMBLE_LENGTH, | |||||
| 0, FSK_FIX_LENGTH_PAYLOAD_ON, 0, true, | |||||
| 0, 0,false, true ); | |||||
| Radio.SetMaxPayloadLength( MODEM_FSK, BUFFER_SIZE ); | |||||
| #else | |||||
| #error "Please define a frequency band in the compiler options." | |||||
| #endif | |||||
| Radio.Rx( RX_TIMEOUT_VALUE ); | |||||
| while( 1 ) | |||||
| { | |||||
| switch( State ) | |||||
| { | |||||
| case RX: | |||||
| if( isMaster == true ) | |||||
| { | |||||
| if( BufferSize > 0 ) | |||||
| { | |||||
| if( strncmp( ( const char* )Buffer, ( const char* )PongMsg, 4 ) == 0 ) | |||||
| { | |||||
| // Indicates on a LED that the received frame is a PONG | |||||
| GpioToggle( &Led4 ); | |||||
| // Send the next PING frame | |||||
| Buffer[0] = 'P'; | |||||
| Buffer[1] = 'I'; | |||||
| Buffer[2] = 'N'; | |||||
| Buffer[3] = 'G'; | |||||
| // We fill the buffer with numbers for the payload | |||||
| for( i = 4; i < BufferSize; i++ ) | |||||
| { | |||||
| Buffer[i] = i - 4; | |||||
| } | |||||
| DelayMs( 1 ); | |||||
| Radio.Send( Buffer, BufferSize ); | |||||
| } | |||||
| else if( strncmp( ( const char* )Buffer, ( const char* )PingMsg, 4 ) == 0 ) | |||||
| { // A master already exists then become a slave | |||||
| isMaster = false; | |||||
| GpioToggle( &Led3 ); // Set LED off | |||||
| Radio.Rx( RX_TIMEOUT_VALUE ); | |||||
| } | |||||
| else // valid reception but neither a PING or a PONG message | |||||
| { // Set device as master ans start again | |||||
| isMaster = true; | |||||
| Radio.Rx( RX_TIMEOUT_VALUE ); | |||||
| } | |||||
| } | |||||
| } | |||||
| else | |||||
| { | |||||
| if( BufferSize > 0 ) | |||||
| { | |||||
| if( strncmp( ( const char* )Buffer, ( const char* )PingMsg, 4 ) == 0 ) | |||||
| { | |||||
| // Indicates on a LED that the received frame is a PING | |||||
| GpioToggle( &Led4 ); | |||||
| // Send the reply to the PONG string | |||||
| Buffer[0] = 'P'; | |||||
| Buffer[1] = 'O'; | |||||
| Buffer[2] = 'N'; | |||||
| Buffer[3] = 'G'; | |||||
| // We fill the buffer with numbers for the payload | |||||
| for( i = 4; i < BufferSize; i++ ) | |||||
| { | |||||
| Buffer[i] = i - 4; | |||||
| } | |||||
| DelayMs( 1 ); | |||||
| Radio.Send( Buffer, BufferSize ); | |||||
| } | |||||
| else // valid reception but not a PING as expected | |||||
| { // Set device as master and start again | |||||
| isMaster = true; | |||||
| Radio.Rx( RX_TIMEOUT_VALUE ); | |||||
| } | |||||
| } | |||||
| } | |||||
| State = LOWPOWER; | |||||
| break; | |||||
| case TX: | |||||
| // Indicates on a LED that we have sent a PING [Master] | |||||
| // Indicates on a LED that we have sent a PONG [Slave] | |||||
| GpioToggle( &Led3 ); | |||||
| Radio.Rx( RX_TIMEOUT_VALUE ); | |||||
| State = LOWPOWER; | |||||
| break; | |||||
| case RX_TIMEOUT: | |||||
| case RX_ERROR: | |||||
| if( isMaster == true ) | |||||
| { | |||||
| // Send the next PING frame | |||||
| Buffer[0] = 'P'; | |||||
| Buffer[1] = 'I'; | |||||
| Buffer[2] = 'N'; | |||||
| Buffer[3] = 'G'; | |||||
| for( i = 4; i < BufferSize; i++ ) | |||||
| { | |||||
| Buffer[i] = i - 4; | |||||
| } | |||||
| DelayMs( 1 ); | |||||
| Radio.Send( Buffer, BufferSize ); | |||||
| } | |||||
| else | |||||
| { | |||||
| Radio.Rx( RX_TIMEOUT_VALUE ); | |||||
| } | |||||
| State = LOWPOWER; | |||||
| break; | |||||
| case TX_TIMEOUT: | |||||
| Radio.Rx( RX_TIMEOUT_VALUE ); | |||||
| State = LOWPOWER; | |||||
| break; | |||||
| case LOWPOWER: | |||||
| default: | |||||
| // Set low power | |||||
| break; | |||||
| } | |||||
| BoardLowPowerHandler( ); | |||||
| } | |||||
| } | |||||
| void OnTxDone( void ) | |||||
| { | |||||
| Radio.Sleep( ); | |||||
| State = TX; | |||||
| } | |||||
| void OnRxDone( uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr ) | |||||
| { | |||||
| Radio.Sleep( ); | |||||
| BufferSize = size; | |||||
| memcpy( Buffer, payload, BufferSize ); | |||||
| RssiValue = rssi; | |||||
| SnrValue = snr; | |||||
| State = RX; | |||||
| } | |||||
| void OnTxTimeout( void ) | |||||
| { | |||||
| Radio.Sleep( ); | |||||
| State = TX_TIMEOUT; | |||||
| } | |||||
| void OnRxTimeout( void ) | |||||
| { | |||||
| Radio.Sleep( ); | |||||
| State = RX_TIMEOUT; | |||||
| } | |||||
| void OnRxError( void ) | |||||
| { | |||||
| Radio.Sleep( ); | |||||
| State = RX_ERROR; | |||||
| } | |||||
| @@ -1,361 +1,361 @@ | |||||
| /*! | |||||
| * \file main.c | |||||
| * | |||||
| * \brief Ping-Pong implementation | |||||
| * | |||||
| * \copyright Revised BSD License, see section \ref LICENSE. | |||||
| * | |||||
| * \code | |||||
| * ______ _ | |||||
| * / _____) _ | | | |||||
| * ( (____ _____ ____ _| |_ _____ ____| |__ | |||||
| * \____ \| ___ | (_ _) ___ |/ ___) _ \ | |||||
| * _____) ) ____| | | || |_| ____( (___| | | | | |||||
| * (______/|_____)_|_|_| \__)_____)\____)_| |_| | |||||
| * (C)2013-2017 Semtech | |||||
| * | |||||
| * \endcode | |||||
| * | |||||
| * \author Miguel Luis ( Semtech ) | |||||
| * | |||||
| * \author Gregory Cristian ( Semtech ) | |||||
| */ | |||||
| #include <string.h> | |||||
| #include "board.h" | |||||
| #include "gpio.h" | |||||
| #include "delay.h" | |||||
| #include "timer.h" | |||||
| #include "radio.h" | |||||
| #if defined( REGION_AS923 ) | |||||
| #define RF_FREQUENCY 923000000 // Hz | |||||
| #elif defined( REGION_AU915 ) | |||||
| #define RF_FREQUENCY 915000000 // Hz | |||||
| #elif defined( REGION_CN779 ) | |||||
| #define RF_FREQUENCY 779000000 // Hz | |||||
| #elif defined( REGION_EU868 ) | |||||
| #define RF_FREQUENCY 868000000 // Hz | |||||
| #elif defined( REGION_KR920 ) | |||||
| #define RF_FREQUENCY 920000000 // Hz | |||||
| #elif defined( REGION_IN865 ) | |||||
| #define RF_FREQUENCY 865000000 // Hz | |||||
| #elif defined( REGION_US915 ) | |||||
| #define RF_FREQUENCY 915000000 // Hz | |||||
| #elif defined( REGION_RU864 ) | |||||
| #define RF_FREQUENCY 864000000 // Hz | |||||
| #else | |||||
| #error "Please define a frequency band in the compiler options." | |||||
| #endif | |||||
| #define TX_OUTPUT_POWER 14 // dBm | |||||
| #if defined( USE_MODEM_LORA ) | |||||
| #define LORA_BANDWIDTH 0 // [0: 125 kHz, | |||||
| // 1: 250 kHz, | |||||
| // 2: 500 kHz, | |||||
| // 3: Reserved] | |||||
| #define LORA_SPREADING_FACTOR 7 // [SF7..SF12] | |||||
| #define LORA_CODINGRATE 1 // [1: 4/5, | |||||
| // 2: 4/6, | |||||
| // 3: 4/7, | |||||
| // 4: 4/8] | |||||
| #define LORA_PREAMBLE_LENGTH 8 // Same for Tx and Rx | |||||
| #define LORA_SYMBOL_TIMEOUT 5 // Symbols | |||||
| #define LORA_FIX_LENGTH_PAYLOAD_ON false | |||||
| #define LORA_IQ_INVERSION_ON false | |||||
| #elif defined( USE_MODEM_FSK ) | |||||
| #define FSK_FDEV 25000 // Hz | |||||
| #define FSK_DATARATE 50000 // bps | |||||
| #define FSK_BANDWIDTH 50000 // Hz | |||||
| #define FSK_AFC_BANDWIDTH 83333 // Hz | |||||
| #define FSK_PREAMBLE_LENGTH 5 // Same for Tx and Rx | |||||
| #define FSK_FIX_LENGTH_PAYLOAD_ON false | |||||
| #else | |||||
| #error "Please define a modem in the compiler options." | |||||
| #endif | |||||
| typedef enum | |||||
| { | |||||
| LOWPOWER, | |||||
| RX, | |||||
| RX_TIMEOUT, | |||||
| RX_ERROR, | |||||
| TX, | |||||
| TX_TIMEOUT, | |||||
| }States_t; | |||||
| #define RX_TIMEOUT_VALUE 1000 | |||||
| #define BUFFER_SIZE 64 // Define the payload size here | |||||
| const uint8_t PingMsg[] = "PING"; | |||||
| const uint8_t PongMsg[] = "PONG"; | |||||
| uint16_t BufferSize = BUFFER_SIZE; | |||||
| uint8_t Buffer[BUFFER_SIZE]; | |||||
| States_t State = LOWPOWER; | |||||
| int8_t RssiValue = 0; | |||||
| int8_t SnrValue = 0; | |||||
| /*! | |||||
| * Radio events function pointer | |||||
| */ | |||||
| static RadioEvents_t RadioEvents; | |||||
| /*! | |||||
| * LED GPIO pins objects | |||||
| */ | |||||
| extern Gpio_t Led3; | |||||
| extern Gpio_t Led4; | |||||
| /*! | |||||
| * \brief Function to be executed on Radio Tx Done event | |||||
| */ | |||||
| void OnTxDone( void ); | |||||
| /*! | |||||
| * \brief Function to be executed on Radio Rx Done event | |||||
| */ | |||||
| void OnRxDone( uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr ); | |||||
| /*! | |||||
| * \brief Function executed on Radio Tx Timeout event | |||||
| */ | |||||
| void OnTxTimeout( void ); | |||||
| /*! | |||||
| * \brief Function executed on Radio Rx Timeout event | |||||
| */ | |||||
| void OnRxTimeout( void ); | |||||
| /*! | |||||
| * \brief Function executed on Radio Rx Error event | |||||
| */ | |||||
| void OnRxError( void ); | |||||
| /** | |||||
| * Main application entry point. | |||||
| */ | |||||
| int main( void ) | |||||
| { | |||||
| bool isMaster = true; | |||||
| uint8_t i; | |||||
| // Target board initialization | |||||
| BoardInitMcu( ); | |||||
| BoardInitPeriph( ); | |||||
| // Radio initialization | |||||
| RadioEvents.TxDone = OnTxDone; | |||||
| RadioEvents.RxDone = OnRxDone; | |||||
| RadioEvents.TxTimeout = OnTxTimeout; | |||||
| RadioEvents.RxTimeout = OnRxTimeout; | |||||
| RadioEvents.RxError = OnRxError; | |||||
| Radio.Init( &RadioEvents ); | |||||
| Radio.SetChannel( RF_FREQUENCY ); | |||||
| #if defined( USE_MODEM_LORA ) | |||||
| Radio.SetTxConfig( MODEM_LORA, TX_OUTPUT_POWER, 0, LORA_BANDWIDTH, | |||||
| LORA_SPREADING_FACTOR, LORA_CODINGRATE, | |||||
| LORA_PREAMBLE_LENGTH, LORA_FIX_LENGTH_PAYLOAD_ON, | |||||
| true, 0, 0, LORA_IQ_INVERSION_ON, 3000 ); | |||||
| Radio.SetRxConfig( MODEM_LORA, LORA_BANDWIDTH, LORA_SPREADING_FACTOR, | |||||
| LORA_CODINGRATE, 0, LORA_PREAMBLE_LENGTH, | |||||
| LORA_SYMBOL_TIMEOUT, LORA_FIX_LENGTH_PAYLOAD_ON, | |||||
| 0, true, 0, 0, LORA_IQ_INVERSION_ON, true ); | |||||
| Radio.SetMaxPayloadLength( MODEM_LORA, BUFFER_SIZE ); | |||||
| #elif defined( USE_MODEM_FSK ) | |||||
| Radio.SetTxConfig( MODEM_FSK, TX_OUTPUT_POWER, FSK_FDEV, 0, | |||||
| FSK_DATARATE, 0, | |||||
| FSK_PREAMBLE_LENGTH, FSK_FIX_LENGTH_PAYLOAD_ON, | |||||
| true, 0, 0, 0, 3000 ); | |||||
| Radio.SetRxConfig( MODEM_FSK, FSK_BANDWIDTH, FSK_DATARATE, | |||||
| 0, FSK_AFC_BANDWIDTH, FSK_PREAMBLE_LENGTH, | |||||
| 0, FSK_FIX_LENGTH_PAYLOAD_ON, 0, true, | |||||
| 0, 0,false, true ); | |||||
| Radio.SetMaxPayloadLength( MODEM_FSK, BUFFER_SIZE ); | |||||
| #else | |||||
| #error "Please define a frequency band in the compiler options." | |||||
| #endif | |||||
| Radio.Rx( RX_TIMEOUT_VALUE ); | |||||
| while( 1 ) | |||||
| { | |||||
| switch( State ) | |||||
| { | |||||
| case RX: | |||||
| if( isMaster == true ) | |||||
| { | |||||
| if( BufferSize > 0 ) | |||||
| { | |||||
| if( strncmp( ( const char* )Buffer, ( const char* )PongMsg, 4 ) == 0 ) | |||||
| { | |||||
| // Indicates on a LED that the received frame is a PONG | |||||
| GpioToggle( &Led4 ); | |||||
| // Send the next PING frame | |||||
| Buffer[0] = 'P'; | |||||
| Buffer[1] = 'I'; | |||||
| Buffer[2] = 'N'; | |||||
| Buffer[3] = 'G'; | |||||
| // We fill the buffer with numbers for the payload | |||||
| for( i = 4; i < BufferSize; i++ ) | |||||
| { | |||||
| Buffer[i] = i - 4; | |||||
| } | |||||
| DelayMs( 1 ); | |||||
| Radio.Send( Buffer, BufferSize ); | |||||
| } | |||||
| else if( strncmp( ( const char* )Buffer, ( const char* )PingMsg, 4 ) == 0 ) | |||||
| { // A master already exists then become a slave | |||||
| isMaster = false; | |||||
| GpioToggle( &Led3 ); // Set LED off | |||||
| Radio.Rx( RX_TIMEOUT_VALUE ); | |||||
| } | |||||
| else // valid reception but neither a PING or a PONG message | |||||
| { // Set device as master ans start again | |||||
| isMaster = true; | |||||
| Radio.Rx( RX_TIMEOUT_VALUE ); | |||||
| } | |||||
| } | |||||
| } | |||||
| else | |||||
| { | |||||
| if( BufferSize > 0 ) | |||||
| { | |||||
| if( strncmp( ( const char* )Buffer, ( const char* )PingMsg, 4 ) == 0 ) | |||||
| { | |||||
| // Indicates on a LED that the received frame is a PING | |||||
| GpioToggle( &Led4 ); | |||||
| // Send the reply to the PONG string | |||||
| Buffer[0] = 'P'; | |||||
| Buffer[1] = 'O'; | |||||
| Buffer[2] = 'N'; | |||||
| Buffer[3] = 'G'; | |||||
| // We fill the buffer with numbers for the payload | |||||
| for( i = 4; i < BufferSize; i++ ) | |||||
| { | |||||
| Buffer[i] = i - 4; | |||||
| } | |||||
| DelayMs( 1 ); | |||||
| Radio.Send( Buffer, BufferSize ); | |||||
| } | |||||
| else // valid reception but not a PING as expected | |||||
| { // Set device as master and start again | |||||
| isMaster = true; | |||||
| Radio.Rx( RX_TIMEOUT_VALUE ); | |||||
| } | |||||
| } | |||||
| } | |||||
| State = LOWPOWER; | |||||
| break; | |||||
| case TX: | |||||
| // Indicates on a LED that we have sent a PING [Master] | |||||
| // Indicates on a LED that we have sent a PONG [Slave] | |||||
| GpioToggle( &Led3 ); | |||||
| Radio.Rx( RX_TIMEOUT_VALUE ); | |||||
| State = LOWPOWER; | |||||
| break; | |||||
| case RX_TIMEOUT: | |||||
| case RX_ERROR: | |||||
| if( isMaster == true ) | |||||
| { | |||||
| // Send the next PING frame | |||||
| Buffer[0] = 'P'; | |||||
| Buffer[1] = 'I'; | |||||
| Buffer[2] = 'N'; | |||||
| Buffer[3] = 'G'; | |||||
| for( i = 4; i < BufferSize; i++ ) | |||||
| { | |||||
| Buffer[i] = i - 4; | |||||
| } | |||||
| DelayMs( 1 ); | |||||
| Radio.Send( Buffer, BufferSize ); | |||||
| } | |||||
| else | |||||
| { | |||||
| Radio.Rx( RX_TIMEOUT_VALUE ); | |||||
| } | |||||
| State = LOWPOWER; | |||||
| break; | |||||
| case TX_TIMEOUT: | |||||
| Radio.Rx( RX_TIMEOUT_VALUE ); | |||||
| State = LOWPOWER; | |||||
| break; | |||||
| case LOWPOWER: | |||||
| default: | |||||
| // Set low power | |||||
| break; | |||||
| } | |||||
| BoardLowPowerHandler( ); | |||||
| } | |||||
| } | |||||
| void OnTxDone( void ) | |||||
| { | |||||
| Radio.Sleep( ); | |||||
| State = TX; | |||||
| } | |||||
| void OnRxDone( uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr ) | |||||
| { | |||||
| Radio.Sleep( ); | |||||
| BufferSize = size; | |||||
| memcpy( Buffer, payload, BufferSize ); | |||||
| RssiValue = rssi; | |||||
| SnrValue = snr; | |||||
| State = RX; | |||||
| } | |||||
| void OnTxTimeout( void ) | |||||
| { | |||||
| Radio.Sleep( ); | |||||
| State = TX_TIMEOUT; | |||||
| } | |||||
| void OnRxTimeout( void ) | |||||
| { | |||||
| Radio.Sleep( ); | |||||
| State = RX_TIMEOUT; | |||||
| } | |||||
| void OnRxError( void ) | |||||
| { | |||||
| Radio.Sleep( ); | |||||
| State = RX_ERROR; | |||||
| } | |||||
| /*! | |||||
| * \file main.c | |||||
| * | |||||
| * \brief Ping-Pong implementation | |||||
| * | |||||
| * \copyright Revised BSD License, see section \ref LICENSE. | |||||
| * | |||||
| * \code | |||||
| * ______ _ | |||||
| * / _____) _ | | | |||||
| * ( (____ _____ ____ _| |_ _____ ____| |__ | |||||
| * \____ \| ___ | (_ _) ___ |/ ___) _ \ | |||||
| * _____) ) ____| | | || |_| ____( (___| | | | | |||||
| * (______/|_____)_|_|_| \__)_____)\____)_| |_| | |||||
| * (C)2013-2017 Semtech | |||||
| * | |||||
| * \endcode | |||||
| * | |||||
| * \author Miguel Luis ( Semtech ) | |||||
| * | |||||
| * \author Gregory Cristian ( Semtech ) | |||||
| */ | |||||
| #include <string.h> | |||||
| #include "board.h" | |||||
| #include "gpio.h" | |||||
| #include "delay.h" | |||||
| #include "timer.h" | |||||
| #include "radio.h" | |||||
| #if defined( REGION_AS923 ) | |||||
| #define RF_FREQUENCY 923000000 // Hz | |||||
| #elif defined( REGION_AU915 ) | |||||
| #define RF_FREQUENCY 915000000 // Hz | |||||
| #elif defined( REGION_CN779 ) | |||||
| #define RF_FREQUENCY 779000000 // Hz | |||||
| #elif defined( REGION_EU868 ) | |||||
| #define RF_FREQUENCY 868000000 // Hz | |||||
| #elif defined( REGION_KR920 ) | |||||
| #define RF_FREQUENCY 920000000 // Hz | |||||
| #elif defined( REGION_IN865 ) | |||||
| #define RF_FREQUENCY 865000000 // Hz | |||||
| #elif defined( REGION_US915 ) | |||||
| #define RF_FREQUENCY 915000000 // Hz | |||||
| #elif defined( REGION_RU864 ) | |||||
| #define RF_FREQUENCY 864000000 // Hz | |||||
| #else | |||||
| #error "Please define a frequency band in the compiler options." | |||||
| #endif | |||||
| #define TX_OUTPUT_POWER 14 // dBm | |||||
| #if defined( USE_MODEM_LORA ) | |||||
| #define LORA_BANDWIDTH 0 // [0: 125 kHz, | |||||
| // 1: 250 kHz, | |||||
| // 2: 500 kHz, | |||||
| // 3: Reserved] | |||||
| #define LORA_SPREADING_FACTOR 7 // [SF7..SF12] | |||||
| #define LORA_CODINGRATE 1 // [1: 4/5, | |||||
| // 2: 4/6, | |||||
| // 3: 4/7, | |||||
| // 4: 4/8] | |||||
| #define LORA_PREAMBLE_LENGTH 8 // Same for Tx and Rx | |||||
| #define LORA_SYMBOL_TIMEOUT 5 // Symbols | |||||
| #define LORA_FIX_LENGTH_PAYLOAD_ON false | |||||
| #define LORA_IQ_INVERSION_ON false | |||||
| #elif defined( USE_MODEM_FSK ) | |||||
| #define FSK_FDEV 25000 // Hz | |||||
| #define FSK_DATARATE 50000 // bps | |||||
| #define FSK_BANDWIDTH 50000 // Hz | |||||
| #define FSK_AFC_BANDWIDTH 83333 // Hz | |||||
| #define FSK_PREAMBLE_LENGTH 5 // Same for Tx and Rx | |||||
| #define FSK_FIX_LENGTH_PAYLOAD_ON false | |||||
| #else | |||||
| #error "Please define a modem in the compiler options." | |||||
| #endif | |||||
| typedef enum | |||||
| { | |||||
| LOWPOWER, | |||||
| RX, | |||||
| RX_TIMEOUT, | |||||
| RX_ERROR, | |||||
| TX, | |||||
| TX_TIMEOUT, | |||||
| }States_t; | |||||
| #define RX_TIMEOUT_VALUE 1000 | |||||
| #define BUFFER_SIZE 64 // Define the payload size here | |||||
| const uint8_t PingMsg[] = "PING"; | |||||
| const uint8_t PongMsg[] = "PONG"; | |||||
| uint16_t BufferSize = BUFFER_SIZE; | |||||
| uint8_t Buffer[BUFFER_SIZE]; | |||||
| States_t State = LOWPOWER; | |||||
| int8_t RssiValue = 0; | |||||
| int8_t SnrValue = 0; | |||||
| /*! | |||||
| * Radio events function pointer | |||||
| */ | |||||
| static RadioEvents_t RadioEvents; | |||||
| /*! | |||||
| * LED GPIO pins objects | |||||
| */ | |||||
| extern Gpio_t Led3; | |||||
| extern Gpio_t Led4; | |||||
| /*! | |||||
| * \brief Function to be executed on Radio Tx Done event | |||||
| */ | |||||
| void OnTxDone( void ); | |||||
| /*! | |||||
| * \brief Function to be executed on Radio Rx Done event | |||||
| */ | |||||
| void OnRxDone( uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr ); | |||||
| /*! | |||||
| * \brief Function executed on Radio Tx Timeout event | |||||
| */ | |||||
| void OnTxTimeout( void ); | |||||
| /*! | |||||
| * \brief Function executed on Radio Rx Timeout event | |||||
| */ | |||||
| void OnRxTimeout( void ); | |||||
| /*! | |||||
| * \brief Function executed on Radio Rx Error event | |||||
| */ | |||||
| void OnRxError( void ); | |||||
| /** | |||||
| * Main application entry point. | |||||
| */ | |||||
| int main( void ) | |||||
| { | |||||
| bool isMaster = true; | |||||
| uint8_t i; | |||||
| // Target board initialization | |||||
| BoardInitMcu( ); | |||||
| BoardInitPeriph( ); | |||||
| // Radio initialization | |||||
| RadioEvents.TxDone = OnTxDone; | |||||
| RadioEvents.RxDone = OnRxDone; | |||||
| RadioEvents.TxTimeout = OnTxTimeout; | |||||
| RadioEvents.RxTimeout = OnRxTimeout; | |||||
| RadioEvents.RxError = OnRxError; | |||||
| Radio.Init( &RadioEvents ); | |||||
| Radio.SetChannel( RF_FREQUENCY ); | |||||
| #if defined( USE_MODEM_LORA ) | |||||
| Radio.SetTxConfig( MODEM_LORA, TX_OUTPUT_POWER, 0, LORA_BANDWIDTH, | |||||
| LORA_SPREADING_FACTOR, LORA_CODINGRATE, | |||||
| LORA_PREAMBLE_LENGTH, LORA_FIX_LENGTH_PAYLOAD_ON, | |||||
| true, 0, 0, LORA_IQ_INVERSION_ON, 3000 ); | |||||
| Radio.SetRxConfig( MODEM_LORA, LORA_BANDWIDTH, LORA_SPREADING_FACTOR, | |||||
| LORA_CODINGRATE, 0, LORA_PREAMBLE_LENGTH, | |||||
| LORA_SYMBOL_TIMEOUT, LORA_FIX_LENGTH_PAYLOAD_ON, | |||||
| 0, true, 0, 0, LORA_IQ_INVERSION_ON, true ); | |||||
| Radio.SetMaxPayloadLength( MODEM_LORA, BUFFER_SIZE ); | |||||
| #elif defined( USE_MODEM_FSK ) | |||||
| Radio.SetTxConfig( MODEM_FSK, TX_OUTPUT_POWER, FSK_FDEV, 0, | |||||
| FSK_DATARATE, 0, | |||||
| FSK_PREAMBLE_LENGTH, FSK_FIX_LENGTH_PAYLOAD_ON, | |||||
| true, 0, 0, 0, 3000 ); | |||||
| Radio.SetRxConfig( MODEM_FSK, FSK_BANDWIDTH, FSK_DATARATE, | |||||
| 0, FSK_AFC_BANDWIDTH, FSK_PREAMBLE_LENGTH, | |||||
| 0, FSK_FIX_LENGTH_PAYLOAD_ON, 0, true, | |||||
| 0, 0,false, true ); | |||||
| Radio.SetMaxPayloadLength( MODEM_FSK, BUFFER_SIZE ); | |||||
| #else | |||||
| #error "Please define a frequency band in the compiler options." | |||||
| #endif | |||||
| Radio.Rx( RX_TIMEOUT_VALUE ); | |||||
| while( 1 ) | |||||
| { | |||||
| switch( State ) | |||||
| { | |||||
| case RX: | |||||
| if( isMaster == true ) | |||||
| { | |||||
| if( BufferSize > 0 ) | |||||
| { | |||||
| if( strncmp( ( const char* )Buffer, ( const char* )PongMsg, 4 ) == 0 ) | |||||
| { | |||||
| // Indicates on a LED that the received frame is a PONG | |||||
| GpioToggle( &Led4 ); | |||||
| // Send the next PING frame | |||||
| Buffer[0] = 'P'; | |||||
| Buffer[1] = 'I'; | |||||
| Buffer[2] = 'N'; | |||||
| Buffer[3] = 'G'; | |||||
| // We fill the buffer with numbers for the payload | |||||
| for( i = 4; i < BufferSize; i++ ) | |||||
| { | |||||
| Buffer[i] = i - 4; | |||||
| } | |||||
| DelayMs( 1 ); | |||||
| Radio.Send( Buffer, BufferSize ); | |||||
| } | |||||
| else if( strncmp( ( const char* )Buffer, ( const char* )PingMsg, 4 ) == 0 ) | |||||
| { // A master already exists then become a slave | |||||
| isMaster = false; | |||||
| GpioToggle( &Led3 ); // Set LED off | |||||
| Radio.Rx( RX_TIMEOUT_VALUE ); | |||||
| } | |||||
| else // valid reception but neither a PING or a PONG message | |||||
| { // Set device as master ans start again | |||||
| isMaster = true; | |||||
| Radio.Rx( RX_TIMEOUT_VALUE ); | |||||
| } | |||||
| } | |||||
| } | |||||
| else | |||||
| { | |||||
| if( BufferSize > 0 ) | |||||
| { | |||||
| if( strncmp( ( const char* )Buffer, ( const char* )PingMsg, 4 ) == 0 ) | |||||
| { | |||||
| // Indicates on a LED that the received frame is a PING | |||||
| GpioToggle( &Led4 ); | |||||
| // Send the reply to the PONG string | |||||
| Buffer[0] = 'P'; | |||||
| Buffer[1] = 'O'; | |||||
| Buffer[2] = 'N'; | |||||
| Buffer[3] = 'G'; | |||||
| // We fill the buffer with numbers for the payload | |||||
| for( i = 4; i < BufferSize; i++ ) | |||||
| { | |||||
| Buffer[i] = i - 4; | |||||
| } | |||||
| DelayMs( 1 ); | |||||
| Radio.Send( Buffer, BufferSize ); | |||||
| } | |||||
| else // valid reception but not a PING as expected | |||||
| { // Set device as master and start again | |||||
| isMaster = true; | |||||
| Radio.Rx( RX_TIMEOUT_VALUE ); | |||||
| } | |||||
| } | |||||
| } | |||||
| State = LOWPOWER; | |||||
| break; | |||||
| case TX: | |||||
| // Indicates on a LED that we have sent a PING [Master] | |||||
| // Indicates on a LED that we have sent a PONG [Slave] | |||||
| GpioToggle( &Led3 ); | |||||
| Radio.Rx( RX_TIMEOUT_VALUE ); | |||||
| State = LOWPOWER; | |||||
| break; | |||||
| case RX_TIMEOUT: | |||||
| case RX_ERROR: | |||||
| if( isMaster == true ) | |||||
| { | |||||
| // Send the next PING frame | |||||
| Buffer[0] = 'P'; | |||||
| Buffer[1] = 'I'; | |||||
| Buffer[2] = 'N'; | |||||
| Buffer[3] = 'G'; | |||||
| for( i = 4; i < BufferSize; i++ ) | |||||
| { | |||||
| Buffer[i] = i - 4; | |||||
| } | |||||
| DelayMs( 1 ); | |||||
| Radio.Send( Buffer, BufferSize ); | |||||
| } | |||||
| else | |||||
| { | |||||
| Radio.Rx( RX_TIMEOUT_VALUE ); | |||||
| } | |||||
| State = LOWPOWER; | |||||
| break; | |||||
| case TX_TIMEOUT: | |||||
| Radio.Rx( RX_TIMEOUT_VALUE ); | |||||
| State = LOWPOWER; | |||||
| break; | |||||
| case LOWPOWER: | |||||
| default: | |||||
| // Set low power | |||||
| break; | |||||
| } | |||||
| BoardLowPowerHandler( ); | |||||
| } | |||||
| } | |||||
| void OnTxDone( void ) | |||||
| { | |||||
| Radio.Sleep( ); | |||||
| State = TX; | |||||
| } | |||||
| void OnRxDone( uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr ) | |||||
| { | |||||
| Radio.Sleep( ); | |||||
| BufferSize = size; | |||||
| memcpy( Buffer, payload, BufferSize ); | |||||
| RssiValue = rssi; | |||||
| SnrValue = snr; | |||||
| State = RX; | |||||
| } | |||||
| void OnTxTimeout( void ) | |||||
| { | |||||
| Radio.Sleep( ); | |||||
| State = TX_TIMEOUT; | |||||
| } | |||||
| void OnRxTimeout( void ) | |||||
| { | |||||
| Radio.Sleep( ); | |||||
| State = RX_TIMEOUT; | |||||
| } | |||||
| void OnRxError( void ) | |||||
| { | |||||
| Radio.Sleep( ); | |||||
| State = RX_ERROR; | |||||
| } | |||||
| @@ -1,361 +1,361 @@ | |||||
| /*! | |||||
| * \file main.c | |||||
| * | |||||
| * \brief Ping-Pong implementation | |||||
| * | |||||
| * \copyright Revised BSD License, see section \ref LICENSE. | |||||
| * | |||||
| * \code | |||||
| * ______ _ | |||||
| * / _____) _ | | | |||||
| * ( (____ _____ ____ _| |_ _____ ____| |__ | |||||
| * \____ \| ___ | (_ _) ___ |/ ___) _ \ | |||||
| * _____) ) ____| | | || |_| ____( (___| | | | | |||||
| * (______/|_____)_|_|_| \__)_____)\____)_| |_| | |||||
| * (C)2013-2017 Semtech | |||||
| * | |||||
| * \endcode | |||||
| * | |||||
| * \author Miguel Luis ( Semtech ) | |||||
| * | |||||
| * \author Gregory Cristian ( Semtech ) | |||||
| */ | |||||
| #include <string.h> | |||||
| #include "board.h" | |||||
| #include "gpio.h" | |||||
| #include "delay.h" | |||||
| #include "timer.h" | |||||
| #include "radio.h" | |||||
| #if defined( REGION_AS923 ) | |||||
| #define RF_FREQUENCY 923000000 // Hz | |||||
| #elif defined( REGION_AU915 ) | |||||
| #define RF_FREQUENCY 915000000 // Hz | |||||
| #elif defined( REGION_CN779 ) | |||||
| #define RF_FREQUENCY 779000000 // Hz | |||||
| #elif defined( REGION_EU868 ) | |||||
| #define RF_FREQUENCY 868000000 // Hz | |||||
| #elif defined( REGION_KR920 ) | |||||
| #define RF_FREQUENCY 920000000 // Hz | |||||
| #elif defined( REGION_IN865 ) | |||||
| #define RF_FREQUENCY 865000000 // Hz | |||||
| #elif defined( REGION_US915 ) | |||||
| #define RF_FREQUENCY 915000000 // Hz | |||||
| #elif defined( REGION_RU864 ) | |||||
| #define RF_FREQUENCY 864000000 // Hz | |||||
| #else | |||||
| #error "Please define a frequency band in the compiler options." | |||||
| #endif | |||||
| #define TX_OUTPUT_POWER 14 // dBm | |||||
| #if defined( USE_MODEM_LORA ) | |||||
| #define LORA_BANDWIDTH 0 // [0: 125 kHz, | |||||
| // 1: 250 kHz, | |||||
| // 2: 500 kHz, | |||||
| // 3: Reserved] | |||||
| #define LORA_SPREADING_FACTOR 7 // [SF7..SF12] | |||||
| #define LORA_CODINGRATE 1 // [1: 4/5, | |||||
| // 2: 4/6, | |||||
| // 3: 4/7, | |||||
| // 4: 4/8] | |||||
| #define LORA_PREAMBLE_LENGTH 8 // Same for Tx and Rx | |||||
| #define LORA_SYMBOL_TIMEOUT 5 // Symbols | |||||
| #define LORA_FIX_LENGTH_PAYLOAD_ON false | |||||
| #define LORA_IQ_INVERSION_ON false | |||||
| #elif defined( USE_MODEM_FSK ) | |||||
| #define FSK_FDEV 25000 // Hz | |||||
| #define FSK_DATARATE 50000 // bps | |||||
| #define FSK_BANDWIDTH 50000 // Hz | |||||
| #define FSK_AFC_BANDWIDTH 83333 // Hz | |||||
| #define FSK_PREAMBLE_LENGTH 5 // Same for Tx and Rx | |||||
| #define FSK_FIX_LENGTH_PAYLOAD_ON false | |||||
| #else | |||||
| #error "Please define a modem in the compiler options." | |||||
| #endif | |||||
| typedef enum | |||||
| { | |||||
| LOWPOWER, | |||||
| RX, | |||||
| RX_TIMEOUT, | |||||
| RX_ERROR, | |||||
| TX, | |||||
| TX_TIMEOUT, | |||||
| }States_t; | |||||
| #define RX_TIMEOUT_VALUE 1000 | |||||
| #define BUFFER_SIZE 64 // Define the payload size here | |||||
| const uint8_t PingMsg[] = "PING"; | |||||
| const uint8_t PongMsg[] = "PONG"; | |||||
| uint16_t BufferSize = BUFFER_SIZE; | |||||
| uint8_t Buffer[BUFFER_SIZE]; | |||||
| States_t State = LOWPOWER; | |||||
| int8_t RssiValue = 0; | |||||
| int8_t SnrValue = 0; | |||||
| /*! | |||||
| * Radio events function pointer | |||||
| */ | |||||
| static RadioEvents_t RadioEvents; | |||||
| /*! | |||||
| * LED GPIO pins objects | |||||
| */ | |||||
| extern Gpio_t Led3; | |||||
| extern Gpio_t Led4; | |||||
| /*! | |||||
| * \brief Function to be executed on Radio Tx Done event | |||||
| */ | |||||
| void OnTxDone( void ); | |||||
| /*! | |||||
| * \brief Function to be executed on Radio Rx Done event | |||||
| */ | |||||
| void OnRxDone( uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr ); | |||||
| /*! | |||||
| * \brief Function executed on Radio Tx Timeout event | |||||
| */ | |||||
| void OnTxTimeout( void ); | |||||
| /*! | |||||
| * \brief Function executed on Radio Rx Timeout event | |||||
| */ | |||||
| void OnRxTimeout( void ); | |||||
| /*! | |||||
| * \brief Function executed on Radio Rx Error event | |||||
| */ | |||||
| void OnRxError( void ); | |||||
| /** | |||||
| * Main application entry point. | |||||
| */ | |||||
| int main( void ) | |||||
| { | |||||
| bool isMaster = true; | |||||
| uint8_t i; | |||||
| // Target board initialization | |||||
| BoardInitMcu( ); | |||||
| BoardInitPeriph( ); | |||||
| // Radio initialization | |||||
| RadioEvents.TxDone = OnTxDone; | |||||
| RadioEvents.RxDone = OnRxDone; | |||||
| RadioEvents.TxTimeout = OnTxTimeout; | |||||
| RadioEvents.RxTimeout = OnRxTimeout; | |||||
| RadioEvents.RxError = OnRxError; | |||||
| Radio.Init( &RadioEvents ); | |||||
| Radio.SetChannel( RF_FREQUENCY ); | |||||
| #if defined( USE_MODEM_LORA ) | |||||
| Radio.SetTxConfig( MODEM_LORA, TX_OUTPUT_POWER, 0, LORA_BANDWIDTH, | |||||
| LORA_SPREADING_FACTOR, LORA_CODINGRATE, | |||||
| LORA_PREAMBLE_LENGTH, LORA_FIX_LENGTH_PAYLOAD_ON, | |||||
| true, 0, 0, LORA_IQ_INVERSION_ON, 3000 ); | |||||
| Radio.SetRxConfig( MODEM_LORA, LORA_BANDWIDTH, LORA_SPREADING_FACTOR, | |||||
| LORA_CODINGRATE, 0, LORA_PREAMBLE_LENGTH, | |||||
| LORA_SYMBOL_TIMEOUT, LORA_FIX_LENGTH_PAYLOAD_ON, | |||||
| 0, true, 0, 0, LORA_IQ_INVERSION_ON, true ); | |||||
| Radio.SetMaxPayloadLength( MODEM_LORA, BUFFER_SIZE ); | |||||
| #elif defined( USE_MODEM_FSK ) | |||||
| Radio.SetTxConfig( MODEM_FSK, TX_OUTPUT_POWER, FSK_FDEV, 0, | |||||
| FSK_DATARATE, 0, | |||||
| FSK_PREAMBLE_LENGTH, FSK_FIX_LENGTH_PAYLOAD_ON, | |||||
| true, 0, 0, 0, 3000 ); | |||||
| Radio.SetRxConfig( MODEM_FSK, FSK_BANDWIDTH, FSK_DATARATE, | |||||
| 0, FSK_AFC_BANDWIDTH, FSK_PREAMBLE_LENGTH, | |||||
| 0, FSK_FIX_LENGTH_PAYLOAD_ON, 0, true, | |||||
| 0, 0,false, true ); | |||||
| Radio.SetMaxPayloadLength( MODEM_FSK, BUFFER_SIZE ); | |||||
| #else | |||||
| #error "Please define a frequency band in the compiler options." | |||||
| #endif | |||||
| Radio.Rx( RX_TIMEOUT_VALUE ); | |||||
| while( 1 ) | |||||
| { | |||||
| switch( State ) | |||||
| { | |||||
| case RX: | |||||
| if( isMaster == true ) | |||||
| { | |||||
| if( BufferSize > 0 ) | |||||
| { | |||||
| if( strncmp( ( const char* )Buffer, ( const char* )PongMsg, 4 ) == 0 ) | |||||
| { | |||||
| // Indicates on a LED that the received frame is a PONG | |||||
| GpioToggle( &Led4 ); | |||||
| // Send the next PING frame | |||||
| Buffer[0] = 'P'; | |||||
| Buffer[1] = 'I'; | |||||
| Buffer[2] = 'N'; | |||||
| Buffer[3] = 'G'; | |||||
| // We fill the buffer with numbers for the payload | |||||
| for( i = 4; i < BufferSize; i++ ) | |||||
| { | |||||
| Buffer[i] = i - 4; | |||||
| } | |||||
| DelayMs( 1 ); | |||||
| Radio.Send( Buffer, BufferSize ); | |||||
| } | |||||
| else if( strncmp( ( const char* )Buffer, ( const char* )PingMsg, 4 ) == 0 ) | |||||
| { // A master already exists then become a slave | |||||
| isMaster = false; | |||||
| GpioToggle( &Led3 ); // Set LED off | |||||
| Radio.Rx( RX_TIMEOUT_VALUE ); | |||||
| } | |||||
| else // valid reception but neither a PING or a PONG message | |||||
| { // Set device as master ans start again | |||||
| isMaster = true; | |||||
| Radio.Rx( RX_TIMEOUT_VALUE ); | |||||
| } | |||||
| } | |||||
| } | |||||
| else | |||||
| { | |||||
| if( BufferSize > 0 ) | |||||
| { | |||||
| if( strncmp( ( const char* )Buffer, ( const char* )PingMsg, 4 ) == 0 ) | |||||
| { | |||||
| // Indicates on a LED that the received frame is a PING | |||||
| GpioToggle( &Led4 ); | |||||
| // Send the reply to the PONG string | |||||
| Buffer[0] = 'P'; | |||||
| Buffer[1] = 'O'; | |||||
| Buffer[2] = 'N'; | |||||
| Buffer[3] = 'G'; | |||||
| // We fill the buffer with numbers for the payload | |||||
| for( i = 4; i < BufferSize; i++ ) | |||||
| { | |||||
| Buffer[i] = i - 4; | |||||
| } | |||||
| DelayMs( 1 ); | |||||
| Radio.Send( Buffer, BufferSize ); | |||||
| } | |||||
| else // valid reception but not a PING as expected | |||||
| { // Set device as master and start again | |||||
| isMaster = true; | |||||
| Radio.Rx( RX_TIMEOUT_VALUE ); | |||||
| } | |||||
| } | |||||
| } | |||||
| State = LOWPOWER; | |||||
| break; | |||||
| case TX: | |||||
| // Indicates on a LED that we have sent a PING [Master] | |||||
| // Indicates on a LED that we have sent a PONG [Slave] | |||||
| GpioToggle( &Led3 ); | |||||
| Radio.Rx( RX_TIMEOUT_VALUE ); | |||||
| State = LOWPOWER; | |||||
| break; | |||||
| case RX_TIMEOUT: | |||||
| case RX_ERROR: | |||||
| if( isMaster == true ) | |||||
| { | |||||
| // Send the next PING frame | |||||
| Buffer[0] = 'P'; | |||||
| Buffer[1] = 'I'; | |||||
| Buffer[2] = 'N'; | |||||
| Buffer[3] = 'G'; | |||||
| for( i = 4; i < BufferSize; i++ ) | |||||
| { | |||||
| Buffer[i] = i - 4; | |||||
| } | |||||
| DelayMs( 1 ); | |||||
| Radio.Send( Buffer, BufferSize ); | |||||
| } | |||||
| else | |||||
| { | |||||
| Radio.Rx( RX_TIMEOUT_VALUE ); | |||||
| } | |||||
| State = LOWPOWER; | |||||
| break; | |||||
| case TX_TIMEOUT: | |||||
| Radio.Rx( RX_TIMEOUT_VALUE ); | |||||
| State = LOWPOWER; | |||||
| break; | |||||
| case LOWPOWER: | |||||
| default: | |||||
| // Set low power | |||||
| break; | |||||
| } | |||||
| BoardLowPowerHandler( ); | |||||
| } | |||||
| } | |||||
| void OnTxDone( void ) | |||||
| { | |||||
| Radio.Sleep( ); | |||||
| State = TX; | |||||
| } | |||||
| void OnRxDone( uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr ) | |||||
| { | |||||
| Radio.Sleep( ); | |||||
| BufferSize = size; | |||||
| memcpy( Buffer, payload, BufferSize ); | |||||
| RssiValue = rssi; | |||||
| SnrValue = snr; | |||||
| State = RX; | |||||
| } | |||||
| void OnTxTimeout( void ) | |||||
| { | |||||
| Radio.Sleep( ); | |||||
| State = TX_TIMEOUT; | |||||
| } | |||||
| void OnRxTimeout( void ) | |||||
| { | |||||
| Radio.Sleep( ); | |||||
| State = RX_TIMEOUT; | |||||
| } | |||||
| void OnRxError( void ) | |||||
| { | |||||
| Radio.Sleep( ); | |||||
| State = RX_ERROR; | |||||
| } | |||||
| /*! | |||||
| * \file main.c | |||||
| * | |||||
| * \brief Ping-Pong implementation | |||||
| * | |||||
| * \copyright Revised BSD License, see section \ref LICENSE. | |||||
| * | |||||
| * \code | |||||
| * ______ _ | |||||
| * / _____) _ | | | |||||
| * ( (____ _____ ____ _| |_ _____ ____| |__ | |||||
| * \____ \| ___ | (_ _) ___ |/ ___) _ \ | |||||
| * _____) ) ____| | | || |_| ____( (___| | | | | |||||
| * (______/|_____)_|_|_| \__)_____)\____)_| |_| | |||||
| * (C)2013-2017 Semtech | |||||
| * | |||||
| * \endcode | |||||
| * | |||||
| * \author Miguel Luis ( Semtech ) | |||||
| * | |||||
| * \author Gregory Cristian ( Semtech ) | |||||
| */ | |||||
| #include <string.h> | |||||
| #include "board.h" | |||||
| #include "gpio.h" | |||||
| #include "delay.h" | |||||
| #include "timer.h" | |||||
| #include "radio.h" | |||||
| #if defined( REGION_AS923 ) | |||||
| #define RF_FREQUENCY 923000000 // Hz | |||||
| #elif defined( REGION_AU915 ) | |||||
| #define RF_FREQUENCY 915000000 // Hz | |||||
| #elif defined( REGION_CN779 ) | |||||
| #define RF_FREQUENCY 779000000 // Hz | |||||
| #elif defined( REGION_EU868 ) | |||||
| #define RF_FREQUENCY 868000000 // Hz | |||||
| #elif defined( REGION_KR920 ) | |||||
| #define RF_FREQUENCY 920000000 // Hz | |||||
| #elif defined( REGION_IN865 ) | |||||
| #define RF_FREQUENCY 865000000 // Hz | |||||
| #elif defined( REGION_US915 ) | |||||
| #define RF_FREQUENCY 915000000 // Hz | |||||
| #elif defined( REGION_RU864 ) | |||||
| #define RF_FREQUENCY 864000000 // Hz | |||||
| #else | |||||
| #error "Please define a frequency band in the compiler options." | |||||
| #endif | |||||
| #define TX_OUTPUT_POWER 14 // dBm | |||||
| #if defined( USE_MODEM_LORA ) | |||||
| #define LORA_BANDWIDTH 0 // [0: 125 kHz, | |||||
| // 1: 250 kHz, | |||||
| // 2: 500 kHz, | |||||
| // 3: Reserved] | |||||
| #define LORA_SPREADING_FACTOR 7 // [SF7..SF12] | |||||
| #define LORA_CODINGRATE 1 // [1: 4/5, | |||||
| // 2: 4/6, | |||||
| // 3: 4/7, | |||||
| // 4: 4/8] | |||||
| #define LORA_PREAMBLE_LENGTH 8 // Same for Tx and Rx | |||||
| #define LORA_SYMBOL_TIMEOUT 5 // Symbols | |||||
| #define LORA_FIX_LENGTH_PAYLOAD_ON false | |||||
| #define LORA_IQ_INVERSION_ON false | |||||
| #elif defined( USE_MODEM_FSK ) | |||||
| #define FSK_FDEV 25000 // Hz | |||||
| #define FSK_DATARATE 50000 // bps | |||||
| #define FSK_BANDWIDTH 50000 // Hz | |||||
| #define FSK_AFC_BANDWIDTH 83333 // Hz | |||||
| #define FSK_PREAMBLE_LENGTH 5 // Same for Tx and Rx | |||||
| #define FSK_FIX_LENGTH_PAYLOAD_ON false | |||||
| #else | |||||
| #error "Please define a modem in the compiler options." | |||||
| #endif | |||||
| typedef enum | |||||
| { | |||||
| LOWPOWER, | |||||
| RX, | |||||
| RX_TIMEOUT, | |||||
| RX_ERROR, | |||||
| TX, | |||||
| TX_TIMEOUT, | |||||
| }States_t; | |||||
| #define RX_TIMEOUT_VALUE 1000 | |||||
| #define BUFFER_SIZE 64 // Define the payload size here | |||||
| const uint8_t PingMsg[] = "PING"; | |||||
| const uint8_t PongMsg[] = "PONG"; | |||||
| uint16_t BufferSize = BUFFER_SIZE; | |||||
| uint8_t Buffer[BUFFER_SIZE]; | |||||
| States_t State = LOWPOWER; | |||||
| int8_t RssiValue = 0; | |||||
| int8_t SnrValue = 0; | |||||
| /*! | |||||
| * Radio events function pointer | |||||
| */ | |||||
| static RadioEvents_t RadioEvents; | |||||
| /*! | |||||
| * LED GPIO pins objects | |||||
| */ | |||||
| extern Gpio_t Led3; | |||||
| extern Gpio_t Led4; | |||||
| /*! | |||||
| * \brief Function to be executed on Radio Tx Done event | |||||
| */ | |||||
| void OnTxDone( void ); | |||||
| /*! | |||||
| * \brief Function to be executed on Radio Rx Done event | |||||
| */ | |||||
| void OnRxDone( uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr ); | |||||
| /*! | |||||
| * \brief Function executed on Radio Tx Timeout event | |||||
| */ | |||||
| void OnTxTimeout( void ); | |||||
| /*! | |||||
| * \brief Function executed on Radio Rx Timeout event | |||||
| */ | |||||
| void OnRxTimeout( void ); | |||||
| /*! | |||||
| * \brief Function executed on Radio Rx Error event | |||||
| */ | |||||
| void OnRxError( void ); | |||||
| /** | |||||
| * Main application entry point. | |||||
| */ | |||||
| int main( void ) | |||||
| { | |||||
| bool isMaster = true; | |||||
| uint8_t i; | |||||
| // Target board initialization | |||||
| BoardInitMcu( ); | |||||
| BoardInitPeriph( ); | |||||
| // Radio initialization | |||||
| RadioEvents.TxDone = OnTxDone; | |||||
| RadioEvents.RxDone = OnRxDone; | |||||
| RadioEvents.TxTimeout = OnTxTimeout; | |||||
| RadioEvents.RxTimeout = OnRxTimeout; | |||||
| RadioEvents.RxError = OnRxError; | |||||
| Radio.Init( &RadioEvents ); | |||||
| Radio.SetChannel( RF_FREQUENCY ); | |||||
| #if defined( USE_MODEM_LORA ) | |||||
| Radio.SetTxConfig( MODEM_LORA, TX_OUTPUT_POWER, 0, LORA_BANDWIDTH, | |||||
| LORA_SPREADING_FACTOR, LORA_CODINGRATE, | |||||
| LORA_PREAMBLE_LENGTH, LORA_FIX_LENGTH_PAYLOAD_ON, | |||||
| true, 0, 0, LORA_IQ_INVERSION_ON, 3000 ); | |||||
| Radio.SetRxConfig( MODEM_LORA, LORA_BANDWIDTH, LORA_SPREADING_FACTOR, | |||||
| LORA_CODINGRATE, 0, LORA_PREAMBLE_LENGTH, | |||||
| LORA_SYMBOL_TIMEOUT, LORA_FIX_LENGTH_PAYLOAD_ON, | |||||
| 0, true, 0, 0, LORA_IQ_INVERSION_ON, true ); | |||||
| Radio.SetMaxPayloadLength( MODEM_LORA, BUFFER_SIZE ); | |||||
| #elif defined( USE_MODEM_FSK ) | |||||
| Radio.SetTxConfig( MODEM_FSK, TX_OUTPUT_POWER, FSK_FDEV, 0, | |||||
| FSK_DATARATE, 0, | |||||
| FSK_PREAMBLE_LENGTH, FSK_FIX_LENGTH_PAYLOAD_ON, | |||||
| true, 0, 0, 0, 3000 ); | |||||
| Radio.SetRxConfig( MODEM_FSK, FSK_BANDWIDTH, FSK_DATARATE, | |||||
| 0, FSK_AFC_BANDWIDTH, FSK_PREAMBLE_LENGTH, | |||||
| 0, FSK_FIX_LENGTH_PAYLOAD_ON, 0, true, | |||||
| 0, 0,false, true ); | |||||
| Radio.SetMaxPayloadLength( MODEM_FSK, BUFFER_SIZE ); | |||||
| #else | |||||
| #error "Please define a frequency band in the compiler options." | |||||
| #endif | |||||
| Radio.Rx( RX_TIMEOUT_VALUE ); | |||||
| while( 1 ) | |||||
| { | |||||
| switch( State ) | |||||
| { | |||||
| case RX: | |||||
| if( isMaster == true ) | |||||
| { | |||||
| if( BufferSize > 0 ) | |||||
| { | |||||
| if( strncmp( ( const char* )Buffer, ( const char* )PongMsg, 4 ) == 0 ) | |||||
| { | |||||
| // Indicates on a LED that the received frame is a PONG | |||||
| GpioToggle( &Led4 ); | |||||
| // Send the next PING frame | |||||
| Buffer[0] = 'P'; | |||||
| Buffer[1] = 'I'; | |||||
| Buffer[2] = 'N'; | |||||
| Buffer[3] = 'G'; | |||||
| // We fill the buffer with numbers for the payload | |||||
| for( i = 4; i < BufferSize; i++ ) | |||||
| { | |||||
| Buffer[i] = i - 4; | |||||
| } | |||||
| DelayMs( 1 ); | |||||
| Radio.Send( Buffer, BufferSize ); | |||||
| } | |||||
| else if( strncmp( ( const char* )Buffer, ( const char* )PingMsg, 4 ) == 0 ) | |||||
| { // A master already exists then become a slave | |||||
| isMaster = false; | |||||
| GpioToggle( &Led3 ); // Set LED off | |||||
| Radio.Rx( RX_TIMEOUT_VALUE ); | |||||
| } | |||||
| else // valid reception but neither a PING or a PONG message | |||||
| { // Set device as master ans start again | |||||
| isMaster = true; | |||||
| Radio.Rx( RX_TIMEOUT_VALUE ); | |||||
| } | |||||
| } | |||||
| } | |||||
| else | |||||
| { | |||||
| if( BufferSize > 0 ) | |||||
| { | |||||
| if( strncmp( ( const char* )Buffer, ( const char* )PingMsg, 4 ) == 0 ) | |||||
| { | |||||
| // Indicates on a LED that the received frame is a PING | |||||
| GpioToggle( &Led4 ); | |||||
| // Send the reply to the PONG string | |||||
| Buffer[0] = 'P'; | |||||
| Buffer[1] = 'O'; | |||||
| Buffer[2] = 'N'; | |||||
| Buffer[3] = 'G'; | |||||
| // We fill the buffer with numbers for the payload | |||||
| for( i = 4; i < BufferSize; i++ ) | |||||
| { | |||||
| Buffer[i] = i - 4; | |||||
| } | |||||
| DelayMs( 1 ); | |||||
| Radio.Send( Buffer, BufferSize ); | |||||
| } | |||||
| else // valid reception but not a PING as expected | |||||
| { // Set device as master and start again | |||||
| isMaster = true; | |||||
| Radio.Rx( RX_TIMEOUT_VALUE ); | |||||
| } | |||||
| } | |||||
| } | |||||
| State = LOWPOWER; | |||||
| break; | |||||
| case TX: | |||||
| // Indicates on a LED that we have sent a PING [Master] | |||||
| // Indicates on a LED that we have sent a PONG [Slave] | |||||
| GpioToggle( &Led3 ); | |||||
| Radio.Rx( RX_TIMEOUT_VALUE ); | |||||
| State = LOWPOWER; | |||||
| break; | |||||
| case RX_TIMEOUT: | |||||
| case RX_ERROR: | |||||
| if( isMaster == true ) | |||||
| { | |||||
| // Send the next PING frame | |||||
| Buffer[0] = 'P'; | |||||
| Buffer[1] = 'I'; | |||||
| Buffer[2] = 'N'; | |||||
| Buffer[3] = 'G'; | |||||
| for( i = 4; i < BufferSize; i++ ) | |||||
| { | |||||
| Buffer[i] = i - 4; | |||||
| } | |||||
| DelayMs( 1 ); | |||||
| Radio.Send( Buffer, BufferSize ); | |||||
| } | |||||
| else | |||||
| { | |||||
| Radio.Rx( RX_TIMEOUT_VALUE ); | |||||
| } | |||||
| State = LOWPOWER; | |||||
| break; | |||||
| case TX_TIMEOUT: | |||||
| Radio.Rx( RX_TIMEOUT_VALUE ); | |||||
| State = LOWPOWER; | |||||
| break; | |||||
| case LOWPOWER: | |||||
| default: | |||||
| // Set low power | |||||
| break; | |||||
| } | |||||
| BoardLowPowerHandler( ); | |||||
| } | |||||
| } | |||||
| void OnTxDone( void ) | |||||
| { | |||||
| Radio.Sleep( ); | |||||
| State = TX; | |||||
| } | |||||
| void OnRxDone( uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr ) | |||||
| { | |||||
| Radio.Sleep( ); | |||||
| BufferSize = size; | |||||
| memcpy( Buffer, payload, BufferSize ); | |||||
| RssiValue = rssi; | |||||
| SnrValue = snr; | |||||
| State = RX; | |||||
| } | |||||
| void OnTxTimeout( void ) | |||||
| { | |||||
| Radio.Sleep( ); | |||||
| State = TX_TIMEOUT; | |||||
| } | |||||
| void OnRxTimeout( void ) | |||||
| { | |||||
| Radio.Sleep( ); | |||||
| State = RX_TIMEOUT; | |||||
| } | |||||
| void OnRxError( void ) | |||||
| { | |||||
| Radio.Sleep( ); | |||||
| State = RX_ERROR; | |||||
| } | |||||
| @@ -1,172 +1,172 @@ | |||||
| /*! | |||||
| * \file main.c | |||||
| * | |||||
| * \brief Radio sensitivity test | |||||
| * | |||||
| * \remark When LED1 stops blinking LoRa packets aren't received any more and | |||||
| * the sensitivity level has been reached. | |||||
| * By reading the RF generator output power we can estimate the board | |||||
| * sensitivity | |||||
| * | |||||
| * \copyright Revised BSD License, see section \ref LICENSE. | |||||
| * | |||||
| * \code | |||||
| * ______ _ | |||||
| * / _____) _ | | | |||||
| * ( (____ _____ ____ _| |_ _____ ____| |__ | |||||
| * \____ \| ___ | (_ _) ___ |/ ___) _ \ | |||||
| * _____) ) ____| | | || |_| ____( (___| | | | | |||||
| * (______/|_____)_|_|_| \__)_____)\____)_| |_| | |||||
| * (C)2013-2017 Semtech | |||||
| * | |||||
| * \endcode | |||||
| * | |||||
| * \author Miguel Luis ( Semtech ) | |||||
| * | |||||
| * \author Gregory Cristian ( Semtech ) | |||||
| */ | |||||
| #include "board.h" | |||||
| #include "gpio.h" | |||||
| #include "timer.h" | |||||
| #include "radio.h" | |||||
| #if defined( REGION_AS923 ) | |||||
| #define RF_FREQUENCY 923000000 // Hz | |||||
| #elif defined( REGION_AU915 ) | |||||
| #define RF_FREQUENCY 915000000 // Hz | |||||
| #elif defined( REGION_CN470 ) | |||||
| #define RF_FREQUENCY 470000000 // Hz | |||||
| #elif defined( REGION_CN779 ) | |||||
| #define RF_FREQUENCY 779000000 // Hz | |||||
| #elif defined( REGION_EU433 ) | |||||
| #define RF_FREQUENCY 433000000 // Hz | |||||
| #elif defined( REGION_EU868 ) | |||||
| #define RF_FREQUENCY 868000000 // Hz | |||||
| #elif defined( REGION_KR920 ) | |||||
| #define RF_FREQUENCY 920000000 // Hz | |||||
| #elif defined( REGION_IN865 ) | |||||
| #define RF_FREQUENCY 865000000 // Hz | |||||
| #elif defined( REGION_US915 ) | |||||
| #define RF_FREQUENCY 915000000 // Hz | |||||
| #elif defined( REGION_RU864 ) | |||||
| #define RF_FREQUENCY 864000000 // Hz | |||||
| #else | |||||
| #error "Please define a frequency band in the compiler options." | |||||
| #endif | |||||
| #if defined( USE_MODEM_LORA ) | |||||
| #define LORA_BANDWIDTH 0 // [0: 125 kHz, | |||||
| // 1: 250 kHz, | |||||
| // 2: 500 kHz, | |||||
| // 3: Reserved] | |||||
| #define LORA_SPREADING_FACTOR 10 // [SF7..SF12] | |||||
| #define LORA_CODINGRATE 1 // [1: 4/5, | |||||
| // 2: 4/6, | |||||
| // 3: 4/7, | |||||
| // 4: 4/8] | |||||
| #define LORA_SYMBOL_TIMEOUT 5 // Symbols | |||||
| #define LORA_PREAMBLE_LENGTH 8 // Same for Tx and Rx | |||||
| #define LORA_FIX_LENGTH_PAYLOAD_ON false | |||||
| #define LORA_IQ_INVERSION_ON false | |||||
| #elif defined( USE_MODEM_FSK ) | |||||
| #define FSK_DATARATE 50000 // bps | |||||
| #define FSK_BANDWIDTH 50000 // Hz | |||||
| #define FSK_AFC_BANDWIDTH 83333 // Hz | |||||
| #define FSK_PREAMBLE_LENGTH 5 // Same for Tx and Rx | |||||
| #define FSK_FIX_LENGTH_PAYLOAD_ON false | |||||
| #else | |||||
| #error "Please define a modem in the compiler options." | |||||
| #endif | |||||
| /*! | |||||
| * Radio events function pointer | |||||
| */ | |||||
| static RadioEvents_t RadioEvents; | |||||
| /*! | |||||
| * LED GPIO pins objects | |||||
| */ | |||||
| extern Gpio_t Led1; | |||||
| /*! | |||||
| * \brief Function to be executed on Radio Rx Done event | |||||
| */ | |||||
| void OnRxDone( uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr ); | |||||
| /*! | |||||
| * Main application entry point. | |||||
| */ | |||||
| int main( void ) | |||||
| { | |||||
| // Target board initialization | |||||
| BoardInitMcu( ); | |||||
| BoardInitPeriph( ); | |||||
| // Radio initialization | |||||
| RadioEvents.RxDone = OnRxDone; | |||||
| Radio.Init( &RadioEvents ); | |||||
| Radio.SetChannel( RF_FREQUENCY ); | |||||
| #if defined( USE_MODEM_LORA ) | |||||
| Radio.SetRxConfig( MODEM_LORA, LORA_BANDWIDTH, LORA_SPREADING_FACTOR, | |||||
| LORA_CODINGRATE, 0, LORA_PREAMBLE_LENGTH, | |||||
| LORA_SYMBOL_TIMEOUT, LORA_FIX_LENGTH_PAYLOAD_ON, | |||||
| 0, true, 0, 0, LORA_IQ_INVERSION_ON, true ); | |||||
| Radio.SetMaxPayloadLength( MODEM_LORA, 255 ); | |||||
| #elif defined( USE_MODEM_FSK ) | |||||
| Radio.SetRxConfig( MODEM_FSK, FSK_BANDWIDTH, FSK_DATARATE, | |||||
| 0, FSK_AFC_BANDWIDTH, FSK_PREAMBLE_LENGTH, | |||||
| 0, FSK_FIX_LENGTH_PAYLOAD_ON, 0, true, | |||||
| 0, 0, false, true ); | |||||
| Radio.SetMaxPayloadLength( MODEM_FSK, 255 ); | |||||
| #else | |||||
| #error "Please define a frequency band in the compiler options." | |||||
| #endif | |||||
| Radio.Rx( 0 ); // Continuous Rx | |||||
| while( 1 ) | |||||
| { | |||||
| BoardLowPowerHandler( ); | |||||
| } | |||||
| } | |||||
| void OnRxDone( uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr ) | |||||
| { | |||||
| static uint8_t ledState = 1; | |||||
| // Toggle LED 1 | |||||
| ledState ^= 1; | |||||
| GpioWrite( &Led1, ledState ); | |||||
| } | |||||
| /*! | |||||
| * \file main.c | |||||
| * | |||||
| * \brief Radio sensitivity test | |||||
| * | |||||
| * \remark When LED1 stops blinking LoRa packets aren't received any more and | |||||
| * the sensitivity level has been reached. | |||||
| * By reading the RF generator output power we can estimate the board | |||||
| * sensitivity | |||||
| * | |||||
| * \copyright Revised BSD License, see section \ref LICENSE. | |||||
| * | |||||
| * \code | |||||
| * ______ _ | |||||
| * / _____) _ | | | |||||
| * ( (____ _____ ____ _| |_ _____ ____| |__ | |||||
| * \____ \| ___ | (_ _) ___ |/ ___) _ \ | |||||
| * _____) ) ____| | | || |_| ____( (___| | | | | |||||
| * (______/|_____)_|_|_| \__)_____)\____)_| |_| | |||||
| * (C)2013-2017 Semtech | |||||
| * | |||||
| * \endcode | |||||
| * | |||||
| * \author Miguel Luis ( Semtech ) | |||||
| * | |||||
| * \author Gregory Cristian ( Semtech ) | |||||
| */ | |||||
| #include "board.h" | |||||
| #include "gpio.h" | |||||
| #include "timer.h" | |||||
| #include "radio.h" | |||||
| #if defined( REGION_AS923 ) | |||||
| #define RF_FREQUENCY 923000000 // Hz | |||||
| #elif defined( REGION_AU915 ) | |||||
| #define RF_FREQUENCY 915000000 // Hz | |||||
| #elif defined( REGION_CN470 ) | |||||
| #define RF_FREQUENCY 470000000 // Hz | |||||
| #elif defined( REGION_CN779 ) | |||||
| #define RF_FREQUENCY 779000000 // Hz | |||||
| #elif defined( REGION_EU433 ) | |||||
| #define RF_FREQUENCY 433000000 // Hz | |||||
| #elif defined( REGION_EU868 ) | |||||
| #define RF_FREQUENCY 868000000 // Hz | |||||
| #elif defined( REGION_KR920 ) | |||||
| #define RF_FREQUENCY 920000000 // Hz | |||||
| #elif defined( REGION_IN865 ) | |||||
| #define RF_FREQUENCY 865000000 // Hz | |||||
| #elif defined( REGION_US915 ) | |||||
| #define RF_FREQUENCY 915000000 // Hz | |||||
| #elif defined( REGION_RU864 ) | |||||
| #define RF_FREQUENCY 864000000 // Hz | |||||
| #else | |||||
| #error "Please define a frequency band in the compiler options." | |||||
| #endif | |||||
| #if defined( USE_MODEM_LORA ) | |||||
| #define LORA_BANDWIDTH 0 // [0: 125 kHz, | |||||
| // 1: 250 kHz, | |||||
| // 2: 500 kHz, | |||||
| // 3: Reserved] | |||||
| #define LORA_SPREADING_FACTOR 10 // [SF7..SF12] | |||||
| #define LORA_CODINGRATE 1 // [1: 4/5, | |||||
| // 2: 4/6, | |||||
| // 3: 4/7, | |||||
| // 4: 4/8] | |||||
| #define LORA_SYMBOL_TIMEOUT 5 // Symbols | |||||
| #define LORA_PREAMBLE_LENGTH 8 // Same for Tx and Rx | |||||
| #define LORA_FIX_LENGTH_PAYLOAD_ON false | |||||
| #define LORA_IQ_INVERSION_ON false | |||||
| #elif defined( USE_MODEM_FSK ) | |||||
| #define FSK_DATARATE 50000 // bps | |||||
| #define FSK_BANDWIDTH 50000 // Hz | |||||
| #define FSK_AFC_BANDWIDTH 83333 // Hz | |||||
| #define FSK_PREAMBLE_LENGTH 5 // Same for Tx and Rx | |||||
| #define FSK_FIX_LENGTH_PAYLOAD_ON false | |||||
| #else | |||||
| #error "Please define a modem in the compiler options." | |||||
| #endif | |||||
| /*! | |||||
| * Radio events function pointer | |||||
| */ | |||||
| static RadioEvents_t RadioEvents; | |||||
| /*! | |||||
| * LED GPIO pins objects | |||||
| */ | |||||
| extern Gpio_t Led1; | |||||
| /*! | |||||
| * \brief Function to be executed on Radio Rx Done event | |||||
| */ | |||||
| void OnRxDone( uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr ); | |||||
| /*! | |||||
| * Main application entry point. | |||||
| */ | |||||
| int main( void ) | |||||
| { | |||||
| // Target board initialization | |||||
| BoardInitMcu( ); | |||||
| BoardInitPeriph( ); | |||||
| // Radio initialization | |||||
| RadioEvents.RxDone = OnRxDone; | |||||
| Radio.Init( &RadioEvents ); | |||||
| Radio.SetChannel( RF_FREQUENCY ); | |||||
| #if defined( USE_MODEM_LORA ) | |||||
| Radio.SetRxConfig( MODEM_LORA, LORA_BANDWIDTH, LORA_SPREADING_FACTOR, | |||||
| LORA_CODINGRATE, 0, LORA_PREAMBLE_LENGTH, | |||||
| LORA_SYMBOL_TIMEOUT, LORA_FIX_LENGTH_PAYLOAD_ON, | |||||
| 0, true, 0, 0, LORA_IQ_INVERSION_ON, true ); | |||||
| Radio.SetMaxPayloadLength( MODEM_LORA, 255 ); | |||||
| #elif defined( USE_MODEM_FSK ) | |||||
| Radio.SetRxConfig( MODEM_FSK, FSK_BANDWIDTH, FSK_DATARATE, | |||||
| 0, FSK_AFC_BANDWIDTH, FSK_PREAMBLE_LENGTH, | |||||
| 0, FSK_FIX_LENGTH_PAYLOAD_ON, 0, true, | |||||
| 0, 0, false, true ); | |||||
| Radio.SetMaxPayloadLength( MODEM_FSK, 255 ); | |||||
| #else | |||||
| #error "Please define a frequency band in the compiler options." | |||||
| #endif | |||||
| Radio.Rx( 0 ); // Continuous Rx | |||||
| while( 1 ) | |||||
| { | |||||
| BoardLowPowerHandler( ); | |||||
| } | |||||
| } | |||||
| void OnRxDone( uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr ) | |||||
| { | |||||
| static uint8_t ledState = 1; | |||||
| // Toggle LED 1 | |||||
| ledState ^= 1; | |||||
| GpioWrite( &Led1, ledState ); | |||||
| } | |||||
| @@ -1,105 +1,105 @@ | |||||
| ## | |||||
| ## ______ _ | |||||
| ## / _____) _ | | | |||||
| ## ( (____ _____ ____ _| |_ _____ ____| |__ | |||||
| ## \____ \| ___ | (_ _) ___ |/ ___) _ \ | |||||
| ## _____) ) ____| | | || |_| ____( (___| | | | | |||||
| ## (______/|_____)_|_|_| \__)_____)\____)_| |_| | |||||
| ## (C)2013-2017 Semtech | |||||
| ## ___ _____ _ ___ _ _____ ___ ___ ___ ___ | |||||
| ## / __|_ _/_\ / __| |/ / __/ _ \| _ \/ __| __| | |||||
| ## \__ \ | |/ _ \ (__| ' <| _| (_) | / (__| _| | |||||
| ## |___/ |_/_/ \_\___|_|\_\_| \___/|_|_\\___|___| | |||||
| ## embedded.connectivity.solutions.============== | |||||
| ## | |||||
| ## License: Revised BSD License, see LICENSE.TXT file included in the project | |||||
| ## Authors: Johannes Bruder (STACKFORCE), Miguel Luis (Semtech) | |||||
| ## | |||||
| project(rx-sensi) | |||||
| cmake_minimum_required(VERSION 3.6) | |||||
| #--------------------------------------------------------------------------------------- | |||||
| # Options | |||||
| #--------------------------------------------------------------------------------------- | |||||
| # Allow selection of region | |||||
| option(REGION_EU868 "Region EU868" ON) | |||||
| option(REGION_US915 "Region US915" OFF) | |||||
| option(REGION_CN779 "Region CN779" OFF) | |||||
| option(REGION_EU433 "Region EU433" OFF) | |||||
| option(REGION_AU915 "Region AU915" OFF) | |||||
| option(REGION_AS923 "Region AS923" OFF) | |||||
| option(REGION_CN470 "Region CN470" OFF) | |||||
| option(REGION_KR920 "Region KR920" OFF) | |||||
| option(REGION_IN865 "Region IN865" OFF) | |||||
| option(REGION_RU864 "Region RU864" OFF) | |||||
| set(REGION_LIST REGION_EU868 REGION_US915 REGION_CN779 REGION_EU433 REGION_AU915 REGION_AS923 REGION_CN470 REGION_KR920 REGION_IN865 REGION_RU864) | |||||
| # Allow switching of modulation | |||||
| set(MODULATION_LIST LORA FSK) | |||||
| set(MODULATION LORA CACHE STRING "Default modulation is LoRa") | |||||
| set_property(CACHE MODULATION PROPERTY STRINGS ${MODEM_LIST}) | |||||
| #--------------------------------------------------------------------------------------- | |||||
| # Target | |||||
| #--------------------------------------------------------------------------------------- | |||||
| file(GLOB ${PROJECT_NAME}_SOURCES "${CMAKE_CURRENT_LIST_DIR}/${BOARD}/*.c") | |||||
| add_executable(${PROJECT_NAME} | |||||
| ${${PROJECT_NAME}_SOURCES} | |||||
| $<TARGET_OBJECTS:system> | |||||
| $<TARGET_OBJECTS:radio> | |||||
| $<TARGET_OBJECTS:peripherals> | |||||
| $<TARGET_OBJECTS:${BOARD}> | |||||
| ) | |||||
| # Loops through all regions and add compile time definitions for the enabled ones. | |||||
| foreach( REGION ${REGION_LIST} ) | |||||
| if(${REGION}) | |||||
| target_compile_definitions(${PROJECT_NAME} PUBLIC -D"${REGION}") | |||||
| endif() | |||||
| endforeach() | |||||
| if(MODULATION STREQUAL LORA) | |||||
| target_compile_definitions(${PROJECT_NAME} PRIVATE USE_MODEM_LORA) | |||||
| elseif(MODULATION STREQUAL FSK) | |||||
| target_compile_definitions(${PROJECT_NAME} PRIVATE USE_MODEM_FSK) | |||||
| endif() | |||||
| # Add compile time definition for the mbed shield if set. | |||||
| target_compile_definitions(${PROJECT_NAME} PUBLIC -D${MBED_RADIO_SHIELD}) | |||||
| target_compile_definitions(${PROJECT_NAME} PUBLIC | |||||
| $<BUILD_INTERFACE:$<TARGET_PROPERTY:mac,INTERFACE_COMPILE_DEFINITIONS>> | |||||
| ) | |||||
| target_include_directories(${PROJECT_NAME} PUBLIC | |||||
| $<BUILD_INTERFACE:$<TARGET_PROPERTY:system,INTERFACE_INCLUDE_DIRECTORIES>> | |||||
| $<BUILD_INTERFACE:$<TARGET_PROPERTY:radio,INTERFACE_INCLUDE_DIRECTORIES>> | |||||
| $<BUILD_INTERFACE:$<TARGET_PROPERTY:peripherals,INTERFACE_INCLUDE_DIRECTORIES>> | |||||
| $<BUILD_INTERFACE:$<TARGET_PROPERTY:${BOARD},INTERFACE_INCLUDE_DIRECTORIES>> | |||||
| ) | |||||
| set_property(TARGET ${PROJECT_NAME} PROPERTY C_STANDARD 11) | |||||
| target_link_libraries(${PROJECT_NAME} m) | |||||
| #--------------------------------------------------------------------------------------- | |||||
| # Debugging and Binutils | |||||
| #--------------------------------------------------------------------------------------- | |||||
| include(gdb-helper) | |||||
| include(binutils-arm-none-eabi) | |||||
| # Generate debugger configurations | |||||
| generate_run_gdb_stlink(${PROJECT_NAME}) | |||||
| generate_run_gdb_openocd(${PROJECT_NAME}) | |||||
| generate_vscode_launch_openocd(${PROJECT_NAME}) | |||||
| # Print section sizes of target | |||||
| print_section_sizes(${PROJECT_NAME}) | |||||
| # Create output in hex and binary format | |||||
| create_bin_output(${PROJECT_NAME}) | |||||
| create_hex_output(${PROJECT_NAME}) | |||||
| ## | |||||
| ## ______ _ | |||||
| ## / _____) _ | | | |||||
| ## ( (____ _____ ____ _| |_ _____ ____| |__ | |||||
| ## \____ \| ___ | (_ _) ___ |/ ___) _ \ | |||||
| ## _____) ) ____| | | || |_| ____( (___| | | | | |||||
| ## (______/|_____)_|_|_| \__)_____)\____)_| |_| | |||||
| ## (C)2013-2017 Semtech | |||||
| ## ___ _____ _ ___ _ _____ ___ ___ ___ ___ | |||||
| ## / __|_ _/_\ / __| |/ / __/ _ \| _ \/ __| __| | |||||
| ## \__ \ | |/ _ \ (__| ' <| _| (_) | / (__| _| | |||||
| ## |___/ |_/_/ \_\___|_|\_\_| \___/|_|_\\___|___| | |||||
| ## embedded.connectivity.solutions.============== | |||||
| ## | |||||
| ## License: Revised BSD License, see LICENSE.TXT file included in the project | |||||
| ## Authors: Johannes Bruder (STACKFORCE), Miguel Luis (Semtech) | |||||
| ## | |||||
| project(rx-sensi) | |||||
| cmake_minimum_required(VERSION 3.6) | |||||
| #--------------------------------------------------------------------------------------- | |||||
| # Options | |||||
| #--------------------------------------------------------------------------------------- | |||||
| # Allow selection of region | |||||
| option(REGION_EU868 "Region EU868" ON) | |||||
| option(REGION_US915 "Region US915" OFF) | |||||
| option(REGION_CN779 "Region CN779" OFF) | |||||
| option(REGION_EU433 "Region EU433" OFF) | |||||
| option(REGION_AU915 "Region AU915" OFF) | |||||
| option(REGION_AS923 "Region AS923" OFF) | |||||
| option(REGION_CN470 "Region CN470" OFF) | |||||
| option(REGION_KR920 "Region KR920" OFF) | |||||
| option(REGION_IN865 "Region IN865" OFF) | |||||
| option(REGION_RU864 "Region RU864" OFF) | |||||
| set(REGION_LIST REGION_EU868 REGION_US915 REGION_CN779 REGION_EU433 REGION_AU915 REGION_AS923 REGION_CN470 REGION_KR920 REGION_IN865 REGION_RU864) | |||||
| # Allow switching of modulation | |||||
| set(MODULATION_LIST LORA FSK) | |||||
| set(MODULATION LORA CACHE STRING "Default modulation is LoRa") | |||||
| set_property(CACHE MODULATION PROPERTY STRINGS ${MODEM_LIST}) | |||||
| #--------------------------------------------------------------------------------------- | |||||
| # Target | |||||
| #--------------------------------------------------------------------------------------- | |||||
| file(GLOB ${PROJECT_NAME}_SOURCES "${CMAKE_CURRENT_LIST_DIR}/${BOARD}/*.c") | |||||
| add_executable(${PROJECT_NAME} | |||||
| ${${PROJECT_NAME}_SOURCES} | |||||
| $<TARGET_OBJECTS:system> | |||||
| $<TARGET_OBJECTS:radio> | |||||
| $<TARGET_OBJECTS:peripherals> | |||||
| $<TARGET_OBJECTS:${BOARD}> | |||||
| ) | |||||
| # Loops through all regions and add compile time definitions for the enabled ones. | |||||
| foreach( REGION ${REGION_LIST} ) | |||||
| if(${REGION}) | |||||
| target_compile_definitions(${PROJECT_NAME} PUBLIC -D"${REGION}") | |||||
| endif() | |||||
| endforeach() | |||||
| if(MODULATION STREQUAL LORA) | |||||
| target_compile_definitions(${PROJECT_NAME} PRIVATE USE_MODEM_LORA) | |||||
| elseif(MODULATION STREQUAL FSK) | |||||
| target_compile_definitions(${PROJECT_NAME} PRIVATE USE_MODEM_FSK) | |||||
| endif() | |||||
| # Add compile time definition for the mbed shield if set. | |||||
| target_compile_definitions(${PROJECT_NAME} PUBLIC -D${MBED_RADIO_SHIELD}) | |||||
| target_compile_definitions(${PROJECT_NAME} PUBLIC | |||||
| $<BUILD_INTERFACE:$<TARGET_PROPERTY:mac,INTERFACE_COMPILE_DEFINITIONS>> | |||||
| ) | |||||
| target_include_directories(${PROJECT_NAME} PUBLIC | |||||
| $<BUILD_INTERFACE:$<TARGET_PROPERTY:system,INTERFACE_INCLUDE_DIRECTORIES>> | |||||
| $<BUILD_INTERFACE:$<TARGET_PROPERTY:radio,INTERFACE_INCLUDE_DIRECTORIES>> | |||||
| $<BUILD_INTERFACE:$<TARGET_PROPERTY:peripherals,INTERFACE_INCLUDE_DIRECTORIES>> | |||||
| $<BUILD_INTERFACE:$<TARGET_PROPERTY:${BOARD},INTERFACE_INCLUDE_DIRECTORIES>> | |||||
| ) | |||||
| set_property(TARGET ${PROJECT_NAME} PROPERTY C_STANDARD 11) | |||||
| target_link_libraries(${PROJECT_NAME} m) | |||||
| #--------------------------------------------------------------------------------------- | |||||
| # Debugging and Binutils | |||||
| #--------------------------------------------------------------------------------------- | |||||
| include(gdb-helper) | |||||
| include(binutils-arm-none-eabi) | |||||
| # Generate debugger configurations | |||||
| generate_run_gdb_stlink(${PROJECT_NAME}) | |||||
| generate_run_gdb_openocd(${PROJECT_NAME}) | |||||
| generate_vscode_launch_openocd(${PROJECT_NAME}) | |||||
| # Print section sizes of target | |||||
| print_section_sizes(${PROJECT_NAME}) | |||||
| # Create output in hex and binary format | |||||
| create_bin_output(${PROJECT_NAME}) | |||||
| create_hex_output(${PROJECT_NAME}) | |||||
| @@ -1,165 +1,165 @@ | |||||
| /*! | |||||
| * \file main.c | |||||
| * | |||||
| * \brief Radio sensitivity test | |||||
| * | |||||
| * \remark When LED1 stops blinking LoRa packets aren't received any more and | |||||
| * the sensitivity level has been reached. | |||||
| * By reading the RF generator output power we can estimate the board | |||||
| * sensitivity | |||||
| * | |||||
| * \copyright Revised BSD License, see section \ref LICENSE. | |||||
| * | |||||
| * \code | |||||
| * ______ _ | |||||
| * / _____) _ | | | |||||
| * ( (____ _____ ____ _| |_ _____ ____| |__ | |||||
| * \____ \| ___ | (_ _) ___ |/ ___) _ \ | |||||
| * _____) ) ____| | | || |_| ____( (___| | | | | |||||
| * (______/|_____)_|_|_| \__)_____)\____)_| |_| | |||||
| * (C)2013-2017 Semtech | |||||
| * | |||||
| * \endcode | |||||
| * | |||||
| * \author Miguel Luis ( Semtech ) | |||||
| * | |||||
| * \author Gregory Cristian ( Semtech ) | |||||
| */ | |||||
| #include "board-config.h" | |||||
| #include "board.h" | |||||
| #include "gpio.h" | |||||
| #include "timer.h" | |||||
| #include "radio.h" | |||||
| #if defined( REGION_AS923 ) | |||||
| #define RF_FREQUENCY 923000000 // Hz | |||||
| #elif defined( REGION_AU915 ) | |||||
| #define RF_FREQUENCY 915000000 // Hz | |||||
| #elif defined( REGION_CN779 ) | |||||
| #define RF_FREQUENCY 779000000 // Hz | |||||
| #elif defined( REGION_EU868 ) | |||||
| #define RF_FREQUENCY 868000000 // Hz | |||||
| #elif defined( REGION_KR920 ) | |||||
| #define RF_FREQUENCY 920000000 // Hz | |||||
| #elif defined( REGION_IN865 ) | |||||
| #define RF_FREQUENCY 865000000 // Hz | |||||
| #elif defined( REGION_US915 ) | |||||
| #define RF_FREQUENCY 915000000 // Hz | |||||
| #elif defined( REGION_RU864 ) | |||||
| #define RF_FREQUENCY 864000000 // Hz | |||||
| #else | |||||
| #error "Please define a frequency band in the compiler options." | |||||
| #endif | |||||
| #if defined( USE_MODEM_LORA ) | |||||
| #define LORA_BANDWIDTH 0 // [0: 125 kHz, | |||||
| // 1: 250 kHz, | |||||
| // 2: 500 kHz, | |||||
| // 3: Reserved] | |||||
| #define LORA_SPREADING_FACTOR 10 // [SF7..SF12] | |||||
| #define LORA_CODINGRATE 1 // [1: 4/5, | |||||
| // 2: 4/6, | |||||
| // 3: 4/7, | |||||
| // 4: 4/8] | |||||
| #define LORA_SYMBOL_TIMEOUT 5 // Symbols | |||||
| #define LORA_PREAMBLE_LENGTH 8 // Same for Tx and Rx | |||||
| #define LORA_FIX_LENGTH_PAYLOAD_ON false | |||||
| #define LORA_IQ_INVERSION_ON false | |||||
| #elif defined( USE_MODEM_FSK ) | |||||
| #define FSK_DATARATE 50000 // bps | |||||
| #define FSK_BANDWIDTH 50000 // Hz | |||||
| #define FSK_AFC_BANDWIDTH 83333 // Hz | |||||
| #define FSK_PREAMBLE_LENGTH 5 // Same for Tx and Rx | |||||
| #define FSK_FIX_LENGTH_PAYLOAD_ON false | |||||
| #else | |||||
| #error "Please define a modem in the compiler options." | |||||
| #endif | |||||
| /*! | |||||
| * Radio events function pointer | |||||
| */ | |||||
| static RadioEvents_t RadioEvents; | |||||
| /*! | |||||
| * LED GPIO pins objects | |||||
| */ | |||||
| extern Gpio_t Led1; | |||||
| /*! | |||||
| * \brief Function to be executed on Radio Rx Done event | |||||
| */ | |||||
| void OnRxDone( uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr ); | |||||
| /*! | |||||
| * Main application entry point. | |||||
| */ | |||||
| int main( void ) | |||||
| { | |||||
| // Target board initialization | |||||
| BoardInitMcu( ); | |||||
| BoardInitPeriph( ); | |||||
| // Radio initialization | |||||
| RadioEvents.RxDone = OnRxDone; | |||||
| Radio.Init( &RadioEvents ); | |||||
| Radio.SetChannel( RF_FREQUENCY ); | |||||
| #if defined( USE_MODEM_LORA ) | |||||
| Radio.SetRxConfig( MODEM_LORA, LORA_BANDWIDTH, LORA_SPREADING_FACTOR, | |||||
| LORA_CODINGRATE, 0, LORA_PREAMBLE_LENGTH, | |||||
| LORA_SYMBOL_TIMEOUT, LORA_FIX_LENGTH_PAYLOAD_ON, | |||||
| 0, true, 0, 0, LORA_IQ_INVERSION_ON, true ); | |||||
| Radio.SetMaxPayloadLength( MODEM_LORA, 255 ); | |||||
| #elif defined( USE_MODEM_FSK ) | |||||
| Radio.SetRxConfig( MODEM_FSK, FSK_BANDWIDTH, FSK_DATARATE, | |||||
| 0, FSK_AFC_BANDWIDTH, FSK_PREAMBLE_LENGTH, | |||||
| 0, FSK_FIX_LENGTH_PAYLOAD_ON, 0, true, | |||||
| 0, 0, false, true ); | |||||
| Radio.SetMaxPayloadLength( MODEM_FSK, 255 ); | |||||
| #else | |||||
| #error "Please define a frequency band in the compiler options." | |||||
| #endif | |||||
| Radio.Rx( 0 ); // Continuous Rx | |||||
| while( 1 ) | |||||
| { | |||||
| BoardLowPowerHandler( ); | |||||
| } | |||||
| } | |||||
| void OnRxDone( uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr ) | |||||
| { | |||||
| static uint8_t ledState = 1; | |||||
| // Toggle LED 1 | |||||
| ledState ^= 1; | |||||
| GpioWrite( &Led1, ledState ); | |||||
| } | |||||
| /*! | |||||
| * \file main.c | |||||
| * | |||||
| * \brief Radio sensitivity test | |||||
| * | |||||
| * \remark When LED1 stops blinking LoRa packets aren't received any more and | |||||
| * the sensitivity level has been reached. | |||||
| * By reading the RF generator output power we can estimate the board | |||||
| * sensitivity | |||||
| * | |||||
| * \copyright Revised BSD License, see section \ref LICENSE. | |||||
| * | |||||
| * \code | |||||
| * ______ _ | |||||
| * / _____) _ | | | |||||
| * ( (____ _____ ____ _| |_ _____ ____| |__ | |||||
| * \____ \| ___ | (_ _) ___ |/ ___) _ \ | |||||
| * _____) ) ____| | | || |_| ____( (___| | | | | |||||
| * (______/|_____)_|_|_| \__)_____)\____)_| |_| | |||||
| * (C)2013-2017 Semtech | |||||
| * | |||||
| * \endcode | |||||
| * | |||||
| * \author Miguel Luis ( Semtech ) | |||||
| * | |||||
| * \author Gregory Cristian ( Semtech ) | |||||
| */ | |||||
| #include "board-config.h" | |||||
| #include "board.h" | |||||
| #include "gpio.h" | |||||
| #include "timer.h" | |||||
| #include "radio.h" | |||||
| #if defined( REGION_AS923 ) | |||||
| #define RF_FREQUENCY 923000000 // Hz | |||||
| #elif defined( REGION_AU915 ) | |||||
| #define RF_FREQUENCY 915000000 // Hz | |||||
| #elif defined( REGION_CN779 ) | |||||
| #define RF_FREQUENCY 779000000 // Hz | |||||
| #elif defined( REGION_EU868 ) | |||||
| #define RF_FREQUENCY 868000000 // Hz | |||||
| #elif defined( REGION_KR920 ) | |||||
| #define RF_FREQUENCY 920000000 // Hz | |||||
| #elif defined( REGION_IN865 ) | |||||
| #define RF_FREQUENCY 865000000 // Hz | |||||
| #elif defined( REGION_US915 ) | |||||
| #define RF_FREQUENCY 915000000 // Hz | |||||
| #elif defined( REGION_RU864 ) | |||||
| #define RF_FREQUENCY 864000000 // Hz | |||||
| #else | |||||
| #error "Please define a frequency band in the compiler options." | |||||
| #endif | |||||
| #if defined( USE_MODEM_LORA ) | |||||
| #define LORA_BANDWIDTH 0 // [0: 125 kHz, | |||||
| // 1: 250 kHz, | |||||
| // 2: 500 kHz, | |||||
| // 3: Reserved] | |||||
| #define LORA_SPREADING_FACTOR 10 // [SF7..SF12] | |||||
| #define LORA_CODINGRATE 1 // [1: 4/5, | |||||
| // 2: 4/6, | |||||
| // 3: 4/7, | |||||
| // 4: 4/8] | |||||
| #define LORA_SYMBOL_TIMEOUT 5 // Symbols | |||||
| #define LORA_PREAMBLE_LENGTH 8 // Same for Tx and Rx | |||||
| #define LORA_FIX_LENGTH_PAYLOAD_ON false | |||||
| #define LORA_IQ_INVERSION_ON false | |||||
| #elif defined( USE_MODEM_FSK ) | |||||
| #define FSK_DATARATE 50000 // bps | |||||
| #define FSK_BANDWIDTH 50000 // Hz | |||||
| #define FSK_AFC_BANDWIDTH 83333 // Hz | |||||
| #define FSK_PREAMBLE_LENGTH 5 // Same for Tx and Rx | |||||
| #define FSK_FIX_LENGTH_PAYLOAD_ON false | |||||
| #else | |||||
| #error "Please define a modem in the compiler options." | |||||
| #endif | |||||
| /*! | |||||
| * Radio events function pointer | |||||
| */ | |||||
| static RadioEvents_t RadioEvents; | |||||
| /*! | |||||
| * LED GPIO pins objects | |||||
| */ | |||||
| extern Gpio_t Led1; | |||||
| /*! | |||||
| * \brief Function to be executed on Radio Rx Done event | |||||
| */ | |||||
| void OnRxDone( uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr ); | |||||
| /*! | |||||
| * Main application entry point. | |||||
| */ | |||||
| int main( void ) | |||||
| { | |||||
| // Target board initialization | |||||
| BoardInitMcu( ); | |||||
| BoardInitPeriph( ); | |||||
| // Radio initialization | |||||
| RadioEvents.RxDone = OnRxDone; | |||||
| Radio.Init( &RadioEvents ); | |||||
| Radio.SetChannel( RF_FREQUENCY ); | |||||
| #if defined( USE_MODEM_LORA ) | |||||
| Radio.SetRxConfig( MODEM_LORA, LORA_BANDWIDTH, LORA_SPREADING_FACTOR, | |||||
| LORA_CODINGRATE, 0, LORA_PREAMBLE_LENGTH, | |||||
| LORA_SYMBOL_TIMEOUT, LORA_FIX_LENGTH_PAYLOAD_ON, | |||||
| 0, true, 0, 0, LORA_IQ_INVERSION_ON, true ); | |||||
| Radio.SetMaxPayloadLength( MODEM_LORA, 255 ); | |||||
| #elif defined( USE_MODEM_FSK ) | |||||
| Radio.SetRxConfig( MODEM_FSK, FSK_BANDWIDTH, FSK_DATARATE, | |||||
| 0, FSK_AFC_BANDWIDTH, FSK_PREAMBLE_LENGTH, | |||||
| 0, FSK_FIX_LENGTH_PAYLOAD_ON, 0, true, | |||||
| 0, 0, false, true ); | |||||
| Radio.SetMaxPayloadLength( MODEM_FSK, 255 ); | |||||
| #else | |||||
| #error "Please define a frequency band in the compiler options." | |||||
| #endif | |||||
| Radio.Rx( 0 ); // Continuous Rx | |||||
| while( 1 ) | |||||
| { | |||||
| BoardLowPowerHandler( ); | |||||
| } | |||||
| } | |||||
| void OnRxDone( uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr ) | |||||
| { | |||||
| static uint8_t ledState = 1; | |||||
| // Toggle LED 1 | |||||
| ledState ^= 1; | |||||
| GpioWrite( &Led1, ledState ); | |||||
| } | |||||
| @@ -1,177 +1,177 @@ | |||||
| /*! | |||||
| * \file main.c | |||||
| * | |||||
| * \brief Radio sensitivity test | |||||
| * | |||||
| * \remark When LED1 stops blinking LoRa packets aren't received any more and | |||||
| * the sensitivity level has been reached. | |||||
| * By reading the RF generator output power we can estimate the board | |||||
| * sensitivity | |||||
| * | |||||
| * \copyright Revised BSD License, see section \ref LICENSE. | |||||
| * | |||||
| * \code | |||||
| * ______ _ | |||||
| * / _____) _ | | | |||||
| * ( (____ _____ ____ _| |_ _____ ____| |__ | |||||
| * \____ \| ___ | (_ _) ___ |/ ___) _ \ | |||||
| * _____) ) ____| | | || |_| ____( (___| | | | | |||||
| * (______/|_____)_|_|_| \__)_____)\____)_| |_| | |||||
| * (C)2013-2017 Semtech | |||||
| * | |||||
| * \endcode | |||||
| * | |||||
| * \author Miguel Luis ( Semtech ) | |||||
| * | |||||
| * \author Gregory Cristian ( Semtech ) | |||||
| */ | |||||
| #include "board.h" | |||||
| #include "gpio.h" | |||||
| #include "timer.h" | |||||
| #include "radio.h" | |||||
| #if defined( REGION_AS923 ) | |||||
| #define RF_FREQUENCY 923000000 // Hz | |||||
| #elif defined( REGION_AU915 ) | |||||
| #define RF_FREQUENCY 915000000 // Hz | |||||
| #elif defined( REGION_CN470 ) | |||||
| #define RF_FREQUENCY 470000000 // Hz | |||||
| #elif defined( REGION_CN779 ) | |||||
| #define RF_FREQUENCY 779000000 // Hz | |||||
| #elif defined( REGION_EU433 ) | |||||
| #define RF_FREQUENCY 433000000 // Hz | |||||
| #elif defined( REGION_EU868 ) | |||||
| #define RF_FREQUENCY 868000000 // Hz | |||||
| #elif defined( REGION_KR920 ) | |||||
| #define RF_FREQUENCY 920000000 // Hz | |||||
| #elif defined( REGION_IN865 ) | |||||
| #define RF_FREQUENCY 865000000 // Hz | |||||
| #elif defined( REGION_US915 ) | |||||
| #define RF_FREQUENCY 915000000 // Hz | |||||
| #elif defined( REGION_RU864 ) | |||||
| #define RF_FREQUENCY 864000000 // Hz | |||||
| #else | |||||
| #error "Please define a frequency band in the compiler options." | |||||
| #endif | |||||
| #if defined( USE_MODEM_LORA ) | |||||
| #define LORA_BANDWIDTH 0 // [0: 125 kHz, | |||||
| // 1: 250 kHz, | |||||
| // 2: 500 kHz, | |||||
| // 3: Reserved] | |||||
| #define LORA_SPREADING_FACTOR 10 // [SF7..SF12] | |||||
| #define LORA_CODINGRATE 1 // [1: 4/5, | |||||
| // 2: 4/6, | |||||
| // 3: 4/7, | |||||
| // 4: 4/8] | |||||
| #define LORA_SYMBOL_TIMEOUT 5 // Symbols | |||||
| #define LORA_PREAMBLE_LENGTH 8 // Same for Tx and Rx | |||||
| #define LORA_FIX_LENGTH_PAYLOAD_ON false | |||||
| #define LORA_IQ_INVERSION_ON false | |||||
| #elif defined( USE_MODEM_FSK ) | |||||
| #define FSK_DATARATE 50000 // bps | |||||
| #define FSK_BANDWIDTH 50000 // Hz | |||||
| #define FSK_AFC_BANDWIDTH 83333 // Hz | |||||
| #define FSK_PREAMBLE_LENGTH 5 // Same for Tx and Rx | |||||
| #define FSK_FIX_LENGTH_PAYLOAD_ON false | |||||
| #else | |||||
| #error "Please define a modem in the compiler options." | |||||
| #endif | |||||
| /*! | |||||
| * Radio events function pointer | |||||
| */ | |||||
| static RadioEvents_t RadioEvents; | |||||
| /*! | |||||
| * LED GPIO pins objects | |||||
| */ | |||||
| extern Gpio_t Led1; | |||||
| /*! | |||||
| * \brief Function to be executed on Radio Rx Done event | |||||
| */ | |||||
| void OnRxDone( uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr ); | |||||
| /*! | |||||
| * Main application entry point. | |||||
| */ | |||||
| int main( void ) | |||||
| { | |||||
| // Target board initialization | |||||
| BoardInitMcu( ); | |||||
| BoardInitPeriph( ); | |||||
| // Radio initialization | |||||
| RadioEvents.RxDone = OnRxDone; | |||||
| Radio.Init( &RadioEvents ); | |||||
| Radio.SetChannel( RF_FREQUENCY ); | |||||
| #if defined( USE_MODEM_LORA ) | |||||
| Radio.SetRxConfig( MODEM_LORA, LORA_BANDWIDTH, LORA_SPREADING_FACTOR, | |||||
| LORA_CODINGRATE, 0, LORA_PREAMBLE_LENGTH, | |||||
| LORA_SYMBOL_TIMEOUT, LORA_FIX_LENGTH_PAYLOAD_ON, | |||||
| 0, true, 0, 0, LORA_IQ_INVERSION_ON, true ); | |||||
| Radio.SetMaxPayloadLength( MODEM_LORA, 255 ); | |||||
| #elif defined( USE_MODEM_FSK ) | |||||
| Radio.SetRxConfig( MODEM_FSK, FSK_BANDWIDTH, FSK_DATARATE, | |||||
| 0, FSK_AFC_BANDWIDTH, FSK_PREAMBLE_LENGTH, | |||||
| 0, FSK_FIX_LENGTH_PAYLOAD_ON, 0, true, | |||||
| 0, 0, false, true ); | |||||
| Radio.SetMaxPayloadLength( MODEM_FSK, 255 ); | |||||
| #else | |||||
| #error "Please define a frequency band in the compiler options." | |||||
| #endif | |||||
| Radio.Rx( 0 ); // Continuous Rx | |||||
| while( 1 ) | |||||
| { | |||||
| BoardLowPowerHandler( ); | |||||
| // Process Radio IRQ | |||||
| if( Radio.IrqProcess != NULL ) | |||||
| { | |||||
| Radio.IrqProcess( ); | |||||
| } | |||||
| } | |||||
| } | |||||
| void OnRxDone( uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr ) | |||||
| { | |||||
| static uint8_t ledState = 1; | |||||
| // Toggle LED 1 | |||||
| ledState ^= 1; | |||||
| GpioWrite( &Led1, ledState ); | |||||
| } | |||||
| /*! | |||||
| * \file main.c | |||||
| * | |||||
| * \brief Radio sensitivity test | |||||
| * | |||||
| * \remark When LED1 stops blinking LoRa packets aren't received any more and | |||||
| * the sensitivity level has been reached. | |||||
| * By reading the RF generator output power we can estimate the board | |||||
| * sensitivity | |||||
| * | |||||
| * \copyright Revised BSD License, see section \ref LICENSE. | |||||
| * | |||||
| * \code | |||||
| * ______ _ | |||||
| * / _____) _ | | | |||||
| * ( (____ _____ ____ _| |_ _____ ____| |__ | |||||
| * \____ \| ___ | (_ _) ___ |/ ___) _ \ | |||||
| * _____) ) ____| | | || |_| ____( (___| | | | | |||||
| * (______/|_____)_|_|_| \__)_____)\____)_| |_| | |||||
| * (C)2013-2017 Semtech | |||||
| * | |||||
| * \endcode | |||||
| * | |||||
| * \author Miguel Luis ( Semtech ) | |||||
| * | |||||
| * \author Gregory Cristian ( Semtech ) | |||||
| */ | |||||
| #include "board.h" | |||||
| #include "gpio.h" | |||||
| #include "timer.h" | |||||
| #include "radio.h" | |||||
| #if defined( REGION_AS923 ) | |||||
| #define RF_FREQUENCY 923000000 // Hz | |||||
| #elif defined( REGION_AU915 ) | |||||
| #define RF_FREQUENCY 915000000 // Hz | |||||
| #elif defined( REGION_CN470 ) | |||||
| #define RF_FREQUENCY 470000000 // Hz | |||||
| #elif defined( REGION_CN779 ) | |||||
| #define RF_FREQUENCY 779000000 // Hz | |||||
| #elif defined( REGION_EU433 ) | |||||
| #define RF_FREQUENCY 433000000 // Hz | |||||
| #elif defined( REGION_EU868 ) | |||||
| #define RF_FREQUENCY 868000000 // Hz | |||||
| #elif defined( REGION_KR920 ) | |||||
| #define RF_FREQUENCY 920000000 // Hz | |||||
| #elif defined( REGION_IN865 ) | |||||
| #define RF_FREQUENCY 865000000 // Hz | |||||
| #elif defined( REGION_US915 ) | |||||
| #define RF_FREQUENCY 915000000 // Hz | |||||
| #elif defined( REGION_RU864 ) | |||||
| #define RF_FREQUENCY 864000000 // Hz | |||||
| #else | |||||
| #error "Please define a frequency band in the compiler options." | |||||
| #endif | |||||
| #if defined( USE_MODEM_LORA ) | |||||
| #define LORA_BANDWIDTH 0 // [0: 125 kHz, | |||||
| // 1: 250 kHz, | |||||
| // 2: 500 kHz, | |||||
| // 3: Reserved] | |||||
| #define LORA_SPREADING_FACTOR 10 // [SF7..SF12] | |||||
| #define LORA_CODINGRATE 1 // [1: 4/5, | |||||
| // 2: 4/6, | |||||
| // 3: 4/7, | |||||
| // 4: 4/8] | |||||
| #define LORA_SYMBOL_TIMEOUT 5 // Symbols | |||||
| #define LORA_PREAMBLE_LENGTH 8 // Same for Tx and Rx | |||||
| #define LORA_FIX_LENGTH_PAYLOAD_ON false | |||||
| #define LORA_IQ_INVERSION_ON false | |||||
| #elif defined( USE_MODEM_FSK ) | |||||
| #define FSK_DATARATE 50000 // bps | |||||
| #define FSK_BANDWIDTH 50000 // Hz | |||||
| #define FSK_AFC_BANDWIDTH 83333 // Hz | |||||
| #define FSK_PREAMBLE_LENGTH 5 // Same for Tx and Rx | |||||
| #define FSK_FIX_LENGTH_PAYLOAD_ON false | |||||
| #else | |||||
| #error "Please define a modem in the compiler options." | |||||
| #endif | |||||
| /*! | |||||
| * Radio events function pointer | |||||
| */ | |||||
| static RadioEvents_t RadioEvents; | |||||
| /*! | |||||
| * LED GPIO pins objects | |||||
| */ | |||||
| extern Gpio_t Led1; | |||||
| /*! | |||||
| * \brief Function to be executed on Radio Rx Done event | |||||
| */ | |||||
| void OnRxDone( uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr ); | |||||
| /*! | |||||
| * Main application entry point. | |||||
| */ | |||||
| int main( void ) | |||||
| { | |||||
| // Target board initialization | |||||
| BoardInitMcu( ); | |||||
| BoardInitPeriph( ); | |||||
| // Radio initialization | |||||
| RadioEvents.RxDone = OnRxDone; | |||||
| Radio.Init( &RadioEvents ); | |||||
| Radio.SetChannel( RF_FREQUENCY ); | |||||
| #if defined( USE_MODEM_LORA ) | |||||
| Radio.SetRxConfig( MODEM_LORA, LORA_BANDWIDTH, LORA_SPREADING_FACTOR, | |||||
| LORA_CODINGRATE, 0, LORA_PREAMBLE_LENGTH, | |||||
| LORA_SYMBOL_TIMEOUT, LORA_FIX_LENGTH_PAYLOAD_ON, | |||||
| 0, true, 0, 0, LORA_IQ_INVERSION_ON, true ); | |||||
| Radio.SetMaxPayloadLength( MODEM_LORA, 255 ); | |||||
| #elif defined( USE_MODEM_FSK ) | |||||
| Radio.SetRxConfig( MODEM_FSK, FSK_BANDWIDTH, FSK_DATARATE, | |||||
| 0, FSK_AFC_BANDWIDTH, FSK_PREAMBLE_LENGTH, | |||||
| 0, FSK_FIX_LENGTH_PAYLOAD_ON, 0, true, | |||||
| 0, 0, false, true ); | |||||
| Radio.SetMaxPayloadLength( MODEM_FSK, 255 ); | |||||
| #else | |||||
| #error "Please define a frequency band in the compiler options." | |||||
| #endif | |||||
| Radio.Rx( 0 ); // Continuous Rx | |||||
| while( 1 ) | |||||
| { | |||||
| BoardLowPowerHandler( ); | |||||
| // Process Radio IRQ | |||||
| if( Radio.IrqProcess != NULL ) | |||||
| { | |||||
| Radio.IrqProcess( ); | |||||
| } | |||||
| } | |||||
| } | |||||
| void OnRxDone( uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr ) | |||||
| { | |||||
| static uint8_t ledState = 1; | |||||
| // Toggle LED 1 | |||||
| ledState ^= 1; | |||||
| GpioWrite( &Led1, ledState ); | |||||
| } | |||||
| @@ -1,177 +1,177 @@ | |||||
| /*! | |||||
| * \file main.c | |||||
| * | |||||
| * \brief Radio sensitivity test | |||||
| * | |||||
| * \remark When LED1 stops blinking LoRa packets aren't received any more and | |||||
| * the sensitivity level has been reached. | |||||
| * By reading the RF generator output power we can estimate the board | |||||
| * sensitivity | |||||
| * | |||||
| * \copyright Revised BSD License, see section \ref LICENSE. | |||||
| * | |||||
| * \code | |||||
| * ______ _ | |||||
| * / _____) _ | | | |||||
| * ( (____ _____ ____ _| |_ _____ ____| |__ | |||||
| * \____ \| ___ | (_ _) ___ |/ ___) _ \ | |||||
| * _____) ) ____| | | || |_| ____( (___| | | | | |||||
| * (______/|_____)_|_|_| \__)_____)\____)_| |_| | |||||
| * (C)2013-2017 Semtech | |||||
| * | |||||
| * \endcode | |||||
| * | |||||
| * \author Miguel Luis ( Semtech ) | |||||
| * | |||||
| * \author Gregory Cristian ( Semtech ) | |||||
| */ | |||||
| #include "board.h" | |||||
| #include "gpio.h" | |||||
| #include "timer.h" | |||||
| #include "radio.h" | |||||
| #if defined( REGION_AS923 ) | |||||
| #define RF_FREQUENCY 923000000 // Hz | |||||
| #elif defined( REGION_AU915 ) | |||||
| #define RF_FREQUENCY 915000000 // Hz | |||||
| #elif defined( REGION_CN470 ) | |||||
| #define RF_FREQUENCY 470000000 // Hz | |||||
| #elif defined( REGION_CN779 ) | |||||
| #define RF_FREQUENCY 779000000 // Hz | |||||
| #elif defined( REGION_EU433 ) | |||||
| #define RF_FREQUENCY 433000000 // Hz | |||||
| #elif defined( REGION_EU868 ) | |||||
| #define RF_FREQUENCY 868000000 // Hz | |||||
| #elif defined( REGION_KR920 ) | |||||
| #define RF_FREQUENCY 920000000 // Hz | |||||
| #elif defined( REGION_IN865 ) | |||||
| #define RF_FREQUENCY 865000000 // Hz | |||||
| #elif defined( REGION_US915 ) | |||||
| #define RF_FREQUENCY 915000000 // Hz | |||||
| #elif defined( REGION_RU864 ) | |||||
| #define RF_FREQUENCY 864000000 // Hz | |||||
| #else | |||||
| #error "Please define a frequency band in the compiler options." | |||||
| #endif | |||||
| #if defined( USE_MODEM_LORA ) | |||||
| #define LORA_BANDWIDTH 0 // [0: 125 kHz, | |||||
| // 1: 250 kHz, | |||||
| // 2: 500 kHz, | |||||
| // 3: Reserved] | |||||
| #define LORA_SPREADING_FACTOR 10 // [SF7..SF12] | |||||
| #define LORA_CODINGRATE 1 // [1: 4/5, | |||||
| // 2: 4/6, | |||||
| // 3: 4/7, | |||||
| // 4: 4/8] | |||||
| #define LORA_SYMBOL_TIMEOUT 5 // Symbols | |||||
| #define LORA_PREAMBLE_LENGTH 8 // Same for Tx and Rx | |||||
| #define LORA_FIX_LENGTH_PAYLOAD_ON false | |||||
| #define LORA_IQ_INVERSION_ON false | |||||
| #elif defined( USE_MODEM_FSK ) | |||||
| #define FSK_DATARATE 50000 // bps | |||||
| #define FSK_BANDWIDTH 50000 // Hz | |||||
| #define FSK_AFC_BANDWIDTH 83333 // Hz | |||||
| #define FSK_PREAMBLE_LENGTH 5 // Same for Tx and Rx | |||||
| #define FSK_FIX_LENGTH_PAYLOAD_ON false | |||||
| #else | |||||
| #error "Please define a modem in the compiler options." | |||||
| #endif | |||||
| /*! | |||||
| * Radio events function pointer | |||||
| */ | |||||
| static RadioEvents_t RadioEvents; | |||||
| /*! | |||||
| * LED GPIO pins objects | |||||
| */ | |||||
| extern Gpio_t Led1; | |||||
| /*! | |||||
| * \brief Function to be executed on Radio Rx Done event | |||||
| */ | |||||
| void OnRxDone( uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr ); | |||||
| /*! | |||||
| * Main application entry point. | |||||
| */ | |||||
| int main( void ) | |||||
| { | |||||
| // Target board initialization | |||||
| BoardInitMcu( ); | |||||
| BoardInitPeriph( ); | |||||
| // Radio initialization | |||||
| RadioEvents.RxDone = OnRxDone; | |||||
| Radio.Init( &RadioEvents ); | |||||
| Radio.SetChannel( RF_FREQUENCY ); | |||||
| #if defined( USE_MODEM_LORA ) | |||||
| Radio.SetRxConfig( MODEM_LORA, LORA_BANDWIDTH, LORA_SPREADING_FACTOR, | |||||
| LORA_CODINGRATE, 0, LORA_PREAMBLE_LENGTH, | |||||
| LORA_SYMBOL_TIMEOUT, LORA_FIX_LENGTH_PAYLOAD_ON, | |||||
| 0, true, 0, 0, LORA_IQ_INVERSION_ON, true ); | |||||
| Radio.SetMaxPayloadLength( MODEM_LORA, 255 ); | |||||
| #elif defined( USE_MODEM_FSK ) | |||||
| Radio.SetRxConfig( MODEM_FSK, FSK_BANDWIDTH, FSK_DATARATE, | |||||
| 0, FSK_AFC_BANDWIDTH, FSK_PREAMBLE_LENGTH, | |||||
| 0, FSK_FIX_LENGTH_PAYLOAD_ON, 0, true, | |||||
| 0, 0, false, true ); | |||||
| Radio.SetMaxPayloadLength( MODEM_FSK, 255 ); | |||||
| #else | |||||
| #error "Please define a frequency band in the compiler options." | |||||
| #endif | |||||
| Radio.Rx( 0 ); // Continuous Rx | |||||
| while( 1 ) | |||||
| { | |||||
| BoardLowPowerHandler( ); | |||||
| // Process Radio IRQ | |||||
| if( Radio.IrqProcess != NULL ) | |||||
| { | |||||
| Radio.IrqProcess( ); | |||||
| } | |||||
| } | |||||
| } | |||||
| void OnRxDone( uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr ) | |||||
| { | |||||
| static uint8_t ledState = 1; | |||||
| // Toggle LED 1 | |||||
| ledState ^= 1; | |||||
| GpioWrite( &Led1, ledState ); | |||||
| } | |||||
| /*! | |||||
| * \file main.c | |||||
| * | |||||
| * \brief Radio sensitivity test | |||||
| * | |||||
| * \remark When LED1 stops blinking LoRa packets aren't received any more and | |||||
| * the sensitivity level has been reached. | |||||
| * By reading the RF generator output power we can estimate the board | |||||
| * sensitivity | |||||
| * | |||||
| * \copyright Revised BSD License, see section \ref LICENSE. | |||||
| * | |||||
| * \code | |||||
| * ______ _ | |||||
| * / _____) _ | | | |||||
| * ( (____ _____ ____ _| |_ _____ ____| |__ | |||||
| * \____ \| ___ | (_ _) ___ |/ ___) _ \ | |||||
| * _____) ) ____| | | || |_| ____( (___| | | | | |||||
| * (______/|_____)_|_|_| \__)_____)\____)_| |_| | |||||
| * (C)2013-2017 Semtech | |||||
| * | |||||
| * \endcode | |||||
| * | |||||
| * \author Miguel Luis ( Semtech ) | |||||
| * | |||||
| * \author Gregory Cristian ( Semtech ) | |||||
| */ | |||||
| #include "board.h" | |||||
| #include "gpio.h" | |||||
| #include "timer.h" | |||||
| #include "radio.h" | |||||
| #if defined( REGION_AS923 ) | |||||
| #define RF_FREQUENCY 923000000 // Hz | |||||
| #elif defined( REGION_AU915 ) | |||||
| #define RF_FREQUENCY 915000000 // Hz | |||||
| #elif defined( REGION_CN470 ) | |||||
| #define RF_FREQUENCY 470000000 // Hz | |||||
| #elif defined( REGION_CN779 ) | |||||
| #define RF_FREQUENCY 779000000 // Hz | |||||
| #elif defined( REGION_EU433 ) | |||||
| #define RF_FREQUENCY 433000000 // Hz | |||||
| #elif defined( REGION_EU868 ) | |||||
| #define RF_FREQUENCY 868000000 // Hz | |||||
| #elif defined( REGION_KR920 ) | |||||
| #define RF_FREQUENCY 920000000 // Hz | |||||
| #elif defined( REGION_IN865 ) | |||||
| #define RF_FREQUENCY 865000000 // Hz | |||||
| #elif defined( REGION_US915 ) | |||||
| #define RF_FREQUENCY 915000000 // Hz | |||||
| #elif defined( REGION_RU864 ) | |||||
| #define RF_FREQUENCY 864000000 // Hz | |||||
| #else | |||||
| #error "Please define a frequency band in the compiler options." | |||||
| #endif | |||||
| #if defined( USE_MODEM_LORA ) | |||||
| #define LORA_BANDWIDTH 0 // [0: 125 kHz, | |||||
| // 1: 250 kHz, | |||||
| // 2: 500 kHz, | |||||
| // 3: Reserved] | |||||
| #define LORA_SPREADING_FACTOR 10 // [SF7..SF12] | |||||
| #define LORA_CODINGRATE 1 // [1: 4/5, | |||||
| // 2: 4/6, | |||||
| // 3: 4/7, | |||||
| // 4: 4/8] | |||||
| #define LORA_SYMBOL_TIMEOUT 5 // Symbols | |||||
| #define LORA_PREAMBLE_LENGTH 8 // Same for Tx and Rx | |||||
| #define LORA_FIX_LENGTH_PAYLOAD_ON false | |||||
| #define LORA_IQ_INVERSION_ON false | |||||
| #elif defined( USE_MODEM_FSK ) | |||||
| #define FSK_DATARATE 50000 // bps | |||||
| #define FSK_BANDWIDTH 50000 // Hz | |||||
| #define FSK_AFC_BANDWIDTH 83333 // Hz | |||||
| #define FSK_PREAMBLE_LENGTH 5 // Same for Tx and Rx | |||||
| #define FSK_FIX_LENGTH_PAYLOAD_ON false | |||||
| #else | |||||
| #error "Please define a modem in the compiler options." | |||||
| #endif | |||||
| /*! | |||||
| * Radio events function pointer | |||||
| */ | |||||
| static RadioEvents_t RadioEvents; | |||||
| /*! | |||||
| * LED GPIO pins objects | |||||
| */ | |||||
| extern Gpio_t Led1; | |||||
| /*! | |||||
| * \brief Function to be executed on Radio Rx Done event | |||||
| */ | |||||
| void OnRxDone( uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr ); | |||||
| /*! | |||||
| * Main application entry point. | |||||
| */ | |||||
| int main( void ) | |||||
| { | |||||
| // Target board initialization | |||||
| BoardInitMcu( ); | |||||
| BoardInitPeriph( ); | |||||
| // Radio initialization | |||||
| RadioEvents.RxDone = OnRxDone; | |||||
| Radio.Init( &RadioEvents ); | |||||
| Radio.SetChannel( RF_FREQUENCY ); | |||||
| #if defined( USE_MODEM_LORA ) | |||||
| Radio.SetRxConfig( MODEM_LORA, LORA_BANDWIDTH, LORA_SPREADING_FACTOR, | |||||
| LORA_CODINGRATE, 0, LORA_PREAMBLE_LENGTH, | |||||
| LORA_SYMBOL_TIMEOUT, LORA_FIX_LENGTH_PAYLOAD_ON, | |||||
| 0, true, 0, 0, LORA_IQ_INVERSION_ON, true ); | |||||
| Radio.SetMaxPayloadLength( MODEM_LORA, 255 ); | |||||
| #elif defined( USE_MODEM_FSK ) | |||||
| Radio.SetRxConfig( MODEM_FSK, FSK_BANDWIDTH, FSK_DATARATE, | |||||
| 0, FSK_AFC_BANDWIDTH, FSK_PREAMBLE_LENGTH, | |||||
| 0, FSK_FIX_LENGTH_PAYLOAD_ON, 0, true, | |||||
| 0, 0, false, true ); | |||||
| Radio.SetMaxPayloadLength( MODEM_FSK, 255 ); | |||||
| #else | |||||
| #error "Please define a frequency band in the compiler options." | |||||
| #endif | |||||
| Radio.Rx( 0 ); // Continuous Rx | |||||
| while( 1 ) | |||||
| { | |||||
| BoardLowPowerHandler( ); | |||||
| // Process Radio IRQ | |||||
| if( Radio.IrqProcess != NULL ) | |||||
| { | |||||
| Radio.IrqProcess( ); | |||||
| } | |||||
| } | |||||
| } | |||||
| void OnRxDone( uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr ) | |||||
| { | |||||
| static uint8_t ledState = 1; | |||||
| // Toggle LED 1 | |||||
| ledState ^= 1; | |||||
| GpioWrite( &Led1, ledState ); | |||||
| } | |||||
| @@ -1,177 +1,177 @@ | |||||
| /*! | |||||
| * \file main.c | |||||
| * | |||||
| * \brief Radio sensitivity test | |||||
| * | |||||
| * \remark When LED1 stops blinking LoRa packets aren't received any more and | |||||
| * the sensitivity level has been reached. | |||||
| * By reading the RF generator output power we can estimate the board | |||||
| * sensitivity | |||||
| * | |||||
| * \copyright Revised BSD License, see section \ref LICENSE. | |||||
| * | |||||
| * \code | |||||
| * ______ _ | |||||
| * / _____) _ | | | |||||
| * ( (____ _____ ____ _| |_ _____ ____| |__ | |||||
| * \____ \| ___ | (_ _) ___ |/ ___) _ \ | |||||
| * _____) ) ____| | | || |_| ____( (___| | | | | |||||
| * (______/|_____)_|_|_| \__)_____)\____)_| |_| | |||||
| * (C)2013-2017 Semtech | |||||
| * | |||||
| * \endcode | |||||
| * | |||||
| * \author Miguel Luis ( Semtech ) | |||||
| * | |||||
| * \author Gregory Cristian ( Semtech ) | |||||
| */ | |||||
| #include "board.h" | |||||
| #include "gpio.h" | |||||
| #include "timer.h" | |||||
| #include "radio.h" | |||||
| #if defined( REGION_AS923 ) | |||||
| #define RF_FREQUENCY 923000000 // Hz | |||||
| #elif defined( REGION_AU915 ) | |||||
| #define RF_FREQUENCY 915000000 // Hz | |||||
| #elif defined( REGION_CN470 ) | |||||
| #define RF_FREQUENCY 470000000 // Hz | |||||
| #elif defined( REGION_CN779 ) | |||||
| #define RF_FREQUENCY 779000000 // Hz | |||||
| #elif defined( REGION_EU433 ) | |||||
| #define RF_FREQUENCY 433000000 // Hz | |||||
| #elif defined( REGION_EU868 ) | |||||
| #define RF_FREQUENCY 868000000 // Hz | |||||
| #elif defined( REGION_KR920 ) | |||||
| #define RF_FREQUENCY 920000000 // Hz | |||||
| #elif defined( REGION_IN865 ) | |||||
| #define RF_FREQUENCY 865000000 // Hz | |||||
| #elif defined( REGION_US915 ) | |||||
| #define RF_FREQUENCY 915000000 // Hz | |||||
| #elif defined( REGION_RU864 ) | |||||
| #define RF_FREQUENCY 864000000 // Hz | |||||
| #else | |||||
| #error "Please define a frequency band in the compiler options." | |||||
| #endif | |||||
| #if defined( USE_MODEM_LORA ) | |||||
| #define LORA_BANDWIDTH 0 // [0: 125 kHz, | |||||
| // 1: 250 kHz, | |||||
| // 2: 500 kHz, | |||||
| // 3: Reserved] | |||||
| #define LORA_SPREADING_FACTOR 10 // [SF7..SF12] | |||||
| #define LORA_CODINGRATE 1 // [1: 4/5, | |||||
| // 2: 4/6, | |||||
| // 3: 4/7, | |||||
| // 4: 4/8] | |||||
| #define LORA_SYMBOL_TIMEOUT 5 // Symbols | |||||
| #define LORA_PREAMBLE_LENGTH 8 // Same for Tx and Rx | |||||
| #define LORA_FIX_LENGTH_PAYLOAD_ON false | |||||
| #define LORA_IQ_INVERSION_ON false | |||||
| #elif defined( USE_MODEM_FSK ) | |||||
| #define FSK_DATARATE 50000 // bps | |||||
| #define FSK_BANDWIDTH 50000 // Hz | |||||
| #define FSK_AFC_BANDWIDTH 83333 // Hz | |||||
| #define FSK_PREAMBLE_LENGTH 5 // Same for Tx and Rx | |||||
| #define FSK_FIX_LENGTH_PAYLOAD_ON false | |||||
| #else | |||||
| #error "Please define a modem in the compiler options." | |||||
| #endif | |||||
| /*! | |||||
| * Radio events function pointer | |||||
| */ | |||||
| static RadioEvents_t RadioEvents; | |||||
| /*! | |||||
| * LED GPIO pins objects | |||||
| */ | |||||
| extern Gpio_t Led1; | |||||
| /*! | |||||
| * \brief Function to be executed on Radio Rx Done event | |||||
| */ | |||||
| void OnRxDone( uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr ); | |||||
| /*! | |||||
| * Main application entry point. | |||||
| */ | |||||
| int main( void ) | |||||
| { | |||||
| // Target board initialization | |||||
| BoardInitMcu( ); | |||||
| BoardInitPeriph( ); | |||||
| // Radio initialization | |||||
| RadioEvents.RxDone = OnRxDone; | |||||
| Radio.Init( &RadioEvents ); | |||||
| Radio.SetChannel( RF_FREQUENCY ); | |||||
| #if defined( USE_MODEM_LORA ) | |||||
| Radio.SetRxConfig( MODEM_LORA, LORA_BANDWIDTH, LORA_SPREADING_FACTOR, | |||||
| LORA_CODINGRATE, 0, LORA_PREAMBLE_LENGTH, | |||||
| LORA_SYMBOL_TIMEOUT, LORA_FIX_LENGTH_PAYLOAD_ON, | |||||
| 0, true, 0, 0, LORA_IQ_INVERSION_ON, true ); | |||||
| Radio.SetMaxPayloadLength( MODEM_LORA, 255 ); | |||||
| #elif defined( USE_MODEM_FSK ) | |||||
| Radio.SetRxConfig( MODEM_FSK, FSK_BANDWIDTH, FSK_DATARATE, | |||||
| 0, FSK_AFC_BANDWIDTH, FSK_PREAMBLE_LENGTH, | |||||
| 0, FSK_FIX_LENGTH_PAYLOAD_ON, 0, true, | |||||
| 0, 0, false, true ); | |||||
| Radio.SetMaxPayloadLength( MODEM_FSK, 255 ); | |||||
| #else | |||||
| #error "Please define a frequency band in the compiler options." | |||||
| #endif | |||||
| Radio.Rx( 0 ); // Continuous Rx | |||||
| while( 1 ) | |||||
| { | |||||
| BoardLowPowerHandler( ); | |||||
| // Process Radio IRQ | |||||
| if( Radio.IrqProcess != NULL ) | |||||
| { | |||||
| Radio.IrqProcess( ); | |||||
| } | |||||
| } | |||||
| } | |||||
| void OnRxDone( uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr ) | |||||
| { | |||||
| static uint8_t ledState = 1; | |||||
| // Toggle LED 1 | |||||
| ledState ^= 1; | |||||
| GpioWrite( &Led1, ledState ); | |||||
| } | |||||
| /*! | |||||
| * \file main.c | |||||
| * | |||||
| * \brief Radio sensitivity test | |||||
| * | |||||
| * \remark When LED1 stops blinking LoRa packets aren't received any more and | |||||
| * the sensitivity level has been reached. | |||||
| * By reading the RF generator output power we can estimate the board | |||||
| * sensitivity | |||||
| * | |||||
| * \copyright Revised BSD License, see section \ref LICENSE. | |||||
| * | |||||
| * \code | |||||
| * ______ _ | |||||
| * / _____) _ | | | |||||
| * ( (____ _____ ____ _| |_ _____ ____| |__ | |||||
| * \____ \| ___ | (_ _) ___ |/ ___) _ \ | |||||
| * _____) ) ____| | | || |_| ____( (___| | | | | |||||
| * (______/|_____)_|_|_| \__)_____)\____)_| |_| | |||||
| * (C)2013-2017 Semtech | |||||
| * | |||||
| * \endcode | |||||
| * | |||||
| * \author Miguel Luis ( Semtech ) | |||||
| * | |||||
| * \author Gregory Cristian ( Semtech ) | |||||
| */ | |||||
| #include "board.h" | |||||
| #include "gpio.h" | |||||
| #include "timer.h" | |||||
| #include "radio.h" | |||||
| #if defined( REGION_AS923 ) | |||||
| #define RF_FREQUENCY 923000000 // Hz | |||||
| #elif defined( REGION_AU915 ) | |||||
| #define RF_FREQUENCY 915000000 // Hz | |||||
| #elif defined( REGION_CN470 ) | |||||
| #define RF_FREQUENCY 470000000 // Hz | |||||
| #elif defined( REGION_CN779 ) | |||||
| #define RF_FREQUENCY 779000000 // Hz | |||||
| #elif defined( REGION_EU433 ) | |||||
| #define RF_FREQUENCY 433000000 // Hz | |||||
| #elif defined( REGION_EU868 ) | |||||
| #define RF_FREQUENCY 868000000 // Hz | |||||
| #elif defined( REGION_KR920 ) | |||||
| #define RF_FREQUENCY 920000000 // Hz | |||||
| #elif defined( REGION_IN865 ) | |||||
| #define RF_FREQUENCY 865000000 // Hz | |||||
| #elif defined( REGION_US915 ) | |||||
| #define RF_FREQUENCY 915000000 // Hz | |||||
| #elif defined( REGION_RU864 ) | |||||
| #define RF_FREQUENCY 864000000 // Hz | |||||
| #else | |||||
| #error "Please define a frequency band in the compiler options." | |||||
| #endif | |||||
| #if defined( USE_MODEM_LORA ) | |||||
| #define LORA_BANDWIDTH 0 // [0: 125 kHz, | |||||
| // 1: 250 kHz, | |||||
| // 2: 500 kHz, | |||||
| // 3: Reserved] | |||||
| #define LORA_SPREADING_FACTOR 10 // [SF7..SF12] | |||||
| #define LORA_CODINGRATE 1 // [1: 4/5, | |||||
| // 2: 4/6, | |||||
| // 3: 4/7, | |||||
| // 4: 4/8] | |||||
| #define LORA_SYMBOL_TIMEOUT 5 // Symbols | |||||
| #define LORA_PREAMBLE_LENGTH 8 // Same for Tx and Rx | |||||
| #define LORA_FIX_LENGTH_PAYLOAD_ON false | |||||
| #define LORA_IQ_INVERSION_ON false | |||||
| #elif defined( USE_MODEM_FSK ) | |||||
| #define FSK_DATARATE 50000 // bps | |||||
| #define FSK_BANDWIDTH 50000 // Hz | |||||
| #define FSK_AFC_BANDWIDTH 83333 // Hz | |||||
| #define FSK_PREAMBLE_LENGTH 5 // Same for Tx and Rx | |||||
| #define FSK_FIX_LENGTH_PAYLOAD_ON false | |||||
| #else | |||||
| #error "Please define a modem in the compiler options." | |||||
| #endif | |||||
| /*! | |||||
| * Radio events function pointer | |||||
| */ | |||||
| static RadioEvents_t RadioEvents; | |||||
| /*! | |||||
| * LED GPIO pins objects | |||||
| */ | |||||
| extern Gpio_t Led1; | |||||
| /*! | |||||
| * \brief Function to be executed on Radio Rx Done event | |||||
| */ | |||||
| void OnRxDone( uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr ); | |||||
| /*! | |||||
| * Main application entry point. | |||||
| */ | |||||
| int main( void ) | |||||
| { | |||||
| // Target board initialization | |||||
| BoardInitMcu( ); | |||||
| BoardInitPeriph( ); | |||||
| // Radio initialization | |||||
| RadioEvents.RxDone = OnRxDone; | |||||
| Radio.Init( &RadioEvents ); | |||||
| Radio.SetChannel( RF_FREQUENCY ); | |||||
| #if defined( USE_MODEM_LORA ) | |||||
| Radio.SetRxConfig( MODEM_LORA, LORA_BANDWIDTH, LORA_SPREADING_FACTOR, | |||||
| LORA_CODINGRATE, 0, LORA_PREAMBLE_LENGTH, | |||||
| LORA_SYMBOL_TIMEOUT, LORA_FIX_LENGTH_PAYLOAD_ON, | |||||
| 0, true, 0, 0, LORA_IQ_INVERSION_ON, true ); | |||||
| Radio.SetMaxPayloadLength( MODEM_LORA, 255 ); | |||||
| #elif defined( USE_MODEM_FSK ) | |||||
| Radio.SetRxConfig( MODEM_FSK, FSK_BANDWIDTH, FSK_DATARATE, | |||||
| 0, FSK_AFC_BANDWIDTH, FSK_PREAMBLE_LENGTH, | |||||
| 0, FSK_FIX_LENGTH_PAYLOAD_ON, 0, true, | |||||
| 0, 0, false, true ); | |||||
| Radio.SetMaxPayloadLength( MODEM_FSK, 255 ); | |||||
| #else | |||||
| #error "Please define a frequency band in the compiler options." | |||||
| #endif | |||||
| Radio.Rx( 0 ); // Continuous Rx | |||||
| while( 1 ) | |||||
| { | |||||
| BoardLowPowerHandler( ); | |||||
| // Process Radio IRQ | |||||
| if( Radio.IrqProcess != NULL ) | |||||
| { | |||||
| Radio.IrqProcess( ); | |||||
| } | |||||
| } | |||||
| } | |||||
| void OnRxDone( uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr ) | |||||
| { | |||||
| static uint8_t ledState = 1; | |||||
| // Toggle LED 1 | |||||
| ledState ^= 1; | |||||
| GpioWrite( &Led1, ledState ); | |||||
| } | |||||
| @@ -1,177 +1,177 @@ | |||||
| /*! | |||||
| * \file main.c | |||||
| * | |||||
| * \brief Radio sensitivity test | |||||
| * | |||||
| * \remark When LED1 stops blinking LoRa packets aren't received any more and | |||||
| * the sensitivity level has been reached. | |||||
| * By reading the RF generator output power we can estimate the board | |||||
| * sensitivity | |||||
| * | |||||
| * \copyright Revised BSD License, see section \ref LICENSE. | |||||
| * | |||||
| * \code | |||||
| * ______ _ | |||||
| * / _____) _ | | | |||||
| * ( (____ _____ ____ _| |_ _____ ____| |__ | |||||
| * \____ \| ___ | (_ _) ___ |/ ___) _ \ | |||||
| * _____) ) ____| | | || |_| ____( (___| | | | | |||||
| * (______/|_____)_|_|_| \__)_____)\____)_| |_| | |||||
| * (C)2013-2017 Semtech | |||||
| * | |||||
| * \endcode | |||||
| * | |||||
| * \author Miguel Luis ( Semtech ) | |||||
| * | |||||
| * \author Gregory Cristian ( Semtech ) | |||||
| * | |||||
| * \author Marten Lootsma(TWTG) on behalf of Microchip/Atmel (c)2017 | |||||
| */ | |||||
| #include "board.h" | |||||
| #include "gpio.h" | |||||
| #include "timer.h" | |||||
| #include "radio.h" | |||||
| #if defined( REGION_AS923 ) | |||||
| #define RF_FREQUENCY 923000000 // Hz | |||||
| #elif defined( REGION_AU915 ) | |||||
| #define RF_FREQUENCY 915000000 // Hz | |||||
| #elif defined( REGION_CN470 ) | |||||
| #define RF_FREQUENCY 470000000 // Hz | |||||
| #elif defined( REGION_CN779 ) | |||||
| #define RF_FREQUENCY 779000000 // Hz | |||||
| #elif defined( REGION_EU433 ) | |||||
| #define RF_FREQUENCY 433000000 // Hz | |||||
| #elif defined( REGION_EU868 ) | |||||
| #define RF_FREQUENCY 868000000 // Hz | |||||
| #elif defined( REGION_KR920 ) | |||||
| #define RF_FREQUENCY 920000000 // Hz | |||||
| #elif defined( REGION_IN865 ) | |||||
| #define RF_FREQUENCY 865000000 // Hz | |||||
| #elif defined( REGION_US915 ) | |||||
| #define RF_FREQUENCY 915000000 // Hz | |||||
| #elif defined( REGION_RU864 ) | |||||
| #define RF_FREQUENCY 864000000 // Hz | |||||
| #else | |||||
| #error "Please define a frequency band in the compiler options." | |||||
| #endif | |||||
| #if defined( USE_MODEM_LORA ) | |||||
| #define LORA_BANDWIDTH 0 // [0: 125 kHz, | |||||
| // 1: 250 kHz, | |||||
| // 2: 500 kHz, | |||||
| // 3: Reserved] | |||||
| #define LORA_SPREADING_FACTOR 10 // [SF7..SF12] | |||||
| #define LORA_CODINGRATE 1 // [1: 4/5, | |||||
| // 2: 4/6, | |||||
| // 3: 4/7, | |||||
| // 4: 4/8] | |||||
| #define LORA_SYMBOL_TIMEOUT 5 // Symbols | |||||
| #define LORA_PREAMBLE_LENGTH 8 // Same for Tx and Rx | |||||
| #define LORA_FIX_LENGTH_PAYLOAD_ON false | |||||
| #define LORA_IQ_INVERSION_ON false | |||||
| #elif defined( USE_MODEM_FSK ) | |||||
| #define FSK_DATARATE 50000 // bps | |||||
| #define FSK_BANDWIDTH 50000 // Hz | |||||
| #define FSK_AFC_BANDWIDTH 83333 // Hz | |||||
| #define FSK_PREAMBLE_LENGTH 5 // Same for Tx and Rx | |||||
| #define FSK_FIX_LENGTH_PAYLOAD_ON false | |||||
| #else | |||||
| #error "Please define a modem in the compiler options." | |||||
| #endif | |||||
| /*! | |||||
| * Radio events function pointer | |||||
| */ | |||||
| static RadioEvents_t RadioEvents; | |||||
| /*! | |||||
| * LED GPIO pins objects | |||||
| */ | |||||
| extern Gpio_t Led1; | |||||
| /*! | |||||
| * \brief Function to be executed on Radio Rx Done event | |||||
| */ | |||||
| void OnRxDone( uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr ); | |||||
| /*! | |||||
| * Main application entry point. | |||||
| */ | |||||
| int main( void ) | |||||
| { | |||||
| // Target board initialization | |||||
| BoardInitMcu( ); | |||||
| BoardInitPeriph( ); | |||||
| // Radio initialization | |||||
| RadioEvents.RxDone = OnRxDone; | |||||
| Radio.Init( &RadioEvents ); | |||||
| Radio.SetChannel( RF_FREQUENCY ); | |||||
| #if defined( USE_MODEM_LORA ) | |||||
| Radio.SetRxConfig( MODEM_LORA, LORA_BANDWIDTH, LORA_SPREADING_FACTOR, | |||||
| LORA_CODINGRATE, 0, LORA_PREAMBLE_LENGTH, | |||||
| LORA_SYMBOL_TIMEOUT, LORA_FIX_LENGTH_PAYLOAD_ON, | |||||
| 0, true, 0, 0, LORA_IQ_INVERSION_ON, true ); | |||||
| Radio.SetMaxPayloadLength( MODEM_LORA, 255 ); | |||||
| #elif defined( USE_MODEM_FSK ) | |||||
| Radio.SetRxConfig( MODEM_FSK, FSK_BANDWIDTH, FSK_DATARATE, | |||||
| 0, FSK_AFC_BANDWIDTH, FSK_PREAMBLE_LENGTH, | |||||
| 0, FSK_FIX_LENGTH_PAYLOAD_ON, 0, true, | |||||
| 0, 0, false, true ); | |||||
| Radio.SetMaxPayloadLength( MODEM_FSK, 255 ); | |||||
| #else | |||||
| #error "Please define a frequency band in the compiler options." | |||||
| #endif | |||||
| Radio.Rx( 0 ); // Continuous Rx | |||||
| while( 1 ) | |||||
| { | |||||
| // Tick the RTC to execute callback in context of the main loop (in stead of the IRQ) | |||||
| TimerProcess( ); | |||||
| BoardLowPowerHandler( ); | |||||
| } | |||||
| } | |||||
| void OnRxDone( uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr ) | |||||
| { | |||||
| static uint8_t ledState = 1; | |||||
| // Toggle LED 1 | |||||
| ledState ^= 1; | |||||
| GpioWrite( &Led1, ledState ); | |||||
| } | |||||
| /*! | |||||
| * \file main.c | |||||
| * | |||||
| * \brief Radio sensitivity test | |||||
| * | |||||
| * \remark When LED1 stops blinking LoRa packets aren't received any more and | |||||
| * the sensitivity level has been reached. | |||||
| * By reading the RF generator output power we can estimate the board | |||||
| * sensitivity | |||||
| * | |||||
| * \copyright Revised BSD License, see section \ref LICENSE. | |||||
| * | |||||
| * \code | |||||
| * ______ _ | |||||
| * / _____) _ | | | |||||
| * ( (____ _____ ____ _| |_ _____ ____| |__ | |||||
| * \____ \| ___ | (_ _) ___ |/ ___) _ \ | |||||
| * _____) ) ____| | | || |_| ____( (___| | | | | |||||
| * (______/|_____)_|_|_| \__)_____)\____)_| |_| | |||||
| * (C)2013-2017 Semtech | |||||
| * | |||||
| * \endcode | |||||
| * | |||||
| * \author Miguel Luis ( Semtech ) | |||||
| * | |||||
| * \author Gregory Cristian ( Semtech ) | |||||
| * | |||||
| * \author Marten Lootsma(TWTG) on behalf of Microchip/Atmel (c)2017 | |||||
| */ | |||||
| #include "board.h" | |||||
| #include "gpio.h" | |||||
| #include "timer.h" | |||||
| #include "radio.h" | |||||
| #if defined( REGION_AS923 ) | |||||
| #define RF_FREQUENCY 923000000 // Hz | |||||
| #elif defined( REGION_AU915 ) | |||||
| #define RF_FREQUENCY 915000000 // Hz | |||||
| #elif defined( REGION_CN470 ) | |||||
| #define RF_FREQUENCY 470000000 // Hz | |||||
| #elif defined( REGION_CN779 ) | |||||
| #define RF_FREQUENCY 779000000 // Hz | |||||
| #elif defined( REGION_EU433 ) | |||||
| #define RF_FREQUENCY 433000000 // Hz | |||||
| #elif defined( REGION_EU868 ) | |||||
| #define RF_FREQUENCY 868000000 // Hz | |||||
| #elif defined( REGION_KR920 ) | |||||
| #define RF_FREQUENCY 920000000 // Hz | |||||
| #elif defined( REGION_IN865 ) | |||||
| #define RF_FREQUENCY 865000000 // Hz | |||||
| #elif defined( REGION_US915 ) | |||||
| #define RF_FREQUENCY 915000000 // Hz | |||||
| #elif defined( REGION_RU864 ) | |||||
| #define RF_FREQUENCY 864000000 // Hz | |||||
| #else | |||||
| #error "Please define a frequency band in the compiler options." | |||||
| #endif | |||||
| #if defined( USE_MODEM_LORA ) | |||||
| #define LORA_BANDWIDTH 0 // [0: 125 kHz, | |||||
| // 1: 250 kHz, | |||||
| // 2: 500 kHz, | |||||
| // 3: Reserved] | |||||
| #define LORA_SPREADING_FACTOR 10 // [SF7..SF12] | |||||
| #define LORA_CODINGRATE 1 // [1: 4/5, | |||||
| // 2: 4/6, | |||||
| // 3: 4/7, | |||||
| // 4: 4/8] | |||||
| #define LORA_SYMBOL_TIMEOUT 5 // Symbols | |||||
| #define LORA_PREAMBLE_LENGTH 8 // Same for Tx and Rx | |||||
| #define LORA_FIX_LENGTH_PAYLOAD_ON false | |||||
| #define LORA_IQ_INVERSION_ON false | |||||
| #elif defined( USE_MODEM_FSK ) | |||||
| #define FSK_DATARATE 50000 // bps | |||||
| #define FSK_BANDWIDTH 50000 // Hz | |||||
| #define FSK_AFC_BANDWIDTH 83333 // Hz | |||||
| #define FSK_PREAMBLE_LENGTH 5 // Same for Tx and Rx | |||||
| #define FSK_FIX_LENGTH_PAYLOAD_ON false | |||||
| #else | |||||
| #error "Please define a modem in the compiler options." | |||||
| #endif | |||||
| /*! | |||||
| * Radio events function pointer | |||||
| */ | |||||
| static RadioEvents_t RadioEvents; | |||||
| /*! | |||||
| * LED GPIO pins objects | |||||
| */ | |||||
| extern Gpio_t Led1; | |||||
| /*! | |||||
| * \brief Function to be executed on Radio Rx Done event | |||||
| */ | |||||
| void OnRxDone( uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr ); | |||||
| /*! | |||||
| * Main application entry point. | |||||
| */ | |||||
| int main( void ) | |||||
| { | |||||
| // Target board initialization | |||||
| BoardInitMcu( ); | |||||
| BoardInitPeriph( ); | |||||
| // Radio initialization | |||||
| RadioEvents.RxDone = OnRxDone; | |||||
| Radio.Init( &RadioEvents ); | |||||
| Radio.SetChannel( RF_FREQUENCY ); | |||||
| #if defined( USE_MODEM_LORA ) | |||||
| Radio.SetRxConfig( MODEM_LORA, LORA_BANDWIDTH, LORA_SPREADING_FACTOR, | |||||
| LORA_CODINGRATE, 0, LORA_PREAMBLE_LENGTH, | |||||
| LORA_SYMBOL_TIMEOUT, LORA_FIX_LENGTH_PAYLOAD_ON, | |||||
| 0, true, 0, 0, LORA_IQ_INVERSION_ON, true ); | |||||
| Radio.SetMaxPayloadLength( MODEM_LORA, 255 ); | |||||
| #elif defined( USE_MODEM_FSK ) | |||||
| Radio.SetRxConfig( MODEM_FSK, FSK_BANDWIDTH, FSK_DATARATE, | |||||
| 0, FSK_AFC_BANDWIDTH, FSK_PREAMBLE_LENGTH, | |||||
| 0, FSK_FIX_LENGTH_PAYLOAD_ON, 0, true, | |||||
| 0, 0, false, true ); | |||||
| Radio.SetMaxPayloadLength( MODEM_FSK, 255 ); | |||||
| #else | |||||
| #error "Please define a frequency band in the compiler options." | |||||
| #endif | |||||
| Radio.Rx( 0 ); // Continuous Rx | |||||
| while( 1 ) | |||||
| { | |||||
| // Tick the RTC to execute callback in context of the main loop (in stead of the IRQ) | |||||
| TimerProcess( ); | |||||
| BoardLowPowerHandler( ); | |||||
| } | |||||
| } | |||||
| void OnRxDone( uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr ) | |||||
| { | |||||
| static uint8_t ledState = 1; | |||||
| // Toggle LED 1 | |||||
| ledState ^= 1; | |||||
| GpioWrite( &Led1, ledState ); | |||||
| } | |||||
| @@ -1,164 +1,164 @@ | |||||
| /*! | |||||
| * \file main.c | |||||
| * | |||||
| * \brief Radio sensitivity test | |||||
| * | |||||
| * \remark When LED1 stops blinking LoRa packets aren't received any more and | |||||
| * the sensitivity level has been reached. | |||||
| * By reading the RF generator output power we can estimate the board | |||||
| * sensitivity | |||||
| * | |||||
| * \copyright Revised BSD License, see section \ref LICENSE. | |||||
| * | |||||
| * \code | |||||
| * ______ _ | |||||
| * / _____) _ | | | |||||
| * ( (____ _____ ____ _| |_ _____ ____| |__ | |||||
| * \____ \| ___ | (_ _) ___ |/ ___) _ \ | |||||
| * _____) ) ____| | | || |_| ____( (___| | | | | |||||
| * (______/|_____)_|_|_| \__)_____)\____)_| |_| | |||||
| * (C)2013-2017 Semtech | |||||
| * | |||||
| * \endcode | |||||
| * | |||||
| * \author Miguel Luis ( Semtech ) | |||||
| * | |||||
| * \author Gregory Cristian ( Semtech ) | |||||
| */ | |||||
| #include "board.h" | |||||
| #include "gpio.h" | |||||
| #include "timer.h" | |||||
| #include "radio.h" | |||||
| #if defined( REGION_AS923 ) | |||||
| #define RF_FREQUENCY 923000000 // Hz | |||||
| #elif defined( REGION_AU915 ) | |||||
| #define RF_FREQUENCY 915000000 // Hz | |||||
| #elif defined( REGION_CN779 ) | |||||
| #define RF_FREQUENCY 779000000 // Hz | |||||
| #elif defined( REGION_EU868 ) | |||||
| #define RF_FREQUENCY 868000000 // Hz | |||||
| #elif defined( REGION_KR920 ) | |||||
| #define RF_FREQUENCY 920000000 // Hz | |||||
| #elif defined( REGION_IN865 ) | |||||
| #define RF_FREQUENCY 865000000 // Hz | |||||
| #elif defined( REGION_US915 ) | |||||
| #define RF_FREQUENCY 915000000 // Hz | |||||
| #elif defined( REGION_RU864 ) | |||||
| #define RF_FREQUENCY 864000000 // Hz | |||||
| #else | |||||
| #error "Please define a frequency band in the compiler options." | |||||
| #endif | |||||
| #if defined( USE_MODEM_LORA ) | |||||
| #define LORA_BANDWIDTH 0 // [0: 125 kHz, | |||||
| // 1: 250 kHz, | |||||
| // 2: 500 kHz, | |||||
| // 3: Reserved] | |||||
| #define LORA_SPREADING_FACTOR 10 // [SF7..SF12] | |||||
| #define LORA_CODINGRATE 1 // [1: 4/5, | |||||
| // 2: 4/6, | |||||
| // 3: 4/7, | |||||
| // 4: 4/8] | |||||
| #define LORA_SYMBOL_TIMEOUT 5 // Symbols | |||||
| #define LORA_PREAMBLE_LENGTH 8 // Same for Tx and Rx | |||||
| #define LORA_FIX_LENGTH_PAYLOAD_ON false | |||||
| #define LORA_IQ_INVERSION_ON false | |||||
| #elif defined( USE_MODEM_FSK ) | |||||
| #define FSK_DATARATE 50000 // bps | |||||
| #define FSK_BANDWIDTH 50000 // Hz | |||||
| #define FSK_AFC_BANDWIDTH 83333 // Hz | |||||
| #define FSK_PREAMBLE_LENGTH 5 // Same for Tx and Rx | |||||
| #define FSK_FIX_LENGTH_PAYLOAD_ON false | |||||
| #else | |||||
| #error "Please define a modem in the compiler options." | |||||
| #endif | |||||
| /*! | |||||
| * Radio events function pointer | |||||
| */ | |||||
| static RadioEvents_t RadioEvents; | |||||
| /*! | |||||
| * LED GPIO pins objects | |||||
| */ | |||||
| extern Gpio_t Led4; | |||||
| /*! | |||||
| * \brief Function to be executed on Radio Rx Done event | |||||
| */ | |||||
| void OnRxDone( uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr ); | |||||
| /*! | |||||
| * Main application entry point. | |||||
| */ | |||||
| int main( void ) | |||||
| { | |||||
| // Target board initialization | |||||
| BoardInitMcu( ); | |||||
| BoardInitPeriph( ); | |||||
| // Radio initialization | |||||
| RadioEvents.RxDone = OnRxDone; | |||||
| Radio.Init( &RadioEvents ); | |||||
| Radio.SetChannel( RF_FREQUENCY ); | |||||
| #if defined( USE_MODEM_LORA ) | |||||
| Radio.SetRxConfig( MODEM_LORA, LORA_BANDWIDTH, LORA_SPREADING_FACTOR, | |||||
| LORA_CODINGRATE, 0, LORA_PREAMBLE_LENGTH, | |||||
| LORA_SYMBOL_TIMEOUT, LORA_FIX_LENGTH_PAYLOAD_ON, | |||||
| 0, true, 0, 0, LORA_IQ_INVERSION_ON, true ); | |||||
| Radio.SetMaxPayloadLength( MODEM_LORA, 255 ); | |||||
| #elif defined( USE_MODEM_FSK ) | |||||
| Radio.SetRxConfig( MODEM_FSK, FSK_BANDWIDTH, FSK_DATARATE, | |||||
| 0, FSK_AFC_BANDWIDTH, FSK_PREAMBLE_LENGTH, | |||||
| 0, FSK_FIX_LENGTH_PAYLOAD_ON, 0, true, | |||||
| 0, 0, false, true ); | |||||
| Radio.SetMaxPayloadLength( MODEM_FSK, 255 ); | |||||
| #else | |||||
| #error "Please define a frequency band in the compiler options." | |||||
| #endif | |||||
| Radio.Rx( 0 ); // Continuous Rx | |||||
| while( 1 ) | |||||
| { | |||||
| BoardLowPowerHandler( ); | |||||
| } | |||||
| } | |||||
| void OnRxDone( uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr ) | |||||
| { | |||||
| static uint8_t ledState = 1; | |||||
| // Toggle LED 4 | |||||
| ledState ^= 1; | |||||
| GpioWrite( &Led4, ledState ); | |||||
| } | |||||
| /*! | |||||
| * \file main.c | |||||
| * | |||||
| * \brief Radio sensitivity test | |||||
| * | |||||
| * \remark When LED1 stops blinking LoRa packets aren't received any more and | |||||
| * the sensitivity level has been reached. | |||||
| * By reading the RF generator output power we can estimate the board | |||||
| * sensitivity | |||||
| * | |||||
| * \copyright Revised BSD License, see section \ref LICENSE. | |||||
| * | |||||
| * \code | |||||
| * ______ _ | |||||
| * / _____) _ | | | |||||
| * ( (____ _____ ____ _| |_ _____ ____| |__ | |||||
| * \____ \| ___ | (_ _) ___ |/ ___) _ \ | |||||
| * _____) ) ____| | | || |_| ____( (___| | | | | |||||
| * (______/|_____)_|_|_| \__)_____)\____)_| |_| | |||||
| * (C)2013-2017 Semtech | |||||
| * | |||||
| * \endcode | |||||
| * | |||||
| * \author Miguel Luis ( Semtech ) | |||||
| * | |||||
| * \author Gregory Cristian ( Semtech ) | |||||
| */ | |||||
| #include "board.h" | |||||
| #include "gpio.h" | |||||
| #include "timer.h" | |||||
| #include "radio.h" | |||||
| #if defined( REGION_AS923 ) | |||||
| #define RF_FREQUENCY 923000000 // Hz | |||||
| #elif defined( REGION_AU915 ) | |||||
| #define RF_FREQUENCY 915000000 // Hz | |||||
| #elif defined( REGION_CN779 ) | |||||
| #define RF_FREQUENCY 779000000 // Hz | |||||
| #elif defined( REGION_EU868 ) | |||||
| #define RF_FREQUENCY 868000000 // Hz | |||||
| #elif defined( REGION_KR920 ) | |||||
| #define RF_FREQUENCY 920000000 // Hz | |||||
| #elif defined( REGION_IN865 ) | |||||
| #define RF_FREQUENCY 865000000 // Hz | |||||
| #elif defined( REGION_US915 ) | |||||
| #define RF_FREQUENCY 915000000 // Hz | |||||
| #elif defined( REGION_RU864 ) | |||||
| #define RF_FREQUENCY 864000000 // Hz | |||||
| #else | |||||
| #error "Please define a frequency band in the compiler options." | |||||
| #endif | |||||
| #if defined( USE_MODEM_LORA ) | |||||
| #define LORA_BANDWIDTH 0 // [0: 125 kHz, | |||||
| // 1: 250 kHz, | |||||
| // 2: 500 kHz, | |||||
| // 3: Reserved] | |||||
| #define LORA_SPREADING_FACTOR 10 // [SF7..SF12] | |||||
| #define LORA_CODINGRATE 1 // [1: 4/5, | |||||
| // 2: 4/6, | |||||
| // 3: 4/7, | |||||
| // 4: 4/8] | |||||
| #define LORA_SYMBOL_TIMEOUT 5 // Symbols | |||||
| #define LORA_PREAMBLE_LENGTH 8 // Same for Tx and Rx | |||||
| #define LORA_FIX_LENGTH_PAYLOAD_ON false | |||||
| #define LORA_IQ_INVERSION_ON false | |||||
| #elif defined( USE_MODEM_FSK ) | |||||
| #define FSK_DATARATE 50000 // bps | |||||
| #define FSK_BANDWIDTH 50000 // Hz | |||||
| #define FSK_AFC_BANDWIDTH 83333 // Hz | |||||
| #define FSK_PREAMBLE_LENGTH 5 // Same for Tx and Rx | |||||
| #define FSK_FIX_LENGTH_PAYLOAD_ON false | |||||
| #else | |||||
| #error "Please define a modem in the compiler options." | |||||
| #endif | |||||
| /*! | |||||
| * Radio events function pointer | |||||
| */ | |||||
| static RadioEvents_t RadioEvents; | |||||
| /*! | |||||
| * LED GPIO pins objects | |||||
| */ | |||||
| extern Gpio_t Led4; | |||||
| /*! | |||||
| * \brief Function to be executed on Radio Rx Done event | |||||
| */ | |||||
| void OnRxDone( uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr ); | |||||
| /*! | |||||
| * Main application entry point. | |||||
| */ | |||||
| int main( void ) | |||||
| { | |||||
| // Target board initialization | |||||
| BoardInitMcu( ); | |||||
| BoardInitPeriph( ); | |||||
| // Radio initialization | |||||
| RadioEvents.RxDone = OnRxDone; | |||||
| Radio.Init( &RadioEvents ); | |||||
| Radio.SetChannel( RF_FREQUENCY ); | |||||
| #if defined( USE_MODEM_LORA ) | |||||
| Radio.SetRxConfig( MODEM_LORA, LORA_BANDWIDTH, LORA_SPREADING_FACTOR, | |||||
| LORA_CODINGRATE, 0, LORA_PREAMBLE_LENGTH, | |||||
| LORA_SYMBOL_TIMEOUT, LORA_FIX_LENGTH_PAYLOAD_ON, | |||||
| 0, true, 0, 0, LORA_IQ_INVERSION_ON, true ); | |||||
| Radio.SetMaxPayloadLength( MODEM_LORA, 255 ); | |||||
| #elif defined( USE_MODEM_FSK ) | |||||
| Radio.SetRxConfig( MODEM_FSK, FSK_BANDWIDTH, FSK_DATARATE, | |||||
| 0, FSK_AFC_BANDWIDTH, FSK_PREAMBLE_LENGTH, | |||||
| 0, FSK_FIX_LENGTH_PAYLOAD_ON, 0, true, | |||||
| 0, 0, false, true ); | |||||
| Radio.SetMaxPayloadLength( MODEM_FSK, 255 ); | |||||
| #else | |||||
| #error "Please define a frequency band in the compiler options." | |||||
| #endif | |||||
| Radio.Rx( 0 ); // Continuous Rx | |||||
| while( 1 ) | |||||
| { | |||||
| BoardLowPowerHandler( ); | |||||
| } | |||||
| } | |||||
| void OnRxDone( uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr ) | |||||
| { | |||||
| static uint8_t ledState = 1; | |||||
| // Toggle LED 4 | |||||
| ledState ^= 1; | |||||
| GpioWrite( &Led4, ledState ); | |||||
| } | |||||
| @@ -1,164 +1,164 @@ | |||||
| /*! | |||||
| * \file main.c | |||||
| * | |||||
| * \brief Radio sensitivity test | |||||
| * | |||||
| * \remark When LED1 stops blinking LoRa packets aren't received any more and | |||||
| * the sensitivity level has been reached. | |||||
| * By reading the RF generator output power we can estimate the board | |||||
| * sensitivity | |||||
| * | |||||
| * \copyright Revised BSD License, see section \ref LICENSE. | |||||
| * | |||||
| * \code | |||||
| * ______ _ | |||||
| * / _____) _ | | | |||||
| * ( (____ _____ ____ _| |_ _____ ____| |__ | |||||
| * \____ \| ___ | (_ _) ___ |/ ___) _ \ | |||||
| * _____) ) ____| | | || |_| ____( (___| | | | | |||||
| * (______/|_____)_|_|_| \__)_____)\____)_| |_| | |||||
| * (C)2013-2017 Semtech | |||||
| * | |||||
| * \endcode | |||||
| * | |||||
| * \author Miguel Luis ( Semtech ) | |||||
| * | |||||
| * \author Gregory Cristian ( Semtech ) | |||||
| */ | |||||
| #include "board.h" | |||||
| #include "gpio.h" | |||||
| #include "timer.h" | |||||
| #include "radio.h" | |||||
| #if defined( REGION_AS923 ) | |||||
| #define RF_FREQUENCY 923000000 // Hz | |||||
| #elif defined( REGION_AU915 ) | |||||
| #define RF_FREQUENCY 915000000 // Hz | |||||
| #elif defined( REGION_CN779 ) | |||||
| #define RF_FREQUENCY 779000000 // Hz | |||||
| #elif defined( REGION_EU868 ) | |||||
| #define RF_FREQUENCY 868000000 // Hz | |||||
| #elif defined( REGION_KR920 ) | |||||
| #define RF_FREQUENCY 920000000 // Hz | |||||
| #elif defined( REGION_IN865 ) | |||||
| #define RF_FREQUENCY 865000000 // Hz | |||||
| #elif defined( REGION_US915 ) | |||||
| #define RF_FREQUENCY 915000000 // Hz | |||||
| #elif defined( REGION_RU864 ) | |||||
| #define RF_FREQUENCY 864000000 // Hz | |||||
| #else | |||||
| #error "Please define a frequency band in the compiler options." | |||||
| #endif | |||||
| #if defined( USE_MODEM_LORA ) | |||||
| #define LORA_BANDWIDTH 0 // [0: 125 kHz, | |||||
| // 1: 250 kHz, | |||||
| // 2: 500 kHz, | |||||
| // 3: Reserved] | |||||
| #define LORA_SPREADING_FACTOR 10 // [SF7..SF12] | |||||
| #define LORA_CODINGRATE 1 // [1: 4/5, | |||||
| // 2: 4/6, | |||||
| // 3: 4/7, | |||||
| // 4: 4/8] | |||||
| #define LORA_SYMBOL_TIMEOUT 5 // Symbols | |||||
| #define LORA_PREAMBLE_LENGTH 8 // Same for Tx and Rx | |||||
| #define LORA_FIX_LENGTH_PAYLOAD_ON false | |||||
| #define LORA_IQ_INVERSION_ON false | |||||
| #elif defined( USE_MODEM_FSK ) | |||||
| #define FSK_DATARATE 50000 // bps | |||||
| #define FSK_BANDWIDTH 50000 // Hz | |||||
| #define FSK_AFC_BANDWIDTH 83333 // Hz | |||||
| #define FSK_PREAMBLE_LENGTH 5 // Same for Tx and Rx | |||||
| #define FSK_FIX_LENGTH_PAYLOAD_ON false | |||||
| #else | |||||
| #error "Please define a modem in the compiler options." | |||||
| #endif | |||||
| /*! | |||||
| * Radio events function pointer | |||||
| */ | |||||
| static RadioEvents_t RadioEvents; | |||||
| /*! | |||||
| * LED GPIO pins objects | |||||
| */ | |||||
| extern Gpio_t Led4; | |||||
| /*! | |||||
| * \brief Function to be executed on Radio Rx Done event | |||||
| */ | |||||
| void OnRxDone( uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr ); | |||||
| /*! | |||||
| * Main application entry point. | |||||
| */ | |||||
| int main( void ) | |||||
| { | |||||
| // Target board initialization | |||||
| BoardInitMcu( ); | |||||
| BoardInitPeriph( ); | |||||
| // Radio initialization | |||||
| RadioEvents.RxDone = OnRxDone; | |||||
| Radio.Init( &RadioEvents ); | |||||
| Radio.SetChannel( RF_FREQUENCY ); | |||||
| #if defined( USE_MODEM_LORA ) | |||||
| Radio.SetRxConfig( MODEM_LORA, LORA_BANDWIDTH, LORA_SPREADING_FACTOR, | |||||
| LORA_CODINGRATE, 0, LORA_PREAMBLE_LENGTH, | |||||
| LORA_SYMBOL_TIMEOUT, LORA_FIX_LENGTH_PAYLOAD_ON, | |||||
| 0, true, 0, 0, LORA_IQ_INVERSION_ON, true ); | |||||
| Radio.SetMaxPayloadLength( MODEM_LORA, 255 ); | |||||
| #elif defined( USE_MODEM_FSK ) | |||||
| Radio.SetRxConfig( MODEM_FSK, FSK_BANDWIDTH, FSK_DATARATE, | |||||
| 0, FSK_AFC_BANDWIDTH, FSK_PREAMBLE_LENGTH, | |||||
| 0, FSK_FIX_LENGTH_PAYLOAD_ON, 0, true, | |||||
| 0, 0, false, true ); | |||||
| Radio.SetMaxPayloadLength( MODEM_FSK, 255 ); | |||||
| #else | |||||
| #error "Please define a frequency band in the compiler options." | |||||
| #endif | |||||
| Radio.Rx( 0 ); // Continuous Rx | |||||
| while( 1 ) | |||||
| { | |||||
| BoardLowPowerHandler( ); | |||||
| } | |||||
| } | |||||
| void OnRxDone( uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr ) | |||||
| { | |||||
| static uint8_t ledState = 1; | |||||
| // Toggle LED 4 | |||||
| ledState ^= 1; | |||||
| GpioWrite( &Led4, ledState ); | |||||
| } | |||||
| /*! | |||||
| * \file main.c | |||||
| * | |||||
| * \brief Radio sensitivity test | |||||
| * | |||||
| * \remark When LED1 stops blinking LoRa packets aren't received any more and | |||||
| * the sensitivity level has been reached. | |||||
| * By reading the RF generator output power we can estimate the board | |||||
| * sensitivity | |||||
| * | |||||
| * \copyright Revised BSD License, see section \ref LICENSE. | |||||
| * | |||||
| * \code | |||||
| * ______ _ | |||||
| * / _____) _ | | | |||||
| * ( (____ _____ ____ _| |_ _____ ____| |__ | |||||
| * \____ \| ___ | (_ _) ___ |/ ___) _ \ | |||||
| * _____) ) ____| | | || |_| ____( (___| | | | | |||||
| * (______/|_____)_|_|_| \__)_____)\____)_| |_| | |||||
| * (C)2013-2017 Semtech | |||||
| * | |||||
| * \endcode | |||||
| * | |||||
| * \author Miguel Luis ( Semtech ) | |||||
| * | |||||
| * \author Gregory Cristian ( Semtech ) | |||||
| */ | |||||
| #include "board.h" | |||||
| #include "gpio.h" | |||||
| #include "timer.h" | |||||
| #include "radio.h" | |||||
| #if defined( REGION_AS923 ) | |||||
| #define RF_FREQUENCY 923000000 // Hz | |||||
| #elif defined( REGION_AU915 ) | |||||
| #define RF_FREQUENCY 915000000 // Hz | |||||
| #elif defined( REGION_CN779 ) | |||||
| #define RF_FREQUENCY 779000000 // Hz | |||||
| #elif defined( REGION_EU868 ) | |||||
| #define RF_FREQUENCY 868000000 // Hz | |||||
| #elif defined( REGION_KR920 ) | |||||
| #define RF_FREQUENCY 920000000 // Hz | |||||
| #elif defined( REGION_IN865 ) | |||||
| #define RF_FREQUENCY 865000000 // Hz | |||||
| #elif defined( REGION_US915 ) | |||||
| #define RF_FREQUENCY 915000000 // Hz | |||||
| #elif defined( REGION_RU864 ) | |||||
| #define RF_FREQUENCY 864000000 // Hz | |||||
| #else | |||||
| #error "Please define a frequency band in the compiler options." | |||||
| #endif | |||||
| #if defined( USE_MODEM_LORA ) | |||||
| #define LORA_BANDWIDTH 0 // [0: 125 kHz, | |||||
| // 1: 250 kHz, | |||||
| // 2: 500 kHz, | |||||
| // 3: Reserved] | |||||
| #define LORA_SPREADING_FACTOR 10 // [SF7..SF12] | |||||
| #define LORA_CODINGRATE 1 // [1: 4/5, | |||||
| // 2: 4/6, | |||||
| // 3: 4/7, | |||||
| // 4: 4/8] | |||||
| #define LORA_SYMBOL_TIMEOUT 5 // Symbols | |||||
| #define LORA_PREAMBLE_LENGTH 8 // Same for Tx and Rx | |||||
| #define LORA_FIX_LENGTH_PAYLOAD_ON false | |||||
| #define LORA_IQ_INVERSION_ON false | |||||
| #elif defined( USE_MODEM_FSK ) | |||||
| #define FSK_DATARATE 50000 // bps | |||||
| #define FSK_BANDWIDTH 50000 // Hz | |||||
| #define FSK_AFC_BANDWIDTH 83333 // Hz | |||||
| #define FSK_PREAMBLE_LENGTH 5 // Same for Tx and Rx | |||||
| #define FSK_FIX_LENGTH_PAYLOAD_ON false | |||||
| #else | |||||
| #error "Please define a modem in the compiler options." | |||||
| #endif | |||||
| /*! | |||||
| * Radio events function pointer | |||||
| */ | |||||
| static RadioEvents_t RadioEvents; | |||||
| /*! | |||||
| * LED GPIO pins objects | |||||
| */ | |||||
| extern Gpio_t Led4; | |||||
| /*! | |||||
| * \brief Function to be executed on Radio Rx Done event | |||||
| */ | |||||
| void OnRxDone( uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr ); | |||||
| /*! | |||||
| * Main application entry point. | |||||
| */ | |||||
| int main( void ) | |||||
| { | |||||
| // Target board initialization | |||||
| BoardInitMcu( ); | |||||
| BoardInitPeriph( ); | |||||
| // Radio initialization | |||||
| RadioEvents.RxDone = OnRxDone; | |||||
| Radio.Init( &RadioEvents ); | |||||
| Radio.SetChannel( RF_FREQUENCY ); | |||||
| #if defined( USE_MODEM_LORA ) | |||||
| Radio.SetRxConfig( MODEM_LORA, LORA_BANDWIDTH, LORA_SPREADING_FACTOR, | |||||
| LORA_CODINGRATE, 0, LORA_PREAMBLE_LENGTH, | |||||
| LORA_SYMBOL_TIMEOUT, LORA_FIX_LENGTH_PAYLOAD_ON, | |||||
| 0, true, 0, 0, LORA_IQ_INVERSION_ON, true ); | |||||
| Radio.SetMaxPayloadLength( MODEM_LORA, 255 ); | |||||
| #elif defined( USE_MODEM_FSK ) | |||||
| Radio.SetRxConfig( MODEM_FSK, FSK_BANDWIDTH, FSK_DATARATE, | |||||
| 0, FSK_AFC_BANDWIDTH, FSK_PREAMBLE_LENGTH, | |||||
| 0, FSK_FIX_LENGTH_PAYLOAD_ON, 0, true, | |||||
| 0, 0, false, true ); | |||||
| Radio.SetMaxPayloadLength( MODEM_FSK, 255 ); | |||||
| #else | |||||
| #error "Please define a frequency band in the compiler options." | |||||
| #endif | |||||
| Radio.Rx( 0 ); // Continuous Rx | |||||
| while( 1 ) | |||||
| { | |||||
| BoardLowPowerHandler( ); | |||||
| } | |||||
| } | |||||
| void OnRxDone( uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr ) | |||||
| { | |||||
| static uint8_t ledState = 1; | |||||
| // Toggle LED 4 | |||||
| ledState ^= 1; | |||||
| GpioWrite( &Led4, ledState ); | |||||
| } | |||||
| @@ -1,164 +1,164 @@ | |||||
| /*! | |||||
| * \file main.c | |||||
| * | |||||
| * \brief Radio sensitivity test | |||||
| * | |||||
| * \remark When LED1 stops blinking LoRa packets aren't received any more and | |||||
| * the sensitivity level has been reached. | |||||
| * By reading the RF generator output power we can estimate the board | |||||
| * sensitivity | |||||
| * | |||||
| * \copyright Revised BSD License, see section \ref LICENSE. | |||||
| * | |||||
| * \code | |||||
| * ______ _ | |||||
| * / _____) _ | | | |||||
| * ( (____ _____ ____ _| |_ _____ ____| |__ | |||||
| * \____ \| ___ | (_ _) ___ |/ ___) _ \ | |||||
| * _____) ) ____| | | || |_| ____( (___| | | | | |||||
| * (______/|_____)_|_|_| \__)_____)\____)_| |_| | |||||
| * (C)2013-2017 Semtech | |||||
| * | |||||
| * \endcode | |||||
| * | |||||
| * \author Miguel Luis ( Semtech ) | |||||
| * | |||||
| * \author Gregory Cristian ( Semtech ) | |||||
| */ | |||||
| #include "board.h" | |||||
| #include "gpio.h" | |||||
| #include "timer.h" | |||||
| #include "radio.h" | |||||
| #if defined( REGION_AS923 ) | |||||
| #define RF_FREQUENCY 923000000 // Hz | |||||
| #elif defined( REGION_AU915 ) | |||||
| #define RF_FREQUENCY 915000000 // Hz | |||||
| #elif defined( REGION_CN779 ) | |||||
| #define RF_FREQUENCY 779000000 // Hz | |||||
| #elif defined( REGION_EU868 ) | |||||
| #define RF_FREQUENCY 868000000 // Hz | |||||
| #elif defined( REGION_KR920 ) | |||||
| #define RF_FREQUENCY 920000000 // Hz | |||||
| #elif defined( REGION_IN865 ) | |||||
| #define RF_FREQUENCY 865000000 // Hz | |||||
| #elif defined( REGION_US915 ) | |||||
| #define RF_FREQUENCY 915000000 // Hz | |||||
| #elif defined( REGION_RU864 ) | |||||
| #define RF_FREQUENCY 864000000 // Hz | |||||
| #else | |||||
| #error "Please define a frequency band in the compiler options." | |||||
| #endif | |||||
| #if defined( USE_MODEM_LORA ) | |||||
| #define LORA_BANDWIDTH 0 // [0: 125 kHz, | |||||
| // 1: 250 kHz, | |||||
| // 2: 500 kHz, | |||||
| // 3: Reserved] | |||||
| #define LORA_SPREADING_FACTOR 10 // [SF7..SF12] | |||||
| #define LORA_CODINGRATE 1 // [1: 4/5, | |||||
| // 2: 4/6, | |||||
| // 3: 4/7, | |||||
| // 4: 4/8] | |||||
| #define LORA_SYMBOL_TIMEOUT 5 // Symbols | |||||
| #define LORA_PREAMBLE_LENGTH 8 // Same for Tx and Rx | |||||
| #define LORA_FIX_LENGTH_PAYLOAD_ON false | |||||
| #define LORA_IQ_INVERSION_ON false | |||||
| #elif defined( USE_MODEM_FSK ) | |||||
| #define FSK_DATARATE 50000 // bps | |||||
| #define FSK_BANDWIDTH 50000 // Hz | |||||
| #define FSK_AFC_BANDWIDTH 83333 // Hz | |||||
| #define FSK_PREAMBLE_LENGTH 5 // Same for Tx and Rx | |||||
| #define FSK_FIX_LENGTH_PAYLOAD_ON false | |||||
| #else | |||||
| #error "Please define a modem in the compiler options." | |||||
| #endif | |||||
| /*! | |||||
| * Radio events function pointer | |||||
| */ | |||||
| static RadioEvents_t RadioEvents; | |||||
| /*! | |||||
| * LED GPIO pins objects | |||||
| */ | |||||
| extern Gpio_t Led4; | |||||
| /*! | |||||
| * \brief Function to be executed on Radio Rx Done event | |||||
| */ | |||||
| void OnRxDone( uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr ); | |||||
| /*! | |||||
| * Main application entry point. | |||||
| */ | |||||
| int main( void ) | |||||
| { | |||||
| // Target board initialization | |||||
| BoardInitMcu( ); | |||||
| BoardInitPeriph( ); | |||||
| // Radio initialization | |||||
| RadioEvents.RxDone = OnRxDone; | |||||
| Radio.Init( &RadioEvents ); | |||||
| Radio.SetChannel( RF_FREQUENCY ); | |||||
| #if defined( USE_MODEM_LORA ) | |||||
| Radio.SetRxConfig( MODEM_LORA, LORA_BANDWIDTH, LORA_SPREADING_FACTOR, | |||||
| LORA_CODINGRATE, 0, LORA_PREAMBLE_LENGTH, | |||||
| LORA_SYMBOL_TIMEOUT, LORA_FIX_LENGTH_PAYLOAD_ON, | |||||
| 0, true, 0, 0, LORA_IQ_INVERSION_ON, true ); | |||||
| Radio.SetMaxPayloadLength( MODEM_LORA, 255 ); | |||||
| #elif defined( USE_MODEM_FSK ) | |||||
| Radio.SetRxConfig( MODEM_FSK, FSK_BANDWIDTH, FSK_DATARATE, | |||||
| 0, FSK_AFC_BANDWIDTH, FSK_PREAMBLE_LENGTH, | |||||
| 0, FSK_FIX_LENGTH_PAYLOAD_ON, 0, true, | |||||
| 0, 0, false, true ); | |||||
| Radio.SetMaxPayloadLength( MODEM_FSK, 255 ); | |||||
| #else | |||||
| #error "Please define a frequency band in the compiler options." | |||||
| #endif | |||||
| Radio.Rx( 0 ); // Continuous Rx | |||||
| while( 1 ) | |||||
| { | |||||
| BoardLowPowerHandler( ); | |||||
| } | |||||
| } | |||||
| void OnRxDone( uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr ) | |||||
| { | |||||
| static uint8_t ledState = 1; | |||||
| // Toggle LED 4 | |||||
| ledState ^= 1; | |||||
| GpioWrite( &Led4, ledState ); | |||||
| } | |||||
| /*! | |||||
| * \file main.c | |||||
| * | |||||
| * \brief Radio sensitivity test | |||||
| * | |||||
| * \remark When LED1 stops blinking LoRa packets aren't received any more and | |||||
| * the sensitivity level has been reached. | |||||
| * By reading the RF generator output power we can estimate the board | |||||
| * sensitivity | |||||
| * | |||||
| * \copyright Revised BSD License, see section \ref LICENSE. | |||||
| * | |||||
| * \code | |||||
| * ______ _ | |||||
| * / _____) _ | | | |||||
| * ( (____ _____ ____ _| |_ _____ ____| |__ | |||||
| * \____ \| ___ | (_ _) ___ |/ ___) _ \ | |||||
| * _____) ) ____| | | || |_| ____( (___| | | | | |||||
| * (______/|_____)_|_|_| \__)_____)\____)_| |_| | |||||
| * (C)2013-2017 Semtech | |||||
| * | |||||
| * \endcode | |||||
| * | |||||
| * \author Miguel Luis ( Semtech ) | |||||
| * | |||||
| * \author Gregory Cristian ( Semtech ) | |||||
| */ | |||||
| #include "board.h" | |||||
| #include "gpio.h" | |||||
| #include "timer.h" | |||||
| #include "radio.h" | |||||
| #if defined( REGION_AS923 ) | |||||
| #define RF_FREQUENCY 923000000 // Hz | |||||
| #elif defined( REGION_AU915 ) | |||||
| #define RF_FREQUENCY 915000000 // Hz | |||||
| #elif defined( REGION_CN779 ) | |||||
| #define RF_FREQUENCY 779000000 // Hz | |||||
| #elif defined( REGION_EU868 ) | |||||
| #define RF_FREQUENCY 868000000 // Hz | |||||
| #elif defined( REGION_KR920 ) | |||||
| #define RF_FREQUENCY 920000000 // Hz | |||||
| #elif defined( REGION_IN865 ) | |||||
| #define RF_FREQUENCY 865000000 // Hz | |||||
| #elif defined( REGION_US915 ) | |||||
| #define RF_FREQUENCY 915000000 // Hz | |||||
| #elif defined( REGION_RU864 ) | |||||
| #define RF_FREQUENCY 864000000 // Hz | |||||
| #else | |||||
| #error "Please define a frequency band in the compiler options." | |||||
| #endif | |||||
| #if defined( USE_MODEM_LORA ) | |||||
| #define LORA_BANDWIDTH 0 // [0: 125 kHz, | |||||
| // 1: 250 kHz, | |||||
| // 2: 500 kHz, | |||||
| // 3: Reserved] | |||||
| #define LORA_SPREADING_FACTOR 10 // [SF7..SF12] | |||||
| #define LORA_CODINGRATE 1 // [1: 4/5, | |||||
| // 2: 4/6, | |||||
| // 3: 4/7, | |||||
| // 4: 4/8] | |||||
| #define LORA_SYMBOL_TIMEOUT 5 // Symbols | |||||
| #define LORA_PREAMBLE_LENGTH 8 // Same for Tx and Rx | |||||
| #define LORA_FIX_LENGTH_PAYLOAD_ON false | |||||
| #define LORA_IQ_INVERSION_ON false | |||||
| #elif defined( USE_MODEM_FSK ) | |||||
| #define FSK_DATARATE 50000 // bps | |||||
| #define FSK_BANDWIDTH 50000 // Hz | |||||
| #define FSK_AFC_BANDWIDTH 83333 // Hz | |||||
| #define FSK_PREAMBLE_LENGTH 5 // Same for Tx and Rx | |||||
| #define FSK_FIX_LENGTH_PAYLOAD_ON false | |||||
| #else | |||||
| #error "Please define a modem in the compiler options." | |||||
| #endif | |||||
| /*! | |||||
| * Radio events function pointer | |||||
| */ | |||||
| static RadioEvents_t RadioEvents; | |||||
| /*! | |||||
| * LED GPIO pins objects | |||||
| */ | |||||
| extern Gpio_t Led4; | |||||
| /*! | |||||
| * \brief Function to be executed on Radio Rx Done event | |||||
| */ | |||||
| void OnRxDone( uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr ); | |||||
| /*! | |||||
| * Main application entry point. | |||||
| */ | |||||
| int main( void ) | |||||
| { | |||||
| // Target board initialization | |||||
| BoardInitMcu( ); | |||||
| BoardInitPeriph( ); | |||||
| // Radio initialization | |||||
| RadioEvents.RxDone = OnRxDone; | |||||
| Radio.Init( &RadioEvents ); | |||||
| Radio.SetChannel( RF_FREQUENCY ); | |||||
| #if defined( USE_MODEM_LORA ) | |||||
| Radio.SetRxConfig( MODEM_LORA, LORA_BANDWIDTH, LORA_SPREADING_FACTOR, | |||||
| LORA_CODINGRATE, 0, LORA_PREAMBLE_LENGTH, | |||||
| LORA_SYMBOL_TIMEOUT, LORA_FIX_LENGTH_PAYLOAD_ON, | |||||
| 0, true, 0, 0, LORA_IQ_INVERSION_ON, true ); | |||||
| Radio.SetMaxPayloadLength( MODEM_LORA, 255 ); | |||||
| #elif defined( USE_MODEM_FSK ) | |||||
| Radio.SetRxConfig( MODEM_FSK, FSK_BANDWIDTH, FSK_DATARATE, | |||||
| 0, FSK_AFC_BANDWIDTH, FSK_PREAMBLE_LENGTH, | |||||
| 0, FSK_FIX_LENGTH_PAYLOAD_ON, 0, true, | |||||
| 0, 0, false, true ); | |||||
| Radio.SetMaxPayloadLength( MODEM_FSK, 255 ); | |||||
| #else | |||||
| #error "Please define a frequency band in the compiler options." | |||||
| #endif | |||||
| Radio.Rx( 0 ); // Continuous Rx | |||||
| while( 1 ) | |||||
| { | |||||
| BoardLowPowerHandler( ); | |||||
| } | |||||
| } | |||||
| void OnRxDone( uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr ) | |||||
| { | |||||
| static uint8_t ledState = 1; | |||||
| // Toggle LED 4 | |||||
| ledState ^= 1; | |||||
| GpioWrite( &Led4, ledState ); | |||||
| } | |||||
| @@ -1,203 +1,203 @@ | |||||
| /*! | |||||
| * \file main.c | |||||
| * | |||||
| * \brief Tx Continuous Wave implementation | |||||
| * | |||||
| * \copyright Revised BSD License, see section \ref LICENSE. | |||||
| * | |||||
| * \code | |||||
| * ______ _ | |||||
| * / _____) _ | | | |||||
| * ( (____ _____ ____ _| |_ _____ ____| |__ | |||||
| * \____ \| ___ | (_ _) ___ |/ ___) _ \ | |||||
| * _____) ) ____| | | || |_| ____( (___| | | | | |||||
| * (______/|_____)_|_|_| \__)_____)\____)_| |_| | |||||
| * (C)2013-2017 Semtech | |||||
| * | |||||
| * \endcode | |||||
| * | |||||
| * \author Miguel Luis ( Semtech ) | |||||
| * | |||||
| * \author Gregory Cristian ( Semtech ) | |||||
| */ | |||||
| #include "board.h" | |||||
| #include "gpio.h" | |||||
| #include "timer.h" | |||||
| #include "radio.h" | |||||
| #if defined( REGION_AS923 ) | |||||
| #define RF_FREQUENCY 923000000 // Hz | |||||
| #define TX_OUTPUT_POWER 14 // 14 dBm | |||||
| #elif defined( REGION_AU915 ) | |||||
| #define RF_FREQUENCY 915000000 // Hz | |||||
| #define TX_OUTPUT_POWER 14 // 14 dBm | |||||
| #elif defined( REGION_CN470 ) | |||||
| #define RF_FREQUENCY 470000000 // Hz | |||||
| #define TX_OUTPUT_POWER 20 // 20 dBm | |||||
| #elif defined( REGION_CN779 ) | |||||
| #define RF_FREQUENCY 779000000 // Hz | |||||
| #define TX_OUTPUT_POWER 14 // 14 dBm | |||||
| #elif defined( REGION_EU433 ) | |||||
| #define RF_FREQUENCY 433000000 // Hz | |||||
| #define TX_OUTPUT_POWER 20 // 20 dBm | |||||
| #elif defined( REGION_EU868 ) | |||||
| #define RF_FREQUENCY 868000000 // Hz | |||||
| #define TX_OUTPUT_POWER 14 // 14 dBm | |||||
| #elif defined( REGION_KR920 ) | |||||
| #define RF_FREQUENCY 920000000 // Hz | |||||
| #define TX_OUTPUT_POWER 14 // 14 dBm | |||||
| #elif defined( REGION_IN865 ) | |||||
| #define RF_FREQUENCY 865000000 // Hz | |||||
| #define TX_OUTPUT_POWER 14 // 14 dBm | |||||
| #elif defined( REGION_US915 ) | |||||
| #define RF_FREQUENCY 915000000 // Hz | |||||
| #define TX_OUTPUT_POWER 14 // 14 dBm | |||||
| #elif defined( REGION_RU864 ) | |||||
| #define RF_FREQUENCY 864000000 // Hz | |||||
| #define TX_OUTPUT_POWER 14 // 14 dBm | |||||
| #else | |||||
| #error "Please define a frequency band in the compiler options." | |||||
| #endif | |||||
| #define TX_TIMEOUT 65535 // seconds (MAX value) | |||||
| static TimerEvent_t Led1Timer; | |||||
| volatile bool Led1TimerEvent = false; | |||||
| static TimerEvent_t Led2Timer; | |||||
| volatile bool Led2TimerEvent = false; | |||||
| static TimerEvent_t Led3Timer; | |||||
| volatile bool Led3TimerEvent = false; | |||||
| /*! | |||||
| * Radio events function pointer | |||||
| */ | |||||
| static RadioEvents_t RadioEvents; | |||||
| /*! | |||||
| * LED GPIO pins objects | |||||
| */ | |||||
| extern Gpio_t Led1; | |||||
| extern Gpio_t Led2; | |||||
| extern Gpio_t Led3; | |||||
| /*! | |||||
| * \brief Function executed on Led 1 Timeout event | |||||
| */ | |||||
| void OnLed1TimerEvent( void* context ) | |||||
| { | |||||
| Led1TimerEvent = true; | |||||
| } | |||||
| /*! | |||||
| * \brief Function executed on Led 2 Timeout event | |||||
| */ | |||||
| void OnLed2TimerEvent( void* context ) | |||||
| { | |||||
| Led2TimerEvent = true; | |||||
| } | |||||
| /*! | |||||
| * \brief Function executed on Led 3 Timeout event | |||||
| */ | |||||
| void OnLed3TimerEvent( void* context ) | |||||
| { | |||||
| Led3TimerEvent = true; | |||||
| } | |||||
| /*! | |||||
| * \brief Function executed on Radio Tx Timeout event | |||||
| */ | |||||
| void OnRadioTxTimeout( void ) | |||||
| { | |||||
| // Restarts continuous wave transmission when timeout expires | |||||
| Radio.SetTxContinuousWave( RF_FREQUENCY, TX_OUTPUT_POWER, TX_TIMEOUT ); | |||||
| } | |||||
| /** | |||||
| * Main application entry point. | |||||
| */ | |||||
| int main( void ) | |||||
| { | |||||
| // Target board initialization | |||||
| BoardInitMcu( ); | |||||
| BoardInitPeriph( ); | |||||
| TimerInit( &Led1Timer, OnLed1TimerEvent ); | |||||
| TimerSetValue( &Led1Timer, 90 ); | |||||
| TimerInit( &Led2Timer, OnLed2TimerEvent ); | |||||
| TimerSetValue( &Led2Timer, 90 ); | |||||
| TimerInit( &Led3Timer, OnLed3TimerEvent ); | |||||
| TimerSetValue( &Led3Timer, 90 ); | |||||
| // Switch LED 1 ON | |||||
| GpioWrite( &Led1, 0 ); | |||||
| TimerStart( &Led1Timer ); | |||||
| // Radio initialization | |||||
| RadioEvents.TxTimeout = OnRadioTxTimeout; | |||||
| Radio.Init( &RadioEvents ); | |||||
| Radio.SetTxContinuousWave( RF_FREQUENCY, TX_OUTPUT_POWER, TX_TIMEOUT ); | |||||
| // Blink LEDs just to show some activity | |||||
| while( 1 ) | |||||
| { | |||||
| if( Led1TimerEvent == true ) | |||||
| { | |||||
| Led1TimerEvent = false; | |||||
| // Switch LED 1 OFF | |||||
| GpioWrite( &Led1, 1 ); | |||||
| // Switch LED 2 ON | |||||
| GpioWrite( &Led2, 0 ); | |||||
| TimerStart( &Led2Timer ); | |||||
| } | |||||
| if( Led2TimerEvent == true ) | |||||
| { | |||||
| Led2TimerEvent = false; | |||||
| // Switch LED 2 OFF | |||||
| GpioWrite( &Led2, 1 ); | |||||
| // Switch LED 3 ON | |||||
| GpioWrite( &Led3, 0 ); | |||||
| TimerStart( &Led3Timer ); | |||||
| } | |||||
| if( Led3TimerEvent == true ) | |||||
| { | |||||
| Led3TimerEvent = false; | |||||
| // Switch LED 3 OFF | |||||
| GpioWrite( &Led3, 1 ); | |||||
| // Switch LED 1 ON | |||||
| GpioWrite( &Led1, 0 ); | |||||
| TimerStart( &Led1Timer ); | |||||
| } | |||||
| } | |||||
| } | |||||
| /*! | |||||
| * \file main.c | |||||
| * | |||||
| * \brief Tx Continuous Wave implementation | |||||
| * | |||||
| * \copyright Revised BSD License, see section \ref LICENSE. | |||||
| * | |||||
| * \code | |||||
| * ______ _ | |||||
| * / _____) _ | | | |||||
| * ( (____ _____ ____ _| |_ _____ ____| |__ | |||||
| * \____ \| ___ | (_ _) ___ |/ ___) _ \ | |||||
| * _____) ) ____| | | || |_| ____( (___| | | | | |||||
| * (______/|_____)_|_|_| \__)_____)\____)_| |_| | |||||
| * (C)2013-2017 Semtech | |||||
| * | |||||
| * \endcode | |||||
| * | |||||
| * \author Miguel Luis ( Semtech ) | |||||
| * | |||||
| * \author Gregory Cristian ( Semtech ) | |||||
| */ | |||||
| #include "board.h" | |||||
| #include "gpio.h" | |||||
| #include "timer.h" | |||||
| #include "radio.h" | |||||
| #if defined( REGION_AS923 ) | |||||
| #define RF_FREQUENCY 923000000 // Hz | |||||
| #define TX_OUTPUT_POWER 14 // 14 dBm | |||||
| #elif defined( REGION_AU915 ) | |||||
| #define RF_FREQUENCY 915000000 // Hz | |||||
| #define TX_OUTPUT_POWER 14 // 14 dBm | |||||
| #elif defined( REGION_CN470 ) | |||||
| #define RF_FREQUENCY 470000000 // Hz | |||||
| #define TX_OUTPUT_POWER 20 // 20 dBm | |||||
| #elif defined( REGION_CN779 ) | |||||
| #define RF_FREQUENCY 779000000 // Hz | |||||
| #define TX_OUTPUT_POWER 14 // 14 dBm | |||||
| #elif defined( REGION_EU433 ) | |||||
| #define RF_FREQUENCY 433000000 // Hz | |||||
| #define TX_OUTPUT_POWER 20 // 20 dBm | |||||
| #elif defined( REGION_EU868 ) | |||||
| #define RF_FREQUENCY 868000000 // Hz | |||||
| #define TX_OUTPUT_POWER 14 // 14 dBm | |||||
| #elif defined( REGION_KR920 ) | |||||
| #define RF_FREQUENCY 920000000 // Hz | |||||
| #define TX_OUTPUT_POWER 14 // 14 dBm | |||||
| #elif defined( REGION_IN865 ) | |||||
| #define RF_FREQUENCY 865000000 // Hz | |||||
| #define TX_OUTPUT_POWER 14 // 14 dBm | |||||
| #elif defined( REGION_US915 ) | |||||
| #define RF_FREQUENCY 915000000 // Hz | |||||
| #define TX_OUTPUT_POWER 14 // 14 dBm | |||||
| #elif defined( REGION_RU864 ) | |||||
| #define RF_FREQUENCY 864000000 // Hz | |||||
| #define TX_OUTPUT_POWER 14 // 14 dBm | |||||
| #else | |||||
| #error "Please define a frequency band in the compiler options." | |||||
| #endif | |||||
| #define TX_TIMEOUT 65535 // seconds (MAX value) | |||||
| static TimerEvent_t Led1Timer; | |||||
| volatile bool Led1TimerEvent = false; | |||||
| static TimerEvent_t Led2Timer; | |||||
| volatile bool Led2TimerEvent = false; | |||||
| static TimerEvent_t Led3Timer; | |||||
| volatile bool Led3TimerEvent = false; | |||||
| /*! | |||||
| * Radio events function pointer | |||||
| */ | |||||
| static RadioEvents_t RadioEvents; | |||||
| /*! | |||||
| * LED GPIO pins objects | |||||
| */ | |||||
| extern Gpio_t Led1; | |||||
| extern Gpio_t Led2; | |||||
| extern Gpio_t Led3; | |||||
| /*! | |||||
| * \brief Function executed on Led 1 Timeout event | |||||
| */ | |||||
| void OnLed1TimerEvent( void* context ) | |||||
| { | |||||
| Led1TimerEvent = true; | |||||
| } | |||||
| /*! | |||||
| * \brief Function executed on Led 2 Timeout event | |||||
| */ | |||||
| void OnLed2TimerEvent( void* context ) | |||||
| { | |||||
| Led2TimerEvent = true; | |||||
| } | |||||
| /*! | |||||
| * \brief Function executed on Led 3 Timeout event | |||||
| */ | |||||
| void OnLed3TimerEvent( void* context ) | |||||
| { | |||||
| Led3TimerEvent = true; | |||||
| } | |||||
| /*! | |||||
| * \brief Function executed on Radio Tx Timeout event | |||||
| */ | |||||
| void OnRadioTxTimeout( void ) | |||||
| { | |||||
| // Restarts continuous wave transmission when timeout expires | |||||
| Radio.SetTxContinuousWave( RF_FREQUENCY, TX_OUTPUT_POWER, TX_TIMEOUT ); | |||||
| } | |||||
| /** | |||||
| * Main application entry point. | |||||
| */ | |||||
| int main( void ) | |||||
| { | |||||
| // Target board initialization | |||||
| BoardInitMcu( ); | |||||
| BoardInitPeriph( ); | |||||
| TimerInit( &Led1Timer, OnLed1TimerEvent ); | |||||
| TimerSetValue( &Led1Timer, 90 ); | |||||
| TimerInit( &Led2Timer, OnLed2TimerEvent ); | |||||
| TimerSetValue( &Led2Timer, 90 ); | |||||
| TimerInit( &Led3Timer, OnLed3TimerEvent ); | |||||
| TimerSetValue( &Led3Timer, 90 ); | |||||
| // Switch LED 1 ON | |||||
| GpioWrite( &Led1, 0 ); | |||||
| TimerStart( &Led1Timer ); | |||||
| // Radio initialization | |||||
| RadioEvents.TxTimeout = OnRadioTxTimeout; | |||||
| Radio.Init( &RadioEvents ); | |||||
| Radio.SetTxContinuousWave( RF_FREQUENCY, TX_OUTPUT_POWER, TX_TIMEOUT ); | |||||
| // Blink LEDs just to show some activity | |||||
| while( 1 ) | |||||
| { | |||||
| if( Led1TimerEvent == true ) | |||||
| { | |||||
| Led1TimerEvent = false; | |||||
| // Switch LED 1 OFF | |||||
| GpioWrite( &Led1, 1 ); | |||||
| // Switch LED 2 ON | |||||
| GpioWrite( &Led2, 0 ); | |||||
| TimerStart( &Led2Timer ); | |||||
| } | |||||
| if( Led2TimerEvent == true ) | |||||
| { | |||||
| Led2TimerEvent = false; | |||||
| // Switch LED 2 OFF | |||||
| GpioWrite( &Led2, 1 ); | |||||
| // Switch LED 3 ON | |||||
| GpioWrite( &Led3, 0 ); | |||||
| TimerStart( &Led3Timer ); | |||||
| } | |||||
| if( Led3TimerEvent == true ) | |||||
| { | |||||
| Led3TimerEvent = false; | |||||
| // Switch LED 3 OFF | |||||
| GpioWrite( &Led3, 1 ); | |||||
| // Switch LED 1 ON | |||||
| GpioWrite( &Led1, 0 ); | |||||
| TimerStart( &Led1Timer ); | |||||
| } | |||||
| } | |||||
| } | |||||
| @@ -1,91 +1,91 @@ | |||||
| ## | |||||
| ## ______ _ | |||||
| ## / _____) _ | | | |||||
| ## ( (____ _____ ____ _| |_ _____ ____| |__ | |||||
| ## \____ \| ___ | (_ _) ___ |/ ___) _ \ | |||||
| ## _____) ) ____| | | || |_| ____( (___| | | | | |||||
| ## (______/|_____)_|_|_| \__)_____)\____)_| |_| | |||||
| ## (C)2013-2017 Semtech | |||||
| ## ___ _____ _ ___ _ _____ ___ ___ ___ ___ | |||||
| ## / __|_ _/_\ / __| |/ / __/ _ \| _ \/ __| __| | |||||
| ## \__ \ | |/ _ \ (__| ' <| _| (_) | / (__| _| | |||||
| ## |___/ |_/_/ \_\___|_|\_\_| \___/|_|_\\___|___| | |||||
| ## embedded.connectivity.solutions.============== | |||||
| ## | |||||
| ## License: Revised BSD License, see LICENSE.TXT file included in the project | |||||
| ## Authors: Johannes Bruder (STACKFORCE), Miguel Luis (Semtech) | |||||
| ## | |||||
| project(tx-cw) | |||||
| cmake_minimum_required(VERSION 3.6) | |||||
| #--------------------------------------------------------------------------------------- | |||||
| # Options | |||||
| #--------------------------------------------------------------------------------------- | |||||
| # Allow selection of region | |||||
| option(REGION_EU868 "Region EU868" ON) | |||||
| option(REGION_US915 "Region US915" OFF) | |||||
| option(REGION_CN779 "Region CN779" OFF) | |||||
| option(REGION_EU433 "Region EU433" OFF) | |||||
| option(REGION_AU915 "Region AU915" OFF) | |||||
| option(REGION_AS923 "Region AS923" OFF) | |||||
| option(REGION_CN470 "Region CN470" OFF) | |||||
| option(REGION_KR920 "Region KR920" OFF) | |||||
| option(REGION_IN865 "Region IN865" OFF) | |||||
| option(REGION_RU864 "Region RU864" OFF) | |||||
| set(REGION_LIST REGION_EU868 REGION_US915 REGION_CN779 REGION_EU433 REGION_AU915 REGION_AS923 REGION_CN470 REGION_KR920 REGION_IN865 REGION_RU864) | |||||
| #--------------------------------------------------------------------------------------- | |||||
| # Target | |||||
| #--------------------------------------------------------------------------------------- | |||||
| file(GLOB ${PROJECT_NAME}_SOURCES "${CMAKE_CURRENT_LIST_DIR}/${BOARD}/*.c") | |||||
| add_executable(${PROJECT_NAME} | |||||
| ${${PROJECT_NAME}_SOURCES} | |||||
| $<TARGET_OBJECTS:system> | |||||
| $<TARGET_OBJECTS:radio> | |||||
| $<TARGET_OBJECTS:peripherals> | |||||
| $<TARGET_OBJECTS:${BOARD}> | |||||
| ) | |||||
| # Loops through all regions and add compile time definitions for the enabled ones. | |||||
| foreach( REGION ${REGION_LIST} ) | |||||
| if(${REGION}) | |||||
| target_compile_definitions(${PROJECT_NAME} PUBLIC -D"${REGION}") | |||||
| endif() | |||||
| endforeach() | |||||
| target_compile_definitions(${PROJECT_NAME} PUBLIC | |||||
| $<BUILD_INTERFACE:$<TARGET_PROPERTY:mac,INTERFACE_COMPILE_DEFINITIONS>> | |||||
| ) | |||||
| target_include_directories(${PROJECT_NAME} PUBLIC | |||||
| $<BUILD_INTERFACE:$<TARGET_PROPERTY:system,INTERFACE_INCLUDE_DIRECTORIES>> | |||||
| $<BUILD_INTERFACE:$<TARGET_PROPERTY:radio,INTERFACE_INCLUDE_DIRECTORIES>> | |||||
| $<BUILD_INTERFACE:$<TARGET_PROPERTY:peripherals,INTERFACE_INCLUDE_DIRECTORIES>> | |||||
| $<BUILD_INTERFACE:$<TARGET_PROPERTY:${BOARD},INTERFACE_INCLUDE_DIRECTORIES>> | |||||
| ) | |||||
| set_property(TARGET ${PROJECT_NAME} PROPERTY C_STANDARD 11) | |||||
| target_link_libraries(${PROJECT_NAME} m) | |||||
| #--------------------------------------------------------------------------------------- | |||||
| # Debugging and Binutils | |||||
| #--------------------------------------------------------------------------------------- | |||||
| include(gdb-helper) | |||||
| include(binutils-arm-none-eabi) | |||||
| # Generate debugger configurations | |||||
| generate_run_gdb_stlink(${PROJECT_NAME}) | |||||
| generate_run_gdb_openocd(${PROJECT_NAME}) | |||||
| generate_vscode_launch_openocd(${PROJECT_NAME}) | |||||
| # Print section sizes of target | |||||
| print_section_sizes(${PROJECT_NAME}) | |||||
| # Create output in hex and binary format | |||||
| create_bin_output(${PROJECT_NAME}) | |||||
| create_hex_output(${PROJECT_NAME}) | |||||
| ## | |||||
| ## ______ _ | |||||
| ## / _____) _ | | | |||||
| ## ( (____ _____ ____ _| |_ _____ ____| |__ | |||||
| ## \____ \| ___ | (_ _) ___ |/ ___) _ \ | |||||
| ## _____) ) ____| | | || |_| ____( (___| | | | | |||||
| ## (______/|_____)_|_|_| \__)_____)\____)_| |_| | |||||
| ## (C)2013-2017 Semtech | |||||
| ## ___ _____ _ ___ _ _____ ___ ___ ___ ___ | |||||
| ## / __|_ _/_\ / __| |/ / __/ _ \| _ \/ __| __| | |||||
| ## \__ \ | |/ _ \ (__| ' <| _| (_) | / (__| _| | |||||
| ## |___/ |_/_/ \_\___|_|\_\_| \___/|_|_\\___|___| | |||||
| ## embedded.connectivity.solutions.============== | |||||
| ## | |||||
| ## License: Revised BSD License, see LICENSE.TXT file included in the project | |||||
| ## Authors: Johannes Bruder (STACKFORCE), Miguel Luis (Semtech) | |||||
| ## | |||||
| project(tx-cw) | |||||
| cmake_minimum_required(VERSION 3.6) | |||||
| #--------------------------------------------------------------------------------------- | |||||
| # Options | |||||
| #--------------------------------------------------------------------------------------- | |||||
| # Allow selection of region | |||||
| option(REGION_EU868 "Region EU868" ON) | |||||
| option(REGION_US915 "Region US915" OFF) | |||||
| option(REGION_CN779 "Region CN779" OFF) | |||||
| option(REGION_EU433 "Region EU433" OFF) | |||||
| option(REGION_AU915 "Region AU915" OFF) | |||||
| option(REGION_AS923 "Region AS923" OFF) | |||||
| option(REGION_CN470 "Region CN470" OFF) | |||||
| option(REGION_KR920 "Region KR920" OFF) | |||||
| option(REGION_IN865 "Region IN865" OFF) | |||||
| option(REGION_RU864 "Region RU864" OFF) | |||||
| set(REGION_LIST REGION_EU868 REGION_US915 REGION_CN779 REGION_EU433 REGION_AU915 REGION_AS923 REGION_CN470 REGION_KR920 REGION_IN865 REGION_RU864) | |||||
| #--------------------------------------------------------------------------------------- | |||||
| # Target | |||||
| #--------------------------------------------------------------------------------------- | |||||
| file(GLOB ${PROJECT_NAME}_SOURCES "${CMAKE_CURRENT_LIST_DIR}/${BOARD}/*.c") | |||||
| add_executable(${PROJECT_NAME} | |||||
| ${${PROJECT_NAME}_SOURCES} | |||||
| $<TARGET_OBJECTS:system> | |||||
| $<TARGET_OBJECTS:radio> | |||||
| $<TARGET_OBJECTS:peripherals> | |||||
| $<TARGET_OBJECTS:${BOARD}> | |||||
| ) | |||||
| # Loops through all regions and add compile time definitions for the enabled ones. | |||||
| foreach( REGION ${REGION_LIST} ) | |||||
| if(${REGION}) | |||||
| target_compile_definitions(${PROJECT_NAME} PUBLIC -D"${REGION}") | |||||
| endif() | |||||
| endforeach() | |||||
| target_compile_definitions(${PROJECT_NAME} PUBLIC | |||||
| $<BUILD_INTERFACE:$<TARGET_PROPERTY:mac,INTERFACE_COMPILE_DEFINITIONS>> | |||||
| ) | |||||
| target_include_directories(${PROJECT_NAME} PUBLIC | |||||
| $<BUILD_INTERFACE:$<TARGET_PROPERTY:system,INTERFACE_INCLUDE_DIRECTORIES>> | |||||
| $<BUILD_INTERFACE:$<TARGET_PROPERTY:radio,INTERFACE_INCLUDE_DIRECTORIES>> | |||||
| $<BUILD_INTERFACE:$<TARGET_PROPERTY:peripherals,INTERFACE_INCLUDE_DIRECTORIES>> | |||||
| $<BUILD_INTERFACE:$<TARGET_PROPERTY:${BOARD},INTERFACE_INCLUDE_DIRECTORIES>> | |||||
| ) | |||||
| set_property(TARGET ${PROJECT_NAME} PROPERTY C_STANDARD 11) | |||||
| target_link_libraries(${PROJECT_NAME} m) | |||||
| #--------------------------------------------------------------------------------------- | |||||
| # Debugging and Binutils | |||||
| #--------------------------------------------------------------------------------------- | |||||
| include(gdb-helper) | |||||
| include(binutils-arm-none-eabi) | |||||
| # Generate debugger configurations | |||||
| generate_run_gdb_stlink(${PROJECT_NAME}) | |||||
| generate_run_gdb_openocd(${PROJECT_NAME}) | |||||
| generate_vscode_launch_openocd(${PROJECT_NAME}) | |||||
| # Print section sizes of target | |||||
| print_section_sizes(${PROJECT_NAME}) | |||||
| # Create output in hex and binary format | |||||
| create_bin_output(${PROJECT_NAME}) | |||||
| create_hex_output(${PROJECT_NAME}) | |||||
| @@ -1,188 +1,188 @@ | |||||
| /*! | |||||
| * \file main.c | |||||
| * | |||||
| * \brief Tx Continuous Wave implementation | |||||
| * | |||||
| * \copyright Revised BSD License, see section \ref LICENSE. | |||||
| * | |||||
| * \code | |||||
| * ______ _ | |||||
| * / _____) _ | | | |||||
| * ( (____ _____ ____ _| |_ _____ ____| |__ | |||||
| * \____ \| ___ | (_ _) ___ |/ ___) _ \ | |||||
| * _____) ) ____| | | || |_| ____( (___| | | | | |||||
| * (______/|_____)_|_|_| \__)_____)\____)_| |_| | |||||
| * (C)2013-2017 Semtech | |||||
| * | |||||
| * \endcode | |||||
| * | |||||
| * \author Miguel Luis ( Semtech ) | |||||
| * | |||||
| * \author Gregory Cristian ( Semtech ) | |||||
| */ | |||||
| #include "board-config.h" | |||||
| #include "board.h" | |||||
| #include "gpio.h" | |||||
| #include "timer.h" | |||||
| #include "radio.h" | |||||
| #if defined( REGION_AS923 ) | |||||
| #define RF_FREQUENCY 923000000 // Hz | |||||
| #elif defined( REGION_AU915 ) | |||||
| #define RF_FREQUENCY 915000000 // Hz | |||||
| #elif defined( REGION_CN779 ) | |||||
| #define RF_FREQUENCY 779000000 // Hz | |||||
| #elif defined( REGION_EU868 ) | |||||
| #define RF_FREQUENCY 868000000 // Hz | |||||
| #elif defined( REGION_KR920 ) | |||||
| #define RF_FREQUENCY 920000000 // Hz | |||||
| #elif defined( REGION_IN865 ) | |||||
| #define RF_FREQUENCY 865000000 // Hz | |||||
| #elif defined( REGION_US915 ) | |||||
| #define RF_FREQUENCY 915000000 // Hz | |||||
| #elif defined( REGION_RU864 ) | |||||
| #define RF_FREQUENCY 864000000 // Hz | |||||
| #else | |||||
| #error "Please define a frequency band in the compiler options." | |||||
| #endif | |||||
| #define TX_OUTPUT_POWER 20 // 20 dBm | |||||
| #define TX_TIMEOUT 65535 // seconds (MAX value) | |||||
| static TimerEvent_t Led1Timer; | |||||
| volatile bool Led1TimerEvent = false; | |||||
| static TimerEvent_t Led2Timer; | |||||
| volatile bool Led2TimerEvent = false; | |||||
| static TimerEvent_t Led3Timer; | |||||
| volatile bool Led3TimerEvent = false; | |||||
| /*! | |||||
| * Radio events function pointer | |||||
| */ | |||||
| static RadioEvents_t RadioEvents; | |||||
| /*! | |||||
| * LED GPIO pins objects | |||||
| */ | |||||
| extern Gpio_t Led1; | |||||
| extern Gpio_t Led2; | |||||
| extern Gpio_t Led3; | |||||
| /*! | |||||
| * \brief Function executed on Led 1 Timeout event | |||||
| */ | |||||
| void OnLed1TimerEvent( void* context ) | |||||
| { | |||||
| Led1TimerEvent = true; | |||||
| } | |||||
| /*! | |||||
| * \brief Function executed on Led 2 Timeout event | |||||
| */ | |||||
| void OnLed2TimerEvent( void* context ) | |||||
| { | |||||
| Led2TimerEvent = true; | |||||
| } | |||||
| /*! | |||||
| * \brief Function executed on Led 3 Timeout event | |||||
| */ | |||||
| void OnLed3TimerEvent( void* context ) | |||||
| { | |||||
| Led3TimerEvent = true; | |||||
| } | |||||
| /*! | |||||
| * \brief Function executed on Radio Tx Timeout event | |||||
| */ | |||||
| void OnRadioTxTimeout( void ) | |||||
| { | |||||
| // Restarts continuous wave transmission when timeout expires | |||||
| Radio.SetTxContinuousWave( RF_FREQUENCY, TX_OUTPUT_POWER, TX_TIMEOUT ); | |||||
| } | |||||
| /** | |||||
| * Main application entry point. | |||||
| */ | |||||
| int main( void ) | |||||
| { | |||||
| // Target board initialization | |||||
| BoardInitMcu( ); | |||||
| BoardInitPeriph( ); | |||||
| TimerInit( &Led1Timer, OnLed1TimerEvent ); | |||||
| TimerSetValue( &Led1Timer, 90 ); | |||||
| TimerInit( &Led2Timer, OnLed2TimerEvent ); | |||||
| TimerSetValue( &Led2Timer, 90 ); | |||||
| TimerInit( &Led3Timer, OnLed3TimerEvent ); | |||||
| TimerSetValue( &Led3Timer, 90 ); | |||||
| // Switch LED 1 ON | |||||
| GpioWrite( &Led1, 0 ); | |||||
| TimerStart( &Led1Timer ); | |||||
| // Radio initialization | |||||
| RadioEvents.TxTimeout = OnRadioTxTimeout; | |||||
| Radio.Init( &RadioEvents ); | |||||
| Radio.SetTxContinuousWave( RF_FREQUENCY, TX_OUTPUT_POWER, TX_TIMEOUT ); | |||||
| // Blink LEDs just to show some activity | |||||
| while( 1 ) | |||||
| { | |||||
| if( Led1TimerEvent == true ) | |||||
| { | |||||
| Led1TimerEvent = false; | |||||
| // Switch LED 1 OFF | |||||
| GpioWrite( &Led1, 1 ); | |||||
| // Switch LED 2 ON | |||||
| GpioWrite( &Led2, 0 ); | |||||
| TimerStart( &Led2Timer ); | |||||
| } | |||||
| if( Led2TimerEvent == true ) | |||||
| { | |||||
| Led2TimerEvent = false; | |||||
| // Switch LED 2 OFF | |||||
| GpioWrite( &Led2, 1 ); | |||||
| // Switch LED 3 ON | |||||
| GpioWrite( &Led3, 0 ); | |||||
| TimerStart( &Led3Timer ); | |||||
| } | |||||
| if( Led3TimerEvent == true ) | |||||
| { | |||||
| Led3TimerEvent = false; | |||||
| // Switch LED 3 OFF | |||||
| GpioWrite( &Led3, 1 ); | |||||
| // Switch LED 1 ON | |||||
| GpioWrite( &Led1, 0 ); | |||||
| TimerStart( &Led1Timer ); | |||||
| } | |||||
| } | |||||
| } | |||||
| /*! | |||||
| * \file main.c | |||||
| * | |||||
| * \brief Tx Continuous Wave implementation | |||||
| * | |||||
| * \copyright Revised BSD License, see section \ref LICENSE. | |||||
| * | |||||
| * \code | |||||
| * ______ _ | |||||
| * / _____) _ | | | |||||
| * ( (____ _____ ____ _| |_ _____ ____| |__ | |||||
| * \____ \| ___ | (_ _) ___ |/ ___) _ \ | |||||
| * _____) ) ____| | | || |_| ____( (___| | | | | |||||
| * (______/|_____)_|_|_| \__)_____)\____)_| |_| | |||||
| * (C)2013-2017 Semtech | |||||
| * | |||||
| * \endcode | |||||
| * | |||||
| * \author Miguel Luis ( Semtech ) | |||||
| * | |||||
| * \author Gregory Cristian ( Semtech ) | |||||
| */ | |||||
| #include "board-config.h" | |||||
| #include "board.h" | |||||
| #include "gpio.h" | |||||
| #include "timer.h" | |||||
| #include "radio.h" | |||||
| #if defined( REGION_AS923 ) | |||||
| #define RF_FREQUENCY 923000000 // Hz | |||||
| #elif defined( REGION_AU915 ) | |||||
| #define RF_FREQUENCY 915000000 // Hz | |||||
| #elif defined( REGION_CN779 ) | |||||
| #define RF_FREQUENCY 779000000 // Hz | |||||
| #elif defined( REGION_EU868 ) | |||||
| #define RF_FREQUENCY 868000000 // Hz | |||||
| #elif defined( REGION_KR920 ) | |||||
| #define RF_FREQUENCY 920000000 // Hz | |||||
| #elif defined( REGION_IN865 ) | |||||
| #define RF_FREQUENCY 865000000 // Hz | |||||
| #elif defined( REGION_US915 ) | |||||
| #define RF_FREQUENCY 915000000 // Hz | |||||
| #elif defined( REGION_RU864 ) | |||||
| #define RF_FREQUENCY 864000000 // Hz | |||||
| #else | |||||
| #error "Please define a frequency band in the compiler options." | |||||
| #endif | |||||
| #define TX_OUTPUT_POWER 20 // 20 dBm | |||||
| #define TX_TIMEOUT 65535 // seconds (MAX value) | |||||
| static TimerEvent_t Led1Timer; | |||||
| volatile bool Led1TimerEvent = false; | |||||
| static TimerEvent_t Led2Timer; | |||||
| volatile bool Led2TimerEvent = false; | |||||
| static TimerEvent_t Led3Timer; | |||||
| volatile bool Led3TimerEvent = false; | |||||
| /*! | |||||
| * Radio events function pointer | |||||
| */ | |||||
| static RadioEvents_t RadioEvents; | |||||
| /*! | |||||
| * LED GPIO pins objects | |||||
| */ | |||||
| extern Gpio_t Led1; | |||||
| extern Gpio_t Led2; | |||||
| extern Gpio_t Led3; | |||||
| /*! | |||||
| * \brief Function executed on Led 1 Timeout event | |||||
| */ | |||||
| void OnLed1TimerEvent( void* context ) | |||||
| { | |||||
| Led1TimerEvent = true; | |||||
| } | |||||
| /*! | |||||
| * \brief Function executed on Led 2 Timeout event | |||||
| */ | |||||
| void OnLed2TimerEvent( void* context ) | |||||
| { | |||||
| Led2TimerEvent = true; | |||||
| } | |||||
| /*! | |||||
| * \brief Function executed on Led 3 Timeout event | |||||
| */ | |||||
| void OnLed3TimerEvent( void* context ) | |||||
| { | |||||
| Led3TimerEvent = true; | |||||
| } | |||||
| /*! | |||||
| * \brief Function executed on Radio Tx Timeout event | |||||
| */ | |||||
| void OnRadioTxTimeout( void ) | |||||
| { | |||||
| // Restarts continuous wave transmission when timeout expires | |||||
| Radio.SetTxContinuousWave( RF_FREQUENCY, TX_OUTPUT_POWER, TX_TIMEOUT ); | |||||
| } | |||||
| /** | |||||
| * Main application entry point. | |||||
| */ | |||||
| int main( void ) | |||||
| { | |||||
| // Target board initialization | |||||
| BoardInitMcu( ); | |||||
| BoardInitPeriph( ); | |||||
| TimerInit( &Led1Timer, OnLed1TimerEvent ); | |||||
| TimerSetValue( &Led1Timer, 90 ); | |||||
| TimerInit( &Led2Timer, OnLed2TimerEvent ); | |||||
| TimerSetValue( &Led2Timer, 90 ); | |||||
| TimerInit( &Led3Timer, OnLed3TimerEvent ); | |||||
| TimerSetValue( &Led3Timer, 90 ); | |||||
| // Switch LED 1 ON | |||||
| GpioWrite( &Led1, 0 ); | |||||
| TimerStart( &Led1Timer ); | |||||
| // Radio initialization | |||||
| RadioEvents.TxTimeout = OnRadioTxTimeout; | |||||
| Radio.Init( &RadioEvents ); | |||||
| Radio.SetTxContinuousWave( RF_FREQUENCY, TX_OUTPUT_POWER, TX_TIMEOUT ); | |||||
| // Blink LEDs just to show some activity | |||||
| while( 1 ) | |||||
| { | |||||
| if( Led1TimerEvent == true ) | |||||
| { | |||||
| Led1TimerEvent = false; | |||||
| // Switch LED 1 OFF | |||||
| GpioWrite( &Led1, 1 ); | |||||
| // Switch LED 2 ON | |||||
| GpioWrite( &Led2, 0 ); | |||||
| TimerStart( &Led2Timer ); | |||||
| } | |||||
| if( Led2TimerEvent == true ) | |||||
| { | |||||
| Led2TimerEvent = false; | |||||
| // Switch LED 2 OFF | |||||
| GpioWrite( &Led2, 1 ); | |||||
| // Switch LED 3 ON | |||||
| GpioWrite( &Led3, 0 ); | |||||
| TimerStart( &Led3Timer ); | |||||
| } | |||||
| if( Led3TimerEvent == true ) | |||||
| { | |||||
| Led3TimerEvent = false; | |||||
| // Switch LED 3 OFF | |||||
| GpioWrite( &Led3, 1 ); | |||||
| // Switch LED 1 ON | |||||
| GpioWrite( &Led1, 0 ); | |||||
| TimerStart( &Led1Timer ); | |||||
| } | |||||
| } | |||||
| } | |||||
| @@ -1,182 +1,182 @@ | |||||
| /*! | |||||
| * \file main.c | |||||
| * | |||||
| * \brief Tx Continuous Wave implementation | |||||
| * | |||||
| * \copyright Revised BSD License, see section \ref LICENSE. | |||||
| * | |||||
| * \code | |||||
| * ______ _ | |||||
| * / _____) _ | | | |||||
| * ( (____ _____ ____ _| |_ _____ ____| |__ | |||||
| * \____ \| ___ | (_ _) ___ |/ ___) _ \ | |||||
| * _____) ) ____| | | || |_| ____( (___| | | | | |||||
| * (______/|_____)_|_|_| \__)_____)\____)_| |_| | |||||
| * (C)2013-2017 Semtech | |||||
| * | |||||
| * \endcode | |||||
| * | |||||
| * \author Miguel Luis ( Semtech ) | |||||
| * | |||||
| * \author Gregory Cristian ( Semtech ) | |||||
| */ | |||||
| #include "board.h" | |||||
| #include "gpio.h" | |||||
| #include "timer.h" | |||||
| #include "radio.h" | |||||
| #if defined( REGION_AS923 ) | |||||
| #define RF_FREQUENCY 923000000 // Hz | |||||
| #define TX_OUTPUT_POWER 14 // 14 dBm | |||||
| #elif defined( REGION_AU915 ) | |||||
| #define RF_FREQUENCY 915000000 // Hz | |||||
| #define TX_OUTPUT_POWER 14 // 14 dBm | |||||
| #elif defined( REGION_CN470 ) | |||||
| #define RF_FREQUENCY 470000000 // Hz | |||||
| #define TX_OUTPUT_POWER 20 // 20 dBm | |||||
| #elif defined( REGION_CN779 ) | |||||
| #define RF_FREQUENCY 779000000 // Hz | |||||
| #define TX_OUTPUT_POWER 14 // 14 dBm | |||||
| #elif defined( REGION_EU433 ) | |||||
| #define RF_FREQUENCY 433000000 // Hz | |||||
| #define TX_OUTPUT_POWER 20 // 20 dBm | |||||
| #elif defined( REGION_EU868 ) | |||||
| #define RF_FREQUENCY 868000000 // Hz | |||||
| #define TX_OUTPUT_POWER 14 // 14 dBm | |||||
| #elif defined( REGION_KR920 ) | |||||
| #define RF_FREQUENCY 920000000 // Hz | |||||
| #define TX_OUTPUT_POWER 14 // 14 dBm | |||||
| #elif defined( REGION_IN865 ) | |||||
| #define RF_FREQUENCY 865000000 // Hz | |||||
| #define TX_OUTPUT_POWER 14 // 14 dBm | |||||
| #elif defined( REGION_US915 ) | |||||
| #define RF_FREQUENCY 915000000 // Hz | |||||
| #define TX_OUTPUT_POWER 14 // 14 dBm | |||||
| #elif defined( REGION_RU864 ) | |||||
| #define RF_FREQUENCY 864000000 // Hz | |||||
| #define TX_OUTPUT_POWER 14 // 14 dBm | |||||
| #else | |||||
| #error "Please define a frequency band in the compiler options." | |||||
| #endif | |||||
| #define TX_TIMEOUT 10 // seconds (MAX value) | |||||
| static TimerEvent_t Led1Timer; | |||||
| volatile bool Led1TimerEvent = false; | |||||
| static TimerEvent_t Led2Timer; | |||||
| volatile bool Led2TimerEvent = false; | |||||
| /*! | |||||
| * Radio events function pointer | |||||
| */ | |||||
| static RadioEvents_t RadioEvents; | |||||
| /*! | |||||
| * LED GPIO pins objects | |||||
| */ | |||||
| extern Gpio_t Led1; | |||||
| extern Gpio_t Led2; | |||||
| /*! | |||||
| * \brief Function executed on Led 1 Timeout event | |||||
| */ | |||||
| void OnLed1TimerEvent( void* context ) | |||||
| { | |||||
| Led1TimerEvent = true; | |||||
| } | |||||
| /*! | |||||
| * \brief Function executed on Led 2 Timeout event | |||||
| */ | |||||
| void OnLed2TimerEvent( void* context ) | |||||
| { | |||||
| Led2TimerEvent = true; | |||||
| } | |||||
| /*! | |||||
| * \brief Function executed on Radio Tx Timeout event | |||||
| */ | |||||
| void OnRadioTxTimeout( void ) | |||||
| { | |||||
| // Restarts continuous wave transmission when timeout expires | |||||
| Radio.SetTxContinuousWave( RF_FREQUENCY, TX_OUTPUT_POWER, TX_TIMEOUT ); | |||||
| } | |||||
| /** | |||||
| * Main application entry point. | |||||
| */ | |||||
| int main( void ) | |||||
| { | |||||
| // Target board initialization | |||||
| BoardInitMcu( ); | |||||
| BoardInitPeriph( ); | |||||
| TimerInit( &Led1Timer, OnLed1TimerEvent ); | |||||
| TimerSetValue( &Led1Timer, 90 ); | |||||
| TimerInit( &Led2Timer, OnLed2TimerEvent ); | |||||
| TimerSetValue( &Led2Timer, 90 ); | |||||
| // Switch LED 1 ON | |||||
| GpioWrite( &Led1, 0 ); | |||||
| TimerStart( &Led1Timer ); | |||||
| // Radio initialization | |||||
| RadioEvents.TxTimeout = OnRadioTxTimeout; | |||||
| Radio.Init( &RadioEvents ); | |||||
| Radio.SetTxContinuousWave( RF_FREQUENCY, TX_OUTPUT_POWER, TX_TIMEOUT ); | |||||
| // Blink LEDs just to show some activity | |||||
| while( 1 ) | |||||
| { | |||||
| // Process Radio IRQ | |||||
| if( Radio.IrqProcess != NULL ) | |||||
| { | |||||
| Radio.IrqProcess( ); | |||||
| } | |||||
| if( Led1TimerEvent == true ) | |||||
| { | |||||
| Led1TimerEvent = false; | |||||
| // Switch LED 1 OFF | |||||
| GpioWrite( &Led1, 1 ); | |||||
| // Switch LED 2 ON | |||||
| GpioWrite( &Led2, 0 ); | |||||
| TimerStart( &Led2Timer ); | |||||
| } | |||||
| if( Led2TimerEvent == true ) | |||||
| { | |||||
| Led2TimerEvent = false; | |||||
| // Switch LED 2 OFF | |||||
| GpioWrite( &Led2, 1 ); | |||||
| // Switch LED 1 ON | |||||
| GpioWrite( &Led1, 0 ); | |||||
| TimerStart( &Led1Timer ); | |||||
| } | |||||
| } | |||||
| } | |||||
| /*! | |||||
| * \file main.c | |||||
| * | |||||
| * \brief Tx Continuous Wave implementation | |||||
| * | |||||
| * \copyright Revised BSD License, see section \ref LICENSE. | |||||
| * | |||||
| * \code | |||||
| * ______ _ | |||||
| * / _____) _ | | | |||||
| * ( (____ _____ ____ _| |_ _____ ____| |__ | |||||
| * \____ \| ___ | (_ _) ___ |/ ___) _ \ | |||||
| * _____) ) ____| | | || |_| ____( (___| | | | | |||||
| * (______/|_____)_|_|_| \__)_____)\____)_| |_| | |||||
| * (C)2013-2017 Semtech | |||||
| * | |||||
| * \endcode | |||||
| * | |||||
| * \author Miguel Luis ( Semtech ) | |||||
| * | |||||
| * \author Gregory Cristian ( Semtech ) | |||||
| */ | |||||
| #include "board.h" | |||||
| #include "gpio.h" | |||||
| #include "timer.h" | |||||
| #include "radio.h" | |||||
| #if defined( REGION_AS923 ) | |||||
| #define RF_FREQUENCY 923000000 // Hz | |||||
| #define TX_OUTPUT_POWER 14 // 14 dBm | |||||
| #elif defined( REGION_AU915 ) | |||||
| #define RF_FREQUENCY 915000000 // Hz | |||||
| #define TX_OUTPUT_POWER 14 // 14 dBm | |||||
| #elif defined( REGION_CN470 ) | |||||
| #define RF_FREQUENCY 470000000 // Hz | |||||
| #define TX_OUTPUT_POWER 20 // 20 dBm | |||||
| #elif defined( REGION_CN779 ) | |||||
| #define RF_FREQUENCY 779000000 // Hz | |||||
| #define TX_OUTPUT_POWER 14 // 14 dBm | |||||
| #elif defined( REGION_EU433 ) | |||||
| #define RF_FREQUENCY 433000000 // Hz | |||||
| #define TX_OUTPUT_POWER 20 // 20 dBm | |||||
| #elif defined( REGION_EU868 ) | |||||
| #define RF_FREQUENCY 868000000 // Hz | |||||
| #define TX_OUTPUT_POWER 14 // 14 dBm | |||||
| #elif defined( REGION_KR920 ) | |||||
| #define RF_FREQUENCY 920000000 // Hz | |||||
| #define TX_OUTPUT_POWER 14 // 14 dBm | |||||
| #elif defined( REGION_IN865 ) | |||||
| #define RF_FREQUENCY 865000000 // Hz | |||||
| #define TX_OUTPUT_POWER 14 // 14 dBm | |||||
| #elif defined( REGION_US915 ) | |||||
| #define RF_FREQUENCY 915000000 // Hz | |||||
| #define TX_OUTPUT_POWER 14 // 14 dBm | |||||
| #elif defined( REGION_RU864 ) | |||||
| #define RF_FREQUENCY 864000000 // Hz | |||||
| #define TX_OUTPUT_POWER 14 // 14 dBm | |||||
| #else | |||||
| #error "Please define a frequency band in the compiler options." | |||||
| #endif | |||||
| #define TX_TIMEOUT 10 // seconds (MAX value) | |||||
| static TimerEvent_t Led1Timer; | |||||
| volatile bool Led1TimerEvent = false; | |||||
| static TimerEvent_t Led2Timer; | |||||
| volatile bool Led2TimerEvent = false; | |||||
| /*! | |||||
| * Radio events function pointer | |||||
| */ | |||||
| static RadioEvents_t RadioEvents; | |||||
| /*! | |||||
| * LED GPIO pins objects | |||||
| */ | |||||
| extern Gpio_t Led1; | |||||
| extern Gpio_t Led2; | |||||
| /*! | |||||
| * \brief Function executed on Led 1 Timeout event | |||||
| */ | |||||
| void OnLed1TimerEvent( void* context ) | |||||
| { | |||||
| Led1TimerEvent = true; | |||||
| } | |||||
| /*! | |||||
| * \brief Function executed on Led 2 Timeout event | |||||
| */ | |||||
| void OnLed2TimerEvent( void* context ) | |||||
| { | |||||
| Led2TimerEvent = true; | |||||
| } | |||||
| /*! | |||||
| * \brief Function executed on Radio Tx Timeout event | |||||
| */ | |||||
| void OnRadioTxTimeout( void ) | |||||
| { | |||||
| // Restarts continuous wave transmission when timeout expires | |||||
| Radio.SetTxContinuousWave( RF_FREQUENCY, TX_OUTPUT_POWER, TX_TIMEOUT ); | |||||
| } | |||||
| /** | |||||
| * Main application entry point. | |||||
| */ | |||||
| int main( void ) | |||||
| { | |||||
| // Target board initialization | |||||
| BoardInitMcu( ); | |||||
| BoardInitPeriph( ); | |||||
| TimerInit( &Led1Timer, OnLed1TimerEvent ); | |||||
| TimerSetValue( &Led1Timer, 90 ); | |||||
| TimerInit( &Led2Timer, OnLed2TimerEvent ); | |||||
| TimerSetValue( &Led2Timer, 90 ); | |||||
| // Switch LED 1 ON | |||||
| GpioWrite( &Led1, 0 ); | |||||
| TimerStart( &Led1Timer ); | |||||
| // Radio initialization | |||||
| RadioEvents.TxTimeout = OnRadioTxTimeout; | |||||
| Radio.Init( &RadioEvents ); | |||||
| Radio.SetTxContinuousWave( RF_FREQUENCY, TX_OUTPUT_POWER, TX_TIMEOUT ); | |||||
| // Blink LEDs just to show some activity | |||||
| while( 1 ) | |||||
| { | |||||
| // Process Radio IRQ | |||||
| if( Radio.IrqProcess != NULL ) | |||||
| { | |||||
| Radio.IrqProcess( ); | |||||
| } | |||||
| if( Led1TimerEvent == true ) | |||||
| { | |||||
| Led1TimerEvent = false; | |||||
| // Switch LED 1 OFF | |||||
| GpioWrite( &Led1, 1 ); | |||||
| // Switch LED 2 ON | |||||
| GpioWrite( &Led2, 0 ); | |||||
| TimerStart( &Led2Timer ); | |||||
| } | |||||
| if( Led2TimerEvent == true ) | |||||
| { | |||||
| Led2TimerEvent = false; | |||||
| // Switch LED 2 OFF | |||||
| GpioWrite( &Led2, 1 ); | |||||
| // Switch LED 1 ON | |||||
| GpioWrite( &Led1, 0 ); | |||||
| TimerStart( &Led1Timer ); | |||||
| } | |||||
| } | |||||
| } | |||||
| @@ -1,182 +1,182 @@ | |||||
| /*! | |||||
| * \file main.c | |||||
| * | |||||
| * \brief Tx Continuous Wave implementation | |||||
| * | |||||
| * \copyright Revised BSD License, see section \ref LICENSE. | |||||
| * | |||||
| * \code | |||||
| * ______ _ | |||||
| * / _____) _ | | | |||||
| * ( (____ _____ ____ _| |_ _____ ____| |__ | |||||
| * \____ \| ___ | (_ _) ___ |/ ___) _ \ | |||||
| * _____) ) ____| | | || |_| ____( (___| | | | | |||||
| * (______/|_____)_|_|_| \__)_____)\____)_| |_| | |||||
| * (C)2013-2017 Semtech | |||||
| * | |||||
| * \endcode | |||||
| * | |||||
| * \author Miguel Luis ( Semtech ) | |||||
| * | |||||
| * \author Gregory Cristian ( Semtech ) | |||||
| */ | |||||
| #include "board.h" | |||||
| #include "gpio.h" | |||||
| #include "timer.h" | |||||
| #include "radio.h" | |||||
| #if defined( REGION_AS923 ) | |||||
| #define RF_FREQUENCY 923000000 // Hz | |||||
| #define TX_OUTPUT_POWER 14 // 14 dBm | |||||
| #elif defined( REGION_AU915 ) | |||||
| #define RF_FREQUENCY 915000000 // Hz | |||||
| #define TX_OUTPUT_POWER 14 // 14 dBm | |||||
| #elif defined( REGION_CN470 ) | |||||
| #define RF_FREQUENCY 470000000 // Hz | |||||
| #define TX_OUTPUT_POWER 20 // 20 dBm | |||||
| #elif defined( REGION_CN779 ) | |||||
| #define RF_FREQUENCY 779000000 // Hz | |||||
| #define TX_OUTPUT_POWER 14 // 14 dBm | |||||
| #elif defined( REGION_EU433 ) | |||||
| #define RF_FREQUENCY 433000000 // Hz | |||||
| #define TX_OUTPUT_POWER 20 // 20 dBm | |||||
| #elif defined( REGION_EU868 ) | |||||
| #define RF_FREQUENCY 868000000 // Hz | |||||
| #define TX_OUTPUT_POWER 14 // 14 dBm | |||||
| #elif defined( REGION_KR920 ) | |||||
| #define RF_FREQUENCY 920000000 // Hz | |||||
| #define TX_OUTPUT_POWER 14 // 14 dBm | |||||
| #elif defined( REGION_IN865 ) | |||||
| #define RF_FREQUENCY 865000000 // Hz | |||||
| #define TX_OUTPUT_POWER 14 // 14 dBm | |||||
| #elif defined( REGION_US915 ) | |||||
| #define RF_FREQUENCY 915000000 // Hz | |||||
| #define TX_OUTPUT_POWER 14 // 14 dBm | |||||
| #elif defined( REGION_RU864 ) | |||||
| #define RF_FREQUENCY 864000000 // Hz | |||||
| #define TX_OUTPUT_POWER 14 // 14 dBm | |||||
| #else | |||||
| #error "Please define a frequency band in the compiler options." | |||||
| #endif | |||||
| #define TX_TIMEOUT 10 // seconds (MAX value) | |||||
| static TimerEvent_t Led1Timer; | |||||
| volatile bool Led1TimerEvent = false; | |||||
| static TimerEvent_t Led2Timer; | |||||
| volatile bool Led2TimerEvent = false; | |||||
| /*! | |||||
| * Radio events function pointer | |||||
| */ | |||||
| static RadioEvents_t RadioEvents; | |||||
| /*! | |||||
| * LED GPIO pins objects | |||||
| */ | |||||
| extern Gpio_t Led1; | |||||
| extern Gpio_t Led2; | |||||
| /*! | |||||
| * \brief Function executed on Led 1 Timeout event | |||||
| */ | |||||
| void OnLed1TimerEvent( void* context ) | |||||
| { | |||||
| Led1TimerEvent = true; | |||||
| } | |||||
| /*! | |||||
| * \brief Function executed on Led 2 Timeout event | |||||
| */ | |||||
| void OnLed2TimerEvent( void* context ) | |||||
| { | |||||
| Led2TimerEvent = true; | |||||
| } | |||||
| /*! | |||||
| * \brief Function executed on Radio Tx Timeout event | |||||
| */ | |||||
| void OnRadioTxTimeout( void ) | |||||
| { | |||||
| // Restarts continuous wave transmission when timeout expires | |||||
| Radio.SetTxContinuousWave( RF_FREQUENCY, TX_OUTPUT_POWER, TX_TIMEOUT ); | |||||
| } | |||||
| /** | |||||
| * Main application entry point. | |||||
| */ | |||||
| int main( void ) | |||||
| { | |||||
| // Target board initialization | |||||
| BoardInitMcu( ); | |||||
| BoardInitPeriph( ); | |||||
| TimerInit( &Led1Timer, OnLed1TimerEvent ); | |||||
| TimerSetValue( &Led1Timer, 90 ); | |||||
| TimerInit( &Led2Timer, OnLed2TimerEvent ); | |||||
| TimerSetValue( &Led2Timer, 90 ); | |||||
| // Switch LED 1 ON | |||||
| GpioWrite( &Led1, 0 ); | |||||
| TimerStart( &Led1Timer ); | |||||
| // Radio initialization | |||||
| RadioEvents.TxTimeout = OnRadioTxTimeout; | |||||
| Radio.Init( &RadioEvents ); | |||||
| Radio.SetTxContinuousWave( RF_FREQUENCY, TX_OUTPUT_POWER, TX_TIMEOUT ); | |||||
| // Blink LEDs just to show some activity | |||||
| while( 1 ) | |||||
| { | |||||
| // Process Radio IRQ | |||||
| if( Radio.IrqProcess != NULL ) | |||||
| { | |||||
| Radio.IrqProcess( ); | |||||
| } | |||||
| if( Led1TimerEvent == true ) | |||||
| { | |||||
| Led1TimerEvent = false; | |||||
| // Switch LED 1 OFF | |||||
| GpioWrite( &Led1, 1 ); | |||||
| // Switch LED 2 ON | |||||
| GpioWrite( &Led2, 0 ); | |||||
| TimerStart( &Led2Timer ); | |||||
| } | |||||
| if( Led2TimerEvent == true ) | |||||
| { | |||||
| Led2TimerEvent = false; | |||||
| // Switch LED 2 OFF | |||||
| GpioWrite( &Led2, 1 ); | |||||
| // Switch LED 1 ON | |||||
| GpioWrite( &Led1, 0 ); | |||||
| TimerStart( &Led1Timer ); | |||||
| } | |||||
| } | |||||
| } | |||||
| /*! | |||||
| * \file main.c | |||||
| * | |||||
| * \brief Tx Continuous Wave implementation | |||||
| * | |||||
| * \copyright Revised BSD License, see section \ref LICENSE. | |||||
| * | |||||
| * \code | |||||
| * ______ _ | |||||
| * / _____) _ | | | |||||
| * ( (____ _____ ____ _| |_ _____ ____| |__ | |||||
| * \____ \| ___ | (_ _) ___ |/ ___) _ \ | |||||
| * _____) ) ____| | | || |_| ____( (___| | | | | |||||
| * (______/|_____)_|_|_| \__)_____)\____)_| |_| | |||||
| * (C)2013-2017 Semtech | |||||
| * | |||||
| * \endcode | |||||
| * | |||||
| * \author Miguel Luis ( Semtech ) | |||||
| * | |||||
| * \author Gregory Cristian ( Semtech ) | |||||
| */ | |||||
| #include "board.h" | |||||
| #include "gpio.h" | |||||
| #include "timer.h" | |||||
| #include "radio.h" | |||||
| #if defined( REGION_AS923 ) | |||||
| #define RF_FREQUENCY 923000000 // Hz | |||||
| #define TX_OUTPUT_POWER 14 // 14 dBm | |||||
| #elif defined( REGION_AU915 ) | |||||
| #define RF_FREQUENCY 915000000 // Hz | |||||
| #define TX_OUTPUT_POWER 14 // 14 dBm | |||||
| #elif defined( REGION_CN470 ) | |||||
| #define RF_FREQUENCY 470000000 // Hz | |||||
| #define TX_OUTPUT_POWER 20 // 20 dBm | |||||
| #elif defined( REGION_CN779 ) | |||||
| #define RF_FREQUENCY 779000000 // Hz | |||||
| #define TX_OUTPUT_POWER 14 // 14 dBm | |||||
| #elif defined( REGION_EU433 ) | |||||
| #define RF_FREQUENCY 433000000 // Hz | |||||
| #define TX_OUTPUT_POWER 20 // 20 dBm | |||||
| #elif defined( REGION_EU868 ) | |||||
| #define RF_FREQUENCY 868000000 // Hz | |||||
| #define TX_OUTPUT_POWER 14 // 14 dBm | |||||
| #elif defined( REGION_KR920 ) | |||||
| #define RF_FREQUENCY 920000000 // Hz | |||||
| #define TX_OUTPUT_POWER 14 // 14 dBm | |||||
| #elif defined( REGION_IN865 ) | |||||
| #define RF_FREQUENCY 865000000 // Hz | |||||
| #define TX_OUTPUT_POWER 14 // 14 dBm | |||||
| #elif defined( REGION_US915 ) | |||||
| #define RF_FREQUENCY 915000000 // Hz | |||||
| #define TX_OUTPUT_POWER 14 // 14 dBm | |||||
| #elif defined( REGION_RU864 ) | |||||
| #define RF_FREQUENCY 864000000 // Hz | |||||
| #define TX_OUTPUT_POWER 14 // 14 dBm | |||||
| #else | |||||
| #error "Please define a frequency band in the compiler options." | |||||
| #endif | |||||
| #define TX_TIMEOUT 10 // seconds (MAX value) | |||||
| static TimerEvent_t Led1Timer; | |||||
| volatile bool Led1TimerEvent = false; | |||||
| static TimerEvent_t Led2Timer; | |||||
| volatile bool Led2TimerEvent = false; | |||||
| /*! | |||||
| * Radio events function pointer | |||||
| */ | |||||
| static RadioEvents_t RadioEvents; | |||||
| /*! | |||||
| * LED GPIO pins objects | |||||
| */ | |||||
| extern Gpio_t Led1; | |||||
| extern Gpio_t Led2; | |||||
| /*! | |||||
| * \brief Function executed on Led 1 Timeout event | |||||
| */ | |||||
| void OnLed1TimerEvent( void* context ) | |||||
| { | |||||
| Led1TimerEvent = true; | |||||
| } | |||||
| /*! | |||||
| * \brief Function executed on Led 2 Timeout event | |||||
| */ | |||||
| void OnLed2TimerEvent( void* context ) | |||||
| { | |||||
| Led2TimerEvent = true; | |||||
| } | |||||
| /*! | |||||
| * \brief Function executed on Radio Tx Timeout event | |||||
| */ | |||||
| void OnRadioTxTimeout( void ) | |||||
| { | |||||
| // Restarts continuous wave transmission when timeout expires | |||||
| Radio.SetTxContinuousWave( RF_FREQUENCY, TX_OUTPUT_POWER, TX_TIMEOUT ); | |||||
| } | |||||
| /** | |||||
| * Main application entry point. | |||||
| */ | |||||
| int main( void ) | |||||
| { | |||||
| // Target board initialization | |||||
| BoardInitMcu( ); | |||||
| BoardInitPeriph( ); | |||||
| TimerInit( &Led1Timer, OnLed1TimerEvent ); | |||||
| TimerSetValue( &Led1Timer, 90 ); | |||||
| TimerInit( &Led2Timer, OnLed2TimerEvent ); | |||||
| TimerSetValue( &Led2Timer, 90 ); | |||||
| // Switch LED 1 ON | |||||
| GpioWrite( &Led1, 0 ); | |||||
| TimerStart( &Led1Timer ); | |||||
| // Radio initialization | |||||
| RadioEvents.TxTimeout = OnRadioTxTimeout; | |||||
| Radio.Init( &RadioEvents ); | |||||
| Radio.SetTxContinuousWave( RF_FREQUENCY, TX_OUTPUT_POWER, TX_TIMEOUT ); | |||||
| // Blink LEDs just to show some activity | |||||
| while( 1 ) | |||||
| { | |||||
| // Process Radio IRQ | |||||
| if( Radio.IrqProcess != NULL ) | |||||
| { | |||||
| Radio.IrqProcess( ); | |||||
| } | |||||
| if( Led1TimerEvent == true ) | |||||
| { | |||||
| Led1TimerEvent = false; | |||||
| // Switch LED 1 OFF | |||||
| GpioWrite( &Led1, 1 ); | |||||
| // Switch LED 2 ON | |||||
| GpioWrite( &Led2, 0 ); | |||||
| TimerStart( &Led2Timer ); | |||||
| } | |||||
| if( Led2TimerEvent == true ) | |||||
| { | |||||
| Led2TimerEvent = false; | |||||
| // Switch LED 2 OFF | |||||
| GpioWrite( &Led2, 1 ); | |||||
| // Switch LED 1 ON | |||||
| GpioWrite( &Led1, 0 ); | |||||
| TimerStart( &Led1Timer ); | |||||
| } | |||||
| } | |||||
| } | |||||
| @@ -1,182 +1,182 @@ | |||||
| /*! | |||||
| * \file main.c | |||||
| * | |||||
| * \brief Tx Continuous Wave implementation | |||||
| * | |||||
| * \copyright Revised BSD License, see section \ref LICENSE. | |||||
| * | |||||
| * \code | |||||
| * ______ _ | |||||
| * / _____) _ | | | |||||
| * ( (____ _____ ____ _| |_ _____ ____| |__ | |||||
| * \____ \| ___ | (_ _) ___ |/ ___) _ \ | |||||
| * _____) ) ____| | | || |_| ____( (___| | | | | |||||
| * (______/|_____)_|_|_| \__)_____)\____)_| |_| | |||||
| * (C)2013-2017 Semtech | |||||
| * | |||||
| * \endcode | |||||
| * | |||||
| * \author Miguel Luis ( Semtech ) | |||||
| * | |||||
| * \author Gregory Cristian ( Semtech ) | |||||
| */ | |||||
| #include "board.h" | |||||
| #include "gpio.h" | |||||
| #include "timer.h" | |||||
| #include "radio.h" | |||||
| #if defined( REGION_AS923 ) | |||||
| #define RF_FREQUENCY 923000000 // Hz | |||||
| #define TX_OUTPUT_POWER 14 // 14 dBm | |||||
| #elif defined( REGION_AU915 ) | |||||
| #define RF_FREQUENCY 915000000 // Hz | |||||
| #define TX_OUTPUT_POWER 14 // 14 dBm | |||||
| #elif defined( REGION_CN470 ) | |||||
| #define RF_FREQUENCY 470000000 // Hz | |||||
| #define TX_OUTPUT_POWER 20 // 20 dBm | |||||
| #elif defined( REGION_CN779 ) | |||||
| #define RF_FREQUENCY 779000000 // Hz | |||||
| #define TX_OUTPUT_POWER 14 // 14 dBm | |||||
| #elif defined( REGION_EU433 ) | |||||
| #define RF_FREQUENCY 433000000 // Hz | |||||
| #define TX_OUTPUT_POWER 20 // 20 dBm | |||||
| #elif defined( REGION_EU868 ) | |||||
| #define RF_FREQUENCY 868000000 // Hz | |||||
| #define TX_OUTPUT_POWER 14 // 14 dBm | |||||
| #elif defined( REGION_KR920 ) | |||||
| #define RF_FREQUENCY 920000000 // Hz | |||||
| #define TX_OUTPUT_POWER 14 // 14 dBm | |||||
| #elif defined( REGION_IN865 ) | |||||
| #define RF_FREQUENCY 865000000 // Hz | |||||
| #define TX_OUTPUT_POWER 14 // 14 dBm | |||||
| #elif defined( REGION_US915 ) | |||||
| #define RF_FREQUENCY 915000000 // Hz | |||||
| #define TX_OUTPUT_POWER 14 // 14 dBm | |||||
| #elif defined( REGION_RU864 ) | |||||
| #define RF_FREQUENCY 864000000 // Hz | |||||
| #define TX_OUTPUT_POWER 14 // 14 dBm | |||||
| #else | |||||
| #error "Please define a frequency band in the compiler options." | |||||
| #endif | |||||
| #define TX_TIMEOUT 10 // seconds (MAX value) | |||||
| static TimerEvent_t Led1Timer; | |||||
| volatile bool Led1TimerEvent = false; | |||||
| static TimerEvent_t Led2Timer; | |||||
| volatile bool Led2TimerEvent = false; | |||||
| /*! | |||||
| * Radio events function pointer | |||||
| */ | |||||
| static RadioEvents_t RadioEvents; | |||||
| /*! | |||||
| * LED GPIO pins objects | |||||
| */ | |||||
| extern Gpio_t Led1; | |||||
| extern Gpio_t Led2; | |||||
| /*! | |||||
| * \brief Function executed on Led 1 Timeout event | |||||
| */ | |||||
| void OnLed1TimerEvent( void* context ) | |||||
| { | |||||
| Led1TimerEvent = true; | |||||
| } | |||||
| /*! | |||||
| * \brief Function executed on Led 2 Timeout event | |||||
| */ | |||||
| void OnLed2TimerEvent( void* context ) | |||||
| { | |||||
| Led2TimerEvent = true; | |||||
| } | |||||
| /*! | |||||
| * \brief Function executed on Radio Tx Timeout event | |||||
| */ | |||||
| void OnRadioTxTimeout( void ) | |||||
| { | |||||
| // Restarts continuous wave transmission when timeout expires | |||||
| Radio.SetTxContinuousWave( RF_FREQUENCY, TX_OUTPUT_POWER, TX_TIMEOUT ); | |||||
| } | |||||
| /** | |||||
| * Main application entry point. | |||||
| */ | |||||
| int main( void ) | |||||
| { | |||||
| // Target board initialization | |||||
| BoardInitMcu( ); | |||||
| BoardInitPeriph( ); | |||||
| TimerInit( &Led1Timer, OnLed1TimerEvent ); | |||||
| TimerSetValue( &Led1Timer, 90 ); | |||||
| TimerInit( &Led2Timer, OnLed2TimerEvent ); | |||||
| TimerSetValue( &Led2Timer, 90 ); | |||||
| // Switch LED 1 ON | |||||
| GpioWrite( &Led1, 0 ); | |||||
| TimerStart( &Led1Timer ); | |||||
| // Radio initialization | |||||
| RadioEvents.TxTimeout = OnRadioTxTimeout; | |||||
| Radio.Init( &RadioEvents ); | |||||
| Radio.SetTxContinuousWave( RF_FREQUENCY, TX_OUTPUT_POWER, TX_TIMEOUT ); | |||||
| // Blink LEDs just to show some activity | |||||
| while( 1 ) | |||||
| { | |||||
| // Process Radio IRQ | |||||
| if( Radio.IrqProcess != NULL ) | |||||
| { | |||||
| Radio.IrqProcess( ); | |||||
| } | |||||
| if( Led1TimerEvent == true ) | |||||
| { | |||||
| Led1TimerEvent = false; | |||||
| // Switch LED 1 OFF | |||||
| GpioWrite( &Led1, 1 ); | |||||
| // Switch LED 2 ON | |||||
| GpioWrite( &Led2, 0 ); | |||||
| TimerStart( &Led2Timer ); | |||||
| } | |||||
| if( Led2TimerEvent == true ) | |||||
| { | |||||
| Led2TimerEvent = false; | |||||
| // Switch LED 2 OFF | |||||
| GpioWrite( &Led2, 1 ); | |||||
| // Switch LED 1 ON | |||||
| GpioWrite( &Led1, 0 ); | |||||
| TimerStart( &Led1Timer ); | |||||
| } | |||||
| } | |||||
| } | |||||
| /*! | |||||
| * \file main.c | |||||
| * | |||||
| * \brief Tx Continuous Wave implementation | |||||
| * | |||||
| * \copyright Revised BSD License, see section \ref LICENSE. | |||||
| * | |||||
| * \code | |||||
| * ______ _ | |||||
| * / _____) _ | | | |||||
| * ( (____ _____ ____ _| |_ _____ ____| |__ | |||||
| * \____ \| ___ | (_ _) ___ |/ ___) _ \ | |||||
| * _____) ) ____| | | || |_| ____( (___| | | | | |||||
| * (______/|_____)_|_|_| \__)_____)\____)_| |_| | |||||
| * (C)2013-2017 Semtech | |||||
| * | |||||
| * \endcode | |||||
| * | |||||
| * \author Miguel Luis ( Semtech ) | |||||
| * | |||||
| * \author Gregory Cristian ( Semtech ) | |||||
| */ | |||||
| #include "board.h" | |||||
| #include "gpio.h" | |||||
| #include "timer.h" | |||||
| #include "radio.h" | |||||
| #if defined( REGION_AS923 ) | |||||
| #define RF_FREQUENCY 923000000 // Hz | |||||
| #define TX_OUTPUT_POWER 14 // 14 dBm | |||||
| #elif defined( REGION_AU915 ) | |||||
| #define RF_FREQUENCY 915000000 // Hz | |||||
| #define TX_OUTPUT_POWER 14 // 14 dBm | |||||
| #elif defined( REGION_CN470 ) | |||||
| #define RF_FREQUENCY 470000000 // Hz | |||||
| #define TX_OUTPUT_POWER 20 // 20 dBm | |||||
| #elif defined( REGION_CN779 ) | |||||
| #define RF_FREQUENCY 779000000 // Hz | |||||
| #define TX_OUTPUT_POWER 14 // 14 dBm | |||||
| #elif defined( REGION_EU433 ) | |||||
| #define RF_FREQUENCY 433000000 // Hz | |||||
| #define TX_OUTPUT_POWER 20 // 20 dBm | |||||
| #elif defined( REGION_EU868 ) | |||||
| #define RF_FREQUENCY 868000000 // Hz | |||||
| #define TX_OUTPUT_POWER 14 // 14 dBm | |||||
| #elif defined( REGION_KR920 ) | |||||
| #define RF_FREQUENCY 920000000 // Hz | |||||
| #define TX_OUTPUT_POWER 14 // 14 dBm | |||||
| #elif defined( REGION_IN865 ) | |||||
| #define RF_FREQUENCY 865000000 // Hz | |||||
| #define TX_OUTPUT_POWER 14 // 14 dBm | |||||
| #elif defined( REGION_US915 ) | |||||
| #define RF_FREQUENCY 915000000 // Hz | |||||
| #define TX_OUTPUT_POWER 14 // 14 dBm | |||||
| #elif defined( REGION_RU864 ) | |||||
| #define RF_FREQUENCY 864000000 // Hz | |||||
| #define TX_OUTPUT_POWER 14 // 14 dBm | |||||
| #else | |||||
| #error "Please define a frequency band in the compiler options." | |||||
| #endif | |||||
| #define TX_TIMEOUT 10 // seconds (MAX value) | |||||
| static TimerEvent_t Led1Timer; | |||||
| volatile bool Led1TimerEvent = false; | |||||
| static TimerEvent_t Led2Timer; | |||||
| volatile bool Led2TimerEvent = false; | |||||
| /*! | |||||
| * Radio events function pointer | |||||
| */ | |||||
| static RadioEvents_t RadioEvents; | |||||
| /*! | |||||
| * LED GPIO pins objects | |||||
| */ | |||||
| extern Gpio_t Led1; | |||||
| extern Gpio_t Led2; | |||||
| /*! | |||||
| * \brief Function executed on Led 1 Timeout event | |||||
| */ | |||||
| void OnLed1TimerEvent( void* context ) | |||||
| { | |||||
| Led1TimerEvent = true; | |||||
| } | |||||
| /*! | |||||
| * \brief Function executed on Led 2 Timeout event | |||||
| */ | |||||
| void OnLed2TimerEvent( void* context ) | |||||
| { | |||||
| Led2TimerEvent = true; | |||||
| } | |||||
| /*! | |||||
| * \brief Function executed on Radio Tx Timeout event | |||||
| */ | |||||
| void OnRadioTxTimeout( void ) | |||||
| { | |||||
| // Restarts continuous wave transmission when timeout expires | |||||
| Radio.SetTxContinuousWave( RF_FREQUENCY, TX_OUTPUT_POWER, TX_TIMEOUT ); | |||||
| } | |||||
| /** | |||||
| * Main application entry point. | |||||
| */ | |||||
| int main( void ) | |||||
| { | |||||
| // Target board initialization | |||||
| BoardInitMcu( ); | |||||
| BoardInitPeriph( ); | |||||
| TimerInit( &Led1Timer, OnLed1TimerEvent ); | |||||
| TimerSetValue( &Led1Timer, 90 ); | |||||
| TimerInit( &Led2Timer, OnLed2TimerEvent ); | |||||
| TimerSetValue( &Led2Timer, 90 ); | |||||
| // Switch LED 1 ON | |||||
| GpioWrite( &Led1, 0 ); | |||||
| TimerStart( &Led1Timer ); | |||||
| // Radio initialization | |||||
| RadioEvents.TxTimeout = OnRadioTxTimeout; | |||||
| Radio.Init( &RadioEvents ); | |||||
| Radio.SetTxContinuousWave( RF_FREQUENCY, TX_OUTPUT_POWER, TX_TIMEOUT ); | |||||
| // Blink LEDs just to show some activity | |||||
| while( 1 ) | |||||
| { | |||||
| // Process Radio IRQ | |||||
| if( Radio.IrqProcess != NULL ) | |||||
| { | |||||
| Radio.IrqProcess( ); | |||||
| } | |||||
| if( Led1TimerEvent == true ) | |||||
| { | |||||
| Led1TimerEvent = false; | |||||
| // Switch LED 1 OFF | |||||
| GpioWrite( &Led1, 1 ); | |||||
| // Switch LED 2 ON | |||||
| GpioWrite( &Led2, 0 ); | |||||
| TimerStart( &Led2Timer ); | |||||
| } | |||||
| if( Led2TimerEvent == true ) | |||||
| { | |||||
| Led2TimerEvent = false; | |||||
| // Switch LED 2 OFF | |||||
| GpioWrite( &Led2, 1 ); | |||||
| // Switch LED 1 ON | |||||
| GpioWrite( &Led1, 0 ); | |||||
| TimerStart( &Led1Timer ); | |||||
| } | |||||
| } | |||||
| } | |||||
| @@ -1,156 +1,156 @@ | |||||
| /*! | |||||
| * \file main.c | |||||
| * | |||||
| * \brief Tx Continuous Wave implementation | |||||
| * | |||||
| * \copyright Revised BSD License, see section \ref LICENSE. | |||||
| * | |||||
| * \code | |||||
| * ______ _ | |||||
| * / _____) _ | | | |||||
| * ( (____ _____ ____ _| |_ _____ ____| |__ | |||||
| * \____ \| ___ | (_ _) ___ |/ ___) _ \ | |||||
| * _____) ) ____| | | || |_| ____( (___| | | | | |||||
| * (______/|_____)_|_|_| \__)_____)\____)_| |_| | |||||
| * (C)2013-2017 Semtech | |||||
| * | |||||
| * \endcode | |||||
| * | |||||
| * \author Miguel Luis ( Semtech ) | |||||
| * | |||||
| * \author Gregory Cristian ( Semtech ) | |||||
| * | |||||
| * \author Marten Lootsma(TWTG) on behalf of Microchip/Atmel (c)2017 | |||||
| */ | |||||
| #include "board.h" | |||||
| #include "gpio.h" | |||||
| #include "timer.h" | |||||
| #include "radio.h" | |||||
| #if defined( REGION_AS923 ) | |||||
| #define RF_FREQUENCY 923000000 // Hz | |||||
| #define TX_OUTPUT_POWER 14 // 14 dBm | |||||
| #elif defined( REGION_AU915 ) | |||||
| #define RF_FREQUENCY 915000000 // Hz | |||||
| #define TX_OUTPUT_POWER 14 // 14 dBm | |||||
| #elif defined( REGION_CN470 ) | |||||
| #define RF_FREQUENCY 470000000 // Hz | |||||
| #define TX_OUTPUT_POWER 20 // 20 dBm | |||||
| #elif defined( REGION_CN779 ) | |||||
| #define RF_FREQUENCY 779000000 // Hz | |||||
| #define TX_OUTPUT_POWER 14 // 14 dBm | |||||
| #elif defined( REGION_EU433 ) | |||||
| #define RF_FREQUENCY 433000000 // Hz | |||||
| #define TX_OUTPUT_POWER 20 // 20 dBm | |||||
| #elif defined( REGION_EU868 ) | |||||
| #define RF_FREQUENCY 868000000 // Hz | |||||
| #define TX_OUTPUT_POWER 14 // 14 dBm | |||||
| #elif defined( REGION_KR920 ) | |||||
| #define RF_FREQUENCY 920000000 // Hz | |||||
| #define TX_OUTPUT_POWER 14 // 14 dBm | |||||
| #elif defined( REGION_IN865 ) | |||||
| #define RF_FREQUENCY 865000000 // Hz | |||||
| #define TX_OUTPUT_POWER 14 // 14 dBm | |||||
| #elif defined( REGION_US915 ) | |||||
| #define RF_FREQUENCY 915000000 // Hz | |||||
| #define TX_OUTPUT_POWER 14 // 14 dBm | |||||
| #elif defined( REGION_RU864 ) | |||||
| #define RF_FREQUENCY 864000000 // Hz | |||||
| #define TX_OUTPUT_POWER 14 // 14 dBm | |||||
| #else | |||||
| #error "Please define a frequency band in the compiler options." | |||||
| #endif | |||||
| #define TX_TIMEOUT 65535 // seconds (MAX value) | |||||
| static TimerEvent_t Led1Timer; | |||||
| volatile bool Led1TimerEvent = false; | |||||
| /*! | |||||
| * Radio events function pointer | |||||
| */ | |||||
| static RadioEvents_t RadioEvents; | |||||
| /*! | |||||
| * LED GPIO pins objects | |||||
| */ | |||||
| extern Gpio_t Led1; | |||||
| /*! | |||||
| * \brief Function executed on Led 1 Timeout event | |||||
| */ | |||||
| void OnLed1TimerEvent( void* context ) | |||||
| { | |||||
| Led1TimerEvent = true; | |||||
| } | |||||
| /*! | |||||
| * \brief Function executed on Radio Tx Timeout event | |||||
| */ | |||||
| void OnRadioTxTimeout( void ) | |||||
| { | |||||
| // Restarts continuous wave transmission when timeout expires | |||||
| Radio.SetTxContinuousWave( RF_FREQUENCY, TX_OUTPUT_POWER, TX_TIMEOUT ); | |||||
| } | |||||
| /** | |||||
| * Main application entry point. | |||||
| */ | |||||
| int main( void ) | |||||
| { | |||||
| // Target board initialization | |||||
| BoardInitMcu( ); | |||||
| BoardInitPeriph( ); | |||||
| TimerInit( &Led1Timer, OnLed1TimerEvent ); | |||||
| TimerSetValue( &Led1Timer, 90 ); | |||||
| // Switch LED 1 ON | |||||
| GpioWrite( &Led1, 0 ); | |||||
| TimerStart( &Led1Timer ); | |||||
| // Radio initialization | |||||
| RadioEvents.TxTimeout = OnRadioTxTimeout; | |||||
| Radio.Init( &RadioEvents ); | |||||
| Radio.SetTxContinuousWave( RF_FREQUENCY, TX_OUTPUT_POWER, TX_TIMEOUT ); | |||||
| // Blink LEDs just to show some activity | |||||
| while( 1 ) | |||||
| { | |||||
| // Tick the RTC to execute callback in context of the main loop (in stead of the IRQ) | |||||
| TimerProcess( ); | |||||
| if( Led1TimerEvent == true ) | |||||
| { | |||||
| Led1TimerEvent = false; | |||||
| // Switch LED 1 OFF | |||||
| GpioWrite( &Led1, 1 ); | |||||
| } | |||||
| } | |||||
| } | |||||
| /*! | |||||
| * \file main.c | |||||
| * | |||||
| * \brief Tx Continuous Wave implementation | |||||
| * | |||||
| * \copyright Revised BSD License, see section \ref LICENSE. | |||||
| * | |||||
| * \code | |||||
| * ______ _ | |||||
| * / _____) _ | | | |||||
| * ( (____ _____ ____ _| |_ _____ ____| |__ | |||||
| * \____ \| ___ | (_ _) ___ |/ ___) _ \ | |||||
| * _____) ) ____| | | || |_| ____( (___| | | | | |||||
| * (______/|_____)_|_|_| \__)_____)\____)_| |_| | |||||
| * (C)2013-2017 Semtech | |||||
| * | |||||
| * \endcode | |||||
| * | |||||
| * \author Miguel Luis ( Semtech ) | |||||
| * | |||||
| * \author Gregory Cristian ( Semtech ) | |||||
| * | |||||
| * \author Marten Lootsma(TWTG) on behalf of Microchip/Atmel (c)2017 | |||||
| */ | |||||
| #include "board.h" | |||||
| #include "gpio.h" | |||||
| #include "timer.h" | |||||
| #include "radio.h" | |||||
| #if defined( REGION_AS923 ) | |||||
| #define RF_FREQUENCY 923000000 // Hz | |||||
| #define TX_OUTPUT_POWER 14 // 14 dBm | |||||
| #elif defined( REGION_AU915 ) | |||||
| #define RF_FREQUENCY 915000000 // Hz | |||||
| #define TX_OUTPUT_POWER 14 // 14 dBm | |||||
| #elif defined( REGION_CN470 ) | |||||
| #define RF_FREQUENCY 470000000 // Hz | |||||
| #define TX_OUTPUT_POWER 20 // 20 dBm | |||||
| #elif defined( REGION_CN779 ) | |||||
| #define RF_FREQUENCY 779000000 // Hz | |||||
| #define TX_OUTPUT_POWER 14 // 14 dBm | |||||
| #elif defined( REGION_EU433 ) | |||||
| #define RF_FREQUENCY 433000000 // Hz | |||||
| #define TX_OUTPUT_POWER 20 // 20 dBm | |||||
| #elif defined( REGION_EU868 ) | |||||
| #define RF_FREQUENCY 868000000 // Hz | |||||
| #define TX_OUTPUT_POWER 14 // 14 dBm | |||||
| #elif defined( REGION_KR920 ) | |||||
| #define RF_FREQUENCY 920000000 // Hz | |||||
| #define TX_OUTPUT_POWER 14 // 14 dBm | |||||
| #elif defined( REGION_IN865 ) | |||||
| #define RF_FREQUENCY 865000000 // Hz | |||||
| #define TX_OUTPUT_POWER 14 // 14 dBm | |||||
| #elif defined( REGION_US915 ) | |||||
| #define RF_FREQUENCY 915000000 // Hz | |||||
| #define TX_OUTPUT_POWER 14 // 14 dBm | |||||
| #elif defined( REGION_RU864 ) | |||||
| #define RF_FREQUENCY 864000000 // Hz | |||||
| #define TX_OUTPUT_POWER 14 // 14 dBm | |||||
| #else | |||||
| #error "Please define a frequency band in the compiler options." | |||||
| #endif | |||||
| #define TX_TIMEOUT 65535 // seconds (MAX value) | |||||
| static TimerEvent_t Led1Timer; | |||||
| volatile bool Led1TimerEvent = false; | |||||
| /*! | |||||
| * Radio events function pointer | |||||
| */ | |||||
| static RadioEvents_t RadioEvents; | |||||
| /*! | |||||
| * LED GPIO pins objects | |||||
| */ | |||||
| extern Gpio_t Led1; | |||||
| /*! | |||||
| * \brief Function executed on Led 1 Timeout event | |||||
| */ | |||||
| void OnLed1TimerEvent( void* context ) | |||||
| { | |||||
| Led1TimerEvent = true; | |||||
| } | |||||
| /*! | |||||
| * \brief Function executed on Radio Tx Timeout event | |||||
| */ | |||||
| void OnRadioTxTimeout( void ) | |||||
| { | |||||
| // Restarts continuous wave transmission when timeout expires | |||||
| Radio.SetTxContinuousWave( RF_FREQUENCY, TX_OUTPUT_POWER, TX_TIMEOUT ); | |||||
| } | |||||
| /** | |||||
| * Main application entry point. | |||||
| */ | |||||
| int main( void ) | |||||
| { | |||||
| // Target board initialization | |||||
| BoardInitMcu( ); | |||||
| BoardInitPeriph( ); | |||||
| TimerInit( &Led1Timer, OnLed1TimerEvent ); | |||||
| TimerSetValue( &Led1Timer, 90 ); | |||||
| // Switch LED 1 ON | |||||
| GpioWrite( &Led1, 0 ); | |||||
| TimerStart( &Led1Timer ); | |||||
| // Radio initialization | |||||
| RadioEvents.TxTimeout = OnRadioTxTimeout; | |||||
| Radio.Init( &RadioEvents ); | |||||
| Radio.SetTxContinuousWave( RF_FREQUENCY, TX_OUTPUT_POWER, TX_TIMEOUT ); | |||||
| // Blink LEDs just to show some activity | |||||
| while( 1 ) | |||||
| { | |||||
| // Tick the RTC to execute callback in context of the main loop (in stead of the IRQ) | |||||
| TimerProcess( ); | |||||
| if( Led1TimerEvent == true ) | |||||
| { | |||||
| Led1TimerEvent = false; | |||||
| // Switch LED 1 OFF | |||||
| GpioWrite( &Led1, 1 ); | |||||
| } | |||||
| } | |||||
| } | |||||
| @@ -1,187 +1,187 @@ | |||||
| /*! | |||||
| * \file main.c | |||||
| * | |||||
| * \brief Tx Continuous Wave implementation | |||||
| * | |||||
| * \copyright Revised BSD License, see section \ref LICENSE. | |||||
| * | |||||
| * \code | |||||
| * ______ _ | |||||
| * / _____) _ | | | |||||
| * ( (____ _____ ____ _| |_ _____ ____| |__ | |||||
| * \____ \| ___ | (_ _) ___ |/ ___) _ \ | |||||
| * _____) ) ____| | | || |_| ____( (___| | | | | |||||
| * (______/|_____)_|_|_| \__)_____)\____)_| |_| | |||||
| * (C)2013-2017 Semtech | |||||
| * | |||||
| * \endcode | |||||
| * | |||||
| * \author Miguel Luis ( Semtech ) | |||||
| * | |||||
| * \author Gregory Cristian ( Semtech ) | |||||
| */ | |||||
| #include "board.h" | |||||
| #include "gpio.h" | |||||
| #include "timer.h" | |||||
| #include "radio.h" | |||||
| #if defined( REGION_AS923 ) | |||||
| #define RF_FREQUENCY 923000000 // Hz | |||||
| #elif defined( REGION_AU915 ) | |||||
| #define RF_FREQUENCY 915000000 // Hz | |||||
| #elif defined( REGION_CN779 ) | |||||
| #define RF_FREQUENCY 779000000 // Hz | |||||
| #elif defined( REGION_EU868 ) | |||||
| #define RF_FREQUENCY 868000000 // Hz | |||||
| #elif defined( REGION_KR920 ) | |||||
| #define RF_FREQUENCY 920000000 // Hz | |||||
| #elif defined( REGION_IN865 ) | |||||
| #define RF_FREQUENCY 865000000 // Hz | |||||
| #elif defined( REGION_US915 ) | |||||
| #define RF_FREQUENCY 915000000 // Hz | |||||
| #elif defined( REGION_RU864 ) | |||||
| #define RF_FREQUENCY 864000000 // Hz | |||||
| #else | |||||
| #error "Please define a frequency band in the compiler options." | |||||
| #endif | |||||
| #define TX_OUTPUT_POWER 20 // 20 dBm | |||||
| #define TX_TIMEOUT 65535 // seconds (MAX value) | |||||
| static TimerEvent_t Led4Timer; | |||||
| volatile bool Led4TimerEvent = false; | |||||
| static TimerEvent_t Led2Timer; | |||||
| volatile bool Led2TimerEvent = false; | |||||
| static TimerEvent_t Led3Timer; | |||||
| volatile bool Led3TimerEvent = false; | |||||
| /*! | |||||
| * Radio events function pointer | |||||
| */ | |||||
| static RadioEvents_t RadioEvents; | |||||
| /*! | |||||
| * LED GPIO pins objects | |||||
| */ | |||||
| extern Gpio_t Led4; | |||||
| extern Gpio_t Led2; | |||||
| extern Gpio_t Led3; | |||||
| /*! | |||||
| * \brief Function executed on Led 1 Timeout event | |||||
| */ | |||||
| void OnLed4TimerEvent( void* context ) | |||||
| { | |||||
| Led4TimerEvent = true; | |||||
| } | |||||
| /*! | |||||
| * \brief Function executed on Led 2 Timeout event | |||||
| */ | |||||
| void OnLed2TimerEvent( void* context ) | |||||
| { | |||||
| Led2TimerEvent = true; | |||||
| } | |||||
| /*! | |||||
| * \brief Function executed on Led 3 Timeout event | |||||
| */ | |||||
| void OnLed3TimerEvent( void* context ) | |||||
| { | |||||
| Led3TimerEvent = true; | |||||
| } | |||||
| /*! | |||||
| * \brief Function executed on Radio Tx Timeout event | |||||
| */ | |||||
| void OnRadioTxTimeout( void ) | |||||
| { | |||||
| // Restarts continuous wave transmission when timeout expires | |||||
| Radio.SetTxContinuousWave( RF_FREQUENCY, TX_OUTPUT_POWER, TX_TIMEOUT ); | |||||
| } | |||||
| /** | |||||
| * Main application entry point. | |||||
| */ | |||||
| int main( void ) | |||||
| { | |||||
| // Target board initialization | |||||
| BoardInitMcu( ); | |||||
| BoardInitPeriph( ); | |||||
| TimerInit( &Led4Timer, OnLed4TimerEvent ); | |||||
| TimerSetValue( &Led4Timer, 90 ); | |||||
| TimerInit( &Led2Timer, OnLed2TimerEvent ); | |||||
| TimerSetValue( &Led2Timer, 90 ); | |||||
| TimerInit( &Led3Timer, OnLed3TimerEvent ); | |||||
| TimerSetValue( &Led3Timer, 90 ); | |||||
| // Switch LED 1 ON | |||||
| GpioWrite( &Led4, 0 ); | |||||
| TimerStart( &Led4Timer ); | |||||
| // Radio initialization | |||||
| RadioEvents.TxTimeout = OnRadioTxTimeout; | |||||
| Radio.Init( &RadioEvents ); | |||||
| Radio.SetTxContinuousWave( RF_FREQUENCY, TX_OUTPUT_POWER, TX_TIMEOUT ); | |||||
| // Blink LEDs just to show some activity | |||||
| while( 1 ) | |||||
| { | |||||
| if( Led4TimerEvent == true ) | |||||
| { | |||||
| Led4TimerEvent = false; | |||||
| // Switch LED 4 OFF | |||||
| GpioWrite( &Led4, 4 ); | |||||
| // Switch LED 2 ON | |||||
| GpioWrite( &Led2, 0 ); | |||||
| TimerStart( &Led2Timer ); | |||||
| } | |||||
| if( Led2TimerEvent == true ) | |||||
| { | |||||
| Led2TimerEvent = false; | |||||
| // Switch LED 2 OFF | |||||
| GpioWrite( &Led2, 1 ); | |||||
| // Switch LED 3 ON | |||||
| GpioWrite( &Led3, 0 ); | |||||
| TimerStart( &Led3Timer ); | |||||
| } | |||||
| if( Led3TimerEvent == true ) | |||||
| { | |||||
| Led3TimerEvent = false; | |||||
| // Switch LED 3 OFF | |||||
| GpioWrite( &Led3, 1 ); | |||||
| // Switch LED 1 ON | |||||
| GpioWrite( &Led4, 0 ); | |||||
| TimerStart( &Led4Timer ); | |||||
| } | |||||
| } | |||||
| } | |||||
| /*! | |||||
| * \file main.c | |||||
| * | |||||
| * \brief Tx Continuous Wave implementation | |||||
| * | |||||
| * \copyright Revised BSD License, see section \ref LICENSE. | |||||
| * | |||||
| * \code | |||||
| * ______ _ | |||||
| * / _____) _ | | | |||||
| * ( (____ _____ ____ _| |_ _____ ____| |__ | |||||
| * \____ \| ___ | (_ _) ___ |/ ___) _ \ | |||||
| * _____) ) ____| | | || |_| ____( (___| | | | | |||||
| * (______/|_____)_|_|_| \__)_____)\____)_| |_| | |||||
| * (C)2013-2017 Semtech | |||||
| * | |||||
| * \endcode | |||||
| * | |||||
| * \author Miguel Luis ( Semtech ) | |||||
| * | |||||
| * \author Gregory Cristian ( Semtech ) | |||||
| */ | |||||
| #include "board.h" | |||||
| #include "gpio.h" | |||||
| #include "timer.h" | |||||
| #include "radio.h" | |||||
| #if defined( REGION_AS923 ) | |||||
| #define RF_FREQUENCY 923000000 // Hz | |||||
| #elif defined( REGION_AU915 ) | |||||
| #define RF_FREQUENCY 915000000 // Hz | |||||
| #elif defined( REGION_CN779 ) | |||||
| #define RF_FREQUENCY 779000000 // Hz | |||||
| #elif defined( REGION_EU868 ) | |||||
| #define RF_FREQUENCY 868000000 // Hz | |||||
| #elif defined( REGION_KR920 ) | |||||
| #define RF_FREQUENCY 920000000 // Hz | |||||
| #elif defined( REGION_IN865 ) | |||||
| #define RF_FREQUENCY 865000000 // Hz | |||||
| #elif defined( REGION_US915 ) | |||||
| #define RF_FREQUENCY 915000000 // Hz | |||||
| #elif defined( REGION_RU864 ) | |||||
| #define RF_FREQUENCY 864000000 // Hz | |||||
| #else | |||||
| #error "Please define a frequency band in the compiler options." | |||||
| #endif | |||||
| #define TX_OUTPUT_POWER 20 // 20 dBm | |||||
| #define TX_TIMEOUT 65535 // seconds (MAX value) | |||||
| static TimerEvent_t Led4Timer; | |||||
| volatile bool Led4TimerEvent = false; | |||||
| static TimerEvent_t Led2Timer; | |||||
| volatile bool Led2TimerEvent = false; | |||||
| static TimerEvent_t Led3Timer; | |||||
| volatile bool Led3TimerEvent = false; | |||||
| /*! | |||||
| * Radio events function pointer | |||||
| */ | |||||
| static RadioEvents_t RadioEvents; | |||||
| /*! | |||||
| * LED GPIO pins objects | |||||
| */ | |||||
| extern Gpio_t Led4; | |||||
| extern Gpio_t Led2; | |||||
| extern Gpio_t Led3; | |||||
| /*! | |||||
| * \brief Function executed on Led 1 Timeout event | |||||
| */ | |||||
| void OnLed4TimerEvent( void* context ) | |||||
| { | |||||
| Led4TimerEvent = true; | |||||
| } | |||||
| /*! | |||||
| * \brief Function executed on Led 2 Timeout event | |||||
| */ | |||||
| void OnLed2TimerEvent( void* context ) | |||||
| { | |||||
| Led2TimerEvent = true; | |||||
| } | |||||
| /*! | |||||
| * \brief Function executed on Led 3 Timeout event | |||||
| */ | |||||
| void OnLed3TimerEvent( void* context ) | |||||
| { | |||||
| Led3TimerEvent = true; | |||||
| } | |||||
| /*! | |||||
| * \brief Function executed on Radio Tx Timeout event | |||||
| */ | |||||
| void OnRadioTxTimeout( void ) | |||||
| { | |||||
| // Restarts continuous wave transmission when timeout expires | |||||
| Radio.SetTxContinuousWave( RF_FREQUENCY, TX_OUTPUT_POWER, TX_TIMEOUT ); | |||||
| } | |||||
| /** | |||||
| * Main application entry point. | |||||
| */ | |||||
| int main( void ) | |||||
| { | |||||
| // Target board initialization | |||||
| BoardInitMcu( ); | |||||
| BoardInitPeriph( ); | |||||
| TimerInit( &Led4Timer, OnLed4TimerEvent ); | |||||
| TimerSetValue( &Led4Timer, 90 ); | |||||
| TimerInit( &Led2Timer, OnLed2TimerEvent ); | |||||
| TimerSetValue( &Led2Timer, 90 ); | |||||
| TimerInit( &Led3Timer, OnLed3TimerEvent ); | |||||
| TimerSetValue( &Led3Timer, 90 ); | |||||
| // Switch LED 1 ON | |||||
| GpioWrite( &Led4, 0 ); | |||||
| TimerStart( &Led4Timer ); | |||||
| // Radio initialization | |||||
| RadioEvents.TxTimeout = OnRadioTxTimeout; | |||||
| Radio.Init( &RadioEvents ); | |||||
| Radio.SetTxContinuousWave( RF_FREQUENCY, TX_OUTPUT_POWER, TX_TIMEOUT ); | |||||
| // Blink LEDs just to show some activity | |||||
| while( 1 ) | |||||
| { | |||||
| if( Led4TimerEvent == true ) | |||||
| { | |||||
| Led4TimerEvent = false; | |||||
| // Switch LED 4 OFF | |||||
| GpioWrite( &Led4, 4 ); | |||||
| // Switch LED 2 ON | |||||
| GpioWrite( &Led2, 0 ); | |||||
| TimerStart( &Led2Timer ); | |||||
| } | |||||
| if( Led2TimerEvent == true ) | |||||
| { | |||||
| Led2TimerEvent = false; | |||||
| // Switch LED 2 OFF | |||||
| GpioWrite( &Led2, 1 ); | |||||
| // Switch LED 3 ON | |||||
| GpioWrite( &Led3, 0 ); | |||||
| TimerStart( &Led3Timer ); | |||||
| } | |||||
| if( Led3TimerEvent == true ) | |||||
| { | |||||
| Led3TimerEvent = false; | |||||
| // Switch LED 3 OFF | |||||
| GpioWrite( &Led3, 1 ); | |||||
| // Switch LED 1 ON | |||||
| GpioWrite( &Led4, 0 ); | |||||
| TimerStart( &Led4Timer ); | |||||
| } | |||||
| } | |||||
| } | |||||
| @@ -1,187 +1,187 @@ | |||||
| /*! | |||||
| * \file main.c | |||||
| * | |||||
| * \brief Tx Continuous Wave implementation | |||||
| * | |||||
| * \copyright Revised BSD License, see section \ref LICENSE. | |||||
| * | |||||
| * \code | |||||
| * ______ _ | |||||
| * / _____) _ | | | |||||
| * ( (____ _____ ____ _| |_ _____ ____| |__ | |||||
| * \____ \| ___ | (_ _) ___ |/ ___) _ \ | |||||
| * _____) ) ____| | | || |_| ____( (___| | | | | |||||
| * (______/|_____)_|_|_| \__)_____)\____)_| |_| | |||||
| * (C)2013-2017 Semtech | |||||
| * | |||||
| * \endcode | |||||
| * | |||||
| * \author Miguel Luis ( Semtech ) | |||||
| * | |||||
| * \author Gregory Cristian ( Semtech ) | |||||
| */ | |||||
| #include "board.h" | |||||
| #include "gpio.h" | |||||
| #include "timer.h" | |||||
| #include "radio.h" | |||||
| #if defined( REGION_AS923 ) | |||||
| #define RF_FREQUENCY 923000000 // Hz | |||||
| #elif defined( REGION_AU915 ) | |||||
| #define RF_FREQUENCY 915000000 // Hz | |||||
| #elif defined( REGION_CN779 ) | |||||
| #define RF_FREQUENCY 779000000 // Hz | |||||
| #elif defined( REGION_EU868 ) | |||||
| #define RF_FREQUENCY 868000000 // Hz | |||||
| #elif defined( REGION_KR920 ) | |||||
| #define RF_FREQUENCY 920000000 // Hz | |||||
| #elif defined( REGION_IN865 ) | |||||
| #define RF_FREQUENCY 865000000 // Hz | |||||
| #elif defined( REGION_US915 ) | |||||
| #define RF_FREQUENCY 915000000 // Hz | |||||
| #elif defined( REGION_RU864 ) | |||||
| #define RF_FREQUENCY 864000000 // Hz | |||||
| #else | |||||
| #error "Please define a frequency band in the compiler options." | |||||
| #endif | |||||
| #define TX_OUTPUT_POWER 20 // 20 dBm | |||||
| #define TX_TIMEOUT 65535 // seconds (MAX value) | |||||
| static TimerEvent_t Led4Timer; | |||||
| volatile bool Led4TimerEvent = false; | |||||
| static TimerEvent_t Led2Timer; | |||||
| volatile bool Led2TimerEvent = false; | |||||
| static TimerEvent_t Led3Timer; | |||||
| volatile bool Led3TimerEvent = false; | |||||
| /*! | |||||
| * Radio events function pointer | |||||
| */ | |||||
| static RadioEvents_t RadioEvents; | |||||
| /*! | |||||
| * LED GPIO pins objects | |||||
| */ | |||||
| extern Gpio_t Led4; | |||||
| extern Gpio_t Led2; | |||||
| extern Gpio_t Led3; | |||||
| /*! | |||||
| * \brief Function executed on Led 1 Timeout event | |||||
| */ | |||||
| void OnLed4TimerEvent( void* context ) | |||||
| { | |||||
| Led4TimerEvent = true; | |||||
| } | |||||
| /*! | |||||
| * \brief Function executed on Led 2 Timeout event | |||||
| */ | |||||
| void OnLed2TimerEvent( void* context ) | |||||
| { | |||||
| Led2TimerEvent = true; | |||||
| } | |||||
| /*! | |||||
| * \brief Function executed on Led 3 Timeout event | |||||
| */ | |||||
| void OnLed3TimerEvent( void* context ) | |||||
| { | |||||
| Led3TimerEvent = true; | |||||
| } | |||||
| /*! | |||||
| * \brief Function executed on Radio Tx Timeout event | |||||
| */ | |||||
| void OnRadioTxTimeout( void ) | |||||
| { | |||||
| // Restarts continuous wave transmission when timeout expires | |||||
| Radio.SetTxContinuousWave( RF_FREQUENCY, TX_OUTPUT_POWER, TX_TIMEOUT ); | |||||
| } | |||||
| /** | |||||
| * Main application entry point. | |||||
| */ | |||||
| int main( void ) | |||||
| { | |||||
| // Target board initialization | |||||
| BoardInitMcu( ); | |||||
| BoardInitPeriph( ); | |||||
| TimerInit( &Led4Timer, OnLed4TimerEvent ); | |||||
| TimerSetValue( &Led4Timer, 90 ); | |||||
| TimerInit( &Led2Timer, OnLed2TimerEvent ); | |||||
| TimerSetValue( &Led2Timer, 90 ); | |||||
| TimerInit( &Led3Timer, OnLed3TimerEvent ); | |||||
| TimerSetValue( &Led3Timer, 90 ); | |||||
| // Switch LED 1 ON | |||||
| GpioWrite( &Led4, 0 ); | |||||
| TimerStart( &Led4Timer ); | |||||
| // Radio initialization | |||||
| RadioEvents.TxTimeout = OnRadioTxTimeout; | |||||
| Radio.Init( &RadioEvents ); | |||||
| Radio.SetTxContinuousWave( RF_FREQUENCY, TX_OUTPUT_POWER, TX_TIMEOUT ); | |||||
| // Blink LEDs just to show some activity | |||||
| while( 1 ) | |||||
| { | |||||
| if( Led4TimerEvent == true ) | |||||
| { | |||||
| Led4TimerEvent = false; | |||||
| // Switch LED 4 OFF | |||||
| GpioWrite( &Led4, 4 ); | |||||
| // Switch LED 2 ON | |||||
| GpioWrite( &Led2, 0 ); | |||||
| TimerStart( &Led2Timer ); | |||||
| } | |||||
| if( Led2TimerEvent == true ) | |||||
| { | |||||
| Led2TimerEvent = false; | |||||
| // Switch LED 2 OFF | |||||
| GpioWrite( &Led2, 1 ); | |||||
| // Switch LED 3 ON | |||||
| GpioWrite( &Led3, 0 ); | |||||
| TimerStart( &Led3Timer ); | |||||
| } | |||||
| if( Led3TimerEvent == true ) | |||||
| { | |||||
| Led3TimerEvent = false; | |||||
| // Switch LED 3 OFF | |||||
| GpioWrite( &Led3, 1 ); | |||||
| // Switch LED 1 ON | |||||
| GpioWrite( &Led4, 0 ); | |||||
| TimerStart( &Led4Timer ); | |||||
| } | |||||
| } | |||||
| } | |||||
| /*! | |||||
| * \file main.c | |||||
| * | |||||
| * \brief Tx Continuous Wave implementation | |||||
| * | |||||
| * \copyright Revised BSD License, see section \ref LICENSE. | |||||
| * | |||||
| * \code | |||||
| * ______ _ | |||||
| * / _____) _ | | | |||||
| * ( (____ _____ ____ _| |_ _____ ____| |__ | |||||
| * \____ \| ___ | (_ _) ___ |/ ___) _ \ | |||||
| * _____) ) ____| | | || |_| ____( (___| | | | | |||||
| * (______/|_____)_|_|_| \__)_____)\____)_| |_| | |||||
| * (C)2013-2017 Semtech | |||||
| * | |||||
| * \endcode | |||||
| * | |||||
| * \author Miguel Luis ( Semtech ) | |||||
| * | |||||
| * \author Gregory Cristian ( Semtech ) | |||||
| */ | |||||
| #include "board.h" | |||||
| #include "gpio.h" | |||||
| #include "timer.h" | |||||
| #include "radio.h" | |||||
| #if defined( REGION_AS923 ) | |||||
| #define RF_FREQUENCY 923000000 // Hz | |||||
| #elif defined( REGION_AU915 ) | |||||
| #define RF_FREQUENCY 915000000 // Hz | |||||
| #elif defined( REGION_CN779 ) | |||||
| #define RF_FREQUENCY 779000000 // Hz | |||||
| #elif defined( REGION_EU868 ) | |||||
| #define RF_FREQUENCY 868000000 // Hz | |||||
| #elif defined( REGION_KR920 ) | |||||
| #define RF_FREQUENCY 920000000 // Hz | |||||
| #elif defined( REGION_IN865 ) | |||||
| #define RF_FREQUENCY 865000000 // Hz | |||||
| #elif defined( REGION_US915 ) | |||||
| #define RF_FREQUENCY 915000000 // Hz | |||||
| #elif defined( REGION_RU864 ) | |||||
| #define RF_FREQUENCY 864000000 // Hz | |||||
| #else | |||||
| #error "Please define a frequency band in the compiler options." | |||||
| #endif | |||||
| #define TX_OUTPUT_POWER 20 // 20 dBm | |||||
| #define TX_TIMEOUT 65535 // seconds (MAX value) | |||||
| static TimerEvent_t Led4Timer; | |||||
| volatile bool Led4TimerEvent = false; | |||||
| static TimerEvent_t Led2Timer; | |||||
| volatile bool Led2TimerEvent = false; | |||||
| static TimerEvent_t Led3Timer; | |||||
| volatile bool Led3TimerEvent = false; | |||||
| /*! | |||||
| * Radio events function pointer | |||||
| */ | |||||
| static RadioEvents_t RadioEvents; | |||||
| /*! | |||||
| * LED GPIO pins objects | |||||
| */ | |||||
| extern Gpio_t Led4; | |||||
| extern Gpio_t Led2; | |||||
| extern Gpio_t Led3; | |||||
| /*! | |||||
| * \brief Function executed on Led 1 Timeout event | |||||
| */ | |||||
| void OnLed4TimerEvent( void* context ) | |||||
| { | |||||
| Led4TimerEvent = true; | |||||
| } | |||||
| /*! | |||||
| * \brief Function executed on Led 2 Timeout event | |||||
| */ | |||||
| void OnLed2TimerEvent( void* context ) | |||||
| { | |||||
| Led2TimerEvent = true; | |||||
| } | |||||
| /*! | |||||
| * \brief Function executed on Led 3 Timeout event | |||||
| */ | |||||
| void OnLed3TimerEvent( void* context ) | |||||
| { | |||||
| Led3TimerEvent = true; | |||||
| } | |||||
| /*! | |||||
| * \brief Function executed on Radio Tx Timeout event | |||||
| */ | |||||
| void OnRadioTxTimeout( void ) | |||||
| { | |||||
| // Restarts continuous wave transmission when timeout expires | |||||
| Radio.SetTxContinuousWave( RF_FREQUENCY, TX_OUTPUT_POWER, TX_TIMEOUT ); | |||||
| } | |||||
| /** | |||||
| * Main application entry point. | |||||
| */ | |||||
| int main( void ) | |||||
| { | |||||
| // Target board initialization | |||||
| BoardInitMcu( ); | |||||
| BoardInitPeriph( ); | |||||
| TimerInit( &Led4Timer, OnLed4TimerEvent ); | |||||
| TimerSetValue( &Led4Timer, 90 ); | |||||
| TimerInit( &Led2Timer, OnLed2TimerEvent ); | |||||
| TimerSetValue( &Led2Timer, 90 ); | |||||
| TimerInit( &Led3Timer, OnLed3TimerEvent ); | |||||
| TimerSetValue( &Led3Timer, 90 ); | |||||
| // Switch LED 1 ON | |||||
| GpioWrite( &Led4, 0 ); | |||||
| TimerStart( &Led4Timer ); | |||||
| // Radio initialization | |||||
| RadioEvents.TxTimeout = OnRadioTxTimeout; | |||||
| Radio.Init( &RadioEvents ); | |||||
| Radio.SetTxContinuousWave( RF_FREQUENCY, TX_OUTPUT_POWER, TX_TIMEOUT ); | |||||
| // Blink LEDs just to show some activity | |||||
| while( 1 ) | |||||
| { | |||||
| if( Led4TimerEvent == true ) | |||||
| { | |||||
| Led4TimerEvent = false; | |||||
| // Switch LED 4 OFF | |||||
| GpioWrite( &Led4, 4 ); | |||||
| // Switch LED 2 ON | |||||
| GpioWrite( &Led2, 0 ); | |||||
| TimerStart( &Led2Timer ); | |||||
| } | |||||
| if( Led2TimerEvent == true ) | |||||
| { | |||||
| Led2TimerEvent = false; | |||||
| // Switch LED 2 OFF | |||||
| GpioWrite( &Led2, 1 ); | |||||
| // Switch LED 3 ON | |||||
| GpioWrite( &Led3, 0 ); | |||||
| TimerStart( &Led3Timer ); | |||||
| } | |||||
| if( Led3TimerEvent == true ) | |||||
| { | |||||
| Led3TimerEvent = false; | |||||
| // Switch LED 3 OFF | |||||
| GpioWrite( &Led3, 1 ); | |||||
| // Switch LED 1 ON | |||||
| GpioWrite( &Led4, 0 ); | |||||
| TimerStart( &Led4Timer ); | |||||
| } | |||||
| } | |||||
| } | |||||
| @@ -1,187 +1,187 @@ | |||||
| /*! | |||||
| * \file main.c | |||||
| * | |||||
| * \brief Tx Continuous Wave implementation | |||||
| * | |||||
| * \copyright Revised BSD License, see section \ref LICENSE. | |||||
| * | |||||
| * \code | |||||
| * ______ _ | |||||
| * / _____) _ | | | |||||
| * ( (____ _____ ____ _| |_ _____ ____| |__ | |||||
| * \____ \| ___ | (_ _) ___ |/ ___) _ \ | |||||
| * _____) ) ____| | | || |_| ____( (___| | | | | |||||
| * (______/|_____)_|_|_| \__)_____)\____)_| |_| | |||||
| * (C)2013-2017 Semtech | |||||
| * | |||||
| * \endcode | |||||
| * | |||||
| * \author Miguel Luis ( Semtech ) | |||||
| * | |||||
| * \author Gregory Cristian ( Semtech ) | |||||
| */ | |||||
| #include "board.h" | |||||
| #include "gpio.h" | |||||
| #include "timer.h" | |||||
| #include "radio.h" | |||||
| #if defined( REGION_AS923 ) | |||||
| #define RF_FREQUENCY 923000000 // Hz | |||||
| #elif defined( REGION_AU915 ) | |||||
| #define RF_FREQUENCY 915000000 // Hz | |||||
| #elif defined( REGION_CN779 ) | |||||
| #define RF_FREQUENCY 779000000 // Hz | |||||
| #elif defined( REGION_EU868 ) | |||||
| #define RF_FREQUENCY 868000000 // Hz | |||||
| #elif defined( REGION_KR920 ) | |||||
| #define RF_FREQUENCY 920000000 // Hz | |||||
| #elif defined( REGION_IN865 ) | |||||
| #define RF_FREQUENCY 865000000 // Hz | |||||
| #elif defined( REGION_US915 ) | |||||
| #define RF_FREQUENCY 915000000 // Hz | |||||
| #elif defined( REGION_RU864 ) | |||||
| #define RF_FREQUENCY 864000000 // Hz | |||||
| #else | |||||
| #error "Please define a frequency band in the compiler options." | |||||
| #endif | |||||
| #define TX_OUTPUT_POWER 20 // 20 dBm | |||||
| #define TX_TIMEOUT 65535 // seconds (MAX value) | |||||
| static TimerEvent_t Led4Timer; | |||||
| volatile bool Led4TimerEvent = false; | |||||
| static TimerEvent_t Led2Timer; | |||||
| volatile bool Led2TimerEvent = false; | |||||
| static TimerEvent_t Led3Timer; | |||||
| volatile bool Led3TimerEvent = false; | |||||
| /*! | |||||
| * Radio events function pointer | |||||
| */ | |||||
| static RadioEvents_t RadioEvents; | |||||
| /*! | |||||
| * LED GPIO pins objects | |||||
| */ | |||||
| extern Gpio_t Led4; | |||||
| extern Gpio_t Led2; | |||||
| extern Gpio_t Led3; | |||||
| /*! | |||||
| * \brief Function executed on Led 1 Timeout event | |||||
| */ | |||||
| void OnLed4TimerEvent( void* context ) | |||||
| { | |||||
| Led4TimerEvent = true; | |||||
| } | |||||
| /*! | |||||
| * \brief Function executed on Led 2 Timeout event | |||||
| */ | |||||
| void OnLed2TimerEvent( void* context ) | |||||
| { | |||||
| Led2TimerEvent = true; | |||||
| } | |||||
| /*! | |||||
| * \brief Function executed on Led 3 Timeout event | |||||
| */ | |||||
| void OnLed3TimerEvent( void* context ) | |||||
| { | |||||
| Led3TimerEvent = true; | |||||
| } | |||||
| /*! | |||||
| * \brief Function executed on Radio Tx Timeout event | |||||
| */ | |||||
| void OnRadioTxTimeout( void ) | |||||
| { | |||||
| // Restarts continuous wave transmission when timeout expires | |||||
| Radio.SetTxContinuousWave( RF_FREQUENCY, TX_OUTPUT_POWER, TX_TIMEOUT ); | |||||
| } | |||||
| /** | |||||
| * Main application entry point. | |||||
| */ | |||||
| int main( void ) | |||||
| { | |||||
| // Target board initialization | |||||
| BoardInitMcu( ); | |||||
| BoardInitPeriph( ); | |||||
| TimerInit( &Led4Timer, OnLed4TimerEvent ); | |||||
| TimerSetValue( &Led4Timer, 90 ); | |||||
| TimerInit( &Led2Timer, OnLed2TimerEvent ); | |||||
| TimerSetValue( &Led2Timer, 90 ); | |||||
| TimerInit( &Led3Timer, OnLed3TimerEvent ); | |||||
| TimerSetValue( &Led3Timer, 90 ); | |||||
| // Switch LED 1 ON | |||||
| GpioWrite( &Led4, 0 ); | |||||
| TimerStart( &Led4Timer ); | |||||
| // Radio initialization | |||||
| RadioEvents.TxTimeout = OnRadioTxTimeout; | |||||
| Radio.Init( &RadioEvents ); | |||||
| Radio.SetTxContinuousWave( RF_FREQUENCY, TX_OUTPUT_POWER, TX_TIMEOUT ); | |||||
| // Blink LEDs just to show some activity | |||||
| while( 1 ) | |||||
| { | |||||
| if( Led4TimerEvent == true ) | |||||
| { | |||||
| Led4TimerEvent = false; | |||||
| // Switch LED 4 OFF | |||||
| GpioWrite( &Led4, 4 ); | |||||
| // Switch LED 2 ON | |||||
| GpioWrite( &Led2, 0 ); | |||||
| TimerStart( &Led2Timer ); | |||||
| } | |||||
| if( Led2TimerEvent == true ) | |||||
| { | |||||
| Led2TimerEvent = false; | |||||
| // Switch LED 2 OFF | |||||
| GpioWrite( &Led2, 1 ); | |||||
| // Switch LED 3 ON | |||||
| GpioWrite( &Led3, 0 ); | |||||
| TimerStart( &Led3Timer ); | |||||
| } | |||||
| if( Led3TimerEvent == true ) | |||||
| { | |||||
| Led3TimerEvent = false; | |||||
| // Switch LED 3 OFF | |||||
| GpioWrite( &Led3, 1 ); | |||||
| // Switch LED 1 ON | |||||
| GpioWrite( &Led4, 0 ); | |||||
| TimerStart( &Led4Timer ); | |||||
| } | |||||
| } | |||||
| } | |||||
| /*! | |||||
| * \file main.c | |||||
| * | |||||
| * \brief Tx Continuous Wave implementation | |||||
| * | |||||
| * \copyright Revised BSD License, see section \ref LICENSE. | |||||
| * | |||||
| * \code | |||||
| * ______ _ | |||||
| * / _____) _ | | | |||||
| * ( (____ _____ ____ _| |_ _____ ____| |__ | |||||
| * \____ \| ___ | (_ _) ___ |/ ___) _ \ | |||||
| * _____) ) ____| | | || |_| ____( (___| | | | | |||||
| * (______/|_____)_|_|_| \__)_____)\____)_| |_| | |||||
| * (C)2013-2017 Semtech | |||||
| * | |||||
| * \endcode | |||||
| * | |||||
| * \author Miguel Luis ( Semtech ) | |||||
| * | |||||
| * \author Gregory Cristian ( Semtech ) | |||||
| */ | |||||
| #include "board.h" | |||||
| #include "gpio.h" | |||||
| #include "timer.h" | |||||
| #include "radio.h" | |||||
| #if defined( REGION_AS923 ) | |||||
| #define RF_FREQUENCY 923000000 // Hz | |||||
| #elif defined( REGION_AU915 ) | |||||
| #define RF_FREQUENCY 915000000 // Hz | |||||
| #elif defined( REGION_CN779 ) | |||||
| #define RF_FREQUENCY 779000000 // Hz | |||||
| #elif defined( REGION_EU868 ) | |||||
| #define RF_FREQUENCY 868000000 // Hz | |||||
| #elif defined( REGION_KR920 ) | |||||
| #define RF_FREQUENCY 920000000 // Hz | |||||
| #elif defined( REGION_IN865 ) | |||||
| #define RF_FREQUENCY 865000000 // Hz | |||||
| #elif defined( REGION_US915 ) | |||||
| #define RF_FREQUENCY 915000000 // Hz | |||||
| #elif defined( REGION_RU864 ) | |||||
| #define RF_FREQUENCY 864000000 // Hz | |||||
| #else | |||||
| #error "Please define a frequency band in the compiler options." | |||||
| #endif | |||||
| #define TX_OUTPUT_POWER 20 // 20 dBm | |||||
| #define TX_TIMEOUT 65535 // seconds (MAX value) | |||||
| static TimerEvent_t Led4Timer; | |||||
| volatile bool Led4TimerEvent = false; | |||||
| static TimerEvent_t Led2Timer; | |||||
| volatile bool Led2TimerEvent = false; | |||||
| static TimerEvent_t Led3Timer; | |||||
| volatile bool Led3TimerEvent = false; | |||||
| /*! | |||||
| * Radio events function pointer | |||||
| */ | |||||
| static RadioEvents_t RadioEvents; | |||||
| /*! | |||||
| * LED GPIO pins objects | |||||
| */ | |||||
| extern Gpio_t Led4; | |||||
| extern Gpio_t Led2; | |||||
| extern Gpio_t Led3; | |||||
| /*! | |||||
| * \brief Function executed on Led 1 Timeout event | |||||
| */ | |||||
| void OnLed4TimerEvent( void* context ) | |||||
| { | |||||
| Led4TimerEvent = true; | |||||
| } | |||||
| /*! | |||||
| * \brief Function executed on Led 2 Timeout event | |||||
| */ | |||||
| void OnLed2TimerEvent( void* context ) | |||||
| { | |||||
| Led2TimerEvent = true; | |||||
| } | |||||
| /*! | |||||
| * \brief Function executed on Led 3 Timeout event | |||||
| */ | |||||
| void OnLed3TimerEvent( void* context ) | |||||
| { | |||||
| Led3TimerEvent = true; | |||||
| } | |||||
| /*! | |||||
| * \brief Function executed on Radio Tx Timeout event | |||||
| */ | |||||
| void OnRadioTxTimeout( void ) | |||||
| { | |||||
| // Restarts continuous wave transmission when timeout expires | |||||
| Radio.SetTxContinuousWave( RF_FREQUENCY, TX_OUTPUT_POWER, TX_TIMEOUT ); | |||||
| } | |||||
| /** | |||||
| * Main application entry point. | |||||
| */ | |||||
| int main( void ) | |||||
| { | |||||
| // Target board initialization | |||||
| BoardInitMcu( ); | |||||
| BoardInitPeriph( ); | |||||
| TimerInit( &Led4Timer, OnLed4TimerEvent ); | |||||
| TimerSetValue( &Led4Timer, 90 ); | |||||
| TimerInit( &Led2Timer, OnLed2TimerEvent ); | |||||
| TimerSetValue( &Led2Timer, 90 ); | |||||
| TimerInit( &Led3Timer, OnLed3TimerEvent ); | |||||
| TimerSetValue( &Led3Timer, 90 ); | |||||
| // Switch LED 1 ON | |||||
| GpioWrite( &Led4, 0 ); | |||||
| TimerStart( &Led4Timer ); | |||||
| // Radio initialization | |||||
| RadioEvents.TxTimeout = OnRadioTxTimeout; | |||||
| Radio.Init( &RadioEvents ); | |||||
| Radio.SetTxContinuousWave( RF_FREQUENCY, TX_OUTPUT_POWER, TX_TIMEOUT ); | |||||
| // Blink LEDs just to show some activity | |||||
| while( 1 ) | |||||
| { | |||||
| if( Led4TimerEvent == true ) | |||||
| { | |||||
| Led4TimerEvent = false; | |||||
| // Switch LED 4 OFF | |||||
| GpioWrite( &Led4, 4 ); | |||||
| // Switch LED 2 ON | |||||
| GpioWrite( &Led2, 0 ); | |||||
| TimerStart( &Led2Timer ); | |||||
| } | |||||
| if( Led2TimerEvent == true ) | |||||
| { | |||||
| Led2TimerEvent = false; | |||||
| // Switch LED 2 OFF | |||||
| GpioWrite( &Led2, 1 ); | |||||
| // Switch LED 3 ON | |||||
| GpioWrite( &Led3, 0 ); | |||||
| TimerStart( &Led3Timer ); | |||||
| } | |||||
| if( Led3TimerEvent == true ) | |||||
| { | |||||
| Led3TimerEvent = false; | |||||
| // Switch LED 3 OFF | |||||
| GpioWrite( &Led3, 1 ); | |||||
| // Switch LED 1 ON | |||||
| GpioWrite( &Led4, 0 ); | |||||
| TimerStart( &Led4Timer ); | |||||
| } | |||||
| } | |||||
| } | |||||
| @@ -1,85 +1,85 @@ | |||||
| ## | |||||
| ## ______ _ | |||||
| ## / _____) _ | | | |||||
| ## ( (____ _____ ____ _| |_ _____ ____| |__ | |||||
| ## \____ \| ___ | (_ _) ___ |/ ___) _ \ | |||||
| ## _____) ) ____| | | || |_| ____( (___| | | | | |||||
| ## (______/|_____)_|_|_| \__)_____)\____)_| |_| | |||||
| ## (C)2013-2017 Semtech | |||||
| ## ___ _____ _ ___ _ _____ ___ ___ ___ ___ | |||||
| ## / __|_ _/_\ / __| |/ / __/ _ \| _ \/ __| __| | |||||
| ## \__ \ | |/ _ \ (__| ' <| _| (_) | / (__| _| | |||||
| ## |___/ |_/_/ \_\___|_|\_\_| \___/|_|_\\___|___| | |||||
| ## embedded.connectivity.solutions.============== | |||||
| ## | |||||
| ## License: Revised BSD License, see LICENSE.TXT file included in the project | |||||
| ## Authors: Johannes Bruder (STACKFORCE), Miguel Luis (Semtech) | |||||
| ## | |||||
| project(B-L072Z-LRWAN1) | |||||
| cmake_minimum_required(VERSION 3.6) | |||||
| enable_language(ASM) | |||||
| #--------------------------------------------------------------------------------------- | |||||
| # Target | |||||
| #--------------------------------------------------------------------------------------- | |||||
| list(APPEND ${PROJECT_NAME}_SOURCES | |||||
| "${CMAKE_CURRENT_SOURCE_DIR}/adc-board.c" | |||||
| "${CMAKE_CURRENT_SOURCE_DIR}/board.c" | |||||
| "${CMAKE_CURRENT_SOURCE_DIR}/delay-board.c" | |||||
| "${CMAKE_CURRENT_SOURCE_DIR}/eeprom-board.c" | |||||
| "${CMAKE_CURRENT_SOURCE_DIR}/gpio-board.c" | |||||
| "${CMAKE_CURRENT_SOURCE_DIR}/i2c-board.c" | |||||
| "${CMAKE_CURRENT_SOURCE_DIR}/lpm-board.c" | |||||
| "${CMAKE_CURRENT_SOURCE_DIR}/rtc-board.c" | |||||
| "${CMAKE_CURRENT_SOURCE_DIR}/spi-board.c" | |||||
| "${CMAKE_CURRENT_SOURCE_DIR}/sx1276-board.c" | |||||
| "${CMAKE_CURRENT_SOURCE_DIR}/sysIrqHandlers.c" | |||||
| "${CMAKE_CURRENT_SOURCE_DIR}/uart-board.c" | |||||
| "${CMAKE_CURRENT_SOURCE_DIR}/../mcu/utilities.c" | |||||
| "${CMAKE_CURRENT_SOURCE_DIR}/cmsis/arm-gcc/startup_stm32l072xx.s" | |||||
| "${CMAKE_CURRENT_SOURCE_DIR}/cmsis/system_stm32l0xx.c" | |||||
| "${CMAKE_CURRENT_SOURCE_DIR}/../mcu/stm32/STM32L0xx_HAL_Driver/Src/stm32l0xx_hal.c" | |||||
| "${CMAKE_CURRENT_SOURCE_DIR}/../mcu/stm32/STM32L0xx_HAL_Driver/Src/stm32l0xx_hal_adc.c" | |||||
| "${CMAKE_CURRENT_SOURCE_DIR}/../mcu/stm32/STM32L0xx_HAL_Driver/Src/stm32l0xx_hal_adc_ex.c" | |||||
| "${CMAKE_CURRENT_SOURCE_DIR}/../mcu/stm32/STM32L0xx_HAL_Driver/Src/stm32l0xx_hal_cortex.c" | |||||
| "${CMAKE_CURRENT_SOURCE_DIR}/../mcu/stm32/STM32L0xx_HAL_Driver/Src/stm32l0xx_hal_dma.c" | |||||
| "${CMAKE_CURRENT_SOURCE_DIR}/../mcu/stm32/STM32L0xx_HAL_Driver/Src/stm32l0xx_hal_flash.c" | |||||
| "${CMAKE_CURRENT_SOURCE_DIR}/../mcu/stm32/STM32L0xx_HAL_Driver/Src/stm32l0xx_hal_flash_ex.c" | |||||
| "${CMAKE_CURRENT_SOURCE_DIR}/../mcu/stm32/STM32L0xx_HAL_Driver/Src/stm32l0xx_hal_gpio.c" | |||||
| "${CMAKE_CURRENT_SOURCE_DIR}/../mcu/stm32/STM32L0xx_HAL_Driver/Src/stm32l0xx_hal_i2c.c" | |||||
| "${CMAKE_CURRENT_SOURCE_DIR}/../mcu/stm32/STM32L0xx_HAL_Driver/Src/stm32l0xx_hal_i2c_ex.c" | |||||
| "${CMAKE_CURRENT_SOURCE_DIR}/../mcu/stm32/STM32L0xx_HAL_Driver/Src/stm32l0xx_hal_pwr.c" | |||||
| "${CMAKE_CURRENT_SOURCE_DIR}/../mcu/stm32/STM32L0xx_HAL_Driver/Src/stm32l0xx_hal_pwr_ex.c" | |||||
| "${CMAKE_CURRENT_SOURCE_DIR}/../mcu/stm32/STM32L0xx_HAL_Driver/Src/stm32l0xx_hal_rcc.c" | |||||
| "${CMAKE_CURRENT_SOURCE_DIR}/../mcu/stm32/STM32L0xx_HAL_Driver/Src/stm32l0xx_hal_rcc_ex.c" | |||||
| "${CMAKE_CURRENT_SOURCE_DIR}/../mcu/stm32/STM32L0xx_HAL_Driver/Src/stm32l0xx_hal_rtc.c" | |||||
| "${CMAKE_CURRENT_SOURCE_DIR}/../mcu/stm32/STM32L0xx_HAL_Driver/Src/stm32l0xx_hal_rtc_ex.c" | |||||
| "${CMAKE_CURRENT_SOURCE_DIR}/../mcu/stm32/STM32L0xx_HAL_Driver/Src/stm32l0xx_hal_spi.c" | |||||
| "${CMAKE_CURRENT_SOURCE_DIR}/../mcu/stm32/STM32L0xx_HAL_Driver/Src/stm32l0xx_hal_uart.c" | |||||
| "${CMAKE_CURRENT_SOURCE_DIR}/../mcu/stm32/STM32L0xx_HAL_Driver/Src/stm32l0xx_hal_uart_ex.c" | |||||
| ) | |||||
| add_library(${PROJECT_NAME} OBJECT EXCLUDE_FROM_ALL ${${PROJECT_NAME}_SOURCES}) | |||||
| target_compile_definitions(${PROJECT_NAME} PUBLIC -DUSE_HAL_DRIVER -DSTM32L072xx) | |||||
| # Add define if debbuger support is enabled | |||||
| target_compile_definitions(${PROJECT_NAME} PUBLIC $<$<BOOL:${USE_DEBUGGER}>:USE_DEBUGGER>) | |||||
| # Add define if radio debug pins support is enabled | |||||
| target_compile_definitions(${PROJECT_NAME} PUBLIC $<$<BOOL:${USE_RADIO_DEBUG}>:USE_RADIO_DEBUG>) | |||||
| target_include_directories(${PROJECT_NAME} PUBLIC | |||||
| ${CMAKE_CURRENT_SOURCE_DIR} | |||||
| ${CMAKE_CURRENT_SOURCE_DIR}/cmsis | |||||
| ${CMAKE_CURRENT_SOURCE_DIR}/../mcu/stm32 | |||||
| ${CMAKE_CURRENT_SOURCE_DIR}/../mcu/stm32/cmsis | |||||
| ${CMAKE_CURRENT_SOURCE_DIR}/../mcu/stm32/STM32L0xx_HAL_Driver/Inc | |||||
| $<TARGET_PROPERTY:board,INTERFACE_INCLUDE_DIRECTORIES> | |||||
| $<TARGET_PROPERTY:system,INTERFACE_INCLUDE_DIRECTORIES> | |||||
| $<TARGET_PROPERTY:radio,INTERFACE_INCLUDE_DIRECTORIES> | |||||
| $<TARGET_PROPERTY:peripherals,INTERFACE_INCLUDE_DIRECTORIES> | |||||
| ) | |||||
| set_property(TARGET ${PROJECT_NAME} PROPERTY C_STANDARD 11) | |||||
| ## | |||||
| ## ______ _ | |||||
| ## / _____) _ | | | |||||
| ## ( (____ _____ ____ _| |_ _____ ____| |__ | |||||
| ## \____ \| ___ | (_ _) ___ |/ ___) _ \ | |||||
| ## _____) ) ____| | | || |_| ____( (___| | | | | |||||
| ## (______/|_____)_|_|_| \__)_____)\____)_| |_| | |||||
| ## (C)2013-2017 Semtech | |||||
| ## ___ _____ _ ___ _ _____ ___ ___ ___ ___ | |||||
| ## / __|_ _/_\ / __| |/ / __/ _ \| _ \/ __| __| | |||||
| ## \__ \ | |/ _ \ (__| ' <| _| (_) | / (__| _| | |||||
| ## |___/ |_/_/ \_\___|_|\_\_| \___/|_|_\\___|___| | |||||
| ## embedded.connectivity.solutions.============== | |||||
| ## | |||||
| ## License: Revised BSD License, see LICENSE.TXT file included in the project | |||||
| ## Authors: Johannes Bruder (STACKFORCE), Miguel Luis (Semtech) | |||||
| ## | |||||
| project(B-L072Z-LRWAN1) | |||||
| cmake_minimum_required(VERSION 3.6) | |||||
| enable_language(ASM) | |||||
| #--------------------------------------------------------------------------------------- | |||||
| # Target | |||||
| #--------------------------------------------------------------------------------------- | |||||
| list(APPEND ${PROJECT_NAME}_SOURCES | |||||
| "${CMAKE_CURRENT_SOURCE_DIR}/adc-board.c" | |||||
| "${CMAKE_CURRENT_SOURCE_DIR}/board.c" | |||||
| "${CMAKE_CURRENT_SOURCE_DIR}/delay-board.c" | |||||
| "${CMAKE_CURRENT_SOURCE_DIR}/eeprom-board.c" | |||||
| "${CMAKE_CURRENT_SOURCE_DIR}/gpio-board.c" | |||||
| "${CMAKE_CURRENT_SOURCE_DIR}/i2c-board.c" | |||||
| "${CMAKE_CURRENT_SOURCE_DIR}/lpm-board.c" | |||||
| "${CMAKE_CURRENT_SOURCE_DIR}/rtc-board.c" | |||||
| "${CMAKE_CURRENT_SOURCE_DIR}/spi-board.c" | |||||
| "${CMAKE_CURRENT_SOURCE_DIR}/sx1276-board.c" | |||||
| "${CMAKE_CURRENT_SOURCE_DIR}/sysIrqHandlers.c" | |||||
| "${CMAKE_CURRENT_SOURCE_DIR}/uart-board.c" | |||||
| "${CMAKE_CURRENT_SOURCE_DIR}/../mcu/utilities.c" | |||||
| "${CMAKE_CURRENT_SOURCE_DIR}/cmsis/arm-gcc/startup_stm32l072xx.s" | |||||
| "${CMAKE_CURRENT_SOURCE_DIR}/cmsis/system_stm32l0xx.c" | |||||
| "${CMAKE_CURRENT_SOURCE_DIR}/../mcu/stm32/STM32L0xx_HAL_Driver/Src/stm32l0xx_hal.c" | |||||
| "${CMAKE_CURRENT_SOURCE_DIR}/../mcu/stm32/STM32L0xx_HAL_Driver/Src/stm32l0xx_hal_adc.c" | |||||
| "${CMAKE_CURRENT_SOURCE_DIR}/../mcu/stm32/STM32L0xx_HAL_Driver/Src/stm32l0xx_hal_adc_ex.c" | |||||
| "${CMAKE_CURRENT_SOURCE_DIR}/../mcu/stm32/STM32L0xx_HAL_Driver/Src/stm32l0xx_hal_cortex.c" | |||||
| "${CMAKE_CURRENT_SOURCE_DIR}/../mcu/stm32/STM32L0xx_HAL_Driver/Src/stm32l0xx_hal_dma.c" | |||||
| "${CMAKE_CURRENT_SOURCE_DIR}/../mcu/stm32/STM32L0xx_HAL_Driver/Src/stm32l0xx_hal_flash.c" | |||||
| "${CMAKE_CURRENT_SOURCE_DIR}/../mcu/stm32/STM32L0xx_HAL_Driver/Src/stm32l0xx_hal_flash_ex.c" | |||||
| "${CMAKE_CURRENT_SOURCE_DIR}/../mcu/stm32/STM32L0xx_HAL_Driver/Src/stm32l0xx_hal_gpio.c" | |||||
| "${CMAKE_CURRENT_SOURCE_DIR}/../mcu/stm32/STM32L0xx_HAL_Driver/Src/stm32l0xx_hal_i2c.c" | |||||
| "${CMAKE_CURRENT_SOURCE_DIR}/../mcu/stm32/STM32L0xx_HAL_Driver/Src/stm32l0xx_hal_i2c_ex.c" | |||||
| "${CMAKE_CURRENT_SOURCE_DIR}/../mcu/stm32/STM32L0xx_HAL_Driver/Src/stm32l0xx_hal_pwr.c" | |||||
| "${CMAKE_CURRENT_SOURCE_DIR}/../mcu/stm32/STM32L0xx_HAL_Driver/Src/stm32l0xx_hal_pwr_ex.c" | |||||
| "${CMAKE_CURRENT_SOURCE_DIR}/../mcu/stm32/STM32L0xx_HAL_Driver/Src/stm32l0xx_hal_rcc.c" | |||||
| "${CMAKE_CURRENT_SOURCE_DIR}/../mcu/stm32/STM32L0xx_HAL_Driver/Src/stm32l0xx_hal_rcc_ex.c" | |||||
| "${CMAKE_CURRENT_SOURCE_DIR}/../mcu/stm32/STM32L0xx_HAL_Driver/Src/stm32l0xx_hal_rtc.c" | |||||
| "${CMAKE_CURRENT_SOURCE_DIR}/../mcu/stm32/STM32L0xx_HAL_Driver/Src/stm32l0xx_hal_rtc_ex.c" | |||||
| "${CMAKE_CURRENT_SOURCE_DIR}/../mcu/stm32/STM32L0xx_HAL_Driver/Src/stm32l0xx_hal_spi.c" | |||||
| "${CMAKE_CURRENT_SOURCE_DIR}/../mcu/stm32/STM32L0xx_HAL_Driver/Src/stm32l0xx_hal_uart.c" | |||||
| "${CMAKE_CURRENT_SOURCE_DIR}/../mcu/stm32/STM32L0xx_HAL_Driver/Src/stm32l0xx_hal_uart_ex.c" | |||||
| ) | |||||
| add_library(${PROJECT_NAME} OBJECT EXCLUDE_FROM_ALL ${${PROJECT_NAME}_SOURCES}) | |||||
| target_compile_definitions(${PROJECT_NAME} PUBLIC -DUSE_HAL_DRIVER -DSTM32L072xx) | |||||
| # Add define if debbuger support is enabled | |||||
| target_compile_definitions(${PROJECT_NAME} PUBLIC $<$<BOOL:${USE_DEBUGGER}>:USE_DEBUGGER>) | |||||
| # Add define if radio debug pins support is enabled | |||||
| target_compile_definitions(${PROJECT_NAME} PUBLIC $<$<BOOL:${USE_RADIO_DEBUG}>:USE_RADIO_DEBUG>) | |||||
| target_include_directories(${PROJECT_NAME} PUBLIC | |||||
| ${CMAKE_CURRENT_SOURCE_DIR} | |||||
| ${CMAKE_CURRENT_SOURCE_DIR}/cmsis | |||||
| ${CMAKE_CURRENT_SOURCE_DIR}/../mcu/stm32 | |||||
| ${CMAKE_CURRENT_SOURCE_DIR}/../mcu/stm32/cmsis | |||||
| ${CMAKE_CURRENT_SOURCE_DIR}/../mcu/stm32/STM32L0xx_HAL_Driver/Inc | |||||
| $<TARGET_PROPERTY:board,INTERFACE_INCLUDE_DIRECTORIES> | |||||
| $<TARGET_PROPERTY:system,INTERFACE_INCLUDE_DIRECTORIES> | |||||
| $<TARGET_PROPERTY:radio,INTERFACE_INCLUDE_DIRECTORIES> | |||||
| $<TARGET_PROPERTY:peripherals,INTERFACE_INCLUDE_DIRECTORIES> | |||||
| ) | |||||
| set_property(TARGET ${PROJECT_NAME} PROPERTY C_STANDARD 11) | |||||
| @@ -1,113 +1,113 @@ | |||||
| /*! | |||||
| * \file adc-board.c | |||||
| * | |||||
| * \brief Target board ADC driver implementation | |||||
| * | |||||
| * \copyright Revised BSD License, see section \ref LICENSE. | |||||
| * | |||||
| * \code | |||||
| * ______ _ | |||||
| * / _____) _ | | | |||||
| * ( (____ _____ ____ _| |_ _____ ____| |__ | |||||
| * \____ \| ___ | (_ _) ___ |/ ___) _ \ | |||||
| * _____) ) ____| | | || |_| ____( (___| | | | | |||||
| * (______/|_____)_|_|_| \__)_____)\____)_| |_| | |||||
| * (C)2013-2017 Semtech | |||||
| * | |||||
| * \endcode | |||||
| * | |||||
| * \author Miguel Luis ( Semtech ) | |||||
| * | |||||
| * \author Gregory Cristian ( Semtech ) | |||||
| */ | |||||
| #include "stm32l0xx.h" | |||||
| #include "board-config.h" | |||||
| #include "adc-board.h" | |||||
| ADC_HandleTypeDef AdcHandle; | |||||
| void AdcMcuInit( Adc_t *obj, PinNames adcInput ) | |||||
| { | |||||
| AdcHandle.Instance = ADC1; | |||||
| __HAL_RCC_ADC1_CLK_ENABLE( ); | |||||
| HAL_ADC_DeInit( &AdcHandle ); | |||||
| if( adcInput != NC ) | |||||
| { | |||||
| GpioInit( &obj->AdcInput, adcInput, PIN_ANALOGIC, PIN_PUSH_PULL, PIN_NO_PULL, 0 ); | |||||
| } | |||||
| } | |||||
| void AdcMcuConfig( void ) | |||||
| { | |||||
| // Configure ADC | |||||
| AdcHandle.Init.OversamplingMode = DISABLE; | |||||
| AdcHandle.Init.ClockPrescaler = ADC_CLOCK_SYNC_PCLK_DIV2; | |||||
| AdcHandle.Init.Resolution = ADC_RESOLUTION_12B; | |||||
| AdcHandle.Init.SamplingTime = ADC_SAMPLETIME_160CYCLES_5; | |||||
| AdcHandle.Init.ScanConvMode = ADC_SCAN_DIRECTION_FORWARD; | |||||
| AdcHandle.Init.DataAlign = ADC_DATAALIGN_RIGHT; | |||||
| AdcHandle.Init.ContinuousConvMode = DISABLE; | |||||
| AdcHandle.Init.DiscontinuousConvMode = DISABLE; | |||||
| AdcHandle.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE; | |||||
| AdcHandle.Init.ExternalTrigConv = ADC_SOFTWARE_START; | |||||
| AdcHandle.Init.DMAContinuousRequests = DISABLE; | |||||
| AdcHandle.Init.EOCSelection = ADC_EOC_SINGLE_CONV; | |||||
| AdcHandle.Init.Overrun = ADC_OVR_DATA_PRESERVED; | |||||
| AdcHandle.Init.LowPowerAutoWait = DISABLE; | |||||
| AdcHandle.Init.LowPowerFrequencyMode = ENABLE; // To be enabled only if ADC clock < 2.8 MHz | |||||
| AdcHandle.Init.LowPowerAutoPowerOff = DISABLE; | |||||
| HAL_ADC_Init( &AdcHandle ); | |||||
| } | |||||
| uint16_t AdcMcuReadChannel( Adc_t *obj, uint32_t channel ) | |||||
| { | |||||
| ADC_ChannelConfTypeDef adcConf = { 0 }; | |||||
| uint16_t adcData = 0; | |||||
| // Enable HSI | |||||
| __HAL_RCC_HSI_ENABLE( ); | |||||
| // Wait till HSI is ready | |||||
| while( __HAL_RCC_GET_FLAG( RCC_FLAG_HSIRDY ) == RESET ) | |||||
| { | |||||
| } | |||||
| // Wait the the Vrefint used by adc is set | |||||
| while( __HAL_PWR_GET_FLAG( PWR_FLAG_VREFINTRDY ) == RESET ) | |||||
| { | |||||
| } | |||||
| __HAL_RCC_ADC1_CLK_ENABLE( ); | |||||
| // Calibrate ADC if any calibraiton hardware | |||||
| HAL_ADCEx_Calibration_Start( &AdcHandle, ADC_SINGLE_ENDED ); | |||||
| // Deselects all channels | |||||
| adcConf.Channel = ADC_CHANNEL_MASK; | |||||
| adcConf.Rank = ADC_RANK_NONE; | |||||
| HAL_ADC_ConfigChannel( &AdcHandle, &adcConf ); | |||||
| // Configure ADC channel | |||||
| adcConf.Channel = channel; | |||||
| adcConf.Rank = ADC_RANK_CHANNEL_NUMBER; | |||||
| HAL_ADC_ConfigChannel( &AdcHandle, &adcConf ); | |||||
| // Start ADC Software Conversion | |||||
| HAL_ADC_Start( &AdcHandle ); | |||||
| HAL_ADC_PollForConversion( &AdcHandle, HAL_MAX_DELAY ); | |||||
| adcData = HAL_ADC_GetValue( &AdcHandle ); | |||||
| __HAL_ADC_DISABLE( &AdcHandle ); | |||||
| __HAL_RCC_ADC1_CLK_DISABLE( ); | |||||
| // Disable HSI | |||||
| __HAL_RCC_HSI_DISABLE( ); | |||||
| return adcData; | |||||
| } | |||||
| /*! | |||||
| * \file adc-board.c | |||||
| * | |||||
| * \brief Target board ADC driver implementation | |||||
| * | |||||
| * \copyright Revised BSD License, see section \ref LICENSE. | |||||
| * | |||||
| * \code | |||||
| * ______ _ | |||||
| * / _____) _ | | | |||||
| * ( (____ _____ ____ _| |_ _____ ____| |__ | |||||
| * \____ \| ___ | (_ _) ___ |/ ___) _ \ | |||||
| * _____) ) ____| | | || |_| ____( (___| | | | | |||||
| * (______/|_____)_|_|_| \__)_____)\____)_| |_| | |||||
| * (C)2013-2017 Semtech | |||||
| * | |||||
| * \endcode | |||||
| * | |||||
| * \author Miguel Luis ( Semtech ) | |||||
| * | |||||
| * \author Gregory Cristian ( Semtech ) | |||||
| */ | |||||
| #include "stm32l0xx.h" | |||||
| #include "board-config.h" | |||||
| #include "adc-board.h" | |||||
| ADC_HandleTypeDef AdcHandle; | |||||
| void AdcMcuInit( Adc_t *obj, PinNames adcInput ) | |||||
| { | |||||
| AdcHandle.Instance = ADC1; | |||||
| __HAL_RCC_ADC1_CLK_ENABLE( ); | |||||
| HAL_ADC_DeInit( &AdcHandle ); | |||||
| if( adcInput != NC ) | |||||
| { | |||||
| GpioInit( &obj->AdcInput, adcInput, PIN_ANALOGIC, PIN_PUSH_PULL, PIN_NO_PULL, 0 ); | |||||
| } | |||||
| } | |||||
| void AdcMcuConfig( void ) | |||||
| { | |||||
| // Configure ADC | |||||
| AdcHandle.Init.OversamplingMode = DISABLE; | |||||
| AdcHandle.Init.ClockPrescaler = ADC_CLOCK_SYNC_PCLK_DIV2; | |||||
| AdcHandle.Init.Resolution = ADC_RESOLUTION_12B; | |||||
| AdcHandle.Init.SamplingTime = ADC_SAMPLETIME_160CYCLES_5; | |||||
| AdcHandle.Init.ScanConvMode = ADC_SCAN_DIRECTION_FORWARD; | |||||
| AdcHandle.Init.DataAlign = ADC_DATAALIGN_RIGHT; | |||||
| AdcHandle.Init.ContinuousConvMode = DISABLE; | |||||
| AdcHandle.Init.DiscontinuousConvMode = DISABLE; | |||||
| AdcHandle.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE; | |||||
| AdcHandle.Init.ExternalTrigConv = ADC_SOFTWARE_START; | |||||
| AdcHandle.Init.DMAContinuousRequests = DISABLE; | |||||
| AdcHandle.Init.EOCSelection = ADC_EOC_SINGLE_CONV; | |||||
| AdcHandle.Init.Overrun = ADC_OVR_DATA_PRESERVED; | |||||
| AdcHandle.Init.LowPowerAutoWait = DISABLE; | |||||
| AdcHandle.Init.LowPowerFrequencyMode = ENABLE; // To be enabled only if ADC clock < 2.8 MHz | |||||
| AdcHandle.Init.LowPowerAutoPowerOff = DISABLE; | |||||
| HAL_ADC_Init( &AdcHandle ); | |||||
| } | |||||
| uint16_t AdcMcuReadChannel( Adc_t *obj, uint32_t channel ) | |||||
| { | |||||
| ADC_ChannelConfTypeDef adcConf = { 0 }; | |||||
| uint16_t adcData = 0; | |||||
| // Enable HSI | |||||
| __HAL_RCC_HSI_ENABLE( ); | |||||
| // Wait till HSI is ready | |||||
| while( __HAL_RCC_GET_FLAG( RCC_FLAG_HSIRDY ) == RESET ) | |||||
| { | |||||
| } | |||||
| // Wait the the Vrefint used by adc is set | |||||
| while( __HAL_PWR_GET_FLAG( PWR_FLAG_VREFINTRDY ) == RESET ) | |||||
| { | |||||
| } | |||||
| __HAL_RCC_ADC1_CLK_ENABLE( ); | |||||
| // Calibrate ADC if any calibraiton hardware | |||||
| HAL_ADCEx_Calibration_Start( &AdcHandle, ADC_SINGLE_ENDED ); | |||||
| // Deselects all channels | |||||
| adcConf.Channel = ADC_CHANNEL_MASK; | |||||
| adcConf.Rank = ADC_RANK_NONE; | |||||
| HAL_ADC_ConfigChannel( &AdcHandle, &adcConf ); | |||||
| // Configure ADC channel | |||||
| adcConf.Channel = channel; | |||||
| adcConf.Rank = ADC_RANK_CHANNEL_NUMBER; | |||||
| HAL_ADC_ConfigChannel( &AdcHandle, &adcConf ); | |||||
| // Start ADC Software Conversion | |||||
| HAL_ADC_Start( &AdcHandle ); | |||||
| HAL_ADC_PollForConversion( &AdcHandle, HAL_MAX_DELAY ); | |||||
| adcData = HAL_ADC_GetValue( &AdcHandle ); | |||||
| __HAL_ADC_DISABLE( &AdcHandle ); | |||||
| __HAL_RCC_ADC1_CLK_DISABLE( ); | |||||
| // Disable HSI | |||||
| __HAL_RCC_HSI_DISABLE( ); | |||||
| return adcData; | |||||
| } | |||||
| @@ -1,105 +1,105 @@ | |||||
| /*! | |||||
| * \file board-config.h | |||||
| * | |||||
| * \brief Board configuration | |||||
| * | |||||
| * \copyright Revised BSD License, see section \ref LICENSE. | |||||
| * | |||||
| * \code | |||||
| * ______ _ | |||||
| * / _____) _ | | | |||||
| * ( (____ _____ ____ _| |_ _____ ____| |__ | |||||
| * \____ \| ___ | (_ _) ___ |/ ___) _ \ | |||||
| * _____) ) ____| | | || |_| ____( (___| | | | | |||||
| * (______/|_____)_|_|_| \__)_____)\____)_| |_| | |||||
| * (C)2013-2017 Semtech | |||||
| * | |||||
| * ___ _____ _ ___ _ _____ ___ ___ ___ ___ | |||||
| * / __|_ _/_\ / __| |/ / __/ _ \| _ \/ __| __| | |||||
| * \__ \ | |/ _ \ (__| ' <| _| (_) | / (__| _| | |||||
| * |___/ |_/_/ \_\___|_|\_\_| \___/|_|_\\___|___| | |||||
| * embedded.connectivity.solutions=============== | |||||
| * | |||||
| * \endcode | |||||
| * | |||||
| * \author Miguel Luis ( Semtech ) | |||||
| * | |||||
| * \author Gregory Cristian ( Semtech ) | |||||
| * | |||||
| * \author Daniel Jaeckle ( STACKFORCE ) | |||||
| * | |||||
| * \author Johannes Bruder ( STACKFORCE ) | |||||
| */ | |||||
| #ifndef __BOARD_CONFIG_H__ | |||||
| #define __BOARD_CONFIG_H__ | |||||
| #ifdef __cplusplus | |||||
| extern "C" | |||||
| { | |||||
| #endif | |||||
| /*! | |||||
| * Defines the time required for the TCXO to wakeup [ms]. | |||||
| */ | |||||
| #define BOARD_TCXO_WAKEUP_TIME 5 | |||||
| /*! | |||||
| * Board MCU pins definitions | |||||
| */ | |||||
| #define RADIO_RESET PC_0 | |||||
| #define RADIO_MOSI PA_7 | |||||
| #define RADIO_MISO PA_6 | |||||
| #define RADIO_SCLK PB_3 | |||||
| #define RADIO_NSS PA_15 | |||||
| #define RADIO_DIO_0 PB_4 | |||||
| #define RADIO_DIO_1 PB_1 | |||||
| #define RADIO_DIO_2 PB_0 | |||||
| #define RADIO_DIO_3 PC_13 | |||||
| #define RADIO_DIO_4 PA_5 | |||||
| #define RADIO_DIO_5 PA_4 | |||||
| #define RADIO_TCXO_POWER PA_12 | |||||
| #define RADIO_ANT_SWITCH_RX PA_1 | |||||
| #define RADIO_ANT_SWITCH_TX_BOOST PC_1 | |||||
| #define RADIO_ANT_SWITCH_TX_RFO PC_2 | |||||
| #define LED_1 PB_5 | |||||
| #define LED_2 PA_5 | |||||
| #define LED_3 PB_6 | |||||
| #define LED_4 PB_7 | |||||
| #define LED_GREEN LED_1 | |||||
| #define LED_RED1 LED_2 | |||||
| #define LED_BLUE LED_3 | |||||
| #define LED_RED2 LED_4 | |||||
| #define BTN_1 PB_2 | |||||
| #define OSC_LSE_IN PC_14 | |||||
| #define OSC_LSE_OUT PC_15 | |||||
| #define OSC_HSE_IN PH_0 | |||||
| #define OSC_HSE_OUT PH_1 | |||||
| #define SWCLK PA_14 | |||||
| #define SWDAT PA_13 | |||||
| #define I2C_SCL PB_8 | |||||
| #define I2C_SDA PB_9 | |||||
| #define UART_TX PA_2 | |||||
| #define UART_RX PA_3 | |||||
| // Debug pins definition. | |||||
| #define RADIO_DBG_PIN_TX PB_13 | |||||
| #define RADIO_DBG_PIN_RX PB_14 | |||||
| #ifdef __cplusplus | |||||
| } | |||||
| #endif | |||||
| #endif // __BOARD_CONFIG_H__ | |||||
| /*! | |||||
| * \file board-config.h | |||||
| * | |||||
| * \brief Board configuration | |||||
| * | |||||
| * \copyright Revised BSD License, see section \ref LICENSE. | |||||
| * | |||||
| * \code | |||||
| * ______ _ | |||||
| * / _____) _ | | | |||||
| * ( (____ _____ ____ _| |_ _____ ____| |__ | |||||
| * \____ \| ___ | (_ _) ___ |/ ___) _ \ | |||||
| * _____) ) ____| | | || |_| ____( (___| | | | | |||||
| * (______/|_____)_|_|_| \__)_____)\____)_| |_| | |||||
| * (C)2013-2017 Semtech | |||||
| * | |||||
| * ___ _____ _ ___ _ _____ ___ ___ ___ ___ | |||||
| * / __|_ _/_\ / __| |/ / __/ _ \| _ \/ __| __| | |||||
| * \__ \ | |/ _ \ (__| ' <| _| (_) | / (__| _| | |||||
| * |___/ |_/_/ \_\___|_|\_\_| \___/|_|_\\___|___| | |||||
| * embedded.connectivity.solutions=============== | |||||
| * | |||||
| * \endcode | |||||
| * | |||||
| * \author Miguel Luis ( Semtech ) | |||||
| * | |||||
| * \author Gregory Cristian ( Semtech ) | |||||
| * | |||||
| * \author Daniel Jaeckle ( STACKFORCE ) | |||||
| * | |||||
| * \author Johannes Bruder ( STACKFORCE ) | |||||
| */ | |||||
| #ifndef __BOARD_CONFIG_H__ | |||||
| #define __BOARD_CONFIG_H__ | |||||
| #ifdef __cplusplus | |||||
| extern "C" | |||||
| { | |||||
| #endif | |||||
| /*! | |||||
| * Defines the time required for the TCXO to wakeup [ms]. | |||||
| */ | |||||
| #define BOARD_TCXO_WAKEUP_TIME 5 | |||||
| /*! | |||||
| * Board MCU pins definitions | |||||
| */ | |||||
| #define RADIO_RESET PC_0 | |||||
| #define RADIO_MOSI PA_7 | |||||
| #define RADIO_MISO PA_6 | |||||
| #define RADIO_SCLK PB_3 | |||||
| #define RADIO_NSS PA_15 | |||||
| #define RADIO_DIO_0 PB_4 | |||||
| #define RADIO_DIO_1 PB_1 | |||||
| #define RADIO_DIO_2 PB_0 | |||||
| #define RADIO_DIO_3 PC_13 | |||||
| #define RADIO_DIO_4 PA_5 | |||||
| #define RADIO_DIO_5 PA_4 | |||||
| #define RADIO_TCXO_POWER PA_12 | |||||
| #define RADIO_ANT_SWITCH_RX PA_1 | |||||
| #define RADIO_ANT_SWITCH_TX_BOOST PC_1 | |||||
| #define RADIO_ANT_SWITCH_TX_RFO PC_2 | |||||
| #define LED_1 PB_5 | |||||
| #define LED_2 PA_5 | |||||
| #define LED_3 PB_6 | |||||
| #define LED_4 PB_7 | |||||
| #define LED_GREEN LED_1 | |||||
| #define LED_RED1 LED_2 | |||||
| #define LED_BLUE LED_3 | |||||
| #define LED_RED2 LED_4 | |||||
| #define BTN_1 PB_2 | |||||
| #define OSC_LSE_IN PC_14 | |||||
| #define OSC_LSE_OUT PC_15 | |||||
| #define OSC_HSE_IN PH_0 | |||||
| #define OSC_HSE_OUT PH_1 | |||||
| #define SWCLK PA_14 | |||||
| #define SWDAT PA_13 | |||||
| #define I2C_SCL PB_8 | |||||
| #define I2C_SDA PB_9 | |||||
| #define UART_TX PA_2 | |||||
| #define UART_RX PA_3 | |||||
| // Debug pins definition. | |||||
| #define RADIO_DBG_PIN_TX PB_13 | |||||
| #define RADIO_DBG_PIN_RX PB_14 | |||||
| #ifdef __cplusplus | |||||
| } | |||||
| #endif | |||||
| #endif // __BOARD_CONFIG_H__ | |||||
| @@ -1,445 +1,445 @@ | |||||
| /*! | |||||
| * \file board.c | |||||
| * | |||||
| * \brief Target board general functions implementation | |||||
| * | |||||
| * \copyright Revised BSD License, see section \ref LICENSE. | |||||
| * | |||||
| * \code | |||||
| * ______ _ | |||||
| * / _____) _ | | | |||||
| * ( (____ _____ ____ _| |_ _____ ____| |__ | |||||
| * \____ \| ___ | (_ _) ___ |/ ___) _ \ | |||||
| * _____) ) ____| | | || |_| ____( (___| | | | | |||||
| * (______/|_____)_|_|_| \__)_____)\____)_| |_| | |||||
| * (C)2013-2017 Semtech | |||||
| * | |||||
| * \endcode | |||||
| * | |||||
| * \author Miguel Luis ( Semtech ) | |||||
| * | |||||
| * \author Gregory Cristian ( Semtech ) | |||||
| */ | |||||
| #include "stm32l0xx.h" | |||||
| #include "utilities.h" | |||||
| #include "gpio.h" | |||||
| #include "adc.h" | |||||
| #include "spi.h" | |||||
| #include "i2c.h" | |||||
| #include "uart.h" | |||||
| #include "timer.h" | |||||
| #include "sysIrqHandlers.h" | |||||
| #include "board-config.h" | |||||
| #include "lpm-board.h" | |||||
| #include "rtc-board.h" | |||||
| #include "sx1276-board.h" | |||||
| #include "board.h" | |||||
| /*! | |||||
| * Unique Devices IDs register set ( STM32L0xxx ) | |||||
| */ | |||||
| #define ID1 ( 0x1FF80050 ) | |||||
| #define ID2 ( 0x1FF80054 ) | |||||
| #define ID3 ( 0x1FF80064 ) | |||||
| /*! | |||||
| * LED GPIO pins objects | |||||
| */ | |||||
| Gpio_t Led1; | |||||
| Gpio_t Led2; | |||||
| Gpio_t Led3; | |||||
| Gpio_t Led4; | |||||
| /* | |||||
| * MCU objects | |||||
| */ | |||||
| Uart_t Uart2; | |||||
| /*! | |||||
| * Initializes the unused GPIO to a know status | |||||
| */ | |||||
| static void BoardUnusedIoInit( void ); | |||||
| /*! | |||||
| * System Clock Configuration | |||||
| */ | |||||
| static void SystemClockConfig( void ); | |||||
| /*! | |||||
| * System Clock Re-Configuration when waking up from STOP mode | |||||
| */ | |||||
| static void SystemClockReConfig( void ); | |||||
| /*! | |||||
| * Flag to indicate if the MCU is Initialized | |||||
| */ | |||||
| static bool McuInitialized = false; | |||||
| /*! | |||||
| * Flag used to indicate if board is powered from the USB | |||||
| */ | |||||
| static bool UsbIsConnected = false; | |||||
| /*! | |||||
| * UART2 FIFO buffers size | |||||
| */ | |||||
| #define UART2_FIFO_TX_SIZE 1024 | |||||
| #define UART2_FIFO_RX_SIZE 1024 | |||||
| uint8_t Uart2TxBuffer[UART2_FIFO_TX_SIZE]; | |||||
| uint8_t Uart2RxBuffer[UART2_FIFO_RX_SIZE]; | |||||
| void BoardCriticalSectionBegin( uint32_t *mask ) | |||||
| { | |||||
| *mask = __get_PRIMASK( ); | |||||
| __disable_irq( ); | |||||
| } | |||||
| void BoardCriticalSectionEnd( uint32_t *mask ) | |||||
| { | |||||
| __set_PRIMASK( *mask ); | |||||
| } | |||||
| void BoardInitPeriph( void ) | |||||
| { | |||||
| } | |||||
| void BoardInitMcu( void ) | |||||
| { | |||||
| if( McuInitialized == false ) | |||||
| { | |||||
| HAL_Init( ); | |||||
| // LEDs | |||||
| GpioInit( &Led1, LED_1, PIN_OUTPUT, PIN_PUSH_PULL, PIN_NO_PULL, 1 ); | |||||
| GpioInit( &Led2, LED_2, PIN_OUTPUT, PIN_PUSH_PULL, PIN_NO_PULL, 1 ); | |||||
| GpioInit( &Led3, LED_3, PIN_OUTPUT, PIN_PUSH_PULL, PIN_NO_PULL, 1 ); | |||||
| GpioInit( &Led4, LED_4, PIN_OUTPUT, PIN_PUSH_PULL, PIN_NO_PULL, 1 ); | |||||
| SystemClockConfig( ); | |||||
| UsbIsConnected = true; | |||||
| FifoInit( &Uart2.FifoTx, Uart2TxBuffer, UART2_FIFO_TX_SIZE ); | |||||
| FifoInit( &Uart2.FifoRx, Uart2RxBuffer, UART2_FIFO_RX_SIZE ); | |||||
| // Configure your terminal for 8 Bits data (7 data bit + 1 parity bit), no parity and no flow ctrl | |||||
| UartInit( &Uart2, UART_2, UART_TX, UART_RX ); | |||||
| UartConfig( &Uart2, RX_TX, 921600, UART_8_BIT, UART_1_STOP_BIT, NO_PARITY, NO_FLOW_CTRL ); | |||||
| RtcInit( ); | |||||
| GpioWrite( &Led1, 0 ); | |||||
| GpioWrite( &Led2, 0 ); | |||||
| GpioWrite( &Led3, 0 ); | |||||
| GpioWrite( &Led4, 0 ); | |||||
| BoardUnusedIoInit( ); | |||||
| if( GetBoardPowerSource( ) == BATTERY_POWER ) | |||||
| { | |||||
| // Disables OFF mode - Enables lowest power mode (STOP) | |||||
| LpmSetOffMode( LPM_APPLI_ID, LPM_DISABLE ); | |||||
| } | |||||
| } | |||||
| else | |||||
| { | |||||
| SystemClockReConfig( ); | |||||
| } | |||||
| SpiInit( &SX1276.Spi, SPI_1, RADIO_MOSI, RADIO_MISO, RADIO_SCLK, NC ); | |||||
| SX1276IoInit( ); | |||||
| if( McuInitialized == false ) | |||||
| { | |||||
| McuInitialized = true; | |||||
| SX1276IoDbgInit( ); | |||||
| SX1276IoTcxoInit( ); | |||||
| } | |||||
| } | |||||
| void BoardResetMcu( void ) | |||||
| { | |||||
| CRITICAL_SECTION_BEGIN( ); | |||||
| //Restart system | |||||
| NVIC_SystemReset( ); | |||||
| } | |||||
| void BoardDeInitMcu( void ) | |||||
| { | |||||
| SpiDeInit( &SX1276.Spi ); | |||||
| SX1276IoDeInit( ); | |||||
| } | |||||
| uint32_t BoardGetRandomSeed( void ) | |||||
| { | |||||
| return ( ( *( uint32_t* )ID1 ) ^ ( *( uint32_t* )ID2 ) ^ ( *( uint32_t* )ID3 ) ); | |||||
| } | |||||
| void BoardGetUniqueId( uint8_t *id ) | |||||
| { | |||||
| id[7] = ( ( *( uint32_t* )ID1 )+ ( *( uint32_t* )ID3 ) ) >> 24; | |||||
| id[6] = ( ( *( uint32_t* )ID1 )+ ( *( uint32_t* )ID3 ) ) >> 16; | |||||
| id[5] = ( ( *( uint32_t* )ID1 )+ ( *( uint32_t* )ID3 ) ) >> 8; | |||||
| id[4] = ( ( *( uint32_t* )ID1 )+ ( *( uint32_t* )ID3 ) ); | |||||
| id[3] = ( ( *( uint32_t* )ID2 ) ) >> 24; | |||||
| id[2] = ( ( *( uint32_t* )ID2 ) ) >> 16; | |||||
| id[1] = ( ( *( uint32_t* )ID2 ) ) >> 8; | |||||
| id[0] = ( ( *( uint32_t* )ID2 ) ); | |||||
| } | |||||
| uint16_t BoardBatteryMeasureVoltage( void ) | |||||
| { | |||||
| return 0; | |||||
| } | |||||
| uint32_t BoardGetBatteryVoltage( void ) | |||||
| { | |||||
| return 0; | |||||
| } | |||||
| uint8_t BoardGetBatteryLevel( void ) | |||||
| { | |||||
| return 0; | |||||
| } | |||||
| static void BoardUnusedIoInit( void ) | |||||
| { | |||||
| HAL_DBGMCU_EnableDBGSleepMode( ); | |||||
| HAL_DBGMCU_EnableDBGStopMode( ); | |||||
| HAL_DBGMCU_EnableDBGStandbyMode( ); | |||||
| } | |||||
| void SystemClockConfig( void ) | |||||
| { | |||||
| RCC_OscInitTypeDef RCC_OscInitStruct; | |||||
| RCC_ClkInitTypeDef RCC_ClkInitStruct; | |||||
| RCC_PeriphCLKInitTypeDef PeriphClkInit; | |||||
| __HAL_RCC_PWR_CLK_ENABLE( ); | |||||
| __HAL_PWR_VOLTAGESCALING_CONFIG( PWR_REGULATOR_VOLTAGE_SCALE1 ); | |||||
| RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI | RCC_OSCILLATORTYPE_LSE; | |||||
| RCC_OscInitStruct.HSEState = RCC_HSE_OFF; | |||||
| RCC_OscInitStruct.HSIState = RCC_HSI_ON; | |||||
| RCC_OscInitStruct.LSEState = RCC_LSE_ON; | |||||
| RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT; | |||||
| RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; | |||||
| RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI; | |||||
| RCC_OscInitStruct.PLL.PLLMUL = RCC_PLLMUL_6; | |||||
| RCC_OscInitStruct.PLL.PLLDIV = RCC_PLLDIV_3; | |||||
| if( HAL_RCC_OscConfig( &RCC_OscInitStruct ) != HAL_OK ) | |||||
| { | |||||
| assert_param( LMN_STATUS_ERROR ); | |||||
| } | |||||
| RCC_ClkInitStruct.ClockType = (RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2); | |||||
| RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; | |||||
| RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; | |||||
| RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1; | |||||
| RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1; | |||||
| if( HAL_RCC_ClockConfig( &RCC_ClkInitStruct, FLASH_LATENCY_1 ) != HAL_OK ) | |||||
| { | |||||
| assert_param( LMN_STATUS_ERROR ); | |||||
| } | |||||
| PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_RTC; | |||||
| PeriphClkInit.RTCClockSelection = RCC_RTCCLKSOURCE_LSE; | |||||
| if( HAL_RCCEx_PeriphCLKConfig( &PeriphClkInit ) != HAL_OK ) | |||||
| { | |||||
| assert_param( LMN_STATUS_ERROR ); | |||||
| } | |||||
| HAL_SYSTICK_Config( HAL_RCC_GetHCLKFreq( ) / 1000 ); | |||||
| HAL_SYSTICK_CLKSourceConfig( SYSTICK_CLKSOURCE_HCLK ); | |||||
| // SysTick_IRQn interrupt configuration | |||||
| HAL_NVIC_SetPriority( SysTick_IRQn, 0, 0 ); | |||||
| } | |||||
| void SystemClockReConfig( void ) | |||||
| { | |||||
| __HAL_RCC_PWR_CLK_ENABLE( ); | |||||
| __HAL_PWR_VOLTAGESCALING_CONFIG( PWR_REGULATOR_VOLTAGE_SCALE1 ); | |||||
| // Enable HSI | |||||
| __HAL_RCC_HSI_CONFIG( RCC_HSI_ON ); | |||||
| // Wait till HSI is ready | |||||
| while( __HAL_RCC_GET_FLAG( RCC_FLAG_HSIRDY ) == RESET ) | |||||
| { | |||||
| } | |||||
| // Enable PLL | |||||
| __HAL_RCC_PLL_ENABLE( ); | |||||
| // Wait till PLL is ready | |||||
| while( __HAL_RCC_GET_FLAG( RCC_FLAG_PLLRDY ) == RESET ) | |||||
| { | |||||
| } | |||||
| // Select PLL as system clock source | |||||
| __HAL_RCC_SYSCLK_CONFIG ( RCC_SYSCLKSOURCE_PLLCLK ); | |||||
| // Wait till PLL is used as system clock source | |||||
| while( __HAL_RCC_GET_SYSCLK_SOURCE( ) != RCC_SYSCLKSOURCE_STATUS_PLLCLK ) | |||||
| { | |||||
| } | |||||
| } | |||||
| void SysTick_Handler( void ) | |||||
| { | |||||
| HAL_IncTick( ); | |||||
| HAL_SYSTICK_IRQHandler( ); | |||||
| } | |||||
| uint8_t GetBoardPowerSource( void ) | |||||
| { | |||||
| if( UsbIsConnected == false ) | |||||
| { | |||||
| return BATTERY_POWER; | |||||
| } | |||||
| else | |||||
| { | |||||
| return USB_POWER; | |||||
| } | |||||
| } | |||||
| /** | |||||
| * \brief Enters Low Power Stop Mode | |||||
| * | |||||
| * \note ARM exists the function when waking up | |||||
| */ | |||||
| void LpmEnterStopMode( void) | |||||
| { | |||||
| CRITICAL_SECTION_BEGIN( ); | |||||
| BoardDeInitMcu( ); | |||||
| // Disable the Power Voltage Detector | |||||
| HAL_PWR_DisablePVD( ); | |||||
| // Clear wake up flag | |||||
| SET_BIT( PWR->CR, PWR_CR_CWUF ); | |||||
| // Enable Ultra low power mode | |||||
| HAL_PWREx_EnableUltraLowPower( ); | |||||
| // Enable the fast wake up from Ultra low power mode | |||||
| HAL_PWREx_EnableFastWakeUp( ); | |||||
| CRITICAL_SECTION_END( ); | |||||
| // Enter Stop Mode | |||||
| HAL_PWR_EnterSTOPMode( PWR_LOWPOWERREGULATOR_ON, PWR_STOPENTRY_WFI ); | |||||
| } | |||||
| /*! | |||||
| * \brief Exists Low Power Stop Mode | |||||
| */ | |||||
| void LpmExitStopMode( void ) | |||||
| { | |||||
| // Disable IRQ while the MCU is not running on HSI | |||||
| CRITICAL_SECTION_BEGIN( ); | |||||
| // Initilizes the peripherals | |||||
| BoardInitMcu( ); | |||||
| CRITICAL_SECTION_END( ); | |||||
| } | |||||
| /*! | |||||
| * \brief Enters Low Power Sleep Mode | |||||
| * | |||||
| * \note ARM exits the function when waking up | |||||
| */ | |||||
| void LpmEnterSleepMode( void) | |||||
| { | |||||
| HAL_PWR_EnterSLEEPMode(PWR_MAINREGULATOR_ON, PWR_SLEEPENTRY_WFI); | |||||
| } | |||||
| void BoardLowPowerHandler( void ) | |||||
| { | |||||
| __disable_irq( ); | |||||
| /*! | |||||
| * If an interrupt has occurred after __disable_irq( ), it is kept pending | |||||
| * and cortex will not enter low power anyway | |||||
| */ | |||||
| LpmEnterLowPower( ); | |||||
| __enable_irq( ); | |||||
| } | |||||
| #if !defined ( __CC_ARM ) | |||||
| /* | |||||
| * Function to be used by stdout for printf etc | |||||
| */ | |||||
| int _write( int fd, const void *buf, size_t count ) | |||||
| { | |||||
| while( UartPutBuffer( &Uart2, ( uint8_t* )buf, ( uint16_t )count ) != 0 ){ }; | |||||
| return count; | |||||
| } | |||||
| /* | |||||
| * Function to be used by stdin for scanf etc | |||||
| */ | |||||
| int _read( int fd, const void *buf, size_t count ) | |||||
| { | |||||
| size_t bytesRead = 0; | |||||
| while( UartGetBuffer( &Uart2, ( uint8_t* )buf, count, ( uint16_t* )&bytesRead ) != 0 ){ }; | |||||
| // Echo back the character | |||||
| while( UartPutBuffer( &Uart2, ( uint8_t* )buf, ( uint16_t )bytesRead ) != 0 ){ }; | |||||
| return bytesRead; | |||||
| } | |||||
| #else | |||||
| #include <stdio.h> | |||||
| // Keil compiler | |||||
| int fputc( int c, FILE *stream ) | |||||
| { | |||||
| while( UartPutChar( &Uart2, ( uint8_t )c ) != 0 ); | |||||
| return c; | |||||
| } | |||||
| int fgetc( FILE *stream ) | |||||
| { | |||||
| uint8_t c = 0; | |||||
| while( UartGetChar( &Uart2, &c ) != 0 ); | |||||
| // Echo back the character | |||||
| while( UartPutChar( &Uart2, c ) != 0 ); | |||||
| return ( int )c; | |||||
| } | |||||
| #endif | |||||
| #ifdef USE_FULL_ASSERT | |||||
| #include <stdio.h> | |||||
| /* | |||||
| * Function Name : assert_failed | |||||
| * Description : Reports the name of the source file and the source line number | |||||
| * where the assert_param error has occurred. | |||||
| * Input : - file: pointer to the source file name | |||||
| * - line: assert_param error line source number | |||||
| * Output : None | |||||
| * Return : None | |||||
| */ | |||||
| void assert_failed( uint8_t* file, uint32_t line ) | |||||
| { | |||||
| /* User can add his own implementation to report the file name and line number, | |||||
| ex: printf("Wrong parameters value: file %s on line %lu\n", file, line) */ | |||||
| printf( "Wrong parameters value: file %s on line %lu\n", ( const char* )file, line ); | |||||
| /* Infinite loop */ | |||||
| while( 1 ) | |||||
| { | |||||
| } | |||||
| } | |||||
| #endif | |||||
| /*! | |||||
| * \file board.c | |||||
| * | |||||
| * \brief Target board general functions implementation | |||||
| * | |||||
| * \copyright Revised BSD License, see section \ref LICENSE. | |||||
| * | |||||
| * \code | |||||
| * ______ _ | |||||
| * / _____) _ | | | |||||
| * ( (____ _____ ____ _| |_ _____ ____| |__ | |||||
| * \____ \| ___ | (_ _) ___ |/ ___) _ \ | |||||
| * _____) ) ____| | | || |_| ____( (___| | | | | |||||
| * (______/|_____)_|_|_| \__)_____)\____)_| |_| | |||||
| * (C)2013-2017 Semtech | |||||
| * | |||||
| * \endcode | |||||
| * | |||||
| * \author Miguel Luis ( Semtech ) | |||||
| * | |||||
| * \author Gregory Cristian ( Semtech ) | |||||
| */ | |||||
| #include "stm32l0xx.h" | |||||
| #include "utilities.h" | |||||
| #include "gpio.h" | |||||
| #include "adc.h" | |||||
| #include "spi.h" | |||||
| #include "i2c.h" | |||||
| #include "uart.h" | |||||
| #include "timer.h" | |||||
| #include "sysIrqHandlers.h" | |||||
| #include "board-config.h" | |||||
| #include "lpm-board.h" | |||||
| #include "rtc-board.h" | |||||
| #include "sx1276-board.h" | |||||
| #include "board.h" | |||||
| /*! | |||||
| * Unique Devices IDs register set ( STM32L0xxx ) | |||||
| */ | |||||
| #define ID1 ( 0x1FF80050 ) | |||||
| #define ID2 ( 0x1FF80054 ) | |||||
| #define ID3 ( 0x1FF80064 ) | |||||
| /*! | |||||
| * LED GPIO pins objects | |||||
| */ | |||||
| Gpio_t Led1; | |||||
| Gpio_t Led2; | |||||
| Gpio_t Led3; | |||||
| Gpio_t Led4; | |||||
| /* | |||||
| * MCU objects | |||||
| */ | |||||
| Uart_t Uart2; | |||||
| /*! | |||||
| * Initializes the unused GPIO to a know status | |||||
| */ | |||||
| static void BoardUnusedIoInit( void ); | |||||
| /*! | |||||
| * System Clock Configuration | |||||
| */ | |||||
| static void SystemClockConfig( void ); | |||||
| /*! | |||||
| * System Clock Re-Configuration when waking up from STOP mode | |||||
| */ | |||||
| static void SystemClockReConfig( void ); | |||||
| /*! | |||||
| * Flag to indicate if the MCU is Initialized | |||||
| */ | |||||
| static bool McuInitialized = false; | |||||
| /*! | |||||
| * Flag used to indicate if board is powered from the USB | |||||
| */ | |||||
| static bool UsbIsConnected = false; | |||||
| /*! | |||||
| * UART2 FIFO buffers size | |||||
| */ | |||||
| #define UART2_FIFO_TX_SIZE 1024 | |||||
| #define UART2_FIFO_RX_SIZE 1024 | |||||
| uint8_t Uart2TxBuffer[UART2_FIFO_TX_SIZE]; | |||||
| uint8_t Uart2RxBuffer[UART2_FIFO_RX_SIZE]; | |||||
| void BoardCriticalSectionBegin( uint32_t *mask ) | |||||
| { | |||||
| *mask = __get_PRIMASK( ); | |||||
| __disable_irq( ); | |||||
| } | |||||
| void BoardCriticalSectionEnd( uint32_t *mask ) | |||||
| { | |||||
| __set_PRIMASK( *mask ); | |||||
| } | |||||
| void BoardInitPeriph( void ) | |||||
| { | |||||
| } | |||||
| void BoardInitMcu( void ) | |||||
| { | |||||
| if( McuInitialized == false ) | |||||
| { | |||||
| HAL_Init( ); | |||||
| // LEDs | |||||
| GpioInit( &Led1, LED_1, PIN_OUTPUT, PIN_PUSH_PULL, PIN_NO_PULL, 1 ); | |||||
| GpioInit( &Led2, LED_2, PIN_OUTPUT, PIN_PUSH_PULL, PIN_NO_PULL, 1 ); | |||||
| GpioInit( &Led3, LED_3, PIN_OUTPUT, PIN_PUSH_PULL, PIN_NO_PULL, 1 ); | |||||
| GpioInit( &Led4, LED_4, PIN_OUTPUT, PIN_PUSH_PULL, PIN_NO_PULL, 1 ); | |||||
| SystemClockConfig( ); | |||||
| UsbIsConnected = true; | |||||
| FifoInit( &Uart2.FifoTx, Uart2TxBuffer, UART2_FIFO_TX_SIZE ); | |||||
| FifoInit( &Uart2.FifoRx, Uart2RxBuffer, UART2_FIFO_RX_SIZE ); | |||||
| // Configure your terminal for 8 Bits data (7 data bit + 1 parity bit), no parity and no flow ctrl | |||||
| UartInit( &Uart2, UART_2, UART_TX, UART_RX ); | |||||
| UartConfig( &Uart2, RX_TX, 921600, UART_8_BIT, UART_1_STOP_BIT, NO_PARITY, NO_FLOW_CTRL ); | |||||
| RtcInit( ); | |||||
| GpioWrite( &Led1, 0 ); | |||||
| GpioWrite( &Led2, 0 ); | |||||
| GpioWrite( &Led3, 0 ); | |||||
| GpioWrite( &Led4, 0 ); | |||||
| BoardUnusedIoInit( ); | |||||
| if( GetBoardPowerSource( ) == BATTERY_POWER ) | |||||
| { | |||||
| // Disables OFF mode - Enables lowest power mode (STOP) | |||||
| LpmSetOffMode( LPM_APPLI_ID, LPM_DISABLE ); | |||||
| } | |||||
| } | |||||
| else | |||||
| { | |||||
| SystemClockReConfig( ); | |||||
| } | |||||
| SpiInit( &SX1276.Spi, SPI_1, RADIO_MOSI, RADIO_MISO, RADIO_SCLK, NC ); | |||||
| SX1276IoInit( ); | |||||
| if( McuInitialized == false ) | |||||
| { | |||||
| McuInitialized = true; | |||||
| SX1276IoDbgInit( ); | |||||
| SX1276IoTcxoInit( ); | |||||
| } | |||||
| } | |||||
| void BoardResetMcu( void ) | |||||
| { | |||||
| CRITICAL_SECTION_BEGIN( ); | |||||
| //Restart system | |||||
| NVIC_SystemReset( ); | |||||
| } | |||||
| void BoardDeInitMcu( void ) | |||||
| { | |||||
| SpiDeInit( &SX1276.Spi ); | |||||
| SX1276IoDeInit( ); | |||||
| } | |||||
| uint32_t BoardGetRandomSeed( void ) | |||||
| { | |||||
| return ( ( *( uint32_t* )ID1 ) ^ ( *( uint32_t* )ID2 ) ^ ( *( uint32_t* )ID3 ) ); | |||||
| } | |||||
| void BoardGetUniqueId( uint8_t *id ) | |||||
| { | |||||
| id[7] = ( ( *( uint32_t* )ID1 )+ ( *( uint32_t* )ID3 ) ) >> 24; | |||||
| id[6] = ( ( *( uint32_t* )ID1 )+ ( *( uint32_t* )ID3 ) ) >> 16; | |||||
| id[5] = ( ( *( uint32_t* )ID1 )+ ( *( uint32_t* )ID3 ) ) >> 8; | |||||
| id[4] = ( ( *( uint32_t* )ID1 )+ ( *( uint32_t* )ID3 ) ); | |||||
| id[3] = ( ( *( uint32_t* )ID2 ) ) >> 24; | |||||
| id[2] = ( ( *( uint32_t* )ID2 ) ) >> 16; | |||||
| id[1] = ( ( *( uint32_t* )ID2 ) ) >> 8; | |||||
| id[0] = ( ( *( uint32_t* )ID2 ) ); | |||||
| } | |||||
| uint16_t BoardBatteryMeasureVoltage( void ) | |||||
| { | |||||
| return 0; | |||||
| } | |||||
| uint32_t BoardGetBatteryVoltage( void ) | |||||
| { | |||||
| return 0; | |||||
| } | |||||
| uint8_t BoardGetBatteryLevel( void ) | |||||
| { | |||||
| return 0; | |||||
| } | |||||
| static void BoardUnusedIoInit( void ) | |||||
| { | |||||
| HAL_DBGMCU_EnableDBGSleepMode( ); | |||||
| HAL_DBGMCU_EnableDBGStopMode( ); | |||||
| HAL_DBGMCU_EnableDBGStandbyMode( ); | |||||
| } | |||||
| void SystemClockConfig( void ) | |||||
| { | |||||
| RCC_OscInitTypeDef RCC_OscInitStruct; | |||||
| RCC_ClkInitTypeDef RCC_ClkInitStruct; | |||||
| RCC_PeriphCLKInitTypeDef PeriphClkInit; | |||||
| __HAL_RCC_PWR_CLK_ENABLE( ); | |||||
| __HAL_PWR_VOLTAGESCALING_CONFIG( PWR_REGULATOR_VOLTAGE_SCALE1 ); | |||||
| RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI | RCC_OSCILLATORTYPE_LSE; | |||||
| RCC_OscInitStruct.HSEState = RCC_HSE_OFF; | |||||
| RCC_OscInitStruct.HSIState = RCC_HSI_ON; | |||||
| RCC_OscInitStruct.LSEState = RCC_LSE_ON; | |||||
| RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT; | |||||
| RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; | |||||
| RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI; | |||||
| RCC_OscInitStruct.PLL.PLLMUL = RCC_PLLMUL_6; | |||||
| RCC_OscInitStruct.PLL.PLLDIV = RCC_PLLDIV_3; | |||||
| if( HAL_RCC_OscConfig( &RCC_OscInitStruct ) != HAL_OK ) | |||||
| { | |||||
| assert_param( LMN_STATUS_ERROR ); | |||||
| } | |||||
| RCC_ClkInitStruct.ClockType = (RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2); | |||||
| RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; | |||||
| RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; | |||||
| RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1; | |||||
| RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1; | |||||
| if( HAL_RCC_ClockConfig( &RCC_ClkInitStruct, FLASH_LATENCY_1 ) != HAL_OK ) | |||||
| { | |||||
| assert_param( LMN_STATUS_ERROR ); | |||||
| } | |||||
| PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_RTC; | |||||
| PeriphClkInit.RTCClockSelection = RCC_RTCCLKSOURCE_LSE; | |||||
| if( HAL_RCCEx_PeriphCLKConfig( &PeriphClkInit ) != HAL_OK ) | |||||
| { | |||||
| assert_param( LMN_STATUS_ERROR ); | |||||
| } | |||||
| HAL_SYSTICK_Config( HAL_RCC_GetHCLKFreq( ) / 1000 ); | |||||
| HAL_SYSTICK_CLKSourceConfig( SYSTICK_CLKSOURCE_HCLK ); | |||||
| // SysTick_IRQn interrupt configuration | |||||
| HAL_NVIC_SetPriority( SysTick_IRQn, 0, 0 ); | |||||
| } | |||||
| void SystemClockReConfig( void ) | |||||
| { | |||||
| __HAL_RCC_PWR_CLK_ENABLE( ); | |||||
| __HAL_PWR_VOLTAGESCALING_CONFIG( PWR_REGULATOR_VOLTAGE_SCALE1 ); | |||||
| // Enable HSI | |||||
| __HAL_RCC_HSI_CONFIG( RCC_HSI_ON ); | |||||
| // Wait till HSI is ready | |||||
| while( __HAL_RCC_GET_FLAG( RCC_FLAG_HSIRDY ) == RESET ) | |||||
| { | |||||
| } | |||||
| // Enable PLL | |||||
| __HAL_RCC_PLL_ENABLE( ); | |||||
| // Wait till PLL is ready | |||||
| while( __HAL_RCC_GET_FLAG( RCC_FLAG_PLLRDY ) == RESET ) | |||||
| { | |||||
| } | |||||
| // Select PLL as system clock source | |||||
| __HAL_RCC_SYSCLK_CONFIG ( RCC_SYSCLKSOURCE_PLLCLK ); | |||||
| // Wait till PLL is used as system clock source | |||||
| while( __HAL_RCC_GET_SYSCLK_SOURCE( ) != RCC_SYSCLKSOURCE_STATUS_PLLCLK ) | |||||
| { | |||||
| } | |||||
| } | |||||
| void SysTick_Handler( void ) | |||||
| { | |||||
| HAL_IncTick( ); | |||||
| HAL_SYSTICK_IRQHandler( ); | |||||
| } | |||||
| uint8_t GetBoardPowerSource( void ) | |||||
| { | |||||
| if( UsbIsConnected == false ) | |||||
| { | |||||
| return BATTERY_POWER; | |||||
| } | |||||
| else | |||||
| { | |||||
| return USB_POWER; | |||||
| } | |||||
| } | |||||
| /** | |||||
| * \brief Enters Low Power Stop Mode | |||||
| * | |||||
| * \note ARM exists the function when waking up | |||||
| */ | |||||
| void LpmEnterStopMode( void) | |||||
| { | |||||
| CRITICAL_SECTION_BEGIN( ); | |||||
| BoardDeInitMcu( ); | |||||
| // Disable the Power Voltage Detector | |||||
| HAL_PWR_DisablePVD( ); | |||||
| // Clear wake up flag | |||||
| SET_BIT( PWR->CR, PWR_CR_CWUF ); | |||||
| // Enable Ultra low power mode | |||||
| HAL_PWREx_EnableUltraLowPower( ); | |||||
| // Enable the fast wake up from Ultra low power mode | |||||
| HAL_PWREx_EnableFastWakeUp( ); | |||||
| CRITICAL_SECTION_END( ); | |||||
| // Enter Stop Mode | |||||
| HAL_PWR_EnterSTOPMode( PWR_LOWPOWERREGULATOR_ON, PWR_STOPENTRY_WFI ); | |||||
| } | |||||
| /*! | |||||
| * \brief Exists Low Power Stop Mode | |||||
| */ | |||||
| void LpmExitStopMode( void ) | |||||
| { | |||||
| // Disable IRQ while the MCU is not running on HSI | |||||
| CRITICAL_SECTION_BEGIN( ); | |||||
| // Initilizes the peripherals | |||||
| BoardInitMcu( ); | |||||
| CRITICAL_SECTION_END( ); | |||||
| } | |||||
| /*! | |||||
| * \brief Enters Low Power Sleep Mode | |||||
| * | |||||
| * \note ARM exits the function when waking up | |||||
| */ | |||||
| void LpmEnterSleepMode( void) | |||||
| { | |||||
| HAL_PWR_EnterSLEEPMode(PWR_MAINREGULATOR_ON, PWR_SLEEPENTRY_WFI); | |||||
| } | |||||
| void BoardLowPowerHandler( void ) | |||||
| { | |||||
| __disable_irq( ); | |||||
| /*! | |||||
| * If an interrupt has occurred after __disable_irq( ), it is kept pending | |||||
| * and cortex will not enter low power anyway | |||||
| */ | |||||
| LpmEnterLowPower( ); | |||||
| __enable_irq( ); | |||||
| } | |||||
| #if !defined ( __CC_ARM ) | |||||
| /* | |||||
| * Function to be used by stdout for printf etc | |||||
| */ | |||||
| int _write( int fd, const void *buf, size_t count ) | |||||
| { | |||||
| while( UartPutBuffer( &Uart2, ( uint8_t* )buf, ( uint16_t )count ) != 0 ){ }; | |||||
| return count; | |||||
| } | |||||
| /* | |||||
| * Function to be used by stdin for scanf etc | |||||
| */ | |||||
| int _read( int fd, const void *buf, size_t count ) | |||||
| { | |||||
| size_t bytesRead = 0; | |||||
| while( UartGetBuffer( &Uart2, ( uint8_t* )buf, count, ( uint16_t* )&bytesRead ) != 0 ){ }; | |||||
| // Echo back the character | |||||
| while( UartPutBuffer( &Uart2, ( uint8_t* )buf, ( uint16_t )bytesRead ) != 0 ){ }; | |||||
| return bytesRead; | |||||
| } | |||||
| #else | |||||
| #include <stdio.h> | |||||
| // Keil compiler | |||||
| int fputc( int c, FILE *stream ) | |||||
| { | |||||
| while( UartPutChar( &Uart2, ( uint8_t )c ) != 0 ); | |||||
| return c; | |||||
| } | |||||
| int fgetc( FILE *stream ) | |||||
| { | |||||
| uint8_t c = 0; | |||||
| while( UartGetChar( &Uart2, &c ) != 0 ); | |||||
| // Echo back the character | |||||
| while( UartPutChar( &Uart2, c ) != 0 ); | |||||
| return ( int )c; | |||||
| } | |||||
| #endif | |||||
| #ifdef USE_FULL_ASSERT | |||||
| #include <stdio.h> | |||||
| /* | |||||
| * Function Name : assert_failed | |||||
| * Description : Reports the name of the source file and the source line number | |||||
| * where the assert_param error has occurred. | |||||
| * Input : - file: pointer to the source file name | |||||
| * - line: assert_param error line source number | |||||
| * Output : None | |||||
| * Return : None | |||||
| */ | |||||
| void assert_failed( uint8_t* file, uint32_t line ) | |||||
| { | |||||
| /* User can add his own implementation to report the file name and line number, | |||||
| ex: printf("Wrong parameters value: file %s on line %lu\n", file, line) */ | |||||
| printf( "Wrong parameters value: file %s on line %lu\n", ( const char* )file, line ); | |||||
| /* Infinite loop */ | |||||
| while( 1 ) | |||||
| { | |||||
| } | |||||
| } | |||||
| #endif | |||||
| @@ -1,302 +1,302 @@ | |||||
| /** | |||||
| ****************************************************************************** | |||||
| * @file startup_stm32l072xx.s | |||||
| * @author MCD Application Team | |||||
| * @brief STM32L072xx Devices vector table for Atollic TrueSTUDIO toolchain. | |||||
| * This module performs: | |||||
| * - Set the initial SP | |||||
| * - Set the initial PC == Reset_Handler, | |||||
| * - Set the vector table entries with the exceptions ISR address | |||||
| * - Branches to main in the C library (which eventually | |||||
| * calls main()). | |||||
| * After Reset the Cortex-M0+ processor is in Thread mode, | |||||
| * priority is Privileged, and the Stack is set to Main. | |||||
| ****************************************************************************** | |||||
| * | |||||
| * Redistribution and use in source and binary forms, with or without modification, | |||||
| * are permitted provided that the following conditions are met: | |||||
| * 1. Redistributions of source code must retain the above copyright notice, | |||||
| * this list of conditions and the following disclaimer. | |||||
| * 2. Redistributions in binary form must reproduce the above copyright notice, | |||||
| * this list of conditions and the following disclaimer in the documentation | |||||
| * and/or other materials provided with the distribution. | |||||
| * 3. Neither the name of STMicroelectronics nor the names of its contributors | |||||
| * may be used to endorse or promote products derived from this software | |||||
| * without specific prior written permission. | |||||
| * | |||||
| * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | |||||
| * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |||||
| * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |||||
| * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE | |||||
| * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |||||
| * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | |||||
| * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | |||||
| * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |||||
| * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |||||
| * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |||||
| * | |||||
| ****************************************************************************** | |||||
| */ | |||||
| .syntax unified | |||||
| .cpu cortex-m0plus | |||||
| .fpu softvfp | |||||
| .thumb | |||||
| .global g_pfnVectors | |||||
| .global Default_Handler | |||||
| /* start address for the initialization values of the .data section. | |||||
| defined in linker script */ | |||||
| .word _sidata | |||||
| /* start address for the .data section. defined in linker script */ | |||||
| .word _sdata | |||||
| /* end address for the .data section. defined in linker script */ | |||||
| .word _edata | |||||
| /* start address for the .bss section. defined in linker script */ | |||||
| .word _sbss | |||||
| /* end address for the .bss section. defined in linker script */ | |||||
| .word _ebss | |||||
| .section .text.Reset_Handler | |||||
| .weak Reset_Handler | |||||
| .type Reset_Handler, %function | |||||
| Reset_Handler: | |||||
| ldr r0, =_estack | |||||
| mov sp, r0 /* set stack pointer */ | |||||
| /* Copy the data segment initializers from flash to SRAM */ | |||||
| movs r1, #0 | |||||
| b LoopCopyDataInit | |||||
| CopyDataInit: | |||||
| ldr r3, =_sidata | |||||
| ldr r3, [r3, r1] | |||||
| str r3, [r0, r1] | |||||
| adds r1, r1, #4 | |||||
| LoopCopyDataInit: | |||||
| ldr r0, =_sdata | |||||
| ldr r3, =_edata | |||||
| adds r2, r0, r1 | |||||
| cmp r2, r3 | |||||
| bcc CopyDataInit | |||||
| ldr r2, =_sbss | |||||
| b LoopFillZerobss | |||||
| /* Zero fill the bss segment. */ | |||||
| FillZerobss: | |||||
| movs r3, #0 | |||||
| str r3, [r2] | |||||
| adds r2, r2, #4 | |||||
| LoopFillZerobss: | |||||
| ldr r3, = _ebss | |||||
| cmp r2, r3 | |||||
| bcc FillZerobss | |||||
| /* Call the clock system intitialization function.*/ | |||||
| bl SystemInit | |||||
| /* Call static constructors */ | |||||
| bl __libc_init_array | |||||
| /* Call the application's entry point.*/ | |||||
| bl main | |||||
| LoopForever: | |||||
| b LoopForever | |||||
| .size Reset_Handler, .-Reset_Handler | |||||
| /** | |||||
| * @brief This is the code that gets called when the processor receives an | |||||
| * unexpected interrupt. This simply enters an infinite loop, preserving | |||||
| * the system state for examination by a debugger. | |||||
| * | |||||
| * @param None | |||||
| * @retval : None | |||||
| */ | |||||
| .section .text.Default_Handler,"ax",%progbits | |||||
| Default_Handler: | |||||
| Infinite_Loop: | |||||
| b Infinite_Loop | |||||
| .size Default_Handler, .-Default_Handler | |||||
| /****************************************************************************** | |||||
| * | |||||
| * The minimal vector table for a Cortex M0. Note that the proper constructs | |||||
| * must be placed on this to ensure that it ends up at physical address | |||||
| * 0x0000.0000. | |||||
| * | |||||
| ******************************************************************************/ | |||||
| .section .isr_vector,"a",%progbits | |||||
| .type g_pfnVectors, %object | |||||
| .size g_pfnVectors, .-g_pfnVectors | |||||
| g_pfnVectors: | |||||
| .word _estack | |||||
| .word Reset_Handler | |||||
| .word NMI_Handler | |||||
| .word HardFault_Handler | |||||
| .word 0 | |||||
| .word 0 | |||||
| .word 0 | |||||
| .word 0 | |||||
| .word 0 | |||||
| .word 0 | |||||
| .word 0 | |||||
| .word SVC_Handler | |||||
| .word 0 | |||||
| .word 0 | |||||
| .word PendSV_Handler | |||||
| .word SysTick_Handler | |||||
| .word WWDG_IRQHandler /* Window WatchDog */ | |||||
| .word PVD_IRQHandler /* PVD through EXTI Line detection */ | |||||
| .word RTC_IRQHandler /* RTC through the EXTI line */ | |||||
| .word FLASH_IRQHandler /* FLASH */ | |||||
| .word RCC_CRS_IRQHandler /* RCC and CRS */ | |||||
| .word EXTI0_1_IRQHandler /* EXTI Line 0 and 1 */ | |||||
| .word EXTI2_3_IRQHandler /* EXTI Line 2 and 3 */ | |||||
| .word EXTI4_15_IRQHandler /* EXTI Line 4 to 15 */ | |||||
| .word TSC_IRQHandler /* TSC */ | |||||
| .word DMA1_Channel1_IRQHandler /* DMA1 Channel 1 */ | |||||
| .word DMA1_Channel2_3_IRQHandler /* DMA1 Channel 2 and Channel 3 */ | |||||
| .word DMA1_Channel4_5_6_7_IRQHandler /* DMA1 Channel 4, Channel 5, Channel 6 and Channel 7*/ | |||||
| .word ADC1_COMP_IRQHandler /* ADC1, COMP1 and COMP2 */ | |||||
| .word LPTIM1_IRQHandler /* LPTIM1 */ | |||||
| .word USART4_5_IRQHandler /* USART4 and USART 5 */ | |||||
| .word TIM2_IRQHandler /* TIM2 */ | |||||
| .word TIM3_IRQHandler /* TIM3 */ | |||||
| .word TIM6_DAC_IRQHandler /* TIM6 and DAC */ | |||||
| .word TIM7_IRQHandler /* TIM7 */ | |||||
| .word 0 /* Reserved */ | |||||
| .word TIM21_IRQHandler /* TIM21 */ | |||||
| .word I2C3_IRQHandler /* I2C3 */ | |||||
| .word TIM22_IRQHandler /* TIM22 */ | |||||
| .word I2C1_IRQHandler /* I2C1 */ | |||||
| .word I2C2_IRQHandler /* I2C2 */ | |||||
| .word SPI1_IRQHandler /* SPI1 */ | |||||
| .word SPI2_IRQHandler /* SPI2 */ | |||||
| .word USART1_IRQHandler /* USART1 */ | |||||
| .word USART2_IRQHandler /* USART2 */ | |||||
| .word RNG_LPUART1_IRQHandler /* RNG and LPUART1 */ | |||||
| .word 0 /* Reserved */ | |||||
| .word USB_IRQHandler /* USB */ | |||||
| /******************************************************************************* | |||||
| * | |||||
| * Provide weak aliases for each Exception handler to the Default_Handler. | |||||
| * As they are weak aliases, any function with the same name will override | |||||
| * this definition. | |||||
| * | |||||
| *******************************************************************************/ | |||||
| .weak NMI_Handler | |||||
| .thumb_set NMI_Handler,Default_Handler | |||||
| .weak HardFault_Handler | |||||
| .thumb_set HardFault_Handler,Default_Handler | |||||
| .weak SVC_Handler | |||||
| .thumb_set SVC_Handler,Default_Handler | |||||
| .weak PendSV_Handler | |||||
| .thumb_set PendSV_Handler,Default_Handler | |||||
| .weak SysTick_Handler | |||||
| .thumb_set SysTick_Handler,Default_Handler | |||||
| .weak WWDG_IRQHandler | |||||
| .thumb_set WWDG_IRQHandler,Default_Handler | |||||
| .weak PVD_IRQHandler | |||||
| .thumb_set PVD_IRQHandler,Default_Handler | |||||
| .weak RTC_IRQHandler | |||||
| .thumb_set RTC_IRQHandler,Default_Handler | |||||
| .weak FLASH_IRQHandler | |||||
| .thumb_set FLASH_IRQHandler,Default_Handler | |||||
| .weak RCC_CRS_IRQHandler | |||||
| .thumb_set RCC_CRS_IRQHandler,Default_Handler | |||||
| .weak EXTI0_1_IRQHandler | |||||
| .thumb_set EXTI0_1_IRQHandler,Default_Handler | |||||
| .weak EXTI2_3_IRQHandler | |||||
| .thumb_set EXTI2_3_IRQHandler,Default_Handler | |||||
| .weak EXTI4_15_IRQHandler | |||||
| .thumb_set EXTI4_15_IRQHandler,Default_Handler | |||||
| .weak TSC_IRQHandler | |||||
| .thumb_set TSC_IRQHandler,Default_Handler | |||||
| .weak DMA1_Channel1_IRQHandler | |||||
| .thumb_set DMA1_Channel1_IRQHandler,Default_Handler | |||||
| .weak DMA1_Channel2_3_IRQHandler | |||||
| .thumb_set DMA1_Channel2_3_IRQHandler,Default_Handler | |||||
| .weak DMA1_Channel4_5_6_7_IRQHandler | |||||
| .thumb_set DMA1_Channel4_5_6_7_IRQHandler,Default_Handler | |||||
| .weak ADC1_COMP_IRQHandler | |||||
| .thumb_set ADC1_COMP_IRQHandler,Default_Handler | |||||
| .weak LPTIM1_IRQHandler | |||||
| .thumb_set LPTIM1_IRQHandler,Default_Handler | |||||
| .weak USART4_5_IRQHandler | |||||
| .thumb_set USART4_5_IRQHandler,Default_Handler | |||||
| .weak TIM2_IRQHandler | |||||
| .thumb_set TIM2_IRQHandler,Default_Handler | |||||
| .weak TIM3_IRQHandler | |||||
| .thumb_set TIM3_IRQHandler,Default_Handler | |||||
| .weak TIM6_DAC_IRQHandler | |||||
| .thumb_set TIM6_DAC_IRQHandler,Default_Handler | |||||
| .weak TIM7_IRQHandler | |||||
| .thumb_set TIM7_IRQHandler,Default_Handler | |||||
| .weak TIM21_IRQHandler | |||||
| .thumb_set TIM21_IRQHandler,Default_Handler | |||||
| .weak I2C3_IRQHandler | |||||
| .thumb_set I2C3_IRQHandler,Default_Handler | |||||
| .weak TIM22_IRQHandler | |||||
| .thumb_set TIM22_IRQHandler,Default_Handler | |||||
| .weak I2C1_IRQHandler | |||||
| .thumb_set I2C1_IRQHandler,Default_Handler | |||||
| .weak I2C2_IRQHandler | |||||
| .thumb_set I2C2_IRQHandler,Default_Handler | |||||
| .weak SPI1_IRQHandler | |||||
| .thumb_set SPI1_IRQHandler,Default_Handler | |||||
| .weak SPI2_IRQHandler | |||||
| .thumb_set SPI2_IRQHandler,Default_Handler | |||||
| .weak USART1_IRQHandler | |||||
| .thumb_set USART1_IRQHandler,Default_Handler | |||||
| .weak USART2_IRQHandler | |||||
| .thumb_set USART2_IRQHandler,Default_Handler | |||||
| .weak RNG_LPUART1_IRQHandler | |||||
| .thumb_set RNG_LPUART1_IRQHandler,Default_Handler | |||||
| .weak USB_IRQHandler | |||||
| .thumb_set USB_IRQHandler,Default_Handler | |||||
| /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ | |||||
| /** | |||||
| ****************************************************************************** | |||||
| * @file startup_stm32l072xx.s | |||||
| * @author MCD Application Team | |||||
| * @brief STM32L072xx Devices vector table for Atollic TrueSTUDIO toolchain. | |||||
| * This module performs: | |||||
| * - Set the initial SP | |||||
| * - Set the initial PC == Reset_Handler, | |||||
| * - Set the vector table entries with the exceptions ISR address | |||||
| * - Branches to main in the C library (which eventually | |||||
| * calls main()). | |||||
| * After Reset the Cortex-M0+ processor is in Thread mode, | |||||
| * priority is Privileged, and the Stack is set to Main. | |||||
| ****************************************************************************** | |||||
| * | |||||
| * Redistribution and use in source and binary forms, with or without modification, | |||||
| * are permitted provided that the following conditions are met: | |||||
| * 1. Redistributions of source code must retain the above copyright notice, | |||||
| * this list of conditions and the following disclaimer. | |||||
| * 2. Redistributions in binary form must reproduce the above copyright notice, | |||||
| * this list of conditions and the following disclaimer in the documentation | |||||
| * and/or other materials provided with the distribution. | |||||
| * 3. Neither the name of STMicroelectronics nor the names of its contributors | |||||
| * may be used to endorse or promote products derived from this software | |||||
| * without specific prior written permission. | |||||
| * | |||||
| * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | |||||
| * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |||||
| * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |||||
| * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE | |||||
| * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |||||
| * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | |||||
| * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | |||||
| * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |||||
| * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |||||
| * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |||||
| * | |||||
| ****************************************************************************** | |||||
| */ | |||||
| .syntax unified | |||||
| .cpu cortex-m0plus | |||||
| .fpu softvfp | |||||
| .thumb | |||||
| .global g_pfnVectors | |||||
| .global Default_Handler | |||||
| /* start address for the initialization values of the .data section. | |||||
| defined in linker script */ | |||||
| .word _sidata | |||||
| /* start address for the .data section. defined in linker script */ | |||||
| .word _sdata | |||||
| /* end address for the .data section. defined in linker script */ | |||||
| .word _edata | |||||
| /* start address for the .bss section. defined in linker script */ | |||||
| .word _sbss | |||||
| /* end address for the .bss section. defined in linker script */ | |||||
| .word _ebss | |||||
| .section .text.Reset_Handler | |||||
| .weak Reset_Handler | |||||
| .type Reset_Handler, %function | |||||
| Reset_Handler: | |||||
| ldr r0, =_estack | |||||
| mov sp, r0 /* set stack pointer */ | |||||
| /* Copy the data segment initializers from flash to SRAM */ | |||||
| movs r1, #0 | |||||
| b LoopCopyDataInit | |||||
| CopyDataInit: | |||||
| ldr r3, =_sidata | |||||
| ldr r3, [r3, r1] | |||||
| str r3, [r0, r1] | |||||
| adds r1, r1, #4 | |||||
| LoopCopyDataInit: | |||||
| ldr r0, =_sdata | |||||
| ldr r3, =_edata | |||||
| adds r2, r0, r1 | |||||
| cmp r2, r3 | |||||
| bcc CopyDataInit | |||||
| ldr r2, =_sbss | |||||
| b LoopFillZerobss | |||||
| /* Zero fill the bss segment. */ | |||||
| FillZerobss: | |||||
| movs r3, #0 | |||||
| str r3, [r2] | |||||
| adds r2, r2, #4 | |||||
| LoopFillZerobss: | |||||
| ldr r3, = _ebss | |||||
| cmp r2, r3 | |||||
| bcc FillZerobss | |||||
| /* Call the clock system intitialization function.*/ | |||||
| bl SystemInit | |||||
| /* Call static constructors */ | |||||
| bl __libc_init_array | |||||
| /* Call the application's entry point.*/ | |||||
| bl main | |||||
| LoopForever: | |||||
| b LoopForever | |||||
| .size Reset_Handler, .-Reset_Handler | |||||
| /** | |||||
| * @brief This is the code that gets called when the processor receives an | |||||
| * unexpected interrupt. This simply enters an infinite loop, preserving | |||||
| * the system state for examination by a debugger. | |||||
| * | |||||
| * @param None | |||||
| * @retval : None | |||||
| */ | |||||
| .section .text.Default_Handler,"ax",%progbits | |||||
| Default_Handler: | |||||
| Infinite_Loop: | |||||
| b Infinite_Loop | |||||
| .size Default_Handler, .-Default_Handler | |||||
| /****************************************************************************** | |||||
| * | |||||
| * The minimal vector table for a Cortex M0. Note that the proper constructs | |||||
| * must be placed on this to ensure that it ends up at physical address | |||||
| * 0x0000.0000. | |||||
| * | |||||
| ******************************************************************************/ | |||||
| .section .isr_vector,"a",%progbits | |||||
| .type g_pfnVectors, %object | |||||
| .size g_pfnVectors, .-g_pfnVectors | |||||
| g_pfnVectors: | |||||
| .word _estack | |||||
| .word Reset_Handler | |||||
| .word NMI_Handler | |||||
| .word HardFault_Handler | |||||
| .word 0 | |||||
| .word 0 | |||||
| .word 0 | |||||
| .word 0 | |||||
| .word 0 | |||||
| .word 0 | |||||
| .word 0 | |||||
| .word SVC_Handler | |||||
| .word 0 | |||||
| .word 0 | |||||
| .word PendSV_Handler | |||||
| .word SysTick_Handler | |||||
| .word WWDG_IRQHandler /* Window WatchDog */ | |||||
| .word PVD_IRQHandler /* PVD through EXTI Line detection */ | |||||
| .word RTC_IRQHandler /* RTC through the EXTI line */ | |||||
| .word FLASH_IRQHandler /* FLASH */ | |||||
| .word RCC_CRS_IRQHandler /* RCC and CRS */ | |||||
| .word EXTI0_1_IRQHandler /* EXTI Line 0 and 1 */ | |||||
| .word EXTI2_3_IRQHandler /* EXTI Line 2 and 3 */ | |||||
| .word EXTI4_15_IRQHandler /* EXTI Line 4 to 15 */ | |||||
| .word TSC_IRQHandler /* TSC */ | |||||
| .word DMA1_Channel1_IRQHandler /* DMA1 Channel 1 */ | |||||
| .word DMA1_Channel2_3_IRQHandler /* DMA1 Channel 2 and Channel 3 */ | |||||
| .word DMA1_Channel4_5_6_7_IRQHandler /* DMA1 Channel 4, Channel 5, Channel 6 and Channel 7*/ | |||||
| .word ADC1_COMP_IRQHandler /* ADC1, COMP1 and COMP2 */ | |||||
| .word LPTIM1_IRQHandler /* LPTIM1 */ | |||||
| .word USART4_5_IRQHandler /* USART4 and USART 5 */ | |||||
| .word TIM2_IRQHandler /* TIM2 */ | |||||
| .word TIM3_IRQHandler /* TIM3 */ | |||||
| .word TIM6_DAC_IRQHandler /* TIM6 and DAC */ | |||||
| .word TIM7_IRQHandler /* TIM7 */ | |||||
| .word 0 /* Reserved */ | |||||
| .word TIM21_IRQHandler /* TIM21 */ | |||||
| .word I2C3_IRQHandler /* I2C3 */ | |||||
| .word TIM22_IRQHandler /* TIM22 */ | |||||
| .word I2C1_IRQHandler /* I2C1 */ | |||||
| .word I2C2_IRQHandler /* I2C2 */ | |||||
| .word SPI1_IRQHandler /* SPI1 */ | |||||
| .word SPI2_IRQHandler /* SPI2 */ | |||||
| .word USART1_IRQHandler /* USART1 */ | |||||
| .word USART2_IRQHandler /* USART2 */ | |||||
| .word RNG_LPUART1_IRQHandler /* RNG and LPUART1 */ | |||||
| .word 0 /* Reserved */ | |||||
| .word USB_IRQHandler /* USB */ | |||||
| /******************************************************************************* | |||||
| * | |||||
| * Provide weak aliases for each Exception handler to the Default_Handler. | |||||
| * As they are weak aliases, any function with the same name will override | |||||
| * this definition. | |||||
| * | |||||
| *******************************************************************************/ | |||||
| .weak NMI_Handler | |||||
| .thumb_set NMI_Handler,Default_Handler | |||||
| .weak HardFault_Handler | |||||
| .thumb_set HardFault_Handler,Default_Handler | |||||
| .weak SVC_Handler | |||||
| .thumb_set SVC_Handler,Default_Handler | |||||
| .weak PendSV_Handler | |||||
| .thumb_set PendSV_Handler,Default_Handler | |||||
| .weak SysTick_Handler | |||||
| .thumb_set SysTick_Handler,Default_Handler | |||||
| .weak WWDG_IRQHandler | |||||
| .thumb_set WWDG_IRQHandler,Default_Handler | |||||
| .weak PVD_IRQHandler | |||||
| .thumb_set PVD_IRQHandler,Default_Handler | |||||
| .weak RTC_IRQHandler | |||||
| .thumb_set RTC_IRQHandler,Default_Handler | |||||
| .weak FLASH_IRQHandler | |||||
| .thumb_set FLASH_IRQHandler,Default_Handler | |||||
| .weak RCC_CRS_IRQHandler | |||||
| .thumb_set RCC_CRS_IRQHandler,Default_Handler | |||||
| .weak EXTI0_1_IRQHandler | |||||
| .thumb_set EXTI0_1_IRQHandler,Default_Handler | |||||
| .weak EXTI2_3_IRQHandler | |||||
| .thumb_set EXTI2_3_IRQHandler,Default_Handler | |||||
| .weak EXTI4_15_IRQHandler | |||||
| .thumb_set EXTI4_15_IRQHandler,Default_Handler | |||||
| .weak TSC_IRQHandler | |||||
| .thumb_set TSC_IRQHandler,Default_Handler | |||||
| .weak DMA1_Channel1_IRQHandler | |||||
| .thumb_set DMA1_Channel1_IRQHandler,Default_Handler | |||||
| .weak DMA1_Channel2_3_IRQHandler | |||||
| .thumb_set DMA1_Channel2_3_IRQHandler,Default_Handler | |||||
| .weak DMA1_Channel4_5_6_7_IRQHandler | |||||
| .thumb_set DMA1_Channel4_5_6_7_IRQHandler,Default_Handler | |||||
| .weak ADC1_COMP_IRQHandler | |||||
| .thumb_set ADC1_COMP_IRQHandler,Default_Handler | |||||
| .weak LPTIM1_IRQHandler | |||||
| .thumb_set LPTIM1_IRQHandler,Default_Handler | |||||
| .weak USART4_5_IRQHandler | |||||
| .thumb_set USART4_5_IRQHandler,Default_Handler | |||||
| .weak TIM2_IRQHandler | |||||
| .thumb_set TIM2_IRQHandler,Default_Handler | |||||
| .weak TIM3_IRQHandler | |||||
| .thumb_set TIM3_IRQHandler,Default_Handler | |||||
| .weak TIM6_DAC_IRQHandler | |||||
| .thumb_set TIM6_DAC_IRQHandler,Default_Handler | |||||
| .weak TIM7_IRQHandler | |||||
| .thumb_set TIM7_IRQHandler,Default_Handler | |||||
| .weak TIM21_IRQHandler | |||||
| .thumb_set TIM21_IRQHandler,Default_Handler | |||||
| .weak I2C3_IRQHandler | |||||
| .thumb_set I2C3_IRQHandler,Default_Handler | |||||
| .weak TIM22_IRQHandler | |||||
| .thumb_set TIM22_IRQHandler,Default_Handler | |||||
| .weak I2C1_IRQHandler | |||||
| .thumb_set I2C1_IRQHandler,Default_Handler | |||||
| .weak I2C2_IRQHandler | |||||
| .thumb_set I2C2_IRQHandler,Default_Handler | |||||
| .weak SPI1_IRQHandler | |||||
| .thumb_set SPI1_IRQHandler,Default_Handler | |||||
| .weak SPI2_IRQHandler | |||||
| .thumb_set SPI2_IRQHandler,Default_Handler | |||||
| .weak USART1_IRQHandler | |||||
| .thumb_set USART1_IRQHandler,Default_Handler | |||||
| .weak USART2_IRQHandler | |||||
| .thumb_set USART2_IRQHandler,Default_Handler | |||||
| .weak RNG_LPUART1_IRQHandler | |||||
| .thumb_set RNG_LPUART1_IRQHandler,Default_Handler | |||||
| .weak USB_IRQHandler | |||||
| .thumb_set USB_IRQHandler,Default_Handler | |||||
| /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ | |||||
| @@ -1,129 +1,129 @@ | |||||
| /* Memory regions.*/ | |||||
| MEMORY | |||||
| { | |||||
| FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 192K | |||||
| RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 20K | |||||
| } | |||||
| /* Entry Point */ | |||||
| ENTRY(Reset_Handler) | |||||
| /* Define output sections */ | |||||
| SECTIONS | |||||
| { | |||||
| .text : | |||||
| { | |||||
| KEEP(*(.isr_vector)) | |||||
| *(.text*) | |||||
| KEEP(*(.init)) | |||||
| KEEP(*(.fini)) | |||||
| /* .ctors */ | |||||
| *crtbegin.o(.ctors) | |||||
| *crtbegin?.o(.ctors) | |||||
| *(EXCLUDE_FILE(*crtend?.o *crtend.o) .ctors) | |||||
| *(SORT(.ctors.*)) | |||||
| *(.ctors) | |||||
| /* .dtors */ | |||||
| *crtbegin.o(.dtors) | |||||
| *crtbegin?.o(.dtors) | |||||
| *(EXCLUDE_FILE(*crtend?.o *crtend.o) .dtors) | |||||
| *(SORT(.dtors.*)) | |||||
| *(.dtors) | |||||
| *(.rodata*) | |||||
| KEEP(*(.eh_frame*)) | |||||
| } > FLASH | |||||
| .ARM.extab : | |||||
| { | |||||
| *(.ARM.extab* .gnu.linkonce.armextab.*) | |||||
| } > FLASH | |||||
| __exidx_start = .; | |||||
| .ARM.exidx : | |||||
| { | |||||
| *(.ARM.exidx* .gnu.linkonce.armexidx.*) | |||||
| } > FLASH | |||||
| __exidx_end = .; | |||||
| __etext = .; | |||||
| _sidata = .; | |||||
| .data : AT (__etext) | |||||
| { | |||||
| __data_start__ = .; | |||||
| _sdata = .; | |||||
| *(vtable) | |||||
| *(.data*) | |||||
| . = ALIGN(4); | |||||
| /* preinit data */ | |||||
| PROVIDE_HIDDEN (__preinit_array_start = .); | |||||
| KEEP(*(.preinit_array)) | |||||
| PROVIDE_HIDDEN (__preinit_array_end = .); | |||||
| . = ALIGN(4); | |||||
| /* init data */ | |||||
| PROVIDE_HIDDEN (__init_array_start = .); | |||||
| KEEP(*(SORT(.init_array.*))) | |||||
| KEEP(*(.init_array)) | |||||
| PROVIDE_HIDDEN (__init_array_end = .); | |||||
| . = ALIGN(4); | |||||
| /* finit data */ | |||||
| PROVIDE_HIDDEN (__fini_array_start = .); | |||||
| KEEP(*(SORT(.fini_array.*))) | |||||
| KEEP(*(.fini_array)) | |||||
| PROVIDE_HIDDEN (__fini_array_end = .); | |||||
| KEEP(*(.jcr*)) | |||||
| . = ALIGN(4); | |||||
| /* All data end */ | |||||
| __data_end__ = .; | |||||
| _edata = .; | |||||
| } > RAM | |||||
| .bss : | |||||
| { | |||||
| . = ALIGN(4); | |||||
| __bss_start__ = .; | |||||
| _sbss = .; | |||||
| *(.bss*) | |||||
| *(COMMON) | |||||
| . = ALIGN(4); | |||||
| __bss_end__ = .; | |||||
| _ebss = .; | |||||
| } > RAM | |||||
| .heap (COPY): | |||||
| { | |||||
| __end__ = .; | |||||
| end = __end__; | |||||
| *(.heap*) | |||||
| __HeapLimit = .; | |||||
| } > RAM | |||||
| /* .stack_dummy section doesn't contains any symbols. It is only | |||||
| * used for linker to calculate size of stack sections, and assign | |||||
| * values to stack symbols later */ | |||||
| .stack_dummy (COPY): | |||||
| { | |||||
| *(.stack*) | |||||
| } > RAM | |||||
| /* Set stack top to end of RAM, and stack limit move down by | |||||
| * size of stack_dummy section */ | |||||
| __StackTop = ORIGIN(RAM) + LENGTH(RAM); | |||||
| _estack = __StackTop; | |||||
| __StackLimit = __StackTop - SIZEOF(.stack_dummy); | |||||
| PROVIDE(__stack = __StackTop); | |||||
| /* Check if data + heap + stack exceeds RAM limit */ | |||||
| ASSERT(__StackLimit >= __HeapLimit, "region RAM overflowed with stack") | |||||
| } | |||||
| /* Memory regions.*/ | |||||
| MEMORY | |||||
| { | |||||
| FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 192K | |||||
| RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 20K | |||||
| } | |||||
| /* Entry Point */ | |||||
| ENTRY(Reset_Handler) | |||||
| /* Define output sections */ | |||||
| SECTIONS | |||||
| { | |||||
| .text : | |||||
| { | |||||
| KEEP(*(.isr_vector)) | |||||
| *(.text*) | |||||
| KEEP(*(.init)) | |||||
| KEEP(*(.fini)) | |||||
| /* .ctors */ | |||||
| *crtbegin.o(.ctors) | |||||
| *crtbegin?.o(.ctors) | |||||
| *(EXCLUDE_FILE(*crtend?.o *crtend.o) .ctors) | |||||
| *(SORT(.ctors.*)) | |||||
| *(.ctors) | |||||
| /* .dtors */ | |||||
| *crtbegin.o(.dtors) | |||||
| *crtbegin?.o(.dtors) | |||||
| *(EXCLUDE_FILE(*crtend?.o *crtend.o) .dtors) | |||||
| *(SORT(.dtors.*)) | |||||
| *(.dtors) | |||||
| *(.rodata*) | |||||
| KEEP(*(.eh_frame*)) | |||||
| } > FLASH | |||||
| .ARM.extab : | |||||
| { | |||||
| *(.ARM.extab* .gnu.linkonce.armextab.*) | |||||
| } > FLASH | |||||
| __exidx_start = .; | |||||
| .ARM.exidx : | |||||
| { | |||||
| *(.ARM.exidx* .gnu.linkonce.armexidx.*) | |||||
| } > FLASH | |||||
| __exidx_end = .; | |||||
| __etext = .; | |||||
| _sidata = .; | |||||
| .data : AT (__etext) | |||||
| { | |||||
| __data_start__ = .; | |||||
| _sdata = .; | |||||
| *(vtable) | |||||
| *(.data*) | |||||
| . = ALIGN(4); | |||||
| /* preinit data */ | |||||
| PROVIDE_HIDDEN (__preinit_array_start = .); | |||||
| KEEP(*(.preinit_array)) | |||||
| PROVIDE_HIDDEN (__preinit_array_end = .); | |||||
| . = ALIGN(4); | |||||
| /* init data */ | |||||
| PROVIDE_HIDDEN (__init_array_start = .); | |||||
| KEEP(*(SORT(.init_array.*))) | |||||
| KEEP(*(.init_array)) | |||||
| PROVIDE_HIDDEN (__init_array_end = .); | |||||
| . = ALIGN(4); | |||||
| /* finit data */ | |||||
| PROVIDE_HIDDEN (__fini_array_start = .); | |||||
| KEEP(*(SORT(.fini_array.*))) | |||||
| KEEP(*(.fini_array)) | |||||
| PROVIDE_HIDDEN (__fini_array_end = .); | |||||
| KEEP(*(.jcr*)) | |||||
| . = ALIGN(4); | |||||
| /* All data end */ | |||||
| __data_end__ = .; | |||||
| _edata = .; | |||||
| } > RAM | |||||
| .bss : | |||||
| { | |||||
| . = ALIGN(4); | |||||
| __bss_start__ = .; | |||||
| _sbss = .; | |||||
| *(.bss*) | |||||
| *(COMMON) | |||||
| . = ALIGN(4); | |||||
| __bss_end__ = .; | |||||
| _ebss = .; | |||||
| } > RAM | |||||
| .heap (COPY): | |||||
| { | |||||
| __end__ = .; | |||||
| end = __end__; | |||||
| *(.heap*) | |||||
| __HeapLimit = .; | |||||
| } > RAM | |||||
| /* .stack_dummy section doesn't contains any symbols. It is only | |||||
| * used for linker to calculate size of stack sections, and assign | |||||
| * values to stack symbols later */ | |||||
| .stack_dummy (COPY): | |||||
| { | |||||
| *(.stack*) | |||||
| } > RAM | |||||
| /* Set stack top to end of RAM, and stack limit move down by | |||||
| * size of stack_dummy section */ | |||||
| __StackTop = ORIGIN(RAM) + LENGTH(RAM); | |||||
| _estack = __StackTop; | |||||
| __StackLimit = __StackTop - SIZEOF(.stack_dummy); | |||||
| PROVIDE(__stack = __StackTop); | |||||
| /* Check if data + heap + stack exceeds RAM limit */ | |||||
| ASSERT(__StackLimit >= __HeapLimit, "region RAM overflowed with stack") | |||||
| } | |||||
| @@ -1,266 +1,266 @@ | |||||
| ;******************** (C) COPYRIGHT 2016 STMicroelectronics ******************** | |||||
| ;* File Name : startup_stm32l072xx.s | |||||
| ;* Author : MCD Application Team | |||||
| ;* Version : V1.7.1 | |||||
| ;* Date : 25-November-2016 | |||||
| ;* Description : STM32l072xx Devices vector table for MDK-ARM toolchain. | |||||
| ;* This module performs: | |||||
| ;* - Set the initial SP | |||||
| ;* - Set the initial PC == Reset_Handler | |||||
| ;* - Set the vector table entries with the exceptions ISR address | |||||
| ;* - Branches to __main in the C lbrary (which eventually | |||||
| ;* calls main()). | |||||
| ;* After Reset the Cortex-M0+ processor is in Thread mode, | |||||
| ;* priority is Privileged, and the Stack is set to Main. | |||||
| ;******************************************************************************* | |||||
| ;* | |||||
| ;* Redistribution and use in source and binary forms, with or without modification, | |||||
| ;* are permitted provided that the following conditions are met: | |||||
| ;* 1. Redistributions of source code must retain the above copyright notice, | |||||
| ;* this list of conditions and the following disclaimer. | |||||
| ;* 2. Redistributions in binary form must reproduce the above copyright notice, | |||||
| ;* this list of conditions and the following disclaimer in the documentation | |||||
| ;* and/or other materials provided with the distribution. | |||||
| ;* 3. Neither the name of STMicroelectronics nor the names of its contributors | |||||
| ;* may be used to endorse or promote products derived from this software | |||||
| ;* without specific prior written permission. | |||||
| ;* | |||||
| ;* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | |||||
| ;* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |||||
| ;* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |||||
| ;* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE | |||||
| ;* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |||||
| ;* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | |||||
| ;* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | |||||
| ;* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |||||
| ;* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |||||
| ;* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |||||
| ;* | |||||
| ;******************************************************************************* | |||||
| ; | |||||
| ; Amount of memory (in bytes) allocated for Stack | |||||
| ; Tailor this value to your application needs | |||||
| ; <h> Stack Configuration | |||||
| ; <o> Stack Size (in Bytes) <0x0-0xFFFFFFFF:8> | |||||
| ; </h> | |||||
| Stack_Size EQU 0x00000400 | |||||
| AREA STACK, NOINIT, READWRITE, ALIGN=3 | |||||
| Stack_Mem SPACE Stack_Size | |||||
| __initial_sp | |||||
| ; <h> Heap Configuration | |||||
| ; <o> Heap Size (in Bytes) <0x0-0xFFFFFFFF:8> | |||||
| ; </h> | |||||
| Heap_Size EQU 0x00000200 | |||||
| AREA HEAP, NOINIT, READWRITE, ALIGN=3 | |||||
| __heap_base | |||||
| Heap_Mem SPACE Heap_Size | |||||
| __heap_limit | |||||
| PRESERVE8 | |||||
| THUMB | |||||
| ; Vector Table Mapped to Address 0 at Reset | |||||
| AREA RESET, DATA, READONLY | |||||
| EXPORT __Vectors | |||||
| EXPORT __Vectors_End | |||||
| EXPORT __Vectors_Size | |||||
| __Vectors DCD __initial_sp ; Top of Stack | |||||
| DCD Reset_Handler ; Reset Handler | |||||
| DCD NMI_Handler ; NMI Handler | |||||
| DCD HardFault_Handler ; Hard Fault Handler | |||||
| DCD 0 ; Reserved | |||||
| DCD 0 ; Reserved | |||||
| DCD 0 ; Reserved | |||||
| DCD 0 ; Reserved | |||||
| DCD 0 ; Reserved | |||||
| DCD 0 ; Reserved | |||||
| DCD 0 ; Reserved | |||||
| DCD SVC_Handler ; SVCall Handler | |||||
| DCD 0 ; Reserved | |||||
| DCD 0 ; Reserved | |||||
| DCD PendSV_Handler ; PendSV Handler | |||||
| DCD SysTick_Handler ; SysTick Handler | |||||
| ; External Interrupts | |||||
| DCD WWDG_IRQHandler ; Window Watchdog | |||||
| DCD PVD_IRQHandler ; PVD through EXTI Line detect | |||||
| DCD RTC_IRQHandler ; RTC through EXTI Line | |||||
| DCD FLASH_IRQHandler ; FLASH | |||||
| DCD RCC_CRS_IRQHandler ; RCC and CRS | |||||
| DCD EXTI0_1_IRQHandler ; EXTI Line 0 and 1 | |||||
| DCD EXTI2_3_IRQHandler ; EXTI Line 2 and 3 | |||||
| DCD EXTI4_15_IRQHandler ; EXTI Line 4 to 15 | |||||
| DCD TSC_IRQHandler ; TSC | |||||
| DCD DMA1_Channel1_IRQHandler ; DMA1 Channel 1 | |||||
| DCD DMA1_Channel2_3_IRQHandler ; DMA1 Channel 2 and Channel 3 | |||||
| DCD DMA1_Channel4_5_6_7_IRQHandler ; DMA1 Channel 4, Channel 5, Channel 6 and Channel 7 | |||||
| DCD ADC1_COMP_IRQHandler ; ADC1, COMP1 and COMP2 | |||||
| DCD LPTIM1_IRQHandler ; LPTIM1 | |||||
| DCD USART4_5_IRQHandler ; USART4 and USART5 | |||||
| DCD TIM2_IRQHandler ; TIM2 | |||||
| DCD TIM3_IRQHandler ; TIM3 | |||||
| DCD TIM6_DAC_IRQHandler ; TIM6 and DAC | |||||
| DCD TIM7_IRQHandler ; TIM7 | |||||
| DCD 0 ; Reserved | |||||
| DCD TIM21_IRQHandler ; TIM21 | |||||
| DCD I2C3_IRQHandler ; I2C3 | |||||
| DCD TIM22_IRQHandler ; TIM22 | |||||
| DCD I2C1_IRQHandler ; I2C1 | |||||
| DCD I2C2_IRQHandler ; I2C2 | |||||
| DCD SPI1_IRQHandler ; SPI1 | |||||
| DCD SPI2_IRQHandler ; SPI2 | |||||
| DCD USART1_IRQHandler ; USART1 | |||||
| DCD USART2_IRQHandler ; USART2 | |||||
| DCD RNG_LPUART1_IRQHandler ; RNG and LPUART1 | |||||
| DCD 0 ; Reserved | |||||
| DCD USB_IRQHandler ; USB | |||||
| __Vectors_End | |||||
| __Vectors_Size EQU __Vectors_End - __Vectors | |||||
| AREA |.text|, CODE, READONLY | |||||
| ; Reset handler routine | |||||
| Reset_Handler PROC | |||||
| EXPORT Reset_Handler [WEAK] | |||||
| IMPORT __main | |||||
| IMPORT SystemInit | |||||
| LDR R0, =SystemInit | |||||
| BLX R0 | |||||
| LDR R0, =__main | |||||
| BX R0 | |||||
| ENDP | |||||
| ; Dummy Exception Handlers (infinite loops which can be modified) | |||||
| NMI_Handler PROC | |||||
| EXPORT NMI_Handler [WEAK] | |||||
| B . | |||||
| ENDP | |||||
| HardFault_Handler\ | |||||
| PROC | |||||
| EXPORT HardFault_Handler [WEAK] | |||||
| B . | |||||
| ENDP | |||||
| SVC_Handler PROC | |||||
| EXPORT SVC_Handler [WEAK] | |||||
| B . | |||||
| ENDP | |||||
| PendSV_Handler PROC | |||||
| EXPORT PendSV_Handler [WEAK] | |||||
| B . | |||||
| ENDP | |||||
| SysTick_Handler PROC | |||||
| EXPORT SysTick_Handler [WEAK] | |||||
| B . | |||||
| ENDP | |||||
| Default_Handler PROC | |||||
| EXPORT WWDG_IRQHandler [WEAK] | |||||
| EXPORT PVD_IRQHandler [WEAK] | |||||
| EXPORT RTC_IRQHandler [WEAK] | |||||
| EXPORT FLASH_IRQHandler [WEAK] | |||||
| EXPORT RCC_CRS_IRQHandler [WEAK] | |||||
| EXPORT EXTI0_1_IRQHandler [WEAK] | |||||
| EXPORT EXTI2_3_IRQHandler [WEAK] | |||||
| EXPORT EXTI4_15_IRQHandler [WEAK] | |||||
| EXPORT TSC_IRQHandler [WEAK] | |||||
| EXPORT DMA1_Channel1_IRQHandler [WEAK] | |||||
| EXPORT DMA1_Channel2_3_IRQHandler [WEAK] | |||||
| EXPORT DMA1_Channel4_5_6_7_IRQHandler [WEAK] | |||||
| EXPORT ADC1_COMP_IRQHandler [WEAK] | |||||
| EXPORT LPTIM1_IRQHandler [WEAK] | |||||
| EXPORT USART4_5_IRQHandler [WEAK] | |||||
| EXPORT TIM2_IRQHandler [WEAK] | |||||
| EXPORT TIM3_IRQHandler [WEAK] | |||||
| EXPORT TIM6_DAC_IRQHandler [WEAK] | |||||
| EXPORT TIM7_IRQHandler [WEAK] | |||||
| EXPORT TIM21_IRQHandler [WEAK] | |||||
| EXPORT TIM22_IRQHandler [WEAK] | |||||
| EXPORT I2C1_IRQHandler [WEAK] | |||||
| EXPORT I2C2_IRQHandler [WEAK] | |||||
| EXPORT I2C3_IRQHandler [WEAK] | |||||
| EXPORT SPI1_IRQHandler [WEAK] | |||||
| EXPORT SPI2_IRQHandler [WEAK] | |||||
| EXPORT USART1_IRQHandler [WEAK] | |||||
| EXPORT USART2_IRQHandler [WEAK] | |||||
| EXPORT RNG_LPUART1_IRQHandler [WEAK] | |||||
| EXPORT USB_IRQHandler [WEAK] | |||||
| WWDG_IRQHandler | |||||
| PVD_IRQHandler | |||||
| RTC_IRQHandler | |||||
| FLASH_IRQHandler | |||||
| RCC_CRS_IRQHandler | |||||
| EXTI0_1_IRQHandler | |||||
| EXTI2_3_IRQHandler | |||||
| EXTI4_15_IRQHandler | |||||
| TSC_IRQHandler | |||||
| DMA1_Channel1_IRQHandler | |||||
| DMA1_Channel2_3_IRQHandler | |||||
| DMA1_Channel4_5_6_7_IRQHandler | |||||
| ADC1_COMP_IRQHandler | |||||
| LPTIM1_IRQHandler | |||||
| USART4_5_IRQHandler | |||||
| TIM2_IRQHandler | |||||
| TIM3_IRQHandler | |||||
| TIM6_DAC_IRQHandler | |||||
| TIM7_IRQHandler | |||||
| TIM21_IRQHandler | |||||
| TIM22_IRQHandler | |||||
| I2C1_IRQHandler | |||||
| I2C2_IRQHandler | |||||
| I2C3_IRQHandler | |||||
| SPI1_IRQHandler | |||||
| SPI2_IRQHandler | |||||
| USART1_IRQHandler | |||||
| USART2_IRQHandler | |||||
| RNG_LPUART1_IRQHandler | |||||
| USB_IRQHandler | |||||
| B . | |||||
| ENDP | |||||
| ALIGN | |||||
| ;******************************************************************************* | |||||
| ; User Stack and Heap initialization | |||||
| ;******************************************************************************* | |||||
| IF :DEF:__MICROLIB | |||||
| EXPORT __initial_sp | |||||
| EXPORT __heap_base | |||||
| EXPORT __heap_limit | |||||
| ELSE | |||||
| IMPORT __use_two_region_memory | |||||
| EXPORT __user_initial_stackheap | |||||
| __user_initial_stackheap | |||||
| LDR R0, = Heap_Mem | |||||
| LDR R1, =(Stack_Mem + Stack_Size) | |||||
| LDR R2, = (Heap_Mem + Heap_Size) | |||||
| LDR R3, = Stack_Mem | |||||
| BX LR | |||||
| ALIGN | |||||
| ENDIF | |||||
| END | |||||
| ;************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE***** | |||||
| ;******************** (C) COPYRIGHT 2016 STMicroelectronics ******************** | |||||
| ;* File Name : startup_stm32l072xx.s | |||||
| ;* Author : MCD Application Team | |||||
| ;* Version : V1.7.1 | |||||
| ;* Date : 25-November-2016 | |||||
| ;* Description : STM32l072xx Devices vector table for MDK-ARM toolchain. | |||||
| ;* This module performs: | |||||
| ;* - Set the initial SP | |||||
| ;* - Set the initial PC == Reset_Handler | |||||
| ;* - Set the vector table entries with the exceptions ISR address | |||||
| ;* - Branches to __main in the C lbrary (which eventually | |||||
| ;* calls main()). | |||||
| ;* After Reset the Cortex-M0+ processor is in Thread mode, | |||||
| ;* priority is Privileged, and the Stack is set to Main. | |||||
| ;******************************************************************************* | |||||
| ;* | |||||
| ;* Redistribution and use in source and binary forms, with or without modification, | |||||
| ;* are permitted provided that the following conditions are met: | |||||
| ;* 1. Redistributions of source code must retain the above copyright notice, | |||||
| ;* this list of conditions and the following disclaimer. | |||||
| ;* 2. Redistributions in binary form must reproduce the above copyright notice, | |||||
| ;* this list of conditions and the following disclaimer in the documentation | |||||
| ;* and/or other materials provided with the distribution. | |||||
| ;* 3. Neither the name of STMicroelectronics nor the names of its contributors | |||||
| ;* may be used to endorse or promote products derived from this software | |||||
| ;* without specific prior written permission. | |||||
| ;* | |||||
| ;* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | |||||
| ;* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |||||
| ;* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |||||
| ;* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE | |||||
| ;* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |||||
| ;* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | |||||
| ;* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | |||||
| ;* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |||||
| ;* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |||||
| ;* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |||||
| ;* | |||||
| ;******************************************************************************* | |||||
| ; | |||||
| ; Amount of memory (in bytes) allocated for Stack | |||||
| ; Tailor this value to your application needs | |||||
| ; <h> Stack Configuration | |||||
| ; <o> Stack Size (in Bytes) <0x0-0xFFFFFFFF:8> | |||||
| ; </h> | |||||
| Stack_Size EQU 0x00000400 | |||||
| AREA STACK, NOINIT, READWRITE, ALIGN=3 | |||||
| Stack_Mem SPACE Stack_Size | |||||
| __initial_sp | |||||
| ; <h> Heap Configuration | |||||
| ; <o> Heap Size (in Bytes) <0x0-0xFFFFFFFF:8> | |||||
| ; </h> | |||||
| Heap_Size EQU 0x00000200 | |||||
| AREA HEAP, NOINIT, READWRITE, ALIGN=3 | |||||
| __heap_base | |||||
| Heap_Mem SPACE Heap_Size | |||||
| __heap_limit | |||||
| PRESERVE8 | |||||
| THUMB | |||||
| ; Vector Table Mapped to Address 0 at Reset | |||||
| AREA RESET, DATA, READONLY | |||||
| EXPORT __Vectors | |||||
| EXPORT __Vectors_End | |||||
| EXPORT __Vectors_Size | |||||
| __Vectors DCD __initial_sp ; Top of Stack | |||||
| DCD Reset_Handler ; Reset Handler | |||||
| DCD NMI_Handler ; NMI Handler | |||||
| DCD HardFault_Handler ; Hard Fault Handler | |||||
| DCD 0 ; Reserved | |||||
| DCD 0 ; Reserved | |||||
| DCD 0 ; Reserved | |||||
| DCD 0 ; Reserved | |||||
| DCD 0 ; Reserved | |||||
| DCD 0 ; Reserved | |||||
| DCD 0 ; Reserved | |||||
| DCD SVC_Handler ; SVCall Handler | |||||
| DCD 0 ; Reserved | |||||
| DCD 0 ; Reserved | |||||
| DCD PendSV_Handler ; PendSV Handler | |||||
| DCD SysTick_Handler ; SysTick Handler | |||||
| ; External Interrupts | |||||
| DCD WWDG_IRQHandler ; Window Watchdog | |||||
| DCD PVD_IRQHandler ; PVD through EXTI Line detect | |||||
| DCD RTC_IRQHandler ; RTC through EXTI Line | |||||
| DCD FLASH_IRQHandler ; FLASH | |||||
| DCD RCC_CRS_IRQHandler ; RCC and CRS | |||||
| DCD EXTI0_1_IRQHandler ; EXTI Line 0 and 1 | |||||
| DCD EXTI2_3_IRQHandler ; EXTI Line 2 and 3 | |||||
| DCD EXTI4_15_IRQHandler ; EXTI Line 4 to 15 | |||||
| DCD TSC_IRQHandler ; TSC | |||||
| DCD DMA1_Channel1_IRQHandler ; DMA1 Channel 1 | |||||
| DCD DMA1_Channel2_3_IRQHandler ; DMA1 Channel 2 and Channel 3 | |||||
| DCD DMA1_Channel4_5_6_7_IRQHandler ; DMA1 Channel 4, Channel 5, Channel 6 and Channel 7 | |||||
| DCD ADC1_COMP_IRQHandler ; ADC1, COMP1 and COMP2 | |||||
| DCD LPTIM1_IRQHandler ; LPTIM1 | |||||
| DCD USART4_5_IRQHandler ; USART4 and USART5 | |||||
| DCD TIM2_IRQHandler ; TIM2 | |||||
| DCD TIM3_IRQHandler ; TIM3 | |||||
| DCD TIM6_DAC_IRQHandler ; TIM6 and DAC | |||||
| DCD TIM7_IRQHandler ; TIM7 | |||||
| DCD 0 ; Reserved | |||||
| DCD TIM21_IRQHandler ; TIM21 | |||||
| DCD I2C3_IRQHandler ; I2C3 | |||||
| DCD TIM22_IRQHandler ; TIM22 | |||||
| DCD I2C1_IRQHandler ; I2C1 | |||||
| DCD I2C2_IRQHandler ; I2C2 | |||||
| DCD SPI1_IRQHandler ; SPI1 | |||||
| DCD SPI2_IRQHandler ; SPI2 | |||||
| DCD USART1_IRQHandler ; USART1 | |||||
| DCD USART2_IRQHandler ; USART2 | |||||
| DCD RNG_LPUART1_IRQHandler ; RNG and LPUART1 | |||||
| DCD 0 ; Reserved | |||||
| DCD USB_IRQHandler ; USB | |||||
| __Vectors_End | |||||
| __Vectors_Size EQU __Vectors_End - __Vectors | |||||
| AREA |.text|, CODE, READONLY | |||||
| ; Reset handler routine | |||||
| Reset_Handler PROC | |||||
| EXPORT Reset_Handler [WEAK] | |||||
| IMPORT __main | |||||
| IMPORT SystemInit | |||||
| LDR R0, =SystemInit | |||||
| BLX R0 | |||||
| LDR R0, =__main | |||||
| BX R0 | |||||
| ENDP | |||||
| ; Dummy Exception Handlers (infinite loops which can be modified) | |||||
| NMI_Handler PROC | |||||
| EXPORT NMI_Handler [WEAK] | |||||
| B . | |||||
| ENDP | |||||
| HardFault_Handler\ | |||||
| PROC | |||||
| EXPORT HardFault_Handler [WEAK] | |||||
| B . | |||||
| ENDP | |||||
| SVC_Handler PROC | |||||
| EXPORT SVC_Handler [WEAK] | |||||
| B . | |||||
| ENDP | |||||
| PendSV_Handler PROC | |||||
| EXPORT PendSV_Handler [WEAK] | |||||
| B . | |||||
| ENDP | |||||
| SysTick_Handler PROC | |||||
| EXPORT SysTick_Handler [WEAK] | |||||
| B . | |||||
| ENDP | |||||
| Default_Handler PROC | |||||
| EXPORT WWDG_IRQHandler [WEAK] | |||||
| EXPORT PVD_IRQHandler [WEAK] | |||||
| EXPORT RTC_IRQHandler [WEAK] | |||||
| EXPORT FLASH_IRQHandler [WEAK] | |||||
| EXPORT RCC_CRS_IRQHandler [WEAK] | |||||
| EXPORT EXTI0_1_IRQHandler [WEAK] | |||||
| EXPORT EXTI2_3_IRQHandler [WEAK] | |||||
| EXPORT EXTI4_15_IRQHandler [WEAK] | |||||
| EXPORT TSC_IRQHandler [WEAK] | |||||
| EXPORT DMA1_Channel1_IRQHandler [WEAK] | |||||
| EXPORT DMA1_Channel2_3_IRQHandler [WEAK] | |||||
| EXPORT DMA1_Channel4_5_6_7_IRQHandler [WEAK] | |||||
| EXPORT ADC1_COMP_IRQHandler [WEAK] | |||||
| EXPORT LPTIM1_IRQHandler [WEAK] | |||||
| EXPORT USART4_5_IRQHandler [WEAK] | |||||
| EXPORT TIM2_IRQHandler [WEAK] | |||||
| EXPORT TIM3_IRQHandler [WEAK] | |||||
| EXPORT TIM6_DAC_IRQHandler [WEAK] | |||||
| EXPORT TIM7_IRQHandler [WEAK] | |||||
| EXPORT TIM21_IRQHandler [WEAK] | |||||
| EXPORT TIM22_IRQHandler [WEAK] | |||||
| EXPORT I2C1_IRQHandler [WEAK] | |||||
| EXPORT I2C2_IRQHandler [WEAK] | |||||
| EXPORT I2C3_IRQHandler [WEAK] | |||||
| EXPORT SPI1_IRQHandler [WEAK] | |||||
| EXPORT SPI2_IRQHandler [WEAK] | |||||
| EXPORT USART1_IRQHandler [WEAK] | |||||
| EXPORT USART2_IRQHandler [WEAK] | |||||
| EXPORT RNG_LPUART1_IRQHandler [WEAK] | |||||
| EXPORT USB_IRQHandler [WEAK] | |||||
| WWDG_IRQHandler | |||||
| PVD_IRQHandler | |||||
| RTC_IRQHandler | |||||
| FLASH_IRQHandler | |||||
| RCC_CRS_IRQHandler | |||||
| EXTI0_1_IRQHandler | |||||
| EXTI2_3_IRQHandler | |||||
| EXTI4_15_IRQHandler | |||||
| TSC_IRQHandler | |||||
| DMA1_Channel1_IRQHandler | |||||
| DMA1_Channel2_3_IRQHandler | |||||
| DMA1_Channel4_5_6_7_IRQHandler | |||||
| ADC1_COMP_IRQHandler | |||||
| LPTIM1_IRQHandler | |||||
| USART4_5_IRQHandler | |||||
| TIM2_IRQHandler | |||||
| TIM3_IRQHandler | |||||
| TIM6_DAC_IRQHandler | |||||
| TIM7_IRQHandler | |||||
| TIM21_IRQHandler | |||||
| TIM22_IRQHandler | |||||
| I2C1_IRQHandler | |||||
| I2C2_IRQHandler | |||||
| I2C3_IRQHandler | |||||
| SPI1_IRQHandler | |||||
| SPI2_IRQHandler | |||||
| USART1_IRQHandler | |||||
| USART2_IRQHandler | |||||
| RNG_LPUART1_IRQHandler | |||||
| USB_IRQHandler | |||||
| B . | |||||
| ENDP | |||||
| ALIGN | |||||
| ;******************************************************************************* | |||||
| ; User Stack and Heap initialization | |||||
| ;******************************************************************************* | |||||
| IF :DEF:__MICROLIB | |||||
| EXPORT __initial_sp | |||||
| EXPORT __heap_base | |||||
| EXPORT __heap_limit | |||||
| ELSE | |||||
| IMPORT __use_two_region_memory | |||||
| EXPORT __user_initial_stackheap | |||||
| __user_initial_stackheap | |||||
| LDR R0, = Heap_Mem | |||||
| LDR R1, =(Stack_Mem + Stack_Size) | |||||
| LDR R2, = (Heap_Mem + Heap_Size) | |||||
| LDR R3, = Stack_Mem | |||||
| BX LR | |||||
| ALIGN | |||||
| ENDIF | |||||
| END | |||||
| ;************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE***** | |||||
| @@ -1,57 +1,57 @@ | |||||
| /** | |||||
| ****************************************************************************** | |||||
| * File Name : mxconstants.h | |||||
| * Description : This file contains the common defines of the application | |||||
| ****************************************************************************** | |||||
| * | |||||
| * COPYRIGHT(c) 2016 STMicroelectronics | |||||
| * | |||||
| * Redistribution and use in source and binary forms, with or without modification, | |||||
| * are permitted provided that the following conditions are met: | |||||
| * 1. Redistributions of source code must retain the above copyright notice, | |||||
| * this list of conditions and the following disclaimer. | |||||
| * 2. Redistributions in binary form must reproduce the above copyright notice, | |||||
| * this list of conditions and the following disclaimer in the documentation | |||||
| * and/or other materials provided with the distribution. | |||||
| * 3. Neither the name of STMicroelectronics nor the names of its contributors | |||||
| * may be used to endorse or promote products derived from this software | |||||
| * without specific prior written permission. | |||||
| * | |||||
| * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | |||||
| * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |||||
| * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |||||
| * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE | |||||
| * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |||||
| * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | |||||
| * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | |||||
| * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |||||
| * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |||||
| * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |||||
| * | |||||
| ****************************************************************************** | |||||
| */ | |||||
| /* Define to prevent recursive inclusion -------------------------------------*/ | |||||
| #ifndef __MXCONSTANT_H | |||||
| #define __MXCONSTANT_H | |||||
| /* Includes ------------------------------------------------------------------*/ | |||||
| /* USER CODE BEGIN Includes */ | |||||
| /* USER CODE END Includes */ | |||||
| /* Private define ------------------------------------------------------------*/ | |||||
| /* USER CODE BEGIN Private defines */ | |||||
| /* USER CODE END Private defines */ | |||||
| /** | |||||
| * @} | |||||
| */ | |||||
| /** | |||||
| * @} | |||||
| */ | |||||
| #endif /* __MXCONSTANT_H */ | |||||
| /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ | |||||
| /** | |||||
| ****************************************************************************** | |||||
| * File Name : mxconstants.h | |||||
| * Description : This file contains the common defines of the application | |||||
| ****************************************************************************** | |||||
| * | |||||
| * COPYRIGHT(c) 2016 STMicroelectronics | |||||
| * | |||||
| * Redistribution and use in source and binary forms, with or without modification, | |||||
| * are permitted provided that the following conditions are met: | |||||
| * 1. Redistributions of source code must retain the above copyright notice, | |||||
| * this list of conditions and the following disclaimer. | |||||
| * 2. Redistributions in binary form must reproduce the above copyright notice, | |||||
| * this list of conditions and the following disclaimer in the documentation | |||||
| * and/or other materials provided with the distribution. | |||||
| * 3. Neither the name of STMicroelectronics nor the names of its contributors | |||||
| * may be used to endorse or promote products derived from this software | |||||
| * without specific prior written permission. | |||||
| * | |||||
| * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | |||||
| * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |||||
| * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |||||
| * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE | |||||
| * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |||||
| * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | |||||
| * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | |||||
| * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |||||
| * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |||||
| * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |||||
| * | |||||
| ****************************************************************************** | |||||
| */ | |||||
| /* Define to prevent recursive inclusion -------------------------------------*/ | |||||
| #ifndef __MXCONSTANT_H | |||||
| #define __MXCONSTANT_H | |||||
| /* Includes ------------------------------------------------------------------*/ | |||||
| /* USER CODE BEGIN Includes */ | |||||
| /* USER CODE END Includes */ | |||||
| /* Private define ------------------------------------------------------------*/ | |||||
| /* USER CODE BEGIN Private defines */ | |||||
| /* USER CODE END Private defines */ | |||||
| /** | |||||
| * @} | |||||
| */ | |||||
| /** | |||||
| * @} | |||||
| */ | |||||
| #endif /* __MXCONSTANT_H */ | |||||
| /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ | |||||
| @@ -1,241 +1,241 @@ | |||||
| /** | |||||
| ****************************************************************************** | |||||
| * @file stm32l0xx.h | |||||
| * @author MCD Application Team | |||||
| * @brief CMSIS Cortex-M0+ Device Peripheral Access Layer Header File. | |||||
| * This file contains all the peripheral register's definitions, bits | |||||
| * definitions and memory mapping for STM32L0xx devices. | |||||
| * | |||||
| * The file is the unique include file that the application programmer | |||||
| * is using in the C source code, usually in main.c. This file contains: | |||||
| * - Configuration section that allows to select: | |||||
| * - The device used in the target application | |||||
| * - To use or not the peripheral's drivers in application code(i.e. | |||||
| * code will be based on direct access to peripheral's registers | |||||
| * rather than drivers API), this option is controlled by | |||||
| * "#define USE_HAL_DRIVER" | |||||
| * | |||||
| ****************************************************************************** | |||||
| * @attention | |||||
| * | |||||
| * <h2><center>© COPYRIGHT(c) 2016 STMicroelectronics</center></h2> | |||||
| * | |||||
| * Redistribution and use in source and binary forms, with or without modification, | |||||
| * are permitted provided that the following conditions are met: | |||||
| * 1. Redistributions of source code must retain the above copyright notice, | |||||
| * this list of conditions and the following disclaimer. | |||||
| * 2. Redistributions in binary form must reproduce the above copyright notice, | |||||
| * this list of conditions and the following disclaimer in the documentation | |||||
| * and/or other materials provided with the distribution. | |||||
| * 3. Neither the name of STMicroelectronics nor the names of its contributors | |||||
| * may be used to endorse or promote products derived from this software | |||||
| * without specific prior written permission. | |||||
| * | |||||
| * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | |||||
| * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |||||
| * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |||||
| * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE | |||||
| * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |||||
| * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | |||||
| * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | |||||
| * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |||||
| * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |||||
| * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |||||
| * | |||||
| ****************************************************************************** | |||||
| */ | |||||
| /** @addtogroup CMSIS | |||||
| * @{ | |||||
| */ | |||||
| /** @addtogroup stm32l0xx | |||||
| * @{ | |||||
| */ | |||||
| #ifndef __STM32L0xx_H | |||||
| #define __STM32L0xx_H | |||||
| #ifdef __cplusplus | |||||
| extern "C" { | |||||
| #endif /* __cplusplus */ | |||||
| /** @addtogroup Library_configuration_section | |||||
| * @{ | |||||
| */ | |||||
| /** | |||||
| * @brief STM32 Family | |||||
| */ | |||||
| #if !defined (STM32L0) | |||||
| #define STM32L0 | |||||
| #endif /* STM32L0 */ | |||||
| /* Uncomment the line below according to the target STM32 device used in your | |||||
| application | |||||
| */ | |||||
| #if !defined (STM32L011xx) && !defined (STM32L021xx) && \ | |||||
| !defined (STM32L031xx) && !defined (STM32L041xx) && \ | |||||
| !defined (STM32L051xx) && !defined (STM32L052xx) && !defined (STM32L053xx) && \ | |||||
| !defined (STM32L061xx) && !defined (STM32L062xx) && !defined (STM32L063xx) && \ | |||||
| !defined (STM32L071xx) && !defined (STM32L072xx) && !defined (STM32L073xx) && \ | |||||
| !defined (STM32L081xx) && !defined (STM32L082xx) && !defined (STM32L083xx) \ | |||||
| /* #define STM32L011xx */ | |||||
| /* #define STM32L021xx */ | |||||
| /* #define STM32L031xx */ /*!< STM32L031C6, STM32L031E6, STM32L031F6, STM32L031G6, STM32L031K6 Devices */ | |||||
| /* #define STM32L041xx */ /*!< STM32L041C6, STM32L041E6, STM32L041F6, STM32L041G6, STM32L041K6 Devices */ | |||||
| /* #define STM32L051xx */ /*!< STM32L051K8, STM32L051C6, STM32L051C8, STM32L051R6, STM32L051R8 Devices */ | |||||
| /* #define STM32L052xx */ /*!< STM32L052K6, STM32L052K8, STM32L052C6, STM32L052C8, STM32L052R6, STM32L052R8 Devices */ | |||||
| /* #define STM32L053xx */ /*!< STM32L053C6, STM32L053C8, STM32L053R6, STM32L053R8 Devices */ | |||||
| /* #define STM32L061xx */ /*!< */ | |||||
| /* #define STM32L062xx */ /*!< STM32L062K8 */ | |||||
| /* #define STM32L063xx */ /*!< STM32L063C8, STM32L063R8 */ | |||||
| /* #define STM32L071xx */ /*!< */ | |||||
| /* #define STM32L072xx */ /*!< */ | |||||
| /* #define STM32L073xx */ /*!< STM32L073V8, STM32L073VB, STM32L073RB, STM32L073VZ, STM32L073RZ Devices */ | |||||
| /* #define STM32L081xx */ /*!< */ | |||||
| /* #define STM32L082xx */ /*!< */ | |||||
| /* #define STM32L083xx */ /*!< */ | |||||
| #endif | |||||
| /* Tip: To avoid modifying this file each time you need to switch between these | |||||
| devices, you can define the device in your toolchain compiler preprocessor. | |||||
| */ | |||||
| #if !defined (USE_HAL_DRIVER) | |||||
| /** | |||||
| * @brief Comment the line below if you will not use the peripherals drivers. | |||||
| In this case, these drivers will not be included and the application code will | |||||
| be based on direct access to peripherals registers | |||||
| */ | |||||
| /*#define USE_HAL_DRIVER */ | |||||
| #endif /* USE_HAL_DRIVER */ | |||||
| /** | |||||
| * @brief CMSIS Device version number V1.7.1 | |||||
| */ | |||||
| #define __STM32L0xx_CMSIS_VERSION_MAIN (0x01) /*!< [31:24] main version */ | |||||
| #define __STM32L0xx_CMSIS_VERSION_SUB1 (0x07) /*!< [23:16] sub1 version */ | |||||
| #define __STM32L0xx_CMSIS_VERSION_SUB2 (0x02) /*!< [15:8] sub2 version */ | |||||
| #define __STM32L0xx_CMSIS_VERSION_RC (0x00) /*!< [7:0] release candidate */ | |||||
| #define __STM32L0xx_CMSIS_VERSION ((__STM32L0xx_CMSIS_VERSION_MAIN << 24)\ | |||||
| |(__STM32L0xx_CMSIS_VERSION_SUB1 << 16)\ | |||||
| |(__STM32L0xx_CMSIS_VERSION_SUB2 << 8 )\ | |||||
| |(__STM32L0xx_CMSIS_VERSION_RC)) | |||||
| /** | |||||
| * @} | |||||
| */ | |||||
| /** @addtogroup Device_Included | |||||
| * @{ | |||||
| */ | |||||
| #if defined(STM32L011xx) | |||||
| #include "stm32l011xx.h" | |||||
| #elif defined(STM32L021xx) | |||||
| #include "stm32l021xx.h" | |||||
| #elif defined(STM32L031xx) | |||||
| #include "stm32l031xx.h" | |||||
| #elif defined(STM32L041xx) | |||||
| #include "stm32l041xx.h" | |||||
| #elif defined(STM32L051xx) | |||||
| #include "stm32l051xx.h" | |||||
| #elif defined(STM32L052xx) | |||||
| #include "stm32l052xx.h" | |||||
| #elif defined(STM32L053xx) | |||||
| #include "stm32l053xx.h" | |||||
| #elif defined(STM32L062xx) | |||||
| #include "stm32l062xx.h" | |||||
| #elif defined(STM32L063xx) | |||||
| #include "stm32l063xx.h" | |||||
| #elif defined(STM32L061xx) | |||||
| #include "stm32l061xx.h" | |||||
| #elif defined(STM32L071xx) | |||||
| #include "stm32l071xx.h" | |||||
| #elif defined(STM32L072xx) | |||||
| #include "stm32l072xx.h" | |||||
| #elif defined(STM32L073xx) | |||||
| #include "stm32l073xx.h" | |||||
| #elif defined(STM32L082xx) | |||||
| #include "stm32l082xx.h" | |||||
| #elif defined(STM32L083xx) | |||||
| #include "stm32l083xx.h" | |||||
| #elif defined(STM32L081xx) | |||||
| #include "stm32l081xx.h" | |||||
| #else | |||||
| #error "Please select first the target STM32L0xx device used in your application (in stm32l0xx.h file)" | |||||
| #endif | |||||
| /** | |||||
| * @} | |||||
| */ | |||||
| /** @addtogroup Exported_types | |||||
| * @{ | |||||
| */ | |||||
| typedef enum | |||||
| { | |||||
| RESET = 0, | |||||
| SET = !RESET | |||||
| } FlagStatus, ITStatus; | |||||
| typedef enum | |||||
| { | |||||
| DISABLE = 0, | |||||
| ENABLE = !DISABLE | |||||
| } FunctionalState; | |||||
| #define IS_FUNCTIONAL_STATE(STATE) (((STATE) == DISABLE) || ((STATE) == ENABLE)) | |||||
| typedef enum | |||||
| { | |||||
| ERROR = 0, | |||||
| SUCCESS = !ERROR | |||||
| } ErrorStatus; | |||||
| /** | |||||
| * @} | |||||
| */ | |||||
| /** @addtogroup Exported_macro | |||||
| * @{ | |||||
| */ | |||||
| #define SET_BIT(REG, BIT) ((REG) |= (BIT)) | |||||
| #define CLEAR_BIT(REG, BIT) ((REG) &= ~(BIT)) | |||||
| #define READ_BIT(REG, BIT) ((REG) & (BIT)) | |||||
| #define CLEAR_REG(REG) ((REG) = (0x0)) | |||||
| #define WRITE_REG(REG, VAL) ((REG) = (VAL)) | |||||
| #define READ_REG(REG) ((REG)) | |||||
| #define MODIFY_REG(REG, CLEARMASK, SETMASK) WRITE_REG((REG), (((READ_REG(REG)) & (~(CLEARMASK))) | (SETMASK))) | |||||
| /** | |||||
| * @} | |||||
| */ | |||||
| #if defined (USE_HAL_DRIVER) | |||||
| #include "stm32l0xx_hal.h" | |||||
| #endif /* USE_HAL_DRIVER */ | |||||
| #ifdef __cplusplus | |||||
| } | |||||
| #endif /* __cplusplus */ | |||||
| #endif /* __STM32L0xx_H */ | |||||
| /** | |||||
| * @} | |||||
| */ | |||||
| /** | |||||
| * @} | |||||
| */ | |||||
| /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ | |||||
| /** | |||||
| ****************************************************************************** | |||||
| * @file stm32l0xx.h | |||||
| * @author MCD Application Team | |||||
| * @brief CMSIS Cortex-M0+ Device Peripheral Access Layer Header File. | |||||
| * This file contains all the peripheral register's definitions, bits | |||||
| * definitions and memory mapping for STM32L0xx devices. | |||||
| * | |||||
| * The file is the unique include file that the application programmer | |||||
| * is using in the C source code, usually in main.c. This file contains: | |||||
| * - Configuration section that allows to select: | |||||
| * - The device used in the target application | |||||
| * - To use or not the peripheral's drivers in application code(i.e. | |||||
| * code will be based on direct access to peripheral's registers | |||||
| * rather than drivers API), this option is controlled by | |||||
| * "#define USE_HAL_DRIVER" | |||||
| * | |||||
| ****************************************************************************** | |||||
| * @attention | |||||
| * | |||||
| * <h2><center>© COPYRIGHT(c) 2016 STMicroelectronics</center></h2> | |||||
| * | |||||
| * Redistribution and use in source and binary forms, with or without modification, | |||||
| * are permitted provided that the following conditions are met: | |||||
| * 1. Redistributions of source code must retain the above copyright notice, | |||||
| * this list of conditions and the following disclaimer. | |||||
| * 2. Redistributions in binary form must reproduce the above copyright notice, | |||||
| * this list of conditions and the following disclaimer in the documentation | |||||
| * and/or other materials provided with the distribution. | |||||
| * 3. Neither the name of STMicroelectronics nor the names of its contributors | |||||
| * may be used to endorse or promote products derived from this software | |||||
| * without specific prior written permission. | |||||
| * | |||||
| * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | |||||
| * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |||||
| * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |||||
| * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE | |||||
| * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |||||
| * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | |||||
| * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | |||||
| * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |||||
| * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |||||
| * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |||||
| * | |||||
| ****************************************************************************** | |||||
| */ | |||||
| /** @addtogroup CMSIS | |||||
| * @{ | |||||
| */ | |||||
| /** @addtogroup stm32l0xx | |||||
| * @{ | |||||
| */ | |||||
| #ifndef __STM32L0xx_H | |||||
| #define __STM32L0xx_H | |||||
| #ifdef __cplusplus | |||||
| extern "C" { | |||||
| #endif /* __cplusplus */ | |||||
| /** @addtogroup Library_configuration_section | |||||
| * @{ | |||||
| */ | |||||
| /** | |||||
| * @brief STM32 Family | |||||
| */ | |||||
| #if !defined (STM32L0) | |||||
| #define STM32L0 | |||||
| #endif /* STM32L0 */ | |||||
| /* Uncomment the line below according to the target STM32 device used in your | |||||
| application | |||||
| */ | |||||
| #if !defined (STM32L011xx) && !defined (STM32L021xx) && \ | |||||
| !defined (STM32L031xx) && !defined (STM32L041xx) && \ | |||||
| !defined (STM32L051xx) && !defined (STM32L052xx) && !defined (STM32L053xx) && \ | |||||
| !defined (STM32L061xx) && !defined (STM32L062xx) && !defined (STM32L063xx) && \ | |||||
| !defined (STM32L071xx) && !defined (STM32L072xx) && !defined (STM32L073xx) && \ | |||||
| !defined (STM32L081xx) && !defined (STM32L082xx) && !defined (STM32L083xx) \ | |||||
| /* #define STM32L011xx */ | |||||
| /* #define STM32L021xx */ | |||||
| /* #define STM32L031xx */ /*!< STM32L031C6, STM32L031E6, STM32L031F6, STM32L031G6, STM32L031K6 Devices */ | |||||
| /* #define STM32L041xx */ /*!< STM32L041C6, STM32L041E6, STM32L041F6, STM32L041G6, STM32L041K6 Devices */ | |||||
| /* #define STM32L051xx */ /*!< STM32L051K8, STM32L051C6, STM32L051C8, STM32L051R6, STM32L051R8 Devices */ | |||||
| /* #define STM32L052xx */ /*!< STM32L052K6, STM32L052K8, STM32L052C6, STM32L052C8, STM32L052R6, STM32L052R8 Devices */ | |||||
| /* #define STM32L053xx */ /*!< STM32L053C6, STM32L053C8, STM32L053R6, STM32L053R8 Devices */ | |||||
| /* #define STM32L061xx */ /*!< */ | |||||
| /* #define STM32L062xx */ /*!< STM32L062K8 */ | |||||
| /* #define STM32L063xx */ /*!< STM32L063C8, STM32L063R8 */ | |||||
| /* #define STM32L071xx */ /*!< */ | |||||
| /* #define STM32L072xx */ /*!< */ | |||||
| /* #define STM32L073xx */ /*!< STM32L073V8, STM32L073VB, STM32L073RB, STM32L073VZ, STM32L073RZ Devices */ | |||||
| /* #define STM32L081xx */ /*!< */ | |||||
| /* #define STM32L082xx */ /*!< */ | |||||
| /* #define STM32L083xx */ /*!< */ | |||||
| #endif | |||||
| /* Tip: To avoid modifying this file each time you need to switch between these | |||||
| devices, you can define the device in your toolchain compiler preprocessor. | |||||
| */ | |||||
| #if !defined (USE_HAL_DRIVER) | |||||
| /** | |||||
| * @brief Comment the line below if you will not use the peripherals drivers. | |||||
| In this case, these drivers will not be included and the application code will | |||||
| be based on direct access to peripherals registers | |||||
| */ | |||||
| /*#define USE_HAL_DRIVER */ | |||||
| #endif /* USE_HAL_DRIVER */ | |||||
| /** | |||||
| * @brief CMSIS Device version number V1.7.1 | |||||
| */ | |||||
| #define __STM32L0xx_CMSIS_VERSION_MAIN (0x01) /*!< [31:24] main version */ | |||||
| #define __STM32L0xx_CMSIS_VERSION_SUB1 (0x07) /*!< [23:16] sub1 version */ | |||||
| #define __STM32L0xx_CMSIS_VERSION_SUB2 (0x02) /*!< [15:8] sub2 version */ | |||||
| #define __STM32L0xx_CMSIS_VERSION_RC (0x00) /*!< [7:0] release candidate */ | |||||
| #define __STM32L0xx_CMSIS_VERSION ((__STM32L0xx_CMSIS_VERSION_MAIN << 24)\ | |||||
| |(__STM32L0xx_CMSIS_VERSION_SUB1 << 16)\ | |||||
| |(__STM32L0xx_CMSIS_VERSION_SUB2 << 8 )\ | |||||
| |(__STM32L0xx_CMSIS_VERSION_RC)) | |||||
| /** | |||||
| * @} | |||||
| */ | |||||
| /** @addtogroup Device_Included | |||||
| * @{ | |||||
| */ | |||||
| #if defined(STM32L011xx) | |||||
| #include "stm32l011xx.h" | |||||
| #elif defined(STM32L021xx) | |||||
| #include "stm32l021xx.h" | |||||
| #elif defined(STM32L031xx) | |||||
| #include "stm32l031xx.h" | |||||
| #elif defined(STM32L041xx) | |||||
| #include "stm32l041xx.h" | |||||
| #elif defined(STM32L051xx) | |||||
| #include "stm32l051xx.h" | |||||
| #elif defined(STM32L052xx) | |||||
| #include "stm32l052xx.h" | |||||
| #elif defined(STM32L053xx) | |||||
| #include "stm32l053xx.h" | |||||
| #elif defined(STM32L062xx) | |||||
| #include "stm32l062xx.h" | |||||
| #elif defined(STM32L063xx) | |||||
| #include "stm32l063xx.h" | |||||
| #elif defined(STM32L061xx) | |||||
| #include "stm32l061xx.h" | |||||
| #elif defined(STM32L071xx) | |||||
| #include "stm32l071xx.h" | |||||
| #elif defined(STM32L072xx) | |||||
| #include "stm32l072xx.h" | |||||
| #elif defined(STM32L073xx) | |||||
| #include "stm32l073xx.h" | |||||
| #elif defined(STM32L082xx) | |||||
| #include "stm32l082xx.h" | |||||
| #elif defined(STM32L083xx) | |||||
| #include "stm32l083xx.h" | |||||
| #elif defined(STM32L081xx) | |||||
| #include "stm32l081xx.h" | |||||
| #else | |||||
| #error "Please select first the target STM32L0xx device used in your application (in stm32l0xx.h file)" | |||||
| #endif | |||||
| /** | |||||
| * @} | |||||
| */ | |||||
| /** @addtogroup Exported_types | |||||
| * @{ | |||||
| */ | |||||
| typedef enum | |||||
| { | |||||
| RESET = 0, | |||||
| SET = !RESET | |||||
| } FlagStatus, ITStatus; | |||||
| typedef enum | |||||
| { | |||||
| DISABLE = 0, | |||||
| ENABLE = !DISABLE | |||||
| } FunctionalState; | |||||
| #define IS_FUNCTIONAL_STATE(STATE) (((STATE) == DISABLE) || ((STATE) == ENABLE)) | |||||
| typedef enum | |||||
| { | |||||
| ERROR = 0, | |||||
| SUCCESS = !ERROR | |||||
| } ErrorStatus; | |||||
| /** | |||||
| * @} | |||||
| */ | |||||
| /** @addtogroup Exported_macro | |||||
| * @{ | |||||
| */ | |||||
| #define SET_BIT(REG, BIT) ((REG) |= (BIT)) | |||||
| #define CLEAR_BIT(REG, BIT) ((REG) &= ~(BIT)) | |||||
| #define READ_BIT(REG, BIT) ((REG) & (BIT)) | |||||
| #define CLEAR_REG(REG) ((REG) = (0x0)) | |||||
| #define WRITE_REG(REG, VAL) ((REG) = (VAL)) | |||||
| #define READ_REG(REG) ((REG)) | |||||
| #define MODIFY_REG(REG, CLEARMASK, SETMASK) WRITE_REG((REG), (((READ_REG(REG)) & (~(CLEARMASK))) | (SETMASK))) | |||||
| /** | |||||
| * @} | |||||
| */ | |||||
| #if defined (USE_HAL_DRIVER) | |||||
| #include "stm32l0xx_hal.h" | |||||
| #endif /* USE_HAL_DRIVER */ | |||||
| #ifdef __cplusplus | |||||
| } | |||||
| #endif /* __cplusplus */ | |||||
| #endif /* __STM32L0xx_H */ | |||||
| /** | |||||
| * @} | |||||
| */ | |||||
| /** | |||||
| * @} | |||||
| */ | |||||
| /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ | |||||
| @@ -1,318 +1,318 @@ | |||||
| /** | |||||
| ****************************************************************************** | |||||
| * @file stm32l0xx_hal_conf.h | |||||
| * @author MCD Application Team | |||||
| * @version V1.1.4 | |||||
| * @date 08-January-2018 | |||||
| * @brief HAL configuration file. | |||||
| ****************************************************************************** | |||||
| * @attention | |||||
| * | |||||
| * <h2><center>© Copyright (c) 2017 STMicroelectronics International N.V. | |||||
| * All rights reserved.</center></h2> | |||||
| * | |||||
| * Redistribution and use in source and binary forms, with or without | |||||
| * modification, are permitted, provided that the following conditions are met: | |||||
| * | |||||
| * 1. Redistribution of source code must retain the above copyright notice, | |||||
| * this list of conditions and the following disclaimer. | |||||
| * 2. Redistributions in binary form must reproduce the above copyright notice, | |||||
| * this list of conditions and the following disclaimer in the documentation | |||||
| * and/or other materials provided with the distribution. | |||||
| * 3. Neither the name of STMicroelectronics nor the names of other | |||||
| * contributors to this software may be used to endorse or promote products | |||||
| * derived from this software without specific written permission. | |||||
| * 4. This software, including modifications and/or derivative works of this | |||||
| * software, must execute solely and exclusively on microcontroller or | |||||
| * microprocessor devices manufactured by or for STMicroelectronics. | |||||
| * 5. Redistribution and use of this software other than as permitted under | |||||
| * this license is void and will automatically terminate your rights under | |||||
| * this license. | |||||
| * | |||||
| * THIS SOFTWARE IS PROVIDED BY STMICROELECTRONICS AND CONTRIBUTORS "AS IS" | |||||
| * AND ANY EXPRESS, IMPLIED OR STATUTORY WARRANTIES, INCLUDING, BUT NOT | |||||
| * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A | |||||
| * PARTICULAR PURPOSE AND NON-INFRINGEMENT OF THIRD PARTY INTELLECTUAL PROPERTY | |||||
| * RIGHTS ARE DISCLAIMED TO THE FULLEST EXTENT PERMITTED BY LAW. IN NO EVENT | |||||
| * SHALL STMICROELECTRONICS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, | |||||
| * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |||||
| * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, | |||||
| * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF | |||||
| * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | |||||
| * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, | |||||
| * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |||||
| * | |||||
| ****************************************************************************** | |||||
| */ | |||||
| /* Define to prevent recursive inclusion -------------------------------------*/ | |||||
| #ifndef __STM32L0xx_HAL_CONF_H__ | |||||
| #define __STM32L0xx_HAL_CONF_H__ | |||||
| #ifdef __cplusplus | |||||
| extern "C" { | |||||
| #endif | |||||
| /* Exported types ------------------------------------------------------------*/ | |||||
| /* Exported constants --------------------------------------------------------*/ | |||||
| /* ########################## Module Selection ############################## */ | |||||
| /** | |||||
| * @brief This is the list of modules to be used in the HAL driver | |||||
| */ | |||||
| #define HAL_MODULE_ENABLED | |||||
| #define HAL_ADC_MODULE_ENABLED | |||||
| /* #define HAL_COMP_MODULE_ENABLED */ | |||||
| /* #define HAL_CRC_MODULE_ENABLED */ | |||||
| /* #define HAL_CRYP_MODULE_ENABLED */ | |||||
| /* #define HAL_DAC_MODULE_ENABLED */ | |||||
| #define HAL_DMA_MODULE_ENABLED | |||||
| #define HAL_FLASH_MODULE_ENABLED | |||||
| #define HAL_GPIO_MODULE_ENABLED | |||||
| #define HAL_I2C_MODULE_ENABLED | |||||
| /* #define HAL_I2S_MODULE_ENABLED */ | |||||
| #define HAL_IWDG_MODULE_ENABLED | |||||
| /* #define HAL_LCD_MODULE_ENABLED */ | |||||
| /* #define HAL_LPTIM_MODULE_ENABLED */ | |||||
| #define HAL_PWR_MODULE_ENABLED | |||||
| #define HAL_RCC_MODULE_ENABLED | |||||
| /* #define HAL_RNG_MODULE_ENABLED */ | |||||
| #define HAL_RTC_MODULE_ENABLED | |||||
| #define HAL_SPI_MODULE_ENABLED | |||||
| #define HAL_TIM_MODULE_ENABLED | |||||
| /* #define HAL_TSC_MODULE_ENABLED */ | |||||
| #define HAL_UART_MODULE_ENABLED | |||||
| /* #define HAL_USART_MODULE_ENABLED */ | |||||
| /* #define HAL_IRDA_MODULE_ENABLED */ | |||||
| /* #define HAL_SMARTCARD_MODULE_ENABLED */ | |||||
| /* #define HAL_SMBUS_MODULE_ENABLED */ | |||||
| /* #define HAL_WWDG_MODULE_ENABLED */ | |||||
| #define HAL_CORTEX_MODULE_ENABLED | |||||
| /* #define HAL_PCD_MODULE_ENABLED */ | |||||
| /* ########################## Oscillator Values adaptation ####################*/ | |||||
| /** | |||||
| * @brief Adjust the value of External High Speed oscillator (HSE) used in your application. | |||||
| * This value is used by the RCC HAL module to compute the system frequency | |||||
| * (when HSE is used as system clock source, directly or through the PLL). | |||||
| */ | |||||
| #if !defined (HSE_VALUE) | |||||
| #define HSE_VALUE ((uint32_t)8000000) /*!< Value of the External oscillator in Hz */ | |||||
| #endif /* HSE_VALUE */ | |||||
| #if !defined (HSE_STARTUP_TIMEOUT) | |||||
| #define HSE_STARTUP_TIMEOUT ((uint32_t)5000) /*!< Time out for HSE start up, in ms */ | |||||
| #endif /* HSE_STARTUP_TIMEOUT */ | |||||
| /** | |||||
| * @brief Internal Multiple Speed oscillator (MSI) default value. | |||||
| * This value is the default MSI range value after Reset. | |||||
| */ | |||||
| #if !defined (MSI_VALUE) | |||||
| #define MSI_VALUE ((uint32_t)2000000) /*!< Value of the Internal oscillator in Hz*/ | |||||
| #endif /* MSI_VALUE */ | |||||
| /** | |||||
| * @brief Internal High Speed oscillator (HSI) value. | |||||
| * This value is used by the RCC HAL module to compute the system frequency | |||||
| * (when HSI is used as system clock source, directly or through the PLL). | |||||
| */ | |||||
| #if !defined (HSI_VALUE) | |||||
| #define HSI_VALUE ((uint32_t)16000000) /*!< Value of the Internal oscillator in Hz*/ | |||||
| #endif /* HSI_VALUE */ | |||||
| /** | |||||
| * @brief Internal High Speed oscillator for USB (HSI48) value. | |||||
| */ | |||||
| #if !defined (HSI48_VALUE) | |||||
| #define HSI48_VALUE ((uint32_t)48000000) /*!< Value of the Internal High Speed oscillator for USB in Hz. | |||||
| The real value may vary depending on the variations | |||||
| in voltage and temperature. */ | |||||
| #endif /* HSI48_VALUE */ | |||||
| /** | |||||
| * @brief Internal Low Speed oscillator (LSI) value. | |||||
| */ | |||||
| #if !defined (LSI_VALUE) | |||||
| #define LSI_VALUE ((uint32_t)37000) /*!< LSI Typical Value in Hz*/ | |||||
| #endif /* LSI_VALUE */ /*!< Value of the Internal Low Speed oscillator in Hz | |||||
| The real value may vary depending on the variations | |||||
| in voltage and temperature.*/ | |||||
| /** | |||||
| * @brief External Low Speed oscillator (LSE) value. | |||||
| * This value is used by the UART, RTC HAL module to compute the system frequency | |||||
| */ | |||||
| #if !defined (LSE_VALUE) | |||||
| #define LSE_VALUE ((uint32_t)32768) /*!< Value of the External oscillator in Hz*/ | |||||
| #endif /* LSE_VALUE */ | |||||
| #if !defined (LSE_STARTUP_TIMEOUT) | |||||
| #define LSE_STARTUP_TIMEOUT ((uint32_t)5000) /*!< Time out for LSE start up, in ms */ | |||||
| #endif /* HSE_STARTUP_TIMEOUT */ | |||||
| /* Tip: To avoid modifying this file each time you need to use different HSE, | |||||
| === you can define the HSE value in your toolchain compiler preprocessor. */ | |||||
| /* ########################### System Configuration ######################### */ | |||||
| /** | |||||
| * @brief This is the HAL system configuration section | |||||
| */ | |||||
| #define VDD_VALUE ((uint32_t)3300) /*!< Value of VDD in mv */ | |||||
| #define TICK_INT_PRIORITY (((uint32_t)1<<__NVIC_PRIO_BITS) - 1) /*!< tick interrupt priority */ | |||||
| #define USE_RTOS 0 | |||||
| #define PREFETCH_ENABLE 1 | |||||
| #define PREREAD_ENABLE 0 | |||||
| #define BUFFER_CACHE_DISABLE 0 | |||||
| /* ########################## Assert Selection ############################## */ | |||||
| /** | |||||
| * @brief Uncomment the line below to expanse the "assert_param" macro in the | |||||
| * HAL drivers code | |||||
| */ | |||||
| /* #define USE_FULL_ASSERT 1 */ | |||||
| /* Includes ------------------------------------------------------------------*/ | |||||
| /** | |||||
| * @brief Include module's header file | |||||
| */ | |||||
| #ifdef HAL_RCC_MODULE_ENABLED | |||||
| #include "stm32l0xx_hal_rcc.h" | |||||
| #endif /* HAL_RCC_MODULE_ENABLED */ | |||||
| #ifdef HAL_GPIO_MODULE_ENABLED | |||||
| #include "stm32l0xx_hal_gpio.h" | |||||
| #endif /* HAL_GPIO_MODULE_ENABLED */ | |||||
| #ifdef HAL_DMA_MODULE_ENABLED | |||||
| #include "stm32l0xx_hal_dma.h" | |||||
| #endif /* HAL_DMA_MODULE_ENABLED */ | |||||
| #ifdef HAL_CORTEX_MODULE_ENABLED | |||||
| #include "stm32l0xx_hal_cortex.h" | |||||
| #endif /* HAL_CORTEX_MODULE_ENABLED */ | |||||
| #ifdef HAL_ADC_MODULE_ENABLED | |||||
| #include "stm32l0xx_hal_adc.h" | |||||
| #endif /* HAL_ADC_MODULE_ENABLED */ | |||||
| #ifdef HAL_COMP_MODULE_ENABLED | |||||
| #include "stm32l0xx_hal_comp.h" | |||||
| #endif /* HAL_COMP_MODULE_ENABLED */ | |||||
| #ifdef HAL_CRC_MODULE_ENABLED | |||||
| #include "stm32l0xx_hal_crc.h" | |||||
| #endif /* HAL_CRC_MODULE_ENABLED */ | |||||
| #ifdef HAL_CRYP_MODULE_ENABLED | |||||
| #include "stm32l0xx_hal_cryp.h" | |||||
| #endif /* HAL_CRYP_MODULE_ENABLED */ | |||||
| #ifdef HAL_DAC_MODULE_ENABLED | |||||
| #include "stm32l0xx_hal_dac.h" | |||||
| #endif /* HAL_DAC_MODULE_ENABLED */ | |||||
| #ifdef HAL_FLASH_MODULE_ENABLED | |||||
| #include "stm32l0xx_hal_flash.h" | |||||
| #endif /* HAL_FLASH_MODULE_ENABLED */ | |||||
| #ifdef HAL_I2C_MODULE_ENABLED | |||||
| #include "stm32l0xx_hal_i2c.h" | |||||
| #endif /* HAL_I2C_MODULE_ENABLED */ | |||||
| #ifdef HAL_I2S_MODULE_ENABLED | |||||
| #include "stm32l0xx_hal_i2s.h" | |||||
| #endif /* HAL_I2S_MODULE_ENABLED */ | |||||
| #ifdef HAL_IWDG_MODULE_ENABLED | |||||
| #include "stm32l0xx_hal_iwdg.h" | |||||
| #endif /* HAL_IWDG_MODULE_ENABLED */ | |||||
| #ifdef HAL_LCD_MODULE_ENABLED | |||||
| #include "stm32l0xx_hal_lcd.h" | |||||
| #endif /* HAL_LCD_MODULE_ENABLED */ | |||||
| #ifdef HAL_LPTIM_MODULE_ENABLED | |||||
| #include "stm32l0xx_hal_lptim.h" | |||||
| #endif /* HAL_LPTIM_MODULE_ENABLED */ | |||||
| #ifdef HAL_PWR_MODULE_ENABLED | |||||
| #include "stm32l0xx_hal_pwr.h" | |||||
| #endif /* HAL_PWR_MODULE_ENABLED */ | |||||
| #ifdef HAL_RNG_MODULE_ENABLED | |||||
| #include "stm32l0xx_hal_rng.h" | |||||
| #endif /* HAL_RNG_MODULE_ENABLED */ | |||||
| #ifdef HAL_RTC_MODULE_ENABLED | |||||
| #include "stm32l0xx_hal_rtc.h" | |||||
| #endif /* HAL_RTC_MODULE_ENABLED */ | |||||
| #ifdef HAL_SPI_MODULE_ENABLED | |||||
| #include "stm32l0xx_hal_spi.h" | |||||
| #endif /* HAL_SPI_MODULE_ENABLED */ | |||||
| #ifdef HAL_TIM_MODULE_ENABLED | |||||
| #include "stm32l0xx_hal_tim.h" | |||||
| #endif /* HAL_TIM_MODULE_ENABLED */ | |||||
| #ifdef HAL_TSC_MODULE_ENABLED | |||||
| #include "stm32l0xx_hal_tsc.h" | |||||
| #endif /* HAL_TSC_MODULE_ENABLED */ | |||||
| #ifdef HAL_UART_MODULE_ENABLED | |||||
| #include "stm32l0xx_hal_uart.h" | |||||
| #endif /* HAL_UART_MODULE_ENABLED */ | |||||
| #ifdef HAL_USART_MODULE_ENABLED | |||||
| #include "stm32l0xx_hal_usart.h" | |||||
| #endif /* HAL_USART_MODULE_ENABLED */ | |||||
| #ifdef HAL_IRDA_MODULE_ENABLED | |||||
| #include "stm32l0xx_hal_irda.h" | |||||
| #endif /* HAL_IRDA_MODULE_ENABLED */ | |||||
| #ifdef HAL_SMARTCARD_MODULE_ENABLED | |||||
| #include "stm32l0xx_hal_smartcard.h" | |||||
| #endif /* HAL_SMARTCARD_MODULE_ENABLED */ | |||||
| #ifdef HAL_SMBUS_MODULE_ENABLED | |||||
| #include "stm32l0xx_hal_smbus.h" | |||||
| #endif /* HAL_SMBUS_MODULE_ENABLED */ | |||||
| #ifdef HAL_WWDG_MODULE_ENABLED | |||||
| #include "stm32l0xx_hal_wwdg.h" | |||||
| #endif /* HAL_WWDG_MODULE_ENABLED */ | |||||
| #ifdef HAL_PCD_MODULE_ENABLED | |||||
| #include "stm32l0xx_hal_pcd.h" | |||||
| #endif /* HAL_PCD_MODULE_ENABLED */ | |||||
| /* Exported macro ------------------------------------------------------------*/ | |||||
| #ifdef USE_FULL_ASSERT | |||||
| /** | |||||
| * @brief The assert_param macro is used for function's parameters check. | |||||
| * @param expr: If expr is false, it calls assert_failed function | |||||
| * which reports the name of the source file and the source | |||||
| * line number of the call that failed. | |||||
| * If expr is true, it returns no value. | |||||
| * @retval None | |||||
| */ | |||||
| #define assert_param(expr) ((expr) ? (void)0 : assert_failed((uint8_t *)__FILE__, __LINE__)) | |||||
| /* Exported functions ------------------------------------------------------- */ | |||||
| void assert_failed(uint8_t* file, uint32_t line); | |||||
| #else | |||||
| #define assert_param(expr) ((void)0) | |||||
| #endif /* USE_FULL_ASSERT */ | |||||
| #ifdef __cplusplus | |||||
| } | |||||
| #endif | |||||
| #endif /* __STM32L0xx_HAL_CONF_H__ */ | |||||
| /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ | |||||
| /** | |||||
| ****************************************************************************** | |||||
| * @file stm32l0xx_hal_conf.h | |||||
| * @author MCD Application Team | |||||
| * @version V1.1.4 | |||||
| * @date 08-January-2018 | |||||
| * @brief HAL configuration file. | |||||
| ****************************************************************************** | |||||
| * @attention | |||||
| * | |||||
| * <h2><center>© Copyright (c) 2017 STMicroelectronics International N.V. | |||||
| * All rights reserved.</center></h2> | |||||
| * | |||||
| * Redistribution and use in source and binary forms, with or without | |||||
| * modification, are permitted, provided that the following conditions are met: | |||||
| * | |||||
| * 1. Redistribution of source code must retain the above copyright notice, | |||||
| * this list of conditions and the following disclaimer. | |||||
| * 2. Redistributions in binary form must reproduce the above copyright notice, | |||||
| * this list of conditions and the following disclaimer in the documentation | |||||
| * and/or other materials provided with the distribution. | |||||
| * 3. Neither the name of STMicroelectronics nor the names of other | |||||
| * contributors to this software may be used to endorse or promote products | |||||
| * derived from this software without specific written permission. | |||||
| * 4. This software, including modifications and/or derivative works of this | |||||
| * software, must execute solely and exclusively on microcontroller or | |||||
| * microprocessor devices manufactured by or for STMicroelectronics. | |||||
| * 5. Redistribution and use of this software other than as permitted under | |||||
| * this license is void and will automatically terminate your rights under | |||||
| * this license. | |||||
| * | |||||
| * THIS SOFTWARE IS PROVIDED BY STMICROELECTRONICS AND CONTRIBUTORS "AS IS" | |||||
| * AND ANY EXPRESS, IMPLIED OR STATUTORY WARRANTIES, INCLUDING, BUT NOT | |||||
| * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A | |||||
| * PARTICULAR PURPOSE AND NON-INFRINGEMENT OF THIRD PARTY INTELLECTUAL PROPERTY | |||||
| * RIGHTS ARE DISCLAIMED TO THE FULLEST EXTENT PERMITTED BY LAW. IN NO EVENT | |||||
| * SHALL STMICROELECTRONICS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, | |||||
| * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |||||
| * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, | |||||
| * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF | |||||
| * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | |||||
| * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, | |||||
| * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |||||
| * | |||||
| ****************************************************************************** | |||||
| */ | |||||
| /* Define to prevent recursive inclusion -------------------------------------*/ | |||||
| #ifndef __STM32L0xx_HAL_CONF_H__ | |||||
| #define __STM32L0xx_HAL_CONF_H__ | |||||
| #ifdef __cplusplus | |||||
| extern "C" { | |||||
| #endif | |||||
| /* Exported types ------------------------------------------------------------*/ | |||||
| /* Exported constants --------------------------------------------------------*/ | |||||
| /* ########################## Module Selection ############################## */ | |||||
| /** | |||||
| * @brief This is the list of modules to be used in the HAL driver | |||||
| */ | |||||
| #define HAL_MODULE_ENABLED | |||||
| #define HAL_ADC_MODULE_ENABLED | |||||
| /* #define HAL_COMP_MODULE_ENABLED */ | |||||
| /* #define HAL_CRC_MODULE_ENABLED */ | |||||
| /* #define HAL_CRYP_MODULE_ENABLED */ | |||||
| /* #define HAL_DAC_MODULE_ENABLED */ | |||||
| #define HAL_DMA_MODULE_ENABLED | |||||
| #define HAL_FLASH_MODULE_ENABLED | |||||
| #define HAL_GPIO_MODULE_ENABLED | |||||
| #define HAL_I2C_MODULE_ENABLED | |||||
| /* #define HAL_I2S_MODULE_ENABLED */ | |||||
| #define HAL_IWDG_MODULE_ENABLED | |||||
| /* #define HAL_LCD_MODULE_ENABLED */ | |||||
| /* #define HAL_LPTIM_MODULE_ENABLED */ | |||||
| #define HAL_PWR_MODULE_ENABLED | |||||
| #define HAL_RCC_MODULE_ENABLED | |||||
| /* #define HAL_RNG_MODULE_ENABLED */ | |||||
| #define HAL_RTC_MODULE_ENABLED | |||||
| #define HAL_SPI_MODULE_ENABLED | |||||
| #define HAL_TIM_MODULE_ENABLED | |||||
| /* #define HAL_TSC_MODULE_ENABLED */ | |||||
| #define HAL_UART_MODULE_ENABLED | |||||
| /* #define HAL_USART_MODULE_ENABLED */ | |||||
| /* #define HAL_IRDA_MODULE_ENABLED */ | |||||
| /* #define HAL_SMARTCARD_MODULE_ENABLED */ | |||||
| /* #define HAL_SMBUS_MODULE_ENABLED */ | |||||
| /* #define HAL_WWDG_MODULE_ENABLED */ | |||||
| #define HAL_CORTEX_MODULE_ENABLED | |||||
| /* #define HAL_PCD_MODULE_ENABLED */ | |||||
| /* ########################## Oscillator Values adaptation ####################*/ | |||||
| /** | |||||
| * @brief Adjust the value of External High Speed oscillator (HSE) used in your application. | |||||
| * This value is used by the RCC HAL module to compute the system frequency | |||||
| * (when HSE is used as system clock source, directly or through the PLL). | |||||
| */ | |||||
| #if !defined (HSE_VALUE) | |||||
| #define HSE_VALUE ((uint32_t)8000000) /*!< Value of the External oscillator in Hz */ | |||||
| #endif /* HSE_VALUE */ | |||||
| #if !defined (HSE_STARTUP_TIMEOUT) | |||||
| #define HSE_STARTUP_TIMEOUT ((uint32_t)5000) /*!< Time out for HSE start up, in ms */ | |||||
| #endif /* HSE_STARTUP_TIMEOUT */ | |||||
| /** | |||||
| * @brief Internal Multiple Speed oscillator (MSI) default value. | |||||
| * This value is the default MSI range value after Reset. | |||||
| */ | |||||
| #if !defined (MSI_VALUE) | |||||
| #define MSI_VALUE ((uint32_t)2000000) /*!< Value of the Internal oscillator in Hz*/ | |||||
| #endif /* MSI_VALUE */ | |||||
| /** | |||||
| * @brief Internal High Speed oscillator (HSI) value. | |||||
| * This value is used by the RCC HAL module to compute the system frequency | |||||
| * (when HSI is used as system clock source, directly or through the PLL). | |||||
| */ | |||||
| #if !defined (HSI_VALUE) | |||||
| #define HSI_VALUE ((uint32_t)16000000) /*!< Value of the Internal oscillator in Hz*/ | |||||
| #endif /* HSI_VALUE */ | |||||
| /** | |||||
| * @brief Internal High Speed oscillator for USB (HSI48) value. | |||||
| */ | |||||
| #if !defined (HSI48_VALUE) | |||||
| #define HSI48_VALUE ((uint32_t)48000000) /*!< Value of the Internal High Speed oscillator for USB in Hz. | |||||
| The real value may vary depending on the variations | |||||
| in voltage and temperature. */ | |||||
| #endif /* HSI48_VALUE */ | |||||
| /** | |||||
| * @brief Internal Low Speed oscillator (LSI) value. | |||||
| */ | |||||
| #if !defined (LSI_VALUE) | |||||
| #define LSI_VALUE ((uint32_t)37000) /*!< LSI Typical Value in Hz*/ | |||||
| #endif /* LSI_VALUE */ /*!< Value of the Internal Low Speed oscillator in Hz | |||||
| The real value may vary depending on the variations | |||||
| in voltage and temperature.*/ | |||||
| /** | |||||
| * @brief External Low Speed oscillator (LSE) value. | |||||
| * This value is used by the UART, RTC HAL module to compute the system frequency | |||||
| */ | |||||
| #if !defined (LSE_VALUE) | |||||
| #define LSE_VALUE ((uint32_t)32768) /*!< Value of the External oscillator in Hz*/ | |||||
| #endif /* LSE_VALUE */ | |||||
| #if !defined (LSE_STARTUP_TIMEOUT) | |||||
| #define LSE_STARTUP_TIMEOUT ((uint32_t)5000) /*!< Time out for LSE start up, in ms */ | |||||
| #endif /* HSE_STARTUP_TIMEOUT */ | |||||
| /* Tip: To avoid modifying this file each time you need to use different HSE, | |||||
| === you can define the HSE value in your toolchain compiler preprocessor. */ | |||||
| /* ########################### System Configuration ######################### */ | |||||
| /** | |||||
| * @brief This is the HAL system configuration section | |||||
| */ | |||||
| #define VDD_VALUE ((uint32_t)3300) /*!< Value of VDD in mv */ | |||||
| #define TICK_INT_PRIORITY (((uint32_t)1<<__NVIC_PRIO_BITS) - 1) /*!< tick interrupt priority */ | |||||
| #define USE_RTOS 0 | |||||
| #define PREFETCH_ENABLE 1 | |||||
| #define PREREAD_ENABLE 0 | |||||
| #define BUFFER_CACHE_DISABLE 0 | |||||
| /* ########################## Assert Selection ############################## */ | |||||
| /** | |||||
| * @brief Uncomment the line below to expanse the "assert_param" macro in the | |||||
| * HAL drivers code | |||||
| */ | |||||
| /* #define USE_FULL_ASSERT 1 */ | |||||
| /* Includes ------------------------------------------------------------------*/ | |||||
| /** | |||||
| * @brief Include module's header file | |||||
| */ | |||||
| #ifdef HAL_RCC_MODULE_ENABLED | |||||
| #include "stm32l0xx_hal_rcc.h" | |||||
| #endif /* HAL_RCC_MODULE_ENABLED */ | |||||
| #ifdef HAL_GPIO_MODULE_ENABLED | |||||
| #include "stm32l0xx_hal_gpio.h" | |||||
| #endif /* HAL_GPIO_MODULE_ENABLED */ | |||||
| #ifdef HAL_DMA_MODULE_ENABLED | |||||
| #include "stm32l0xx_hal_dma.h" | |||||
| #endif /* HAL_DMA_MODULE_ENABLED */ | |||||
| #ifdef HAL_CORTEX_MODULE_ENABLED | |||||
| #include "stm32l0xx_hal_cortex.h" | |||||
| #endif /* HAL_CORTEX_MODULE_ENABLED */ | |||||
| #ifdef HAL_ADC_MODULE_ENABLED | |||||
| #include "stm32l0xx_hal_adc.h" | |||||
| #endif /* HAL_ADC_MODULE_ENABLED */ | |||||
| #ifdef HAL_COMP_MODULE_ENABLED | |||||
| #include "stm32l0xx_hal_comp.h" | |||||
| #endif /* HAL_COMP_MODULE_ENABLED */ | |||||
| #ifdef HAL_CRC_MODULE_ENABLED | |||||
| #include "stm32l0xx_hal_crc.h" | |||||
| #endif /* HAL_CRC_MODULE_ENABLED */ | |||||
| #ifdef HAL_CRYP_MODULE_ENABLED | |||||
| #include "stm32l0xx_hal_cryp.h" | |||||
| #endif /* HAL_CRYP_MODULE_ENABLED */ | |||||
| #ifdef HAL_DAC_MODULE_ENABLED | |||||
| #include "stm32l0xx_hal_dac.h" | |||||
| #endif /* HAL_DAC_MODULE_ENABLED */ | |||||
| #ifdef HAL_FLASH_MODULE_ENABLED | |||||
| #include "stm32l0xx_hal_flash.h" | |||||
| #endif /* HAL_FLASH_MODULE_ENABLED */ | |||||
| #ifdef HAL_I2C_MODULE_ENABLED | |||||
| #include "stm32l0xx_hal_i2c.h" | |||||
| #endif /* HAL_I2C_MODULE_ENABLED */ | |||||
| #ifdef HAL_I2S_MODULE_ENABLED | |||||
| #include "stm32l0xx_hal_i2s.h" | |||||
| #endif /* HAL_I2S_MODULE_ENABLED */ | |||||
| #ifdef HAL_IWDG_MODULE_ENABLED | |||||
| #include "stm32l0xx_hal_iwdg.h" | |||||
| #endif /* HAL_IWDG_MODULE_ENABLED */ | |||||
| #ifdef HAL_LCD_MODULE_ENABLED | |||||
| #include "stm32l0xx_hal_lcd.h" | |||||
| #endif /* HAL_LCD_MODULE_ENABLED */ | |||||
| #ifdef HAL_LPTIM_MODULE_ENABLED | |||||
| #include "stm32l0xx_hal_lptim.h" | |||||
| #endif /* HAL_LPTIM_MODULE_ENABLED */ | |||||
| #ifdef HAL_PWR_MODULE_ENABLED | |||||
| #include "stm32l0xx_hal_pwr.h" | |||||
| #endif /* HAL_PWR_MODULE_ENABLED */ | |||||
| #ifdef HAL_RNG_MODULE_ENABLED | |||||
| #include "stm32l0xx_hal_rng.h" | |||||
| #endif /* HAL_RNG_MODULE_ENABLED */ | |||||
| #ifdef HAL_RTC_MODULE_ENABLED | |||||
| #include "stm32l0xx_hal_rtc.h" | |||||
| #endif /* HAL_RTC_MODULE_ENABLED */ | |||||
| #ifdef HAL_SPI_MODULE_ENABLED | |||||
| #include "stm32l0xx_hal_spi.h" | |||||
| #endif /* HAL_SPI_MODULE_ENABLED */ | |||||
| #ifdef HAL_TIM_MODULE_ENABLED | |||||
| #include "stm32l0xx_hal_tim.h" | |||||
| #endif /* HAL_TIM_MODULE_ENABLED */ | |||||
| #ifdef HAL_TSC_MODULE_ENABLED | |||||
| #include "stm32l0xx_hal_tsc.h" | |||||
| #endif /* HAL_TSC_MODULE_ENABLED */ | |||||
| #ifdef HAL_UART_MODULE_ENABLED | |||||
| #include "stm32l0xx_hal_uart.h" | |||||
| #endif /* HAL_UART_MODULE_ENABLED */ | |||||
| #ifdef HAL_USART_MODULE_ENABLED | |||||
| #include "stm32l0xx_hal_usart.h" | |||||
| #endif /* HAL_USART_MODULE_ENABLED */ | |||||
| #ifdef HAL_IRDA_MODULE_ENABLED | |||||
| #include "stm32l0xx_hal_irda.h" | |||||
| #endif /* HAL_IRDA_MODULE_ENABLED */ | |||||
| #ifdef HAL_SMARTCARD_MODULE_ENABLED | |||||
| #include "stm32l0xx_hal_smartcard.h" | |||||
| #endif /* HAL_SMARTCARD_MODULE_ENABLED */ | |||||
| #ifdef HAL_SMBUS_MODULE_ENABLED | |||||
| #include "stm32l0xx_hal_smbus.h" | |||||
| #endif /* HAL_SMBUS_MODULE_ENABLED */ | |||||
| #ifdef HAL_WWDG_MODULE_ENABLED | |||||
| #include "stm32l0xx_hal_wwdg.h" | |||||
| #endif /* HAL_WWDG_MODULE_ENABLED */ | |||||
| #ifdef HAL_PCD_MODULE_ENABLED | |||||
| #include "stm32l0xx_hal_pcd.h" | |||||
| #endif /* HAL_PCD_MODULE_ENABLED */ | |||||
| /* Exported macro ------------------------------------------------------------*/ | |||||
| #ifdef USE_FULL_ASSERT | |||||
| /** | |||||
| * @brief The assert_param macro is used for function's parameters check. | |||||
| * @param expr: If expr is false, it calls assert_failed function | |||||
| * which reports the name of the source file and the source | |||||
| * line number of the call that failed. | |||||
| * If expr is true, it returns no value. | |||||
| * @retval None | |||||
| */ | |||||
| #define assert_param(expr) ((expr) ? (void)0 : assert_failed((uint8_t *)__FILE__, __LINE__)) | |||||
| /* Exported functions ------------------------------------------------------- */ | |||||
| void assert_failed(uint8_t* file, uint32_t line); | |||||
| #else | |||||
| #define assert_param(expr) ((void)0) | |||||
| #endif /* USE_FULL_ASSERT */ | |||||
| #ifdef __cplusplus | |||||
| } | |||||
| #endif | |||||
| #endif /* __STM32L0xx_HAL_CONF_H__ */ | |||||
| /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ | |||||
| @@ -1,285 +1,285 @@ | |||||
| /** | |||||
| ****************************************************************************** | |||||
| * @file system_stm32l0xx.c | |||||
| * @author MCD Application Team | |||||
| * @brief CMSIS Cortex-M0+ Device Peripheral Access Layer System Source File. | |||||
| * | |||||
| * This file provides two functions and one global variable to be called from | |||||
| * user application: | |||||
| * - SystemInit(): This function is called at startup just after reset and | |||||
| * before branch to main program. This call is made inside | |||||
| * the "startup_stm32l0xx.s" file. | |||||
| * | |||||
| * - SystemCoreClock variable: Contains the core clock (HCLK), it can be used | |||||
| * by the user application to setup the SysTick | |||||
| * timer or configure other parameters. | |||||
| * | |||||
| * - SystemCoreClockUpdate(): Updates the variable SystemCoreClock and must | |||||
| * be called whenever the core clock is changed | |||||
| * during program execution. | |||||
| * | |||||
| * | |||||
| ****************************************************************************** | |||||
| * @attention | |||||
| * | |||||
| * <h2><center>© COPYRIGHT(c) 2016 STMicroelectronics</center></h2> | |||||
| * | |||||
| * Redistribution and use in source and binary forms, with or without modification, | |||||
| * are permitted provided that the following conditions are met: | |||||
| * 1. Redistributions of source code must retain the above copyright notice, | |||||
| * this list of conditions and the following disclaimer. | |||||
| * 2. Redistributions in binary form must reproduce the above copyright notice, | |||||
| * this list of conditions and the following disclaimer in the documentation | |||||
| * and/or other materials provided with the distribution. | |||||
| * 3. Neither the name of STMicroelectronics nor the names of its contributors | |||||
| * may be used to endorse or promote products derived from this software | |||||
| * without specific prior written permission. | |||||
| * | |||||
| * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | |||||
| * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |||||
| * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |||||
| * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE | |||||
| * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |||||
| * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | |||||
| * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | |||||
| * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |||||
| * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |||||
| * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |||||
| * | |||||
| ****************************************************************************** | |||||
| */ | |||||
| /** @addtogroup CMSIS | |||||
| * @{ | |||||
| */ | |||||
| /** @addtogroup stm32l0xx_system | |||||
| * @{ | |||||
| */ | |||||
| /** @addtogroup STM32L0xx_System_Private_Includes | |||||
| * @{ | |||||
| */ | |||||
| #include "stm32l0xx.h" | |||||
| #if !defined (HSE_VALUE) | |||||
| #define HSE_VALUE ((uint32_t)8000000U) /*!< Value of the External oscillator in Hz */ | |||||
| #endif /* HSE_VALUE */ | |||||
| #if !defined (MSI_VALUE) | |||||
| #define MSI_VALUE ((uint32_t)2000000U) /*!< Value of the Internal oscillator in Hz*/ | |||||
| #endif /* MSI_VALUE */ | |||||
| #if !defined (HSI_VALUE) | |||||
| #define HSI_VALUE ((uint32_t)16000000U) /*!< Value of the Internal oscillator in Hz*/ | |||||
| #endif /* HSI_VALUE */ | |||||
| /** | |||||
| * @} | |||||
| */ | |||||
| /** @addtogroup STM32L0xx_System_Private_TypesDefinitions | |||||
| * @{ | |||||
| */ | |||||
| /** | |||||
| * @} | |||||
| */ | |||||
| /** @addtogroup STM32L0xx_System_Private_Defines | |||||
| * @{ | |||||
| */ | |||||
| /************************* Miscellaneous Configuration ************************/ | |||||
| /*!< Uncomment the following line if you need to relocate your vector Table in | |||||
| Internal SRAM. */ | |||||
| /* #define VECT_TAB_SRAM */ | |||||
| #define VECT_TAB_OFFSET 0x00U /*!< Vector Table base offset field. | |||||
| This value must be a multiple of 0x200. */ | |||||
| /******************************************************************************/ | |||||
| /** | |||||
| * @} | |||||
| */ | |||||
| /** @addtogroup STM32L0xx_System_Private_Macros | |||||
| * @{ | |||||
| */ | |||||
| /** | |||||
| * @} | |||||
| */ | |||||
| /** @addtogroup STM32L0xx_System_Private_Variables | |||||
| * @{ | |||||
| */ | |||||
| /* This variable is updated in three ways: | |||||
| 1) by calling CMSIS function SystemCoreClockUpdate() | |||||
| 2) by calling HAL API function HAL_RCC_GetHCLKFreq() | |||||
| 3) each time HAL_RCC_ClockConfig() is called to configure the system clock frequency | |||||
| Note: If you use this function to configure the system clock; then there | |||||
| is no need to call the 2 first functions listed above, since SystemCoreClock | |||||
| variable is updated automatically. | |||||
| */ | |||||
| uint32_t SystemCoreClock = 2000000U; | |||||
| const uint8_t AHBPrescTable[16] = {0U, 0U, 0U, 0U, 0U, 0U, 0U, 0U, 1U, 2U, 3U, 4U, 6U, 7U, 8U, 9U}; | |||||
| const uint8_t APBPrescTable[8] = {0U, 0U, 0U, 0U, 1U, 2U, 3U, 4U}; | |||||
| const uint8_t PLLMulTable[9] = {3U, 4U, 6U, 8U, 12U, 16U, 24U, 32U, 48U}; | |||||
| /** | |||||
| * @} | |||||
| */ | |||||
| /** @addtogroup STM32L0xx_System_Private_FunctionPrototypes | |||||
| * @{ | |||||
| */ | |||||
| /** | |||||
| * @} | |||||
| */ | |||||
| /** @addtogroup STM32L0xx_System_Private_Functions | |||||
| * @{ | |||||
| */ | |||||
| /** | |||||
| * @brief Setup the microcontroller system. | |||||
| * @param None | |||||
| * @retval None | |||||
| */ | |||||
| void SystemInit (void) | |||||
| { | |||||
| /*!< Set MSION bit */ | |||||
| RCC->CR |= (uint32_t)0x00000100U; | |||||
| /*!< Reset SW[1:0], HPRE[3:0], PPRE1[2:0], PPRE2[2:0], MCOSEL[2:0] and MCOPRE[2:0] bits */ | |||||
| RCC->CFGR &= (uint32_t) 0x88FF400CU; | |||||
| /*!< Reset HSION, HSIDIVEN, HSEON, CSSON and PLLON bits */ | |||||
| RCC->CR &= (uint32_t)0xFEF6FFF6U; | |||||
| /*!< Reset HSI48ON bit */ | |||||
| RCC->CRRCR &= (uint32_t)0xFFFFFFFEU; | |||||
| /*!< Reset HSEBYP bit */ | |||||
| RCC->CR &= (uint32_t)0xFFFBFFFFU; | |||||
| /*!< Reset PLLSRC, PLLMUL[3:0] and PLLDIV[1:0] bits */ | |||||
| RCC->CFGR &= (uint32_t)0xFF02FFFFU; | |||||
| /*!< Disable all interrupts */ | |||||
| RCC->CIER = 0x00000000U; | |||||
| /* Configure the Vector Table location add offset address ------------------*/ | |||||
| #ifdef VECT_TAB_SRAM | |||||
| SCB->VTOR = SRAM_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal SRAM */ | |||||
| #else | |||||
| SCB->VTOR = FLASH_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal FLASH */ | |||||
| #endif | |||||
| } | |||||
| /** | |||||
| * @brief Update SystemCoreClock according to Clock Register Values | |||||
| * The SystemCoreClock variable contains the core clock (HCLK), it can | |||||
| * be used by the user application to setup the SysTick timer or configure | |||||
| * other parameters. | |||||
| * | |||||
| * @note Each time the core clock (HCLK) changes, this function must be called | |||||
| * to update SystemCoreClock variable value. Otherwise, any configuration | |||||
| * based on this variable will be incorrect. | |||||
| * | |||||
| * @note - The system frequency computed by this function is not the real | |||||
| * frequency in the chip. It is calculated based on the predefined | |||||
| * constant and the selected clock source: | |||||
| * | |||||
| * - If SYSCLK source is MSI, SystemCoreClock will contain the MSI | |||||
| * value as defined by the MSI range. | |||||
| * | |||||
| * - If SYSCLK source is HSI, SystemCoreClock will contain the HSI_VALUE(*) | |||||
| * | |||||
| * - If SYSCLK source is HSE, SystemCoreClock will contain the HSE_VALUE(**) | |||||
| * | |||||
| * - If SYSCLK source is PLL, SystemCoreClock will contain the HSE_VALUE(**) | |||||
| * or HSI_VALUE(*) multiplied/divided by the PLL factors. | |||||
| * | |||||
| * (*) HSI_VALUE is a constant defined in stm32l0xx_hal.h file (default value | |||||
| * 16 MHz) but the real value may vary depending on the variations | |||||
| * in voltage and temperature. | |||||
| * | |||||
| * (**) HSE_VALUE is a constant defined in stm32l0xx_hal.h file (default value | |||||
| * 8 MHz), user has to ensure that HSE_VALUE is same as the real | |||||
| * frequency of the crystal used. Otherwise, this function may | |||||
| * have wrong result. | |||||
| * | |||||
| * - The result of this function could be not correct when using fractional | |||||
| * value for HSE crystal. | |||||
| * @param None | |||||
| * @retval None | |||||
| */ | |||||
| void SystemCoreClockUpdate (void) | |||||
| { | |||||
| uint32_t tmp = 0U, pllmul = 0U, plldiv = 0U, pllsource = 0U, msirange = 0U; | |||||
| /* Get SYSCLK source -------------------------------------------------------*/ | |||||
| tmp = RCC->CFGR & RCC_CFGR_SWS; | |||||
| switch (tmp) | |||||
| { | |||||
| case 0x00U: /* MSI used as system clock */ | |||||
| msirange = (RCC->ICSCR & RCC_ICSCR_MSIRANGE) >> 13U; | |||||
| SystemCoreClock = (32768U * (1U << (msirange + 1U))); | |||||
| break; | |||||
| case 0x04U: /* HSI used as system clock */ | |||||
| SystemCoreClock = HSI_VALUE; | |||||
| break; | |||||
| case 0x08U: /* HSE used as system clock */ | |||||
| SystemCoreClock = HSE_VALUE; | |||||
| break; | |||||
| case 0x0CU: /* PLL used as system clock */ | |||||
| /* Get PLL clock source and multiplication factor ----------------------*/ | |||||
| pllmul = RCC->CFGR & RCC_CFGR_PLLMUL; | |||||
| plldiv = RCC->CFGR & RCC_CFGR_PLLDIV; | |||||
| pllmul = PLLMulTable[(pllmul >> 18U)]; | |||||
| plldiv = (plldiv >> 22U) + 1U; | |||||
| pllsource = RCC->CFGR & RCC_CFGR_PLLSRC; | |||||
| if (pllsource == 0x00U) | |||||
| { | |||||
| /* HSI oscillator clock selected as PLL clock entry */ | |||||
| SystemCoreClock = (((HSI_VALUE) * pllmul) / plldiv); | |||||
| } | |||||
| else | |||||
| { | |||||
| /* HSE selected as PLL clock entry */ | |||||
| SystemCoreClock = (((HSE_VALUE) * pllmul) / plldiv); | |||||
| } | |||||
| break; | |||||
| default: /* MSI used as system clock */ | |||||
| msirange = (RCC->ICSCR & RCC_ICSCR_MSIRANGE) >> 13U; | |||||
| SystemCoreClock = (32768U * (1U << (msirange + 1U))); | |||||
| break; | |||||
| } | |||||
| /* Compute HCLK clock frequency --------------------------------------------*/ | |||||
| /* Get HCLK prescaler */ | |||||
| tmp = AHBPrescTable[((RCC->CFGR & RCC_CFGR_HPRE) >> 4U)]; | |||||
| /* HCLK clock frequency */ | |||||
| SystemCoreClock >>= tmp; | |||||
| } | |||||
| /** | |||||
| * @} | |||||
| */ | |||||
| /** | |||||
| * @} | |||||
| */ | |||||
| /** | |||||
| * @} | |||||
| */ | |||||
| /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ | |||||
| /** | |||||
| ****************************************************************************** | |||||
| * @file system_stm32l0xx.c | |||||
| * @author MCD Application Team | |||||
| * @brief CMSIS Cortex-M0+ Device Peripheral Access Layer System Source File. | |||||
| * | |||||
| * This file provides two functions and one global variable to be called from | |||||
| * user application: | |||||
| * - SystemInit(): This function is called at startup just after reset and | |||||
| * before branch to main program. This call is made inside | |||||
| * the "startup_stm32l0xx.s" file. | |||||
| * | |||||
| * - SystemCoreClock variable: Contains the core clock (HCLK), it can be used | |||||
| * by the user application to setup the SysTick | |||||
| * timer or configure other parameters. | |||||
| * | |||||
| * - SystemCoreClockUpdate(): Updates the variable SystemCoreClock and must | |||||
| * be called whenever the core clock is changed | |||||
| * during program execution. | |||||
| * | |||||
| * | |||||
| ****************************************************************************** | |||||
| * @attention | |||||
| * | |||||
| * <h2><center>© COPYRIGHT(c) 2016 STMicroelectronics</center></h2> | |||||
| * | |||||
| * Redistribution and use in source and binary forms, with or without modification, | |||||
| * are permitted provided that the following conditions are met: | |||||
| * 1. Redistributions of source code must retain the above copyright notice, | |||||
| * this list of conditions and the following disclaimer. | |||||
| * 2. Redistributions in binary form must reproduce the above copyright notice, | |||||
| * this list of conditions and the following disclaimer in the documentation | |||||
| * and/or other materials provided with the distribution. | |||||
| * 3. Neither the name of STMicroelectronics nor the names of its contributors | |||||
| * may be used to endorse or promote products derived from this software | |||||
| * without specific prior written permission. | |||||
| * | |||||
| * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | |||||
| * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |||||
| * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |||||
| * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE | |||||
| * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |||||
| * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | |||||
| * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | |||||
| * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |||||
| * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |||||
| * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |||||
| * | |||||
| ****************************************************************************** | |||||
| */ | |||||
| /** @addtogroup CMSIS | |||||
| * @{ | |||||
| */ | |||||
| /** @addtogroup stm32l0xx_system | |||||
| * @{ | |||||
| */ | |||||
| /** @addtogroup STM32L0xx_System_Private_Includes | |||||
| * @{ | |||||
| */ | |||||
| #include "stm32l0xx.h" | |||||
| #if !defined (HSE_VALUE) | |||||
| #define HSE_VALUE ((uint32_t)8000000U) /*!< Value of the External oscillator in Hz */ | |||||
| #endif /* HSE_VALUE */ | |||||
| #if !defined (MSI_VALUE) | |||||
| #define MSI_VALUE ((uint32_t)2000000U) /*!< Value of the Internal oscillator in Hz*/ | |||||
| #endif /* MSI_VALUE */ | |||||
| #if !defined (HSI_VALUE) | |||||
| #define HSI_VALUE ((uint32_t)16000000U) /*!< Value of the Internal oscillator in Hz*/ | |||||
| #endif /* HSI_VALUE */ | |||||
| /** | |||||
| * @} | |||||
| */ | |||||
| /** @addtogroup STM32L0xx_System_Private_TypesDefinitions | |||||
| * @{ | |||||
| */ | |||||
| /** | |||||
| * @} | |||||
| */ | |||||
| /** @addtogroup STM32L0xx_System_Private_Defines | |||||
| * @{ | |||||
| */ | |||||
| /************************* Miscellaneous Configuration ************************/ | |||||
| /*!< Uncomment the following line if you need to relocate your vector Table in | |||||
| Internal SRAM. */ | |||||
| /* #define VECT_TAB_SRAM */ | |||||
| #define VECT_TAB_OFFSET 0x00U /*!< Vector Table base offset field. | |||||
| This value must be a multiple of 0x200. */ | |||||
| /******************************************************************************/ | |||||
| /** | |||||
| * @} | |||||
| */ | |||||
| /** @addtogroup STM32L0xx_System_Private_Macros | |||||
| * @{ | |||||
| */ | |||||
| /** | |||||
| * @} | |||||
| */ | |||||
| /** @addtogroup STM32L0xx_System_Private_Variables | |||||
| * @{ | |||||
| */ | |||||
| /* This variable is updated in three ways: | |||||
| 1) by calling CMSIS function SystemCoreClockUpdate() | |||||
| 2) by calling HAL API function HAL_RCC_GetHCLKFreq() | |||||
| 3) each time HAL_RCC_ClockConfig() is called to configure the system clock frequency | |||||
| Note: If you use this function to configure the system clock; then there | |||||
| is no need to call the 2 first functions listed above, since SystemCoreClock | |||||
| variable is updated automatically. | |||||
| */ | |||||
| uint32_t SystemCoreClock = 2000000U; | |||||
| const uint8_t AHBPrescTable[16] = {0U, 0U, 0U, 0U, 0U, 0U, 0U, 0U, 1U, 2U, 3U, 4U, 6U, 7U, 8U, 9U}; | |||||
| const uint8_t APBPrescTable[8] = {0U, 0U, 0U, 0U, 1U, 2U, 3U, 4U}; | |||||
| const uint8_t PLLMulTable[9] = {3U, 4U, 6U, 8U, 12U, 16U, 24U, 32U, 48U}; | |||||
| /** | |||||
| * @} | |||||
| */ | |||||
| /** @addtogroup STM32L0xx_System_Private_FunctionPrototypes | |||||
| * @{ | |||||
| */ | |||||
| /** | |||||
| * @} | |||||
| */ | |||||
| /** @addtogroup STM32L0xx_System_Private_Functions | |||||
| * @{ | |||||
| */ | |||||
| /** | |||||
| * @brief Setup the microcontroller system. | |||||
| * @param None | |||||
| * @retval None | |||||
| */ | |||||
| void SystemInit (void) | |||||
| { | |||||
| /*!< Set MSION bit */ | |||||
| RCC->CR |= (uint32_t)0x00000100U; | |||||
| /*!< Reset SW[1:0], HPRE[3:0], PPRE1[2:0], PPRE2[2:0], MCOSEL[2:0] and MCOPRE[2:0] bits */ | |||||
| RCC->CFGR &= (uint32_t) 0x88FF400CU; | |||||
| /*!< Reset HSION, HSIDIVEN, HSEON, CSSON and PLLON bits */ | |||||
| RCC->CR &= (uint32_t)0xFEF6FFF6U; | |||||
| /*!< Reset HSI48ON bit */ | |||||
| RCC->CRRCR &= (uint32_t)0xFFFFFFFEU; | |||||
| /*!< Reset HSEBYP bit */ | |||||
| RCC->CR &= (uint32_t)0xFFFBFFFFU; | |||||
| /*!< Reset PLLSRC, PLLMUL[3:0] and PLLDIV[1:0] bits */ | |||||
| RCC->CFGR &= (uint32_t)0xFF02FFFFU; | |||||
| /*!< Disable all interrupts */ | |||||
| RCC->CIER = 0x00000000U; | |||||
| /* Configure the Vector Table location add offset address ------------------*/ | |||||
| #ifdef VECT_TAB_SRAM | |||||
| SCB->VTOR = SRAM_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal SRAM */ | |||||
| #else | |||||
| SCB->VTOR = FLASH_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal FLASH */ | |||||
| #endif | |||||
| } | |||||
| /** | |||||
| * @brief Update SystemCoreClock according to Clock Register Values | |||||
| * The SystemCoreClock variable contains the core clock (HCLK), it can | |||||
| * be used by the user application to setup the SysTick timer or configure | |||||
| * other parameters. | |||||
| * | |||||
| * @note Each time the core clock (HCLK) changes, this function must be called | |||||
| * to update SystemCoreClock variable value. Otherwise, any configuration | |||||
| * based on this variable will be incorrect. | |||||
| * | |||||
| * @note - The system frequency computed by this function is not the real | |||||
| * frequency in the chip. It is calculated based on the predefined | |||||
| * constant and the selected clock source: | |||||
| * | |||||
| * - If SYSCLK source is MSI, SystemCoreClock will contain the MSI | |||||
| * value as defined by the MSI range. | |||||
| * | |||||
| * - If SYSCLK source is HSI, SystemCoreClock will contain the HSI_VALUE(*) | |||||
| * | |||||
| * - If SYSCLK source is HSE, SystemCoreClock will contain the HSE_VALUE(**) | |||||
| * | |||||
| * - If SYSCLK source is PLL, SystemCoreClock will contain the HSE_VALUE(**) | |||||
| * or HSI_VALUE(*) multiplied/divided by the PLL factors. | |||||
| * | |||||
| * (*) HSI_VALUE is a constant defined in stm32l0xx_hal.h file (default value | |||||
| * 16 MHz) but the real value may vary depending on the variations | |||||
| * in voltage and temperature. | |||||
| * | |||||
| * (**) HSE_VALUE is a constant defined in stm32l0xx_hal.h file (default value | |||||
| * 8 MHz), user has to ensure that HSE_VALUE is same as the real | |||||
| * frequency of the crystal used. Otherwise, this function may | |||||
| * have wrong result. | |||||
| * | |||||
| * - The result of this function could be not correct when using fractional | |||||
| * value for HSE crystal. | |||||
| * @param None | |||||
| * @retval None | |||||
| */ | |||||
| void SystemCoreClockUpdate (void) | |||||
| { | |||||
| uint32_t tmp = 0U, pllmul = 0U, plldiv = 0U, pllsource = 0U, msirange = 0U; | |||||
| /* Get SYSCLK source -------------------------------------------------------*/ | |||||
| tmp = RCC->CFGR & RCC_CFGR_SWS; | |||||
| switch (tmp) | |||||
| { | |||||
| case 0x00U: /* MSI used as system clock */ | |||||
| msirange = (RCC->ICSCR & RCC_ICSCR_MSIRANGE) >> 13U; | |||||
| SystemCoreClock = (32768U * (1U << (msirange + 1U))); | |||||
| break; | |||||
| case 0x04U: /* HSI used as system clock */ | |||||
| SystemCoreClock = HSI_VALUE; | |||||
| break; | |||||
| case 0x08U: /* HSE used as system clock */ | |||||
| SystemCoreClock = HSE_VALUE; | |||||
| break; | |||||
| case 0x0CU: /* PLL used as system clock */ | |||||
| /* Get PLL clock source and multiplication factor ----------------------*/ | |||||
| pllmul = RCC->CFGR & RCC_CFGR_PLLMUL; | |||||
| plldiv = RCC->CFGR & RCC_CFGR_PLLDIV; | |||||
| pllmul = PLLMulTable[(pllmul >> 18U)]; | |||||
| plldiv = (plldiv >> 22U) + 1U; | |||||
| pllsource = RCC->CFGR & RCC_CFGR_PLLSRC; | |||||
| if (pllsource == 0x00U) | |||||
| { | |||||
| /* HSI oscillator clock selected as PLL clock entry */ | |||||
| SystemCoreClock = (((HSI_VALUE) * pllmul) / plldiv); | |||||
| } | |||||
| else | |||||
| { | |||||
| /* HSE selected as PLL clock entry */ | |||||
| SystemCoreClock = (((HSE_VALUE) * pllmul) / plldiv); | |||||
| } | |||||
| break; | |||||
| default: /* MSI used as system clock */ | |||||
| msirange = (RCC->ICSCR & RCC_ICSCR_MSIRANGE) >> 13U; | |||||
| SystemCoreClock = (32768U * (1U << (msirange + 1U))); | |||||
| break; | |||||
| } | |||||
| /* Compute HCLK clock frequency --------------------------------------------*/ | |||||
| /* Get HCLK prescaler */ | |||||
| tmp = AHBPrescTable[((RCC->CFGR & RCC_CFGR_HPRE) >> 4U)]; | |||||
| /* HCLK clock frequency */ | |||||
| SystemCoreClock >>= tmp; | |||||
| } | |||||
| /** | |||||
| * @} | |||||
| */ | |||||
| /** | |||||
| * @} | |||||
| */ | |||||
| /** | |||||
| * @} | |||||
| */ | |||||
| /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ | |||||