Prusa Slicer 2.6.0
Loading...
Searching...
No Matches
bitbang.c File Reference
#include "ac_cfg.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <unistd.h>
#include <errno.h>
#include <signal.h>
#include <sys/time.h>
#include "avrdude.h"
#include "libavrdude.h"
#include "par.h"
#include "serbb.h"
#include "tpi.h"
#include "bitbang.h"
+ Include dependency graph for bitbang.c:

Go to the source code of this file.

Typedefs

typedef void(* mysighandler_t) (int)
 

Functions

static void alarmhandler (int signo)
 
static void bitbang_calibrate_delay (void)
 
void bitbang_delay (unsigned int us)
 
static unsigned char bitbang_txrx (PROGRAMMER *pgm, unsigned char byte)
 
static int bitbang_tpi_clk (PROGRAMMER *pgm)
 
void bitbang_tpi_tx (PROGRAMMER *pgm, unsigned char byte)
 
int bitbang_tpi_rx (PROGRAMMER *pgm)
 
int bitbang_rdy_led (PROGRAMMER *pgm, int value)
 
int bitbang_err_led (PROGRAMMER *pgm, int value)
 
int bitbang_pgm_led (PROGRAMMER *pgm, int value)
 
int bitbang_vfy_led (PROGRAMMER *pgm, int value)
 
int bitbang_cmd (PROGRAMMER *pgm, const unsigned char *cmd, unsigned char *res)
 
int bitbang_cmd_tpi (PROGRAMMER *pgm, const unsigned char *cmd, int cmd_len, unsigned char *res, int res_len)
 
int bitbang_spi (PROGRAMMER *pgm, const unsigned char *cmd, unsigned char *res, int count)
 
int bitbang_chip_erase (PROGRAMMER *pgm, AVRPART *p)
 
int bitbang_program_enable (PROGRAMMER *pgm, AVRPART *p)
 
int bitbang_initialize (PROGRAMMER *pgm, AVRPART *p)
 
static int verify_pin_assigned (PROGRAMMER *pgm, int pin, char *desc)
 
int bitbang_check_prerequisites (PROGRAMMER *pgm)
 

Variables

static int delay_decrement
 
static volatile int done
 
static mysighandler_t saved_alarmhandler
 

Typedef Documentation

◆ mysighandler_t

typedef void(* mysighandler_t) (int)

Function Documentation

◆ alarmhandler()

static void alarmhandler ( int  signo)
static
56{
57 done = 1;
58 signal(SIGALRM, saved_alarmhandler);
59}
static mysighandler_t saved_alarmhandler
Definition bitbang.c:53
static volatile int done
Definition bitbang.c:50

References done, and saved_alarmhandler.

Referenced by bitbang_calibrate_delay().

+ Here is the caller graph for this function:

◆ bitbang_calibrate_delay()

static void bitbang_calibrate_delay ( void  )
static
66{
67#if defined(WIN32NATIVE)
68 /*
69 * If the hardware supports a high-resolution performance counter,
70 * we ultimately prefer that one, as it gives quite accurate delays
71 * on modern high-speed CPUs.
72 */
73 if (QueryPerformanceFrequency(&freq))
74 {
75 has_perfcount = 1;
76 avrdude_message(MSG_NOTICE2, "%s: Using performance counter for bitbang delays\n",
77 progname);
78 }
79 else
80 {
81 /*
82 * If a high-resolution performance counter is not available, we
83 * don't have any Win32 implementation for setting up the
84 * per-microsecond delay count, so we can only run on a
85 * preconfigured delay stepping there. The figure below should at
86 * least be correct within an order of magnitude, judging from the
87 * auto-calibration figures seen on various Unix systems on
88 * comparable hardware.
89 */
90 avrdude_message(MSG_NOTICE2, "%s: Using guessed per-microsecond delay count for bitbang delays\n",
91 progname);
92 delay_decrement = 100;
93 }
94#else /* !WIN32NATIVE */
95 struct itimerval itv;
96 volatile int i;
97
98 avrdude_message(MSG_NOTICE2, "%s: Calibrating delay loop...",
99 progname);
100 i = 0;
101 done = 0;
102 saved_alarmhandler = signal(SIGALRM, alarmhandler);
103 /*
104 * Set ITIMER_REAL to 100 ms. All known systems have a timer
105 * granularity of 10 ms or better, so counting the delay cycles
106 * accumulating over 100 ms should give us a rather realistic
107 * picture, without annoying the user by a lengthy startup time (as
108 * an alarm(1) would do). Of course, if heavy system activity
109 * happens just during calibration but stops before the remaining
110 * part of AVRDUDE runs, this will yield wrong values. There's not
111 * much we can do about this.
112 */
113 itv.it_value.tv_sec = 0;
114 itv.it_value.tv_usec = 100000;
115 itv.it_interval.tv_sec = itv.it_interval.tv_usec = 0;
116 setitimer(ITIMER_REAL, &itv, 0);
117 while (!done)
118 i--;
119 itv.it_value.tv_sec = itv.it_value.tv_usec = 0;
120 setitimer(ITIMER_REAL, &itv, 0);
121 /*
122 * Calculate back from 100 ms to 1 us.
123 */
124 delay_decrement = -i / 100000;
125 avrdude_message(MSG_NOTICE2, " calibrated to %d cycles per us\n",
127#endif /* WIN32NATIVE */
128}
char * progname
Definition main.c:61
int avrdude_message(const int msglvl, const char *format,...)
Definition main.c:93
#define MSG_NOTICE2
Definition avrdude.h:53
static int delay_decrement
Definition bitbang.c:44
static void alarmhandler(int signo)
Definition bitbang.c:55

References alarmhandler(), avrdude_message(), delay_decrement, done, MSG_NOTICE2, progname, and saved_alarmhandler.

Referenced by bitbang_initialize().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ bitbang_check_prerequisites()

int bitbang_check_prerequisites ( PROGRAMMER pgm)
638{
639
640 if (verify_pin_assigned(pgm, PIN_AVR_RESET, "AVR RESET") < 0)
641 return -1;
642 if (verify_pin_assigned(pgm, PIN_AVR_SCK, "AVR SCK") < 0)
643 return -1;
644 if (verify_pin_assigned(pgm, PIN_AVR_MISO, "AVR MISO") < 0)
645 return -1;
646 if (verify_pin_assigned(pgm, PIN_AVR_MOSI, "AVR MOSI") < 0)
647 return -1;
648
649 if (pgm->cmd == NULL) {
650 avrdude_message(MSG_INFO, "%s: error: no cmd() method defined for bitbang programmer\n",
651 progname);
652 return -1;
653 }
654 return 0;
655}
#define MSG_INFO
Definition avrdude.h:51
static int verify_pin_assigned(PROGRAMMER *pgm, int pin, char *desc)
Definition bitbang.c:623
@ PIN_AVR_RESET
Definition libavrdude.h:355
@ PIN_AVR_MISO
Definition libavrdude.h:358
@ PIN_AVR_SCK
Definition libavrdude.h:356
@ PIN_AVR_MOSI
Definition libavrdude.h:357
static PROGRAMMER * pgm
Definition main.c:192
int(* cmd)(struct programmer_t *pgm, const unsigned char *cmd, unsigned char *res)
Definition libavrdude.h:651

References avrdude_message(), programmer_t::cmd, MSG_INFO, pgm, PIN_AVR_MISO, PIN_AVR_MOSI, PIN_AVR_RESET, PIN_AVR_SCK, progname, and verify_pin_assigned().

Referenced by buspirate_bb_enable(), and serbb_open().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ bitbang_chip_erase()

int bitbang_chip_erase ( PROGRAMMER pgm,
AVRPART p 
)
426{
427 unsigned char cmd[4];
428 unsigned char res[4];
429 AVRMEM *mem;
430
431 if (p->flags & AVRPART_HAS_TPI) {
432 pgm->pgm_led(pgm, ON);
433
434 while (avr_tpi_poll_nvmbsy(pgm));
435
436 /* NVMCMD <- CHIP_ERASE */
438 bitbang_tpi_tx(pgm, TPI_NVMCMD_CHIP_ERASE); /* CHIP_ERASE */
439
440 /* Set Pointer Register */
441 mem = avr_locate_mem(p, "flash");
442 if (mem == NULL) {
443 avrdude_message(MSG_INFO, "No flash memory to erase for part %s\n",
444 p->desc);
445 return -1;
446 }
448 bitbang_tpi_tx(pgm, (mem->offset & 0xFF) | 1); /* high byte */
450 bitbang_tpi_tx(pgm, (mem->offset >> 8) & 0xFF);
451
452 /* write dummy value to start erase */
454 bitbang_tpi_tx(pgm, 0xFF);
455
456 while (avr_tpi_poll_nvmbsy(pgm));
457
458 pgm->pgm_led(pgm, OFF);
459
460 return 0;
461 }
462
463 if (p->op[AVR_OP_CHIP_ERASE] == NULL) {
464 avrdude_message(MSG_INFO, "chip erase instruction not defined for part \"%s\"\n",
465 p->desc);
466 return -1;
467 }
468
469 pgm->pgm_led(pgm, ON);
470
471 memset(cmd, 0, sizeof(cmd));
472
474 pgm->cmd(pgm, cmd, res);
476 pgm->initialize(pgm, p);
477
478 pgm->pgm_led(pgm, OFF);
479
480 return 0;
481}
int avr_tpi_poll_nvmbsy(PROGRAMMER *pgm)
Definition avr.c:44
AVRMEM * avr_locate_mem(AVRPART *p, char *desc)
Definition avrpart.c:354
int avr_set_bits(OPCODE *op, unsigned char *cmd)
Definition avrpart.c:80
void bitbang_tpi_tx(PROGRAMMER *pgm, unsigned char byte)
Definition bitbang.c:220
#define OFF
Definition libavrdude.h:585
@ AVR_OP_CHIP_ERASE
Definition libavrdude.h:156
unsigned int offset
Definition libavrdude.h:289
int chip_erase_delay
Definition libavrdude.h:222
char desc[AVR_DESCLEN]
Definition libavrdude.h:218
OPCODE * op[AVR_OP_MAX]
Definition libavrdude.h:275
#define AVRPART_HAS_TPI
Definition libavrdude.h:206
#define ON
Definition libavrdude.h:584
unsigned flags
Definition libavrdude.h:230
Definition libavrdude.h:283
int(* pgm_led)(struct programmer_t *pgm, int value)
Definition libavrdude.h:641
int(* initialize)(struct programmer_t *pgm, AVRPART *p)
Definition libavrdude.h:643
struct command cmd[]
Definition term.c:94
#define TPI_CMD_SSTPR
Definition tpi.h:50
#define TPI_SIO_ADDR(x)
Definition tpi.h:54
#define TPI_IOREG_NVMCMD
Definition tpi.h:58
#define TPI_CMD_SST
Definition tpi.h:46
#define TPI_CMD_SOUT
Definition tpi.h:44
#define TPI_NVMCMD_CHIP_ERASE
Definition tpi.h:65
int usleep(unsigned usec)
Definition unistd.cpp:13

References avr_locate_mem(), AVR_OP_CHIP_ERASE, avr_set_bits(), avr_tpi_poll_nvmbsy(), avrdude_message(), AVRPART_HAS_TPI, bitbang_tpi_tx(), avrpart::chip_erase_delay, programmer_t::cmd, cmd, avrpart::desc, avrpart::flags, programmer_t::initialize, MSG_INFO, OFF, avrmem::offset, ON, avrpart::op, pgm, programmer_t::pgm_led, TPI_CMD_SOUT, TPI_CMD_SST, TPI_CMD_SSTPR, TPI_IOREG_NVMCMD, TPI_NVMCMD_CHIP_ERASE, TPI_SIO_ADDR, and usleep().

Referenced by buspirate_bb_initpgm(), and serbb_initpgm().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ bitbang_cmd()

int bitbang_cmd ( PROGRAMMER pgm,
const unsigned char *  cmd,
unsigned char *  res 
)
327{
328 int i;
329
330 for (i=0; i<4; i++) {
331 res[i] = bitbang_txrx(pgm, cmd[i]);
332 }
333
334 if(verbose >= 2)
335 {
336 avrdude_message(MSG_NOTICE2, "bitbang_cmd(): [ ");
337 for(i = 0; i < 4; i++)
338 avrdude_message(MSG_NOTICE2, "%02X ", cmd[i]);
340 for(i = 0; i < 4; i++)
341 {
342 avrdude_message(MSG_NOTICE2, "%02X ", res[i]);
343 }
345 }
346
347 return 0;
348}
int verbose
Definition main.c:198
static unsigned char bitbang_txrx(PROGRAMMER *pgm, unsigned char byte)
Definition bitbang.c:163

References avrdude_message(), bitbang_txrx(), cmd, MSG_NOTICE2, pgm, and verbose.

Referenced by buspirate_bb_initpgm(), and serbb_initpgm().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ bitbang_cmd_tpi()

int bitbang_cmd_tpi ( PROGRAMMER pgm,
const unsigned char *  cmd,
int  cmd_len,
unsigned char *  res,
int  res_len 
)
352{
353 int i, r;
354
355 pgm->pgm_led(pgm, ON);
356
357 for (i=0; i<cmd_len; i++) {
359 }
360
361 r = 0;
362 for (i=0; i<res_len; i++) {
363 r = bitbang_tpi_rx(pgm);
364 if (r == -1)
365 break;
366 res[i] = r;
367 }
368
369 if(verbose >= 2)
370 {
371 avrdude_message(MSG_NOTICE2, "bitbang_cmd_tpi(): [ ");
372 for(i = 0; i < cmd_len; i++)
373 avrdude_message(MSG_NOTICE2, "%02X ", cmd[i]);
375 for(i = 0; i < res_len; i++)
376 {
377 avrdude_message(MSG_NOTICE2, "%02X ", res[i]);
378 }
380 }
381
382 pgm->pgm_led(pgm, OFF);
383 if (r == -1)
384 return -1;
385 return 0;
386}
int bitbang_tpi_rx(PROGRAMMER *pgm)
Definition bitbang.c:249

References avrdude_message(), bitbang_tpi_rx(), bitbang_tpi_tx(), cmd, MSG_NOTICE2, OFF, ON, pgm, programmer_t::pgm_led, and verbose.

Referenced by buspirate_bb_initpgm(), and serbb_initpgm().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ bitbang_delay()

void bitbang_delay ( unsigned int  us)
136{
137#if defined(WIN32NATIVE)
138 LARGE_INTEGER countNow, countEnd;
139
140 if (has_perfcount)
141 {
142 QueryPerformanceCounter(&countNow);
143 countEnd.QuadPart = countNow.QuadPart + freq.QuadPart * us / 1000000ll;
144
145 while (countNow.QuadPart < countEnd.QuadPart)
146 QueryPerformanceCounter(&countNow);
147 }
148 else /* no performance counters -- run normal uncalibrated delay */
149 {
150#endif /* WIN32NATIVE */
151 volatile unsigned int del = us * delay_decrement;
152
153 while (del > 0)
154 del--;
155#if defined(WIN32NATIVE)
156 }
157#endif /* WIN32NATIVE */
158}

References delay_decrement.

Referenced by serbb_setpin().

+ Here is the caller graph for this function:

◆ bitbang_err_led()

int bitbang_err_led ( PROGRAMMER pgm,
int  value 
)
303{
304 pgm->setpin(pgm, PIN_LED_ERR, !value);
305 return 0;
306}
@ PIN_LED_ERR
Definition libavrdude.h:359
int(* setpin)(struct programmer_t *pgm, int pinfunc, int value)
Definition libavrdude.h:678

References pgm, PIN_LED_ERR, and programmer_t::setpin.

Referenced by buspirate_bb_initpgm(), and serbb_initpgm().

+ Here is the caller graph for this function:

◆ bitbang_initialize()

int bitbang_initialize ( PROGRAMMER pgm,
AVRPART p 
)
524{
525 int rc;
526 int tries;
527 int i;
528
530
531 pgm->powerup(pgm);
532 usleep(20000);
533
534 /* TPIDATA is a single line, so MISO & MOSI should be connected */
535 if (p->flags & AVRPART_HAS_TPI) {
536 /* make sure cmd_tpi() is defined */
537 if (pgm->cmd_tpi == NULL) {
538 avrdude_message(MSG_INFO, "%s: Error: %s programmer does not support TPI\n",
539 progname, pgm->type);
540 return -1;
541 }
542
543 /* bring RESET high first */
545 usleep(1000);
546
547 avrdude_message(MSG_NOTICE2, "doing MOSI-MISO link check\n");
548
550 if (pgm->getpin(pgm, PIN_AVR_MISO) != 0) {
551 avrdude_message(MSG_INFO, "MOSI->MISO 0 failed\n");
552 return -1;
553 }
555 if (pgm->getpin(pgm, PIN_AVR_MISO) != 1) {
556 avrdude_message(MSG_INFO, "MOSI->MISO 1 failed\n");
557 return -1;
558 }
559
560 avrdude_message(MSG_NOTICE2, "MOSI-MISO link present\n");
561 }
562
565 usleep(20000);
566
567 if (p->flags & AVRPART_HAS_TPI) {
568 /* keep TPIDATA high for 16 clock cycles */
570 for (i = 0; i < 16; i++)
572
573 /* remove extra guard timing bits */
575 bitbang_tpi_tx(pgm, 0x7);
576
577 /* read TPI ident reg */
579 rc = bitbang_tpi_rx(pgm);
580 if (rc != 0x80) {
581 avrdude_message(MSG_INFO, "TPIIR not correct\n");
582 return -1;
583 }
584 } else {
586 }
587
588 usleep(20000); /* 20 ms XXX should be a per-chip parameter */
589
590 /*
591 * Enable programming mode. If we are programming an AT90S1200, we
592 * can only issue the command and hope it worked. If we are using
593 * one of the other chips, the chip will echo 0x53 when issuing the
594 * third byte of the command. In this case, try up to 32 times in
595 * order to possibly get back into sync with the chip if we are out
596 * of sync.
597 */
598 if (p->flags & AVRPART_IS_AT90S1200) {
600 }
601 else {
602 tries = 0;
603 do {
604 rc = pgm->program_enable(pgm, p);
605 if ((rc == 0)||(rc == -1))
606 break;
607 pgm->highpulsepin(pgm, p->retry_pulse/*PIN_AVR_SCK*/);
608 tries++;
609 } while (tries < 65);
610
611 /*
612 * can't sync with the device, maybe it's not attached?
613 */
614 if (rc) {
615 avrdude_message(MSG_INFO, "%s: AVR device not responding\n", progname);
616 return -1;
617 }
618 }
619
620 return 0;
621}
static void bitbang_calibrate_delay(void)
Definition bitbang.c:65
#define AVRPART_IS_AT90S1200
Definition libavrdude.h:207
int retry_pulse
Definition libavrdude.h:228
void(* powerup)(struct programmer_t *pgm)
Definition libavrdude.h:647
int(* getpin)(struct programmer_t *pgm, int pinfunc)
Definition libavrdude.h:679
int(* cmd_tpi)(struct programmer_t *pgm, const unsigned char *cmd, int cmd_len, unsigned char res[], int res_len)
Definition libavrdude.h:653
int(* highpulsepin)(struct programmer_t *pgm, int pinfunc)
Definition libavrdude.h:680
int(* program_enable)(struct programmer_t *pgm, AVRPART *p)
Definition libavrdude.h:649
char type[PGM_TYPELEN]
Definition libavrdude.h:619
#define TPI_REG_TPIPCR
Definition tpi.h:35
#define TPI_CMD_SLDCS
Definition tpi.h:49
#define TPI_REG_TPIIR
Definition tpi.h:31
#define TPI_CMD_SSTCS
Definition tpi.h:45

References avrdude_message(), AVRPART_HAS_TPI, AVRPART_IS_AT90S1200, bitbang_calibrate_delay(), bitbang_tpi_rx(), bitbang_tpi_tx(), programmer_t::cmd_tpi, avrpart::flags, programmer_t::getpin, programmer_t::highpulsepin, MSG_INFO, MSG_NOTICE2, pgm, PIN_AVR_MISO, PIN_AVR_MOSI, PIN_AVR_RESET, PIN_AVR_SCK, programmer_t::powerup, progname, programmer_t::program_enable, avrpart::retry_pulse, programmer_t::setpin, TPI_CMD_SLDCS, TPI_CMD_SSTCS, TPI_REG_TPIIR, TPI_REG_TPIPCR, programmer_t::type, and usleep().

Referenced by buspirate_bb_initpgm(), and serbb_initpgm().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ bitbang_pgm_led()

int bitbang_pgm_led ( PROGRAMMER pgm,
int  value 
)
309{
310 pgm->setpin(pgm, PIN_LED_PGM, !value);
311 return 0;
312}
@ PIN_LED_PGM
Definition libavrdude.h:361

References pgm, PIN_LED_PGM, and programmer_t::setpin.

Referenced by buspirate_bb_initpgm(), and serbb_initpgm().

+ Here is the caller graph for this function:

◆ bitbang_program_enable()

int bitbang_program_enable ( PROGRAMMER pgm,
AVRPART p 
)
487{
488 unsigned char cmd[4];
489 unsigned char res[4];
490 int i;
491
492 if (p->flags & AVRPART_HAS_TPI) {
493 /* enable NVM programming */
495 for (i = sizeof(tpi_skey) - 1; i >= 0; i--)
497
498 /* check NVMEN bit */
500 i = bitbang_tpi_rx(pgm);
501 return (i != -1 && (i & TPI_REG_TPISR_NVMEN)) ? 0 : -2;
502 }
503
504 if (p->op[AVR_OP_PGM_ENABLE] == NULL) {
505 avrdude_message(MSG_INFO, "program enable instruction not defined for part \"%s\"\n",
506 p->desc);
507 return -1;
508 }
509
510 memset(cmd, 0, sizeof(cmd));
512 pgm->cmd(pgm, cmd, res);
513
514 if (res[2] != cmd[1])
515 return -2;
516
517 return 0;
518}
@ AVR_OP_PGM_ENABLE
Definition libavrdude.h:157
#define TPI_REG_TPISR_NVMEN
Definition tpi.h:38
#define TPI_REG_TPISR
Definition tpi.h:36
#define TPI_CMD_SKEY
Definition tpi.h:51
static const unsigned char tpi_skey[]
Definition tpi.h:28

References AVR_OP_PGM_ENABLE, avr_set_bits(), avrdude_message(), AVRPART_HAS_TPI, bitbang_tpi_rx(), bitbang_tpi_tx(), programmer_t::cmd, cmd, avrpart::desc, avrpart::flags, MSG_INFO, avrpart::op, pgm, TPI_CMD_SKEY, TPI_CMD_SLDCS, TPI_REG_TPISR, TPI_REG_TPISR_NVMEN, and tpi_skey.

Referenced by buspirate_bb_initpgm(), and serbb_initpgm().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ bitbang_rdy_led()

int bitbang_rdy_led ( PROGRAMMER pgm,
int  value 
)
297{
298 pgm->setpin(pgm, PIN_LED_RDY, !value);
299 return 0;
300}
@ PIN_LED_RDY
Definition libavrdude.h:360

References pgm, PIN_LED_RDY, and programmer_t::setpin.

Referenced by buspirate_bb_initpgm(), and serbb_initpgm().

+ Here is the caller graph for this function:

◆ bitbang_spi()

int bitbang_spi ( PROGRAMMER pgm,
const unsigned char *  cmd,
unsigned char *  res,
int  count 
)
394{
395 int i;
396
398
399 for (i=0; i<count; i++) {
400 res[i] = bitbang_txrx(pgm, cmd[i]);
401 }
402
404
405 if(verbose >= 2)
406 {
407 avrdude_message(MSG_NOTICE2, "bitbang_cmd(): [ ");
408 for(i = 0; i < count; i++)
409 avrdude_message(MSG_NOTICE2, "%02X ", cmd[i]);
411 for(i = 0; i < count; i++)
412 {
413 avrdude_message(MSG_NOTICE2, "%02X ", res[i]);
414 }
416 }
417
418 return 0;
419}
IGL_INLINE void count(const Eigen::SparseMatrix< XType > &X, const int dim, Eigen::SparseVector< SType > &S)
Definition count.cpp:12

References avrdude_message(), bitbang_txrx(), cmd, MSG_NOTICE2, pgm, PIN_LED_PGM, programmer_t::setpin, and verbose.

+ Here is the call graph for this function:

◆ bitbang_tpi_clk()

static int bitbang_tpi_clk ( PROGRAMMER pgm)
static
209{
210 unsigned char r = 0;
212
213 r = pgm->getpin(pgm, PIN_AVR_MISO);
214
216
217 return r;
218}

References programmer_t::getpin, pgm, PIN_AVR_MISO, PIN_AVR_SCK, and programmer_t::setpin.

Referenced by bitbang_tpi_rx(), and bitbang_tpi_tx().

+ Here is the caller graph for this function:

◆ bitbang_tpi_rx()

int bitbang_tpi_rx ( PROGRAMMER pgm)
250{
251 int i;
252 unsigned char b, rbyte, parity;
253
254 /* make sure pin is on for "pullup" */
256
257 /* wait for start bit (up to 10 bits) */
258 b = 1;
259 for (i = 0; i < 10; i++) {
261 if (b == 0)
262 break;
263 }
264 if (b != 0) {
265 avrdude_message(MSG_INFO, "bitbang_tpi_rx: start bit not received correctly\n");
266 return -1;
267 }
268
269 rbyte = 0;
270 parity = 0;
271 for (i=0; i<=7; i++) {
273 parity ^= b;
274
275 rbyte |= b << i;
276 }
277
278 /* parity bit */
279 if (bitbang_tpi_clk(pgm) != parity) {
280 avrdude_message(MSG_INFO, "bitbang_tpi_rx: parity bit is wrong\n");
281 return -1;
282 }
283
284 /* 2 stop bits */
285 b = 1;
288 if (b != 1) {
289 avrdude_message(MSG_INFO, "bitbang_tpi_rx: stop bits not received correctly\n");
290 return -1;
291 }
292
293 return rbyte;
294}
static int bitbang_tpi_clk(PROGRAMMER *pgm)
Definition bitbang.c:208

References avrdude_message(), bitbang_tpi_clk(), MSG_INFO, pgm, PIN_AVR_MOSI, and programmer_t::setpin.

Referenced by bitbang_cmd_tpi(), bitbang_initialize(), and bitbang_program_enable().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ bitbang_tpi_tx()

void bitbang_tpi_tx ( PROGRAMMER pgm,
unsigned char  byte 
)
221{
222 int i;
223 unsigned char b, parity;
224
225 /* start bit */
228
229 parity = 0;
230 for (i = 0; i <= 7; i++) {
231 b = (byte >> i) & 0x01;
232 parity ^= b;
233
234 /* set the data input line as desired */
237 }
238
239 /* parity bit */
240 pgm->setpin(pgm, PIN_AVR_MOSI, parity);
242
243 /* 2 stop bits */
247}

References bitbang_tpi_clk(), pgm, PIN_AVR_MOSI, and programmer_t::setpin.

Referenced by bitbang_chip_erase(), bitbang_cmd_tpi(), bitbang_initialize(), and bitbang_program_enable().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ bitbang_txrx()

static unsigned char bitbang_txrx ( PROGRAMMER pgm,
unsigned char  byte 
)
static
164{
165 int i;
166 unsigned char r, b, rbyte;
167
168 rbyte = 0;
169 for (i=7; i>=0; i--) {
170 /*
171 * Write and read one bit on SPI.
172 * Some notes on timing: Let T be the time it takes to do
173 * one pgm->setpin()-call resp. par clrpin()-call, then
174 * - SCK is high for 2T
175 * - SCK is low for 2T
176 * - MOSI setuptime is 1T
177 * - MOSI holdtime is 3T
178 * - SCK low to MISO read is 2T to 3T
179 * So we are within programming specs (expect for AT90S1200),
180 * if and only if T>t_CLCL (t_CLCL=clock period of target system).
181 *
182 * Due to the delay introduced by "IN" and "OUT"-commands,
183 * T is greater than 1us (more like 2us) on x86-architectures.
184 * So programming works safely down to 1MHz target clock.
185 */
186
187 b = (byte >> i) & 0x01;
188
189 /* set the data input line as desired */
191
193
194 /*
195 * read the result bit (it is either valid from a previous falling
196 * edge or it is ignored in the current context)
197 */
198 r = pgm->getpin(pgm, PIN_AVR_MISO);
199
201
202 rbyte |= r << i;
203 }
204
205 return rbyte;
206}

References programmer_t::getpin, pgm, PIN_AVR_MISO, PIN_AVR_MOSI, PIN_AVR_SCK, and programmer_t::setpin.

Referenced by bitbang_cmd(), and bitbang_spi().

+ Here is the caller graph for this function:

◆ bitbang_vfy_led()

int bitbang_vfy_led ( PROGRAMMER pgm,
int  value 
)
315{
316 pgm->setpin(pgm, PIN_LED_VFY, !value);
317 return 0;
318}
@ PIN_LED_VFY
Definition libavrdude.h:362

References pgm, PIN_LED_VFY, and programmer_t::setpin.

Referenced by buspirate_bb_initpgm(), and serbb_initpgm().

+ Here is the caller graph for this function:

◆ verify_pin_assigned()

static int verify_pin_assigned ( PROGRAMMER pgm,
int  pin,
char *  desc 
)
static
624{
625 if (pgm->pinno[pin] == 0) {
626 avrdude_message(MSG_INFO, "%s: error: no pin has been assigned for %s\n",
627 progname, desc);
628 return -1;
629 }
630 return 0;
631}
unsigned int pinno[N_PINS]
Definition libavrdude.h:622

References avrdude_message(), MSG_INFO, pgm, programmer_t::pinno, and progname.

Referenced by bitbang_check_prerequisites().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Variable Documentation

◆ delay_decrement

int delay_decrement
static

◆ done

◆ saved_alarmhandler

mysighandler_t saved_alarmhandler
static