1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00
RIOT/cpu/esp8266/startup.c

161 lines
3.5 KiB
C
Raw Normal View History

2018-09-05 02:39:50 +02:00
/*
2019-09-05 13:35:58 +02:00
* Copyright (C) 2019 Gunar Schorcht
2018-09-05 02:39:50 +02:00
*
* This file is subject to the terms and conditions of the GNU Lesser
* General Public License v2.1. See the file LICENSE in the top level
* directory for more details.
*/
/**
* @ingroup cpu_esp8266
* @{
*
* @file
* @brief Implementation of the CPU initialization
*
* @author Gunar Schorcht <gunar@schorcht.net>
* @}
*/
2019-09-05 13:35:58 +02:00
#include <stdint.h>
#include <stdio.h>
#include <stddef.h>
#include <stdarg.h>
2018-09-05 02:39:50 +02:00
#include <string.h>
#include "kernel_init.h"
#include "periph/init.h"
2019-09-05 13:35:58 +02:00
#include "periph/uart.h"
2018-09-05 02:39:50 +02:00
#include "board.h"
2019-09-05 13:35:58 +02:00
#include "esp/common_macros.h"
#include "esp_log.h"
2020-03-19 13:59:45 +01:00
#include "esp_system.h"
2018-09-05 02:39:50 +02:00
#include "exceptions.h"
#include "stdio_base.h"
2018-09-05 02:39:50 +02:00
#include "syscalls.h"
#include "thread_arch.h"
2019-09-05 13:35:58 +02:00
#include "rom_functions.h"
2018-09-05 02:39:50 +02:00
#include "sdk/sdk.h"
#if MODULE_ESP_GDBSTUB
2019-09-05 13:35:58 +02:00
#include "gdbstub.h"
2018-09-05 02:39:50 +02:00
#endif
#define ENABLE_DEBUG 0
#include "debug.h"
2019-09-05 13:35:58 +02:00
/* external esp function declarations */
extern uint32_t hwrand (void);
2018-09-05 02:39:50 +02:00
2019-09-05 13:35:58 +02:00
void esp_riot_init(void)
2018-09-05 02:39:50 +02:00
{
2020-03-19 13:59:45 +01:00
/* clear RTC bss data */
extern uint8_t _rtc_bss_start, _rtc_bss_end;
esp_reset_reason_t reset_reason = esp_reset_reason();
if (reset_reason != ESP_RST_DEEPSLEEP && reset_reason != ESP_RST_SW) {
/* cppcheck-suppress comparePointers */
2020-03-19 13:59:45 +01:00
memset(&_rtc_bss_start, 0, (&_rtc_bss_end - &_rtc_bss_start));
}
2019-09-05 13:35:58 +02:00
/* enable cached read from flash */
Cache_Read_Enable_New();
2018-09-05 02:39:50 +02:00
2019-09-05 13:35:58 +02:00
/* initialize the ISR stack for usage measurements */
thread_isr_stack_init();
#ifndef CPU_ESP8266
2019-09-05 13:35:58 +02:00
/* initialize newlib system calls */
2018-09-05 02:39:50 +02:00
syscalls_init ();
2019-09-05 13:35:58 +02:00
#endif
2018-09-05 02:39:50 +02:00
2019-09-05 13:35:58 +02:00
/* set system frequency if not 80 MHz */
if (ESP8266_CPU_FREQUENCY != 80) {
system_update_cpu_freq(ESP8266_CPU_FREQUENCY);
2018-09-05 02:39:50 +02:00
}
2019-09-05 13:35:58 +02:00
ets_printf("\n");
#ifdef MODULE_ESP_LOG_STARTUP
2019-09-05 13:35:58 +02:00
ets_printf("Starting ESP8266 CPU with ID: %08x\n", system_get_chip_id());
ets_printf("ESP8266-RTOS-SDK Version %s\n\n", system_get_sdk_version());
ets_printf("CPU clock frequency: %d MHz\n", system_get_cpu_freq());
extern void heap_stats(void);
heap_stats();
#endif
2018-09-05 02:39:50 +02:00
2019-09-05 13:35:58 +02:00
/* set exception handlers */
2018-09-05 02:39:50 +02:00
init_exceptions ();
2019-09-05 13:35:58 +02:00
/* systemwide UART initialization */
extern void uart_system_init (void);
uart_system_init();
2018-09-05 02:39:50 +02:00
2019-09-05 13:35:58 +02:00
/* init watchdogs */
system_wdt_init();
2018-09-05 02:39:50 +02:00
/* init random number generator */
srand(hwrand());
2019-09-05 13:35:58 +02:00
#if MODULE_MTD
2018-09-05 02:39:50 +02:00
/* init flash drive */
2019-09-05 13:35:58 +02:00
extern void spi_flash_drive_init (void);
spi_flash_drive_init();
#endif
2018-09-05 02:39:50 +02:00
/* initialize stdio*/
extern int stdio_is_initialized;
2023-01-02 18:08:35 +01:00
early_init();
stdio_is_initialized = 1;
2018-09-05 02:39:50 +02:00
/* trigger static peripheral initialization */
periph_init();
2019-09-05 13:35:58 +02:00
/* trigger board initialization */
2018-09-05 02:39:50 +02:00
board_init();
#ifdef MODULE_ESP_LOG_STARTUP
2018-09-05 02:39:50 +02:00
/* print the board config */
board_print_config();
#else
/* to have an empty line after the unreadable characters from ROM loader */
puts("");
#endif
2018-09-05 02:39:50 +02:00
2019-09-05 13:35:58 +02:00
/* initialize ESP system event loop */
extern void esp_event_handler_init(void);
esp_event_handler_init();
2018-09-05 02:39:50 +02:00
2019-09-05 13:35:58 +02:00
/* activate software interrupt based context switch */
2018-09-05 02:39:50 +02:00
extern void IRAM thread_yield_isr(void* arg);
ets_isr_attach(ETS_SOFT_INUM, thread_yield_isr, NULL);
ets_isr_unmask(BIT(ETS_SOFT_INUM));
2019-09-05 13:35:58 +02:00
#ifdef MODULE_ESP_GDBSTUB
gdbstub_init();
#endif
2018-09-05 02:39:50 +02:00
}
2019-09-05 13:35:58 +02:00
void esp_riot_start(void)
2018-09-05 02:39:50 +02:00
{
2019-09-05 13:35:58 +02:00
/* does not return */
kernel_init();
2018-09-05 02:39:50 +02:00
}
void __wrap_pp_attach(void)
{
#ifdef MODULE_ESP_WIFI_ANY
extern void __real_pp_attach(void);
__real_pp_attach();
#endif
}
void __wrap_pm_attach(void)
{
#ifdef MODULE_ESP_WIFI_ANY
extern void __real_pm_attach(void);
__real_pm_attach();
#endif
}