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.
Fork of mbed-dev by
mbed_error_hist.c
00001 /* mbed Microcontroller Library 00002 * Copyright (c) 2006-2013 ARM Limited 00003 * 00004 * Licensed under the Apache License, Version 2.0 (the "License"); 00005 * you may not use this file except in compliance with the License. 00006 * You may obtain a copy of the License at 00007 * 00008 * http://www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an "AS IS" BASIS, 00012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 */ 00016 #include <stdlib.h> 00017 #include <string.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 #ifndef MBED_CONF_ERROR_HIST_DISABLED 00026 #include "platform/mbed_error_hist.h" 00027 00028 static mbed_error_ctx mbed_error_ctx_log[MBED_CONF_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_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_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_ERROR_HIST_SIZE) { 00056 index = (error_log_count + index + 1) % MBED_CONF_ERROR_HIST_SIZE; 00057 } 00058 core_util_critical_section_exit(); 00059 memcpy(error_ctx, &mbed_error_ctx_log[index % MBED_CONF_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_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_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_ERROR_HIST_SIZE? MBED_CONF_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 12:59:33 by
1.7.2
