source: asp3_tinet_ecnl_arm/trunk/asp3_dcre/mbed/platform/mbed_error_hist.c@ 374

Last change on this file since 374 was 374, checked in by coas-nagasima, 5 years ago

mbed関連を更新
シリアルドライバをmbedのHALを使うよう変更
ファイルディスクリプタの処理を更新

  • Property charset set to UTF-8
  • Property svn:eol-style set to native
  • Property svn:mime-type set to text/x-csrc
File size: 3.1 KB
Line 
1/* mbed Microcontroller Library
2 * Copyright (c) 2006-2013 ARM Limited
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16#include <stdlib.h>
17#include <stdarg.h>
18#include "device.h"
19#include "platform/mbed_error.h"
20#include "platform/mbed_toolchain.h"
21#include "platform/mbed_critical.h"
22#include "platform/mbed_interface.h"
23
24#if MBED_CONF_PLATFORM_ERROR_HIST_ENABLED
25#include "platform/mbed_error_hist.h"
26
27static mbed_error_ctx mbed_error_ctx_log[MBED_CONF_PLATFORM_ERROR_HIST_SIZE] = {0};
28static int error_log_count = -1;
29
30mbed_error_status_t mbed_error_hist_put(mbed_error_ctx *error_ctx)
31{
32 //Return error if error_ctx is NULL
33 if (NULL == error_ctx) {
34 return MBED_ERROR_INVALID_ARGUMENT;
35 }
36
37 core_util_critical_section_enter();
38 error_log_count++;
39 memcpy(&mbed_error_ctx_log[error_log_count % MBED_CONF_PLATFORM_ERROR_HIST_SIZE], error_ctx, sizeof(mbed_error_ctx));
40 core_util_critical_section_exit();
41
42 return MBED_SUCCESS;
43}
44
45mbed_error_status_t mbed_error_hist_get(int index, mbed_error_ctx *error_ctx)
46{
47 //Return error if index is more than max log size
48 if (index >= MBED_CONF_PLATFORM_ERROR_HIST_SIZE) {
49 return MBED_ERROR_INVALID_ARGUMENT;
50 }
51
52 core_util_critical_section_enter();
53 //calculate the index where we want to pick the ctx
54 if (error_log_count >= MBED_CONF_PLATFORM_ERROR_HIST_SIZE) {
55 index = (error_log_count + index + 1) % MBED_CONF_PLATFORM_ERROR_HIST_SIZE;
56 }
57 core_util_critical_section_exit();
58 memcpy(error_ctx, &mbed_error_ctx_log[index % MBED_CONF_PLATFORM_ERROR_HIST_SIZE], sizeof(mbed_error_ctx));
59
60 return MBED_SUCCESS;
61}
62
63mbed_error_ctx *mbed_error_hist_get_entry(void)
64{
65 core_util_critical_section_enter();
66 error_log_count++;
67 mbed_error_ctx *ctx = &mbed_error_ctx_log[error_log_count % MBED_CONF_PLATFORM_ERROR_HIST_SIZE];
68 core_util_critical_section_exit();
69
70 return ctx;
71}
72
73mbed_error_status_t mbed_error_hist_get_last_error(mbed_error_ctx *error_ctx)
74{
75 if (-1 == error_log_count) {
76 return MBED_ERROR_ITEM_NOT_FOUND;
77 }
78 core_util_critical_section_enter();
79 memcpy(error_ctx, &mbed_error_ctx_log[error_log_count % MBED_CONF_PLATFORM_ERROR_HIST_SIZE], sizeof(mbed_error_ctx));
80 core_util_critical_section_exit();
81
82 return MBED_SUCCESS;
83}
84
85int mbed_error_hist_get_count()
86{
87 return (error_log_count >= MBED_CONF_PLATFORM_ERROR_HIST_SIZE ? MBED_CONF_PLATFORM_ERROR_HIST_SIZE : error_log_count + 1);
88}
89
90mbed_error_status_t mbed_error_hist_reset()
91{
92 core_util_critical_section_enter();
93 error_log_count = -1;
94 core_util_critical_section_exit();
95
96 return MBED_SUCCESS;
97}
98
99#endif
Note: See TracBrowser for help on using the repository browser.