smp_interrupt_pri_tc.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. /*
  2. * Copyright (c) 2006-2024, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2024-08-10 RV the first version
  9. */
  10. #include <rtthread.h>
  11. #include "utest.h"
  12. #include <interrupt.h>
  13. /**
  14. * @brief Setting the Interrupt Priority Test.
  15. *
  16. * @note Without turning off interrupts, interrupts respond in the order in which they are triggered.
  17. * With interrupts turned off, low and high priority interrupts are triggered sequentially,
  18. * and when interrupts are turned on, high priority interrupts respond first.
  19. */
  20. #define RES_VAL 0X0
  21. #define SET_VAL 0XA
  22. #define RT_SPI_1 1
  23. #define RT_SPI_2 2
  24. #define RT_SPI_PRI_HIGH 120
  25. #define RT_SPI_PRI_LOW 140
  26. static int mode = 0;
  27. static int ipi_val[2] = {0, 0};
  28. /* Software Interrupt 1 Service Functions */
  29. static void rt_scheduler_ipi1_handler(int vector, void *param)
  30. {
  31. ipi_val[0] = SET_VAL;
  32. if (mode == 0)
  33. {
  34. uassert_true(ipi_val[0] > ipi_val[1]);
  35. }
  36. else
  37. {
  38. ipi_val[0] = RES_VAL;
  39. ipi_val[1] = RES_VAL;
  40. }
  41. }
  42. /* Software Interrupt 2 Service Functions */
  43. static void rt_scheduler_ipi2_handler(int vector, void *param)
  44. {
  45. ipi_val[1] = SET_VAL;
  46. if (mode == 0)
  47. {
  48. ipi_val[0] = RES_VAL;
  49. ipi_val[1] = RES_VAL;
  50. }
  51. else
  52. {
  53. uassert_true(ipi_val[0] < ipi_val[1]);
  54. }
  55. }
  56. /* Interrupt priority testcases 1 */
  57. static void int_pri1_tc(void)
  58. {
  59. mode = 0;
  60. unsigned int pri1, pri2;
  61. pri1 = rt_hw_interrupt_get_priority(RT_SPI_1);
  62. pri2 = rt_hw_interrupt_get_priority(RT_SPI_2);
  63. if (pri1 < pri2)
  64. uassert_true(pri1 < pri2);
  65. /* Trigger interrupt */
  66. rt_hw_ipi_send(RT_SPI_1, 0x1);
  67. rt_hw_ipi_send(RT_SPI_2, 0x1);
  68. rt_thread_delay(5);
  69. }
  70. /* Interrupt priority testcases 2 */
  71. static void int_pri2_tc(void)
  72. {
  73. mode = 1;
  74. unsigned int pri1, pri2;
  75. pri1 = rt_hw_interrupt_get_priority(RT_SPI_1);
  76. pri2 = rt_hw_interrupt_get_priority(RT_SPI_2);
  77. if (pri1 < pri2)
  78. uassert_true(pri1 < pri2);
  79. rt_base_t level = rt_hw_local_irq_disable();
  80. /* Trigger interrupt */
  81. rt_hw_ipi_send(RT_SPI_1, 0x1);
  82. rt_hw_ipi_send(RT_SPI_2, 0x1);
  83. rt_hw_local_irq_enable(level);
  84. rt_thread_delay(5);
  85. }
  86. static rt_err_t utest_tc_init(void)
  87. {
  88. /* Setting the priority of software interrupts */
  89. rt_hw_interrupt_set_priority(RT_SPI_1, RT_SPI_PRI_LOW);
  90. rt_hw_interrupt_set_priority(RT_SPI_2, RT_SPI_PRI_HIGH);
  91. /* Register software interrupt service functions */
  92. rt_hw_ipi_handler_install(RT_SPI_1, rt_scheduler_ipi1_handler);
  93. rt_hw_ipi_handler_install(RT_SPI_2, rt_scheduler_ipi2_handler);
  94. return RT_EOK;
  95. }
  96. static rt_err_t utest_tc_cleanup(void)
  97. {
  98. return RT_EOK;
  99. }
  100. static void testcase(void)
  101. {
  102. UTEST_UNIT_RUN(int_pri1_tc);
  103. UTEST_UNIT_RUN(int_pri2_tc);
  104. }
  105. UTEST_TC_EXPORT(testcase, "testcases.smp.interrupt_pri_tc", utest_tc_init, utest_tc_cleanup, 10);