Prusa Slicer 2.6.0
Loading...
Searching...
No Matches
wiring.c File Reference
#include "ac_cfg.h"
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include "avrdude.h"
#include "libavrdude.h"
#include "stk500v2_private.h"
#include "stk500v2.h"
#include "wiring.h"
+ Include dependency graph for wiring.c:

Go to the source code of this file.

Classes

struct  wiringpdata
 

Macros

#define WIRINGPDATA(x)   ((struct wiringpdata *)(x))
 
#define STK500V2PDATA(pgm)   ((struct pdata *)(pgm->cookie))
 

Functions

static void wiring_setup (PROGRAMMER *pgm)
 
static void wiring_teardown (PROGRAMMER *pgm)
 
static int wiring_parseextparms (PROGRAMMER *pgm, LISTID extparms)
 
static int wiring_open (PROGRAMMER *pgm, char *port)
 
static void wiring_close (PROGRAMMER *pgm)
 
void wiring_initpgm (PROGRAMMER *pgm)
 

Variables

const char wiring_desc [] = "http://wiring.org.co/, Basically STK500v2 protocol, with some glue to trigger the bootloader."
 

Class Documentation

◆ wiringpdata

struct wiringpdata
Class Members
int snoozetime

Macro Definition Documentation

◆ STK500V2PDATA

#define STK500V2PDATA (   pgm)    ((struct pdata *)(pgm->cookie))

◆ WIRINGPDATA

#define WIRINGPDATA (   x)    ((struct wiringpdata *)(x))

Function Documentation

◆ wiring_close()

static void wiring_close ( PROGRAMMER pgm)
static
204{
207 pgm->fd.ifd = -1;
208}
#define serial_close
Definition libavrdude.h:576
#define serial_set_dtr_rts
Definition libavrdude.h:580
int ifd
Definition libavrdude.h:522
static PROGRAMMER * pgm
Definition main.c:192
union filedescriptor fd
Definition libavrdude.h:637

References programmer_t::fd, filedescriptor::ifd, pgm, serial_close, and serial_set_dtr_rts.

Referenced by wiring_initpgm().

+ Here is the caller graph for this function:

◆ wiring_initpgm()

void wiring_initpgm ( PROGRAMMER pgm)
213{
214 /* The Wiring bootloader uses a near-complete STK500v2 protocol. */
215
217
218 strcpy(pgm->type, "Wiring");
221
225}
void stk500v2_initpgm(PROGRAMMER *pgm)
Definition stk500v2.c:4418
int(* open)(struct programmer_t *pgm, char *port)
Definition libavrdude.h:657
void(* teardown)(struct programmer_t *pgm)
Definition libavrdude.h:685
int(* parseextparams)(struct programmer_t *pgm, LISTID xparams)
Definition libavrdude.h:683
void(* setup)(struct programmer_t *pgm)
Definition libavrdude.h:684
char type[PGM_TYPELEN]
Definition libavrdude.h:619
void(* close)(struct programmer_t *pgm)
Definition libavrdude.h:658
static int wiring_open(PROGRAMMER *pgm, char *port)
Definition wiring.c:147
static void wiring_setup(PROGRAMMER *pgm)
Definition wiring.c:75
static void wiring_teardown(PROGRAMMER *pgm)
Definition wiring.c:102
static void wiring_close(PROGRAMMER *pgm)
Definition wiring.c:203
static int wiring_parseextparms(PROGRAMMER *pgm, LISTID extparms)
Definition wiring.c:113

References programmer_t::close, programmer_t::open, programmer_t::parseextparams, pgm, programmer_t::setup, stk500v2_initpgm(), programmer_t::teardown, programmer_t::type, wiring_close(), wiring_open(), wiring_parseextparms(), wiring_setup(), and wiring_teardown().

+ Here is the call graph for this function:

◆ wiring_open()

static int wiring_open ( PROGRAMMER pgm,
char *  port 
)
static
148{
149 int timetosnooze;
150 void *mycookie = STK500V2PDATA(pgm)->chained_pdata;
151 union pinfo pinfo;
152
153 strcpy(pgm->port, port);
154 pinfo.baud = pgm->baudrate ? pgm->baudrate: 115200;
155 if (serial_open(port, pinfo, &pgm->fd) < 0) {
156 return -1;
157 }
158
159 /* If we have a snoozetime, then we wait and do NOT toggle DTR/RTS */
160
161 if (WIRINGPDATA(mycookie)->snoozetime > 0) {
162 timetosnooze = WIRINGPDATA(mycookie)->snoozetime;
163
164 avrdude_message(MSG_NOTICE2, "%s: wiring_open(): snoozing for %d ms\n",
165 progname, timetosnooze);
166 while (timetosnooze--)
167 usleep(1000);
168 avrdude_message(MSG_NOTICE2, "%s: wiring_open(): done snoozing\n",
169 progname);
170 } else {
171 /* Perform Wiring programming mode RESET. */
172 /* This effectively *releases* both DTR and RTS. */
173 /* i.e. both DTR and RTS rise to a HIGH logic level */
174 /* since they are active LOW signals. */
175
176 avrdude_message(MSG_NOTICE2, "%s: wiring_open(): releasing DTR/RTS\n",
177 progname);
178
180 usleep(50*1000);
181
182 /* After releasing for 50 milliseconds, DTR and RTS */
183 /* are asserted (i.e. logic LOW) again. */
184
185 avrdude_message(MSG_NOTICE2, "%s: wiring_open(): asserting DTR/RTS\n",
186 progname);
187
189 usleep(50*1000);
190 }
191
192 /* drain any extraneous input */
194
195 if (stk500v2_getsync(pgm) < 0) {
197 return -1;
198 }
199
200 return 0;
201}
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
#define serial_open
Definition libavrdude.h:574
long baud
Definition libavrdude.h:537
Definition libavrdude.h:536
int stk500v2_getsync(PROGRAMMER *pgm)
Definition stk500v2.c:749
int stk500v2_drain(PROGRAMMER *pgm, int display)
Definition stk500v2.c:530
char port[PGM_PORTLEN]
Definition libavrdude.h:620
int baudrate
Definition libavrdude.h:630
int usleep(unsigned usec)
Definition unistd.cpp:13
#define WIRINGPDATA(x)
Definition wiring.c:70
#define STK500V2PDATA(pgm)
Definition wiring.c:72

References avrdude_message(), pinfo::baud, programmer_t::baudrate, programmer_t::fd, MSG_NOTICE2, pgm, programmer_t::port, progname, serial_close, serial_open, serial_set_dtr_rts, stk500v2_drain(), stk500v2_getsync(), STK500V2PDATA, usleep(), and WIRINGPDATA.

Referenced by wiring_initpgm().

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

◆ wiring_parseextparms()

static int wiring_parseextparms ( PROGRAMMER pgm,
LISTID  extparms 
)
static
114{
115 LNODEID ln;
116 const char *extended_param;
117 int rv = 0;
118 void *mycookie = STK500V2PDATA(pgm)->chained_pdata;
119
120 for (ln = lfirst(extparms); ln; ln = lnext(ln)) {
121 extended_param = ldata(ln);
122
123 if (strncmp(extended_param, "snooze=", strlen("snooze=")) == 0) {
124 int newsnooze;
125 if (sscanf(extended_param, "snooze=%i", &newsnooze) != 1 ||
126 newsnooze < 0) {
127 avrdude_message(MSG_INFO, "%s: wiring_parseextparms(): invalid snooze time '%s'\n",
128 progname, extended_param);
129 rv = -1;
130 continue;
131 }
132 avrdude_message(MSG_NOTICE2, "%s: wiring_parseextparms(): snooze time set to %d ms\n",
133 progname, newsnooze);
134 WIRINGPDATA(mycookie)->snoozetime = newsnooze;
135
136 continue;
137 }
138
139 avrdude_message(MSG_INFO, "%s: wiring_parseextparms(): invalid extended parameter '%s'\n",
140 progname, extended_param);
141 rv = -1;
142 }
143
144 return rv;
145}
#define MSG_INFO
Definition avrdude.h:51
void * ldata(LNODEID)
Definition lists.c:720
void * LNODEID
Definition libavrdude.h:64
LNODEID lnext(LNODEID)
Definition lists.c:704
LNODEID lfirst(LISTID)
Definition lists.c:688

References avrdude_message(), ldata(), lfirst(), lnext(), MSG_INFO, MSG_NOTICE2, pgm, progname, STK500V2PDATA, and WIRINGPDATA.

Referenced by wiring_initpgm().

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

◆ wiring_setup()

static void wiring_setup ( PROGRAMMER pgm)
static
76{
77 void *mycookie;
78
79 /*
80 * First, have STK500v2 backend allocate its own private data.
81 */
83
84 /*
85 * Now prepare our data
86 */
87 if ((mycookie = malloc(sizeof(struct wiringpdata))) == 0) {
88 // avrdude_message(MSG_INFO, "%s: wiring_setup(): Out of memory allocating private data\n",
89 // progname);
90 // exit(1);
91 avrdude_oom("wiring_setup(): Out of memory allocating private data\n");
92 }
93 memset(mycookie, 0, sizeof(struct wiringpdata));
94 WIRINGPDATA(mycookie)->snoozetime = 0;
95
96 /*
97 * Store our own cookie in a safe place for the time being.
98 */
99 STK500V2PDATA(pgm)->chained_pdata = mycookie;
100}
void avrdude_oom(const char *context)
Definition main.c:169
void * malloc(YYSIZE_T)
void stk500v2_setup(PROGRAMMER *pgm)
Definition stk500v2.c:295
Definition wiring.c:59

References avrdude_oom(), malloc(), pgm, stk500v2_setup(), STK500V2PDATA, and WIRINGPDATA.

Referenced by wiring_initpgm().

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

◆ wiring_teardown()

static void wiring_teardown ( PROGRAMMER pgm)
static
103{
104 void *mycookie;
105
106 mycookie = STK500V2PDATA(pgm)->chained_pdata;
107
108 free(mycookie);
109
111}
void free(void *)
void stk500v2_teardown(PROGRAMMER *pgm)
Definition stk500v2.c:354

References free(), pgm, stk500v2_teardown(), and STK500V2PDATA.

Referenced by wiring_initpgm().

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

Variable Documentation

◆ wiring_desc

const char wiring_desc[] = "http://wiring.org.co/, Basically STK500v2 protocol, with some glue to trigger the bootloader."