FreeRTOS/Demo/RX700_RX72N_EnvisionKit_Renesas_e2studio_CS+/src/smc_gen/r_dtc_rx/src/r_dtc_rx.c
/*******************************************************************************
* Function Name: r_dtc_set_transfer_data
* Description  : Applies configurations to a Transfer data area, it is an internal
*                function called by R_DTC_Create(); and all arguments are validated
*                in R_DTC_Create()
* Arguments    : transfer_data -
*                    Start address of Transfer data
*                data_cfg -
*                    Contains configurations for the Transfer data
* Return Value : DTC_SUCCESS -
*                    Apply configurations for Transfer data successfully.
*                DTC_ERR_INVALID_ARG
*                    Fail to apply configurations for Transfer data.
*******************************************************************************/
Function Name: r_dtc_set_transfer_data
Description  : Applies configurations to a Transfer data area, it is an internal
function called by R_DTC_Create(); and all arguments are validated
in R_DTC_Create()
Arguments    : transfer_data
Start address of Transfer data
data_cfg
Contains configurations for the Transfer data
Return Value : DTC_SUCCESS
Apply configurations for Transfer data successfully.
DTC_ERR_INVALID_ARG
Fail to apply configurations for Transfer data.
Function Name : r_dtc_set_transfer_data Description : Applies configurations to a Transfer data area it is an internal function called by R_DTC_Create () ; and all arguments are validated in R_DTC_Create () Arguments : transfer_data Start address of Transfer data data_cfg Contains configurations for the Transfer data Return Value : DTC_SUCCESS Apply configurations for Transfer data successfully . DTC_ERR_INVALID_ARG Fail to apply configurations for Transfer data .
static dtc_err_t r_dtc_set_transfer_data(dtc_transfer_data_t *p_transfer_data,
                                   dtc_transfer_data_cfg_t *p_cfg)
{
    dtc_mra_t                          t_mra;
    dtc_mrb_t                          t_mrb;
    dtc_cra_t                          t_cra;
    dtc_crb_t                          t_crb;
    volatile dtc_internal_registers_t *p_td_ptr = (volatile dtc_internal_registers_t *)p_transfer_data;
#if (DTC_IP_VER_DTCb <= DTC_IP)
#if (DTC_ENABLE != DTC_CFG_SHORT_ADDRESS_MODE) 
    dtc_mrc_t                          t_mrc;
    t_mrc.BYTE = (uint8_t)(p_cfg->disp_add_enable);
#endif 
    t_mra.BYTE = ((((uint8_t)p_cfg->writeback_disable | (uint8_t)p_cfg->src_addr_mode) | (uint8_t)p_cfg->data_size) | (uint8_t)p_cfg->transfer_mode);
    t_mrb.BYTE = (((((((uint8_t)p_cfg->sequence_end |(uint8_t)p_cfg->refer_index_table_enable) | (uint8_t)p_cfg->dest_addr_mode) |
                           (uint8_t)p_cfg->repeat_block_side) | (uint8_t)p_cfg->response_interrupt) |
                           (uint8_t)p_cfg->chain_transfer_enable) | (uint8_t)p_cfg->chain_transfer_mode);
#else
    t_mra.BYTE = (uint8_t)(p_cfg->src_addr_mode | p_cfg->data_size | p_cfg->transfer_mode);
    t_mrb.BYTE = (uint8_t)(p_cfg->dest_addr_mode | p_cfg->repeat_block_side | p_cfg->response_interrupt |
                           p_cfg->chain_transfer_enable | p_cfg->chain_transfer_mode);
#endif 
    switch (t_mra.BIT.MD) 
    {
        case 0x0: 
        {
            if (DTC_PRV_MAX_16BITS_COUNT_VAL == p_cfg->transfer_count)
            {
                t_cra.WORD = 0x0000;
            }
            else 
            {
                t_cra.WORD = (uint16_t)p_cfg->transfer_count;
            }
            break;
        }
        case 0x1: 
        {
            if (p_cfg->transfer_count < DTC_PRV_MAX_8BITS_COUNT_VAL) 
            {
                t_cra.BYTE.CRA_H = (uint8_t)p_cfg->transfer_count;
                t_cra.BYTE.CRA_L = (uint8_t)p_cfg->transfer_count;
            }
            else if (DTC_PRV_MAX_8BITS_COUNT_VAL == p_cfg->transfer_count)
            {
                t_cra.BYTE.CRA_H = 0x00;
                t_cra.BYTE.CRA_L = 0x00;
            }
            else 
            {
                return DTC_ERR_INVALID_ARG;
            }
            break;
        }
        case 0x2: 
        {
            if (DTC_PRV_MAX_16BITS_COUNT_VAL == p_cfg->transfer_count)
            {
                t_crb.WORD = 0x0000;
            }
            else 
            {
                t_crb.WORD = (uint16_t)p_cfg->transfer_count;
            }
            if (p_cfg->block_size < DTC_PRV_MAX_8BITS_COUNT_VAL) 
            {
                t_cra.BYTE.CRA_H = (uint8_t)p_cfg->block_size;
                t_cra.BYTE.CRA_L = (uint8_t)p_cfg->block_size;
            }
            else if (DTC_PRV_MAX_8BITS_COUNT_VAL == p_cfg->block_size) 
            {
                t_cra.BYTE.CRA_H = 0;
                t_cra.BYTE.CRA_L = 0;
            }
            else 
            {
                return DTC_ERR_INVALID_ARG;
            }
            break;
        }
        default:
        {
            return DTC_ERR_INVALID_ARG;
            break;
        }
    }
#if (DTC_ENABLE == DTC_CFG_SHORT_ADDRESS_MODE) 
    p_td_ptr->FIRST_LWORD.LWORD   =  0; 
    p_td_ptr->FIRST_LWORD.REG.MRA =  t_mra; 
    p_td_ptr->FIRST_LWORD.LWORD   |= (p_cfg->source_addr & 0x00FFFFFF); 
    p_td_ptr->SECOND_LWORD.LWORD   =  0; 
    p_td_ptr->SECOND_LWORD.REG.MRB =  t_mrb; 
    p_td_ptr->SECOND_LWORD.LWORD   |= (p_cfg->dest_addr & 0x00FFFFFF); 
    p_td_ptr->THIRD_LWORD.REG.CRA.WORD = t_cra.WORD;
    p_td_ptr->THIRD_LWORD.REG.CRB.WORD = t_crb.WORD;
#else 
    p_td_ptr->FIRST_LWORD.REG.MRA.BYTE = t_mra.BYTE; 
    p_td_ptr->FIRST_LWORD.REG.MRB.BYTE = t_mrb.BYTE; 
#if (DTC_IP_VER_DTCb <= DTC_IP)
    p_td_ptr->FIRST_LWORD.REG.MRC.BYTE = t_mrc.BYTE; 
#endif 
    p_td_ptr->SECOND_LWORD.SAR = p_cfg->source_addr; 
    p_td_ptr->THIRD_LWORD.DAR = p_cfg->dest_addr; 
    p_td_ptr->FOURTH_LWORD.REG.CRA.WORD = t_cra.WORD;
    p_td_ptr->FOURTH_LWORD.REG.CRB.WORD = t_crb.WORD;
#endif 
    return DTC_SUCCESS;
}
static dtc_err_t r_dtc_set_transfer_data ( dtc_transfer_data_t * p_transfer_data , dtc_transfer_data_cfg_t * p_cfg ) { dtc_mra_t t_mra ; dtc_mrb_t t_mrb ; dtc_cra_t t_cra ; dtc_crb_t t_crb ; volatile dtc_internal_registers_t * p_td_ptr = ( volatile dtc_internal_registers_t * ) p_transfer_data ; #if ( DTC_IP_VER_DTCb <= DTC_IP ) #if ( DTC_ENABLE != DTC_CFG_SHORT_ADDRESS_MODE ) dtc_mrc_t t_mrc ; t_mrc . BYTE = ( uint8_t ) ( p_cfg -> disp_add_enable ) ; #endif t_mra . BYTE = ( ( ( ( uint8_t ) p_cfg -> writeback_disable | ( uint8_t ) p_cfg -> src_addr_mode ) | ( uint8_t ) p_cfg -> data_size ) | ( uint8_t ) p_cfg -> transfer_mode ) ; t_mrb . BYTE = ( ( ( ( ( ( ( uint8_t ) p_cfg -> sequence_end | ( uint8_t ) p_cfg -> refer_index_table_enable ) | ( uint8_t ) p_cfg -> dest_addr_mode ) | ( uint8_t ) p_cfg -> repeat_block_side ) | ( uint8_t ) p_cfg -> response_interrupt ) | ( uint8_t ) p_cfg -> chain_transfer_enable ) | ( uint8_t ) p_cfg -> chain_transfer_mode ) ; #else t_mra . BYTE = ( uint8_t ) ( p_cfg -> src_addr_mode | p_cfg -> data_size | p_cfg -> transfer_mode ) ; t_mrb . BYTE = ( uint8_t ) ( p_cfg -> dest_addr_mode | p_cfg -> repeat_block_side | p_cfg -> response_interrupt | p_cfg -> chain_transfer_enable | p_cfg -> chain_transfer_mode ) ; #endif switch ( t_mra . BIT . MD ) { case 0x0 : { if ( DTC_PRV_MAX_16BITS_COUNT_VAL == p_cfg -> transfer_count ) { t_cra . WORD = 0x0000 ; } else { t_cra . WORD = ( uint16_t ) p_cfg -> transfer_count ; } break ; } case 0x1 : { if ( p_cfg -> transfer_count < DTC_PRV_MAX_8BITS_COUNT_VAL ) { t_cra . BYTE . CRA_H = ( uint8_t ) p_cfg -> transfer_count ; t_cra . BYTE . CRA_L = ( uint8_t ) p_cfg -> transfer_count ; } else if ( DTC_PRV_MAX_8BITS_COUNT_VAL == p_cfg -> transfer_count ) { t_cra . BYTE . CRA_H = 0x00 ; t_cra . BYTE . CRA_L = 0x00 ; } else { return DTC_ERR_INVALID_ARG ; } break ; } case 0x2 : { if ( DTC_PRV_MAX_16BITS_COUNT_VAL == p_cfg -> transfer_count ) { t_crb . WORD = 0x0000 ; } else { t_crb . WORD = ( uint16_t ) p_cfg -> transfer_count ; } if ( p_cfg -> block_size < DTC_PRV_MAX_8BITS_COUNT_VAL ) { t_cra . BYTE . CRA_H = ( uint8_t ) p_cfg -> block_size ; t_cra . BYTE . CRA_L = ( uint8_t ) p_cfg -> block_size ; } else if ( DTC_PRV_MAX_8BITS_COUNT_VAL == p_cfg -> block_size ) { t_cra . BYTE . CRA_H = 0 ; t_cra . BYTE . CRA_L = 0 ; } else { return DTC_ERR_INVALID_ARG ; } break ; } default : { return DTC_ERR_INVALID_ARG ; break ; } } #if ( DTC_ENABLE == DTC_CFG_SHORT_ADDRESS_MODE ) p_td_ptr -> FIRST_LWORD . LWORD = 0 ; p_td_ptr -> FIRST_LWORD . REG . MRA = t_mra ; p_td_ptr -> FIRST_LWORD . LWORD |= ( p_cfg -> source_addr & 0x00FFFFFF ) ; p_td_ptr -> SECOND_LWORD . LWORD = 0 ; p_td_ptr -> SECOND_LWORD . REG . MRB = t_mrb ; p_td_ptr -> SECOND_LWORD . LWORD |= ( p_cfg -> dest_addr & 0x00FFFFFF ) ; p_td_ptr -> THIRD_LWORD . REG . CRA . WORD = t_cra . WORD ; p_td_ptr -> THIRD_LWORD . REG . CRB . WORD = t_crb . WORD ; #else p_td_ptr -> FIRST_LWORD . REG . MRA . BYTE = t_mra . BYTE ; p_td_ptr -> FIRST_LWORD . REG . MRB . BYTE = t_mrb . BYTE ; #if ( DTC_IP_VER_DTCb <= DTC_IP ) p_td_ptr -> FIRST_LWORD . REG . MRC . BYTE = t_mrc . BYTE ; #endif p_td_ptr -> SECOND_LWORD . SAR = p_cfg -> source_addr ; p_td_ptr -> THIRD_LWORD . DAR = p_cfg -> dest_addr ; p_td_ptr -> FOURTH_LWORD . REG . CRA . WORD = t_cra . WORD ; p_td_ptr -> FOURTH_LWORD . REG . CRB . WORD = t_crb . WORD ; #endif return DTC_SUCCESS ; }
Function Name: r_dtc_set_transfer_data
Description  : Applies configurations to a Transfer data area, it is an internal
function called by R_DTC_Create(); and all arguments are validated
in R_DTC_Create()
Arguments    : transfer_data
Start address of Transfer data
data_cfg
Contains configurations for the Transfer data
Return Value : DTC_SUCCESS
Apply configurations for Transfer data successfully.
Function Name : r_dtc_set_transfer_data Description : Applies configurations to a Transfer data area it is an internal function called by R_DTC_Create () ; and all arguments are validated in R_DTC_Create () Arguments : transfer_data Start address of Transfer data data_cfg Contains configurations for the Transfer data Return Value : DTC_SUCCESS Apply configurations for Transfer data successfully .
/* Cast type of "p_transfer_data" to match type of "p_td_ptr" */ /* Set for MRA - . */ /* Full-address mode */ /* Casting to match type of "t_mrc.BYTE" */ /* (DTC_ENABLE == DTC_CFG_SHORT_ADDRESS_MODE) */ /* Casting to match type of "t_mra.BYTE" */ /* Casting to match type of "t_mrb.BYTE" */ /* Casting to match type of "t_mra.BYTE" */ /* Casting to match type of "t_mrb.BYTE" */ /* (DTC_IP_VER_DTCb <= DTC_IP) */ /* DTC transfer mode */ /* Normal mode */ /* Transfer count = 65536 */ /* 1 - 65535 */ /* Cast type of "p_cfg->transfer_count" to uint16_t to match type of "t_cra.WORD" */ /* Repeat mode */ /* Set counter. */ /* count 1-255 */ /* Cast type of "p_cfg->transfer_count" to match type of "t_cra.BYTE.CRA_H" */ /* Cast type of "p_cfg->transfer_count" to match type of "t_cra.BYTE.CRA_L" */ /* Transfer count > 256 */ /* DTC_TRANSFER_MODE_BLOCK - Block transfer mode */ /* Set counter. */ /* Transfer count = 65536 */ /* 1 - 65535 */ /* Cast type of "p_cfg->transfer_count" to uint16_t to match type of "t_cra.WORD" */ /* Block size 1-255 */ /* Cast type of "p_cfg->block_size" to match type of "t_cra.BYTE.CRA_H" */ /* Cast type of "p_cfg->block_size" to match type of "t_cra.BYTE.CRA_L" */ /* Block size = 256 */ /* Invalid block size */ /* Short-address mode */ /* settings for fist long word: MRA & SAR */ /* clear */ /* 1 byte MRA */ /* 3 byte SAR */ /* settings for second long word: MRB & DAR */ /* clear */ /* 1 byte MRB */ /* 3 byte DAR */ /* settings for third long word: CRA & CRB */ /* Full-address mode */ /* settings for fist long word: MRA & MRB */ /* 1 byte MRA */ /* 1 byte MRB */ /* 1 byte MRC */ /* (DTC_IP_VER_DTCb <= DTC_IP) */ /* settings for second long word: SAR */ /* 4 byte SAR */ /* settings for third long word: DAR */ /* 4 byte DAR */ /* settings for fourth long word: CRA & CRB */ /* (DTC_ENABLE == DTC_CFG_SHORT_ADDRESS_MODE) */