AVRISP-MKII Clone Programmer Project

Macros | Functions | Variables
ISPTarget.h File Reference
`#include <avr/io.h>`
`#include <avr/pgmspace.h>`
`#include <util/delay.h>`
`#include <LUFA/Drivers/USB/USB.h>`
`#include <LUFA/Drivers/Peripheral/SPI.h>`
`#include "../V2Protocol.h"`
`#include "ISPProtocol.h"`
`#include "Config/AppConfig.h"`

## Macros

#define | LOAD_EXTENDED_ADDRESS_CMD 0x4D
#define | TIMER_COMP(freq) (((F_CPU / 8) / 2 / freq) - 1)
#define | ISP_RESCUE_CLOCK_SPEED 4000000

## Functions

void | ISPTarget_EnableTargetISP (void)
void | ISPTarget_DisableTargetISP (void)
void | ISPTarget_ConfigureRescueClock (void)
void | ISPTarget_ConfigureSoftwareSPI (const uint8_t SCKDuration)
uint8_t | ISPTarget_TransferSoftSPIByte (const uint8_t Byte)
void | ISPTarget_ChangeTargetResetLine (const bool ResetTarget)
uint8_t | ISPTarget_WaitWhileTargetBusy (void)
void | ISPTarget_LoadExtendedAddress (void)
uint8_t | ISPTarget_WaitForProgComplete (const uint8_t ProgrammingMode, const uint16_t PollAddress, const uint8_t PollValue, const uint8_t DelayMS, const uint8_t ReadMemCommand)
static void | ISPTarget_SendByte (const uint8_t Byte)
static uint8_t | ISPTarget_ReceiveByte (void)
static uint8_t | ISPTarget_TransferByte (const uint8_t Byte)

## Variables

bool | HardwareSPIMode

## Detailed Description

Header file for ISPTarget.c.

## Macro Definition Documentation

## § ISP_RESCUE_CLOCK_SPEED

#define ISP_RESCUE_CLOCK_SPEED 4000000

ISP rescue clock speed in Hz, for clocking targets with incorrectly set fuses.

## § LOAD_EXTENDED_ADDRESS_CMD

#define LOAD_EXTENDED_ADDRESS_CMD 0x4D

Low level device command to issue an extended FLASH address, for devices with over 128KB of FLASH.

## § TIMER_COMP

#define TIMER_COMP | ( |  | freq | ) | (((F_CPU / 8) / 2 / freq) - 1)

Macro to convert an ISP frequency to a number of timer clock cycles for the software SPI driver.

## Function Documentation

## § ISPTarget_ChangeTargetResetLine()

void ISPTarget_ChangeTargetResetLine | ( | const bool | ResetTarget | ) |

Asserts or deasserts the target's reset line, using the correct polarity as set by the host using a SET PARAM command. When not asserted, the line is tristated so as not to interfere with normal device operation.

Parameters

  [in] | ResetTarget | Boolean true when the target should be held in reset, `false` otherwise

## § ISPTarget_ConfigureRescueClock()

void ISPTarget_ConfigureRescueClock | ( | void |  | ) |

Configures the AVR to produce a 4MHz rescue clock out of the OCR1A pin of the AVR, so that it can be fed into the XTAL1 pin of an AVR whose fuses have been mis-configured for an external clock rather than a crystal. When used, the ISP speed must be 125KHz for this functionality to work correctly.

## § ISPTarget_ConfigureSoftwareSPI()

void ISPTarget_ConfigureSoftwareSPI | ( | const uint8_t | SCKDuration | ) |

Configures the AVR's timer ready to produce software SPI for the slower ISP speeds that cannot be obtained when using the AVR's hardware SPI module.

Parameters

  [in] | SCKDuration | Duration of the desired software ISP SCK clock

## § ISPTarget_DisableTargetISP()

void ISPTarget_DisableTargetISP | ( | void |  | ) |

Shuts down the current selected SPI driver (hardware or software, depending on the selected ISP speed) so that no further communications can occur until the driver is re-initialized.

## § ISPTarget_EnableTargetISP()

void ISPTarget_EnableTargetISP | ( | void |  | ) |

Initializes the appropriate SPI driver (hardware or software, depending on the selected ISP speed) ready for communication with the attached target.

## § ISPTarget_LoadExtendedAddress()

void ISPTarget_LoadExtendedAddress | ( | void |  | ) |

Sends a low-level LOAD EXTENDED ADDRESS command to the target, for addressing of memory beyond the 64KB boundary. This sends the command with the correct address as indicated by the current address pointer variable set by the host when a SET ADDRESS command is issued.

## § ISPTarget_ReceiveByte()

static uint8_t ISPTarget_ReceiveByte | ( | void |  | ) |

inline static

Receives a byte of ISP data from the attached target, using the appropriate SPI hardware or software routines depending on the selected ISP speed.

Returns
  Received byte of data from the attached target

## § ISPTarget_SendByte()

static void ISPTarget_SendByte | ( | const uint8_t | Byte | ) |

inline static

Sends a byte of ISP data to the attached target, using the appropriate SPI hardware or software routines depending on the selected ISP speed.

Parameters

  [in] | Byte | Byte of data to send to the attached target

## § ISPTarget_TransferByte()

static uint8_t ISPTarget_TransferByte | ( | const uint8_t | Byte | ) |

inline static

Sends and receives a byte of ISP data to and from the attached target, using the appropriate SPI hardware or software routines depending on the selected ISP speed.

Parameters

  [in] | Byte | Byte of data to send to the attached target

Returns
  Received byte of data from the attached target

## § ISPTarget_TransferSoftSPIByte()

uint8_t ISPTarget_TransferSoftSPIByte | ( | const uint8_t | Byte | ) |

Sends and receives a single byte of data to and from the attached target via software SPI.

Parameters

  [in] | Byte | Byte of data to send to the attached target

Returns
  Received byte of data from the attached target

## § ISPTarget_WaitForProgComplete()

uint8_t ISPTarget_WaitForProgComplete | ( | const uint8_t | ProgrammingMode,
|  | const uint16_t | PollAddress,
|  | const uint8_t | PollValue,
|  | const uint8_t | DelayMS,
|  | const uint8_t | ReadMemCommand
| ) |  |

Waits until the last issued target memory programming command has completed, via the check mode given and using the given parameters.

Parameters

  [in] | ProgrammingMode | Programming mode used and completion check to use, a mask of `PROG_MODE_*` constants
  [in] | PollAddress | Memory address to poll for completion if polling check mode used
  [in] | PollValue | Poll value to check against if polling check mode used
  [in] | DelayMS | Milliseconds to delay before returning if delay check mode used
  [in] | ReadMemCommand | Device low-level READ MEMORY command to send if value check mode used

Returns
  V2 Protocol status STATUS_CMD_OK if the no timeout occurred, STATUS_RDY_BSY_TOUT or STATUS_CMD_TOUT otherwise

## § ISPTarget_WaitWhileTargetBusy()

uint8_t ISPTarget_WaitWhileTargetBusy | ( | void |  | ) |

Waits until the target has completed the last operation, by continuously polling the device's BUSY flag until it is cleared, or until the command timeout period has expired.

Returns
  V2 Protocol status STATUS_CMD_OK if the no timeout occurred, STATUS_RDY_BSY_TOUT otherwise

## Variable Documentation

## § HardwareSPIMode

bool HardwareSPIMode

Currently selected SPI driver, either hardware (for fast ISP speeds) or software (for slower ISP speeds).