Brakowało
pobrania TimerBase
TimerBase = (struct Library *)TimerIO->tr_node.io_Device;
TimerBase - wskaźnik typu struct Library *
zarezerwowania pamięci na currentval
currentval=(struct timeval*)malloc(sizeof(struct timeval));
Poza tym ok
Kod:
#include <stdio.h>
#include <stdlib.h>
#include <proto/timer.h>
#include <proto/exec.h>
#include <proto/dos.h>
#include <proto/utility.h>
#include <devices/timer.h>
#include <exec/types.h>
static int init(void);
static void close(void);
struct MsgPort *TimerMP = NULL;
struct Library *TimerBase = NULL;
struct timerequest *TimerIO = NULL;
struct IORequest timereq;
struct timeval *currentval;
long error; //OpenDevice
static int init(void)
{
TimerMP=CreateMsgPort();
if (!TimerMP)
{
return -1;
}
TimerIO=(struct timerequest *) CreateIORequest(TimerMP, sizeof(struct timerequest));
if (!TimerIO)
{
return -1;
}
error=OpenDevice(TIMERNAME, UNIT_ECLOCK, (struct IORequest*)TimerIO, 0);
if (0 != error)
{
return -1;
}
TimerBase = (struct Library *)TimerIO->tr_node.io_Device;
currentval=(struct timeval*)malloc(sizeof(struct timeval));
if (!currentval)
{
return -1;
}
return 0;
}
static void close(void)
{
if (currentval)
{
free(currentval);
}
if (TimerIO)
{
CloseDevice((struct IORequest*)TimerIO);
DeleteIORequest(TimerIO);
}
if (TimerMP)
{
DeletePort(TimerMP);
}
}
int main(void)
{
if (0 == init())
{
GetSysTime(currentval);
printf("%d %d \n",currentval->tv_secs,currentval->tv_micro);
GetSysTime(currentval);
printf("%d %d \n",currentval->tv_secs,currentval->tv_micro);
}
close();
return 0;
}