Browse Source

Followup to HAL optimizations and delays

- Cleanups, fixes for Due HAL code.
- TC_IER is write-only. Use TC_IMR to test ISR state.
etagle 6 years ago
parent
commit
9d98a62699

+ 2
- 0
Marlin/src/HAL/Delay.h View File

@@ -33,6 +33,8 @@
33 33
 #ifndef MARLIN_DELAY_H
34 34
 #define MARLIN_DELAY_H
35 35
 
36
+#include "../core/macros.h"
37
+
36 38
 #if defined(__arm__) || defined(__thumb__)
37 39
 
38 40
   /* https://blueprints.launchpad.net/gcc-arm-embedded/+spec/delay-cycles */

+ 4
- 4
Marlin/src/HAL/HAL_DUE/HAL_spi_Due.cpp View File

@@ -89,7 +89,7 @@
89 89
 
90 90
     /* The software SPI routine */
91 91
     __asm__ __volatile__(
92
-      ".syntax unified" "\n\t" // is to prevent CM0,CM1 non-unified syntax
92
+      A(".syntax unified") // is to prevent CM0,CM1 non-unified syntax
93 93
 
94 94
       /* Bit 7 */
95 95
       A("ubfx %[idx],%[txval],#7,#1")                      /* Place bit 7 in bit 0 of idx*/
@@ -170,7 +170,7 @@
170 170
 
171 171
     /* The software SPI routine */
172 172
     __asm__ __volatile__(
173
-      ".syntax unified" "\n\t" // is to prevent CM0,CM1 non-unified syntax
173
+      A(".syntax unified") // is to prevent CM0,CM1 non-unified syntax
174 174
 
175 175
       /* bit 7 */
176 176
       A("str %[sck_mask],[%[sck_port]]")           /* SODR */
@@ -290,7 +290,7 @@
290 290
 
291 291
     /* The software SPI routine */
292 292
     __asm__ __volatile__(
293
-      ".syntax unified" "\n\t" // is to prevent CM0,CM1 non-unified syntax
293
+      A(".syntax unified") // is to prevent CM0,CM1 non-unified syntax
294 294
 
295 295
       L("loop%=")
296 296
       A("ldrb.w %[txval], [%[ptr]], #1")                   /* Load value to send, increment buffer */
@@ -368,7 +368,7 @@
368 368
 
369 369
     /* The software SPI routine */
370 370
     __asm__ __volatile__(
371
-      ".syntax unified" "\n\t" // is to prevent CM0,CM1 non-unified syntax
371
+      A(".syntax unified")                  // is to prevent CM0,CM1 non-unified syntax
372 372
 
373 373
       L("loop%=")
374 374
 

+ 1
- 13
Marlin/src/HAL/HAL_DUE/HAL_timers_Due.cpp View File

@@ -137,19 +137,7 @@ void HAL_timer_disable_interrupt(const uint8_t timer_num) {
137 137
 
138 138
 bool HAL_timer_interrupt_enabled(const uint8_t timer_num) {
139 139
   const tTimerConfig * const pConfig = &TimerConfig[timer_num];
140
-  return pConfig->pTimerRegs->TC_CHANNEL[pConfig->channel].TC_IER == TC_IER_CPCS;
140
+  return (pConfig->pTimerRegs->TC_CHANNEL[pConfig->channel].TC_IMR & TC_IMR_CPCS) != 0;
141 141
 }
142 142
 
143
-#if 0
144
-  void HAL_timer_set_compare(const uint8_t timer_num, const uint32_t compare) {
145
-    const tTimerConfig * const pConfig = &TimerConfig[timer_num];
146
-    TC_SetRC(pConfig->pTimerRegs, pConfig->channel, compare);
147
-  }
148
-
149
-  void HAL_timer_isr_prologue(const uint8_t timer_num) {
150
-    const tTimerConfig * const pConfig = &TimerConfig[timer_num];
151
-    TC_GetStatus(pConfig->pTimerRegs, pConfig->channel);
152
-  }
153
-#endif
154
-
155 143
 #endif // ARDUINO_ARCH_SAM

+ 4
- 26
Marlin/src/HAL/HAL_DUE/u8g_com_HAL_DUE_st7920_sw_spi.cpp View File

@@ -58,6 +58,7 @@
58 58
 #include <U8glib.h>
59 59
 #include <Arduino.h>
60 60
 #include "../../core/macros.h"
61
+#include "../Delay.h"
61 62
 
62 63
 void u8g_SetPIOutput_DUE(u8g_t *u8g, uint8_t pin_index) {
63 64
    PIO_Configure(g_APinDescription[u8g->pin_list[pin_index]].pPort, PIO_OUTPUT_1,
@@ -71,28 +72,6 @@ void u8g_SetPILevel_DUE(u8g_t *u8g, uint8_t pin_index, uint8_t level) {
71 72
   else port->PIO_CODR = mask;
72 73
 }
73 74
 
74
-void __delay_4cycles(uint32_t cy) __attribute__ ((weak));
75
-
76
-FORCE_INLINE void __delay_4cycles(uint32_t cy) { // +1 cycle
77
-  #if ARCH_PIPELINE_RELOAD_CYCLES<2
78
-    #define EXTRA_NOP_CYCLES "nop"
79
-  #else
80
-    #define EXTRA_NOP_CYCLES ""
81
-  #endif
82
-
83
-  __asm__ __volatile__(
84
-    ".syntax unified" "\n\t" // is to prevent CM0,CM1 non-unified syntax
85
-
86
-    L("loop%=")
87
-    A("subs %[cnt],#1")
88
-    A(EXTRA_NOP_CYCLES)
89
-    A("bne loop%=")
90
-    : [cnt]"+r"(cy) // output: +r means input+output
91
-    : // input:
92
-    : "cc" // clobbers:
93
-  );
94
-}
95
-
96 75
 Pio *SCK_pPio, *MOSI_pPio;
97 76
 uint32_t SCK_dwMask, MOSI_dwMask;
98 77
 
@@ -102,9 +81,9 @@ static void spiSend_sw_DUE(uint8_t val) { // 800KHz
102 81
       MOSI_pPio->PIO_SODR = MOSI_dwMask;
103 82
     else
104 83
       MOSI_pPio->PIO_CODR = MOSI_dwMask;
105
-    __delay_4cycles(1);
84
+    DELAY_NS(48);
106 85
     SCK_pPio->PIO_SODR = SCK_dwMask;
107
-    __delay_4cycles(19); // 16 dead, 17 garbage, 18/0 900kHz, 19/1 825k, 20/1 800k, 21/2 725KHz
86
+    DELAY_NS(905); // 762 dead, 810 garbage, 858/0 900kHz, 905/1 825k, 953/1 800k, 1000/2 725KHz
108 87
     val <<= 1;
109 88
     SCK_pPio->PIO_CODR = SCK_dwMask;
110 89
   }
@@ -125,8 +104,7 @@ static void u8g_com_DUE_st7920_write_byte_sw_spi(uint8_t rs, uint8_t val) {
125 104
        /* data */
126 105
       spiSend_sw_DUE(0x0FA);
127 106
 
128
-    for (i = 0; i < 4; i++)   // give the controller some time to process the data
129
-      u8g_10MicroDelay();     // 2 is bad, 3 is OK, 4 is safe
107
+    DELAY_US(40); // give the controller some time to process the data: 20 is bad, 30 is OK, 40 is safe
130 108
   }
131 109
 
132 110
   spiSend_sw_DUE(val & 0x0F0);

+ 11
- 11
Marlin/src/HAL/HAL_LPC1768/include/Wire.cpp View File

@@ -118,12 +118,12 @@ uint8_t TwoWire::requestFrom(uint8_t address, uint8_t quantity) {
118 118
   // perform blocking read into buffer
119 119
   I2C_M_SETUP_Type transferMCfg;
120 120
   transferMCfg.sl_addr7bit = address >> 1; // not sure about the right shift
121
-	transferMCfg.tx_data = NULL;
122
-	transferMCfg.tx_length = 0;
123
-	transferMCfg.rx_data = rxBuffer;
124
-	transferMCfg.rx_length = quantity;
125
-	transferMCfg.retransmissions_max = 3;
126
-	I2C_MasterTransferData(I2CDEV_M, &transferMCfg, I2C_TRANSFER_POLLING);
121
+  transferMCfg.tx_data = NULL;
122
+  transferMCfg.tx_length = 0;
123
+  transferMCfg.rx_data = rxBuffer;
124
+  transferMCfg.rx_length = quantity;
125
+  transferMCfg.retransmissions_max = 3;
126
+  I2C_MasterTransferData(I2CDEV_M, &transferMCfg, I2C_TRANSFER_POLLING);
127 127
 
128 128
   // set rx buffer iterator vars
129 129
   rxBufferIndex = 0;
@@ -154,11 +154,11 @@ uint8_t TwoWire::endTransmission(void) {
154 154
   // transmit buffer (blocking)
155 155
   I2C_M_SETUP_Type transferMCfg;
156 156
   transferMCfg.sl_addr7bit = txAddress >> 1; // not sure about the right shift
157
-	transferMCfg.tx_data = txBuffer;
158
-	transferMCfg.tx_length = txBufferLength;
159
-	transferMCfg.rx_data = NULL;
160
-	transferMCfg.rx_length = 0;
161
-	transferMCfg.retransmissions_max = 3;
157
+  transferMCfg.tx_data = txBuffer;
158
+  transferMCfg.tx_length = txBufferLength;
159
+  transferMCfg.rx_data = NULL;
160
+  transferMCfg.rx_length = 0;
161
+  transferMCfg.retransmissions_max = 3;
162 162
   Status status = I2C_MasterTransferData(I2CDEV_M, &transferMCfg, I2C_TRANSFER_POLLING);
163 163
 
164 164
   // reset tx buffer iterator vars

+ 2
- 2
Marlin/src/HAL/HAL_LPC1768/u8g_com_HAL_LPC1768_st7920_hw_spi.cpp View File

@@ -60,6 +60,7 @@
60 60
   //#include "Configuration.h"
61 61
 
62 62
   #include <U8glib.h>
63
+  #include "../Delay.h"
63 64
 
64 65
   #define SPI_FULL_SPEED 0
65 66
   #define SPI_HALF_SPEED 1
@@ -92,8 +93,7 @@
92 93
          /* data */
93 94
         spiSend(0x0FA);
94 95
 
95
-      for( i = 0; i < 4; i++ )   // give the controller some time to process the data
96
-        u8g_10MicroDelay();      // 2 is bad, 3 is OK, 4 is safe
96
+      DELAY_US(40); // give the controller some time to process the data: 20 is bad, 30 is OK, 40 is safe
97 97
     }
98 98
 
99 99
     spiSend(val & 0x0F0);

+ 2
- 2
Marlin/src/HAL/HAL_LPC1768/u8g_com_HAL_LPC1768_st7920_sw_spi.cpp View File

@@ -57,6 +57,7 @@
57 57
 
58 58
   #include <U8glib.h>
59 59
   #include "SoftwareSPI.h"
60
+  #include "../Delay.h"
60 61
 
61 62
   #define SPI_SPEED 3  // About 1 MHz
62 63
 
@@ -78,8 +79,7 @@
78 79
          /* data */
79 80
          swSpiTransfer(0x0FA, SPI_speed, SCK_pin_ST7920_HAL, -1, MOSI_pin_ST7920_HAL_HAL);
80 81
 
81
-      for( i = 0; i < 4; i++ )   // give the controller some time to process the data
82
-        u8g_10MicroDelay();      // 2 is bad, 3 is OK, 4 is safe
82
+      DELAY_US(40); // give the controller some time to process the data: 20 is bad, 30 is OK, 40 is safe
83 83
     }
84 84
 
85 85
     swSpiTransfer(val & 0x0F0, SPI_speed, SCK_pin_ST7920_HAL, -1, MOSI_pin_ST7920_HAL_HAL);

+ 1
- 1
Marlin/src/lcd/dogm/ultralcd_st7920_u8glib_rrd_AVR.cpp View File

@@ -105,7 +105,7 @@ static void ST7920_SWSPI_SND_8BIT(uint8_t val) {
105 105
 #if DOGM_SPI_DELAY_US > 0
106 106
   #define U8G_DELAY() DELAY_US(DOGM_SPI_DELAY_US)
107 107
 #else
108
-  #define U8G_DELAY() u8g_10MicroDelay()
108
+  #define U8G_DELAY() DELAY_US(10)
109 109
 #endif
110 110
 
111 111
 #define ST7920_CS()              { WRITE(ST7920_CS_PIN,1); U8G_DELAY(); }

Loading…
Cancel
Save