/******************************************************************
* Copyright (C) 2009 Ram Narula
* Filename: generalUtil.h
* Version: 0.1
* Date: 14 July 2009
* Information: http://www.xduino.com/
******************************************************************/
/******************************************************************
* This file is part of Xduino
*
* Xduino is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Xduino is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Xduino. If not, see .
******************************************************************/
// load this library only once
#ifndef generalUtil_h
#define generalUtil_h
// function prototype
void delay(u32 milliSec);
void delayMicroseconds(u32 microSec);
static void delay2(void);
void delay(u32 milliSec)
{
SysTick_SetReload(9000); // 72MHz = 9 x 8MHz so 9000ticks/ms
SysTick_ITConfig(ENABLE);
SysTick_CounterCmd(SysTick_Counter_Enable); // Start SysTick
TimingDelay = milliSec; // TimingDelay_Decrement() start value
while(TimingDelay); // Do nothing until time counter is 0
SysTick_CounterCmd(SysTick_Counter_Disable); // Stop SysTick
SysTick_CounterCmd(SysTick_Counter_Clear); // Reset SysTick
}
void delayMicroseconds(u32 microSec)
{
SysTick_SetReload(9); // 9 x 8MHz so 9ticks/microsec
SysTick_ITConfig(ENABLE);
SysTick_CounterCmd(SysTick_Counter_Enable); // Start SysTick
TimingDelay = microSec; // TimingDelay_Decrement() start value
while(TimingDelay); // Do nothing until time counter is 0
SysTick_CounterCmd(SysTick_Counter_Disable); // Stop SysTick
SysTick_CounterCmd(SysTick_Counter_Clear); // Reset SysTick
}
static void delay2(void)
{
volatile int i,j;
for (i=0;i<100;i++)
for (j=0;j<100000;j++);
}
#endif