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

Go to the source code of this file.

Functions

static int pgm_default_2 (struct programmer_t *, AVRPART *)
 
static int pgm_default_3 (struct programmer_t *pgm, AVRPART *p, AVRMEM *mem, unsigned long addr, unsigned char *value)
 
static void pgm_default_4 (struct programmer_t *)
 
static int pgm_default_5 (struct programmer_t *pgm, AVRPART *p, AVRMEM *mem, unsigned long addr, unsigned char data)
 
static void pgm_default_6 (struct programmer_t *, const char *)
 
static int pgm_default_open (struct programmer_t *pgm, char *name)
 
static int pgm_default_led (struct programmer_t *pgm, int value)
 
static void pgm_default_powerup_powerdown (struct programmer_t *pgm)
 
PROGRAMMERpgm_new (void)
 
void pgm_free (PROGRAMMER *const p)
 
PROGRAMMERpgm_dup (const PROGRAMMER *const src)
 
static void pgm_default (void)
 
void programmer_display (PROGRAMMER *pgm, const char *p)
 
void pgm_display_generic_mask (PROGRAMMER *pgm, const char *p, unsigned int show)
 
void pgm_display_generic (PROGRAMMER *pgm, const char *p)
 
PROGRAMMERlocate_programmer (LISTID programmers, const char *configid)
 
void walk_programmers (LISTID programmers, walk_programmers_cb cb, void *cookie)
 
static int sort_programmer_compare (PROGRAMMER *p1, PROGRAMMER *p2)
 
void sort_programmers (LISTID programmers)
 

Function Documentation

◆ locate_programmer()

PROGRAMMER * locate_programmer ( LISTID  programmers,
const char *  configid 
)
264{
265 LNODEID ln1, ln2;
266 PROGRAMMER * p = NULL;
267 const char * id;
268 int found;
269
270 found = 0;
271
272 for (ln1=lfirst(programmers); ln1 && !found; ln1=lnext(ln1)) {
273 p = ldata(ln1);
274 for (ln2=lfirst(p->id); ln2 && !found; ln2=lnext(ln2)) {
275 id = ldata(ln2);
276 if (strcasecmp(configid, id) == 0)
277 found = 1;
278 }
279 }
280
281 if (found)
282 return p;
283
284 return NULL;
285}
LISTID programmers
Definition config.c:52
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
Definition libavrdude.h:616
LISTID id
Definition libavrdude.h:617
#define strcasecmp
Definition unistd.h:52

References programmer_t::id, ldata(), lfirst(), lnext(), programmers, and strcasecmp.

Referenced by avrdude_main(), and yyparse().

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

◆ pgm_default()

static void pgm_default ( void  )
static
189{
190 avrdude_message(MSG_INFO, "%s: programmer operation not supported\n", progname);
191}
#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

References avrdude_message(), MSG_INFO, and progname.

Referenced by pgm_default_2(), pgm_default_3(), pgm_default_4(), pgm_default_5(), and pgm_default_6().

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

◆ pgm_default_2()

static int pgm_default_2 ( struct programmer_t pgm,
AVRPART p 
)
static
195{
196 pgm_default();
197 return -1;
198}
static void pgm_default(void)
Definition pgm.c:188

References pgm_default().

Referenced by pgm_new().

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

◆ pgm_default_3()

static int pgm_default_3 ( struct programmer_t pgm,
AVRPART p,
AVRMEM mem,
unsigned long  addr,
unsigned char *  value 
)
static
202{
203 pgm_default();
204 return -1;
205}

References pgm_default().

Referenced by pgm_new().

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

◆ pgm_default_4()

static void pgm_default_4 ( struct programmer_t pgm)
static
208{
209 pgm_default();
210}

References pgm_default().

Referenced by pgm_new().

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

◆ pgm_default_5()

static int pgm_default_5 ( struct programmer_t pgm,
AVRPART p,
AVRMEM mem,
unsigned long  addr,
unsigned char  data 
)
static
214{
215 pgm_default();
216 return -1;
217}

References pgm_default().

Referenced by pgm_new().

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

◆ pgm_default_6()

static void pgm_default_6 ( struct programmer_t pgm,
const char *  p 
)
static
220{
221 pgm_default();
222}

References pgm_default().

Referenced by pgm_new().

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

◆ pgm_default_led()

static int pgm_default_led ( struct programmer_t pgm,
int  value 
)
static
48{
49 /*
50 * If programmer has no LEDs, just do nothing.
51 */
52 return 0;
53}

Referenced by pgm_new().

+ Here is the caller graph for this function:

◆ pgm_default_open()

static int pgm_default_open ( struct programmer_t pgm,
char *  name 
)
static
41{
42 avrdude_message(MSG_INFO, "\n%s: Fatal error: Programmer does not support open()",
43 progname);
44 return -1;
45}

References avrdude_message(), MSG_INFO, and progname.

Referenced by pgm_new().

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

◆ pgm_default_powerup_powerdown()

static void pgm_default_powerup_powerdown ( struct programmer_t pgm)
static
57{
58 /*
59 * If programmer does not support powerup/down, just do nothing.
60 */
61}

Referenced by pgm_new().

+ Here is the caller graph for this function:

◆ pgm_display_generic()

void pgm_display_generic ( PROGRAMMER pgm,
const char *  p 
)
259{
261}
#define SHOW_ALL_PINS
Definition libavrdude.h:704
static PROGRAMMER * pgm
Definition main.c:192
void pgm_display_generic_mask(PROGRAMMER *pgm, const char *p, unsigned int show)
Definition pgm.c:234

References pgm, pgm_display_generic_mask(), and SHOW_ALL_PINS.

+ Here is the call graph for this function:

◆ pgm_display_generic_mask()

void pgm_display_generic_mask ( PROGRAMMER pgm,
const char *  p,
unsigned int  show 
)
235{
236 if(show & (1<<PPI_AVR_VCC))
237 avrdude_message(MSG_INFO, "%s VCC = %s\n", p, pins_to_str(&pgm->pin[PPI_AVR_VCC]));
238 if(show & (1<<PPI_AVR_BUFF))
239 avrdude_message(MSG_INFO, "%s BUFF = %s\n", p, pins_to_str(&pgm->pin[PPI_AVR_BUFF]));
240 if(show & (1<<PIN_AVR_RESET))
241 avrdude_message(MSG_INFO, "%s RESET = %s\n", p, pins_to_str(&pgm->pin[PIN_AVR_RESET]));
242 if(show & (1<<PIN_AVR_SCK))
243 avrdude_message(MSG_INFO, "%s SCK = %s\n", p, pins_to_str(&pgm->pin[PIN_AVR_SCK]));
244 if(show & (1<<PIN_AVR_MOSI))
245 avrdude_message(MSG_INFO, "%s MOSI = %s\n", p, pins_to_str(&pgm->pin[PIN_AVR_MOSI]));
246 if(show & (1<<PIN_AVR_MISO))
247 avrdude_message(MSG_INFO, "%s MISO = %s\n", p, pins_to_str(&pgm->pin[PIN_AVR_MISO]));
248 if(show & (1<<PIN_LED_ERR))
249 avrdude_message(MSG_INFO, "%s ERR LED = %s\n", p, pins_to_str(&pgm->pin[PIN_LED_ERR]));
250 if(show & (1<<PIN_LED_RDY))
251 avrdude_message(MSG_INFO, "%s RDY LED = %s\n", p, pins_to_str(&pgm->pin[PIN_LED_RDY]));
252 if(show & (1<<PIN_LED_PGM))
253 avrdude_message(MSG_INFO, "%s PGM LED = %s\n", p, pins_to_str(&pgm->pin[PIN_LED_PGM]));
254 if(show & (1<<PIN_LED_VFY))
255 avrdude_message(MSG_INFO, "%s VFY LED = %s\n", p, pins_to_str(&pgm->pin[PIN_LED_VFY]));
256}
const char * pins_to_str(const struct pindef_t *const pindef)
Definition pindefs.c:320
@ PIN_LED_VFY
Definition libavrdude.h:362
@ PIN_AVR_RESET
Definition libavrdude.h:355
@ PIN_AVR_MISO
Definition libavrdude.h:358
@ PIN_LED_RDY
Definition libavrdude.h:360
@ PIN_LED_ERR
Definition libavrdude.h:359
@ PIN_AVR_SCK
Definition libavrdude.h:356
@ PIN_LED_PGM
Definition libavrdude.h:361
@ PIN_AVR_MOSI
Definition libavrdude.h:357
@ PPI_AVR_BUFF
Definition libavrdude.h:354
@ PPI_AVR_VCC
Definition libavrdude.h:353
struct pindef_t pin[N_PINS]
Definition libavrdude.h:623

References avrdude_message(), MSG_INFO, pgm, programmer_t::pin, PIN_AVR_MISO, PIN_AVR_MOSI, PIN_AVR_RESET, PIN_AVR_SCK, PIN_LED_ERR, PIN_LED_PGM, PIN_LED_RDY, PIN_LED_VFY, pins_to_str(), PPI_AVR_BUFF, and PPI_AVR_VCC.

Referenced by pgm_display_generic().

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

◆ pgm_dup()

PROGRAMMER * pgm_dup ( const PROGRAMMER *const  src)
156{
157 PROGRAMMER * pgm;
158 LNODEID ln;
159
160 pgm = (PROGRAMMER *)malloc(sizeof(*pgm));
161 if (pgm == NULL) {
162 avrdude_message(MSG_INFO, "%s: out of memory allocating programmer structure\n",
163 progname);
164 return NULL;
165 }
166
167 memcpy(pgm, src, sizeof(*pgm));
168
169 pgm->id = lcreat(NULL, 0);
170 pgm->usbpid = lcreat(NULL, 0);
171
172 for (ln = lfirst(src->usbpid); ln; ln = lnext(ln)) {
173 int *ip = malloc(sizeof(int));
174 if (ip == NULL) {
175 // avrdude_message(MSG_INFO, "%s: out of memory allocating programmer structure\n",
176 // progname);
177 // exit(1);
178 avrdude_oom("out of memory allocating programmer structure\n");
179 }
180 *ip = *(int *) ldata(ln);
181 ladd(pgm->usbpid, ip);
182 }
183
184 return pgm;
185}
void avrdude_oom(const char *context)
Definition main.c:169
void * malloc(YYSIZE_T)
int ladd(LISTID lid, void *p)
Definition lists.c:547
LISTID lcreat(void *liststruct, int poolsize)
Definition lists.c:410
LISTID usbpid
Definition libavrdude.h:632

References avrdude_message(), avrdude_oom(), programmer_t::id, ladd(), lcreat(), ldata(), lfirst(), lnext(), malloc(), MSG_INFO, pgm, progname, and programmer_t::usbpid.

Referenced by yyparse().

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

◆ pgm_free()

void pgm_free ( PROGRAMMER *const  p)
142{
143 ldestroy_cb(p->id, free);
145 p->id = NULL;
146 p->usbpid = NULL;
147 /* this is done by pgm_teardown, but usually cookie is not set to NULL */
148 /* if (p->cookie !=NULL) {
149 free(p->cookie);
150 p->cookie = NULL;
151 }*/
152 free(p);
153}
void free(void *)
void ldestroy_cb(LISTID lid, void(*ucleanup)(void *data_ptr))
Definition lists.c:480

References free(), programmer_t::id, ldestroy_cb(), and programmer_t::usbpid.

Referenced by cleanup_config(), and yyparse().

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

◆ pgm_new()

PROGRAMMER * pgm_new ( void  )
65{
66 int i;
68
69 pgm = (PROGRAMMER *)malloc(sizeof(*pgm));
70 if (pgm == NULL) {
71 avrdude_message(MSG_INFO, "%s: out of memory allocating programmer structure\n",
72 progname);
73 return NULL;
74 }
75
76 memset(pgm, 0, sizeof(*pgm));
77
78 pgm->id = lcreat(NULL, 0);
79 pgm->usbpid = lcreat(NULL, 0);
80 pgm->desc[0] = 0;
81 pgm->type[0] = 0;
82 pgm->config_file[0] = 0;
83 pgm->lineno = 0;
84 pgm->baudrate = 0;
85 pgm->initpgm = NULL;
86
87 for (i=0; i<N_PINS; i++) {
88 pgm->pinno[i] = 0;
89 pin_clear_all(&(pgm->pin[i]));
90 }
91
92 /*
93 * mandatory functions - these are called without checking to see
94 * whether they are assigned or not
95 */
108
109 /*
110 * predefined functions - these functions have a valid default
111 * implementation. Hence, they don't need to be defined in
112 * the programmer.
113 */
118
119 /*
120 * optional functions - these are checked to make sure they are
121 * assigned before they are called
122 */
123 pgm->cmd = NULL;
124 pgm->cmd_tpi = NULL;
125 pgm->spi = NULL;
126 pgm->paged_write = NULL;
127 pgm->paged_load = NULL;
128 pgm->write_setup = NULL;
129 pgm->read_sig_bytes = NULL;
130 pgm->set_vtarget = NULL;
131 pgm->set_varef = NULL;
132 pgm->set_fosc = NULL;
133 pgm->perform_osccal = NULL;
134 pgm->parseextparams = NULL;
135 pgm->setup = NULL;
136 pgm->teardown = NULL;
137
138 return pgm;
139}
void pin_clear_all(struct pindef_t *const pindef)
Definition pindefs.c:50
@ N_PINS
Definition libavrdude.h:363
static int pgm_default_3(struct programmer_t *pgm, AVRPART *p, AVRMEM *mem, unsigned long addr, unsigned char *value)
Definition pgm.c:200
static int pgm_default_led(struct programmer_t *pgm, int value)
Definition pgm.c:47
static int pgm_default_2(struct programmer_t *, AVRPART *)
Definition pgm.c:194
static int pgm_default_5(struct programmer_t *pgm, AVRPART *p, AVRMEM *mem, unsigned long addr, unsigned char data)
Definition pgm.c:212
static void pgm_default_4(struct programmer_t *)
Definition pgm.c:207
static void pgm_default_6(struct programmer_t *, const char *)
Definition pgm.c:219
static void pgm_default_powerup_powerdown(struct programmer_t *pgm)
Definition pgm.c:56
static int pgm_default_open(struct programmer_t *pgm, char *name)
Definition pgm.c:40
void(* display)(struct programmer_t *pgm, const char *p)
Definition libavrdude.h:644
int(* paged_write)(struct programmer_t *pgm, AVRPART *p, AVRMEM *m, unsigned int page_size, unsigned int baseaddr, unsigned int n_bytes)
Definition libavrdude.h:659
int(* read_sig_bytes)(struct programmer_t *pgm, AVRPART *p, AVRMEM *m)
Definition libavrdude.h:672
int(* open)(struct programmer_t *pgm, char *port)
Definition libavrdude.h:657
unsigned int pinno[N_PINS]
Definition libavrdude.h:622
int(* read_byte)(struct programmer_t *pgm, AVRPART *p, AVRMEM *m, unsigned long addr, unsigned char *value)
Definition libavrdude.h:670
int(* paged_load)(struct programmer_t *pgm, AVRPART *p, AVRMEM *m, unsigned int page_size, unsigned int baseaddr, unsigned int n_bytes)
Definition libavrdude.h:662
void(* powerup)(struct programmer_t *pgm)
Definition libavrdude.h:647
char desc[PGM_DESCLEN]
Definition libavrdude.h:618
int(* set_vtarget)(struct programmer_t *pgm, double v)
Definition libavrdude.h:674
int(* perform_osccal)(struct programmer_t *pgm)
Definition libavrdude.h:682
char config_file[PATH_MAX]
Definition libavrdude.h:687
int baudrate
Definition libavrdude.h:630
void(* write_setup)(struct programmer_t *pgm, AVRPART *p, AVRMEM *m)
Definition libavrdude.h:667
void(* teardown)(struct programmer_t *pgm)
Definition libavrdude.h:685
int(* spi)(struct programmer_t *pgm, const unsigned char *cmd, unsigned char *res, int count)
Definition libavrdude.h:655
int(* vfy_led)(struct programmer_t *pgm, int value)
Definition libavrdude.h:642
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(* set_varef)(struct programmer_t *pgm, unsigned int chan, double v)
Definition libavrdude.h:675
void(* initpgm)(struct programmer_t *pgm)
Definition libavrdude.h:621
int(* cmd)(struct programmer_t *pgm, const unsigned char *cmd, unsigned char *res)
Definition libavrdude.h:651
int(* pgm_led)(struct programmer_t *pgm, int value)
Definition libavrdude.h:641
int(* parseextparams)(struct programmer_t *pgm, LISTID xparams)
Definition libavrdude.h:683
void(* enable)(struct programmer_t *pgm)
Definition libavrdude.h:645
int(* rdy_led)(struct programmer_t *pgm, int value)
Definition libavrdude.h:639
int(* err_led)(struct programmer_t *pgm, int value)
Definition libavrdude.h:640
int(* program_enable)(struct programmer_t *pgm, AVRPART *p)
Definition libavrdude.h:649
int lineno
Definition libavrdude.h:688
int(* write_byte)(struct programmer_t *pgm, AVRPART *p, AVRMEM *m, unsigned long addr, unsigned char value)
Definition libavrdude.h:668
void(* setup)(struct programmer_t *pgm)
Definition libavrdude.h:684
int(* set_fosc)(struct programmer_t *pgm, double v)
Definition libavrdude.h:676
char type[PGM_TYPELEN]
Definition libavrdude.h:619
int(* initialize)(struct programmer_t *pgm, AVRPART *p)
Definition libavrdude.h:643
void(* close)(struct programmer_t *pgm)
Definition libavrdude.h:658
int(* chip_erase)(struct programmer_t *pgm, AVRPART *p)
Definition libavrdude.h:650
void(* disable)(struct programmer_t *pgm)
Definition libavrdude.h:646
void(* powerdown)(struct programmer_t *pgm)
Definition libavrdude.h:648

References avrdude_message(), programmer_t::baudrate, programmer_t::chip_erase, programmer_t::close, programmer_t::cmd, programmer_t::cmd_tpi, programmer_t::config_file, programmer_t::desc, programmer_t::disable, programmer_t::display, programmer_t::enable, programmer_t::err_led, programmer_t::id, programmer_t::initialize, programmer_t::initpgm, lcreat(), programmer_t::lineno, malloc(), MSG_INFO, N_PINS, programmer_t::open, programmer_t::paged_load, programmer_t::paged_write, programmer_t::parseextparams, programmer_t::perform_osccal, pgm, pgm_default_2(), pgm_default_3(), pgm_default_4(), pgm_default_5(), pgm_default_6(), pgm_default_led(), pgm_default_open(), pgm_default_powerup_powerdown(), programmer_t::pgm_led, programmer_t::pin, pin_clear_all(), programmer_t::pinno, programmer_t::powerdown, programmer_t::powerup, progname, programmer_t::program_enable, programmer_t::rdy_led, programmer_t::read_byte, programmer_t::read_sig_bytes, programmer_t::set_fosc, programmer_t::set_varef, programmer_t::set_vtarget, programmer_t::setup, programmer_t::spi, programmer_t::teardown, programmer_t::type, programmer_t::usbpid, programmer_t::vfy_led, programmer_t::write_byte, and programmer_t::write_setup.

Referenced by yyparse().

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

◆ programmer_display()

void programmer_display ( PROGRAMMER pgm,
const char *  p 
)
226{
227 avrdude_message(MSG_INFO, "%sProgrammer Type : %s\n", p, pgm->type);
228 avrdude_message(MSG_INFO, "%sDescription : %s\n", p, pgm->desc);
229
230 pgm->display(pgm, p);
231}

References avrdude_message(), programmer_t::desc, programmer_t::display, MSG_INFO, pgm, and programmer_t::type.

Referenced by avrdude_main().

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

◆ sort_programmer_compare()

static int sort_programmer_compare ( PROGRAMMER p1,
PROGRAMMER p2 
)
static
315{
316 char* id1;
317 char* id2;
318 if(p1 == NULL || p2 == NULL) {
319 return 0;
320 }
321 id1 = ldata(lfirst(p1->id));
322 id2 = ldata(lfirst(p2->id));
323 return strncasecmp(id1,id2,AVR_IDLEN);
324}
#define AVR_IDLEN
Definition libavrdude.h:210
#define strncasecmp
Definition unistd.h:51

References AVR_IDLEN, programmer_t::id, ldata(), lfirst(), and strncasecmp.

Referenced by sort_programmers().

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

◆ sort_programmers()

void sort_programmers ( LISTID  programmers)
330{
331 lsort(programmers,(int (*)(void*, void*)) sort_programmer_compare);
332}
void lsort(LISTID lid, int(*compare)(void *p1, void *p2))
Definition lists.c:1289
static int sort_programmer_compare(PROGRAMMER *p1, PROGRAMMER *p2)
Definition pgm.c:314

References lsort(), programmers, and sort_programmer_compare().

Referenced by list_programmers().

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

◆ walk_programmers()

void walk_programmers ( LISTID  programmers,
walk_programmers_cb  cb,
void cookie 
)
298{
299 LNODEID ln1;
300 LNODEID ln2;
301 PROGRAMMER * p;
302
303 for (ln1 = lfirst(programmers); ln1; ln1 = lnext(ln1)) {
304 p = ldata(ln1);
305 for (ln2=lfirst(p->id); ln2; ln2=lnext(ln2)) {
306 cb(ldata(ln2), p->desc, p->config_file, p->lineno, cookie);
307 }
308 }
309}

References programmer_t::config_file, programmer_t::desc, programmer_t::id, ldata(), lfirst(), programmer_t::lineno, lnext(), and programmers.

Referenced by list_programmers().

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