mbed library sources. Supersedes mbed-src.
Dependents: Nucleo_Hello_Encoder BLE_iBeaconScan AM1805_DEMO DISCO-F429ZI_ExportTemplate1 ... more
mbed_error_hist.c
00001 /* mbed Microcontroller Library 00002 * Copyright (c) 2006-2013 ARM Limited 00003 * SPDX-License-Identifier: Apache-2.0 00004 * 00005 * Licensed under the Apache License, Version 2.0 (the "License"); 00006 * you may not use this file except in compliance with the License. 00007 * You may obtain a copy of the License at 00008 * 00009 * http://www.apache.org/licenses/LICENSE-2.0 00010 * 00011 * Unless required by applicable law or agreed to in writing, software 00012 * distributed under the License is distributed on an "AS IS" BASIS, 00013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00014 * See the License for the specific language governing permissions and 00015 * limitations under the License. 00016 */ 00017 #include <stdlib.h> 00018 #include <stdarg.h> 00019 #include "device.h" 00020 #include "platform/mbed_error.h" 00021 #include "platform/mbed_toolchain.h" 00022 #include "platform/mbed_critical.h" 00023 #include "platform/mbed_interface.h" 00024 00025 #if MBED_CONF_PLATFORM_ERROR_HIST_ENABLED 00026 #include "platform/mbed_error_hist.h" 00027 00028 static mbed_error_ctx mbed_error_ctx_log[MBED_CONF_PLATFORM_ERROR_HIST_SIZE] = {0}; 00029 static int error_log_count = -1; 00030 00031 mbed_error_status_t mbed_error_hist_put(mbed_error_ctx *error_ctx) 00032 { 00033 //Return error if error_ctx is NULL 00034 if (NULL == error_ctx) { 00035 return MBED_ERROR_INVALID_ARGUMENT; 00036 } 00037 00038 core_util_critical_section_enter(); 00039 error_log_count++; 00040 memcpy(&mbed_error_ctx_log[error_log_count % MBED_CONF_PLATFORM_ERROR_HIST_SIZE], error_ctx, sizeof(mbed_error_ctx)); 00041 core_util_critical_section_exit(); 00042 00043 return MBED_SUCCESS; 00044 } 00045 00046 mbed_error_status_t mbed_error_hist_get(int index, mbed_error_ctx *error_ctx) 00047 { 00048 //Return error if index is more than max log size 00049 if (index >= MBED_CONF_PLATFORM_ERROR_HIST_SIZE) { 00050 return MBED_ERROR_INVALID_ARGUMENT; 00051 } 00052 00053 core_util_critical_section_enter(); 00054 //calculate the index where we want to pick the ctx 00055 if (error_log_count >= MBED_CONF_PLATFORM_ERROR_HIST_SIZE) { 00056 index = (error_log_count + index + 1) % MBED_CONF_PLATFORM_ERROR_HIST_SIZE; 00057 } 00058 core_util_critical_section_exit(); 00059 memcpy(error_ctx, &mbed_error_ctx_log[index % MBED_CONF_PLATFORM_ERROR_HIST_SIZE], sizeof(mbed_error_ctx)); 00060 00061 return MBED_SUCCESS; 00062 } 00063 00064 mbed_error_ctx *mbed_error_hist_get_entry(void) 00065 { 00066 core_util_critical_section_enter(); 00067 error_log_count++; 00068 mbed_error_ctx *ctx = &mbed_error_ctx_log[error_log_count % MBED_CONF_PLATFORM_ERROR_HIST_SIZE]; 00069 core_util_critical_section_exit(); 00070 00071 return ctx; 00072 } 00073 00074 mbed_error_status_t mbed_error_hist_get_last_error(mbed_error_ctx *error_ctx) 00075 { 00076 if (-1 == error_log_count) { 00077 return MBED_ERROR_ITEM_NOT_FOUND; 00078 } 00079 core_util_critical_section_enter(); 00080 memcpy(error_ctx, &mbed_error_ctx_log[error_log_count % MBED_CONF_PLATFORM_ERROR_HIST_SIZE], sizeof(mbed_error_ctx)); 00081 core_util_critical_section_exit(); 00082 00083 return MBED_SUCCESS; 00084 } 00085 00086 int mbed_error_hist_get_count() 00087 { 00088 return (error_log_count >= MBED_CONF_PLATFORM_ERROR_HIST_SIZE ? MBED_CONF_PLATFORM_ERROR_HIST_SIZE : error_log_count + 1); 00089 } 00090 00091 mbed_error_status_t mbed_error_hist_reset() 00092 { 00093 core_util_critical_section_enter(); 00094 error_log_count = -1; 00095 core_util_critical_section_exit(); 00096 00097 return MBED_SUCCESS; 00098 } 00099 00100 #endif
Generated on Tue Jul 12 2022 20:41:15 by 1.7.2