Compare commits

..

1 commit

Author SHA1 Message Date
Jeff Epler
103c23866b pi3: nasty hack to make mesaflash at least able to readhmid
pi3 /dev/spidev is just broken:
 * only 8-bit transfers are supported
 * have to usleep after each transfer or some just go broken

this is enough to let mesaflash --readhmid.

Signed-off-by: Jeff Epler <jepler@unpythonic.net>
2016-09-14 22:37:17 +00:00
23 changed files with 91 additions and 284 deletions

View file

@ -30,7 +30,7 @@ OPT = -O0
#DEBUG = -g -pedantic -Wall -Wextra
#DEBUG = -g -Wall -Wextra
DEBUG = -g -Werror=missing-prototypes -Werror=strict-prototypes -Werror=implicit-function-declaration
DEBUG = -g
ifeq ($(TARGET),linux)
INCLUDE = -I/usr/include

14
anyio.c
View file

@ -30,10 +30,7 @@
#include "serial_boards.h"
supported_board_entry_t supported_boards[] = {
{"ETHER", BOARD_ETH | BOARD_WILDCARD},
{"7I92", BOARD_ETH},
{"7I93", BOARD_ETH},
{"7I96", BOARD_ETH},
{"7I80", BOARD_ETH},
{"7I76E", BOARD_ETH},
@ -108,8 +105,6 @@ int anyio_find_dev(board_access_t *access) {
}
access->open_iface = 0;
if (supported_board->type & BOARD_WILDCARD)
access->open_iface = BOARD_WILDCARD;
if (access->type == BOARD_ANY) {
if (supported_board->type & BOARD_MULTI_INTERFACE) {
printf("ERROR: you must select transport layer for board\n");
@ -195,16 +190,16 @@ int anyio_find_dev(board_access_t *access) {
board_t *anyio_get_dev(board_access_t *access, int board_number) {
int i, j;
board_t *board = NULL;
if (access == NULL) {
return NULL;
}
for (i = 0, j = 0; i < boards_count; i++) {
board_t *board = NULL;
board = &boards[i];
if (strncmp(access->device_name, board->llio.board_name, strlen(access->device_name)) == 0 || access->open_iface & BOARD_WILDCARD) {
if (strncmp(access->device_name, boards[i].llio.board_name, strlen(access->device_name)) == 0) {
j++;
if (j == board_number) {
board = &boards[i];
return board;
}
}
@ -334,7 +329,6 @@ void anyio_dev_print_sserial_info(board_t *board) {
void anyio_bitfile_print_info(char *bitfile_name, int verbose_flag) {
FILE *fp;
char part_name[32];
char board_name[5];
if (bitfile_name == NULL) {
return;
@ -344,6 +338,6 @@ void anyio_bitfile_print_info(char *bitfile_name, int verbose_flag) {
printf("Can't open file %s: %s\n", bitfile_name, strerror(errno));
return;
}
print_bitfile_header(fp, (char*) &part_name, (char*) &board_name, verbose_flag);
print_bitfile_header(fp, (char*) &part_name, verbose_flag);
fclose(fp);
}

View file

@ -22,15 +22,12 @@
#include "bitfile.h"
// prints info about bitfile and returns header length or -1 when error
int print_bitfile_header(FILE *fp, char *part_name, char *board_id, int verbose_flag) {
int print_bitfile_header(FILE *fp, char *part_name, int verbose_flag) {
u8 buff[256];
int sleng;
int bytesread, conflength;
int ret = 0;
if(board_id)
strcpy(board_id, "");
printf("Checking file... ");
bytesread = fread(&buff, 1, 14, fp);
ret += bytesread;
@ -52,20 +49,6 @@ int print_bitfile_header(FILE *fp, char *part_name, char *board_id, int verbose_
if (verbose_flag == 1) {
printf(" Design name: %s\n", buff);
}
char *id = strstr(buff, "UserID=");
if(id && board_id) {
int id_hex = -1;
sscanf(id+7, "%x", &id_hex);
if(id_hex != 0xffffffff)
{
board_id[0] = (id_hex >> 24) & 0xff;
board_id[1] = (id_hex >> 16) & 0xff;
board_id[2] = (id_hex >> 8) & 0xff;
board_id[3] = id_hex & 0xff;
board_id[4] = 0;
}
fprintf(stderr, "note: board_id = %s\n", board_id);
}
bytesread = fread(&buff, 1, 3, fp);
ret += bytesread;
@ -142,40 +125,3 @@ u8 bitfile_reverse_bits(u8 data) {
};
return swaptab[data];
}
static const char *bitfile_basename(const char *filename) {
const char *s = strrchr(filename, '/');
if(!s) s = filename;
else s = s + 1;
#ifdef _WIN32
s = strrchr(filename, '\\');
if(!s) s = filename;
else s = s + 1;
#endif
return s;
}
int check_board_name(char *llio_board_name, const char *bitfile_board_name, const char *filename)
{
fprintf(stderr, "check_board_name %s %s %s\n",
llio_board_name, filename, bitfile_board_name);
if(!llio_board_name) {
fprintf(stderr, "LLIO: no boardname, cannot check that bitfile matches\n");
return 1;
}
if(bitfile_board_name && *bitfile_board_name) {
fprintf(stderr, "NOTE: comparing llio board name '%s' with bitfile board name '%s'\n", llio_board_name, bitfile_board_name);
int result = !strncasecmp(llio_board_name, bitfile_board_name, 4);
if(!result)
fprintf(stderr, "Error: wrong bitfile destination card: Detected %s, bitfile ID is %s\n", llio_board_name, bitfile_board_name);
return result;
}
if(filename) {
filename = bitfile_basename(filename);
int result = !strncasecmp(llio_board_name, filename, 4);
if(!result)
fprintf(stderr, "Error: wrong bitfile destination card: Detected %s, filename is %.4s\n", llio_board_name, filename);
return result;
}
}

View file

@ -22,8 +22,7 @@
#include <stdio.h>
#include "types.h"
int print_bitfile_header(FILE *fp, char *part_name, char *board_id, int verbose_flag);
int check_board_name(char *llio_board_name, const char *filename, const char *bitfile_board_name);
int print_bitfile_header(FILE *fp, char *part_name, int verbose_flag);
u8 bitfile_reverse_bits(u8 data);
#endif

View file

@ -36,7 +36,6 @@
#define BOARD_USB (1<<4)
#define BOARD_SPI (1<<5)
#define BOARD_SER (1<<6)
#define BOARD_WILDCARD (1<<30)
typedef enum {BOARD_MODE_CPLD, BOARD_MODE_FPGA} board_mode;
typedef enum {BOARD_FLASH_NONE = 0, BOARD_FLASH_HM2, BOARD_FLASH_IO, BOARD_FLASH_GPIO, BOARD_FLASH_REMOTE, BOARD_FLASH_EPP} board_flash;

View file

@ -22,7 +22,6 @@
#include <sys/stat.h>
#include <sys/time.h>
#include "types.h"
#include "bitfile.h"
#include "eeprom.h"
#include "eeprom_local.h"
#include "eeprom_remote.h"
@ -155,7 +154,6 @@ int eeprom_write(llio_t *self, char *bitfile_name, u32 start_address, int fix_bo
int bytesread, i;
u32 eeprom_addr;
char part_name[32];
char board_name[32];
struct stat file_stat;
FILE *fp;
struct timeval tv1, tv2;
@ -170,7 +168,7 @@ int eeprom_write(llio_t *self, char *bitfile_name, u32 start_address, int fix_bo
printf("Can't open file %s: %s\n", bitfile_name, strerror(errno));
return -1;
}
if (print_bitfile_header(fp, (char*) &part_name, (char*) &board_name, board->llio.verbose) == -1) {
if (print_bitfile_header(fp, (char*) &part_name, board->llio.verbose) == -1) {
fclose(fp);
return -1;
}
@ -182,10 +180,6 @@ int eeprom_write(llio_t *self, char *bitfile_name, u32 start_address, int fix_bo
return -1;
}
}
if (!check_board_name(self->board_name, board_name, bitfile_name)) {
fclose(fp);
return -1;
}
}
// if board doesn't support fallback there is no boot block
if (board->fallback_support == 1) {
@ -244,7 +238,6 @@ int eeprom_verify(llio_t *self, char *bitfile_name, u32 start_address) {
int bytesread, i, bindex;
u32 eeprom_addr;
char part_name[32];
char board_name[32];
struct stat file_stat;
FILE *fp;
struct timeval tv1, tv2;
@ -259,7 +252,7 @@ int eeprom_verify(llio_t *self, char *bitfile_name, u32 start_address) {
printf("Can't open file %s: %s\n", bitfile_name, strerror(errno));
return -1;
}
if (print_bitfile_header(fp, (char*) &part_name, (char*) &board_name, board->llio.verbose) == -1) {
if (print_bitfile_header(fp, (char*) &part_name, board->llio.verbose) == -1) {
fclose(fp);
return -1;
}
@ -270,10 +263,6 @@ int eeprom_verify(llio_t *self, char *bitfile_name, u32 start_address) {
return -1;
}
}
if (!check_board_name(self->board_name, board_name, bitfile_name)) {
fclose(fp);
return -1;
}
// if board doesn't support fallback there is no boot block
if (board->fallback_support == 1) {
if (check_boot(self) == -1) {

View file

@ -258,7 +258,7 @@ static u8 recv_byte_io(llio_t *self) {
// spi access via epp on board 7i43 with EPPIO firmware
static void wait_for_data_epp(llio_t *self) {
void wait_for_data_epp(llio_t *self) {
board_t *board = self->board;
u32 i = 0;
u8 data = 0;

View file

@ -136,7 +136,7 @@ static inline void epp_write32(board_t *board, u32 data) {
}
}
static int epp_read(llio_t *self, u32 addr, void *buffer, int size) {
int epp_read(llio_t *self, u32 addr, void *buffer, int size) {
int bytes_remaining = size;
board_t *board = self->board;
@ -162,7 +162,7 @@ static int epp_read(llio_t *self, u32 addr, void *buffer, int size) {
return 1; // success
}
static int epp_write(llio_t *self, u32 addr, void *buffer, int size) {
int epp_write(llio_t *self, u32 addr, void *buffer, int size) {
int bytes_remaining = size;
board_t *board = self->board;
@ -188,11 +188,10 @@ static int epp_write(llio_t *self, u32 addr, void *buffer, int size) {
return 1;
}
static int epp_program_fpga(llio_t *self, char *bitfile_name) {
int epp_program_fpga(llio_t *self, char *bitfile_name) {
board_t *board = self->board;
int bindex, bytesread;
char part_name[32];
char board_name[32];
struct stat file_stat;
FILE *fp;
@ -205,11 +204,7 @@ static int epp_program_fpga(llio_t *self, char *bitfile_name) {
printf("Can't open file %s: %s\n", bitfile_name, strerror(errno));
return -1;
}
if (print_bitfile_header(fp, (char*) &part_name, (char*) &board_name, board->llio.verbose) == -1) {
fclose(fp);
return -1;
}
if (!check_board_name(self->board_name, board_name, bitfile_name)) {
if (print_bitfile_header(fp, (char*) &part_name, board->llio.verbose) == -1) {
fclose(fp);
return -1;
}
@ -249,7 +244,7 @@ static int epp_program_fpga(llio_t *self, char *bitfile_name) {
}
// return 0 if the board has been reset, -errno if not
static int epp_reset(llio_t *self) {
int epp_reset(llio_t *self) {
board_t *board = self->board;
u8 byte;

View file

@ -64,7 +64,7 @@ inline int eth_recv_packet(void *buffer, int size) {
return recvfrom(sd, (char*) buffer, size, 0, (struct sockaddr *) &src_addr, &len);
}
static void eth_socket_nonblocking(void) {
static void eth_socket_nonblocking() {
#ifdef __linux__
int val = fcntl(sd, F_GETFL);
@ -77,7 +77,7 @@ static void eth_socket_nonblocking(void) {
#endif
}
static void eth_socket_blocking(void) {
static void eth_socket_blocking() {
#ifdef __linux__
int val = fcntl(sd, F_GETFL);
@ -94,7 +94,7 @@ void eth_socket_set_dest_ip(char *addr_name) {
dst_addr.sin_addr.s_addr = inet_addr(addr_name);
}
static char *eth_socket_get_src_ip(void) {
static char *eth_socket_get_src_ip() {
return inet_ntoa(src_addr.sin_addr);
}
@ -294,54 +294,6 @@ static int eth_scan_one_addr(board_access_t *access) {
board->llio.reset = &lbp16_board_reset;
board->llio.reload = &lbp16_board_reload;
board->open = &eth_board_open;
board->close = &eth_board_close;
board->print_info = &eth_print_info;
board->flash = BOARD_FLASH_REMOTE;
board->fallback_support = 1;
board->llio.verbose = access->verbose;
} else if (strncmp(buff, "7I93", 4) == 0) {
board->type = BOARD_ETH;
strncpy(board->dev_addr, eth_socket_get_src_ip(), 16);
strncpy(board->llio.board_name, buff, 16);
board->llio.num_ioport_connectors = 2;
board->llio.pins_per_connector = 24;
board->llio.ioport_connector_name[0] = "P2";
board->llio.ioport_connector_name[1] = "P1";
board->llio.fpga_part_number = "6slx9tqg144";
board->llio.num_leds = 4;
board->llio.read = &eth_read;
board->llio.write = &eth_write;
board->llio.write_flash = &remote_write_flash;
board->llio.verify_flash = &remote_verify_flash;
board->llio.reset = &lbp16_board_reset;
board->llio.reload = &lbp16_board_reload;
board->open = &eth_board_open;
board->close = &eth_board_close;
board->print_info = &eth_print_info;
board->flash = BOARD_FLASH_REMOTE;
board->fallback_support = 1;
board->llio.verbose = access->verbose;
} else if (strncmp(buff, "7I96", 4) == 0) {
board->type = BOARD_ETH;
strncpy(board->dev_addr, eth_socket_get_src_ip(), 16);
strncpy(board->llio.board_name, buff, 16);
board->llio.num_ioport_connectors = 3;
board->llio.pins_per_connector = 13;
board->llio.ioport_connector_name[0] = "P1";
board->llio.ioport_connector_name[1] = "TB1";
board->llio.ioport_connector_name[2] = "TB2";
board->llio.ioport_connector_name[3] = "TB3";
board->llio.fpga_part_number = "6slx9tqg144";
board->llio.num_leds = 4;
board->llio.read = &eth_read;
board->llio.write = &eth_write;
board->llio.write_flash = &remote_write_flash;
board->llio.verify_flash = &remote_verify_flash;
board->llio.reset = &lbp16_board_reset;
board->llio.reload = &lbp16_board_reload;
board->open = &eth_board_open;
board->close = &eth_board_close;
board->print_info = &eth_print_info;

View file

@ -22,7 +22,6 @@
#include <ctype.h>
#include <stdlib.h>
#include <errno.h>
#include <unistd.h>
#include "../anyio.h"
#include "../sserial_module.h"
#ifdef __linux__
@ -39,7 +38,7 @@ static int instance = 0;
static int delay_flag;
static int delay = 50;
static int verbose_flag;
static board_access_t board_access;
static board_access_t access;
static struct option long_options[] = {
{"device", required_argument, 0, 'd'},
@ -49,7 +48,7 @@ static struct option long_options[] = {
{0, 0, 0, 0}
};
static void print_short_usage(void) {
void print_short_usage() {
printf("Example program for writing analog output on pci boards\n");
printf("Syntax:\n");
printf(" pci_analog_write --device str [--instance i] [--delay d] [--verbose]\n");
@ -59,7 +58,7 @@ static void print_short_usage(void) {
printf(" --verbose printf additional info during execution\n");
}
static int process_cmd_line(int argc, char *argv[]) {
int process_cmd_line(int argc, char *argv[]) {
int c;
while (1) {
@ -88,9 +87,9 @@ static int process_cmd_line(int argc, char *argv[]) {
printf("Error: multiply --device option\n");
exit(-1);
}
board_access.device_name = optarg;
access.device_name = optarg;
for (i = 0; optarg[i] != '\0'; i++)
board_access.device_name[i] = toupper(board_access.device_name[i]);
access.device_name[i] = toupper(access.device_name[i]);
device_flag++;
}
@ -144,18 +143,18 @@ int main(int argc, char *argv[]) {
return -1;
}
board_access.verbose = verbose_flag;
access.verbose = verbose_flag;
if (anyio_init(&board_access) != 0) { // init library
if (anyio_init(&access) != 0) { // init library
return -1;
}
ret = anyio_find_dev(&board_access); // find board
ret = anyio_find_dev(&access); // find board
if (ret < 0) {
return -1;
}
board = anyio_get_dev(&board_access, 1); // if found the get board handle
board = anyio_get_dev(&access, 1); // if found the get board handle
if (board == NULL) {
printf("No %s board found\n", board_access.device_name);
printf("No %s board found\n", access.device_name);
return -1;
}
@ -185,7 +184,7 @@ int main(int argc, char *argv[]) {
board->close(board); // close board communication
anyio_cleanup(&board_access); // close library
anyio_cleanup(&access); // close library
return 0;
}

View file

@ -22,7 +22,6 @@
#include <ctype.h>
#include <stdlib.h>
#include <errno.h>
#include <unistd.h>
#include "../anyio.h"
#include "../encoder_module.h"
#ifdef __linux__
@ -39,7 +38,7 @@ static int instance = 0;
static int delay_flag;
static int delay = 50;
static int verbose_flag;
static board_access_t board_access;
static board_access_t access;
static struct option long_options[] = {
{"device", required_argument, 0, 'd'},
@ -49,7 +48,7 @@ static struct option long_options[] = {
{0, 0, 0, 0}
};
static void print_short_usage(void) {
void print_short_usage() {
printf("Example program forreading encoder on pci boards\n");
printf("Syntax:\n");
printf(" pci_encoder_read --device str [--instance i] [--delay d] [--verbose]\n");
@ -59,7 +58,7 @@ static void print_short_usage(void) {
printf(" --verbose printf additional info during execution\n");
}
static int process_cmd_line(int argc, char *argv[]) {
int process_cmd_line(int argc, char *argv[]) {
int c;
while (1) {
@ -88,9 +87,9 @@ static int process_cmd_line(int argc, char *argv[]) {
printf("Error: multiply --device option\n");
exit(-1);
}
board_access.device_name = optarg;
access.device_name = optarg;
for (i = 0; optarg[i] != '\0'; i++)
board_access.device_name[i] = toupper(board_access.device_name[i]);
access.device_name[i] = toupper(access.device_name[i]);
device_flag++;
}
@ -142,18 +141,18 @@ int main(int argc, char *argv[]) {
return -1;
}
board_access.verbose = verbose_flag;
access.verbose = verbose_flag;
if (anyio_init(&board_access) != 0) { // init library
if (anyio_init(&access) != 0) { // init library
return -1;
}
ret = anyio_find_dev(&board_access); // find board
ret = anyio_find_dev(&access); // find board
if (ret < 0) {
return -1;
}
board = anyio_get_dev(&board_access, 1); // if found the get board handle
board = anyio_get_dev(&access, 1); // if found the get board handle
if (board == NULL) {
printf("No %s board found\n", board_access.device_name);
printf("No %s board found\n", access.device_name);
return -1;
}
@ -177,7 +176,7 @@ int main(int argc, char *argv[]) {
fail0:
board->close(board); // close board communication
anyio_cleanup(&board_access); // close library
anyio_cleanup(&access); // close library
return 0;
}

View file

@ -46,7 +46,7 @@ void hm2_read_idrom(hostmot2_t *hm2) {
}
}
static const char *hm2_hz_to_mhz(u32 freq_hz) {
const char *hm2_hz_to_mhz(u32 freq_hz) {
static char mhz_str[20];
int r;
int freq_mhz, freq_mhz_fractional;
@ -62,7 +62,7 @@ static const char *hm2_hz_to_mhz(u32 freq_hz) {
return mhz_str;
}
static const char *hm2_get_general_function_name(int gtag) {
const char *hm2_get_general_function_name(int gtag) {
switch (gtag) {
case HM2_GTAG_IRQ_LOGIC: return "IRQ logic";
case HM2_GTAG_WATCHDOG: return "Watchdog";
@ -95,7 +95,6 @@ static const char *hm2_get_general_function_name(int gtag) {
case HM2_GTAG_RESOLVER: return "Resolver";
case HM2_GTAG_SSERIAL: return "Smart Serial Interface";
case HM2_GTAG_TWIDDLER: return "TWIDDLER";
case HM2_GTAG_XFORMER: return "Transformer";
default: {
static char unknown[100];
snprintf(unknown, 100, "(unknown-gtag-%d)", gtag);
@ -420,7 +419,6 @@ static pin_name_t pin_names[HM2_MAX_TAGS] = {
{HM2_GTAG_RESOLVER, {"PwrEn", "PDMP", "PDMM", "ADChan0", "ADChan1", "ADChan2", "SPICS", "SPIClk", "SPIDI0", "SPIDI1"}},
{HM2_GTAG_SSERIAL, {"RXData", "TXData", "TXEn", "TestPin", "Null5", "Null6", "Null7", "Null8", "Null9", "Null10"}},
{HM2_GTAG_TWIDDLER, {"InBit", "IOBit", "OutBit", "Null4", "Null5", "Null6", "Null7", "Null8", "Null9", "Null10"}},
{HM2_GTAG_XFORMER, {"Drive", "Ref", "Null3", "Null4", "Null5", "Null6", "Null7", "Null8", "Null9", "Null10"}},
{HM2_GTAG_SPI, {"/Frame", "DOut", "SClk", "DIn", "Null5", "Null6", "Null7", "Null8", "Null9", "Null10"}},
{HM2_GTAG_BSPI, {"/Frame", "DOut", "SClk", "DIn", "CS0", "CS1", "CS2", "CS3", "Null9", "Null10"}},
{HM2_GTAG_DBSPI, {"Null1", "DOut", "SClk", "DIn", "/CS-FRM0", "/CS-FRM1", "/CS-FRM2", "/CS-FRM3", "Null9", "Null10"}},
@ -452,7 +450,6 @@ static pin_name_t pin_names_xml[HM2_MAX_TAGS] = {
{HM2_GTAG_RESOLVER, {"PwrEn", "PDMP", "PDMM", "ADChan0", "ADChan1", "ADChan2", "SPICS", "SPIClk", "SPIDI0", "SPIDI1"}},
{HM2_GTAG_SSERIAL, {"RXData", "TXData", "TXEn", "TestPin", "Null5", "Null6", "Null7", "Null8", "Null9", "Null10"}},
{HM2_GTAG_TWIDDLER, {"InBit", "IOBit", "OutBit", "Null4", "Null5", "Null6", "Null7", "Null8", "Null9", "Null10"}},
{HM2_GTAG_XFORMER, {"Drive", "Ref", "Null3", "Null4", "Null5", "Null6", "Null7", "Null8", "Null9", "Null10"}},
{HM2_GTAG_SPI, {"/Frame", "DOut", "SClk", "DIn", "Null5", "Null6", "Null7", "Null8", "Null9", "Null10"}},
{HM2_GTAG_BSPI, {"/Frame", "DOut", "SClk", "DIn", "CS0", "CS1", "CS2", "CS3", "Null9", "Null10"}},
{HM2_GTAG_DBSPI, {"Null1", "DOut", "SClk", "DIn", "/CS-FRM0", "/CS-FRM1", "/CS-FRM2", "/CS-FRM3", "Null9", "Null10"}},
@ -494,7 +491,6 @@ static mod_name_t mod_names[HM2_MAX_TAGS] = {
{"ResolverMod", HM2_GTAG_RESOLVER},
{"SSerial", HM2_GTAG_SSERIAL},
{"Twiddler", HM2_GTAG_TWIDDLER},
{"Transformer", HM2_GTAG_XFORMER},
};
static mod_name_t mod_names_xml[HM2_MAX_TAGS] = {
@ -527,7 +523,6 @@ static mod_name_t mod_names_xml[HM2_MAX_TAGS] = {
{"ResolverMod", HM2_GTAG_RESOLVER},
{"SSerial", HM2_GTAG_SSERIAL},
{"Twiddler", HM2_GTAG_TWIDDLER},
{"Transformer", HM2_GTAG_XFORMER},
};
static char *pin_find_module_name(int gtag, int xml_flag) {

View file

@ -36,7 +36,7 @@ typedef struct {
int sw_modes_cnt;
} sserial_device_t;
#define HM2_MAX_TAGS 30
#define HM2_MAX_TAGS 29
#define ANYIO_MAX_IOPORT_CONNECTORS 8
typedef struct llio_struct llio_t;
@ -90,8 +90,6 @@ void hm2_print_pin_file(llio_t *llio, int xml_flag);
void hm2_set_pin_source(hostmot2_t *hm2, int pin_number, u8 source);
void hm2_set_pin_direction(hostmot2_t *hm2, int pin_number, u8 direction);
void sserial_module_init(llio_t *llio);
void hm2_set_pin_source(hostmot2_t *hm2, int pin_number, u8 source);
void hm2_set_pin_direction(hostmot2_t *hm2, int pin_number, u8 direction);
#endif

View file

@ -64,7 +64,6 @@
#define HM2_GTAG_RESOLVER 0xC0
#define HM2_GTAG_SSERIAL 0xC1
#define HM2_GTAG_TWIDDLER 0xC2
#define HM2_GTAG_XFORMER 0xC3
// HM2 EEPROM SPI INTERFACE

4
lbp.c
View file

@ -99,7 +99,7 @@ int lbp_write(u16 addr, void *buffer) {
return 0;
}
void lbp_print_info(void) {
void lbp_print_info() {
u8 data;
data = lbp_read_ctrl(LBP_CMD_READ_VERSION);
@ -122,7 +122,7 @@ void lbp_init(board_access_t *access) {
#endif
}
void lbp_release(void) {
void lbp_release() {
#ifdef __linux__
close(sd);
#endif

4
lbp.h
View file

@ -85,9 +85,9 @@ int lbp_recv(void *packet, int size);
u8 lbp_read_ctrl(u8 cmd);
int lbp_read(u16 addr, void *buffer);
int lbp_write(u16 addr, void *buffer);
void lbp_print_info(void);
void lbp_print_info();
void lbp_init(board_access_t *access);
void lbp_release(void);
void lbp_release();
#endif

View file

@ -142,5 +142,5 @@ void lbp16_init(int board_type) {
}
}
void lbp16_cleanup(int board_type) {
void lbp_cleanup(int board_type) {
}

View file

@ -89,7 +89,7 @@ static struct option long_options[] = {
{0, 0, 0, 0}
};
static void print_short_usage(void) {
void print_short_usage() {
printf("\nMesaflash version 3.3.0~pre (built on %s %s with libpci %s)\n", __DATE__, __TIME__, PCILIB_VERSION);
printf("Configuration and diagnostic tool for Mesa Electronics PCI(E)/ETH/EPP/USB boards\n");
printf("(C) 2013-2015 Michael Geszkiewicz (contact: micges@wp.pl)\n");
@ -97,7 +97,7 @@ static void print_short_usage(void) {
printf("Try 'mesaflash --help' for more information\n");
}
static void print_usage(void) {
void print_usage() {
printf("Syntax:\n");
printf(" mesaflash --device device_name [options]\n");
printf(" mesaflash --device device_name [options] --write filename\n");
@ -141,7 +141,7 @@ static void print_usage(void) {
printf(" --help print this help message\n");
}
static int process_cmd_line(int argc, char *argv[]) {
int process_cmd_line(int argc, char *argv[]) {
int c;
while (1) {

View file

@ -20,7 +20,6 @@
#include <sys/mman.h>
#include <sys/io.h>
#include <pci/pci.h>
#include <sys/time.h>
#elif _WIN32
#include <windows.h>
#include "libpci/pci.h"
@ -47,9 +46,6 @@ static int memfd = -1;
struct pci_access *pacc;
static u8 file_buffer[SECTOR_SIZE];
static int pci_read(llio_t *self, u32 addr, void *buffer, int size);
static int pci_write(llio_t *self, u32 addr, void *buffer, int size);
u16 setup_eeprom_5i20[256] = {
0x9030, // DEVICE ID
0x10B5, // VENDOR ID
@ -387,7 +383,7 @@ static u16 plx9030_read_eeprom_word(board_t *board, u8 reg) {
return tdata;
}
static void pci_plx9030_bridge_eeprom_setup_read(board_t *board) {
void pci_plx9030_bridge_eeprom_setup_read(board_t *board) {
int i;
char *bridge_name = "Unknown";
@ -414,7 +410,6 @@ static int plx9030_program_fpga(llio_t *self, char *bitfile_name) {
int bindex, bytesread;
u32 status, control;
char part_name[32];
char board_name[32];
struct stat file_stat;
FILE *fp;
struct timeval tv1, tv2;
@ -428,15 +423,10 @@ static int plx9030_program_fpga(llio_t *self, char *bitfile_name) {
printf("Can't open file %s: %s\n", bitfile_name, strerror(errno));
return -1;
}
if (print_bitfile_header(fp, (char*) &part_name, (char*) &board_name, board->llio.verbose) == -1) {
if (print_bitfile_header(fp, (char*) &part_name, board->llio.verbose) == -1) {
fclose(fp);
return -1;
}
if (!check_board_name(self->board_name, board_name, bitfile_name)) {
fclose(fp);
return -1;
}
// set /WRITE low for data transfer, and turn on LED
status = inl(board->ctrl_base_addr + PLX9030_CTRL_STAT_OFFSET);
control = status & ~PLX9030_WRITE_MASK & ~PLX9030_LED_MASK;
@ -576,7 +566,6 @@ static int plx905x_program_fpga(llio_t *self, char *bitfile_name) {
int bindex, bytesread, i;
u32 status;
char part_name[32];
char board_name[32];
struct stat file_stat;
FILE *fp;
struct timeval tv1, tv2;
@ -590,11 +579,7 @@ static int plx905x_program_fpga(llio_t *self, char *bitfile_name) {
printf("Can't open file %s: %s\n", bitfile_name, strerror(errno));
return -1;
}
if (print_bitfile_header(fp, (char*) &part_name, (char*) &board_name, board->llio.verbose) == -1) {
fclose(fp);
return -1;
}
if (!check_board_name(self->board_name, board_name, bitfile_name)) {
if (print_bitfile_header(fp, (char*) &part_name, board->llio.verbose) == -1) {
fclose(fp);
return -1;
}
@ -678,7 +663,7 @@ static int plx905x_reset(llio_t *self) {
return 0;
}
static void memcpy32(void *vdest, void *vsrc, int size) {
void memcpy32(void *vdest, void *vsrc, int size) {
volatile u32 *dest = (volatile u32*)vdest;
volatile u32 *src = (volatile u32*)vsrc;
while(size) {
@ -689,14 +674,14 @@ static void memcpy32(void *vdest, void *vsrc, int size) {
}
}
static int pci_read(llio_t *self, u32 addr, void *buffer, int size) {
int pci_read(llio_t *self, u32 addr, void *buffer, int size) {
board_t *board = self->board;
assert(size % 4 == 0);
memcpy32(buffer, board->base + addr, size/4);
return 0;
}
static int pci_write(llio_t *self, u32 addr, void *buffer, int size) {
int pci_write(llio_t *self, u32 addr, void *buffer, int size) {
board_t *board = self->board;
assert(size % 4 == 0);
memcpy32(board->base + addr, buffer, size/4);

View file

@ -24,9 +24,7 @@
#include <string.h>
#include <errno.h>
#include <math.h>
#include <poll.h>
#include <sys/poll.h>
#include <unistd.h>
#include "types.h"
#include "anyio.h"
#include "serial_boards.h"

View file

@ -16,7 +16,6 @@
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
//
#include <ctype.h>
#include <fcntl.h>
#include <linux/spi/spidev.h>
#include <stdbool.h>
@ -29,17 +28,14 @@
#include <sys/types.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include "types.h"
#include "eeprom.h"
#include "eeprom_local.h"
#include "spi_boards.h"
#include "common.h"
extern board_t boards[MAX_BOARDS];
extern int boards_count;
bool canDo32 = true;
int sd = -1;
struct spi_ioc_transfer settings;
@ -87,7 +83,7 @@ static int spi_board_close(board_t *board) {
int spi_boards_init(board_access_t *access) {
settings.speed_hz = 8 * 1000 * 1000;
settings.bits_per_word = 32;
settings.bits_per_word = 8;
sd = open(access->dev_addr, O_RDWR);
if(sd == -1) {
@ -96,13 +92,7 @@ int spi_boards_init(board_access_t *access) {
}
spidev_set_lsb_first(sd, false);
spidev_set_mode(sd, 0);
if (spidev_set_bits_per_word(sd, settings.bits_per_word) < 0)
{
fprintf(stderr,"unable to set bpw32, fallback to bpw8\n");
canDo32 = false;
settings.bits_per_word = 8;
spidev_set_bits_per_word(sd, settings.bits_per_word);
}
spidev_set_bits_per_word(sd, 8);
spidev_set_max_speed_hz(sd, settings.speed_hz);
return 0;
@ -112,55 +102,31 @@ void spi_boards_cleanup(board_access_t *access) {
if(sd != -1) close(sd);
}
static void reorderBuffer(char *pBuf, int numInts)
{
int lcv;
for (lcv = 0; lcv < numInts; lcv++)
{
pBuf[0] ^= pBuf[3];
pBuf[3] ^= pBuf[0];
pBuf[0] ^= pBuf[3];
pBuf[1] ^= pBuf[2];
pBuf[2] ^= pBuf[1];
pBuf[1] ^= pBuf[2];
pBuf += 4;
}
}
static int spi_read(llio_t *self, u32 addr, void *buffer, int size) {
int spi_read(llio_t *self, u32 addr, void *buffer, int size) {
if(size % 4 != 0) return -1;
int numInts = 1+size/4;
u32 trxbuf[numInts];
trxbuf[0] = read_command(addr, size/4);
u32 trxbuf[1+size/4];
trxbuf[0] = htobe32(read_command(addr, size));
memset(trxbuf+1, 0, size);
struct spi_ioc_transfer t;
t = settings;
t.tx_buf = t.rx_buf = (uint64_t)(intptr_t)trxbuf;
t.len = sizeof(trxbuf);
if (!canDo32)
{
reorderBuffer((char *) trxbuf, 1);
}
int r = ioctl(sd, SPI_IOC_MESSAGE(1), &t);
if(r < 0) return r;
if (!canDo32)
{
reorderBuffer((char *) trxbuf, numInts);
}
usleep(1000);
int i;
for(i=0; i<size/4; i++)
trxbuf[i+1] = be32toh(trxbuf[i+1]);
memcpy(buffer, trxbuf+1, size);
return 0;
}
static int spi_write(llio_t *self, u32 addr, void *buffer, int size) {
int spi_write(llio_t *self, u32 addr, void *buffer, int size) {
if(size % 4 != 0) return -1;
int numInts = 1+size/4;
u32 txbuf[numInts];
u32 txbuf[1+size/4];
txbuf[0] = write_command(addr, size/4);
memcpy(txbuf + 1, buffer, size);
@ -168,12 +134,9 @@ static int spi_write(llio_t *self, u32 addr, void *buffer, int size) {
t = settings;
t.tx_buf = (uint64_t)(intptr_t)txbuf;
t.len = sizeof(txbuf);
if (!canDo32)
{
reorderBuffer((char *) txbuf, numInts);
}
int r = ioctl(sd, SPI_IOC_MESSAGE(1), &t);
usleep(1000);
if(r <= 0) return r;
return 0;
}
@ -184,6 +147,7 @@ void spi_boards_scan(board_access_t *access) {
board_t *board = &boards[boards_count];
board_init_struct(board);
if (spi_read(&(board->llio), HM2_COOKIE_REG, &buf, sizeof(buf)) < 0) {
return;
}

View file

@ -68,40 +68,40 @@ static void disable_sserial_pins(llio_t *llio) {
}
}
static void sslbp_send_local_cmd(sserial_module_t *ssmod, int interface, u32 cmd) {
void sslbp_send_local_cmd(sserial_module_t *ssmod, int interface, u32 cmd) {
ssmod->board->llio.write(&(ssmod->board->llio), ssmod->base_address + HM2_MOD_OFFS_SSERIAL_CMD + interface*0x40, &(cmd), sizeof(u32));
}
static u32 sslbp_read_local_cmd(sserial_module_t *ssmod, int interface) {
u32 sslbp_read_local_cmd(sserial_module_t *ssmod, int interface) {
u32 data;
ssmod->board->llio.read(&(ssmod->board->llio), ssmod->base_address + HM2_MOD_OFFS_SSERIAL_CMD + interface*0x40, &(data), sizeof(u32));
return data;
}
static u8 sslbp_read_data(sserial_module_t *ssmod, int interface) {
u8 sslbp_read_data(sserial_module_t *ssmod, int interface) {
u32 data;
ssmod->board->llio.read(&(ssmod->board->llio), ssmod->base_address + HM2_MOD_OFFS_SSERIAL_DATA + interface*0x40, &(data), sizeof(u32));
return data & 0xFF;
}
static void sslbp_wait_complete(sserial_module_t *ssmod, int interface) {
void sslbp_wait_complete(sserial_module_t *ssmod, int interface) {
while (sslbp_read_local_cmd(ssmod, interface) != 0) {}
}
static void sslbp_send_remote_cmd(sserial_module_t *ssmod, int interface, int channel, u32 cmd) {
void sslbp_send_remote_cmd(sserial_module_t *ssmod, int interface, int channel, u32 cmd) {
ssmod->board->llio.write(&(ssmod->board->llio), ssmod->base_address + HM2_MOD_OFFS_SSERIAL_CS + interface*0x40 + channel*4, &(cmd), sizeof(u32));
}
static u8 sslbp_read_local8(sserial_module_t *ssmod, int interface, u32 addr) {
u8 sslbp_read_local8(sserial_module_t *ssmod, int interface, u32 addr) {
sslbp_send_local_cmd(ssmod, interface, SSLBP_CMD_READ(addr));
sslbp_wait_complete(ssmod, interface);
return sslbp_read_data(ssmod, interface);
}
static u32 sslbp_read_local32(sserial_module_t *ssmod, int interface, u32 addr) {
u32 sslbp_read_local32(sserial_module_t *ssmod, int interface, u32 addr) {
int byte = 4;
u32 ret = 0;
@ -110,7 +110,7 @@ static u32 sslbp_read_local32(sserial_module_t *ssmod, int interface, u32 addr)
return ret;
}
static u8 sslbp_read_remote8(sserial_module_t *ssmod, int interface, int channel, u32 addr) {
u8 sslbp_read_remote8(sserial_module_t *ssmod, int interface, int channel, u32 addr) {
u32 data;
sslbp_send_remote_cmd(ssmod, interface, channel, ((LBP_CMD_READ | LBP_ADDR_AUTO_INC) << 24) | addr);
@ -120,7 +120,7 @@ static u8 sslbp_read_remote8(sserial_module_t *ssmod, int interface, int channel
return data & 0xFF;
}
static u16 sslbp_read_remote16(sserial_module_t *ssmod, int interface, int channel, u32 addr) {
u16 sslbp_read_remote16(sserial_module_t *ssmod, int interface, int channel, u32 addr) {
int byte;
u16 ret = 0;
@ -129,7 +129,7 @@ static u16 sslbp_read_remote16(sserial_module_t *ssmod, int interface, int chann
return ret;
}
static u32 sslbp_read_remote32(sserial_module_t *ssmod, int interface, int channel, u32 addr) {
u32 sslbp_read_remote32(sserial_module_t *ssmod, int interface, int channel, u32 addr) {
int byte;
u32 ret = 0;
@ -138,7 +138,7 @@ static u32 sslbp_read_remote32(sserial_module_t *ssmod, int interface, int chann
return ret;
}
static void sslbp_write_remote8(sserial_module_t *ssmod, int interface, int channel, u32 addr, u8 data) {
void sslbp_write_remote8(sserial_module_t *ssmod, int interface, int channel, u32 addr, u8 data) {
u32 d = data;
sslbp_send_remote_cmd(ssmod, interface, channel, ((LBP_CMD_WRITE | LBP_ARGS_8BIT | LBP_ADDR_AUTO_INC) << 24) | addr);
@ -147,7 +147,7 @@ static void sslbp_write_remote8(sserial_module_t *ssmod, int interface, int chan
sslbp_wait_complete(ssmod, interface);
}
static void sslbp_write_remote16(sserial_module_t *ssmod, int interface, int channel, u32 addr, u16 data) {
void sslbp_write_remote16(sserial_module_t *ssmod, int interface, int channel, u32 addr, u16 data) {
u32 d = data;
sslbp_send_remote_cmd(ssmod, interface, channel, ((LBP_CMD_WRITE | LBP_ARGS_16BIT | LBP_ADDR_AUTO_INC) << 24) | addr);
@ -156,7 +156,7 @@ static void sslbp_write_remote16(sserial_module_t *ssmod, int interface, int cha
sslbp_wait_complete(ssmod, interface);
}
static void sslbp_write_remote32(sserial_module_t *ssmod, int interface, int channel, u32 addr, u32 data) {
void sslbp_write_remote32(sserial_module_t *ssmod, int interface, int channel, u32 addr, u32 data) {
u32 d = data;
sslbp_send_remote_cmd(ssmod, interface, channel, ((LBP_CMD_WRITE | LBP_ARGS_32BIT | LBP_ADDR_AUTO_INC) << 24) | addr);
@ -165,7 +165,7 @@ static void sslbp_write_remote32(sserial_module_t *ssmod, int interface, int cha
sslbp_wait_complete(ssmod, interface);
}
static u16 sslbp_read_nv_remote16(sserial_module_t *ssmod, int interface, int channel, u32 addr) {
u16 sslbp_read_nv_remote16(sserial_module_t *ssmod, int interface, int channel, u32 addr) {
u16 data;
u32 cmd = LBP_CMD_READ_NV << 24;
@ -185,7 +185,7 @@ static u16 sslbp_read_nv_remote16(sserial_module_t *ssmod, int interface, int ch
return data;
}
static u32 sslbp_read_nv_remote32(sserial_module_t *ssmod, int interface, int channel, u32 addr) {
u32 sslbp_read_nv_remote32(sserial_module_t *ssmod, int interface, int channel, u32 addr) {
u32 data;
u32 cmd = LBP_CMD_READ_NV << 24;
@ -205,7 +205,7 @@ static u32 sslbp_read_nv_remote32(sserial_module_t *ssmod, int interface, int ch
return data;
}
static void sslbp_read_remote_bytes(sserial_module_t *ssmod, int interface, int channel, u32 addr, void *buffer, int size) {
void sslbp_read_remote_bytes(sserial_module_t *ssmod, int interface, int channel, u32 addr, void *buffer, int size) {
char *ptr = (char *) buffer;
while (size != 0) {

View file

@ -33,7 +33,7 @@ extern board_t boards[MAX_BOARDS];
extern int boards_count;
static u8 file_buffer[SECTOR_SIZE];
static int usb_read(llio_t *self, u32 addr, void *buffer, int size) {
int usb_read(llio_t *self, u32 addr, void *buffer, int size) {
while (size > 0) {
lbp_read(addr & 0xFFFF, buffer);
addr += 4;
@ -43,7 +43,7 @@ static int usb_read(llio_t *self, u32 addr, void *buffer, int size) {
return 0;
}
static int usb_write(llio_t *self, u32 addr, void *buffer, int size) {
int usb_write(llio_t *self, u32 addr, void *buffer, int size) {
while (size > 0) {
lbp_write(addr & 0xFFFF, buffer);
addr += 4;
@ -57,7 +57,6 @@ static int usb_program_fpga(llio_t *self, char *bitfile_name) {
board_t *board = self->board;
int bindex, bytesread;
char part_name[32];
char board_name[32];
struct stat file_stat;
FILE *fp;
u8 cmd = '0';
@ -71,13 +70,10 @@ static int usb_program_fpga(llio_t *self, char *bitfile_name) {
printf("Can't open file %s: %s\n", bitfile_name, strerror(errno));
return -1;
}
if (print_bitfile_header(fp, (char*) &part_name, (char*) &board_name, board->llio.verbose) == -1) {
if (print_bitfile_header(fp, (char*) &part_name, board->llio.verbose) == -1) {
fclose(fp);
return -1;
}
if (!check_board_name(self->board_name, board_name, bitfile_name)) {
return -1;
}
printf("Programming FPGA...\n");
printf(" |");