Example #1
0
ble_error_t nRF5xn::init(BLE::InstanceID_t instanceID, FunctionPointerWithContext<BLE::InitializationCompleteCallbackContext *> callback)
{
    if (initialized) {
        BLE::InitializationCompleteCallbackContext context = {
            BLE::Instance(instanceID),
            BLE_ERROR_ALREADY_INITIALIZED
        };
        callback.call(&context);
        return BLE_ERROR_ALREADY_INITIALIZED;
    }

    instanceID   = instanceID;

    /* ToDo: Clear memory contents, reset the SD, etc. */
    if (btle_init() != ERROR_NONE) {
        return BLE_ERROR_INTERNAL_STACK_FAILURE;
    }

    initialized = true;
    BLE::InitializationCompleteCallbackContext context = {
        BLE::Instance(instanceID),
        BLE_ERROR_NONE
    };
    callback.call(&context);
    return BLE_ERROR_NONE;
}
Example #2
0
ble_error_t MaximBLE::init(BLE::InstanceID_t instanceID, FunctionPointerWithContext<BLE::InitializationCompleteCallbackContext *> initCallback)
{
    wsfHandlerId_t handlerId;

    /* init OS subsystems */
    WsfTimerInit(1);
    WsfBufInit(sizeof(mainBufMem), mainBufMem, WSF_BUF_POOLS, mainPoolDesc);
    WsfSecInit();

    /* init stack */
    handlerId = WsfOsSetNextHandler(HciHandler);
    HciHandlerInit(handlerId);

    handlerId = WsfOsSetNextHandler(DmHandler);
    DmAdvInit();
    DmScanInit();
    DmConnInit();
    DmConnSlaveInit();
    DmSecInit();
    DmHandlerInit(handlerId);

    handlerId = WsfOsSetNextHandler(L2cSlaveHandler);
    L2cSlaveHandlerInit(handlerId);
    L2cInit();
    L2cMasterInit();
    L2cSlaveInit();

    handlerId = WsfOsSetNextHandler(AttHandler);
    AttHandlerInit(handlerId);
    AttsInit();
    AttsIndInit();
    AttcInit();

    handlerId = WsfOsSetNextHandler(SmpHandler);
    SmpHandlerInit(handlerId);
    SmpiInit();
    SmprInit();

    /* store handler ID */
    maximHandlerId = WsfOsSetNextHandler(maximHandler);

    /* init HCI */
#ifdef BLE_HCI_UART
    hciDrvInit(BT_TX, BT_RST, BT_CLK);
#else
    _irq.disable_irq();
    _irq.rise(hciDrvIsr);
    _irq.fall(NULL);
    hciDrvInit(HCI_CSN, HCI_RST, HCI_IRQ);
#endif

    /* Register for stack callbacks */
    DmRegister(DmCback);
    DmConnRegister(DM_CLIENT_ID_APP, DmCback);
    AttConnRegister(AppServerConnCback);

    /* Reset the device */
    reset_complete = 0;
    DmDevReset();

    while (!reset_complete) {
        callDispatcher();
    }

    initialized = true;
    BLE::InitializationCompleteCallbackContext context = {
        BLE::Instance(instanceID),
        BLE_ERROR_NONE
    };
    initCallback.call(&context);
    return BLE_ERROR_NONE;
}