This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

[参考译文] CC2340R5:大量堆栈使用量变为黄色

Guru**** 2589280 points


请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

https://e2e.ti.com/support/wireless-connectivity/bluetooth-group/bluetooth/f/bluetooth-forum/1382070/cc2340r5-lots-of-stack-usage-turn-yellow

器件型号:CC2340R5

工具与软件:

大家好!

我正在片上 OAD 示例上进行开发、创建了一个新任务和一个队列。

static void *DataStream_Task(void *arg)
{
    for (;;)
    {
        DataStream_appEvt_t pAppEvt;

        if (mq_receive(DataStream_theardEntity.queueHandle, (char*)&pAppEvt, sizeof(pAppEvt), NULL) > 0)
        {
            
        }
    }
}

static bStatus_t DataStream_createQueue(void)
{
    struct mq_attr attr;

     attr.mq_flags = 0;
     attr.mq_curmsgs = 0;
     attr.mq_maxmsg = 8;
     attr.mq_msgsize = sizeof(DataStream_appEvt_t);

     /* Create the message queue */
     DataStream_theardEntity.queueHandle = mq_open("DataStream_theardQueue", O_CREAT , 0, &attr);

     if (DataStream_theardEntity.queueHandle == (mqd_t)-1)
     {
         return FAILURE;
     }
     return SUCCESS;
}

Status_t DataStream_enqueueMsg(uint8_t event, void *pData)
{
    int8_t status = SUCCESS;
    DataStream_appEvt_t msg;

    // Check if the queue is valid
    if (DataStream_theardEntity.queueHandle == (mqd_t)-1)
    {
        return FAILURE;
    }

    msg.event = event;
    msg.pData = pData;

    // Send the msg to the application queue
    status = mq_send(DataStream_theardEntity.queueHandle,(char*)&msg,sizeof(msg),1);

    return status;
}

int DataStream_createTask(void)
{
    int retVal = 0;
    pthread_attr_t param_attribute;
    struct sched_param param;

    retVal =  pthread_attr_init(&param_attribute);
    param.sched_priority = 1;

    retVal |= pthread_attr_setschedparam(&param_attribute, &param);
    retVal |= pthread_attr_setstack(&param_attribute, dataStreamTaskStack, 1024);
    retVal |= pthread_attr_setdetachstate(&param_attribute, PTHREAD_CREATE_DETACHED);

    retVal |= pthread_create(&DataStream_theardEntity.threadId,
                             &param_attribute,
                             &DataStream_Task,
                             NULL);
    return retVal;
}

在调试期间、它被清空、然后我发现堆栈使用窗口中有许多黄色项目。 我从未修改过的一些项目、导致此问题的原因、以及如何修复它并保留我的代码。