AVRISP-MKII Clone Programmer Project

Macros | Functions
XMEGANVM.h File Reference
`#include <avr/io.h>`
`#include <avr/interrupt.h>`
`#include <stdbool.h>`
`#include <LUFA/Common/Common.h>`
`#include "XPROGProtocol.h"`
`#include "XPROGTarget.h"`
`#include "Config/AppConfig.h"`

## Macros

#define | XMEGA_CRC_LENGTH_BYTES 3
#define | XMEGA_NVM_REG_ADDR0 0x00
#define | XMEGA_NVM_REG_ADDR1 0x01
#define | XMEGA_NVM_REG_ADDR2 0x02
#define | XMEGA_NVM_REG_DAT0 0x04
#define | XMEGA_NVM_REG_DAT1 0x05
#define | XMEGA_NVM_REG_DAT2 0x06
#define | XMEGA_NVM_REG_CMD 0x0A
#define | XMEGA_NVM_REG_CTRLA 0x0B
#define | XMEGA_NVM_REG_CTRLB 0x0C
#define | XMEGA_NVM_REG_INTCTRL 0x0D
#define | XMEGA_NVM_REG_STATUS 0x0F
#define | XMEGA_NVM_REG_LOCKBITS 0x10
#define | XMEGA_NVM_BIT_CTRLA_CMDEX (1 << 0)
#define | XMEGA_NVM_CMD_NOOP 0x00
#define | XMEGA_NVM_CMD_CHIPERASE 0x40
#define | XMEGA_NVM_CMD_READNVM 0x43
#define | XMEGA_NVM_CMD_LOADFLASHPAGEBUFF 0x23
#define | XMEGA_NVM_CMD_ERASEFLASHPAGEBUFF 0x26
#define | XMEGA_NVM_CMD_ERASEFLASHPAGE 0x2B
#define | XMEGA_NVM_CMD_WRITEFLASHPAGE 0x2E
#define | XMEGA_NVM_CMD_ERASEWRITEFLASH 0x2F
#define | XMEGA_NVM_CMD_FLASHCRC 0x78
#define | XMEGA_NVM_CMD_ERASEAPPSEC 0x20
#define | XMEGA_NVM_CMD_ERASEAPPSECPAGE 0x22
#define | XMEGA_NVM_CMD_WRITEAPPSECPAGE 0x24
#define | XMEGA_NVM_CMD_ERASEWRITEAPPSECPAGE 0x25
#define | XMEGA_NVM_CMD_APPCRC 0x38
#define | XMEGA_NVM_CMD_ERASEBOOTSEC 0x68
#define | XMEGA_NVM_CMD_ERASEBOOTSECPAGE 0x2A
#define | XMEGA_NVM_CMD_WRITEBOOTSECPAGE 0x2C
#define | XMEGA_NVM_CMD_ERASEWRITEBOOTSECPAGE 0x2D
#define | XMEGA_NVM_CMD_BOOTCRC 0x39
#define | XMEGA_NVM_CMD_READUSERSIG 0x03
#define | XMEGA_NVM_CMD_ERASEUSERSIG 0x18
#define | XMEGA_NVM_CMD_WRITEUSERSIG 0x1A
#define | XMEGA_NVM_CMD_READCALIBRATION 0x02
#define | XMEGA_NVM_CMD_READFUSE 0x07
#define | XMEGA_NVM_CMD_WRITEFUSE 0x4C
#define | XMEGA_NVM_CMD_WRITELOCK 0x08
#define | XMEGA_NVM_CMD_LOADEEPROMPAGEBUFF 0x33
#define | XMEGA_NVM_CMD_ERASEEEPROMPAGEBUFF 0x36
#define | XMEGA_NVM_CMD_ERASEEEPROM 0x30
#define | XMEGA_NVM_CMD_ERASEEEPROMPAGE 0x32
#define | XMEGA_NVM_CMD_WRITEEEPROMPAGE 0x34
#define | XMEGA_NVM_CMD_ERASEWRITEEEPROMPAGE 0x35
#define | XMEGA_NVM_CMD_READEEPROM 0x06

## Functions

bool | XMEGANVM_WaitWhileNVMBusBusy (void)
bool | XMEGANVM_WaitWhileNVMControllerBusy (void)
bool | XMEGANVM_EnablePDI (void)
void | XMEGANVM_DisablePDI (void)
bool | XMEGANVM_GetMemoryCRC (const uint8_t CRCCommand, uint32_t *const CRCDest)
bool | XMEGANVM_ReadMemory (const uint32_t ReadAddress, uint8_t *ReadBuffer, uint16_t ReadSize)
bool | XMEGANVM_WriteByteMemory (const uint8_t WriteCommand, const uint32_t WriteAddress, const uint8_t Byte)
bool | XMEGANVM_WritePageMemory (const uint8_t WriteBuffCommand, const uint8_t EraseBuffCommand, const uint8_t WritePageCommand, const uint8_t PageMode, const uint32_t WriteAddress, const uint8_t *WriteBuffer, uint16_t WriteSize)
bool | XMEGANVM_EraseMemory (const uint8_t EraseCommand, const uint32_t Address)

## Detailed Description

Header file for XMEGANVM.c.

## Macro Definition Documentation

## § XMEGA_CRC_LENGTH_BYTES

#define XMEGA_CRC_LENGTH_BYTES 3

## § XMEGA_NVM_BIT_CTRLA_CMDEX

#define XMEGA_NVM_BIT_CTRLA_CMDEX (1 << 0)

## § XMEGA_NVM_CMD_APPCRC

#define XMEGA_NVM_CMD_APPCRC 0x38

## § XMEGA_NVM_CMD_BOOTCRC

#define XMEGA_NVM_CMD_BOOTCRC 0x39

## § XMEGA_NVM_CMD_CHIPERASE

#define XMEGA_NVM_CMD_CHIPERASE 0x40

## § XMEGA_NVM_CMD_ERASEAPPSEC

#define XMEGA_NVM_CMD_ERASEAPPSEC 0x20

## § XMEGA_NVM_CMD_ERASEAPPSECPAGE

#define XMEGA_NVM_CMD_ERASEAPPSECPAGE 0x22

## § XMEGA_NVM_CMD_ERASEBOOTSEC

#define XMEGA_NVM_CMD_ERASEBOOTSEC 0x68

## § XMEGA_NVM_CMD_ERASEBOOTSECPAGE

#define XMEGA_NVM_CMD_ERASEBOOTSECPAGE 0x2A

## § XMEGA_NVM_CMD_ERASEEEPROM

#define XMEGA_NVM_CMD_ERASEEEPROM 0x30

## § XMEGA_NVM_CMD_ERASEEEPROMPAGE

#define XMEGA_NVM_CMD_ERASEEEPROMPAGE 0x32

## § XMEGA_NVM_CMD_ERASEEEPROMPAGEBUFF

#define XMEGA_NVM_CMD_ERASEEEPROMPAGEBUFF 0x36

## § XMEGA_NVM_CMD_ERASEFLASHPAGE

#define XMEGA_NVM_CMD_ERASEFLASHPAGE 0x2B

## § XMEGA_NVM_CMD_ERASEFLASHPAGEBUFF

#define XMEGA_NVM_CMD_ERASEFLASHPAGEBUFF 0x26

## § XMEGA_NVM_CMD_ERASEUSERSIG

#define XMEGA_NVM_CMD_ERASEUSERSIG 0x18

## § XMEGA_NVM_CMD_ERASEWRITEAPPSECPAGE

#define XMEGA_NVM_CMD_ERASEWRITEAPPSECPAGE 0x25

## § XMEGA_NVM_CMD_ERASEWRITEBOOTSECPAGE

#define XMEGA_NVM_CMD_ERASEWRITEBOOTSECPAGE 0x2D

## § XMEGA_NVM_CMD_ERASEWRITEEEPROMPAGE

#define XMEGA_NVM_CMD_ERASEWRITEEEPROMPAGE 0x35

## § XMEGA_NVM_CMD_ERASEWRITEFLASH

#define XMEGA_NVM_CMD_ERASEWRITEFLASH 0x2F

## § XMEGA_NVM_CMD_FLASHCRC

#define XMEGA_NVM_CMD_FLASHCRC 0x78

## § XMEGA_NVM_CMD_LOADEEPROMPAGEBUFF

#define XMEGA_NVM_CMD_LOADEEPROMPAGEBUFF 0x33

## § XMEGA_NVM_CMD_LOADFLASHPAGEBUFF

#define XMEGA_NVM_CMD_LOADFLASHPAGEBUFF 0x23

## § XMEGA_NVM_CMD_NOOP

#define XMEGA_NVM_CMD_NOOP 0x00

## § XMEGA_NVM_CMD_READCALIBRATION

#define XMEGA_NVM_CMD_READCALIBRATION 0x02

## § XMEGA_NVM_CMD_READEEPROM

#define XMEGA_NVM_CMD_READEEPROM 0x06

## § XMEGA_NVM_CMD_READFUSE

#define XMEGA_NVM_CMD_READFUSE 0x07

## § XMEGA_NVM_CMD_READNVM

#define XMEGA_NVM_CMD_READNVM 0x43

## § XMEGA_NVM_CMD_READUSERSIG

#define XMEGA_NVM_CMD_READUSERSIG 0x03

## § XMEGA_NVM_CMD_WRITEAPPSECPAGE

#define XMEGA_NVM_CMD_WRITEAPPSECPAGE 0x24

## § XMEGA_NVM_CMD_WRITEBOOTSECPAGE

#define XMEGA_NVM_CMD_WRITEBOOTSECPAGE 0x2C

## § XMEGA_NVM_CMD_WRITEEEPROMPAGE

#define XMEGA_NVM_CMD_WRITEEEPROMPAGE 0x34

## § XMEGA_NVM_CMD_WRITEFLASHPAGE

#define XMEGA_NVM_CMD_WRITEFLASHPAGE 0x2E

## § XMEGA_NVM_CMD_WRITEFUSE

#define XMEGA_NVM_CMD_WRITEFUSE 0x4C

## § XMEGA_NVM_CMD_WRITELOCK

#define XMEGA_NVM_CMD_WRITELOCK 0x08

## § XMEGA_NVM_CMD_WRITEUSERSIG

#define XMEGA_NVM_CMD_WRITEUSERSIG 0x1A

## § XMEGA_NVM_REG_ADDR0

#define XMEGA_NVM_REG_ADDR0 0x00

## § XMEGA_NVM_REG_ADDR1

#define XMEGA_NVM_REG_ADDR1 0x01

## § XMEGA_NVM_REG_ADDR2

#define XMEGA_NVM_REG_ADDR2 0x02

## § XMEGA_NVM_REG_CMD

#define XMEGA_NVM_REG_CMD 0x0A

## § XMEGA_NVM_REG_CTRLA

#define XMEGA_NVM_REG_CTRLA 0x0B

## § XMEGA_NVM_REG_CTRLB

#define XMEGA_NVM_REG_CTRLB 0x0C

## § XMEGA_NVM_REG_DAT0

#define XMEGA_NVM_REG_DAT0 0x04

## § XMEGA_NVM_REG_DAT1

#define XMEGA_NVM_REG_DAT1 0x05

## § XMEGA_NVM_REG_DAT2

#define XMEGA_NVM_REG_DAT2 0x06

## § XMEGA_NVM_REG_INTCTRL

#define XMEGA_NVM_REG_INTCTRL 0x0D

## § XMEGA_NVM_REG_LOCKBITS

#define XMEGA_NVM_REG_LOCKBITS 0x10

## § XMEGA_NVM_REG_STATUS

#define XMEGA_NVM_REG_STATUS 0x0F

## Function Documentation

## § XMEGANVM_DisablePDI()

void XMEGANVM_DisablePDI | ( | void |  | ) |

Removes access to the target's NVM controller and physically disables the target's physical PDI interface.

## § XMEGANVM_EnablePDI()

bool XMEGANVM_EnablePDI | ( | void |  | ) |

Enables the physical PDI interface on the target and enables access to the internal NVM controller.

Returns
  Boolean `true` if the PDI interface was enabled successfully, `false` otherwise

## § XMEGANVM_EraseMemory()

bool XMEGANVM_EraseMemory | ( | const uint8_t | EraseCommand,
|  | const uint32_t | Address
| ) |  |

Erases a specific memory space of the target.

Parameters

  [in] | EraseCommand | NVM erase command to send to the device
  [in] | Address | Address inside the memory space to erase

Returns
  Boolean `true` if the command sequence complete successfully

## § XMEGANVM_GetMemoryCRC()

bool XMEGANVM_GetMemoryCRC | ( | const uint8_t | CRCCommand,
|  | uint32_t *const | CRCDest
| ) |  |

Retrieves the CRC value of the given memory space.

Parameters

  [in] | CRCCommand | NVM CRC command to issue to the target
  [out] | CRCDest | CRC Destination when read from the target

Returns
  Boolean `true` if the command sequence complete successfully

## § XMEGANVM_ReadMemory()

bool XMEGANVM_ReadMemory | ( | const uint32_t | ReadAddress,
|  | uint8_t * | ReadBuffer,
|  | uint16_t | ReadSize
| ) |  |

Reads memory from the target's memory spaces.

Parameters

  [in] | ReadAddress | Start address to read from within the target's address space
  [out] | ReadBuffer | Buffer to store read data into
  [in] | ReadSize | Number of bytes to read

Returns
  Boolean `true` if the command sequence complete successfully

## § XMEGANVM_WaitWhileNVMBusBusy()

bool XMEGANVM_WaitWhileNVMBusBusy | ( | void |  | ) |

Busy-waits while the NVM controller is busy performing a NVM operation, such as a FLASH page read or CRC calculation.

Returns
  Boolean `true` if the NVM controller became ready within the timeout period, `false` otherwise

## § XMEGANVM_WaitWhileNVMControllerBusy()

bool XMEGANVM_WaitWhileNVMControllerBusy | ( | void |  | ) |

Waits while the target's NVM controller is busy performing an operation, exiting if the timeout period expires.

Returns
  Boolean `true` if the NVM controller became ready within the timeout period, `false` otherwise

## § XMEGANVM_WriteByteMemory()

bool XMEGANVM_WriteByteMemory | ( | const uint8_t | WriteCommand,
|  | const uint32_t | WriteAddress,
|  | const uint8_t | Byte
| ) |  |

Writes byte addressed memory to the target's memory spaces.

Parameters

  [in] | WriteCommand | Command to send to the device to write each memory byte
  [in] | WriteAddress | Address to write to within the target's address space
  [in] | Byte | Byte to write to the target

Returns
  Boolean `true` if the command sequence complete successfully

## § XMEGANVM_WritePageMemory()

bool XMEGANVM_WritePageMemory | ( | const uint8_t | WriteBuffCommand,
|  | const uint8_t | EraseBuffCommand,
|  | const uint8_t | WritePageCommand,
|  | const uint8_t | PageMode,
|  | const uint32_t | WriteAddress,
|  | const uint8_t * | WriteBuffer,
|  | uint16_t | WriteSize
| ) |  |

Writes page addressed memory to the target's memory spaces.

Parameters

  [in] | WriteBuffCommand | Command to send to the device to write a byte to the memory page buffer
  [in] | EraseBuffCommand | Command to send to the device to erase the memory page buffer
  [in] | WritePageCommand | Command to send to the device to write the page buffer to the destination memory
  [in] | PageMode | Bitfield indicating what operations need to be executed on the specified page
  [in] | WriteAddress | Start address to write the page data to within the target's address space
  [in] | WriteBuffer | Buffer to source data from
  [in] | WriteSize | Number of bytes to write

Returns
  Boolean `true` if the command sequence complete successfully