/* msgbox_alloc_channel - alloc channel from msgbox @func when function as send, it act as tx_done when function as rev, it act as word reveive.  */
struct msg_channel* msgbox_alloc_channel_sx(struct messagebox *mb, int channel, enum msgbox_channel_direction dir, int(*func)(unsigned long, void *), void *data)
/* msgbox_alloc_channel - alloc channel from msgbox @func when function as send, it act as tx_done when function as rev, it act as word reveive.  */
struct msg_channel* msgbox_alloc_channel_sx(struct messagebox *mb, int channel, enum msgbox_channel_direction dir, int(*func)(unsigned long, void *), void *data)
{
    struct msg_channel *ch;
    if (!mb || channel >= MSGBOX_MAX_QUEUE)
        return 0;
    ch = &mb->msg_handler[channel];
    ch->mb = mb;
    ch->channel = channel;
    ch->data = data;
    ch->dir = dir;
    if (mb->channel_set_direction(mb, channel, dir))
        return 0;
    if (ch->dir == MSGBOX_CHANNEL_SEND) {
        ch->cb_of_msg_queue = msgbox_send_handler;
        ch->cb_tx_done = func;
    }
    else {
        ch->cb_of_msg_queue = msgbox_rev_handler;
        ch->cb_rx = func;
        mb->channel_irq_set(mb, channel, true);
    }
    return ch;
}