FUNC(uint16, NVM_CODE) NvM_QueuePop(void) { uint16 nextBlockId = NVM_INIT_0; SchM_Enter_NVM_EXCLUSIVE_AREA(); /* Check if there is a single block request. / if( Nvm_QueueHeader.Counter > NVM_INIT_0 ) { / Find the block id at the head of the queue. / nextBlockId = Nvm_QueueHeader.FirstBlockId; / Point to the next block in the queue. / Nvm_QueueHeader.FirstBlockId = NvM_gstaBlockVar[nextBlockId].NxtBlockId; / Check if the pushed block is the end of the queue. / if( NVM_QUEUE_CURRENTBLOCKID == NvM_gstaBlockVar[nextBlockId].NxtBlockId ) { Nvm_QueueHeader.LastBlockId = NvM_gstaBlockVar[nextBlockId].NxtBlockId; } else { / Clear the link relationship of the block. / NvM_gstaBlockVar[nextBlockId].NxtBlockId = NVM_QUEUE_CURRENTBLOCKID; } / Queue length minus one. / Nvm_QueueHeader.Counter--; / Check if the pushed block is immediate write type. / if( (NVM_WRITE_BLOCK == NvM_gstaBlockVar[nextBlockId].CtrlType) && (NVM_BLOCK_HIGHEST_PRI ==NvM_gstaBlockVar[nextBlockId].Priority) ) { if( Nvm_QueueHeader.CounterImmediate > NVM_INIT_0 ) { / Immediate queue length minus one. */ Nvm_QueueHeader.CounterImmediate--; } } } SchM_Exit_NVM_EXCLUSIVE_AREA(); return nextBlockId; }逐句解释代码
时间: 2024-02-01 18:02:09 浏览: 119
test-func-name-inference.rar_Code Name
这段代码是一个函数的实现,函数名为 `NvM_QueuePop`,返回一个 `uint16` 类型的值。下面逐句解释代码:
```
FUNC(uint16, NVM_CODE) NvM_QueuePop(void)
```
这是函数定义,返回一个 `uint16` 类型的值,函数名为 `NvM_QueuePop`,不接受任何参数,存储在 `NVM_CODE` 类型的内存区域中。
```
uint16 nextBlockId = NVM_INIT_0;
```
定义一个 `uint16` 类型的变量 `nextBlockId` 并将其初始化为 `NVM_INIT_0`。
```
SchM_Enter_NVM_EXCLUSIVE_AREA();
```
进入一个名为 `NVM_EXCLUSIVE_AREA` 的互斥区域,该互斥区域用于保护共享资源,避免多个任务同时访问导致竞争条件。
```
if( Nvm_QueueHeader.Counter > NVM_INIT_0 )
```
如果队列中有请求,则执行下面的代码块。
```
nextBlockId = Nvm_QueueHeader.FirstBlockId;
```
将队列头部的块 ID 赋值给 `nextBlockId`。
```
Nvm_QueueHeader.FirstBlockId = NvM_gstaBlockVar[nextBlockId].NxtBlockId;
```
将队列头部的块的下一个块 ID 赋值给队列头部的块 ID,即将队列头部的块移出队列。
```
if( NVM_QUEUE_CURRENTBLOCKID == NvM_gstaBlockVar[nextBlockId].NxtBlockId )
{
Nvm_QueueHeader.LastBlockId = NvM_gstaBlockVar[nextBlockId].NxtBlockId;
}
else
{
NvM_gstaBlockVar[nextBlockId].NxtBlockId = NVM_QUEUE_CURRENTBLOCKID;
}
```
如果队列头部的块是队列的最后一个块,则将队列的最后一个块 ID 赋值为队列头部的块的下一个块 ID;否则,将队列头部的块的下一个块 ID 赋值为队列当前块 ID。
```
Nvm_QueueHeader.Counter--;
```
队列长度减一。
```
if( (NVM_WRITE_BLOCK == NvM_gstaBlockVar[nextBlockId].CtrlType) && (NVM_BLOCK_HIGHEST_PRI ==NvM_gstaBlockVar[nextBlockId].Priority) )
{
if( Nvm_QueueHeader.CounterImmediate > NVM_INIT_0 )
{
Nvm_QueueHeader.CounterImmediate--;
}
}
```
如果被移除的块是一个立即写入类型的块,并且其优先级最高,则将立即写入块的计数器减一。
```
SchM_Exit_NVM_EXCLUSIVE_AREA();
```
退出互斥区域。
阅读全文