fix: yet more wiznet bugs, reconnects, led status indicators

This commit is contained in:
2024-11-11 15:40:05 +06:00
parent 8fe50deeed
commit 5f9c966602
11 changed files with 208 additions and 63 deletions

View File

@@ -289,19 +289,19 @@ uint8_t OneWireReset(void) {
// wait until the wire is high... just in case
do {
if (--retries == 0) return 0;
Delay_Us(2);
Delay_Us(ONEWIRE_RESET_RETRY_TIME);
} while (!DIRECT_READ());
DIRECT_WRITE_LOW();
DIRECT_MODE_OUTPUT(); // drive output low
Delay_Us(480);
Delay_Us(ONEWIRE_RESET_LOW_TIME);
DIRECT_MODE_INPUT(); // allow it to float
Delay_Us(70);
Delay_Us(ONEWIRE_RESET_SAMPLE_TIME);
r = !DIRECT_READ();
Delay_Us(410);
Delay_Us(ONEWIRE_RESET_POST_TIME);
return r;
}
@@ -313,17 +313,17 @@ void OneWireWriteBit(uint8_t v) {
if (v & 1) {
DIRECT_WRITE_LOW();
DIRECT_MODE_OUTPUT(); // drive output low
Delay_Us(10);
Delay_Us(ONEWIRE_WRITE_1_LOW_TIME);
DIRECT_WRITE_HIGH(); // drive output high
Delay_Us(55);
Delay_Us(ONEWIRE_WRITE_1_TOTAL_TIME - ONEWIRE_WRITE_1_LOW_TIME);
} else {
DIRECT_WRITE_LOW();
DIRECT_MODE_OUTPUT(); // drive output low
Delay_Us(65);
Delay_Us(ONEWIRE_WRITE_0_LOW_TIME);
DIRECT_WRITE_HIGH(); // drive output high
Delay_Us(5);
Delay_Us(ONEWIRE_WRITE_0_TOTAL_TIME - ONEWIRE_WRITE_0_LOW_TIME);
}
}
@@ -336,12 +336,17 @@ uint8_t OneWireReadBit(void) {
DIRECT_MODE_OUTPUT();
DIRECT_WRITE_LOW();
Delay_Us(3);
DIRECT_MODE_INPUT(); // let pin float, pull up will raise
Delay_Us(10);
Delay_Us(ONEWIRE_READ_INIT_LOW_TIME); // 6us initial low pulse
DIRECT_MODE_INPUT(); // let pin float, pull up will raise
Delay_Us(ONEWIRE_READ_SAMPLE_TIME); // 8us until sample point
r = DIRECT_READ();
Delay_Us(53);
// Wait for remainder of the read timeslot
// Total - init_low - sample = 64 - 6 - 8 = 50us
Delay_Us(ONEWIRE_READ_TOTAL_TIME - ONEWIRE_READ_INIT_LOW_TIME -
ONEWIRE_READ_SAMPLE_TIME);
return r;
}

View File

@@ -14,14 +14,14 @@ static inline __attribute__((always_inline)) uint8_t directRead() {
return (GPIOB->INDR & (1 << 9)) ? 1 : 0;
}
static inline __attribute__((always_inline)) void directModeInput() {
static inline void directModeInput() {
GPIOB->CFGHR &= ~(0xF << (4 * (9 - 8)));
GPIOB->CFGHR |= (0x4 << (4 * (9 - 8)));
GPIOB->CFGHR |= (GPIO_CNF_IN_FLOATING << (4 * (9 - 8)));
}
static inline __attribute__((always_inline)) void directModeOutput() {
static inline void directModeOutput() {
GPIOB->CFGHR &= ~(0xF << (4 * (9 - 8)));
GPIOB->CFGHR |= (0x3 << (4 * (9 - 8)));
GPIOB->CFGHR |= ((GPIO_Speed_50MHz | GPIO_CNF_OUT_PP) << (4 * (9 - 8)));
}
static inline __attribute__((always_inline)) void directWriteLow() {
@@ -39,6 +39,27 @@ static inline __attribute__((always_inline)) void directWriteHigh() {
#define DIRECT_MODE_OUTPUT() directModeOutput()
#endif
// timing configuration
// time between line check retries
#define ONEWIRE_RESET_RETRY_TIME 2
// reset cycle
#define ONEWIRE_RESET_LOW_TIME 480
#define ONEWIRE_RESET_SAMPLE_TIME 60
#define ONEWIRE_RESET_POST_TIME 410
// write 1 bit
#define ONEWIRE_WRITE_1_LOW_TIME 6
#define ONEWIRE_WRITE_1_TOTAL_TIME 64
// write 0 bit
#define ONEWIRE_WRITE_0_LOW_TIME 80
#define ONEWIRE_WRITE_0_TOTAL_TIME 84
// read bit
#define ONEWIRE_READ_INIT_LOW_TIME 6
#define ONEWIRE_READ_SAMPLE_TIME 8
#define ONEWIRE_READ_TOTAL_TIME 64
// OneWire Function Declarations
// Initialize the OneWire bus