minimacplus/firmware/components/tme-esp32/main.c

83 lines
2.0 KiB
C

/*
* ----------------------------------------------------------------------------
* "THE BEER-WARE LICENSE" (Revision 42):
* Jeroen Domburg <jeroen@spritesmods.com> wrote this file. As long as you retain
* this notice you can do whatever you want with this stuff. If we meet some day,
* and you think this stuff is worth it, you can buy me a beer in return.
* ----------------------------------------------------------------------------
*/
#include "esp_attr.h"
#include "rom/cache.h"
#include "rom/ets_sys.h"
#include "rom/spi_flash.h"
#include "rom/crc.h"
#include "soc/soc.h"
#include "soc/dport_reg.h"
#include "soc/io_mux_reg.h"
#include "soc/efuse_reg.h"
#include "soc/rtc_cntl_reg.h"
#include <stdio.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include <stdlib.h>
#include "esp_err.h"
#include "nvs_flash.h"
#include "nvs.h"
#include "esp_partition.h"
#include "emu.h"
#include "tmeconfig.h"
#include "rtc.h"
unsigned char *romdata;
nvs_handle nvs;
void emuTask(void *pvParameters)
{
tmeStartEmu(romdata);
}
void saveRtcMem(char *data) {
esp_err_t err;
err=nvs_set_blob(nvs, "pram", data, 32);
if (err!=ESP_OK) {
printf("NVS: Saving to PRAM failed!");
}
}
void app_main()
{
int i;
const esp_partition_t* part;
spi_flash_mmap_handle_t hrom;
esp_err_t err;
uint8_t pram[32];
nvs_flash_init();
err=nvs_open("pram", NVS_READWRITE, &nvs);
if (err!=ESP_OK) {
printf("NVS: Try erase\n");
nvs_flash_erase();
err=nvs_open("pram", NVS_READWRITE, &nvs);
}
unsigned int sz=32;
err = nvs_get_blob(nvs, "pram", pram, &sz);
if (err == ESP_OK) {
rtcInit((char*)pram);
} else {
printf("NVS: Cannot load pram!\n");
}
part=esp_partition_find_first(0x40, 0x1, NULL);
if (part==0) printf("Couldn't find bootrom part!\n");
err=esp_partition_mmap(part, 0, 128*1024, SPI_FLASH_MMAP_DATA, (const void**)&romdata, &hrom);
if (err!=ESP_OK) printf("Couldn't map bootrom part!\n");
printf("Starting emu...\n");
xTaskCreatePinnedToCore(&emuTask, "emu", 6*1024, NULL, 5, NULL, 0);
}