AVRISP-MKII Clone Programmer Project

Functions | Variables
ISPTarget.c File Reference
`#include "ISPTarget.h"`

## Functions

| ISR (TIMER1_COMPA_vect, ISR_BLOCK)
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)

## Variables

static const uint8_t | SPIMaskFromSCKDuration []
static const uint16_t | TimerCompareFromSCKDuration []
bool | HardwareSPIMode = true
static volatile uint8_t | SoftSPI_Data
static volatile uint8_t | SoftSPI_BitsRemaining

## Detailed Description

Target-related functions for the ISP Protocol decoder.

## 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_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

## § ISR()

ISR | ( | TIMER1_COMPA_vect | ,
|  | ISR_BLOCK |
| ) |  |

ISR to handle software SPI transmission and reception

## Variable Documentation

## § HardwareSPIMode

bool HardwareSPIMode = true

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

## § SoftSPI_BitsRemaining

volatile uint8_t SoftSPI_BitsRemaining

static

Number of bits left to transfer in the software SPI driver

## § SoftSPI_Data

volatile uint8_t SoftSPI_Data

static

Software SPI data register for sending and receiving

## § SPIMaskFromSCKDuration

const uint8_t SPIMaskFromSCKDuration[]

static

List of hardware SPI prescaler masks for possible AVRStudio ISP programming speeds.

## § TimerCompareFromSCKDuration

const uint16_t TimerCompareFromSCKDuration[]

static

Lookup table to convert the slower ISP speeds into a compare value for the software SPI driver.