Мною был написан драйвер для ISA устройства .
Драйвер работает , но есть одна проблема .
Простенькая программа читает данные из драйвера , но обновляются данные только если разкомментировать freopen();
Код: Выделить всё
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
char name[]="/proc/ISA_TIME";
char str[]="day 000 run 00 hour 00 min 00 sec 00 msec 0000 irq 0 \n ";
FILE * dfd;
unsigned int uistrlen;
int main(void){
uistrlen=strlen(str);
dfd=fopen(name,"r");
if(dfd==NULL){
printf("open device error\n");
exit(0);
};
while(1){
sprintf(str,"day 000 run 00 hour 00 min 00 sec 00 msec 0000 irq 0 ");
fgets(str,uistrlen,dfd);
//freopen(name,"r",dfd);
fseek(dfd,0,SEEK_SET);
printf("%s\n",str);
usleep(100000);
};
fclose(dfd);
return(0);
}
строка обновляется по прерыванию от устройства .
Код: Выделить всё
static irqreturn_t ISATIME_irq_handler(int irq,void *dev_id){
set3=inw(0x326);
irqgen=set3>>12;
if(irqgen>0){
set0=inw(0x320);
set1=inw(0x322);
set2=inw(0x324);
den=((set0>>14)&0x3)*100+((set0>>10)&0xf)*10+((set0>>6)&0xf);
tmp=((set0&0x3)<<2)|((set1>>14)&0x3);
chas=tmp+((set0>>2)&0x3)*10;
min=((set1>>10)&0x7)*10+((set1>>6)&0xf);
tmp=((set1&0x3)<<2)|((set2>>14)&0x3);
sec=((set1>>2)&0x7)*10+tmp;
msec=((set2>>10)&0xf)*100+((set2>>6)&0xf)*10+((set2>>2)&0xf);
mksec=set3&0xf;
run=chas*4;
if(min<15) run=run+1;
if((min>=15)&(min< 30))run=run+2;
if((min>=30)&(min< 45))run=run+3;
if((min>=45)&(min<=59))run=run+4;
inw(0x328);
sprintf(str,"day %03d run %02d hour %02d min %02d sec %02d msec %04d irq %1x\n",den,run,chas,min,sec,msec,irqgen);
return IRQ_HANDLED;
}else{
return IRQ_NONE;
};
}
Код: Выделить всё
static ssize_t proc_node_read(char *buffer,char **start,off_t off,int count,int *eof,void *data){
static int offset=0,i;
//printk( KERN_INFO "read: %d\n", count );
for(i=0;(offset<=len)&&('\0'!=str[offset]);offset++,i++)
*(buffer+i)=str[offset];
*(buffer+i)='\n';
i++;
if((offset>=len)||('\0'==str[offset])){
offset=0;
*eof=1;
}else{
*eof=0;
};
//printk( KERN_INFO "return bytes: %d\n", i );
//if(*eof!=0)printk(KERN_INFO "EOF\n");
return i;
};
хотя пробовал и такой :
[code]
static ssize_t device_read(struct file * file,char * buf,size_t count,loff_t *ppos){
if(count<len)return -EINVAL;
if(*ppos!=0){return 0;};
if(copy_to_user((void*)buf,str,len))return -EINVAL;
//printk("ISA module : copy to user Ok\n");
*ppos=len+1;
//*ppos=0;
returned=count;
return returned;
}
результат одинаковый .