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

你可能感兴趣的文章
OpenStack版本升级与故障排查实战
查看>>
Openstack的HA解决方案【替换原有的dashboard】
查看>>
OpenStack的基本概念与架构详解
查看>>
Openstack的视频学习
查看>>
OpenStack自动化安装部署实战(附OpenStack实验环境)
查看>>
openstack虚拟机迁移live-migration中libvirt配置
查看>>
OpenStack项目管理实战
查看>>
OpenStreetMap初探(一)——了解OpenStreetMap
查看>>
openSUSE 13.1 Milestone 2 发布
查看>>
openSUSE推出独立 GUI 包管理工具:YQPkg,简化了整个软件包管理流程
查看>>
OpenVP共用账号 一个账号多台电脑登录
查看>>
OpenVSwtich(OVS)Vlan间路由实战 附实验环境
查看>>
Openwrt LuCI模块练习详细步骤
查看>>
openwrt_git_pull命令提示merger冲突时如何解决?
查看>>
OpenWrt包管理软件opkg的使用(极路由)
查看>>
OpenWrt固件编译刷机完全总结
查看>>
Open××× for Linux搭建之二
查看>>
Open×××有线网络时使用正常,无线网络时使用报错的解决方案
查看>>
Opera Mobile Classic Emulator
查看>>
Operation not supported on read-only collection 的解决方法 - [Windows Phone开发技巧系列1]
查看>>