test_main.c 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. #include <stdio.h>
  15. #include <stdint.h>
  16. #include <stdbool.h>
  17. #include "ulp_riscv/ulp_riscv.h"
  18. #include "ulp_riscv/ulp_riscv_utils.h"
  19. typedef enum{
  20. RISCV_READ_WRITE_TEST = 1,
  21. RISCV_DEEP_SLEEP_WAKEUP_TEST,
  22. RISCV_LIGHT_SLEEP_WAKEUP_TEST,
  23. RISCV_NO_COMMAND,
  24. } riscv_test_commands_t;
  25. typedef enum {
  26. RISCV_COMMAND_OK = 1,
  27. RISCV_COMMAND_NOK,
  28. RISCV_COMMAND_INVALID,
  29. } riscv_test_command_reply_t;
  30. #define XOR_MASK 0xDEADBEEF
  31. volatile riscv_test_commands_t main_cpu_command = RISCV_NO_COMMAND;
  32. volatile riscv_test_command_reply_t main_cpu_reply = RISCV_COMMAND_INVALID;
  33. volatile uint32_t riscv_test_data_in = 0;
  34. volatile uint32_t riscv_test_data_out = 0;
  35. void handle_commands(riscv_test_commands_t cmd)
  36. {
  37. switch (cmd) {
  38. case RISCV_READ_WRITE_TEST:
  39. riscv_test_data_out =riscv_test_data_in ^ XOR_MASK;
  40. main_cpu_reply = RISCV_COMMAND_OK;
  41. break;
  42. case RISCV_DEEP_SLEEP_WAKEUP_TEST:
  43. case RISCV_LIGHT_SLEEP_WAKEUP_TEST:
  44. main_cpu_reply = RISCV_COMMAND_OK;
  45. break;
  46. default:
  47. main_cpu_reply = RISCV_COMMAND_NOK;
  48. break;
  49. }
  50. ulp_riscv_wakeup_main_processor();
  51. }
  52. int main (void)
  53. {
  54. while (1) {
  55. handle_commands(main_cpu_command);
  56. break;
  57. }
  58. /* ulp_riscv_shutdown() is called automatically when main exits */
  59. return 0;
  60. }