Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: TYBLE16_simple_data_logger TYBLE16_MP3_Air
mbed_error_hist.c
00001 /* mbed Microcontroller Library 00002 * Copyright (c) 2006-2019 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_critical.h" 00022 00023 #if MBED_CONF_PLATFORM_ERROR_HIST_ENABLED 00024 #include "platform/source/mbed_error_hist.h" 00025 00026 static mbed_error_ctx mbed_error_ctx_log[MBED_CONF_PLATFORM_ERROR_HIST_SIZE] = {0}; 00027 static int error_log_count = -1; 00028 00029 mbed_error_status_t mbed_error_hist_put(mbed_error_ctx *error_ctx) 00030 { 00031 //Return error if error_ctx is NULL 00032 if (NULL == error_ctx) { 00033 return MBED_ERROR_INVALID_ARGUMENT; 00034 } 00035 00036 core_util_critical_section_enter(); 00037 error_log_count++; 00038 memcpy(&mbed_error_ctx_log[error_log_count % MBED_CONF_PLATFORM_ERROR_HIST_SIZE], error_ctx, sizeof(mbed_error_ctx)); 00039 core_util_critical_section_exit(); 00040 00041 return MBED_SUCCESS; 00042 } 00043 00044 mbed_error_status_t mbed_error_hist_get(int index, mbed_error_ctx *error_ctx) 00045 { 00046 //Return error if index is more than max log size 00047 if (index >= MBED_CONF_PLATFORM_ERROR_HIST_SIZE) { 00048 return MBED_ERROR_INVALID_ARGUMENT; 00049 } 00050 00051 core_util_critical_section_enter(); 00052 //calculate the index where we want to pick the ctx 00053 if (error_log_count >= MBED_CONF_PLATFORM_ERROR_HIST_SIZE) { 00054 index = (error_log_count + index + 1) % MBED_CONF_PLATFORM_ERROR_HIST_SIZE; 00055 } 00056 core_util_critical_section_exit(); 00057 memcpy(error_ctx, &mbed_error_ctx_log[index % MBED_CONF_PLATFORM_ERROR_HIST_SIZE], sizeof(mbed_error_ctx)); 00058 00059 return MBED_SUCCESS; 00060 } 00061 00062 mbed_error_ctx *mbed_error_hist_get_entry(void) 00063 { 00064 core_util_critical_section_enter(); 00065 error_log_count++; 00066 mbed_error_ctx *ctx = &mbed_error_ctx_log[error_log_count % MBED_CONF_PLATFORM_ERROR_HIST_SIZE]; 00067 core_util_critical_section_exit(); 00068 00069 return ctx; 00070 } 00071 00072 mbed_error_status_t mbed_error_hist_get_last_error(mbed_error_ctx *error_ctx) 00073 { 00074 if (-1 == error_log_count) { 00075 return MBED_ERROR_ITEM_NOT_FOUND; 00076 } 00077 core_util_critical_section_enter(); 00078 memcpy(error_ctx, &mbed_error_ctx_log[error_log_count % MBED_CONF_PLATFORM_ERROR_HIST_SIZE], sizeof(mbed_error_ctx)); 00079 core_util_critical_section_exit(); 00080 00081 return MBED_SUCCESS; 00082 } 00083 00084 int mbed_error_hist_get_count() 00085 { 00086 return (error_log_count >= MBED_CONF_PLATFORM_ERROR_HIST_SIZE ? MBED_CONF_PLATFORM_ERROR_HIST_SIZE : error_log_count + 1); 00087 } 00088 00089 mbed_error_status_t mbed_error_hist_reset() 00090 { 00091 core_util_critical_section_enter(); 00092 error_log_count = -1; 00093 core_util_critical_section_exit(); 00094 00095 return MBED_SUCCESS; 00096 } 00097 00098 #endif
Generated on Tue Jul 12 2022 13:54:33 by
