Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

Bluetooth SDK Forum Discussions

14993901
Level 3
Level 3
First like given 25 replies posted 50 sign-ins

Hi,

编程环境ModusToolbox,芯片cyw20719b2,运行于BLE server状态,
(1)程序片段如下:
APPLICATION_START()
{
...
pImgSemaphore = wiced_rtos_create_semaphore();//线程同步信号量
wiced_rtos_init_semaphore(pImgSemaphore);

spi1_thread_pointer = wiced_rtos_create_thread();//初始化线程
wiced_rtos_init_thread(spi1_thread_pointer, SPI1_THREAD_PRIORITY, NULL, spi1_thread_func, THREAD_STACK_MIN_SIZE, NULL) ;
...
}

static wiced_bt_gatt_status_t
tput_gatts_callback(wiced_bt_gatt_evt_t event, wiced_bt_gatt_event_data_t *p_data)
{
...
switch(event)
{
...
case GATT_ATTRIBUTE_REQUEST_EVT://判断client向server的写入值,增加信号量,触发线程函数运行
{
wiced_rtos_set_semaphore(pImgSemaphore);
break;
}
...
}
...
}

static void spi1_thread_func(uint32_t arg )//线程函数
{
wiced_rtos_get_semaphore(pImgSemaphore, 0xffffffff);//等待信号量
//通知外设发送数据
//通过SPI1口连续读入数据,SPI1工作于Slave方式,读入数据错误!
...
}

上述程序的线程函数spi1_thread_func()从读入SPI1读入的数据不正常。
(2)
经调试发现:如果去掉同步信号量,改为如下程序;APPLICATION_START()中初始化的线程函数,直接读入的SPI1数据,数据始终保持正常:
APPLICATION_START()
{
...
//去掉同步信号量
//pImgSemaphore = wiced_rtos_create_semaphore();//线程同步信号量
//wiced_rtos_init_semaphore(pImgSemaphore);

spi1_thread_pointer = wiced_rtos_create_thread();//初始化线程
wiced_rtos_init_thread(spi1_thread_pointer, SPI1_THREAD_PRIORITY, NULL, spi1_thread_func, THREAD_STACK_MIN_SIZE, NULL) ;
...
}

static wiced_bt_gatt_status_t
tput_gatts_callback(wiced_bt_gatt_evt_t event, wiced_bt_gatt_event_data_t *p_data)
{
...
switch(event)
{
...
case GATT_ATTRIBUTE_REQUEST_EVT://判断client向server的写入值,增加信号量,触发线程函数运行
{
//wiced_rtos_set_semaphore(pImgSemaphore);//去掉set semaphore操作
break;
}
...
}
...
}

static void spi1_thread_func(uint32_t arg )//线程函数
{
//wiced_rtos_get_semaphore(pImgSemaphore, 0xffffffff);//去掉等待信号量,APPLICATION_START()中初始化的线程函                                                                                                                           //数,直接读入的SPI1数据
//通知外设发送数据
//通过SPI1口连续读入数据,SPI1工作于Slave方式,读入数据保持正确!
...
}
(3)
如果将wiced_rtos_init_thread() 函数从APPLICATION_START()中移至tput_gatts_callback(),同时spi1_thread_func()去除等待信号量,SPI1读入的数据也是错误的。

请问,该问题是由于同步信号量使用不当,还是线程函数错误引起的?应该怎样修改?

 

万分感谢!

0 Likes
3 Replies
Owen_Zhang123
Moderator
Moderator
Moderator
500 solutions authored 250 sign-ins 1000 replies posted

请问你的代码中是否有用到HCI UART或者对其做了初始化?

0 Likes

只在APPLICATION_START()中设置了

APPLICATION_START()
{

...
wiced_set_debug_uart(WICED_ROUTE_DEBUG_TO_PUART);

...

}

没有使用HCI UART

0 Likes
Owen_Zhang123
Moderator
Moderator
Moderator
500 solutions authored 250 sign-ins 1000 replies posted

请问您的具体应用场景是怎样的?是否可以避免使用同步信号量?

0 Likes