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