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 7 years ago
parent
commit
9d98a62699

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

33
 #ifndef MARLIN_DELAY_H
33
 #ifndef MARLIN_DELAY_H
34
 #define MARLIN_DELAY_H
34
 #define MARLIN_DELAY_H
35
 
35
 
36
+#include "../core/macros.h"
37
+
36
 #if defined(__arm__) || defined(__thumb__)
38
 #if defined(__arm__) || defined(__thumb__)
37
 
39
 
38
   /* https://blueprints.launchpad.net/gcc-arm-embedded/+spec/delay-cycles */
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
 
89
 
90
     /* The software SPI routine */
90
     /* The software SPI routine */
91
     __asm__ __volatile__(
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
       /* Bit 7 */
94
       /* Bit 7 */
95
       A("ubfx %[idx],%[txval],#7,#1")                      /* Place bit 7 in bit 0 of idx*/
95
       A("ubfx %[idx],%[txval],#7,#1")                      /* Place bit 7 in bit 0 of idx*/
170
 
170
 
171
     /* The software SPI routine */
171
     /* The software SPI routine */
172
     __asm__ __volatile__(
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
       /* bit 7 */
175
       /* bit 7 */
176
       A("str %[sck_mask],[%[sck_port]]")           /* SODR */
176
       A("str %[sck_mask],[%[sck_port]]")           /* SODR */
290
 
290
 
291
     /* The software SPI routine */
291
     /* The software SPI routine */
292
     __asm__ __volatile__(
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
       L("loop%=")
295
       L("loop%=")
296
       A("ldrb.w %[txval], [%[ptr]], #1")                   /* Load value to send, increment buffer */
296
       A("ldrb.w %[txval], [%[ptr]], #1")                   /* Load value to send, increment buffer */
368
 
368
 
369
     /* The software SPI routine */
369
     /* The software SPI routine */
370
     __asm__ __volatile__(
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
       L("loop%=")
373
       L("loop%=")
374
 
374
 

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

137
 
137
 
138
 bool HAL_timer_interrupt_enabled(const uint8_t timer_num) {
138
 bool HAL_timer_interrupt_enabled(const uint8_t timer_num) {
139
   const tTimerConfig * const pConfig = &TimerConfig[timer_num];
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
 #endif // ARDUINO_ARCH_SAM
143
 #endif // ARDUINO_ARCH_SAM

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

58
 #include <U8glib.h>
58
 #include <U8glib.h>
59
 #include <Arduino.h>
59
 #include <Arduino.h>
60
 #include "../../core/macros.h"
60
 #include "../../core/macros.h"
61
+#include "../Delay.h"
61
 
62
 
62
 void u8g_SetPIOutput_DUE(u8g_t *u8g, uint8_t pin_index) {
63
 void u8g_SetPIOutput_DUE(u8g_t *u8g, uint8_t pin_index) {
63
    PIO_Configure(g_APinDescription[u8g->pin_list[pin_index]].pPort, PIO_OUTPUT_1,
64
    PIO_Configure(g_APinDescription[u8g->pin_list[pin_index]].pPort, PIO_OUTPUT_1,
71
   else port->PIO_CODR = mask;
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
 Pio *SCK_pPio, *MOSI_pPio;
75
 Pio *SCK_pPio, *MOSI_pPio;
97
 uint32_t SCK_dwMask, MOSI_dwMask;
76
 uint32_t SCK_dwMask, MOSI_dwMask;
98
 
77
 
102
       MOSI_pPio->PIO_SODR = MOSI_dwMask;
81
       MOSI_pPio->PIO_SODR = MOSI_dwMask;
103
     else
82
     else
104
       MOSI_pPio->PIO_CODR = MOSI_dwMask;
83
       MOSI_pPio->PIO_CODR = MOSI_dwMask;
105
-    __delay_4cycles(1);
84
+    DELAY_NS(48);
106
     SCK_pPio->PIO_SODR = SCK_dwMask;
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
     val <<= 1;
87
     val <<= 1;
109
     SCK_pPio->PIO_CODR = SCK_dwMask;
88
     SCK_pPio->PIO_CODR = SCK_dwMask;
110
   }
89
   }
125
        /* data */
104
        /* data */
126
       spiSend_sw_DUE(0x0FA);
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
   spiSend_sw_DUE(val & 0x0F0);
110
   spiSend_sw_DUE(val & 0x0F0);

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

118
   // perform blocking read into buffer
118
   // perform blocking read into buffer
119
   I2C_M_SETUP_Type transferMCfg;
119
   I2C_M_SETUP_Type transferMCfg;
120
   transferMCfg.sl_addr7bit = address >> 1; // not sure about the right shift
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
   // set rx buffer iterator vars
128
   // set rx buffer iterator vars
129
   rxBufferIndex = 0;
129
   rxBufferIndex = 0;
154
   // transmit buffer (blocking)
154
   // transmit buffer (blocking)
155
   I2C_M_SETUP_Type transferMCfg;
155
   I2C_M_SETUP_Type transferMCfg;
156
   transferMCfg.sl_addr7bit = txAddress >> 1; // not sure about the right shift
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
   Status status = I2C_MasterTransferData(I2CDEV_M, &transferMCfg, I2C_TRANSFER_POLLING);
162
   Status status = I2C_MasterTransferData(I2CDEV_M, &transferMCfg, I2C_TRANSFER_POLLING);
163
 
163
 
164
   // reset tx buffer iterator vars
164
   // reset tx buffer iterator vars

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

60
   //#include "Configuration.h"
60
   //#include "Configuration.h"
61
 
61
 
62
   #include <U8glib.h>
62
   #include <U8glib.h>
63
+  #include "../Delay.h"
63
 
64
 
64
   #define SPI_FULL_SPEED 0
65
   #define SPI_FULL_SPEED 0
65
   #define SPI_HALF_SPEED 1
66
   #define SPI_HALF_SPEED 1
92
          /* data */
93
          /* data */
93
         spiSend(0x0FA);
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
     spiSend(val & 0x0F0);
99
     spiSend(val & 0x0F0);

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

57
 
57
 
58
   #include <U8glib.h>
58
   #include <U8glib.h>
59
   #include "SoftwareSPI.h"
59
   #include "SoftwareSPI.h"
60
+  #include "../Delay.h"
60
 
61
 
61
   #define SPI_SPEED 3  // About 1 MHz
62
   #define SPI_SPEED 3  // About 1 MHz
62
 
63
 
78
          /* data */
79
          /* data */
79
          swSpiTransfer(0x0FA, SPI_speed, SCK_pin_ST7920_HAL, -1, MOSI_pin_ST7920_HAL_HAL);
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
     swSpiTransfer(val & 0x0F0, SPI_speed, SCK_pin_ST7920_HAL, -1, MOSI_pin_ST7920_HAL_HAL);
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
 #if DOGM_SPI_DELAY_US > 0
105
 #if DOGM_SPI_DELAY_US > 0
106
   #define U8G_DELAY() DELAY_US(DOGM_SPI_DELAY_US)
106
   #define U8G_DELAY() DELAY_US(DOGM_SPI_DELAY_US)
107
 #else
107
 #else
108
-  #define U8G_DELAY() u8g_10MicroDelay()
108
+  #define U8G_DELAY() DELAY_US(10)
109
 #endif
109
 #endif
110
 
110
 
111
 #define ST7920_CS()              { WRITE(ST7920_CS_PIN,1); U8G_DELAY(); }
111
 #define ST7920_CS()              { WRITE(ST7920_CS_PIN,1); U8G_DELAY(); }

Loading…
Cancel
Save