mirror of
https://github.com/avrdudes/avrdude.git
synced 2026-09-21 16:46:30 +03:00
Reformat spacing/comments in src/ppi.c
This commit is contained in:
131
src/ppi.c
131
src/ppi.c
@@ -16,13 +16,10 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
#if !defined(WIN32)
|
||||
|
||||
#include <ac_cfg.h>
|
||||
|
||||
#if HAVE_PARPORT
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
@@ -31,11 +28,11 @@
|
||||
#include <errno.h>
|
||||
|
||||
#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
|
||||
# include "freebsd_ppi.h"
|
||||
#include "freebsd_ppi.h"
|
||||
#elif defined(__linux__)
|
||||
# include "linux_ppdev.h"
|
||||
#elif defined(__sun__) || defined(__sun) /* Solaris */
|
||||
# include "solaris_ecpp.h"
|
||||
#include "linux_ppdev.h"
|
||||
#elif defined(__sun__) || defined(__sun) // Solaris
|
||||
#include "solaris_ecpp.h"
|
||||
#endif
|
||||
|
||||
#include "avrdude.h"
|
||||
@@ -49,46 +46,42 @@ enum {
|
||||
PPI_SHADOWREAD
|
||||
};
|
||||
|
||||
static int ppi_shadow_access(const union filedescriptor *fdp, int reg,
|
||||
unsigned char *v, unsigned char action)
|
||||
{
|
||||
static int ppi_shadow_access(const union filedescriptor *fdp, int reg, unsigned char *v, unsigned char action) {
|
||||
int shadow_num;
|
||||
|
||||
switch (reg) {
|
||||
case PPIDATA:
|
||||
shadow_num = 0;
|
||||
break;
|
||||
case PPICTRL:
|
||||
shadow_num = 1;
|
||||
break;
|
||||
case PPISTATUS:
|
||||
shadow_num = 2;
|
||||
break;
|
||||
default:
|
||||
pmsg_error("invalid register=%d\n", reg);
|
||||
return -1;
|
||||
break;
|
||||
case PPIDATA:
|
||||
shadow_num = 0;
|
||||
break;
|
||||
case PPICTRL:
|
||||
shadow_num = 1;
|
||||
break;
|
||||
case PPISTATUS:
|
||||
shadow_num = 2;
|
||||
break;
|
||||
default:
|
||||
pmsg_error("invalid register=%d\n", reg);
|
||||
return -1;
|
||||
break;
|
||||
}
|
||||
|
||||
switch (action) {
|
||||
case PPI_SHADOWREAD:
|
||||
*v = cx->ppi_shadow[shadow_num];
|
||||
break;
|
||||
case PPI_READ:
|
||||
DO_PPI_READ(fdp->ifd, reg, v);
|
||||
cx->ppi_shadow[shadow_num]=*v;
|
||||
break;
|
||||
case PPI_WRITE:
|
||||
cx->ppi_shadow[shadow_num]=*v;
|
||||
DO_PPI_WRITE(fdp->ifd, reg, v);
|
||||
break;
|
||||
case PPI_SHADOWREAD:
|
||||
*v = cx->ppi_shadow[shadow_num];
|
||||
break;
|
||||
case PPI_READ:
|
||||
DO_PPI_READ(fdp->ifd, reg, v);
|
||||
cx->ppi_shadow[shadow_num] = *v;
|
||||
break;
|
||||
case PPI_WRITE:
|
||||
cx->ppi_shadow[shadow_num] = *v;
|
||||
DO_PPI_WRITE(fdp->ifd, reg, v);
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* set the indicated bit of the specified register.
|
||||
*/
|
||||
// Set the indicated bit of the specified register
|
||||
int ppi_set(const union filedescriptor *fdp, int reg, int bit) {
|
||||
unsigned char v;
|
||||
int rc;
|
||||
@@ -97,16 +90,13 @@ int ppi_set(const union filedescriptor *fdp, int reg, int bit) {
|
||||
v |= bit;
|
||||
rc |= ppi_shadow_access(fdp, reg, &v, PPI_WRITE);
|
||||
|
||||
if (rc)
|
||||
if(rc)
|
||||
return -1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* clear the indicated bit of the specified register.
|
||||
*/
|
||||
// Clear the indicated bit of the specified register
|
||||
int ppi_clr(const union filedescriptor *fdp, int reg, int bit) {
|
||||
unsigned char v;
|
||||
int rc;
|
||||
@@ -115,16 +105,13 @@ int ppi_clr(const union filedescriptor *fdp, int reg, int bit) {
|
||||
v &= ~bit;
|
||||
rc |= ppi_shadow_access(fdp, reg, &v, PPI_WRITE);
|
||||
|
||||
if (rc)
|
||||
if(rc)
|
||||
return -1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* get the indicated bit of the specified register.
|
||||
*/
|
||||
// Get the indicated bit of the specified register
|
||||
int ppi_get(const union filedescriptor *fdp, int reg, int bit) {
|
||||
unsigned char v;
|
||||
int rc;
|
||||
@@ -132,15 +119,13 @@ int ppi_get(const union filedescriptor *fdp, int reg, int bit) {
|
||||
rc = ppi_shadow_access(fdp, reg, &v, PPI_READ);
|
||||
v &= bit;
|
||||
|
||||
if (rc)
|
||||
if(rc)
|
||||
return -1;
|
||||
|
||||
return v; /* v == bit */
|
||||
return v; // v == bit
|
||||
}
|
||||
|
||||
/*
|
||||
* toggle the indicated bit of the specified register.
|
||||
*/
|
||||
// Toggle the indicated bit of the specified register
|
||||
int ppi_toggle(const union filedescriptor *fdp, int reg, int bit) {
|
||||
unsigned char v;
|
||||
int rc;
|
||||
@@ -149,31 +134,26 @@ int ppi_toggle(const union filedescriptor *fdp, int reg, int bit) {
|
||||
v ^= bit;
|
||||
rc |= ppi_shadow_access(fdp, reg, &v, PPI_WRITE);
|
||||
|
||||
if (rc)
|
||||
if(rc)
|
||||
return -1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* get all bits of the specified register.
|
||||
*/
|
||||
// Get all bits of the specified register
|
||||
int ppi_getall(const union filedescriptor *fdp, int reg) {
|
||||
unsigned char v;
|
||||
int rc;
|
||||
|
||||
rc = ppi_shadow_access(fdp, reg, &v, PPI_READ);
|
||||
|
||||
if (rc)
|
||||
if(rc)
|
||||
return -1;
|
||||
|
||||
return v; /* v == bit */
|
||||
return v; // v == bit
|
||||
}
|
||||
|
||||
/*
|
||||
* set all bits of the specified register to val.
|
||||
*/
|
||||
// Set all bits of the specified register to val
|
||||
int ppi_setall(const union filedescriptor *fdp, int reg, int val) {
|
||||
unsigned char v;
|
||||
int rc;
|
||||
@@ -181,43 +161,36 @@ int ppi_setall(const union filedescriptor *fdp, int reg, int val) {
|
||||
v = val;
|
||||
rc = ppi_shadow_access(fdp, reg, &v, PPI_WRITE);
|
||||
|
||||
if (rc)
|
||||
if(rc)
|
||||
return -1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
void ppi_open(const char *port, union filedescriptor *fdp) {
|
||||
int fd;
|
||||
unsigned char v;
|
||||
|
||||
fd = open(port, O_RDWR);
|
||||
if (fd < 0) {
|
||||
if(fd < 0) {
|
||||
pmsg_ext_error("cannot open port %s: %s\n", port, strerror(errno));
|
||||
fdp->ifd = -1;
|
||||
return;
|
||||
}
|
||||
|
||||
ppi_claim (fd);
|
||||
ppi_claim(fd);
|
||||
|
||||
/*
|
||||
* Initialize shadow registers
|
||||
*/
|
||||
|
||||
ppi_shadow_access (fdp, PPIDATA, &v, PPI_READ);
|
||||
ppi_shadow_access (fdp, PPICTRL, &v, PPI_READ);
|
||||
ppi_shadow_access (fdp, PPISTATUS, &v, PPI_READ);
|
||||
// Initialize shadow registers
|
||||
ppi_shadow_access(fdp, PPIDATA, &v, PPI_READ);
|
||||
ppi_shadow_access(fdp, PPICTRL, &v, PPI_READ);
|
||||
ppi_shadow_access(fdp, PPISTATUS, &v, PPI_READ);
|
||||
|
||||
fdp->ifd = fd;
|
||||
}
|
||||
|
||||
|
||||
void ppi_close(const union filedescriptor *fdp) {
|
||||
ppi_release (fdp->ifd);
|
||||
ppi_release(fdp->ifd);
|
||||
close(fdp->ifd);
|
||||
}
|
||||
|
||||
#endif /* HAVE_PARPORT */
|
||||
|
||||
#endif /* !WIN32 */
|
||||
#endif // HAVE_PARPORT
|
||||
#endif // ! WIN32
|
||||
|
||||
Reference in New Issue
Block a user