コード例 #1
0
MAILBOX_EXTERN unsigned long mailbox_send_msg(
	unsigned long			 mailcode,
	void					*data,
	unsigned long			 length)
{
	unsigned long  ret_val;
	unsigned long  try_go_on = MAILBOX_TRUE;
	unsigned long  try_times = 0;

	extern bool hifi_is_loaded(void);
	if (!hifi_is_loaded()) {
		return MAILBOX_TARGET_NOT_READY;
	}

	ret_val= BSP_CPU_StateGet(mailbox_get_dst_id(mailcode));
	if(!ret_val) {
		return MAILBOX_TARGET_NOT_READY;
	}
	ret_val = mailbox_try_send_msg(mailcode, data, length);

	if (MAILBOX_FALSE == mailbox_int_context()) {
		/*发送满等待轮询尝试*/
		while (MAILBOX_FULL == ret_val) {
			mailbox_delivery(mailbox_get_channel_id(mailcode));
			try_go_on = mailbox_scene_delay(MAILBOX_DELAY_SCENE_MSG_FULL, &try_times);

			if (MAILBOX_TRUE == try_go_on) {
				ret_val = mailbox_try_send_msg(mailcode, data, length);
			} else {
				break;
			}
		}
	}

	if (MAILBOX_OK != ret_val) {
		mailbox_show(mailcode,0);
		mailbox_assert(ret_val);
		if (MAILBOX_FULL != ret_val) {
			ret_val = MAILBOX_ERRO;
		}
		return ret_val;
	}

	return ret_val;
}
コード例 #2
0
/*****************************************************************************
 函 数 名  : mailbox_send_msg
 功能描述  : 提供给各模块进行核间数据发送的接口。
 输入参数  :
             unsigned int       mailcode      -- 邮件的id号, 逻辑通道号。
             unsigned char      *data           -- 指向邮件数据的指针。
             unsigned int       length/byte     -- 数据或者消息总长度 字节为单位。
 输出参数  : 无
 返 回 值  : unsigned int
             成功OK, 异常返回值
 调用函数  :
 被调函数  :

 修改历史      :
  1.日    期   : 2012年9月28日
    作    者   : 莫南 00176101
    修改内容   : 新生成函数

*****************************************************************************/
MAILBOX_EXTERN unsigned int mailbox_send_msg(
                unsigned int            mailcode,
                void                    *data,
                unsigned int            length)
{
    int  ret_val = MAILBOX_OK;
    unsigned int  try_go_on = MAILBOX_TRUE;
    int  try_times = 0;

    ret_val= BSP_CPU_StateGet(mailbox_get_dst_id(mailcode));
    if(!ret_val)
    {
        return MAILBOX_TARGET_NOT_READY;
    }

    ret_val = (int)mailbox_try_send_msg(mailcode, data, length);

    if (MAILBOX_FALSE == mailbox_int_context()) {
        /*发送满等待轮询尝试*/
        while ((int)MAILBOX_FULL == ret_val) {
            mailbox_delivery(mailbox_get_channel_id(mailcode));
            try_go_on = (unsigned int)mailbox_scene_delay(MAILBOX_DELAY_SCENE_MSG_FULL, &try_times);

            if (MAILBOX_TRUE == try_go_on) {
                ret_val = (int)mailbox_try_send_msg(mailcode, data, length);
            } else {
                break;
            }
        }
    }

    if (MAILBOX_OK != ret_val) {
        /*mailbox_show(mailcode,0);*/
        /*mailbox_assert(ret_val);*/
        if ((int)MAILBOX_FULL != ret_val) {
            ret_val = (int)MAILBOX_ERRO;
        }
        return (unsigned int)ret_val;
    }

    return (unsigned int)ret_val;
}
コード例 #3
0
/*****************************************************************************
 函 数 名  : mailbox_init_all_handle
 接口类型  : 对内接口
 功能描述  : 初始化邮箱的所有通道句柄
 输入参数  : struct mb *mb  -- 邮箱总句柄
             struct mb_cfg *config  -- 邮箱通道的全局配置表。
             unsigned long  cpu_id     -- 注册此通道的CPU号。
 输出参数  : 无
 返 回 值  : 邮箱操作句柄
 调用函数  :
 被调函数  :

 修改历史      :
  1.日    期   : 2012年9月7日
    作    者   : 莫南 00176101
    修改内容   : 新生成函数

*****************************************************************************/
MAILBOX_LOCAL long mailbox_init_all_handle(
                struct mb           *mb,
                struct mb_cfg    *config,
                unsigned long     cpu_id)
{
    struct mb_queue        *queue  = MAILBOX_NULL;
    unsigned long           direct= MIALBOX_DIRECTION_INVALID; /*标记当前邮箱通道
                                            是不是本核相关的有效通道*/
    unsigned long           ret_val      = MAILBOX_OK;
    struct mb_link         *send_link    = MAILBOX_NULL;/*指向主结构体的发送通道
                                                          数组基地址*/
    struct mb_link         *recv_link = MAILBOX_NULL;   /*指向主结构体的接收通道
                                                          数组基地址*/
    struct mb_buff         *mbuf_prob   = &g_mailbox_channel_handle_pool[0];
    struct mb_cb           *cb_prob  = &g_mailbox_user_cb_pool[0];
    struct mb_buff         *mbuf_cur = MAILBOX_NULL;    /*指向正在处理的邮箱通道*/
    unsigned long           channel_sum    = 0;
    unsigned long           use_sum    = 0;
    unsigned long           src_id       = 0;
    unsigned long           dst_id       = 0;
    unsigned long           carrier_id   = 0;
    unsigned long           use_max      = 0;

    send_link  =  mb->send_tbl;
    recv_link  =  mb->recv_tbl;

    /*第二次循环对每个通道句柄分配空间,并赋值。(这段代码变量太多,不方便拆开另建函数)*/
    /*初始化每个邮箱的控制句柄*/
    while (MAILBOX_MAILCODE_INVALID != config->butt_id) {
        direct = MIALBOX_DIRECTION_INVALID;
        src_id       = mailbox_get_src_id(config->butt_id);
        dst_id       = mailbox_get_dst_id(config->butt_id);
        carrier_id   = mailbox_get_carrier_id(config->butt_id);
        use_max      = mailbox_get_use_id(config->butt_id);

        /*检查是不是本CPU发送通道*/
        if (cpu_id == src_id) {
            direct = MIALBOX_DIRECTION_SEND;

            /*没有分配空间则分配空间*/
            if (MAILBOX_NULL == send_link[dst_id].channel_buff) {
                send_link[dst_id].channel_buff = mbuf_prob;
                mbuf_prob += (send_link[dst_id].carrier_butt);
                channel_sum  += (send_link[dst_id].carrier_butt);
                if (channel_sum > MAILBOX_CHANNEL_NUM) {
                    return mailbox_logerro_p1(MAILBOX_CRIT_GUT_INIT_CHANNEL_POOL_TOO_SMALL,
                                                channel_sum);
                }
            }
            mbuf_cur = &send_link[dst_id].channel_buff[carrier_id];
        }

        /*检查是不是本CPU接收通道*/
        if (cpu_id == dst_id) {
             direct = MIALBOX_DIRECTION_RECEIVE;

            /*没有分配空间则分配空间*/
            if (MAILBOX_NULL == recv_link[src_id].channel_buff) {
                recv_link[src_id].channel_buff = mbuf_prob;
                mbuf_prob += (recv_link[src_id].carrier_butt);
                channel_sum  += (recv_link[src_id].carrier_butt);
                if (channel_sum > MAILBOX_CHANNEL_NUM) {
                    return mailbox_logerro_p1(MAILBOX_CRIT_GUT_INIT_CHANNEL_POOL_TOO_SMALL,
                                                channel_sum);
                }
            }

            mbuf_cur = &recv_link[src_id].channel_buff[carrier_id];

            /*1。为邮件注册回调函数申请空间*/
            mbuf_cur->read_cb = cb_prob;
            cb_prob += use_max;
            use_sum   += use_max;
            if (use_sum > MAILBOX_USER_NUM) {
                return mailbox_logerro_p1(MAILBOX_CRIT_GUT_INIT_USER_POOL_TOO_SMALL, use_sum);
            }

            /*3.注册邮箱线程回调接口,用于获取共享内存邮箱数据的处理*/
            ret_val = mailbox_process_register(mailbox_get_channel_id(config->butt_id),
                                                mailbox_read_channel, mbuf_cur);

            /*4.初始化邮箱共享内存,设置标志位。*/
            ret_val |= mailbox_init_mem(config);

        }

        if ((MIALBOX_DIRECTION_INVALID != direct ) && (MAILBOX_NULL != mbuf_cur)) {
            /*给控制句柄赋予邮箱ID号*/
            mbuf_cur->channel_id = mailbox_get_channel_id(config->butt_id);
            mbuf_cur->seq_num = MAILBOX_SEQNUM_START;
#ifdef MAILBOX_OPEN_MNTN
            mbuf_cur->mntn.peak_traffic_left = MAILBOX_QUEUE_LEFT_INVALID;
            mbuf_cur->mntn.mbuff    = mbuf_cur;
#endif
            /*给邮箱配置物理资源*/
            mbuf_cur->config = config;

            /*初始化通道资源*/
            queue = &(mbuf_cur->mail_queue);

            /*初始化邮箱通道的环形队列控制符,以下两项是初始化以后不会再变化的。*/
            queue->length  = mbuf_cur->config->data_size -
                            (MAILBOX_DATA_LEN_PROTECT_NUM * MAILBOX_PROTECT_LEN);
            queue->base    = mbuf_cur->config->data_addr +
                           (MAILBOX_DATA_BASE_PROTECT_NUM * MAILBOX_PROTECT_LEN);


            /*把此通道注册到具体平台*/
            ret_val = mailbox_channel_register(mailbox_get_channel_id(config->butt_id), /*lint !e539*/
                       config->int_src,
                       mailbox_get_dst_id(config->butt_id),
                       direct,
                       &mbuf_cur->mutex);
        }

        config++;
    }

    /*检查内存池大小是否刚好,如果报错,请检查宏设置是否匹配:
      这里检查下面三个数组的空间是否适配。
        g_mailbox_global_cfg_tbl[];
        g_mailbox_channel_handle_pool[MAILBOX_CHANNEL_NUM];
        g_mailbox_user_cb_pool[MAILBOX_USER_NUM];
    */
    if((unsigned long)MAILBOX_CHANNEL_NUM != channel_sum ) {
        ret_val = mailbox_logerro_p1(MAILBOX_ERR_GUT_INIT_CHANNEL_POOL_TOO_LARGE,
                                    (MAILBOX_CHANNEL_NUM<<16) | channel_sum);
    }

    if(MAILBOX_USER_NUM != use_sum) {
       ret_val = mailbox_logerro_p1(MAILBOX_ERR_GUT_INIT_USER_POOL_TOO_LARGE, use_sum);
    }

    return ret_val;
}