rel_1.6.0 init

This commit is contained in:
guocheng.kgc 2020-06-18 20:06:52 +08:00 committed by shengdong.dsd
commit 27b3e2883d
19359 changed files with 8093121 additions and 0 deletions

View file

@ -0,0 +1,24 @@
/*
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
*/
#include "hal/soc/soc.h"
#include <aos/kernel.h>
#include <aos/aos.h>
/* Logic partition on flash devices */
hal_logic_partition_t hal_partitions[HAL_PARTITION_MAX] =
{
[HAL_PARTITION_PARAMETER_2] =
{
.partition_owner = HAL_FLASH_EMBEDDED,
.partition_description = "PARAMETER2",
.partition_start_addr = 0x8015000,
.partition_length = 0x2000, // 8k bytes
.partition_options = PAR_OPT_READ_EN | PAR_OPT_WRITE_EN,
},
};
void board_init(void)
{
}

View file

@ -0,0 +1,10 @@
#define HARDWARE_REVISION "V1.0"
#define MODEL "EML3047"
#ifdef BOOTLOADER
#define STDIO_UART 0
#define STDIO_UART_BUADRATE 115200
#else
#define STDIO_UART 0
#define STDIO_UART_BUADRATE 115200
#endif

View file

@ -0,0 +1,69 @@
NAME := board_eml3047
JTAG := jlink_swd
$(NAME)_TYPE := kernel
MODULE := 1062
HOST_ARCH := Cortex-M0
HOST_MCU_FAMILY := stm32l0xx.stm32l071kb
SUPPORT_BINS := no
$(NAME)_SOURCES := board.c \
src/debug.c \
src/hw_gpio.c \
src/hw_spi.c \
src/hw_rtc.c \
src/eml3047_hw.c \
src/eml3047_it.c \
src/vcom.c \
src/lorawan_port.c \
../../device/lora/eml3047_lrwan/eml3047.c \
- ../../device/lora/sx1276/sx1276.c
#$(NAME)_COMPONENTS += modules.fs.kv
linkwan ?= 0
ifeq ($(linkwan), 0)
$(NAME)_SOURCES += src/lora.c
endif
#$(NAME)_LINK_FILES := src/eml3047_it.o
GLOBAL_INCLUDES += . \
inc \
../../platform/mcu/stm32l0xx/Drivers/STM32L0xx_HAL_Driver/Inc \
../../platform/mcu/stm32l0xx/Drivers/STM32L0xx_HAL_Driver/Inc/Legacy \
../../platform/mcu/stm32l0xx/Drivers/CMSIS/Device/ST/STM32L0xx/Include \
../../platform/mcu/stm32l0xx/Drivers/CMSIS/Include
GLOBAL_DEFINES += \
USE_HAL_DRIVER \
STM32L071xx
GLOBAL_INCLUDES += ../../device/lora/eml3047_lrwan \
../../device/lora/sx1276 \
GLOBAL_DEFINES += STDIO_UART=0 CONFIG_NO_TCPIP
GLOBAL_DEFINES += RHINO_CONFIG_TICK_TASK=0 RHINO_CONFIG_WORKQUEUE=0
GLOBAL_DEFINES += USE_FULL_LL_DRIVER USE_B_EML3047
CONFIG_SYSINFO_PRODUCT_MODEL := ALI_AOS_EML3047
CONFIG_SYSINFO_DEVICE_NAME := EML3047
GLOBAL_CFLAGS += -DSYSINFO_OS_VERSION=\"$(CONFIG_SYSINFO_OS_VERSION)\"
GLOBAL_CFLAGS += -DSYSINFO_PRODUCT_MODEL=\"$(CONFIG_SYSINFO_PRODUCT_MODEL)\"
GLOBAL_CFLAGS += -DSYSINFO_DEVICE_NAME=\"$(CONFIG_SYSINFO_DEVICE_NAME)\"
GLOBAL_LDFLAGS += -L $(SOURCE_ROOT)/board/eml3047
# Global defines
# HSE_VALUE = STM32 crystal frequency = 26MHz (needed to make UART work correctly)
GLOBAL_DEFINES += $$(if $$(NO_CRLF_STDIO_REPLACEMENT),,CRLF_STDIO_REPLACEMENT)
GLOBAL_CFLAGS += -mcpu=cortex-m0plus -mthumb -mfloat-abi=soft
WIFI_FIRMWARE_SECTOR_START := 2 #0x2000
FILESYSTEM_IMAGE_SECTOR_START := 256 #0x100000
# Extra build target in mico_standard_targets.mk, include bootloader, and copy output file to eclipse debug file (copy_output_for_eclipse)
EXTRA_TARGET_MAKEFILES += $(MAKEFILES_PATH)/aos_standard_targets.mk
#EXTRA_TARGET_MAKEFILES += $(SOURCE_ROOT)/platform/mcu/$(HOST_MCU_FAMILY)/gen_crc_bin.mk

View file

@ -0,0 +1,158 @@
/*
/ _____) _ | |
( (____ _____ ____ _| |_ _____ ____| |__
\____ \| ___ | (_ _) ___ |/ ___) _ \
_____) ) ____| | | || |_| ____( (___| | | |
(______/|_____)_|_|_| \__)_____)\____)_| |_|
(C)2015 Semtech
Description: End device comissioning parameters
License: Revised BSD License, see LICENSE.TXT file include in the project
Maintainer: Miguel Luis and Gregory Cristian
*/
/******************************************************************************
* @file comissioning.h
* @author MCD Application Team
* @version V1.1.1
* @date 01-June-2017
* @brief End device comissioning parameters
******************************************************************************
* @attention
*
* <h2><center>&copy; 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 __LORA_COMISSIONING_H__
#define __LORA_COMISSIONING_H__
#ifdef __cplusplus
extern "C" {
#endif
/* Exported types ------------------------------------------------------------*/
/* Exported constants --------------------------------------------------------*/
/* External variables --------------------------------------------------------*/
/* Exported macros -----------------------------------------------------------*/
/* Exported functions ------------------------------------------------------- */
/**
* 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
/**
* Indicates if the end-device is to be connected to a private or public network
*/
#define LORAWAN_PUBLIC_NETWORK true
/**
* When set to 1 DevEui is LORAWAN_DEVICE_EUI
* When set to 0 DevEui is automatically generated by calling
* BoardGetUniqueId function
*/
#define STATIC_DEVICE_EUI 0
/**
* Mote device IEEE EUI (big endian)
*
* \remark see STATIC_DEVICE_EUI comments
*/
#define LORAWAN_DEVICE_EUI { 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01 }
/**
* Application IEEE EUI (big endian)
*/
#define LORAWAN_APPLICATION_EUI { 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01 }
/**
* AES encryption/decryption cipher application key
*/
#define LORAWAN_APPLICATION_KEY { 0x2B, 0x7E, 0x15, 0x16, 0x28, 0xAE, 0xD2, 0xA6, 0xAB, 0xF7, 0x15, 0x88, 0x09, 0xCF, 0x4F, 0x3C }
/**
* Current network ID
*/
#define LORAWAN_NETWORK_ID ( uint32_t )0
/**
* When set to 1 DevAdd is LORAWAN_DEVICE_ADDRESS
* When set to 0 DevAdd is automatically generated using
* a pseudo random generator seeded with a value derived from
* BoardUniqueId value
*/
#define STATIC_DEVICE_ADDRESS 0
/**
* Device address on the network (big endian)
*
* \remark see STATIC_DEVICE_ADDRESS comments
*/
#define LORAWAN_DEVICE_ADDRESS ( uint32_t )0x0100000a
/**
* AES encryption/decryption cipher network session key
*/
#define LORAWAN_NWKSKEY { 0x2B, 0x7E, 0x15, 0x16, 0x28, 0xAE, 0xD2, 0xA6, 0xAB, 0xF7, 0x15, 0x88, 0x09, 0xCF, 0x4F, 0x3C }
/**
* AES encryption/decryption cipher application session key
*/
#define LORAWAN_APPSKEY { 0x2B, 0x7E, 0x15, 0x16, 0x28, 0xAE, 0xD2, 0xA6, 0xAB, 0xF7, 0x15, 0x88, 0x09, 0xCF, 0x4F, 0x3C }
/**
* Multicast address
*/
#define LORAWAN_MULTICAST_ADDRESS 0x06344bf2
/**
* AES encryption/decryption cipher network session key for multicast
*/
#define LORAWAN_MULTICAST_NWKSKEY { 0x65, 0xe4, 0x48, 0x3d, 0xe3, 0xa9, 0xce, 0xb1, 0x50, 0xd8, 0x86, 0xf3, 0x61, 0x46, 0x02, 0xb5 }
/**
* AES encryption/decryption cipher application session key for multicast
*/
#define LORAWAN_MULTICAST_APPSKEY { 0xc2, 0x65, 0x67, 0xa3, 0xec, 0xd3, 0x96, 0x67, 0xd6, 0x23, 0xf8, 0x7a, 0xe1, 0x6c, 0x12, 0x23 }
#ifdef __cplusplus
}
#endif
#endif /* __LORA_COMISSIONING_H__ */

View file

@ -0,0 +1,115 @@
/******************************************************************************
* @file debug.h
* @author MCD Application Team
* @version V1.1.1
* @date 01-June-2017
* @brief Header for driver debug.c module
******************************************************************************
* @attention
*
* <h2><center>&copy; 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 __DEBUG_H__
#define __DEBUG_H__
#ifdef __cplusplus
extern "C" {
#endif
/* Includes ------------------------------------------------------------------*/
#include <string.h>
#include <stdio.h>
#include "hw_conf.h"
#include "vcom.h"
/* Exported types ------------------------------------------------------------*/
/* Exported constants --------------------------------------------------------*/
/* External variables --------------------------------------------------------*/
/* Exported macros -----------------------------------------------------------*/
#ifdef LORA_DEBUG
#define DBG_GPIO_WRITE(gpio, n, x) HW_GPIO_Write(gpio, n, (GPIO_PinState)(x))
#define DBG_GPIO_SET(gpio, n) gpio->BSRR = n
#define DBG_GPIO_RST(gpio, n) gpio->BRR = n
#define DBG_RTC_OUTPUT LL_RTC_ALARMOUT_DISABLE /* LL_RTC_ALARMOUT_ALMA on PC13 */
#define DBG(x) do { x } while (0)
#ifdef LORA_TRACE
#include "hw_rtc.h"
#define DBG_PRINTF(format, ...) do {DBG_Send("[%d][%s:%4d] " format "", HW_RTC_GetTimerValue(), __FILE__, __LINE__, ##__VA_ARGS__);}while(0==1)//DBG_Send(__VA_ARGS__)//vcom_Send(__VA_ARGS__)
#define LOG_PRINTF(format, ...) do {DBG_Send(format, HW_RTC_GetTimerValue(), ##__VA_ARGS__);}while(0==1)
#define DBG_PRINTF_CRITICAL(...)
#else /*TRACE*/
#define DBG_PRINTF(...)
#define DBG_PRINTF_CRITICAL(...)
#endif /*TRACE*/
#else /* DEBUG */
#define DBG_GPIO_WRITE(gpio, n, x)
#define DBG_GPIO_SET(gpio, n)
#define DBG_GPIO_RST(gpio, n)
#define DBG(x) do { } while (0)
#define DBG_PRINTF(...)
#define DBG_PRINTF_CRITICAL(...)
#define DBG_RTC_OUTPUT LL_RTC_ALARMOUT_DISABLE
#endif /* DEBUG */
/* Exported functions ------------------------------------------------------- */
/**
* @brief Initializes the debug
* @param None
* @retval None
*/
void DBG_Init(void);
#ifdef __cplusplus
}
#endif
#endif /* __DEBUG_H__*/
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

View file

@ -0,0 +1,169 @@
/*
/ _____) _ | |
( (____ _____ ____ _| |_ _____ ____| |__
\____ \| ___ | (_ _) ___ |/ ___) _ \
_____) ) ____| | | || |_| ____( (___| | | |
(______/|_____)_|_|_| \__)_____)\____)_| |_|
(C)2013 Semtech
Description: contains hardaware configuration Macros and Constants
License: Revised BSD License, see LICENSE.TXT file include in the project
Maintainer: Miguel Luis and Gregory Cristian
*/
/******************************************************************************
* @file eml3047_hw_conf.h
* @author MCD Application Team
* @version V1.1.1
* @date 01-June-2017
* @brief contains hardaware configuration Macros and Constants
******************************************************************************
* @attention
*
* <h2><center>&copy; 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 __EML3047_HW_CONF_H__
#define __EML3047_HW_CONF_H__
#ifdef __cplusplus
extern "C" {
#endif
/* Includes ------------------------------------------------------------------*/
/* Exported types ------------------------------------------------------------*/
/* Exported constants --------------------------------------------------------*/
/* LORA I/O definition */
#define RADIO_RESET_PORT GPIOB
#define RADIO_RESET_PIN GPIO_PIN_0
#define RADIO_MOSI_PORT GPIOB
#define RADIO_MOSI_PIN GPIO_PIN_5
#define RADIO_MISO_PORT GPIOB
#define RADIO_MISO_PIN GPIO_PIN_4
#define RADIO_SCLK_PORT GPIOA
#define RADIO_SCLK_PIN GPIO_PIN_5
#define RADIO_NSS_PORT GPIOA
#define RADIO_NSS_PIN GPIO_PIN_4
#define RADIO_DIO_0_PORT GPIOB
#define RADIO_DIO_0_PIN GPIO_PIN_6
#define RADIO_DIO_1_PORT GPIOA
#define RADIO_DIO_1_PIN GPIO_PIN_12
#define RADIO_DIO_2_PORT GPIOA
#define RADIO_DIO_2_PIN GPIO_PIN_11
#define RADIO_DIO_3_PORT GPIOA
#define RADIO_DIO_3_PIN GPIO_PIN_8
#ifdef RADIO_DIO_4
#define RADIO_DIO_4_PORT GPIOA
#define RADIO_DIO_4_PIN GPIO_PIN_9
#endif
#ifdef RADIO_DIO_5
#define RADIO_DIO_5_PORT GPIOC
#define RADIO_DIO_5_PIN GPIO_PIN_7
#endif
//#define RADIO_TCXO_VCC_PORT GPIOA
//#define RADIO_TCXO_VCC_PIN GPIO_PIN_12
#define RADIO_ANT_SWITCH_PORT GPIOA
#define RADIO_ANT_SWITCH_PIN GPIO_PIN_7
#define BAT_LEVEL_PORT GPIOA
#define BAT_LEVEL_PIN GPIO_PIN_4
/* SPI MACRO redefinition */
#define SPI_CLK_ENABLE() __HAL_RCC_SPI1_CLK_ENABLE()
#define SPI1_AF GPIO_AF0_SPI1
/* ADC MACRO redefinition */
#define BAT_LEVEL_PORT GPIOA //CRF2
#define BAT_LEVEL_PIN GPIO_PIN_4
#define ADC_READ_CHANNEL ADC_CHANNEL_4
#define ADCCLK_ENABLE() __HAL_RCC_ADC1_CLK_ENABLE();
#define ADCCLK_DISABLE() __HAL_RCC_ADC1_CLK_DISABLE();
/* --------------------------- RTC HW definition -------------------------------- */
#define RTC_OUTPUT DBG_RTC_OUTPUT
#define RTC_Alarm_IRQn RTC_IRQn
/* --------------------------- UART HW definition -------------------------------*/
/* Definition for UARTx clock resources */
#define UARTX LPUART1
#define UARTX_CLK_ENABLE() LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_LPUART1)
#define UARTX_RX_GPIO_CLK_ENABLE() LL_IOP_GRP1_EnableClock(RCC_IOPENR_GPIOBEN)
#define UARTX_TX_GPIO_CLK_ENABLE() LL_IOP_GRP1_EnableClock(RCC_IOPENR_GPIOBEN)
#define UARTX_FORCE_RESET() LL_APB1_GRP1_ForceReset(LL_APB1_GRP1_PERIPH_LPUART1)
#define UARTX_RELEASE_RESET() LL_APB1_GRP1_ReleaseReset(LL_APB1_GRP1_PERIPH_LPUART1)
#define UARTX_TX_PIN GPIO_PIN_2
#define UARTX_TX_GPIO_PORT GPIOA
#define UARTX_TX_AF GPIO_AF6_LPUART1
#define UARTX_RX_PIN GPIO_PIN_3
#define UARTX_RX_GPIO_PORT GPIOA
#define UARTX_RX_AF GPIO_AF6_LPUART1
/* Definition for USARTx's NVIC */
#define UARTX_IRQn LPUART1_IRQn
#define UARTX_IRQHandler LPUART1_IRQHandler
#ifdef __cplusplus
}
#endif
#endif /* __32L082MLM_HW_CONF_H__ */
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

View file

@ -0,0 +1,117 @@
/*
/ _____) _ | |
( (____ _____ ____ _| |_ _____ ____| |__
\____ \| ___ | (_ _) ___ |/ ___) _ \
_____) ) ____| | | || |_| ____( (___| | | |
(______/|_____)_|_|_| \__)_____)\____)_| |_|
(C)2013 Semtech
Description: Bleeper board GPIO driver implementation
License: Revised BSD License, see LICENSE.TXT file include in the project
Maintainer: Miguel Luis and Gregory Cristian
*/
/******************************************************************************
* @file mlm32l0xx_it.h
* @author MCD Application Team
* @version V1.1.1
* @date 01-June-2017
* @brief manages interupt
******************************************************************************
* @attention
*
* <h2><center>&copy; 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 __32L082MLM_IT_H__
#define __32L082MLM_IT_H__
#ifdef __cplusplus
extern "C" {
#endif
/* Includes ------------------------------------------------------------------*/
/* Exported types ------------------------------------------------------------*/
/* Exported constants --------------------------------------------------------*/
/* Exported macro ------------------------------------------------------------*/
/* Exported functions ------------------------------------------------------- */
/**
* @brief RTC IRQ Handler on the RTC Alarm
* @param None
* @retval None
*/
void RTC_IRQHandler(void);
/**
* @brief Handles External lines 0 to 1 interrupt request.
* @param None
* @retval None
*/
void EXTI0_1_IRQHandler(void);
/**
* @brief Handles External lines 2 to 3 interrupt request.
* @param None
* @retval None
*/
void EXTI2_3_IRQHandler(void);
/**
* @brief Handles External lines 4 to 15 interrupt request.
* @param None
* @retval None
*/
void EXTI4_15_IRQHandler(void);
/**
* @brief vcom IRQ Handler
* @param None
* @retval None
*/
void UARTX_IRQHandler(void);
#ifdef __cplusplus
}
#endif
#endif /* __32L082MLM_IT_H__ */
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

View file

@ -0,0 +1,109 @@
/*
/ _____) _ | |
( (____ _____ ____ _| |_ _____ ____| |__
\____ \| ___ | (_ _) ___ |/ ___) _ \
_____) ) ____| | | || |_| ____( (___| | | |
(______/|_____)_|_|_| \__)_____)\____)_| |_|
(C)2013 Semtech
Description: contains all hardware driver
License: Revised BSD License, see LICENSE.TXT file include in the project
Maintainer: Miguel Luis and Gregory Cristian
*/
/******************************************************************************
* @file hw.h
* @author MCD Application Team
* @version V1.1.1
* @date 01-June-2017
* @brief contains all hardware driver
******************************************************************************
* @attention
*
* <h2><center>&copy; 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 __HW_H__
#define __HW_H__
#ifdef __cplusplus
extern "C" {
#endif
/* Includes ------------------------------------------------------------------*/
#include <math.h>
#include <stdbool.h>
#include <stdint.h>
#include "hw_conf.h"
#include "hw_gpio.h"
#include "hw_spi.h"
#include "hw_rtc.h"
#include "hw_msp.h"
#include "debug.h"
#include "vcom.h"
typedef enum
{
HW_UNLOCKED = 0x00U,
HW_LOCKED = 0x01U
} HW_LockTypeDef;
#define HW_LOCK(__HANDLE__) \
do { \
if ((__HANDLE__)->Lock == HW_LOCKED) \
{ \
return; \
} \
else \
{ \
(__HANDLE__)->Lock = HW_LOCKED; \
} \
} while (0)
#define HW_UNLOCK(__HANDLE__) \
do { \
(__HANDLE__)->Lock = HW_UNLOCKED; \
} while (0)
#ifdef __cplusplus
}
#endif
#endif /* __HW_H__ */
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

View file

@ -0,0 +1,117 @@
/*
/ _____) _ | |
( (____ _____ ____ _| |_ _____ ____| |__
\____ \| ___ | (_ _) ___ |/ ___) _ \
_____) ) ____| | | || |_| ____( (___| | | |
(______/|_____)_|_|_| \__)_____)\____)_| |_|
(C)2013 Semtech
Description: contains hardaware configuration Macros and Constants
License: Revised BSD License, see LICENSE.TXT file include in the project
Maintainer: Miguel Luis and Gregory Cristian
*/
/******************************************************************************
* @file hw_conf.h
* @author MCD Application Team
* @version V1.1.1
* @date 01-June-2017
* @brief contains hardware configuration Macros and Constants
******************************************************************************
* @attention
*
* <h2><center>&copy; 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 __HW_CONF_H__
#define __HW_CONF_H__
#ifdef __cplusplus
extern "C" {
#endif
#if !defined(USE_FULL_LL_DRIVER)
#error USE_FULL_LL_DRIVER must be defined
#endif
#if !defined(USE_B_EML3047)
#error Only USE_32L082MLM_DISCO is supported
#endif
/* Includes ------------------------------------------------------------------*/
#include "stm32l0xx_ll_adc.h"
#include "stm32l0xx_ll_bus.h"
#include "stm32l0xx_ll_cortex.h"
#include "stm32l0xx_ll_exti.h"
#include "stm32l0xx_ll_gpio.h"
#include "stm32l0xx_ll_pwr.h"
#include "stm32l0xx_ll_rcc.h"
#include "stm32l0xx_ll_rtc.h"
#include "stm32l0xx_ll_spi.h"
#include "stm32l0xx_ll_system.h"
#include "stm32l0xx_ll_lpuart.h"
#include "stm32l0xx_ll_usart.h"
#include "eml3047_hw_conf.h"
#ifdef USE_FULL_ASSERT
#include "stm32_assert.h"
#else
#define assert_param(expr) ((void)0U)
#endif
/* --------Preprocessor compile swicth------------ */
/* debug swicthes in debug.h */
#ifdef CONFIG_LINKWAN_AT
#define LORA_DEBUG
#define LORA_TRACE
#endif
/* uncomment below line to never enter lowpower modes in main.c*/
/* #define LOW_POWER_DISABLE */
/* Exported types ------------------------------------------------------------*/
/* Exported constants --------------------------------------------------------*/
#ifdef __cplusplus
}
#endif
#endif /* __HW_CONF_H__ */
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

View file

@ -0,0 +1,203 @@
/*
/ _____) _ | |
( (____ _____ ____ _| |_ _____ ____| |__
\____ \| ___ | (_ _) ___ |/ ___) _ \
_____) ) ____| | | || |_| ____( (___| | | |
(______/|_____)_|_|_| \__)_____)\____)_| |_|
(C)2013 Semtech
Description: Bleeper board GPIO driver implementation
License: Revised BSD License, see LICENSE.TXT file include in the project
Maintainer: Miguel Luis and Gregory Cristian
*/
/******************************************************************************
* @file hw_gpio.h
* @author MCD Application Team
* @version V1.1.1
* @date 01-June-2017
* @brief Header for driver hw_rtc.c module
******************************************************************************
* @attention
*
* <h2><center>&copy; 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 __HW_GPIO_H__
#define __HW_GPIO_H__
#ifdef __cplusplus
extern "C" {
#endif
/* Includes ------------------------------------------------------------------*/
#include "stm32l0xx_ll_gpio.h"
/*
* Force the include of HAL GPIO in order to benefit from enum and structure
* definition which are used in LoRa modules
* Note that the code size is slighty increased by about 40 bytes on classA application because
* "Pin" of structure "GPIO_InitTypeDef" is not used in our HW_GPIO_xxx() implementation
*/
#include "stm32l0xx_hal_gpio.h"
#include "stm32l0xx_hal_gpio_ex.h"
/* Exported types ------------------------------------------------------------*/
typedef void ( GpioIrqHandler )(void);
/* Exported constants --------------------------------------------------------*/
/* External variables --------------------------------------------------------*/
/* Exported macros -----------------------------------------------------------*/
/* Exported functions ------------------------------------------------------- */
/**
* @brief Initializes the given GPIO object
*
* @param GPIOx: where x can be (A..E and H)
* @param GPIO_Pin: specifies the port bit to be written.
* This parameter can be one of GPIO_PIN_x where x can be (0..15).
* All port bits are not necessarily available on all GPIOs.
* @param [IN] initStruct GPIO_InitTypeDef intit structure
* @retval None
*/
void HW_GPIO_Init(GPIO_TypeDef *GPIOx, uint16_t GPIO_Pin, GPIO_InitTypeDef *initStruct);
/**
* @brief De-initializes the GPIOx peripheral registers to their default reset values.
* @param GPIOx: where x can be (A..E and H) to select the GPIO peripheral for STM32L0XX family devices.
* Note that GPIOE is not available on all devices.
* @param GPIO_Pin: specifies the port bit to be written.
* This parameter can be one of GPIO_PIN_x where x can be (0..15).
* All port bits are not necessarily available on all GPIOs.
* @retval None
* @note this is an implementation of HAL_GPIO_DeInit() using LL
*/
void HW_GPIO_DeInit(GPIO_TypeDef *GPIOx, uint32_t GPIO_Pin);
/**
* @brief This function handles EXTI interrupt request.
* @param GPIO_Pin: Specifies the pins connected to the EXTI line.
* @retval None
* @note this is an implementation of HAL_GPIO_EXTI_IRQHandler() using LL
*/
void HW_GPIO_EXTI_IRQHandler(uint16_t GPIO_Pin);
/**
* @brief Records the interrupt handler for the GPIO object
*
* @param GPIOx: where x can be (A..E and H)
* @param GPIO_Pin: specifies the port bit to be written.
* This parameter can be one of GPIO_PIN_x where x can be (0..15).
* All port bits are not necessarily available on all GPIOs.
* @param [IN] prio NVIC priority (0 is highest)
* @param [IN] irqHandler points to the function to execute
* @retval None
*/
void HW_GPIO_SetIrq(GPIO_TypeDef *GPIOx, uint16_t GPIO_Pin, uint32_t prio, GpioIrqHandler *irqHandler);
/**
* @brief Execute the interrupt from the object
*
* @param GPIOx: where x can be (A..E and H)
* @param GPIO_Pin: specifies the port bit to be written.
* This parameter can be one of GPIO_PIN_x where x can be (0..15).
* All port bits are not necessarily available on all GPIOs.
* @retval None
*/
void HW_GPIO_IrqHandler(uint16_t GPIO_Pin);
/**
* @brief Writes the given value to the GPIO output
*
* @param GPIO_Pin: specifies the port bit to be written.
* This parameter can be one of GPIO_PIN_x where x can be (0..15).
* All port bits are not necessarily available on all GPIOs.
* @param [IN] value New GPIO output value
* @retval None
*/
__STATIC_INLINE void HW_GPIO_Write(GPIO_TypeDef *GPIOx, uint16_t GPIO_Pin, uint32_t value)
{
/*
* Function HAL_GPIO_WritePin is inlined using LL Driver. It saves code size
* as the value to set is known at compile time most of the time
*/
if (value != RESET)
{
LL_GPIO_SetOutputPin(GPIOx, GPIO_Pin);
}
else
{
LL_GPIO_ResetOutputPin(GPIOx, GPIO_Pin);
}
}
/**
* @brief Reads the current GPIO input value
*
* @param GPIOx: where x can be (A..E and H)
* @param GPIO_Pin: specifies the port bit to be written.
* This parameter can be one of GPIO_PIN_x where x can be (0..15).
* All port bits are not necessarily available on all GPIOs.
* @retval value Current GPIO input value
*/
uint32_t HW_GPIO_Read(GPIO_TypeDef *GPIOx, uint16_t GPIO_Pin);
/**
* @brief Toggles the specified GPIO pins.
* @param GPIOx: Where x can be (A..E and H) to select the GPIO peripheral for STM32L0xx family devices.
* Note that GPIOE is not available on all devices.
* All port bits are not necessarily available on all GPIOs.
* @param GPIO_Pin: Specifies the pins to be toggled.
* @retval None
*/
__STATIC_INLINE void HW_GPIO_TogglePin(GPIO_TypeDef *GPIOx, uint32_t PinMask)
{
LL_GPIO_TogglePin(GPIOx, PinMask);
}
#ifdef __cplusplus
}
#endif
#endif /* __HW_GPIO_H__ */
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

View file

@ -0,0 +1,214 @@
/*
/ _____) _ | |
( (____ _____ ____ _| |_ _____ ____| |__
\____ \| ___ | (_ _) ___ |/ ___) _ \
_____) ) ____| | | || |_| ____( (___| | | |
(______/|_____)_|_|_| \__)_____)\____)_| |_|
(C)2013 Semtech
Description: Header for driver hw msp module
License: Revised BSD License, see LICENSE.TXT file include in the project
Maintainer: Miguel Luis and Gregory Cristian
*/
/******************************************************************************
* @file hw_msp.h
* @author MCD Application Team
* @version V1.1.1
* @date 01-June-2017
* @brief Header for driver hw msp module
******************************************************************************
* @attention
*
* <h2><center>&copy; 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 __HW_MSP_H__
#define __HW_MSP_H__
#ifdef __cplusplus
extern "C" {
#endif
/* Includes ------------------------------------------------------------------*/
#include "hw_conf.h"
/* Exported types ------------------------------------------------------------*/
typedef enum
{
e_LOW_POWER_RTC = (1 << 0),
e_LOW_POWER_GPS = (1 << 1),
e_LOW_POWER_UART = (1 << 2), /* can be used to forbid stop mode in case of uart Xfer*/
} e_LOW_POWER_State_Id_t;
/* Exported constants --------------------------------------------------------*/
#define VDDA_VREFINT_CAL ((uint32_t) 3000)
#define BAT_CR2032 ((uint32_t) 3000)
#define VDD_BAT BAT_CR2032
#define VDD_MIN 1800
/* External variables --------------------------------------------------------*/
/* Exported macros -----------------------------------------------------------*/
/**
* @brief GPIOs Macro
*/
#define RCC_GPIO_CLK_ENABLE(__GPIO_PORT__) \
do { \
switch (__GPIO_PORT__) \
{ \
case GPIOA_BASE: LL_IOP_GRP1_EnableClock(LL_IOP_GRP1_PERIPH_GPIOA); break; \
case GPIOB_BASE: LL_IOP_GRP1_EnableClock(LL_IOP_GRP1_PERIPH_GPIOB); break; \
case GPIOC_BASE: LL_IOP_GRP1_EnableClock(LL_IOP_GRP1_PERIPH_GPIOC); break; \
case GPIOD_BASE: LL_IOP_GRP1_EnableClock(LL_IOP_GRP1_PERIPH_GPIOD); break; \
case GPIOH_BASE: default: LL_IOP_GRP1_EnableClock(LL_IOP_GRP1_PERIPH_GPIOH); \
} \
} while (0)
#define RCC_GPIO_CLK_DISABLE(__GPIO_PORT__) \
do { \
switch (__GPIO_PORT__) \
{ \
case GPIOA_BASE: LL_IOP_GRP1_DisableClock(LL_IOP_GRP1_PERIPH_GPIOA); break; \
case GPIOB_BASE: LL_IOP_GRP1_DisableClock(LL_IOP_GRP1_PERIPH_GPIOB); break; \
case GPIOC_BASE: LL_IOP_GRP1_DisableClock(LL_IOP_GRP1_PERIPH_GPIOC); break; \
case GPIOD_BASE: LL_IOP_GRP1_DisableClock(LL_IOP_GRP1_PERIPH_GPIOD); break; \
case GPIOH_BASE: default: LL_IOP_GRP1_DisableClock(LL_IOP_GRP1_PERIPH_GPIOH); \
} \
} while (0)
/* Exported functions ------------------------------------------------------- */
/**
* @brief This function return the battery level
* @param None
* @retval The battery level 0 (very low) to 254 (fully charged)
*/
uint8_t HW_GetBatteryLevel(void);
/**
* @brief Initializes the boards peripherals.
* @param None
* @retval None
*/
void HW_Init(void);
/**
* @brief De-initializes the target board peripherals to decrease power consumption.
* @param None
* @retval None
*/
void HW_DeInit(void);
/**
* @brief This function return a random seed
* @note Based on the device unique ID
* @param None
* @retval Unique number, used as a random seed
*/
uint32_t HW_GetRandomSeed(void);
/**
* @brief Gets the board 64 bits unique ID
* @param Pointer to an array that will contain the Unique ID
* @retval None
*/
void HW_GetUniqueId(uint8_t *id);
/**
* @brief Enters Low Power Stop Mode
* @note ARM exists the function when waking up
* @param None
* @retval None
*/
void HW_EnterStopMode(void);
/**
* @brief Exit Low Power Stop Mode
* @note Enable the pll at 32MHz
* @param None
* @retval None
*/
void HW_ExitStopMode(void);
/**
* @brief Enters Low Power Sleep Mode
* @note ARM exists the function when waking up
* @param None
* @retval None
*/
void HW_EnterSleepMode(void);
/**
* @brief Configures the sytem Clock at start-up, as follow :
* System Clock source = PLL (HSI)
* SYSCLK(Hz) = 32000000
* HCLK(Hz) = 32000000
* AHB Prescaler = 1
* APB1 Prescaler = 1
* APB2 Prescaler = 1
* HSI Frequency(Hz) = 16000000
* PLLMUL = 6
* PLLDIV = 3
* Flash Latency(WS) = 1
* @param None
* @retval None
*/
void SystemClock_Config(void);
/**
* @brief Configure all GPIO's to Analog input to reduce the power consumption
* @param None
* @retval None
*/
void HW_GpioInit(void);
void SYS_LED_OFF(void);
void SYS_LED_ON(void);
#ifdef __cplusplus
}
#endif
#endif /* __HW_MSP_H__ */
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

View file

@ -0,0 +1,177 @@
/*
/ _____) _ | |
( (____ _____ ____ _| |_ _____ ____| |__
\____ \| ___ | (_ _) ___ |/ ___) _ \
_____) ) ____| | | || |_| ____( (___| | | |
(______/|_____)_|_|_| \__)_____)\____)_| |_|
(C)2013 Semtech
Description: Bleeper board GPIO driver implementation
License: Revised BSD License, see LICENSE.TXT file include in the project
Maintainer: Miguel Luis and Gregory Cristian
*/
/******************************************************************************
* @file hw_rtc.h
* @author MCD Application Team
* @version V1.1.1
* @date 01-June-2017
* @brief Header for driver hw_rtc.c module
******************************************************************************
* @attention
*
* <h2><center>&copy; 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.
*
******************************************************************************
*/
#ifndef __HW_RTC_H__
#define __HW_RTC_H__
#ifdef __cplusplus
extern "C" {
#endif
/* Includes ------------------------------------------------------------------*/
#include "utilities.h"
/* Exported types ------------------------------------------------------------*/
/* Exported constants --------------------------------------------------------*/
/* External variables --------------------------------------------------------*/
/* Exported macros -----------------------------------------------------------*/
/* Exported functions ------------------------------------------------------- */
/**
* @brief Initializes the RTC timer
* @note The timer is based on the RTC
* @param None
* @retval None
*/
void HW_RTC_Init(void);
/**
* @brief Stop the Alarm
* @param None
* @retval None
*/
void HW_RTC_StopAlarm(void);
/**
* @brief Return the minimum timeout the RTC is able to handle
* @param None
* @retval Minimum value for a timeout
*/
uint32_t HW_RTC_GetMinimumTimeout(void);
/**
* @brief Set the alarm
* @note The alarm is set at now (read in this funtion) + timeout
* @param Timeout Duration of the Timer ticks
* @retval None
*/
void HW_RTC_SetAlarm(uint32_t timeout);
/**
* @brief Get the RTC timer elapsed time since the last Alarm was set
* @param None
* @retval RTC Elapsed time in ticks
*/
uint32_t HW_RTC_GetTimerElapsedTime(void);
/**
* @brief Get the RTC timer value
* @param None
* @retval RTC Timer value in ticks
*/
uint32_t HW_RTC_GetTimerValue(void);
/**
* @brief Set the RTC timer Reference
* @param None
* @retval Timer Reference Value in Ticks
*/
uint32_t HW_RTC_SetTimerContext(void);
/**
* @brief Get the RTC timer Reference
* @param None
* @retval Timer Value in Ticks
*/
uint32_t HW_RTC_GetTimerContext(void);
/**
* @brief RTC IRQ Handler on the RTC Alarm
* @param None
* @retval None
*/
void HW_RTC_IrqHandler(void);
/**
* @brief Delay of delay ms by polling RTC
* @param Delay in ms
* @retval None
*/
void HW_RTC_DelayMs(uint32_t delay);
/**
* @brief Calculates the wake up time between wake up and mcu start
* @note Resolution in RTC_ALARM_TIME_BASE
* @param None
* @retval None
*/
void HW_RTC_setMcuWakeUpTime(void);
/**
* @brief Converts time in ms to time in ticks
* @param Time in milliseconds
* @retval Returns time in timer ticks
*/
uint32_t HW_RTC_ms2Tick(TimerTime_t timeMicroSec);
/**
* @brief Converts time in ticks to time in ms
* @param Time in timer ticks
* @retval Time in timer milliseconds
*/
TimerTime_t HW_RTC_Tick2ms(uint32_t tick);
#ifdef __cplusplus
}
#endif
#endif /* __HW_RTC_H__ */
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

View file

@ -0,0 +1,134 @@
/*
/ _____) _ | |
( (____ _____ ____ _| |_ _____ ____| |__
\____ \| ___ | (_ _) ___ |/ ___) _ \
_____) ) ____| | | || |_| ____( (___| | | |
(______/|_____)_|_|_| \__)_____)\____)_| |_|
(C)2013 Semtech
Description: Header for driver hw spi module
License: Revised BSD License, see LICENSE.TXT file include in the project
Maintainer: Miguel Luis and Gregory Cristian
*/
/******************************************************************************
* @file hw_spi.h
* @author MCD Application Team
* @version V1.1.1
* @date 01-June-2017
* @brief Header for driver hw_spi.c module
******************************************************************************
* @attention
*
* <h2><center>&copy; 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 __HW_SPI_H__
#define __HW_SPI_H__
#ifdef __cplusplus
extern "C" {
#endif
#include "hw_conf.h"
/* Exported types ------------------------------------------------------------*/
/* Exported constants --------------------------------------------------------*/
/* External variables --------------------------------------------------------*/
/* Exported macros -----------------------------------------------------------*/
/* Exported functions ------------------------------------------------------- */
/**
* @brief Initializes the SPI object and MCU peripheral
*
* @param [IN] None
* @retval None
*/
void HW_SPI_Init(void);
/**
* @brief De-initializes the SPI object and MCU peripheral
*
* @param [IN] None
* @retval None
*/
void HW_SPI_DeInit(void);
/**
* @brief Initializes the SPI IOs
*
* @param [IN] None
* @retval None
*/
void HW_SPI_IoInit(void);
/**
* @brief De-initializes the SPI IOs
*
* @param [IN] None
* @retval None
*/
void HW_SPI_IoDeInit(void);
/**
* @brief Sends outData and receives inData
*
* @param [IN] outData Byte to be sent
* @retval inData Received byte.
* @note This is an implementation of
* HAL_SPI_TransmitReceive(&hspi, (uint8_t *)&txData, (uint8_t*)&rxData, 1, HAL_MAX_DELAY);
*/
uint16_t HW_SPI_InOut(uint16_t outData);
#ifdef __cplusplus
}
#endif
#endif /* __HW_SPI_H__ */
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

View file

@ -0,0 +1,252 @@
/*
/ _____) _ | |
( (____ _____ ____ _| |_ _____ ____| |__
\____ \| ___ | (_ _) ___ |/ ___) _ \
_____) ) ____| | | || |_| ____( (___| | | |
(______/|_____)_|_|_| \__)_____)\____)_| |_|
(C)2013 Semtech
Description: LoRaMac classA device implementation
License: Revised BSD License, see LICENSE.TXT file include in the project
Maintainer: Miguel Luis, Gregory Cristian and Wael Guibene
*/
/******************************************************************************
* @file lora.h
* @author MCD Application Team
* @version V1.1.1
* @date 01-June-2017
* @brief lora API to drive the lora state Machine
******************************************************************************
* @attention
*
* <h2><center>&copy; 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 __LORA_MAIN_H__
#define __LORA_MAIN_H__
#ifdef __cplusplus
extern "C" {
#endif
/* Includes ------------------------------------------------------------------*/
#include "Comissioning.h"
#include "LoRaMac.h"
#include "region/Region.h"
/* Exported constants --------------------------------------------------------*/
/* Exported types ------------------------------------------------------------*/
/*!
* Application Data structure
*/
typedef struct
{
/*point to the LoRa App data buffer*/
uint8_t* Buff;
/*LoRa App data buffer size*/
uint8_t BuffSize;
/*Port on which the LoRa App is data is sent/ received*/
uint8_t Port;
} lora_AppData_t;
/*!
* LoRa State Machine states
*/
typedef enum eDevicState
{
DEVICE_STATE_INIT,
DEVICE_STATE_JOIN,
DEVICE_STATE_JOINED,
DEVICE_STATE_SEND,
DEVICE_STATE_CYCLE,
DEVICE_STATE_SLEEP
} DeviceState_t;
/*!
* LoRa State Machine states
*/
typedef enum eTxEventType
{
/*!
* @brief AppdataTransmition issue based on timer every TxDutyCycleTime
*/
TX_ON_TIMER,
/*!
* @brief AppdataTransmition external event plugged on OnSendEvent( )
*/
TX_ON_EVENT
} TxEventType_t;
/*!
* LoRa State Machine states
*/
typedef struct sLoRaParam
{
/*!
* @brief Event type
*
* @retval value battery level ( 0: very low, 254: fully charged )
*/
TxEventType_t TxEvent;
/*!
* @brief Application data transmission duty cycle in ms
*
* @note when TX_ON_TIMER Event type is selected
*/
uint32_t TxDutyCycleTime;
/*!
* @brief LoRaWAN device class
*/
DeviceClass_t Class;
/*!
* @brief Activation state of adaptativeDatarate
*/
bool AdrEnable;
/*!
* @brief Uplink datarate, if AdrEnable is off
*/
int8_t TxDatarate;
/*!
* @brief Enable or disable a public network
*
*/
bool EnablePublicNetwork;
/*!
* @brief Number of trials for the join request.
*/
uint8_t NbTrials;
} LoRaParam_t;
/* Lora Main callbacks*/
typedef struct sLoRaMainCallback
{
/*!
* @brief Get the current battery level
*
* @retval value battery level ( 0: very low, 254: fully charged )
*/
uint8_t ( *BoardGetBatteryLevel )( void );
/*!
* @brief Gets the board 64 bits unique ID
*
* @param [IN] id Pointer to an array that will contain the Unique ID
*/
void ( *BoardGetUniqueId ) ( uint8_t *id);
/*!
* Returns a pseudo random seed generated using the MCU Unique ID
*
* @retval seed Generated pseudo random seed
*/
uint32_t ( *BoardGetRandomSeed ) (void);
/*!
* @brief Prepares Tx Data to be sent on Lora network
*
* @param [IN] AppData is a buffer to fill
*
* @param [IN] port is a Application port on wicth Appdata will be sent
*
* @param [IN] length of the AppDataBuffer to send
*
* @param [IN] requests a confirmed Frame from the Network
*/
void ( *LoraTxData ) ( lora_AppData_t *AppData, FunctionalState* IsTxConfirmed);
/*!
* @brief Process Rx Data received from Lora network
*
* @param [IN] AppData is a buffer to process
*
* @param [IN] port is a Application port on wicth Appdata will be sent
*
* @param [IN] length is the number of recieved bytes
*/
void ( *LoraRxData ) ( lora_AppData_t *AppData);
} LoRaMainCallback_t;
/* External variables --------------------------------------------------------*/
/* Exported macros -----------------------------------------------------------*/
/* Exported functions ------------------------------------------------------- */
/**
* @brief Lora Initialisation
* @param [IN] LoRaMainCallback_t
* @param [IN] application parmaters
* @retval none
*/
void lora_Init (LoRaMainCallback_t *callbacks, LoRaParam_t* LoRaParam );
/**
* @brief run Lora classA state Machine
* @param [IN] none
* @retval none
*/
void lora_fsm( void );
/**
* @brief functionl requesting loRa state machine to send data
* @note function to link in mode TX_ON_EVENT
* @param none
* @retval none
*/
void OnSendEvent( void );
/**
* @brief API returns the state of the lora state machine
* @note return @DeviceState_t state
* @param [IN] none
* @retval return @FlagStatus
*/
DeviceState_t lora_getDeviceState( void );
#ifdef __cplusplus
}
#endif
#endif /*__LORA_MAIN_H__*/
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

View file

@ -0,0 +1,35 @@
/*
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __LORAWAN_PORT_H__
#define __LORAWAN_PORT_H__
#ifdef __cplusplus
extern "C" {
#endif
/* Includes ------------------------------------------------------------------*/
#include <string.h>
#include <stdio.h>
#include "hal/lorawan.h"
#include "utilities.h"
#include <k_api.h>
typedef uint32_t time_ms_t;
typedef uint32_t time_tick_t;
extern hal_lrwan_dev_chg_mode_t aos_lrwan_chg_mode;
extern hal_lrwan_time_itf_t aos_lrwan_time_itf;
extern hal_lrwan_radio_ctrl_t aos_lrwan_radio_ctrl;
#ifdef __cplusplus
}
#endif
#endif /* lorawan_port.h */

View file

@ -0,0 +1,322 @@
/**
******************************************************************************
* @file stm32l0xx_hal_conf.h
* @author MCD Application Team
* @version V1.1.1
* @date 01-June-2017
* @brief HAL configuration file.
******************************************************************************
* @attention
*
* <h2><center>&copy; 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
#include "stm32l0xx_hal_def.h"
/* 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****/

View file

@ -0,0 +1,162 @@
/*
/ _____) _ | |
( (____ _____ ____ _| |_ _____ ____| |__
\____ \| ___ | (_ _) ___ |/ ___) _ \
_____) ) ____| | | || |_| ____( (___| | | |
(______/|_____)_|_|_| \__)_____)\____)_| |_|
(C)2013 Semtech
Description: virtual com port driver
License: Revised BSD License, see LICENSE.TXT file include in the project
Maintainer: Miguel Luis and Gregory Cristian
*/
/******************************************************************************
* @file vcom.h
* @author MCD Application Team
* @version V1.1.1
* @date 01-June-2017
* @brief Header for vcom.c module
******************************************************************************
* @attention
*
* <h2><center>&copy; 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 __VCOM_H__
#define __VCOM_H__
#ifdef __cplusplus
extern "C" {
#endif
/* Includes ------------------------------------------------------------------*/
#include "hw_conf.h"
/* Exported types ------------------------------------------------------------*/
/* Exported constants --------------------------------------------------------*/
/* External variables --------------------------------------------------------*/
/* Exported functions ------------------------------------------------------- */
/**
* @brief Init the VCOM.
* @param None
* @retval None
*/
void vcom_Init(void);
/**
* @brief DeInit the VCOM.
* @param None
* @retval None
*/
void vcom_DeInit(void);
/**
* @brief Init the VCOM IOs.
* @param None
* @retval None
*/
void vcom_IoInit(void);
/**
* @brief Init the VCOM RX
* @param None
* @retval None
*/
void vcom_ReceiveInit(void);
/**
* @brief DeInit the VCOM IOs.
* @param None
* @retval None
*/
void vcom_IoDeInit(void);
/**
* @brief Sends string on com port
* @param String
* @retval None
*/
void vcom_Send(const char *format, ...);
/**
* @brief Checks if a new character has been received on com port
* @param None
* @retval Returns SET if new character has been received on com port, RESET otherwise
*/
FlagStatus IsNewCharReceived(void);
/**
* @brief Gets new received characters on com port
* @param None
* @retval Returns the character
*/
uint8_t GetNewChar(void);
/**
* @brief vcom IRQ Handler
* @param None
* @retval None
*/
void vcom_IRQHandler(void);
void DBG_Send(const char *format, ...);
void DBG_Uart_Init(void);
void DBG_Uart_Deinit(void);
/* Exported macros -----------------------------------------------------------*/
#if 1
#include "debug.h"
#define PRINTF_RAW(...) DBG_Send(__VA_ARGS__)
#define PRINTF DBG_PRINTF
#else
#define PRINTF_RAW(...)
#define PRINTF(...)
#endif
#ifdef __cplusplus
}
#endif
#endif /* __VCOM_H__*/
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

View file

@ -0,0 +1,89 @@
/*
/ _____) _ | |
( (____ _____ ____ _| |_ _____ ____| |__
\____ \| ___ | (_ _) ___ |/ ___) _ \
_____) ) ____| | | || |_| ____( (___| | | |
(______/|_____)_|_|_| \__)_____)\____)_| |_|
(C)2013 Semtech
Description: LoRaMac classA device implementation
License: Revised BSD License, see LICENSE.TXT file include in the project
Maintainer: Miguel Luis, Gregory Cristian and Wael Guibene
*/
/******************************************************************************
* @file version.h
* @author MCD Application Team
* @version V1.1.1
* @date 01-June-2017
* @brief defines the lora mac version
******************************************************************************
* @attention
*
* <h2><center>&copy; 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 __VERSION_H__
#define __VERSION_H__
#ifdef __cplusplus
extern "C" {
#endif
/* Includes ------------------------------------------------------------------*/
#define LORA_MAC_VERSION (uint32_t) 0x44020000
/* Exported constants --------------------------------------------------------*/
#define TEST_VERSION (uint32_t) 0x00000000 /*1 lsb is always 0 in releases */
#define LRWAN_VERSION (uint32_t) 0x00001110 /*3 next hex is i_cube release*/
#define VERSION (uint32_t) (LORA_MAC_VERSION | LRWAN_VERSION | TEST_VERSION)
#define AT_VERSION_STRING "3.1.3"
#define AT_VERSION_LORAWAN_STRING "1.0.2"
/* Exported types ------------------------------------------------------------*/
/* External variables --------------------------------------------------------*/
/* Exported macros -----------------------------------------------------------*/
/* Exported functions ------------------------------------------------------- */
#ifdef __cplusplus
}
#endif
#endif /*__VERSION_H__*/
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

View file

@ -0,0 +1,229 @@
/*
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
*/
#ifndef CONFIG_H
#define CONFIG_H
/* chip level conf */
#ifndef RHINO_CONFIG_LITTLE_ENDIAN
#define RHINO_CONFIG_LITTLE_ENDIAN 1
#endif
#ifndef RHINO_CONFIG_CPU_STACK_DOWN
#define RHINO_CONFIG_CPU_STACK_DOWN 1
#endif
/* kernel feature conf */
#ifndef RHINO_CONFIG_SEM
#define RHINO_CONFIG_SEM 0
#endif
#ifndef RHINO_CONFIG_QUEUE
#define RHINO_CONFIG_QUEUE 0
#endif
#ifndef RHINO_CONFIG_TASK_SEM
#define RHINO_CONFIG_TASK_SEM 0
#endif
#ifndef RHINO_CONFIG_EVENT_FLAG
#define RHINO_CONFIG_EVENT_FLAG 0
#endif
#ifndef RHINO_CONFIG_TIMER
#define RHINO_CONFIG_TIMER 0
#endif
#ifndef RHINO_CONFIG_BUF_QUEUE
#define RHINO_CONFIG_BUF_QUEUE 0
#endif
#ifndef RHINO_CONFIG_MM_BLK
#define RHINO_CONFIG_MM_BLK 0
#endif
#ifndef RHINO_CONFIG_MM_DEBUG
#define RHINO_CONFIG_MM_DEBUG 0
#endif
#ifndef RHINO_CONFIG_MM_TLF
#define RHINO_CONFIG_MM_TLF 0
#endif
#ifndef RHINO_CONFIG_MM_TLF_BLK_SIZE
#define RHINO_CONFIG_MM_TLF_BLK_SIZE 1024
#endif
#define K_MM_STATISTIC 0
#ifndef RHINO_CONFIG_MM_MAXMSIZEBIT
#define RHINO_CONFIG_MM_MAXMSIZEBIT 19
#endif
#ifndef RHINO_CONFIG_GCC_RETADDR
#define RHINO_CONFIG_GCC_RETADDR 0
#endif
#ifndef RHINO_CONFIG_MM_LEAKCHECK
#define RHINO_CONFIG_MM_LEAKCHECK 0
#endif
#ifndef RHINO_CONFIG_RINGBUF_VENDOR
#define RHINO_CONFIG_RINGBUF_VENDOR 0
#endif
#ifndef RHINO_CONFIG_KOBJ_SET
#define RHINO_CONFIG_KOBJ_SET 0
#endif
/* kernel task conf */
#ifndef RHINO_CONFIG_TASK_SUSPEND
#define RHINO_CONFIG_TASK_SUSPEND 1
#endif
#ifndef RHINO_CONFIG_TASK_INFO
#define RHINO_CONFIG_TASK_INFO 0
#endif
#ifndef RHINO_CONFIG_TASK_DEL
#define RHINO_CONFIG_TASK_DEL 0
#endif
#ifndef RHINO_CONFIG_TASK_STACK_CUR_CHECK
#define RHINO_CONFIG_TASK_STACK_CUR_CHECK 0
#endif
#ifndef RHINO_CONFIG_TASK_WAIT_ABORT
#define RHINO_CONFIG_TASK_WAIT_ABORT 0
#endif
#ifndef RHINO_CONFIG_TASK_STACK_OVF_CHECK
#define RHINO_CONFIG_TASK_STACK_OVF_CHECK 1
#endif
#ifndef RHINO_CONFIG_SCHED_RR
#define RHINO_CONFIG_SCHED_RR 0
#endif
#ifndef RHINO_CONFIG_TIME_SLICE_DEFAULT
#define RHINO_CONFIG_TIME_SLICE_DEFAULT 50
#endif
#ifndef RHINO_CONFIG_PRI_MAX
#define RHINO_CONFIG_PRI_MAX 5
#endif
#ifndef RHINO_CONFIG_USER_PRI_MAX
#define RHINO_CONFIG_USER_PRI_MAX (RHINO_CONFIG_PRI_MAX - 2)
#endif
/* kernel workqueue conf */
#ifndef RHINO_CONFIG_WORKQUEUE
#define RHINO_CONFIG_WORKQUEUE 0
#endif
#ifndef RHINO_CONFIG_WORKQUEUE_STACK_SIZE
#define RHINO_CONFIG_WORKQUEUE_STACK_SIZE 768
#endif
/* kernel mm_region conf */
#ifndef RHINO_CONFIG_MM_REGION_MUTEX
#define RHINO_CONFIG_MM_REGION_MUTEX 0
#endif
/* kernel timer&tick conf */
#ifndef RHINO_CONFIG_HW_COUNT
#define RHINO_CONFIG_HW_COUNT 0
#endif
#ifndef RHINO_CONFIG_TICK_TASK
#define RHINO_CONFIG_TICK_TASK 0
#endif
#if (RHINO_CONFIG_TICK_TASK > 0)
#ifndef RHINO_CONFIG_TICK_TASK_STACK_SIZE
#define RHINO_CONFIG_TICK_TASK_STACK_SIZE 256
#endif
#ifndef RHINO_CONFIG_TICK_TASK_PRI
#define RHINO_CONFIG_TICK_TASK_PRI 1
#endif
#endif
#ifndef RHINO_CONFIG_TICKLESS
#define RHINO_CONFIG_TICKLESS 0
#endif
#ifndef RHINO_CONFIG_TICKS_PER_SECOND
#define RHINO_CONFIG_TICKS_PER_SECOND 100
#endif
/* must be 2^n size!, such as 1, 2, 4, 8, 16,32, etc....... */
#ifndef RHINO_CONFIG_TICK_HEAD_ARRAY
#define RHINO_CONFIG_TICK_HEAD_ARRAY 8
#endif
/*must reserve enough stack size for timer cb will consume*/
#ifndef RHINO_CONFIG_TIMER_TASK_STACK_SIZE
#define RHINO_CONFIG_TIMER_TASK_STACK_SIZE 300
#endif
#ifndef RHINO_CONFIG_TIMER_RATE
#define RHINO_CONFIG_TIMER_RATE 1
#endif
#ifndef RHINO_CONFIG_TIMER_TASK_PRI
#define RHINO_CONFIG_TIMER_TASK_PRI 13
#endif
/* kernel intrpt conf */
#ifndef RHINO_CONFIG_INTRPT_STACK_REMAIN_GET
#define RHINO_CONFIG_INTRPT_STACK_REMAIN_GET 0
#endif
#ifndef RHINO_CONFIG_INTRPT_STACK_OVF_CHECK
#define RHINO_CONFIG_INTRPT_STACK_OVF_CHECK 0
#endif
#ifndef RHINO_CONFIG_INTRPT_MAX_NESTED_LEVEL
#define RHINO_CONFIG_INTRPT_MAX_NESTED_LEVEL 188u
#endif
#ifndef RHINO_CONFIG_INTRPT_GUARD
#define RHINO_CONFIG_INTRPT_GUARD 0
#endif
/* kernel dyn alloc conf */
#ifndef RHINO_CONFIG_KOBJ_DYN_ALLOC
#define RHINO_CONFIG_KOBJ_DYN_ALLOC 0
#endif
#if (RHINO_CONFIG_KOBJ_DYN_ALLOC > 0)
#ifndef RHINO_CONFIG_K_DYN_QUEUE_MSG
#define RHINO_CONFIG_K_DYN_QUEUE_MSG 30
#endif
#ifndef RHINO_CONFIG_K_DYN_TASK_STACK
#define RHINO_CONFIG_K_DYN_TASK_STACK 256
#endif
#ifndef RHINO_CONFIG_K_DYN_MEM_TASK_PRI
#define RHINO_CONFIG_K_DYN_MEM_TASK_PRI 6
#endif
#endif
/* kernel idle conf */
#ifndef RHINO_CONFIG_IDLE_TASK_STACK_SIZE
#define RHINO_CONFIG_IDLE_TASK_STACK_SIZE 20
#endif
/* kernel hook conf */
#ifndef RHINO_CONFIG_USER_HOOK
#define RHINO_CONFIG_USER_HOOK 0
#endif
/* kernel stats conf */
#ifndef RHINO_CONFIG_SYSTEM_STATS
#define RHINO_CONFIG_SYSTEM_STATS 1
#endif
#ifndef RHINO_CONFIG_DISABLE_SCHED_STATS
#define RHINO_CONFIG_DISABLE_SCHED_STATS 0
#endif
#ifndef RHINO_CONFIG_DISABLE_INTRPT_STATS
#define RHINO_CONFIG_DISABLE_INTRPT_STATS 0
#endif
#ifndef RHINO_CONFIG_CPU_USAGE_STATS
#define RHINO_CONFIG_CPU_USAGE_STATS 0
#endif
#ifndef RHINO_CONFIG_CPU_USAGE_TASK_PRI
#define RHINO_CONFIG_CPU_USAGE_TASK_PRI (RHINO_CONFIG_PRI_MAX - 2)
#endif
#ifndef RHINO_CONFIG_TASK_SCHED_STATS
#define RHINO_CONFIG_TASK_SCHED_STATS 0
#endif
#ifndef RHINO_CONFIG_CPU_USAGE_TASK_STACK
#define RHINO_CONFIG_CPU_USAGE_TASK_STACK 256
#endif
#ifndef RHINO_CONFIG_CPU_NUM
#define RHINO_CONFIG_CPU_NUM 1
#endif
#ifndef RHINO_CONFIG_PANIC
#define RHINO_CONFIG_PANIC 0
#endif
#ifndef RHINO_CONFIG_BACKTRACE
#define RHINO_CONFIG_BACKTRACE 0
#endif
#endif /* CONFIG_H */

View file

@ -0,0 +1,116 @@
/******************************************************************************
* @file debug.c
* @author MCD Application Team
* @version V1.1.1
* @date 01-June-2017
* @brief debug API
******************************************************************************
* @attention
*
* <h2><center>&copy; 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.
*
******************************************************************************
*/
/* Includes ------------------------------------------------------------------*/
#include "hw.h"
/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
/* Private function prototypes -----------------------------------------------*/
/* Exported functions ------------------------------------------------------- */
void DBG_Init( void )
{
#ifdef LORA_DEBUG
GPIO_InitTypeDef gpioinitstruct;
/* Enable the GPIO_B Clock */
/* Clock is enabled in HW_GPIO_Init - LL_IOP_GRP1_EnableClock(LL_IOP_GRP1_PERIPH_GPIOB); */
/* Configure the GPIO pin */
gpioinitstruct.Mode = GPIO_MODE_OUTPUT_PP;
gpioinitstruct.Pull = GPIO_PULLUP;
gpioinitstruct.Speed = GPIO_SPEED_HIGH;
HW_GPIO_Init( GPIOB, (GPIO_PIN_12 | GPIO_PIN_13 | GPIO_PIN_14 | GPIO_PIN_15), &gpioinitstruct );
/* Reset debug Pins */
HW_GPIO_Write( GPIOB, GPIO_PIN_12, RESET );
HW_GPIO_Write( GPIOB, GPIO_PIN_13, RESET );
HW_GPIO_Write( GPIOB, GPIO_PIN_14, RESET );
HW_GPIO_Write( GPIOB, GPIO_PIN_15, RESET );
LL_APB2_GRP1_EnableClock( LL_APB2_GRP1_PERIPH_DBGMCU );
LL_DBGMCU_EnableDBGSleepMode( );
LL_DBGMCU_EnableDBGStopMode( );
LL_DBGMCU_EnableDBGStandbyMode( );
#else /* DEBUG */
#if 0
/* sw interface off*/
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitStructure.Mode = GPIO_MODE_ANALOG;
GPIO_InitStructure.Pull = GPIO_NOPULL;
/* Clock is enabled in HW_GPIO_Init - LL_IOP_GRP1_EnableClock(LL_IOP_GRP1_PERIPH_GPIOA); */
HW_GPIO_Init(GPIOA, (GPIO_PIN_13 | GPIO_PIN_14), &GPIO_InitStructure);
LL_IOP_GRP1_DisableClock(LL_IOP_GRP1_PERIPH_GPIOA);
LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_DBGMCU);
LL_DBGMCU_DisableDBGSleepMode();
LL_DBGMCU_DisableDBGStopMode();
LL_DBGMCU_DisableDBGStandbyMode();
LL_APB2_GRP1_DisableClock(LL_APB2_GRP1_PERIPH_DBGMCU);
#endif
#endif
}
void Error_Handler( void )
{
DBG_PRINTF( "Error_Handler\n\r" );
while ( 1 )
{
;
}
}
void _printf_float()
{
}
/* Private functions ---------------------------------------------------------*/
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,155 @@
/*
/ _____) _ | |
( (____ _____ ____ _| |_ _____ ____| |__
\____ \| ___ | (_ _) ___ |/ ___) _ \
_____) ) ____| | | || |_| ____( (___| | | |
(______/|_____)_|_|_| \__)_____)\____)_| |_|
(C)2013 Semtech
Description: Bleeper board GPIO driver implementation
License: Revised BSD License, see LICENSE.TXT file include in the project
Maintainer: Miguel Luis and Gregory Cristian
*/
/******************************************************************************
* @file eml3047_it.c
* @author MCD Application Team
* @version V1.1.1
* @date 01-June-2017
* @brief manages interupt
******************************************************************************
* @attention
*
* <h2><center>&copy; 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.
*
******************************************************************************
*/
/* Includes ------------------------------------------------------------------*/
#include "hw.h"
#include "eml3047_it.h"
#include "low_power.h"
#include "vcom.h"
#include <k_api.h>
/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
/* Private function prototypes -----------------------------------------------*/
/* Functions Definition ------------------------------------------------------*/
void RTC_IRQHandler( void )
{
HW_RTC_IrqHandler( );
}
void EXTI0_1_IRQHandler( void )
{
HW_GPIO_EXTI_IRQHandler( GPIO_PIN_0 );
HW_GPIO_EXTI_IRQHandler( GPIO_PIN_1 );
}
void EXTI2_3_IRQHandler( void )
{
HW_GPIO_EXTI_IRQHandler( GPIO_PIN_2 );
HW_GPIO_EXTI_IRQHandler( GPIO_PIN_3 );
}
void EXTI4_15_IRQHandler( void )
{
HW_GPIO_EXTI_IRQHandler( GPIO_PIN_4 );
HW_GPIO_EXTI_IRQHandler( GPIO_PIN_5 );
HW_GPIO_EXTI_IRQHandler( GPIO_PIN_6 );
HW_GPIO_EXTI_IRQHandler( GPIO_PIN_7 );
HW_GPIO_EXTI_IRQHandler( GPIO_PIN_8 );
HW_GPIO_EXTI_IRQHandler( GPIO_PIN_9 );
HW_GPIO_EXTI_IRQHandler( GPIO_PIN_10 );
HW_GPIO_EXTI_IRQHandler( GPIO_PIN_11 );
HW_GPIO_EXTI_IRQHandler( GPIO_PIN_12 );
HW_GPIO_EXTI_IRQHandler( GPIO_PIN_13 );
HW_GPIO_EXTI_IRQHandler( GPIO_PIN_14 );
HW_GPIO_EXTI_IRQHandler( GPIO_PIN_15 );
}
void UARTX_IRQHandler( void )
{
vcom_IRQHandler( );
}
void USART4_5_IRQHandler(void)
{
int rx_ready = 0;
char rx;
CPSR_ALLOC();
RHINO_CPU_INTRPT_DISABLE();
if ( LL_USART_IsActiveFlag_RXNE(USART4) && (LL_USART_IsEnabledIT_RXNE(USART4 ) != RESET) )
{
/* no need to clear the RXNE flag because it is auto cleared by reading the data*/
rx = LL_USART_ReceiveData8( USART4 );
rx_ready = 1;
}
if (rx_ready) {
#ifdef CONFIG_LINKWAN_AT
extern void linkwan_serial_input(uint8_t cmd);
linkwan_serial_input(rx);
#endif
}
RHINO_CPU_INTRPT_ENABLE();
}
int linkwan_serial_output(uint8_t *buffer, int len)
{
int index;
for (index = 0; index < len; index++ ) {
LL_USART_ClearFlag_TC(USART4);
LL_USART_TransmitData8(USART4, buffer[index]);
while (LL_USART_IsActiveFlag_TC(USART4) != SET) {
;
}
}
LL_USART_ClearFlag_TC(USART4);
return len;
}
/* Private functions ---------------------------------------------------------*/
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

View file

@ -0,0 +1,395 @@
/*
/ _____) _ | |
( (____ _____ ____ _| |_ _____ ____| |__
\____ \| ___ | (_ _) ___ |/ ___) _ \
_____) ) ____| | | || |_| ____( (___| | | |
(______/|_____)_|_|_| \__)_____)\____)_| |_|
(C)2013 Semtech
Description: Bleeper board GPIO driver implementation
License: Revised BSD License, see LICENSE.TXT file include in the project
Maintainer: Miguel Luis and Gregory Cristian
*/
/******************************************************************************
* @file hw_gpio.c
* @author MCD Application Team
* @version V1.1.1
* @date 01-June-2017
* @brief driver for GPIO
******************************************************************************
* @attention
*
* <h2><center>&copy; 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.
*
******************************************************************************
*/
/* Includes ------------------------------------------------------------------*/
#include "hw.h"
/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
/* Private macro -------------------------------------------------------------*/
#define EXTI_MODE ((uint32_t)0x10000000U)
/* Private variables ---------------------------------------------------------*/
static GpioIrqHandler *GpioIrq[16] = { NULL };
/* Private function prototypes -----------------------------------------------*/
/**
* @brief Get the position of the bit set in the GPIO_Pin
* @param GPIO_Pin: specifies the port bit to be written.
* This parameter can be one of GPIO_PIN_x where x can be (0..15).
* All port bits are not necessarily available on all GPIOs.
* @retval the position of the bit
*/
static uint8_t HW_GPIO_GetBitPos( uint16_t GPIO_Pin );
/*
* @brief Helper to initialize a single pin, given its position from 0 to 16.
*
* @param GPIOx: where x can be (A..E and H)
* @param position: position (from 0 to 15) of the single pin t
* @param initStruct: GPIO_InitTypeDef init structure
* @retval none
* @note The supported modes ares:
* GPIO_MODE_ANALOG
* GPIO_MODE_INPUT
* GPIO_MODE_IT_RISING
* GPIO_MODE_OUTPUT_PP
* GPIO_MODE_AF_PP
*/
static void HW_GPIO_Init_singlepin( GPIO_TypeDef *GPIOx, int position, GPIO_InitTypeDef *GPIO_Init );
/**
* @brief Initializes the given GPIO object, similarly to the HAL function HAL_GPIO_Init()
*
* @param GPIOx: where x can be (A..E and H)
* @param GPIO_Pin: specifies the port bit to be written.
* This parameter can be one of GPIO_PIN_x where x can be (0..15).
* All port bits are not necessarily available on all GPIOs.
* @param [IN] initStruct GPIO_InitTypeDef intit structure
* @retval none
* @note The supported modes ares:
* GPIO_MODE_ANALOG
* GPIO_MODE_INPUT
* GPIO_MODE_IT_RISING
* GPIO_MODE_OUTPUT_PP
* GPIO_MODE_AF_PP
*/
static void HW_GPIO_Init_HAL( GPIO_TypeDef *GPIOx, uint16_t GPIO_Pin, GPIO_InitTypeDef *GPIO_Init );
/**
* @brief Deinitialize the given GPIO object given its single pin position
* @param GPIOx: where x can be (A..E and H)
* @param position: the position (0..15) of the pin to uninitialize
* @retval none
*/
static void HW_GPIO_DeInit_singlepin( GPIO_TypeDef *GPIOx, int position );
/**
* @brief Gets IRQ number as a function of the GPIO_Pin.
* @param GPIO_Pin: Specifies the pins connected to the EXTI line.
* @retval IRQ number
*/
static IRQn_Type GetIRQn( uint16_t GPIO_Pin );
/* Exported functions ---------------------------------------------------------*/
void HW_GPIO_Init( GPIO_TypeDef *port, uint16_t GPIO_Pin, GPIO_InitTypeDef *initStruct )
{
RCC_GPIO_CLK_ENABLE( (uint32_t )port );
HW_GPIO_Init_HAL( port, GPIO_Pin, initStruct );
}
void HW_GPIO_SetIrq( GPIO_TypeDef *GPIOx, uint16_t GPIO_Pin, uint32_t prio, GpioIrqHandler *irqHandler )
{
IRQn_Type IRQnb;
uint32_t BitPos = HW_GPIO_GetBitPos( GPIO_Pin );
if ( irqHandler != NULL )
{
GpioIrq[BitPos] = irqHandler;
IRQnb = GetIRQn( GPIO_Pin );
NVIC_SetPriority( IRQnb, prio );
NVIC_EnableIRQ( IRQnb );
}
}
void HW_GPIO_IrqHandler( uint16_t GPIO_Pin )
{
uint32_t BitPos = HW_GPIO_GetBitPos( GPIO_Pin );
if ( GpioIrq[BitPos] != NULL )
{
GpioIrq[BitPos]( );
}
}
uint32_t HW_GPIO_Read( GPIO_TypeDef *GPIOx, uint16_t GPIO_Pin )
{
uint32_t pin_value;
pin_value = LL_GPIO_ReadInputPort( GPIOx );
if ( (pin_value & GPIO_Pin) != (uint32_t) RESET )
{
return SET;
}
else
{
return RESET;
}
}
void HW_GPIO_DeInit( GPIO_TypeDef *GPIOx, uint32_t GPIO_Pin )
{
int position;
assert_param( IS_GPIO_PIN_AVAILABLE(GPIOx, (GPIO_Pin)) );
position = 0;
while ( GPIO_Pin != 0 )
{
if ( GPIO_Pin & 0x1 )
{
HW_GPIO_DeInit_singlepin( GPIOx, position );
}
position++;
GPIO_Pin = GPIO_Pin >> 1;
}
}
void HW_GPIO_EXTI_IRQHandler( uint16_t GPIO_Pin )
{
/* EXTI line interrupt detected */
if ( LL_EXTI_ReadFlag_0_31( GPIO_Pin ) != RESET )
{
LL_EXTI_ClearFlag_0_31( GPIO_Pin );
HW_GPIO_IrqHandler( GPIO_Pin );
}
}
/* Private functions ---------------------------------------------------------*/
static uint8_t HW_GPIO_GetBitPos( uint16_t GPIO_Pin )
{
uint8_t PinPos = 0;
if ( (GPIO_Pin & 0xFF00) != 0 )
{
PinPos |= 0x8;
}
if ( (GPIO_Pin & 0xF0F0) != 0 )
{
PinPos |= 0x4;
}
if ( (GPIO_Pin & 0xCCCC) != 0 )
{
PinPos |= 0x2;
}
if ( (GPIO_Pin & 0xAAAA) != 0 )
{
PinPos |= 0x1;
}
return PinPos;
}
static void HW_GPIO_Init_singlepin( GPIO_TypeDef *GPIOx, int position, GPIO_InitTypeDef *GPIO_Init )
{
uint16_t GPIO_Pin;
uint32_t temp;
/* Check for specific constraints on this implementation */
assert_param( (GPIO_Init->Mode == GPIO_MODE_ANALOG) ||
(GPIO_Init->Mode == GPIO_MODE_INPUT) ||
(GPIO_Init->Mode == GPIO_MODE_IT_RISING) ||
(GPIO_Init->Mode == GPIO_MODE_OUTPUT_PP) ||
(GPIO_Init->Mode == GPIO_MODE_AF_PP) );
GPIO_Pin = 1 << position;
/* In case of Alternate function mode selection */
if ( GPIO_Init->Mode == GPIO_MODE_AF_PP )
{
/* Check if the Alternate function is compliant with the GPIO in use */
assert_param( IS_GPIO_AF_AVAILABLE(GPIOx, (GPIO_Init->Alternate)) );
/* Configure Alternate function mapped with the current IO */
/* the following code could be used to use LL functions, but the code size
* is then much higher
* if (position <= 7) LL_GPIO_SetAFPin_0_7(GPIOx, GPIO_Pin, GPIO_Init->Alternate);
* else LL_GPIO_SetAFPin_8_15(GPIOx, GPIO_Pin, GPIO_Init->Alternate);
*/
temp = GPIOx->AFR[position >> 3U];
temp &= ~((uint32_t) 0xFU << ((uint32_t) (position & (uint32_t) 0x07U) * 4U));
temp |= ((uint32_t) (GPIO_Init->Alternate) << (((uint32_t) position & (uint32_t) 0x07U) * 4U));
GPIOx->AFR[position >> 3U] = temp;
}
/* In case of Output or Alternate function mode selection */
if ( (GPIO_Init->Mode == GPIO_MODE_OUTPUT_PP) || (GPIO_Init->Mode == GPIO_MODE_AF_PP) )
{
/* Check the Speed parameter */
assert_param( IS_GPIO_SPEED(GPIO_Init->Speed) );
/* Configure the IO Speed */
LL_GPIO_SetPinSpeed( GPIOx, GPIO_Pin, GPIO_Init->Speed );
/* Configure the IO Output Type */
LL_GPIO_SetPinOutputType( GPIOx, GPIO_Pin, LL_GPIO_OUTPUT_PUSHPULL );
}
/* Configure IO Direction mode (Input, Output, Alternate or Analog) */
LL_GPIO_SetPinMode( GPIOx, GPIO_Pin, GPIO_Init->Mode );
/* Activate the Pull-up or Pull down resistor for the current IO */
LL_GPIO_SetPinPull( GPIOx, GPIO_Pin, GPIO_Init->Pull );
/*--------------------- EXTI Mode Configuration ------------------------*/
/* Configure the External Interrupt or event for the current IO */
if ( (GPIO_Init->Mode & EXTI_MODE) == EXTI_MODE )
{
/* Enable SYSCFG Clock */
LL_APB2_GRP1_EnableClock( LL_APB2_GRP1_PERIPH_SYSCFG );
LL_SYSCFG_SetEXTISource( GPIO_GET_INDEX( GPIOx ), (((4U * (position & 0x03U)) << 16U) | (position >> 2U)) );
/* Enable Raising IT, disable event and falling */
LL_EXTI_EnableIT_0_31( GPIO_Pin );
LL_EXTI_DisableEvent_0_31( GPIO_Pin );
LL_EXTI_EnableRisingTrig_0_31( GPIO_Pin );
LL_EXTI_DisableFallingTrig_0_31( GPIO_Pin );
}
}
static void HW_GPIO_Init_HAL( GPIO_TypeDef *GPIOx, uint16_t GPIO_Pin, GPIO_InitTypeDef *GPIO_Init )
{
int position;
/* Check the parameters */
assert_param( IS_GPIO_MODE(GPIO_Init->Mode) );
assert_param( IS_GPIO_PULL(GPIO_Init->Pull) );
assert_param( IS_GPIO_PIN_AVAILABLE(GPIOx, GPIO_Pin) );
position = 0;
while ( GPIO_Pin != 0 )
{
if ( GPIO_Pin & 0x1 )
{
HW_GPIO_Init_singlepin( GPIOx, position, GPIO_Init );
}
position++;
GPIO_Pin = GPIO_Pin >> 1;
}
}
static void HW_GPIO_DeInit_singlepin( GPIO_TypeDef *GPIOx, int position )
{
uint16_t GPIO_Pin = 1 << position;
uint32_t tmp;
/* Configure the port pins */
/*------------------------- GPIO Mode Configuration --------------------*/
/* Configure IO Direction in Input Floting Mode */
GPIOx->MODER &= ~(GPIO_MODER_MODE0 << (position * 2U));
/* Configure the default Alternate Function in current IO */
GPIOx->AFR[position >> 3U] &= ~((uint32_t) 0xFU << ((uint32_t) (position & (uint32_t) 0x07U) * 4U));
/* Configure the default value for IO Speed */
GPIOx->OSPEEDR &= ~(GPIO_OSPEEDER_OSPEED0 << (position * 2U));
/* Configure the default value IO Output Type */
GPIOx->OTYPER &= ~(GPIO_OTYPER_OT_0 << position);
/* Deactivate the Pull-up oand Pull-down resistor for the current IO */
GPIOx->PUPDR &= ~(GPIO_PUPDR_PUPD0 << (position * 2U));
/*------------------------- EXTI Mode Configuration --------------------*/
/* Clear the External Interrupt or Event for the current IO */
tmp = SYSCFG->EXTICR[position >> 2U];
tmp &= (((uint32_t) 0x0FU) << (4U * (position & 0x03U)));
if ( tmp == (GPIO_GET_INDEX(GPIOx) << (4U * (position & 0x03U))) )
{
tmp = ((uint32_t) 0x0FU) << (4U * (position & 0x03U));
SYSCFG->EXTICR[position >> 2U] &= ~tmp;
/* Clear EXTI line configuration */
LL_EXTI_DisableIT_0_31( GPIO_Pin );
LL_EXTI_DisableEvent_0_31( GPIO_Pin );
/* Clear Rising Falling edge configuration */
LL_EXTI_DisableRisingTrig_0_31( GPIO_Pin );
LL_EXTI_DisableFallingTrig_0_31( GPIO_Pin );
}
}
static IRQn_Type GetIRQn( uint16_t GPIO_Pin )
{
switch ( GPIO_Pin )
{
case GPIO_PIN_0:
case GPIO_PIN_1:
return EXTI0_1_IRQn;
case GPIO_PIN_2:
case GPIO_PIN_3:
return EXTI2_3_IRQn;
case GPIO_PIN_4:
case GPIO_PIN_5:
case GPIO_PIN_6:
case GPIO_PIN_7:
case GPIO_PIN_8:
case GPIO_PIN_9:
case GPIO_PIN_10:
case GPIO_PIN_11:
case GPIO_PIN_12:
case GPIO_PIN_13:
case GPIO_PIN_14:
case GPIO_PIN_15:
default:
return EXTI4_15_IRQn;
}
}
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

View file

@ -0,0 +1,801 @@
/*
/ _____) _ | |
( (____ _____ ____ _| |_ _____ ____| |__
\____ \| ___ | (_ _) ___ |/ ___) _ \
_____) ) ____| | | || |_| ____( (___| | | |
(______/|_____)_|_|_| \__)_____)\____)_| |_|
(C)2013 Semtech
Description: MCU RTC timer
License: Revised BSD License, see LICENSE.TXT file include in the project
Maintainer: Miguel Luis and Gregory Cristian
*/
/*******************************************************************************
* @file hw_rtc.c
* @author MCD Application Team
* @version V1.1.1
* @date 01-June-2017
* @brief driver for RTC
******************************************************************************
* @attention
*
* <h2><center>&copy; 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.
*
******************************************************************************
*/
/* Includes ------------------------------------------------------------------*/
#include "hw.h"
#include "low_power.h"
#include "timeServer.h"
/* Private typedef -----------------------------------------------------------*/
/**
* @brief Type structure, using LL
* @note The 1st members correspond exactly to LL_RTC_TimeTypeDef sructure
* so that LL_RTC_TIME_Init() can be used easily in the following
*/
typedef struct
{
uint32_t TimeFormat; /*< as defined in LL_RTC_TimeTypeDef */
uint8_t Hours; /*< as defined in LL_RTC_TimeTypeDef */
uint8_t Minutes; /*< as defined in LL_RTC_TimeTypeDef */
uint8_t Seconds; /*< as defined in LL_RTC_TimeTypeDef */
uint32_t SubSeconds; /*< subseconds, as LL_RTC_TimeTypeDef does not save them */
} HW_RTC_TimeTypeDef;
typedef LL_RTC_DateTypeDef HW_RTC_DateTypeDef;
/**
* @brief Timer context struture, containing time and date
*/
typedef struct
{
TimerTime_t Rtc_Time; /*< Reference time */
HW_RTC_TimeTypeDef RTC_Calndr_Time; /*< Reference time in calendar format */
HW_RTC_DateTypeDef RTC_Calndr_Date; /*< Reference date in calendar format */
} RtcTimerContext_t;
/* Private define ------------------------------------------------------------*/
/* MCU Wake Up Time */
#define MIN_ALARM_DELAY 3 /* in ticks */
/* subsecond number of bits */
#define N_PREDIV_S 10
/* Synchonuous prediv */
#define PREDIV_S ((1 << N_PREDIV_S) - 1)
/* Asynchonuous prediv */
#define PREDIV_A ((1 << (15 - N_PREDIV_S)) - 1)
/* Sub-second mask definition */
#if (N_PREDIV_S == 10)
#define HW_RTC_ALARMSUBSECONDMASK_SS14_10 ((uint32_t) (RTC_ALRMASSR_MASKSS_1 | RTC_ALRMASSR_MASKSS_3))
#define HW_RTC_ALARMSUBSECONDMASK HW_RTC_ALARMSUBSECONDMASK_SS14_10
#else
#error "Please define HW_RTC_ALARMSUBSECONDMASK"
#endif
/* RTC Time base in us */
#define USEC_NUMBER 1000000
#define MSEC_NUMBER (USEC_NUMBER / 1000)
#define RTC_ALARM_TIME_BASE (USEC_NUMBER >> N_PREDIV_S)
#define COMMON_FACTOR 3
#define CONV_NUMER (MSEC_NUMBER >> COMMON_FACTOR)
#define CONV_DENOM (1 << (N_PREDIV_S - COMMON_FACTOR))
#if defined (USE_B_EML3047)
#define HW_RTC_EXTI_LINE_ALARM_EVENT LL_EXTI_LINE_17
#else
#error Please check EXTI line to use
#endif
/* Private macro -------------------------------------------------------------*/
#define CALENDAR_VALUE(subsec, sec, min, hours, days) \
((((sec) + 60 * ((min) + 60 * ((hours) + 24 * (days)))) << N_PREDIV_S) + (PREDIV_S - (subsec)))
#define ADJUST_TIME(_x_, _y_, _t_) \
while ((_x_) >= (_t_)) { \
(_x_) -= (_t_); \
(_y_)++; \
}
/* Private variables ---------------------------------------------------------*/
/**
* @brief Indicates if the RTC is already Initalized or not
*/
static FlagStatus HW_RTC_Initalized = RESET;
/**
* @brief compensates MCU wakeup time
*/
static FlagStatus McuWakeUpTimeInitialized = RESET;
/**
* @brief compensates MCU wakeup time
*/
static int16_t McuWakeUpTimeCal = 0;
/**
* Number of seconds in a minute
*/
static const uint8_t SecondsInMinute = 60;
/**
* Number of minutes in an hour
*/
static const uint8_t MinutesInHour = 60;
/**
* Number of seconds in an hour
*/
static const uint16_t SecondsInHour = 3600;
/**
* Number of seconds in a day
*/
static const uint32_t SecondsInDay = 86400;
/**
* Number of hours in a day
*/
static const uint8_t HoursInDay = 24;
/**
* Number of days in a standard year
*/
static const uint16_t DaysInYear = 365;
/**
* Number of days in each month on a normal year
*/
static const uint8_t DaysInMonth[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
/**
* Keep the value of the RTC timer when the RTC alarm is set
* Set with the HW_RTC_SetTimerContext function
* Value is kept as a Reference to calculate alarm
*/
static RtcTimerContext_t RtcTimerContext;
/* Private function prototypes -----------------------------------------------*/
/**
* @brief Configures the RTC timer
* @note The timer is based on the RTC
* @param None
* @retval None
* @note Replicate the behavior of HAL_RTC_Init(), HAL_RTC_SetDate() and HAL_RTC_SetTime()
*/
static void HW_RTC_SetConfig( void );
/**
* @brief Configure alarm at init
* @param None
* @retval None
*/
static void HW_RTC_SetAlarmConfig( void );
/**
* @brief Start wake up alarm
* @note Alarm in RtcTimerContext.Rtc_Time + timeoutValue
* @param TimeoutValue in ticks
* @retval None
*/
static void HW_RTC_StartWakeUpAlarm( uint32_t timeoutValue );
/**
* @brief Get current time from calendar in ticks
* @param Pointer to RTC_DateStruct
* @param Pointer to RTC_TimeStruct
* @retval Time in ticks
*/
static TimerTime_t HW_RTC_GetCalendarValue( HW_RTC_DateTypeDef *RTC_DateStruct, HW_RTC_TimeTypeDef *RTC_TimeStruct );
/**
* @brief BIN to BCD conversion
* @param BIN value
* @retval BCD value
*/
static uint8_t HW_RTC_ByteToBcd2( uint8_t Value );
/**
* @brief BCD to BIN conversion
* @param BCD value
* @retval BIN value
*/
static uint8_t HW_RTC_Bcd2ToByte( uint8_t Value );
/**
* @brief Deactivate the Alarm-A
* @param none
* @retval none
* @note Implementation of HAL_RTC_DeactivateAlarm using LL
*/
static void HW_RTC_DeactivateAlarm( void );
/**
* @brief Handle Alarm interrupt request.
* @param None
* @retval None
* @note LL implementation of HAL_RTC_AlarmIRQHandler
* @note Does not take into account ALARMB
*/
static void HW_RTC_AlarmIRQHandler( void );
/**
* @brief Initializes the RCC Oscillators according to this specific configuration
* RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_LSE;
* RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;
* RCC_OscInitStruct.LSEState = RCC_LSE_ON;
* @param None
* @retval None
*/
static void HW_RCC_OscConfig( void );
/**
* @brief Initializes the RCC extended peripherals clocks
* @note This is a specific implementation with
* PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_RTC;
* PeriphClkInitStruct.RTCClockSelection = RCC_RTCCLKSOURCE_LSE;
* @param None
* @retval None
*/
static void HW_RCCEx_PeriphCLKConfig( void );
/* Exported functions ---------------------------------------------------------*/
void HW_RTC_Init( void )
{
if ( HW_RTC_Initalized == RESET )
{
HW_RTC_SetConfig( );
HW_RTC_SetAlarmConfig( );
HW_RTC_SetTimerContext( );
HW_RTC_Initalized = SET;
}
}
void HW_RTC_setMcuWakeUpTime( void )
{
HW_RTC_TimeTypeDef RTC_TimeStruct;
HW_RTC_DateTypeDef RTC_DateStruct;
uint16_t rtcAlarmSubSeconds;
uint16_t rtcAlarmSeconds;
uint16_t rtcAlarmMinutes;
uint16_t rtcAlarmHours;
uint16_t rtcAlarmDays;
TimerTime_t now, hit;
int16_t McuWakeUpTime;
if ( (McuWakeUpTimeInitialized == RESET) &&
(NVIC_GetPendingIRQ( RTC_Alarm_IRQn ) == 1) )
{ /* warning: works ok if now is below 30 days
it is ok since it's done once at first alarm wake-up*/
McuWakeUpTimeInitialized = SET;
now = HW_RTC_GetCalendarValue( &RTC_DateStruct, &RTC_TimeStruct );
DBG_GPIO_SET( GPIOB, GPIO_PIN_13 );
DBG_GPIO_RST( GPIOB, GPIO_PIN_13 );
rtcAlarmSubSeconds = LL_RTC_ALMA_GetSubSecond( RTC );
rtcAlarmHours = HW_RTC_Bcd2ToByte( LL_RTC_ALMA_GetHour( RTC ) );
rtcAlarmMinutes = HW_RTC_Bcd2ToByte( LL_RTC_ALMA_GetMinute( RTC ) );
rtcAlarmSeconds = HW_RTC_Bcd2ToByte( LL_RTC_ALMA_GetSecond( RTC ) );
rtcAlarmDays = LL_RTC_ALMA_GetDay( RTC );
hit = CALENDAR_VALUE( rtcAlarmSubSeconds, rtcAlarmSeconds, rtcAlarmMinutes, rtcAlarmHours, rtcAlarmDays );
McuWakeUpTime = (int16_t) ((now - hit));
McuWakeUpTimeCal += McuWakeUpTime;
}
}
uint32_t HW_RTC_GetMinimumTimeout( void )
{
return (MIN_ALARM_DELAY);
}
uint32_t HW_RTC_ms2Tick( TimerTime_t timeMicroSec )
{
return (uint32_t) ((((uint64_t) timeMicroSec) * CONV_DENOM) / CONV_NUMER);
}
TimerTime_t HW_RTC_Tick2ms( uint32_t tick )
{
return (((uint64_t)( tick ) * CONV_NUMER) / CONV_DENOM);
}
void HW_RTC_SetAlarm( uint32_t timeout )
{
/* we don't go in Low Power mode for timeout below MIN_ALARM_DELAY */
if ( (MIN_ALARM_DELAY + McuWakeUpTimeCal) < ((timeout - HW_RTC_GetTimerElapsedTime( ))) )
{
LowPower_Enable( e_LOW_POWER_RTC );
}
else
{
LowPower_Disable( e_LOW_POWER_RTC );
}
if ( LowPower_GetState( ) == 0 )
{
LowPower_Enable( e_LOW_POWER_RTC );
timeout = timeout - McuWakeUpTimeCal;
}
HW_RTC_StartWakeUpAlarm( timeout );
}
uint32_t HW_RTC_GetTimerElapsedTime( void )
{
HW_RTC_TimeTypeDef RTC_TimeStruct;
HW_RTC_DateTypeDef RTC_DateStruct;
TimerTime_t CalendarValue = HW_RTC_GetCalendarValue( &RTC_DateStruct, &RTC_TimeStruct );
return ((uint32_t) (CalendarValue - RtcTimerContext.Rtc_Time));
}
uint32_t HW_RTC_GetTimerValue( void )
{
HW_RTC_TimeTypeDef RTC_TimeStruct;
HW_RTC_DateTypeDef RTC_DateStruct;
uint32_t CalendarValue = (uint32_t) HW_RTC_GetCalendarValue( &RTC_DateStruct, &RTC_TimeStruct );
return (CalendarValue);
}
void HW_RTC_StopAlarm( void )
{
/* Clear RTC Alarm Flag */
LL_RTC_ClearFlag_ALRA( RTC );
/* Disable the Alarm A interrupt */
HW_RTC_DeactivateAlarm( );
}
void HW_RTC_IrqHandler( void )
{
HW_RTC_AlarmIRQHandler( );
}
void HW_RTC_DelayMs( uint32_t delay )
{
TimerTime_t delayValue = 0;
TimerTime_t timeout = 0;
delayValue = HW_RTC_ms2Tick( delay );
/* Wait delay ms */
timeout = HW_RTC_GetTimerValue( );
while ( ((HW_RTC_GetTimerValue( ) - timeout)) < delayValue )
{
__NOP( );
}
}
uint32_t HW_RTC_SetTimerContext( void )
{
RtcTimerContext.Rtc_Time = HW_RTC_GetCalendarValue( &RtcTimerContext.RTC_Calndr_Date,
&RtcTimerContext.RTC_Calndr_Time );
return (uint32_t) RtcTimerContext.Rtc_Time;
}
uint32_t HW_RTC_GetTimerContext( void )
{
return (uint32_t) RtcTimerContext.Rtc_Time;
}
/* Private functions ---------------------------------------------------------*/
static void HW_RTC_SetConfig( void )
{
/*
* clock initialization
* - Enable LSE Oscillator
* - Select LSI as RTC clock source
* - Enable RTC Clock
* - Configure the NVIC for RTC Alarm
*/
HW_RCC_OscConfig( );
HW_RCCEx_PeriphCLKConfig( );
LL_RCC_EnableRTC( );
NVIC_SetPriority( RTC_Alarm_IRQn, 0x0 );
NVIC_EnableIRQ( RTC_Alarm_IRQn );
/* Disable write protection so that RTC can be initialized */
LL_RTC_DisableWriteProtection( RTC );
/* Enter init mode */
LL_RTC_EnterInitMode( RTC );
/* Clear RTC_CR FMT, OSEL and POL Bits */
LL_RTC_SetHourFormat( RTC, LL_RTC_HOURFORMAT_24HOUR );
LL_RTC_SetAlarmOutEvent( RTC, RTC_OUTPUT ); /* RTC_OUTPUT is defined to LL_RTC_ALARMOUT_xxx */
LL_RTC_SetOutputPolarity( RTC, LL_RTC_OUTPUTPOLARITY_PIN_HIGH );
/* Configure the RTC PRER */
LL_RTC_SetSynchPrescaler( RTC, PREDIV_S );
LL_RTC_SetAsynchPrescaler( RTC, PREDIV_A );
/* Exit Initialization mode */
LL_RTC_DisableInitMode( RTC );
LL_RTC_DisableOutRemap( RTC );
LL_RTC_SetAlarmOutputType( RTC, LL_RTC_ALARM_OUTPUTTYPE_OPENDRAIN );
/* Enter init mode */
LL_RTC_EnterInitMode( RTC );
/* Friday 1st January 2000, at 0:0:0 */
LL_RTC_DATE_Config( RTC, LL_RTC_WEEKDAY_SATURDAY, __LL_RTC_CONVERT_BIN2BCD( 1 ),
__LL_RTC_CONVERT_BIN2BCD( 1 ),
__LL_RTC_CONVERT_BIN2BCD( 0 ) );
LL_RTC_TIME_Config( RTC, LL_RTC_TIME_FORMAT_AM_OR_24, 0, 0, 0 );
/* Exit init mode */
LL_RTC_DisableInitMode( RTC );
/* If RTC_CR_BYPSHAD bit = 0, wait for synchro else this check is not needed */
if ( LL_RTC_IsShadowRegBypassEnabled( RTC ) == 0U )
{
LL_RTC_WaitForSynchro( RTC );
}
/* Enable Direct Read of the calendar registers (not through Shadow) */
LL_RTC_EnableShadowRegBypass( RTC );
/* Enable write protection so that ISR cannot be modified */
LL_RTC_EnableWriteProtection( RTC );
}
static void HW_RTC_SetAlarmConfig( void )
{
HW_RTC_DeactivateAlarm( );
}
static void HW_RTC_StartWakeUpAlarm( uint32_t timeoutValue )
{
uint16_t rtcAlarmSubSeconds;
uint16_t rtcAlarmSeconds;
uint16_t rtcAlarmMinutes;
uint16_t rtcAlarmHours;
uint16_t rtcAlarmDays;
uint8_t day_in_month;
HW_RTC_TimeTypeDef RTC_TimeStruct = RtcTimerContext.RTC_Calndr_Time;
HW_RTC_DateTypeDef RTC_DateStruct = RtcTimerContext.RTC_Calndr_Date;
HW_RTC_StopAlarm( );
/*reverse counter */
rtcAlarmSubSeconds = PREDIV_S - RTC_TimeStruct.SubSeconds;
rtcAlarmSubSeconds += (timeoutValue & PREDIV_S);
/* convert timeout to seconds */
timeoutValue >>= N_PREDIV_S; /* convert timeout in seconds */
/*convert microsecs to RTC format and add to 'Now' */
rtcAlarmDays = RTC_DateStruct.Day;
ADJUST_TIME( timeoutValue, rtcAlarmDays, SecondsInDay );
/* calc hours */
rtcAlarmHours = RTC_TimeStruct.Hours;
ADJUST_TIME( timeoutValue, rtcAlarmHours, SecondsInHour );
/* calc minutes */
rtcAlarmMinutes = RTC_TimeStruct.Minutes;
ADJUST_TIME( timeoutValue, rtcAlarmMinutes, SecondsInMinute );
/* calc seconds */
rtcAlarmSeconds = RTC_TimeStruct.Seconds + timeoutValue;
/***** correct for modulo********/
ADJUST_TIME( rtcAlarmSubSeconds, rtcAlarmSeconds, (PREDIV_S + 1) );
ADJUST_TIME( rtcAlarmSeconds, rtcAlarmMinutes, SecondsInMinute );
ADJUST_TIME( rtcAlarmMinutes, rtcAlarmHours, MinutesInHour );
ADJUST_TIME( rtcAlarmHours, rtcAlarmDays, HoursInDay );
/* Day in month, adjusted to take into account leap years */
day_in_month = DaysInMonth[RTC_DateStruct.Month - 1];
if ( ((RTC_DateStruct.Year % 4) == 0) && (RTC_DateStruct.Month == 2) )
{
day_in_month++;
}
while ( rtcAlarmDays > day_in_month )
{
rtcAlarmDays = (rtcAlarmDays - day_in_month);
}
/* Set RTC_AlarmStructure with calculated values*/
/* Code from HAL_RTC_SetAlarm_IT / LL_RTC_ALMA_Init */
LL_RTC_DisableWriteProtection( RTC );
/* Disable the Alarm A interrupt */
LL_RTC_ALMA_Disable( RTC );
LL_RTC_ClearFlag_ALRA( RTC );
/* Wait till RTC ALRxWF flag is set */
while ( !LL_RTC_IsActiveFlag_ALRAW( RTC ) )
{
;
}
LL_RTC_ALMA_SetSubSecond( RTC, PREDIV_S - rtcAlarmSubSeconds );
LL_RTC_ALMA_SetSubSecondMask( RTC, ((HW_RTC_ALARMSUBSECONDMASK) >> (RTC_POSITION_ALMA_MASKSS )) );
LL_RTC_ALMA_ConfigTime( RTC, RTC_TimeStruct.TimeFormat,
HW_RTC_ByteToBcd2( rtcAlarmHours ),
HW_RTC_ByteToBcd2( rtcAlarmMinutes ),
HW_RTC_ByteToBcd2( rtcAlarmSeconds ) );
LL_RTC_ALMA_DisableWeekday( RTC );
LL_RTC_ALMA_SetDay( RTC, HW_RTC_ByteToBcd2( rtcAlarmDays ) );
LL_RTC_ALMA_SetMask( RTC, LL_RTC_ALMA_MASK_NONE );
LL_RTC_TIME_DisableDayLightStore( RTC );
/* Configure the Alarm state: Enable Alarm */
LL_RTC_ALMA_Enable( RTC );
/* Configure the Alarm interrupt */
LL_RTC_EnableIT_ALRA( RTC );
/* RTC Alarm Interrupt Configuration: EXTI configuration */
LL_EXTI_EnableIT_0_31( HW_RTC_EXTI_LINE_ALARM_EVENT );
LL_EXTI_EnableRisingTrig_0_31( HW_RTC_EXTI_LINE_ALARM_EVENT );
/* Enable the write protection for RTC registers */
LL_RTC_EnableWriteProtection( RTC );
/* Debug Printf*/
DBG( HW_RTC_GetCalendarValue( &RTC_DateStruct, &RTC_TimeStruct )
;);
#if 0
DBG_PRINTF("it's %d:%d:%d:%d ", RTC_TimeStruct.Hours, RTC_TimeStruct.Minutes, RTC_TimeStruct.Seconds, ((PREDIV_S - RTC_TimeStruct.SubSeconds) * 1000) >> N_PREDIV_S);
#endif
}
static TimerTime_t HW_RTC_GetCalendarValue( HW_RTC_DateTypeDef *RTC_DateStruct, HW_RTC_TimeTypeDef *RTC_TimeStruct )
{
TimerTime_t calendarValue;
TimerTime_t nb_days;
uint32_t i;
uint32_t ssr;
uint32_t tr;
uint32_t dr;
/*
* as shadow registers are not used, we must read RTC->SSR, TR and DR registers
* and ensure they have not changed between 2 reads to ensure time and date are coherent
* Then we must use these values directly instead of readnig them again and again
* with LL_RTC_TIME_Getxxx() functions
*/
do
{
ssr = RTC->SSR;
tr = RTC->TR;
dr = RTC->DR;
} while ( ssr != RTC->SSR );
/* RTC_TimeStruct->SubSeconds = LL_RTC_TIME_GetSubSecond(RTC); */
RTC_TimeStruct->SubSeconds = READ_BIT( ssr, RTC_SSR_SS );
/* RTC_TimeStruct->Hours = HW_RTC_Bcd2ToByte(LL_RTC_TIME_GetHour(RTC)); */
RTC_TimeStruct->Hours = HW_RTC_Bcd2ToByte( (uint8_t) ((tr & (RTC_TR_HT | RTC_TR_HU)) >> 16U) );
/* RTC_TimeStruct->Minutes = HW_RTC_Bcd2ToByte(LL_RTC_TIME_GetMinute(RTC)); */
RTC_TimeStruct->Minutes = HW_RTC_Bcd2ToByte( (uint8_t) ((tr & (RTC_TR_MNT | RTC_TR_MNU)) >> 8U) );
/* RTC_TimeStruct->Seconds = HW_RTC_Bcd2ToByte(LL_RTC_TIME_GetSecond(RTC)); */
RTC_TimeStruct->Seconds = HW_RTC_Bcd2ToByte( (uint8_t) (tr & (RTC_TR_ST | RTC_TR_SU)) );
/* RTC_TimeStruct->TimeFormat = LL_RTC_TIME_GetFormat(RTC); */
RTC_TimeStruct->TimeFormat = READ_BIT( tr, RTC_TR_PM );
/* RTC_DateStruct->WeekDay = LL_RTC_DATE_GetWeekDay(RTC); */
RTC_DateStruct->WeekDay = (uint32_t) (READ_BIT(dr, RTC_DR_WDU) >> RTC_POSITION_DR_WDU );
/* RTC_DateStruct->Month = HW_RTC_Bcd2ToByte(LL_RTC_DATE_GetMonth(RTC)); */
RTC_DateStruct->Month = HW_RTC_Bcd2ToByte( (uint8_t) ((dr & (RTC_DR_MT | RTC_DR_MU)) >> 8U) );
/* RTC_DateStruct->Day = HW_RTC_Bcd2ToByte(LL_RTC_DATE_GetDay(RTC)); */
RTC_DateStruct->Day = HW_RTC_Bcd2ToByte( (uint8_t) (dr & (RTC_DR_DT | RTC_DR_DU)) );
/* RTC_DateStruct->Year = HW_RTC_Bcd2ToByte(LL_RTC_DATE_GetYear(RTC)); */
RTC_DateStruct->Year = HW_RTC_Bcd2ToByte( (uint8_t) ((dr & (RTC_DR_YT | RTC_DR_YU)) >> 16U) );
/* years (calc valid up to year 2099)*/
nb_days = RTC_DateStruct->Year * DaysInYear;
nb_days += (RTC_DateStruct->Year + 3) / 4; /* we add 1 day for full-year 00 (which is 2000), 1 day for full-year 2004,...) */
/* Day in month, adjusted to take into account leap years */
for ( i = 0; i < (RTC_DateStruct->Month - 1); i++ )
{
nb_days += DaysInMonth[i];
}
if ( ((RTC_DateStruct->Year % 4) == 0) && (RTC_DateStruct->Month >= 3) )
{
nb_days++;
}
/* days */
nb_days += (RTC_DateStruct->Day - 1);
calendarValue = CALENDAR_VALUE( RTC_TimeStruct->SubSeconds, RTC_TimeStruct->Seconds,
RTC_TimeStruct->Minutes,
RTC_TimeStruct->Hours, nb_days );
return (calendarValue);
}
static uint8_t HW_RTC_ByteToBcd2( uint8_t Value )
{
return __LL_RTC_CONVERT_BIN2BCD( Value );
}
static uint8_t HW_RTC_Bcd2ToByte( uint8_t Value )
{
return __LL_RTC_CONVERT_BCD2BIN( Value );
}
static void HW_RTC_DeactivateAlarm( void )
{
/* Disable the Alarm A interrupt */
LL_RTC_DisableWriteProtection( RTC );
LL_RTC_ALMA_Disable( RTC );
LL_RTC_DisableIT_ALRA( RTC );
/* Wait till RTC ALRxWF flag is set */
while ( !LL_RTC_IsActiveFlag_ALRAW( RTC ) )
{
;
}
/* Enable the write protection for RTC registers */
LL_RTC_EnableWriteProtection( RTC );
}
static void HW_RTC_AlarmIRQHandler( void )
{
/* enable low power at irq*/
LowPower_Enable( e_LOW_POWER_RTC );
/* Get the pending status of the AlarmA Interrupt */
if ( LL_RTC_IsActiveFlag_ALRA( RTC ) )
{
/* Clear the AlarmA interrupt pending bit */
LL_RTC_ClearFlag_ALRA( RTC );
/* Clear the EXTI's line Flag for RTC Alarm */
LL_EXTI_ClearFlag_0_31( HW_RTC_EXTI_LINE_ALARM_EVENT );
/* AlarmA callback */
TimerIrqHandler( );
}
}
static void HW_RCC_OscConfig( void )
{
FlagStatus pwrclkchanged = RESET;
FlagStatus backupchanged = RESET;
/* Update LSE configuration in Backup Domain control register */
/* Requires to enable write access to Backup Domain of necessary */
if ( LL_APB1_GRP1_IsEnabledClock( LL_APB1_GRP1_PERIPH_PWR ) == RESET )
{
LL_APB1_GRP1_EnableClock( LL_APB1_GRP1_PERIPH_PWR );
pwrclkchanged = SET;
}
if ( LL_PWR_IsEnabledBkUpAccess( ) == RESET )
{
/* Enable write access to Backup domain */
LL_PWR_EnableBkUpAccess( );
backupchanged = SET;
/* Wait for Backup domain Write protection disable */
while ( LL_PWR_IsEnabledBkUpAccess( ) == RESET )
{
;
}
}
/* Set the new LSE configuration -----------------------------------------*/
LL_RCC_LSE_Enable( );
/* Wait till LSE is ready */
while ( (LL_RCC_ReadReg(CSR) & RCC_CSR_LSERDY_Msk) == RESET )
{
;
}
/* Requires to disable write access to Backup Domain of necessary */
if ( backupchanged == SET )
{
LL_PWR_DisableBkUpAccess( );
}
if ( pwrclkchanged == SET )
{
LL_APB1_GRP1_DisableClock( LL_APB1_GRP1_PERIPH_PWR );
}
}
static void HW_RCCEx_PeriphCLKConfig( void )
{
uint32_t tmpreg = 0U;
/* Enable Power Clock*/
LL_APB1_GRP1_EnableClock( LL_APB1_GRP1_PERIPH_PWR );
/* Enable write access to Backup domain */
LL_PWR_EnableBkUpAccess( );
while ( LL_PWR_IsEnabledBkUpAccess( ) == RESET )
{
;
}
/* Reset the Backup domain only if the RTC Clock source selection is modified */
if ( LL_RCC_GetRTCClockSource( ) != LL_RCC_RTC_CLKSOURCE_LSE )
{
/* Store the content of CSR register before the reset of Backup Domain */
tmpreg = (LL_RCC_ReadReg(CSR) & ~(RCC_CSR_RTCSEL));
/* RTC Clock selection can be changed only if the Backup Domain is reset */
LL_RCC_ForceBackupDomainReset( );
LL_RCC_ReleaseBackupDomainReset( );
/* Restore the Content of CSR register */
LL_RCC_WriteReg( CSR, tmpreg );
/* Wait for LSERDY if LSE was enabled */
if ( (tmpreg & RCC_CSR_LSERDY) != RESET )
{
/* Wait till LSE is ready */
while ( (LL_RCC_ReadReg(CSR) & RCC_CSR_LSERDY_Msk) == RESET )
{
;
}
/* RTC Clock update - based on __HAL_RCC_RTC_CONFIG(RCC_RTCCLKSOURCE_LSE) */
CLEAR_BIT( RCC->CR, RCC_CR_RTCPRE );
LL_RCC_SetRTCClockSource( LL_RCC_RTC_CLKSOURCE_LSE );
}
}
}
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

View file

@ -0,0 +1,222 @@
/*
/ _____) _ | |
( (____ _____ ____ _| |_ _____ ____| |__
\____ \| ___ | (_ _) ___ |/ ___) _ \
_____) ) ____| | | || |_| ____( (___| | | |
(______/|_____)_|_|_| \__)_____)\____)_| |_|
(C)2013 Semtech
Description: Bleeper board SPI driver implementation
License: Revised BSD License, see LICENSE.TXT file include in the project
Maintainer: Miguel Luis and Gregory Cristian
*/
/*******************************************************************************
* @file hw_spi.c
* @author MCD Application Team
* @version V1.1.1
* @date 01-June-2017
* @brief manages the SPI interface
******************************************************************************
* @attention
*
* <h2><center>&copy; 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.
*
******************************************************************************
*/
/* Includes ------------------------------------------------------------------*/
#include "hw.h"
#include "utilities.h"
/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
/* Private function prototypes -----------------------------------------------*/
/**
* @brief Calculates Spi Divisor based on Spi Frequency and Mcu Frequency
*
* @param [IN] Spi Frequency
* @retval Spi divisor
*/
static uint32_t SpiFrequency( uint32_t hz );
/* Exported functions ---------------------------------------------------------*/
void HW_SPI_Init( void )
{
/*##-1- Configure the SPI peripheral */
/* Set the SPI parameters */
LL_APB2_GRP1_EnableClock( LL_APB2_GRP1_PERIPH_SPI1 );
LL_SPI_InitTypeDef SPI_InitStruct;
SPI_InitStruct.TransferDirection = LL_SPI_FULL_DUPLEX;
SPI_InitStruct.Mode = LL_SPI_MODE_MASTER;
SPI_InitStruct.DataWidth = LL_SPI_DATAWIDTH_8BIT;
SPI_InitStruct.ClockPolarity = LL_SPI_POLARITY_LOW;
SPI_InitStruct.ClockPhase = LL_SPI_PHASE_1EDGE;
SPI_InitStruct.NSS = LL_SPI_NSS_SOFT;
SPI_InitStruct.BaudRate = SpiFrequency( 10000000 );
SPI_InitStruct.BitOrder = LL_SPI_MSB_FIRST;
SPI_InitStruct.CRCCalculation = LL_SPI_CRCCALCULATION_DISABLE;
if ( LL_SPI_Init( SPI1, &SPI_InitStruct ) != SUCCESS )
{
/* Initialization Error */
Error_Handler( );
}
/*##-2- Configure the SPI GPIOs */
HW_SPI_IoInit( );
}
void HW_SPI_DeInit( void )
{
LL_SPI_DeInit( SPI1 );
/*##-1- Reset peripherals ####*/
LL_APB2_GRP1_ForceReset( LL_APB2_GRP1_PERIPH_SPI1 );
LL_APB2_GRP1_ReleaseReset( LL_APB2_GRP1_PERIPH_SPI1 );
/*##-2- Configure the SPI GPIOs */
HW_SPI_IoDeInit( );
}
void HW_SPI_IoInit( void )
{
GPIO_InitTypeDef initStruct;
initStruct.Mode = GPIO_MODE_AF_PP;
initStruct.Pull = GPIO_PULLDOWN;
initStruct.Speed = GPIO_SPEED_HIGH;
initStruct.Alternate = SPI1_AF;
HW_GPIO_Init( RADIO_SCLK_PORT, RADIO_SCLK_PIN, &initStruct );
HW_GPIO_Init( RADIO_MISO_PORT, RADIO_MISO_PIN, &initStruct );
HW_GPIO_Init( RADIO_MOSI_PORT, RADIO_MOSI_PIN, &initStruct );
initStruct.Mode = GPIO_MODE_OUTPUT_PP;
initStruct.Pull = GPIO_PULLUP;
HW_GPIO_Init( RADIO_NSS_PORT, RADIO_NSS_PIN, &initStruct );
HW_GPIO_Write( RADIO_NSS_PORT, RADIO_NSS_PIN, 1 );
}
void HW_SPI_IoDeInit( void )
{
GPIO_InitTypeDef initStruct;
initStruct.Mode = GPIO_MODE_OUTPUT_PP;
initStruct.Pull = GPIO_NOPULL;
initStruct.Speed = GPIO_SPEED_FREQ_LOW;
HW_GPIO_Init( RADIO_MOSI_PORT, RADIO_MOSI_PIN, &initStruct );
HW_GPIO_Write( RADIO_MOSI_PORT, RADIO_MOSI_PIN, 0 );
initStruct.Pull = GPIO_PULLDOWN;
HW_GPIO_Init( RADIO_MISO_PORT, RADIO_MISO_PIN, &initStruct );
HW_GPIO_Write( RADIO_MISO_PORT, RADIO_MISO_PIN, 0 );
initStruct.Pull = GPIO_NOPULL;
HW_GPIO_Init( RADIO_SCLK_PORT, RADIO_SCLK_PIN, &initStruct );
HW_GPIO_Write( RADIO_SCLK_PORT, RADIO_SCLK_PIN, 0 );
initStruct.Pull = GPIO_PULLUP;
HW_GPIO_Init( RADIO_NSS_PORT, RADIO_NSS_PIN, &initStruct );
HW_GPIO_Write( RADIO_NSS_PORT, RADIO_NSS_PIN, 1 );
}
uint16_t HW_SPI_InOut( uint16_t txData )
{
uint16_t rx_data;
/* Check if the SPI is already enabled. Enable otherwise */
if ( LL_SPI_IsEnabled( SPI1 ) == RESET )
{
LL_SPI_Enable( SPI1 );
}
/* Transmit data */
LL_SPI_TransmitData8( SPI1, txData );
/* Wait until RXNE flag is set */
while ( LL_SPI_IsActiveFlag_RXNE( SPI1 ) == RESET )
{
;
}
/* Receive data */
rx_data = LL_SPI_ReceiveData8( SPI1 );
/* Wait until Busy flag is reset before disabling SPI */
while ( LL_SPI_IsActiveFlag_BSY( SPI1 ) != RESET )
{
;
}
return rx_data;
}
/* Private functions ---------------------------------------------------------*/
static uint32_t SpiFrequency( uint32_t hz )
{
uint32_t divisor = 0;
uint32_t SysClkTmp = SystemCoreClock;
uint32_t baudRate;
while ( SysClkTmp > hz )
{
divisor++;
SysClkTmp = (SysClkTmp >> 1);
if ( divisor >= 7 )
{
break;
}
}
assert_param( ((SPI_CR1_BR_0 == (0x1U << SPI_CR1_BR_Pos)) &&
(SPI_CR1_BR_1 == (0x2U << SPI_CR1_BR_Pos)) &&
(SPI_CR1_BR_2 == (0x4U << SPI_CR1_BR_Pos))) );
baudRate = divisor << SPI_CR1_BR_Pos;
return baudRate;
}
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

View file

@ -0,0 +1,838 @@
/*
/ _____) _ | |
( (____ _____ ____ _| |_ _____ ____| |__
\____ \| ___ | (_ _) ___ |/ ___) _ \
_____) ) ____| | | || |_| ____( (___| | | |
(______/|_____)_|_|_| \__)_____)\____)_| |_|
(C)2013 Semtech
Description: LoRaMac classA device implementation
License: Revised BSD License, see LICENSE.TXT file include in the project
Maintainer: Miguel Luis, Gregory Cristian and Wael Guibene
*/
/******************************************************************************
* @file lora.c
* @author MCD Application Team
* @version V1.1.1
* @date 01-June-2017
* @brief lora API to drive the lora state Machine
******************************************************************************
* @attention
*
* <h2><center>&copy; 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.
*
******************************************************************************
*/
/* Includes ------------------------------------------------------------------*/
#include "hw.h"
#include "timeServer.h"
#include "LoRaMac.h"
#include "lora.h"
/*!
* Join requests trials duty cycle.
*/
#define OVER_THE_AIR_ACTIVATION_DUTYCYCLE 10000 // 10 [s] value in ms
#if defined(REGION_EU868)
#include "LoRaMacTest.h"
/*!
* LoRaWAN ETSI duty cycle control enable/disable
*
* \remark Please note that ETSI mandates duty cycled transmissions. Use only for test purposes
*/
#define LORAWAN_DUTYCYCLE_ON true
#define USE_SEMTECH_DEFAULT_CHANNEL_LINEUP 0
#if (USE_SEMTECH_DEFAULT_CHANNEL_LINEUP == 1)
#define LC4 \
{ \
867100000, 0, {((DR_5 << 4) | DR_0)}, 0 \
}
#define LC5 \
{ \
867300000, 0, {((DR_5 << 4) | DR_0)}, 0 \
}
#define LC6 \
{ \
867500000, 0, {((DR_5 << 4) | DR_0)}, 0 \
}
#define LC7 \
{ \
867700000, 0, {((DR_5 << 4) | DR_0)}, 0 \
}
#define LC8 \
{ \
867900000, 0, {((DR_5 << 4) | DR_0)}, 0 \
}
#define LC9 \
{ \
868800000, 0, {((DR_7 << 4) | DR_7)}, 2 \
}
#define LC10 \
{ \
868300000, 0, {((DR_6 << 4) | DR_6)}, 1 \
}
#endif
#endif
static uint8_t DevEui[] = LORAWAN_DEVICE_EUI;
static uint8_t AppEui[] = LORAWAN_APPLICATION_EUI;
static uint8_t AppKey[] = LORAWAN_APPLICATION_KEY;
#if (OVER_THE_AIR_ACTIVATION == 0)
static uint8_t NwkSKey[] = LORAWAN_NWKSKEY;
static uint8_t AppSKey[] = LORAWAN_APPSKEY;
/*!
* Device address
*/
static uint32_t DevAddr = LORAWAN_DEVICE_ADDRESS;
#endif
/*!
* User application data buffer size
*/
#define LORAWAN_APP_DATA_BUFF_SIZE 242
/*!
* User application data
*/
static uint8_t AppDataBuff[LORAWAN_APP_DATA_BUFF_SIZE];
/*!
* User application data structure
*/
static lora_AppData_t AppData = { AppDataBuff, 0, 0 };
/*!
* Indicates if the node is sending confirmed or unconfirmed messages
*/
static FunctionalState IsTxConfirmed;
/*!
* Defines the LoRa parameters at Init
*/
static LoRaParam_t *LoRaParamInit;
/*!
* Timer to handle the application data transmission duty cycle
*/
static TimerEvent_t TxNextPacketTimer;
static DeviceState_t DeviceState = DEVICE_STATE_INIT;
/*!
* Timer to handle the state of LED1
*/
static LoRaMacPrimitives_t LoRaMacPrimitives;
static LoRaMacCallback_t LoRaMacCallbacks;
static MibRequestConfirm_t mibReq;
static LoRaMainCallback_t *LoRaMainCallbacks;
/*!
* Indicates if a new packet can be sent
*/
static bool NextTx = true;
/*!
* LoRaWAN compliance tests support data
*/
struct ComplianceTest_s
{
bool Running;
uint8_t State;
FunctionalState IsTxConfirmed;
uint8_t AppPort;
uint8_t AppDataSize;
uint8_t *AppDataBuffer;
uint16_t DownLinkCounter;
bool LinkCheck;
uint8_t DemodMargin;
uint8_t NbGateways;
} ComplianceTest;
/*!
* \brief Prepares the payload of the frame
*/
static void PrepareTxFrame( )
{
if ( ComplianceTest.Running == true )
{
if ( ComplianceTest.LinkCheck == true )
{
ComplianceTest.LinkCheck = false;
AppData.BuffSize = 3;
AppData.Buff[0] = 5;
AppData.Buff[1] = ComplianceTest.DemodMargin;
AppData.Buff[2] = ComplianceTest.NbGateways;
ComplianceTest.State = 1;
}
else
{
switch ( ComplianceTest.State )
{
case 4:
ComplianceTest.State = 1;
break;
case 1:
AppData.BuffSize = 2;
AppData.Buff[0] = ComplianceTest.DownLinkCounter >> 8;
AppData.Buff[1] = ComplianceTest.DownLinkCounter;
break;
}
}
}
else
{
LoRaMainCallbacks->LoraTxData( &AppData, &IsTxConfirmed );
}
}
/*!
* \brief Prepares the payload of the frame
*
* \retval [0: frame could be send, 1: error]
*/
static bool SendFrame( void )
{
McpsReq_t mcpsReq;
LoRaMacTxInfo_t txInfo;
if ( LoRaMacQueryTxPossible( AppData.BuffSize, &txInfo ) != LORAMAC_STATUS_OK )
{
// Send empty frame in order to flush MAC commands
mcpsReq.Type = MCPS_UNCONFIRMED;
mcpsReq.Req.Unconfirmed.fBuffer = NULL;
mcpsReq.Req.Unconfirmed.fBufferSize = 0;
mcpsReq.Req.Unconfirmed.Datarate = LoRaParamInit->TxDatarate;
}
else
{
if ( IsTxConfirmed == DISABLE )
{
mcpsReq.Type = MCPS_UNCONFIRMED;
mcpsReq.Req.Unconfirmed.fPort = AppData.Port;
mcpsReq.Req.Unconfirmed.fBuffer = AppData.Buff;
mcpsReq.Req.Unconfirmed.fBufferSize = AppData.BuffSize;
mcpsReq.Req.Unconfirmed.Datarate = LoRaParamInit->TxDatarate;
}
else
{
mcpsReq.Type = MCPS_CONFIRMED;
mcpsReq.Req.Confirmed.fPort = AppData.Port;
mcpsReq.Req.Confirmed.fBuffer = AppData.Buff;
mcpsReq.Req.Confirmed.fBufferSize = AppData.BuffSize;
mcpsReq.Req.Confirmed.NbTrials = 8;
mcpsReq.Req.Confirmed.Datarate = LoRaParamInit->TxDatarate;
}
}
if ( LoRaMacMcpsRequest( &mcpsReq ) == LORAMAC_STATUS_OK )
{
return false;
}
return true;
}
void OnSendEvent( void )
{
MibRequestConfirm_t mibReq;
LoRaMacStatus_t status;
mibReq.Type = MIB_NETWORK_JOINED;
status = LoRaMacMibGetRequestConfirm( &mibReq );
if ( status == LORAMAC_STATUS_OK )
{
if ( mibReq.Param.IsNetworkJoined == true )
{
DeviceState = DEVICE_STATE_SEND;
NextTx = true;
}
else
{
DeviceState = DEVICE_STATE_JOIN;
}
}
}
/*!
* \brief Function executed on TxNextPacket Timeout event
*/
static void OnTxNextPacketTimerEvent( void )
{
TimerStop( &TxNextPacketTimer );
OnSendEvent( );
}
/*!
* \brief MCPS-Confirm event function
*
* \param [IN] McpsConfirm - Pointer to the confirm structure,
* containing confirm attributes.
*/
static void McpsConfirm( McpsConfirm_t *mcpsConfirm )
{
if ( mcpsConfirm->Status == LORAMAC_EVENT_INFO_STATUS_OK )
{
switch ( mcpsConfirm->McpsRequest )
{
case MCPS_UNCONFIRMED:
{
// Check Datarate
// Check TxPower
break;
}
case MCPS_CONFIRMED:
{
// Check Datarate
// Check TxPower
// Check AckReceived
// Check NbTrials
break;
}
case MCPS_PROPRIETARY:
{
break;
}
default:
break;
}
}
NextTx = true;
}
/*!
* \brief MCPS-Indication event function
*
* \param [IN] mcpsIndication - Pointer to the indication structure,
* containing indication attributes.
*/
static void McpsIndication( McpsIndication_t *mcpsIndication )
{
if ( mcpsIndication->Status != LORAMAC_EVENT_INFO_STATUS_OK )
{
return;
}
switch ( mcpsIndication->McpsIndication )
{
case MCPS_UNCONFIRMED:
{
break;
}
case MCPS_CONFIRMED:
{
break;
}
case MCPS_PROPRIETARY:
{
break;
}
case MCPS_MULTICAST:
{
DBG_PRINTF( "MCPS_MULTICAST\n" );
break;
}
default:
break;
}
// Check Multicast
// Check Port
// Check Datarate
// Check FramePending
// Check Buffer
// Check BufferSize
// Check Rssi
// Check Snr
// Check RxSlot
DBG_PRINTF( "rssi = %d, snr = %d, datarate = %d\n", mcpsIndication->Rssi, mcpsIndication->Snr,
mcpsIndication->RxDatarate );
if ( ComplianceTest.Running == true )
{
ComplianceTest.DownLinkCounter++;
}
if ( mcpsIndication->RxData == true )
{
switch ( mcpsIndication->Port )
{
case 224:
if ( ComplianceTest.Running == false )
{
// Check compliance test enable command (i)
if ( (mcpsIndication->BufferSize == 4) &&
(mcpsIndication->Buffer[0] == 0x01)
&&
(mcpsIndication->Buffer[1] == 0x01)
&&
(mcpsIndication->Buffer[2] == 0x01)
&&
(mcpsIndication->Buffer[3] == 0x01) )
{
IsTxConfirmed = DISABLE;
AppData.Port = 224;
AppData.BuffSize = 2;
ComplianceTest.DownLinkCounter = 0;
ComplianceTest.LinkCheck = false;
ComplianceTest.DemodMargin = 0;
ComplianceTest.NbGateways = 0;
ComplianceTest.Running = true;
ComplianceTest.State = 1;
MibRequestConfirm_t mibReq;
mibReq.Type = MIB_ADR;
mibReq.Param.AdrEnable = true;
LoRaMacMibSetRequestConfirm( &mibReq );
#if defined(REGION_EU868)
LoRaMacTestSetDutyCycleOn(false);
#endif
}
}
else
{
ComplianceTest.State = mcpsIndication->Buffer[0];
switch ( ComplianceTest.State )
{
case 0: // Check compliance test disable command (ii)
ComplianceTest.DownLinkCounter = 0;
ComplianceTest.Running = false;
MibRequestConfirm_t mibReq;
mibReq.Type = MIB_ADR;
mibReq.Param.AdrEnable = LoRaParamInit->AdrEnable;
LoRaMacMibSetRequestConfirm( &mibReq );
#if defined(REGION_EU868)
lora_config_duty_cycle_set(LORAWAN_DUTYCYCLE_ON ? ENABLE : DISABLE);
#endif
break;
case 1: // (iii, iv)
AppData.BuffSize = 2;
break;
case 2: // Enable confirmed messages (v)
IsTxConfirmed = ENABLE;
ComplianceTest.State = 1;
break;
case 3: // Disable confirmed messages (vi)
IsTxConfirmed = DISABLE;
ComplianceTest.State = 1;
break;
case 4: // (vii)
AppData.BuffSize = mcpsIndication->BufferSize;
AppData.Buff[0] = 4;
for ( uint8_t i = 1; i < AppData.BuffSize; i++ )
{
AppData.Buff[i] = mcpsIndication->Buffer[i] + 1;
}
break;
case 5: // (viii)
{
MlmeReq_t mlmeReq;
mlmeReq.Type = MLME_LINK_CHECK;
LoRaMacMlmeRequest( &mlmeReq );
}
break;
case 6: // (ix)
{
MlmeReq_t mlmeReq;
// Disable TestMode and revert back to normal operation
ComplianceTest.DownLinkCounter = 0;
ComplianceTest.Running = false;
MibRequestConfirm_t mibReq;
mibReq.Type = MIB_ADR;
mibReq.Param.AdrEnable = LoRaParamInit->AdrEnable;
LoRaMacMibSetRequestConfirm( &mibReq );
#if defined(REGION_EU868)
lora_config_duty_cycle_set(LORAWAN_DUTYCYCLE_ON ? ENABLE : DISABLE);
#endif
mlmeReq.Type = MLME_JOIN;
mlmeReq.Req.Join.DevEui = DevEui;
mlmeReq.Req.Join.AppEui = AppEui;
mlmeReq.Req.Join.AppKey = AppKey;
mlmeReq.Req.Join.NbTrials = 3;
LoRaMacMlmeRequest( &mlmeReq );
DeviceState = DEVICE_STATE_SLEEP;
}
break;
case 7: // (x)
{
if ( mcpsIndication->BufferSize == 3 )
{
MlmeReq_t mlmeReq;
mlmeReq.Type = MLME_TXCW;
mlmeReq.Req.TxCw.Timeout = (uint16_t) ((mcpsIndication->Buffer[1] << 8)
| mcpsIndication->Buffer[2]);
LoRaMacMlmeRequest( &mlmeReq );
}
else if ( mcpsIndication->BufferSize == 7 )
{
MlmeReq_t mlmeReq;
mlmeReq.Type = MLME_TXCW_1;
mlmeReq.Req.TxCw.Timeout = (uint16_t) ((mcpsIndication->Buffer[1] << 8)
| mcpsIndication->Buffer[2]);
mlmeReq.Req.TxCw.Frequency = (uint32_t) ((mcpsIndication->Buffer[3] << 16)
| (mcpsIndication->Buffer[4] << 8) | mcpsIndication->Buffer[5])
* 100;
mlmeReq.Req.TxCw.Power = mcpsIndication->Buffer[6];
LoRaMacMlmeRequest( &mlmeReq );
}
ComplianceTest.State = 1;
}
break;
default:
break;
}
}
break;
default:
AppData.Port = mcpsIndication->Port;
AppData.BuffSize = mcpsIndication->BufferSize;
memcpy1( AppData.Buff, mcpsIndication->Buffer, AppData.BuffSize );
LoRaMainCallbacks->LoraRxData( &AppData );
break;
}
}
}
/*!
* \brief MLME-Confirm event function
*
* \param [IN] MlmeConfirm - Pointer to the confirm structure,
* containing confirm attributes.
*/
static void MlmeConfirm( MlmeConfirm_t *mlmeConfirm )
{
switch ( mlmeConfirm->MlmeRequest )
{
case MLME_JOIN:
{
if ( mlmeConfirm->Status == LORAMAC_EVENT_INFO_STATUS_OK )
{
SYS_LED_ON( );
// Status is OK, node has joined the network
DeviceState = DEVICE_STATE_JOINED;
}
else
{
SYS_LED_OFF( );
// Join was not successful. Try to join again
DeviceState = DEVICE_STATE_JOIN;
}
break;
}
case MLME_LINK_CHECK:
{
if ( mlmeConfirm->Status == LORAMAC_EVENT_INFO_STATUS_OK )
{
// Check DemodMargin
// Check NbGateways
if ( ComplianceTest.Running == true )
{
ComplianceTest.LinkCheck = true;
ComplianceTest.DemodMargin = mlmeConfirm->DemodMargin;
ComplianceTest.NbGateways = mlmeConfirm->NbGateways;
}
}
break;
}
default:
break;
}
NextTx = true;
}
/**
* lora Init
*/
void lora_Init( LoRaMainCallback_t *callbacks, LoRaParam_t *LoRaParam )
{
/* init the DeviceState*/
DeviceState = DEVICE_STATE_INIT;
/* init the Tx Duty Cycle*/
LoRaParamInit = LoRaParam;
/* init the main call backs*/
LoRaMainCallbacks = callbacks;
#if (STATIC_DEVICE_EUI != 1)
LoRaMainCallbacks->BoardGetUniqueId( DevEui );
#endif
#if (OVER_THE_AIR_ACTIVATION != 0)
PRINTF_RAW( "OTAA\r\n" );
PRINTF_RAW( "DevEui= %02X", DevEui[0] );
for ( int i = 1; i < 8; i++ )
{
PRINTF_RAW( "-%02X", DevEui[i] );
};
PRINTF_RAW( "\r\n" );
PRINTF_RAW( "AppEui= %02X", AppEui[0] );
for ( int i = 1; i < 8; i++ )
{
PRINTF_RAW( "-%02X", AppEui[i] );
};
PRINTF_RAW( "\r\n" );
PRINTF_RAW( "AppKey= %02X", AppKey[0] );
for ( int i = 1; i < 16; i++ )
{
PRINTF_RAW( " %02X", AppKey[i] );
};
PRINTF_RAW( "\n\r\n" );
#else
#if (STATIC_DEVICE_ADDRESS != 1)
// Random seed initialization
srand1(LoRaMainCallbacks->BoardGetRandomSeed());
// Choose a random device address
DevAddr = randr(0, 0x01FFFFFF);
#endif
PRINTF_RAW("ABP\r\n");
PRINTF_RAW("DevEui= %02X", DevEui[0]);
for (int i = 1; i < 8; i++)
{
PRINTF_RAW("-%02X", DevEui[i]);
};
PRINTF_RAW("\r\n");
PRINTF_RAW("DevAdd= %08X\n\r", DevAddr);
PRINTF_RAW("NwkSKey= %02X", NwkSKey[0]);
for (int i = 1; i < 16; i++)
{
PRINTF_RAW(" %02X", NwkSKey[i]);
};
PRINTF_RAW("\r\n");
PRINTF_RAW("AppSKey= %02X", AppSKey[0]);
for (int i = 1; i < 16; i++)
{
PRINTF_RAW(" %02X", AppSKey[i]);
};
PRINTF_RAW("\r\n");
#endif
}
/**
* lora class A state machine
*/
void lora_fsm( void )
{
switch ( DeviceState )
{
case DEVICE_STATE_INIT:
{
LoRaMacPrimitives.MacMcpsConfirm = McpsConfirm;
LoRaMacPrimitives.MacMcpsIndication = McpsIndication;
LoRaMacPrimitives.MacMlmeConfirm = MlmeConfirm;
LoRaMacCallbacks.GetBatteryLevel = LoRaMainCallbacks->BoardGetBatteryLevel;
#if defined(REGION_AS923)
LoRaMacInitialization(&LoRaMacPrimitives, &LoRaMacCallbacks, LORAMAC_REGION_AS923);
#elif defined(REGION_AS923)
LoRaMacInitialization(&LoRaMacPrimitives, &LoRaMacCallbacks, LORAMAC_REGION_AU915);
#elif defined(REGION_CN470)
LoRaMacInitialization(&LoRaMacPrimitives, &LoRaMacCallbacks, LORAMAC_REGION_CN470);
#elif defined(REGION_CN779)
LoRaMacInitialization(&LoRaMacPrimitives, &LoRaMacCallbacks, LORAMAC_REGION_CN779);
#elif defined(REGION_EU433)
LoRaMacInitialization(&LoRaMacPrimitives, &LoRaMacCallbacks, LORAMAC_REGION_EU433);
#elif defined(REGION_IN865)
LoRaMacInitialization(&LoRaMacPrimitives, &LoRaMacCallbacks, LORAMAC_REGION_IN865);
#elif defined(REGION_EU868)
LoRaMacInitialization(&LoRaMacPrimitives, &LoRaMacCallbacks, LORAMAC_REGION_EU868);
#elif defined(REGION_KR920)
LoRaMacInitialization(&LoRaMacPrimitives, &LoRaMacCallbacks, LORAMAC_REGION_KR920);
#elif defined(REGION_US915)
LoRaMacInitialization(&LoRaMacPrimitives, &LoRaMacCallbacks, LORAMAC_REGION_US915);
#elif defined(REGION_US915_HYBRID)
LoRaMacInitialization(&LoRaMacPrimitives, &LoRaMacCallbacks, LORAMAC_REGION_US915_HYBRID);
#else
#error "Please define a region in the compiler options."
#endif
TimerInit( &TxNextPacketTimer, OnTxNextPacketTimerEvent );
mibReq.Type = MIB_ADR;
mibReq.Param.AdrEnable = LoRaParamInit->AdrEnable;
LoRaMacMibSetRequestConfirm( &mibReq );
mibReq.Type = MIB_PUBLIC_NETWORK;
mibReq.Param.EnablePublicNetwork = LoRaParamInit->EnablePublicNetwork;
LoRaMacMibSetRequestConfirm( &mibReq );
mibReq.Type = MIB_DEVICE_CLASS;
mibReq.Param.Class = LoRaParamInit->Class;
LoRaMacMibSetRequestConfirm( &mibReq );
#if defined(REGION_EU868)
lora_config_duty_cycle_set(LORAWAN_DUTYCYCLE_ON ? ENABLE : DISABLE);
#if (USE_SEMTECH_DEFAULT_CHANNEL_LINEUP == 1)
LoRaMacChannelAdd(3, (ChannelParams_t)LC4);
LoRaMacChannelAdd(4, (ChannelParams_t)LC5);
LoRaMacChannelAdd(5, (ChannelParams_t)LC6);
LoRaMacChannelAdd(6, (ChannelParams_t)LC7);
LoRaMacChannelAdd(7, (ChannelParams_t)LC8);
LoRaMacChannelAdd(8, (ChannelParams_t)LC9);
LoRaMacChannelAdd(9, (ChannelParams_t)LC10);
mibReq.Type = MIB_RX2_DEFAULT_CHANNEL;
mibReq.Param.Rx2DefaultChannel = (Rx2ChannelParams_t)
{ 869525000, DR_3};
LoRaMacMibSetRequestConfirm(&mibReq);
mibReq.Type = MIB_RX2_CHANNEL;
mibReq.Param.Rx2Channel = (Rx2ChannelParams_t)
{ 869525000, DR_3};
LoRaMacMibSetRequestConfirm(&mibReq);
#endif
#endif
DeviceState = DEVICE_STATE_JOIN;
break;
}
case DEVICE_STATE_JOIN:
{
#if (OVER_THE_AIR_ACTIVATION != 0)
MlmeReq_t mlmeReq;
mlmeReq.Type = MLME_JOIN;
mlmeReq.Req.Join.DevEui = DevEui;
mlmeReq.Req.Join.AppEui = AppEui;
mlmeReq.Req.Join.AppKey = AppKey;
mlmeReq.Req.Join.NbTrials = LoRaParamInit->NbTrials;
if ( NextTx == true )
{
LoRaMacMlmeRequest( &mlmeReq );
}
DeviceState = DEVICE_STATE_SLEEP;
#else
mibReq.Type = MIB_NET_ID;
mibReq.Param.NetID = LORAWAN_NETWORK_ID;
LoRaMacMibSetRequestConfirm(&mibReq);
mibReq.Type = MIB_DEV_ADDR;
mibReq.Param.DevAddr = DevAddr;
LoRaMacMibSetRequestConfirm(&mibReq);
mibReq.Type = MIB_NWK_SKEY;
mibReq.Param.NwkSKey = NwkSKey;
LoRaMacMibSetRequestConfirm(&mibReq);
mibReq.Type = MIB_APP_SKEY;
mibReq.Param.AppSKey = AppSKey;
LoRaMacMibSetRequestConfirm(&mibReq);
mibReq.Type = MIB_NETWORK_JOINED;
mibReq.Param.IsNetworkJoined = true;
LoRaMacMibSetRequestConfirm(&mibReq);
DeviceState = DEVICE_STATE_SEND;
#endif
break;
}
case DEVICE_STATE_JOINED:
{
PRINTF("JOINED\n\r")
;
DeviceState = DEVICE_STATE_SEND;
break;
}
case DEVICE_STATE_SEND:
{
if ( NextTx == true )
{
PrepareTxFrame( );
NextTx = SendFrame( );
}
if ( ComplianceTest.Running == true )
{
// Schedule next packet transmission as soon as possible
TimerSetValue( &TxNextPacketTimer, 5000 ); /* 5s */
TimerStart( &TxNextPacketTimer );
}
else if ( LoRaParamInit->TxEvent == TX_ON_TIMER )
{
// Schedule next packet transmission
TimerSetValue( &TxNextPacketTimer, LoRaParamInit->TxDutyCycleTime );
TimerStart( &TxNextPacketTimer );
}
DeviceState = DEVICE_STATE_SLEEP;
break;
}
case DEVICE_STATE_SLEEP:
{
// Wake up through events
break;
}
default:
{
DeviceState = DEVICE_STATE_INIT;
break;
}
}
}
DeviceState_t lora_getDeviceState( void )
{
return DeviceState;
}
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

View file

@ -0,0 +1,274 @@
/*
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
*/
/* Includes ------------------------------------------------------------------*/
#include "lorawan_port.h"
#include "hw_msp.h"
#include "hw_rtc.h"
#include "hw_gpio.h"
#include "hw_spi.h"
#include "timeServer.h"
/**
* @fn enter_stop_mode
* @brief enter stop mode
* @param None
* @rtn None
*/
static void enter_stop_mode()
{
HW_EnterStopMode();
}
/**
* @fn exit_stop_mode
* @brief exit from stop mode
* @param None
* @rtn None
*/
static void exit_stop_mode()
{
HW_ExitStopMode();
}
/**
* @fn enter_sleep_mode
* @brief enter sleep mode
* @param None
* @rtn None
*/
static void enter_sleep_mode()
{
HW_EnterSleepMode();
}
/**
* @fn delay_ms
* @brief Delay of delay ms
* @param Delay in ms
* @rtn None
*/
static void delay_ms(time_ms_t delay)
{
HW_RTC_DelayMs(delay);
}
/**
* @fn set_timer_context
* @brief set timer reference
* @param None
* @rtn Timer Reference Value in Ticks
*/
static uint32_t set_timer_context()
{
return (time_tick_t)HW_RTC_SetTimerContext();
}
/**
* @fn get_timer_context
* @brief get timer reference
* @param None
* @rtn Timer Reference Value in Ticks
*/
static uint32_t get_timer_context()
{
return (time_tick_t)HW_RTC_GetTimerContext();
}
/**
* @fn get_timer_elapsed_time
* @brief get the low level time since the last alarm was set
* @param None
* @rtn The Elapsed time in ticks
*/
static uint32_t get_timer_elapsed_time()
{
return (time_tick_t)HW_RTC_GetTimerElapsedTime();
}
/**
* @fn set_uc_wakeup_time
* @brief Calculates the wake up time between wake up and mcu start
* @param None
* @rtn None
*/
static void set_uc_wakeup_time()
{
HW_RTC_setMcuWakeUpTime();
}
/**
* @fn set_alarm
* @brief Set the alarm
* @param Timeout Duration of the Timer ticks
* @rtn None
*/
static void set_alarm(uint32_t timeout)
{
HW_RTC_SetAlarm(timeout);
}
/**
* @fn stop_alarm
* @brief Stop the Alarm
* @param None
* @rtn None
*/
static void stop_alarm()
{
HW_RTC_StopAlarm();
}
static void set_timer_val(TimerEvent_t *obj, uint32_t value)
{
uint32_t minValue = 0;
uint32_t ticks = HW_RTC_ms2Tick( value );
minValue = HW_RTC_GetMinimumTimeout( );
if( ticks < minValue )
{
ticks = minValue;
}
obj->Timestamp = ticks;
obj->ReloadValue = ticks;
}
static TimerTime_t get_current_time(void )
{
uint32_t now = HW_RTC_GetTimerValue( );
return HW_RTC_Tick2ms(now);
}
static TimerTime_t compute_elapsed_time(TimerTime_t time)
{
uint32_t nowInTicks = HW_RTC_GetTimerValue( );
uint32_t pastInTicks = HW_RTC_ms2Tick( time );
/* intentional wrap around. Works Ok if tick duation below 1ms */
return HW_RTC_Tick2ms( nowInTicks- pastInTicks );
}
static void set_timeout(TimerEvent_t *obj)
{
int32_t minTicks = HW_RTC_GetMinimumTimeout( );
obj->IsRunning = true;
//in case deadline too soon
if(obj->Timestamp < (aos_lrwan_time_itf.get_timer_elapsed_time( ) + minTicks) )
{
obj->Timestamp = aos_lrwan_time_itf.get_timer_elapsed_time( ) + minTicks;
}
aos_lrwan_time_itf.set_alarm( obj->Timestamp );
}
/**
* @fn radio_reset
* @brief reset radio by gpio
* @param None
* @rtn None
*/
static void radio_reset()
{
GPIO_InitTypeDef initStruct={0};
initStruct.Mode =GPIO_MODE_OUTPUT_PP;
initStruct.Pull = GPIO_NOPULL;
initStruct.Speed = GPIO_SPEED_HIGH;
// Set RESET pin to 0
HW_GPIO_Init( RADIO_RESET_PORT, RADIO_RESET_PIN, &initStruct);
HW_GPIO_Write( RADIO_RESET_PORT, RADIO_RESET_PIN, 0 );
}
/**
* @fn radio_reset_cfg_input
* @brief Configure radio reset pin as input
* @param None
* @rtn None
*/
static void radio_reset_cfg_input()
{
GPIO_InitTypeDef initStruct={0};
initStruct.Mode =GPIO_MODE_OUTPUT_PP;
initStruct.Pull = GPIO_NOPULL;
initStruct.Speed = GPIO_SPEED_HIGH;
// Configure RESET as input
initStruct.Mode = GPIO_NOPULL;
HW_GPIO_Init( RADIO_RESET_PORT, RADIO_RESET_PIN, &initStruct);
}
/**
* @fn radio_rw_en
* @brief enable radio data tx/rx
* @param None
* @rtn None
*/
static void radio_rw_en()
{
//NSS = 0;
HW_GPIO_Write( RADIO_NSS_PORT, RADIO_NSS_PIN, 0 );
}
/**
* @fn radio_rw_dis
* @brief disable radio data tx/rx
* @param None
* @rtn None
*/
static void radio_rw_dis()
{
//NSS = 1;
HW_GPIO_Write( RADIO_NSS_PORT, RADIO_NSS_PIN, 1 );
}
/**
* @fn radio_rw
* @brief write and read radio data
* @param None
* @rtn None
*/
static uint16_t radio_rw(uint16_t tx_data)
{
HW_SPI_InOut(tx_data);
}
/* the struct is for changing the device working mode */
hal_lrwan_dev_chg_mode_t aos_lrwan_chg_mode = {
.enter_stop_mode = enter_stop_mode,
.exit_stop_mode = exit_stop_mode,
.enter_sleep_mode = enter_sleep_mode,
};
/* LoRaWan time and timer interface */
hal_lrwan_time_itf_t aos_lrwan_time_itf = {
.delay_ms = delay_ms,
.set_timer_context = set_timer_context,
.get_timer_context = get_timer_context,
.get_timer_elapsed_time = get_timer_elapsed_time,
.stop_alarm = stop_alarm,
.set_alarm = set_alarm,
.set_uc_wakeup_time = set_uc_wakeup_time,
.set_timeout = set_timeout,
.compute_elapsed_time = compute_elapsed_time,
.get_current_time = get_current_time,
.set_timer_val = set_timer_val,
};
/* LoRaWan radio control */
hal_lrwan_radio_ctrl_t aos_lrwan_radio_ctrl = {
.radio_reset = radio_reset,
.radio_reset_cfg_input = radio_reset_cfg_input,
.radio_rw_en = radio_rw_en,
.radio_rw_dis = radio_rw_dis,
.radio_rw = radio_rw,
};

View file

@ -0,0 +1,555 @@
/******************************************************************************
* @file vcom.c
* @author MCD Application Team
* @version V1.1.1
* @date 01-June-2017
* @brief manages virtual com port
******************************************************************************
* @attention
*
* <h2><center>&copy; 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.
*
******************************************************************************
*/
#include "hw.h"
#include "vcom.h"
#include "hw_gpio.h"
#include <stdarg.h>
#include "low_power.h"
/* Force include of hal uart in order to inherite HAL_UART_StateTypeDef definition */
#include "stm32l0xx_hal_dma.h"
#include "stm32l0xx_hal_uart.h"
#include <k_api.h>
/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
/* based on UART_HandleTypeDef */
static struct
{
char buffTx[256]; /**< buffer to transmit */
char buffRx[256]; /**< Circular buffer of received chars */
int rx_idx_free; /**< 1st free index in BuffRx */
int rx_idx_toread; /**< next char to read in buffRx, when not rx_idx_free */
HW_LockTypeDef Lock; /**< Locking object */
__IO HAL_UART_StateTypeDef gState; /**< UART state information related to global Handle management
and also related to Tx operations. */
__IO HAL_UART_StateTypeDef RxState; /**< UART state information related to Rx operations. */
} uart_context;
static char dbgTxBuff[256];
/* Private function prototypes -----------------------------------------------*/
/**
* @brief Transmit uart_context.buffTx from start to len - 1
* @param 1st index to transmit
* @param Last index not to transmit
* @return Last index not transmitted
*/
static int buffer_transmit( int start, int len );
/**
* @brief Takes one character that has been received and save it in uart_context.buffRx
* @param received character
*/
static void receive( char rx );
/* Functions Definition ------------------------------------------------------*/
static int dbg_buffer_transmit( int start, int len )
{
int i;
for ( i = start; i < len; i++ )
{
LL_USART_ClearFlag_TC( USART4 );
LL_USART_TransmitData8( USART4, dbgTxBuff[i] );
while ( LL_USART_IsActiveFlag_TC( USART4 ) != SET )
{
;
}
}
LL_USART_ClearFlag_TC( USART4 );
return len;
}
void DBG_Uart_Deinit( void )
{
LL_USART_DeInit( USART4 );
/*##-1- Reset peripherals ##################################################*/
LL_APB1_GRP1_ForceReset( LL_APB1_GRP1_PERIPH_USART4 );
LL_APB1_GRP1_ReleaseReset( LL_APB1_GRP1_PERIPH_USART4 );
/*##-2- Disable peripherals and GPIO Clocks #################################*/
/* Configure UART Tx as alternate function */
HW_GPIO_DeInit( GPIOA, GPIO_PIN_0 );
/* Configure UART Rx as alternate function */
HW_GPIO_DeInit( GPIOA, GPIO_PIN_1 );
/*##-3- Disable the NVIC for UART ##########################################*/
NVIC_DisableIRQ( USART4_5_IRQn );
}
void DBG_Uart_Init( void )
{
LL_USART_InitTypeDef USART_InitStruct;
LL_GPIO_InitTypeDef GPIO_InitStruct;
DBG_Uart_Deinit( );
/* Peripheral clock enable */
LL_APB1_GRP1_EnableClock( LL_APB1_GRP1_PERIPH_USART4 );
/**USART4 GPIO Configuration
PA0 ------> USART4_TX
PA1 ------> USART4_RX
*/
GPIO_InitStruct.Pin = LL_GPIO_PIN_0;
GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE;
GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_VERY_HIGH;
GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
GPIO_InitStruct.Pull = LL_GPIO_PULL_UP;
GPIO_InitStruct.Alternate = LL_GPIO_AF_6;
LL_GPIO_Init( GPIOA, &GPIO_InitStruct );
GPIO_InitStruct.Pin = LL_GPIO_PIN_1;
GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE;
GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_VERY_HIGH;
GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
GPIO_InitStruct.Pull = LL_GPIO_PULL_UP;
GPIO_InitStruct.Alternate = LL_GPIO_AF_6;
LL_GPIO_Init( GPIOA, &GPIO_InitStruct );
USART_InitStruct.BaudRate = 115200;
USART_InitStruct.DataWidth = LL_USART_DATAWIDTH_8B;
USART_InitStruct.StopBits = LL_USART_STOPBITS_1;
USART_InitStruct.Parity = LL_USART_PARITY_NONE;
#ifdef CONFIG_LINKWAN_AT
USART_InitStruct.TransferDirection = LL_USART_DIRECTION_TX_RX;
#else
USART_InitStruct.TransferDirection = LL_USART_DIRECTION_TX;
#endif
USART_InitStruct.HardwareFlowControl = LL_USART_HWCONTROL_NONE;
USART_InitStruct.OverSampling = LL_USART_OVERSAMPLING_16;
LL_USART_Init( USART4, &USART_InitStruct );
LL_USART_DisableOverrunDetect( USART4 );
LL_USART_ConfigAsyncMode( USART4 );
LL_USART_Enable( USART4 );
NVIC_SetPriority(USART4_5_IRQn, 0);
NVIC_EnableIRQ(USART4_5_IRQn);
LL_USART_EnableIT_RXNE(USART4);
}
#if (RHINO_CONFIG_PANIC > 0)
//use DBG_Send in exception print
void print_str() __attribute__ ((alias ("DBG_Send")));
#endif
void DBG_Send( const char *format, ... )
{
va_list args;
static __IO uint16_t len = 0;
uint16_t current_len;
int start;
int stop;
CPSR_ALLOC();
va_start( args, format );
RHINO_CPU_INTRPT_DISABLE();
if ( len != 0 )
{
if ( len != sizeof(uart_context.buffTx) )
{
current_len = len; /* use current_len instead of volatile len in below computation */
len = current_len + vsnprintf( dbgTxBuff + current_len,
sizeof(dbgTxBuff) - current_len,
format, args );
}
RHINO_CPU_INTRPT_ENABLE();
va_end( args );
return;
}
else
{
len = vsnprintf( dbgTxBuff, sizeof(dbgTxBuff), format, args );
}
current_len = len;
RHINO_CPU_INTRPT_ENABLE();
start = 0;
do
{
stop = dbg_buffer_transmit( start, current_len );
{
RHINO_CPU_INTRPT_DISABLE();
if ( len == stop )
{
len = 0;
RHINO_CPU_INTRPT_ENABLE();
}
else
{
start = stop;
current_len = len;
RHINO_CPU_INTRPT_ENABLE();
}
}
} while ( current_len != stop );
va_end( args );
}
void vcom_Init( void )
{
LL_LPUART_InitTypeDef LPUART_InitStruct;
/*## Configure the UART peripheral ######################################*/
/* Put the UART peripheral in the Asynchronous mode (UART Mode) */
/* UART1 configured as follow:
- Word Length = 8 Bits
- Stop Bit = One Stop bit
- Parity = ODD parity
- BaudRate = 921600 baud
- Hardware flow control disabled (RTS and CTS signals) */
/*
* Clock initialization:
* - LSE source selection
* - LPUART clock enable
* - GPIO clocks are enabled in vcom_IoInit()
*/
LL_RCC_SetLPUARTClockSource( LL_RCC_LPUART1_CLKSOURCE_HSI );
UARTX_CLK_ENABLE();
vcom_IoInit( );
LPUART_InitStruct.BaudRate = 9600;
LPUART_InitStruct.DataWidth = LL_LPUART_DATAWIDTH_8B;
LPUART_InitStruct.StopBits = LL_LPUART_STOPBITS_1;
LPUART_InitStruct.Parity = LL_LPUART_PARITY_NONE;
LPUART_InitStruct.TransferDirection = LL_LPUART_DIRECTION_TX_RX;
LPUART_InitStruct.HardwareFlowControl = LL_LPUART_HWCONTROL_NONE;
if ( LL_LPUART_Init( UARTX, &LPUART_InitStruct ) != SUCCESS )
{
Error_Handler( );
}
/* Configuring the LPUART specific LP feature - the wakeup from STOP */
LL_LPUART_EnableInStopMode( UARTX );
/* WakeUp from stop mode on start bit detection*/
LL_LPUART_SetWKUPType( UARTX, LL_LPUART_WAKEUP_ON_STARTBIT );
//LL_LPUART_SetWKUPType(UARTX, LL_LPUART_WAKEUP_ON_RXNE);
LL_LPUART_EnableIT_WKUP( UARTX );
LL_LPUART_Enable( UARTX );
while ( LL_LPUART_IsActiveFlag_TEACK( UARTX ) == RESET )
{
;
}
while ( LL_LPUART_IsActiveFlag_REACK( UARTX ) == RESET )
{
;
}
uart_context.gState = HAL_UART_STATE_READY;
uart_context.RxState = HAL_UART_STATE_READY;
}
void vcom_DeInit( void )
{
LL_LPUART_DeInit( UARTX );
/*##-1- Reset peripherals ##################################################*/
UARTX_FORCE_RESET();
UARTX_RELEASE_RESET();
/*##-2- Disable peripherals and GPIO Clocks #################################*/
/* Configure UART Tx as alternate function */
HW_GPIO_DeInit( UARTX_TX_GPIO_PORT, UARTX_TX_PIN );
/* Configure UART Rx as alternate function */
HW_GPIO_DeInit( UARTX_RX_GPIO_PORT, UARTX_RX_PIN );
/*##-3- Disable the NVIC for UART ##########################################*/
NVIC_DisableIRQ( UARTX_IRQn );
}
void vcom_Send( const char *format, ... )
{
va_list args;
static __IO uint16_t len = 0;
uint16_t current_len;
int start;
int stop;
CPSR_ALLOC();
va_start( args, format );
RHINO_CPU_INTRPT_DISABLE();
if ( len != 0 )
{
if ( len != sizeof(uart_context.buffTx) )
{
current_len = len; /* use current_len instead of volatile len in below computation */
len = current_len + vsnprintf( uart_context.buffTx + current_len,
sizeof(uart_context.buffTx) - current_len,
format, args );
}
RHINO_CPU_INTRPT_ENABLE();
va_end( args );
return;
}
else
{
len = vsnprintf( uart_context.buffTx, sizeof(uart_context.buffTx), format, args );
}
current_len = len;
RHINO_CPU_INTRPT_ENABLE();
start = 0;
do
{
stop = buffer_transmit( start, current_len );
{
RHINO_CPU_INTRPT_DISABLE();
if ( len == stop )
{
len = 0;
RHINO_CPU_INTRPT_ENABLE();
}
else
{
start = stop;
current_len = len;
RHINO_CPU_INTRPT_ENABLE();
}
}
} while ( current_len != stop );
va_end( args );
}
void vcom_ReceiveInit( void )
{
if ( uart_context.RxState != HAL_UART_STATE_READY )
{
return;
}
/* Process Locked */
HW_LOCK( &uart_context );
uart_context.RxState = HAL_UART_STATE_BUSY_RX;
/* Enable the UART Parity Error Interrupt */
LL_LPUART_EnableIT_PE( UARTX );
/* Enable the UART Error Interrupt: (Frame error, noise error, overrun error) */
LL_LPUART_EnableIT_ERROR( UARTX );
/* Process Unlocked */
HW_UNLOCK( &uart_context );
}
void vcom_IoInit( void )
{
GPIO_InitTypeDef GPIO_InitStruct;
/* UART TX GPIO pin configuration */
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_PULLUP;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_MEDIUM;
GPIO_InitStruct.Alternate = UARTX_TX_AF;
HW_GPIO_Init( UARTX_TX_GPIO_PORT, UARTX_TX_PIN, &GPIO_InitStruct );
/* UART RX GPIO pin configuration */
GPIO_InitStruct.Alternate = UARTX_RX_AF;
HW_GPIO_Init( UARTX_RX_GPIO_PORT, UARTX_RX_PIN, &GPIO_InitStruct );
/*##-3- Configure the NVIC for UART ########################################*/
/* NVIC for UART */
NVIC_SetPriority( UARTX_IRQn, 0 );
NVIC_EnableIRQ( UARTX_IRQn );
/* enable RXNE */
LL_LPUART_EnableIT_RXNE( UARTX );
}
void vcom_IoDeInit( void )
{
GPIO_InitTypeDef GPIO_InitStructure = { 0 };
GPIO_InitStructure.Mode = GPIO_MODE_ANALOG;
GPIO_InitStructure.Pull = GPIO_NOPULL;
HW_GPIO_Init( UARTX_TX_GPIO_PORT, UARTX_TX_PIN, &GPIO_InitStructure );
HW_GPIO_Init( UARTX_RX_GPIO_PORT, UARTX_RX_PIN, &GPIO_InitStructure );
}
FlagStatus IsNewCharReceived( void )
{
FlagStatus status;
CPSR_ALLOC();
RHINO_CPU_INTRPT_DISABLE();
status = ((uart_context.rx_idx_toread == uart_context.rx_idx_free) ? RESET : SET);
RHINO_CPU_INTRPT_ENABLE();
return status;
}
uint8_t GetNewChar( void )
{
uint8_t NewChar;
CPSR_ALLOC();
RHINO_CPU_INTRPT_DISABLE();
NewChar = uart_context.buffRx[uart_context.rx_idx_toread];
uart_context.rx_idx_toread = (uart_context.rx_idx_toread + 1) % sizeof(uart_context.buffRx);
RHINO_CPU_INTRPT_ENABLE();
return NewChar;
}
void vcom_IRQHandler( void )
{
int rx_ready = 0;
char rx;
/* UART Wake Up interrupt occured ------------------------------------------*/
if ( LL_LPUART_IsActiveFlag_WKUP( UARTX ) && (LL_LPUART_IsEnabledIT_WKUP( UARTX ) != RESET) )
{
LL_LPUART_ClearFlag_WKUP( UARTX );
/* forbid stop mode */
LowPower_Disable( e_LOW_POWER_UART );
/* Enable the UART Data Register not empty Interrupt */
LL_LPUART_EnableIT_RXNE( UARTX );
}
if ( LL_LPUART_IsActiveFlag_RXNE( UARTX ) && (LL_LPUART_IsEnabledIT_RXNE( UARTX ) != RESET) )
{
/* no need to clear the RXNE flag because it is auto cleared by reading the data*/
rx = LL_LPUART_ReceiveData8( UARTX );
rx_ready = 1;
//PRINTF("%02X\n", rx);
/* allow stop mode*/
LowPower_Enable( e_LOW_POWER_UART );
}
if ( LL_LPUART_IsActiveFlag_PE( UARTX ) || LL_LPUART_IsActiveFlag_FE( UARTX ) || LL_LPUART_IsActiveFlag_ORE( UARTX )
|| LL_LPUART_IsActiveFlag_NE( UARTX ) )
{
PRINTF("Error when receiving\n")
;
/* clear error IT */
LL_LPUART_ClearFlag_PE( UARTX );
LL_LPUART_ClearFlag_FE( UARTX );
LL_LPUART_ClearFlag_ORE( UARTX );
LL_LPUART_ClearFlag_NE( UARTX );
rx = 0x01;
rx_ready = 1;
}
if ( rx_ready == 1 )
{
receive( rx );
}
}
/* Private functions Definition ------------------------------------------------------*/
static int buffer_transmit( int start, int len )
{
int i;
for ( i = start; i < len; i++ )
{
LL_LPUART_ClearFlag_TC( UARTX );
LL_LPUART_TransmitData8( UARTX, uart_context.buffTx[i] );
while ( LL_LPUART_IsActiveFlag_TC( UARTX ) != SET )
{
;
}
}
LL_LPUART_ClearFlag_TC( UARTX );
return len;
}
static void receive( char rx )
{
int next_free;
/** no need to clear the RXNE flag because it is auto cleared by reading the data*/
uart_context.buffRx[uart_context.rx_idx_free] = rx;
next_free = (uart_context.rx_idx_free + 1) % sizeof(uart_context.buffRx);
if ( next_free != uart_context.rx_idx_toread )
{
/* this is ok to read as there is no buffer overflow in input */
uart_context.rx_idx_free = next_free;
}
else
{
/* force the end of a command in case of overflow so that we can process it */
uart_context.buffRx[uart_context.rx_idx_free] = '\r';
PRINTF("uart_context.buffRx buffer overflow %d\r\n")
;
}
}
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/