will wkupct callback function interrupt user_custs1_xxx_wr_ind_handler

⚠️
Hi there.. thanks for coming to the forums. Exciting news! we’re now in the process of moving to our new forum platform that will offer better functionality and is contained within the main Dialog website. All posts and accounts have been migrated. We’re now accepting traffic on the new forum only - please POST any new threads at//www.xmece.com/support. We’ll be fixing bugs / optimising the searching and tagging over the coming days.
6 posts / 0 new
Last post
ops.
Offline
Last seen:10 months 4 weeks ago
Joined:2016-01-04 09:20
will wkupct callback function interrupt user_custs1_xxx_wr_ind_handler

Dear Dialog Support Team;

I am building a project based on DA14583 SDK 5.0.4 sample code ble_app_peripheral.

我们的项目使用SPI G-Sensor和DA14583内部SPI闪光,但DA14583只有一个SPI控制器。

So we can access only one of these SPI devices at the same time. We use G-Sensor's interrupt pin to notify DA14583 for reading sampling data.

代码是这样的(简化):

----------- Code A --------------

wkupct_register_callback(wkup_callback);

wkupct_enable_irq(...);

void wkup_callback(){

app_easy_timer(1, app_easy_timer_cb);

}

void app_easy_timer_cb() {

(access G-Sensor via SPI interface to read out sampling data)

}

And user will send command via ble characteristic's write action, that will make system save some data to internal SPI Flash.

我在user_custs1_ctrl_wr_ind_handler()函数下实现此要求。

代码是这样的(简化):

----------- Code B ----------------

void user_custs1_ctrl_wr_ind_handler(...){

if(param->值[0] == 0x01)(将数据写入SPI Flash)

}

I want to ask: "Will wkup_callback() function or app_easy_timer_cb() function (at Code A) interrupt the execute of user_custs1_ctrl_wr_ind_handler() function (at Code B)? vice versa." or the SDK API will make sure these callback function or handler function will execute completely without break (interrupt) by another callback or handler function? In short, do I face a race condition? Do I need to add some synchronize mechanism?

Thanks a lot.

设备:
PM_Dialog
Online
Last seen:3 min 25 sec ago
Staff
Joined:2018-02-08 11:03
嗨ops,

嗨ops,

To be honest, I cannot completely understand what you are trying to accomplish. The user_custs1_ctrl_wr_ind_handler() will be triggered when the Control Point characteristic is written for the peer device. The WKUP callback function will be triggered as soon as a wake-up interrupt is detected to the wake-up controller. The app_easy_timer_cb() will be triggered if you set up a timer. Can you please provide me more inputs on that? Have you set up a timer? In addition, why don’t you use the APIs from the SPI flash driver?

Thanks, PM_Dialog

ops.
Offline
Last seen:10 months 4 weeks ago
Joined:2016-01-04 09:20
Hi, PM_Dialog;

Hi, PM_Dialog;

Thanks for your quick response.

1.我确实使用SPI Flash驱动程序访问内部闪存。当写入控制点特性时,我可以将一些数据保存到闪存。这项工作很好。我的代码看起来像:

void user_custs1_ctrl_wr_ind_handler(...){

GPIO_ConfigurePin(FLASH_CS_PORT, FLASH_CS_PIN, OUTPUT, PID_SPI_EN, true);
gpio_configurepin(flash_clk_port,flash_clk_pin,输出,pid_spi_clk,false);
gpio_configurepin(flash_do_port,flash_do_pin,输出,pid_spi_do,false);
gpio_configurepin(flash_di_port,flash_di_pin,输入,pid_spi_di,false);

spi_init(&spi_flash_cs_pad,spi_mode_8bit,spi_rool_master,spi_clk_dle_pol_low,spi_pha_mode_0,spi_mint_disable,spi_xtal_div_8);

spi_flash_init(SPI_FLASH_SIZE, SPI_FLASH_PAGE);

// point A

spi_flash_block_erase(configaddress,sector_erase);

spi_flash_write_data (&configData[0], ConfigAddress, sizeof(configData));

...

}

2.当它的缓冲区已满时,我有一个G-Sensor,它会产生脉冲(DA14583的外部中断)。发生此事件时,我使用WKUP回调函数从G-Sensor的缓冲区VIS界面读出所有数据。这也很好。但是,我注意到错误发生在此WKUP回调函数中的错误。似乎我在WKUP回调函数时做了太多的作品,导致某种超时!这就是为什么我正在使用app_easy_timer()来安排WKUP回调函数的一枪App_easy_timer_cb()。通过这种方式,WKUP回调函数只是进行计时器计划工作,因此它不再导致timerout了。并且真实的工作留给了App_easy_timer_cb()函数。这个策略为我工作,但如果不是批判,请纠正我!

So, the app_easy_timer_cb() look like:

void app_easy_timer_cb(void){

spi_init(&spi_gsensor_cs_pad,spi_mode_8bit,spi_rool_master,spi_clk_idle_pol_low,spi_pha_mode_0,spi_mint_disable,spi_xtal_div_8);

... // read G-Sensor data from SPI interface

}

3. The problem come from both Flash and G-Sensor are using SPI interface, and DA14583 had just one spi controller! when I access Flash, I must make sure

GPIO_ConfigurePin(FLASH_CS_PORT, FLASH_CS_PIN, OUTPUT, PID_SPI_EN, true);
gpio_configurepin(flash_clk_port,flash_clk_pin,输出,pid_spi_clk,false);
gpio_configurepin(flash_do_port,flash_do_pin,输出,pid_spi_do,false);
gpio_configurepin(flash_di_port,flash_di_pin,输入,pid_spi_di,false);

spi_init(&spi_flash_cs_pad,spi_mode_8bit,spi_rool_master,spi_clk_dle_pol_low,spi_pha_mode_0,spi_mint_disable,spi_xtal_div_8);

spi_flash_init(SPI_FLASH_SIZE, SPI_FLASH_PAGE);

had executed before below fucntion was called.

spi_flash_write_data (&configData[0], ConfigAddress, sizeof(configData));

以同样的方式,当我读取G-Sensor的数据时,我必须确保

GPIO_ConfigurePin(GSensor_CS_PORT, GSensor_CS_PIN, OUTPUT, PID_SPI_EN, true);
GPIO_ConfigurePin(GSensor_CLK_PORT, GSensor_CLK_PIN, OUTPUT, PID_SPI_CLK, false);
gpio_configurepin(gsensor_do_port,gsensor_do_pin,输出,pid_spi_do,false);
GPIO_ConfigurePin(GSensor_DI_PORT, GSensor_DI_PIN, INPUT, PID_SPI_DI, false);

spi_init(&spi_gsensor_cs_pad,spi_mode_8bit,spi_rool_master,spi_clk_idle_pol_low,spi_pha_mode_0,spi_mint_disable,spi_xtal_div_8);

had executed.

Since G-Sensor alway generate data continuously, it will causing WKUP callback to be called periodically. (In my case, app_easy_timer_cb() will also be called periodically)

What if when the Control Point characteristic is written, and the G-Sensor's buffer full at the same time?

I want to know if the following will happen?

------------------------------------------------------------------

The user_custs1_ctrl_wr_ind_handler() execute first.

Inside this handler function,

GPIO_ConfigurePin(...) was call, then spi_init() was call next, then spi_flash_init() was call.

Then before spi_flash_block_erase(...) function was call (point A), The app_easy_timer_cb() was trigger.

因此,user_custs1_ctrl_wr_ind_handler()停止(暂停)在Point A中执行。并开始Expection App_easy_timer_cb()函数。

After app_easy_timer_cb() execute, user_custs1_ctrl_wr_ind_handler() resume execution from point A.

-------------------------------------------------------------------

If this happen, it will make flash write fail.

Or the SDK will execute app_easy_timer_cb() after user_custs1_ctrl_wr_ind_handler() had finished execution?

谢谢。

PM_Dialog
Online
Last seen:3 min 25 sec ago
Staff
Joined:2018-02-08 11:03
嗨ops,

嗨ops,

Thanks for your detailed feedback. Let me check it and I will get back to you as soon as possible.

Thanks, PM_Dialog

ops.
Offline
Last seen:10 months 4 weeks ago
Joined:2016-01-04 09:20
Hi, PM_Dialog;

Hi, PM_Dialog;

很高兴知道你正在研究我的问题。我期待着你的回复。

Thanks a lot.

PM_Dialog
Online
Last seen:3 min 25 sec ago
Staff
Joined:2018-02-08 11:03
嗨ops,

嗨ops,

My apologies for the late response. You will have to stop the sensor transaction with the SPI flash when the characteristic is written and then restart the transaction. Two peripherals having the SPI at the same time is not possible.

Thanks, PM_Dialog