博客
关于我
FreeRTOS源码分析与应用开发03:时间管理
阅读量:253 次
发布时间:2019-03-01

本文共 4726 字,大约阅读时间需要 15 分钟。

FreeRTOS?????SysTick???

1. FreeRTOS????

1.1 ??????

FreeRTOS??????????????

  • static List_t xDelayedTaskList1;
  • static List_t xDelayedTaskList2;
  • static List_t * volatile pxDelayedTaskList;
  • static List_t * volatile pxOverflowDelayedTaskList;
  • static volatile TickType_t xNextTaskUnblockTime

???????????????????????????????????????xTickCount?uint32_t???????????FreeRTOS?????????????????????????????

?xTickCount?????????pxDelayedTaskList?pxOverflowDelayedTaskList????xNextTaskUnblockTime??????????????????????????

1.2 vTaskDelay??

vTaskDelay????????????????????????????????????????????????????????????????????????

1.2.1 ????

void vTaskDelay(const TickType_t xTicksToDelay) {    BaseType_t xAlreadyYielded = pdFALSE;    if (xTicksToDelay > (TickType_t)0U) {        configASSERT(uxSchedulerSuspended == 0);        vTaskSuspendAll();        prvAddCurrentTaskToDelayedList(xTicksToDelay, pdFALSE);        xAlreadyYielded = xTaskResumeAll();    }    if (xAlreadyYielded == pdFALSE) {        portYIELD_WITHIN_API();    }}

1.2.2 ??

  • ???????????????????
  • ???????vTaskDelay????????????????????
  • ??????????????????????
    • ?10ms????
    • ???????10ms

1.3 vTaskDelayUntil??

vTaskDelayUntil??????????????????????????????????????xTimeIncrement??????????????????

1.3.1 ????

void vTaskDelayUntil(TickType_t * const pxPreviousWakeTime, const TickType_t xTimeIncrement) {    TickType_t xTimeToWake;    BaseType_t xAlreadyYielded, xShouldDelay = pdFALSE;    configASSERT(pxPreviousWakeTime);    configASSERT(xTimeIncrement > 0U);    configASSERT(uxSchedulerSuspended == 0);    vTaskSuspendAll();    {        const TickType_t xConstTickCount = xTickCount;        xTimeToWake = *pxPreviousWakeTime + xTimeIncrement;        if (xConstTickCount < *pxPreviousWakeTime) {            if ((xTimeToWake < *pxPreviousWakeTime) && (xTimeToWake > xConstTickCount)) {                xShouldDelay = pdTRUE;            }        } else {            if ((xTimeToWake < *pxPreviousWakeTime) || (xTimeToWake > xConstTickCount)) {                xShouldDelay = pdTRUE;            }        }        *pxPreviousWakeTime = xTimeToWake;        if (xShouldDelay != pdFALSE) {            prvAddCurrentTaskToDelayedList(xTimeToWake - xConstTickCount, pdFALSE);        }    }    xAlreadyYielded = xTaskResumeAll();    if (xAlreadyYielded == pdFALSE) {        portYIELD_WITHIN_API();    }}

1.3.2 ??

  • ?????????????????????????

  • ?????????xTimeIncrement????????????????????????????????????

  • ????????????????????????????????

  • xConstTickCount?xTimeToWake????
  • xConstTickCount????xTimeToWake??
  • xConstTickCount?xTimeToWake???

2. FreeRTOS????

2.1 SysTick???

SysTick??Cortex-M?????????24??????????????FreeRTOS??SysTick??????????????????????

2.1.2 ?????

SysTick?4????????

  • CTRL???????????????
  • LOAD???????????????

2.1.3 ????

vPortSetupTimerInterrupt();

2.1.3 ??

  • ?????SysTick??????configTICK_RATE_HZ?configSYSTICK_CLOCK_HZ?????
  • ??????????????????????????

2.2 SysTick????

2.2.1 xPortSysTickHandler??

SysTick????????????xTaskIncrementTick????????????????????

2.2.2 xTaskIncrementTick??

BaseType_t xTaskIncrementTick(void) {    if (uxSchedulerSuspended == pdFALSE) {        xTickCount++;        if (xTickCount == (TickType_t)0U) {            taskSWITCH_DELAYED_LISTS();        }        if (xTickCount >= xNextTaskUnblockTime) {            while (listLIST_IS_EMPTY(pxDelayedTaskList) == pdFALSE) {                pxTCB = listGET_OWNER_OF_HEAD_ENTRY(pxDelayedTaskList);                xItemValue = listGET_LIST_ITEM_VALUE(pxTCB->xStateListItem);                if (xTickCount < xItemValue) {                    xNextTaskUnblockTime = xItemValue;                    break;                }                uxListRemove(pxTCB->xStateListItem);                if (listLIST_ITEM_CONTAINER(pxTCB->xEventListItem) != NULL) {                    uxListRemove(pxTCB->xEventListItem);                }                prvAddTaskToReadyList(pxTCB);                #if (configUSE_PREEMPTION == 1)                    if (pxTCB->uxPriority >= pxCurrentTCB->uxPriority) {                        xSwitchRequired = pdTRUE;                    }                #endif            }            xNextTaskUnblockTime = portMAX_DELAY;        }        #if (configUSE_PREEMPTION == 1 && configUSE_TIME_SLICING == 1)            if (listCURRENT_LIST_LENGTH(pxReadyTasksLists[pxCurrentTCB->uxPriority]) > 1) {                xSwitchRequired = pdTRUE;            }        #endif    } else {        uxPendedTicks++;    }    #if (configUSE_PREEMPTION == 1)        if (xYieldPending != pdFALSE) {            xSwitchRequired = pdTRUE;        }    #endif    return xSwitchRequired;}

2.2.3 ??

  • ????????xTickCount??????taskSWITCH_DELAYED_LISTS???????
  • ?????????????????????xNextTaskUnblockTime?????????????????????

??????????FreeRTOS??????????????????????????

转载地址:http://kqwx.baihongyu.com/

你可能感兴趣的文章
npm install CERT_HAS_EXPIRED解决方法
查看>>
npm install digital envelope routines::unsupported解决方法
查看>>
npm install 卡着不动的解决方法
查看>>
npm install 报错 EEXIST File exists 的解决方法
查看>>
npm install 报错 ERR_SOCKET_TIMEOUT 的解决方法
查看>>
npm install 报错 Failed to connect to github.com port 443 的解决方法
查看>>
npm install 报错 fatal: unable to connect to github.com 的解决方法
查看>>
npm install 报错 no such file or directory 的解决方法
查看>>
npm install 权限问题
查看>>
npm install报错,证书验证失败unable to get local issuer certificate
查看>>
npm install无法生成node_modules的解决方法
查看>>
npm install的--save和--save-dev使用说明
查看>>
npm node pm2相关问题
查看>>
npm run build 失败Compiler server unexpectedly exited with code: null and signal: SIGBUS
查看>>
npm run build报Cannot find module错误的解决方法
查看>>
npm run build部署到云服务器中的Nginx(图文配置)
查看>>
npm run dev 和npm dev、npm run start和npm start、npm run serve和npm serve等的区别
查看>>
npm run dev 报错PS ‘vite‘ 不是内部或外部命令,也不是可运行的程序或批处理文件。
查看>>
npm scripts 使用指南
查看>>
npm should be run outside of the node repl, in your normal shell
查看>>