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

Bluetooth SDK Forum Discussions

bt_fw_eng
Level 1
Level 1
5 sign-ins First reply posted First question asked

Is there an API provided to support critical sections on the CYW920721?

I want to share some variables between threads and the interrupt callback context. I don't know if the interrupt callback is running in a thread or ISR. In either case, from what I've seen in the documentation the threading is preemptive, so my question is does the Modus Bluetooth SDK support critical sections where all interrupts are temporarily disabled?

I think this is needed to prevent race-conditions in the use of shared variables.

What are the functions for enabling/disabling global interrupts?

Thanks

0 Likes
1 Solution
BragadeeshV
Moderator
Moderator
Moderator
First question asked 1000 replies posted 750 replies posted

Hi @bt_fw_eng ,

1. To disable the callback, you need to pass NULL to the call back registering function 

wiced_hal_puart_register_interrupt(NULL).

To re-enable the callback function:

wiced_hal_puart_reset_puart_interrupt();
wiced_hal_puart_register_interrupt(puart_rx_interrupt_callback);

2. Disabling the callback function will not disable the PUART from receiving data in to the RX FIFO.

3. The RX FIFO of PUART is 256 bytes. You can find this information in the device datasheet.

If you don't want to disable interrupts, you could simply implement a lock variable (mutex) to ensure that such race conditions don't happen. If the lock variable is set, you can't access the shared variable.

Regards,
Bragadeesh

View solution in original post

0 Likes
3 Replies
BragadeeshV
Moderator
Moderator
Moderator
First question asked 1000 replies posted 750 replies posted

Hi @bt_fw_eng,

We do not have APIs to disable global interrupts or to enter critical sections. 

Can you please let us know which peripheral interrupt you are referring to here? Is it possible for you to disable the callback of only that interrupt so that you can prevent it from executing when you are modifying that variable in the task?

Regards,
Bragadeesh
0 Likes

I'm referring to the Peripheral UART.  Your reply raises the following questions.

1. How do you disable the PUART receive callback?
2. Will disabling the callback also disable the PUART receiving data?

3. What is the size in bytes of the PUART receive FIFO?

Thanks,

bt_fw_eng

0 Likes
BragadeeshV
Moderator
Moderator
Moderator
First question asked 1000 replies posted 750 replies posted

Hi @bt_fw_eng ,

1. To disable the callback, you need to pass NULL to the call back registering function 

wiced_hal_puart_register_interrupt(NULL).

To re-enable the callback function:

wiced_hal_puart_reset_puart_interrupt();
wiced_hal_puart_register_interrupt(puart_rx_interrupt_callback);

2. Disabling the callback function will not disable the PUART from receiving data in to the RX FIFO.

3. The RX FIFO of PUART is 256 bytes. You can find this information in the device datasheet.

If you don't want to disable interrupts, you could simply implement a lock variable (mutex) to ensure that such race conditions don't happen. If the lock variable is set, you can't access the shared variable.

Regards,
Bragadeesh
0 Likes