Increase the TX buffer to be big enough to fit an entire hub image.

This commit is contained in:
David Betz 2015-02-09 20:34:05 -05:00
parent 7596a4165b
commit 093f46ea3a
4 changed files with 34 additions and 25 deletions

View File

@ -5,6 +5,7 @@
*
* Copyright (c) 2009 by John Steven Denson
* Modified in 2011 by David Michael Betz
* GPIO reset code by Michael Rychlik
*
* MIT License
*

View File

@ -59,7 +59,7 @@ static int cb_rx_timeout(void *data, uint8_t* buf, int n, int timeout)
return rx_timeout(buf, n, timeout);
}
static void cb_progress(void *data, int phase, int current)
static void cb_progress(void *data, int phase)
{
switch (phase) {
case LOAD_PHASE_HANDSHAKE:
@ -71,11 +71,11 @@ static void cb_progress(void *data, int phase, int current)
case LOAD_PHASE_HANDSHAKE_DONE:
break;
case LOAD_PHASE_PROGRAM:
printf("\rLoading hub memory ... %d", current);
printf("Loading hub memory ... ");
fflush(stdout);
break;
case LOAD_PHASE_EEPROM_WRITE:
printf(" -- OK\nWriting EEPROM ... ");
printf("OK\nWriting EEPROM ... ");
fflush(stdout);
break;
case LOAD_PHASE_EEPROM_VERIFY:
@ -252,16 +252,16 @@ int main(int argc, char *argv[])
printf("Loading '%s' (%ld bytes)\n", file, imageSize);
switch (PL_LoadSpinBinary(&state, loadType, image, imageSize)) {
case LOAD_STS_OK:
printf(" -- OK\n");
printf("OK\n");
break;
case LOAD_STS_ERROR:
printf(" -- Error\n");
printf("Error\n");
break;
case LOAD_STS_TIMEOUT:
printf(" -- Timeout\n");
printf("Timeout\n");
break;
default:
printf(" -- Internal error\n");
printf("Internal error\n");
break;
}
}

View File

@ -41,26 +41,22 @@ int PL_LoadSpinBinary(PL_state *state, int loadType, uint8_t *image, int size)
{
int i, sts;
/* report the start of program loading */
if (state->progress)
(*state->progress)(state->progressData, LOAD_PHASE_PROGRAM);
TLong(state, loadType);
TLong(state, size / sizeof(uint32_t));
/* download the spin binary */
for (i = 0; i < size; i += 4) {
/* report load progress */
if (state->progress && (i % 1024) == 0)
(*state->progress)(state->progressData, LOAD_PHASE_PROGRAM, i);
/* transmit the next long */
uint32_t data = image[i] | (image[i + 1] << 8) | (image[i + 2] << 16) | (image[i + 3] << 24);
TLong(state, data);
}
TComm(state);
/* report load of program code finished */
if (state->progress)
(*state->progress)(state->progressData, LOAD_PHASE_PROGRAM, size);
/* wait for an ACK indicating a successful load */
if ((sts = WaitForAck(state, CHECKSUM_RETRIES)) < 0)
return LOAD_STS_TIMEOUT;
@ -72,7 +68,7 @@ int PL_LoadSpinBinary(PL_state *state, int loadType, uint8_t *image, int size)
/* report the start of the eeprom writing phase */
if (state->progress)
(*state->progress)(state->progressData, LOAD_PHASE_EEPROM_WRITE, 0);
(*state->progress)(state->progressData, LOAD_PHASE_EEPROM_WRITE);
/* wait for an ACK indicating a successful EEPROM programming */
if ((sts = WaitForAck(state, EEPROM_PROGRAMMING_RETRIES)) < 0)
@ -82,7 +78,7 @@ int PL_LoadSpinBinary(PL_state *state, int loadType, uint8_t *image, int size)
/* report the start of the eeprom verification phase */
if (state->progress)
(*state->progress)(state->progressData, LOAD_PHASE_EEPROM_VERIFY, 0);
(*state->progress)(state->progressData, LOAD_PHASE_EEPROM_VERIFY);
/* wait for an ACK indicating a successful EEPROM verification */
if ((sts = WaitForAck(state, EEPROM_VERIFICATION_RETRIES)) < 0)
@ -93,7 +89,7 @@ int PL_LoadSpinBinary(PL_state *state, int loadType, uint8_t *image, int size)
/* report load completion */
if (state->progress)
(*state->progress)(state->progressData, LOAD_PHASE_DONE, 0);
(*state->progress)(state->progressData, LOAD_PHASE_DONE);
/* load completed successfully */
return LOAD_STS_OK;
@ -122,7 +118,7 @@ int PL_HardwareFound(PL_state *state, int *pVersion)
/* report the start of the handshake phase */
if (state->progress)
(*state->progress)(state->progressData, LOAD_PHASE_HANDSHAKE, 0);
(*state->progress)(state->progressData, LOAD_PHASE_HANDSHAKE);
/* reset the propeller (includes post-reset delay of 100ms) */
(*state->reset)(state->serialData);
@ -144,7 +140,7 @@ int PL_HardwareFound(PL_state *state, int *pVersion)
/* report the start of the handshake response phase */
if (state->progress)
(*state->progress)(state->progressData, LOAD_PHASE_RESPONSE, 0);
(*state->progress)(state->progressData, LOAD_PHASE_RESPONSE);
/* receive the connection response */
for (i = 0; i < 250; ++i) {
@ -157,7 +153,7 @@ int PL_HardwareFound(PL_state *state, int *pVersion)
/* report the start of the version phase */
if (state->progress)
(*state->progress)(state->progressData, LOAD_PHASE_VERSION, 0);
(*state->progress)(state->progressData, LOAD_PHASE_VERSION);
/* receive the chip version */
for (version = i = 0; i < 8; ++i) {
@ -170,7 +166,7 @@ int PL_HardwareFound(PL_state *state, int *pVersion)
/* report handshake completion */
if (state->progress)
(*state->progress)(state->progressData, LOAD_PHASE_HANDSHAKE_DONE, 0);
(*state->progress)(state->progressData, LOAD_PHASE_HANDSHAKE_DONE);
/* return successfully */
return LOAD_STS_OK;

View File

@ -26,6 +26,18 @@ extern "C"
#define LOAD_TYPE_EEPROM 2
#define LOAD_TYPE_EEPROM_RUN 3
/* constants taken from the Propeller Tool loader */
#define BaudRate 115200 // Likely Baud rate of Propeller communication
#define ResetPulsePeriod 25 // Reset pulse size (in ms)
#define MinResetDelay 60 // Minimum post-reset delay
#define MaxResetDelay 500 // Maximum post-reset delay
/* Transmit buffer size is 32K / 4 = 8K longs * 11 bytes per long plus two longs for the command and size */
#define TxBufSize ((((1024 * 32) / 4) + 2) * 11)
/* Receive buffer is large enough to receive max possible bytes during reset + 250 bytes for handshake response */
#define RxBufSize (((BaudRate / 10 * (ResetPulsePeriod + MaxResetDelay) / 1000) & 0xFFFFFFFE) + 258)
/* loader state structure - filled in by the loader functions */
typedef struct {
@ -36,13 +48,13 @@ typedef struct {
void *serialData;
/* load progress interface */
void (*progress)(void *data, int phase, int current);
void (*progress)(void *data, int phase);
void *progressData;
/* internal variables */
uint8_t txbuf[1024];
uint8_t txbuf[TxBufSize];
int txcnt;
uint8_t rxbuf[1024];
uint8_t rxbuf[RxBufSize];
int rxnext;
int rxcnt;
uint8_t lfsr;