V2Protocol.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /*
  2. LUFA Library
  3. Copyright (C) Dean Camera, 2018.
  4. dean [at] fourwalledcubicle [dot] com
  5. www.lufa-lib.org
  6. */
  7. /*
  8. Copyright 2018 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 V2Protocol.c.
  29. */
  30. #ifndef _V2_PROTOCOL_
  31. #define _V2_PROTOCOL_
  32. /* Includes: */
  33. #include <avr/io.h>
  34. #include <avr/interrupt.h>
  35. #include <avr/wdt.h>
  36. #include <LUFA/Drivers/USB/USB.h>
  37. #include "../AVRISPDescriptors.h"
  38. #include "V2ProtocolConstants.h"
  39. #include "V2ProtocolParams.h"
  40. #include "ISP/ISPProtocol.h"
  41. #include "XPROG/XPROGProtocol.h"
  42. #include "Config/AppConfig.h"
  43. /* Preprocessor Checks: */
  44. #if ((BOARD == BOARD_XPLAIN) || (BOARD == BOARD_XPLAIN_REV1))
  45. #undef ENABLE_ISP_PROTOCOL
  46. #if !defined(ENABLE_XPROG_PROTOCOL)
  47. #define ENABLE_XPROG_PROTOCOL
  48. #endif
  49. #endif
  50. #if defined(USB_SERIES_4_AVR) && ((VTARGET_ADC_CHANNEL == 2) || (VTARGET_ADC_CHANNEL == 3)) && !defined(NO_VTARGET_DETECT)
  51. #error The U4 AVR chips do not contain ADC channels 2 or 3. Please change VTARGET_ADC_CHANNEL or define NO_VTARGET_DETECT in the makefile.
  52. #endif
  53. #if defined(VTARGET_USE_INTERNAL_REF)
  54. #undef VTARGET_REF_VOLTS
  55. #define VTARGET_REF_VOLTS 2.56
  56. #define VTARGET_REF_MASK ADC_REFERENCE_INT2560MV
  57. #else
  58. #define VTARGET_REF_MASK ADC_REFERENCE_AVCC
  59. #endif
  60. /* Macros: */
  61. /** Programmer ID string, returned to the host during the CMD_SIGN_ON command processing. */
  62. #define PROGRAMMER_ID "AVRISP_MK2"
  63. /** Timeout period for each issued command from the host before it is aborted (in 10ms ticks). */
  64. #define COMMAND_TIMEOUT_TICKS 100
  65. /** Command timeout ticks remaining counter, GPIOR for speed. */
  66. #define TimeoutTicksRemaining GPIOR1
  67. /** MUX mask for the VTARGET ADC channel number. */
  68. #define VTARGET_ADC_CHANNEL_MASK ADC_GET_CHANNEL_MASK(VTARGET_ADC_CHANNEL)
  69. /* External Variables: */
  70. extern uint32_t CurrentAddress;
  71. extern bool MustLoadExtendedAddress;
  72. /* Function Prototypes: */
  73. void V2Protocol_Init(void);
  74. void V2Protocol_ProcessCommand(void);
  75. #if defined(INCLUDE_FROM_V2PROTOCOL_C)
  76. static void V2Protocol_UnknownCommand(const uint8_t V2Command);
  77. static void V2Protocol_SignOn(void);
  78. static void V2Protocol_GetSetParam(const uint8_t V2Command);
  79. static void V2Protocol_ResetProtection(void);
  80. static void V2Protocol_LoadAddress(void);
  81. #endif
  82. #endif