Aufgabe 2 - Verwendung von Zählern

Transcrição

Aufgabe 2 - Verwendung von Zählern
Übungen zur Vorlesung Realzeitsysteme
Übung 2
Seite 1
Aufgabe 2 - Verwendung von Zählern
Lösung: OILDatei
/*
* uebung2.oil
*/
OIL_VERSION = "2.0";
// Pull in LEO's implementation definitions
#include <leo.oil>
CPU Counters
{
// Container object
OS LEO {
// OS-Settings
CC = AUTO;
STATUS = EXTENDED;
SCHEDULE = AUTO;
ErrorHook = FALSE;
StartupHook = FALSE;
ShutdownHook = FALSE;
PreTaskHook = FALSE;
PostTaskHook = FALSE;
};
TASK Main {
// Define Main Task
TYPE = EXTENDED;
AUTOSTART = TRUE;
PRIORITY = 1;
ACTIVATION = 1;
SCHEDULE = FULL;
EVENT = NONE;
RESOURCE = NONE;
};
};
© STZ Softwaretechnik - Jens Härer, 2001
Übungen zur Vorlesung Realzeitsysteme
Übung 2
Seite 2
Lösung: CDatei (Quellcode der Applikation)
/*
* uebung2.c
*/
#include <osek/osek.h>
#include "uebung2_defs.h"
DeclareTask(Main);
static int shared_int=0;
static TickType t2_old_cnt=0;
static TickType t3_old_cnt=0;
void bailout(StatusType status)
{
printf("Bailing out due to OSEK error %d\n", status);
ShutdownOS(status);
}
TASK(Main)
{
StatusType rc;
EventMaskType event_mask;
TickType tt1;
CtrInfoType ci1;
int j;
printf("Main: started\n");
printf("Main: calling InitCounter( CTR_OS, 0 )\n");
if( (rc=InitCounter(CTR_OS,0)) != E_OK ) bailout(rc);
printf("Main: calling GetCounterValue( CTR_OS )\n");
if( (rc=GetCounterValue(CTR_OS,&tt1)) != E_OK ) bailout(rc);
printf("Main: actual CTR_OS value = %d ticks\n", tt1);
printf("\nMain: looping...\n\n");
// block really much time
for( j=0; j<1000000000; j++ );
printf("Main: calling GetCounterValue( CTR_OS )\n");
if( (rc=GetCounterValue(CTR_OS,&tt1)) != E_OK ) bailout(rc);
printf("Main: measured %d ticks * 10ms = %dms\n", tt1, tt1*10);
printf("Main: calling GetCounterInfo( CTR_OS )\n");
if( (rc=GetCounterInfo(CTR_OS,&ci1)) != E_OK ) bailout(rc);
printf("Main:
maxallowedvalue=%d\n",ci1.maxallowedvalue);
printf("Main:
ticksperbase=%d\n",ci1.ticksperbase);
printf("Main:
mincycle=%d\n",ci1.mincycle);
}
printf("Main: calling ShutdownOS\n");
ShutdownOS(E_OK);
© STZ Softwaretechnik - Jens Härer, 2001