URL
https://opencores.org/ocsvn/minsoc/minsoc/trunk
Subversion Repositories minsoc
Compare Revisions
- This comparison shows the changes necessary to convert path
/minsoc/branches/verilator/utils/contributions/gpio/sw
- from Rev 109 to Rev 139
- ↔ Reverse comparison
Rev 109 → Rev 139
/gpio.c
0,0 → 1,225
#include "../support/support.h" |
#include "../support/board.h" |
|
#include "../support/spr_defs.h" |
|
#include "../drivers/uart.h" |
|
#include "gpio.h" |
|
void gpio_init(gpio_t *gpio, long instance_num, unsigned long base_addr) |
{ |
int i = MIN_GPIO_BIT; |
|
if ( gpio != NULL ) { |
gpio->instance_num = instance_num; |
gpio->base_addr = (unsigned char*)base_addr; |
for ( ;i<=MAX_GPIO_BIT;i++) |
gpio->vectors[i].vec = NULL; |
return; |
} else { |
// Print the error msgs here |
// |
uart_print_str("gpio inst in NULL.\n"); |
return; |
} |
} |
|
void gpio_config_bit(gpio_t *gpio, unsigned long bit, iotype_t io) |
{ |
if ( gpio != NULL ) { |
if ( io == IO_INPUT ) { |
gpio->io_config |= (1 << bit); |
*(unsigned long*)(gpio->base_addr + OE_REG_OFFSET) &= (~(1 << bit)); |
} else { |
gpio->io_config &= (~(1 << bit)); |
*(unsigned long*)(gpio->base_addr + OE_REG_OFFSET) |= (1 << bit); |
} |
return; |
} else { |
// Print the error msgs here |
// |
uart_print_str("gpio inst in NULL.\n"); |
return; |
} |
} |
|
void gpio_set_bit(gpio_t *gpio, unsigned long bit, unsigned long val) |
{ |
if ( gpio != NULL ) { |
if ( val != 0 ) |
*(unsigned long*)(gpio->base_addr + OUT_REG_OFFSET) |= (1 << bit); |
else |
*(unsigned long*)(gpio->base_addr + OUT_REG_OFFSET) &= (~(1 << bit)); |
return; |
} else { |
// Print the error msgs here |
// |
uart_print_str("gpio inst in NULL.\n"); |
return; |
} |
} |
|
void gpio_get_bit(gpio_t *gpio, unsigned long bit, unsigned long *val) |
{ |
unsigned long temp; |
|
if ( gpio != NULL ) { |
temp = *(unsigned long*)(gpio->base_addr + IN_REG_OFFSET); |
*val = (temp & (1 << bit))? 1 : 0; |
return; |
} else { |
// Print the error msgs here |
// |
uart_print_str("gpio inst in NULL.\n"); |
return; |
} |
} |
|
|
void gpio_add_interrupt(gpio_t *gpio, unsigned int bit, edge_t edge,void (*func)() ) |
{ |
if ( gpio != NULL ) { |
if ( ( gpio->io_config &(1 << bit)) != 0 ) { // Port bit is configured as IO_INPUT |
// |
// Disable the interrupts |
// |
*(unsigned long*)(gpio->base_addr + CTRL_REG_OFFSET) &= (~0x01); |
|
// Enable the interrupt bit |
// |
*(unsigned long*)(gpio->base_addr + INTE_REG_OFFSET) |= (1 << bit); |
|
// Enable the edge type |
// |
if ( edge == POS_EDGE ) |
*(unsigned long*)(gpio->base_addr + PTRIG_REG_OFFSET) |= (1 << bit); |
else |
*(unsigned long*)(gpio->base_addr + PTRIG_REG_OFFSET) &= (~(1 << bit)); |
|
// Set the function vector |
// |
gpio->vectors[bit].vec = func; |
|
int_add( 6, gpio_interrupt, gpio ); |
|
// Re-enable the global control bit |
// |
*(unsigned long*)(gpio->base_addr + CTRL_REG_OFFSET) |= 0x01; |
} else { |
// Port is configured as IO_OUTPUT |
uart_print_str("gpio pin is not an input pin.\n"); |
return; |
} |
|
} else { |
// Print the error msgs here |
// |
uart_print_str("gpio inst in NULL.\n"); |
return; |
} |
|
} |
|
void gpio_interrupt(gpio_t *gpio) |
{ |
int i; |
unsigned long int interrupt_status; |
|
if ( (*(unsigned long*)(gpio->base_addr + CTRL_REG_OFFSET)) & 0x02 ) |
{ |
// Interrupt is pending here |
// |
interrupt_status = *(unsigned long*)(gpio->base_addr + INTS_REG_OFFSET); |
|
// Prioritize from lower bits(0) to higher ones(31) |
// |
|
for ( i=MIN_GPIO_BIT; i<=MAX_GPIO_BIT; i++ ) { |
if ( (interrupt_status & (1<<i)) ) { |
*(unsigned long*)(gpio->base_addr + INTS_REG_OFFSET) &= (~( 1 << i )); |
(gpio->vectors[i].vec)(); |
} |
} |
|
*(unsigned long*)(gpio->base_addr + CTRL_REG_OFFSET) &= (~0x02); |
|
} |
} |
|
void hello_east() |
{ |
uart_print_str("Hello from PUSH Button EAST.\n"); |
} |
|
|
void hello_west() |
{ |
uart_print_str("Hello from PUSH Button WEST.\n"); |
} |
|
|
void hello_south() |
{ |
uart_print_str("Hello from PUSH Button SOUTH.\n"); |
} |
|
|
|
|
#define MAX_COUNT 10 |
|
int main() |
{ |
gpio_t gpio_1; |
unsigned long t0, t1, t2, t3; |
unsigned long count = 0; |
|
tick_init(); |
uart_init(); |
int_init(); |
int_add(2,&uart_interrupt); |
|
gpio_init( &gpio_1, 1, GPIO_BASE ); |
|
gpio_config_bit( &gpio_1, LED_0, IO_OUTPUT); |
gpio_config_bit( &gpio_1, LED_1, IO_OUTPUT); |
gpio_config_bit( &gpio_1, LED_2, IO_OUTPUT); |
gpio_config_bit( &gpio_1, LED_3, IO_OUTPUT); |
gpio_config_bit( &gpio_1, LED_4, IO_OUTPUT); |
gpio_config_bit( &gpio_1, LED_5, IO_OUTPUT); |
gpio_config_bit( &gpio_1, LED_6, IO_OUTPUT); |
gpio_config_bit( &gpio_1, LED_7, IO_OUTPUT); |
|
while ( count++ < MAX_COUNT ) { |
gpio_set_bit( &gpio_1, LED_7, 0 ); |
gpio_set_bit( &gpio_1, LED_0, 1 ); |
udelay(); |
gpio_set_bit( &gpio_1, LED_0, 0 ); |
gpio_set_bit( &gpio_1, LED_1, 1 ); |
udelay(); |
gpio_set_bit( &gpio_1, LED_1, 0 ); |
gpio_set_bit( &gpio_1, LED_2, 1 ); |
udelay(); |
gpio_set_bit( &gpio_1, LED_2, 0 ); |
gpio_set_bit( &gpio_1, LED_3, 1 ); |
udelay(); |
gpio_set_bit( &gpio_1, LED_3, 0 ); |
gpio_set_bit( &gpio_1, LED_4, 1 ); |
udelay(); |
gpio_set_bit( &gpio_1, LED_4, 0 ); |
gpio_set_bit( &gpio_1, LED_5, 1 ); |
udelay(); |
gpio_set_bit( &gpio_1, LED_5, 0 ); |
gpio_set_bit( &gpio_1, LED_6, 1 ); |
udelay(); |
gpio_set_bit( &gpio_1, LED_6, 0 ); |
gpio_set_bit( &gpio_1, LED_7, 1 ); |
udelay(); |
} |
|
gpio_set_bit( &gpio_1, LED_7, 0 ); |
|
report(0xdeaddead); |
or32_exit(0); |
} |
/udelay.c
0,0 → 1,13
#include "../support/support.h" |
#include "../support/board.h" |
|
#include "../drivers/tick.h" |
|
extern int tick_int; |
|
void udelay(void) |
{ |
while (!tick_int); |
tick_ack(); |
} |
|
/gpio.h
0,0 → 1,76
#ifndef __GPIO_H__ |
|
#define __GPIO_H__ |
|
#define MIN_GPIO_BIT 0 |
#define MAX_GPIO_BIT 31 |
|
#define TOTAL_GPIO_BITS ((MAX_GPIO_BIT-MIN_GPIO_BIT+1)) |
|
|
#define IN_REG_OFFSET 0x00 |
#define OUT_REG_OFFSET 0x04 |
#define OE_REG_OFFSET 0x08 |
#define INTE_REG_OFFSET 0x0C |
#define PTRIG_REG_OFFSET 0x10 |
#define AUX_REG_OFFSET 0x14 |
#define CTRL_REG_OFFSET 0x18 |
#define INTS_REG_OFFSET 0x1C |
#define ECLK_REG_OFFSET 0x20 |
#define NEC_REG_OFFSET 0x24 |
|
|
typedef struct vector_t_ |
{ |
void (*vec)(); |
} vector_t; |
|
typedef struct gpio_t_ |
{ |
volatile unsigned char *base_addr; |
unsigned int instance_num; |
unsigned int io_config; |
vector_t vectors[TOTAL_GPIO_BITS]; |
} gpio_t; |
|
typedef enum iotype_t_ |
{ |
IO_OUTPUT = 0, |
IO_INPUT = 1 |
} iotype_t; |
|
typedef enum edge_t_ |
{ |
NEG_EDGE = 0, |
POS_EDGE = 1 |
} edge_t; |
|
|
#define LED_0 0x00 |
#define LED_1 0x01 |
#define LED_2 0x02 |
#define LED_3 0x03 |
#define LED_4 0x04 |
#define LED_5 0x05 |
#define LED_6 0x06 |
#define LED_7 0x07 |
|
#define DIP_0 0x08 |
#define DIP_1 0x09 |
#define DIP_2 0x0A |
#define DIP_3 0x0B |
|
#define PUSH_EAST 0x0C |
#define PUSH_WEST 0x0D |
#define PUSH_NORTH 0x0E |
#define PUSH_SOUTH 0x0F |
|
|
void gpio_init(gpio_t *, long, unsigned long); |
void gpio_config_bit(gpio_t *, unsigned long, iotype_t); |
void gpio_set_bit(gpio_t *, unsigned long, unsigned long); |
void gpio_get_bit(gpio_t *, unsigned long, unsigned long *); |
void gpio_add_interrupt(gpio_t *, unsigned int, edge_t,void (*func)() ); |
void gpio_interrupt(gpio_t *gpio); |
|
#endif |
/Makefile
0,0 → 1,26
include ../support/Makefile.inc |
drivers = ../drivers/libdrivers.a |
cases = gpio-nocache gpio-icdc |
common = ../support/libsupport.a ../support/except.o |
|
all: $(cases) |
|
gpio-nocache: gpio.o udelay.o ../support/reset-nocache.o $(common) $(drivers) |
$(OR32_TOOL_PREFIX)-gcc $(GCC_OPT) $(GCC_LIB_OPTS) -T ../support/orp.ld $? -o $@.or32 |
$(OR32_TOOL_PREFIX)-objcopy -O binary $@.or32 $@.bin |
../utils/bin2hex $@.bin 1 -size_word > $@$(FLASH_MEM_HEX_FILE_SUFFIX).hex |
../utils/bin2vmem $@.bin > $@.vmem |
|
|
gpio-icdc: gpio.o udelay.o ../support/reset-icdc.o $(common) $(drivers) |
$(OR32_TOOL_PREFIX)-gcc $(GCC_OPT) $(GCC_LIB_OPTS) -T ../support/orp.ld $? -o $@.or32 |
$(OR32_TOOL_PREFIX)-objcopy -O binary $@.or32 $@.bin |
../utils/bin2hex $@.bin 1 -size_word > $@$(FLASH_MEM_HEX_FILE_SUFFIX).hex |
../utils/bin2vmem $@.bin > $@.vmem |
|
|
gpio.o: gpio.c |
$(OR32_TOOL_PREFIX)-gcc $(GCC_OPT) $? -c -o $@ |
|
udelay.o: udelay.c |
$(OR32_TOOL_PREFIX)-gcc $(GCC_OPT) $? -c -o $@ |
/old/gpio.c
0,0 → 1,351
#include "../support/support.h" |
#include "../support/board.h" |
#include "../support/uart.h" |
|
#include "../support/spr_defs.h" |
|
#include "gpio.h" |
|
|
void uart_print_str(char *); |
void uart_print_long(unsigned long); |
|
// Dummy or32 except vectors |
void buserr_except(){} |
void dpf_except(){} |
void ipf_except(){} |
void lpint_except(){} |
void align_except(){} |
void illegal_except(){} |
/*void hpint_except(){ |
|
}*/ |
void dtlbmiss_except(){} |
void itlbmiss_except(){} |
void range_except(){} |
void syscall_except(){} |
void res1_except(){} |
void trap_except(){} |
void res2_except(){} |
|
|
void uart_interrupt() |
{ |
char lala; |
unsigned char interrupt_id; |
interrupt_id = REG8(UART_BASE + UART_IIR); |
if ( interrupt_id & UART_IIR_RDI ) |
{ |
lala = uart_getc(); |
uart_putc(lala+1); |
} |
} |
|
|
void uart_print_str(char *p) |
{ |
while(*p != 0) { |
uart_putc(*p); |
p++; |
} |
} |
|
void uart_print_long(unsigned long ul) |
{ |
int i; |
char c; |
|
|
uart_print_str("0x"); |
for(i=0; i<8; i++) { |
|
c = (char) (ul>>((7-i)*4)) & 0xf; |
if(c >= 0x0 && c<=0x9) |
c += '0'; |
else |
c += 'a' - 10; |
uart_putc(c); |
} |
|
} |
|
void uart_print_short(unsigned long ul) |
{ |
int i; |
char c; |
char flag=0; |
|
|
uart_print_str("0x"); |
for(i=0; i<8; i++) { |
|
c = (char) (ul>>((7-i)*4)) & 0xf; |
if(c >= 0x0 && c<=0x9) |
c += '0'; |
else |
c += 'a' - 10; |
if ((c != '0') || (i==7)) |
flag=1; |
if(flag) |
uart_putc(c); |
} |
|
} |
|
/* |
* |
* |
* |
* |
* |
* |
* |
* |
* |
*/ |
|
void gpio_init(gpio_t *gpio, long instance_num, unsigned long base_addr) |
{ |
int i = MIN_GPIO_BIT; |
|
if ( gpio != NULL ) { |
gpio->instance_num = instance_num; |
gpio->base_addr = (unsigned char*)base_addr; |
for ( ;i<=MAX_GPIO_BIT;i++) |
gpio->vectors[i].vec = NULL; |
return; |
} else { |
// Print the error msgs here |
// |
uart_print_str("gpio inst in NULL.\n"); |
return; |
} |
} |
|
void gpio_config_bit(gpio_t *gpio, unsigned long bit, iotype_t io) |
{ |
if ( gpio != NULL ) { |
if ( io == IO_INPUT ) { |
gpio->io_config |= (1 << bit); |
*(unsigned long*)(gpio->base_addr + OE_REG_OFFSET) &= (~(1 << bit)); |
} else { |
gpio->io_config &= (~(1 << bit)); |
*(unsigned long*)(gpio->base_addr + OE_REG_OFFSET) |= (1 << bit); |
} |
return; |
} else { |
// Print the error msgs here |
// |
uart_print_str("gpio inst in NULL.\n"); |
return; |
} |
} |
|
void gpio_set_bit(gpio_t *gpio, unsigned long bit, unsigned long val) |
{ |
if ( gpio != NULL ) { |
if ( val != 0 ) |
*(unsigned long*)(gpio->base_addr + OUT_REG_OFFSET) |= (1 << bit); |
else |
*(unsigned long*)(gpio->base_addr + OUT_REG_OFFSET) &= (~(1 << bit)); |
return; |
} else { |
// Print the error msgs here |
// |
uart_print_str("gpio inst in NULL.\n"); |
return; |
} |
} |
|
void gpio_get_bit(gpio_t *gpio, unsigned long bit, unsigned long *val) |
{ |
unsigned long temp; |
|
if ( gpio != NULL ) { |
temp = *(unsigned long*)(gpio->base_addr + IN_REG_OFFSET); |
*val = (temp & (1 << bit))? 1 : 0; |
return; |
} else { |
// Print the error msgs here |
// |
uart_print_str("gpio inst in NULL.\n"); |
return; |
} |
} |
|
|
void gpio_add_interrupt(gpio_t *gpio, unsigned int bit, edge_t edge,void (*func)() ) |
{ |
if ( gpio != NULL ) { |
if ( ( gpio->io_config &(1 << bit)) != 0 ) { // Port bit is configured as IO_INPUT |
// |
// Disable the interrupts |
// |
*(unsigned long*)(gpio->base_addr + CTRL_REG_OFFSET) &= (~0x01); |
|
// Enable the interrupt bit |
// |
*(unsigned long*)(gpio->base_addr + INTE_REG_OFFSET) |= (1 << bit); |
|
// Enable the edge type |
// |
if ( edge == POS_EDGE ) |
*(unsigned long*)(gpio->base_addr + PTRIG_REG_OFFSET) |= (1 << bit); |
else |
*(unsigned long*)(gpio->base_addr + PTRIG_REG_OFFSET) &= (~(1 << bit)); |
|
// Set the function vector |
// |
gpio->vectors[bit].vec = func; |
|
int_add( 6, gpio_interrupt, gpio ); |
|
// Re-enable the global control bit |
// |
*(unsigned long*)(gpio->base_addr + CTRL_REG_OFFSET) |= 0x01; |
} else { |
// Port is configured as IO_OUTPUT |
uart_print_str("gpio pin is not an input pin.\n"); |
return; |
} |
|
} else { |
// Print the error msgs here |
// |
uart_print_str("gpio inst in NULL.\n"); |
return; |
} |
|
} |
|
void gpio_interrupt(gpio_t *gpio) |
{ |
int i; |
unsigned long int interrupt_status; |
|
if ( (*(unsigned long*)(gpio->base_addr + CTRL_REG_OFFSET)) & 0x02 ) |
{ |
// Interrupt is pending here |
// |
interrupt_status = *(unsigned long*)(gpio->base_addr + INTS_REG_OFFSET); |
|
// Prioritize from lower bits(0) to higher ones(31) |
// |
|
for ( i=MIN_GPIO_BIT; i<=MAX_GPIO_BIT; i++ ) { |
if ( (interrupt_status & (1<<i)) ) { |
*(unsigned long*)(gpio->base_addr + INTS_REG_OFFSET) &= (~( 1 << i )); |
(gpio->vectors[i].vec)(); |
} |
} |
|
*(unsigned long*)(gpio->base_addr + CTRL_REG_OFFSET) &= (~0x02); |
|
} |
} |
|
void hello_east() |
{ |
uart_print_str("Hello from PUSH Button EAST.\n"); |
} |
|
|
void hello_west() |
{ |
uart_print_str("Hello from PUSH Button WEST.\n"); |
} |
|
|
void hello_south() |
{ |
uart_print_str("Hello from PUSH Button SOUTH.\n"); |
} |
|
|
|
|
#define MAX_COUNT 10 |
|
int main() |
{ |
gpio_t gpio_1; |
unsigned long t0, t1, t2, t3; |
unsigned long count = 0; |
|
uart_init(); |
int_init(); |
int_add(2,&uart_interrupt); |
|
gpio_init( &gpio_1, 1, GPIO_BASE ); |
|
gpio_config_bit( &gpio_1, LED_0, IO_OUTPUT); |
gpio_config_bit( &gpio_1, LED_1, IO_OUTPUT); |
gpio_config_bit( &gpio_1, LED_2, IO_OUTPUT); |
gpio_config_bit( &gpio_1, LED_3, IO_OUTPUT); |
gpio_config_bit( &gpio_1, LED_4, IO_OUTPUT); |
gpio_config_bit( &gpio_1, LED_5, IO_OUTPUT); |
gpio_config_bit( &gpio_1, LED_6, IO_OUTPUT); |
gpio_config_bit( &gpio_1, LED_7, IO_OUTPUT); |
|
gpio_config_bit( &gpio_1, DIP_0, IO_INPUT); |
gpio_config_bit( &gpio_1, DIP_1, IO_INPUT); |
gpio_config_bit( &gpio_1, DIP_2, IO_INPUT); |
gpio_config_bit( &gpio_1, DIP_3, IO_INPUT); |
|
uart_print_str("Demo 1 : Check for running LED patterns on board ...\n"); |
|
while ( count++ < MAX_COUNT ) { |
gpio_set_bit( &gpio_1, LED_7, 0 ); |
gpio_set_bit( &gpio_1, LED_0, 1 ); |
udelay( 100000 ); |
gpio_set_bit( &gpio_1, LED_0, 0 ); |
gpio_set_bit( &gpio_1, LED_1, 1 ); |
udelay( 100000 ); |
gpio_set_bit( &gpio_1, LED_1, 0 ); |
gpio_set_bit( &gpio_1, LED_2, 1 ); |
udelay( 100000 ); |
gpio_set_bit( &gpio_1, LED_2, 0 ); |
gpio_set_bit( &gpio_1, LED_3, 1 ); |
udelay( 100000 ); |
gpio_set_bit( &gpio_1, LED_3, 0 ); |
gpio_set_bit( &gpio_1, LED_4, 1 ); |
udelay( 100000 ); |
gpio_set_bit( &gpio_1, LED_4, 0 ); |
gpio_set_bit( &gpio_1, LED_5, 1 ); |
udelay( 100000 ); |
gpio_set_bit( &gpio_1, LED_5, 0 ); |
gpio_set_bit( &gpio_1, LED_6, 1 ); |
udelay( 100000 ); |
gpio_set_bit( &gpio_1, LED_6, 0 ); |
gpio_set_bit( &gpio_1, LED_7, 1 ); |
udelay( 100000 ); |
} |
|
gpio_set_bit( &gpio_1, LED_7, 0 ); |
|
gpio_config_bit( &gpio_1, PUSH_EAST, IO_INPUT); |
gpio_add_interrupt( &gpio_1, PUSH_EAST, POS_EDGE, hello_east ); |
gpio_config_bit( &gpio_1, PUSH_WEST, IO_INPUT); |
gpio_add_interrupt( &gpio_1, PUSH_WEST, POS_EDGE, hello_west ); |
gpio_config_bit( &gpio_1, PUSH_SOUTH, IO_INPUT); |
gpio_add_interrupt( &gpio_1, PUSH_SOUTH, POS_EDGE, hello_south ); |
|
uart_print_str("Demo 2 : Press the DIP switches and watch corresponding LED glow ...\n"); |
|
|
while (1) { |
gpio_get_bit( &gpio_1, DIP_0, &t0 ); |
gpio_get_bit( &gpio_1, DIP_1, &t1 ); |
gpio_get_bit( &gpio_1, DIP_2, &t2 ); |
gpio_get_bit( &gpio_1, DIP_3, &t3 ); |
// |
gpio_set_bit( &gpio_1, LED_0, t0 ); |
gpio_set_bit( &gpio_1, LED_1, t1 ); |
gpio_set_bit( &gpio_1, LED_2, t2 ); |
gpio_set_bit( &gpio_1, LED_3, t3 ); |
} |
|
|
report(0xdeaddead); |
or32_exit(0); |
} |
/old/udelay.c
0,0 → 1,17
#include "../support/support.h" |
#include "../support/board.h" |
|
|
void udelay(unsigned long); |
|
void udelay(unsigned long usecs) |
{ |
unsigned long i; |
unsigned long cycles = usecs / (IN_CLK / 1000000 ); |
unsigned long mem_dummy; |
volatile unsigned long* ptr = &mem_dummy; |
|
for ( i=0; i< cycles; i++) |
*ptr = 0xABCD; |
} |
|
/old/gpio.h
0,0 → 1,76
#ifndef __GPIO_H__ |
|
#define __GPIO_H__ |
|
#define MIN_GPIO_BIT 0 |
#define MAX_GPIO_BIT 31 |
|
#define TOTAL_GPIO_BITS ((MAX_GPIO_BIT-MIN_GPIO_BIT+1)) |
|
|
#define IN_REG_OFFSET 0x00 |
#define OUT_REG_OFFSET 0x04 |
#define OE_REG_OFFSET 0x08 |
#define INTE_REG_OFFSET 0x0C |
#define PTRIG_REG_OFFSET 0x10 |
#define AUX_REG_OFFSET 0x14 |
#define CTRL_REG_OFFSET 0x18 |
#define INTS_REG_OFFSET 0x1C |
#define ECLK_REG_OFFSET 0x20 |
#define NEC_REG_OFFSET 0x24 |
|
|
typedef struct vector_t_ |
{ |
void (*vec)(); |
} vector_t; |
|
typedef struct gpio_t_ |
{ |
volatile unsigned char *base_addr; |
unsigned int instance_num; |
unsigned int io_config; |
vector_t vectors[TOTAL_GPIO_BITS]; |
} gpio_t; |
|
typedef enum iotype_t_ |
{ |
IO_OUTPUT = 0, |
IO_INPUT = 1 |
} iotype_t; |
|
typedef enum edge_t_ |
{ |
NEG_EDGE = 0, |
POS_EDGE = 1 |
} edge_t; |
|
|
#define LED_0 0x00 |
#define LED_1 0x01 |
#define LED_2 0x02 |
#define LED_3 0x03 |
#define LED_4 0x04 |
#define LED_5 0x05 |
#define LED_6 0x06 |
#define LED_7 0x07 |
|
#define DIP_0 0x08 |
#define DIP_1 0x09 |
#define DIP_2 0x0A |
#define DIP_3 0x0B |
|
#define PUSH_EAST 0x0C |
#define PUSH_WEST 0x0D |
#define PUSH_NORTH 0x0E |
#define PUSH_SOUTH 0x0F |
|
|
void gpio_init(gpio_t *, long, unsigned long); |
void gpio_config_bit(gpio_t *, unsigned long, iotype_t); |
void gpio_set_bit(gpio_t *, unsigned long, unsigned long); |
void gpio_get_bit(gpio_t *, unsigned long, unsigned long *); |
void gpio_add_interrupt(gpio_t *, unsigned int, edge_t,void (*func)() ); |
void gpio_interrupt(gpio_t *gpio); |
|
#endif |
/old/Makefile
0,0 → 1,26
include ../support/Makefile.inc |
cases = gpio-nocache gpio-icdc |
common = ../support/libsupport.a ../support/except.o |
|
all: $(cases) |
|
gpio-nocache: gpio.o udelay.o ../support/reset-nocache.o $(common) |
$(OR32_TOOL_PREFIX)-gcc $(GCC_OPT) $(GCC_LIB_OPTS) -T ../support/orp.ld $? -o $@.or32 |
$(OR32_TOOL_PREFIX)-objcopy -O binary $@.or32 $@.bin |
../utils/bin2hex $@.bin 1 -size_word > $@$(FLASH_MEM_HEX_FILE_SUFFIX).hex |
../utils/bin2vmem $@.bin > $@.vmem |
|
|
gpio-icdc: gpio.o udelay.o ../support/reset-icdc.o |
$(OR32_TOOL_PREFIX)-gcc $(GCC_OPT) $(GCC_LIB_OPTS) -T ../support/orp.ld $? -o $@.or32 $(common) |
$(OR32_TOOL_PREFIX)-objcopy -O binary $@.or32 $@.bin |
../utils/bin2hex $@.bin 1 -size_word > $@$(FLASH_MEM_HEX_FILE_SUFFIX).hex |
../utils/bin2vmem $@.bin > $@.vmem |
|
|
gpio.o: gpio.c |
$(OR32_TOOL_PREFIX)-gcc $(GCC_OPT) $? -c -o $@ |
|
udelay.o: udelay.c |
$(OR32_TOOL_PREFIX)-gcc $(GCC_OPT) $? -c -o $@ |
|