test_ipc_isr.c 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. #include <stdio.h>
  2. #include "sdkconfig.h"
  3. #include "freertos/FreeRTOS.h"
  4. #include "freertos/task.h"
  5. #include "freertos/semphr.h"
  6. #include "unity.h"
  7. #include "test_utils.h"
  8. #include "esp_rom_sys.h"
  9. #include "esp_ipc_isr.h"
  10. #ifdef CONFIG_ESP_IPC_ISR_ENABLE
  11. void esp_test_ipc_isr_asm(void* arg);
  12. TEST_CASE("Test ipc_isr blocking IPC function calls a ASM function", "[ipc]")
  13. {
  14. int val = 0x5a5a;
  15. esp_ipc_isr_asm_call_blocking(esp_test_ipc_isr_asm, &val);
  16. TEST_ASSERT_EQUAL_HEX(val, 0xa5a5);
  17. }
  18. void esp_test_ipc_isr_get_other_core_id(void* arg);
  19. TEST_CASE("Test ipc_isr blocking IPC function calls get_other_core_id", "[ipc]")
  20. {
  21. int val = 0x5a5a;
  22. esp_ipc_isr_asm_call_blocking(esp_test_ipc_isr_get_other_core_id, &val);
  23. TEST_ASSERT_EQUAL_HEX(val, 1);
  24. }
  25. TEST_CASE("Test ipc_isr exception in asm func leads to StoreProhibited not to Unhandled debug exception", "[ipc][reset=StoreProhibited,SW_CPU_RESET]")
  26. {
  27. esp_ipc_isr_asm_call_blocking(esp_test_ipc_isr_asm, NULL);
  28. }
  29. void esp_test_ipc_isr_get_cycle_count_other_cpu(void* arg);
  30. TEST_CASE("Test ipc_isr blocking IPC function calls get_cycle_count_other_cpu", "[ipc]")
  31. {
  32. int val = 0x5a5a;
  33. esp_ipc_isr_asm_call_blocking(esp_test_ipc_isr_get_cycle_count_other_cpu, &val);
  34. esp_rom_printf("CCOUNT CPU0 = %d\n", cpu_ll_get_cycle_count());
  35. esp_rom_printf("CCOUNT CPU1 = %d\n", val);
  36. }
  37. static bool volatile s_stop;
  38. static void task_asm(void *arg)
  39. {
  40. xSemaphoreHandle *sema = (xSemaphoreHandle *) arg;
  41. int val;
  42. int counter = 0;
  43. printf("task_asm\n");
  44. while (s_stop == false) {
  45. val = 0x5a5a;
  46. esp_ipc_isr_asm_call_blocking(esp_test_ipc_isr_asm, &val);
  47. TEST_ASSERT_EQUAL_HEX(val, 0xa5a5);
  48. ++counter;
  49. }
  50. printf("task_asm counter = %d\n", counter);
  51. TEST_ASSERT_GREATER_THAN(1000000, counter);
  52. xSemaphoreGive(*sema);
  53. vTaskDelete(NULL);
  54. }
  55. TEST_CASE("Test ipc_isr two tasks use IPC function calls", "[ipc]")
  56. {
  57. xSemaphoreHandle exit_sema[2];
  58. exit_sema[0] = xSemaphoreCreateBinary();
  59. exit_sema[1] = xSemaphoreCreateBinary();
  60. s_stop = false;
  61. printf("Test start\n");
  62. xTaskCreatePinnedToCore(task_asm, "task_asm", 2048, &exit_sema[0], UNITY_FREERTOS_PRIORITY - 1, NULL, 0);
  63. xTaskCreatePinnedToCore(task_asm, "task_asm", 2048, &exit_sema[1], UNITY_FREERTOS_PRIORITY - 1, NULL, 1);
  64. vTaskDelay(5000 / portTICK_PERIOD_MS);
  65. s_stop = true;
  66. xSemaphoreTake(exit_sema[0], portMAX_DELAY);
  67. xSemaphoreTake(exit_sema[1], portMAX_DELAY);
  68. printf("Test end\n");
  69. vSemaphoreDelete(exit_sema[0]);
  70. vSemaphoreDelete(exit_sema[1]);
  71. }
  72. #endif /* CONFIG_ESP_IPC_ISR_ENABLE */