b2064fc26ce6149a51c78f75076e15c8810ff48c
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 * Target-related functions for the V2 Protocol decoder.
36 #include "V2ProtocolTarget.h"
38 /** Current memory address for FLASH/EEPROM memory read/write commands */
39 uint32_t CurrentAddress
;
41 uint8_t V2Protocol_GetSPIPrescalerMask(void)
43 static const uint8_t SPIMaskFromSCKDuration
[] =
45 #if (F_CPU == 8000000)
48 SPI_SPEED_FCPU_DIV_2
, SPI_SPEED_FCPU_DIV_4
, SPI_SPEED_FCPU_DIV_8
,
49 SPI_SPEED_FCPU_DIV_16
, SPI_SPEED_FCPU_DIV_32
, SPI_SPEED_FCPU_DIV_64
50 #if (F_CPU == 16000000)
51 , SPI_SPEED_FCPU_DIV_128
55 uint8_t SCKDuration
= V2Params_GetParameterValue(PARAM_SCK_DURATION
);
57 if (SCKDuration
>= sizeof(SPIMaskFromSCKDuration
))
58 SCKDuration
= (sizeof(SPIMaskFromSCKDuration
) - 1);
60 return SPIMaskFromSCKDuration
[SCKDuration
];
63 void V2Protocol_ChangeTargetResetLine(bool ResetTarget
)
67 RESET_LINE_DDR
|= RESET_LINE_MASK
;
69 if (!(V2Params_GetParameterValue(PARAM_RESET_POLARITY
)))
70 RESET_LINE_PORT
|= RESET_LINE_MASK
;
74 RESET_LINE_PORT
&= ~RESET_LINE_MASK
;
75 RESET_LINE_DDR
&= ~RESET_LINE_MASK
;
79 void V2Protocol_DelayMS(uint8_t MS
)
85 uint8_t V2Protocol_WaitForProgrammingComplete(uint16_t PollAddress
, uint8_t ProgrammingMode
)
92 uint8_t V2Protocol_WaitWhileTargetBusy(void)
94 uint8_t TimeoutMS
= TARGET_BUSY_TIMEOUT_MS
;
103 ResponseByte
= SPI_ReceiveByte();
105 V2Protocol_DelayMS(1);
107 while ((ResponseByte
& 0x01) && (TimeoutMS
--));
110 return STATUS_CMD_TOUT
;
112 return STATUS_CMD_OK
;
115 void V2Protocol_LoadExtendedAddress(void)
119 SPI_SendByte((CurrentAddress
& 0x00FF0000) >> 16);