3      Copyright (C) Dean Camera, 2014. 
   5   dean [at] fourwalledcubicle [dot] com 
  10   Copyright 2014  Dean Camera (dean [at] fourwalledcubicle [dot] com) 
  12   Permission to use, copy, modify, distribute, and sell this 
  13   software and its documentation for any purpose is hereby granted 
  14   without fee, provided that the above copyright notice appear in 
  15   all copies and that both that the copyright notice and this 
  16   permission notice and warranty disclaimer appear in supporting 
  17   documentation, and that the name of the author not be used in 
  18   advertising or publicity pertaining to distribution of the 
  19   software without specific, written prior permission. 
  21   The author disclaims all warranties with regard to this 
  22   software, including all implied warranties of merchantability 
  23   and fitness.  In no event shall the author be liable for any 
  24   special, indirect or consequential damages or any damages 
  25   whatsoever resulting from loss of use, data or profits, whether 
  26   in an action of contract, negligence or other tortious action, 
  27   arising out of or in connection with the use or performance of 
  33  *  Header file for XPROGTarget.c. 
  36 #ifndef _XPROG_TARGET_ 
  37 #define _XPROG_TARGET_ 
  41                 #include <avr/interrupt.h> 
  44                 #include <LUFA/Common/Common.h> 
  46                 #include "../V2Protocol.h" 
  47                 #include "XPROGProtocol.h" 
  48                 #include "Config/AppConfig.h" 
  50         /* Preprocessor Checks: */ 
  51                 #if ((BOARD == BOARD_XPLAIN) || (BOARD == BOARD_XPLAIN_REV1)) 
  52                         #undef ENABLE_ISP_PROTOCOL 
  54                         #if !defined(ENABLE_XPROG_PROTOCOL) 
  55                                 #define ENABLE_XPROG_PROTOCOL 
  59                 /** Serial carrier TPI/PDI speed in Hz, when hardware TPI/PDI mode is used. */ 
  60                 #define XPROG_HARDWARE_SPEED       2000000 
  62                 /** Total number of bits in a single USART frame. */ 
  63                 #define BITS_IN_USART_FRAME        12 
  65                 /** \name PDI Related Constants 
  68                 #define PDI_CMD_LDS(AddressSize, DataSize)  (0x00 | (  AddressSize << 2) | DataSize) 
  69                 #define PDI_CMD_LD(PointerAccess, DataSize) (0x20 | (PointerAccess << 2) | DataSize) 
  70                 #define PDI_CMD_STS(AddressSize, DataSize)  (0x40 | (  AddressSize << 2) | DataSize) 
  71                 #define PDI_CMD_ST(PointerAccess, DataSize) (0x60 | (PointerAccess << 2) | DataSize) 
  72                 #define PDI_CMD_LDCS(PDIReg)                (0x80 | PDIReg) 
  73                 #define PDI_CMD_REPEAT(DataSize)            (0xA0 | DataSize) 
  74                 #define PDI_CMD_STCS(PDIReg)                (0xC0 | PDIReg) 
  75                 #define PDI_CMD_KEY                         0xE0 
  77                 #define PDI_REG_STATUS             0 
  78                 #define PDI_REG_RESET              1 
  79                 #define PDI_REG_CTRL               2 
  81                 #define PDI_STATUS_NVM             (1 << 1) 
  83                 #define PDI_RESET_KEY              0x59 
  84                 #define PDI_NVMENABLE_KEY          (uint8_t[]){0x12, 0x89, 0xAB, 0x45, 0xCD, 0xD8, 0x88, 0xFF} 
  86                 #define PDI_DATASIZE_1BYTE         0 
  87                 #define PDI_DATASIZE_2BYTES        1 
  88                 #define PDI_DATASIZE_3BYTES        2 
  89                 #define PDI_DATASIZE_4BYTES        3 
  91                 #define PDI_POINTER_INDIRECT       0 
  92                 #define PDI_POINTER_INDIRECT_PI    1 
  93                 #define PDI_POINTER_DIRECT         2 
  96                 /** \name TPI Related Constants 
  99                 #define TPI_CMD_SLD(PointerAccess) (0x20 | PointerAccess) 
 100                 #define TPI_CMD_SST(PointerAccess) (0x60 | PointerAccess) 
 101                 #define TPI_CMD_SSTPR              0x68 
 102                 #define TPI_CMD_SIN(Address)       (0x10 | ((Address & 0x30) << 1) | (Address & 0x0F)) 
 103                 #define TPI_CMD_SOUT(Address)      (0x90 | ((Address & 0x30) << 1) | (Address & 0x0F)) 
 104                 #define TPI_CMD_SLDCS(TPIReg)      (0x80 | TPIReg) 
 105                 #define TPI_CMD_SSTCS(TPIReg)      (0xC0 | TPIReg) 
 106                 #define TPI_CMD_SKEY               0xE0 
 108                 #define TPI_REG_STATUS             0x00 
 109                 #define TPI_REG_CTRL               0x02 
 110                 #define TPI_REG_ID                 0x0F 
 112                 #define TPI_STATUS_NVM             (1 << 1) 
 114                 #define TPI_NVMENABLE_KEY          (uint8_t[]){0x12, 0x89, 0xAB, 0x45, 0xCD, 0xD8, 0x88, 0xFF} 
 116                 #define TPI_POINTER_INDIRECT       0 
 117                 #define TPI_POINTER_INDIRECT_PI    4 
 120         /* Function Prototypes: */ 
 121                 void    XPROGTarget_EnableTargetPDI(void); 
 122                 void    XPROGTarget_EnableTargetTPI(void); 
 123                 void    XPROGTarget_DisableTargetPDI(void); 
 124                 void    XPROGTarget_DisableTargetTPI(void); 
 125                 void    XPROGTarget_SendByte(const uint8_t Byte
); 
 126                 uint8_t XPROGTarget_ReceiveByte(void); 
 127                 void    XPROGTarget_SendIdle(void); 
 128                 bool    XPROGTarget_WaitWhileNVMBusBusy(void); 
 130                 #if (defined(INCLUDE_FROM_XPROGTARGET_C) && defined(ENABLE_XPROG_PROTOCOL)) 
 131                         static void XPROGTarget_SetTxMode(void); 
 132                         static void XPROGTarget_SetRxMode(void);