在IAR工程中添加如下代码段
...
extern apsGroupItem_t *apsGroupTable;
struct apsGroupNVItem {
uint8 endpoint;
aps_Group_t group;
};
apsGroupItem_t *pLoop = apsGroupTable;
struct apsGroupNVItem item;
if (id == ZCD_NV_GROUP_TABLE)
{
if (restoreInProgress_NLME)
return NV_OPER_FAILED; // don't write to NV group table while a restore is in progress
// write correctly to NV group table
uint16 i = 0;
while ( pLoop )
{
// Build the record
item.endpoint = pLoop->endpoint;
OsalPort_memcpy( &(item.group), &(pLoop->group), sizeof ( aps_Group_t ) );
OsalPort_memcpy(buf + (uint16)((sizeof(uint16)) + (i * sizeof ( struct apsGroupNVItem ))), &item, sizeof ( struct apsGroupNVItem ));
...
编译过程中报出函数OsalPort_memcpy Error[Pe852]: expression must be a pointer to a complete object type问题,首先怀疑是接口内某个结构体定义或声明问题,将能定义的结构体重新在上面定义之后,问题依旧,最后参考其他网友的类似经历,OsalPort_memcpy的第一个参数是void *,在实际使用过程中,必须要告知编译器这个指针一次移动的基本单位,比如一个字节(32位机)那就是uint8 *,两个字节就是uint16 *,也就是使用时必须要强制类型转换来告知编译器这个指针每次偏移的基本单位,不然就报上面的错误。。
改成如下
OsalPort_memcpy((uint8 *)buf + (uint16)((sizeof(uint16)) + (i * sizeof ( struct apsGroupNVItem ))), &item, sizeof ( struct apsGroupNVItem ));
编译通过。