From 82c98618cd063cd09f6c43ee0c7cb0f82d21f4d1 Mon Sep 17 00:00:00 2001 From: Dustin Crossman Date: Tue, 5 Jan 2021 13:51:52 -0800 Subject: [PATCH] Ran astyle for mbed code format. --- .../cy_ext_wifi_fw_reserved_region_bd.cpp | 5 +- .../ext-wifi-fw/cy_ext_wifi_fw_resources.c | 109 +++++++----------- .../CyReservedRegionBlockDevice.cpp | 16 +-- 3 files changed, 49 insertions(+), 81 deletions(-) diff --git a/targets/TARGET_Cypress/TARGET_PSOC6/common/ext-wifi-fw/cy_ext_wifi_fw_reserved_region_bd.cpp b/targets/TARGET_Cypress/TARGET_PSOC6/common/ext-wifi-fw/cy_ext_wifi_fw_reserved_region_bd.cpp index 8db6460d5e..b149d4025a 100644 --- a/targets/TARGET_Cypress/TARGET_PSOC6/common/ext-wifi-fw/cy_ext_wifi_fw_reserved_region_bd.cpp +++ b/targets/TARGET_Cypress/TARGET_PSOC6/common/ext-wifi-fw/cy_ext_wifi_fw_reserved_region_bd.cpp @@ -53,15 +53,14 @@ CyReservedRegionBlockDevice *cy_get_ext_wifi_fw_reserved_region_bd() } extern "C" { -extern void cy_ext_wifi_fw_resources_update_handles(void *image_addr, unsigned long image_size, void *clm_blob_addr, unsigned long clm_blob_size); + extern void cy_ext_wifi_fw_resources_update_handles(void *image_addr, unsigned long image_size, void *clm_blob_addr, unsigned long clm_blob_size); } int cy_update_ext_wifi_fw_location_and_size(mbed::bd_addr_t image_addr, mbed::bd_size_t image_size, mbed::bd_addr_t clm_blob_addr, mbed::bd_size_t clm_blob_size) { CyReservedRegionBlockDevice *bd = cy_get_ext_wifi_fw_reserved_region_bd(); // If the reserved region end is NULL, the block device hasn't been initialized yet, so we can't perform this check - if ((bd->reserved_region_end() != 0) && (image_addr + image_size > bd->reserved_region_end() || clm_blob_addr + clm_blob_size > bd->reserved_region_end())) - { + if ((bd->reserved_region_end() != 0) && (image_addr + image_size > bd->reserved_region_end() || clm_blob_addr + clm_blob_size > bd->reserved_region_end())) { // Should not exceed originally computed reserved region size, as this will break anything that was using the rest of external storage return -1; } diff --git a/targets/TARGET_Cypress/TARGET_PSOC6/common/ext-wifi-fw/cy_ext_wifi_fw_resources.c b/targets/TARGET_Cypress/TARGET_PSOC6/common/ext-wifi-fw/cy_ext_wifi_fw_resources.c index 0ce615105a..83e27290cd 100644 --- a/targets/TARGET_Cypress/TARGET_PSOC6/common/ext-wifi-fw/cy_ext_wifi_fw_resources.c +++ b/targets/TARGET_Cypress/TARGET_PSOC6/common/ext-wifi-fw/cy_ext_wifi_fw_resources.c @@ -68,9 +68,9 @@ extern "C" { * Static Function Declarations ******************************************************/ uint32_t ext_wifi_fw_host_get_resource_block(whd_driver_t whd_drv, whd_resource_type_t type, - uint32_t blockno, const uint8_t **data, uint32_t *size_out); + uint32_t blockno, const uint8_t **data, uint32_t *size_out); resource_result_t ext_wifi_fw_resource_read(const resource_hnd_t *resource, uint32_t offset, uint32_t maxsize, uint32_t *size, - void *buffer); + void *buffer); extern uint32_t host_platform_resource_size(whd_driver_t whd_drv, whd_resource_type_t resource, uint32_t *size_out); extern uint32_t host_get_resource_block_size(whd_driver_t whd_drv, whd_resource_type_t type, uint32_t *size_out); @@ -119,29 +119,28 @@ void *dynamic_nvram_image = &wifi_nvram_image; void try_init_external_handles() { - if (!external_handles_initialized) - { + if (!external_handles_initialized) { #if defined(WLAN_MFG_FIRMWARE) - wifi_mfg_firmware_image_external = (resource_hnd_t){ + wifi_mfg_firmware_image_external = (resource_hnd_t) { RESOURCE_IN_EXTERNAL_STORAGE, wifi_mfg_firmware_image.size, - { .external_storage_context = (void *) (wifi_mfg_firmware_image.val.mem.data - (uint32_t) CY_WIFI_FW_SECTION_START) } + { .external_storage_context = (void *)(wifi_mfg_firmware_image.val.mem.data - (uint32_t) CY_WIFI_FW_SECTION_START) } }; - wifi_mfg_firmware_clm_blob_external = (resource_hnd_t){ + wifi_mfg_firmware_clm_blob_external = (resource_hnd_t) { RESOURCE_IN_EXTERNAL_STORAGE, wifi_mfg_firmware_clm_blob.size, - { .external_storage_context = (void *) (wifi_mfg_firmware_clm_blob.val.mem.data - (uint32_t) CY_WIFI_FW_SECTION_START) } + { .external_storage_context = (void *)(wifi_mfg_firmware_clm_blob.val.mem.data - (uint32_t) CY_WIFI_FW_SECTION_START) } }; #else - wifi_firmware_image_external = (resource_hnd_t){ + wifi_firmware_image_external = (resource_hnd_t) { RESOURCE_IN_EXTERNAL_STORAGE, wifi_firmware_image.size, - { .external_storage_context = (void *) (wifi_firmware_image.val.mem.data - (uint32_t) CY_WIFI_FW_SECTION_START) } + { .external_storage_context = (void *)(wifi_firmware_image.val.mem.data - (uint32_t) CY_WIFI_FW_SECTION_START) } }; - wifi_firmware_clm_blob_external = (resource_hnd_t){ + wifi_firmware_clm_blob_external = (resource_hnd_t) { RESOURCE_IN_EXTERNAL_STORAGE, wifi_firmware_clm_blob.size, - { .external_storage_context = (void *) (wifi_firmware_clm_blob.val.mem.data - (uint32_t) CY_WIFI_FW_SECTION_START) } + { .external_storage_context = (void *)(wifi_firmware_clm_blob.val.mem.data - (uint32_t) CY_WIFI_FW_SECTION_START) } }; #endif /* defined(WLAN_MFG_FIRMWARE) */ external_handles_initialized = true; @@ -158,65 +157,53 @@ void cy_ext_wifi_fw_resources_update_handles(void *image_addr, unsigned long ima } resource_result_t ext_wifi_fw_resource_read(const resource_hnd_t *resource, uint32_t offset, uint32_t maxsize, uint32_t *size, - void *buffer) + void *buffer) { - if (offset > resource->size) - { + if (offset > resource->size) { return RESOURCE_OFFSET_TOO_BIG; } *size = MIN(maxsize, resource->size - offset); - if (resource->location == RESOURCE_IN_MEMORY) - { + if (resource->location == RESOURCE_IN_MEMORY) { memcpy(buffer, &resource->val.mem.data[offset], *size); - } - else if (resource->location == RESOURCE_IN_EXTERNAL_STORAGE) - { + } else if (resource->location == RESOURCE_IN_EXTERNAL_STORAGE) { return platform_read_external_resource(resource, offset, maxsize, size, buffer); } #ifdef USES_RESOURCE_GENERIC_FILESYSTEM - else - { + else { wiced_file_t file_handle; uint64_t size64; uint64_t maxsize64 = maxsize; if (WICED_SUCCESS != - wiced_filesystem_file_open (&resource_fs_handle, &file_handle, resource->val.fs.filename, - WICED_FILESYSTEM_OPEN_FOR_READ) ) - { + wiced_filesystem_file_open(&resource_fs_handle, &file_handle, resource->val.fs.filename, + WICED_FILESYSTEM_OPEN_FOR_READ)) { return RESOURCE_FILE_OPEN_FAIL; } - if (WICED_SUCCESS != wiced_filesystem_file_seek (&file_handle, (offset + resource->val.fs.offset), SEEK_SET) ) - { + if (WICED_SUCCESS != wiced_filesystem_file_seek(&file_handle, (offset + resource->val.fs.offset), SEEK_SET)) { return RESOURCE_FILE_SEEK_FAIL; } - if (WICED_SUCCESS != wiced_filesystem_file_read (&file_handle, buffer, maxsize64, &size64) ) - { - wiced_filesystem_file_close (&file_handle); + if (WICED_SUCCESS != wiced_filesystem_file_read(&file_handle, buffer, maxsize64, &size64)) { + wiced_filesystem_file_close(&file_handle); return RESOURCE_FILE_READ_FAIL; } *size = (uint32_t)size64; - wiced_filesystem_file_close (&file_handle); + wiced_filesystem_file_close(&file_handle); } #elif USES_RESOURCE_FILESYSTEM - else - { + else { wicedfs_file_t file_hnd; - if (0 != wicedfs_fopen(&resource_fs_handle, &file_hnd, resource->val.fs.filename) ) - { + if (0 != wicedfs_fopen(&resource_fs_handle, &file_hnd, resource->val.fs.filename)) { return RESOURCE_FILE_OPEN_FAIL; } - if (0 != wicedfs_fseek(&file_hnd, (long)(offset + resource->val.fs.offset), SEEK_SET) ) - { + if (0 != wicedfs_fseek(&file_hnd, (long)(offset + resource->val.fs.offset), SEEK_SET)) { wicedfs_fclose(&file_hnd); return RESOURCE_FILE_SEEK_FAIL; } - if (*size != wicedfs_fread(buffer, 1, *size, &file_hnd) ) - { + if (*size != wicedfs_fread(buffer, 1, *size, &file_hnd)) { wicedfs_fclose(&file_hnd); return RESOURCE_FILE_READ_FAIL; } @@ -228,7 +215,7 @@ resource_result_t ext_wifi_fw_resource_read(const resource_hnd_t *resource, uint } uint32_t ext_wifi_fw_host_get_resource_block(whd_driver_t whd_drv, whd_resource_type_t type, - uint32_t blockno, const uint8_t **data, uint32_t *size_out) + uint32_t blockno, const uint8_t **data, uint32_t *size_out) { uint32_t resource_size; uint32_t block_size; @@ -244,17 +231,14 @@ uint32_t ext_wifi_fw_host_get_resource_block(whd_driver_t whd_drv, whd_resource_ memset(whd_r_buffer, 0, block_size); read_pos = blockno * block_size; - if (blockno >= block_count) - { + if (blockno >= block_count) { return WHD_BADARG; } - if (type == WHD_RESOURCE_WLAN_FIRMWARE) - { - result = ext_wifi_fw_resource_read( (const resource_hnd_t *)&WIFI_FIRMWARE_IMAGE, read_pos, block_size, size_out, - whd_r_buffer ); - if (result != WHD_SUCCESS) - { + if (type == WHD_RESOURCE_WLAN_FIRMWARE) { + result = ext_wifi_fw_resource_read((const resource_hnd_t *)&WIFI_FIRMWARE_IMAGE, read_pos, block_size, size_out, + whd_r_buffer); + if (result != WHD_SUCCESS) { return result; } *data = (uint8_t *)&whd_r_buffer; @@ -267,26 +251,18 @@ uint32_t ext_wifi_fw_host_get_resource_block(whd_driver_t whd_drv, whd_resource_ * For sending the entire buffer in single block set size out as following * *size_out = (uint32_t)resource_get_size(&wifi_firmware_image); */ - } - else if (type == WHD_RESOURCE_WLAN_NVRAM) - { - if (NVRAM_SIZE - read_pos > block_size) - { + } else if (type == WHD_RESOURCE_WLAN_NVRAM) { + if (NVRAM_SIZE - read_pos > block_size) { *size_out = block_size; - } - else - { + } else { *size_out = NVRAM_SIZE - read_pos; } - *data = ( (uint8_t *)NVRAM_IMAGE_VARIABLE ) + read_pos; - } - else - { - result = ext_wifi_fw_resource_read( (const resource_hnd_t *)&WIFI_FIRMWARE_CLM_BLOB, read_pos, block_size, - size_out, - whd_r_buffer ); - if (result != WHD_SUCCESS) - { + *data = ((uint8_t *)NVRAM_IMAGE_VARIABLE) + read_pos; + } else { + result = ext_wifi_fw_resource_read((const resource_hnd_t *)&WIFI_FIRMWARE_CLM_BLOB, read_pos, block_size, + size_out, + whd_r_buffer); + if (result != WHD_SUCCESS) { return result; } *data = (uint8_t *)&whd_r_buffer; @@ -305,8 +281,7 @@ uint32_t ext_wifi_fw_host_get_resource_block(whd_driver_t whd_drv, whd_resource_ return WHD_SUCCESS; } -whd_resource_source_t cy_ext_wifi_fw_resource_ops = -{ +whd_resource_source_t cy_ext_wifi_fw_resource_ops = { .whd_resource_size = host_platform_resource_size, .whd_get_resource_block_size = host_get_resource_block_size, .whd_get_resource_no_of_blocks = host_get_resource_no_of_blocks, diff --git a/targets/TARGET_Cypress/TARGET_PSOC6/common/reserved-region-bd/CyReservedRegionBlockDevice.cpp b/targets/TARGET_Cypress/TARGET_PSOC6/common/reserved-region-bd/CyReservedRegionBlockDevice.cpp index 46e4481ce8..72d9a0a080 100644 --- a/targets/TARGET_Cypress/TARGET_PSOC6/common/reserved-region-bd/CyReservedRegionBlockDevice.cpp +++ b/targets/TARGET_Cypress/TARGET_PSOC6/common/reserved-region-bd/CyReservedRegionBlockDevice.cpp @@ -35,16 +35,12 @@ CyReservedRegionBlockDevice::CyReservedRegionBlockDevice(BlockDevice *underlying int CyReservedRegionBlockDevice::init() { int status = _underlying_bd->init(); - if (status == BD_ERROR_OK) - { + if (status == BD_ERROR_OK) { // Round up to start usable region on an erase boundary // May need to wait until after init() to determine erase size (e.g. QSPI) - if (_reserved_region_size % get_erase_size() != 0) - { + if (_reserved_region_size % get_erase_size() != 0) { _reserved_region_end = _reserved_region_size + get_erase_size() - (_reserved_region_size % get_erase_size()); - } - else - { + } else { _reserved_region_end = _reserved_region_size; } } @@ -54,8 +50,7 @@ int CyReservedRegionBlockDevice::init() int CyReservedRegionBlockDevice::deinit() { int status = _underlying_bd->deinit(); - if (status == BD_ERROR_OK) - { + if (status == BD_ERROR_OK) { _reserved_region_end = 0; } return status; @@ -113,8 +108,7 @@ const char *CyReservedRegionBlockDevice::get_type() const int CyReservedRegionBlockDevice::reserved_read(void *buffer, mbed::bd_addr_t addr, mbed::bd_size_t size) { - if (addr + size > _reserved_region_end || addr % get_read_size() != 0 || size % get_read_size() != 0) - { + if (addr + size > _reserved_region_end || addr % get_read_size() != 0 || size % get_read_size() != 0) { return BD_ERROR_DEVICE_ERROR; }