Skip to content
Snippets Groups Projects
Commit 3c17b81d authored by Alessandro Rubini's avatar Alessandro Rubini
Browse files

tools: whitespace cleanup, .gitignore lines

This makes no functional change at all, it just removed trailing white
space and makes the code fit into 80 columns
parent f7b7be53
Branches
Tags
No related merge requests found
libspec.a
spec-cl
specmem
spec-fwloader
spec-vuart
\ No newline at end of file
/*
* A tool to program our soft-core (LM32) within the SPEC.
*
* Alessandro Rubini 2012 for CERN, GPLv2 or later.
*/
#include <stdio.h>
......@@ -33,9 +31,13 @@ int main(int argc, char **argv)
break;
default:
fprintf(stderr,
"Use: \"%s [-b bus] [-d devfn] [-c lm32 base address] <lm32_program.bin>\"\n", argv[0]);
"Use: \"%s [-b bus] [-d devfn] "
"[-c lm32 base address] <lm32_program.bin>\"\n",
argv[0]);
fprintf(stderr,
"By default, the first available SPEC is used and the LM32 is assumed at 0x%x.\n", lm32_base);
"By default, the first available SPEC is used "
"and the LM32 is assumed at 0x%x.\n",
lm32_base);
exit(1);
}
}
......@@ -44,21 +46,23 @@ int main(int argc, char **argv)
fprintf(stderr, "Expected binary name after options.\n");
exit(1);
}
card = spec_open(bus, dev_fn);
card = spec_open(bus, dev_fn);
if(!card)
{
fprintf(stderr, "Can't detect a SPEC card under the given adress. Make sure a SPEC card is present in your PC and the driver is loaded.\n");
exit(1);
fprintf(stderr, "Can't detect a SPEC card under the given "
"adress. Make sure a SPEC card is present in your PC "
"and the driver is loaded.\n");
exit(1);
}
if(spec_load_lm32(card, argv[optind], lm32_base) < 0)
{
fprintf(stderr, "Loader failure.\n");
exit(1);
fprintf(stderr, "Loader failure.\n");
exit(1);
}
spec_close(card);
exit (0);
}
/*
* A tool to program the FPGA within the SPEC.
*
* Alessandro Rubini 2012 for CERN, GPLv2 or later.
*/
#include <stdio.h>
......@@ -28,9 +26,10 @@ int main(int argc, char **argv)
break;
default:
fprintf(stderr,
"Use: \"%s [-b bus] [-d devfn] <fpga_bitstream.bin>\"\n", argv[0]);
fprintf(stderr,
"By default, the first available SPEC is used.\n");
"Use: \"%s [-b bus] [-d devfn] "
"<fpga_bitstream.bin>\"\n", argv[0]);
fprintf(stderr, "By default, the first available SPEC "
"is used.\n");
exit(1);
}
}
......@@ -39,21 +38,23 @@ int main(int argc, char **argv)
fprintf(stderr, "Expected binary name after options.\n");
exit(1);
}
card = spec_open(bus, dev_fn);
card = spec_open(bus, dev_fn);
if(!card)
{
fprintf(stderr, "Can't detect a SPEC card under the given adress. Make sure a SPEC card is present in your PC and the driver is loaded.\n");
exit(1);
fprintf(stderr, "Can't detect a SPEC card under the given "
"adress. Make sure a SPEC card is present in your PC "
"and the driver is loaded.\n");
exit(1);
}
if(spec_load_bitstream(card, argv[optind]) < 0)
{
fprintf(stderr, "Loader failure.\n");
exit(1);
fprintf(stderr, "Loader failure.\n");
exit(1);
}
spec_close(card);
exit (0);
}
......@@ -26,11 +26,11 @@ static int transfer_byte(int from, int is_control) {
if(is_control) {
if(c == '\x01') { // C-a
return -1;
}
}
}
spec_vuart_tx(card, &c, 1);
} else {
fprintf(stderr, "\nnothing to read. probably port disconnected.\n");
fprintf(stderr, "nothing to read. Port disconnected?\n");
return -2;
}
return 0;
......@@ -39,7 +39,8 @@ static int transfer_byte(int from, int is_control) {
void term_main(int keep_term)
{
struct termios oldkey, newkey; //place tor old and new port settings for keyboard teletype
struct termios oldkey, newkey;
//above is place for old and new port settings for keyboard teletype
int need_exit = 0;
fprintf(stderr, "[press C-a to exit]\n");
......@@ -60,7 +61,7 @@ void term_main(int keep_term)
int ret;
char rx;
struct timeval tv = {0, 10000};
FD_ZERO(&fds);
FD_SET(STDIN_FILENO, &fds);
......@@ -106,10 +107,13 @@ int main(int argc, char **argv)
break;
default:
fprintf(stderr,
"Use: \"%s [-b bus] [-d devfn] [-u VUART base] [-k]\"\n", argv[0]);
"Use: \"%s [-b bus] [-d devfn] "
"[-u VUART base] [-k]\"\n", argv[0]);
fprintf(stderr,
"By default, the first available SPEC is used and the VUART is assumed at 0x%x.\n \
-k option keeps the terminal config unchanged.", vuart_base);
"By default, the first available SPEC "
"is used and the VUART is assumed at 0x%x.\n"
"-k option keeps the prev terminal config\n",
vuart_base);
exit(1);
}
}
......@@ -117,8 +121,10 @@ int main(int argc, char **argv)
card = spec_open(bus, dev_fn);
if(!card)
{
fprintf(stderr, "Can't detect a SPEC card under the given adress. Make sure a SPEC card is present in your PC and the driver is loaded.\n");
exit(1);
fprintf(stderr, "Can't detect a SPEC card under the given "
"adress. Make sure a SPEC card is present in your PC "
"and the driver is loaded.\n");
exit(1);
}
spec_vuart_init(card, vuart_base);
......
......@@ -24,13 +24,16 @@
struct spec_private {
void *bar0;
void *bar4;
uint32_t vuart_base;
void *bar0;
void *bar4;
uint32_t vuart_base;
};
/* Checks if there's a SPEC card at bus/def_fn. If one (or both) parameters are < 0, takes first available card and returns 0.
If no cards have been detected, returns -1 */
/*
* Checks if there's a SPEC card at bus/def_fn.
* If one (or both) parameters are < 0, takes first available card
* and returns 0. If no cards have been detected, returns -1
*/
static int spec_scan(int *bus, int *devfn)
{
struct dirent **namelist;
......@@ -43,9 +46,11 @@ static int spec_scan(int *bus, int *devfn)
perror("scandir");
exit(-1);
} else {
while (n--)
while (n--)
{
if(!found && sscanf(namelist[n]->d_name, "0000:%02x:%02x.0", &my_bus, &my_devfn) == 2)
if(!found && sscanf(namelist[n]->d_name,
"0000:%02x:%02x.0",
&my_bus, &my_devfn) == 2)
{
if(*bus < 0) *bus = my_bus;
if(*devfn < 0) *devfn = my_devfn;
......@@ -56,18 +61,18 @@ static int spec_scan(int *bus, int *devfn)
}
free(namelist);
}
if(!found)
{
fprintf(stderr,"Can't detect any SPEC card :(\n");
return -1;
}
return 0;
}
/* Maps a particular BAR of given SPEC card and returns its virtual address
/* Maps a particular BAR of given SPEC card and returns its virtual address
(or NULL in case of failure) */
static void *spec_map_area(int bus, int dev, int bar, size_t size)
......@@ -76,20 +81,22 @@ static void *spec_map_area(int bus, int dev, int bar, size_t size)
int fd;
void *ptr;
snprintf(path, sizeof(path), "/sys/bus/pci/drivers/spec/0000:%02x:%02x.0/resource%d", bus, dev, bar);
snprintf(path, sizeof(path), "/sys/bus/pci/drivers/spec"
"/0000:%02x:%02x.0/resource%d", bus, dev, bar);
fd = open(path, O_RDWR | O_SYNC);
if(fd <= 0)
return NULL;
ptr = mmap(NULL, size & ~(getpagesize()-1), PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
ptr = mmap(NULL, size & ~(getpagesize()-1), PROT_READ | PROT_WRITE,
MAP_SHARED, fd, 0);
if((int)ptr == -1)
{
close(fd);
return NULL;
}
return ptr;
}
......@@ -99,51 +106,52 @@ void *spec_open(int bus, int dev)
if(!card || spec_scan(&bus, &dev) < 0)
return NULL;
card->bar0 = spec_map_area(bus, dev, BASE_BAR0, 0x100000);
card->bar4 = spec_map_area(bus, dev, BASE_BAR4, 0x1000);
return card;
}
void spec_close(void *card)
{
struct spec_private *p = (struct spec_private *) card;
struct spec_private *p = (struct spec_private *) card;
if(!card)
return;
munmap(p->bar0, 0x100000);
munmap(p->bar4, 0x1000);
free(card);
munmap(p->bar0, 0x100000);
munmap(p->bar4, 0x1000);
free(card);
}
void spec_writel(void *card, uint32_t data, uint32_t addr)
{
struct spec_private *p = (struct spec_private *) card;
*(volatile uint32_t *) (p->bar0 + addr) = data;
struct spec_private *p = (struct spec_private *) card;
*(volatile uint32_t *) (p->bar0 + addr) = data;
}
uint32_t spec_readl(void *card, uint32_t addr)
{
struct spec_private *p = (struct spec_private *) card;
return *(volatile uint32_t *) (p->bar0 + addr);
struct spec_private *p = (struct spec_private *) card;
return *(volatile uint32_t *) (p->bar0 + addr);
}
static int vuart_rx(void *card)
{
struct spec_private *p = (struct spec_private *) card;
int rdr = spec_readl(card, p->vuart_base + UART_REG_HOST_RDR);
if(rdr & UART_HOST_RDR_RDY)
return UART_HOST_RDR_DATA_R(rdr);
else
return -1;
struct spec_private *p = (struct spec_private *) card;
int rdr = spec_readl(card, p->vuart_base + UART_REG_HOST_RDR);
if(rdr & UART_HOST_RDR_RDY)
return UART_HOST_RDR_DATA_R(rdr);
else
return -1;
}
static void vuart_tx(void *card, int c)
{
struct spec_private *p = (struct spec_private *) card;
struct spec_private *p = (struct spec_private *) card;
while( spec_readl(card, p->vuart_base + UART_REG_SR) & UART_SR_RX_RDY);
spec_writel(card, UART_HOST_TDR_DATA_W(c), p->vuart_base + UART_REG_HOST_TDR);
spec_writel(card, UART_HOST_TDR_DATA_W(c),
p->vuart_base + UART_REG_HOST_TDR);
}
static char *load_binary_file(const char *filename, size_t *size)
......@@ -154,7 +162,7 @@ static char *load_binary_file(const char *filename, size_t *size)
FILE *f;
f = fopen(filename, "r");
if (!f)
if (!f)
return NULL;
if (fstat(fileno(f), &stbuf))
......@@ -170,12 +178,12 @@ static char *load_binary_file(const char *filename, size_t *size)
}
buf = malloc(stbuf.st_size);
if (!buf)
if (!buf)
{
fclose(f);
return NULL;
}
}
i = fread(buf, 1, stbuf.st_size, f);
if (i < 0) {
fclose(f);
......@@ -195,14 +203,14 @@ static char *load_binary_file(const char *filename, size_t *size)
int spec_load_bitstream(void *card, const char *filename)
{
struct spec_private *p = (struct spec_private *) card;
struct spec_private *p = (struct spec_private *) card;
char *buf;
size_t size;
buf = load_binary_file(filename, &size);
if(!buf)
return -1;
int rv = loader_low_level(0, p->bar4, buf, size);
free(buf);
......@@ -215,7 +223,7 @@ int spec_load_lm32(void *card, const char *filename, uint32_t base_addr)
uint32_t *ibuf;
size_t size;
int i;
buf = load_binary_file(filename, &size);
if(!buf)
return -1;
......@@ -225,7 +233,7 @@ int spec_load_lm32(void *card, const char *filename, uint32_t base_addr)
while ( ! (spec_readl(card, base_addr + 0x20400) & (1<<28)) );
ibuf = (uint32_t *) buf;
for (i = 0; i < (size + 3) / 4; i++)
for (i = 0; i < (size + 3) / 4; i++)
spec_writel(card, htonl(ibuf[i]), base_addr + i*4);
sync();
......@@ -273,7 +281,7 @@ size_t spec_vuart_tx(void *card, char *buffer, size_t size)
size_t s = size;
while(s--)
vuart_tx(card, *buffer++);
return size;
}
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment