123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268 |
- #include <string.h>
- #include "ap_cp.h"
- #include "clock.h"
- #include "pwrmgr.h"
- #include "error.h"
- #include "log.h"
- #include "dma.h"
- typedef struct{
- bool init_flg;
-
- }dma_ctx_t;
- const static AP_DMACH_TypeDef* spDMACh[8] = {
- AP_DMACH0,
- AP_DMACH1,
- AP_DMACH2,
- AP_DMACH3,
- AP_DMACH4,
- AP_DMACH5,
- AP_DMACH6,
- AP_DMACH7,
- };
- dma_ctx_t s_dma_ctx = {
- .init_flg = FALSE,
- };
- const uint8_t DMA_LUTPerBurst[] = {
- DMA_BSIZE_1,
- DMA_BSIZE_32,
- DMA_BSIZE_4,
- DMA_BSIZE_4,
- DMA_BSIZE_4,
- DMA_BSIZE_4,
- DMA_BSIZE_4,
- DMA_BSIZE_4,
- DMA_BSIZE_4,
- DMA_BSIZE_1,
- DMA_BSIZE_1,
- DMA_BSIZE_1,
- DMA_BSIZE_1,
- DMA_BSIZE_1,
- DMA_BSIZE_1,
- DMA_BSIZE_1,
- DMA_BSIZE_1,
- DMA_BSIZE_1,
- DMA_BSIZE_1,
- DMA_BSIZE_1,
- DMA_BSIZE_1,
- DMA_BSIZE_1,
- DMA_BSIZE_32,
- DMA_BSIZE_32,
- 0,
- 0,
- DMA_BSIZE_1,
- DMA_BSIZE_1,
- DMA_BSIZE_1,
- DMA_BSIZE_1,
- DMA_BSIZE_1,
- DMA_BSIZE_1,
- };
- const uint8_t DMA_LUTPerWid[] = {
- DMA_WIDTH_WORD,
- DMA_WIDTH_WORD,
- DMA_WIDTH_BYTE,
- DMA_WIDTH_BYTE,
- DMA_WIDTH_BYTE,
- DMA_WIDTH_BYTE,
- DMA_WIDTH_BYTE,
- DMA_WIDTH_BYTE,
- DMA_WIDTH_WORD,
- DMA_WIDTH_BYTE,
- DMA_WIDTH_BYTE,
- DMA_WIDTH_BYTE,
- DMA_WIDTH_BYTE,
- DMA_WIDTH_BYTE,
- DMA_WIDTH_BYTE,
- DMA_WIDTH_BYTE,
- DMA_WIDTH_WORD,
- DMA_WIDTH_WORD,
- DMA_WIDTH_WORD,
- DMA_WIDTH_WORD,
- DMA_WIDTH_WORD,
- DMA_WIDTH_WORD,
- DMA_WIDTH_WORD,
- DMA_WIDTH_WORD,
- 0,
- 0,
- DMA_WIDTH_BYTE,
- DMA_WIDTH_BYTE,
- DMA_WIDTH_BYTE,
- DMA_WIDTH_BYTE,
- DMA_WIDTH_WORD,
- DMA_WIDTH_WORD,
- };
- int dma_config_channel(dma_ch_t ch, dma_ch_cfg_t* cfg)
- {
- AP_DMACH_TypeDef *pdma;
- uint32_t cctrl = 0;
- uint32_t transf_type = DMA_TRANSFERTYPE_M2M;
- uint32_t src_bsize = DMA_BSIZE_1;
- uint32_t dst_bsize = DMA_BSIZE_1;
- uint32_t src_wide = DMA_WIDTH_WORD;
- uint32_t dst_wide = DMA_WIDTH_WORD;
- if(!s_dma_ctx.init_flg)
- return PPlus_ERR_NOT_REGISTED;
- clk_gate_enable(MOD_DMA);
-
- if (AP_DMA->EnbldChns & (DMA_DMACEnbldChns_Ch(ch))) {
-
- return PPlus_ERR_BUSY;
- }
-
- pdma = (AP_DMACH_TypeDef *) spDMACh[ch];
-
- AP_DMA->IntTCClear = DMA_DMACIntTCClear_Ch(ch);
- AP_DMA->IntErrClr = DMA_DMACIntErrClr_Ch(ch);
-
- pdma->CControl = 0x00;
- pdma->CConfig = 0x00;
-
- pdma->CLLI = cfg->lli;
- if(cfg->src_conn && cfg->dst_conn){
- transf_type = DMA_TRANSFERTYPE_P2P;
- src_bsize = DMA_LUTPerBurst[cfg->src_conn];
- dst_bsize = DMA_LUTPerBurst[cfg->dst_conn];
- src_wide = DMA_LUTPerWid[cfg->src_conn];
- dst_wide = DMA_LUTPerWid[cfg->dst_conn];
- }
- else if(cfg->src_conn){
- transf_type = DMA_TRANSFERTYPE_P2M;
- src_bsize = DMA_LUTPerBurst[cfg->src_conn];
- src_wide = DMA_LUTPerWid[cfg->src_conn];
- }
- else if(cfg->dst_conn){
- transf_type = DMA_TRANSFERTYPE_M2P;
- dst_bsize = DMA_LUTPerBurst[cfg->dst_conn];
- dst_wide = DMA_LUTPerWid[cfg->dst_conn];
- }
- pdma->CSrcAddr = cfg->src_addr;
- pdma->CDestAddr = cfg->dst_addr;
-
-
- cctrl = DMA_DMACCxControl_TransferSize(cfg->transf_size)| \
- DMA_DMACCxControl_SBSize(src_bsize)| \
- DMA_DMACCxControl_DBSize(dst_bsize)| \
- DMA_DMACCxControl_SWidth(src_wide)| \
- DMA_DMACCxControl_DWidth(dst_wide);
- if(cfg->di)
- cctrl |= DMA_DMACCxControl_DI;
- if(cfg->si)
- cctrl |= DMA_DMACCxControl_SI;
-
- if(cfg->enable_int)
- cctrl |= DMA_DMACCxControl_I;
- pdma->CControl = cctrl;
-
- AP_DMA->Config = DMA_DMACConfig_E;
- while (!(AP_DMA->Config & DMA_DMACConfig_E));
-
-
- pdma->CConfig = DMA_DMACCxConfig_TransferType(transf_type)| \
- DMA_DMACCxConfig_SrcPeripheral(cfg->src_conn)| \
- DMA_DMACCxConfig_DestPeripheral(cfg->dst_conn);
- if(cfg->enable_int)
- pdma->CConfig |= DMA_DMACCxConfig_IE | DMA_DMACCxConfig_ITC;
- return PPlus_SUCCESS;
- }
- int dma_start_channel(dma_ch_t ch, bool enable)
- {
- AP_DMACH_TypeDef *pDMAch;
- if(!s_dma_ctx.init_flg)
- return PPlus_ERR_NOT_REGISTED;
-
-
- pDMAch = (AP_DMACH_TypeDef *) spDMACh[ch];
- if(enable){
- pDMAch->CConfig |= DMA_DMACCxConfig_E;
- } else {
- pDMAch->CConfig &= ~DMA_DMACCxConfig_E;
- }
- return PPlus_SUCCESS;
- }
- int dma_wait_channel_complete(dma_ch_t ch)
- {
- if(!s_dma_ctx.init_flg)
- return PPlus_ERR_NOT_REGISTED;
- return PPlus_SUCCESS;
- }
- int dma_init(void)
- {
- s_dma_ctx.init_flg = TRUE;
- return PPlus_SUCCESS;
- }
|