mbed_error_hist.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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. #ifndef MBED_ERROR_HIST_H
  17. #define MBED_ERROR_HIST_H
  18. #ifndef MBED_CONF_PLATFORM_ERROR_HIST_SIZE
  19. #define MBED_CONF_PLATFORM_ERROR_HIST_SIZE 4
  20. #else
  21. #if MBED_CONF_PLATFORM_ERROR_HIST_SIZE == 0
  22. #define MBED_CONF_PLATFORM_ERROR_HIST_SIZE 1
  23. #endif
  24. #endif
  25. #ifdef __cplusplus
  26. extern "C" {
  27. #endif
  28. /*
  29. * Puts/Adds an error entry into the error history list
  30. *
  31. * @param error_ctx pointer to the mbed_error_ctx struct with the error context
  32. * @return 0 or MBED_SUCCESS on success.
  33. * MBED_ERROR_WRITE_FAILED if writing to file failed
  34. * MBED_ERROR_INVALID_ARGUMENT if path is not valid
  35. *
  36. *
  37. */
  38. mbed_error_status_t mbed_error_hist_put(mbed_error_ctx *error_ctx);
  39. /*
  40. * Reads the error entry from the error list with the specified index
  41. *
  42. * @param index Index of the error context to be retrieved. It starts from 0 and 0 is the oldest.
  43. * @param error_ctx pointer to the mbed_error_ctx struct where the error context will be filled, this should be allocated by the caller
  44. * @return 0 or MBED_SUCCESS on success.
  45. * MBED_ERROR_WRITE_FAILED if writing to file failed
  46. * MBED_ERROR_INVALID_ARGUMENT if path is not valid
  47. *
  48. *
  49. */
  50. mbed_error_status_t mbed_error_hist_get(int index, mbed_error_ctx *error_ctx);
  51. /*
  52. * Gets a reference to the next error entry in the error log where in the error ctx can be filled in.
  53. * Its like reserving the next error entry to fill in the error info
  54. *
  55. * @return Returns the pointer to the next error ctx entry
  56. *
  57. *
  58. */
  59. mbed_error_ctx *mbed_error_hist_get_entry(void);
  60. /*
  61. * Reads the last(latest) error entry from the error history
  62. *
  63. * @param error_ctx pointer to the mbed_error_ctx struct where the error context will be filled, this should be allocated by the caller
  64. * @return 0 or MBED_SUCCESS on success.
  65. * MBED_ERROR_WRITE_FAILED if writing to file failed
  66. * MBED_ERROR_INVALID_ARGUMENT if path is not valid
  67. *
  68. *
  69. */
  70. mbed_error_status_t mbed_error_hist_get_last_error(mbed_error_ctx *error_ctx);
  71. /*
  72. * Returns the number of error entries in the error history list
  73. *
  74. * @return Number of entries in the history list
  75. *
  76. *
  77. */
  78. int mbed_error_hist_get_count(void);
  79. /*
  80. * Resets the error log by resetting the number of errors to 0 and clears all previous errors in the history list
  81. *
  82. * @return 0 or MBED_SUCCESS on success.
  83. * MBED_ERROR_WRITE_FAILED if writing to file failed
  84. * MBED_ERROR_INVALID_ARGUMENT if path is not valid
  85. *
  86. *
  87. */
  88. mbed_error_status_t mbed_error_hist_reset(void);
  89. /*
  90. * Saves the error log information to a file
  91. *
  92. * @param path path to the file in the filesystem
  93. * @return 0 or MBED_SUCCESS on success.
  94. * MBED_ERROR_WRITE_FAILED if writing to file failed
  95. * MBED_ERROR_INVALID_ARGUMENT if path is not valid
  96. *
  97. * @note Filesystem support is required in order for this function to work.
  98. *
  99. */
  100. mbed_error_status_t mbed_save_error_hist(const char *path);
  101. #ifdef __cplusplus
  102. }
  103. #endif
  104. #endif