查看更多
这是这个初始化函数的代码:void rt_object_init(struct rt_object object, enum rt_object_class_type type, const char name){ register rt_base_t temp; struct rt_list_node node = RT_NULL; struct rt_object_information information;
struct rt_dlmodule *module = dlmodule_self();
/* get object information */information = rt_object_get_information(type);RT_ASSERT(information != RT_NULL);/* check object type to avoid re-initialization *//* enter critical */rt_enter_critical();/* try to find object */for (node = information->object_list.next; node != &(information->object_list); node = node->next){ struct rt_object *obj; obj = rt_list_entry(node, struct rt_object, list); if (obj) /* skip warning when disable debug */ { RT_ASSERT(obj != object); }}/* leave critical */rt_exit_critical();/* initialize object's parameters *//* set object type to static */object->type = type | RT_Object_Class_Static;/* copy name */rt_strncpy(object->name, name, RT_NAME_MAX);RT_OBJECT_HOOK_CALL(rt_object_attach_hook, (object));/* lock interrupt */temp = rt_hw_interrupt_disable();
/* get object information */
information = rt_object_get_information(type);
RT_ASSERT(information != RT_NULL);
/* check object type to avoid re-initialization */
/* enter critical */
rt_enter_critical();
/* try to find object */
for (node = information->object_list.next;
node != &(information->object_list);
node = node->next)
{
struct rt_object *obj;
obj = rt_list_entry(node, struct rt_object, list);
if (obj) /* skip warning when disable debug */
RT_ASSERT(obj != object);
}
/* leave critical */
rt_exit_critical();
/* initialize object's parameters */
/* set object type to static */
object->type = type | RT_Object_Class_Static;
/* copy name */
rt_strncpy(object->name, name, RT_NAME_MAX);
RT_OBJECT_HOOK_CALL(rt_object_attach_hook, (object));
/* lock interrupt */
temp = rt_hw_interrupt_disable();
if (module){ rt_list_insert_after(&(module->object_list), &(object->list)); object->module_id = (void *)module;}else
if (module)
rt_list_insert_after(&(module->object_list), &(object->list));
object->module_id = (void *)module;
else
{ /* insert object into information object list */ rt_list_insert_after(&(information->object_list), &(object->list));}/* unlock interrupt */rt_hw_interrupt_enable(temp);
/* insert object into information object list */
rt_list_insert_after(&(information->object_list), &(object->list));
/* unlock interrupt */
rt_hw_interrupt_enable(temp);
出错的源码line328具体是什么内容?
/* try to find object */for (node = information->object_list.next; node != &(information->object_list); node = node->next){ struct rt_object *obj; obj = rt_list_entry(node, struct rt_object, list); if (obj) /* skip warning when disable debug */ { RT_ASSERT(obj != object); //程序运行到这里,产生assert; }}
RT_ASSERT(obj != object); //程序运行到这里,产生assert;
可能的原因就是你在初始化某一个组件的时候,重复执行了相关的初始化函数;这个for循环的作用就是遍历对象容器,如果要初始化的对象已经在对象容器当中,就不用再次初始化。
仔细排查下你的代码,是否重复注册同一个I2C总线啦。
欢迎发表与嵌入式相关的技术分享、开发技巧、工具介绍、技术设想、职业心得、行业评论等对他人有启发,排版优雅的文章
回到 顶部
发布 问题
分享 好友
手机 浏览
投诉 建议
回到 底部
没找到,想问的就是这个
建议你单步调试,看看问题出在哪里。