2018-09-07 16:00:13 +01:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2018 Atmosphère-NX
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms and conditions of the GNU General Public License,
|
|
|
|
* version 2, as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope it will be useful, but WITHOUT
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
|
|
* more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2018-03-15 15:14:41 +00:00
|
|
|
#ifndef FUSEE_TIMERS_H
|
|
|
|
#define FUSEE_TIMERS_H
|
|
|
|
|
|
|
|
#include "utils.h"
|
|
|
|
|
|
|
|
#define TIMERS_BASE 0x60005000
|
|
|
|
#define MAKE_TIMERS_REG(n) MAKE_REG32(TIMERS_BASE + n)
|
2018-11-14 20:14:41 +00:00
|
|
|
|
2018-09-05 20:51:03 +01:00
|
|
|
#define TIMERUS_CNTR_1US_0 MAKE_TIMERS_REG(0x10)
|
|
|
|
#define TIMERUS_USEC_CFG_0 MAKE_TIMERS_REG(0x14)
|
2018-11-14 20:14:41 +00:00
|
|
|
#define SHARED_INTR_STATUS_0 MAKE_TIMERS_REG(0x1A0)
|
|
|
|
#define SHARED_TIMER_SECURE_CFG_0 MAKE_TIMERS_REG(0x1A4)
|
2018-03-15 15:14:41 +00:00
|
|
|
|
2018-07-19 21:07:53 +01:00
|
|
|
#define RTC_BASE 0x7000E000
|
2018-08-18 17:59:33 +01:00
|
|
|
#define MAKE_RTC_REG(n) MAKE_REG32(RTC_BASE + n)
|
2018-11-14 20:14:41 +00:00
|
|
|
|
2018-09-05 20:51:03 +01:00
|
|
|
#define RTC_SECONDS MAKE_RTC_REG(0x08)
|
|
|
|
#define RTC_SHADOW_SECONDS MAKE_RTC_REG(0x0C)
|
|
|
|
#define RTC_MILLI_SECONDS MAKE_RTC_REG(0x10)
|
2018-07-19 21:07:53 +01:00
|
|
|
|
2018-03-15 15:14:41 +00:00
|
|
|
typedef struct {
|
|
|
|
uint32_t CONFIG;
|
|
|
|
uint32_t STATUS;
|
|
|
|
uint32_t COMMAND;
|
|
|
|
uint32_t PATTERN;
|
|
|
|
} watchdog_timers_t;
|
|
|
|
|
|
|
|
#define GET_WDT(n) ((volatile watchdog_timers_t *)(TIMERS_BASE + 0x100 + 0x20 * n))
|
|
|
|
#define WDT_REBOOT_PATTERN 0xC45A
|
2018-11-14 20:14:41 +00:00
|
|
|
#define GET_WDT_REBOOT_CFG_REG(n) MAKE_REG32(TIMERS_BASE + 0x60 + 0x8 * n)
|
2018-03-15 15:14:41 +00:00
|
|
|
|
|
|
|
void wait(uint32_t microseconds);
|
|
|
|
|
2018-07-19 21:07:53 +01:00
|
|
|
static inline uint32_t get_time_s(void) {
|
|
|
|
return RTC_SECONDS;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline uint32_t get_time_ms(void) {
|
|
|
|
return (RTC_MILLI_SECONDS | (RTC_SHADOW_SECONDS << 10));
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline uint32_t get_time_us(void) {
|
2018-03-15 15:14:41 +00:00
|
|
|
return TIMERUS_CNTR_1US_0;
|
|
|
|
}
|
|
|
|
|
2018-07-19 21:07:53 +01:00
|
|
|
/**
|
|
|
|
* Returns the time in microseconds.
|
|
|
|
*/
|
|
|
|
static inline uint32_t get_time(void) {
|
|
|
|
return get_time_us();
|
|
|
|
}
|
|
|
|
|
2018-04-22 02:38:55 +01:00
|
|
|
/**
|
|
|
|
* Returns the number of microseconds that have passed since a given get_time().
|
|
|
|
*/
|
|
|
|
static inline uint32_t get_time_since(uint32_t base) {
|
2018-07-19 21:07:53 +01:00
|
|
|
return get_time_us() - base;
|
2018-04-22 02:38:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Delays for a given number of microseconds.
|
|
|
|
*/
|
2018-07-19 21:07:53 +01:00
|
|
|
static inline void udelay(uint32_t usecs) {
|
|
|
|
uint32_t start = get_time_us();
|
|
|
|
while (get_time_us() - start < usecs);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Delays for a given number of milliseconds.
|
|
|
|
*/
|
|
|
|
static inline void mdelay(uint32_t msecs) {
|
|
|
|
uint32_t start = get_time_ms();
|
|
|
|
while (get_time_ms() - start < msecs);
|
2018-04-22 02:38:55 +01:00
|
|
|
}
|
|
|
|
|
2018-03-15 15:14:41 +00:00
|
|
|
__attribute__ ((noreturn)) void watchdog_reboot(void);
|
|
|
|
|
|
|
|
#endif
|