内容:
(一)设计方案
首先,为开发板编写ADC接口的驱动程序,使开发板自带的三路ADC接口可以像普通文件那样被打开、读、写、关闭。
然后,编写一个 server 端程序和client端程序,使其可以运行在开发板上,选择合适的通信协议族,使得该 server 程序可以接收远程 client的访问(即,client 向server发出的关于server端当前某一路ADC数据的查询)并能返回ADC的读数。
最后,可以在PC机上运行client程序访问开发板上的ADC接口的数据。
(二)设计内容和要求
(1)ADC接口驱动程序
1定义驱动接口结构体。要求实现 open, write, read, close 等ADC设备功能。
2编写驱动程序的 makefile 文件,使 ADC 接口能以模块的形式加载到kernel。
3可以读指定 ADC 接口(ARM2410提供0-2三个可调节ADC接口)。
(2)开发板端server 程序
1server程序要能open ADC设备,像操作文件那样。
2建立inet connection,等待远程client 的访问。
3编写client端程序。Client通过发送指定字符串来表示查询server 上那个ADC的读数,例如,发送”adc0”、 “adc1”、“adc2” 时分别表示预读取server端(开发板)编号为0、1、2的ADC接口。
4Server 端识别client的具体请求,返回相应的读数。在此基础上,建议实现client对server的另一种查询方式:查询开发板上某个ADC接口近30秒钟内读数的平均值(提示:修改server程序)。
5编写server端和client端程序的makefile文件。
实现方法:
(一)ADC驱动程序
1、ADC驱动程序的设计思路
(1)定义驱动接口结构体,实现open, write, read, close 等ADC设备功能。
(2)编写驱动程序的makefile 文件,使 ADC 接口能以模块的形式加载到 kernel。
(3)可以读指定ADC 接口。(ARM2410提供0-2三个可调节ADC接口)
2、具体程序如下
(1) s3c2410-adc.c(使用开发板自带的程序)
#include<linux/config.h>
#include<linux/module.h>
#include<linux/kernel.h>
#include<linux/init.h>
#include<linux/sched.h>
#include<linux/irq.h>
#include<linux/delay.h>
#include<asm/hardware.h>
#include<asm/semaphore.h>
#include<asm/uaccess.h>
#include"s3c2410-adc.h"
#undefDEBUG
//#defineDEBUG
#ifdefDEBUG
#define DPRINTK(x...){printk(__FUNCTION__"(%d): ",__LINE__);printk(##x);}
#else
#defineDPRINTK(x...) (void)(0)
#endif
#defineDEVICE_NAME "s3c2410-adc"
#defineADCRAW_MINOR 1
staticint adcMajor = 0;
typedefstruct {
struct semaphore lock;
wait_queue_head_twait;
int channel;
intprescale;
}ADC_DEV;
staticADC_DEV adcdev;
#define START_ADC_AIN(ch,prescale) \
do{\
ADCCON= PRESCALE_EN | PRSCVL(prescale) | ADC_INPUT((ch)) ; \
ADCCON|= ADC_START; \
}while(0)
staticvoid adcdone_int_handler(int irq, void *dev_id, struct pt_regs *reg){
wake_up(&adcdev.wait);
}
//ADC驱动程序中open, close,read和write方法的实现
static ssize_ts3c2410_adc_write(struct file *file, const char *buffer, size_t count, loff_t *ppos){
int data;
if(count!=sizeof(data)){
//errorinput data size
DPRINTK("the size of input data must be %d\n", sizeof(data));
return0;
}