I am getting this fault when i try to run a observer handler where i have implemented semaphores.

And i cant figure out what this error code means
Thanks in advance
I am getting this fault when i try to run a observer handler where i have implemented semaphores.

And i cant figure out what this error code means
Thanks in advance
Hello!
It would probably help with a bit more context.
What are you trying to do?
Are your semaphores properly defined when you use them?
Best regards,
Einar
Hi!
I am trying to create an algorithm that uses an observer with an accept list to get the rssi value of an beacon(another NRF52DK). We are using an antenna switch that are giving us the possibility to measure the rssi value of two antennas.
The algorithm are supposed to activate the observer which send the rssi values to a data processor, alternating between the antennas. Here I have used an semaphore to wait until the observer have processed x numbers of rssi values. After the observer have processed the rssi values it releases the semaphore which lets our algorithm "get" the values from the data processor. The algorithm does this x-amount of times before it ends.
The error occurs after the algorithm are done, which makes the system to restart.
When running the code, i get the correct values from the Logging i have implemented in the code.
Main c
#include "initiater.h"
#include "search.h"
#define LOG_MODULE_NAME app
K_SEM_DEFINE(my_sem,0,1);
LOG_MODULE_REGISTER(LOG_MODULE_NAME);
int azimuth_reading[20][3];
int nulls_azimuth[1];
int min_encoder_search = 0;
int16_t max_encoder_search = 20;
int increment = 1;
void main(void)
{
LOG_INF("Hello World! %s\n", CONFIG_BOARD);
initiate_modules();
k_sem_give(&my_sem);
sweep_search(0, min_encoder_search, max_encoder_search,increment);
k_sem_take(&my_sem, K_FOREVER);
// if(err){
// LOG_ERR("err:%d", err);
// }
while(1){
}
}
Search.c
#include "search.h"
#define LOG_MODULE_NAME SEARCHER
LOG_MODULE_REGISTER(LOG_MODULE_NAME);
extern struct k_sem my_sem;
void sweep_search(bool state, int min_encoder_search, int16_t max_encoder_search, int increment){
LOG_INF("Starting to search in Azimuth");
int16_t readings[][3] = {0};
int16_t index = 0;
for (int i = 0; i < 10; i+= 1){
//move_servo(state, i) bevege servo enten i asimuth til enkoder verdi i (ikke implementert enda)
int16_t *buffer_data;
LOG_INF("started");
set_observer(true);
LOG_INF("waiting");
k_sem_take(&my_sem, K_FOREVER);
LOG_INF("next");
buffer_data = get_data();
for (int i = 0; i < 3; i++){
readings[index][i] = buffer_data[i];
}
int16_t encoder = readings[index][0];
int16_t delta = readings[index][1];
int16_t zigma = readings[index][2];
LOG_INF("Encoder: %d, Delta: %d, Zigma %d, i: %d: ",encoder, delta, zigma, index);
index+=1;
}
k_sem_give(&my_sem);
LOG_INF("Azimuth search done");
}
Observer.c
#include "observer.h"
#define LOG_MODULE_NAME Observer
#define average_counter 5
LOG_MODULE_REGISTER(LOG_MODULE_NAME);
extern struct k_sem my_sem;
bool send_data_state = true;
int set_observer(bool state){
int err = 1;
send_data_state = state;
LOG_INF("Observer state changed to %d", send_data_state);
return err = 0;
}
void set_switch(int state){
//set gpio switch to value;
}
static void device_found(const bt_addr_le_t *addr, int8_t rssi, uint8_t type,
struct net_buf_simple *ad)
{
if(send_data_state){
// rssi = KALMAN(rssi);
static int counter = 0;
static bool delta_zigma_state = false; // 0 = delta, 1 = zigma, 2 = done
if(!delta_zigma_state){
LOG_INF("counter: %d, rssi: %d, zigma: %d",counter,rssi,delta_zigma_state);
send_data_delta(rssi, counter);
counter +=1;
if(counter >= average_counter){
counter = 0;
delta_zigma_state = true;
}
}
else if(delta_zigma_state){
LOG_INF("counter: %d, rssi: %d, zigma: %d ",counter,rssi, delta_zigma_state);
send_data_zigma(rssi, counter);
counter += 1;
if(counter >= average_counter){
delta_zigma_state = false;
counter = 0;
set_observer(false);
k_sem_give(&my_sem);
LOG_INF("given");
}
}
}
else{LOG_INF("rssi: %d", rssi);}
}
int add_filter_accept_list_from_string(const char *addr_str,const char *type){
int err;
bt_addr_le_t addr_le = {.a = BT_ADDR_LE_ANY, .type = BT_ADDR_LE_RANDOM};
err = bt_addr_le_from_str(addr_str, type, &addr_le);
if (err){
LOG_ERR("error: %d", err);
}
err = bt_le_filter_accept_list_add(&addr_le);
if (err){
LOG_ERR("Could not add to acceptlist (error: %d)", err);
return err;
}
return err;
}
int init_bluethooth_scan(){
struct bt_le_scan_param scan_param = {
.type = BT_LE_SCAN_TYPE_ACTIVE,
.options = BT_LE_SCAN_OPT_FILTER_ACCEPT_LIST,
.interval = BT_GAP_SCAN_FAST_INTERVAL,
.window = BT_GAP_SCAN_FAST_WINDOW,
};
int err;
LOG_INF("Starting Observer\n");
/* Initialize the Bluetooth Subsystem */
err = bt_enable(NULL);
if (err) {
LOG_ERR("Bluetooth init failed (err %d)\n", err);
return err;
}
err = add_filter_accept_list_from_string("C8:4A:E6:23:F5:13", "(random)");
if (err){
LOG_ERR("Could not add to acceptlist (error: %d)", err);
return err;
}
LOG_INF("Bluetooth initialized\n");
err = bt_le_scan_start(&scan_param, device_found);
if (err) {
LOG_ERR("Starting scanning failed (err %d)\n", err);
return err;
}
return err;
}
Dataprocessor.c
#include "data_processor.h"
#define LOG_MODULE_NAME DATA_PROCESSOR
#define average_counter 5
LOG_MODULE_REGISTER(LOG_MODULE_NAME);
int8_t data_delta[average_counter];
int8_t data_zigma[average_counter];
void send_data_delta(int8_t rssi, int index){
data_delta[index] = rssi;
}
void send_data_zigma(int8_t rssi, int index){
data_zigma[index] = rssi;
}
int16_t *get_data(){
static int16_t buffer_data[3];
buffer_data[0] = (int16_t) get_encoder();
buffer_data[1] = (int16_t) get_average(data_delta);
buffer_data[2] = (int16_t) get_average(data_zigma);
return buffer_data;
}
int8_t get_average(int8_t *list){
int16_t average = 0;
int8_t size = average_counter;
for(int i = 0; i < size; i++){
average += list[i];
}
average = average/size;
return (int8_t) average;
}
prj.conf # Configure logger CONFIG_LOG=y CONFIG_USE_SEGGER_RTT=n CONFIG_LOG_BACKEND_UART=y CONFIG_LOG_DEFAULT_LEVEL=3 #From observer CONFIG_BT=y CONFIG_BT_OBSERVER=y # Configure buttons and LEDs CONFIG_GPIO=y CONFIG_DK_LIBRARY=y # Enable the BLE modules from NCS CONFIG_BT_NUS_CLIENT=y CONFIG_BT_CENTRAL=y CONFIG_BT_SCAN=y CONFIG_BT_SCAN_FILTER_ENABLE=y CONFIG_BT_SCAN_UUID_CNT=1 CONFIG_BT_GATT_DM=y CONFIG_HEAP_MEM_POOL_SIZE=2048 CONFIG_BT_FILTER_ACCEPT_LIST=y CONFIG_BT_SCAN_NAME_CNT=1 #Servomotors CONFIG_GPIO=y CONFIG_DK_LIBRARY=y # Enable math.h CONFIG_NEWLIB_LIBC=y #vet ikke CONFIG_MAIN_STACK_SIZE=1024 CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=4096
Hope this gives a better picture of what I am trying to implement.
Thanks in advance.
Hi!
I am trying to create an algorithm that uses an observer with an accept list to get the rssi value of an beacon(another NRF52DK). We are using an antenna switch that are giving us the possibility to measure the rssi value of two antennas.
The algorithm are supposed to activate the observer which send the rssi values to a data processor, alternating between the antennas. Here I have used an semaphore to wait until the observer have processed x numbers of rssi values. After the observer have processed the rssi values it releases the semaphore which lets our algorithm "get" the values from the data processor. The algorithm does this x-amount of times before it ends.
The error occurs after the algorithm are done, which makes the system to restart.
When running the code, i get the correct values from the Logging i have implemented in the code.
Main c
#include "initiater.h"
#include "search.h"
#define LOG_MODULE_NAME app
K_SEM_DEFINE(my_sem,0,1);
LOG_MODULE_REGISTER(LOG_MODULE_NAME);
int azimuth_reading[20][3];
int nulls_azimuth[1];
int min_encoder_search = 0;
int16_t max_encoder_search = 20;
int increment = 1;
void main(void)
{
LOG_INF("Hello World! %s\n", CONFIG_BOARD);
initiate_modules();
k_sem_give(&my_sem);
sweep_search(0, min_encoder_search, max_encoder_search,increment);
k_sem_take(&my_sem, K_FOREVER);
// if(err){
// LOG_ERR("err:%d", err);
// }
while(1){
}
}
Search.c
#include "search.h"
#define LOG_MODULE_NAME SEARCHER
LOG_MODULE_REGISTER(LOG_MODULE_NAME);
extern struct k_sem my_sem;
void sweep_search(bool state, int min_encoder_search, int16_t max_encoder_search, int increment){
LOG_INF("Starting to search in Azimuth");
int16_t readings[][3] = {0};
int16_t index = 0;
for (int i = 0; i < 10; i+= 1){
//move_servo(state, i) bevege servo enten i asimuth til enkoder verdi i (ikke implementert enda)
int16_t *buffer_data;
LOG_INF("started");
set_observer(true);
LOG_INF("waiting");
k_sem_take(&my_sem, K_FOREVER);
LOG_INF("next");
buffer_data = get_data();
for (int i = 0; i < 3; i++){
readings[index][i] = buffer_data[i];
}
int16_t encoder = readings[index][0];
int16_t delta = readings[index][1];
int16_t zigma = readings[index][2];
LOG_INF("Encoder: %d, Delta: %d, Zigma %d, i: %d: ",encoder, delta, zigma, index);
index+=1;
}
k_sem_give(&my_sem);
LOG_INF("Azimuth search done");
}
Observer.c
#include "observer.h"
#define LOG_MODULE_NAME Observer
#define average_counter 5
LOG_MODULE_REGISTER(LOG_MODULE_NAME);
extern struct k_sem my_sem;
bool send_data_state = true;
int set_observer(bool state){
int err = 1;
send_data_state = state;
LOG_INF("Observer state changed to %d", send_data_state);
return err = 0;
}
void set_switch(int state){
//set gpio switch to value;
}
static void device_found(const bt_addr_le_t *addr, int8_t rssi, uint8_t type,
struct net_buf_simple *ad)
{
if(send_data_state){
// rssi = KALMAN(rssi);
static int counter = 0;
static bool delta_zigma_state = false; // 0 = delta, 1 = zigma, 2 = done
if(!delta_zigma_state){
LOG_INF("counter: %d, rssi: %d, zigma: %d",counter,rssi,delta_zigma_state);
send_data_delta(rssi, counter);
counter +=1;
if(counter >= average_counter){
counter = 0;
delta_zigma_state = true;
}
}
else if(delta_zigma_state){
LOG_INF("counter: %d, rssi: %d, zigma: %d ",counter,rssi, delta_zigma_state);
send_data_zigma(rssi, counter);
counter += 1;
if(counter >= average_counter){
delta_zigma_state = false;
counter = 0;
set_observer(false);
k_sem_give(&my_sem);
LOG_INF("given");
}
}
}
else{LOG_INF("rssi: %d", rssi);}
}
int add_filter_accept_list_from_string(const char *addr_str,const char *type){
int err;
bt_addr_le_t addr_le = {.a = BT_ADDR_LE_ANY, .type = BT_ADDR_LE_RANDOM};
err = bt_addr_le_from_str(addr_str, type, &addr_le);
if (err){
LOG_ERR("error: %d", err);
}
err = bt_le_filter_accept_list_add(&addr_le);
if (err){
LOG_ERR("Could not add to acceptlist (error: %d)", err);
return err;
}
return err;
}
int init_bluethooth_scan(){
struct bt_le_scan_param scan_param = {
.type = BT_LE_SCAN_TYPE_ACTIVE,
.options = BT_LE_SCAN_OPT_FILTER_ACCEPT_LIST,
.interval = BT_GAP_SCAN_FAST_INTERVAL,
.window = BT_GAP_SCAN_FAST_WINDOW,
};
int err;
LOG_INF("Starting Observer\n");
/* Initialize the Bluetooth Subsystem */
err = bt_enable(NULL);
if (err) {
LOG_ERR("Bluetooth init failed (err %d)\n", err);
return err;
}
err = add_filter_accept_list_from_string("C8:4A:E6:23:F5:13", "(random)");
if (err){
LOG_ERR("Could not add to acceptlist (error: %d)", err);
return err;
}
LOG_INF("Bluetooth initialized\n");
err = bt_le_scan_start(&scan_param, device_found);
if (err) {
LOG_ERR("Starting scanning failed (err %d)\n", err);
return err;
}
return err;
}
Dataprocessor.c
#include "data_processor.h"
#define LOG_MODULE_NAME DATA_PROCESSOR
#define average_counter 5
LOG_MODULE_REGISTER(LOG_MODULE_NAME);
int8_t data_delta[average_counter];
int8_t data_zigma[average_counter];
void send_data_delta(int8_t rssi, int index){
data_delta[index] = rssi;
}
void send_data_zigma(int8_t rssi, int index){
data_zigma[index] = rssi;
}
int16_t *get_data(){
static int16_t buffer_data[3];
buffer_data[0] = (int16_t) get_encoder();
buffer_data[1] = (int16_t) get_average(data_delta);
buffer_data[2] = (int16_t) get_average(data_zigma);
return buffer_data;
}
int8_t get_average(int8_t *list){
int16_t average = 0;
int8_t size = average_counter;
for(int i = 0; i < size; i++){
average += list[i];
}
average = average/size;
return (int8_t) average;
}
prj.conf # Configure logger CONFIG_LOG=y CONFIG_USE_SEGGER_RTT=n CONFIG_LOG_BACKEND_UART=y CONFIG_LOG_DEFAULT_LEVEL=3 #From observer CONFIG_BT=y CONFIG_BT_OBSERVER=y # Configure buttons and LEDs CONFIG_GPIO=y CONFIG_DK_LIBRARY=y # Enable the BLE modules from NCS CONFIG_BT_NUS_CLIENT=y CONFIG_BT_CENTRAL=y CONFIG_BT_SCAN=y CONFIG_BT_SCAN_FILTER_ENABLE=y CONFIG_BT_SCAN_UUID_CNT=1 CONFIG_BT_GATT_DM=y CONFIG_HEAP_MEM_POOL_SIZE=2048 CONFIG_BT_FILTER_ACCEPT_LIST=y CONFIG_BT_SCAN_NAME_CNT=1 #Servomotors CONFIG_GPIO=y CONFIG_DK_LIBRARY=y # Enable math.h CONFIG_NEWLIB_LIBC=y #vet ikke CONFIG_MAIN_STACK_SIZE=1024 CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=4096
Hope this gives a better picture of what I am trying to implement.
Thanks in advance.
Thank you for explaining.
Do you know exactly what line of code your program crashes on?
-Einar