-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathploader.h
More file actions
88 lines (69 loc) · 2.79 KB
/
Copy pathploader.h
File metadata and controls
88 lines (69 loc) · 2.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#ifndef __PLOADER_H__
#define __PLOADER_H__
#ifdef __cplusplus
extern "C"
{
#endif
#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
#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 */
typedef struct {
/* serial driver interface */
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);
void (*msleep)(void *data, int msecs);
void *serialData;
/* propeller version */
int version;
/* load progress interface */
void (*progress)(void *data, int phase);
void *progressData;
/* internal variables */
uint8_t txbuf[TxBufSize];
int txcnt;
uint8_t rxbuf[RxBufSize];
int rxnext;
int rxcnt;
uint8_t lfsr;
} PL_state;
/* PL_Init - Initializes the loader state structure. */
void PL_Init(PL_state *state);
/* 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);
#ifdef __cplusplus
}
#endif
#endif