/*----------------------------------------------------------------------------* * NAME * ReadDiscoveredBatteryServiceHandlesFromNVM * * DESCRIPTION * This function reads the Battery Service handles from NVM * * RETURNS * Nothing. *----------------------------------------------------------------------------*/ extern void ReadDiscoveredBatteryServiceHandlesFromNVM(uint16 *p_offset, bool handles_present) { g_disc_battery_service.nvm_offset = *p_offset; if(handles_present) { /* Read the Battery Service start handle from NVM */ Nvm_Read((uint16*)&g_disc_battery_service.start_handle, sizeof(g_disc_battery_service.start_handle), *p_offset + NVM_DISC_BATTERY_SERVICE_START_HANDLE_OFFSET); /* Read the Battery Service end handle from NVM */ Nvm_Read((uint16*)&g_disc_battery_service.end_handle, sizeof(g_disc_battery_service.end_handle), *p_offset + NVM_DISC_BATTERY_SERVICE_END_HANDLE_OFFSET); /* Read the Battery Level characteristic handle from NVM */ Nvm_Read((uint16*)&g_disc_battery_char.start_handle, sizeof(g_disc_battery_char.start_handle), *p_offset + NVM_DISC_BATTERY_LEVEL_HANDLE_OFFSET); /* Read the Battery Level Client Characteristic Configuration descriptor * handle from NVM */ Nvm_Read((uint16*)&g_disc_battery_char.ccd_handle, sizeof(g_disc_battery_char.ccd_handle), *p_offset + NVM_DISC_BATTERY_LEVEL_CCD_HANDLE_OFFSET); } /* Increment the offset by the number of words of NVM memory required * by the discovered Battery Service. */ *p_offset += NVM_DISC_BATTERY_SERVICE_TOTAL_WORDS; }
/*----------------------------------------------------------------------------* * NAME * ReadDiscoveredSerialServiceHandlesFromNVM * * DESCRIPTION * This function reads the Serial Service handles from NVM * * RETURNS * Nothing. *----------------------------------------------------------------------------*/ extern void ReadDiscoveredSerialServiceHandlesFromNVM(uint16 *p_offset, bool handles_present) { g_disc_serial_service.nvm_offset = *p_offset; if(handles_present) { /* Read the Serial Service start handle from NVM */ Nvm_Read((uint16*)&g_disc_serial_service.start_handle, sizeof(g_disc_serial_service.start_handle), *p_offset + NVM_DISC_SERIAL_SERVICE_START_HANDLE_OFFSET); /* Read the Serial Service end handle from NVM */ Nvm_Read((uint16*)&g_disc_serial_service.end_handle, sizeof(g_disc_serial_service.end_handle), *p_offset + NVM_DISC_SERIAL_SERVICE_END_HANDLE_OFFSET); /* Read the Serial Data Transfer characteristic handle from NVM */ Nvm_Read((uint16*)&g_disc_serial_data_char.start_handle, sizeof(g_disc_serial_data_char.start_handle), *p_offset + NVM_DISC_SERIAL_DATA_TRANSFER_HANDLE_OFFSET); /* Read the Serial Data Transfer Client Characteristic Configuration * descriptor handle from NVM */ Nvm_Read((uint16*)&g_disc_serial_data_char.ccd_handle, sizeof(g_disc_serial_data_char.ccd_handle), *p_offset + NVM_DISC_SERIAL_DATA_TRANSFER_CCD_HANDLE_OFFSET); } /* Increment the offset by the number of words of NVM memory required * by the discovered Serial Service. */ *p_offset += NVM_DISC_SERIAL_SERVICE_TOTAL_WORDS; }
extern void GapReadDataFromNVM(uint16 *p_offset) { g_gap_data.nvm_offset = *p_offset; /* Read Device Length */ Nvm_Read(&g_gap_data.length, sizeof(g_gap_data.length), *p_offset + GAP_NVM_DEVICE_LENGTH_OFFSET); /* Read Device Name * Typecast of uint8 to uint16 or vice-versa shall not have any side * affects as both types (uint8 and uint16) take one word memory on XAP */ Nvm_Read((uint16*)g_gap_data.p_dev_name, g_gap_data.length, *p_offset + GAP_NVM_DEVICE_NAME_OFFSET); /* Add NULL character to terminate the device name string */ g_gap_data.p_dev_name[g_gap_data.length] = '\0'; /* Increase NVM offset for maximum device name length. Add 1 for * 'device name length' field as well */ *p_offset += DEVICE_NAME_MAX_LENGTH + 1; }
extern void GattReadDataFromNVM(uint16 *p_offset) { uint8 dev_index; g_gatt_data.nvm_offset = *p_offset; /* Read NVM only if devices are bonded */ for(dev_index = 0; dev_index < MAX_BONDED_DEVICES; dev_index++) { if(AppIsDeviceBonded(dev_index)) { /* Read Service Changed client configuration */ Nvm_Read((uint16*)&(g_gatt_data.serv_changed_config[dev_index]), sizeof(g_gatt_data.serv_changed_config[dev_index]), (g_gatt_data.nvm_offset + SERV_CHANGED_CLIENT_CONFIG_OFFSET(dev_index))); /* Read Service Has Changed flag */ Nvm_Read((uint16*)&(g_gatt_data.serv_changed), sizeof(g_gatt_data.serv_changed), (g_gatt_data.nvm_offset + SERV_CHANGED_SEND_IND(dev_index))); } else { g_gatt_data.serv_changed_config[dev_index] = gatt_client_config_none; g_gatt_data.serv_changed[dev_index] = FALSE; /* Reset the information in the NVM */ Nvm_Write((uint16*)&(g_gatt_data.serv_changed_config[dev_index]), sizeof(g_gatt_data.serv_changed_config[dev_index]), (g_gatt_data.nvm_offset + SERV_CHANGED_CLIENT_CONFIG_OFFSET(dev_index))); Nvm_Write((uint16*)&(g_gatt_data.serv_changed[dev_index]), sizeof(g_gatt_data.serv_changed[dev_index]), (g_gatt_data.nvm_offset + SERV_CHANGED_SEND_IND(dev_index))); } } /* Increment the offset by the number of words of NVM memory required * by GATT service */ *p_offset += SERV_CHANGED_NVM_MEMORY_WORDS; }
extern void HeartRateReadDataFromNVM(bool nvm_fresh_start, uint16 *p_offset) { g_hr_serv_data.nvm_offset = *p_offset; /* Read NVM only if devices are bonded */ if(AppIsDeviceBonded()) { /* Read Heart Rate Measurement Client Configuration */ Nvm_Read((uint16*)&g_hr_serv_data.hr_meas_client_config, sizeof(g_hr_serv_data.hr_meas_client_config), g_hr_serv_data.nvm_offset + HR_NVM_HR_MEAS_CLIENT_CONFIG_OFFSET); } if(nvm_fresh_start) { /* As NVM is being written for the first time, update NVM with the * energy expended value [initialised in HRInitChipReset() function] */ Nvm_Write(&g_hr_serv_data.energy_expended, sizeof(g_hr_serv_data.energy_expended), g_hr_serv_data.nvm_offset + HR_NVM_ENERGY_EXPENDED_OFFSET); } else { /* Read Energy Expended charcteristic value */ Nvm_Read(&g_hr_serv_data.energy_expended, sizeof(g_hr_serv_data.energy_expended), g_hr_serv_data.nvm_offset + HR_NVM_ENERGY_EXPENDED_OFFSET); } /* Increment the offset by the number of words of NVM memory required * by heart rate service */ *p_offset += HEART_RATE_SERVICE_NVM_MEMORY_WORDS; }
/*----------------------------------------------------------------------------* * NAME * ReadDiscoveredVehicleInfoServiceHandlesFromNVM * * DESCRIPTION * This function reads the vehicle Information service handles from NVM * * RETURNS * Nothing. *----------------------------------------------------------------------------*/ extern void ReadDiscoveredVehicleInfoServiceHandlesFromNVM(uint16 *p_offset, bool handles_present) { uint8 index; /* The application stores the discoverd Device Information service * handles in NVM */ vehicle_service_discovery.nvm_offset = *p_offset; if(handles_present) { for(index = 0 ; index < vehicle_service_discovery.num_chars ; index++ ) { /* Read the service start handle from NVM */ Nvm_Read((uint16*)&vehicle_info_chars[index].start_handle, sizeof(vehicle_info_chars[index].start_handle), *p_offset + (index*2)); /* Read the characteristic client configuration * descriptor handle from NVM */ Nvm_Read((uint16*)&vehicle_info_chars[index].ccd_handle, sizeof(vehicle_info_chars[index].ccd_handle), *p_offset + (index*2)+1); } /* Read the service start handle */ Nvm_Read((uint16*)&vehicle_service_discovery.start_hndl, sizeof(vehicle_service_discovery.start_hndl), *p_offset + NVM_DISC_VEHICLE_INFO_SERV_STRT_HANDLE_OFFSET); /* Read the service end handle */ Nvm_Read((uint16*)&vehicle_service_discovery.end_hndl, sizeof(vehicle_service_discovery.end_hndl), *p_offset + NVM_DISC_VEHICLE_INFO_SERV_END_HANDLE_OFFSET); } /* Increment the offset by the number of words of NVM memory required * by the discovered device information service. */ *p_offset += NVM_DISC_VEHICLE_INFO_SERVICE_TOTAL_WORDS; }
extern void GapReadDataFromNVM(uint16 *p_offset) { g_gap_data.nvm_offset = *p_offset; /* Read Device Length */ Nvm_Read(&g_gap_data.length, sizeof(g_gap_data.length), g_gap_data.nvm_offset + GAP_NVM_DEVICE_NAME_LENGTH_OFFSET); /* Typecast of uint8 to uint16 or vice-versa shall not have any side affects * as both types (uint8 and uint16) take one word memory on XAP. */ /* Skip 1st byte to move over AD Type field and point to device name */ g_gap_data.p_dev_name = (g_device_name + 1); Nvm_Read((uint16*)g_gap_data.p_dev_name, g_gap_data.length, g_gap_data.nvm_offset + GAP_NVM_DEVICE_NAME_OFFSET); /* Add NULL character to terminate the device name string */ g_gap_data.p_dev_name[g_gap_data.length] = '\0'; #ifdef __GAP_PRIVACY_SUPPORT__ /* If device is not bonded, by default, set privacy to TRUE */ if(!AppIsDeviceBonded()) { g_gap_data.peripheral_privacy_flag = TRUE; MAKE_RECONNECTION_ADDRESS_INVALID(); } else { Nvm_Read((uint16*)&g_gap_data.peripheral_privacy_flag, sizeof(g_gap_data.peripheral_privacy_flag), g_gap_data.nvm_offset + GAP_NVM_DEVICE_PERIPHERAL_FLAG_OFFSET); Nvm_Read((uint16*)&g_gap_data.reconnect_address, sizeof(BD_ADDR_T), g_gap_data.nvm_offset + GAP_NVM_DEVICE_RECONNECTION_ADDRESS_OFFSET); } #endif /* __GAP_PRIVACY_SUPPORT__ */ *p_offset += GAP_SERVICE_NVM_MEMORY_WORDS; }
extern void HidReadDataFromNVM(bool bonded, uint16 *p_offset) { hid_data.nvm_offset = *p_offset; /* Read NVM only if devices are bonded */ if(bonded) { /* Read HID Boot Input Report Client Configuration */ Nvm_Read((uint16*)&hid_data.input_boot_client_config, sizeof(gatt_client_config), *p_offset + HID_NVM_INPUT_BOOT_RPT_CLIENT_CONFIG_OFFSET); /* Read HID Input Report Client Configuration */ Nvm_Read((uint16*)&hid_data.input_client_config, sizeof(gatt_client_config), *p_offset + HID_NVM_INPUT_RPT_CLIENT_CONFIG_OFFSET); } /* Increment the offset by the number of words of NVM memory required * by HID service */ *p_offset += HID_SERVICE_NVM_MEMORY_WORDS; }
extern void ReadDiscoveredTrunkControlServiceHandlesFromNVM(uint16 *p_offset, bool handles_present) { /* The application stores the discoverd trunk control service * handles in NVM */ trunk_service_discovery.nvm_offset = *p_offset; if(handles_present) { /* Read the trunk control characteristic handle from NVM */ Nvm_Read((uint16*)&trunk_control_char.start_handle, sizeof(trunk_control_char.start_handle), *p_offset + NVM_DISC_TRUNK_OPEN_CHAR_HANDLE_OFFSET); /* Read the trunk control characteristic client configuration * descriptor handle from NVM */ Nvm_Read((uint16*)&trunk_control_char.ccd_handle, sizeof(trunk_control_char.ccd_handle), *p_offset + NVM_DISC_TRUNK_OPEN_CCD_HANDLE_OFFSET); /* Read the Trunk control service start handle */ Nvm_Read((uint16*)&trunk_service_discovery.start_hndl, sizeof(trunk_service_discovery.start_hndl), *p_offset + NVM_DISC_TRUNK_OPEN_SERV_START_HANDLE_OFFSET); /* Read the Trunk control service end handle */ Nvm_Read((uint16*)&trunk_service_discovery.end_hndl, sizeof(trunk_service_discovery.end_hndl), *p_offset + NVM_DISC_TRUNK_OPEN_SERV_END_HANDLE_OFFSET); } /* Increment the offset by the number of words of NVM memory required * by the discovered trunk control service. */ *p_offset += NVM_DISC_TRUNK_CONTROL_SERVICE_TOTAL_WORDS; }
/*----------------------------------------------------------------------------* * NAME * ReadDiscoveredLockServiceHandlesFromNVM * * DESCRIPTION * This function reads the lock service handles from NVM * * RETURNS * Nothing. *----------------------------------------------------------------------------*/ extern void ReadDiscoveredLockServiceHandlesFromNVM(uint16 *p_offset, bool handles_present) { lock_service_discovery.nvm_offset = *p_offset; if(handles_present) { /* Read the lock unlock characteristic handle from NVM */ Nvm_Read((uint16*)&lock_char.start_handle, sizeof(lock_char.start_handle), *p_offset + NVM_DISC_LOCK_CHAR_HANDLE_OFFSET); /* Read the lock unlock characteristic client configuration descriptor * handle from NVM */ Nvm_Read((uint16*)&lock_char.ccd_handle, sizeof(lock_char.ccd_handle), *p_offset + NVM_DISC_LOCK_CHAR_CCD_HANDLE_OFFSET); /* Read the Lock service start handle */ Nvm_Read((uint16*)&lock_service_discovery.start_hndl, sizeof(lock_service_discovery.start_hndl), lock_service_discovery.nvm_offset + NVM_DISC_LOCK_SERV_STRT_HANDLE_OFFSET); /* Read the Lock service end handle */ Nvm_Read((uint16*)&lock_service_discovery.end_hndl, sizeof(lock_service_discovery.end_hndl), lock_service_discovery.nvm_offset + NVM_DISC_LOCK_SERV_END_HANDLE_OFFSET); } /* Increment the offset by the number of words of NVM memory required * by the discovered lock unlock service. */ *p_offset += NVM_DISC_LOCK_SERVICE_TOTAL_WORDS; }
extern void GapReadDataFromNVM(uint16 *p_offset) { g_gap_data.nvm_offset = *p_offset; /* Read Device Length */ Nvm_Read(&g_gap_data.length, sizeof(g_gap_data.length), *p_offset + GAP_NVM_DEVICE_LENGTH_OFFSET); /* If the dev name length read from the NVM is incorrect then better update * the NVM with the correct device name and its length. */ if(g_gap_data.length > DEVICE_NAME_MAX_LENGTH) { g_gap_data.p_dev_name = (g_device_name + 1); g_gap_data.length = StrLen((char *)g_gap_data.p_dev_name); updateDeviceName(g_gap_data.length, g_gap_data.p_dev_name); } else { /* Read Device Name * Typecast of uint8 to uint16 or vice-versa shall not have any side * affects as both types (uint8 and uint16) take one word memory on XAP */ Nvm_Read((uint16*)g_gap_data.p_dev_name, g_gap_data.length, *p_offset + GAP_NVM_DEVICE_NAME_OFFSET); /* Add NULL character to terminate the device name string */ g_gap_data.p_dev_name[g_gap_data.length] = '\0'; } /* Increase NVM offset for maximum device name length. Add 1 for * 'device name length' field as well */ *p_offset += DEVICE_NAME_MAX_LENGTH + 1; }
extern void BatteryReadDataFromNVM(bool bonded, uint16 *p_offset) { g_batt_data.nvm_offset = *p_offset; /* Read NVM only if devices are bonded */ if(bonded) { /* Read Battery Level Client Configuration */ Nvm_Read((uint16*)&g_batt_data.level_client_config, sizeof(g_batt_data.level_client_config), g_batt_data.nvm_offset + BATTERY_NVM_LEVEL_CLIENT_CONFIG_OFFSET); } /* Increment the offset by the number of words of NVM memory required * by battery service */ *p_offset += BATTERY_SERVICE_NVM_MEMORY_WORDS; }
extern void ScanParamReadDataFromNVM(bool bonded, uint16 *p_offset) { scan_param_data.nvm_offset = *p_offset; /* Read NVM only if devices are bonded */ if(bonded) { /* Read Scan Parameter Refresh Client Configuration */ Nvm_Read((uint16*)&scan_param_data.refresh_client_config, sizeof(gatt_client_config), scan_param_data.nvm_offset + SCAN_PARAM_NVM_REFRESH_CLIENT_CONFIG_OFFSET); } /* Increment the offset by the number of words of NVM memory required * by Scan Parameter service */ *p_offset += SCAN_PARAM_SERVICE_NVM_MEMORY_WORDS; }
/*----------------------------------------------------------------------------* * NAME * BatteryReadDataFromNVM * * DESCRIPTION * This function is used to read Battery Service specific data stored in * NVM. * * PARAMETERS * p_offset [in] Offset to Battery Service data in NVM * [out] Offset to next entry in NVM * * RETURNS * Nothing *----------------------------------------------------------------------------*/ extern void BatteryReadDataFromNVM(uint16 *p_offset) { g_batt_data.nvm_offset = *p_offset; /* Read NVM only if devices are bonded */ if(IsDeviceBonded()) { /* Read battery level client configuration descriptor */ Nvm_Read((uint16*)&g_batt_data.level_client_config, sizeof(g_batt_data.level_client_config), *p_offset + BATTERY_NVM_LEVEL_CLIENT_CONFIG_OFFSET); } /* Increment the offset by the number of words of NVM memory required * by the Battery Service */ *p_offset += BATTERY_SERVICE_NVM_MEMORY_WORDS; }
extern void TimeReadDataFromNVM(uint16 *pOffset) { g_time_serv_data.nvm_offset = *pOffset; /* Read NVM only if devices are bonded */ if(AppIsDeviceBonded()) { /* Read Current Time handle value */ Nvm_Read((uint16*)&g_time_serv_data.cur_time_handle, sizeof(g_time_serv_data.cur_time_handle), (*pOffset+TIME_NVM_CURRENT_TIME_HANDLE_OFFSET)); /* Read local time info handle value */ Nvm_Read((uint16*)&g_time_serv_data.local_time_info_handle, sizeof(g_time_serv_data.local_time_info_handle), (*pOffset+TIME_NVM_LOCAL_TIMEINFO_HANDLE_OFFSET)); /* Read the reference time handle value*/ Nvm_Read((uint16*)&g_time_serv_data.ref_time_info_handle, sizeof(g_time_serv_data.ref_time_info_handle), (*pOffset+TIME_NVM_REFERENCE_TIMEINFO_HANDLE_OFFSET)); /* Read the client configuration descriptor value for current time*/ Nvm_Read((uint16*)&g_time_serv_data.cur_time_ccd_hndl, sizeof(g_time_serv_data.cur_time_ccd_hndl), (*pOffset+TIME_NVM_CURRENT_TIME_CLIENTCFG_HANDLE_OFFSET)); /* Read the time with DST characteristic handle value */ Nvm_Read((uint16*)&g_time_serv_data.time_with_dst_handle, sizeof(g_time_serv_data.time_with_dst_handle), (*pOffset+TIME_NVM_TIME_WITH_DST_OFFSET)); /* Read the handle value of time update control point characteritic */ Nvm_Read((uint16*)&g_time_serv_data.time_update_cp_handle, sizeof(g_time_serv_data.time_update_cp_handle), (*pOffset+TIME_NVM_TIME_UPDATE_CTRL_POINT_OFFSET)); /* Read handle value of reference source update state */ Nvm_Read((uint16*)&g_time_serv_data.time_update_state_handle, sizeof(g_time_serv_data.time_update_state_handle), (*pOffset+TIME_NVM_TIME_UPDATE_STATE_OFFSET)); } /* Increment the offset by the number of words of NVM memory * required by the time profile */ *pOffset += TIME_NVM_MEMORY_WORDS; if(g_time_serv_data.cur_time_handle) { /* if cts is supported by the remote device, update the supported * - "connected_device_services" field as supported */ g_time_serv_data.connected_device_services |= cts_supported; /* if optional characteristics are also supported mark the * "optional_features_supported" field with appropriate values */ if(g_time_serv_data.local_time_info_handle) { g_time_serv_data.optional_features_supported |= lti_supported; } if(g_time_serv_data.ref_time_info_handle) { g_time_serv_data.optional_features_supported |= rti_supported; } } /* if time with dst is supported by the remote device update the supported * "connected_device_services" field as supported */ if(g_time_serv_data.time_with_dst_handle) { g_time_serv_data.connected_device_services |= nds_supported; } /* if reference time update is supported by the remote device update the * supported "connected_device_services" field as supported */ if(g_time_serv_data.time_update_cp_handle) { g_time_serv_data.connected_device_services |= rts_supported; } }