actions_exception.c 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /*
  2. * Copyright (c) 2017 Intel Corporation
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. #include <kernel.h>
  7. #include <debug/actions_exception.h>
  8. #define MAX_EXCEPTION_CALLBACKS 2
  9. typedef struct
  10. {
  11. int index;
  12. actions_exception_callback_routine_t callback[MAX_EXCEPTION_CALLBACKS];
  13. } exception_ctx_t;
  14. static exception_ctx_t g_exception_ctx;
  15. int exception_register_callbacks(actions_exception_callback_routine_t *cb)
  16. {
  17. int i;
  18. if (g_exception_ctx.index >= MAX_EXCEPTION_CALLBACKS) {
  19. return -ENOMEM;
  20. } else {
  21. for (i = 0; i < g_exception_ctx.index; i++) {
  22. if ( g_exception_ctx.callback[i].init_cb == cb->init_cb
  23. && g_exception_ctx.callback[i].run_cb == cb->run_cb) {
  24. return 0;
  25. }
  26. }
  27. g_exception_ctx.callback[g_exception_ctx.index].init_cb = cb->init_cb;
  28. g_exception_ctx.callback[g_exception_ctx.index].run_cb = cb->run_cb;
  29. g_exception_ctx.index++;
  30. return true;
  31. }
  32. }
  33. void exception_init(void)
  34. {
  35. int i;
  36. for (i = 0; i < g_exception_ctx.index; i++) {
  37. if (g_exception_ctx.callback[i].init_cb) {
  38. g_exception_ctx.callback[i].init_cb();
  39. }
  40. }
  41. }
  42. void exception_run(void)
  43. {
  44. int i;
  45. for (i = 0; i < g_exception_ctx.index; i++) {
  46. if (g_exception_ctx.callback[i].run_cb) {
  47. g_exception_ctx.callback[i].run_cb();
  48. }
  49. }
  50. }