diff --git a/MCAL_Drivers/DMA/include/DMA_config.h b/MCAL_Drivers/DMA/include/DMA_config.h new file mode 100755 index 0000000..5e6cb33 --- /dev/null +++ b/MCAL_Drivers/DMA/include/DMA_config.h @@ -0,0 +1,14 @@ +/*****************************************/ +/* Author : Gehad Elkoumy */ +/* Version : V01 */ +/* Date : 23 April 2023 */ +/*****************************************/ + +#ifndef DMA_CONFIG_H +#define DMA_CONFIG_H + +/* Options : channels from 1 to 7 */ +//#define channelID 1 + + +#endif diff --git a/MCAL_Drivers/DMA/include/DMA_interface.h b/MCAL_Drivers/DMA/include/DMA_interface.h new file mode 100755 index 0000000..4e89e55 --- /dev/null +++ b/MCAL_Drivers/DMA/include/DMA_interface.h @@ -0,0 +1,13 @@ +/*****************************************/ +/* Author : Gehad Elkoumy */ +/* Version : V01 */ +/* Date : 23 April 2023 */ +/*****************************************/ + +#ifndef DMA_INTERFACE_H_ +#define DMA_INTERFACE_H_ + +void MDMA_voidChannel1Init(void); +void MDMA_voidChannel1Start(u32 *Copy_Pointeru32SourceAddress, u32 *Copy_Pointer32DestinationAddress, u16 Copy_u16BlockLength); + +#endif \ No newline at end of file diff --git a/MCAL_Drivers/DMA/include/DMA_private.h b/MCAL_Drivers/DMA/include/DMA_private.h new file mode 100755 index 0000000..b543730 --- /dev/null +++ b/MCAL_Drivers/DMA/include/DMA_private.h @@ -0,0 +1,32 @@ +/*****************************************/ +/* Author : Gehad Elkoumy */ +/* Version : V01 */ +/* Date : 23 April 2023 */ +/*****************************************/ + +#ifndef DMA_PRIVATE_H_ +#define DMA_PRIVATE_H_ + +/*Array for 7 channels*/ +typedef struct +{ + volatile u32 CCR; + volatile u32 CNDTR; + volatile u32 CPAR; + volatile u32 CMAR; + volatile u32 Reserved; +}DMA_Channel; + +typedef struct +{ + /*flags for the 7 channels*/ + volatile u32 ISR; + volatile u32 IFCR; + + /*each register is an array of 7 elements(each channel has a register)*/ + DMA_Channel Channel[7]; +}DMA_t; + +#define DMA ((volatile DMA_t*)0x40020000) + +#endif \ No newline at end of file diff --git a/MCAL_Drivers/DMA/src/DMA_program.c b/MCAL_Drivers/DMA/src/DMA_program.c new file mode 100755 index 0000000..c39f7fd --- /dev/null +++ b/MCAL_Drivers/DMA/src/DMA_program.c @@ -0,0 +1,48 @@ +/*****************************************/ +/* Author : Gehad Elkoumy */ +/* Version : V01 */ +/* Date : 23 April 2023 */ +/*****************************************/ + +#include "STD_TYPES.h" +#include "BIT_MATH.h" + +#include "DMA_interface.h" +#include "DMA_private.h" +#include "DMA_config.h" + +void MDMA_voidChannel1Init(void) +{ + /* channel priority level is low */ + /* Memory size of 16-bits */ + SET_BIT(DMA->Channel[0].CCR , 10); + CLR_BIT(DMA->Channel[0].CCR , 11); + + /* Peripheral size of 16-bits */ + SET_BIT(DMA->Channel[0].CCR , 8); + CLR_BIT(DMA->Channel[0].CCR , 9); + + /* Enable memory increment mode */ + SET_BIT(DMA->Channel[0].CCR , 7); + + /* Enable circular mode */ + SET_BIT(DMA->Channel[0].CCR , 5); + +} + + +void MDMA_voidChannel1Start(u32 *Copy_Pointer32SourceAddress, u32 *Copy_Pointeru32DestinationAddress, u16 Copy_u16BlockLength) +{ + /* channel must be disabled first */ + CLR_BIT(DMA->Channel[0].CCR , 0); + + /*Load the source & destination addresses*/ + DMA->Channel[0].CPAR = Copy_Pointer32SourceAddress; + DMA->Channel[0].CMAR = Copy_Pointeru32DestinationAddress; + + /*Load the block length*/ + DMA->Channel[0].CNDTR = Copy_u16BlockLength; + + /*Enable channel*/ + SET_BIT(DMA->Channel[0].CCR , 0); +}