3      Copyright (C) Dean Camera, 2010. 
   5   dean [at] fourwalledcubicle [dot] com 
   6       www.fourwalledcubicle.com 
  10   Copyright 2010  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 disclaim 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" 
  49         /* Preprocessor Checks: */ 
  50                 #if ((BOARD == BOARD_XPLAIN) || (BOARD == BOARD_XPLAIN_REV1)) 
  51                         #undef ENABLE_ISP_PROTOCOL 
  53                         #if !defined(ENABLE_XPROG_PROTOCOL) 
  54                                 #define ENABLE_XPROG_PROTOCOL 
  58                 /** Serial carrier TPI/PDI speed when hardware TPI/PDI mode is used */ 
  59                 #define XPROG_HARDWARE_SPEED       1000000 
  61                 /** Total number of bits in a single USART frame */ 
  62                 #define BITS_IN_USART_FRAME        12 
  64                 #define PDI_CMD_LDS                0x00 
  65                 #define PDI_CMD_LD                 0x20 
  66                 #define PDI_CMD_STS                0x40 
  67                 #define PDI_CMD_ST                 0x60 
  68                 #define PDI_CMD_LDCS               0x80 
  69                 #define PDI_CMD_REPEAT             0xA0 
  70                 #define PDI_CMD_STCS               0xC0 
  71                 #define PDI_CMD_KEY                0xE0 
  73                 #define PDI_STATUS_REG             0 
  74                 #define PDI_RESET_REG              1 
  75                 #define PDI_CTRL_REG               2 
  77                 #define PDI_STATUS_NVM             (1 << 1) 
  79                 #define PDI_RESET_KEY              0x59 
  80                 #define PDI_NVMENABLE_KEY          (uint8_t[]){0x12, 0x89, 0xAB, 0x45, 0xCD, 0xD8, 0x88, 0xFF} 
  82                 #define PDI_DATSIZE_1BYTE          0 
  83                 #define PDI_DATSIZE_2BYTES         1 
  84                 #define PDI_DATSIZE_3BYTES         2 
  85                 #define PDI_DATSIZE_4BYTES         3 
  87                 #define PDI_POINTER_INDIRECT       0 
  88                 #define PDI_POINTER_INDIRECT_PI    1 
  89                 #define PDI_POINTER_DIRECT         2 
  91                 #define TPI_CMD_SLD                0x20 
  92                 #define TPI_CMD_SST                0x60 
  93                 #define TPI_CMD_SSTPR              0x68 
  94                 #define TPI_CMD_SIN                0x10 
  95                 #define TPI_CMD_SOUT               0x90 
  96                 #define TPI_CMD_SLDCS              0x80 
  97                 #define TPI_CMD_SSTCS              0xC0 
  98                 #define TPI_CMD_SKEY               0xE0 
 100                 #define TPI_STATUS_REG             0x00 
 101                 #define TPI_CTRL_REG               0x02 
 102                 #define TPI_ID_REG                 0x0F 
 104                 #define TPI_STATUS_NVM             (1 << 1) 
 106                 #define TPI_NVMENABLE_KEY          (uint8_t[]){0x12, 0x89, 0xAB, 0x45, 0xCD, 0xD8, 0x88, 0xFF} 
 108                 #define TPI_POINTER_INDIRECT       0 
 109                 #define TPI_POINTER_INDIRECT_PI    4 
 111         /* Function Prototypes: */ 
 112                 void    XPROGTarget_EnableTargetPDI(void); 
 113                 void    XPROGTarget_EnableTargetTPI(void); 
 114                 void    XPROGTarget_DisableTargetPDI(void); 
 115                 void    XPROGTarget_DisableTargetTPI(void); 
 116                 void    XPROGTarget_SendByte(const uint8_t Byte
); 
 117                 uint8_t XPROGTarget_ReceiveByte(void); 
 118                 void    XPROGTarget_SendBreak(void); 
 119                 bool    XPROGTarget_WaitWhileNVMBusBusy(void); 
 121                 #if (defined(INCLUDE_FROM_XPROGTARGET_C) && defined(ENABLE_XPROG_PROTOCOL)) 
 122                         static void XPROGTarget_SetTxMode(void); 
 123                         static void XPROGTarget_SetRxMode(void);