Hi,
Last week, I have sent a request concerning an ioremap problem.
With the answers of Stephen Cohen I have change parts of my
source and I have obtain a result.
I can resume my problem like this : I use a PCI acquisition board
for a weather experiment project. This board has onboard two
memories : one is call DPRAM and this other on is LOOKUP.
This two memories are read write and can be accessed via the
pci bus. With a small module and a test program I try to fill the 2
memories and read back them to be sure every thing is correct.
Before last thursday I was only able to pass the test for the DPRAM.
When I tried to read the value from the LOOKUP I collected for the
whole memory only the last value written. After a reboot on thursday
afternoon I was able to pass the test for both memory. But with a new
reboot the problem appeared again and now it still there.
I have test the same code with a other pc and a other acquisition board
without success.
I do something wrong or I forget something but I don't know what.
I add the code of my module and the small test program to this mail
If someone is able to help me it will be great !!!
Thanks a lot
Fred
//////////MODULE
#include <linux/errno.h>
#include <rtl.h>
#include <time.h>
#include <string.h>
#include <linux/pci.h>
#include <linux/ioport.h>
#include <asm/io.h>
#include <mbuff.h>
#include <rtl_sched.h>
#include <rtl_fifo.h>
#include "globals.h"
#include "dialog.h"
pthread_t thread;
#define PIRAQ_VENDOR 0x10E8
#define PIRAQ_ID 0x5920
#define PIRAQ_DEVICE 0xB102
#define OFFSET_DPRAM 0x10000
#define FIFO_CMD 1
#define FIFO_RESULT 2
unsigned char state=0;
unsigned int *PII_DPRAM;
unsigned short *STATUS;
unsigned int *TIMER;
unsigned int *LOOKUP;
unsigned char result;
u32 *shm;
int init_piraq(void)
{
u32 val;
struct pci_dev * dev = NULL;
printk("\nStarting Real Time Piraq II module\n");
dev = pci_find_device(PIRAQ_VENDOR,PIRAQ_ID, dev);
if (dev == NULL) {
printk("No Piraq board installed\n");
return (-1);
}
pci_read_config_dword (dev,0x14,&val);
PII_DPRAM = ioremap(val,(u32)0x20000);
#ifdef DEBUG
printk("@DPRAM = 0x%x %x\n",(u32)PII_DPRAM,val);
#endif
if(check_region((u32)PII_DPRAM,0x20000)) {
printk("Piraq Dpram is locked by someone else\n");
// return (-1);
}
request_region((u32)PII_DPRAM,0x20000,"PII_dpram");
pci_read_config_dword (dev,0x18,&val);
TIMER = ioremap(val,(u32)0x40);
#ifdef DEBUG
printk("@TIMER = 0x%x %x\n",(u32)TIMER,val);
#endif
if(check_region((u32)TIMER,0x40)) {
printk("Piraq Timer is locked by someone else\n");
//return (-1);
}
request_region((u32)TIMER,0x40,"PII_Timer");
pci_read_config_dword (dev,0x1C,&val);
STATUS = ioremap(val,(u32)0x02);
#ifdef DEBUG
printk("@STATUS = 0x%x %x\n",(u32)STATUS,val);
#endif
if(check_region((u32)STATUS,0x02)) {
printk("Piraq Status is locked by someone else\n");
//return (-1);
}
request_region((u32)STATUS,0x02,"PII_Status");
pci_read_config_dword (dev,0x20,&val);
LOOKUP = ioremap(val,(u32)0x40000);
#ifdef DEBUG
printk("@LOOKUP = 0x%x %x\n",(u32)LOOKUP,val);
#endif
if(check_region((u32)LOOKUP,0x40000)) {
printk("Piraq Lookup Table is locked by someone else\n");
//return (-1);
}
request_region((u32)LOOKUP,0x40000,"PII_lookup");
state = 0;
printk("Piraq II board found at 0x%lx interrupt
0x%x\n",dev->base_address[0],dev->irq);
return (0);
}
unsigned char read_mem (u32 Base)
{
Mem_RW def;
unsigned int *ptr,*mem;
int i;
#ifdef DEBUG
printk("Cmd Mem_read received\n");
#endif
ptr = shm;
memcpy (&def,(Mem_RW *)ptr,sizeof(Mem_RW));
mem = (u32 *)(Base+def.offset);
// memcpy_fromio(ptr,mem,def.size*sizeof(u32));
for(i=0;i<def.size;i++)
*ptr++ = readl(mem++);
return(SUCCESS);
}
unsigned char write_mem (u32 Base)
{
Mem_RW def;
unsigned int *ptr,*mem;
int i;
#ifdef DEBUG
printk("Cmd Mem_write received\n");
#endif
ptr = shm;
memcpy (&def,(Mem_RW *)ptr,sizeof(Mem_RW));
ptr+=sizeof(Mem_RW);
mem = (u32 *)(Base+def.offset);
// memcpy_toio(mem,ptr,def.size*sizeof(u32));
for(i=0;i<def.size;i++)
writel(*ptr++,mem++);
return(SUCCESS);
}
int read_command (unsigned int fifo)
{
unsigned int cmd;
int err;
while ((err = rtf_get(FIFO_CMD,&cmd,sizeof(unsigned int))) ==
sizeof(unsigned int)) {
switch ( cmd ) {
case RDPRAM : result = read_mem ((u32)PII_DPRAM);
break;
case WDPRAM : result = write_mem ((u32)PII_DPRAM);
break;
case RLOOKUP : result = read_mem ((u32) LOOKUP);
break;
case WLOOKUP : result = write_mem ((u32) LOOKUP);
break;
default :
#ifdef DEBUG
printk("Status CMD unknown\n");
#endif
result = -BADCMD;
break;
}
if ( (cmd != DSPSTART) && (cmd != RCONFIG) )
rtf_put(FIFO_RESULT,&result,sizeof(unsigned char));
}
return(0);
}
int init_module(void)
{
int ret;
rtf_destroy(FIFO_CMD);
if ((ret = rtf_create(FIFO_CMD,4000)) != 0){
printk (" Cannot allocate FIFO_CMD \n");
return (-1);
}
rtf_destroy(FIFO_RESULT);
if ((ret = rtf_create(FIFO_RESULT, 4000)) != 0 ) {
printk (" Cannot allocate FIFO_USER \n");
return (-1);
}
rtf_create_handler(FIFO_CMD, &read_command);
//allocate 10M of share memory
shm =(u32 *) mbuff_alloc ("SHMEM",1024 * 1024 * 10);
return (init_piraq());
}
void cleanup_module(void)
{
#ifdef DEBUG
printk("rtf_destroy = %d\n", rtf_destroy(1));
#else
rtf_destroy(1);
#endif
mbuff_free("SHMEM",(void *)shm);
release_region((u32)LOOKUP,0x40000);
release_region((u32)PII_DPRAM,0x20000);
release_region((u32)TIMER,0x40);
release_region((u32)STATUS,0x02);
printk("Piraq II module has been removed\n");
}
////TEST
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <sys/time.h>
#include <sys/types.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/ioctl.h>
#include <mbuff.h>
#include "dialog.h"
#define IVALUE(a) ((a) * 0x52384745)
int memtest(char mem, int offset, int size, char *str)
{
// offset and size are in bytes
int fd0,fd2;
unsigned int cmd;
Mem_RW ram;
int i;
int success;
unsigned int *shm,*ptr;
unsigned char result;
// shm =(unsigned int *) mbuff_alloc ("SHMEM",1024 * 1024 * 10);
shm =(unsigned int *) mbuff_attach ("SHMEM",1024 * 1024 * 10);
ptr= shm;
if ((fd0 = open("/dev/rtf1", O_WRONLY)) < 0) {
fprintf(stderr, "Error opening /dev/rtf8\n");
return(-1);
}
memset(shm,0,1024*1024*10);
if ((fd2 = open("/dev/rtf2", O_RDONLY)) < 0) {
fprintf(stderr, "Error opening /dev/rtf3\n");
exit(1);
}
printf ("Test %s started\n",str);
/* first determine if there is anything wrong */
/* a) write deterministic uncorrelated number to every address */
if (mem == 'D' ) cmd = WDPRAM;
else cmd = WLOOKUP;
ram.offset=offset;
ram.size= size/sizeof(int);
memcpy((Mem_RW *)ptr,&ram,sizeof(Mem_RW));
ptr+=sizeof(Mem_RW);
for (i=0;i<size/sizeof(int);i++)
*(unsigned int *)ptr++= IVALUE(i);
if ( write(fd0,&cmd,sizeof(unsigned int)) <= 0){
fprintf(stderr, "Can't send a command to RT-task 1\n");
close(fd0);
return(-1);
}
if ( read(fd2,&result,sizeof(char)) <= 0) {
fprintf(stderr, "Can't receive result\n");
close(fd2);
return(-1);
}
/* b) see if it could all be read back */
memset(shm,0,1024*1024*10);
if (mem == 'D' ) cmd = RDPRAM;
else cmd = RLOOKUP;
ram.offset=offset;
ram.size= size/sizeof(int);
ptr = shm;
memcpy((Mem_RW *)ptr,&ram,sizeof(Mem_RW));
if (write(fd0,&cmd, sizeof(unsigned int)) <= 0) {
fprintf(stderr, "Can't send a command to RT-task 2\n");
close(fd0);
return(-1);
}
if ( read(fd2,&result,sizeof(char)) <= 0) {
fprintf(stderr, "Can't receive result\n");
close(fd2);
return(-1);
}
success=1;
ptr = shm;
for (i=0;i<size/sizeof(int);i++){
if ( *(unsigned int *)ptr++ != IVALUE(i)) {
success=0;
printf ("value = %x expected = %d\n",*(unsigned int
*)ptr,IVALUE(i));
break;
}
}
printf("%s test: %s\n",str,success?"PASSED\n":"FAILED");
mbuff_free("SHMEM",(void *)shm);
close (fd0);
close(fd2);
}
int main (void) {
memtest('D',0,0x10000,"Dual Port RAM
0"); //passed
memtest('D',0x10000,0x10000,"Dual Port RAM 1");
//passed
memtest('D',0,0x20000,"Both Dual Port RAM 1 and 2"); //passed
memtest('L',0,0x40000,"Lookup
Table"); //failed
}
-- [rtl] ---
To unsubscribe:
echo "unsubscribe rtl" | mail [EMAIL PROTECTED] OR
echo "unsubscribe rtl <Your_email>" | mail [EMAIL PROTECTED]
---
For more information on Real-Time Linux see:
http://www.rtlinux.org/rtlinux/