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