/* {+D} SYSTEM: AVME9670.h FILENAME: AVME9670.h MODULE NAME: Functions common to the AVME9670 example software. VERSION: C CREATION DATE: 06/06/01 DESIGNED BY: FJM CODED BY: FJM ABSTRACT: This file contains the definitions, structures and prototypes for AVME9670. CALLING SEQUENCE: MODULE TYPE: I/O RESOURCES: SYSTEM RESOURCES: MODULES CALLED: REVISIONS: DATE BY PURPOSE ------- ---- ------------------------------------------------ 04/10/03 FJM T2.2 updates. 01/20/05 FJM Extended carrier function library interface. 09/07/06 FJM Ifdef'ed definitions of TRUE and FALSE. {-D} */ /* MODULES FUNCTIONAL DETAILS: This file contains the definitions, structures and prototypes for AVME9670. */ #include "stdio.h" #include "stdlib.h" /* RTEMS does not have BOOL typedef'd */ /* Acromag code uses BOOL as defined by vxWorks */ #if defined(__rtems__) typedef int BOOL; #endif typedef unsigned char byte; /* custom made byte data type */ typedef unsigned short word; /* custom made word data type */ typedef int CSTATUS; /* Custom mad CSTATUS data type, used as return value from the carrier functions. */ #if !defined(FALSE) || (FALSE!=0) #define FALSE 0 /* Boolean value for false */ #endif #if !defined(TRUE) || (TRUE!=1) #define TRUE 1 /* Boolean value for true */ #endif #define SLOT_A 0x41 /* Value for slot A */ #define SLOT_B 0x42 /* Value for slot B */ #define SLOT_C 0x43 /* Value for slot C */ #define SLOT_D 0x44 /* Value for slot D */ /* see carrier manual for additional info about setting the base address and size (memory space set to 4meg) */ #define SLOT_A_IO_OFFSET 0x0000 /* Slot A IO space addr. offset from carrier base addr. */ #define SLOT_A_ID_OFFSET 0x0080 /* Slot A ID space addr. offset from carrier base addr. */ #define SLOT_A_MEM_OFFSET 0x0 /* Slot A MEM space addr. */ #define SLOT_A_MEM_BADR_SIZE 0x0002 /* Slot A base address & size register */ #define SLOT_B_IO_OFFSET 0x0100 /* Slot B IO space addr. offset from carrier base addr. */ #define SLOT_B_ID_OFFSET 0x0180 /* Slot B ID space addr. offset from carrier base addr. */ #define SLOT_B_MEM_OFFSET 0x400000 /* Slot B MEM space addr. */ #define SLOT_B_MEM_BADR_SIZE 0x0042 /* Slot B base address & size register */ #define SLOT_C_IO_OFFSET 0x0200 /* Slot C IO space addr. offset from carrier base addr. */ #define SLOT_C_ID_OFFSET 0x0280 /* Slot C ID space addr. offset from carrier base addr. */ #define SLOT_C_MEM_OFFSET 0x800000 /* Slot C MEM space addr. */ #define SLOT_C_MEM_BADR_SIZE 0x0082 /* Slot C base address & size register */ #define SLOT_D_IO_OFFSET 0x0300 /* Slot D IO space addr. offset from carrier base addr. */ #define SLOT_D_ID_OFFSET 0x0380 /* Slot D ID space addr. offset from carrier base addr. */ #define SLOT_D_MEM_OFFSET 0xC00000 /* Slot D MEM space addr. */ #define SLOT_D_MEM_BADR_SIZE 0x00C2 /* Slot D base address & size register */ #define MAX_CARRIERS 5 /* maximum number of carriers */ #define SOFTWARE_RESET 0x10 /* Value to OR with control register to reset carrier */ #define INT_ENABLE 0x08 /* Global interrupt enable */ #define INT_PENDING_CLEAR 0x04 /* Global interrupt pending bit */ #define IPA_INT0_PENDING 0x01 /* IP A Int 0 Interrupt Pending bit */ #define IPA_INT1_PENDING 0x02 /* IP A Int 1 Interrupt Pending bit */ #define IPB_INT0_PENDING 0x04 /* IP B Int 0 Interrupt Pending bit */ #define IPB_INT1_PENDING 0x08 /* IP B Int 1 Interrupt Pending bit */ #define IPC_INT0_PENDING 0x10 /* IP C Int 0 Interrupt Pending bit */ #define IPC_INT1_PENDING 0x20 /* IP C Int 1 Interrupt Pending bit */ #define IPD_INT0_PENDING 0x40 /* IP D Int 0 Interrupt Pending bit */ #define IPD_INT1_PENDING 0x80 /* IP D Int 1 Interrupt Pending bit */ /* Carrier attributes */ #define VME_CARRIER 1 << 4 /* VME type carrier */ #define ISA_CARRIER 2 << 4 /* ISA type carrier */ #define PCI_CARRIER 3 << 4 /* PCI type carrier */ #define CARRIER_MEM 1 << 2 /* carrier supports memory space */ #define CARRIER_CLK 1 /* carrier supports 32MHz IP clocking */ /* CSTATUS return values Errors will have most significant bit set and are preceded with an E_. Success values will be succeeded with an S_. */ #define E_OUT_OF_MEMORY 0x8001 /* Out of memory status value */ #define E_OUT_OF_CARRIERS 0x8002 /* All carrier spots have been taken */ #define E_INVALID_HANDLE 0x8003 /* no carrier exists for this handle */ #define E_INVALID_SLOT 0x8004 /* no slot available with this number */ #define E_NOT_INITIALIZED 0x8006 /* carrier not initialized */ #define E_NOT_IMPLEMENTED 0x8007; /* Function is not implemented */ #define E_NO_INTERRUPTS 0x8008; /* Carrier will be unable to handle interrupts */ #define S_OK 0x0000 /* Everything worked successfully */ /* Carrier data structure */ typedef struct { int nHandle; /* handle of this carrier structure */ long lBaseAddress; /* pointer to base address of carrier board */ int nIntLevel; /* Interrupt level of Carrier */ void (*pSlotAHandler)(void*); /* Interrupt Handler for Slot A */ void* pSlotAData; /* Slot A interrupt data */ void (*pSlotBHandler)(void*); /* Interrupt Handler for Slot B */ void* pSlotBData; /* Slot B interrupt data */ void (*pSlotCHandler)(void*); /* Interrupt Handler for Slot C */ void* pSlotCData; /* Slot C interrupt data */ void (*pSlotDHandler)(void*); /* Interrupt Handler for Slot D */ void* pSlotDData; /* Slot D interrupt data */ BOOL bInitialized; /* Carrier intialized flag */ BOOL bIntEnabled; /* interrupts enabled flag */ word uCarrierID; /* Carrier Identification value from open */ long lMemBaseAddress; /* pointer to base address of carrier board memory space */ }CARRIERDATA_STRUCT; typedef struct { word unused0[96]; word controlReg; /* Status/Control Register */ word intLevel; /* interrupt level Register */ word ipError; /* IP error Register */ word ipMemoryEnable; /* IP memory enable Register */ word unused1[4]; word ipABAS; /* IP A base address & size register */ word ipBBAS; /* IP B base address & size register */ word ipCBAS; /* IP C base address & size register */ word ipDBAS; /* IP D base address & size register */ word unused2[4]; word intEnable; /* Interrupt Enable Register */ word intPending; /* Interrupt Pending Register */ word intClear; /* Interrupt Clear Register */ }BOARD_MEMORY_MAP; /* Function Prototypes For a description of these data types see the file infoCarrier.txt */ CSTATUS GetCarrierAddress(int nHandle, long* pAddress); CSTATUS SetCarrierAddress(int nHandle, long lAddress); CSTATUS GetIpackAddress(int nHandle, char chSlot, long* pAddress); CSTATUS ReadIpackID(int nHandle, char chSlot, word* pWords, int nWords); CSTATUS EnableInterrupts(int nHandle); CSTATUS DisableInterrupts(int nHandle); CSTATUS SetInterruptLevel(int nHandle, word uLevel); CSTATUS GetInterruptLevel(int nHandle, word* pLevel); CSTATUS SetInterruptHandler(int nHandle, char chSlot, int nRequestNumber, int nVector, void(*pHandler)(void*), void* pData); CSTATUS InitCarrierLib(void); CSTATUS CarrierOpen(int nDevInstance, int* pHandle); CSTATUS CarrierClose(int nHandle); CSTATUS CarrierInitialize(int nHandle); byte GetLastSlotLetter(); /* carrier enhancements */ CSTATUS GetMemoryAddress(int nHandle, long* pAddress); CSTATUS SetMemoryAddress(int nHandle, long lAddress); CSTATUS GetIpackMemoryAddress(int nHandle, char chSlot, long* pAddress); CSTATUS SetIPClockControl(int nHandle, char chSlot, word uControl); CSTATUS GetIPClockControl(int nHandle, char chSlot, word* pControl); CSTATUS GetCarrierID(int nHandle, word* pCarrierID); CSTATUS SetAutoAckDisable(int nHandle, word uState); CSTATUS GetAutoAckDisable(int nHandle, word* pState); CSTATUS GetTimeOutAccess(int nHandle, word* pState); CSTATUS GetIPErrorBit(int nHandle, word* pState); /* Functions used by above functions */ void AddCarrier(CARRIERDATA_STRUCT* pCarrier); void DeleteCarrier(int nHandle); CARRIERDATA_STRUCT* GetCarrier(int nHandle); void CarrierIntHandler(int nParam); byte input_byte(byte*);/* function to read an input byte */ word input_word(word*);/* function to read an input word */ void output_byte(byte*, byte); /* function to output a byte */ void output_word(word*, word); /* function to output a word */ CSTATUS BspGetCarrierAddress(int nHandle, long* pAddress); CSTATUS BspSetCarrierAddress(int nHandle, long lAddress); CSTATUS BspEnableInterrupts(int nHandle); CSTATUS BspDisableInterrupts(int nHandle); CSTATUS BspSetInterruptHandler(int nHandle, char chSlot, int nRequestNumber, int nVector, void(*pHandler)(void*), void* pData); CSTATUS BspSetInterruptLevel(int nHandle, word uLevel); CSTATUS BspGetInterruptLevel(int nHandle, word* pLevel); CSTATUS BspSetMemoryAddress(int nHandle, long lAddress); CSTATUS BspGetMemoryAddress(int nHandle, long* pAddress);