RetroBSD

2.11BSD operating system for microcontrollers
It is currently Wed Apr 01, 2020 11:54 pm

All times are UTC




Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: GPIO Driver
PostPosted: Mon Dec 28, 2015 10:54 pm 
User avatar

Joined: Fri Mar 06, 2015 9:13 pm
Posts: 37
Location: Barcelona, SP
Simple question about gpio driver .....
We look at configured gpio's

Code:
4.4BSD-Lite build 1 compiled 2015-12-27
    root@ubuntuvm:LiteBSD/sys/compile/Whitecat.pic32
cpu: PIC32MZ2048EFM064 rev A1, 200 MHz
oscillator: system PLL div 1:6 mult x50
cache: 16/4 kbytes
real mem = 512 kbytes
avail mem = 348 kbytes
using 18 buffers containing 73728 bytes of memory
spi1 at pins sdi=RD2/sdo=RD3/sck=RD1
spi2 at pins sdi=RG7/sdo=RG8/sck=RG6
spi3 at pins sdi=RB10/sdo=RB9/sck=RB14
spi4 at pins sdi=RD11/sdo=RD0/sck=RD10
uart1 at pins rx=RF4/tx=RF5, interrupts 112/113/114, console
uart2 at pins rx=RB7/tx=RB6, interrupts 145/146/147
uart3 at pins rx=RC13/tx=RC14, interrupts 157/158/159
uart4 at pins rx=RD5/tx=RD4, interrupts 170/171/172
sd0 at port spi1, pin cs=RF3
sd1 at port spi3, pin cs=RB11 <- :) mtd1 at port spi3
gpio0 at portA, pins ----------------
gpio1 at portB, pins i-ii---i--iiiiii
gpio2 at portC, pins ----------------
gpio3 at portD, pins ----------------
gpio4 at portE, pins --------iiiiiiii
gpio5 at portF, pins ----------------
gpio6 at portG, pins ----------------
gpio7 at portH, pins ----------------
gpio8 at portJ, pins ----------------
gpio9 at portK, pins ----------------
sd0: function groups 1/1/1/1/4001/1
sd0: type SDHC, size 7761920 kbytes, speed 25 Mbit/sec
sd0a: partition type b7, sector 2, size 260096 kbytes
sd0b: partition type b7, sector 520194, size 260096 kbytes
sd0c: partition type b8, sector 1040386, size 131072 kbytes
WARNING: preposterous clock chip time -- CHECK AND RESET THE DATE!


Then used this code to blink RE0;

Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <machine/gpio.h>

void main() {

        int fd = open("/dev/porte", O_RDWR);
        ioctl(fd, GPIO_PORTE | GPIO_CONFOUT, 1<<1); /* configure porte0 as output -> porte2*/

        while(1) {

                ioctl(fd, GPIO_PORTE | GPIO_SET, 1<<1); /* set porte0 high -> set porte2 ?? */
                printf("pin on!!\n");
                usleep(100000);

                ioctl(fd, GPIO_PORTE | GPIO_CLEAR, 1<<1); /* clear porte0 -> clear porte2 ?? */
                printf("pin off!!\n");
                usleep(100000);

        }

        close(fd);

}


And RE2 is blinking :shock:, maybe i missunderstand something....

_________________
Dennis MacAlistair Ritchie (Sep.09.1941 - Oct.12.2011)


Top
 Profile  
 
 Post subject: Re: GPIO Driver
PostPosted: Tue Dec 29, 2015 11:06 am 
Committer
User avatar

Joined: Thu Oct 11, 2012 8:45 am
Posts: 1801
Location: Room 217, Floor 8, Arm 8, Wheel S7, Mars Base Alpha 3
Here's a hint: 1<<1 == 2.

_________________
Why not visit my shop? http://majenko.co.uk/catalog
Universal IDE: http://uecide.org
"I was trying to find out if it was possible to only eat one Jaffa Cake. I had to abandon the experiment because I ran out of Jaffa Cakes".


Top
 Profile  
 
 Post subject: Re: GPIO Driver
PostPosted: Tue Dec 29, 2015 7:23 pm 
User avatar

Joined: Fri Mar 06, 2015 9:13 pm
Posts: 37
Location: Barcelona, SP
majenko wrote:
Here's a hint: 1<<1 == 2.


Yes, but i follow this

https://github.com/sergev/LiteBSD/wiki/General-Purpose-IO-Driver
at the end of the page, I will look into the driver...

_________________
Dennis MacAlistair Ritchie (Sep.09.1941 - Oct.12.2011)


Top
 Profile  
 
 Post subject: Re: GPIO Driver
PostPosted: Tue Dec 29, 2015 7:47 pm 
Committer
User avatar

Joined: Thu Oct 11, 2012 8:45 am
Posts: 1801
Location: Room 217, Floor 8, Arm 8, Wheel S7, Mars Base Alpha 3
Looking at the source it does look like it should be a bitmask. Incidentally, I'd expect RE1 not RE2 or RE0 to blink with that code - you're setting and clearing bit 1, not bit 0 (if it is working with a mask).

Try with 1<<0 (or just 1) and see if it blinks RE0.

_________________
Why not visit my shop? http://majenko.co.uk/catalog
Universal IDE: http://uecide.org
"I was trying to find out if it was possible to only eat one Jaffa Cake. I had to abandon the experiment because I ran out of Jaffa Cakes".


Top
 Profile  
 
 Post subject: Re: GPIO Driver
PostPosted: Tue Dec 29, 2015 11:00 pm 
Contributor
User avatar

Joined: Thu Nov 08, 2012 7:04 am
Posts: 2401
Location: Rapa Nui
Code:
ioctl(fd, GPIO_PORTE | GPIO_SET, 0x0001); // bit E0
ioctl(fd, GPIO_PORTE | GPIO_SET, 0x0002); // bit E1
ioctl(fd, GPIO_PORTE | GPIO_SET, 0x0004); // bit E2
ioctl(fd, GPIO_PORTE | GPIO_SET, 0x0008); // bit E3
..
ioctl(fd, GPIO_PORTE | GPIO_SET, 0x0080); // bit E7
..
ioctl(fd, GPIO_PORTE | GPIO_SET, 0x0083); // bits E7 E1 E0

_________________
Pukao Hats Cleaning Services Ltd.


Top
 Profile  
 
 Post subject: Re: GPIO Driver
PostPosted: Wed Dec 30, 2015 10:39 pm 
User avatar

Joined: Fri Mar 06, 2015 9:13 pm
Posts: 37
Location: Barcelona, SP
Pito wrote:
Code:
ioctl(fd, GPIO_PORTE | GPIO_SET, 0x0001); // bit E0
ioctl(fd, GPIO_PORTE | GPIO_SET, 0x0002); // bit E1
ioctl(fd, GPIO_PORTE | GPIO_SET, 0x0004); // bit E2
ioctl(fd, GPIO_PORTE | GPIO_SET, 0x0008); // bit E3
..
ioctl(fd, GPIO_PORTE | GPIO_SET, 0x0080); // bit E7
..
ioctl(fd, GPIO_PORTE | GPIO_SET, 0x0083); // bits E7 E1 E0


Hehe I try too and strange behavior..... the PPS sometimes is a headhache I talk with Vak sometime ago... about tis "feature" :D

At the moment Russian Style solution :)

http://whitecatboard.org/websvn/filedetails.php?repname=Whitecat&path=%2Fgpio%2Fmain.c

Using NetBeans for working with code.

_________________
Dennis MacAlistair Ritchie (Sep.09.1941 - Oct.12.2011)


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
cron




Powered by phpBB® Forum Software © phpBB Group

BSD Daemon used with permission