3 Copyright (C) Dean Camera, 2018.
5 dean [at] fourwalledcubicle [dot] com
10 Copyright 2018 Dean Camera (dean [at] fourwalledcubicle [dot] com)
12 Function ISPProtocol_Calibrate() copyright 2018 Jacob September
14 Permission to use, copy, modify, distribute, and sell this
15 software and its documentation for any purpose is hereby granted
16 without fee, provided that the above copyright notice appear in
17 all copies and that both that the copyright notice and this
18 permission notice and warranty disclaimer appear in supporting
19 documentation, and that the name of the author not be used in
20 advertising or publicity pertaining to distribution of the
21 software without specific, written prior permission.
23 The author disclaims all warranties with regard to this
24 software, including all implied warranties of merchantability
25 and fitness. In no event shall the author be liable for any
26 special, indirect or consequential damages or any damages
27 whatsoever resulting from loss of use, data or profits, whether
28 in an action of contract, negligence or other tortious action,
29 arising out of or in connection with the use or performance of
35 * ISP Protocol handler, to process V2 Protocol wrapped ISP commands used in Atmel programmer devices.
38 #include "ISPProtocol.h"
40 #if defined(ENABLE_ISP_PROTOCOL) || defined(__DOXYGEN__)
42 /** Handler for the CMD_ENTER_PROGMODE_ISP command, which attempts to enter programming mode on
43 * the attached device, returning success or failure back to the host.
45 void ISPProtocol_EnterISPMode(void)
50 uint8_t PinStabDelayMS
;
51 uint8_t ExecutionDelayMS
;
56 uint8_t EnterProgBytes
[4];
59 Endpoint_Read_Stream_LE(&Enter_ISP_Params
, sizeof(Enter_ISP_Params
), NULL
);
62 Endpoint_SelectEndpoint(AVRISP_DATA_IN_EPADDR
);
63 Endpoint_SetEndpointDirection(ENDPOINT_DIR_IN
);
65 uint8_t ResponseStatus
= STATUS_CMD_FAILED
;
69 /* Perform execution delay, initialize SPI bus */
70 ISPProtocol_DelayMS(Enter_ISP_Params
.ExecutionDelayMS
);
71 ISPTarget_EnableTargetISP();
73 ISPTarget_ChangeTargetResetLine(true);
74 ISPProtocol_DelayMS(Enter_ISP_Params
.PinStabDelayMS
);
76 /* Continuously attempt to synchronize with the target until either the number of attempts specified
77 * by the host has exceeded, or the the device sends back the expected response values */
78 while (Enter_ISP_Params
.SynchLoops
-- && TimeoutTicksRemaining
)
80 uint8_t ResponseBytes
[4];
82 for (uint8_t RByte
= 0; RByte
< sizeof(ResponseBytes
); RByte
++)
84 ISPProtocol_DelayMS(Enter_ISP_Params
.ByteDelay
);
85 ResponseBytes
[RByte
] = ISPTarget_TransferByte(Enter_ISP_Params
.EnterProgBytes
[RByte
]);
88 /* Check if polling disabled, or if the polled value matches the expected value */
89 if (!(Enter_ISP_Params
.PollIndex
) || (ResponseBytes
[Enter_ISP_Params
.PollIndex
- 1] == Enter_ISP_Params
.PollValue
))
91 ResponseStatus
= STATUS_CMD_OK
;
96 ISPTarget_ChangeTargetResetLine(false);
97 ISPProtocol_DelayMS(Enter_ISP_Params
.PinStabDelayMS
);
98 ISPTarget_ChangeTargetResetLine(true);
99 ISPProtocol_DelayMS(Enter_ISP_Params
.PinStabDelayMS
);
103 Endpoint_Write_8(CMD_ENTER_PROGMODE_ISP
);
104 Endpoint_Write_8(ResponseStatus
);
108 /** Handler for the CMD_LEAVE_ISP command, which releases the target from programming mode. */
109 void ISPProtocol_LeaveISPMode(void)
117 Endpoint_Read_Stream_LE(&Leave_ISP_Params
, sizeof(Leave_ISP_Params
), NULL
);
120 Endpoint_SelectEndpoint(AVRISP_DATA_IN_EPADDR
);
121 Endpoint_SetEndpointDirection(ENDPOINT_DIR_IN
);
123 /* Perform pre-exit delay, release the target /RESET, disable the SPI bus and perform the post-exit delay */
124 ISPProtocol_DelayMS(Leave_ISP_Params
.PreDelayMS
);
125 ISPTarget_ChangeTargetResetLine(false);
126 ISPTarget_DisableTargetISP();
127 ISPProtocol_DelayMS(Leave_ISP_Params
.PostDelayMS
);
129 Endpoint_Write_8(CMD_LEAVE_PROGMODE_ISP
);
130 Endpoint_Write_8(STATUS_CMD_OK
);
134 /** Handler for the CMD_PROGRAM_FLASH_ISP and CMD_PROGRAM_EEPROM_ISP commands, writing out bytes,
135 * words or pages of data to the attached device.
137 * \param[in] V2Command Issued V2 Protocol command byte from the host
139 void ISPProtocol_ProgramMemory(uint8_t V2Command
)
143 uint16_t BytesToWrite
;
144 uint8_t ProgrammingMode
;
146 uint8_t ProgrammingCommands
[3];
149 uint8_t ProgData
[256]; // Note, the Jungo driver has a very short ACK timeout period, need to buffer the
150 } Write_Memory_Params
; // whole page and ACK the packet as fast as possible to prevent it from aborting
152 Endpoint_Read_Stream_LE(&Write_Memory_Params
, (sizeof(Write_Memory_Params
) -
153 sizeof(Write_Memory_Params
.ProgData
)), NULL
);
154 Write_Memory_Params
.BytesToWrite
= SwapEndian_16(Write_Memory_Params
.BytesToWrite
);
156 if (Write_Memory_Params
.BytesToWrite
> sizeof(Write_Memory_Params
.ProgData
))
159 Endpoint_SelectEndpoint(AVRISP_DATA_IN_EPADDR
);
160 Endpoint_SetEndpointDirection(ENDPOINT_DIR_IN
);
162 Endpoint_Write_8(V2Command
);
163 Endpoint_Write_8(STATUS_CMD_FAILED
);
168 Endpoint_Read_Stream_LE(&Write_Memory_Params
.ProgData
, Write_Memory_Params
.BytesToWrite
, NULL
);
170 // The driver will terminate transfers that are a round multiple of the endpoint bank in size with a ZLP, need
171 // to catch this and discard it before continuing on with packet processing to prevent communication issues
172 if (((sizeof(uint8_t) + sizeof(Write_Memory_Params
) - sizeof(Write_Memory_Params
.ProgData
)) +
173 Write_Memory_Params
.BytesToWrite
) % AVRISP_DATA_EPSIZE
== 0)
176 Endpoint_WaitUntilReady();
180 Endpoint_SelectEndpoint(AVRISP_DATA_IN_EPADDR
);
181 Endpoint_SetEndpointDirection(ENDPOINT_DIR_IN
);
183 uint8_t ProgrammingStatus
= STATUS_CMD_OK
;
184 uint8_t PollValue
= (V2Command
== CMD_PROGRAM_FLASH_ISP
) ? Write_Memory_Params
.PollValue1
:
185 Write_Memory_Params
.PollValue2
;
186 uint16_t PollAddress
= 0;
187 uint8_t* NextWriteByte
= Write_Memory_Params
.ProgData
;
188 uint16_t PageStartAddress
= (CurrentAddress
& 0xFFFF);
190 for (uint16_t CurrentByte
= 0; CurrentByte
< Write_Memory_Params
.BytesToWrite
; CurrentByte
++)
192 uint8_t ByteToWrite
= *(NextWriteByte
++);
193 uint8_t ProgrammingMode
= Write_Memory_Params
.ProgrammingMode
;
195 /* Check to see if we need to send a LOAD EXTENDED ADDRESS command to the target */
196 if (MustLoadExtendedAddress
)
198 ISPTarget_LoadExtendedAddress();
199 MustLoadExtendedAddress
= false;
202 ISPTarget_SendByte(Write_Memory_Params
.ProgrammingCommands
[0]);
203 ISPTarget_SendByte(CurrentAddress
>> 8);
204 ISPTarget_SendByte(CurrentAddress
& 0xFF);
205 ISPTarget_SendByte(ByteToWrite
);
207 /* AVR FLASH addressing requires us to modify the write command based on if we are writing a high
208 * or low byte at the current word address */
209 if (V2Command
== CMD_PROGRAM_FLASH_ISP
)
210 Write_Memory_Params
.ProgrammingCommands
[0] ^= READ_WRITE_HIGH_BYTE_MASK
;
212 /* Check to see if we have a valid polling address */
213 if (!(PollAddress
) && (ByteToWrite
!= PollValue
))
215 if ((CurrentByte
& 0x01) && (V2Command
== CMD_PROGRAM_FLASH_ISP
))
216 Write_Memory_Params
.ProgrammingCommands
[2] |= READ_WRITE_HIGH_BYTE_MASK
;
218 Write_Memory_Params
.ProgrammingCommands
[2] &= ~READ_WRITE_HIGH_BYTE_MASK
;
220 PollAddress
= (CurrentAddress
& 0xFFFF);
223 /* If in word programming mode, commit the byte to the target's memory */
224 if (!(ProgrammingMode
& PROG_MODE_PAGED_WRITES_MASK
))
226 /* If the current polling address is invalid, switch to timed delay write completion mode */
227 if (!(PollAddress
) && !(ProgrammingMode
& PROG_MODE_WORD_READYBUSY_MASK
))
228 ProgrammingMode
= (ProgrammingMode
& ~PROG_MODE_WORD_VALUE_MASK
) | PROG_MODE_WORD_TIMEDELAY_MASK
;
230 ProgrammingStatus
= ISPTarget_WaitForProgComplete(ProgrammingMode
, PollAddress
, PollValue
,
231 Write_Memory_Params
.DelayMS
,
232 Write_Memory_Params
.ProgrammingCommands
[2]);
234 /* Abort the programming loop early if the byte/word programming failed */
235 if (ProgrammingStatus
!= STATUS_CMD_OK
)
238 /* Must reset the polling address afterwards, so it is not erroneously used for the next byte */
242 /* EEPROM just increments the address each byte, flash needs to increment on each word and
243 * also check to ensure that a LOAD EXTENDED ADDRESS command is issued each time the extended
244 * address boundary has been crossed during FLASH memory programming */
245 if ((CurrentByte
& 0x01) || (V2Command
== CMD_PROGRAM_EEPROM_ISP
))
249 if ((V2Command
== CMD_PROGRAM_FLASH_ISP
) && !(CurrentAddress
& 0xFFFF))
250 MustLoadExtendedAddress
= true;
254 /* If the current page must be committed, send the PROGRAM PAGE command to the target */
255 if (Write_Memory_Params
.ProgrammingMode
& PROG_MODE_COMMIT_PAGE_MASK
)
257 ISPTarget_SendByte(Write_Memory_Params
.ProgrammingCommands
[1]);
258 ISPTarget_SendByte(PageStartAddress
>> 8);
259 ISPTarget_SendByte(PageStartAddress
& 0xFF);
260 ISPTarget_SendByte(0x00);
262 /* Check if polling is enabled and possible, if not switch to timed delay mode */
263 if ((Write_Memory_Params
.ProgrammingMode
& PROG_MODE_PAGED_VALUE_MASK
) && !(PollAddress
))
265 Write_Memory_Params
.ProgrammingMode
= (Write_Memory_Params
.ProgrammingMode
& ~PROG_MODE_PAGED_VALUE_MASK
) |
266 PROG_MODE_PAGED_TIMEDELAY_MASK
;
269 ProgrammingStatus
= ISPTarget_WaitForProgComplete(Write_Memory_Params
.ProgrammingMode
, PollAddress
, PollValue
,
270 Write_Memory_Params
.DelayMS
,
271 Write_Memory_Params
.ProgrammingCommands
[2]);
273 /* Check to see if the FLASH address has crossed the extended address boundary */
274 if ((V2Command
== CMD_PROGRAM_FLASH_ISP
) && !(CurrentAddress
& 0xFFFF))
275 MustLoadExtendedAddress
= true;
278 Endpoint_Write_8(V2Command
);
279 Endpoint_Write_8(ProgrammingStatus
);
283 /** Handler for the CMD_READ_FLASH_ISP and CMD_READ_EEPROM_ISP commands, reading in bytes,
284 * words or pages of data from the attached device.
286 * \param[in] V2Command Issued V2 Protocol command byte from the host
288 void ISPProtocol_ReadMemory(uint8_t V2Command
)
292 uint16_t BytesToRead
;
293 uint8_t ReadMemoryCommand
;
294 } Read_Memory_Params
;
296 Endpoint_Read_Stream_LE(&Read_Memory_Params
, sizeof(Read_Memory_Params
), NULL
);
297 Read_Memory_Params
.BytesToRead
= SwapEndian_16(Read_Memory_Params
.BytesToRead
);
300 Endpoint_SelectEndpoint(AVRISP_DATA_IN_EPADDR
);
301 Endpoint_SetEndpointDirection(ENDPOINT_DIR_IN
);
303 Endpoint_Write_8(V2Command
);
304 Endpoint_Write_8(STATUS_CMD_OK
);
306 /* Read each byte from the device and write them to the packet for the host */
307 for (uint16_t CurrentByte
= 0; CurrentByte
< Read_Memory_Params
.BytesToRead
; CurrentByte
++)
309 /* Check to see if we need to send a LOAD EXTENDED ADDRESS command to the target */
310 if (MustLoadExtendedAddress
)
312 ISPTarget_LoadExtendedAddress();
313 MustLoadExtendedAddress
= false;
316 /* Read the next byte from the desired memory space in the device */
317 ISPTarget_SendByte(Read_Memory_Params
.ReadMemoryCommand
);
318 ISPTarget_SendByte(CurrentAddress
>> 8);
319 ISPTarget_SendByte(CurrentAddress
& 0xFF);
320 Endpoint_Write_8(ISPTarget_ReceiveByte());
322 /* Check if the endpoint bank is currently full, if so send the packet */
323 if (!(Endpoint_IsReadWriteAllowed()))
326 Endpoint_WaitUntilReady();
329 /* AVR FLASH addressing requires us to modify the read command based on if we are reading a high
330 * or low byte at the current word address */
331 if (V2Command
== CMD_READ_FLASH_ISP
)
332 Read_Memory_Params
.ReadMemoryCommand
^= READ_WRITE_HIGH_BYTE_MASK
;
334 /* EEPROM just increments the address each byte, flash needs to increment on each word and
335 * also check to ensure that a LOAD EXTENDED ADDRESS command is issued each time the extended
336 * address boundary has been crossed */
337 if ((CurrentByte
& 0x01) || (V2Command
== CMD_READ_EEPROM_ISP
))
341 if ((V2Command
!= CMD_READ_EEPROM_ISP
) && !(CurrentAddress
& 0xFFFF))
342 MustLoadExtendedAddress
= true;
346 Endpoint_Write_8(STATUS_CMD_OK
);
348 bool IsEndpointFull
= !(Endpoint_IsReadWriteAllowed());
351 /* Ensure last packet is a short packet to terminate the transfer */
354 Endpoint_WaitUntilReady();
356 Endpoint_WaitUntilReady();
360 /** Handler for the CMD_CHI_ERASE_ISP command, clearing the target's FLASH memory. */
361 void ISPProtocol_ChipErase(void)
365 uint8_t EraseDelayMS
;
367 uint8_t EraseCommandBytes
[4];
370 Endpoint_Read_Stream_LE(&Erase_Chip_Params
, sizeof(Erase_Chip_Params
), NULL
);
373 Endpoint_SelectEndpoint(AVRISP_DATA_IN_EPADDR
);
374 Endpoint_SetEndpointDirection(ENDPOINT_DIR_IN
);
376 uint8_t ResponseStatus
= STATUS_CMD_OK
;
378 /* Send the chip erase commands as given by the host to the device */
379 for (uint8_t SByte
= 0; SByte
< sizeof(Erase_Chip_Params
.EraseCommandBytes
); SByte
++)
380 ISPTarget_SendByte(Erase_Chip_Params
.EraseCommandBytes
[SByte
]);
382 /* Use appropriate command completion check as given by the host (delay or busy polling) */
383 if (!(Erase_Chip_Params
.PollMethod
))
384 ISPProtocol_DelayMS(Erase_Chip_Params
.EraseDelayMS
);
386 ResponseStatus
= ISPTarget_WaitWhileTargetBusy();
388 Endpoint_Write_8(CMD_CHIP_ERASE_ISP
);
389 Endpoint_Write_8(ResponseStatus
);
393 /** Global volatile variables used in ISRs relating to ISPProtocol_Calibrate() */
394 volatile uint16_t HalfCyclesRemaining
;
395 volatile uint8_t ResponseTogglesRemaining
;
397 /** ISR to toggle MOSI pin when TIMER1 overflows */
400 PINB
|= (1 << PB2
); // toggle PB2 (MOSI) by writing 1 to its bit in PINB
401 HalfCyclesRemaining
--;
404 /** ISR to listen for toggles on MISO pin */
407 ResponseTogglesRemaining
--;
410 /** Handler for the CMD_OSCCAL command, entering RC-calibration mode as specified in AVR053 */
411 void ISPProtocol_Calibrate(void)
413 #define CALIB_CLOCK 32768
414 // CALIB_TICKS uses 2x frequency because we toggle twice per cycle
415 // and adds 1/2 denom. to nom. to ensure rounding instead of flooring of integer division
416 #define CALIB_TICKS ( (F_CPU+CALIB_CLOCK) / (2*CALIB_CLOCK) )
417 // Per AVR053, calibration guaranteed to take 1024 cycles (2048 half-cycles) or fewer;
418 // add some cycles for response delay (5-10 after success) and response itself
419 #define HALF_CYCLE_LIMIT (2*1024 + 50)
420 #define SUCCESS_TOGGLE_NUM 8
422 uint8_t ResponseStatus
= STATUS_CMD_OK
;
424 /* Don't entirely know why this is needed, something to do with the USB communication back to PC */
426 Endpoint_SelectEndpoint(AVRISP_DATA_IN_EPADDR
);
427 Endpoint_SetEndpointDirection(ENDPOINT_DIR_IN
);
429 /* Enable pullup on MISO and release ~RESET */
430 DDRB
= ~(1 << PB3
); // explicitly set all PORTB to outputs except PB3 (MISO)
431 PORTB
|= ( (1 << PB4
) | (1 << PB3
) ); // set PB4 (TARG_RST) high (i.e. not reset) and enable pullup on PB3 (MISO)
433 /* Set up MISO pin (PCINT3) to listen for toggles */
434 PCMSK0
= (1 << PCINT3
); // set mask to enable PCINT on only Pin 3 (MISO)
436 /* Set up timer that fires at a rate of 65536 Hz - this will drive the MOSI toggle */
437 OCR1A
= CALIB_TICKS
- 1; // zero-indexed counter; for 16MHz system clock, this becomes 243
438 TCCR1A
= ( (1 << WGM11
) | (1 << WGM10
) ); // set for fast PWM, TOP = OCR1A
439 TCCR1B
= ( (1 << WGM13
) | (1 << WGM12
) | (1 << CS10
) ); // ... and no clock prescaling
440 TCNT1
= 0; // reset counter
442 /* Initialize counter variables */
443 HalfCyclesRemaining
= HALF_CYCLE_LIMIT
;
444 ResponseTogglesRemaining
= SUCCESS_TOGGLE_NUM
;
446 /* Turn on interrupts */
447 uint8_t OldSREG
= SREG
; // save current global interrupt state
448 PCICR
|= (1 << PCIE0
); // enable interrupts for PCINT7:0 (don't touch setting for PCINT12:8)
449 TIMSK1
= (1 << TOIE1
); // enable T1 OVF interrupt (and no other T1 interrupts)
450 sei(); // enable global interrupts
452 /* Let device do its calibration, wait for reponse on MISO */
453 while ( HalfCyclesRemaining
&& ResponseTogglesRemaining
)
458 /* Disable interrupts, restore SREG */
459 PCICR
&= ~(1 << PCIE0
);
463 /* Check if device responded with a success message or if we timed out */
464 if (ResponseTogglesRemaining
)
466 ResponseStatus
= STATUS_CMD_TOUT
;
469 /* Report back to PC via USB */
470 Endpoint_Write_8(CMD_OSCCAL
);
471 Endpoint_Write_8(ResponseStatus
);
474 } // void ISPProtocol_Calibrate(void)
476 /** Handler for the CMD_READ_FUSE_ISP, CMD_READ_LOCK_ISP, CMD_READ_SIGNATURE_ISP and CMD_READ_OSCCAL commands,
477 * reading the requested configuration byte from the device.
479 * \param[in] V2Command Issued V2 Protocol command byte from the host
481 void ISPProtocol_ReadFuseLockSigOSCCAL(uint8_t V2Command
)
486 uint8_t ReadCommandBytes
[4];
487 } Read_FuseLockSigOSCCAL_Params
;
489 Endpoint_Read_Stream_LE(&Read_FuseLockSigOSCCAL_Params
, sizeof(Read_FuseLockSigOSCCAL_Params
), NULL
);
492 Endpoint_SelectEndpoint(AVRISP_DATA_IN_EPADDR
);
493 Endpoint_SetEndpointDirection(ENDPOINT_DIR_IN
);
495 uint8_t ResponseBytes
[4];
497 /* Send the Fuse or Lock byte read commands as given by the host to the device, store response */
498 for (uint8_t RByte
= 0; RByte
< sizeof(ResponseBytes
); RByte
++)
499 ResponseBytes
[RByte
] = ISPTarget_TransferByte(Read_FuseLockSigOSCCAL_Params
.ReadCommandBytes
[RByte
]);
501 Endpoint_Write_8(V2Command
);
502 Endpoint_Write_8(STATUS_CMD_OK
);
503 Endpoint_Write_8(ResponseBytes
[Read_FuseLockSigOSCCAL_Params
.RetByte
- 1]);
504 Endpoint_Write_8(STATUS_CMD_OK
);
508 /** Handler for the CMD_WRITE_FUSE_ISP and CMD_WRITE_LOCK_ISP commands, writing the requested configuration
509 * byte to the device.
511 * \param[in] V2Command Issued V2 Protocol command byte from the host
513 void ISPProtocol_WriteFuseLock(uint8_t V2Command
)
517 uint8_t WriteCommandBytes
[4];
518 } Write_FuseLockSig_Params
;
520 Endpoint_Read_Stream_LE(&Write_FuseLockSig_Params
, sizeof(Write_FuseLockSig_Params
), NULL
);
523 Endpoint_SelectEndpoint(AVRISP_DATA_IN_EPADDR
);
524 Endpoint_SetEndpointDirection(ENDPOINT_DIR_IN
);
526 /* Send the Fuse or Lock byte program commands as given by the host to the device */
527 for (uint8_t SByte
= 0; SByte
< sizeof(Write_FuseLockSig_Params
.WriteCommandBytes
); SByte
++)
528 ISPTarget_SendByte(Write_FuseLockSig_Params
.WriteCommandBytes
[SByte
]);
530 Endpoint_Write_8(V2Command
);
531 Endpoint_Write_8(STATUS_CMD_OK
);
532 Endpoint_Write_8(STATUS_CMD_OK
);
536 /** Handler for the CMD_SPI_MULTI command, writing and reading arbitrary SPI data to and from the attached device. */
537 void ISPProtocol_SPIMulti(void)
547 Endpoint_Read_Stream_LE(&SPI_Multi_Params
, (sizeof(SPI_Multi_Params
) - sizeof(SPI_Multi_Params
.TxData
)), NULL
);
548 Endpoint_Read_Stream_LE(&SPI_Multi_Params
.TxData
, SPI_Multi_Params
.TxBytes
, NULL
);
551 Endpoint_SelectEndpoint(AVRISP_DATA_IN_EPADDR
);
552 Endpoint_SetEndpointDirection(ENDPOINT_DIR_IN
);
554 Endpoint_Write_8(CMD_SPI_MULTI
);
555 Endpoint_Write_8(STATUS_CMD_OK
);
557 uint8_t CurrTxPos
= 0;
558 uint8_t CurrRxPos
= 0;
560 /* Write out bytes to transmit until the start of the bytes to receive is met */
561 while (CurrTxPos
< SPI_Multi_Params
.RxStartAddr
)
563 if (CurrTxPos
< SPI_Multi_Params
.TxBytes
)
564 ISPTarget_SendByte(SPI_Multi_Params
.TxData
[CurrTxPos
]);
566 ISPTarget_SendByte(0);
571 /* Transmit remaining bytes with padding as needed, read in response bytes */
572 while (CurrRxPos
< SPI_Multi_Params
.RxBytes
)
574 if (CurrTxPos
< SPI_Multi_Params
.TxBytes
)
575 Endpoint_Write_8(ISPTarget_TransferByte(SPI_Multi_Params
.TxData
[CurrTxPos
++]));
577 Endpoint_Write_8(ISPTarget_ReceiveByte());
579 /* Check to see if we have filled the endpoint bank and need to send the packet */
580 if (!(Endpoint_IsReadWriteAllowed()))
583 Endpoint_WaitUntilReady();
589 Endpoint_Write_8(STATUS_CMD_OK
);
591 bool IsEndpointFull
= !(Endpoint_IsReadWriteAllowed());
594 /* Ensure last packet is a short packet to terminate the transfer */
597 Endpoint_WaitUntilReady();
599 Endpoint_WaitUntilReady();
603 /** Blocking delay for a given number of milliseconds. This provides a simple wrapper around
604 * the avr-libc provided delay function, so that the delay function can be called with a
605 * constant value (to prevent run-time floating point operations being required).
607 * \param[in] DelayMS Number of milliseconds to delay for
609 void ISPProtocol_DelayMS(uint8_t DelayMS
)
611 while (DelayMS
-- && TimeoutTicksRemaining
)