相关疑难解决方法(0)

`memcpy((void*)dest,src,n)``volatile`数组是否安全?

我有一个用于UART的缓冲区,它以这种方式声明:

union   Eusart_Buff {
    uint8_t     b8[16];
    uint16_t    b9[16];
};

struct  Eusart_Msg {
    uint8_t             msg_posn;
    uint8_t             msg_len;
    union Eusart_Buff   buff;
};

struct  Eusart {
    struct Eusart_Msg   tx;
    struct Eusart_Msg   rx;
};

extern  volatile    struct Eusart   eusart;
Run Code Online (Sandbox Code Playgroud)

这里是填充缓冲区的函数(将使用中断发送):

void    eusart_msg_transmit (uint8_t n, void *msg)
{

    if (!n)
        return;

    /*
     * The end of the previous transmission will reset
     * eusart.tx.msg_len (i.e. ISR is off)
     */
    while (eusart.tx.msg_len)
        ;

    if (data_9b) {
        memcpy((void *)eusart.tx.buff.b9, msg,
                sizeof(eusart.tx.buff.b9[0]) * n);
    } else {
        memcpy((void *)eusart.tx.buff.b8, …
Run Code Online (Sandbox Code Playgroud)

c casting interrupt volatile memcpy

9
推荐指数
1
解决办法
404
查看次数

标签 统计

c ×1

casting ×1

interrupt ×1

memcpy ×1

volatile ×1