I'm trying to put together a small driver-thing that does memory-mapped
device reads/writes.
So far it's been a learning experience - but a rewarding one :)
Up till now I've used 'synthetic IO' in the form of assignments using
internal counters etc.
As far as actual IO is concerned, memory range allocations and
chipselect assignments went well.
But doing the actual read from memory produces an 'illegal instruction'
at runtime. Compiles OK, but at runtime something's wrong...
I've tried using
data = inw(address);
and
data = *(volatile unsigned short *)HW_register;
but to no avail.
Pondering about what might generate an 'illegal instruction', i can't
but think this might be caused by the compiler somehow generating
garbage, causing the Coldfire to execute an exception. Which is caught
by the kernel, displaying "Illegal Instruction" on my terminal.
Or it could be me doing something silly!
Hmmmm...
Pointers, anyone?
Best regards,
Martin Filtenborg
-----------
Reference info:
Arcturus Networks uCdimm 5282 + uCevolution eval-board.
A fast 16-bit FIFO attached to CS2.
Stock uClinux 2.4.24 and m68k-elf-tools:
uClinux-2.4.x-2004-11-19.tar.gz
uClinux-dist-2004-05-28.tar.gz
as found on the accompanying CD.
And then of course a source code excerpt:
#include <linux/module.h>
#include <linux/kernel.h> // KERN_EMERG etc...
#include <linux/init.h>
#include <linux/fs.h>
#include <asm/coldfire.h>
#include <asm/m5272sim.h> // MCF_IPSBAR, GPTA, GPTB etc found here
//#include <asm/m5307sim.h> // To get at the CSAR, CSMR and CSCR
definitions
#include <linux/ioport.h>
#include <asm/io.h>
#include <asm/uaccess.h> // copy_to/from_user() defs found here
#include "my_drv.h"
#define MCFSIM_CSAR1 0x8c /* CS 1 Address reg (r/w) */
#define MCFSIM_CSMR1 0x90 /* CS 1 Mask reg (r/w) */
#define MCFSIM_CSCR1 0x96 /* CS 1 Control reg (r/w) */
#define MCFSIM_CSAR2 0x98 /* CS 2 Adress reg (r/w) */
#define MCFSIM_CSMR2 0x9c /* CS 2 Mask reg (r/w) */
#define MCFSIM_CSCR2 0xa2 /* CS 2 Control reg (r/w) */
#define BUFFERSIZE 10000
#define HW_register 0x20010000
#define CSAR2 *((volatile unsigned int *)(MCF_IPSBAR + MCFSIM_CSAR2 ))
#define CSMR2 *((volatile unsigned long *)(MCF_IPSBAR + MCFSIM_CSMR2 ))
#define CSCR2 *((volatile unsigned int *)(MCF_IPSBAR + MCFSIM_CSCR2 ))
<snip>
unsigned short uiblock[BUFFERSIZE];
unsigned int ui_baseval = 0;
<snip>
printk (KERN_ERR "my_dev: Grabbing mem\n");
if(check_mem_region(0x20010000,0x00010000))
{
printk(KERN_ERR " - mem occupied, aborting!\n");
return -EBUSY;
}
request_mem_region(0x20010000,0x00010000,"my_dev_mem");
printk (KERN_ERR "my_dev: Setup dev CS\n");
CSAR2 = 0x2001; // Setup memory BaseAddress
CSMR2 = 0x00000074; // BAM=0, AM=1, SD=0, UD=0,
CSCR2 = 0x01A0; // WS=0000, AA=1, PS=10(16 bit), BSTR=0, BSTW=0
<snip>
static ssize_t dev_read (struct file *file, char *buf, size_t count,
loff_t *ppos)
{
unsigned int i;
uiblock[0] = ui_baseval;
for(i=1;i<BUFFERSIZE;i++)
{
// uiblock[i] = inw(HW_register);
uiblock[i] = *(volatile unsigned short *)HW_register;
// uiblock[i] = ui_baseval+i;
}
ui_baseval+=BUFFERSIZE;
copy_to_user((unsigned short *)buf,&uiblock[0],BUFFERSIZE);
return count;
}
- and a small makefile to go with it:
ROOTDIR = /home/mf/uClinux-workspace/uClinux-dist
LINUXDIR = linux-2.4.x
TOOLDIR = /opt/uClinux-m68k-elf
include $(ROOTDIR)/vendors/config/m68knommu/config.arch
CROSS = m68k-elf-
CC = $(CROSS)gcc
CXX = $(CROSS)g++
STRIP = $(CROSS)strip
INC = $(ROOTDIR)/$(LINUXDIR)/include
MOD = my_drv
CFLAGSP = -D__KERNEL__ -DMODULE -D__linux__ -DMAGIC_ROM_PTR \
-DNO_MM -DNO_FPU -m5307 -Wa,-S -Wa,-m5307 -O1 -g \
-Wall -Wstrict-prototypes -Wno-trigraphs \
-pipe -fno-builtin -fno-strict-aliasing -fno-common -nostdinc \
-I$(TOOLDIR)/lib/gcc-lib/m68k-elf/2.95.3/include \
-I$(INC) \
-I$(ROOTDIR)/$(LINUXDIR)
all: $(MOD).o
$(MOD).o: #Makefile $(MOD).c
$(CC) $(CFLAGSP) -c $(MOD).c -o $(MOD).o
$(STRIP) -g $(MOD).o
./mtt
clean:
rm -f $(MOD).o
_______________________________________________
uClinux-dev mailing list
[email protected]
http://mailman.uclinux.org/mailman/listinfo/uclinux-dev
This message was resent by [email protected]
To unsubscribe see:
http://mailman.uclinux.org/mailman/options/uclinux-dev