Use millis_t where needed (#12152)

This commit is contained in:
Ludy 2018-10-21 06:21:27 +02:00 committed by Scott Lahteine
parent b641571098
commit 44369d536a
6 changed files with 17 additions and 15 deletions

View file

@ -37,7 +37,7 @@ void HAL_init();
#include <stdarg.h> #include <stdarg.h>
#include <algorithm> #include <algorithm>
extern "C" volatile uint32_t _millis; extern "C" volatile millis_t _millis;
#include <Arduino.h> #include <Arduino.h>
#include <pinmapping.h> #include <pinmapping.h>

View file

@ -71,7 +71,7 @@ void HAL_init() {
#ifndef USB_SD_DISABLED #ifndef USB_SD_DISABLED
MSC_SD_Init(0); // Enable USB SD card access MSC_SD_Init(0); // Enable USB SD card access
#endif #endif
const uint32_t usb_timeout = millis() + 2000; const millis_t usb_timeout = millis() + 2000;
while (!USB_Configuration && PENDING(millis(), usb_timeout)) { while (!USB_Configuration && PENDING(millis(), usb_timeout)) {
delay(50); delay(50);
HAL_idletask(); HAL_idletask();

View file

@ -33,6 +33,8 @@
#include <lpc17xx_pinsel.h> #include <lpc17xx_pinsel.h>
#include <lpc17xx_libcfg_default.h> #include <lpc17xx_libcfg_default.h>
#include "../../../core/millis_t.h"
////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////
// These two routines are exact copies of the lpc17xx_i2c.c routines. Couldn't link to // These two routines are exact copies of the lpc17xx_i2c.c routines. Couldn't link to
@ -149,13 +151,13 @@ void u8g_i2c_init(uint8_t clock_option) {
u8g_i2c_start(0); // send slave address and write bit u8g_i2c_start(0); // send slave address and write bit
} }
volatile extern uint32_t _millis; volatile extern millis_t _millis;
uint8_t u8g_i2c_send_byte(uint8_t data) { uint8_t u8g_i2c_send_byte(uint8_t data) {
#define I2C_TIMEOUT 3 #define I2C_TIMEOUT 3
LPC_I2C1->I2DAT = data & I2C_I2DAT_BITMASK; // transmit data LPC_I2C1->I2DAT = data & I2C_I2DAT_BITMASK; // transmit data
LPC_I2C1->I2CONSET = I2C_I2CONSET_AA; LPC_I2C1->I2CONSET = I2C_I2CONSET_AA;
LPC_I2C1->I2CONCLR = I2C_I2CONCLR_SIC; LPC_I2C1->I2CONCLR = I2C_I2CONCLR_SIC;
uint32_t timeout = _millis + I2C_TIMEOUT; millis_t timeout = _millis + I2C_TIMEOUT;
while ((I2C_status != I2C_I2STAT_M_TX_DAT_ACK) && (I2C_status != I2C_I2STAT_M_TX_DAT_NACK) && (timeout > _millis)); // wait for xmit to finish while ((I2C_status != I2C_I2STAT_M_TX_DAT_ACK) && (I2C_status != I2C_I2STAT_M_TX_DAT_NACK) && (timeout > _millis)); // wait for xmit to finish
// had hangs with SH1106 so added time out - have seen temporary screen corruption when this happens // had hangs with SH1106 so added time out - have seen temporary screen corruption when this happens
return 1; return 1;

View file

@ -240,7 +240,7 @@ bool Sd2Card::init(uint8_t sckRateID, pin_t chipSelectPin) {
errorCode_ = type_ = 0; errorCode_ = type_ = 0;
chipSelectPin_ = chipSelectPin; chipSelectPin_ = chipSelectPin;
// 16-bit init start time allows over a minute // 16-bit init start time allows over a minute
uint16_t t0 = (uint16_t)millis(); const millis_t init_timeout = millis() + SD_INIT_TIMEOUT;
uint32_t arg; uint32_t arg;
// If init takes more than 4s it could trigger // If init takes more than 4s it could trigger
@ -268,7 +268,7 @@ bool Sd2Card::init(uint8_t sckRateID, pin_t chipSelectPin) {
// Command to go idle in SPI mode // Command to go idle in SPI mode
while ((status_ = cardCommand(CMD0, 0)) != R1_IDLE_STATE) { while ((status_ = cardCommand(CMD0, 0)) != R1_IDLE_STATE) {
if (((uint16_t)millis() - t0) > SD_INIT_TIMEOUT) { if (ELAPSED(millis(), init_timeout)) {
error(SD_CARD_ERROR_CMD0); error(SD_CARD_ERROR_CMD0);
goto FAIL; goto FAIL;
} }
@ -297,7 +297,7 @@ bool Sd2Card::init(uint8_t sckRateID, pin_t chipSelectPin) {
break; break;
} }
if (((uint16_t)millis() - t0) > SD_INIT_TIMEOUT) { if (ELAPSED(millis(), init_timeout)) {
error(SD_CARD_ERROR_CMD8); error(SD_CARD_ERROR_CMD8);
goto FAIL; goto FAIL;
} }
@ -312,7 +312,7 @@ bool Sd2Card::init(uint8_t sckRateID, pin_t chipSelectPin) {
arg = type() == SD_CARD_TYPE_SD2 ? 0x40000000 : 0; arg = type() == SD_CARD_TYPE_SD2 ? 0x40000000 : 0;
while ((status_ = cardAcmd(ACMD41, arg)) != R1_READY_STATE) { while ((status_ = cardAcmd(ACMD41, arg)) != R1_READY_STATE) {
// check for timeout // check for timeout
if (((uint16_t)millis() - t0) > SD_INIT_TIMEOUT) { if (ELAPSED(millis(), init_timeout)) {
error(SD_CARD_ERROR_ACMD41); error(SD_CARD_ERROR_ACMD41);
goto FAIL; goto FAIL;
} }
@ -449,9 +449,9 @@ bool Sd2Card::readData(uint8_t* dst) {
bool Sd2Card::readData(uint8_t* dst, uint16_t count) { bool Sd2Card::readData(uint8_t* dst, uint16_t count) {
// wait for start block token // wait for start block token
uint16_t t0 = millis(); const millis_t read_timeout = millis() + SD_READ_TIMEOUT;
while ((status_ = spiRec()) == 0xFF) { while ((status_ = spiRec()) == 0xFF) {
if (((uint16_t)millis() - t0) > SD_READ_TIMEOUT) { if (ELAPSED(millis(), read_timeout)) {
error(SD_CARD_ERROR_READ_TIMEOUT); error(SD_CARD_ERROR_READ_TIMEOUT);
goto FAIL; goto FAIL;
} }
@ -553,10 +553,10 @@ bool Sd2Card::setSckRate(uint8_t sckRateID) {
} }
// wait for card to go not busy // wait for card to go not busy
bool Sd2Card::waitNotBusy(uint16_t timeoutMillis) { bool Sd2Card::waitNotBusy(const millis_t timeout_ms) {
uint16_t t0 = millis(); const millis_t wait_timeout = millis() + timeout_ms;
while (spiRec() != 0xFF) while (spiRec() != 0xFF)
if (((uint16_t)millis() - t0) >= timeoutMillis) return false; if (ELAPSED(millis(), wait_timeout)) return false;
return true; return true;
} }

View file

@ -199,7 +199,7 @@ class Sd2Card {
void chipDeselect(); void chipDeselect();
void chipSelect(); void chipSelect();
void type(uint8_t value) { type_ = value; } void type(uint8_t value) { type_ = value; }
bool waitNotBusy(uint16_t timeoutMillis); bool waitNotBusy(const millis_t timeout_ms);
bool writeData(uint8_t token, const uint8_t* src); bool writeData(uint8_t token, const uint8_t* src);
}; };

View file

@ -50,7 +50,7 @@ void Sd2Card::idle() {
state = USB_HOST_WAITING; state = USB_HOST_WAITING;
break; break;
case USB_HOST_WAITING: case USB_HOST_WAITING:
if (millis() > next_retry) { if (ELAPSED(millis(), next_retry)) {
next_retry = millis() + 10000; next_retry = millis() + 10000;
state = USB_HOST_UNINITIALIZED; state = USB_HOST_UNINITIALIZED;
} }