2001-01-24 19:10:34 +00:00
|
|
|
/*
|
2003-02-08 04:17:25 +00:00
|
|
|
* avrdude - A Downloader/Uploader for AVR device programmers
|
2004-12-22 01:52:45 +00:00
|
|
|
* Copyright (C) 2000-2004 Brian S. Dean <bsd@bsdhome.com>
|
2001-01-24 19:10:34 +00:00
|
|
|
*
|
2003-02-06 19:08:33 +00:00
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
2001-01-24 19:10:34 +00:00
|
|
|
*
|
2003-02-06 19:08:33 +00:00
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
2001-01-24 19:10:34 +00:00
|
|
|
*
|
2003-02-06 19:08:33 +00:00
|
|
|
* You should have received a copy of the GNU General Public License
|
2012-11-20 14:03:50 +00:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2001-01-24 19:10:34 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/* $Id$ */
|
|
|
|
|
|
|
|
#ifndef __pindefs_h__
|
|
|
|
#define __pindefs_h__
|
|
|
|
|
2012-02-01 22:26:58 +00:00
|
|
|
#include <limits.h>
|
|
|
|
|
2013-05-06 09:54:27 +00:00
|
|
|
#include "ac_cfg.h"
|
|
|
|
|
2013-05-03 22:35:00 +00:00
|
|
|
/* lets try to select at least 32 bits */
|
|
|
|
#ifdef HAVE_STDINT_H
|
|
|
|
#include <stdint.h>
|
|
|
|
typedef uint32_t pinmask_t;
|
|
|
|
#else
|
2013-05-06 19:21:38 +00:00
|
|
|
#if UINT_MAX >= 0xFFFFFFFF
|
|
|
|
typedef unsigned int pinmask_t;
|
|
|
|
#else
|
2013-05-03 22:35:00 +00:00
|
|
|
typedef unsigned long pinmask_t;
|
|
|
|
#endif
|
2013-05-06 19:21:38 +00:00
|
|
|
#endif
|
2013-05-03 22:35:00 +00:00
|
|
|
|
|
|
|
#include <stdbool.h>
|
|
|
|
|
|
|
|
|
2001-09-19 17:04:25 +00:00
|
|
|
enum {
|
2013-05-05 13:35:35 +00:00
|
|
|
PPI_AVR_VCC = 1,
|
2001-12-29 21:37:20 +00:00
|
|
|
PPI_AVR_BUFF,
|
2001-09-19 17:04:25 +00:00
|
|
|
PIN_AVR_RESET,
|
|
|
|
PIN_AVR_SCK,
|
|
|
|
PIN_AVR_MOSI,
|
|
|
|
PIN_AVR_MISO,
|
|
|
|
PIN_LED_ERR,
|
|
|
|
PIN_LED_RDY,
|
|
|
|
PIN_LED_PGM,
|
|
|
|
PIN_LED_VFY,
|
|
|
|
N_PINS
|
|
|
|
};
|
2013-05-03 22:35:00 +00:00
|
|
|
|
2012-02-01 22:26:58 +00:00
|
|
|
#define PIN_MASK (UINT_MAX>>1)
|
|
|
|
#define PIN_INVERSE (~(PIN_MASK)) /* flag for inverted pin in serbb */
|
2013-05-03 22:35:00 +00:00
|
|
|
#define PIN_MIN 0 /* smallest allowed pin number */
|
|
|
|
#define PIN_MAX 31 /* largest allowed pin number */
|
|
|
|
|
2014-05-07 20:53:34 +00:00
|
|
|
#ifdef HAVE_LINUXGPIO
|
2013-05-03 22:35:00 +00:00
|
|
|
/* Embedded systems might have a lot more gpio than only 0-31 */
|
|
|
|
#undef PIN_MAX
|
2013-01-09 19:23:30 +00:00
|
|
|
#define PIN_MAX 255 /* largest allowed pin number */
|
2013-05-03 22:35:00 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/** Number of pins in each element of the bitfield */
|
|
|
|
#define PIN_FIELD_ELEMENT_SIZE (sizeof(pinmask_t) * 8)
|
|
|
|
/** Numer of elements to store the complete bitfield of all pins */
|
|
|
|
#define PIN_FIELD_SIZE ((PIN_MAX + PIN_FIELD_ELEMENT_SIZE)/PIN_FIELD_ELEMENT_SIZE)
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This sets the corresponding bits to 1 or 0, the inverse mask is used to invert the value in necessary.
|
|
|
|
* It uses only the lowest element (index=0) of the bitfield, which should be enough for most
|
|
|
|
* programmers.
|
|
|
|
*
|
|
|
|
* @param[in] x input value
|
|
|
|
* @param[in] pgm the programmer whose pin definitions to use
|
|
|
|
* @param[in] pinname the logical name of the pin (PIN_AVR_*, ...)
|
2013-05-05 13:35:35 +00:00
|
|
|
* @param[in] level the logical level (level != 0 => 1, level == 0 => 0),
|
2013-05-03 22:35:00 +00:00
|
|
|
* if the pin is defined as inverted the resulting bit is also inverted
|
|
|
|
* @returns the input value with the relevant bits modified
|
|
|
|
*/
|
|
|
|
#define SET_BITS_0(x,pgm,pinname,level) (((x) & ~(pgm)->pin[pinname].mask[0]) \
|
|
|
|
| (\
|
|
|
|
(pgm)->pin[pinname].mask[0] & ( \
|
|
|
|
(level) \
|
|
|
|
?~((pgm)->pin[pinname].inverse[0]) \
|
|
|
|
: ((pgm)->pin[pinname].inverse[0]) \
|
|
|
|
) \
|
|
|
|
) \
|
|
|
|
)
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if the corresponding bit is set (returns != 0) or cleared.
|
|
|
|
* The inverse mask is used, to invert the relevant bits.
|
|
|
|
* If the pin definition contains multiple pins, then a single set pin leads to return value != 0.
|
|
|
|
* Then you have to check the relevant bits of the returned value, if you need more information.
|
|
|
|
* It uses only the lowest element (index=0) of the bitfield, which should be enough for most
|
|
|
|
* programmers.
|
|
|
|
*
|
|
|
|
* @param[in] x input value
|
|
|
|
* @param[in] pgm the programmer whose pin definitions to use
|
|
|
|
* @param[in] pinname the logical name of the pin (PIN_AVR_*, ...)
|
|
|
|
* @returns the input value with only the relevant bits (which are already inverted,
|
|
|
|
* so you get always the logical level)
|
|
|
|
*/
|
|
|
|
#define GET_BITS_0(x,pgm,pinname) (((x) ^ (pgm)->pin[pinname].inverse[0]) & (pgm)->pin[pinname].mask[0])
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Data structure to hold used pins by logical function (PIN_AVR_*, ...)
|
|
|
|
*/
|
|
|
|
struct pindef_t {
|
2013-05-05 13:35:35 +00:00
|
|
|
pinmask_t mask[PIN_FIELD_SIZE]; ///< bitfield of used pins
|
|
|
|
pinmask_t inverse[PIN_FIELD_SIZE]; ///< bitfield of inverse/normal usage of used pins
|
2013-05-03 22:35:00 +00:00
|
|
|
};
|
|
|
|
|
2013-05-05 13:35:35 +00:00
|
|
|
/**
|
|
|
|
* Data structure to define a checklist of valid pins for each function.
|
|
|
|
*/
|
|
|
|
struct pin_checklist_t {
|
|
|
|
int pinname; ///< logical pinname eg. PIN_AVR_SCK
|
|
|
|
int mandatory; ///< is this a mandatory pin
|
|
|
|
const struct pindef_t* valid_pins; ///< mask defines allowed pins, inverse define is they might be used inverted
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Adds a pin in the pin definition as normal or inverse pin.
|
|
|
|
*
|
|
|
|
* @param[out] pindef pin definition to update
|
|
|
|
* @param[in] pin number of pin [0..PIN_MAX]
|
|
|
|
* @param[in] inverse inverse (true) or normal (false) pin
|
|
|
|
*/
|
2013-05-03 22:35:00 +00:00
|
|
|
void pin_set_value(struct pindef_t * const pindef, const int pin, const bool inverse);
|
|
|
|
|
2013-05-05 13:35:35 +00:00
|
|
|
/**
|
|
|
|
* Clear all defined pins in pindef.
|
|
|
|
*
|
|
|
|
* @param[out] pindef pin definition to clear
|
|
|
|
*/
|
2013-05-03 22:35:00 +00:00
|
|
|
void pin_clear_all(struct pindef_t * const pindef);
|
|
|
|
|
|
|
|
struct programmer_t; /* forward declaration */
|
2013-05-05 13:35:35 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Convert for given programmer new pin definitions to old pin definitions.
|
|
|
|
*
|
|
|
|
* @param[inout] pgm programmer whose pins shall be converted.
|
|
|
|
*/
|
2014-05-16 15:52:25 +00:00
|
|
|
int pgm_fill_old_pins(struct programmer_t * const pgm);
|
2001-01-24 19:10:34 +00:00
|
|
|
|
2013-05-05 13:35:35 +00:00
|
|
|
/**
|
|
|
|
* This function checks all pin of pgm against the constraints given in the checklist.
|
|
|
|
* It checks if
|
|
|
|
* @li any invalid pins are used
|
|
|
|
* @li valid pins are used inverted when not allowed
|
|
|
|
* @li any pins are used by more than one function
|
|
|
|
* @li 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.
|
|
|
|
*
|
|
|
|
* @param[in] pgm the programmer to check
|
|
|
|
* @param[in] checklist the constraint for the pins
|
|
|
|
* @param[in] size the number of entries in checklist
|
2013-06-19 17:40:32 +00:00
|
|
|
* @param[in] output false suppresses error messages to the user
|
2013-05-05 13:35:35 +00:00
|
|
|
* @returns 0 if all pin definitions are valid, -1 otherwise
|
|
|
|
*/
|
2013-06-19 17:40:32 +00:00
|
|
|
int pins_check(const struct programmer_t * const pgm, const struct pin_checklist_t * const checklist, const int size, const bool output);
|
2013-05-05 13:35:35 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the name of the pin as string.
|
|
|
|
*
|
|
|
|
* @param pinname the pinname which we want as string.
|
|
|
|
* @returns a string with the pinname, or <unknown> if pinname is invalid.
|
|
|
|
*/
|
|
|
|
const char * avr_pin_name(int pinname);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* @param[in] pindef the pin definition for which we want the string representation
|
|
|
|
* @returns pointer to a static string.
|
|
|
|
*/
|
|
|
|
const char * pins_to_str(const struct pindef_t * const pindef);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* @param[in] pinmask the pin mask for which we want the string representation
|
|
|
|
* @returns pointer to a static string.
|
|
|
|
*/
|
|
|
|
const char * pinmask_to_str(const pinmask_t * const pinmask);
|
|
|
|
|
|
|
|
|
2001-01-24 19:10:34 +00:00
|
|
|
#endif
|
2013-05-03 22:35:00 +00:00
|
|
|
|