cancel
Showing results for 
Search instead for 
Did you mean: 

PSoC 4 MCU

JiMi_3706716
New Contributor II

while(1)

    {

        BLE_Run();

        BLE_ManagePower();

        if(Application_GetPowerState() == ACTIVE)

        {

            Application_Run();           

        }

        Application_ManagePower();  

        System_ManagePower();       

    } /* End of while(1) */

Hello,

    Above seems to be a generic main loop that can be used for low power ble applications. It works fine when the Application_Run(); function is quick and shorter than the BLE connection interval. After the quick application, the processor can go into deepsleep until the next connection. However, my application will run for up to two minutes and I don't need any BLE events to occur during the application.

Initially, I wanted to update the connection parameters such that I could skip connection events during the application. However, it seems the maximum connection timeout is 32s and I don't want disconnection.

If a connection occurs during my application, I assume my application would be halted for a few milliseconds and then resume after the connection. How would I put BLESS back into deepsleep after connection during the middle of my application? The 2 minute application is not a repetitive loop timed according to each connection event, so I cannot call Cybleprocessevents() and call CyBle_EnterLPM(CYBLE_BLESS_DEEPSLEEP) repetitively. Is there a way to call Cybleprocessevents() and call CyBle_EnterLPM(CYBLE_BLESS_DEEPSLEEP) every connection cycle?

I assume a can use a bless_interrupt callback function to call Cybleprocessevents() right before the connection. However, How would I put BLESS into deepsleep after connection.

Thanks!

0 Likes
1 Solution
VenkataD_41
Moderator
Moderator

Hi,

Please note that the current consumption for BLE will be very less when you set the connection interval to be high. However, to answer to your query:

>> "Is there a way to call Cybleprocessevents() and call CyBle_EnterLPM(CYBLE_BLESS_DEEPSLEEP) every connection cycle?"

--> You can use the "pendsv" interrupt handler to process the events and put the BLE subsystem back to sleep.

Fo this you have to pend the pendsv interrupt in the BLE isr callback.

The attached code snippet might help you. Please check.

For more information about pendsv interrupt please refer the ARM cortex M0 generic user guide from the link below:

http://infocenter.arm.com/help/topic/com.arm.doc.dui0497a/DUI0497A_cortex_m0_r0p0_generic_ug.pdf

We hope this helps, please update for more queries.

Thanks

Ganesh

View solution in original post

3 Replies
VenkataD_41
Moderator
Moderator

Hi,

Please note that the current consumption for BLE will be very less when you set the connection interval to be high. However, to answer to your query:

>> "Is there a way to call Cybleprocessevents() and call CyBle_EnterLPM(CYBLE_BLESS_DEEPSLEEP) every connection cycle?"

--> You can use the "pendsv" interrupt handler to process the events and put the BLE subsystem back to sleep.

Fo this you have to pend the pendsv interrupt in the BLE isr callback.

The attached code snippet might help you. Please check.

For more information about pendsv interrupt please refer the ARM cortex M0 generic user guide from the link below:

http://infocenter.arm.com/help/topic/com.arm.doc.dui0497a/DUI0497A_cortex_m0_r0p0_generic_ug.pdf

We hope this helps, please update for more queries.

Thanks

Ganesh

View solution in original post

JiMi_3706716
New Contributor II

Thanks! It is very helpful but I have a few more questions.

1. Can the new code below replace the old code?

void pendsvhandler()

{

    uint32 temp=0;

    CY_SET_REG32(CYREG_CM0_ICSR, (temp | SCB_ICSR_PENDSVCLR_Msk));

    //Write your application code here

        BLE_Run();

        BLE_ManagePower();

void BLE_bless_isr_Interrupt_InterruptCallback(void)

{

    uint32 temp=0;

    temp=(CY_GET_REG32(CYREG_CM0_ICSR));

    CY_SET_REG32(CYREG_CM0_ICSR, (temp | SCB_ICSR_PENDSVSET_Msk));   

}

while(1)

    {

        // ble connection occurs and the next line of code occurs only after the entire connection??

        BLE_Run(); //                                         CyBle_ProcessEvents() is called

        BLE_ManagePower();   //                     CyBle_EnterLPM(CYBLE_BLESS_DEEPSLEEP) is called

        if(Application_GetPowerState() == ACTIVE)

        {

            Application_Run();         

        }

        Application_ManagePower();

        System_ManagePower();     

    } /* End of while(1) */

2. I am confused about the operation flow about the connection event. When exactly is the pendsv interrupt triggered?

- bless isr interrupt triggered. Pend pendsv interrupt.

- During ble module RX, any events will call the stack event handler

- After RX, transmit packets if there is anything to send

- After connection, pendsv callback processes events and puts ble to deepsleep.

Is this true? During the connection event, is the processor code blocked and only the stack event handler is called when there is an ble event?

Thanks for the help!

0 Likes
VenkataD_41
Moderator
Moderator

Hi,

"2. I am confused about the operation flow about the connection event. When exactly is the pendsv interrupt triggered?

- bless isr interrupt triggered. Pend pendsv interrupt.

- During ble module RX, any events will call the stack event handler

- After RX, transmit packets if there is anything to send

- After connection, pendsv callback processes events and puts ble to deepsleep."

--> Yes. You can use this firmware flow.

"Is this true? During the connection event, is the processor code blocked and only the stack event handler is called when there is an ble event?"

--> Since you pended the 'pendsv' interrupt during connection event and did the processevents in pendsv handler, the above should be true.

Thanks

Ganesh

0 Likes