使用ringbuffer时,自检到thread的type不匹配

发布于 2021-04-08 11:09:46

错误现象:

msh >(rt_object_get_type((rt_object_t)thread) == RT_Object_Class_Thread) assertion failed at function:rt_thread_resume, line number:770

代码:

void pack_thread_entry(void *parameter)
{
    rt_err_t result;
    rt_size_t len = 0;
    rt_size_t size = 0;
    uint8_t cal[512] = {0};
    uint16_t send_len = 0;
    uint8_t send[512] = {0};
    struct msg ind_send;   
    g_data_ringbuffer = rt_ringbuffer_create(RINGBUFFER_SIZE);
    while (1)
    {
//        len = rt_ringbuffer_data_len(g_data_ringbuffer);
//        if (len >= CTD_PACK_SIZE)
//        {
        if (g_data_count == 24)
        {
            g_data_count = 0;
            len = rt_ringbuffer_data_len(g_data_ringbuffer);
//            while (rt_ringbuffer_data_len(g_data_ringbuffer))
//            {
                size = rt_ringbuffer_get(g_data_ringbuffer, cal, len);
//                rt_ringbuffer_reset(g_data_ringbuffer);
//                send_len = package_ind_data(cal, size, send);
//                for (uint16_t i = 0; i < send_len; i++)
//                {
//                    pm_printf("%c", send[i]);
//                }
//            }
            send_len = 1024;
            ind_send.data_ptr = send;
            ind_send.data_size = send_len;
            result = rt_mq_send(g_ind_send_mq, (void*)&ind_send, sizeof(struct msg));
            if ( result == -RT_EFULL)
            {
                /* 消息队列满 */
                rt_kprintf("ind_send_mq full!\n");
            }
              /* 申请一块内存 要是内存池满了 就挂起等待 */
//            ind_send = rt_mp_alloc(tmp_msg_mp, RT_WAITING_FOREVER);
//            ind_send->data_size = send_len;
//            ind_send->data_ptr  = send;
//            rt_mb_send(tmp_msg_mb, (rt_ubase_t)ind_send);
//            ind_send = NULL;  

//        }
        }
        rt_thread_mdelay(10);        
    }    
}

分析过程:

定位问题,这是在rt_mq_send中死机打印上述提示信息的
消息队列换为邮箱+内存池,仍有同样问题
注释掉消息队列,仅用ringbuffer,正常
注释掉ringbuffer,仅用消息队列,正常

这是什么原因呢,是因为用ringbuffer有哪不合适吗

查看更多

关注者
0
被浏览
55
aozima
aozima 4 days ago
拒绝白嫖,拒绝键盘侠!
uint8_t cal[512] = {0};
uint8_t send[512] = {0};

你这2个大的局部数组,很可能撑爆了你的栈,你看下你的线程栈是多大。

4 个回答
aprilhome
aprilhome 4 days ago

这是什么问题呢,是ringbuffer有哪用的不合适吗

mii
mii 4 days ago

不会是您邮箱初始化不对吧

flashman2002
flashman2002 4 days ago

估计是你的线程栈设置过小了。

撰写答案

请登录后再发布答案,点击登录

发布
问题

分享
好友

手机
浏览

扫码手机浏览