반응형
반응형
반응형
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
반응형
DMA 설명

DMA(Direct Memory Access) 설명

DMA란?

DMA(Direct Memory Access)는 CPU의 개입 없이 주변 장치와 메모리 간에 데이터를 직접 전송할 수 있는 기능입니다. DMA를 사용하면 CPU가 다른 작업을 수행하는 동안 데이터를 빠르게 전송할 수 있어 효율성이 증가합니다.

DMA의 주요 구성 요소

  • DMA 컨트롤러: 데이터 전송을 관리하는 장치로, 전송의 시작 주소, 전송 크기, 방향 등을 설정합니다.
  • 소스 주소: 데이터를 읽어올 주소입니다.
  • 목적지 주소: 데이터를 쓸 주소입니다.
  • 전송 크기: 한 번의 전송에서 이동할 데이터 크기입니다.
  • 인터럽트: DMA 전송 완료 후 CPU에 알리는 신호입니다.

DMA의 종류

DMA에는 다양한 종류가 있으며, 주요한 종류는 다음과 같습니다:

  • 버스트 모드 DMA: 한 번에 많은 데이터를 전송하는 방식입니다. CPU가 버스 사용을 완전히 포기하고 DMA가 모든 버스를 차지하여 빠르게 데이터를 전송합니다.
  • 사이클 스틸링 모드 DMA: CPU와 DMA가 번갈아가며 버스를 사용하는 방식으로, CPU의 작업을 방해하지 않고 데이터를 전송할 수 있습니다.
  • 블록 전송 모드 DMA: 한 번의 트랜잭션으로 큰 데이터 블록을 전송하며, 데이터가 많을 때 효율적인 방법입니다.

DMA 제어 방법

DMA는 다양한 제어 방법을 사용하여 데이터를 전송할 수 있습니다:

  • 소프트웨어 제어: CPU가 DMA 레지스터를 통해 직접 전송을 제어하는 방식입니다. 주로 초기화나 전송 시작을 위한 설정에 사용됩니다.
  • 하드웨어 요청: 주변 장치가 DMA 요청을 보내면, DMA 컨트롤러가 자동으로 데이터를 전송합니다. 주로 실시간 데이터 전송이 필요한 장치에서 사용됩니다.
  • 인터럽트 제어: 전송이 완료되면 DMA가 인터럽트를 발생시켜 CPU에 알리며, 이로 인해 CPU가 다른 작업을 수행할 수 있습니다.

DMA 펌웨어 코드 예시

#include <stdint.h>

#define DMA_BASE_ADDR 0x40026000  // DMA 컨트롤러의 베이스 주소
#define DMA_SRC_ADDR  0x20000000  // 소스 주소
#define DMA_DEST_ADDR 0x20001000  // 목적지 주소
#define DMA_SIZE      1024        // 전송할 데이터 크기

typedef struct {
    volatile uint32_t SRC_ADDR;   // 소스 주소 레지스터
    volatile uint32_t DEST_ADDR;  // 목적지 주소 레지스터
    volatile uint32_t SIZE;       // 전송 크기
    volatile uint32_t CTRL;       // 제어 레지스터
    volatile uint32_t STATUS;     // 상태 레지스터
} DMA_TypeDef;

#define DMA ((DMA_TypeDef *)DMA_BASE_ADDR)

void dma_init() {
    // DMA 소스 및 목적지 주소 설정
    DMA->SRC_ADDR = DMA_SRC_ADDR;
    DMA->DEST_ADDR = DMA_DEST_ADDR;

    // DMA 전송 크기 설정
    DMA->SIZE = DMA_SIZE;

    // DMA 전송 시작
    DMA->CTRL = 1;  // 제어 비트를 설정하여 DMA 전송을 시작
}

int main() {
    dma_init();

    // DMA가 완료될 때까지 대기
    while ((DMA->STATUS & 0x1) == 0) {
        // 전송 완료를 대기
    }

    // 전송 완료
    return 0;
}
    
반응형

'IT' 카테고리의 다른 글

Embedded System Boot Process  (3) 2024.11.04
DMA Explanation  (1) 2024.11.04
멀티스레딩에 대한 소개  (1) 2024.11.04
Introduction to Multithreading  (1) 2024.11.04
Understanding Mutex and Semaphore – A Practical Example for Synchronization  (2) 2024.11.04

+ Recent posts