1 /* ipc_isr example
2 
3    This example code is in the Public Domain (or CC0 licensed, at your option.)
4 
5    Unless required by applicable law or agreed to in writing, this
6    software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
7    CONDITIONS OF ANY KIND, either express or implied.
8 */
9 
10 #include <stdio.h>
11 #include <string.h>
12 #include "esp_timer.h"
13 #include "esp_log.h"
14 #include "esp_ipc_isr.h"
15 #include "sdkconfig.h"
16 #if __XTENSA__
17 #include "xtensa/config/core.h"
18 #else
19 #error "Doesn't support other architectures"
20 #endif
21 
22 static const char* TAG = "example";
23 
24 typedef struct {
25     uint32_t regs[11];
26     uint32_t in[3];
27     uint32_t out[4];
28 } arg_data_t;
29 
30 void get_ps_other_cpu(void* arg);
31 void extended_ipc_isr_asm(void* arg);
32 
app_main(void)33 void app_main(void)
34 {
35     ESP_LOGI(TAG, "Start");
36     uint32_t ps_other_cpu = 0;
37     ESP_LOGI(TAG, "call get_ps_other_cpu");
38     esp_ipc_isr_asm_call_blocking(get_ps_other_cpu, &ps_other_cpu);
39     ESP_LOGI(TAG, "PS_INTLEVEL = 0x%x", ps_other_cpu & XCHAL_PS_INTLEVEL_MASK);
40     ESP_LOGI(TAG, "PS_EXCM = 0x%x", (ps_other_cpu & XCHAL_PS_EXCM_MASK) >> XCHAL_PS_EXCM_SHIFT);
41     ESP_LOGI(TAG, "PS_UM = 0x%x", (ps_other_cpu & XCHAL_PS_UM_MASK) >> XCHAL_PS_UM_SHIFT);
42 
43     ESP_LOGI(TAG, "call extended_ipc_isr_asm");
44     arg_data_t arg = { 0 };
45     arg.in[0] = 0x01;
46     arg.in[1] = 0x02;
47     arg.in[2] = 0x03;
48     ESP_LOGI(TAG, "in[0] = 0x%x", arg.in[0]);
49     ESP_LOGI(TAG, "in[1] = 0x%x", arg.in[1]);
50     ESP_LOGI(TAG, "in[2] = 0x%x", arg.in[2]);
51     esp_ipc_isr_asm_call_blocking(extended_ipc_isr_asm, (void*)&arg);
52     ESP_LOGI(TAG, "out[0] = (in[0] | in[1] | in[2]) = 0x%x", arg.out[0]);
53     assert(0x03 == arg.out[0]);
54     ESP_LOGI(TAG, "out[1] = (in[0] & in[1] & in[2]) = 0x%x", arg.out[1]);
55     assert(0x06 == arg.out[1]);
56     ESP_LOGI(TAG, "out[2] = in[2] = 0x%x", arg.out[2]);
57     assert(0x03 == arg.out[2]);
58     ESP_LOGI(TAG, "out[3] = PS of other cpu = 0x%x", arg.out[3]);
59     assert(ps_other_cpu == arg.out[3]);
60     ESP_LOGI(TAG, "End");
61 }
62