1 /* Implementation of utility functions to verify
2    unit tests aren't performing SMP-unsafe DPORT reads.
3 */
4 
5 #include "unity.h"
6 #include "sdkconfig.h"
7 #include "freertos/FreeRTOS.h"
8 #include "freertos/task.h"
9 #include "soc/uart_periph.h"
10 #include "test_apb_dport_access.h"
11 #include "test_utils.h"
12 
13 #ifndef CONFIG_FREERTOS_UNICORE
14 
15 static void apb_access_loop_task(void *ignore);
16 
17 static volatile bool apb_access_corrupt;
18 static TaskHandle_t apb_task_handle;
19 
start_apb_access_loop(void)20 void start_apb_access_loop(void)
21 {
22     apb_access_corrupt = false;
23     xTaskCreatePinnedToCore(apb_access_loop_task, "accessAPB", 2048, NULL,
24                             UNITY_FREERTOS_PRIORITY - 1,
25                             &apb_task_handle, !UNITY_FREERTOS_CPU);
26 }
27 
verify_apb_access_loop(void)28 void verify_apb_access_loop(void)
29 {
30     vTaskDelete(apb_task_handle);
31     apb_task_handle = NULL;
32     TEST_ASSERT_FALSE(apb_access_corrupt);
33     printf("Verified no APB corruption from operations\n");
34 }
35 
apb_access_loop_task(void * ignore)36 static void apb_access_loop_task(void *ignore)
37 {
38     uint32_t initial = REG_READ(UART_DATE_REG(0));
39     while(1) {
40         if (REG_READ(UART_DATE_REG(0)) != initial) {
41             apb_access_corrupt = true;
42         }
43     }
44 }
45 
46 #else /*CONFIG_FREERTOS_UNICORE */
47 
start_apb_access_loop(void)48 void start_apb_access_loop(void)
49 {
50 }
51 
verify_apb_access_loop(void)52 void verify_apb_access_loop(void)
53 {
54 }
55 
56 #endif
57