Skip to content

Commit f44c5c6

Browse files
committed
public base
0 parents  commit f44c5c6

File tree

1,275 files changed

+233063
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,275 files changed

+233063
-0
lines changed

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
build/bin/
2+
build/tmp/
3+
build/devices/esp32/xsProj/build
4+
libraries/esp/
5+
.DS_Store
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/*
2+
* Copyright (C) 2016-2017 Moddable Tech, Inc.
3+
* All rights reserved.
4+
*/
5+
6+
#ifndef RTC_ACCESS_H
7+
#define RTC_ACCESS_H
8+
9+
#include <c_types.h>
10+
11+
#define RTC_MMIO_BASE 0x60000700
12+
#define RTC_USER_MEM_BASE 0x60001200
13+
#define RTC_USER_MEM_NUM_DWORDS 128
14+
#define RTC_TARGET_ADDR 0x04
15+
#define RTC_COUNTER_ADDR 0x1c
16+
17+
static inline uint32_t rtc_mem_read(uint32_t addr)
18+
{
19+
return ((uint32_t*)RTC_USER_MEM_BASE)[addr];
20+
}
21+
22+
static inline void rtc_mem_write(uint32_t addr, uint32_t val)
23+
{
24+
((uint32_t*)RTC_USER_MEM_BASE)[addr]=val;
25+
}
26+
27+
static inline uint64_t rtc_make64(uint32_t high, uint32_t low)
28+
{
29+
return (((uint64_t)high)<<32)|low;
30+
}
31+
32+
static inline uint64_t rtc_mem_read64(uint32_t addr)
33+
{
34+
return rtc_make64(rtc_mem_read(addr+1),rtc_mem_read(addr));
35+
}
36+
37+
static inline void rtc_mem_write64(uint32_t addr, uint64_t val)
38+
{
39+
rtc_mem_write(addr+1,val>>32);
40+
rtc_mem_write(addr,val&0xffffffff);
41+
}
42+
43+
static inline void rtc_memw(void)
44+
{
45+
asm volatile ("memw");
46+
}
47+
48+
static inline void rtc_reg_write(uint32_t addr, uint32_t val)
49+
{
50+
rtc_memw();
51+
addr+=RTC_MMIO_BASE;
52+
*((volatile uint32_t*)addr)=val;
53+
rtc_memw();
54+
}
55+
56+
static inline uint32_t rtc_reg_read(uint32_t addr)
57+
{
58+
addr+=RTC_MMIO_BASE;
59+
rtc_memw();
60+
return *((volatile uint32_t*)addr);
61+
}
62+
#endif
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
/*
2+
* Copyright (C) 2016-2017 Moddable Tech, Inc.
3+
* All rights reserved.
4+
*/
5+
6+
// Module for RTC time keeping
7+
8+
#include "rtctime_internal.h"
9+
#include "rtctime.h"
10+
11+
#include "xsesp.h"
12+
13+
/* seconds per day */
14+
#define SPD 24*60*60
15+
16+
/* days per month -- nonleap! */
17+
static const short __spm[13] =
18+
{ 0,
19+
(31),
20+
(31+28),
21+
(31+28+31),
22+
(31+28+31+30),
23+
(31+28+31+30+31),
24+
(31+28+31+30+31+30),
25+
(31+28+31+30+31+30+31),
26+
(31+28+31+30+31+30+31+31),
27+
(31+28+31+30+31+30+31+31+30),
28+
(31+28+31+30+31+30+31+31+30+31),
29+
(31+28+31+30+31+30+31+31+30+31+30),
30+
(31+28+31+30+31+30+31+31+30+31+30+31),
31+
};
32+
33+
static int __isleap (int year) {
34+
/* every fourth year is a leap year except for century years that are
35+
* not divisible by 400. */
36+
/* return (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0)); */
37+
return (!(year % 4) && ((year % 100) || !(year % 400)));
38+
}
39+
40+
// ******* C API functions *************
41+
42+
void rtctime_early_startup (void)
43+
{
44+
// Cache_Read_Enable (0, 0, 1);
45+
rtc_time_register_bootup ();
46+
rtc_time_switch_clocks ();
47+
// Cache_Read_Disable ();
48+
}
49+
50+
void rtctime_late_startup (void)
51+
{
52+
rtc_time_switch_system ();
53+
}
54+
55+
void rtctime_gettimeofday (struct rtc_timeval *tv)
56+
{
57+
rtc_time_gettimeofday (tv);
58+
}
59+
60+
void rtctime_settimeofday (const struct rtc_timeval *tv)
61+
{
62+
if (!rtc_time_check_magic ())
63+
rtc_time_prepare ();
64+
rtc_time_settimeofday (tv);
65+
}
66+
67+
bool rtctime_have_time (void)
68+
{
69+
return rtc_time_have_time ();
70+
}
71+
72+
void rtctime_deep_sleep_us (uint32_t us)
73+
{
74+
rtc_time_deep_sleep_us (us);
75+
}
76+
77+
void rtctime_deep_sleep_until_aligned_us (uint32_t align_us, uint32_t min_us)
78+
{
79+
rtc_time_deep_sleep_until_aligned (align_us, min_us);
80+
}
81+
82+
void rtctime_gmtime (const int32 stamp, struct rtc_tm *r)
83+
{
84+
int32_t i;
85+
int32_t work = stamp % (SPD);
86+
r->tm_sec = work % 60; work /= 60;
87+
r->tm_min = work % 60; r->tm_hour = work / 60;
88+
work = stamp / (SPD);
89+
r->tm_wday = (4 + work) % 7;
90+
for (i = 1970; ; ++i) {
91+
int32_t k = __isleap (i) ? 366 : 365;
92+
if (work >= k) {
93+
work -= k;
94+
} else {
95+
break;
96+
}
97+
}
98+
r->tm_year = i - 1900;
99+
r->tm_yday = work;
100+
101+
r->tm_mday = 1;
102+
if (__isleap (i) && (work > 58)) {
103+
if (work == 59) r->tm_mday = 2; /* 29.2. */
104+
work -= 1;
105+
}
106+
107+
for (i = 11; i && (__spm[i] > work); --i) ;
108+
r->tm_mon = i;
109+
r->tm_mday += work - __spm[i];
110+
}
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
/*
2+
* Copyright 2015 Dius Computing Pty Ltd. All rights reserved.
3+
*
4+
* Redistribution and use in source and binary forms, with or without
5+
* modification, are permitted provided that the following conditions
6+
* are met:
7+
*
8+
* - Redistributions of source code must retain the above copyright
9+
* notice, this list of conditions and the following disclaimer.
10+
* - Redistributions in binary form must reproduce the above copyright
11+
* notice, this list of conditions and the following disclaimer in the
12+
* documentation and/or other materials provided with the
13+
* distribution.
14+
* - Neither the name of the copyright holders nor the names of
15+
* its contributors may be used to endorse or promote products derived
16+
* from this software without specific prior written permission.
17+
*
18+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19+
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20+
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
21+
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
22+
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
23+
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24+
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25+
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26+
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
27+
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
29+
* OF THE POSSIBILITY OF SUCH DAMAGE.
30+
*
31+
* @author Johny Mattsson <jmattsson@dius.com.au>
32+
*/
33+
#ifndef _RTCTIME_H_
34+
#define _RTCTIME_H_
35+
36+
/* We don't want to expose the raw rtctime interface as it is heavily
37+
* 'static inline' and used by a few things, so instead we wrap the
38+
* relevant functions and expose these instead, through the rtctime.c module.
39+
*/
40+
41+
#if ESP32
42+
#include "stdint.h"
43+
#define int32 int32_t
44+
#define uint8 uint8_t
45+
#else
46+
#include <c_types.h>
47+
#endif
48+
#define TEXT_SECTION_ATTR __attribute__((section(".text")))
49+
50+
#ifndef _RTCTIME_INTERNAL_H_
51+
struct rtc_timeval
52+
{
53+
uint32_t tv_sec;
54+
uint32_t tv_usec;
55+
};
56+
#endif
57+
58+
struct rtc_tm{
59+
int tm_sec; /* Seconds. [0-60] (1 leap second) */
60+
int tm_min; /* Minutes. [0-59] */
61+
int tm_hour; /* Hours. [0-23] */
62+
int tm_mday; /* Day. [1-31] */
63+
int tm_mon; /* Month. [0-11] */
64+
int tm_year; /* Year - 1900. */
65+
int tm_wday; /* Day of week. [0-6] */
66+
int tm_yday; /* Days in year.[0-365] */
67+
};
68+
69+
void TEXT_SECTION_ATTR rtctime_early_startup (void);
70+
void rtctime_late_startup (void);
71+
void rtctime_gettimeofday (struct rtc_timeval *tv);
72+
void rtctime_settimeofday (const struct rtc_timeval *tv);
73+
bool rtctime_have_time (void);
74+
void rtctime_deep_sleep_us (uint32_t us);
75+
void rtctime_deep_sleep_until_aligned_us (uint32_t align_us, uint32_t min_us);
76+
void rtctime_gmtime (const int32 stamp, struct rtc_tm *r);
77+
78+
#endif

0 commit comments

Comments
 (0)