LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 09-24-2014, 02:51 AM   #1
a4z
Senior Member
 
Registered: Feb 2009
Posts: 1,727

Rep: Reputation: 742Reputation: 742Reputation: 742Reputation: 742Reputation: 742Reputation: 742Reputation: 742
am335x, read and write some RTC registers


in spruh73g.pdf which is the docu of the AM335x
there are 3 scratch register mentioned, in the RTC
I wold like to access these registers,

I have written one mmap verison and one kernel module
but they do not read the same values the other version has written,
so either one, or even both, are wrong,


this is the mmap verison, redutce to the read part
Code:
/*
 * spruh73g.pdf
 * page 153, memory map
 * RTCSS 0x44E3_E000 - 0x44E3_EFFF 4KB RTC Registers
 *
 * page 3615, 20.3.5 RTC Registers
 * 60h RTC_SCRATCH0_REG Scratch 0 Register
 * 64h RTC_SCRATCH1_REG Scratch 1 Register
 * 68h RTC_SCRATCH2_REG Scratch 2 Register
 *
 */


#define MAP_SIZE 4096UL
#define RTCSSMEM 0x44E3E000

typedef struct scratchreg {
    int value [ 3 ];
} scratchreg;


int
read_scratchreg( scratchreg* sr )
{
  int fd = 0;
  void* memmap;
  void* scratch_addr;

  int offset =  0x60 ;

  fd = open("/dev/mem", O_RDWR | O_SYNC) ;
  if(fd == -1)
  {
    return -1;
  }


  memmap = mmap(0, MAP_SIZE, PROT_READ | PROT_WRITE,
                MAP_SHARED, fd, RTCSSMEM );

  if(memmap == (void *) -1)
  {
    close(fd);
    return -1;
  }

  scratch_addr = (unsigned int*)memmap + (offset );
  memcpy( &sr->value[0], scratch_addr,  sizeof(sr->value));

  munmap(memmap, MAP_SIZE)  ;
  close(fd);

  return 0;

}
these are the relevant parts from the module code


Code:
#define RTCSSMEM 0x44E3E000
#define SCRATCHREG_OFFSET 0x60
#define SCRATCHREG_SIZE 12

// in inti this happes ..
//request_mem_region( RTCSSMEM + SCRATCHREG_OFFSET, SCRATCHREG_SIZE, "scratchdev" ) ;
//scratchreg = ioremap_nocache( RTCSSMEM + SCRATCHREG_OFFSET, SCRATCHREG_SIZE) ;



static ssize_t scratchdev_read(struct file *f, char __user *buf, size_t len, loff_t *off)
{
  int i;
  u8 byte;

  if (*off >= SCRATCHREG_SIZE)
    {
      return 0 ;
    }
  if (*off + len > SCRATCHREG_SIZE)
    {
      len = SCRATCHREG_SIZE - *off;
    }
  for (i = 0; i < len; i++)
    {
      byte = ioread8((u8 *)scratchreg +  i);
      if (copy_to_user(buf + i, &byte, 1))
        {
          return -EFAULT;
        }
    }
  *off += len;

  return len;
}
If anyone can help me with this it would be great


eidt:
the mmap method behaves incorrect,
the first 2 integers get truncated after 127, the last after 64
there must be a very obvious reason what I do wrong, but what?
(the mmap write method does exactly the same but has of course the first 2 memcpy args swapped)

Last edited by a4z; 09-24-2014 at 01:46 PM. Reason: new insights
 
Old 09-25-2014, 01:46 AM   #2
a4z
Senior Member
 
Registered: Feb 2009
Posts: 1,727

Original Poster
Rep: Reputation: 742Reputation: 742Reputation: 742Reputation: 742Reputation: 742Reputation: 742Reputation: 742
in the mmap veriosn, this line is the problem
Code:
scratch_addr = (unsigned int*)memmap + (offset );
it has to be
Code:
scratch_addr = memmap + (offset );
but than -pedantic gives the warning
Quote:
warning: pointer of type 'void *' used in arithmetic
I have no idea how to get rid of the warning other than ignore it.
 
Old 09-25-2014, 10:45 AM   #3
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian, Arch
Posts: 3,774

Rep: Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081
Code:
scratch_addr = (unsigned char*)memmap + offset;
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
mmap to read and write registers crashes markcgriffiths Programming 4 09-08-2014 12:24 AM
Read/Write Gpio using direct access registers PayalG Linux - Embedded & Single-board computer 1 07-24-2014 06:40 PM
Dump SDIO commands (Buffers/blocks and registers Read/Write) lightydo Linux - Hardware 0 11-06-2012 07:42 AM
Read Write access to a iso9660 filesystem..mount a .iso image as read write ceazar123 Linux - General 2 08-26-2010 03:32 PM
Unable to write into RTC navin_karnam Linux - Laptop and Netbook 0 09-02-2008 02:34 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:31 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration