Browse Source

finish base of Task structure

master
sunlight 11 months ago
parent
commit
87e2fdc91a
  1. 4
      .settings/language.settings.xml
  2. 5
      .vscode/settings.json
  3. 35
      Usr/service/app_core.c
  4. 1
      Usr/service/app_core.h
  5. 102
      Usr/service/front_end_controler.c
  6. 25
      Usr/service/front_end_controler.h
  7. 1
      Usr/service/page/Page_main.h
  8. 25
      Usr/service/page/page_processer.c
  9. 8
      Usr/service/page/page_processer.h
  10. 87
      stm32basic/text.txt
  11. 55
      stm32basic/ztask.c
  12. 37
      stm32basic/ztask.h

4
.settings/language.settings.xml

@ -5,7 +5,7 @@
<provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/>
<provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
<provider-reference id="org.eclipse.cdt.managedbuilder.core.MBSLanguageSettingsProvider" ref="shared-provider"/>
<provider class="com.st.stm32cube.ide.mcu.toolchain.armnone.setup.CrossBuiltinSpecsDetector" console="false" env-hash="-705024325747401703" id="com.st.stm32cube.ide.mcu.toolchain.armnone.setup.CrossBuiltinSpecsDetector" keep-relative-paths="false" name="MCU ARM GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
<provider class="com.st.stm32cube.ide.mcu.toolchain.armnone.setup.CrossBuiltinSpecsDetector" console="false" env-hash="1236626136732093992" id="com.st.stm32cube.ide.mcu.toolchain.armnone.setup.CrossBuiltinSpecsDetector" keep-relative-paths="false" name="MCU ARM GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
<language-scope id="org.eclipse.cdt.core.gcc"/>
<language-scope id="org.eclipse.cdt.core.g++"/>
</provider>
@ -16,7 +16,7 @@
<provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/>
<provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
<provider-reference id="org.eclipse.cdt.managedbuilder.core.MBSLanguageSettingsProvider" ref="shared-provider"/>
<provider class="com.st.stm32cube.ide.mcu.toolchain.armnone.setup.CrossBuiltinSpecsDetector" console="false" env-hash="-644080842071547233" id="com.st.stm32cube.ide.mcu.toolchain.armnone.setup.CrossBuiltinSpecsDetector" keep-relative-paths="false" name="MCU ARM GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
<provider class="com.st.stm32cube.ide.mcu.toolchain.armnone.setup.CrossBuiltinSpecsDetector" console="false" env-hash="1297569620407948462" id="com.st.stm32cube.ide.mcu.toolchain.armnone.setup.CrossBuiltinSpecsDetector" keep-relative-paths="false" name="MCU ARM GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
<language-scope id="org.eclipse.cdt.core.gcc"/>
<language-scope id="org.eclipse.cdt.core.g++"/>
</provider>

5
.vscode/settings.json

@ -17,6 +17,9 @@
"page_main.h": "c",
"page_processer.h": "c",
"page_settingtime.h": "c",
"standbymode.h": "c"
"standbymode.h": "c",
"ztask.h": "c",
"stdbool.h": "c",
"stdint.h": "c"
}
}

35
Usr/service/app_core.c

@ -4,31 +4,36 @@
#define TAG "main"
void umain(void){
App_initialize();
Page_initialize(Page_main);//
Page_initialize(Page_SetingTime);
while (1)
{
appsetup();
}
}
void App_initialize(void){
DBUG_USART1_UART_Init(460800);
ZLOGI(TAG,"======================= boardinfo ==================== ");
//zlog("DBUG_UART");
App_HardWare_initialize();//
Front_initialize();//
task_init();
// Front_initialize();//
}
void umain(void){
App_initialize();
task_init();
while (1)
{
appsetup();
HAL_Delay(500);
}
}
void appsetup(void)
{
Front_initialize();
// Page_initialize(Page_main);
// Page_initialize(Page_SetingTime);
Front_startSchedule();
Front_startSchedule();
}

1
Usr/service/app_core.h

@ -7,5 +7,4 @@
void umain(void);
void App_initialize(void);
void appsetup(void);

102
Usr/service/front_end_controler.c

@ -3,15 +3,19 @@
#define TAG "FronEndControler"
uint8_t IsBelongPage;
Task_t usartRxtask;
Task_t eventProcesstask;
FunctionCB m_cb[50];
int32_t m_ncb = 0;
static bool processerstate;
static tjc_packet_t* eventpacket;
static UART_HandleTypeDef* tjcUart;//
void Front_initialize(void)
{
//
void task_init(){
static uint8_t rxbuf[128];
tjcUart = &huart4;
@ -25,11 +29,42 @@ void Front_initialize(void)
}
#define UART_RX_OVERTIME 5//接收最大时间
void uartRxTask(void)
{
/*
* @brief:
*
*/
void processRxpacket(uint8_t* data, size_t len ){
if(!(data[len - 1] == 0xFF && data[len - 2] && data[len - 3])){//
ZLOGI(TAG,"RX invalid packet");
processerstate = error;
}
else{
uint8_t packetType = data[0];
static tjc_packet_t packet;
packet.datalen = len;
memset(packet.data, 0, sizeof(packet.data));
memcpy(packet.data, data, len);
ZLOGI(TAG, "packet information: %s\n", packet.data);
eventpacket = &packet;
processerstate = sucess;
}
}
/*
* @brief:
*
*/
void uartRxTask(void){
static uint8_t processbuf[128];
int32_t rxsize = 0;
//ZLOGI("main","test3\n");
@ -38,7 +73,6 @@ void uartRxTask(void)
HAL_Delay(1);//1
if (tjcUart->USR_UartITRxOff != 0 && haspassedms(tjcUart->USR_UartITLastRxTicket) > UART_RX_OVERTIME)
{
// memset(processbuf, 0, 128);
memcpy(processbuf, tjcUart->USR_UartITRxBuf, tjcUart->USR_UartITRxOff );
rxsize = tjcUart->USR_UartITRxOff;
tjcUart->USR_UartITRxOff = 0;
@ -48,18 +82,21 @@ void uartRxTask(void)
if(rxsize != 0)
{
processRxpacket(processbuf, rxsize);
// ZLOGI("main","%s\n",processbuf);
// ZLOGI("main","test1\n");
}
}
/*
* @brief:
*
*/
tjc_event_t event_cache;
tjc_event_t input_file_event_cache;
bool input_file_event_cache_state;
void eventProcessTask(void)
{
void eventProcessTask(void){
static tjc_packet_t packet;
packet = *(eventpacket);
@ -72,61 +109,52 @@ void eventProcessTask(void)
event_cache.pid = packet.data[1];
event_cache.bid = packet.data[2];
event_cache.date.button_event.val = packet.data[3];
///callUsrEventCb(&event);
callUsrEventCb(&event_cache);
}else if (packetType == tjc_inputfield_content_change_event1){
event_cache.event_id = packet.data[0];
event_cache.pid = packet.data[1];
event_cache.bid = packet.data[2];
// const char* strbegin = (const char*)&packet.data[3];
// strbegin = zcpystr(event_cache.date.inputfiled_content.text, strbegin, sizeof(event_cache.d.inputfield_content.text));
// callUsrEventCb(&event_cache);
callUsrEventCb(&event_cache);
input_file_event_cache = event_cache;//
input_file_event_cache_state = true;
}else if (tjc_sys_event_page_id == packetType){
event_cache.event_id = packet.data[0];
event_cache.pid = packet.data[1];
event_cache.bid = packet.data[2];
callUsrEventCb(&event_cache);
}
}
}
void Front_initialize(void){
Task_init(&usartRxtask);
//Task_init(&eventProcesstask);
}
void Front_startSchedule(void)
{
uartRxTask();
eventProcessTask();
//uart_start注册数据处理
Task_start(uartRxTask,&usartRxtask);
//Task_start(eventProcessTask,&usartRxtask);
}
void processRxpacket(uint8_t* data, size_t len )
{
if(!(data[len - 1] == 0xFF && data[len - 2] && data[len - 3])){//
ZLOGI(TAG,"RX invalid packet");
processerstate = error;
}
else{
uint8_t packetType = data[0];
static tjc_packet_t packet;
packet.datalen = len;
memcpy(packet.data, data, len);
ZLOGI(TAG, "packet information: %s\n", packet.data);
eventpacket = &packet;
processerstate = sucess;
//memcpy(eventpacket.data, packet.data, len);
}
}
void regOnUsrEventCb(FunctionCB cb, uint8_t page){
void regOnUsrEventCb(FunctionCB cb){
m_cb[m_ncb] = cb;
m_ncb++;
IsBelongPage = page;
}
void callUsrEventCb(tjc_event_t* event){
for (int32_t i = 0; i < m_ncb; i++) {
m_cb[i](event);
}
}

25
Usr/service/front_end_controler.h

@ -6,6 +6,7 @@
#include "zlog.h"
#include "tjc_processer.h"
#include "page_processer.h"
#include "ztask.h"
@ -19,19 +20,25 @@ typedef enum{
sucess,
} process_state;
typedef void (*FunctionCB)(tjc_event_t* ,uint8_t);
typedef void (*FunctionCB)(tjc_event_t*);
// typedef struct{
// // Function callUsrEventCb
// } FrontEndControler_t;
extern uint8_t IsBelongPage;
void Front_startSchedule(void);
void Front_initialize(void);
void processRxpacket(uint8_t* data, size_t len );
void regOnUsrEventCb(FunctionCB cb,page_t page);
void regOnUsrEventCb(FunctionCB cb);
void callUsrEventCb(tjc_event_t* event);
void eventProcessTask_init(void);
void eventProcessTask_start(taskfuction cb);
void eventProcessTask(void);
void task_init();

1
Usr/service/page/Page_main.h

@ -1,6 +1,7 @@
#pragma once
#include "stm32f4xx_hal.h"
void OnPageLoad_main();
void OnPageButton_main(uint8_t bid, uint8_t val);

25
Usr/service/page/page_processer.c

@ -9,27 +9,30 @@ PageProcesser init[] = {
};
uint8_t JudgePage(uint8_t page){
switch(page){
case pg_main: return 1;break;
case pg_SettingTime: return 1;break;
default: return 0;break;
}
}
void page_processer(tjc_event_t* event){
uint8_t page = event->pid;
if(page == IsBelongPage)
Page_Mrg = true;
else
Page_Mrg = false;
uint8_t page;
if(!JudgePage(event->pid))
return ;
if(Page_Mrg)
{
page = event->pid;
if(event->event_id == tjc_sys_event_page_id){
init[page].OnPageLoad();
}else if(event->event_id == tjc_button_event){
init[page].OnPageButton(event->bid, event->date.button_event.val);
}
}
}
void Page_initialize(uint8_t page)
{
regOnUsrEventCb(page_processer,page);
regOnUsrEventCb(page_processer);
}
@ -38,3 +41,5 @@ void Page_initialize(uint8_t page)

8
Usr/service/page/page_processer.h

@ -7,10 +7,10 @@
// extern PageProcesser Page_initialize;
typedef enum{
Page_main,
Page_SetingTime,
} page_t;
// typedef enum{
// Page_main,
// Page_SetingTime,
// } page_t;
typedef struct {
void (*OnPageLoad)();

87
stm32basic/text.txt

@ -0,0 +1,87 @@
// void eventProcessTask_init(void){
// if(eventProcesstask.TaskNotify){
// eventProcesstask.TaskNotify--;
// if(eventProcesstask.m_tasktransition){
// eventProcesstask.m_status = working;
// ZLOGI(TAG, "eventRXtask_init");
// if(eventProcesstask.m_taskfunc) eventProcesstask.m_taskfunc();
// eventProcesstask.m_status = end;
// }
// else{
// eventProcesstask.m_status = idle;
// }
// }
// }
// void eventProcessTask_start(taskfuction cb){
// if(eventProcesstask.m_status != idle){
// eventProcesstask.m_tasktransition = false;//状态: 非空闲,状态转换关
// eventProcesstask.TaskNotify++; //通知任务
// }
// else{
// eventProcesstask.m_taskfunc = cb;
// eventProcesstask.m_tasktransition = true;//状态: 空闲,状态转换开
// eventProcesstask.TaskNotify++; //通知任务
// }
// ZLOGI(TAG, "eventTaskNotify: %d", eventProcesstask.TaskNotify);
// }
// void eventProcesstask_start(FunctionCB cb){
// eventProcessfunc = cb;
// }
// /*
// * @brief 回调函数注册
// *
// *
// *
// *判断任务状态
// *任务空闲:状态转换开
// * 状态转换开:1.回调函数登记注册
// * 2.任务通知
// *
// *任务非空闲:状态转换关
// * 状态转换关:1.不注册
// * 2.任务通知等待任务状态空闲
// */
// void uartRxTask_start(taskfuction cb){
// if(usartRxtask.m_status != idle){
// usartRxtask.m_tasktransition = false;//状态: 非空闲,状态转换关
// usartRxtask.TaskNotify++; //通知任务
// }
// else{
// usartRxtask.m_taskfunc = cb;
// usartRxtask.m_tasktransition = true;//状态: 空闲,状态转换开
// usartRxtask.TaskNotify++; //通知任务
// }
// ZLOGI(TAG, "uartTaskNotify: %d", usartRxtask.TaskNotify);
// }
// /*
// * @brief: uart回调任务状态转换,由任务时间表进行任务通知
// *
// */
// void uartRxTask_init(void){
// if(usartRxtask.TaskNotify){
// usartRxtask.TaskNotify--;
// if(usartRxtask.m_tasktransition){
// usartRxtask.m_status = working;
// ZLOGI(TAG, "uartRXtask_init");
// if(usartRxtask.m_taskfunc) usartRxtask.m_taskfunc();
// usartRxtask.m_status = end;
// }
// else{
// usartRxtask.m_status = idle;
// }
// }
// }
先写出uart的一系列函数,在将其上升为任务函数

55
stm32basic/ztask.c

@ -0,0 +1,55 @@
#include "ztask.h"
#define TAG "ztask"
/*
* @brief: uart回调任务状态转换
*
*/
void Task_init(Task_t* task){
if(task->TaskNotify){
task->TaskNotify--;
if(task->m_tasktransition){
task->m_status = working;
ZLOGI(TAG, "task_init");
if(task->m_taskfunc) task->m_taskfunc();
task->m_status = end;
}
else{
task->m_status = idle;
}
}
}
/*
* @brief
*
*
*
*
*:
* 1.
* 2.
*
*
* 1.
* 2.
*/
void Task_start(taskfuction cb, Task_t* task){
if(task->m_status != idle){
task->m_tasktransition = false;//:
task->TaskNotify++; //
}
else{
task->m_taskfunc = cb;
task->m_tasktransition = true;//:
task->TaskNotify++; //
}
ZLOGI(TAG, "TaskNotify: %d", task->TaskNotify);
}

37
stm32basic/ztask.h

@ -0,0 +1,37 @@
#pragma once
#include <stdbool.h>
#include <stdint.h>
#include "zlog.h"
//extern taskfuction m_taskfunc;
typedef void (*taskfuction)();
//typedef void (*taskfuction)(taskfuction);
//
typedef enum{
idle,
working,
end,
} status_t;
typedef struct{
uint32_t TaskNotify;//
status_t m_status;
bool m_tasktransition;
void (*m_taskfunc)();
void (*init)(taskfuction);
void (*start)(taskfuction);
}Task_t;//
void Task_init(Task_t* task);
void Task_start(taskfuction cb, Task_t* task);
Loading…
Cancel
Save