-
-
Notifications
You must be signed in to change notification settings - Fork 106
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
47 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,7 @@ | |
* @file mmc.c | ||
* | ||
*/ | ||
/* Copyright (C) 2018-2020 by Arjan van Vught mailto:[email protected] | ||
/* Copyright (C) 2018-2024 by Arjan van Vught mailto:[email protected] | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
|
@@ -57,10 +57,10 @@ | |
|
||
#include "mmc_internal.h" | ||
|
||
#include "h3_timer.h" | ||
|
||
#include "debug.h" | ||
|
||
extern void __msdelay(const uint32_t ms); | ||
|
||
#define __be32_to_cpu(x) ((0x000000ff&((x)>>24)) | (0x0000ff00&((x)>>8)) | \ | ||
(0x00ff0000&((x)<< 8)) | (0xff000000&((x)<<24))) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ | |
* @file mmc_bsp.c | ||
* | ||
*/ | ||
/* Copyright (C) 2018-2020 by Arjan van Vught mailto:[email protected] | ||
/* Copyright (C) 2018-2024 by Arjan van Vught mailto:[email protected] | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
|
@@ -57,10 +57,11 @@ | |
#include "mmc_internal.h" | ||
|
||
#include "h3.h" | ||
#include "h3_timer.h" | ||
|
||
#include "debug.h" | ||
|
||
extern void __msdelay(const uint32_t ms); | ||
|
||
// CCU register | ||
#define SDMMC_CLK_SCLK_GATING (1U << 31) ///< 1 = Clock is ON. SCLK = Clock source/Divider N/ Divider M | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
/** | ||
* @file h3_timer.c | ||
* @file msdelay.c | ||
* | ||
*/ | ||
/* Copyright (C) 2018 by Arjan van Vught mailto:[email protected] | ||
/* Copyright (C) 2024 by Arjan van Vught mailto:[email protected] | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
|
@@ -23,30 +23,14 @@ | |
* THE SOFTWARE. | ||
*/ | ||
|
||
#include <stdint.h> | ||
|
||
#include "h3.h" | ||
|
||
void __msdelay(uint32_t ms) { | ||
uint32_t t1, t2; | ||
|
||
t1 = H3_TIMER->AVS_CNT0; | ||
t2 = t1 + ms; | ||
do { | ||
t1 = H3_TIMER->AVS_CNT0; | ||
} while (t2 >= t1); | ||
|
||
return; | ||
} | ||
|
||
void __usdelay(uint32_t us) { | ||
uint32_t t1, t2; | ||
void __msdelay(const uint32_t ms) { | ||
const uint32_t t1 = H3_TIMER->AVS_CNT0; | ||
|
||
t1 = H3_TIMER->AVS_CNT1; | ||
t2 = t1 + us; | ||
do { | ||
t1 = H3_TIMER->AVS_CNT1; | ||
} while (t2 >= t1); | ||
__DMB(); | ||
} while ((H3_TIMER->AVS_CNT0 - t1) < ms); | ||
|
||
return; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
* @file h3_timer.h | ||
* | ||
*/ | ||
/* Copyright (C) 2018-2020 by Arjan van Vught mailto:[email protected] | ||
/* Copyright (C) 2018-2024 by Arjan van Vught mailto:[email protected] | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
|
@@ -50,15 +50,4 @@ | |
|
||
#define TIMER_INTV_1SECOND (0xB71B00) ///< 12.000.000 ticks with TIMER_CTRL_CLK_PRES_2 and TIMER_CTRL_CLK_SRC_OSC24M | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
extern void __msdelay(uint32_t); | ||
extern void __usdelay(uint32_t); | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
|
||
#endif /* H3_TIMER_H_ */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
/** | ||
* @file h3_h3_timer_init.cpp | ||
* @file h3_timer_avs.cpp | ||
* | ||
*/ | ||
/* Copyright (C) 2023 by Arjan van Vught mailto:[email protected] | ||
/* Copyright (C) 2023-2024 by Arjan van Vught mailto:[email protected] | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
|
@@ -36,7 +36,7 @@ | |
#define DIV_N_CNT0 0x2EE0 // 24MHz / 2 / 12000 = 1KHz, period 1ms | ||
#define DIV_N_CNT1 0xC // 24MHz / 2 / 12 = 1MHz, period 1us | ||
|
||
void __attribute__((cold)) h3_timer_init() { | ||
void __attribute__((cold)) h3_timer_avs_init() { | ||
H3_CCU->AVS_CLK_CFG |= SCLK_GATING; | ||
|
||
H3_TIMER->AVS_CTRL = AVS_CNT1_EN |AVS_CNT0_EN; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,10 +2,10 @@ | |
# error | ||
#endif | ||
/** | ||
* @file esp8266.c | ||
* @file esp8266.cpp | ||
* | ||
*/ | ||
/* Copyright (C) 2018-2023 by Arjan van Vught mailto:[email protected] | ||
/* Copyright (C) 2018-2024 by Arjan van Vught mailto:[email protected] | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
|
@@ -31,11 +31,8 @@ | |
|
||
#include <cstdint> | ||
|
||
#include "arm/synchronize.h" | ||
|
||
#include "h3.h" | ||
#include "h3_gpio.h" | ||
#include "h3_hs_timer.h" | ||
#include "h3_board.h" | ||
|
||
/* | ||
|
@@ -69,8 +66,8 @@ typedef union pcast32 { | |
uint8_t u8[4]; | ||
} esp8266_pcast32; | ||
|
||
static void data_gpio_fsel_output(void) { | ||
isb(); | ||
static void data_gpio_fsel_output() { | ||
__ISB(); | ||
|
||
uint32_t value = H3_PIO_PORTA->CFG0; | ||
value &= (uint32_t) ~(GPIO_SELECT_MASK << PA2_SELECT_CFG0_SHIFT); | ||
|
@@ -86,11 +83,11 @@ static void data_gpio_fsel_output(void) { | |
value |= (GPIO_FSEL_OUTPUT << PA19_SELECT_CFG2_SHIFT); | ||
H3_PIO_PORTA->CFG2 = value; | ||
|
||
dmb(); | ||
__DMB(); | ||
} | ||
|
||
static void data_gpio_fsel_input(void) { | ||
isb(); | ||
static void data_gpio_fsel_input() { | ||
__ISB(); | ||
|
||
uint32_t value = H3_PIO_PORTA->CFG0; | ||
value &= (uint32_t) ~(GPIO_SELECT_MASK << PA2_SELECT_CFG0_SHIFT); | ||
|
@@ -106,10 +103,10 @@ static void data_gpio_fsel_input(void) { | |
value |= (GPIO_FSEL_INPUT << PA19_SELECT_CFG2_SHIFT); | ||
H3_PIO_PORTA->CFG2 = value; | ||
|
||
dmb(); | ||
__DMB(); | ||
} | ||
|
||
void __attribute__((cold)) esp8266_init(void) { | ||
void __attribute__((cold)) esp8266_init() { | ||
h3_gpio_fsel(GPIO_EXT_13, GPIO_FSEL_INPUT); | ||
h3_gpio_fsel(GPIO_EXT_11, GPIO_FSEL_OUTPUT); | ||
|
||
|
@@ -140,7 +137,7 @@ void esp8266_write_4bits(const uint8_t data) { | |
h3_gpio_clr(GPIO_EXT_11); // we acknowledge, and wait for zero | ||
while (H3_PIO_PORTA->DAT & (1 << CIN)); | ||
|
||
dmb(); | ||
__DMB(); | ||
} | ||
|
||
inline static void _write_byte(const uint8_t data) { | ||
|
@@ -180,14 +177,14 @@ inline static void _write_byte(const uint8_t data) { | |
void esp8266_write_byte(const uint8_t byte) { | ||
data_gpio_fsel_output(); | ||
_write_byte(byte); | ||
dmb(); | ||
__DMB(); | ||
} | ||
|
||
void esp8266_write_halfword(const uint16_t half_word) { | ||
data_gpio_fsel_output(); | ||
_write_byte((uint8_t)(half_word & (uint16_t)0xFF)); | ||
_write_byte((uint8_t)((half_word >> 8) & (uint16_t)0xFF)); | ||
dmb(); | ||
__DMB(); | ||
} | ||
|
||
void esp8266_write_word(const uint32_t word) { | ||
|
@@ -202,7 +199,7 @@ void esp8266_write_word(const uint32_t word) { | |
_write_byte(u32.u8[2]); | ||
_write_byte(u32.u8[3]); | ||
|
||
dmb(); | ||
__DMB(); | ||
} | ||
|
||
void esp8266_write_bytes(const uint8_t *data, const uint32_t len) { | ||
|
@@ -218,7 +215,7 @@ void esp8266_write_bytes(const uint8_t *data, const uint32_t len) { | |
p++; | ||
} | ||
|
||
dmb(); | ||
__DMB(); | ||
} | ||
|
||
void esp8266_write_str(const char *data) { | ||
|
@@ -235,10 +232,10 @@ void esp8266_write_str(const char *data) { | |
|
||
_write_byte(0); | ||
|
||
dmb(); | ||
__DMB(); | ||
} | ||
|
||
inline static uint8_t _read_byte(void) { | ||
inline static uint8_t _read_byte() { | ||
uint8_t data; | ||
|
||
h3_gpio_set(GPIO_EXT_11); | ||
|
@@ -275,14 +272,14 @@ inline static uint8_t _read_byte(void) { | |
return data; | ||
} | ||
|
||
uint8_t esp8266_read_byte(void) { | ||
uint8_t esp8266_read_byte() { | ||
uint8_t data; | ||
|
||
data_gpio_fsel_input(); | ||
|
||
data = _read_byte(); | ||
|
||
dmb(); | ||
__DMB(); | ||
|
||
return data; | ||
} | ||
|
@@ -298,23 +295,23 @@ void esp8266_read_bytes(const uint8_t *data, const uint32_t len){ | |
p++; | ||
} | ||
|
||
dmb(); | ||
__DMB(); | ||
} | ||
|
||
uint16_t esp8266_read_halfword(void) { | ||
uint16_t esp8266_read_halfword() { | ||
uint16_t data; | ||
|
||
data_gpio_fsel_input(); | ||
|
||
data = _read_byte(); | ||
data |= (uint16_t) (_read_byte() << 8); | ||
|
||
dmb(); | ||
__DMB(); | ||
|
||
return data; | ||
} | ||
|
||
uint32_t esp8266_read_word(void) { | ||
uint32_t esp8266_read_word() { | ||
esp8266_pcast32 u32 __attribute__((aligned(4))); | ||
|
||
data_gpio_fsel_input(); | ||
|
@@ -324,7 +321,7 @@ uint32_t esp8266_read_word(void) { | |
u32.u8[2] = _read_byte(); | ||
u32.u8[3] = _read_byte(); | ||
|
||
dmb(); | ||
__DMB(); | ||
|
||
return u32.u32; | ||
} | ||
|
@@ -350,10 +347,10 @@ void esp8266_read_str(char *s, uint32_t *len) { | |
--n; | ||
} | ||
|
||
dmb(); | ||
__DMB(); | ||
} | ||
|
||
bool esp8266_detect(void) { | ||
bool esp8266_detect() { | ||
esp8266_init(); | ||
|
||
data_gpio_fsel_output(); | ||
|
@@ -364,23 +361,22 @@ bool esp8266_detect(void) { | |
|
||
h3_gpio_set(GPIO_EXT_11);// Tell that we have data available. Wait for ack, wait for 0 -> 1 | ||
|
||
uint32_t micros_now = h3_hs_timer_lo_us(); | ||
const auto micros_now = H3_TIMER->AVS_CNT1; | ||
|
||
// wait 0.5 second for the ESP8266 to respond | ||
while ((!(PORT_CIN->DAT & (1 << CIN))) && (h3_hs_timer_lo_us() - micros_now < (uint32_t) 500000)) | ||
while ((!(PORT_CIN->DAT & (1 << CIN))) && (H3_TIMER->AVS_CNT1 - micros_now < 500000U)) | ||
; | ||
|
||
if (!(PORT_CIN->DAT & (1 << CIN))) { | ||
|
||
h3_gpio_clr(GPIO_EXT_11); | ||
h3_gpio_clr(GPIO_EXT_11); | ||
return false; | ||
} | ||
|
||
h3_gpio_clr(GPIO_EXT_11); // we acknowledge, and wait for zero | ||
|
||
while (PORT_CIN->DAT & (1 << CIN)); | ||
|
||
dmb(); | ||
__DMB(); | ||
|
||
return true; | ||
} |