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
操作
Offline
Last seen:1 year 2 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.

我们的项目使用spig传感器和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\u register\u callback(wkup\u callback);

wkupct_enable_irq(...);

作废wkup\u 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\u custs1\u ctrl\u wr\u ind\u handler()函数中实现了这个要求。

代码是这样的(简化):

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

无效用户\u custs1 \u ctrl \u wr \u ind \u处理程序(…){

if(参数->值[0]==0x01)(将数据写入SPI闪存)

}

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
Offline
Last seen:1天1小时前
Staff
Joined:2018-02-08 11:03
嗨,行动组,

嗨,行动组,

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

操作
Offline
Last seen:1 year 2 weeks ago
Joined:2016-01-04 09:20
Hi, PM_Dialog;

Hi, PM_Dialog;

Thanks for your quick response.

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

无效用户\u custs1 \u ctrl \u wr \u ind \u处理程序(…){

GPIO_ConfigurePin(FLASH_CS_PORT, FLASH_CS_PIN, OUTPUT, PID_SPI_EN, true);
GPIO\u ConfigurePin(FLASH\u CLK\u端口,FLASH\u CLK\u PIN,输出,PID\u SPI\u CLK,false);
GPIO\u ConfigurePin(FLASH\u DO\u PORT,FLASH\u DO\u PIN,OUTPUT,PID\u SPI\u DO,false);
GPIO\u ConfigurePin(FLASH\u DI\u PORT,FLASH\u DI\u PIN,INPUT,PID\u SPI\u DI,false);

spi_init(&spi_FLASH_CS_Pad,spi_MODE_8BIT,spi_ROLE_MASTER,spi_CLK_IDLE_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闪存块擦除(配置地址、扇区擦除);

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

...

}

2.我有一个G传感器,当缓冲区满的时候,它会产生一个脉冲(DA14583的外部中断)。当这个事件发生时,我使用WKUP回调函数从G-Sensor的buffer-vis-SPI接口读取所有数据。这也很管用。但是,有时我注意到这个WKUP回调函数发生了错误。似乎我在WKUP回调函数上做了太多的工作,导致了一些类型的超时!这就是为什么我使用app\u easy\u timer()在WKUP回调函数中安排一个一次性app\u easy\u timer\u cb()。通过这种方式,WKUP回调函数只执行计时器调度工作,所以它不再导致timerout。真正的工作留给了app\u easy\u timer\u cb()函数。这个策略对我有效,但如果不可行,请纠正我!

So, the app_easy_timer_cb() look like:

void app\u easy\u timer\u cb(无效){

spi_init(&spi_GSensor_CS_Pad,spi_MODE_8BIT,spi_ROLE_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.问题来自Flash和G-Sensor都使用SPI接口,DA14583只有一个SPI控制器!当我访问Flash时,我必须确保

GPIO_ConfigurePin(FLASH_CS_PORT, FLASH_CS_PIN, OUTPUT, PID_SPI_EN, true);
GPIO\u ConfigurePin(FLASH\u CLK\u端口,FLASH\u CLK\u PIN,输出,PID\u SPI\u CLK,false);
GPIO\u ConfigurePin(FLASH\u DO\u PORT,FLASH\u DO\u PIN,OUTPUT,PID\u SPI\u DO,false);
GPIO\u ConfigurePin(FLASH\u DI\u PORT,FLASH\u DI\u PIN,INPUT,PID\u SPI\u DI,false);

spi_init(&spi_FLASH_CS_Pad,spi_MODE_8BIT,spi_ROLE_MASTER,spi_CLK_IDLE_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\u ConfigurePin(GSensor\u DO\u PORT,GSensor\u DO\u PIN,OUTPUT,PID\u SPI\u 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_ROLE_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\u custs1\u ctrl\u wr\u ind\u handler()在点A处停止(暂停)执行。并开始执行app\u easy\u timer\u 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
Offline
Last seen:1天1小时前
Staff
Joined:2018-02-08 11:03
嗨,行动组,

嗨,行动组,

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

Thanks, PM_Dialog

操作
Offline
Last seen:1 year 2 weeks ago
Joined:2016-01-04 09:20
Hi, PM_Dialog;

Hi, PM_Dialog;

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

Thanks a lot.

PM_Dialog
Offline
Last seen:1天1小时前
Staff
Joined:2018-02-08 11:03
嗨,行动组,

嗨,行动组,

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