반응형
DMA Explanation

DMA (Direct Memory Access) Explanation

What is DMA?

DMA (Direct Memory Access) is a functionality that allows data to be transferred directly between memory and peripheral devices without CPU intervention. By using DMA, data can be transferred quickly while the CPU is free to perform other tasks, increasing efficiency.

Main Components of DMA

  • DMA Controller: A device that manages data transfers by setting the starting address, transfer size, and direction.
  • Source Address: The address from which data will be read.
  • Destination Address: The address where data will be written.
  • Transfer Size: The size of data to be transferred in one operation.
  • Interrupt: A signal that notifies the CPU when the DMA transfer is complete.

Types of DMA

There are various types of DMA, including:

  • Burst Mode DMA: Transfers a large amount of data at once, allowing DMA to take full control of the bus while the CPU pauses its tasks.
  • Cycle Stealing Mode DMA: Allows the CPU and DMA to share the bus, enabling data transfer without fully interrupting the CPU’s tasks.
  • Block Transfer Mode DMA: Transfers a large block of data in a single transaction, efficient for handling large data volumes.

DMA Control Methods

DMA transfers can be controlled in different ways:

  • Software Control: The CPU directly controls DMA registers to initialize and start transfers, mainly used for initial setup.
  • Hardware Request: Peripherals send requests to the DMA controller, which automatically transfers data. This is often used in real-time applications.
  • Interrupt Control: Once the transfer is complete, DMA generates an interrupt to notify the CPU, allowing the CPU to handle other tasks during transfer.

DMA Firmware Code Example

#include <stdint.h>

#define DMA_BASE_ADDR 0x40026000  // Base address of the DMA controller
#define DMA_SRC_ADDR  0x20000000  // Source address
#define DMA_DEST_ADDR 0x20001000  // Destination address
#define DMA_SIZE      1024        // Size of data to transfer

typedef struct {
    volatile uint32_t SRC_ADDR;   // Source address register
    volatile uint32_t DEST_ADDR;  // Destination address register
    volatile uint32_t SIZE;       // Transfer size register
    volatile uint32_t CTRL;       // Control register
    volatile uint32_t STATUS;     // Status register
} DMA_TypeDef;

#define DMA ((DMA_TypeDef *)DMA_BASE_ADDR)

void dma_init() {
    // Set the DMA source and destination addresses
    DMA->SRC_ADDR = DMA_SRC_ADDR;
    DMA->DEST_ADDR = DMA_DEST_ADDR;

    // Set the DMA transfer size
    DMA->SIZE = DMA_SIZE;

    // Start the DMA transfer
    DMA->CTRL = 1;  // Set the control bit to start DMA transfer
}

int main() {
    dma_init();

    // Wait for DMA transfer to complete
    while ((DMA->STATUS & 0x1) == 0) {
        // Waiting for transfer completion
    }

    // Transfer completed
    return 0;
}
    
반응형

'IT' 카테고리의 다른 글

임베디드 시스템 부트 프로세스  (3) 2024.11.04
Embedded System Boot Process  (3) 2024.11.04
DMA(Direct Memory Access) 설명  (1) 2024.11.04
멀티스레딩에 대한 소개  (1) 2024.11.04
Introduction to Multithreading  (1) 2024.11.04

+ Recent posts