One of the more challenging aspects of an embedded systems design is to maximize the time hardware and firmware can work independently while minimizing the time they have to wait for each other. The proper use and sizing of buffers can help balance the load between hardware and firmware.
An I/O block that can hold only one byte at a time constantly interrupts firmware for action. Buffers in the I/O block allow several bytes to be transmitted and/or received between interruptions to firmware. The question is how big should the buffers be? That depends on the application. Here are some general guidelines:
System Attribute | Guideline |
---|---|
Data packet size and burst size | The buffer should be big enough to hold all the bytes of a multi-byte packet or burst of bytes. The hardware block should be able to handle all bytes in a packet without requiring mid-packet intervention from the driver. |
Quantity of data | For large quantities of data with high-speed I/O, increasing the buffer size reduces the frequency and overhead of driver interrupts. If the driver is taking too much time to handle the data, increasing the buffer size can improve performance. |
Operating system | If there is no operating system or a very basic one, then a larger buffer size in hardware can help reduce firmware complexity. Conversely, firmware with proper operating system support is more likely to have separate drivers, each with its own threads and memory buffers, that can efficiently handle I/O traffic with smaller hardware buffers. |
Space on the chip | If space availability on the die is constrained, the size of the buffer may be limited, requiring firmware to take a bigger load. |
Synchronicity of data | If the protocol is such that more data cannot be received without first sending some sort of synchronization data, then the buffer needs to be only as big as the largest expected batch of synchronous data. If the data are asynchronous, the buffer should be sized bigger to accommodate multiple batches that may arrive before the driver has a chance to respond. |
Buffer location | Memory for smaller buffer sizes can be accommodated on the chip itself but it is fixed in size. For large and flexible buffer sizes, consider adding a DMA to access external memory. |
These and other system requirements may compete against each other in driving the buffer sizes and will require striking a proper balance.
This month’s newsletter ran out of buffer space, so I will allocate space in next month’s newsletter for a continuation of this discussion.
Until the next buffered issue…