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

Go to the source code of this file.

Functions

void pin_set_value (struct pindef_t *const pindef, const int pin, const bool inverse)
 
void pin_clear_all (struct pindef_t *const pindef)
 
static int pin_fill_old_pinno (const struct pindef_t *const pindef, unsigned int *const pinno)
 
static int pin_fill_old_pinlist (const struct pindef_t *const pindef, unsigned int *const pinno)
 
int pgm_fill_old_pins (struct programmer_t *const pgm)
 
const char * pinmask_to_str (const pinmask_t *const pinmask)
 
int pins_check (const struct programmer_t *const pgm, const struct pin_checklist_t *const checklist, const int size, const bool output)
 
const char * pins_to_str (const struct pindef_t *const pindef)
 
const char * avr_pin_name (int pinname)
 

Function Documentation

◆ avr_pin_name()

const char * avr_pin_name ( int  pinname)

Returns the name of the pin as string.

Parameters
pinnamethe pinname which we want as string.
Returns
a string with the pinname, or <unknown> if pinname is invalid.
354 {
355 switch(pinname) {
356 case PPI_AVR_VCC : return "VCC";
357 case PPI_AVR_BUFF : return "BUFF";
358 case PIN_AVR_RESET : return "RESET";
359 case PIN_AVR_SCK : return "SCK";
360 case PIN_AVR_MOSI : return "MOSI";
361 case PIN_AVR_MISO : return "MISO";
362 case PIN_LED_ERR : return "ERRLED";
363 case PIN_LED_RDY : return "RDYLED";
364 case PIN_LED_PGM : return "PGMLED";
365 case PIN_LED_VFY : return "VFYLED";
366 default : return "<unknown>";
367 }
368}
@ 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

References PIN_AVR_MISO, PIN_AVR_MOSI, PIN_AVR_RESET, PIN_AVR_SCK, PIN_LED_ERR, PIN_LED_PGM, PIN_LED_RDY, PIN_LED_VFY, PPI_AVR_BUFF, and PPI_AVR_VCC.

Referenced by avr_display(), and pins_check().

+ Here is the caller graph for this function:

◆ pgm_fill_old_pins()

int pgm_fill_old_pins ( struct programmer_t *const  pgm)

Convert for given programmer new pin definitions to old pin definitions.

Parameters
[in,out]pgmprogrammer whose pins shall be converted.
120 {
121
123 return -1;
125 return -1;
127 return -1;
129 return -1;
131 return -1;
133 return -1;
135 return -1;
137 return -1;
139 return -1;
141 return -1;
142
143 return 0;
144}
static PROGRAMMER * pgm
Definition main.c:192
static int pin_fill_old_pinno(const struct pindef_t *const pindef, unsigned int *const pinno)
Definition pindefs.c:60
static int pin_fill_old_pinlist(const struct pindef_t *const pindef, unsigned int *const pinno)
Definition pindefs.c:85
unsigned int pinno[N_PINS]
Definition libavrdude.h:622
struct pindef_t pin[N_PINS]
Definition libavrdude.h:623

References pgm, programmer_t::pin, PIN_AVR_MISO, PIN_AVR_MOSI, PIN_AVR_RESET, PIN_AVR_SCK, pin_fill_old_pinlist(), pin_fill_old_pinno(), PIN_LED_ERR, PIN_LED_PGM, PIN_LED_RDY, PIN_LED_VFY, programmer_t::pinno, PPI_AVR_BUFF, and PPI_AVR_VCC.

Referenced by buspirate_bb_initpgm(), and serbb_initpgm().

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

◆ pin_clear_all()

void pin_clear_all ( struct pindef_t *const  pindef)

Clear all defined pins in pindef.

Parameters
[out]pindefpin definition to clear
50 {
51 memset(pindef, 0, sizeof(struct pindef_t));
52}
Definition libavrdude.h:423

Referenced by pgm_new(), and yyparse().

+ Here is the caller graph for this function:

◆ pin_fill_old_pinlist()

static int pin_fill_old_pinlist ( const struct pindef_t *const  pindef,
unsigned int *const  pinno 
)
static

Convert new pin definition to old pinlist, does not support mixed inverted/non-inverted pin

Parameters
[in]pindefnew pin definition structure
[out]pinnoold pin definition integer
85 {
86 int i;
87
88 for(i = 0; i < PIN_FIELD_SIZE; i++) {
89 if(i == 0) {
90 if((pindef->mask[i] & ~PIN_MASK) != 0) {
91 avrdude_message(MSG_INFO, "Pins of higher index than max field size for old pinno found\n");
92 return -1;
93 }
94 if (pindef->mask[i] == 0) {
95 /* this pin function is not using any pins */
96 *pinno = 0;
97 } else if(pindef->mask[i] == pindef->inverse[i]) { /* all set bits in mask are set in inverse */
98 *pinno = pindef->mask[i];
99 *pinno |= PIN_INVERSE;
100 } else if(pindef->mask[i] == ((~pindef->inverse[i]) & pindef->mask[i])) { /* all set bits in mask are cleared in inverse */
101 *pinno = pindef->mask[i];
102 } else {
103 avrdude_message(MSG_INFO, "pins have different polarity set\n");
104 return -1;
105 }
106 } else if(pindef->mask[i] != 0) {
107 avrdude_message(MSG_INFO, "Pins have higher number than fit in old format\n");
108 return -1;
109 }
110 }
111 return 0;
112}
#define MSG_INFO
Definition avrdude.h:51
int avrdude_message(const int msglvl, const char *format,...)
Definition main.c:93
#define PIN_FIELD_SIZE
Definition libavrdude.h:380
#define PIN_MASK
Definition libavrdude.h:366
pinmask_t mask[PIN_FIELD_SIZE]
bitfield of used pins
Definition libavrdude.h:424
pinmask_t inverse[PIN_FIELD_SIZE]
bitfield of inverse/normal usage of used pins
Definition libavrdude.h:425
#define PIN_INVERSE
Definition libavrdude.h:367

References avrdude_message(), pindef_t::inverse, pindef_t::mask, MSG_INFO, PIN_FIELD_SIZE, PIN_INVERSE, and PIN_MASK.

Referenced by pgm_fill_old_pins().

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

◆ pin_fill_old_pinno()

static int pin_fill_old_pinno ( const struct pindef_t *const  pindef,
unsigned int *const  pinno 
)
static

Convert new pin definition to old pin number

Parameters
[in]pindefnew pin definition structure
[out]pinnoold pin definition integer
60 {
61 bool found = false;
62 int i;
63 for(i = 0; i < PIN_MAX; i++) {
64 if(pindef->mask[i / PIN_FIELD_ELEMENT_SIZE] & (1 << (i % PIN_FIELD_ELEMENT_SIZE))) {
65 if(found) {
66 avrdude_message(MSG_INFO, "Multiple pins found\n"); //TODO
67 return -1;
68 }
69 found = true;
70 *pinno = i;
71 if(pindef->inverse[i / PIN_FIELD_ELEMENT_SIZE] & (1 << (i % PIN_FIELD_ELEMENT_SIZE))) {
72 *pinno |= PIN_INVERSE;
73 }
74 }
75 }
76 return 0;
77}
#define PIN_FIELD_ELEMENT_SIZE
Definition libavrdude.h:378
#define PIN_MAX
Definition libavrdude.h:369

References avrdude_message(), pindef_t::inverse, pindef_t::mask, MSG_INFO, PIN_FIELD_ELEMENT_SIZE, PIN_INVERSE, and PIN_MAX.

Referenced by pgm_fill_old_pins().

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

◆ pin_set_value()

void pin_set_value ( struct pindef_t *const  pindef,
const int  pin,
const bool  inverse 
)

Adds a pin in the pin definition as normal or inverse pin.

Parameters
[out]pindefpin definition to update
[in]pinnumber of pin [0..PIN_MAX]
[in]inverseinverse (true) or normal (false) pin
35 {
36
37 pindef->mask[pin / PIN_FIELD_ELEMENT_SIZE] |= 1 << (pin % PIN_FIELD_ELEMENT_SIZE);
38 if(inverse) {
39 pindef->inverse[pin / PIN_FIELD_ELEMENT_SIZE] |= (1 << (pin % PIN_FIELD_ELEMENT_SIZE));
40 } else {
41 pindef->inverse[pin / PIN_FIELD_ELEMENT_SIZE] &= ~(1 << (pin % PIN_FIELD_ELEMENT_SIZE));
42 }
43}
EIGEN_DEVICE_FUNC const InverseReturnType inverse() const
Definition ArrayCwiseUnaryOps.h:332

References inverse(), pindef_t::inverse, pindef_t::mask, and PIN_FIELD_ELEMENT_SIZE.

Referenced by assign_pin(), and assign_pin_list().

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

◆ pinmask_to_str()

const char * pinmask_to_str ( const pinmask_t *const  pinmask)

This function returns a string representation of pins in the mask eg. 1,3,5-7,9,12 Another execution of this function will overwrite the previous result in the static buffer. Consecutive pin number are representated as start-end.

Parameters
[in]pinmaskthe pin mask for which we want the string representation
Returns
pointer to a static string.
154 {
155 static char buf[(PIN_MAX + 1) * 5]; // should be enough for PIN_MAX=255
156 char *p = buf;
157 int n;
158 int pin;
159 const char * fmt;
160 int start = -1;
161 int end = -1;
162
163 buf[0] = 0;
164 for(pin = PIN_MIN; pin <= PIN_MAX; pin++) {
165 int index = pin / PIN_FIELD_ELEMENT_SIZE;
166 int bit = pin % PIN_FIELD_ELEMENT_SIZE;
167 if(pinmask[index] & (1 << bit)) {
168 bool output = false;
169 if(start == -1) {
170 output = true;
171 start = pin;
172 end = start;
173 } else if(pin == end + 1) {
174 end = pin;
175 } else {
176 if(start != end) {
177 n = sprintf(p, "-%d", end);
178 p += n;
179 }
180 output = true;
181 start = pin;
182 end = start;
183 }
184 if(output) {
185 fmt = (buf[0] == 0) ? "%d" : ",%d";
186 n = sprintf(p, fmt, pin);
187 p += n;
188 }
189 }
190 }
191 if(start != end) {
192 n = sprintf(p, "-%d", end);
193 p += n;
194 }
195
196 if(buf[0] == 0)
197 return "(no pins)";
198
199 return buf;
200}
#define PIN_MIN
Definition libavrdude.h:368
S::iterator end(S &sh, const PathTag &)
Definition geometry_traits.hpp:620

References PIN_FIELD_ELEMENT_SIZE, PIN_MAX, and PIN_MIN.

Referenced by pins_check().

+ Here is the caller graph for this function:

◆ pins_check()

int pins_check ( const struct programmer_t *const  pgm,
const struct pin_checklist_t *const  checklist,
const int  size,
const bool  output 
)

This function checks all pin of pgm against the constraints given in the checklist. It checks if

  • any invalid pins are used
  • valid pins are used inverted when not allowed
  • any pins are used by more than one function
  • any mandatory pin is not set all.

In case of any error it report the wrong function and the pin numbers. For verbose >= 2 it also reports the possible correct values. For verbose >=3 it shows also which pins were ok.

Parameters
[in]pgmthe programmer to check
[in]checklistthe constraint for the pins
[in]sizethe number of entries in checklist
Returns
0 if all pin definitions are valid, -1 otherwise
220 {
221 static const struct pindef_t no_valid_pins = {{0}, {0}}; // default value if check list does not contain anything else
222 int rv = 0; // return value
223 int pinname; // loop counter through pinnames
224 pinmask_t already_used_all[PIN_FIELD_SIZE] = {0}; // collect pin definitions of all pin names for check of double use
225 // loop over all possible pinnames
226 for(pinname = 0; pinname < N_PINS; pinname++) {
227 bool used = false;
228 bool invalid = false;
229 bool inverse = false;
230 int index;
231 int segment;
232 bool mandatory_used = false;
233 pinmask_t invalid_used[PIN_FIELD_SIZE] = {0};
234 pinmask_t inverse_used[PIN_FIELD_SIZE] = {0};
235 pinmask_t already_used[PIN_FIELD_SIZE] = {0};
236 const struct pindef_t * valid_pins = &no_valid_pins;
237 bool is_mandatory = false;
238 bool is_ok = true;
239 //find corresponding check pattern
240 for(index = 0; index < size; index++) {
241 if(checklist[index].pinname == pinname) {
242 valid_pins = checklist[index].valid_pins;
243 is_mandatory = checklist[index].mandatory;
244 break;
245 }
246 }
247
248 for(segment = 0; segment < PIN_FIELD_SIZE; segment++) {
249 // check if for mandatory any pin is defined
250 invalid_used[segment] = pgm->pin[pinname].mask[segment] & ~valid_pins->mask[segment];
251 if(is_mandatory && (0 != (pgm->pin[pinname].mask[segment] & valid_pins->mask[segment]))) {
252 mandatory_used = true;
253 }
254 // check if it does not use any non valid pins
255 invalid_used[segment] = pgm->pin[pinname].mask[segment] & ~valid_pins->mask[segment];
256 if(invalid_used[segment]) {
257 invalid = true;
258 }
259 // check if it does not use any valid pins as inverse if not allowed
260 inverse_used[segment] = pgm->pin[pinname].inverse[segment] & valid_pins->mask[segment] & ~valid_pins->inverse[segment];
261 if(inverse_used[segment]) {
262 inverse = true;
263 }
264 // check if it does not use same pins as other function
265 already_used[segment] = pgm->pin[pinname].mask[segment] & already_used_all[segment];
266 if(already_used[segment]) {
267 used = true;
268 }
269 already_used_all[segment] |= pgm->pin[pinname].mask[segment];
270 }
271 if(invalid) {
272 if(output) {
273 avrdude_message(MSG_INFO, "%s: %s: Following pins are not valid pins for this function: %s\n",
274 progname, avr_pin_name(pinname), pinmask_to_str(invalid_used));
275 avrdude_message(MSG_NOTICE2, "%s: %s: Valid pins for this function are: %s\n",
276 progname, avr_pin_name(pinname), pinmask_to_str(valid_pins->mask));
277 }
278 is_ok = false;
279 }
280 if(inverse) {
281 if(output) {
282 avrdude_message(MSG_INFO, "%s: %s: Following pins are not usable as inverse pins for this function: %s\n",
283 progname, avr_pin_name(pinname), pinmask_to_str(inverse_used));
284 avrdude_message(MSG_NOTICE2, "%s: %s: Valid inverse pins for this function are: %s\n",
285 progname, avr_pin_name(pinname), pinmask_to_str(valid_pins->inverse));
286 }
287 is_ok = false;
288 }
289 if(used) {
290 if(output) {
291 avrdude_message(MSG_INFO, "%s: %s: Following pins are set for other functions too: %s\n",
292 progname, avr_pin_name(pinname), pinmask_to_str(already_used));
293 is_ok = false;
294 }
295 }
296 if(!mandatory_used && is_mandatory && !invalid) {
297 if(output) {
298 avrdude_message(MSG_INFO, "%s: %s: Mandatory pin is not defined.\n",
299 progname, avr_pin_name(pinname));
300 }
301 is_ok = false;
302 }
303 if(!is_ok) {
304 rv = -1;
305 } else if(output) {
306 avrdude_message(MSG_DEBUG, "%s: %s: Pin is ok.\n",
307 progname, avr_pin_name(pinname));
308 }
309 }
310 return rv;
311}
EIGEN_DEVICE_FUNC SegmentReturnType segment(Index start, Index n)
This is the const version of segment(Index,Index).
Definition BlockMethods.h:888
#define MSG_DEBUG
Definition avrdude.h:54
char * progname
Definition main.c:61
#define MSG_NOTICE2
Definition avrdude.h:53
uint32_t pinmask_t
Definition libavrdude.h:34
int mandatory
is this a mandatory pin
Definition libavrdude.h:433
@ N_PINS
Definition libavrdude.h:363
const struct pindef_t * valid_pins
mask defines allowed pins, inverse define is they might be used inverted
Definition libavrdude.h:434
constexpr auto size(const C &c) -> decltype(c.size())
Definition span.hpp:183
const char * avr_pin_name(int pinname)
Definition pindefs.c:354
const char * pinmask_to_str(const pinmask_t *const pinmask)
Definition pindefs.c:154

References avr_pin_name(), avrdude_message(), inverse(), pindef_t::inverse, pin_checklist_t::mandatory, pindef_t::mask, MSG_DEBUG, MSG_INFO, MSG_NOTICE2, N_PINS, pgm, programmer_t::pin, PIN_FIELD_SIZE, pinmask_to_str(), progname, segment(), and pin_checklist_t::valid_pins.

+ Here is the call graph for this function:

◆ pins_to_str()

const char * pins_to_str ( const struct pindef_t *const  pindef)

This function returns a string representation of defined pins eg. ~1,2,~4,~5,7 Another execution of this function will overwrite the previous result in the static buffer.

Parameters
[in]pindefthe pin definition for which we want the string representation
Returns
pointer to a static string.
320 {
321 static char buf[(PIN_MAX + 1) * 5]; // should be enough for PIN_MAX=255
322 char *p = buf;
323 int n;
324 int pin;
325 const char * fmt;
326
327 buf[0] = 0;
328 for(pin = PIN_MIN; pin <= PIN_MAX; pin++) {
329 int index = pin / PIN_FIELD_ELEMENT_SIZE;
330 int bit = pin % PIN_FIELD_ELEMENT_SIZE;
331 if(pindef->mask[index] & (1 << bit)) {
332 if(pindef->inverse[index] & (1 << bit)) {
333 fmt = (buf[0] == 0) ? "~%d" : ",~%d";
334 } else {
335 fmt = (buf[0] == 0) ? " %d" : ",%d";
336 }
337 n = sprintf(p, fmt, pin);
338 p += n;
339 }
340 }
341
342 if(buf[0] == 0)
343 return " (not used)";
344
345 return buf;
346}

References pindef_t::inverse, pindef_t::mask, PIN_FIELD_ELEMENT_SIZE, PIN_MAX, and PIN_MIN.

Referenced by pgm_display_generic_mask().

+ Here is the caller graph for this function: