//JFLASH V0.2
//built from the sa1110jtag.h from Nicolas Pitre and the SA1100 BSDL file from Intel by steve@steves-house.org.uk 
#define SA1100_CHAIN_LENGTH 279	//was 292

#define	ROM_SEL_IN	0			//same
#define	nRESET_OUT_OUT	1		//same
#define	nRESET_IN	2			//same
#define	TXD_3_IN	3			//same			
#define	TXD_3_OUT	4			//same
#define	TXD_3_EN	5			//same
#define	RXD_3_IN	6			//same
#define	RXD_3_OUT	7			//same
#define	RXD_3_EN	8			//same
#define	TXD_2_IN	9			//same
#define	TXD_2_OUT	10			//same
#define	TXD_2_EN	11			//same
#define	RXD_2_IN	12			//same
#define	RXD_2_OUT	13			//same
#define	RXD_2_EN	14			//same
#define	TXD_1_IN	15			//same
#define	TXD_1_OUT	16			//same
#define	TXD_1_EN	17			//same
#define	RXD_1_IN	18			//same
#define	RXD_1_OUT	19			//same
#define	RXD_1_EN	20			//same
#define	UDCp_IN		21			//same
#define	UDCp_OUT	22			//same
#define	UDCp_EN		23			//same
#define	UDCmUDCp_IN	24			//same
#define	UDCm_IN		25			//same
#define	UDCm_OUT	26			//same
#define	UDCm_EN		27			//same

#define	A0_OUT		28			//same
#define	A1_OUT		29			//same
#define	A2_OUT		30			//same
#define	A3_OUT		31			//same
#define	A4_OUT		32			//same
#define	A5_OUT		33			//same
#define	A6_OUT		34			//same
#define	A7_OUT		35			//same
#define	A8_OUT		36			//same
#define	A9_OUT		37			//same
#define	A10_OUT		38			//same
#define	A11_OUT		39			//same
#define	A12_OUT		40			//same
#define	A13_OUT		41			//same
#define	A14_OUT		42			//same
#define	A15_OUT		43			//same
#define	A16_OUT		44			//same
#define	A17_OUT		45			//same
#define	A18_OUT		46			//same
#define	A19_OUT		47			//same
#define	A20_OUT		48			//same
#define	A21_OUT		49			//same
#define	A22_OUT		50			//same
#define	A23_OUT		51			//same
#define	A24_OUT		52			//same
#define	A25_OUT		53			//same

#define	nCS0_OUT	54			//same
#define	nCS1_OUT	55			//same
#define	nCS2_OUT	56			//same
#define	nCS3_OUT	57			//same

//#define	nCS4_OUT	58		gone
//#define	nCS5_OUT	59		gone
//#define	RDY_IN		60		gone
//#define	RD_nWR_OUT	61		gone

#define	nCAS0_OUT	58			//62
#define	nCAS1_OUT	59			//63
#define	nCAS2_OUT	60			//64
#define	nCAS3_OUT	61			//65

#define	nRAS0_OUT	62			//66
#define	nRAS1_OUT	63			//67
#define	nRAS2_OUT	64			//68
#define	nRAS3_OUT	65			//69

//#define	nSDCAS_OUT	70		gone
//#define	nSDRAS_OUT	71		gone

#define	nOE_OUT		66			//72
#define	nWE_OUT		67			//73
#define	multiEN_EN	68			//74 -control for A*, all strobes...

#define	nPCE1_OUT	69			//75
#define	nPCE2_OUT	70			//76
#define	nPREG_OUT	71			//77
#define	nPWAIT_IN	72			//78
#define	nIOIS16_IN	73			//79
#define	PSKTSEL_OUT	74			//80
#define	nPIOW_OUT	75			//81
#define	nPIOR_OUT	76			//82
#define	nPWE_OUT	77			//83
#define	nPOE_OUT	78			//84

#define	L_FCLK_IN	79			//85
#define	L_FCLK_OUT	80			//86
#define	L_FCLK_EN	81			//87
#define	L_LCLK_IN	82			//88
#define	L_LCLK_OUT	83			//89
#define	L_LCLK_EN	84			//90

#define	L_DD7_IN	85			//91
#define	L_DD7_OUT	86			//92
#define	L_DD7_EN	87			//93
#define	L_DD6_IN	88			//94
#define	L_DD6_OUT	89			//95
#define	L_DD6_EN	90			//96
#define	L_DD5_IN	91			//97
#define	L_DD5_OUT	92			//98
#define	L_DD5_EN	93			//99
#define	L_DD4_IN	94			//100
#define	L_DD4_OUT	95			//101
#define	L_DD4_EN	96			//102
#define	L_DD3_IN	97			//103
#define	L_DD3_OUT	98			//104
#define	L_DD3_EN	99			//105
#define	L_DD2_IN	100			//106
#define	L_DD2_OUT	101			//107
#define	L_DD2_EN	102			//108
#define	L_DD1_IN	103			//109
#define	L_DD1_OUT	104			//110
#define	L_DD1_EN	105			//111
#define	L_DD0_IN	106			//112
#define	L_DD0_OUT	107			//113
#define	L_DD0_EN	108			//114

#define	L_PCLK_IN	109			//115
#define	L_PCLK_OUT	110			//116
#define	L_PCLK_EN	111			//117
#define	L_BIAS_IN	112			//118
#define	L_BIAS_OUT	113			//119
#define	L_BIAS_EN	114			//120

#define	GP0_IN		115			//121
#define	GP0_OUT		116			//122
#define	GP0_EN		117			//123
#define	GP1_IN		118			//124
#define	GP1_OUT		119			//125
#define	GP1_EN		120			//126
#define	GP2_IN		121			//127
#define	GP2_OUT		122			//128
#define	GP2_EN		123			//129
#define	GP3_IN		124			//130
#define	GP3_OUT		125			//131
#define	GP3_EN		126			//132
#define	GP4_IN		127			//133
#define	GP4_OUT		128			//134
#define	GP4_EN		129			//135
#define	GP5_IN		130			//136
#define	GP5_OUT		131			//137
#define	GP5_EN		132			//138
#define	GP6_IN		133			//139
#define	GP6_OUT		134			//140
#define	GP6_EN		135			//141
#define	GP7_IN		136			//142
#define	GP7_OUT		137			//143
#define	GP7_EN		138			//144
#define	GP8_IN		139			//145
#define	GP8_OUT		140			//146
#define	GP8_EN		141			//147
#define	GP9_IN		142			//148
#define	GP9_OUT		143			//149
#define	GP9_EN		144			//150
#define	GP10_IN		145			//151
#define	GP10_OUT	146			//152
#define	GP10_EN		147			//153
#define	GP11_IN		148			//154
#define	GP11_OUT	149			//155
#define	GP11_EN		150			//156
#define	GP12_IN		151			//157
#define	GP12_OUT	152			//158
#define	GP12_EN		153			//159
#define	GP13_IN		154			//160
#define	GP13_OUT	155			//161
#define	GP13_EN		156			//162
#define	GP14_IN		157			//163
#define	GP14_OUT	158			//164
#define	GP14_EN		159			//165
#define	GP15_IN		160			//166
#define	GP15_OUT	161			//167
#define	GP15_EN		162			//168
#define	GP16_IN		163			//169
#define	GP16_OUT	164			//170
#define	GP16_EN		165			//171
#define	GP17_IN		166			//172
#define	GP17_OUT	167			//173
#define	GP17_EN		168			//174
#define	GP18_IN		169			//175
#define	GP18_OUT	170			//176
#define	GP18_EN		171			//177
#define	GP19_IN		172			//178
#define	GP19_OUT	173			//179
#define	GP19_EN		174			//180
#define	GP20_IN		175			//181
#define	GP20_OUT	176			//182
#define	GP20_EN		177			//183
#define	GP21_IN		178			//184
#define	GP21_OUT	179			//185
#define	GP21_EN		180			//186
#define	GP22_IN		181			//187
#define	GP22_OUT	182			//188
#define	GP22_EN		183			//189
#define	GP23_IN		184			//190
#define	GP23_OUT	185			//191
#define	GP23_EN		186			//192
#define	GP24_IN		187			//193
#define	GP24_OUT	188			//194
#define	GP24_EN		189			//195
#define	GP25_IN		190			//196
#define	GP25_OUT	191			//197
#define	GP25_EN		192			//198
#define	GP26_IN		193			//199
#define	GP26_OUT	194			//200
#define	GP26_EN		195			//201
#define	GP27_IN		196			//202
#define	GP27_OUT	197			//203
#define	GP27_EN		198			//204

//#define	SMROM_EN_IN	205		gone
//#define	SDCKE0_OUT	206		gone
//#define	SDCLK0_OUT	207		gone
//#define	SDCLK1_OUT	208		gone
//#define	SDCLK1_EN	209		gone
//#define	SDCKE1_OUT	210		gone
//#define	SDCLK2_OUT	211		gone

#define	D31_0_EN	199			//212
#define	D31_IN		200			//213
#define	D31_OUT		201			//214
#define	D23_IN		202			//215
#define	D23_OUT		203			//216
#define	D15_IN		204			//217
#define	D15_OUT		205			//218
#define	D7_IN		206			//219
#define	D7_OUT		207			//220
#define	D30_IN		208			//221
#define	D30_OUT		209			//222
#define	D22_IN		210			//223
#define	D22_OUT		211			//224
#define	D14_IN		212			//225
#define	D14_OUT		213			//226
#define	D6_IN		214			//227
#define	D6_OUT		215			//228
#define	D29_IN		216			//229
#define	D29_OUT		217			//230
#define	D21_IN		218			//231
#define	D21_OUT		219			//232
#define	D13_IN		220			//233
#define	D13_OUT		221			//234
#define	D5_IN		222			//235
#define	D5_OUT		223			//236
#define	D28_IN		224			//237
#define	D28_OUT		225			//238
#define	D20_IN		226			//239
#define	D20_OUT		227			//240
#define	D12_IN		228			//241
#define	D12_OUT		229			//242
#define	D4_IN		230			//243
#define	D4_OUT		231			//244
#define	D27_IN		232			//245
#define	D27_OUT		233			//246
#define	D19_IN		234			//247
#define	D19_OUT		235			//248
#define	D11_IN		236			//249
#define	D11_OUT		237			//250
#define	D3_IN		238			//251
#define	D3_OUT		239			//252
#define	D26_IN		240			//253
#define	D26_OUT		241			//254
#define	D18_IN		242			//255
#define	D18_OUT		243			//256
#define	D10_IN		244			//257
#define	D10_OUT		245			//258
#define	D2_IN		246			//259
#define	D2_OUT		247			//260
#define	D25_IN		248			//261
#define	D25_OUT		249			//262
#define	D17_IN		250			//263
#define	D17_OUT		251			//264
#define	D9_IN		252			//265
#define	D9_OUT		253			//266
#define	D1_IN		254			//267
#define	D1_OUT		255			//268
#define	D24_IN		256			//269
#define	D24_OUT		257			//270
#define	D16_IN		258			//271
#define	D16_OUT		259			//272
#define	D8_IN		260			//273
#define	D8_OUT		261			//274
#define	D0_IN		262			//275
#define	D0_OUT		263			//276

#define	TXD_C_IN	264			//277
#define	TXD_C_OUT	265			//278
#define	TXD_C_EN	266			//279

#define	RXD_C_IN	267			//280
#define	RXD_C_OUT	268			//281
#define	RXD_C_EN	269			//282

#define	SCLK_C_IN	270			//283
#define	SCLK_C_OUT	271			//284
#define	SCLK_C_EN	272			//285

#define	SFRM_C_IN	273			//286
#define	SFRM_C_OUT	274			//287
#define	SFRM_C_EN	275			//288

#define	WEIRD_INTERNAL 276
//#define PWR_EN_OUT	289		gone

#define	VDD_FAULT_IN	277		//290
#define	BATT_FAULT_IN	278		//291

int pin[] = {
1,	//	ROM_SEL_IN
1,	//	nRESET_OUT_OUT
1,	//	nRESET_IN
1,	//	TXD_3_IN
0,	//	TXD_3_OUT
0,	//	TXD_3_EN
1,	//	RXD_3_IN
0,	//	RXD_3_OUT
0,	//	RXD_3_EN
1,	//	TXD_2_IN
0,	//	TXD_2_OUT
0,	//	TXD_2_EN
0,	//	RXD_2_IN
0,	//	RXD_2_OUT
0,	//	RXD_2_EN
1,	//	TXD_1_IN
0,	//	TXD_1_OUT
0,	//	TXD_1_EN
1,	//	RXD_1_IN
0,	//	RX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	//	GP17_IN
0,	//	GP17_OUT
1,	//	GP17_EN
1,	//	GP18_IN
0,	//	GP18_OUT
0,	//	GP18_EN
0,	//	GP19_IN
0,	//	GP19_OUT
0,	//	GP19_EN
1,	//	GP20_IN
0,	//	GP20_OUT
0,	//	GP20_EN
0,	//	GP21_IN
0,	//	GP21_OUT
0,	//	GP21_EN
1,	//	GP22_IN
0,	//	GP22_OUT
0,	//	GP22_EN
0,	//	GP23_IN
0,	//	GP23_OUT
0,	//	GP23_EN
1,	//	GP24_IN
0,	//	GP24_OUT
0,	//	GP24_EN
1,	//	GP25_IN
0,	//	GP25_OUT
0,	//	GP25_EN
1,	//	GP26_IN
0,	//	GP26_OUT
0,	//	GP26_EN
1,	//	GP27_IN
0,	//	GP27_OUT
0,	//	GP27_EN
//0,	//	SMROM_EN_IN
//0,	//	SDCKE0_OUT
//0,	//	SDCLK0_OUT
//0,	//	SDCLK1_OUT
//1,	//	SDCLK1_EN
//1,	//	SDCKE1_OUT
//0,	//	SDCLK2_OUT
1,	//	D31_0_EN
0,	//	D31_IN
0,	//	D31_OUT
0,	//	D23_IN
0,	//	D23_OUT
0,	//	D15_IN
0,	//	D15_OUT
0,	//	D7_IN
0,	//	D7_OUT
0,	//	D30_IN
0,	//	D30_OUT
0,	//	D22_IN
0,	//	D22_OUT
0,	//	D14_IN
0,	//	D14_OUT
0,	//	D6_IN
0,	//	D6_OUT
0,	//	D29_IN
0,	//	D29_OUT
0,	//	D21_IN
0,	//	D21_OUT
0,	//	D13_IN
0,	//	D13_OUT
0,	//	D5_IN
0,	//	D5_OUT
0,	//	D28_IN
0,	//	D28_OUT
0,	//	D20_IN
0,	//	D20_OUT
0,	//	D12_IN
0,	//	D12_OUT
0,	//	D4_IN
0,	//	D4_OUT
0,	//	D27_OUT
0,	//	D27_IN
0,	//	D19_IN
0,	//	D19_OUT
0,	//	D11_IN
0,	//	D11_OUT
0,	//	D3_IN
0,	//	D3_OUT
0,	//	D26_IN
0,	//	D26_OUT
0,	//	D18_IN
0,	//	D18_OUT
0,	//	D10_IN
0,	//	D10_OUT
0,	//	D2_IN
0,	//	D2_OUT
0,	//	D25_IN
0,	//	D25_OUT
0,	//	D17_IN
0,	//	D17_OUT
0,	//	D9_IN
0,	//	D9_OUT
0,	//	D1_IN
0,	//	D1_OUT
0,	//	D24_IN
0,	//	D24_OUT
0,	//	D16_IN
1,	//	D16_OUT
0,	//	D8_IN
0,	//	D8_OUT
0,	//	D0_IN
1,	//	D0_OUT
1,	//	TXD_C_IN
0,	//	TXD_C_OUT
0,	//	TXD_C_EN
1,	//	RXD_C_IN
0,	//	RXD_C_OUT
0,	//	RXD_C_EN
1,	//	SCLK_C_IN
0,	//	SCLK_C_OUT
0,	//	SCLK_C_EN
1,	//	SFRM_C_IN
0,	//	SFRM_C_OUT
0,	//	SFRM_C_EN
//1,	//	PWR_EN_OUT
0,	//	VDD_FAULT_IN
0};		//	BATT_FAULT_IN

//LART format. Aargh. Plaited Flash data lines. Address lines are at least separated 
//by a boundary at A11/A12, which is where the pages chage size so no need to plait them - 
int command_dat_order[] = {	 D12_OUT, D14_OUT, D11_OUT, D9_OUT,  D0_OUT,  D2_OUT,  D7_OUT,  D5_OUT,
					 D13_OUT, D15_OUT, D10_OUT, D8_OUT,  D1_OUT,  D3_OUT,  D6_OUT,  D4_OUT,
					 D20_OUT, D22_OUT, D19_OUT, D17_OUT, D24_OUT, D26_OUT, D31_OUT, D29_OUT,
					 D21_OUT, D23_OUT, D18_OUT, D16_OUT, D25_OUT, D27_OUT, D30_OUT, D28_OUT	};
int data_dat_order[] = {	 D0_OUT, D1_OUT, D2_OUT, D3_OUT,  D4_OUT,  D5_OUT,  D6_OUT,  D7_OUT,
					 D8_OUT, D9_OUT, D10_OUT, D11_OUT,  D12_OUT,  D13_OUT,  D14_OUT,  D15_OUT,
					 D16_OUT, D17_OUT, D18_OUT, D19_OUT, D20_OUT, D21_OUT, D22_OUT, D23_OUT,
					 D24_OUT, D25_OUT, D26_OUT, D27_OUT, D28_OUT, D29_OUT, D30_OUT, D31_OUT	};
/*
#define	D31_OUT	214
#define	D23_OUT	216
#define	D15_OUT	218
#define	D7_OUT	220
#define	D30_OUT	222
#define	D22_OUT	224
#define	D14_OUT	226
#define	D6_OUT	228
#define	D29_OUT	230
#define	D21_OUT	232
#define	D13_OUT	234
#define	D5_OUT	236
#define	D28_OUT	238
#define	D20_OUT	240
#define	D12_OUT	242
#define	D4_OUT	244
#define	D27_OUT	246
#define	D19_OUT	248
#define	D11_OUT	250
#define	D3_OUT	252
#define	D26_OUT	254
#define	D18_OUT	256
#define	D10_OUT	258
#define	D2_OUT	260
#define	D25_OUT	262
#define	D17_OUT	264
#define	D9_OUT	266
#define	D1_OUT	268
#define	D24_OUT	270
#define	D16_OUT	272
#define	D8_OUT	274
#define	D0_OUT	276
*/