Keyboard firmwares for Atmel AVR and Cortex-M
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

XPROGProtocol.h 4.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. /*
  2. LUFA Library
  3. Copyright (C) Dean Camera, 2014.
  4. dean [at] fourwalledcubicle [dot] com
  5. www.lufa-lib.org
  6. */
  7. /*
  8. Copyright 2014 Dean Camera (dean [at] fourwalledcubicle [dot] com)
  9. Permission to use, copy, modify, distribute, and sell this
  10. software and its documentation for any purpose is hereby granted
  11. without fee, provided that the above copyright notice appear in
  12. all copies and that both that the copyright notice and this
  13. permission notice and warranty disclaimer appear in supporting
  14. documentation, and that the name of the author not be used in
  15. advertising or publicity pertaining to distribution of the
  16. software without specific, written prior permission.
  17. The author disclaims all warranties with regard to this
  18. software, including all implied warranties of merchantability
  19. and fitness. In no event shall the author be liable for any
  20. special, indirect or consequential damages or any damages
  21. whatsoever resulting from loss of use, data or profits, whether
  22. in an action of contract, negligence or other tortious action,
  23. arising out of or in connection with the use or performance of
  24. this software.
  25. */
  26. /** \file
  27. *
  28. * Header file for XPROGProtocol.c.
  29. */
  30. #ifndef _XPROG_PROTOCOL_
  31. #define _XPROG_PROTOCOL_
  32. /* Includes: */
  33. #include <avr/io.h>
  34. #include <util/delay.h>
  35. #include <stdio.h>
  36. #include <LUFA/Drivers/USB/USB.h>
  37. #include "../V2Protocol.h"
  38. #include "XMEGANVM.h"
  39. #include "TINYNVM.h"
  40. #include "Config/AppConfig.h"
  41. /* Preprocessor Checks: */
  42. #if ((BOARD == BOARD_XPLAIN) || (BOARD == BOARD_XPLAIN_REV1))
  43. /* On the XPLAIN board, we only need PDI programming
  44. for the ATXMEGA128A1 - disable ISP to prevent hardware
  45. damage and force-enable XPROG.
  46. */
  47. #undef ENABLE_ISP_PROTOCOL
  48. #if !defined(ENABLE_XPROG_PROTOCOL)
  49. #define ENABLE_XPROG_PROTOCOL
  50. #endif
  51. #endif
  52. /* Macros: */
  53. #define XPROG_CMD_ENTER_PROGMODE 0x01
  54. #define XPROG_CMD_LEAVE_PROGMODE 0x02
  55. #define XPROG_CMD_ERASE 0x03
  56. #define XPROG_CMD_WRITE_MEM 0x04
  57. #define XPROG_CMD_READ_MEM 0x05
  58. #define XPROG_CMD_CRC 0x06
  59. #define XPROG_CMD_SET_PARAM 0x07
  60. #define XPROG_MEM_TYPE_APPL 1
  61. #define XPROG_MEM_TYPE_BOOT 2
  62. #define XPROG_MEM_TYPE_EEPROM 3
  63. #define XPROG_MEM_TYPE_FUSE 4
  64. #define XPROG_MEM_TYPE_LOCKBITS 5
  65. #define XPROG_MEM_TYPE_USERSIG 6
  66. #define XPROG_MEM_TYPE_FACTORY_CALIBRATION 7
  67. #define XPROG_ERASE_CHIP 1
  68. #define XPROG_ERASE_APP 2
  69. #define XPROG_ERASE_BOOT 3
  70. #define XPROG_ERASE_EEPROM 4
  71. #define XPROG_ERASE_APP_PAGE 5
  72. #define XPROG_ERASE_BOOT_PAGE 6
  73. #define XPROG_ERASE_EEPROM_PAGE 7
  74. #define XPROG_ERASE_USERSIG 8
  75. #define XPROG_MEM_WRITE_ERASE 0
  76. #define XPROG_MEM_WRITE_WRITE 1
  77. #define XPROG_CRC_APP 1
  78. #define XPROG_CRC_BOOT 2
  79. #define XPROG_CRC_FLASH 3
  80. #define XPROG_ERR_OK 0
  81. #define XPROG_ERR_FAILED 1
  82. #define XPROG_ERR_COLLISION 2
  83. #define XPROG_ERR_TIMEOUT 3
  84. #define XPROG_PARAM_NVMBASE 0x01
  85. #define XPROG_PARAM_EEPPAGESIZE 0x02
  86. #define XPROG_PARAM_NVMCMD_REG 0x03
  87. #define XPROG_PARAM_NVMCSR_REG 0x04
  88. #define XPROG_PARAM_UNKNOWN_1 0x05
  89. #define XPROG_PROTOCOL_PDI 0x00
  90. #define XPROG_PROTOCOL_JTAG 0x01
  91. #define XPROG_PROTOCOL_TPI 0x02
  92. #define XPROG_PAGEMODE_WRITE (1 << 1)
  93. #define XPROG_PAGEMODE_ERASE (1 << 0)
  94. /* External Variables: */
  95. extern uint32_t XPROG_Param_NVMBase;
  96. extern uint16_t XPROG_Param_EEPageSize;
  97. extern uint8_t XPROG_Param_NVMCSRRegAddr;
  98. extern uint8_t XPROG_Param_NVMCMDRegAddr;
  99. /* Function Prototypes: */
  100. void XPROGProtocol_SetMode(void);
  101. void XPROGProtocol_Command(void);
  102. #if (defined(INCLUDE_FROM_XPROGPROTOCOL_C) && defined(ENABLE_XPROG_PROTOCOL))
  103. static void XPROGProtocol_EnterXPROGMode(void);
  104. static void XPROGProtocol_LeaveXPROGMode(void);
  105. static void XPROGProtocol_SetParam(void);
  106. static void XPROGProtocol_Erase(void);
  107. static void XPROGProtocol_WriteMemory(void);
  108. static void XPROGProtocol_ReadMemory(void);
  109. static void XPROGProtocol_ReadCRC(void);
  110. #endif
  111. #endif