You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

mcd_example.c 1.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /*
  2. * Copyright (c) 2025, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2025-08-16 Rbb666 first version
  9. */
  10. #include <math.h>
  11. #include <stdlib.h>
  12. #include <string.h>
  13. #include "coredump.h"
  14. typedef void (*fault_func)(float);
  15. static int mcd_test(int argc, char **argv)
  16. {
  17. int x, y;
  18. const char * sx = "84597";
  19. const char * sy = "35268";
  20. float a, b, c;
  21. const char * fsa = "1.1322";
  22. const char * fsb = "45.2547";
  23. const char * fsc = "7854.2";
  24. if (argc < 2)
  25. {
  26. rt_kprintf("Please input 'mcd_test <COREDUMP|ASSERT|FAULT>' \n");
  27. return 0;
  28. }
  29. if (!strcmp(argv[1], "COREDUMP"))
  30. {
  31. mcd_faultdump(MCD_OUTPUT_SERIAL);
  32. return 0;
  33. }
  34. else if (!strcmp(argv[1], "ASSERT"))
  35. {
  36. a = atof(&fsa[0]);
  37. b = atof(&fsb[0]);
  38. c = atof(&fsc[0]);
  39. x = atoi(&sx[0]);
  40. y = atoi(&sy[0]);
  41. mcd_assert(x * a == y * b * c);
  42. return 0;
  43. }
  44. else if (!strcmp(argv[1], "FAULT"))
  45. {
  46. fault_func func = (fault_func)0xFFFF0000;
  47. a = atof(&fsa[0]);
  48. b = atof(&fsb[0]);
  49. c = atof(&fsc[0]);
  50. x = atoi(&sx[0]);
  51. y = atoi(&sy[0]);
  52. func(x * a + y * b * c);
  53. return 0;
  54. }
  55. return 0;
  56. }
  57. MCD_CMD_EXPORT(mcd_test, mCoreDump test: mcd_test <COREDUMP|FLOAT|ASSERT|FAULT>);