Code Monkey home page Code Monkey logo

freertos_bluetooth's Introduction

freertos_bluetooth

FreeRTOS support for Silicon Labs EFR32BG/MG Bluetooth Stack.

For further information, refer to: https://dev.andrewlabs.com/2019/06/freertos-support-for-silicon-labs.html

Usage

The following describe the steps required to use the Bluetooth Stack in FreeRTOS starting from the Silicon Labs soc-empty template project:

  1. Ensure you have FreeRTOS and the Bluetooth SDK properly functioning on your device.
  2. Remove references to native_gecko.h from your project.
  3. Include freertos_bluetooth.c and freertos_bluetooth.h in your project.
  4. Make sure the Bluetooth stack config_flags configuration has the GECKO_CONFIG_FLAG_RTOS flag set.
static gecko_configuration_t config = {
    .config_flags = GECKO_CONFIG_FLAG_RTOS,
    // ...
};
  1. Configure interrupts in your MCU initialization function, since specifying the GECKO_CONFIG_FLAG_RTOS flag turns off interrupt configuration in the Bluetooth stack. Other interrupts should be configured as required.
// Radio interrupts.
NVIC_SetPriority(FRC_PRI_IRQn, 1);
NVIC_SetPriority(FRC_IRQn, 1);
NVIC_SetPriority(MODEM_IRQn, 1);
NVIC_SetPriority(RAC_SEQ_IRQn, 1);
NVIC_SetPriority(RAC_RSM_IRQn, 1);
NVIC_SetPriority(BUFC_IRQn, 1);
NVIC_SetPriority(AGC_IRQn, 1);
NVIC_SetPriority(PROTIMER_IRQn, 1);
NVIC_SetPriority(RTCC_IRQn, 4);      // Required for EFR32BG1 and EFR32BG12 only.
  1. Start the Bluetooth link-layer and stack tasks in your main function or equivalent. BLUETOOTH_LL_PRIORITY must be the highest priority task in your system. BLUETOOTH_STACK_PRIORITY should be set lower than the link-layer, but higher than your application task.
bluetooth_start(BLUETOOTH_LL_PRIORITY, BLUETOOTH_STACK_PRIORITY, NULL);
app_bluetooth_start_task();     // Start your app's Bluetooth task.
vTaskStartScheduler();          // Start the FreeRTOS scheduler.
  1. In your application's Bluetooth task, wait for the BLUETOOTH_EVENT_FLAG_EVT_WAITING flag in the bluetooth_event_flags event group, indicating an event from the stack is waiting to be handled by the user application.
for (;;)
{
    xEventGroupWaitBits(bluetooth_event_flags, BLUETOOTH_EVENT_FLAG_EVT_WAITING, pdTRUE, pdTRUE, portMAX_DELAY);
    // ...
  1. Handle the event appropriately by examining bluetooth_evt:
    switch (BGLIB_MSG_ID(bluetooth_evt->header))
    {
        case gecko_evt_system_boot_id:
    // ...
  1. After handling the event, flag it as handled by setting BLUETOOTH_EVENT_FLAG_EVT_HANDLED in the bluetooth_event_flags event group:
    // ...
        default:
            break;
    }
 
    xEventGroupSetBits(bluetooth_event_flags, BLUETOOTH_EVENT_FLAG_EVT_HANDLED);
}

Energy Modes

The Bluetooth stack sets a block on the EM3 energy mode if SLEEP_FLAGS_DEEP_SLEEP_ENABLE is specified in the configuration struct, allowing the SoC to power down to the EM2 energy mode. Otherwise, it sets a block on the EM2 energy mode, only allowing EM1 to be entered. The sleep driver must be manually initialized when using an RTOS.

Note that as the HFXO clock is not available in EM2, the SysTick timer will not operate. FreeRTOS will need to be configured for tickless idle mode.

freertos_bluetooth's People

Contributors

andrewtjs avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.