0
0
Embedded Cprogramming~5 mins

DMA with UART for bulk transfer in Embedded C - Time & Space Complexity

Choose your learning style9 modes available
Time Complexity: DMA with UART for bulk transfer
O(n)
Understanding Time Complexity

When using DMA with UART for bulk data transfer, it's important to understand how the time to complete the transfer changes as the data size grows.

We want to know how the program's work increases when sending more data using DMA and UART.

Scenario Under Consideration

Analyze the time complexity of the following code snippet.


// Start DMA transfer of data buffer over UART
void start_dma_uart_transfer(uint8_t *buffer, size_t length) {
    // Configure DMA source and destination
    DMA_SetSource(buffer);
    DMA_SetDestination(UART_DR);
    DMA_SetLength(length);
    DMA_Enable();
    UART_EnableDMA();
    // Transfer happens in background
}
    

This code starts a DMA transfer that sends a block of data over UART without CPU intervention during the transfer.

Identify Repeating Operations

Identify the loops, recursion, array traversals that repeat.

  • Primary operation: DMA hardware moves each byte from memory to UART data register.
  • How many times: Once per byte in the data buffer (length times).
How Execution Grows With Input

The DMA transfers each byte one by one in the background, so the total work grows as the number of bytes increases.

Input Size (n)Approx. Operations
1010 byte transfers
100100 byte transfers
10001000 byte transfers

Pattern observation: The number of operations grows directly with the size of the data.

Final Time Complexity

Time Complexity: O(n)

This means the time to transfer data grows linearly with the amount of data being sent.

Common Mistake

[X] Wrong: "DMA transfers all data instantly regardless of size."

[OK] Correct: DMA still moves each byte one at a time; larger data means more transfers and more time.

Interview Connect

Understanding how DMA offloads work from the CPU but still depends on data size helps you explain efficient data handling in embedded systems.

Self-Check

"What if we used interrupt-driven UART instead of DMA? How would the time complexity change?"