int main( void ) { FILE* fp; // Initialize platform first if( platform_init() != PLATFORM_OK ) { // This should never happen while( 1 ); } // Initialize device manager dm_init(); // Register the ROM filesystem dm_register( romfs_init() ); // Register the MMC filesystem dm_register( mmcfs_init() ); // Register the remote filesystem dm_register( remotefs_init() ); // Autorun: if "autorun.lua" is found in the file system, run it first if( ( fp = fopen( FS_AUTORUN, "r" ) ) != NULL ) { fclose( fp ); char* lua_argv[] = { "lua", FS_AUTORUN, NULL }; lua_main( 2, lua_argv ); } #ifdef ELUA_BOOT_RPC boot_rpc(); #else // Run the shell if( shell_init() == 0 ) { printf( "Unable to initialize the eLua shell!\n" ); // Start Lua directly char* lua_argv[] = { "lua", NULL }; lua_main( 1, lua_argv ); } else shell_start(); #endif // #ifdef ELUA_BOOT_RPC #ifdef ELUA_SIMULATOR hostif_exit(0); return 0; #else while( 1 ); #endif }
int main( void ) { int i; FILE* fp; // Initialize platform first if( platform_init() != PLATFORM_OK ) { // This should never happen while( 1 ); } // Initialize device manager dm_init(); // Register the ROM filesystem dm_register( romfs_init() ); // Register the MMC filesystem dm_register( mmcfs_init() ); // Register the Semihosting filesystem dm_register( semifs_init() ); // Search for autorun files in the defined order and execute the 1st if found for( i = 0; i < sizeof( boot_order ) / sizeof( *boot_order ); i++ ) { if( ( fp = fopen( boot_order[ i ], "r" ) ) != NULL ) { fclose( fp ); char* picoc_argv[] = { "picoc", boot_order[i], NULL }; picoc_main( 2, picoc_argv ); break; // autoruns only the first found } } // Run the shell if( shell_init() == 0 ) { // Start picoc directly char* picoc_argv[] = { "picoc", NULL }; picoc_main( 1, picoc_argv ); } else shell_start(); while( 1 ); }
// **************************************************************************** // Program entry point int main (void) { // Initialize platform first if( platform_init() != PLATFORM_OK ) { // This should never happen while( 1 ); } // Initialize device manager dm_init(); // And register the ROM filesystem dm_register( fs_init() ); // Initialize XMODEM xmodem_init( xmodem_send, xmodem_recv ); printf( ".text ends at %p, first free RAM is at %p, last free ram is at %p\r\n", etext, platform_get_first_free_ram(), platform_get_last_free_ram() ); // Run the shell if( shell_init( XMODEM_MAX_FILE_SIZE ) == 0 ) printf( "Unable to initialize shell!\n" ); else shell_start(); while( 1 ); }
/**@brief Function for the Device Manager initialization. */ static void device_manager_init(void) { uint32_t err_code; dm_init_param_t init_data; dm_application_param_t register_param; // Initialize persistent storage module. err_code = pstorage_init(); APP_ERROR_CHECK(err_code); // Clear all bonded centrals if the "delete all bonds" button is pushed. err_code = bsp_button_is_pressed(BOND_DELETE_ALL_WAKEUP_BUTTON_ID,&(init_data.clear_persistent_data)); APP_ERROR_CHECK(err_code); err_code = dm_init(&init_data); APP_ERROR_CHECK(err_code); memset(®ister_param.sec_param, 0, sizeof(ble_gap_sec_params_t)); register_param.sec_param.timeout = SEC_PARAM_TIMEOUT; register_param.sec_param.bond = SEC_PARAM_BOND; register_param.sec_param.mitm = SEC_PARAM_MITM; register_param.sec_param.io_caps = SEC_PARAM_IO_CAPABILITIES; register_param.sec_param.oob = SEC_PARAM_OOB; register_param.sec_param.min_key_size = SEC_PARAM_MIN_KEY_SIZE; register_param.sec_param.max_key_size = SEC_PARAM_MAX_KEY_SIZE; register_param.evt_handler = device_manager_evt_handler; register_param.service_type = DM_PROTOCOL_CNTXT_GATT_SRVR_ID; err_code = dm_register(&m_app_handle, ®ister_param); APP_ERROR_CHECK(err_code); }
/**@brief Function for the Device Manager initialization. * * @param[in] erase_bonds Indicates whether bonding information should be cleared from * persistent storage during initialization of the Device Manager. */ static void device_manager_init(bool erase_bonds) { uint32_t err_code; dm_init_param_t init_param = {.clear_persistent_data = erase_bonds}; dm_application_param_t register_param; err_code = pstorage_init(); APP_ERROR_CHECK(err_code); err_code = dm_init(&init_param); APP_ERROR_CHECK(err_code); memset(®ister_param.sec_param, 0, sizeof (ble_gap_sec_params_t)); // Event handler to be registered with the module. register_param.evt_handler = device_manager_event_handler; // Service or protocol context for device manager to load, store and apply on behalf of application. // Here set to client as application is a GATT client. register_param.service_type = DM_PROTOCOL_CNTXT_GATT_CLI_ID; // Secuirty parameters to be used for security procedures. register_param.sec_param.bond = SEC_PARAM_BOND; register_param.sec_param.mitm = SEC_PARAM_MITM; register_param.sec_param.io_caps = SEC_PARAM_IO_CAPABILITIES; register_param.sec_param.oob = SEC_PARAM_OOB; register_param.sec_param.min_key_size = SEC_PARAM_MIN_KEY_SIZE; register_param.sec_param.max_key_size = SEC_PARAM_MAX_KEY_SIZE; register_param.sec_param.kdist_periph.enc = 1; register_param.sec_param.kdist_periph.id = 1; err_code = dm_register(&m_dm_app_id, ®ister_param); APP_ERROR_CHECK(err_code); }
/**@brief Function for the Device Manager initialization. * * @param[in] erase_bonds Indicates whether bonding information should be cleared from * persistent storage during initialization of the Device Manager. */ static void device_manager_init(bool erase_bonds) { uint32_t err_code; dm_init_param_t init_param = {.clear_persistent_data = erase_bonds}; dm_application_param_t register_param; // Initialize persistent storage module. err_code = pstorage_init(); APP_ERROR_CHECK(err_code); err_code = dm_init(&init_param); APP_ERROR_CHECK(err_code); memset(®ister_param.sec_param, 0, sizeof(ble_gap_sec_params_t)); register_param.sec_param.bond = SEC_PARAM_BOND; register_param.sec_param.mitm = SEC_PARAM_MITM; register_param.sec_param.io_caps = SEC_PARAM_IO_CAPABILITIES; register_param.sec_param.oob = SEC_PARAM_OOB; register_param.sec_param.min_key_size = SEC_PARAM_MIN_KEY_SIZE; register_param.sec_param.max_key_size = SEC_PARAM_MAX_KEY_SIZE; register_param.evt_handler = device_manager_evt_handler; register_param.service_type = DM_PROTOCOL_CNTXT_GATT_SRVR_ID; err_code = dm_register(&m_app_handle, ®ister_param); APP_ERROR_CHECK(err_code); }
int mmcfs_init() { // Mount the MMC file system using logical disk 0 if ( f_mount( 0, &mmc_fs ) != FR_OK ) return DM_ERR_INIT; return dm_register( "/mmc", NULL, &mmcfs_device ); }
/**@brief Function for the Device Manager initialization. */ static void device_manager_init(void) { uint32_t err_code; dm_init_param_t init_data; dm_application_param_t register_param; // Initialize persistent storage module. err_code = pstorage_init(); APP_ERROR_CHECK(err_code); // Clear all bonded centrals if the Bonds Delete button is pushed. init_data.clear_persistent_data = true;//(nrf_gpio_pin_read(BOND_DELETE_ALL_BUTTON_ID) == 0); err_code = dm_init(&init_data); APP_ERROR_CHECK(err_code); memset(®ister_param.sec_param, 0, sizeof(ble_gap_sec_params_t)); //register_param.sec_param.timeout = SEC_PARAM_TIMEOUT; register_param.sec_param.bond = SEC_PARAM_BOND; register_param.sec_param.mitm = SEC_PARAM_MITM; register_param.sec_param.io_caps = SEC_PARAM_IO_CAPABILITIES; register_param.sec_param.oob = SEC_PARAM_OOB; register_param.sec_param.min_key_size = SEC_PARAM_MIN_KEY_SIZE; register_param.sec_param.max_key_size = SEC_PARAM_MAX_KEY_SIZE; register_param.evt_handler = device_manager_evt_handler; register_param.service_type = DM_PROTOCOL_CNTXT_NONE; err_code = dm_register(&g_AppHandle, ®ister_param); APP_ERROR_CHECK(err_code); }
/**@brief Function for the Device Manager initialization. * * @param[in] erase_bonds Indicates whether bonding information should be cleared from * persistent storage during initialization of the Device Manager. */ static void device_manager_init(bool erase_bonds) { uint32_t err_code; dm_init_param_t init_param = {.clear_persistent_data = erase_bonds}; dm_application_param_t register_param; // Initialize persistent storage module. err_code = pstorage_init(); APP_ERROR_CHECK(err_code); err_code = dm_init(&init_param); APP_ERROR_CHECK(err_code); memset(®ister_param.sec_param, 0, sizeof(ble_gap_sec_params_t)); register_param.sec_param.bond = SEC_PARAM_BOND; register_param.sec_param.mitm = SEC_PARAM_MITM; register_param.sec_param.io_caps = SEC_PARAM_IO_CAPABILITIES; register_param.sec_param.oob = SEC_PARAM_OOB; register_param.sec_param.min_key_size = SEC_PARAM_MIN_KEY_SIZE; register_param.sec_param.max_key_size = SEC_PARAM_MAX_KEY_SIZE; register_param.evt_handler = device_manager_evt_handler; register_param.service_type = DM_PROTOCOL_CNTXT_GATT_SRVR_ID; err_code = dm_register(&m_app_handle, ®ister_param); APP_ERROR_CHECK(err_code); app_bond_init(&m_app_bond_table); for(uint8_t i = 0; i < DEVICE_MANAGER_MAX_BONDS; i++) { APP_LOG("[APP][ID: %d], Application context : %08X\r\n",m_app_bond_table.device_id[i],(unsigned int) m_app_bond_table.app_bond_cnt[i]); } }
// Initialize device manager // This initializes the standard descriptors (stdin, stdout, stderr) // At this point it is assumed that the std device (usually UART) is already initialized int dm_init() { dm_register( std_get_desc() ); #ifndef BUILD_CON_TCP // we need buffering on stdout for console over TCP setbuf( stdout, NULL ); #endif return DM_OK; }
int main( void ) { FILE* fp; // Initialize platform first if( platform_init() != PLATFORM_OK ) { // This should never happen while( 1 ); } // Initialize device manager dm_init(); // Register the ROM filesystem dm_register( romfs_init() ); #ifdef BUILD_XMODEM // Initialize XMODEM xmodem_init( xmodem_send, xmodem_recv ); #endif #ifdef BUILD_TERM // Initialize terminal term_init( TERM_LINES, TERM_COLS, term_out, term_in, term_translate ); #endif // Autorun: if "autorun.lua" is found in the ROM file system, run it first if( ( fp = fopen( "/rom/autorun.lua", "r" ) ) != NULL ) { fclose( fp ); char* lua_argv[] = { "lua", "/rom/autorun.lua", NULL }; lua_main( 2, lua_argv ); } // Run the shell if( shell_init() == 0 ) { printf( "Unable to initialize the eLua shell!\n" ); // Start Lua directly char* lua_argv[] = { "lua", NULL }; lua_main( 1, lua_argv ); } else shell_start(); while( 1 ); }
/**@brief Function for the Device Manager initialization. * * @param[in] erase_bonds Indicates whether bonding information should be cleared from * persistent storage during initialization of the Device Manager. */ static void device_manager_init(bool erase_bonds) { uint32_t err_code; dm_init_param_t init_param = {.clear_persistent_data = erase_bonds}; dm_application_param_t register_param; // Initialize persistent storage module. err_code = pstorage_init(); if (err_code == NRF_SUCCESS) debug_printf("Persistent storage module is ready!\r\n"); else { debug_printf("Ooops.. Something went wrong with initialising the PS module..\r\n"); APP_ERROR_CHECK(err_code); } err_code = dm_init(&init_param); if (err_code == NRF_SUCCESS) debug_printf("DM initialised!\r\n"); else { debug_printf("Ooops.. Something went wrong with initialising the DM..\r\n"); APP_ERROR_CHECK(err_code); } memset(®ister_param.sec_param, 0, sizeof(ble_gap_sec_params_t)); register_param.sec_param.bond = SEC_PARAM_BOND; register_param.sec_param.mitm = SEC_PARAM_MITM; register_param.sec_param.io_caps = SEC_PARAM_IO_CAPABILITIES; register_param.sec_param.oob = SEC_PARAM_OOB; register_param.sec_param.min_key_size = SEC_PARAM_MIN_KEY_SIZE; register_param.sec_param.max_key_size = SEC_PARAM_MAX_KEY_SIZE; register_param.evt_handler = device_manager_evt_handler; register_param.service_type = DM_PROTOCOL_CNTXT_GATT_SRVR_ID; err_code = dm_register(&m_app_handle, ®ister_param); if (err_code == NRF_SUCCESS) debug_printf("Registered parameters for DM!\r\n"); else { debug_printf("Ooops.. Something went wrong with registering the parameters for the DM..\r\n"); APP_ERROR_CHECK(err_code); } }
/**@brief Function for initializing the Device Manager. * * @details Device manager is initialized here. */ static void device_manager_init(void) { dm_application_param_t param; dm_init_param_t init_param; uint32_t err_code; err_code = pstorage_init(); APP_ERROR_CHECK(err_code); init_param.clear_persistent_data = false; #ifdef BOND_DELETE_ALL_BUTTON_PIN // Clear all bonded devices if user requests to. init_param.clear_persistent_data = ((nrf_gpio_pin_read(BOND_DELETE_ALL_BUTTON_PIN) == 0)? true: false); #endif err_code = dm_init(&init_param); APP_ERROR_CHECK(err_code); memset(¶m.sec_param, 0, sizeof (ble_gap_sec_params_t)); // Event handler to be registered with the module. param.evt_handler = device_manager_event_handler; // Service or protocol context for device manager to load, store and apply on behalf of application. // Here set to client as application is a GATT client. param.service_type = DM_PROTOCOL_CNTXT_GATT_CLI_ID; // Secuirty parameters to be used for security procedures. param.sec_param.bond = SEC_PARAM_BOND; param.sec_param.mitm = SEC_PARAM_MITM; param.sec_param.io_caps = SEC_PARAM_IO_CAPABILITIES; param.sec_param.oob = SEC_PARAM_OOB; param.sec_param.min_key_size = SEC_PARAM_MIN_KEY_SIZE; param.sec_param.max_key_size = SEC_PARAM_MAX_KEY_SIZE; param.sec_param.kdist_periph.enc = 1; param.sec_param.kdist_periph.id = 1; err_code = dm_register(&m_dm_app_id,¶m); APP_ERROR_CHECK(err_code); }
int main( void ) { // Initialize platform first if( platform_init() != PLATFORM_OK ) { // This should never happen while( 1 ); } // Initialize the TLSF allocator // (if TLSF is not used, the next function does nothing) tlsf_elua_init(); // Initialize device manager dm_init(); // Register the ROM filesystem dm_register( romfs_init() ); // Initialize XMODEM xmodem_init( xmodem_send, xmodem_recv ); // Initialize terminal term_init( TERMINAL_LINES, TERMINAL_COLS, term_out, term_in, term_translate ); printf( ".text ends at %p\n", etext ); // Run the shell if( shell_init( XMODEM_MAX_FILE_SIZE ) == 0 ) { printf( "Unable to initialize the eLua shell!\n" ); // Start Lua directly char* lua_argv[] = { "lua", NULL }; lua_main( 1, lua_argv ); } else shell_start(); while( 1 ); }
int main( void ) { // Initialize platform first if( platform_init() != PLATFORM_OK ) { // This should never happen while( 1 ); } // Initialize device manager dm_init(); // Register the ROM filesystem dm_register( romfs_init() ); // Initialize XMODEM xmodem_init( xmodem_send, xmodem_recv ); // Initialize terminal term_init( TERMINAL_LINES, TERMINAL_COLS, term_out, term_in, term_translate ); printf( ".text ends at %p, first free RAM is at %p, last free ram is at %p\r\n", etext, platform_get_first_free_ram(), platform_get_last_free_ram() ); // Run the shell if( shell_init( XMODEM_MAX_FILE_SIZE ) == 0 ) { printf( "Unable to initialize the eLua shell!\n" ); // Start Lua directly char* lua_argv[] = { "lua", NULL }; lua_main( 1, lua_argv ); } else shell_start(); while( 1 ); }
int std_register() { return dm_register( STD_DEV_NAME, NULL, &std_device ); }
int mmcfs_init() { return dm_register( NULL, NULL, NULL ); }
ble_error_t btle_initializeSecurity(bool enableBonding, bool requireMITM, SecurityManager::SecurityIOCapabilities_t iocaps, const SecurityManager::Passkey_t passkey) { /* guard against multiple initializations */ if (initialized) { return BLE_ERROR_NONE; } if (pstorage_init() != NRF_SUCCESS) { return BLE_ERROR_UNSPECIFIED; } ret_code_t rc; if (passkey) { ble_opt_t opts; opts.gap_opt.passkey.p_passkey = const_cast<uint8_t *>(passkey); if ((rc = sd_ble_opt_set(BLE_GAP_OPT_PASSKEY, &opts)) != NRF_SUCCESS) { switch (rc) { case BLE_ERROR_INVALID_CONN_HANDLE: case NRF_ERROR_INVALID_ADDR: case NRF_ERROR_INVALID_PARAM: default: return BLE_ERROR_INVALID_PARAM; case NRF_ERROR_INVALID_STATE: return BLE_ERROR_INVALID_STATE; case NRF_ERROR_BUSY: return BLE_STACK_BUSY; } } } dm_init_param_t dm_init_param = { .clear_persistent_data = false /* Set to true in case the module should clear all persistent data. */ }; if (dm_init(&dm_init_param) != NRF_SUCCESS) { return BLE_ERROR_UNSPECIFIED; } // update default security parameters with function call parameters securityParameters.bond = enableBonding; securityParameters.mitm = requireMITM; securityParameters.io_caps = iocaps; const dm_application_param_t dm_param = { .evt_handler = dm_handler, .service_type = DM_PROTOCOL_CNTXT_GATT_CLI_ID, .sec_param = securityParameters }; if ((rc = dm_register(&applicationInstance, &dm_param)) != NRF_SUCCESS) { switch (rc) { case NRF_ERROR_INVALID_STATE: return BLE_ERROR_INVALID_STATE; case NRF_ERROR_NO_MEM: return BLE_ERROR_NO_MEM; default: return BLE_ERROR_UNSPECIFIED; } } initialized = true; return BLE_ERROR_NONE; } ble_error_t btle_purgeAllBondingState(void) { ret_code_t rc; if ((rc = dm_device_delete_all(&applicationInstance)) == NRF_SUCCESS) { return BLE_ERROR_NONE; } switch (rc) { case NRF_ERROR_INVALID_STATE: return BLE_ERROR_INVALID_STATE; case NRF_ERROR_NO_MEM: return BLE_ERROR_NO_MEM; default: return BLE_ERROR_UNSPECIFIED; } }