📄 ul_drv.h
字号:
/******************************************************************* uLan Communication - uL_DRV - multiplatform uLan driver ul_drv.h - driver definitions and types (C) Copyright 1996-2004 by Pavel Pisa - project originator http://cmp.felk.cvut.cz/~pisa (C) Copyright 1996-2004 PiKRON Ltd. http://www.pikron.com (C) Copyright 2002-2004 Petr Smolik The uLan driver project can be used and distributed in compliance with any of next licenses - GPL - GNU Public License See file COPYING for details. - LGPL - Lesser GNU Public License - MPL - Mozilla Public License - and other licenses added by project originator Code can be modified and re-distributed under any combination of the above listed licenses. If contributor does not agree with some of the licenses, he/she can delete appropriate line. WARNING: if you delete all lines, you are not allowed to distribute code or sources in any form. *******************************************************************/#ifndef _LINUX_UL_DRV_H#define _LINUX_UL_DRV_H#define UL_DRV_VERSION "0.7.2"#define UL_DRV_VERCODE 0x000702#if !defined(_WIN32)||defined(__GNUC__) #ifndef INLINE #define INLINE extern inline #endif#else #ifndef INLINE #define INLINE _inline #endif#endif#ifndef uchar #define uchar unsigned char#endif/* Transfer controll byte with B8=1 */#define UL_ERR 0x17F#define UL_ARQ 0x17A#define UL_PRQ 0x179#define UL_AAP 0x176#define UL_BEG 0x175#define UL_END 0x17C/* Transfer acknowledge byte with B8=0 */#define UL_ACK 0x19#define UL_NAK 0x7F#define UL_WAK 0x25/* Memory structures */#define UL_BLK_SIZE 64#define UL_BLK_FSIZE (UL_BLK_SIZE-sizeof(ul_mess_head))#define UL_BLK_FDATA(mem_blk) (mem_blk->blk.head.fdata)#define UL_BLK_NDATA(mem_blk) (mem_blk->blk.ndata)#define UL_BLK_HEAD(mem_blk) (mem_blk->blk.head)/* ul_mess_head flags definition defines proccessing of message or its frames stored in bll */#define UL_BFL_LOCK 0x8000 /* locked message is pointed only once */#define UL_BFL_MSST 0x4000 /* Message must be received by some proccess */#define UL_BFL_M2IN 0x2000 /* After succesfull proccessing move to proc_bll */#define UL_BFL_LNMM 0x1000 /* Length of received frame must match expected len */#define UL_BFL_FAIL 0x0800 /* Message cannot be proccessed - error */#define UL_BFL_TAIL 0x0400 /* Multiframe message continues by next bll block */#define UL_BFL_SND 0x0200 /* Send this frame */#define UL_BFL_REC 0x0100 /* Receive answer frame into this bll block */#define UL_BFL_VERL 0x0040 /* Verify free space in buffer of destination station */#define UL_BFL_NORE 0x0020 /* Do not try to repeat if error occurs */#define UL_BFL_REWA 0x0010 /* If error occurs do wait with retry */#define UL_BFL_PRQ 0x0002 /* Request imediate proccessing of frame by receiver station */#define UL_BFL_ARQ 0x0001 /* Request imediate acknowledge by receiving station *//* error handling */#define UL_RETRY_CNT 4 /* number of retries of messages */typedef struct ul_mess_head { /* head of frame */ struct ul_mem_blk *next;/* BLL of frames */ struct ul_mem_blk *prev; struct ul_blk_bll *bll; /* BLL in which is head */ int ref_cnt; /* usage count */ unsigned flg; /* frame flags */ unsigned len; /* length of message in bytes */ uchar cmd; /* command or service */ uchar dadr; /* destination address */ uchar sadr; /* source address */ uchar retry_cnt; /* actual number of retries */ unsigned stamp; /* unigue message number */ uchar fdata[0]; /* data in first block */} ul_mess_head;typedef struct ul_mem_blk { struct ul_mem_blk *next; /* next relating memory block */ union { ul_mess_head head; uchar ndata[UL_BLK_SIZE]; } blk;} ul_mem_blk;typedef struct ul_blk_bll { /* bidir linked list of frames */ ul_mem_blk *first; ul_mem_blk *last; int cnt; struct ul_drv *udrv; /* owener of bll list */} ul_blk_bll;/* Data iterator structure */typedef struct ul_data_it { ul_mem_blk *blk; /* actual proccessed memory block */ uchar *ptr; /* pointer to actual data byte */ int pos; /* actual position for seek operations */ ul_mem_blk *head_blk; /* first memory block of message */ int trans_len; /* for send/rec routines */} ul_data_it;INLINE void ul_di_init(ul_data_it *di,ul_mem_blk *head_blk){ di->blk=di->head_blk=head_blk; di->pos=0; di->ptr=UL_BLK_HEAD(head_blk).fdata;};INLINE void ul_di_inc(ul_data_it *di){ di->ptr++; di->pos++;};INLINE void ul_di_add(ul_data_it *di,int len){ di->ptr+=len; di->pos+=len;};INLINE int ul_di_adjust(ul_data_it *di){ int offs; while((offs=di->ptr-UL_BLK_NDATA(di->blk)-UL_BLK_SIZE)>=0) { if(!di->blk->next) return 0; di->blk=di->blk->next; di->ptr=UL_BLK_NDATA(di->blk)+offs; }; return 1;};INLINE uchar *ul_di_byte(ul_data_it *di){ return di->ptr;};INLINE int ul_di_atonce(ul_data_it *di){ return UL_BLK_SIZE-(di->ptr-UL_BLK_NDATA(di->blk));};/* Chip driver ctrl functions */#define UL_CC_DIN 1 /* switch off line transmitter */#define UL_CC_DOUT 2 /* switch on line transmitter */#define UL_CC_PINIT 3 /* initialize ports */#define UL_CC_PDONE 4 /* deinitialize ports */#define UL_CC_GENIRQ 5 /* generate irq for irq_probe */#define UL_CC_RQIRQ 6 /* request IRQ handling */#define UL_CC_FREEIRQ 7 /* release IRQ handling */#define UL_CC_HWTEST 8 /* hardware testings */#define UL_CC_SETMYADR 9 /* station address changed *//* driver subfunctions return codes */#define UL_RC_WIRQ 0 /* process fnc_act at next IRQ */#define UL_RC_PROC 1 /* imediately proccess fnc_act */#define UL_RC_ACTIVATE 2 /* timeout or stroke activation */#define UL_RC_FREEMSG 3 /* free message after receive processing */#define UL_RC_EFRAME -1 /* received char frame error */#define UL_RC_ETIMEOUT -2 /* wait for char timeout */#define UL_RC_EBADCHR -3 /* bad character received */#define UL_RC_EARBIT -4 /* connect arbit. proc. lose */#define UL_RC_ENOFNC -5 /* bad function code */#define UL_RC_EPORT -6 /* port access error */#define UL_RC_ENAK -7 /* slave sends NAK */#define UL_RC_EWAK -8 /* slave bussy now and sends WAK */#define UL_RC_EREPLY -9 /* bad reply from slave */#define UL_RC_ERECBEG -10 /* bad char received */#define UL_RC_ERECADR -11 /* bad address in imediate reply */#define UL_RC_ERECEND -12 /* bad char or xorsum received */#define UL_RC_ERECPROT -13 /* nonrecoverable protocol error */#define UL_RC_ENOMEM -14 /* no memory for data */#define UL_RC_ENOTAIL -15 /* no frame tail when flag set */#define UL_RC_EPRMESS -16 /* message processor error */#define UL_RC_EKWT -17 /* error related to kernel worker thread*//* uLan driver flags stored in ul_drv.flags */#ifndef _WIN32#define UL_DFL_CHIPOK 0x10 /* chip driver initialized OK */#define UL_DFLB_CHIPOK 4 /* bit num. */#define UL_DFL_IN_ISR 0x20 /* some CPU is running in ISR */#define UL_DFLB_IN_ISR 5 /* bit num. */#define UL_DFL_ASK_ISR 0x40 /* some CPU likes but can't get ISR */#define UL_DFLB_ASK_ISR 6 /* bit num. */#define UL_DFL_NACTIV 0x80 /* no activity of driver - timeout ? */#define UL_DFLB_NACTIV 7 /* bit num. */#define UL_DFL_IN_BOTTOM 0x100 /* some CPU is running in ulan_do_bh */#define UL_DFLB_IN_BOTTOM 8 /* bit num. */#define UL_DFL_ASK_BOTTOM 0x200 /* request for ulan_do_bh */#define UL_DFLB_ASK_BOTTOM 9 /* bit num. */#define UL_DFL_CHECK_FILT 0x400 /* check filters for UL_OPST_FILTNEW */#define UL_DFLB_CHECK_FILT 10 /* bit num. */#define UL_DFL_WDSCHED 0x800 /* SCHEDULE_UDRV_WDTIM expires */#define UL_DFLB_WDSCHED 11 /* bit num. */#define UL_DFL_KWTRUN 0x1000 /* kernel worker thread running */#define UL_DFLB_KWTRUN 12 /* bit num. */#define UL_DFL_KWTKILL 0x2000 /* stop kernel worker thread */#define UL_DFLB_KWTKILL 13 /* bit num. */#define UL_DFL_WDFORCED 0x4000 /* forced ativation of timeout */#define UL_DFLB_WDFORCED 14 /* bit num. */#endif /* _WIN32 *//* Driver controll structure */#define UL_DRV_MAGIC 0x754c1122typedef int(ul_call_fnc)(struct ul_drv *udrv, int ret_code);struct ul_opdata;struct ul_bottom;struct ul_iac_chain;typedef struct ul_drv { int magic; /* magic number */ /*** parameters used by chip driver ***/ #ifndef _WIN32 volatile unsigned long flags; /* flags */ #else /* _WIN32 */ PDEVICE_OBJECT DeviceObject; /* Functional Device Object for WDM */ PKINTERRUPT InterruptObject; KIRQL Irql; LONG flag_IN_ISR; /* some CPU is running in ISR */ LONG flag_NACTIV; /* no activity of driver - timeout ? */ volatile LONG flag_ASK_ISR; /* some CPU likes but can't get ISR */ volatile LONG flag_CHIPOK; /* chip driver initialized OK */ BOOLEAN MappedPorts; /* Ports mapped into memory space */ #endif /* _WIN32 */ long port; /* base port number */ int irq; /* irq number */ int baud_div; /* used baud divisor */ int baud_val; /* selected speed */ long baud_base; /* XTAL base clocks */ int chip_options; /* additional chip minor diferences */ void *chip_info; /* additional info for chip */ /*** function sequencer ***/ ul_call_fnc *fnc_act; /* actual state call function */ ul_call_fnc *fnc_stack[10]; /* stack of interupted calls */ ul_call_fnc **fnc_sp; /* pointer into stack */ ul_call_fnc *fnc_recch; /* character receive function */ ul_call_fnc *fnc_sndch; /* character send function */ ul_call_fnc *fnc_wait; /* waits for time or receive */ ul_call_fnc *fnc_connect;/* connect to line */ int (*fnc_pool)(struct ul_drv *udrv);/* test interrupt flags state */ int (*fnc_cctrl)(struct ul_drv *udrv,int ctrl_fnc,int param);/* chip drv ctrl */ int (*fnc_stroke)(struct ul_drv *udrv);/* stroke for nonstandard targets */ unsigned char_buff; /* rec/snd char buffer */ unsigned wait_time; /* time limit for fnc_wait */ unsigned xor_sum; /* xor+1 checksum */ unsigned last_ctrl; /* last snd/rec controll char */ unsigned chip_temp; /* temporary variable for chip driver */ unsigned chip_buff[6]; /* buffer for chip driver */ /*** message and frame proccessor ***/ int (*fnc_timeout)(struct ul_drv *udrv);/* timeout or error function */ ul_mem_blk *con_message;/* proccessed message chain */ ul_mem_blk *con_frame; /* actual proccessed frame */ uchar my_adr; /* addres of this computer */ uchar con_dadr; /* connection destination address */ uchar con_sadr; /* connection sender address */ uchar con_cmd; /* connection command */ uchar con_flg; /* connection frame flags */ ul_data_it con_di; /* data iterator for transmit/receive */ /*** memory management ***/ void *mem_ptr; /* pointer to allocated memory */ ul_mem_blk *free_blk; /* single linked list of free blks */ int free_blk_cnt; /* number of block on free list */ ul_blk_bll prep_bll; /* list of frames prepared for output */ ul_blk_bll work_bll; /* list for receive operation */ ul_blk_bll proc_bll; /* list of proccessed frames */ ul_blk_bll opan_bll; /* list of announced frames */ /*** operators - clients ***/ struct ul_opdata *operators; /* double linked list of clients */ /*** kernel integration ***/ struct ul_drv *next_chan; /* used for multichanel PCI and PnP devices */ /*** immediately action commands ***/ #ifdef UL_WITH_IAC struct ul_iac_chain *iac_chain; struct ul_iac_chain *iac_act; int iac_ret_code; #endif /* UL_WITH_IAC */ #ifdef KERNEL struct kc_tasklet_struct bottom; /* deferring of time consumptive tasks */ struct timer_list wd_timer; /* link protecting timeout timer */ #ifdef UL_WITH_DEVFS kc_devfs_handle_t devfs_handle; /* for devfs */ #endif /* UL_WITH_DEVFS */ struct pci_dev *dev; /* kernel PCI device information */ wait_queue_head_t kwt_wq; /* wait queue for kernel worker thread */ #elif defined(_WIN32) LONG flag_IN_BOTTOM; /* some CPU is running in bottom Dpc */ LONG flag_ASK_BOTTOM; /* need to run of bottom Dpc */ LONG flag_CHECK_FILT; /* check for UL_OPST_FILTNEW */ LONG flag_KWTKILL; /* stop kernel worker thread */ LONG flag_WDFORCED; /* forced watchdog activation */ KDPC bottom_dpc; KDPC wd_timer_dpc; KTIMER wd_timer; HANDLE kwt; /* thread */ KEVENT kwt_wake; /* event for wakeup kwt */ KEVENT kwt_stopped; /* event for wakeup kwt */ int usb_bus; /* set for usb bus */ #ifdef FOR_WIN_WDM void *dev; /* kernel USB device information */ UNICODE_STRING ntdev_name; /* NT Device Name */ UNICODE_STRING link_name; /* DOS Link Name */ PDEVICE_OBJECT PhysicalDeviceObject; PDEVICE_OBJECT DeviceToSendIrpsTo; ULONG State; /* State for PnP Purposes */ LONG OutstandingIO; /* Number of unfinished IRPs */ KEVENT RemoveEvent; /* Set when no PnP IRP pending */ ULONG InterruptAffinity; ULONG InterruptMode; /*LONG flag_INITIALIZED;*/ /* DriverObject already initialized */ #endif /* FOR_WIN_WDM */ #ifdef UL_WITH_WIN_PWR DEVICE_CAPABILITIES DeviceCapabilities; DEVICE_POWER_STATE CurrentDevicePowerState; BOOLEAN EnabledForWakeup; ULONG PowerDownLevel; PIRP PowerIrp; BOOLEAN SelfPowerIrp; BOOLEAN SystemPowerStatePending; KEVENT SelfRequestedPowerIrpEvent; #endif /* UL_WITH_WIN_PWR */ #else long int wd_timer_expires; /* helper variable for odd systems */ #endif} ul_drv;#define UL_FNEXT(FNEXT) do{udrv->fnc_act=&FNEXT;}while(0)#define UL_FCALL(FCALL) do{*(udrv->fnc_sp++)=udrv->fnc_act;\ udrv->fnc_act=&FCALL;}while(0)#define UL_FCALL2(FCALL,FNEXT) \ do{*(udrv->fnc_sp++)=FNEXT;\ udrv->fnc_act=&FCALL;}while(0)#define UL_FRET do{udrv->fnc_act=*(--udrv->fnc_sp);}while(0)#endif /* _LINUX_UL_DRV_H */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -