Commit Graph

58 Commits

Author SHA1 Message Date
Ivan Grokhotkov
d2b894862c newlib: auto-detect sizeof(time_t)
To make the transition from 32-bit time_t to 64-bit time_t smoother,
detect the size of this type in CMake and remove the manual option in
Kconfig.
The information about 64-bit time_t support is moved from Kconfig help
string into the "system time" section of the API reference.
2022-01-11 19:01:21 +01:00
Angus Gratton
420aef1ffe Updates for riscv support
* Target components pull in xtensa component directly
* Use CPU HAL where applicable
* Remove unnecessary xtensa headers
* Compilation changes necessary to support non-xtensa gcc types (ie int32_t/uint32_t is no
  longer signed/unsigned int).

Changes come from internal branch commit a6723fc
2020-11-13 07:49:11 +11:00
Angus Gratton
66fb5a29bb Whitespace: Automated whitespace fixes (large commit)
Apply the pre-commit hook whitespace fixes to all files in the repo.

(Line endings, blank lines at end of file, trailing whitespace)
2020-11-11 07:36:35 +00:00
Angus Gratton
4df4bd9558 Merge branch 'bugfix/clock_getres_accuracy_resolution' into 'master'
newlib: Fix clock_getres() improves accuracy

See merge request espressif/esp-idf!10743
2020-10-22 16:50:29 +08:00
Konstantin Kondrashov
9386cafbc3 time: Fix gettimeofday for ESP32-S3 2020-10-20 14:09:32 +08:00
KonstantinKondrashov
7ae7adf16a newlib: Fix clock_getres() improves accuracy
Returns not rounded value of resolution for WITH_RTC and !WITH_FRC
2020-10-07 18:01:35 +08:00
morris
61f89b97c6 bringup esp32-s3 on FPGA 2020-09-22 15:15:03 +08:00
Marius Vikhammer
6fb996b1ac newlib: revert back from spinlocks to using newlib locks for time.h
Spinlocks from spinlock.h do not disable the scheduler and thus cannot safely
be directly used as a locking mechanism. A task holding the lock can get
pre-empted, and at that point the new running task will also be allowed to
take the spinlock and access whatever it was protecting.

Another issue is that the task holding a spinlock could migrate to a different
core which in turn would cause the application to fail asserts. The current
implementation assumes the core that takes the lock is also the core that
releases it.

Closes https://github.com/espressif/esp-idf/issues/5762
2020-09-03 09:56:02 +08:00
Renz Bagaporo
c70c227591 esp_system: private system time functions for now 2020-08-11 17:52:36 +08:00
Renz Bagaporo
346cf4430d esp_system: introduce system time functions
- Introduce system time function and concept of system time provider.
esp_timer is system time provider when present.
- Set the reference point for system time, g_startup_time.
- Use the system time functions in newlib instead of calling esp_timer
functions directly
2020-08-10 15:12:38 +08:00
Renz Bagaporo
a395a00d2c newlib: separate low-level code in time.c implementation 2020-08-10 15:11:37 +08:00
morris
2917651478 esp_rom: extract common ets apis into esp_rom_sys.h 2020-07-27 15:27:01 +08:00
KonstantinKondrashov
0c7e13f0cd newlib: Fix adjtime, returns the amount of time remaining from any previous adjustment
If the olddelta argument is not a null pointer, the adjtime function returns information
about any previous time adjustment that has not yet completed.

Closes: https://github.com/espressif/esp-idf/issues/5194
2020-06-08 22:57:38 +08:00
morris
e30cd361a8 global: rename esp32s2beta to esp32s2 2020-01-22 12:14:38 +08:00
Konstantin Kondrashov
2c793cef06 idf: Support a custom toolchain with time_t wide 64-bits
Allows resolving the Y2K38 problem.

Closes: IDF-350

Closes: https://github.com/espressif/esp-idf/issues/584
2020-01-10 12:58:54 +08:00
Angus Gratton
04ae56806c Merge branch 'master' into feature/esp32s2beta_update 2019-08-08 15:26:58 +10:00
Angus Gratton
24d26fccde Merge branch 'master' into feature/esp32s2beta_update 2019-08-08 13:44:24 +10:00
Anton Maklakov
afbaf74007 tools: Mass fixing of empty prototypes (for -Wstrict-prototypes) 2019-08-01 16:28:56 +07:00
raldone01
7982ed9a7d newlib: Move _gettimeofday_r call in clock_gettime
Signed-off-by: KonstantinKondrashov <konstantin@espressif.com>
Merges: https://github.com/espressif/esp-idf/pull/3789
2019-07-17 16:52:40 +08:00
suda-morris
4a79d750a5 clean up build warnings 2019-06-11 13:07:37 +08:00
suda-morris
84b2f9f14d build and link hello-world for esp32s2beta 2019-06-11 13:07:37 +08:00
Konstantin Kondrashov
399d2d2605 all: Using xxx_periph.h
Using xxx_periph.h in whole IDF instead of xxx_reg.h, xxx_struct.h, xxx_channel.h ... .

Cleaned up header files from unnecessary headers (releated to soc/... headers).
2019-06-03 14:15:08 +08:00
Konstantin Kondrashov
62a9eacced newlib: Fix adjtime
Fixed adjtime function: While using the adjtime() function,
the time correction accumulated an error
when reading the time frequently (using gettimeofday).
2019-04-10 04:33:44 +00:00
morris
c159984264 separate rom from esp32 component to esp_rom
1. separate rom include files and linkscript to esp_rom
2. modefiy "include rom/xxx.h" to "include esp32/rom/xxx.h"
3. Forward compatible
4. update mqtt
2019-03-21 18:51:45 +08:00
morris
956c25dedd move esp32 chip specific includes to esp32/xxx.h 2019-03-18 17:14:05 +08:00
Konstantin Kondrashov
e274940a46 newlib: Add some functions from _POSIX_TIMERS
clock_gettime();
clock_settime();
clock_getres();

Closes https://github.com/espressif/esp-idf/issues/1302
2018-07-03 07:28:29 +05:00
Mahavir Jain
eef8d0f7ed Resolve required include header dependencies in component itself
Signed-off-by: Mahavir Jain <mahavir@espressif.com>
2018-06-12 11:19:39 +05:30
Angus Gratton
c99a30a167 Merge branch 'bugfix/wakeup_from_deep_sleep' into 'master'
esp32: Fix not the right time spent in a deep sleep

See merge request idf/esp-idf!2501
2018-06-08 10:40:47 +08:00
Konstantin Kondrashov
7e2a3da643 esp32: Fix not the right time spent in a deep sleep
Before entering the deep sleep, the RTC and FRC counters are synchronized. Updating the boot_time.
Added a unit test for this case.
Fixed warnings for MULTIPLE_STAGES

Closes https://github.com/espressif/esp-idf/issues/1840
2018-06-06 18:59:30 +05:00
Konstantin Kondrashov
b1189f4f6a newlib: Remove RTC_DATA_ATTR for adjtime
Using RTC_DATA_ATTR in newlib leads to increased power consumption in sleep mode. (RTC SLOW MEM)
2018-06-04 15:59:22 +05:00
Konstantin Kondrashov
6f529cbe64 newlib: Add adjtime - makes a gradual adjustment the system clock
This function speeds up or slows down the system clock in order to make a gradual adjustment. This ensures
 that the calendar time reported by the system clock is always monotonically increasing, which might not happen
 if you simply set the clock.

The delta argument specifies a relative adjustment to be made to the clock time. If negative, the system clock is
 slowed down for a while until it has lost this much elapsed time. If positive, the system clock is speeded up for a
 while.

If the olddelta argument is not a null pointer, the adjtime function returns information about any previous time
 adjustment that has not yet completed.

The return value is 0 on success and -1 on failure.

To stop the adjustement, call the function settimeofday(current_time).
2018-05-28 17:36:04 +05:00
Ivan Grokhotkov
bee1afaf6d time: rename time source option from FRC to "high-resolution timer"
libc time function now rely on esp_timer_get_time as the source of
high-resolution time, rather than FRC1 timer. Internally, on the ESP32
esp_timer implementation uses FRC2 timer.

- Change help text and labels in Kconfig to use "high-resolution timer"
  instead of FRC1. Keep existing Kconfig option name to be backwards
  compatible.
- Change references to "FRC1" in the source code to "FRC".
2017-12-11 12:37:08 +08:00
Ivan Grokhotkov
df74211fc3 newlib/time: fix compilation error when only RTC is used as clock source
Fixes https://github.com/espressif/esp-idf/issues/1245
2017-12-08 16:17:47 +08:00
Ivan Grokhotkov
37e9bc715c esp_clk.h: make public, add getters for RTC time, CPU/APB freq 2017-10-18 14:19:14 +08:00
Ivan Grokhotkov
f13623d97d make esp_timer.h public 2017-10-18 12:31:38 +08:00
Ivan Grokhotkov
5425d8569c Merge branch 'feature/pthread_api' into 'master'
esp32: pthread API

See merge request !1146
2017-09-07 17:49:42 +08:00
Angus Gratton
f8339fc1bd newlib: Avoid deprecation warning calling system_get_time() from system_relative_time() 2017-09-07 16:32:05 +10:00
Alexey Gerenkov
20942421c3 According to review comments 2017-09-06 10:30:23 +08:00
Ivan Grokhotkov
f31efb697c newlib: rename esp_setup_time_syscalls to esp_set_time_from_rtc
This function no longer sets up syscalls, and new name reflects its
purpose better.
2017-09-01 10:36:14 +08:00
Ivan Grokhotkov
42e9d49bb1 newlib: implement gettimeofday using of esp_timer 2017-08-28 11:35:27 +08:00
Ivan Grokhotkov
abe9516fdc newlib: implement usleep 2017-08-21 15:58:28 +08:00
Ivan Grokhotkov
8ccb2a4990 esp32: make time monotonic across resets
Small changes to clock calibration value will cause increasing errors
the longer the device runs. Consider the case of deep sleep, assuming
that RTC counter is used for timekeeping:
- before sleep:
   time_before = rtc_counter * calibration_val
- after sleep:
   time_after = (rtc_counter + sleep_count) * (calibration_val + epsilon)
where 'epsilon' is a small estimation error of 'calibration_val'.
The apparent sleep duration thus will be:
time_after - time_before = sleep_count * (calibration_val + epsilon)
                           + rtc_counter * epsilon

Second term on the right hand side is the error in time difference
estimation, it is proportional to the total system runtime (rtc_counter).

To avoid this issue, this change makes RTC_SLOW_CLK calibration value
persistent across restarts. This allows the calibration value update to
be preformed, while keeping time after update same as before the update.
2017-06-16 12:06:04 +08:00
Ivan Grokhotkov
cc8af68244 syscalls: fix wraparound of RTC time
This change removes the erroneous cast to uint32_t (which caused time to
wrap around after 1 hour) and splits the multiplication into two terms
to remove the wraparound after 13 days.

Ref. https://esp32.com/viewtopic.php?f=13&t=1908
2017-06-12 15:21:43 +08:00
Ivan Grokhotkov
6353bc40d7 Add support for 32k XTAL as RTC_SLOW_CLK source
- RTC_CNTL_SLOWCLK_FREQ define is removed; rtc_clk_slow_freq_get_hz
  function can be used instead to get an approximate RTC_SLOW_CLK
  frequency

- Clock calibration is performed at startup. The value is saved and used
  for timekeeping and when entering deep sleep.

- When using the 32k XTAL, startup code will wait for the oscillator to
  start up. This can be possibly optimized by starting a separate task
  to wait for oscillator startup, and performing clock switch in that
  task.

- Fix a bug that 32k XTAL would be disabled in rtc_clk_init.

- Fix a rounding error in rtc_clk_cal, which caused systematic frequency
  error.

- Fix an overflow bug which caused rtc_clk_cal to timeout early if the
  slow_clk_cycles argument would exceed certain value

- Improve 32k XTAL oscillator startup time by introducing bootstrapping
  code, which uses internal pullup/pulldown resistors on 32K_N/32K_P
  pins to set better initial conditions for the oscillator.
2017-04-26 12:43:22 +08:00
Ivan Grokhotkov
dbf60eb922 rtc: fix typo in RTC_CNTL_SLOWCLK_FREQ macro name 2017-02-22 14:40:36 +08:00
Ivan Grokhotkov
90c43ea95e newlib: fix register used for DPORT/RTC bug workaround
While there was no register at DR_REG_FRC_TIMER_BASE + 0x60, due to
peripheral address space wraparound this write actually affected one of
FRC2 registers, which is used by WiFi stack to implement legacy
ets_timer APIs.
This change uses FRC_TIMER_LOAD_REG(0) instead, which can be set to
known value safely.
2017-01-19 00:36:30 +08:00
Ivan Grokhotkov
7776d3e065 time: only define {get,set}_boot_time if FRC1 or RTC is used as time source
Fixes https://github.com/espressif/esp-idf/issues/238
2017-01-17 12:29:09 +08:00
Ivan Grokhotkov
8c25a0fd9d time: workaround for FRC_TIMER_INT_REG write issue
In some cases (when RTC register reads are performed from the APP CPU), a write to FRC_TIMER_INT_REG may be lost on the bus.
Writing to another DPORT register immediately before or after that works around the issue.
We write one dummy value to an address which doesn’t have any register associated with it.

Fixes https://github.com/espressif/arduino-esp32/issues/120
2017-01-17 12:29:09 +08:00
Ivan Grokhotkov
b24ac487cb newlib: use RTC_STORE registers to keep boot time instead of RTC_SLOW_MEM
This allows RTC_SLOW_MEM to be powered down in deep sleep if no other variables are placed into RTC_SLOW_MEM.
2017-01-12 14:43:34 +08:00
Jeroen Domburg
655fd2986a Add interrupt allocation scheme / interrupt sharing. Also modifies drivers and examples. Also allows interrupts
to be marked specifically as having a handler that's all in IRAM.
2016-12-08 12:39:33 +08:00