diff --git a/board/TencentOS_tiny_EVB_MX_Plus/BSP/Hardware/PM25/sensor_parser.c b/board/TencentOS_tiny_EVB_MX_Plus/BSP/Hardware/PM25/sensor_parser.c new file mode 100644 index 00000000..675b690c --- /dev/null +++ b/board/TencentOS_tiny_EVB_MX_Plus/BSP/Hardware/PM25/sensor_parser.c @@ -0,0 +1,337 @@ +/*---------------------------------------------------------------------------- + * Tencent is pleased to support the open source community by making TencentOS + * available. + * + * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. + * If you have downloaded a copy of the TencentOS binary from Tencent, please + * note that the TencentOS binary is licensed under the BSD 3-Clause License. + * + * If you have downloaded a copy of the TencentOS source code from Tencent, + * please note that TencentOS source code is licensed under the BSD 3-Clause + * License, except for the third-party components listed below which are + * subject to different license terms. Your integration of TencentOS into your + * own projects may require compliance with the BSD 3-Clause License, as well + * as the other licenses applicable to the third-party components included + * within TencentOS. + *---------------------------------------------------------------------------*/ + +#include "sensor_parser.h" + +__STATIC__ shell_ctl_t shell_ctl; + +__STATIC__ k_stack_t shell_parser_task_stack[SHELL_PARSER_TASK_STACK_SIZE]; + +__STATIC__ int shell_getchar(void) +{ + uint8_t chr; + k_err_t err; + + if (tos_sem_pend(&SHELL_CTL->shell_rx_sem, TOS_TIME_FOREVER) != K_ERR_NONE) { + return -1; + } + + err = tos_chr_fifo_pop(&SHELL_CTL->shell_rx_fifo, &chr); + + return err == K_ERR_NONE ? chr : -1; +} + +typedef struct sensor_frame_st { + uint16_t len; + uint16_t data1; + uint16_t data2; + uint16_t data3; + uint16_t data4; + uint16_t data5; + uint16_t data6; + uint16_t data7; + uint16_t data8; + uint16_t data9; + uint16_t data10; + uint16_t data11; + uint16_t data12; + uint16_t data13; + uint16_t chk_sum; + + uint8_t len_h; + uint8_t len_l; + + uint8_t data1_h; + uint8_t data1_l; + + uint8_t data2_h; + uint8_t data2_l; + + uint8_t data3_h; + uint8_t data3_l; + + uint8_t data4_h; + uint8_t data4_l; + + uint8_t data5_h; + uint8_t data5_l; + + uint8_t data6_h; + uint8_t data6_l; + + uint8_t data7_h; + uint8_t data7_l; + + uint8_t data8_h; + uint8_t data8_l; + + uint8_t data9_h; + uint8_t data9_l; + + uint8_t data10_h; + uint8_t data10_l; + + uint8_t data11_h; + uint8_t data11_l; + + uint8_t data12_h; + uint8_t data12_l; + + uint8_t data13_h; + uint8_t data13_l; + + uint8_t chk_sum_h; + uint8_t chk_sum_l; +} __PACKED__ sensor_frame_t; + +extern k_mail_q_t mail_q; + +k_tick_t last_report = 0; + +int read_frame(sensor_frame_t *frame) +{ + frame->len_h = shell_getchar(); + frame->len_l = shell_getchar(); + + frame->data1_h = shell_getchar(); + frame->data1_l = shell_getchar(); + + frame->data2_h = shell_getchar(); + frame->data2_l = shell_getchar(); + + frame->data3_h = shell_getchar(); + frame->data3_l = shell_getchar(); + + frame->data4_h = shell_getchar(); + frame->data4_l = shell_getchar(); + + frame->data5_h = shell_getchar(); + frame->data5_l = shell_getchar(); + + frame->data6_h = shell_getchar(); + frame->data6_l = shell_getchar(); + + frame->data7_h = shell_getchar(); + frame->data7_l = shell_getchar(); + + frame->data8_h = shell_getchar(); + frame->data8_l = shell_getchar(); + + frame->data9_h = shell_getchar(); + frame->data9_l = shell_getchar(); + + frame->data10_h = shell_getchar(); + frame->data10_l = shell_getchar(); + + frame->data11_h = shell_getchar(); + frame->data11_l = shell_getchar(); + + frame->data12_h = shell_getchar(); + frame->data12_l = shell_getchar(); + + frame->data13_h = shell_getchar(); + frame->data13_l = shell_getchar(); + + frame->chk_sum_h = shell_getchar(); + frame->chk_sum_l = shell_getchar(); + + + frame->len = (frame->len_h << 8) | frame->len_l; + frame->data1 = (frame->data1_h << 8) | frame->data1_l; + frame->data2 = (frame->data2_h << 8) | frame->data2_l; + frame->data3 = (frame->data3_h << 8) | frame->data3_l; + frame->data4 = (frame->data4_h << 8) | frame->data4_l; + frame->data5 = (frame->data5_h << 8) | frame->data5_l; + frame->data6 = (frame->data6_h << 8) | frame->data6_l; + frame->data7 = (frame->data7_h << 8) | frame->data7_l; + frame->data8 = (frame->data8_h << 8) | frame->data8_l; + frame->data9 = (frame->data9_h << 8) | frame->data9_l; + frame->data10 = (frame->data10_h << 8) | frame->data10_l; + frame->data11 = (frame->data11_h << 8) | frame->data11_l; + frame->data12 = (frame->data12_h << 8) | frame->data12_l; + frame->data13 = (frame->data13_h << 8) | frame->data13_l; + frame->chk_sum = (frame->chk_sum_h << 8) | frame->chk_sum_l; + + + uint16_t chsum; + chsum = frame->len_h + + frame->len_l + + frame->data1_h + + frame->data1_l + + frame->data2_h + + frame->data2_l + + frame->data3_h + + frame->data3_l + + frame->data4_h + + frame->data4_l + + frame->data5_h + + frame->data5_l + + frame->data6_h + + frame->data6_l + + frame->data7_h + + frame->data7_l + + frame->data8_h + + frame->data8_l + + frame->data9_h + + frame->data9_l + + frame->data10_h + + frame->data10_l + + frame->data11_h + + frame->data11_l + + frame->data12_h + + frame->data12_l + + frame->data13_h + + frame->data13_l; + + if (chsum + 0x42 + 0x4d != frame->chk_sum) { + return -1; + } + + k_tick_t now = tos_systick_get(); + if (last_report == 0 || now - last_report >= 15000) { + last_report = now; + + printf("data1: %d\n", frame->data1); + printf("data2: %d\n", frame->data2); + printf("data3: %d\n", frame->data3); + printf("data4: %d\n", frame->data4); + printf("data5: %d\n", frame->data5); + printf("data6: %d\n", frame->data6); + printf("data7: %d\n", frame->data7); + printf("data8: %d\n", frame->data8); + printf("data9: %d\n", frame->data9); + printf("data10: %d\n", frame->data10); + printf("data11: %d\n", frame->data11); + printf("data12: %d\n", frame->data12); + printf("data13: %d\n", frame->data13); + printf("\n\n"); + + return 0; + } + + return -1; +} + +sensor_frame_t frame; + +__STATIC__ int shell_readline(void) +{ + int chr, last_chr = 0; + char *buf = SHELL_CTL->cmd_buffer; + + while (K_TRUE) { + if (buf - SHELL_CTL->cmd_buffer >= (SHELL_CTL->cmd_buffer_size - 1)) { + return -1; + } + + chr = shell_getchar(); + if (chr < 0) { + return -1; + } + + if (chr == 0x4d && last_chr == 0x42) { + if (read_frame(&frame) == 0) { + tos_mail_q_post(&mail_q, &frame.data1_h, 13 * 2); + } + } + + *buf++ = chr; + last_chr = chr; + } +} + + +__STATIC__ void shell_parser(void *arg) +{ + while (K_TRUE) { + shell_readline(); + } +} + +__API__ int tos_shell_init(char *cmd_buf, int cmd_buf_size, shell_output_t output) +{ + void *buffer = K_NULL; + + TOS_PTR_SANITY_CHECK_RC(cmd_buf, -1); + TOS_PTR_SANITY_CHECK_RC(output, -1); + + memset(SHELL_CTL, 0, sizeof(shell_ctl_t)); + + SHELL_CTL->cmd_buffer = cmd_buf; + SHELL_CTL->cmd_buffer_size = cmd_buf_size; + SHELL_CTL->output = output; + + buffer = tos_mmheap_alloc(cmd_buf_size * 2); + if (!buffer) { + return -1; + } + + SHELL_CTL->shell_rx_fifo_buffer = (uint8_t *)buffer; + tos_chr_fifo_create(&SHELL_CTL->shell_rx_fifo, buffer, cmd_buf_size * 2); + + if (tos_sem_create(&SHELL_CTL->shell_rx_sem, (k_sem_cnt_t)0u) != K_ERR_NONE) { + goto errout0; + } + + if (tos_task_create(&SHELL_CTL->parser, "shell_parser", shell_parser, + K_NULL, SHELL_PARSER_TASK_PRIO, shell_parser_task_stack, + SHELL_PARSER_TASK_STACK_SIZE, 0) != K_ERR_NONE) { + goto errout1; + } + + return 0; + +errout1: + tos_sem_destroy(&SHELL_CTL->shell_rx_sem); + +errout0: + tos_mmheap_free(SHELL_CTL->shell_rx_fifo_buffer); + SHELL_CTL->shell_rx_fifo_buffer = K_NULL; + tos_chr_fifo_destroy(&SHELL_CTL->shell_rx_fifo); + + return -1; +} + +__API__ void tos_shell_deinit(void) +{ + tos_task_destroy(&SHELL_CTL->parser); + tos_sem_destroy(&SHELL_CTL->shell_rx_sem); + + tos_mmheap_free(SHELL_CTL->shell_rx_fifo_buffer); + SHELL_CTL->shell_rx_fifo_buffer = K_NULL; + tos_chr_fifo_destroy(&SHELL_CTL->shell_rx_fifo); +} + +__API__ void tos_shell_printf(const char *format, ...) +{ + va_list args; + static char buffer[SHELL_OUTPUT_MAX]; + + va_start(args, format); + vsnprintf(buffer, sizeof(buffer), format, args); + va_end(args); + + (SHELL_CTL->output)(buffer); +} + +__API__ void tos_shell_input_byte(uint8_t data) +{ + if (tos_chr_fifo_push(&SHELL_CTL->shell_rx_fifo, data) == K_ERR_NONE) { + tos_sem_post(&SHELL_CTL->shell_rx_sem); + } +} + diff --git a/board/TencentOS_tiny_EVB_MX_Plus/BSP/Hardware/PM25/sensor_parser.h b/board/TencentOS_tiny_EVB_MX_Plus/BSP/Hardware/PM25/sensor_parser.h new file mode 100644 index 00000000..b69c8169 --- /dev/null +++ b/board/TencentOS_tiny_EVB_MX_Plus/BSP/Hardware/PM25/sensor_parser.h @@ -0,0 +1,54 @@ +/*---------------------------------------------------------------------------- + * Tencent is pleased to support the open source community by making TencentOS + * available. + * + * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. + * If you have downloaded a copy of the TencentOS binary from Tencent, please + * note that the TencentOS binary is licensed under the BSD 3-Clause License. + * + * If you have downloaded a copy of the TencentOS source code from Tencent, + * please note that TencentOS source code is licensed under the BSD 3-Clause + * License, except for the third-party components listed below which are + * subject to different license terms. Your integration of TencentOS into your + * own projects may require compliance with the BSD 3-Clause License, as well + * as the other licenses applicable to the third-party components included + * within TencentOS. + *---------------------------------------------------------------------------*/ + +#ifndef _TOS_SHELL_H_ +#define _TOS_SHELL_H_ + +#include "tos_k.h" + +#define SHELL_CMD_ARGV_MAX 16 +#define SHELL_OUTPUT_MAX 256 +#define SHELL_PARSER_TASK_STACK_SIZE 1024 +#define SHELL_PARSER_TASK_PRIO 5 + +typedef void (*shell_output_t)(const char *str); + +typedef struct shell_control_st { + k_task_t parser; + + shell_output_t output; + + char *cmd_buffer; + int cmd_buffer_size; + + k_sem_t shell_rx_sem; + k_chr_fifo_t shell_rx_fifo; + uint8_t *shell_rx_fifo_buffer; +} shell_ctl_t; + +#define SHELL_CTL ((shell_ctl_t *)(&shell_ctl)) + +__API__ int tos_shell_init(char *cmd_buf, int cmd_buf_size, shell_output_t output); + +__API__ void tos_shell_deinit(void); + +__API__ void tos_shell_printf(const char *format, ...); + +__API__ void tos_shell_input_byte(uint8_t data); + +#endif /* _TOS_SHELL_H_ */ + diff --git a/board/TencentOS_tiny_EVB_MX_Plus/BSP/LoRaWAN/lora_demo.c b/board/TencentOS_tiny_EVB_MX_Plus/BSP/LoRaWAN/lora_demo.c new file mode 100644 index 00000000..af7281ee --- /dev/null +++ b/board/TencentOS_tiny_EVB_MX_Plus/BSP/LoRaWAN/lora_demo.c @@ -0,0 +1,119 @@ +#include "lora_demo.h" +#include "RHF76.h" +#include "sensor_parser.h" + +/* + ================================================================================== + data template: + + Type Name Token DataType RW Attribute + property temperature temperature integer readonly range: [-100, 155] + initial: 0 + step: 1 + unit: centigrade + + property humidity humidity integer readonly range: [-0, 100] + initial: 0 + step: 1 + unit: % + + property report_period period integer read-write range: [0, 3600] + initial: 0 + step: 1 + unit: second + + ================================================================================== + up-link parser javascript: + + function RawToProtocol(fPort, bytes) { + var data = { + "method": "report", + "clientToken" : new Date(), + "params" : {} + }; + data.params.temperature = bytes[0]; + data.params.humidity = bytes[1]; + data.params.period = bytes[2] | (bytes[3] << 8); + return data; + } + + ================================================================================== + down-link parser javascript: + + function ProtocolToRaw(obj) { + var data = new Array(); + data[0] = 5;// fport=5 + data[1] = 0;// unconfirmed mode + data[2] = obj.params.period & 0x00FF; + data[3] = (obj.params.period >> 8) & 0x00FF; + return data; + } + + */ + +uint16_t report_period = 10; + +k_mail_q_t mail_q; +#define DATA_CNT 26 +uint8_t mail_buf[DATA_CNT]; + +typedef struct device_data_st { + uint8_t data[DATA_CNT]; +} __PACKED__ dev_data_t; + +void recv_callback(uint8_t *data, uint8_t len) +{ + int i = 0; + + printf("len: %d\n", len); + + for (i = 0; i < len; ++i) { + printf("data[%d]: %d\n", i, data[i]); + } + + if (len == 1) { + report_period = data[0]; + } else if (len >= 2) { + report_period = data[0] | (data[1] << 8); + } + printf("report_period: %d\n", report_period); +} + + +#define CMD_LEN_MAX 1024 +char cmd_buf[CMD_LEN_MAX]; + +void uart_output(const char *str) +{ + /* if using c lib printf through uart, a simpler one is: */ + printf(str); +} + +dev_data_t dev_data; +uint8_t pool[DATA_CNT]; + +void application_entry(void *arg) +{ + int i = 0; + + rhf76_lora_init(HAL_UART_PORT_0); + tos_lora_module_recvcb_register(recv_callback); + + tos_lora_module_join_otaa("8cf957200000025a", "8cf957200000025a1e29aaaaad204a72"); + + tos_mail_q_create(&mail_q, pool, DATA_CNT, sizeof(uint8_t)); + tos_shell_init(cmd_buf, sizeof(cmd_buf), uart_output); + + while (1) { + size_t mail_size; + tos_mail_q_pend(&mail_q, &dev_data.data, &mail_size, TOS_TIME_FOREVER); + + for (i = 0; i < mail_size; ++i) { + printf("[%d] %x\n", i, dev_data.data[i]); + } + printf("\n\n"); + + tos_lora_module_send(&dev_data.data, mail_size); + } +} + diff --git a/board/TencentOS_tiny_EVB_MX_Plus/BSP/LoRaWAN/lora_demo.h b/board/TencentOS_tiny_EVB_MX_Plus/BSP/LoRaWAN/lora_demo.h new file mode 100644 index 00000000..fc0cf1e3 --- /dev/null +++ b/board/TencentOS_tiny_EVB_MX_Plus/BSP/LoRaWAN/lora_demo.h @@ -0,0 +1,24 @@ +#ifndef __LORA_DEMO_H__ +#define __LORA_DEMO_H__ + +#include "mcu_init.h" +#include "tos_at.h" +#include "string.h" +#include "tos_k.h" +#include "lora_module_wrapper.h" +#ifdef __cplusplus + extern "C" { +#endif + +typedef struct +{ + char data[32]; +}ReportData_TypeDef; + +void application_entry(void *arg); +#ifdef __cplusplus +} +#endif + +#endif /* __LORA_DEMO_H__ */ + diff --git a/board/TencentOS_tiny_EVB_MX_Plus/BSP/Src/stm32l4xx_it_lorawan.c b/board/TencentOS_tiny_EVB_MX_Plus/BSP/Src/stm32l4xx_it_lorawan.c new file mode 100644 index 00000000..401b6b85 --- /dev/null +++ b/board/TencentOS_tiny_EVB_MX_Plus/BSP/Src/stm32l4xx_it_lorawan.c @@ -0,0 +1,313 @@ +/* USER CODE BEGIN Header */ +/** + ****************************************************************************** + * @file stm32l4xx_it.c + * @brief Interrupt Service Routines. + ****************************************************************************** + * @attention + * + *

© Copyright (c) 2019 STMicroelectronics. + * All rights reserved.

+ * + * This software component is licensed by ST under BSD 3-Clause license, + * the "License"; You may not use this file except in compliance with the + * License. You may obtain a copy of the License at: + * opensource.org/licenses/BSD-3-Clause + * + ****************************************************************************** + */ +/* USER CODE END Header */ + +/* Includes ------------------------------------------------------------------*/ +#include "main.h" +#include "stm32l4xx_it.h" +#include "tos_k.h" +#include "tos_at.h" +#include "sensor_parser.h" +/* Private includes ----------------------------------------------------------*/ +/* USER CODE BEGIN Includes */ +/* USER CODE END Includes */ + +/* Private typedef -----------------------------------------------------------*/ +/* USER CODE BEGIN TD */ + +/* USER CODE END TD */ + +/* Private define ------------------------------------------------------------*/ +/* USER CODE BEGIN PD */ + +/* USER CODE END PD */ + +/* Private macro -------------------------------------------------------------*/ +/* USER CODE BEGIN PM */ + +/* USER CODE END PM */ + +/* Private variables ---------------------------------------------------------*/ +/* USER CODE BEGIN PV */ + +/* USER CODE END PV */ + +/* Private function prototypes -----------------------------------------------*/ +/* USER CODE BEGIN PFP */ + +/* USER CODE END PFP */ + +/* Private user code ---------------------------------------------------------*/ +/* USER CODE BEGIN 0 */ + +/* USER CODE END 0 */ + +/* External variables --------------------------------------------------------*/ +extern UART_HandleTypeDef hlpuart1; +extern UART_HandleTypeDef huart2; +extern UART_HandleTypeDef huart3; +/* USER CODE BEGIN EV */ + +/* USER CODE END EV */ + +/******************************************************************************/ +/* Cortex-M4 Processor Interruption and Exception Handlers */ +/******************************************************************************/ +/** + * @brief This function handles Non maskable interrupt. + */ +void NMI_Handler(void) +{ + /* USER CODE BEGIN NonMaskableInt_IRQn 0 */ + + /* USER CODE END NonMaskableInt_IRQn 0 */ + /* USER CODE BEGIN NonMaskableInt_IRQn 1 */ + + /* USER CODE END NonMaskableInt_IRQn 1 */ +} + +/** + * @brief This function handles Hard fault interrupt. + */ +void HardFault_Handler(void) +{ + /* USER CODE BEGIN HardFault_IRQn 0 */ + + /* USER CODE END HardFault_IRQn 0 */ + while (1) + { + /* USER CODE BEGIN W1_HardFault_IRQn 0 */ + /* USER CODE END W1_HardFault_IRQn 0 */ + } +} + +/** + * @brief This function handles Memory management fault. + */ +void MemManage_Handler(void) +{ + /* USER CODE BEGIN MemoryManagement_IRQn 0 */ + + /* USER CODE END MemoryManagement_IRQn 0 */ + while (1) + { + /* USER CODE BEGIN W1_MemoryManagement_IRQn 0 */ + /* USER CODE END W1_MemoryManagement_IRQn 0 */ + } +} + +/** + * @brief This function handles Prefetch fault, memory access fault. + */ +void BusFault_Handler(void) +{ + /* USER CODE BEGIN BusFault_IRQn 0 */ + + /* USER CODE END BusFault_IRQn 0 */ + while (1) + { + /* USER CODE BEGIN W1_BusFault_IRQn 0 */ + /* USER CODE END W1_BusFault_IRQn 0 */ + } +} + +/** + * @brief This function handles Undefined instruction or illegal state. + */ +void UsageFault_Handler(void) +{ + /* USER CODE BEGIN UsageFault_IRQn 0 */ + + /* USER CODE END UsageFault_IRQn 0 */ + while (1) + { + /* USER CODE BEGIN W1_UsageFault_IRQn 0 */ + /* USER CODE END W1_UsageFault_IRQn 0 */ + } +} + +/** + * @brief This function handles System service call via SWI instruction. + */ +void SVC_Handler(void) +{ + /* USER CODE BEGIN SVCall_IRQn 0 */ + + /* USER CODE END SVCall_IRQn 0 */ + /* USER CODE BEGIN SVCall_IRQn 1 */ + + /* USER CODE END SVCall_IRQn 1 */ +} + +/** + * @brief This function handles Debug monitor. + */ +void DebugMon_Handler(void) +{ + /* USER CODE BEGIN DebugMonitor_IRQn 0 */ + + /* USER CODE END DebugMonitor_IRQn 0 */ + /* USER CODE BEGIN DebugMonitor_IRQn 1 */ + + /* USER CODE END DebugMonitor_IRQn 1 */ +} + +/** + * @brief This function handles Pendable request for system service. + */ +__weak void PendSV_Handler(void) +{ + /* USER CODE BEGIN PendSV_IRQn 0 */ + + /* USER CODE END PendSV_IRQn 0 */ + /* USER CODE BEGIN PendSV_IRQn 1 */ + + /* USER CODE END PendSV_IRQn 1 */ +} + +/** + * @brief This function handles System tick timer. + */ +void SysTick_Handler(void) +{ + /* USER CODE BEGIN SysTick_IRQn 0 */ + + /* USER CODE END SysTick_IRQn 0 */ + HAL_IncTick(); + if (tos_knl_is_running()) + { + tos_knl_irq_enter(); + tos_tick_handler(); + tos_knl_irq_leave(); + } + //HAL_SYSTICK_IRQHandler(); + /* USER CODE BEGIN SysTick_IRQn 1 */ + + /* USER CODE END SysTick_IRQn 1 */ +} + +/******************************************************************************/ +/* STM32L4xx Peripheral Interrupt Handlers */ +/* Add here the Interrupt Handlers for the used peripherals. */ +/* For the available peripheral interrupt handler names, */ +/* please refer to the startup file (startup_stm32l4xx.s). */ +/******************************************************************************/ + +/** + * @brief This function handles EXTI line1 interrupt. + */ +void EXTI1_IRQHandler(void) +{ + /* USER CODE BEGIN EXTI1_IRQn 0 */ + + /* USER CODE END EXTI1_IRQn 0 */ + HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_1); + /* USER CODE BEGIN EXTI1_IRQn 1 */ + + /* USER CODE END EXTI1_IRQn 1 */ +} + +/** + * @brief This function handles EXTI line2 interrupt. + */ +void EXTI2_IRQHandler(void) +{ + /* USER CODE BEGIN EXTI2_IRQn 0 */ + + /* USER CODE END EXTI2_IRQn 0 */ + HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_2); + /* USER CODE BEGIN EXTI2_IRQn 1 */ + + /* USER CODE END EXTI2_IRQn 1 */ +} + +/** + * @brief This function handles EXTI line3 interrupt. + */ +void EXTI3_IRQHandler(void) +{ + /* USER CODE BEGIN EXTI3_IRQn 0 */ + + /* USER CODE END EXTI3_IRQn 0 */ + HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_3); + /* USER CODE BEGIN EXTI3_IRQn 1 */ + + /* USER CODE END EXTI3_IRQn 1 */ +} + +/** + * @brief This function handles USART2 global interrupt. + */ +void USART2_IRQHandler(void) +{ + /* USER CODE BEGIN USART2_IRQn 0 */ + + /* USER CODE END USART2_IRQn 0 */ + HAL_UART_IRQHandler(&huart2); + /* USER CODE BEGIN USART2_IRQn 1 */ + + /* USER CODE END USART2_IRQn 1 */ +} + +/** + * @brief This function handles USART3 global interrupt. + */ +void USART3_IRQHandler(void) +{ + /* USER CODE BEGIN USART3_IRQn 0 */ + + /* USER CODE END USART3_IRQn 0 */ + HAL_UART_IRQHandler(&huart3); + /* USER CODE BEGIN USART3_IRQn 1 */ + + /* USER CODE END USART3_IRQn 1 */ +} + +/** + * @brief This function handles LPUART1 global interrupt. + */ +void LPUART1_IRQHandler(void) +{ + /* USER CODE BEGIN LPUART1_IRQn 0 */ + + /* USER CODE END LPUART1_IRQn 0 */ + tos_knl_irq_enter(); + HAL_UART_IRQHandler(&hlpuart1); + tos_knl_irq_leave(); + /* USER CODE BEGIN LPUART1_IRQn 1 */ + + /* USER CODE END LPUART1_IRQn 1 */ +} + +/* USER CODE BEGIN 1 */ +void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart) +{ + extern uint8_t data; + extern uint8_t msg; + if (huart->Instance == LPUART1) { + HAL_UART_Receive_IT(&hlpuart1, &data, 1); + tos_at_uart_input_byte(data); + } + if (huart->Instance == USART3) { + HAL_UART_Receive_IT(&huart3, &msg, 1); + tos_shell_input_byte(msg); + } +} +/* USER CODE END 1 */ +/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/board/TencentOS_tiny_EVB_MX_Plus/BSP/Src/usart.c b/board/TencentOS_tiny_EVB_MX_Plus/BSP/Src/usart.c index 1b2def87..5ec09a9a 100644 --- a/board/TencentOS_tiny_EVB_MX_Plus/BSP/Src/usart.c +++ b/board/TencentOS_tiny_EVB_MX_Plus/BSP/Src/usart.c @@ -22,6 +22,7 @@ /* USER CODE BEGIN 0 */ uint8_t data; +uint8_t msg; /* USER CODE END 0 */ UART_HandleTypeDef hlpuart1; @@ -111,7 +112,7 @@ void MX_USART3_UART_Init(void) { Error_Handler(); } - HAL_UART_Receive_IT(&huart3, &data, 1);//(uint8_t *)aRxBuffer, 1); + HAL_UART_Receive_IT(&huart3, &msg, 1);//(uint8_t *)aRxBuffer, 1); } void HAL_UART_MspInit(UART_HandleTypeDef* uartHandle) diff --git a/board/TencentOS_tiny_EVB_MX_Plus/KEIL/lorawan/TencentOS_tiny.uvoptx b/board/TencentOS_tiny_EVB_MX_Plus/KEIL/lorawan/TencentOS_tiny.uvoptx index b2338dd3..737dcf83 100644 --- a/board/TencentOS_tiny_EVB_MX_Plus/KEIL/lorawan/TencentOS_tiny.uvoptx +++ b/board/TencentOS_tiny_EVB_MX_Plus/KEIL/lorawan/TencentOS_tiny.uvoptx @@ -270,7 +270,7 @@ Application/User - 0 + 1 0 0 0 @@ -389,8 +389,8 @@ 0 0 0 - ..\..\BSP\Src\stm32l4xx_it_module.c - stm32l4xx_it_module.c + ..\..\BSP\Src\tim.c + tim.c 0 0 @@ -401,8 +401,8 @@ 0 0 0 - ..\..\BSP\Src\tim.c - tim.c + ..\..\BSP\Src\stm32l4xx_it_lorawan.c + stm32l4xx_it_lorawan.c 0 0 @@ -410,7 +410,7 @@ examples - 0 + 1 0 0 0 @@ -421,7 +421,7 @@ 0 0 0 - ..\..\..\..\examples\LoRaWAN\lora_demo.c + ..\..\BSP\LoRaWAN\lora_demo.c lora_demo.c 0 0 @@ -1252,6 +1252,26 @@ + + sensor_parser + 0 + 0 + 0 + 0 + + 14 + 76 + 1 + 0 + 0 + 0 + ..\..\BSP\Hardware\PM25\sensor_parser.c + sensor_parser.c + 0 + 0 + + + ::CMSIS 0 diff --git a/board/TencentOS_tiny_EVB_MX_Plus/KEIL/lorawan/TencentOS_tiny.uvprojx b/board/TencentOS_tiny_EVB_MX_Plus/KEIL/lorawan/TencentOS_tiny.uvprojx index 6040cf44..fde04d95 100644 --- a/board/TencentOS_tiny_EVB_MX_Plus/KEIL/lorawan/TencentOS_tiny.uvprojx +++ b/board/TencentOS_tiny_EVB_MX_Plus/KEIL/lorawan/TencentOS_tiny.uvprojx @@ -16,7 +16,7 @@ STM32L431RCTx STMicroelectronics - Keil.STM32L4xx_DFP.2.0.0 + Keil.STM32L4xx_DFP.2.2.0 http://www.keil.com/pack IRAM(0x20000000-0x2000FFFF) IROM(0x8000000-0x803FFFF) CLOCK(8000000) FPU2 CPUTYPE("Cortex-M4") @@ -338,7 +338,7 @@ USE_HAL_DRIVER,STM32L431xx,WITH_TOS_NET_ADAPTER,USE_ESP8266 - ..\..\BSP\Inc;..\..\..\..\platform\vendor_bsp\st\STM32L4xx_HAL_Driver\Inc;..\..\..\..\platform\vendor_bsp\st\STM32L4xx_HAL_Driver\Legacy;..\..\..\..\platform\vendor_bsp\st\CMSIS\Device\ST\STM32L4xx\Include;..\..\..\..\platform\vendor_bsp\st\CMSIS\Include;..\..\..\..\kernel\core\include;..\..\TOS-CONFIG;..\..\..\..\platform\arch\arm\cortex-m4\keil;..\..\..\..\kernel\pm\include;..\..\..\..\osal\cmsis_os;..\..\..\..\arch\arm\arm-v7m\common\include;..\..\..\..\arch\arm\arm-v7m\cortex-m4\armcc;..\..\BSP\Hardware\DHT11;..\..\BSP\Hardware\BH1750;..\..\BSP\Hardware\OLED;..\..\..\..\net\at\include;..\..\..\..\kernel\hal\include;..\..\..\..\net\lora_module_wrapper;..\..\..\..\components\connectivity\Eclipse-Paho-MQTT\wrapper\include;..\..\..\..\components\connectivity\Eclipse-Paho-MQTT\3rdparty\include;..\..\..\..\examples\LoRaWAN;..\..\..\..\devices\rhf76_lora + ..\..\BSP\Inc;..\..\..\..\platform\vendor_bsp\st\STM32L4xx_HAL_Driver\Inc;..\..\..\..\platform\vendor_bsp\st\STM32L4xx_HAL_Driver\Legacy;..\..\..\..\platform\vendor_bsp\st\CMSIS\Device\ST\STM32L4xx\Include;..\..\..\..\platform\vendor_bsp\st\CMSIS\Include;..\..\..\..\kernel\core\include;..\..\TOS-CONFIG;..\..\..\..\platform\arch\arm\cortex-m4\keil;..\..\..\..\kernel\pm\include;..\..\..\..\osal\cmsis_os;..\..\..\..\arch\arm\arm-v7m\common\include;..\..\..\..\arch\arm\arm-v7m\cortex-m4\armcc;..\..\BSP\Hardware\DHT11;..\..\BSP\Hardware\BH1750;..\..\BSP\Hardware\OLED;..\..\BSP\Hardware\PM25;..\..\..\..\net\at\include;..\..\..\..\kernel\hal\include;..\..\..\..\net\lora_module_wrapper;..\..\..\..\components\connectivity\Eclipse-Paho-MQTT\wrapper\include;..\..\..\..\components\connectivity\Eclipse-Paho-MQTT\3rdparty\include;..\..\BSP\LoRaWAN;..\..\..\..\devices\rhf76_lora @@ -437,16 +437,16 @@ 1 ..\..\BSP\Src\spi.c - - stm32l4xx_it_module.c - 1 - ..\..\BSP\Src\stm32l4xx_it_module.c - tim.c 1 ..\..\BSP\Src\tim.c + + stm32l4xx_it_lorawan.c + 1 + ..\..\BSP\Src\stm32l4xx_it_lorawan.c + @@ -455,7 +455,7 @@ lora_demo.c 1 - ..\..\..\..\examples\LoRaWAN\lora_demo.c + ..\..\BSP\LoRaWAN\lora_demo.c @@ -819,6 +819,16 @@ + + sensor_parser + + + sensor_parser.c + 1 + ..\..\BSP\Hardware\PM25\sensor_parser.c + + + ::CMSIS