129 lines
2.9 KiB
C
129 lines
2.9 KiB
C
|
||
|
||
//#include "FreeRTOS.h"
|
||
//#include "task.h"
|
||
#include "main.h"
|
||
#include "os-app.h"
|
||
#include <stdio.h>
|
||
#include "shell.h"
|
||
#include "shellapp.h"
|
||
#include <rtthread.h>
|
||
#include <easyflash.h>
|
||
#include <string.h>
|
||
#include <stdlib.h>
|
||
#include "mqtt-board.h"
|
||
#include "data.h"
|
||
uint32_t os_timer_count = 1;
|
||
|
||
|
||
|
||
#include <rtthread.h>
|
||
rt_event_t gCtrlEvents;
|
||
rt_event_t gUartEvents;
|
||
//rt_event_t gUIEvents;
|
||
rt_event_t gTrigEvents;
|
||
//rt_event_t gCommEvents;
|
||
|
||
rt_mailbox_t gTCommMail;
|
||
rt_mailbox_t gSluiceMail;
|
||
rt_mailbox_t gCtrlMail;
|
||
rt_mailbox_t gViewMail;
|
||
|
||
|
||
ALIGN (RT_ALIGN_SIZE)
|
||
static char thread_stack[2048];
|
||
static struct rt_thread os_app;
|
||
|
||
static rt_timer_t locktimer;
|
||
static void locktimerouter (void* parameter)
|
||
{
|
||
// todo 关闭定时器
|
||
HAL_GPIO_WritePin (LOCK_GPIO_Port, LOCK_Pin, GPIO_PIN_RESET);
|
||
}
|
||
|
||
static void thread_entry (void *parameter)
|
||
{
|
||
// 创建控制事件组
|
||
gCtrlEvents = rt_event_create ("Ctrl_Events", RT_IPC_FLAG_FIFO) ;
|
||
/* 创建串口事件组*/
|
||
gUartEvents = rt_event_create ("gUartEvents", RT_IPC_FLAG_FIFO) ;
|
||
/* 创建串口事件组*/
|
||
//gUIEvents = rt_event_create ("gUIEvents", RT_IPC_FLAG_FIFO) ;
|
||
|
||
/* 创建串口事件组*/
|
||
gTrigEvents = rt_event_create ("gTrigEvents", RT_IPC_FLAG_FIFO) ;
|
||
|
||
// 创建网络传输邮箱
|
||
gTCommMail = rt_mb_create ("gTCommMail", 32, RT_IPC_FLAG_FIFO);
|
||
|
||
// 创建网络传输邮箱
|
||
gSluiceMail = rt_mb_create ("gSluiceMail", 32, RT_IPC_FLAG_FIFO);
|
||
|
||
// 创建控制传输邮箱
|
||
gCtrlMail = rt_mb_create ("gCtrlMail", 32, RT_IPC_FLAG_FIFO);
|
||
// 创建控制传输邮箱
|
||
gViewMail = rt_mb_create ("gViewMail", 32, RT_IPC_FLAG_FIFO);
|
||
|
||
|
||
//gCommEvents = rt_event_create ("gCommEvents", RT_IPC_FLAG_FIFO) ;
|
||
|
||
locktimer = rt_timer_create ("locktimer", locktimerouter, RT_NULL, 1000, RT_TIMER_FLAG_ONE_SHOT); // 异常检测定时器
|
||
SluiceThreadStart(); // 闸门控制线程
|
||
U4851ThreadStart(); // 4851采集线程
|
||
U4852ThreadStart(); // 4852采集线程
|
||
U4853ThreadStart(); // 4853采集线程
|
||
NET_APPThreadStart(); // 网络线程
|
||
DisThreadStart(); // UI 线程
|
||
PROBUS_APPThreadStart();
|
||
|
||
uint32_t id1 = HAL_GetUIDw0();
|
||
uint32_t id2 = HAL_GetUIDw1();
|
||
uint32_t id3 = HAL_GetUIDw2();
|
||
rt_kprintf ("ID:%X %X %X\r\n", id1, id2, id3);
|
||
rt_kprintf ("Version:%s,%s\r\n",__DATE__,__TIME__);
|
||
rt_kprintf ("os-app running !\r\n");
|
||
|
||
while (1)
|
||
{
|
||
rt_thread_mdelay (500);
|
||
if (RT_EOK == rt_event_recv (gCtrlEvents, EVENT_CTRL_SET_UNLOCK, RT_EVENT_FLAG_AND | RT_EVENT_FLAG_CLEAR, 2000, RT_NULL)) // 数据接受失败,上报异常状态
|
||
{
|
||
// todo: 打开继电器,开启定时器
|
||
HAL_GPIO_WritePin (LOCK_GPIO_Port, LOCK_Pin, GPIO_PIN_SET);
|
||
rt_timer_start (locktimer);
|
||
}
|
||
}
|
||
}
|
||
|
||
|
||
/* 线程示例 */
|
||
int ThreadNewOsApp (void)
|
||
{
|
||
/* 创建线程1,名称是thread1,入口是thread1_entry*/
|
||
rt_thread_init (&os_app, "thread1",
|
||
thread_entry, RT_NULL,
|
||
&thread_stack[0],
|
||
sizeof (thread_stack),
|
||
OS_APP_THREAD_PRIORITY, OS_APP_THREAD_TIMESLICE);
|
||
rt_thread_startup (&os_app);
|
||
|
||
return 0;
|
||
}
|
||
|
||
|
||
|
||
void OsShellTask (void * argument)
|
||
{
|
||
|
||
while (1)
|
||
{
|
||
myshell_task();
|
||
//osDelay(1);
|
||
}
|
||
|
||
}
|
||
|
||
|
||
|
||
|