80 lines
2.1 KiB
C
80 lines
2.1 KiB
C
#include <stddef.h>
|
|
#include <stdint.h>
|
|
#include <exec/sync.h>
|
|
#include <exec/list.h>
|
|
#include <exec/mem.h>
|
|
#include <exec/port.h>
|
|
#include <exec/device.h>
|
|
#include <exec/exec.h>
|
|
|
|
struct List devices;
|
|
|
|
void DevicesInit(void) {
|
|
NewList(&devices, LP_BLOCK);
|
|
}
|
|
|
|
int OpenDevice(char *devName, uint32_t unitNumber, struct IORequest *ior, uint32_t flags) {
|
|
struct Device *dev = (struct Device *)FindNode(&devices, devName);
|
|
if (dev == NULL) return ODE_NOTFOUND;
|
|
ior->dev = dev;
|
|
uint32_t status = ((uint32_t (*)(struct IExec *, struct Device *, uint32_t, struct IORequest *, uint32_t))dev->library.vectors[DV_OPEN])(&exec_api, dev, unitNumber, ior, flags);
|
|
if (status) return status;
|
|
if (ior->unit != NULL) {
|
|
ior->unit->open_count++;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
void AddDevice(struct Device *device) {
|
|
Enqueue(&devices, &device->library.node);
|
|
}
|
|
|
|
uint32_t BeginIO(struct IORequest *ior) {
|
|
struct DevFuncTable *dft = (struct DevFuncTable *)ior->dev->library.vectors;
|
|
return dft->beginio(ior);
|
|
}
|
|
|
|
uint32_t WaitIO(struct IORequest *ior) {
|
|
if (ior->message.node.type == NT_REPLYMSG || ior->flags & IOF_QUICK) {
|
|
return 0;
|
|
}
|
|
WaitPort(ior->message.reply_port);
|
|
return 0;
|
|
}
|
|
|
|
uint32_t DoIO(struct IORequest *ior) {
|
|
ior->flags |= IOF_QUICK;
|
|
BeginIO(ior);
|
|
if (!(ior->flags & IOF_QUICK)) {
|
|
WaitIO(ior);
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
uint32_t SendIO(struct IORequest *ior) {
|
|
ior->flags &= ~IOF_QUICK;
|
|
BeginIO(ior);
|
|
return 0;
|
|
}
|
|
|
|
uint32_t GenericBeginIO(struct IORequest *ior) {
|
|
PutMsg(&ior->unit->port, &ior->message);
|
|
WaitPort(ior->message.reply_port);
|
|
return 0;
|
|
}
|
|
|
|
struct IORequest *CreateExtIO(struct Port *reply_port, uint32_t size) {
|
|
struct IORequest *ior = (struct IORequest *)AllocMem(size);
|
|
if (!ior) return NULL;
|
|
ior->message.reply_port = reply_port;
|
|
ior->message.length = size;
|
|
return ior;
|
|
}
|
|
|
|
struct IOStdReq *CreateStdIO(struct Port *reply_port) {
|
|
return (struct IOStdReq *)CreateExtIO(reply_port, sizeof(struct IOStdReq));
|
|
}
|
|
|
|
void CompleteIO(struct IORequest *ior) {
|
|
ior->message.node.type = NT_REPLYMSG;
|
|
} |