Eliminate _delay(), delay() and _delay_us().
Doesn't change much, even the binary size stays the same. Much cleaner code though, now we have only delay_us() and delay_ms().
This commit is contained in:
parent
1114761bed
commit
a2ce509bed
|
|
@ -94,7 +94,7 @@ void queue_step() {
|
|||
void enqueue_home(TARGET *t, uint8_t endstop_check, uint8_t endstop_stop_cond) {
|
||||
// don't call this function when the queue is full, but just in case, wait for a move to complete and free up the space for the passed target
|
||||
while (queue_full())
|
||||
delay(100);
|
||||
delay_us(100);
|
||||
|
||||
uint8_t h = mb_head + 1;
|
||||
h &= (MOVEBUFFER_SIZE - 1);
|
||||
|
|
|
|||
23
delay.c
23
delay.c
|
|
@ -4,26 +4,17 @@
|
|||
\brief Delay routines
|
||||
*/
|
||||
|
||||
//#include <util/delay_basic.h>
|
||||
#include <stdint.h>
|
||||
#include <util/delay_basic.h>
|
||||
#include "watchdog.h"
|
||||
|
||||
//#include "watchdog.h"
|
||||
|
||||
|
||||
/// interruptable microsecond delay
|
||||
/// does NOT call wd_reset
|
||||
/// \param delay time in microseconds
|
||||
void delay_us( uint16_t delay )
|
||||
{
|
||||
while (delay > (65536UL / (F_CPU / 4000000UL))) {
|
||||
_delay_loop_2(65534); //
|
||||
delay -= (65536L / (F_CPU / 4000000L));
|
||||
}
|
||||
_delay_loop_2( delay * (F_CPU / 4000000UL));
|
||||
}
|
||||
#if F_CPU < 4000000UL
|
||||
#error Delay functions only work with F_CPU >= 4000000UL
|
||||
#endif
|
||||
|
||||
/// delay microseconds
|
||||
/// \param delay time to wait in microseconds
|
||||
void _delay(uint32_t delay) {
|
||||
void delay_us(uint16_t delay) {
|
||||
wd_reset();
|
||||
while (delay > (65536L / (F_CPU / 4000000L))) {
|
||||
_delay_loop_2(65534); // we use 65534 here to compensate for the time that the surrounding loop takes. TODO: exact figure needs tuning
|
||||
|
|
|
|||
29
delay.h
29
delay.h
|
|
@ -1,39 +1,10 @@
|
|||
#ifndef _DELAY_H
|
||||
#define _DELAY_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <util/delay_basic.h>
|
||||
#include "watchdog.h"
|
||||
|
||||
#if F_CPU < 4000000UL
|
||||
#error Delay functions only work with F_CPU >= 4000000UL
|
||||
#endif
|
||||
|
||||
// microsecond delay, does NOT reset WDT if feature enabled
|
||||
void delay_us(uint16_t delay);
|
||||
|
||||
// microsecond delay, does reset WDT if feature enabled
|
||||
void _delay(uint32_t delay);
|
||||
|
||||
// millisecond delay, does reset WDT if feature enabled
|
||||
void delay_ms(uint32_t delay);
|
||||
|
||||
|
||||
// microsecond timer, does reset WDT if feature enabled
|
||||
// 0 results in no real delay, but the watchdog
|
||||
// reset is called if the feature is enabled
|
||||
static void delay(uint32_t) __attribute__ ((always_inline));
|
||||
inline void delay(uint32_t d) {
|
||||
if (d > (65536L / (F_CPU / 4000000L))) {
|
||||
_delay(d);
|
||||
}
|
||||
else {
|
||||
wd_reset();
|
||||
if( d ) {
|
||||
_delay_loop_2(d * (F_CPU / 4000000L));
|
||||
wd_reset();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* _DELAY_H */
|
||||
|
|
|
|||
10
sd.c
10
sd.c
|
|
@ -120,7 +120,7 @@ byte sdc_initialize(void) {
|
|||
if (retries >= 0xFF) {
|
||||
return(NULL); // timed out!
|
||||
}
|
||||
delay(5);
|
||||
delay_ms(5);
|
||||
}
|
||||
// at this stage, the card is in idle mode and ready for start up
|
||||
retries = 0;
|
||||
|
|
@ -159,7 +159,7 @@ void sdc_readRegister(byte sentCommand) {
|
|||
byte retries=0x00;
|
||||
byte res=sdc_cmd(sentCommand, 0);
|
||||
while(res != 0x00) {
|
||||
delay(1);
|
||||
delay_ms(1);
|
||||
retries++;
|
||||
if (retries >= 0xFF) return; // timed out!
|
||||
res=spi_cmd(0xFF); // retry
|
||||
|
|
@ -180,7 +180,7 @@ void sdc_readRegister(byte sentCommand) {
|
|||
void sdc_writeBlock(long blockIndex) {
|
||||
byte retries=0;
|
||||
while(sdc_cmd(WRITE_BLOCK, blockIndex * blockSize) != 0x00) {
|
||||
delay(1);
|
||||
delay_ms(1);
|
||||
retries++;
|
||||
if (retries >= 0xFF) return; // timed out!
|
||||
}
|
||||
|
|
@ -196,7 +196,7 @@ void sdc_writeBlock(long blockIndex) {
|
|||
spi_cmd(0xFF); // LSB
|
||||
spi_cmd(0xFF); // MSB
|
||||
// wait until write is finished
|
||||
while (spi_cmd(0xFF) != 0xFF) delay(1); // kind of NOP
|
||||
while (spi_cmd(0xFF) != 0xFF) delay_ms(1); // kind of NOP
|
||||
}
|
||||
|
||||
// read block on SD card and copy data in block vector
|
||||
|
|
@ -205,7 +205,7 @@ void sdc_readBlock(long blockIndex) {
|
|||
byte retries = 0x00;
|
||||
byte res = sdc_cmd(READ_SINGLE_BLOCK, (blockIndex * blockSize));
|
||||
while(res != 0x00) {
|
||||
delay(1);
|
||||
delay_ms(1);
|
||||
retries++;
|
||||
if (retries >= 0xFF) return; // timed out!
|
||||
res=spi_cmd(0xFF); // retry
|
||||
|
|
|
|||
Loading…
Reference in New Issue