?? zjmdmdrv.h
字號:
/*****************************************
*FileName : zjmdmdrv.h
*Description:Character device drive for zj-modem
*Version:1.0.0
*Author:XieHongwei
*Date:2002-04-26
*****************************************/
#ifndef ZJMDMDRV_H
#define ZJMDMDRV_H
/************ Define port *****************/
#define DATAPORT0 0x210
#define DATAPORT1 0x211
#define DATAPORT2 0x212
#define DATAPORT3 0x213
#define DATAPORT4 0x214
#define DATAPORT5 0x215
#define DATAPORT6 0x216
#define DATAPORT7 0x217
#define STATPORT0 0x218
#define STATPORT1 0x219
#define STATPORT2 0x21A
#define STATPORT3 0x21B
#define STATPORT4 0x21C
#define STATPORT5 0x21D
#define STATPORT6 0x21E
#define STATPORT7 0x21F
#define IOPORTBASE DATAPORT0
#define PORT_RANGE 16
/************ Modem protocol cmd ****************/
#define CMD_CONNECT 0xc1 //建立連接
#define CMD_DISCONN 0xc2 //掛機
#define CMD_CALLOUT 0xc3 //撥號
#define CMD_CONN_SUCCESS 0xc4 //連接成功
#define CMD_CONN_BUSY 0xc5 //占線
#define CMD_CONN_FAIL 0xc6 //連接失敗
#define CMD_OPEN_CHL 0xc7 //開啟通道
#define CMD_SHUT_CHL 0xc8 //關閉通道
#define CMD_DETECT 0x55 //上電自檢
#define CMD_FEEDBACK 0xaa //反饋自檢結果
#define CMD_QUERY_STATE 0xbb //查詢狀態
#define CMD_HANGUP_BACK 0xd0 //返回查詢的狀態:掛機
#define CMD_BRINGUP_BACK 0xd1 //返回查詢的狀態:摘機
#define CMD_REVOVER_HEAD 0x39 //糾正頭錯誤(僅driver支持)
/************ define the ioctl cmd **********/
#define IOCTL_CMD_SHUTCH 0x6b00
#define IOCTL_CMD_OPENCH 0x6b01
#define IOCTL_CMD_DISCONN 0x6b02
#define IOCTL_CMD_MAKECALL 0x6b03
#define IOCTL_CMD_GETSTAT 0x6b04
#define IOCTL_CMD_IsWriteOver 0x6b05
#define IOCTL_CMD_CmdSendOver 0x6b06
#define IOCTL_CMD_GetRdableCH 0x6b07
#define IOCTL_CMD_CORRECTTIME 0x6b08 //糾正系統時間
#define IOCTL_CMD_RESETCH 0x6b09
#define IOCTL_CMD_CARD_USABLE 0x6b0a
#define IOCTL_CMD_QUERY_STATE 0x6b0b
#define IOCTL_CMD_GetQueryResult 0x6b0c //得到查詢結果
#define IOCTL_CMD_RecoverHead 0x6b0d
/******************** buffer state ***************/
#define NORMAL 0
#define EMPTY -1
#define FULL -2
/************ Error code define **************/
#define NO_ERROR 0
#define E_COMMON -1 /*普通錯誤*/
#define E_ACCESS_MEMORY -2; /*訪問內存失敗*/
#define E_NONE_CARD -3 /*卡不可用*/
#define E_SEND_FAIL -4 /*發送數據失敗 */
#define E_RECV_FAIL -5 /*接收數據失敗*/
#define E_SEND_CMD_FAIL -6 /*發送命令給modem時失敗*/
/************ Macro perennial define **********/
#define TRUE 1
#define FALSE 0
#define DEVICE_NAME "zjmdmdrv"
#define MAJOR 0
#define IRQ_NO 5
#define MDM_NUM 8
#define CHL_NUM 4
#define MAX_BUFF_SIZE 4000
#define MAX_CMDBUF_SIZE 128
#define MAX_DETECT_TIMES 4
#define OPT_CARD_NUM_ONE_IRQ 8 /*一次中斷處理幾塊卡*/
#define INVALID_MDMNO 0x22 /*無效的modem號*/
#define INVALID_CHLNO INVALID_MDMNO
#define INVALID_STATE 0x33 /*無效的連接狀態*/
#define MAX_FULL_TIMES 1000 //d 100000
/********* Globe perennial *****************/
const int DataPort[] =
{
DATAPORT0,DATAPORT1,DATAPORT2,DATAPORT3,
DATAPORT4,DATAPORT5,DATAPORT6,DATAPORT7,0
};
const int StatePort[] =
{
STATPORT0,STATPORT1,STATPORT2,STATPORT3,
STATPORT4,STATPORT5,STATPORT6,STATPORT7,0
};
/******** myself date type *****************/
#define BOOL int
#define ERRNO int
struct ChannelDesc
{
u8 mdm_no;
u8 chl_no;
BOOL be_open; //是否已經開啟
BOOL connect; //是否建立連接
char connect_state; //通道連接狀態
char hangup_state; //掛機狀態
/* 各個通道有獨立的讀緩沖*/
char read_buf[MAX_BUFF_SIZE];
u32 rbuf_readpos;
u32 rbuf_writepos;
u32 readable_len; //本通道已經從卡收收到數據的長度
u64 rbuf_max_full_times; //讀緩沖最多能滿的次數,超過指定的值就自動清空
/* 各個通道有獨立的寫緩沖*/
char write_buf[MAX_BUFF_SIZE];
u32 wbuf_readpos;
u32 wbuf_writepos;
u32 writeable_len; //可以發送的數據長度
u16 wbytes_once; //一次發送的字節數
u16 pause_time; //暫停時間(毫秒)
u16 wbytes_after_pause; //暫停后發送的字節數
BOOL wtimer_started; //寫數據的定時器是否開啟
u64 wtimer_start_time; //定時器啟動時間
wait_queue_head_t wait_queue_r; //讀等待隊列
wait_queue_head_t wait_queue_w; //寫等待隊列
u64 wbuf_max_full_times; //寫緩沖最多能滿的次數,超過指定的值就自動清空
};
struct MdmDesc
{
u8 mdm_no;
unsigned int f_flags; //文件打開標志
atomic_t writed_head; //剛寫完數據頭
BOOL writed_head_flag; //寫數據頭標志
atomic_t expect_read_head; //希望讀到數據頭,為FALSE時表示希望讀到數據
atomic_t is_data_head; //最后一次讀到的頭是數據頭,非狀態頭
char head_at_last; //最后一次讀到的頭保存在此
u8 next_write_chl_id; //下一次要發送的通道號
/*命令數據緩沖*/
char cmd_buf[MAX_CMDBUF_SIZE];
u32 cbuf_readpos;
u32 cbuf_writepos;
u32 cmdable_len; //可以發送的命令長度
wait_queue_head_t wait_queue_cmd; //等待命令發完的等待隊列
struct semaphore cmd_sending_sem; //發送命令的信號量
struct ChannelDesc ch_desc[CHL_NUM];
};
/*********** Globe variable ***************/
static int Major;
u8 g_MdmNum; //可用modem數目
u8 g_MdmNO[MDM_NUM]; //依次記錄可用modem卡的編號
u8 g_CurReadCardCount; //當前讀操作的卡號計數
u8 g_CurWriteCardCount; //當前寫操作的卡號計數
struct MdmDesc *gp_MdmDesc[MDM_NUM];
char *gp_mdm_res;
#ifdef _DEBUG
u64 amount_recv_bytes,amount_send_bytes,no_read_data,
max_no_read_data,rbuf_full_times;
BOOL recv_first_data,head_err;
#endif
void TastletRoutine(unsigned long arg);
#endif
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -