博客
关于我
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/

你可能感兴趣的文章
OAuth2授权码模式详细流程(一)——站在OAuth2设计者的角度来理解code
查看>>
oauth2登录认证之SpringSecurity源码分析
查看>>
OAuth2:项目演示-模拟微信授权登录京东
查看>>
OA系统多少钱?OA办公系统中的价格选型
查看>>
OA系统选型:选择好的工作流引擎
查看>>
OA让企业业务流程管理科学有“据”
查看>>
OA项目之会议通知(查询&是否参会&反馈详情)
查看>>
Vue.js 学习总结(13)—— Vue3 version 计数介绍
查看>>
OA项目之我的会议(会议排座&送审)
查看>>
OA项目之我的会议(查询)
查看>>
OA项目之我的审批(会议查询&会议签字)
查看>>
OA项目之项目简介&会议发布
查看>>
ObjC的复制操作
查看>>
Object c将一个double值转换为时间格式
查看>>
object detection之Win10配置
查看>>
object detection训练自己数据
查看>>
object detection错误Message type "object_detection.protos.SsdFeatureExtractor" has no field named "bat
查看>>
object detection错误之Could not create cudnn handle: CUDNN_STATUS_INTERNAL_ERROR
查看>>
object detection错误之no module named nets
查看>>
Object of type 'ndarray' is not JSON serializable
查看>>