mirror of
https://github.com/micropython/micropython.git
synced 2026-01-04 19:20:22 +01:00
all: Simplify mp_int_t/mp_uint_t definition.
Assuming proper C99 language support, we can select "the int type as big as a pointer" (most of the time) or "the 64-bit int type" (nanboxing with REPR_D), and then define everything else automatically. This simplifies port configuration files. And the types can still be overridden if needed. Signed-off-by: Jeff Epler <jepler@unpythonic.net>
This commit is contained in:
committed by
Damien George
parent
eac81de4e0
commit
007f127a61
@@ -337,8 +337,6 @@ void *esp_native_code_commit(void *, size_t, void *);
|
||||
#define MICROPY_WRAP_MP_SCHED_EXCEPTION(f) IRAM_ATTR f
|
||||
#define MICROPY_WRAP_MP_SCHED_KEYBOARD_INTERRUPT(f) IRAM_ATTR f
|
||||
|
||||
typedef int32_t mp_int_t; // must be pointer size
|
||||
typedef uint32_t mp_uint_t; // must be pointer size
|
||||
typedef long mp_off_t;
|
||||
// ssize_t, off_t as required by POSIX-signatured functions in stream.h
|
||||
#include <sys/types.h>
|
||||
|
||||
@@ -184,15 +184,15 @@ mp_uint_t mp_hal_stdout_tx_strn(const char *str, size_t len) {
|
||||
return did_write ? ret : 0;
|
||||
}
|
||||
|
||||
uint32_t mp_hal_ticks_ms(void) {
|
||||
mp_uint_t mp_hal_ticks_ms(void) {
|
||||
return esp_timer_get_time() / 1000;
|
||||
}
|
||||
|
||||
uint32_t mp_hal_ticks_us(void) {
|
||||
mp_uint_t mp_hal_ticks_us(void) {
|
||||
return esp_timer_get_time();
|
||||
}
|
||||
|
||||
void mp_hal_delay_ms(uint32_t ms) {
|
||||
void mp_hal_delay_ms(mp_uint_t ms) {
|
||||
uint64_t us = (uint64_t)ms * 1000ULL;
|
||||
uint64_t dt;
|
||||
uint64_t t0 = esp_timer_get_time();
|
||||
@@ -220,7 +220,7 @@ void mp_hal_delay_ms(uint32_t ms) {
|
||||
}
|
||||
}
|
||||
|
||||
void mp_hal_delay_us(uint32_t us) {
|
||||
void mp_hal_delay_us(mp_uint_t us) {
|
||||
// these constants are tested for a 240MHz clock
|
||||
const uint32_t this_overhead = 5;
|
||||
const uint32_t pend_overhead = 150;
|
||||
|
||||
@@ -82,18 +82,18 @@ static inline void mp_end_atomic_section(mp_uint_t state) {
|
||||
#define MICROPY_BEGIN_ATOMIC_SECTION() mp_begin_atomic_section()
|
||||
#define MICROPY_END_ATOMIC_SECTION(state) mp_end_atomic_section(state)
|
||||
|
||||
uint32_t mp_hal_ticks_us(void);
|
||||
__attribute__((always_inline)) static inline uint32_t mp_hal_ticks_cpu(void) {
|
||||
mp_uint_t mp_hal_ticks_us(void);
|
||||
__attribute__((always_inline)) static inline mp_uint_t mp_hal_ticks_cpu(void) {
|
||||
uint32_t ccount;
|
||||
#if CONFIG_IDF_TARGET_ARCH_RISCV
|
||||
__asm__ __volatile__ ("csrr %0, 0x7E2" : "=r" (ccount)); // Machine Performance Counter Value
|
||||
#else
|
||||
__asm__ __volatile__ ("rsr %0,ccount" : "=a" (ccount));
|
||||
#endif
|
||||
return ccount;
|
||||
return (mp_uint_t)ccount;
|
||||
}
|
||||
|
||||
void mp_hal_delay_us(uint32_t);
|
||||
void mp_hal_delay_us(mp_uint_t);
|
||||
#define mp_hal_delay_us_fast(us) esp_rom_delay_us(us)
|
||||
void mp_hal_set_interrupt_char(int c);
|
||||
uint32_t mp_hal_get_cpu_freq(void);
|
||||
|
||||
Reference in New Issue
Block a user