/*
===============================================================================
Name : lpc824_divtest.c
Author : gl_belre9
Version :
Description : main definition
===============================================================================
*/
#if defined (__USE_LPCOPEN)
#if defined(NO_BOARD_LIB)
#include "chip.h"
#else
#include "board.h"
#endif
#endif
#include <cr_section_macros.h>
#define TICKRATE_HZ (2)/// Frequency for SysTick Timer
#define LOOP_NUMBER24
/*****************************************************************************
* Public types/enumerations/variables
****************************************************************************/
static volatile uint32_t ticks;
/*****************************************************************************
* Private functions
****************************************************************************/
/*****************************************************************************
* Public functions
****************************************************************************/
/**
* @briefHandle interrupt from SysTick timer, measurement of time
* @returnNothing
*/
void SysTick_Handler(void)
{
volatile float time = (float)((1.0 / TICKRATE_HZ) / (float)ticks);
time *= 1000000;
ticks = 0;
}
int main(void) {
// Read clock settings and update SystemCoreClock variable
SystemCoreClockUpdate();
// Set up and initialize all required blocks and
// functions related to the board hardware
Board_Init();
// Set the LED to the state of "On"
Board_LED_Set(0, true);
/// Enable SysTick Timer
SysTick_Config(SystemCoreClock / TICKRATE_HZ);
volatile int i;
volatile int x = 3;
volatile int y = 100;
volatile int z = 0;
volatile int count = 0;
/// Simple Division
while(1) {
for(i = 0 ; i < LOOP_NUMBER; i ++) {
z = y / x;
if( z == 0) {
count --;
} else {
count++;
}
}
ticks++;
}
return 0 ;
}
|
/*
===============================================================================
Name : lpc824_divtest.c
Author : gl_belre9
Version :
Description : main definition
===============================================================================
*/
#if defined (__USE_LPCOPEN)
#if defined(NO_BOARD_LIB)
#include "chip.h"
#else
#include "board.h"
#endif
#endif
#include <cr_section_macros.h>
#define TICKRATE_HZ (1000)/// Frequency for SysTick Timer
#define CALC_NUMBER10000
#define LOOP_NUMBER24*CALC_NUMBER
/*****************************************************************************
* Public types/enumerations/variables
****************************************************************************/
static volatile uint32_t ticks;
/*****************************************************************************
* Private functions
****************************************************************************/
/*****************************************************************************
* Public functions
****************************************************************************/
/**
* @briefHandle interrupt from SysTick timer, measurement of time
* @returnNothing
*/
/// 1. Change your Systick handler so that it just counts ticks. Don't try to do time calcluations here
void SysTick_Handler(void)
{
ticks++;
}
int main(void) {
// Read clock settings and update SystemCoreClock variable
SystemCoreClockUpdate();
// Set up and initialize all required blocks and
// functions related to the board hardware
Board_Init();
// Set the LED to the state of "On"
Board_LED_Set(0, true);
/// Enable SysTick Timer
SysTick_Config(SystemCoreClock / TICKRATE_HZ);
volatile int i;
volatile int x = 1000;
volatile int y = 100;
volatile int z = 0;
volatile int count = 0;
/// Simple Division
while(1) {
/// 2. Do a large number of divisions (100's or 1000's). This will reduce any timing variations
x = 100;
y = 1000;
/// 4. Note the number of ticks at the start of your division loop
/// Simple Division
volatile int startticks = ticks;
/// 6. Repeat several times to give an average
for(i = 0 ; i < LOOP_NUMBER; i ++ )
{
/// 3. Change the numbers used in each division. You are always using the same numbers
z = ++y / ++x;
}
/// 5. Note the number of ticks at the end of the division and calculate the difference from #4
volatile int endticks = ticks;
/// Calculate Process Time
float tickstime = (float)(endticks - startticks) / CALC_NUMBER;
/// UART Debug
DEBUGOUT("Proc Time(x%d):%f[ms]\r\n", LOOP_NUMBER/CALC_NUMBER, tickstime);
/// Reset Ticks
ticks = 0;
}
return 0 ;
}
|