3      Copyright (C) Dean Camera, 2011. 
   5   dean [at] fourwalledcubicle [dot] com 
  10   Copyright 2011  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 XPROGProtocol.c. 
  36 #ifndef _XPROG_PROTOCOL_ 
  37 #define _XPROG_PROTOCOL_ 
  41                 #include <util/delay.h> 
  44                 #include <LUFA/Drivers/USB/USB.h> 
  46                 #include "../V2Protocol.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 
  60                 #define XPRG_CMD_ENTER_PROGMODE             0x01 
  61                 #define XPRG_CMD_LEAVE_PROGMODE             0x02 
  62                 #define XPRG_CMD_ERASE                      0x03 
  63                 #define XPRG_CMD_WRITE_MEM                  0x04 
  64                 #define XPRG_CMD_READ_MEM                   0x05 
  65                 #define XPRG_CMD_CRC                        0x06 
  66                 #define XPRG_CMD_SET_PARAM                  0x07 
  68                 #define XPRG_MEM_TYPE_APPL                  1 
  69                 #define XPRG_MEM_TYPE_BOOT                  2 
  70                 #define XPRG_MEM_TYPE_EEPROM                3 
  71                 #define XPRG_MEM_TYPE_FUSE                  4 
  72                 #define XPRG_MEM_TYPE_LOCKBITS              5 
  73                 #define XPRG_MEM_TYPE_USERSIG               6 
  74                 #define XPRG_MEM_TYPE_FACTORY_CALIBRATION   7 
  76                 #define XPRG_ERASE_CHIP                     1 
  77                 #define XPRG_ERASE_APP                      2 
  78                 #define XPRG_ERASE_BOOT                     3 
  79                 #define XPRG_ERASE_EEPROM                   4 
  80                 #define XPRG_ERASE_APP_PAGE                 5 
  81                 #define XPRG_ERASE_BOOT_PAGE                6 
  82                 #define XPRG_ERASE_EEPROM_PAGE              7 
  83                 #define XPRG_ERASE_USERSIG                  8 
  85                 #define XPRG_MEM_WRITE_ERASE                0 
  86                 #define XPRG_MEM_WRITE_WRITE                1 
  88                 #define XPRG_CRC_APP                        1 
  89                 #define XPRG_CRC_BOOT                       2 
  90                 #define XPRG_CRC_FLASH                      3 
  93                 #define XPRG_ERR_FAILED                     1 
  94                 #define XPRG_ERR_COLLISION                  2 
  95                 #define XPRG_ERR_TIMEOUT                    3 
  97                 #define XPRG_PARAM_NVMBASE                  0x01 
  98                 #define XPRG_PARAM_EEPPAGESIZE              0x02 
  99                 #define XPRG_PARAM_NVMCMD_REG               0x03 
 100                 #define XPRG_PARAM_NVMCSR_REG               0x04 
 102                 #define XPRG_PROTOCOL_PDI                   0x00 
 103                 #define XPRG_PROTOCOL_JTAG                  0x01 
 104                 #define XPRG_PROTOCOL_TPI                   0x02 
 106                 #define XPRG_PAGEMODE_WRITE                 (1 << 1) 
 107                 #define XPRG_PAGEMODE_ERASE                 (1 << 0) 
 109         /* External Variables: */ 
 110                 extern uint32_t XPROG_Param_NVMBase
; 
 111                 extern uint16_t XPROG_Param_EEPageSize
; 
 112                 extern uint8_t  XPROG_Param_NVMCSRRegAddr
; 
 113                 extern uint8_t  XPROG_Param_NVMCMDRegAddr
; 
 115         /* Function Prototypes: */ 
 116                 void XPROGProtocol_SetMode(void); 
 117                 void XPROGProtocol_Command(void); 
 119                 #if (defined(INCLUDE_FROM_XPROGPROTOCOL_C) && defined(ENABLE_XPROG_PROTOCOL)) 
 120                         static void XPROGProtocol_EnterXPROGMode(void); 
 121                         static void XPROGProtocol_LeaveXPROGMode(void); 
 122                         static void XPROGProtocol_SetParam(void); 
 123                         static void XPROGProtocol_Erase(void); 
 124                         static void XPROGProtocol_WriteMemory(void); 
 125                         static void XPROGProtocol_ReadMemory(void); 
 126                         static void XPROGProtocol_ReadCRC(void);