2019-10-09 02:27:08 -04:00
|
|
|
/*
|
|
|
|
* This file is part of the MicroPython project, http://micropython.org/
|
|
|
|
*
|
|
|
|
* The MIT License (MIT)
|
|
|
|
*
|
|
|
|
* Copyright 2019 Sony Semiconductor Solutions Corporation
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
|
|
* in the Software without restriction, including without limitation the rights
|
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
* THE SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdint.h>
|
2020-03-17 17:21:45 -04:00
|
|
|
|
2019-10-09 02:27:08 -04:00
|
|
|
#include <sys/boardctl.h>
|
2020-03-17 17:21:45 -04:00
|
|
|
#include <sys/time.h>
|
2019-10-09 02:27:08 -04:00
|
|
|
|
2020-06-01 05:35:46 -04:00
|
|
|
#include <cxd56_rtc.h>
|
|
|
|
|
2019-10-18 05:10:22 -04:00
|
|
|
#include "sched/sched.h"
|
|
|
|
|
2021-11-30 06:38:48 -05:00
|
|
|
#include "shared-bindings/rtc/__init__.h"
|
2019-10-11 02:54:36 -04:00
|
|
|
|
2021-11-30 06:38:48 -05:00
|
|
|
#include "supervisor/board.h"
|
2019-10-09 02:27:08 -04:00
|
|
|
#include "supervisor/port.h"
|
2020-08-20 10:21:25 -04:00
|
|
|
#include "supervisor/background_callback.h"
|
|
|
|
#include "supervisor/usb.h"
|
2020-03-17 17:21:45 -04:00
|
|
|
#include "supervisor/shared/tick.h"
|
2019-10-09 02:27:08 -04:00
|
|
|
|
|
|
|
#include "common-hal/microcontroller/Pin.h"
|
|
|
|
#include "common-hal/analogio/AnalogIn.h"
|
|
|
|
#include "common-hal/pulseio/PulseOut.h"
|
2020-08-18 16:08:33 -04:00
|
|
|
#include "common-hal/pwmio/PWMOut.h"
|
2019-10-21 07:17:51 -04:00
|
|
|
#include "common-hal/busio/UART.h"
|
2019-10-09 02:27:08 -04:00
|
|
|
|
2020-09-14 06:55:53 -04:00
|
|
|
#define SPRESENSE_MEM_ALIGN (32)
|
2020-09-11 07:24:55 -04:00
|
|
|
|
2021-03-15 09:57:36 -04:00
|
|
|
uint32_t *heap;
|
2020-09-11 07:24:55 -04:00
|
|
|
uint32_t heap_size;
|
|
|
|
|
2019-10-09 02:27:08 -04:00
|
|
|
safe_mode_t port_init(void) {
|
|
|
|
boardctl(BOARDIOC_INIT, 0);
|
2019-10-11 02:54:36 -04:00
|
|
|
|
2020-06-01 05:35:46 -04:00
|
|
|
// Wait until RTC is available
|
2021-03-15 09:57:36 -04:00
|
|
|
while (g_rtc_enabled == false) {
|
|
|
|
;
|
|
|
|
}
|
2019-10-11 02:54:36 -04:00
|
|
|
|
2020-09-14 06:55:53 -04:00
|
|
|
heap = memalign(SPRESENSE_MEM_ALIGN, 128 * 1024);
|
|
|
|
uint32_t size = CONFIG_RAM_START + CONFIG_RAM_SIZE - (uint32_t)heap - 2 * SPRESENSE_MEM_ALIGN;
|
|
|
|
heap = realloc(heap, size);
|
|
|
|
heap_size = size / sizeof(uint32_t);
|
2020-09-11 07:24:55 -04:00
|
|
|
|
2019-10-11 02:54:36 -04:00
|
|
|
if (board_requests_safe_mode()) {
|
2023-02-11 23:50:20 -05:00
|
|
|
return SAFE_MODE_USER;
|
2019-10-11 02:54:36 -04:00
|
|
|
}
|
|
|
|
|
2023-02-11 23:50:20 -05:00
|
|
|
return SAFE_MODE_NONE;
|
2019-10-09 02:27:08 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void reset_cpu(void) {
|
|
|
|
boardctl(BOARDIOC_RESET, 0);
|
2020-09-24 12:20:32 -04:00
|
|
|
for (;;) {
|
|
|
|
}
|
2019-10-09 02:27:08 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void reset_port(void) {
|
2021-03-15 09:57:36 -04:00
|
|
|
#if CIRCUITPY_ANALOGIO
|
2019-10-09 02:27:08 -04:00
|
|
|
analogin_reset();
|
2021-03-15 09:57:36 -04:00
|
|
|
#endif
|
|
|
|
#if CIRCUITPY_PULSEIO
|
2019-10-09 02:27:08 -04:00
|
|
|
pulseout_reset();
|
2021-03-15 09:57:36 -04:00
|
|
|
#endif
|
|
|
|
#if CIRCUITPY_PWMIO
|
2019-10-09 02:27:08 -04:00
|
|
|
pwmout_reset();
|
2021-03-15 09:57:36 -04:00
|
|
|
#endif
|
|
|
|
#if CIRCUITPY_BUSIO
|
2019-10-21 07:17:51 -04:00
|
|
|
busio_uart_reset();
|
2021-03-15 09:57:36 -04:00
|
|
|
#endif
|
2021-11-30 06:38:48 -05:00
|
|
|
#if CIRCUITPY_RTC
|
|
|
|
rtc_reset();
|
|
|
|
#endif
|
2019-10-09 02:27:08 -04:00
|
|
|
|
|
|
|
reset_all_pins();
|
|
|
|
}
|
|
|
|
|
|
|
|
void reset_to_bootloader(void) {
|
2020-09-24 12:20:32 -04:00
|
|
|
boardctl(BOARDIOC_RESET, 0);
|
|
|
|
for (;;) {
|
|
|
|
}
|
2019-10-09 02:27:08 -04:00
|
|
|
}
|
|
|
|
|
2020-10-11 08:59:33 -04:00
|
|
|
bool port_has_fixed_stack(void) {
|
|
|
|
return true;
|
2020-05-15 20:22:41 -04:00
|
|
|
}
|
|
|
|
|
2019-10-18 05:00:09 -04:00
|
|
|
uint32_t *port_stack_get_limit(void) {
|
2019-10-18 05:10:22 -04:00
|
|
|
struct tcb_s *rtcb = this_task();
|
|
|
|
|
2023-01-14 14:31:06 -05:00
|
|
|
return rtcb->stack_base_ptr;
|
2019-10-18 05:00:09 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t *port_stack_get_top(void) {
|
2019-10-18 05:10:22 -04:00
|
|
|
struct tcb_s *rtcb = this_task();
|
|
|
|
|
2023-01-14 14:31:06 -05:00
|
|
|
return rtcb->stack_base_ptr + (uint32_t)rtcb->adj_stack_size;
|
2019-10-18 05:00:09 -04:00
|
|
|
}
|
|
|
|
|
2020-01-18 21:06:56 -05:00
|
|
|
uint32_t *port_heap_get_bottom(void) {
|
2020-09-11 07:24:55 -04:00
|
|
|
return heap;
|
2020-01-18 21:06:56 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t *port_heap_get_top(void) {
|
2020-09-11 07:24:55 -04:00
|
|
|
return heap + heap_size;
|
2020-01-18 21:06:56 -05:00
|
|
|
}
|
|
|
|
|
2019-10-09 02:27:08 -04:00
|
|
|
extern uint32_t _ebss;
|
|
|
|
|
|
|
|
// Place the word to save just after our BSS section that gets blanked.
|
|
|
|
void port_set_saved_word(uint32_t value) {
|
|
|
|
_ebss = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t port_get_saved_word(void) {
|
|
|
|
return _ebss;
|
|
|
|
}
|
2020-03-17 17:21:45 -04:00
|
|
|
|
2020-08-20 10:21:25 -04:00
|
|
|
static background_callback_t callback;
|
2021-03-15 09:57:36 -04:00
|
|
|
static void usb_background_do(void *unused) {
|
2020-08-20 10:21:25 -04:00
|
|
|
usb_background();
|
|
|
|
}
|
|
|
|
|
2020-03-17 17:21:45 -04:00
|
|
|
volatile bool _tick_enabled;
|
2021-03-15 09:57:36 -04:00
|
|
|
void board_timerhook(void) {
|
2020-03-17 17:21:45 -04:00
|
|
|
// Do things common to all ports when the tick occurs
|
|
|
|
if (_tick_enabled) {
|
|
|
|
supervisor_tick();
|
|
|
|
}
|
2020-08-20 10:21:25 -04:00
|
|
|
|
|
|
|
background_callback_add(&callback, usb_background_do, NULL);
|
2020-03-17 17:21:45 -04:00
|
|
|
}
|
|
|
|
|
2021-03-15 09:57:36 -04:00
|
|
|
uint64_t port_get_raw_ticks(uint8_t *subticks) {
|
2020-06-01 05:35:46 -04:00
|
|
|
uint64_t count = cxd56_rtc_count();
|
|
|
|
*subticks = count % 32;
|
2020-03-17 17:21:45 -04:00
|
|
|
|
2020-06-01 05:35:46 -04:00
|
|
|
return count / 32;
|
2020-03-17 17:21:45 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Enable 1/1024 second tick.
|
|
|
|
void port_enable_tick(void) {
|
|
|
|
_tick_enabled = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Disable 1/1024 second tick.
|
|
|
|
void port_disable_tick(void) {
|
|
|
|
_tick_enabled = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void port_interrupt_after_ticks(uint32_t ticks) {
|
|
|
|
}
|
|
|
|
|
2020-12-02 21:05:29 -05:00
|
|
|
void port_idle_until_interrupt(void) {
|
2020-03-17 17:21:45 -04:00
|
|
|
// TODO: Implement sleep.
|
|
|
|
}
|