mbed library sources. Supersedes mbed-src.
Dependents: Nucleo_Hello_Encoder BLE_iBeaconScan AM1805_DEMO DISCO-F429ZI_ExportTemplate1 ... more
Diff: platform/mbed_error_hist.c
- Revision:
- 187:0387e8f68319
- Parent:
- 186:707f6e361f3e
- Child:
- 189:f392fc9709a3
--- a/platform/mbed_error_hist.c Fri Jun 22 16:45:37 2018 +0100 +++ b/platform/mbed_error_hist.c Thu Sep 06 13:40:20 2018 +0100 @@ -21,42 +21,42 @@ #include "platform/mbed_critical.h" #include "platform/mbed_interface.h" -#ifndef MBED_CONF_ERROR_HIST_DISABLED +#if MBED_CONF_PLATFORM_ERROR_HIST_ENABLED #include "platform/mbed_error_hist.h" -static mbed_error_ctx mbed_error_ctx_log[MBED_CONF_ERROR_HIST_SIZE] = {0}; +static mbed_error_ctx mbed_error_ctx_log[MBED_CONF_PLATFORM_ERROR_HIST_SIZE] = {0}; static int error_log_count = -1; mbed_error_status_t mbed_error_hist_put(mbed_error_ctx *error_ctx) { //Return error if error_ctx is NULL - if(NULL == error_ctx) { + if (NULL == error_ctx) { return MBED_ERROR_INVALID_ARGUMENT; } - + core_util_critical_section_enter(); error_log_count++; - memcpy(&mbed_error_ctx_log[error_log_count % MBED_CONF_ERROR_HIST_SIZE], error_ctx, sizeof(mbed_error_ctx) ); - core_util_critical_section_exit(); - + memcpy(&mbed_error_ctx_log[error_log_count % MBED_CONF_PLATFORM_ERROR_HIST_SIZE], error_ctx, sizeof(mbed_error_ctx)); + core_util_critical_section_exit(); + return MBED_SUCCESS; } mbed_error_status_t mbed_error_hist_get(int index, mbed_error_ctx *error_ctx) { //Return error if index is more than max log size - if(index >= MBED_CONF_ERROR_HIST_SIZE) { + if (index >= MBED_CONF_PLATFORM_ERROR_HIST_SIZE) { return MBED_ERROR_INVALID_ARGUMENT; } - + core_util_critical_section_enter(); //calculate the index where we want to pick the ctx - if(error_log_count >= MBED_CONF_ERROR_HIST_SIZE) { - index = (error_log_count + index + 1) % MBED_CONF_ERROR_HIST_SIZE; + if (error_log_count >= MBED_CONF_PLATFORM_ERROR_HIST_SIZE) { + index = (error_log_count + index + 1) % MBED_CONF_PLATFORM_ERROR_HIST_SIZE; } - core_util_critical_section_exit(); - memcpy(error_ctx, &mbed_error_ctx_log[index % MBED_CONF_ERROR_HIST_SIZE], sizeof(mbed_error_ctx) ); - + core_util_critical_section_exit(); + memcpy(error_ctx, &mbed_error_ctx_log[index % MBED_CONF_PLATFORM_ERROR_HIST_SIZE], sizeof(mbed_error_ctx)); + return MBED_SUCCESS; } @@ -64,35 +64,35 @@ { core_util_critical_section_enter(); error_log_count++; - mbed_error_ctx *ctx = &mbed_error_ctx_log[error_log_count % MBED_CONF_ERROR_HIST_SIZE]; - core_util_critical_section_exit(); - + mbed_error_ctx *ctx = &mbed_error_ctx_log[error_log_count % MBED_CONF_PLATFORM_ERROR_HIST_SIZE]; + core_util_critical_section_exit(); + return ctx; } mbed_error_status_t mbed_error_hist_get_last_error(mbed_error_ctx *error_ctx) { - if(-1 == error_log_count) { + if (-1 == error_log_count) { return MBED_ERROR_ITEM_NOT_FOUND; } core_util_critical_section_enter(); - memcpy(error_ctx, &mbed_error_ctx_log[error_log_count % MBED_CONF_ERROR_HIST_SIZE], sizeof(mbed_error_ctx) ); - core_util_critical_section_exit(); - + memcpy(error_ctx, &mbed_error_ctx_log[error_log_count % MBED_CONF_PLATFORM_ERROR_HIST_SIZE], sizeof(mbed_error_ctx)); + core_util_critical_section_exit(); + return MBED_SUCCESS; } int mbed_error_hist_get_count() { - return (error_log_count >= MBED_CONF_ERROR_HIST_SIZE? MBED_CONF_ERROR_HIST_SIZE:error_log_count+1); + return (error_log_count >= MBED_CONF_PLATFORM_ERROR_HIST_SIZE ? MBED_CONF_PLATFORM_ERROR_HIST_SIZE : error_log_count + 1); } mbed_error_status_t mbed_error_hist_reset() { core_util_critical_section_enter(); error_log_count = -1; - core_util_critical_section_exit(); - + core_util_critical_section_exit(); + return MBED_SUCCESS; }