1 // Copyright 2010-2020 Espressif Systems (Shanghai) PTE LTD
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //     http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #include <stdio.h>
16 #include <stdint.h>
17 #include <stdbool.h>
18 #include "ulp_riscv/ulp_riscv.h"
19 #include "ulp_riscv/ulp_riscv_utils.h"
20 
21 typedef enum{
22     RISCV_READ_WRITE_TEST = 1,
23     RISCV_DEEP_SLEEP_WAKEUP_TEST,
24     RISCV_LIGHT_SLEEP_WAKEUP_TEST,
25     RISCV_NO_COMMAND,
26 } riscv_test_commands_t;
27 
28 typedef enum {
29     RISCV_COMMAND_OK = 1,
30     RISCV_COMMAND_NOK,
31     RISCV_COMMAND_INVALID,
32 } riscv_test_command_reply_t;
33 
34 #define XOR_MASK 0xDEADBEEF
35 
36 volatile riscv_test_commands_t main_cpu_command = RISCV_NO_COMMAND;
37 volatile riscv_test_command_reply_t main_cpu_reply = RISCV_COMMAND_INVALID;
38 volatile uint32_t riscv_test_data_in = 0;
39 volatile uint32_t riscv_test_data_out = 0;
40 
handle_commands(riscv_test_commands_t cmd)41 void handle_commands(riscv_test_commands_t cmd)
42 {
43     switch (cmd) {
44         case RISCV_READ_WRITE_TEST:
45             riscv_test_data_out =riscv_test_data_in ^ XOR_MASK;
46             main_cpu_reply =  RISCV_COMMAND_OK;
47             break;
48 
49         case RISCV_DEEP_SLEEP_WAKEUP_TEST:
50         case RISCV_LIGHT_SLEEP_WAKEUP_TEST:
51             main_cpu_reply = RISCV_COMMAND_OK;
52             break;
53 
54         default:
55             main_cpu_reply = RISCV_COMMAND_NOK;
56             break;
57     }
58     ulp_riscv_wakeup_main_processor();
59 }
60 
main(void)61 int main (void)
62 {
63     while (1) {
64         handle_commands(main_cpu_command);
65         break;
66     }
67 
68     /* ulp_riscv_shutdown() is called automatically when main exits */
69     return 0;
70 }
71