Apple16X50UARTSync.h [plain text]
#ifndef _APPLE16X50UARTSYNC_H
#define _APPLE16X50UARTSYNC_H
#include "Apple16X50Serial.h"
#include <IOKit/serial/IORS232SerialStreamSync.h> // superclass
#include "Apple16X50BusInterface.h" // Provider class
#include "Apple16X50Queue.h" // RX & TX command queue class
#include "Apple16X50UARTTypes.h" // Hardware specific details
#include <IOKit/IOCommandGate.h>
#include <IOKit/IOTimerEventSource.h>
enum tXO_State {
kXOnSent = -2,
kXOffSent = -1,
kXO_Idle = 0,
kXOffNeeded = 1,
kXOnNeeded = 2
} ;
#define Apple16X50BusInterface com_apple_driver_16X50BusInterface
class Apple16X50BusInterface;
#define Apple16X50UARTSync com_apple_driver_16X50UARTSync
class Apple16X50UARTSync : public IORS232SerialStreamSync
{
OSDeclareDefaultStructors(com_apple_driver_16X50UARTSync);
public:
#ifdef REFBUG
virtual void retain() const;
virtual void release() const;
#endif
virtual IOReturn acquirePort(bool sleep);
virtual IOReturn releasePort();
virtual IOReturn setState(UInt32 state, UInt32 mask);
virtual UInt32 getState();
virtual IOReturn watchState(UInt32 *state, UInt32 mask);
virtual UInt32 nextEvent();
virtual IOReturn executeEvent(UInt32 event, UInt32 data);
virtual IOReturn requestEvent(UInt32 event, UInt32 *data);
virtual IOReturn enqueueEvent(UInt32 event, UInt32 data, bool sleep);
virtual IOReturn dequeueEvent(UInt32 *event, UInt32 *data, bool sleep);
virtual IOReturn enqueueData(UInt8 *buffer, UInt32 size, UInt32 *count, bool sleep );
virtual IOReturn dequeueData(UInt8 *buffer, UInt32 size, UInt32 *count, UInt32 min);
virtual bool attachToChild(IORegistryEntry *child, const IORegistryPlane *plane);
virtual bool start(IOService *provider);
virtual bool attach(IOService *provider);
virtual bool terminate(IOOptionBits options);
virtual bool finalize(IOOptionBits options);
virtual void stop(IOService *provider);
virtual void free();
virtual void interrupt();
static Apple16X50UARTSync* probeUART(Apple16X50BusInterface *provider,
void *refCon, tUART_Type type=kUART_Unknown);
virtual UInt32 determineMasterClock();
virtual void setMasterClock(UInt32 clock);
protected:
static tUART_Type identifyUART(Apple16X50BusInterface *Provider, void *refCon);
virtual void setDivisor(UInt32 div);
virtual UInt32 getDivisor();
virtual void resetUART();
virtual void programUART();
virtual void startTxEngine();
static void dataLatencyTimeoutAction(OSObject *owner, IOTimerEventSource *);
static void frameTimeoutAction(OSObject *owner, IOTimerEventSource *);
static void delayTimeoutAction(OSObject *owner, IOTimerEventSource *);
static void heartbeatTimeoutAction(OSObject *owner, IOTimerEventSource *);
virtual IOReturn executeEventGated(UInt32 event, UInt32 data, UInt32 *state, UInt32 *delta);
virtual UInt32 generateRxQState();
virtual void flowMachine();
virtual IOReturn activatePort();
virtual void deactivatePort();
virtual void programMCR(UInt32 state, bool irqen=true, bool loop=false);
inline UInt8 inb(tUARTregisters reg) { return Provider->getReg(reg, fRefCon); };
inline void outb(tUARTregisters reg, UInt8 val) { Provider->setReg(reg, val, fRefCon); };
inline UInt32 msrState();
#ifdef DEBUG
virtual void showRegs();
#endif
static IOReturn acquirePortAction(OSObject *owner, void*arg0, void*, void*, void*);
static IOReturn releasePortAction(OSObject *owner, void*, void*, void*, void*);
static IOReturn setStateAction(OSObject *owner, void*arg0, void*arg1, void*, void*);
static IOReturn watchStateAction(OSObject *owner, void*arg0, void*arg1, void*, void*);
static IOReturn nextEventAction(OSObject *owner, void*, void*, void*, void*);
static IOReturn executeEventAction(OSObject *owner, void*arg0, void*arg1, void*, void*);
static IOReturn enqueueEventAction(OSObject *owner, void*arg0, void*arg1, void*arg2, void*);
static IOReturn dequeueEventAction(OSObject *owner, void*arg0, void*arg1, void*arg2, void*);
static IOReturn enqueueDataAction(OSObject *owner, void*arg0, void*arg1, void*arg2, void*arg3);
static IOReturn dequeueDataAction(OSObject *owner, void*arg0, void*arg1, void*arg2, void*arg3);
static IOReturn timerControlAction(OSObject *owner, void*arg0, void*, void*, void*);
static IOReturn stopAction(OSObject *owner, void*arg0, void*, void*, void*);
virtual IOReturn acquirePortGated(bool sleep);
virtual IOReturn releasePortGated();
virtual void setStateGated(UInt32 state, UInt32 mask);
virtual IOReturn watchStateGated(UInt32 *state, UInt32 mask);
virtual UInt32 nextEventGated();
virtual IOReturn executeEventGated(UInt32 event, UInt32 data);
virtual IOReturn enqueueEventGated(UInt32 event, UInt32 data, bool sleep);
virtual IOReturn dequeueEventGated(UInt32 *event, UInt32 *data, bool sleep);
virtual IOReturn enqueueDataGated(UInt8 *buffer, UInt32 size, UInt32 *count, bool sleep);
virtual IOReturn dequeueDataGated(UInt8 *buffer, UInt32 size, UInt32 *count, bool sleep);
virtual void stopGated(IOService *provider);
Apple16X50BusInterface *Provider;
Apple16X50Queue *RxQ, *TxQ;
IOWorkLoop *WorkLoop;
IOCommandGate *CommandGate;
const char *Name;
UInt32 State;
bool OffLine; bool Acquired; UInt32 WatchStateMask;
enum { kFreed=0, kAllocated, kAttached, kProbed, kStarted, kAcquired, kReleased, kTerminated, kFinalized, kStopped, kDetached } Stage;
IOTimerEventSource *FrameTimer;
UInt32 FrameInterval; bool FrameTimerRunning;
IOTimerEventSource *DataLatTimer;
UInt32 DataLatInterval; IOTimerEventSource *DelayTimer;
UInt32 DelayInterval;
bool DelayTimerRunning;
#ifdef HEARTBEAT
IOTimerEventSource *HeartBeatTimer;
UInt32 HeartBeatInterval; bool HeartBeatNeeded;
#endif
tUART_Type UART_Type;
UInt32 MaxBaud;
UInt32 FIFO_Size;
UInt8 LCR_Image;
UInt8 FCR_Image;
UInt8 IER_Mask;
UInt32 SW_Special[8];
UInt32 DataWidth;
UInt8 DataMask;
UInt32 StopBits;
UInt32 Parity;
UInt32 BaudRate;
UInt32 MasterClock;
UInt16 Divisor;
bool MinLatency;
bool IgnoreParityErrors;
UInt32 FlowControl; tXO_State RXO_State;
UInt8 XOnChar;
UInt8 XOffChar;
};
#endif