优化FreeRTOS
This commit is contained in:
parent
f4bd30a4dc
commit
bc65530c00
5
.vscode/settings.json
vendored
5
.vscode/settings.json
vendored
@ -1,4 +1,7 @@
|
|||||||
{
|
{
|
||||||
"cmake.sourceDirectory": "/mnt/c/Users/niuyuling/Desktop/raspberry-pico/Danger-alarm/SOFTWARE",
|
"cmake.sourceDirectory": "/mnt/c/Users/niuyuling/Desktop/raspberry-pico/Danger-alarm/SOFTWARE",
|
||||||
"C_Cpp.errorSquiggles": "disabled"
|
"C_Cpp.errorSquiggles": "disabled",
|
||||||
|
"files.associations": {
|
||||||
|
"cstring": "cpp"
|
||||||
|
}
|
||||||
}
|
}
|
@ -19,6 +19,8 @@
|
|||||||
apt install cmake gcc-arm-none-eabi gcc g++
|
apt install cmake gcc-arm-none-eabi gcc g++
|
||||||
apt install gdb-multiarch automake autoconf build-essential texinfo libtool libftdi-dev libusb-1.0-0-dev
|
apt install gdb-multiarch automake autoconf build-essential texinfo libtool libftdi-dev libusb-1.0-0-dev
|
||||||
|
|
||||||
|
# RP2040 SDK 版本构建
|
||||||
|
cd ~
|
||||||
git clone https://git.aixiao.me/aixiao/Danger-alarm.git
|
git clone https://git.aixiao.me/aixiao/Danger-alarm.git
|
||||||
cd Danger-alarm
|
cd Danger-alarm
|
||||||
git submodule init
|
git submodule init
|
||||||
@ -29,8 +31,13 @@
|
|||||||
cmake -DPICO_BOARD=pico_w ..
|
cmake -DPICO_BOARD=pico_w ..
|
||||||
make
|
make
|
||||||
|
|
||||||
|
# FreeRTOS 版本构建
|
||||||
|
cd ~/Danger-alarm/SOFTWARE-FreeRTOS
|
||||||
|
mkdir build
|
||||||
|
cmake -DPICO_BOARD=pico_w .. && make -j4
|
||||||
|
|
||||||
# 树莓派Zero W 433MHZ HC-12接收服务端构建
|
|
||||||
|
# 树莓派Zero W 433MHZ HC-12接收服务端构建(需要自己设置Raspberry Pi 串口)
|
||||||
apt install libmysqlclient-dev
|
apt install libmysqlclient-dev
|
||||||
cd ~
|
cd ~
|
||||||
git clone https://github.com/WiringPi/WiringPi.git
|
git clone https://github.com/WiringPi/WiringPi.git
|
||||||
|
@ -10,6 +10,7 @@ void DS18B20(void *pvParameters)
|
|||||||
{
|
{
|
||||||
// One_wire 第三方库方法
|
// One_wire 第三方库方法
|
||||||
float TEMPERATURE = -1;
|
float TEMPERATURE = -1;
|
||||||
|
char TEMPERATURE_TEMP[BUFER] = { 0 };
|
||||||
One_wire one_wire(DS18B20_PIN);
|
One_wire one_wire(DS18B20_PIN);
|
||||||
one_wire.init();
|
one_wire.init();
|
||||||
rom_address_t address {
|
rom_address_t address {
|
||||||
@ -23,19 +24,24 @@ void DS18B20(void *pvParameters)
|
|||||||
|
|
||||||
|
|
||||||
one_wire.single_device_read_rom(address);
|
one_wire.single_device_read_rom(address);
|
||||||
one_wire.convert_temperature(address, true, false);
|
int delay_time = one_wire.convert_temperature(address, true, false);
|
||||||
|
//printf("Conversion delay time: %d ms\n", delay_time);
|
||||||
|
|
||||||
TEMPERATURE = one_wire.temperature(address);
|
TEMPERATURE = one_wire.temperature(address);
|
||||||
|
|
||||||
sleep_ms(1000);
|
|
||||||
printf("Device Address: %02x%02x%02x%02x%02x%02x%02x%02x DS18B20 Temperature: %3.1f°C\n", \
|
printf("Device Address: %02x%02x%02x%02x%02x%02x%02x%02x DS18B20 Temperature: %3.1f°C\n", \
|
||||||
address.rom[0], address.rom[1], address.rom[2], address.rom[3], address.rom[4], \
|
address.rom[0], address.rom[1], address.rom[2], address.rom[3], address.rom[4], \
|
||||||
address.rom[5], address.rom[6], address.rom[7], one_wire.temperature(address));
|
address.rom[5], address.rom[6], address.rom[7], one_wire.temperature(address));
|
||||||
|
|
||||||
|
if (TEMPERATURE == -1000) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if (TEMPERATURE != 85) {
|
if (TEMPERATURE != 85) {
|
||||||
char TEMPERATURE_TEMP[BUFER] = { 0 };
|
|
||||||
sprintf(TEMPERATURE_TEMP, "Temperature: %.3f°C\n", TEMPERATURE);
|
sprintf(TEMPERATURE_TEMP, "Temperature: %.3f°C\n", TEMPERATURE);
|
||||||
_HC_12(TEMPERATURE_TEMP);
|
_HC_12(TEMPERATURE_TEMP);
|
||||||
|
memset(TEMPERATURE_TEMP, 0, BUFER);
|
||||||
TEMPERATURE = -1;
|
TEMPERATURE = -1;
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
@ -45,7 +51,7 @@ void DS18B20(void *pvParameters)
|
|||||||
*/
|
*/
|
||||||
//_printTaskStackHighWaterMark("DS18B20");
|
//_printTaskStackHighWaterMark("DS18B20");
|
||||||
//watchdog_update(); // 喂狗
|
//watchdog_update(); // 喂狗
|
||||||
vTaskDelay(pdMS_TO_TICKS(3000)); // 非阻塞延时
|
vTaskDelay(pdMS_TO_TICKS(5000)); // 非阻塞延时
|
||||||
}
|
}
|
||||||
|
|
||||||
return ;
|
return ;
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
#include "semphr.h"
|
#include "semphr.h"
|
||||||
#include "queue.h"
|
#include "queue.h"
|
||||||
|
|
||||||
|
#include <cstring>
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include "pico/stdlib.h"
|
#include "pico/stdlib.h"
|
||||||
|
@ -20,7 +20,8 @@ static uint16_t MH_Z14B(int *MH_Z14B_DATA_IS_OK)
|
|||||||
// 0x86 读气体浓度值
|
// 0x86 读气体浓度值
|
||||||
uint8_t CMD[9] = { 0xFF, 0x01, 0x86, 0x00, 0x00, 0x00, 0x00, 0x00, 0x79 };
|
uint8_t CMD[9] = { 0xFF, 0x01, 0x86, 0x00, 0x00, 0x00, 0x00, 0x00, 0x79 };
|
||||||
uart_write_blocking(UART1, CMD, 9);
|
uart_write_blocking(UART1, CMD, 9);
|
||||||
sleep_ms(200);
|
//sleep_ms(200);
|
||||||
|
vTaskDelay(pdMS_TO_TICKS(200)); // 非阻塞延时
|
||||||
|
|
||||||
// 读取
|
// 读取
|
||||||
uint8_t CO2_DATA[9] = { 0 };
|
uint8_t CO2_DATA[9] = { 0 };
|
||||||
@ -41,12 +42,14 @@ static uint16_t MH_Z14B(int *MH_Z14B_DATA_IS_OK)
|
|||||||
// 校准传感器 零点 (ZERO)
|
// 校准传感器 零点 (ZERO)
|
||||||
uint8_t ZERO[] = { 0XFF, 0X01, 0X87, 0X00, 0X00, 0X00, 0X00, 0X00, 0X78 };
|
uint8_t ZERO[] = { 0XFF, 0X01, 0X87, 0X00, 0X00, 0X00, 0X00, 0X00, 0X78 };
|
||||||
uart_write_blocking(UART1, ZERO, 9);
|
uart_write_blocking(UART1, ZERO, 9);
|
||||||
sleep_ms(200);
|
//sleep_ms(200);
|
||||||
|
vTaskDelay(pdMS_TO_TICKS(200)); // 非阻塞延时
|
||||||
|
|
||||||
// 校准传感器 跨度点 (SPAN)
|
// 校准传感器 跨度点 (SPAN)
|
||||||
uint8_t SPAN[] = { 0XFF, 0X01, 0X88, 0X07, 0XD0, 0X00, 0X00, 0X00, 0XA0 };
|
uint8_t SPAN[] = { 0XFF, 0X01, 0X88, 0X07, 0XD0, 0X00, 0X00, 0X00, 0XA0 };
|
||||||
uart_write_blocking(UART1, SPAN, 9);
|
uart_write_blocking(UART1, SPAN, 9);
|
||||||
sleep_ms(200);
|
//sleep_ms(200);
|
||||||
|
vTaskDelay(pdMS_TO_TICKS(200)); // 非阻塞延时
|
||||||
|
|
||||||
*MH_Z14B_DATA_IS_OK = 0;
|
*MH_Z14B_DATA_IS_OK = 0;
|
||||||
printf("CO2 concentration reading failed!\n");
|
printf("CO2 concentration reading failed!\n");
|
||||||
@ -58,8 +61,9 @@ static uint16_t MH_Z14B(int *MH_Z14B_DATA_IS_OK)
|
|||||||
|
|
||||||
void CO2(void *pvParameters)
|
void CO2(void *pvParameters)
|
||||||
{
|
{
|
||||||
uint16_t CO2_DATA = -1;
|
uint16_t CO2_DATA = 0;
|
||||||
int MH_Z14B_DATA_IS_OK = 0;
|
int MH_Z14B_DATA_IS_OK = 0;
|
||||||
|
char CO2_DATA_TEMP[BUFER] = { 0 };
|
||||||
MH_Z14B_INIT();
|
MH_Z14B_INIT();
|
||||||
_printTaskStackHighWaterMark("CO2");
|
_printTaskStackHighWaterMark("CO2");
|
||||||
|
|
||||||
@ -68,15 +72,15 @@ void CO2(void *pvParameters)
|
|||||||
if (CO2_DATA != -1 && MH_Z14B_DATA_IS_OK == 1) {
|
if (CO2_DATA != -1 && MH_Z14B_DATA_IS_OK == 1) {
|
||||||
printf("CO2 Concentration: %d ppm\n", CO2_DATA);
|
printf("CO2 Concentration: %d ppm\n", CO2_DATA);
|
||||||
|
|
||||||
char CO2_DATA_TEMP[BUFER] = { 0 };
|
snprintf(CO2_DATA_TEMP, BUFER, "CO2 Concentration: %d ppm\n", CO2_DATA);
|
||||||
sprintf(CO2_DATA_TEMP, "CO2 Concentration: %d ppm\n", CO2_DATA);
|
|
||||||
_HC_12(CO2_DATA_TEMP);
|
_HC_12(CO2_DATA_TEMP);
|
||||||
|
memset(CO2_DATA_TEMP, 0, BUFER);
|
||||||
}
|
}
|
||||||
|
|
||||||
//_printTaskStackHighWaterMark("CO2");
|
//_printTaskStackHighWaterMark("CO2");
|
||||||
watchdog_update(); // 喂狗
|
watchdog_update(); // 喂狗
|
||||||
|
|
||||||
vTaskDelay(pdMS_TO_TICKS(3000)); // 非阻塞延时
|
vTaskDelay(pdMS_TO_TICKS(5000)); // 非阻塞延时
|
||||||
printf("\n");
|
printf("\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
#include "semphr.h"
|
#include "semphr.h"
|
||||||
#include "queue.h"
|
#include "queue.h"
|
||||||
|
|
||||||
|
#include <cstring>
|
||||||
#include "pico/stdlib.h"
|
#include "pico/stdlib.h"
|
||||||
#include "hardware/clocks.h"
|
#include "hardware/clocks.h"
|
||||||
#include "hardware/watchdog.h"
|
#include "hardware/watchdog.h"
|
||||||
|
@ -105,18 +105,19 @@ int ZC13(const char *model)
|
|||||||
void CH4(void *pvParameters)
|
void CH4(void *pvParameters)
|
||||||
{
|
{
|
||||||
ZC13_INIT();
|
ZC13_INIT();
|
||||||
|
char CH4_DATA[BUFER] = { 0 };
|
||||||
_printTaskStackHighWaterMark("CH4");
|
_printTaskStackHighWaterMark("CH4");
|
||||||
|
|
||||||
while (1)
|
while (1)
|
||||||
{
|
{
|
||||||
|
|
||||||
char CH4_DATA[BUFER] = { 0 };
|
snprintf(CH4_DATA, BUFER, "CH4 Concentration: %d\n", ZC13("ZC05"));
|
||||||
sprintf(CH4_DATA, "CH4 Concentration: %d\n", ZC13("ZC05"));
|
|
||||||
_HC_12(CH4_DATA);
|
_HC_12(CH4_DATA);
|
||||||
|
memset(CH4_DATA, 0, BUFER);
|
||||||
|
|
||||||
//_printTaskStackHighWaterMark("CH4");
|
//_printTaskStackHighWaterMark("CH4");
|
||||||
//watchdog_update(); // 喂狗
|
//watchdog_update(); // 喂狗
|
||||||
vTaskDelay(pdMS_TO_TICKS(3000)); // 非阻塞延时
|
vTaskDelay(pdMS_TO_TICKS(5000)); // 非阻塞延时
|
||||||
}
|
}
|
||||||
|
|
||||||
return ;
|
return ;
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
#include "semphr.h"
|
#include "semphr.h"
|
||||||
#include "queue.h"
|
#include "queue.h"
|
||||||
|
|
||||||
|
#include <cstring>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <strings.h>
|
#include <strings.h>
|
||||||
#include "pico/stdlib.h"
|
#include "pico/stdlib.h"
|
||||||
|
@ -21,6 +21,7 @@ static uint16_t ZE07CO(int ANSWER, int *ZE07_CO_DATA_IS_OK)
|
|||||||
static uint8_t _ANSWER[9] = { 0xFF, 0x01, 0x78, 0x41, 0x00, 0x00, 0x00, 0x00, 0x46 };
|
static uint8_t _ANSWER[9] = { 0xFF, 0x01, 0x78, 0x41, 0x00, 0x00, 0x00, 0x00, 0x46 };
|
||||||
uart_write_blocking(UART0, _ANSWER, 9);
|
uart_write_blocking(UART0, _ANSWER, 9);
|
||||||
sleep_ms(100);
|
sleep_ms(100);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ANSWER == 2) {
|
if (ANSWER == 2) {
|
||||||
@ -81,7 +82,7 @@ void CO(void *pvParameters)
|
|||||||
|
|
||||||
//_printTaskStackHighWaterMark("CO");
|
//_printTaskStackHighWaterMark("CO");
|
||||||
//watchdog_update(); // 喂狗
|
//watchdog_update(); // 喂狗
|
||||||
vTaskDelay(pdMS_TO_TICKS(3000)); // 非阻塞延时
|
vTaskDelay(pdMS_TO_TICKS(5000)); // 非阻塞延时
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
|
Loading…
Reference in New Issue
Block a user