btstack_tlv: return 0 on ok for store_tag

This commit is contained in:
Matthias Ringwald 2017-08-16 14:59:53 +02:00
parent 8aecaa9f0f
commit c7f4b25f7a
3 changed files with 17 additions and 7 deletions

View File

@ -256,16 +256,23 @@ static int btstack_tlv_flash_sector_get_tag(void * context, uint32_t tag, uint8_
* @param data
* @param data_size
*/
static void btstack_tlv_flash_sector_store_tag(void * context, uint32_t tag, const uint8_t * data, uint32_t data_size){
static int btstack_tlv_flash_sector_store_tag(void * context, uint32_t tag, const uint8_t * data, uint32_t data_size){
btstack_tlv_flash_sector_t * self = (btstack_tlv_flash_sector_t *) context;
// abort if data size not aligned with flash requirements
if (!btstack_tlv_flash_sector_verify_alignment(self, data_size)) return;
if (!btstack_tlv_flash_sector_verify_alignment(self, data_size)) return 1;
// trigger migration if not enough space
if (self->write_offset + 8 + data_size > self->hal_flash_sector_impl->get_size(self->hal_flash_sector_context)){
btstack_tlv_flash_sector_migrate(self);
}
if (self->write_offset + 8 + data_size > self->hal_flash_sector_impl->get_size(self->hal_flash_sector_context)){
log_error("couldn't write entry, not enough space left");
return 2;
}
// prepare entry
uint8_t entry[8];
big_endian_store_32(entry, 0, tag);
@ -297,7 +304,7 @@ static void btstack_tlv_flash_sector_delete_tag(void * context, uint32_t tag){
static const btstack_tlv_t btstack_tlv_flash_sector = {
/* int (*get_tag)(..); */ &btstack_tlv_flash_sector_get_tag,
/* void (*store_tag)(..); */ &btstack_tlv_flash_sector_store_tag,
/* int (*store_tag)(..); */ &btstack_tlv_flash_sector_store_tag,
/* void (*delete_tag)(v..); */ &btstack_tlv_flash_sector_delete_tag,
};

View File

@ -91,7 +91,7 @@ static int btstack_tlv_esp32_get_tag(void * context, uint32_t tag, uint8_t * buf
* @param data
* @param data_size
*/
static void btstack_tlv_esp32_store_tag(void * context, uint32_t tag, const uint8_t * data, uint32_t data_size){
static int btstack_tlv_esp32_store_tag(void * context, uint32_t tag, const uint8_t * data, uint32_t data_size){
if (!nvs_active) return;
char key_buffer[9];
key_for_tag(tag, key_buffer);
@ -99,12 +99,14 @@ static void btstack_tlv_esp32_store_tag(void * context, uint32_t tag, const uint
esp_err_t err = nvs_set_blob(the_nvs_handle, key_buffer, data, data_size);
if (err != ESP_OK){
printf("Error (0x%04x) nvs_set_blob %s!\n", err, key_buffer);
return;
return 1;
}
err = nvs_commit(the_nvs_handle);
if (err != ESP_OK){
printf("Error (0x%04x) nvs_commit %s!\n", err, key_buffer);
return 1;
}
return 0;
}
/**
@ -130,7 +132,7 @@ static void btstack_tlv_esp32_delete_tag(void * context, uint32_t tag){
static const btstack_tlv_t btstack_tlv_esp32 = {
/* int (*get_tag)(..); */ &btstack_tlv_esp32_get_tag,
/* void (*store_tag)(..); */ &btstack_tlv_esp32_store_tag,
/* int (*store_tag)(..); */ &btstack_tlv_esp32_store_tag,
/* void (*delete_tag)(v..); */ &btstack_tlv_esp32_delete_tag,
};

View File

@ -63,8 +63,9 @@ typedef struct {
* @param tag
* @param data
* @param data_size
* @returns 0 on success
*/
void (*store_tag)(void * context, uint32_t tag, const uint8_t * data, uint32_t data_size);
int (*store_tag)(void * context, uint32_t tag, const uint8_t * data, uint32_t data_size);
/**
* Delete Tag