p1load/ploader.h

89 lines
2.8 KiB
C
Raw Normal View History

2015-01-24 23:34:20 -05:00
#ifndef __PLOADER_H__
#define __PLOADER_H__
#ifdef __cplusplus
extern "C"
{
#endif
2015-01-24 23:39:22 -05:00
#include <stdint.h>
#define LOAD_PHASE_HANDSHAKE 0
#define LOAD_PHASE_RESPONSE 1
#define LOAD_PHASE_VERSION 2
#define LOAD_PHASE_HANDSHAKE_DONE 3
#define LOAD_PHASE_PROGRAM 4
#define LOAD_PHASE_EEPROM_WRITE 5
#define LOAD_PHASE_EEPROM_VERIFY 6
#define LOAD_PHASE_DONE 7
2015-01-24 23:34:20 -05:00
#define LOAD_STS_OK 0
#define LOAD_STS_ERROR -1
#define LOAD_STS_TIMEOUT -2
#define LOAD_TYPE_SHUTDOWN 0
#define LOAD_TYPE_RUN 1
#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 */
2015-01-24 23:34:20 -05:00
typedef struct {
/* serial driver interface */
2015-01-24 23:34:20 -05:00
void (*reset)(void *data);
int (*tx)(void *data, uint8_t* buf, int n);
int (*rx_timeout)(void *data, uint8_t* buf, int n, int timeout);
2015-02-10 16:55:23 -05:00
void (*msleep)(void *data, int msecs);
2015-01-24 23:34:20 -05:00
void *serialData;
/* propeller version */
int version;
/* load progress interface */
void (*progress)(void *data, int phase);
void *progressData;
/* internal variables */
uint8_t txbuf[TxBufSize];
2015-01-24 23:34:20 -05:00
int txcnt;
uint8_t rxbuf[RxBufSize];
2015-01-24 23:34:20 -05:00
int rxnext;
int rxcnt;
uint8_t lfsr;
} PL_state;
/* PL_Init - Initializes the loader state structure. */
void PL_Init(PL_state *state);
2015-01-24 23:34:20 -05:00
/* PL_HardwareFound - Sends the handshake sequence and returns non-zero if a Propeller
chip is found on the serial interface and also sets the version parameter to the
chip version.
*/
int PL_HardwareFound(PL_state *state, int *pVersion);
/* PL_LoadSpinBinary - Loads a Spin binary image. Must be called immediatel following a
successful call to PL_HardwareFound.
*/
int PL_LoadSpinBinary(PL_state *state, int loadType, uint8_t *image, int size);
/* PL_Shutdown - Shutdown the loader.*/
void PL_Shutdown(PL_state *state);
2015-01-24 23:34:20 -05:00
#ifdef __cplusplus
}
#endif
#endif