mirror of
git://projects.qi-hardware.com/ben-blinkenlights.git
synced 2025-04-21 12:27:27 +03:00
Initial commit.
This commit is contained in:
12
bbl/Makefile
Normal file
12
bbl/Makefile
Normal file
@@ -0,0 +1,12 @@
|
||||
CC=mipsel-openwrt-linux-uclibc-gcc
|
||||
|
||||
CFLAGS=-Wall -g
|
||||
|
||||
.PHONY: all clean spotless
|
||||
|
||||
all: bbl
|
||||
|
||||
clean:
|
||||
rm -f bbl
|
||||
|
||||
spotless: clean
|
||||
116
bbl/bbl.c
Normal file
116
bbl/bbl.c
Normal file
@@ -0,0 +1,116 @@
|
||||
/*
|
||||
* bbl.c - Read or write any CPU register
|
||||
*
|
||||
* Written 2010 by Werner Almesberger <werner@openmoko.org>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*/
|
||||
|
||||
|
||||
#include <unistd.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <signal.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/mman.h>
|
||||
|
||||
|
||||
#define PDDATS 0x10010314
|
||||
#define PDDATC 0x10010318
|
||||
#define PDFUNC 0x10010348
|
||||
#define PDDIRS 0x10010364
|
||||
#define PDDIRC 0x10010368
|
||||
|
||||
#define LEDS 10
|
||||
|
||||
#define LED_MASK 0x3f00
|
||||
#define LED_SEL 11
|
||||
|
||||
#define DELAY_US 50000
|
||||
|
||||
#define PAGE_SIZE 4096
|
||||
#define GPIO_BASE 0x10010000
|
||||
#define REG(n) (*(uint32_t *) (mem+(n)-GPIO_BASE))
|
||||
|
||||
static volatile void *mem;
|
||||
|
||||
|
||||
/* ----- Command-line parsing ---------------------------------------------- */
|
||||
|
||||
|
||||
static int map(int g)
|
||||
{
|
||||
switch (g) {
|
||||
case 0:
|
||||
return 12;
|
||||
case 1:
|
||||
return 13;
|
||||
case 2:
|
||||
return 8;
|
||||
case 3:
|
||||
return 9;
|
||||
case 4:
|
||||
return 10;
|
||||
default:
|
||||
abort();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void set(int n)
|
||||
{
|
||||
|
||||
if (n & 1) {
|
||||
REG(PDDATC) = LED_MASK;
|
||||
REG(PDDATS) = 1 << map(n >> 1);
|
||||
} else {
|
||||
REG(PDDATS) = LED_MASK;
|
||||
REG(PDDATC) = 1 << map(n >> 1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void die(int sig)
|
||||
{
|
||||
REG(PDDIRC) = LED_MASK;
|
||||
_exit(0);
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
int fd, i;
|
||||
|
||||
fd = open("/dev/mem", O_RDWR);
|
||||
if (fd < 0) {
|
||||
perror("/dev/mem");
|
||||
exit(1);
|
||||
}
|
||||
mem = mmap(NULL, PAGE_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, fd,
|
||||
GPIO_BASE);
|
||||
if (mem == MAP_FAILED) {
|
||||
perror("mmap");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
signal(SIGINT, die);
|
||||
|
||||
REG(PDFUNC) = LED_MASK;
|
||||
REG(PDDIRS) = LED_MASK;
|
||||
|
||||
while (1) {
|
||||
for (i = 0; i != LEDS-1; i++) {
|
||||
set(i);
|
||||
usleep(DELAY_US);
|
||||
}
|
||||
for (i = LEDS-1; i != 0; i--) {
|
||||
set(i);
|
||||
usleep(DELAY_US);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user