2020-04-17 15:34:56 -04:00
|
|
|
/* ULP-RISC-V example
|
|
|
|
|
|
|
|
This example code is in the Public Domain (or CC0 licensed, at your option.)
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, this
|
|
|
|
software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
|
|
|
CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
|
2020-11-10 02:40:01 -05:00
|
|
|
This code runs on ULP-RISC-V coprocessor
|
2020-04-17 15:34:56 -04:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include "ulp_riscv/ulp_riscv.h"
|
|
|
|
#include "ulp_riscv/ulp_riscv_utils.h"
|
2021-06-23 02:54:36 -04:00
|
|
|
#include "ulp_riscv/ulp_riscv_gpio.h"
|
2020-04-17 15:34:56 -04:00
|
|
|
|
|
|
|
static bool gpio_level = false;
|
|
|
|
|
|
|
|
/* this variable will be exported as a public symbol, visible from main CPU: */
|
|
|
|
bool gpio_level_previous = false;
|
|
|
|
|
|
|
|
int main (void)
|
|
|
|
{
|
2021-06-23 02:54:36 -04:00
|
|
|
gpio_level = (bool)ulp_riscv_gpio_get_level(GPIO_NUM_0);
|
2020-04-17 15:34:56 -04:00
|
|
|
gpio_level_previous = gpio_level;
|
|
|
|
|
|
|
|
while(1) {
|
2021-06-23 02:54:36 -04:00
|
|
|
gpio_level = (bool)ulp_riscv_gpio_get_level(GPIO_NUM_0);
|
2020-04-17 15:34:56 -04:00
|
|
|
|
|
|
|
/* Wakes up the main CPU if pin changed its state */
|
|
|
|
if(gpio_level != gpio_level_previous) {
|
|
|
|
gpio_level_previous = gpio_level;
|
|
|
|
ulp_riscv_wakeup_main_processor();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2022-01-18 21:57:31 -05:00
|
|
|
/* ulp_riscv_halt() is called automatically when main exits */
|
2020-04-17 15:34:56 -04:00
|
|
|
return 0;
|
2020-11-10 02:40:01 -05:00
|
|
|
}
|