📄 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 + -