interface design, multiple of the same peripherals

Thread Starter

bug13

Joined Feb 13, 2012
1,954
Hi team

I need to design an interface for a hardware. There are 5 UARTS in the MCU. just wondering which way is better. The goal is to have clean separation from the hardware and software. Which one is better??

For me, option 1 is cleaner. But option 2 is better if we need to loop through them. Thoughts?

Option 1:
C:
typedef struct UART
{
    void     (*writeOneByte)    (uint8_t data);
    uint8_t    (*readOneByte)        (void);
    /* others... */
}uartType;

typedef struct BOARD
{
    uartType uart1;
    uartType uart2;
    uartType uart3;
    uartType uart4;
    uartType uart5;
}boardType
Option 2:
C:
enum UART
{
    UART_1 = 0,
    UART_2,
    UART_3,
    UART_4,
    UART_5,
    UART_COUNTS,
}

typedef struct BOARD
{
    void     (*writeOneByte)        (enum UART uartNum, uint8_t data);
    uint8_t    (*readOneByte)        (enum UART uartNum);
}
 
Top