'struct value pointed at remains unchanged
I have the following function, which should change the value of i2c_msg->size:
static int32_t mode_app_stop(struct v_mode *self)
{
struct i2c_msg_t *i2c_msg;
struct mode_app *app;
app = member_of(self, struct mode_app, mode);
i2c_msg = to_i2cmsg(app);
i2c_msg->size = 0;
.
. // continues here but irrelevant
.
}
struct app has an its own instance of i2c_msg_t, which is pointed to by i2c_msg. This does work and debugging this on an MSP430 it shows the same address as the one in the app struct. However after i2c_msg->size = 0 nothing changes. The value was 65535 and stays the same. If I change it in the debugger it works and the rest of the program continues with the correct value.
In these screenshots you can see the addresses and the values after the call to to_i2cmsg: register values after function call
I hope I could provide sufficient information
the structures and function calls are as follows
struct i2c_msg_t {
uint8_t rid;
uint8_t cmd;
uint8_t tid;
uint16_t size;
uint8_t cfg_id;
uint8_t pckt_size;
uint8_t pckt_num;
uint8_t buf[APP_MAX_MSG_SIZE];
};
struct v_mode {
struct mode_vtable const * ops;
struct info_record info_rec;
int32_t debug;
void *priv;
};
struct mode_app {
struct v_mode mode;
// Volatile data of application
struct volat_data {
bool is_open;
bool is_measuring;
bool clk_corr_enabled;
uint32_t irq;
struct clk_corr clk_cr;
struct msg msg;
struct i2c_msg_t i2c_msg;
uint32_t capture_num;
struct app_config cfg;
uint8_t uid[sizeof(uint32_t)];
struct timespec timestamp;
} volat_data;
};
#define member_of(ptr, type, member) \
((type *) ((uint8_t *)(ptr) - offsetof(type, member)))
static inline struct i2c_msg_t * to_i2cmsg(struct mode_app *app)
{
return &app->volat_data.i2c_msg;
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
