summaryrefslogtreecommitdiffstats
path: root/flash/bootloader/bootloader.h
blob: fc6bcb1eed0b09d667f26bf2f39c1ff3695d3364 (plain)
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#ifndef NULL
#define NULL ((void*)0)
#endif

#define TRUE 1
#define FALSE 0

// scalar types
typedef unsigned char  UINT8;
typedef unsigned short UINT16;
typedef unsigned long  UINT32;
typedef int BOOL;

typedef void(*tpFunc)(void); // type for execute
typedef int(*tpMain)(void); // type for start vector to main()


// structure of an image in the flash
typedef struct 
{
	UINT32* pDestination; // address to copy it to
	UINT32 size;          // how many bytes of payload (to the next header)
	tpFunc pExecute;      // entry point
	UINT32 flags;         // uncompressed or compressed
	// end of header, now comes the payload
	UINT32 image[];       // the binary image starts here
	// after the payload, the next header may follow, all 0xFF if none
} tImage;

// flags valid for image header
#define IF_NONE   0x00000000
#define IF_UCL_2E 0x00000001 // image is compressed with UCL, algorithm 2e


// resolve platform dependency of F1 button check
#if defined PLATFORM_PLAYER
#define F1_MASK 0x0001 // Player has no F1 button, so we use "-"
#define F2_MASK 0x0008 // Player has no F2 button, so we use "Play"
#define F3_MASK 0x0004 // Player has no F3 button, so we use "+"

#elif defined PLATFORM_RECORDER
#define USE_ADC
#define CHANNEL 4
#define F1_LOWER 250
#define F1_UPPER 499
#define F2_LOWER 500
#define F2_UPPER 699
#define F3_LOWER 900
#define F3_UPPER 1023

#elif defined PLATFORM_FM
#define USE_ADC
#define CHANNEL 4
#define F1_LOWER 150
#define F1_UPPER 384
#define F2_LOWER 385
#define F2_UPPER 544
#define F3_LOWER 700
#define F3_UPPER 1023

#elif defined PLATFORM_ONDIO
#define USE_ADC
#define CHANNEL 4
#define F1_LOWER 0x2EF // Ondio has no F1 button,
#define F1_UPPER 0x3FF //  so we use "Left".
#define F2_LOWER 0x19D // Ondio has no F2 button,
#define F2_UPPER 0x245 //  so we use "Up".
#define F3_LOWER 0x246 // Ondio has no F3 button,
#define F3_UPPER 0x2EE //  so we use "Right".

#else
#error ("No platform given!")
#endif


#define FLASH_BASE 0x02000000 // start of the flash memory
#define FW_VERSION *(unsigned short*)(FLASH_BASE + 0xFE) // firmware version


// prototypes
void _main(void) __attribute__ ((section (".startup")));
int main(void);
void PlatformInit(void);
void DramInit(void);
int ucl_nrv2e_decompress_8(const UINT8 *src, UINT8 *dst, UINT32* dst_len);
void DecompressStart(tImage* pImage);
#ifdef USE_ADC
int ReadADC(int channel);
#endif
int ButtonPressed(void);
tImage* GetStartImage(int nPreferred);
// test functions
void SetLed(BOOL bOn);
void UartInit(void);
UINT8 UartRead(void);
void UartWrite(UINT8 byte);
void MiniMon(void);


// minimon commands
#define BAUDRATE       0x00 // followed by BRR value; response: command byte
#define ADDRESS        0x01 // followed by 4 bytes address; response: command byte
#define BYTE_READ      0x02 // response: 1 byte content
#define BYTE_WRITE     0x03 // followed by 1 byte content; response: command byte
#define BYTE_READ16    0x04 // response: 16 bytes content
#define BYTE_WRITE16   0x05 // followed by 16 bytes; response: command byte
#define BYTE_FLASH     0x06 // followed by 1 byte content; response: command byte
#define BYTE_FLASH16   0x07 // followed by 16 bytes; response: command byte
#define HALFWORD_READ  0x08 // response: 2 byte content
#define HALFWORD_WRITE 0x09 // followed by 2 byte content; response: command byte
#define EXECUTE        0x0A // response: command byte if call returns
#define VERSION        0x0B // response: version


// linker symbols
extern UINT32 begin_text[];
extern UINT32 end_text[];
extern UINT32 begin_data[];
extern UINT32 end_data[];
extern UINT32 begin_bss[];
extern UINT32 end_bss[];
extern UINT32 begin_stack[];
extern UINT32 end_stack[];
extern UINT32 begin_iramcopy[];
extern UINT32 total_size[];