mirror of
https://github.com/avrdudes/avrdude.git
synced 2026-09-30 04:49:14 +03:00
Move static variables to PDATA for linuxspi.c
This commit is contained in:
@@ -62,16 +62,14 @@
|
||||
|
||||
#define LINUXSPI "linuxspi"
|
||||
|
||||
/*
|
||||
* Private data for this programmer.
|
||||
*/
|
||||
// Private data for this programmer
|
||||
struct pdata {
|
||||
int disable_no_cs;
|
||||
int fd_spidev, fd_gpiochip, fd_linehandle;
|
||||
};
|
||||
|
||||
#define PDATA(pgm) ((struct pdata *)(pgm->cookie))
|
||||
|
||||
static int fd_spidev, fd_gpiochip, fd_linehandle;
|
||||
// Use private programmer data as if they were a global structure my
|
||||
#define my (*(struct pdata *)(pgm->cookie))
|
||||
|
||||
/**
|
||||
* @brief Sends/receives a message in full duplex mode
|
||||
@@ -91,7 +89,8 @@ static int linuxspi_spi_duplex(const PROGRAMMER *pgm, const unsigned char *tx, u
|
||||
};
|
||||
|
||||
errno = 0;
|
||||
ret = ioctl(fd_spidev, SPI_IOC_MESSAGE(1), &tr);
|
||||
|
||||
ret = ioctl(my.fd_spidev, SPI_IOC_MESSAGE(1), &tr);
|
||||
if (ret != len) {
|
||||
int ioctl_errno = errno;
|
||||
msg_error("\n");
|
||||
@@ -118,10 +117,10 @@ static int linuxspi_reset_mcu(const PROGRAMMER *pgm, bool active) {
|
||||
|
||||
/*
|
||||
* Set the reset state and keep it. The pin will be released and set back to
|
||||
* its initial value, once the fd_gpiochip is closed.
|
||||
* its initial value, once the my.fd_gpiochip is closed.
|
||||
*/
|
||||
data.values[0] = active ^ !(pgm->pinno[PIN_AVR_RESET] & PIN_INVERSE);
|
||||
ret = ioctl(fd_linehandle, GPIOHANDLE_SET_LINE_VALUES_IOCTL, &data);
|
||||
ret = ioctl(my.fd_linehandle, GPIOHANDLE_SET_LINE_VALUES_IOCTL, &data);
|
||||
#ifdef GPIO_V2_LINE_SET_VALUES_IOCTL
|
||||
if (ret == -1) {
|
||||
struct gpio_v2_line_values val;
|
||||
@@ -129,7 +128,7 @@ static int linuxspi_reset_mcu(const PROGRAMMER *pgm, bool active) {
|
||||
val.mask = 1;
|
||||
val.bits = active ^ !(pgm->pinno[PIN_AVR_RESET] & PIN_INVERSE);
|
||||
|
||||
ret = ioctl(fd_linehandle, GPIO_V2_LINE_SET_VALUES_IOCTL, &val);
|
||||
ret = ioctl(my.fd_linehandle, GPIO_V2_LINE_SET_VALUES_IOCTL, &val);
|
||||
}
|
||||
#endif
|
||||
if (ret == -1) {
|
||||
@@ -179,26 +178,26 @@ static int linuxspi_open(PROGRAMMER *pgm, const char *pt) {
|
||||
}
|
||||
|
||||
pgm->port = port;
|
||||
fd_spidev = open(pgm->port, O_RDWR);
|
||||
if (fd_spidev < 0) {
|
||||
my.fd_spidev = open(pgm->port, O_RDWR);
|
||||
if (my.fd_spidev < 0) {
|
||||
pmsg_ext_error("unable to open the spidev device %s: %s\n", pgm->port, strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
|
||||
uint32_t mode = SPI_MODE_0;
|
||||
if (!PDATA(pgm)->disable_no_cs)
|
||||
if (!my.disable_no_cs)
|
||||
mode |= SPI_NO_CS;
|
||||
|
||||
ret = ioctl(fd_spidev, SPI_IOC_WR_MODE32, &mode);
|
||||
ret = ioctl(my.fd_spidev, SPI_IOC_WR_MODE32, &mode);
|
||||
if (ret == -1) {
|
||||
int ioctl_errno = errno;
|
||||
pmsg_ext_error("unable to set SPI mode %02X on %s: %s\n", mode, spidev, strerror(errno));
|
||||
if(ioctl_errno == EINVAL && !PDATA(pgm)->disable_no_cs)
|
||||
if(ioctl_errno == EINVAL && !my.disable_no_cs)
|
||||
pmsg_error("try -x disable_no_cs\n");
|
||||
goto close_spidev;
|
||||
}
|
||||
fd_gpiochip = open(gpiochip, 0);
|
||||
if (fd_gpiochip < 0) {
|
||||
my.fd_gpiochip = open(gpiochip, 0);
|
||||
if (my.fd_gpiochip < 0) {
|
||||
pmsg_ext_error("unable to open the gpiochip %s: %s\n", gpiochip, strerror(errno));
|
||||
ret = -1;
|
||||
goto close_spidev;
|
||||
@@ -210,9 +209,9 @@ static int linuxspi_open(PROGRAMMER *pgm, const char *pt) {
|
||||
req.default_values[0] = !!(pgm->pinno[PIN_AVR_RESET] & PIN_INVERSE);
|
||||
req.flags = GPIOHANDLE_REQUEST_OUTPUT;
|
||||
|
||||
ret = ioctl(fd_gpiochip, GPIO_GET_LINEHANDLE_IOCTL, &req);
|
||||
ret = ioctl(my.fd_gpiochip, GPIO_GET_LINEHANDLE_IOCTL, &req);
|
||||
if (ret != -1)
|
||||
fd_linehandle = req.fd;
|
||||
my.fd_linehandle = req.fd;
|
||||
#ifdef GPIO_V2_GET_LINE_IOCTL
|
||||
if (ret == -1) {
|
||||
struct gpio_v2_line_request reqv2;
|
||||
@@ -227,9 +226,9 @@ static int linuxspi_open(PROGRAMMER *pgm, const char *pt) {
|
||||
reqv2.config.attrs[0].mask = 1;
|
||||
reqv2.num_lines = 1;
|
||||
|
||||
ret = ioctl(fd_gpiochip, GPIO_V2_GET_LINE_IOCTL, &reqv2);
|
||||
ret = ioctl(my.fd_gpiochip, GPIO_V2_GET_LINE_IOCTL, &reqv2);
|
||||
if (ret != -1)
|
||||
fd_linehandle = reqv2.fd;
|
||||
my.fd_linehandle = reqv2.fd;
|
||||
}
|
||||
#endif
|
||||
if (ret == -1) {
|
||||
@@ -254,11 +253,11 @@ static int linuxspi_open(PROGRAMMER *pgm, const char *pt) {
|
||||
return 0;
|
||||
|
||||
close_out:
|
||||
close(fd_linehandle);
|
||||
close(my.fd_linehandle);
|
||||
close_gpiochip:
|
||||
close(fd_gpiochip);
|
||||
close(my.fd_gpiochip);
|
||||
close_spidev:
|
||||
close(fd_spidev);
|
||||
close(my.fd_spidev);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -276,9 +275,9 @@ static void linuxspi_close(PROGRAMMER *pgm) {
|
||||
break;
|
||||
}
|
||||
|
||||
close(fd_linehandle);
|
||||
close(fd_spidev);
|
||||
close(fd_gpiochip);
|
||||
close(my.fd_linehandle);
|
||||
close(my.fd_spidev);
|
||||
close(my.fd_gpiochip);
|
||||
}
|
||||
|
||||
static void linuxspi_disable(const PROGRAMMER* pgm) {
|
||||
@@ -410,7 +409,7 @@ static int linuxspi_parseextparams(const PROGRAMMER *pgm, const LISTID extparms)
|
||||
extended_param = ldata(ln);
|
||||
|
||||
if (str_eq(extended_param, "disable_no_cs")) {
|
||||
PDATA(pgm)->disable_no_cs = 1;
|
||||
my.disable_no_cs = 1;
|
||||
continue;
|
||||
}
|
||||
if (str_eq(extended_param, "help")) {
|
||||
|
||||
Reference in New Issue
Block a user