utility.c 1020 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #include "FreeRTOS.h"
  2. #include "task.h"
  3. #include "queue.h"
  4. #include "semphr.h"
  5. #include "utility.h"
  6. #include "at32f403a_407_int.h"
  7. #include <stdio.h>
  8. #if 1
  9. // OS stack overflow hook
  10. #if (configCHECK_FOR_STACK_OVERFLOW > 0)
  11. void vApplicationStackOverflowHook( xTaskHandle *pxTask, signed char *pcTaskName )
  12. {
  13. NVIC_SystemReset();
  14. }
  15. #endif
  16. #endif
  17. // OS malloc failed hook
  18. #if (configUSE_MALLOC_FAILED_HOOK > 0)
  19. void vApplicationMallocFailedHook(void)
  20. {
  21. NVIC_SystemReset();
  22. while(1);
  23. }
  24. #endif
  25. //
  26. void print_binary_byte(uint8_t val)
  27. {
  28. for (int i = 7; i >= 0; i--) {
  29. if (val & (1 << i))
  30. printf("1");
  31. else
  32. printf("0");
  33. if (i == 4)
  34. printf(" ");
  35. }
  36. printf("\r\n");
  37. }
  38. //
  39. void print_binary_half_word(uint16_t val)
  40. {
  41. for (int i = 15; i >= 0; i--) {
  42. if (val & (1 << i))
  43. printf("1");
  44. else
  45. printf("0");
  46. if ((i == 12) || (i == 8) || (i == 4))
  47. printf(" ");
  48. }
  49. printf("\r\n");
  50. }