RetroBSD
bootup
code:shell
% sudo cu -l /dev/cu.usbmodemFA1211 -s 115200
Connected.
2.11 BSD Unix for PIC32, revision G290 build 7:
Compiled 2015-07-14 by chris@olimex:
/home/chris/retrobsd/sys/pic32/pinguino-micro
cpu: 795F512H 80 MHz, bus 80 MHz
oscillator: HS crystal, PLL div 1:2 mult x20
console: ttyUSB0 (7,0)
sd0: port SPI2, select pin B13
sd0: type SDHC, size 1966080 kbytes, speed 13 Mbit/sec
phys mem = 128 kbytes
user mem = 96 kbytes
root dev = rd0a (0,1)
root size = 102400 kbytes
swap dev = rd0b (0,2)
swap size = 2048 kbytes
/dev/sd0a: 1461 files, 12267 used, 89732 free
Starting daemons:updatecron
2.11 BSD UNIX (pic32) (console)
login:
code:shell
# uname -a
2.11BSD pic32 2.11BSD 2.11 BSD Unix for PIC32, revision G290 build 7: Compiled 2015-07-14 by chris@olimex: /home/chris/retrobsd/sys/pic32/pinguino-micro pic32
Demo
code:gpio-adc-demo.c
void putsym(int c, int count)
{
while (count-- > 1)
putchar(c);
}
int main(int argc, char **argv)
{
int i, opt;
long flags;
unsigned long delay_msec = 100;
int gpiooutfd,gpioinfd;
const char *devout = "/dev/porte";
const char *devin = "/dev/portd";
int out=0,in;
while ((opt = getopt(argc, argv, ":d:")) != -1) {
switch (opt) {
case 'd':
delay_msec = strtol(optarg, 0, 0);
break;
}
}
/* Init GPIO */
gpiooutfd = open (devout, 1);
if (gpiooutfd < 0) {
perror (devname);
return -1;
}
gpioinfd = open (devin, 1);
if (gpioinfd < 0) {
perror (devin);
return -1;
}
ioctl(gpiooutfd, GPIO_PORTE | GPIO_CONFOUT, 0xff);
ioctl(gpioinfd, GPIO_PORTD | GPIO_CONFIN, 0xff);
/* Blink LED */
for(i=0;i<8;i++) {
ioctl(gpiooutfd,GPIO_PORTE|GPIO_CLEAR,0xff);
usleep(delay_msec * 1000);
ioctl(gpiooutfd,GPIO_PORTE|GPIO_SET,0xff);
usleep(delay_msec * 1000);
}
/* Init ADC */
for (i=0; i<5; i++) {
sprintf(buf, "/dev/adc%d", i);
perror(buf);
return -1;
}
fcntl(fdi, F_GETFD, &flags); flags |= O_NONBLOCK;
fcntl(fdi, F_SETFD, &flags); }
/* Clear screen. */
printf("\33[2J");
for (;;) {
/* Top of screen. */
printf("\33[H");
printf("LED output:");
/* GPIO output */
for(i=0; i<8; i++) {
if(out & 1<<i) {
putchar('1');
ioctl(gpiooutfd,GPIO_PORT(4)|GPIO_SET,1<<i);
} else {
putchar('0');
ioctl(gpiooutfd,GPIO_PORT(4)|GPIO_CLEAR,1<<i);
}
}
printf("\n");
/* GPIO input */
in=ioctl(gpioinfd,GPIO_PORTD|GPIO_POLL,0xff);
printf("LED input:");
if(in & 0x1) putchar('1'); else putchar('0');
if(in & 0x2) putchar('1'); else putchar('0');
printf("\n");
/* ADC input */
for (i=0; i<5; i++) {
if (read(fdi, buf, 20) > 0) { valuei = strtol(buf, 0, 0); }
printf("adc%-2d %4d ", i, valuei); putsym('=', valuei >> 4); /* Clear to end of line. */
printf("\33[K");
printf("\n");
}
usleep(delay_msec * 1000);
out++;
if(out>255) out=0;
}
}
code:Makefile
CC=cc
all: hoc0 mytest demo
hoc0: y.tab.c
cc y.tab.c -o hoc0
hoc1: hoc1.o
cc hoc1.o -o hoc1
hoc1.o: y.tab.c
cc -c y.tab.c -o hoc1.o
y.tab.c: hoc1.y
byacc hoc1.y
mytest: mytest.c
cc -o mytest mytest.c
demo: gpio-adc-demo.c
cc -o demo gpio-adc-demo.c