91欧美超碰AV自拍|国产成年人性爱视频免费看|亚洲 日韩 欧美一厂二区入|人人看人人爽人人操aV|丝袜美腿视频一区二区在线看|人人操人人爽人人爱|婷婷五月天超碰|97色色欧美亚州A√|另类A√无码精品一级av|欧美特级日韩特级

0
  • 聊天消息
  • 系統(tǒng)消息
  • 評(píng)論與回復(fù)
登錄后你可以
  • 下載海量資料
  • 學(xué)習(xí)在線課程
  • 觀看技術(shù)視頻
  • 寫文章/發(fā)帖/加入社區(qū)
會(huì)員中心
創(chuàng)作中心

完善資料讓更多小伙伴認(rèn)識(shí)你,還能領(lǐng)取20積分哦,立即完善>

3天內(nèi)不再提示

FreeRTOS中Systick的問題

撞上電子 ? 2023-12-15 08:00 ? 次閱讀
加入交流群
微信小助手二維碼

掃碼添加小助手

加入工程師交流群

在Cortex-M內(nèi)核中,系統(tǒng)節(jié)拍由Systick時(shí)鐘提供,當(dāng)配置好系統(tǒng)滴答時(shí)鐘后,每次時(shí)鐘中斷就會(huì)觸發(fā)中斷處理數(shù)xPortSysTickHandler()。

void xPortSysTickHandler( void ){ /* The SysTick runs at the lowest interrupt priority, so when this interrupt * executes all interrupts must be unmasked. There is therefore no need to * save and then restore the interrupt mask value as its value is already * known - therefore the slightly faster vPortRaiseBASEPRI() function is used * in place of portSET_INTERRUPT_MASK_FROM_ISR(). */ vPortRaiseBASEPRI();//屏蔽歸屬FreeRTOS的中斷優(yōu)先級(jí) { /* Increment the RTOS tick. */ if( xTaskIncrementTick() != pdFALSE )//時(shí)鐘計(jì)數(shù)處理 { /* A context switch is required. Context switching is performed in * the PendSV interrupt. Pend the PendSV interrupt. */ portNVIC_INT_CTRL_REG = portNVIC_PENDSVSET_BIT;//如果需要切換上下文操作,PendSV標(biāo)記置位 } }

vPortClearBASEPRIFromISR();}

這部分主要是依靠 xTaskIncrementTick(),來判斷任務(wù)切換是否在此次系統(tǒng)時(shí)鐘中斷時(shí)被需要。如果是,則PendSV標(biāo)記置位,等待觸發(fā)PendSV中斷。來看看 xTaskIncrementTick()。

BaseType_t xTaskIncrementTick( void ){ TCB_t * pxTCB; TickType_t xItemValue; BaseType_t xSwitchRequired = pdFALSE;

/* Called by the portable layer each time a tick interrupt occurs. * Increments the tick then checks to see if the new tick value will cause any * tasks to be unblocked. */ traceTASK_INCREMENT_TICK( xTickCount );

if( uxSchedulerSuspended == ( UBaseType_t ) pdFALSE ) //調(diào)度是否被掛起,默認(rèn)為否 { /* Minor optimisation. The tick count cannot change in this * block. */ const TickType_t xConstTickCount = xTickCount + ( TickType_t ) 1;

/* Increment the RTOS tick, switching the delayed and overflowed * delayed lists if it wraps to 0. */ xTickCount = xConstTickCount;

if( xConstTickCount == ( TickType_t ) 0U ) /*lint !e774 'if' does not always evaluate to false as it is looking for an overflow. 如果xConstTickCount為0,說明溢出了*/ { taskSWITCH_DELAYED_LISTS();/*切換延遲列表*/ } else { mtCOVERAGE_TEST_MARKER(); }

/* See if this tick has made a timeout expire. Tasks are stored in * the queue in the order of their wake time - meaning once one task * has been found whose block time has not expired there is no need to * look any further down the list. */ if( xConstTickCount >= xNextTaskUnblockTime ) { for( ; ; ) { if( listLIST_IS_EMPTY( pxDelayedTaskList ) != pdFALSE ) { /* The delayed list is empty. Set xNextTaskUnblockTime * to the maximum possible value so it is extremely * unlikely that the * if( xTickCount >= xNextTaskUnblockTime ) test will pass * next time through. */ xNextTaskUnblockTime = portMAX_DELAY; /*lint !e961 MISRA exception as the casts are only redundant for some ports. */ break; } else { /* The delayed list is not empty, get the value of the * item at the head of the delayed list. This is the time * at which the task at the head of the delayed list must * be removed from the Blocked state. */ pxTCB = listGET_OWNER_OF_HEAD_ENTRY( pxDelayedTaskList ); /*lint !e9079 void * is used as this macro is used with timers and co-routines too. Alignment is known to be fine as the type of the pointer stored and retrieved is the same. */ xItemValue = listGET_LIST_ITEM_VALUE( &( pxTCB->xStateListItem ) );

關(guān)鍵問題是,這個(gè)函數(shù)使用到了pxDelayedTaskList, 這定義在本文件

PRIVILEGED_DATA static List_t * volatile pxDelayedTaskList;

該變量初始化為0,該變量正常初始化位置在創(chuàng)建 Task 對(duì)象等的函數(shù)中, 也就是說,如果在Tick中斷到來時(shí),如果還沒有任務(wù)被創(chuàng)建,就會(huì)導(dǎo)致不可預(yù)期的結(jié)果,中斷服務(wù)函數(shù)會(huì)使用這個(gè)野指針,執(zhí)行任務(wù)切換。這會(huì)導(dǎo)致觸發(fā)棧溢出鉤子函數(shù),或者是直接Hardfault。有些硬件初始化需要借助delay功能,不得不在初始化之前配置SysTick。而又不希望在硬件初始化階段觸發(fā)這個(gè)Bug。所以在配置SysTick之前,先創(chuàng)建一個(gè)初始化任務(wù),初始化 pxDelayedTaskList 這個(gè)指針,在初始化任務(wù)里配置SysTick,和其他初始化,這樣能夠避免此類問題?;蛘呤窃谂渲肧ysTick的時(shí)候屏蔽中斷,一切準(zhǔn)備就緒后,開啟中斷。執(zhí)行vTaskStartScheduler()默認(rèn)創(chuàng)建一個(gè)空閑任務(wù)。

聲明:本文內(nèi)容及配圖由入駐作者撰寫或者入駐合作網(wǎng)站授權(quán)轉(zhuǎn)載。文章觀點(diǎn)僅代表作者本人,不代表電子發(fā)燒友網(wǎng)立場(chǎng)。文章及其配圖僅供工程師學(xué)習(xí)之用,如有內(nèi)容侵權(quán)或者其他違規(guī)問題,請(qǐng)聯(lián)系本站處理。 舉報(bào)投訴
  • 內(nèi)核
    +關(guān)注

    關(guān)注

    4

    文章

    1468

    瀏覽量

    42881
  • FreeRTOS
    +關(guān)注

    關(guān)注

    14

    文章

    499

    瀏覽量

    66947
  • Systick
    +關(guān)注

    關(guān)注

    0

    文章

    67

    瀏覽量

    13970
收藏 人收藏
加入交流群
微信小助手二維碼

掃碼添加小助手

加入工程師交流群

    評(píng)論

    相關(guān)推薦
    熱點(diǎn)推薦

    FreeRTOS內(nèi)核默認(rèn)會(huì)初始化systick是必須的嗎?

    FreeRTOS內(nèi)核默認(rèn)會(huì)初始化systick;原子哥的視頻教程里的例程也會(huì)使用delay_init初始化systick。請(qǐng)問是否是必須,有無影響?
    發(fā)表于 07-20 08:03

    使用FreeRTOS時(shí)Systick時(shí)鐘的配置分享

    FreeRTOS按照教程移植好之后就可以使用了。需要注意的是從官網(wǎng)下載的針對(duì)keil環(huán)境下STM32F103的FreeRTOS文件,使用systick時(shí)鐘作為rtos的時(shí)鐘,而這個(gè)systic
    發(fā)表于 07-30 11:39

    SysTicK的函數(shù)重復(fù)定義

    ).原因使用KEIL時(shí)在Manage Run-Time Environment勾選的HAL庫(kù),然后添加FreeRTOS操作系統(tǒng)時(shí),工程會(huì)出現(xiàn)問題首先是下圖SysTicK的函數(shù)重復(fù)定義,是因?yàn)樘砑拥?/div>
    發(fā)表于 08-04 07:55

    使用CubeMX 6為freeRTOS生成代碼的問題如何解決?

    我認(rèn)為在使用 freeRTOS 生成代碼時(shí),新的 CubeMX 6.0 存在錯(cuò)誤。可能只是從舊的 CubeMX 項(xiàng)目遷移到新的項(xiàng)目時(shí),我不確定。我將使用 CubeMX 5.3 構(gòu)建的項(xiàng)目更新為
    發(fā)表于 01-31 08:56

    系統(tǒng)節(jié)拍定時(shí)(SysTick)

    SysTick 是一個(gè)簡(jiǎn)單的系統(tǒng)時(shí)鐘節(jié)拍計(jì)數(shù)器,它屬于 ARM Cortex-M3 內(nèi)核嵌套向量中斷 控制器 NVIC 里的一個(gè)功能單元,而非片內(nèi)外設(shè)。SysTick 常用于操作系統(tǒng)(如:μC/OS-II、 FreeRTOS
    發(fā)表于 01-13 16:34 ?8次下載

    如何使用STM32實(shí)現(xiàn)systick的精確延時(shí)

    SYSTICK寄存器初始化 void SysTick_Configuration(void) { if (SysTick_Config(SystemCoreClock / 100
    發(fā)表于 11-21 15:54 ?6286次閱讀

    STM32SysTick時(shí)鐘源來自哪里?

    STM32的SysTick時(shí)鐘源來自哪里?
    的頭像 發(fā)表于 03-03 14:32 ?8902次閱讀

    如何使用STM32單片機(jī)systick來實(shí)現(xiàn)延時(shí)定時(shí)功能

    SysTick 控制及狀態(tài)寄存器的使能位清除,就永不停息。這樣可以用systick來實(shí)現(xiàn)延時(shí)定時(shí)功能,不用再占用系統(tǒng)定時(shí)器。systick也多用做系統(tǒng)的時(shí)鐘節(jié)拍,如
    的頭像 發(fā)表于 02-14 06:25 ?7900次閱讀
    如何使用STM32單片機(jī)<b class='flag-5'>systick</b>來實(shí)現(xiàn)延時(shí)定時(shí)功能

    STM32—關(guān)于SYSTICK系統(tǒng)時(shí)鐘的詳解及學(xué)習(xí)筆記

    /*配置SYSTICK很簡(jiǎn)單,只需在SySTick_Config寫入一個(gè)不大于2^24次方的數(shù),就可以產(chǎn)生systick中斷1.無需對(duì)NVIC進(jìn)行配置,在
    發(fā)表于 11-30 15:51 ?15次下載
    STM32—關(guān)于<b class='flag-5'>SYSTICK</b>系統(tǒng)時(shí)鐘的詳解及學(xué)習(xí)筆記

    STM32_SysTick—系統(tǒng)定時(shí)器

    SysTick 的簡(jiǎn)介和寄存器的詳細(xì)描述。因?yàn)?SysTick 是屬于CM3 內(nèi)核的外設(shè),有關(guān)寄存器的定義和部分庫(kù)函數(shù)都在 core_CM3.h 這個(gè)頭文件實(shí)現(xiàn)。所以學(xué)習(xí) SysTick
    發(fā)表于 12-23 19:56 ?2次下載
    STM32_<b class='flag-5'>SysTick</b>—系統(tǒng)定時(shí)器

    systick定時(shí)器 延時(shí)計(jì)時(shí)

    是cortex M內(nèi)核的單片機(jī),都擁有這個(gè)24位的systick定時(shí)器。systick定時(shí)器是一個(gè)24位遞減計(jì)時(shí)器,用戶至于要掌握CMSIS包SysTick_Config 函數(shù)進(jìn)行
    發(fā)表于 01-18 10:28 ?7次下載
    <b class='flag-5'>systick</b>定時(shí)器 延時(shí)計(jì)時(shí)

    STM32單片機(jī)systick使用注意事項(xiàng)

    寄存器自動(dòng)重裝載定時(shí)初值。只要不把它在SysTick 控制及狀態(tài)寄存器的使能位清除,就永不停息。這樣可以用systick來實(shí)現(xiàn)延時(shí)定時(shí)功能,不用再占用系統(tǒng)定時(shí)器。
    發(fā)表于 01-18 10:35 ?1次下載
    STM32單片機(jī)<b class='flag-5'>systick</b>使用注意事項(xiàng)

    什么是FreeRTOS的延時(shí)

    FreeRTOS的時(shí)鐘節(jié)拍通常由**SysTick**提供,它周期性的產(chǎn)生定時(shí)中斷,所謂的時(shí)鐘節(jié)拍管理的核心就是這個(gè)定時(shí)中斷的服務(wù)程序。**FreeRTOS**的時(shí)鐘節(jié)拍isr核心的
    的頭像 發(fā)表于 02-14 09:45 ?4929次閱讀
    什么是<b class='flag-5'>FreeRTOS</b>的延時(shí)

    SysTick時(shí)鐘

    Cortex-M3內(nèi)核的處理器,內(nèi)部包含了一個(gè)SysTick定時(shí)器,SysTick是一個(gè)24位的倒計(jì)數(shù)定時(shí)器,當(dāng)計(jì)數(shù)到0時(shí),將從ReLoad寄存器自動(dòng)重裝載定時(shí)初值,開始新一輪計(jì)數(shù)。只要不把它在
    的頭像 發(fā)表于 03-01 17:40 ?1641次閱讀
    <b class='flag-5'>SysTick</b>時(shí)鐘

    systick_handler無法進(jìn)入怎么解決

    在嵌入式系統(tǒng),SysTick是一個(gè)用于定時(shí)器和延時(shí)的模塊,通常用于處理實(shí)時(shí)任務(wù)、中斷和延時(shí)等。然而,在某些情況下,SysTick中斷處理函數(shù)(systick_handler)可能無法
    的頭像 發(fā)表于 12-01 15:36 ?8485次閱讀