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
 #include <stdarg.h>
37
 #include <stdarg.h>
38
 #include <algorithm>
38
 #include <algorithm>
39
 
39
 
40
-extern "C" volatile uint32_t _millis;
40
+extern "C" volatile millis_t _millis;
41
 
41
 
42
 #include <Arduino.h>
42
 #include <Arduino.h>
43
 #include <pinmapping.h>
43
 #include <pinmapping.h>

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

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

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

33
 #include <lpc17xx_pinsel.h>
33
 #include <lpc17xx_pinsel.h>
34
 #include <lpc17xx_libcfg_default.h>
34
 #include <lpc17xx_libcfg_default.h>
35
 
35
 
36
+#include "../../../core/millis_t.h"
37
+
36
 //////////////////////////////////////////////////////////////////////////////////////
38
 //////////////////////////////////////////////////////////////////////////////////////
37
 
39
 
38
 // These two routines are exact copies of the lpc17xx_i2c.c routines.  Couldn't link to
40
 // These two routines are exact copies of the lpc17xx_i2c.c routines.  Couldn't link to
149
   u8g_i2c_start(0); // send slave address and write bit
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
 uint8_t u8g_i2c_send_byte(uint8_t data) {
155
 uint8_t u8g_i2c_send_byte(uint8_t data) {
154
   #define I2C_TIMEOUT 3
156
   #define I2C_TIMEOUT 3
155
   LPC_I2C1->I2DAT = data & I2C_I2DAT_BITMASK; // transmit data
157
   LPC_I2C1->I2DAT = data & I2C_I2DAT_BITMASK; // transmit data
156
   LPC_I2C1->I2CONSET = I2C_I2CONSET_AA;
158
   LPC_I2C1->I2CONSET = I2C_I2CONSET_AA;
157
   LPC_I2C1->I2CONCLR = I2C_I2CONCLR_SIC;
159
   LPC_I2C1->I2CONCLR = I2C_I2CONCLR_SIC;
158
-  uint32_t timeout = _millis + I2C_TIMEOUT;
160
+  millis_t timeout = _millis + I2C_TIMEOUT;
159
   while ((I2C_status != I2C_I2STAT_M_TX_DAT_ACK) && (I2C_status != I2C_I2STAT_M_TX_DAT_NACK) && (timeout > _millis));  // wait for xmit to finish
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
   // had hangs with SH1106 so added time out - have seen temporary screen corruption when this happens
162
   // had hangs with SH1106 so added time out - have seen temporary screen corruption when this happens
161
   return 1;
163
   return 1;

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

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

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

199
   void chipDeselect();
199
   void chipDeselect();
200
   void chipSelect();
200
   void chipSelect();
201
   void type(uint8_t value) { type_ = value; }
201
   void type(uint8_t value) { type_ = value; }
202
-  bool waitNotBusy(uint16_t timeoutMillis);
202
+  bool waitNotBusy(const millis_t timeout_ms);
203
   bool writeData(uint8_t token, const uint8_t* src);
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
       state = USB_HOST_WAITING;
50
       state = USB_HOST_WAITING;
51
       break;
51
       break;
52
     case USB_HOST_WAITING:
52
     case USB_HOST_WAITING:
53
-      if (millis() > next_retry) {
53
+      if (ELAPSED(millis(), next_retry)) {
54
         next_retry = millis() + 10000;
54
         next_retry = millis() + 10000;
55
         state = USB_HOST_UNINITIALIZED;
55
         state = USB_HOST_UNINITIALIZED;
56
       }
56
       }

Loading…
Cancel
Save