|

楼主 |
发表于 2021-12-20 10:37:45
|
显示全部楼层
freeRtos.c中的任务配置如下
osThreadId_t Rs485SysHandle;
const osThreadAttr_t Rs485Sys_attributes = {
.name = "Rs485Sys",
.stack_size = 128 * 4,
.priority = (osPriority_t) (osPriorityAboveNormal-10),
};
osThreadId_t mbSysMasterHandle
const osThreadAttr_t mbSysMaster_attributes = {
.name = "mbSysMaster",
.stack_size = 128 * 4,
.priority = (osPriority_t) osPriorityAboveNormal,
};
osSemaphoreId_t MasterSem = NULL;
Rs485SysHandle = osThreadNew(Rs485SysTask, NULL,&Rs485Sys_attributes);
mbSysMasterHandle == osThreadNew(MBSysMasterTask, NULL, &mbSysMaster_attributes);
MasterSem =xSemaphoreCreateBinary();
应用代码如下
void Rs485SysTask(void *argument)
{
BaseType_t xResult;
while(1)
{
xResult = xSemaphoreTake(MasterSem,10);
if(xResult == pdPASS)
{
SysPoll(); //Modbus数据打包
}
osDelay(100);
}
void MBSysMasterTask(void *argument)
{
eMBMasterInit(MB_RTU, SYS_UART, 9600, MB_PAR_NONE);
eMBMasterEnable();
while(1)
{
xSemaphoreGive(MasterSem);
eMBMasterPoll();
osDelay(1);
}
}
|
|