MAILBOX_LOCAL int mailbox_request_channel( struct mb *mb, struct mb_buff ** mb_buf, unsigned int mailcode) { struct mb_head *head = MAILBOX_NULL; struct mb_queue *queue = MAILBOX_NULL; struct mb_buff *mbuff = MAILBOX_NULL; int ret_val = MAILBOX_OK; *mb_buf = MAILBOX_NULL; mbuff = mailbox_get_channel_handle(mb, mailcode); if (MAILBOX_NULL == mbuff) { ret_val = (int)MAILBOX_ERRO; goto request_erro;/*lint --e{801}*/ } /*通过判断通道保护字,检查通道有没有初始化*/ head = (struct mb_head*)mbuff->config->head_addr; if (( (MAILBOX_PROTECT1 != head->ulProtectWord1) ) || (MAILBOX_PROTECT2 != head->ulProtectWord2) ||(MAILBOX_PROTECT1 != head->ulProtectWord3) || (MAILBOX_PROTECT2 != head->ulProtectWord4)) { /*保护字不正确,说明邮箱未初始化,或者内存被踩,报错。*/ ret_val = mailbox_logerro_p1(MAILBOX_NOT_READY, mailcode); goto request_erro;/*lint --e{801}*/ } if(mailbox_get_src_id(mailcode) == mb->local_id) { /* 不允许在中断中发邮件*/ if (MAILBOX_TRUE == mailbox_int_context()) { //TODO:接下来的开发(IFC for 低功耗)可能需要支持在中断中发送邮件,这里就需要锁中断。 ret_val = mailbox_logerro_p1(MAILBOX_ERR_GUT_SEND_MAIL_IN_INT_CONTEXT, mailcode); goto request_erro;/*lint --e{801}*/ } else { if (MAILBOX_OK != mailbox_mutex_lock(&mbuff->mutex)) { /*非中断发送,需要资源保护,获取当前通道资源。*/ ret_val = mailbox_logerro_p1(MAILBOX_CRIT_GUT_MUTEX_LOCK_FAILED, mailcode); goto request_erro;/*lint --e{801}*/ } } } mbuff->mailcode = mailcode; /*共享内存队列,需要依据邮箱头信息对队列操作符进行填充*/ queue = &mbuff->mail_queue; queue->front = queue->base + head->ulFront * sizeof(unsigned int); queue->rear = queue->base + head->ulRear * sizeof(unsigned int); mbuff->mb = mb; *mb_buf = mbuff; return MAILBOX_OK; request_erro: //mailbox_out(("###mailbox_request_channel ERR!"RT)); return ret_val; }
MAILBOX_EXTERN long mailbox_register_cb( unsigned long mailcode, void (*cb)(void *mbuf, void *handle, void *data), void *usr_handle, void *usr_data) { struct mb_cb *read_cb = MAILBOX_NULL; struct mb_buff *mbuf = MAILBOX_NULL; struct mb *mb = MAILBOX_NULL; unsigned long dst_id; mb = &g_mailbox_handle;/*有可能在初始化过程中注册*/ /* 允许注册空回调,相当于UnRegister if (MAILBOX_NULL == pFun) { return mailbox_logerro_p1(MAILBOX_ERR_GUT_MAILBOX_NULL_PARAM, mailcode); } */ /*往某个CPU的某个邮箱通道中的某个邮件应用用注册回调函数*/ dst_id = mailbox_get_dst_id(mailcode); printk("mb->local_id = %ld dst_id = %ld\n", mb->local_id, dst_id); if (mb->local_id != dst_id) { return mailbox_logerro_p1(MAILBOX_ERR_GUT_INVALID_TARGET_CPU, mailcode); } mbuf = mailbox_get_channel_handle(mb, mailcode); if (MAILBOX_NULL == mbuf) { /*找不到,此通道未初始化。*/ return mailbox_logerro_p1(MAILBOX_ERR_GUT_INVALID_CHANNEL_ID, mailcode); } /*检查OK, 赋值给回调函数指针*/ read_cb = &mbuf->read_cb[mailbox_get_use_id(mailcode)]; if (MAILBOX_NULL != read_cb->func) { /*mailbox_logerro_p1(MAILBOX_WARNING_USER_CALLBACK_ALREADY_EXIST, mailcode);*/ } mailbox_mutex_lock(&mbuf->mutex); read_cb->handle = usr_handle; read_cb->data = usr_data; read_cb->func = cb; mailbox_mutex_unlock(&mbuf->mutex); return MAILBOX_OK; }
MAILBOX_LOCAL long mailbox_request_channel( struct mb *mb, struct mb_buff ** mb_buf, unsigned long mailcode) { struct mb_head *head = MAILBOX_NULL; struct mb_queue *queue = MAILBOX_NULL; struct mb_buff *mbuff = MAILBOX_NULL; long ret_val = MAILBOX_OK; mailbox_dpm_device_get(); *mb_buf = MAILBOX_NULL; mbuff = mailbox_get_channel_handle(mb, mailcode); if (MAILBOX_NULL == mbuff) { ret_val = MAILBOX_ERRO; goto request_erro; } /*通过判断通道保护字,检查通道有没有初始化*/ head = (struct mb_head*)mbuff->config->head_addr; if (( (MAILBOX_PROTECT1 != head->ulProtectWord1) ) || (MAILBOX_PROTECT2 != head->ulProtectWord2) ||(MAILBOX_PROTECT1 != head->ulProtectWord3) || (MAILBOX_PROTECT2 != head->ulProtectWord4)) { #if 1/*k3 modify 保护字不正确重新初始化一下邮箱头,不要return影响通信流程,后续再找根因*/ /*保护字不正确,说明邮箱未初始化,或者内存被踩,报错。*/ /* do not check cause hifi maybe not pwr on when the first ipc message send */ mailbox_init_mem(mbuff->config); mailbox_logerro_p1(MAILBOX_NOT_READY, mailcode); #endif } if(mailbox_get_src_id(mailcode) == mb->local_id) { /* 不允许在中断中发邮件*/ if (MAILBOX_TRUE == mailbox_int_context()) { //TODO:接下来的开发(IFC for 低功耗)可能需要支持在中断中发送邮件,这里就需要锁中断。 ret_val = mailbox_logerro_p1(MAILBOX_ERR_GUT_SEND_MAIL_IN_INT_CONTEXT, mailcode); goto request_erro; } else { if (MAILBOX_OK != mailbox_mutex_lock(&mbuff->mutex)) { /*非中断发送,需要资源保护,获取当前通道资源。*/ ret_val = mailbox_logerro_p1(MAILBOX_CRIT_GUT_MUTEX_LOCK_FAILED, mailcode); goto request_erro; } } } mbuff->mailcode = mailcode; /*共享内存队列,需要依据邮箱头信息对队列操作符进行填充*/ queue = &mbuff->mail_queue; queue->front = queue->base + head->ulFront * sizeof(unsigned long); queue->rear = queue->base + head->ulRear * sizeof(unsigned long); mbuff->mb = mb; *mb_buf = mbuff; return MAILBOX_OK; request_erro: mailbox_out(("###mailbox_request_channel ERR! \n")); mailbox_dpm_device_put(); return ret_val; }