欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

FreeRTOS實(shí)時(shí)操作系統(tǒng)臨界段保護(hù)場(chǎng)合示例

 更新時(shí)間:2022年04月06日 10:51:17   作者:jiang_2018  
這篇文章主要為大家介紹了FreeRTOS實(shí)時(shí)操作系統(tǒng)臨界段保護(hù)場(chǎng)合示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步早日升職加薪

臨界段保護(hù)場(chǎng)合

FreeRTOS中臨界段保護(hù)有2種場(chǎng)合,中斷和非中斷,通過(guò)關(guān)中斷(或者關(guān)部分中斷)來(lái)實(shí)現(xiàn)臨界保護(hù)。

非中斷場(chǎng)合

task.h 中

#define taskENTER_CRITICAL()portENTER_CRITICAL()
#define taskEXIT_CRITICAL()portEXIT_CRITICAL()

portmacro.h中

#define portENTER_CRITICAL()vPortEnterCritical()
#define portEXIT_CRITICAL()vPortExitCritical()

port.c中

//這個(gè)值用來(lái)記錄中斷嵌套次數(shù),在調(diào)度器啟動(dòng)時(shí)會(huì)被重新初始化為0//vTaskStartScheduler()->xPortStartScheduler()->uxCriticalNesting = 0。static UBaseType_t uxCriticalNesting = 0xaaaaaaaa;void vPortEnterCritical( void ){portDISABLE_INTERRUPTS();//關(guān)中斷uxCriticalNesting++;__dsb( portSY_FULL_READ_WRITE );__isb( portSY_FULL_READ_WRITE );if( uxCriticalNesting == 1 ){configASSERT( ( portNVIC_INT_CTRL_REG & portVECTACTIVE_MASK ) == 0 );}}void vPortExitCritical( void ){configASSERT( uxCriticalNesting );uxCriticalNesting--;if( uxCriticalNesting == 0 ) //沒(méi)有嵌套的話就可以開(kāi)中斷了{(lán)portENABLE_INTERRUPTS();}}//這個(gè)值用來(lái)記錄中斷嵌套次數(shù),在調(diào)度器啟動(dòng)時(shí)會(huì)被重新初始化為0
//vTaskStartScheduler()->xPortStartScheduler()->uxCriticalNesting = 0。
static UBaseType_t uxCriticalNesting = 0xaaaaaaaa;
void vPortEnterCritical( void )
{
	portDISABLE_INTERRUPTS();//關(guān)中斷
	uxCriticalNesting++;
	__dsb( portSY_FULL_READ_WRITE );
	__isb( portSY_FULL_READ_WRITE );
	if( uxCriticalNesting == 1 )
	{
		configASSERT( ( portNVIC_INT_CTRL_REG & portVECTACTIVE_MASK ) == 0 );
	}
}
void vPortExitCritical( void )
{
	configASSERT( uxCriticalNesting );
	uxCriticalNesting--;
	if( uxCriticalNesting == 0 ) //沒(méi)有嵌套的話就可以開(kāi)中斷了
	{
		portENABLE_INTERRUPTS();
	}
}

portmacro.h中

#define portDISABLE_INTERRUPTS()ulPortSetInterruptMask()
#define portENABLE_INTERRUPTS()vPortClearInterruptMask( 0 )

port.c中

__asm uint32_t ulPortSetInterruptMask( void )
{
	PRESERVE8
	mrs r0, basepri  //r0作為函數(shù)返回值
	mov r1, #configMAX_SYSCALL_INTERRUPT_PRIORITY
	msr basepri, r1
	bx r14
}
/*-----------------------------------------------------------*/
__asm void vPortClearInterruptMask( uint32_t ulNewMask )
{
	PRESERVE8
	msr basepri, r0
	bx r14
}

中斷場(chǎng)合

task.h

#define taskENTER_CRITICAL_FROM_ISR() portSET_INTERRUPT_MASK_FROM_ISR()
#define taskEXIT_CRITICAL_FROM_ISR( x ) portCLEAR_INTERRUPT_MASK_FROM_ISR( x )

portmacro.h中
下面這2個(gè)函數(shù)在前面的port.c中已經(jīng)實(shí)現(xiàn),只是這里形參是x而不是0

#define portSET_INTERRUPT_MASK_FROM_ISR()ulPortSetInterruptMask()
#define portCLEAR_INTERRUPT_MASK_FROM_ISR(x)vPortClearInterruptMask(x)

使用例子

在這里插入圖片描述

在這里插入圖片描述

以上就是FreeRTOS實(shí)時(shí)操作系統(tǒng)臨界段保護(hù)場(chǎng)合示例的詳細(xì)內(nèi)容,更多關(guān)于FreeRTOS實(shí)時(shí)操作系統(tǒng)臨界段保護(hù)的資料請(qǐng)關(guān)注腳本之家其它相關(guān)文章!

相關(guān)文章

最新評(píng)論