URL
https://opencores.org/ocsvn/or1k_old/or1k_old/trunk
Subversion Repositories or1k_old
Compare Revisions
- This comparison shows the changes necessary to convert path
/
- from Rev 476 to Rev 477
- ↔ Reverse comparison
Rev 476 → Rev 477
/trunk/or1ksim/sim-config.h
75,10 → 75,7
struct { |
unsigned long baseaddr; /* Base address */ |
int irq; /* IRQ of this device */ |
unsigned long vapi_id; /* VAPI id for this instance */ |
unsigned long aux_vapi_id; /* VAPI id for auxiliary inputs */ |
unsigned long clk_vapi_id; /* VAPI id for external clock */ |
unsigned long cfg_vapi_id; /* VAPI id for configuring this instance */ |
unsigned long base_vapi_id; /* First VAPI ID. GPIO uses 8 consecutive IDs */ |
} gpios[MAX_GPIOS]; |
|
struct { |
179,7 → 176,7
int enabled; /* Whether is VAPI module enabled */ |
int server_port; /* A user specified port number for services */ |
int log_enabled; /* Whether to log the vapi requests */ |
int log_device_id; /* Whether to log device ID for each request */ |
int hide_device_id; /* Whether to log device ID for each request */ |
char vapi_fn[STR_SIZE]; /* vapi log filename */ |
} vapi; |
}; |
/trunk/or1ksim/peripheral/gpio.c
52,7 → 52,7
} |
|
|
for ( i = 0; i < MAX_GPIOS; ++ i ) { |
for ( i = 0; i < config.ngpios; ++ i ) { |
struct gpio_device *gpio = &(gpios[i]); |
|
gpio->gpio_number = i; |
66,13 → 66,10
register_memoryarea( gpio->baseaddr, GPIO_ADDR_SPACE, 4, gpio_read32, gpio_write32 ); |
|
/* Possibly connect to VAPI */ |
gpio->vapi_ids[GPIO_VAPI_DATA] = config.gpios[i].vapi_id; |
gpio->vapi_ids[GPIO_VAPI_AUX] = config.gpios[i].aux_vapi_id; |
gpio->vapi_ids[GPIO_VAPI_CLOCK] = config.gpios[i].clk_vapi_id; |
gpio->vapi_ids[GPIO_VAPI_CONFIG] = config.gpios[i].cfg_vapi_id; |
for ( j = 0; j < GPIO_NUM_VAPI_IDS; ++ j ) |
if ( gpio->vapi_ids[j] ) |
vapi_install_handler( gpio->vapi_ids[j], gpio_vapi_read ); |
if ( config.gpios[i].base_vapi_id ) { |
gpio->base_vapi_id = config.gpios[i].base_vapi_id; |
vapi_install_multi_handler( gpio->base_vapi_id, GPIO_NUM_VAPI_IDS, gpio_vapi_read ); |
} |
} |
} |
} |
83,7 → 80,7
{ |
unsigned i; |
|
for ( i = 0; i < MAX_GPIOS; ++ i ) { |
for ( i = 0; i < config.ngpios; ++ i ) { |
struct gpio_device *gpio = &(gpios[i]); |
|
if ( gpio->baseaddr == 0 ) |
108,7 → 105,7
unsigned i; |
*gpio = NULL; |
|
for ( i = 0; i < MAX_GPIOS && *gpio == NULL; ++ i ) { |
for ( i = 0; i < config.ngpios && *gpio == NULL; ++ i ) { |
if ( (addr >= gpios[i].baseaddr) && (addr < gpios[i].baseaddr + GPIO_ADDR_SPACE) ) |
*gpio = &(gpios[i]); |
} |
131,10 → 128,11
{ |
unsigned i, j; |
|
for ( i = 0; i < MAX_GPIOS; ++ i ) |
for ( j = 0; j < GPIO_NUM_VAPI_IDS; ++ j ) |
if ( id == gpios[i].vapi_ids[j] ) |
return &(gpios[i]); |
for ( i = 0; i < config.ngpios; ++ i ) |
if ( (id >= gpios[i].base_vapi_id) && (id < gpios[i].base_vapi_id + GPIO_NUM_VAPI_IDS) ) { |
*which = id - gpios[i].base_vapi_id; |
return &(gpios[i]); |
} |
|
return NULL; |
} |
150,7 → 148,9
} |
|
switch( addr ) { |
case RGPIO_IN: gpio->next.ctrl &= ~RGPIO_CTRL_INT; return gpio->curr.in | gpio->curr.out; |
case RGPIO_IN: |
gpio->next.ctrl &= ~RGPIO_CTRL_INT; |
return gpio->curr.in | gpio->curr.out; |
case RGPIO_OUT: return gpio->curr.out; |
case RGPIO_OE: return gpio->curr.oe; |
case RGPIO_INTE: return gpio->curr.inte; |
171,7 → 171,7
} |
|
switch( addr ) { |
case RGPIO_IN: debug( 3, "GPIO: Cannot write to RGPIO_IN\n" ); break; |
case RGPIO_IN: debug( 2, "GPIO: Cannot write to RGPIO_IN\n" ); break; |
case RGPIO_OUT: gpio->next.out = value; break; |
case RGPIO_OE: gpio->next.oe = value; break; |
case RGPIO_INTE: gpio->next.inte = value; break; |
188,7 → 188,7
unsigned which; |
struct gpio_device *gpio = gpio_find_vapi_device( id, &which ); |
|
debug( 4, "GPIO: id %08x, data %08x\n", id, data ); |
debug( 5, "GPIO: id %08x, data %08x\n", id, data ); |
|
if ( !gpio ) { |
debug( 1, "GPIO: VAPI ID %08x is not ours!\n", id ); |
196,10 → 196,31
} |
|
switch( which ) { |
case GPIO_VAPI_DATA: gpio->next.in = data; break; |
case GPIO_VAPI_AUX: gpio->auxiliary_inputs = data; break; |
case GPIO_VAPI_CLOCK: gpio_external_clock( data ); break; |
case GPIO_VAPI_CONFIG: /* Currently no configuration commands supported */ break; |
case GPIO_VAPI_DATA: |
debug( 3, "GPIO: Next input from VAPI = 0x%08x\n", data ); |
gpio->next.in = data; |
break; |
case GPIO_VAPI_AUX: |
gpio->auxiliary_inputs = data; |
break; |
case GPIO_VAPI_RGPIO_OE: |
gpio->next.oe = data; |
break; |
case GPIO_VAPI_RGPIO_INTE: |
gpio->next.inte = data; |
break; |
case GPIO_VAPI_RGPIO_PTRIG: |
gpio->next.ptrig = data; |
break; |
case GPIO_VAPI_RGPIO_AUX: |
gpio->next.aux = data; |
break; |
case GPIO_VAPI_RGPIO_CTRL: |
gpio->next.ctrl = data; |
break; |
case GPIO_VAPI_CLOCK: |
gpio_external_clock( data ); |
break; |
} |
} |
|
208,7 → 229,7
{ |
unsigned i; |
|
for ( i = 0; i < MAX_GPIOS; ++ i ) |
for ( i = 0; i < config.ngpios; ++ i ) |
if ( !(gpios[i].curr.ctrl & RGPIO_CTRL_ECLK) ) |
gpio_device_clock( &(gpios[i]) ); |
} |
218,21 → 239,23
{ |
unsigned i; |
|
/* "Normalize" clock value */ |
value = (value != 0); |
|
for ( i = 0; i < MAX_GPIOS; ++ i ) { |
for ( i = 0; i < config.ngpios; ++ i ) { |
struct gpio_device *gpio = &(gpios[i]); |
|
int eclk = ((gpio->curr.ctrl & RGPIO_CTRL_ECLK) == RGPIO_CTRL_ECLK); |
int nec = ((gpio->curr.ctrl & RGPIO_CTRL_NEC) == RGPIO_CTRL_NEC); |
int use_external_clock = ((gpio->curr.ctrl & RGPIO_CTRL_ECLK) == RGPIO_CTRL_ECLK); |
int negative_edge = ((gpio->curr.ctrl & RGPIO_CTRL_NEC) == RGPIO_CTRL_NEC); |
|
gpio->next.external_clock = value; |
|
if ( eclk && (gpio->next.external_clock != gpio->curr.external_clock) && (value != nec) ) |
if ( use_external_clock && (gpio->next.external_clock != gpio->curr.external_clock) && (value != negative_edge) ) |
gpio_device_clock( gpio ); |
} |
} |
|
|
/* Clock as handld by one device. */ |
void gpio_device_clock( struct gpio_device *gpio ) |
{ |
243,19 → 266,26
gpio->next.out &= gpio->next.oe; /* Only output-enabled bits */ |
|
/* If any outputs changed, notify the world (i.e. vapi) */ |
if ( gpio->next.out != gpio->curr.out ) |
if ( gpio->vapi_ids[GPIO_VAPI_DATA] != 0 ) |
vapi_send( gpio->vapi_ids[GPIO_VAPI_DATA], gpio->next.out ); |
if ( gpio->next.out != gpio->curr.out ) { |
debug( 3, "GPIO: New output 0x%08x\n", gpio->next.out ); |
if ( gpio->base_vapi_id ) |
vapi_send( gpio->base_vapi_id + GPIO_VAPI_DATA, gpio->next.out ); |
} |
|
/* If any inputs changed and interrupt enabled, generate interrupt */ |
if ( (gpio->next.in != gpio->curr.in) && (gpio->next.ctrl & RGPIO_CTRL_INTE) ) { |
unsigned changed_bits = gpio->next.in ^ gpio->curr.in; /* inputs that have changed */ |
unsigned set_bits = changed_bits & gpio->next.in; /* inputs that have been set */ |
unsigned cleared_bits = changed_bits & gpio->curr.in; /* inputs that have been cleared */ |
unsigned relevant_bits = (gpio->next.ptrig & set_bits) | (~gpio->next.ptrig & cleared_bits); |
if ( relevant_bits & gpio->next.inte ) { |
report_interrupt( gpio->irq ); |
gpio->next.ctrl |= RGPIO_CTRL_INT; |
if ( gpio->next.in != gpio->curr.in ) { |
debug( 3, "GPIO: New input 0x%08x\n", gpio->next.out ); |
|
if ( gpio->next.ctrl & RGPIO_CTRL_INTE ) { |
unsigned changed_bits = gpio->next.in ^ gpio->curr.in; /* inputs that have changed */ |
unsigned set_bits = changed_bits & gpio->next.in; /* inputs that have been set */ |
unsigned cleared_bits = changed_bits & gpio->curr.in; /* inputs that have been cleared */ |
unsigned relevant_bits = (gpio->next.ptrig & set_bits) | (~gpio->next.ptrig & cleared_bits); |
|
if ( relevant_bits & gpio->next.inte ) { |
report_interrupt( gpio->irq ); |
gpio->next.ctrl |= RGPIO_CTRL_INT; |
} |
} |
} |
|
/trunk/or1ksim/peripheral/gpio.h
46,5 → 46,4
#define RGPIO_CTRL_INT 0x00000008 |
|
|
|
#endif /* __OR1KSIM_PERIPHERAL_GPIO_H */ |
/trunk/or1ksim/peripheral/gpio_i.h
27,7 → 27,9
/* |
* The various VAPI IDs each GPIO device has |
*/ |
enum { GPIO_VAPI_CONFIG = 0, GPIO_VAPI_DATA, GPIO_VAPI_AUX, GPIO_VAPI_CLOCK, GPIO_NUM_VAPI_IDS }; |
enum { GPIO_VAPI_DATA = 0, GPIO_VAPI_AUX, GPIO_VAPI_CLOCK, |
GPIO_VAPI_RGPIO_OE, GPIO_VAPI_RGPIO_INTE, GPIO_VAPI_RGPIO_PTRIG, GPIO_VAPI_RGPIO_AUX, GPIO_VAPI_RGPIO_CTRL, |
GPIO_NUM_VAPI_IDS }; |
|
|
/* |
45,7 → 47,7
unsigned gpio_number; |
|
/* VAPI IDs */ |
unsigned long vapi_ids[GPIO_NUM_VAPI_IDS]; |
unsigned long base_vapi_id; |
|
/* Auxiliary inputs */ |
unsigned long auxiliary_inputs; |
/trunk/or1ksim/vapi/vapi.c
52,7 → 52,7
|
static struct vapi_handler { |
int fd; |
unsigned long id; |
unsigned long base_id, num_ids; |
void (*read_func)(unsigned long, unsigned long); |
struct vapi_handler *next; |
int temp; |
89,16 → 89,21
} |
} |
|
/* Determines whether a certain handler handles an ID */ |
static inline int handler_fits_id( const struct vapi_handler *t, unsigned long id ) { |
return ((id >= t->base_id) && (id < t->base_id + t->num_ids)); |
} |
|
/* Finds a handler with given ID, return it, NULL if not found. */ |
static struct vapi_handler *find_handler (unsigned long id) { |
struct vapi_handler *t = vapi_handler; |
while (t && t->id != id) |
while (t && !handler_fits_id (t, id)) |
t = t->next; |
return t; |
} |
|
/* Adds a handler with given id and returns it. */ |
static struct vapi_handler *add_handler (unsigned long id) { |
static struct vapi_handler *add_handler (unsigned long base_id, unsigned long num_ids) { |
struct vapi_handler **t = &vapi_handler; |
struct vapi_handler *tt; |
while ((*t)) |
105,7 → 110,8
t = &(*t)->next; |
tt = (struct vapi_handler *)malloc (sizeof (struct vapi_handler)); |
tt->next = NULL; |
tt->id = id; |
tt->base_id = base_id; |
tt->num_ids = num_ids; |
tt->read_func = NULL; |
tt->fd = 0; |
(*t) = tt; |
120,7 → 126,7
{ |
if (!runtime.vapi.vapi_file) |
return; |
if (config.vapi.log_device_id && devid <= VAPI_MAX_DEVID) |
if (!config.vapi.hide_device_id && devid <= VAPI_MAX_DEVID) |
fprintf (runtime.vapi.vapi_file, "%04x", devid); |
fprintf (runtime.vapi.vapi_file, "%1x%08x\n", command, data); |
} |
382,12 → 388,12
|
static int read_packet (int fd, unsigned long *id, unsigned long *data) |
{ |
if (fd <= 0) |
if (fd <= 0) |
return 1; |
if (vapi_read_stream(fd, id, sizeof(unsigned long)) < 0) |
if (vapi_read_stream(fd, id, sizeof(unsigned long)) < 0) |
return 1; |
*id = ntohl (*id); |
if (vapi_read_stream(fd, data, sizeof(unsigned long)) < 0) |
if (vapi_read_stream(fd, data, sizeof(unsigned long)) < 0) |
return 1; |
*data = ntohl (*data); |
return 0; |
398,7 → 404,7
unsigned long id, data; |
|
if (read_packet(t->fd, &id, &data)) { |
if (t->fd >= 0) { |
if (t->fd > 0) { |
perror("vapi read"); |
close(t->fd); |
t->fd = 0; |
411,7 → 417,7
debug (4, "[%08x, %08x]\n", id, data); |
|
/* This packet may be for another handler */ |
if (t->id != id) |
if (!handler_fits_id (t, id)) |
t = find_handler (id); |
if (!t || !t->read_func) |
fprintf (stderr, "WARNING: Received packet for undefined id %08x, data %08x\n", id, data); |
522,18 → 528,24
} |
} |
|
/* Installs a vapi handler to VAPI id */ |
/* Installs a vapi handler for one VAPI id */ |
void vapi_install_handler (unsigned long id, void (*read_func) (unsigned long, unsigned long)) |
{ |
vapi_install_multi_handler (id, 1, read_func); |
} |
|
/* Installs a vapi handler for many VAPI id */ |
void vapi_install_multi_handler (unsigned long base_id, unsigned long num_ids, void (*read_func) (unsigned long, unsigned long)) |
{ |
struct vapi_handler *tt; |
|
debug(4, "vapi_install_handler %08x, %08x\n", id, read_func); |
debug(4, "vapi_install_handler %08x, %u, %08x\n", base_id, num_ids, read_func); |
if (read_func == NULL) { |
struct vapi_handler **t = &vapi_handler; |
while ((*t) && (*t)->id != id) |
while ((*t) && !handler_fits_id (*t, base_id)) |
t = &(*t)->next; |
if (!t) { |
fprintf (stderr, "Cannot uninstall VAPI read handler from id %x\n", id); |
fprintf (stderr, "Cannot uninstall VAPI read handler from id %x\n", base_id); |
exit (1); |
} |
tt = *t; |
541,9 → 553,9
free (tt); |
nhandlers--; |
} else { |
tt = find_handler (id); |
tt = find_handler (base_id); |
if (!tt) { |
tt = add_handler (id); |
tt = add_handler (base_id, num_ids); |
tt->read_func = read_func; |
} else { |
tt->read_func = read_func; |
560,7 → 572,12
for (; t; t = t->next) { |
if (!t->fd) { |
numu++; |
if (printout) printf (" 0x%x", t->id); |
if (printout) { |
if ( t->num_ids == 1 ) |
printf (" 0x%x", t->base_id); |
else |
printf (" 0x%x..0x%x", t->base_id, t->base_id + t->num_ids - 1); |
} |
} |
} |
return numu; |
/trunk/or1ksim/vapi/vapi.h
26,9 → 26,12
/* Closes the VAPI */ |
void vapi_done (); |
|
/* Installs a vapi handler to VAPI id */ |
/* Installs a vapi handler for one VAPI id */ |
void vapi_install_handler (unsigned long id, void (*read_func) (unsigned long, unsigned long)); |
|
/* Installs a vapi handler for multiple VAPI id */ |
void vapi_install_multi_handler (unsigned long base_id, unsigned long num_ids, void (*read_func) (unsigned long, unsigned long)); |
|
/* Checks for incoming packets */ |
void vapi_check (); |
|
/trunk/or1ksim/sim-config.c
303,10 → 303,7
void gpio_ngpios (); |
void gpio_baseaddr (); |
void gpio_irq (); |
void gpio_vapi_id (); |
void gpio_aux_vapi_id (); |
void gpio_clk_vapi_id (); |
void gpio_cfg_vapi_id (); |
void gpio_base_vapi_id (); |
void immu_enabled (); |
void immu_nsets (); |
void immu_nways (); |
435,7 → 432,7
{8, 0, "enabled", "=%i", NULL, (void *)(&config.vapi.enabled)}, |
{8, 0, "server_port", "=%i", NULL, (void *)(&config.vapi.server_port)}, |
{8, 0, "log_enabled", "=%i", NULL, (void *)(&config.vapi.log_enabled)}, |
{8, 0, "log_device_id", "=%i", NULL, (void *)(&config.vapi.log_device_id)}, |
{8, 0, "hide_device_id", "=%i", NULL, (void *)(&config.vapi.hide_device_id)}, |
{8, 0, "vapi_log_fn", "=\"%s\"", NULL, (void *)(&config.vapi.vapi_fn[0])}, |
|
{9, 0, "enabled", "=%i", NULL, (void *)(&config.ethernets_enabled)}, |
486,10 → 483,7
{15,0, "device", "%i", change_device, (void *)(&tempL)}, |
{15,0, "baseaddr", "=0x%x", gpio_baseaddr, (void *)(&tempUL)}, |
{15,0, "irq", "=%i", gpio_irq, (void *)(&tempL)}, |
{15,0, "vapi_id", "=0x%x", gpio_vapi_id, (void *)(&tempUL)}, |
{15,0, "aux_vapi_id", "=0x%x", gpio_aux_vapi_id, (void *)(&tempUL)}, |
{15,0, "clk_vapi_id", "=0x%x", gpio_clk_vapi_id, (void *)(&tempUL)}, |
{15,0, "cfg_vapi_id", "=0x%x", gpio_cfg_vapi_id, (void *)(&tempUL)} |
{15,0, "base_vapi_id", "=0x%x", gpio_base_vapi_id, (void *)(&tempUL)} |
}; |
|
/* *INDENT-ON* */ |
758,34 → 752,13
ERROR("invalid device number."); |
} |
|
void gpio_vapi_id () { |
void gpio_base_vapi_id () { |
if (current_device >= 0 && current_device < config.ngpios) |
config.gpios[current_device].vapi_id = tempUL; |
config.gpios[current_device].base_vapi_id = tempUL; |
else |
ERROR("invalid device number."); |
} |
|
void gpio_aux_vapi_id () { |
if (current_device >= 0 && current_device < config.ngpios) |
config.gpios[current_device].aux_vapi_id = tempUL; |
else |
ERROR("invalid device number."); |
} |
|
void gpio_clk_vapi_id () { |
if (current_device >= 0 && current_device < config.ngpios) |
config.gpios[current_device].clk_vapi_id = tempUL; |
else |
ERROR("invalid device number."); |
} |
|
void gpio_cfg_vapi_id () { |
if (current_device >= 0 && current_device < config.ngpios) |
config.gpios[current_device].cfg_vapi_id = tempUL; |
else |
ERROR("invalid device number."); |
} |
|
int is_power2 (int x) { |
while (!(x & 1)) |
x >>= 1; |