Browse Source

Use millis_t where needed (#12152)

Ludy 6 years ago
parent
commit
44369d536a

+ 1
- 1
Marlin/src/HAL/HAL_LPC1768/HAL.h View File

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

+ 1
- 1
Marlin/src/HAL/HAL_LPC1768/main.cpp View File

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

+ 4
- 2
Marlin/src/HAL/HAL_LPC1768/u8g/HAL_LCD_I2C_routines.c View File

@@ -33,6 +33,8 @@
33 33
 #include <lpc17xx_pinsel.h>
34 34
 #include <lpc17xx_libcfg_default.h>
35 35
 
36
+#include "../../../core/millis_t.h"
37
+
36 38
 //////////////////////////////////////////////////////////////////////////////////////
37 39
 
38 40
 // 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) {
149 151
   u8g_i2c_start(0); // send slave address and write bit
150 152
 }
151 153
 
152
-volatile extern uint32_t _millis;
154
+volatile extern millis_t _millis;
153 155
 uint8_t u8g_i2c_send_byte(uint8_t data) {
154 156
   #define I2C_TIMEOUT 3
155 157
   LPC_I2C1->I2DAT = data & I2C_I2DAT_BITMASK; // transmit data
156 158
   LPC_I2C1->I2CONSET = I2C_I2CONSET_AA;
157 159
   LPC_I2C1->I2CONCLR = I2C_I2CONCLR_SIC;
158
-  uint32_t timeout = _millis + I2C_TIMEOUT;
160
+  millis_t timeout = _millis + I2C_TIMEOUT;
159 161
   while ((I2C_status != I2C_I2STAT_M_TX_DAT_ACK) && (I2C_status != I2C_I2STAT_M_TX_DAT_NACK) && (timeout > _millis));  // wait for xmit to finish
160 162
   // had hangs with SH1106 so added time out - have seen temporary screen corruption when this happens
161 163
   return 1;

+ 9
- 9
Marlin/src/sd/Sd2Card.cpp View File

@@ -240,7 +240,7 @@ bool Sd2Card::init(uint8_t sckRateID, pin_t chipSelectPin) {
240 240
   errorCode_ = type_ = 0;
241 241
   chipSelectPin_ = chipSelectPin;
242 242
   // 16-bit init start time allows over a minute
243
-  uint16_t t0 = (uint16_t)millis();
243
+  const millis_t init_timeout = millis() + SD_INIT_TIMEOUT;
244 244
   uint32_t arg;
245 245
 
246 246
   // If init takes more than 4s it could trigger
@@ -268,7 +268,7 @@ bool Sd2Card::init(uint8_t sckRateID, pin_t chipSelectPin) {
268 268
 
269 269
   // Command to go idle in SPI mode
270 270
   while ((status_ = cardCommand(CMD0, 0)) != R1_IDLE_STATE) {
271
-    if (((uint16_t)millis() - t0) > SD_INIT_TIMEOUT) {
271
+    if (ELAPSED(millis(), init_timeout)) {
272 272
       error(SD_CARD_ERROR_CMD0);
273 273
       goto FAIL;
274 274
     }
@@ -297,7 +297,7 @@ bool Sd2Card::init(uint8_t sckRateID, pin_t chipSelectPin) {
297 297
       break;
298 298
     }
299 299
 
300
-    if (((uint16_t)millis() - t0) > SD_INIT_TIMEOUT) {
300
+    if (ELAPSED(millis(), init_timeout)) {
301 301
       error(SD_CARD_ERROR_CMD8);
302 302
       goto FAIL;
303 303
     }
@@ -312,7 +312,7 @@ bool Sd2Card::init(uint8_t sckRateID, pin_t chipSelectPin) {
312 312
   arg = type() == SD_CARD_TYPE_SD2 ? 0x40000000 : 0;
313 313
   while ((status_ = cardAcmd(ACMD41, arg)) != R1_READY_STATE) {
314 314
     // check for timeout
315
-    if (((uint16_t)millis() - t0) > SD_INIT_TIMEOUT) {
315
+    if (ELAPSED(millis(), init_timeout)) {
316 316
       error(SD_CARD_ERROR_ACMD41);
317 317
       goto FAIL;
318 318
     }
@@ -449,9 +449,9 @@ bool Sd2Card::readData(uint8_t* dst) {
449 449
 
450 450
 bool Sd2Card::readData(uint8_t* dst, uint16_t count) {
451 451
   // wait for start block token
452
-  uint16_t t0 = millis();
452
+  const millis_t read_timeout = millis() + SD_READ_TIMEOUT;
453 453
   while ((status_ = spiRec()) == 0xFF) {
454
-    if (((uint16_t)millis() - t0) > SD_READ_TIMEOUT) {
454
+    if (ELAPSED(millis(), read_timeout)) {
455 455
       error(SD_CARD_ERROR_READ_TIMEOUT);
456 456
       goto FAIL;
457 457
     }
@@ -553,10 +553,10 @@ bool Sd2Card::setSckRate(uint8_t sckRateID) {
553 553
 }
554 554
 
555 555
 // wait for card to go not busy
556
-bool Sd2Card::waitNotBusy(uint16_t timeoutMillis) {
557
-  uint16_t t0 = millis();
556
+bool Sd2Card::waitNotBusy(const millis_t timeout_ms) {
557
+  const millis_t wait_timeout = millis() + timeout_ms;
558 558
   while (spiRec() != 0xFF)
559
-    if (((uint16_t)millis() - t0) >= timeoutMillis) return false;
559
+    if (ELAPSED(millis(), wait_timeout)) return false;
560 560
 
561 561
   return true;
562 562
 }

+ 1
- 1
Marlin/src/sd/Sd2Card.h View File

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

+ 1
- 1
Marlin/src/sd/usb_flashdrive/Sd2Card_FlashDrive.cpp View File

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

Loading…
Cancel
Save