C ++ 03确定段的开头

时间:2015-03-18 20:13:38

标签: c++03

我正在开发一个32位嵌入式系统,每段闪存的大小为0x200。我正在尝试构建一个函数来更改段中的值,因此函数如下所示:

unsigned int cBSL_flash_set_array(const uint8_t* src_ptr,
                              uint8_t* dest_ptr,
                              unsigned int len,
                              const unsigned int seg_size) {
//  .   .   .   .   .   .   .   .   .   .   .   .   .   .
uint32_t mask = ~(seg_size - 1);

uint8_t* seg_start = dest_ptr & mask;     // Mask it

}

不幸的是编译器不会通过这个,说:

/work/c1202-firmware/msp430-OTP/otp/cBSL_hw_layer.c:229:37: error: invalid operands of types ‘uint8_t* {aka unsigned char*}’ and ‘uint32_t {aka unsigned int}’ to binary ‘operator&’
 uint8_t* seg_start = dest_ptr & mask;     // Mask it

任何想法如何掩盖它?

编辑:

这似乎有效,但只是屏蔽了很多步骤:

union Pointer {
   uint32_t loc;
   uint8_t* loc_ptr;
};

Pointer SegStart;                    // declare Pointer Union

SegStart.loc_ptr = dest_ptr;         // Set to destination

uint32_t rem = SegStart.loc & (seg_size - 1);  // figure out remainder

SegStart.loc -= rem;                 // start of segment

0 个答案:

没有答案