Add 'mdelay()' function to busy-wait for given number of milli-seconds

This commit is contained in:
Harald Welte
2017-02-03 22:16:47 +01:00
parent 2819e9c131
commit 83207e0cad
3 changed files with 23 additions and 2 deletions

View File

@@ -24,6 +24,7 @@
#include "stdlib.h"
#include "string.h"
#include "inttypes.h"
#include "syscalls.h"
#define MIN(a, b) ((a < b) ? a : b)

View File

@@ -50,8 +50,6 @@
extern caddr_t _sbrk ( int incr ) ;
extern int link( char *old, char *new ) ;
extern int _close( int file ) ;
extern int _fstat( int file, struct stat *st ) ;
@@ -63,3 +61,5 @@ extern int _lseek( int file, int ptr, int dir ) ;
extern int _read(int file, char *ptr, int len) ;
extern int _write( int file, char *ptr, int len ) ;
extern void mdelay(unsigned int msecs);

View File

@@ -162,4 +162,24 @@ extern WEAK void LowLevelInit( void )
PMC->PMC_MCKR = BOARD_MCKR ;
/* wait for master clock to be ready */
for ( timeout = 0; !(PMC->PMC_SR & PMC_SR_MCKRDY) && (timeout++ < CLOCK_TIMEOUT) ; );
/* Configure SysTick for 1ms */
SysTick_Config(BOARD_MCK/1000);
}
/* SysTick based delay function */
volatile uint32_t jiffies;
/* Interrupt handler for SysTick interrupt */
void SysTick_Handler(void)
{
jiffies++;
}
void mdelay(unsigned int msecs)
{
uint32_t jiffies_start = jiffies;
do {
} while ((jiffies - jiffies_start) < msecs);
}