代码拉取完成,页面将自动刷新
同步操作将从 bagy/LiteQueue 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
#include "Lite_Queue.h"
#define QUEUE_ITEM_NUM 3
#define QUEUE_ITEM_SIZE 10
/*
* @ brief : Print the contents of each list item in the queue.
* @ param : {LiteQueue *} queue: Message queue handle pointer.
* @ return: None.
* @ author: bagy.
* @ note : None.
*/
static void PrintLiteQueue(LiteQueue *queue)
{
if(queue == NULL)
return;
for(int i = 0; i < queue->item_num; i++)
{
log_i("[item_num:%d] ", i);
for(int n = 0; n < queue->item_size; n++)
{
log_i("%d ", *((uint8_t *)queue + sizeof(LiteQueue) + i * queue->item_size + n));
}
log_i("\n");
}
}
/*
* @ brief : Print the data in buff.
* @ param : {const char *} mode : Print mode.
{LiteQueue *} queue: Message queue handle pointer.
* @ return: None.
* @ author: bagy.
* @ note : Used to observe buff data changes and test to verify the correctness of written or read data.
*/
static void PrintBuff(const char *mode, uint8_t *buff, size_t len)
{
if((buff == NULL) || (len < 1))
return;
if(strstr(mode, "write"))
log_i("Write buff>>>:");
else
log_i("Read buff <<<:");
for(size_t i = 0; i < len; i++)
{
log_i("%d ", buff[i]);
}
log_i("\n\n");
}
/*
* @ brief : Queue callback function.
* @ param : {LiteQueue_Status} sta: Queue status.
* @ return: None.
* @ author: bagy.
* @ note : When the queue writes or reads abnormally, the upper application will be notified through the callback function.
*/
#if(QUEUE_ERROR_CALLBACK == QUEUE_ENABLE)
void LiteQueue_Callback(LiteQueue_Status sta)
{
switch(sta)
{
case LITE_QUEUE_FULL : /*...*/ break;
case LITE_QUEUE_WRITE_BUSY: /*...*/ break;
case LITE_QUEUE_READ_BUSY : /*...*/ break;
default:break;
}
}
#endif
int main(void)
{
uint8_t writebuff[QUEUE_ITEM_SIZE] = {0};
uint8_t readbuff[QUEUE_ITEM_SIZE] = {0};
/* Create message queue, 4 list items, each list item has 10 bytes of memory space */
#if(QUEUE_ERROR_CALLBACK == QUEUE_ENABLE)
pLiteQueue msgQueue = LiteQueue_Create(QUEUE_ITEM_NUM, QUEUE_ITEM_SIZE, LiteQueue_Callback);
#else
pLiteQueue msgQueue = LiteQueue_Create(QUEUE_ITEM_NUM, QUEUE_ITEM_SIZE);
#endif
PrintLiteQueue(msgQueue);
log_i("\n");
/* Simulate writing and reading to the queue 6 times, and observe the data in the queue by printing */
for(int i = 0; i < 4; i++)
{
/* Simulate data, change the writebuff data and write it to the queue */
for(int n = 0; n < msgQueue->item_size; n++)
writebuff[n] = (i * msgQueue->item_size + n) % 256;
/* Data is written to the queue */
Write_Back_To_LiteQueue(msgQueue, writebuff);
PrintLiteQueue(msgQueue);
log_i("\n");
}
/* Read data from queue */
Read_From_LiteQueue(msgQueue, readbuff);
PrintBuff("read", readbuff, sizeof(readbuff));
/* Read data from queue */
Read_From_LiteQueue(msgQueue, readbuff);
PrintBuff("read", readbuff, sizeof(readbuff));
PrintBuff("write", writebuff, sizeof(writebuff));
/* Data is written to the queue */
Write_Back_To_LiteQueue(msgQueue, writebuff);
PrintLiteQueue(msgQueue);
return 0;
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。