3 Copyright (C) Dean Camera, 2009.
5 dean [at] fourwalledcubicle [dot] com
6 www.fourwalledcubicle.com
10 Copyright 2009 Dean Camera (dean [at] fourwalledcubicle [dot] com)
12 Permission to use, copy, modify, and distribute this software
13 and its documentation for any purpose and without fee is hereby
14 granted, provided that the above copyright notice appear in all
15 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 * V2Protocol handler, to process V2 Protocol commands used in Atmel programmer devices.
36 #define INCLUDE_FROM_V2PROTOCOL_C
37 #include "V2Protocol.h"
39 ParameterItem_t ParameterTable
[] EEMEM
=
41 { .ParameterID
= PARAM_BUILD_NUMBER_LOW
,
42 .ParameterValue
= 0x00 },
43 { .ParameterID
= PARAM_BUILD_NUMBER_HIGH
,
44 .ParameterValue
= 0x00 },
45 { .ParameterID
= PARAM_HW_VER
,
46 .ParameterValue
= 0x01 },
47 { .ParameterID
= PARAM_SW_MAJOR
,
48 .ParameterValue
= 0x01 },
49 { .ParameterID
= PARAM_SW_MINOR
,
50 .ParameterValue
= 0x00 },
51 { .ParameterID
= PARAM_VTARGET
,
52 .ParameterValue
= 0x00 },
53 { .ParameterID
= PARAM_SCK_DURATION
,
54 .ParameterValue
= 0x00 },
55 { .ParameterID
= PARAM_RESET_POLARITY
,
56 .ParameterValue
= 0x00 },
57 { .ParameterID
= PARAM_STATUS_TGT_CONN
,
58 .ParameterValue
= 0x00 },
59 { .ParameterID
= PARAM_DISCHARGEDELAY
,
60 .ParameterValue
= 0x00 },
63 void V2Protocol_ProcessCommand(void)
65 uint8_t V2Command
= Endpoint_Read_Byte();
70 V2Protocol_ProcessCmdSignOn();
72 case CMD_SET_PARAMETER
:
73 case CMD_GET_PARAMETER
:
74 V2Protocol_ProcessCmdGetSetParam(V2Command
);
77 while (Endpoint_BytesInEndpoint() == AVRISP_DATA_EPSIZE
)
80 while (!(Endpoint_IsOUTReceived()));
84 Endpoint_SetEndpointDirection(ENDPOINT_DIR_IN
);
86 Endpoint_Write_Byte(STATUS_CMD_UNKNOWN
);
91 printf("COMMAND 0x%02x\r\n", V2Command
);
93 Endpoint_WaitUntilReady();
95 /* Reset Endpoint direction to OUT ready for next command */
96 Endpoint_SetEndpointDirection(ENDPOINT_DIR_OUT
);
99 static ParameterItem_t
* V2Protocol_GetParameterItem(uint8_t ParamID
)
101 for (uint8_t TableIndex
= 0; TableIndex
< (sizeof(ParameterTable
) / sizeof(ParameterTable
[0])); TableIndex
++)
103 if (ParamID
== eeprom_read_byte(&ParameterTable
[TableIndex
].ParameterID
))
104 return &ParameterTable
[TableIndex
];
110 static void V2Protocol_ProcessCmdSignOn(void)
113 Endpoint_SetEndpointDirection(ENDPOINT_DIR_IN
);
114 Endpoint_WaitUntilReady();
116 Endpoint_Write_Byte(CMD_SIGN_ON
);
117 Endpoint_Write_Byte(STATUS_CMD_OK
);
118 Endpoint_Write_Byte(PROGRAMMER_ID_LEN
);
119 Endpoint_Write_Stream_LE(PROGRAMMER_ID
, PROGRAMMER_ID_LEN
);
123 static void V2Protocol_ProcessCmdGetSetParam(uint8_t V2Command
)
125 uint8_t ParamID
= Endpoint_Read_Byte();
126 uint8_t ParamValue
= Endpoint_Read_Byte();
129 Endpoint_SetEndpointDirection(ENDPOINT_DIR_IN
);
130 Endpoint_WaitUntilReady();
132 ParameterItem_t
* ParameterItem
= V2Protocol_GetParameterItem(ParamID
);
134 if (ParameterItem
!= NULL
)
136 Endpoint_Write_Byte(V2Command
);
137 Endpoint_Write_Byte(STATUS_CMD_OK
);
139 if (V2Command
== CMD_SET_PARAMETER
)
140 eeprom_write_byte(&ParameterItem
->ParameterValue
, ParamValue
);
142 Endpoint_Write_Byte(eeprom_read_byte(&ParameterItem
->ParameterValue
));
146 Endpoint_Write_Byte(STATUS_CMD_FAILED
);