Part Number: CC2650
Tool/software: TI-RTOS
Hello,
My code below crashes sensor controller studio. It only happens when I try to use a macro. Am I using macros correctly? Also I tried using a function but that not seem to work and the documentation was not really clear on how to use them.
Video of application crashing:
My code:
macro write_to_buffer(data, size) {
// U16 data = 5;
// U16 size = 4;
// variable declarations
U16 element;
U16 shift_by;
// let's us know how much space we have left in current row
U16 space_left = ARRAYSIZE - state.bitpt;
// special variable to access array
U16 n = state.elempt;
if (size <= space_left) {
// enough for one array
shift_by = space_left - size;
element = output.BUFFER[n];
element = element | (data << shift_by);
output.BUFFER[n] = element;
state.bitpt += size;
if (state.bitpt == ARRAYSIZE) {
state.bitpt = 0;
n += 1;
if (n == BUF_ARR_LEN) {
n = 0;
// we are looping over in the ring buffer
}
}
} else {
// have to split into two arrays
shift_by = size - space_left;
element = output.BUFFER[n];
element = element | (data >> shift_by);
output.BUFFER[n] = element;
n += 1;
if (n == BUF_ARR_LEN) {
n = 0;
// we are looping over in the ring buffer
}
shift_by = (ARRAYSIZE - size) - space_left;
element = output.BUFFER[n];
element = element | (data << shift_by);
output.BUFFER[n] = element;
state.bitpt = size - space_left;
}
state.elempt = n;
}
write_to_buffer(15, 4);