最近在调试一个简单的网卡裸板收发包demo,组包和拆包时,需要使用dma,而我所使用的处理器的dma是128bit对齐的,因此,在使用dma时,需要保证16字节对齐。采用的对齐方式如下:
#pragma pack(16)
u8 __attribute__((aligned(16)))packet[74] = {0x00,0x24,0x8c,0x62,0x5e,0x18,0x00,0x55,0x7b,0xb5,0x7d,0xf7,0x41,0x43,0x4b,0x21,
0x0c,0x0c,0x0c,0x0c,0x0c,0x0c,0x0c,0x0c,0x0c,0x0c,0x0c,0x0c,0x0c,0x0c,0x0c,0x0c,
0x0c,0x0c,0x0c,0x0c,0x0c,0x0c,0x0c,0x0c,0x5e,0x2f,0x61,0x60,0x63,0x64,0x65,0x64,
0x67,0x68,0x69,0x68,0x6b,0x6c,0x6d,0x6c,0x6f,0x70,0x71,0x70,0x73,0x74,0x75,0x74,
0x77,0x61,0x60,0x63,0x64,0x65,0x64,0x67,0x60,0x69
};
#pragma pack()
__attribute__((aligned(16)))表示为数组packet分配地址空间时,按照16字节对齐。