Nios® V/II Embedded Design Suite (EDS)
Support for Embedded Development Tools, Processors (SoCs and Nios® V/II processor), Embedded Development Suites (EDSs), Boot and Configuration, Operating Systems, C and C++
12602 Discussions

Linux with MMU acessing registers

Altera_Forum
Honored Contributor II
1,308 Views

Hello i need to acess my registers from userspace, i am developing a 

critical timing application and i can't consider the time needed to 

call the device driver and read my timestamp register. 

I need to read my timestamp register from userspace, how can i do 

that? I know that 0x8 is for uncached, therefore peripherals adresses 

will have the 8 in the adress. 

 

I am trying to use inl(0x000024e0 (my adress), 0); 

however i get a segmentation fault... i tried to include io.h but with no sucess 

# define inl(addr)  

({  

unsigned int __res; 

__asm__ __volatile__(  

"ldwio %0, 0(%1)"  

: "=r"(__res)  

: "r" (addr));  

__res;  

}) 

 

//----------------------------------------------------------------------- 

# define inb(addr)  

({  

unsigned int __res; 

__asm__ __volatile__(  

"ldbio %0, 0(%1)"  

: "=r"(__res)  

: "r" (addr));  

__res;  

}) 

 

//----------------------------------------------------------------------- 

# define outl(b,addr)  

({  

__asm__ __volatile__(  

"stwio %0, 0(%1)"  

: : "r"(, "r" (addr));  

}) 

 

//----------------------------------------------------------------------- 

# define outw(b,addr)  

({  

__asm__ __volatile__(  

"sthio %0, 0(%1)"  

: : "r"(, "r" (addr));  

}) 

 

//----------------------------------------------------------------------- 

# define outb(b,addr)  

({  

__asm__ __volatile__(  

"stbio %0, 0(%1)"  

: : "r"(, "r" (addr));  

})
0 Kudos
4 Replies
Altera_Forum
Honored Contributor II
434 Views

Please don't cross-post between the mailing list and the nios2-dev list. Or if you do so, please at least link put a link to the other, so people searching for answers to the same or similar questions can find it in the other place too. 

 

As already stated on nios2-dev, this won't work (for obvious reasons). Please see http://article.gmane.org/gmane.linux.uclinux.nios2.devel/189 for the full answer.
0 Kudos
Altera_Forum
Honored Contributor II
434 Views

Okay, is there any easy way to acess the list archive?

0 Kudos
Altera_Forum
Honored Contributor II
434 Views

Yes, there is. Either the mailman archive at http://sopc.et.ntust.edu.tw/pipermail/nios2-dev/ or at gmane (only massages since around beginning of june 2011): http://news.gmane.org/gmane.linux.uclinux.nios2.devel

0 Kudos
Altera_Forum
Honored Contributor II
434 Views

This is my final code 

 

 

memfd = open("/dev/mem", O_RDWR | O_SYNC ); 

if (memfd < 0) 

log_msg("Cannot open /dev/mem\n"); 

exit(1); 

pgoff = (unsigned int) (MENOS_BASE & (sysconf(_SC_PAGE_SIZE)-1)); 

map_len = 16 + pgoff; 

mapped = mmap(NULL, map_len, (PROT_READ | PROT_WRITE), 

MAP_SHARED, memfd, MENOS_BASE - pgoff); 

 

if (mapped == MAP_FAILED ) 

log_msg("Cannot map registers\n"); 

ts_my = mapped + pgoff; 

 

 

inl(ts_my);
0 Kudos
Reply