Prusa Slicer 2.6.0
Loading...
Searching...
No Matches
bitbang.h File Reference
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

int bitbang_setpin (int fd, int pin, int value)
 
int bitbang_getpin (int fd, int pin)
 
int bitbang_highpulsepin (int fd, int pin)
 
void bitbang_delay (unsigned int us)
 
int bitbang_check_prerequisites (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)
 
void bitbang_powerup (PROGRAMMER *pgm)
 
void bitbang_powerdown (PROGRAMMER *pgm)
 
int bitbang_initialize (PROGRAMMER *pgm, AVRPART *p)
 
void bitbang_disable (PROGRAMMER *pgm)
 
void bitbang_enable (PROGRAMMER *pgm)
 

Function Documentation

◆ 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
char * progname
Definition main.c:61
int avrdude_message(const int msglvl, const char *format,...)
Definition main.c:93
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
#define MSG_NOTICE2
Definition avrdude.h:53
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}
static int delay_decrement
Definition bitbang.c:44

References delay_decrement.

Referenced by serbb_setpin().

+ Here is the caller graph for this function:

◆ bitbang_disable()

void bitbang_disable ( PROGRAMMER pgm)

◆ bitbang_enable()

void bitbang_enable ( PROGRAMMER pgm)

◆ 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_getpin()

int bitbang_getpin ( int  fd,
int  pin 
)

◆ bitbang_highpulsepin()

int bitbang_highpulsepin ( int  fd,
int  pin 
)

◆ 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_powerdown()

void bitbang_powerdown ( PROGRAMMER pgm)

◆ bitbang_powerup()

void bitbang_powerup ( PROGRAMMER pgm)

◆ 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_setpin()

int bitbang_setpin ( int  fd,
int  pin,
int  value 
)

◆ 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_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: