test_ipc_isr.c 2.7 KB

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