We don't *need* to, but I've seen others do that before . . .
https://github.com/wphermans/BeagleBone-GPIO/blob/master/src/gpio.c#L98 Not
my code, but I forked it. Because its a decent example how one might access
some various registers. However,in the case of that specific example, I do
not think it's particularly safe to map the whole "register base" when
working with hardware. Especially, when given code only needs todo one
thing or another . . .

Me, I prefer to do something like this . . .

#define GPIO0           (0x44E07000)
#define GPIO2           (0x481AC000)
#define GPIO_SIZE       (0x2000)

#define GPIO_DATAOUT    (0x13C)
#define GPIO_DATAIN     (0x138)

#define MA0 (1<<26)     /*gpio_0*/
#define MA1 (1<<23)     /*gpio_2*/
#define MA2 (1<<24)     /*gpio_2*/

void line_select(uint8_t asp_value)
{
        void *gpio_addr;
        unsigned int *bank0_out, *bank2_out;

        int fd = open("/dev/mem", O_RDWR);
        if(fd == -1){
                perror("/dev/mem");
                exit(1);
        }

        gpio_addr = mmap(0, GPIO_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED,
fd, GPIO0);
        if(gpio_addr == MAP_FAILED){
                perror("GPIO0");
                exit(1);
        }
        bank0_out = gpio_addr + GPIO_DATAOUT;

        gpio_addr = mmap(0, GPIO_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED,
fd, GPIO2);
        if(gpio_addr == MAP_FAILED){
                perror("GPIO2");
                exit(1);
        }
        bank2_out = gpio_addr + GPIO_DATAOUT;

        close(fd);

        (asp_value & (1 << 0)) ? (*bank0_out |= MA0) : (*bank0_out &=
~(MA0));
        (asp_value & (1 << 1)) ? (*bank2_out |= MA1) : (*bank2_out &=
~(MA1));
        (asp_value & (1 << 2)) ? (*bank2_out |= MA2) : (*bank2_out &=
~(MA2));
}

But you also need to keep in mind this code is specific for one thing, and
not some general purpose map of all the registers. Even though I'm using
this as a general purpose way to map more than one register( GPIO banks, 2
in this case).


On Thu, May 25, 2017 at 6:37 AM, <[email protected]> wrote:

> On AM335x,a register has its base address and offset. Why do we need to
> divide offset by 4 for reference ?
>
> An example from am335x sdk
> https://pastebin.com/VmZS7rME
>
> --
> For more options, visit http://beagleboard.org/discuss
> ---
> You received this message because you are subscribed to the Google Groups
> "BeagleBoard" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/beagleboard/2ba642cc-85bc-4205-9ffb-7849cad2fc92%40googlegroups.com
> <https://groups.google.com/d/msgid/beagleboard/2ba642cc-85bc-4205-9ffb-7849cad2fc92%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
For more options, visit http://beagleboard.org/discuss
--- 
You received this message because you are subscribed to the Google Groups 
"BeagleBoard" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/beagleboard/CALHSORojhe57bvN%2Bj31tF8hGjY4aXrGdJTUxBveKUgAM%3DiBxjg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to