/* This function is used to register dma interrupt callback function.  */
void tls_dma_irq_register(unsigned char ch, void(*callback)(void *p), void *arg, unsigned char flags)
/* This function is used to register dma interrupt callback function.  */
void tls_dma_irq_register(unsigned char ch, void(*callback)(void *p), void *arg, unsigned char flags)
{
    unsigned int mask;
    mask  = tls_reg_read32(HR_DMA_INT_MASK);
    mask |= TLS_DMA_IRQ_BOTH_DONE << 2 * ch;
    mask &= ~(flags << 2 * ch);
    tls_reg_write32(HR_DMA_INT_MASK, mask);
    dma_context[ch].flags = flags;
    if (flags & TLS_DMA_IRQ_BURST_DONE)
    {
        dma_context[ch].burst_done_pf   = callback;
        dma_context[ch].burst_done_priv = arg;
    }
    if (flags & TLS_DMA_IRQ_TRANSFER_DONE)
    {
        dma_context[ch].transfer_done_pf   = callback;
        dma_context[ch].transfer_done_priv = arg;
    }
    if (ch > 3)
        ch = 4;
    tls_irq_priority(DMA_Channel0_IRQn + ch, ch/2);
    tls_irq_enable(DMA_Channel0_IRQn + ch);
}