BeagleSWIs 24.5 KB
Newer Older
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
;
; Copyright (c) 2011, Tank Stage Lighting
; All rights reserved.
;
; Redistribution and use in source and binary forms, with or without
; modification, are permitted provided that the following conditions are met:
;     * Redistributions of source code must retain the above copyright
;       notice, this list of conditions and the following disclaimer.
;     * Redistributions in binary form must reproduce the above copyright
;       notice, this list of conditions and the following disclaimer in the
;       documentation and/or other materials provided with the distribution.
;     * Neither the name of the copyright holder nor the names of their
;       contributors may be used to endorse or promote products derived from
;       this software without specific prior written permission.
;
; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
; ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
; WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
; DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY
; DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
; (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
; ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
; (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
; SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
;

;s.BeagleSWIs


;***************** S W I 's ***********
;ReadData
;r0=GPIO number
Read_Data
	CMP	r0,#i2c_flag-1			;check if i2c gpio
	BCS	i2c_Read_Data			;
Robert Sprowson's avatar
Robert Sprowson committed
37
	Push	"r1-r10,lr"			;
38 39 40
	BL	get_logical_and_pin		;
	CMP	r0,#-1				;
	BEQ	%FT10				;
41 42 43 44 45 46
	ADRL	r4,proc_reg_list		;
	ADD	r2,r2,r4			;
	LDRH	r6,[r2,#proc_oe]		;
	LDRH	r5,[r2,#proc_datain]		;
	LDRH	r4,[r2,#proc_dataout]		;
	LDR	r2,[r0,r6]			;get oe register value
47 48
	AND	r2,r2,r1			;
	CMP	r2,#0				;is it output ?
49 50
	LDREQ	r0,[r0,r4]			;read data copy
	LDRNE	r0,[r0,r5]			;read data input
51 52 53
	AND	r0,r0,r1			;mask just ours
	CMP	r0,#0				;
	MOVNE	r0,#1				;
Robert Sprowson's avatar
Robert Sprowson committed
54
10	Pull	"r1-r10,pc"			; restore registers and exit
55 56 57 58 59 60 61 62 63 64
;r0=value (0 or 1) -1 if not GPIO

;---------------------------------------------

;WriteData
;r0=GPIO number
;r1=value
Write_Data
	CMP	r0,#i2c_flag-1			;check if i2c gpio
	BCS	i2c_Write_Data			;
Robert Sprowson's avatar
Robert Sprowson committed
65
	Push	"r2-r10,lr"			;
66
	MOV	r7,r1				;save value
67 68 69 70 71 72
	BL	check_protect_i2c		;
	CMP	r0,#-1				;
	BEQ	%FT10				;
	BL	get_logical_and_pin		;
	CMP	r0,#-1				;
	BEQ	%FT10				;
73 74 75 76 77 78
	ADRL	r4,proc_reg_list		;
	ADD	r2,r2,r4			;
	LDRH	r6,[r2,#proc_oe]		;
	LDRH	r5,[r2,#proc_cleardataout]	;
	LDRH	r4,[r2,#proc_setdataout]	;
	LDR	r2,[r0,r6]			;get oe register value
79 80 81
	TST	r2,r1				;is pin output
	MOVNE	r0,#-1				;its an input
	BNE	%FT10				;
82 83 84
	CMP	r7,#0				;check flag
	STRNE	r1,[r0,r4]			;set data bit
	STREQ	r1,[r0,r5]			;unset data bit
Robert Sprowson's avatar
Robert Sprowson committed
85
10	Pull	"r2-r10,pc"			; restore registers and exit
86 87 88 89 90 91 92 93 94 95 96
;r0= -1 if input , protected or not GPIO
;or
;r0=logical address
;r1=pin

;---------------------------------------------
;ReadOE
;r0=GPIO number
Read_OE
	CMP	r0,#i2c_flag-1			;check if i2c gpio
	BCS	i2c_Read_OE			;
Robert Sprowson's avatar
Robert Sprowson committed
97
	Push	"r1-r10,lr"			;
98 99 100
	BL	get_logical_and_pin		;
	CMP	r0,#-1				;
	BEQ	%FT10				;
101 102 103 104
	ADRL	r4,proc_reg_list		;
	ADD	r2,r2,r4			;
	LDRH	r6,[r2,#proc_oe]		;
	LDR	r0,[r0,r6]			;get oe register value
105 106 107
	AND	r0,r0,r1			;
	CMP	r0,#0				;is it output ?
	MOVNE	r0,#1				;opposite logic to match Pi
Robert Sprowson's avatar
Robert Sprowson committed
108
10	Pull	"r1-r10,pc"			; restore registers and exit
109 110 111 112 113 114 115 116 117
;r0=value (0=output,1=input)

;---------------------------------------------
;WriteOE
;r0=GPIO number
;r1=value 0 or 1
Write_OE
	CMP	r0,#i2c_flag-1			;check if i2c gpio
	BCS	i2c_Write_OE			;
Robert Sprowson's avatar
Robert Sprowson committed
118
	Push	"r1-r10,lr"			;
119
	SWI	XOS_IntOff
120
	MOV	r7,r1				;save value
121 122 123
	BL	check_protect_i2c		;
	CMP	r0,#-1				;
	BEQ	%FT10				;
Robert Sprowson's avatar
Robert Sprowson committed
124
	Push	"r0"				;
125 126 127 128
	BL	get_table			;
	BL	find_register			;
	TST	r0,#input_only			;
	MOVNE	r7,#1				;
Robert Sprowson's avatar
Robert Sprowson committed
129
	Pull	"r0"				;
130 131 132
	BL	get_logical_and_pin		;
	CMP	r0,#-1				;
	BEQ	%FT10				;
133 134 135 136 137
	ADRL	r4,proc_reg_list		;
	ADD	r2,r2,r4			;
	LDRH	r6,[r2,#proc_oe]		;
	LDR	r3,[r0,r6]			;get oe register value
	CMP	r7,#0				;set as output or input
138 139
	BICEQ	r3,r3,r1			;set pin as output if not already
	ORRNE	r3,r3,r1			;set pin as input if not already
140
	STR	r3,[r0,r6]			;save back
141 142
	MOV	r0,#0				;
10	SWI	XOS_IntOn
Robert Sprowson's avatar
Robert Sprowson committed
143
	Pull	"r1-r10,pc"			; restore registers and exit
144 145 146 147 148 149
;r0=0 if ok -1 if protected

;----------------------------------------------
; MapAuxIn
;r0=mode
Aux_As_GPIO
Robert Sprowson's avatar
Robert Sprowson committed
150
	Push	"r0-r10,lr"			;
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165
	BL	get_table			;
	LDR	r6,[r1,#aux_pins]		;get list of pins
common	CMP	r6,#-1				;
	BEQ	%FT20
	TST	r0,#2				;check if in/out
	MOVEQ	r7,#1				;set OE
	MOVNE	r7,#0				;set OE
	TST	r0,#1				;check if up/down
	MOVEQ	r3,#mygpiomode1			;mode for pins
	MOVNE	r3,#mygpiomode2			;mode for pins
common1
10	LDRB	r0,[r6],#1			;get pin number
	CMP	r0,#&FF				;last one ?
	BEQ	%FT20				;
	MOV	r1,r3				;keep mode type
166
	MOV	r4,r0				;keep gpio number
167 168 169 170 171 172
	BL	Write_Mode			;
	CMP	r0,#-1				;
	BEQ	%BT10				;
	CMP	r7,#&FF				;skip OE
	BEQ	%BT10				;
	MOV	r1,r7				;get in/out mode
173
	MOV	r0,r4				;get gpio number
174 175 176
	BL	Write_OE			;write OE
	CMP	r7,#0				;set outputs ?
	BNE	%BT10				;
177
	MOV	r0,r4				;get gpio number
178 179 180
	MOV	r1,#0				;set output to off
	BL	Write_Data			;write data
	B	%BT10				;next
Robert Sprowson's avatar
Robert Sprowson committed
181
20	Pull	"r0-r10,pc"			; restore registers and exit
182 183 184 185
;---------------------------------------------
; MapExpIn
;r0=mode
Exp_As_GPIO
Robert Sprowson's avatar
Robert Sprowson committed
186
	Push	"r0-r10,lr"			;
187 188 189 190 191 192 193 194
	BL	get_table			;
	LDR	r6,[r1,#exp_pins]		;get list of pins
	B	common				;

;---------------------------------------------
; MapCameraIn
;r0=mode
Camera_As_GPIO
Robert Sprowson's avatar
Robert Sprowson committed
195
	Push	"r0-r10,lr"			;
196 197 198 199 200 201
	BL	get_table			;
	LDR	r6,[r1,#camera_pins]		;get list of pins
	B	common				;
;---------------------------------------------
; SafeAuxIn
Aux_As_Safe
Robert Sprowson's avatar
Robert Sprowson committed
202
	Push	"r0-r10,lr"			;
203 204 205 206 207 208 209
	BL	get_table			;
	LDR	r6,[r1,#aux_pins]		;get list of pins
safe	CMP	r6,#-1				;
	BEQ	%FT20
	MOV	r3,#safemode			;safe mode
	MOV	r7,#&FF				;skip OE write
	B	common1				;
Robert Sprowson's avatar
Robert Sprowson committed
210
20	Pull	"r0-r10,pc"			; restore registers and exit
211 212 213
;---------------------------------------------
; SafeExpIn
Exp_As_Safe
Robert Sprowson's avatar
Robert Sprowson committed
214
	Push	"r0-r10,lr"			;
215 216 217 218 219 220
	BL	get_table			;
	LDR	r6,[r1,#exp_pins]		;get list of pins
	B	safe				;
;---------------------------------------------
; SafecameraIn
Camera_As_Safe
Robert Sprowson's avatar
Robert Sprowson committed
221
	Push	"r0-r10,lr"			;
222 223 224 225 226 227
	BL	get_table			;
	LDR	r6,[r1,#camera_pins]		;get list of pins
	B	safe				;
;---------------------------------------------
;
Aux_As_USB
Robert Sprowson's avatar
Robert Sprowson committed
228
	Push	"r0-r10,lr"			;
229 230 231 232 233 234 235 236 237 238 239 240 241
	MOV	r7,#usb_pins			;
set_pins
	BL	get_table			;
	LDR	r6,[r1,r7]			;get list of pins + mode
	CMP	r6,#-1				;
	BEQ	%FT20
10	LDRH	r1,[r6],#2			;get pin and mode
	CMP	r1,#&FF				;last ?
	BEQ	%FT20				;
	AND	r0,r1,#&FF			;just gpio
	MOV	r1,r1,LSR #8			;just mode
	BL	Write_Mode
	B	%BT10
Robert Sprowson's avatar
Robert Sprowson committed
242
20	Pull	"r0-r10,pc"			; restore registers and exit
243 244 245
;---------------------------------------------
;
Exp_As_UART
Robert Sprowson's avatar
Robert Sprowson committed
246
	Push	"r0-r10,lr"			;
247 248 249 250 251
	MOV	r7,#uart_pins			;
	B	set_pins			;
;---------------------------------------------
;
Aux_As_MMC
Robert Sprowson's avatar
Robert Sprowson committed
252
	Push	"r0-r10,lr"			;
253 254 255 256 257
	MOV	r7,#mmc_aux_pins		;
	B	set_pins			;
;---------------------------------------------
; mode2AuxIn
Exp_As_MMC
Robert Sprowson's avatar
Robert Sprowson committed
258
	Push	"r0-r10,lr"			;
259 260 261 262 263
	MOV	r7,#mmc_exp_pins		;
	B	set_pins			;
;---------------------------------------------
; mode3AuxIn
Aux_As_MM
Robert Sprowson's avatar
Robert Sprowson committed
264
	Push	"r0-r10,lr"			;
265 266 267 268 269 270 271 272
	MOV	r7,#mm_pins			;
	B	set_pins			;
;---------------------------------------------
;ReadMode
;r0=GPIO number
Read_Mode
	CMP	r0,#i2c_flag-1			;check if i2c gpio
	BCS	i2c_Read_Mode
Robert Sprowson's avatar
Robert Sprowson committed
273
	Push	"r1-r10,lr"			;
274 275 276 277 278 279 280 281
	MOV	r5,#1				; read/write flag
;r5=read or write (1/0)
;r6=mode to write
modecommon
	BL	get_table			;
	BL	find_register			;
	CMP	r0,#-1				;error ?
	BEQ	%FT10				;
282 283
	BIC	r0,r0,#input_only		; preserve r0
	MOV	r4,r0
284 285 286
	LDR	r1,[r12,#logicalstore1]		;get logical address
	CMP	r5,#0				; check read/write flag
	STREQH	r6,[r1,r4]			; write half word
287 288
	LDRNEH	r0,[r1,r4]			; read half word
	MOVEQ	r0,r6
Robert Sprowson's avatar
Robert Sprowson committed
289
10	Pull	"r1-r10,pc"			; restore registers and exit
290 291 292 293 294 295 296 297
;r0=mode (-1=not ours)
;---------------------------------------------
;WriteMode
;r0=GPIO number
;r1=mode
Write_Mode
	CMP	r0,#i2c_flag-1			;check if i2c gpio
	BCS	i2c_Write_Mode
Robert Sprowson's avatar
Robert Sprowson committed
298
	Push	"r1-r10,lr"			;
299 300 301 302 303
	MOV	r6,r1				; preserve data
	BL	check_protect_i2c		;
	MOV	r5,#0				; read/write flag
	CMP	r0,#-1				;
	BNE	modecommon			;
Robert Sprowson's avatar
Robert Sprowson committed
304
	Pull	"r1-r10,pc"			; restore registers and exit
305 306 307 308 309 310 311
;r0=mode (-1=not ours)
;---------------------------------------------
;ReadLevel0
;r0=GPIO number
Read_Level0
	CMP	r0,#i2c_flag-1			;check if i2c gpio
	BCS	i2c_Read_Polarity
Robert Sprowson's avatar
Robert Sprowson committed
312
	Push	"r1-r10,lr"			;
313
	MOV	r7,#1				; read/write flag
314
	MOV	r8,#proc_leveldetect0		;register
315 316 317 318 319
;r5=read or write (1,0)
;r6=mode to write
;r9=register to check
levelcommon
	BL	get_logical_and_pin		;
320 321 322
	ADRL	r4,proc_reg_list		;
	ADD	r2,r2,r4			;
	LDRH	r8,[r2,r8]			;
323 324 325 326 327
	CMP	r0,#-1				;
	BEQ	%FT10				;
	LDR	r3,[r0,r8]			;get register value
	MOV	r4,r3				;keep setting
	CMP	r6,#0				;set/unset
328
	BICEQ	r3,r3,r1			;dont care if reading
329 330 331 332 333 334
	ORRNE	r3,r3,r1			;
	CMP	r7,#0				;
	STREQ	r3,[r0,r8]			;save back
	AND	r0,r4,r1			;
	CMP	r0,#0				;
	MOVNE	r0,#1				;
Robert Sprowson's avatar
Robert Sprowson committed
335
10	Pull	"r1-r10,pc"			; restore registers and exit
336 337 338 339 340 341 342 343
;r0=mode
;---------------------------------------------
;WriteLevel0
;r0=GPIO number
;r1=0/1
Write_Level0
	CMP	r0,#i2c_flag-1			;check if i2c gpio
	BCS	i2c_Write_Polarity
Robert Sprowson's avatar
Robert Sprowson committed
344
	Push	"r1-r10,lr"			;
345
	MOV	r8,#proc_leveldetect0		;register
346 347 348 349 350 351 352 353
write_register
	MOV	r7,#0				; read/write flag
	CMP	r1,#0				; preserve data
	MOVEQ	r6,#0				;
	MOVNE	r6,#1				;
	BL	check_protect_i2c		;
	CMP	r0,#-1				;
	BNE	levelcommon			;
Robert Sprowson's avatar
Robert Sprowson committed
354
	Pull	"r1-r10,pc"			; restore registers and exit
355 356 357 358 359 360 361 362
;r0=mode or -1 if protected
;preserves all others
;---------------------------------------------
;ReadLevel1
;r0=GPIO number
Read_Level1
	CMP	r0,#i2c_flag-1			;check if i2c gpio
	BCS	i2c_Read_Pull
Robert Sprowson's avatar
Robert Sprowson committed
363
	Push	"r1-r10,lr"			;
364
	MOV	r7,#1				; read/write flag
365
	MOV	r8,#proc_leveldetect1		;register
366 367 368 369 370 371 372 373
	B	levelcommon			;
;---------------------------------------------
;WriteLevel1
;r0=GPIO number
;r1=0/1
Write_Level1
	CMP	r0,#i2c_flag-1			;check if i2c gpio
	BCS	i2c_Write_Pull
Robert Sprowson's avatar
Robert Sprowson committed
374
	Push	"r1-r10,lr"			;
375
	MOV	r8,#proc_leveldetect1		;register
376 377 378 379 380
	B	write_register			;
;---------------------------------------------
;ReadRising
;r0=GPIO number
Read_Rising
Robert Sprowson's avatar
Robert Sprowson committed
381
	Push	"r1-r10,lr"			;
382
	MOV	r7,#1				; read/write flag
383
	MOV	r8,#proc_risingdetect		;register
384 385 386 387 388 389
	B	levelcommon			;
;---------------------------------------------
;WriteRising
;r0=GPIO number
;r1=0/1
Write_Rising
Robert Sprowson's avatar
Robert Sprowson committed
390
	Push	"r1-r10,lr"			;
391
	MOV	r8,#proc_risingdetect		;register
392 393 394 395 396
	B	write_register			;
;---------------------------------------------
;ReadFallin
;r0=GPIO number
Read_Falling
Robert Sprowson's avatar
Robert Sprowson committed
397
	Push	"r1-r10,lr"			;
398
	MOV	r7,#1				; read/write flag
399
	MOV	r8,#proc_fallingdetect		;register
400 401 402 403 404 405
	B	levelcommon			;
;---------------------------------------------
;WriteFalling
;r0=GPIO number
;r1=0/1
Write_Falling
Robert Sprowson's avatar
Robert Sprowson committed
406
	Push	"r1-r10,lr"			;
407
	MOV	r8,#proc_fallingdetect		;register
408 409 410 411 412
	B	write_register			;
;---------------------------------------------
;ReadDebounceEnable
;r0=GPIO number
Read_DebounceEnable
Robert Sprowson's avatar
Robert Sprowson committed
413
	Push	"r1-r10,lr"			;
414
	MOV	r7,#1				; read/write flag
415
	MOV	r8,#proc_debounceenable		;register
416 417 418 419 420 421
	B	levelcommon			;
;---------------------------------------------
;WriteDebounceEnable
;r0=GPIO number
;r1=0/1
Write_DebounceEnable
Robert Sprowson's avatar
Robert Sprowson committed
422
	Push	"r1-r10,lr"			;
423
	MOV	r8,#proc_debounceenable		;register
424 425 426 427 428
	B	write_register			;
;---------------------------------------------
;ReadIRQ1
;r0=GPIO number
Read_IRQ1
Robert Sprowson's avatar
Robert Sprowson committed
429
	Push	"r1-r10,lr"			;
430
	MOV	r7,#1				; read/write flag
431
	MOV	r8,#proc_irqstatus1		;
432 433 434 435 436 437
	B	levelcommon			;
;---------------------------------------------
;WriteIRQ1
;r0=GPIO number
;r1=0/1
Write_IRQ1
Robert Sprowson's avatar
Robert Sprowson committed
438
	Push	"r1-r10,lr"			;
439
	MOV	r7,r1				;
440 441 442 443 444 445
	BL	check_protect_i2c		;
	CMP	r0,#-1				;
	BEQ	%FT10
	BL	get_logical_and_pin		;
	CMP	r0,#-1				;
	BEQ	%FT10				;
446 447 448 449 450 451 452
	ADRL	r4,proc_reg_list		;
	ADD	r2,r2,r4			;
	LDRH	r6,[r2,#proc_irqstatus1]	;
	LDRH	r5,[r2,#proc_setirqenable1]	;
	LDRH	r4,[r2,#proc_clearirqenable1]	;
irqcommon
	LDR	r3,[r0,r6]			;get register value
453
	AND	r1,r3,r1			;
454 455 456
	CMP	r7,#0				;check flag
	STRNE	r1,[r0,r5]			;set irq bit
	STREQ	r1,[r0,r4]			;unset irq bit
457
	MOV	r0,#0				;
Robert Sprowson's avatar
Robert Sprowson committed
458
10	Pull	"r1-r10,pc"			; restore registers and exit
459 460 461 462 463 464
;r0=0 if ok -1 if protected
;preserves all others
;---------------------------------------------
;ReadIRQ2
;r0=GPIO number
Read_IRQ2
Robert Sprowson's avatar
Robert Sprowson committed
465
	Push	"r1-r10,lr"			;
466
	MOV	r7,#1				; read/write flag
467
	MOV	r8,#proc_irqstatus2		;
468 469 470 471 472 473
	B	levelcommon			;
;---------------------------------------------
;WriteIRQ2
;r0=GPIO number
;r1=0/1
Write_IRQ2
Robert Sprowson's avatar
Robert Sprowson committed
474
	Push	"r1-r10,lr"			;
475
	MOV	r7,r1				;
476 477
	BL	check_protect_i2c		;
	BEQ	%FT10				;
478 479 480 481 482 483 484 485 486
	BL	get_logical_and_pin		;
	CMP	r0,#-1				;
	BEQ	%FT10				;
	ADRL	r4,proc_reg_list		;
	ADD	r2,r2,r4			;
	LDRH	r6,[r2,#proc_irqstatus2]	;
	LDRH	r5,[r2,#proc_setirqenable2]	;
	LDRH	r4,[r2,#proc_clearirqenable2]	;
	B	irqcommon
Robert Sprowson's avatar
Robert Sprowson committed
487
10	Pull	"r1-r10,pc"			; restore registers and exit
488 489 490 491 492 493 494
;r0=0 if ok -1 if protected
;preserves all others
;---------------------------------------------
;readexp32
Read_Exp_32
	CMP	r0,#i2c_flag-1			;check if i2c gpio
	BCS	i2c_ReadBlock			;
Robert Sprowson's avatar
Robert Sprowson committed
495
	Push	"r2-r10,lr"			;
496 497 498 499 500 501 502 503 504 505 506 507
	BL	get_table			;
	LDR	r0,[r1,#widebit_pins]		;get list of pins
	CMP	r0,#-1				;check if exists
	BEQ	%FT10				;
	LDR	r5,[r0,#wide_exp]		;get mask
	LDR	r0,[r0,#wide_exppin]		;first pin
commonread32
	CMP	r0,#-1				;check if exists
	BEQ	%FT10				;
	BL	get_logical_and_pin		;
	CMP	r0,#-1				;
	BEQ	%FT10				;
508 509 510 511 512 513 514 515 516 517 518
	ADRL	r4,proc_reg_list		;
	ADD	r2,r2,r4			;
	LDRH	r4,[r2,#proc_oe]		;
	LDR	r4,[r0,r4]			;get oe register value
	LDRH	r6,[r2,#proc_dataout]		;
	LDR	r3,[r0,r6]			;get register value
	LDRH	r6,[r2,#proc_datain]		;
	LDR	r0,[r0,r6]			;get register value
	AND	r0,r0,r4			;just inputs
	MVN	r4,r4				;
	AND	r0,r3,r4			;just our pins again
519 520
	AND	r0,r0,r5			;just our pins
	MOV	r1,r5				;give user the bitmask
Robert Sprowson's avatar
Robert Sprowson committed
521
10	Pull	"r2-r10,pc"			; restore registers and exit
522 523 524 525 526 527 528 529 530
;r0=data state
;r1=bitmask
;preserves all others
;---------------------------------------------
;Readaux32
;r0=bits to set/unset
Read_Aux_32
	CMP	r0,#i2c_flag-1			;check if i2c gpio
	BCS	i2c_ReadByte			;
Robert Sprowson's avatar
Robert Sprowson committed
531
	Push	"r2-r10,lr"			;
532 533 534 535 536 537 538 539 540 541 542 543 544
	BL	get_table			;
	LDR	r0,[r1,#widebit_pins]		;get list of pins
	CMP	r0,#-1				;check if exists
	BEQ	%BT10				;
	LDR	r5,[r0,#wide_aux]		;get mask
	LDR	r0,[r0,#wide_auxpin]		;first pin
	B	commonread32
;r0=bitmask of data state
;r1=bitmask
;preserves all others
;---------------------------------------------
;Readcam32
Read_Cam_32
Robert Sprowson's avatar
Robert Sprowson committed
545
	Push	"r2-r10,lr"			;
546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561
	BL	get_table			;
	LDR	r0,[r1,#widebit_pins]		;get list of pins
	CMP	r0,#-1				;check if exists
	BEQ	%BT10				;
	LDR	r5,[r0,#wide_cam]		;get mask
	LDR	r0,[r0,#wide_campin]		;first pin
	B	commonread32
;r0=bitmask of data state
;r1=bitmask
;preserves all others
;---------------------------------------------
;writeexp32
;r0=bits to set/unset
Write_Exp_32
	CMP	r0,#i2c_flag-1			;check if i2c gpio
	BCS	i2c_WriteBlock			;
Robert Sprowson's avatar
Robert Sprowson committed
562
	Push	"r0-r10,lr"			;
563 564 565 566 567 568 569 570 571 572
	LDR	r7,exp_bitmap			;get mask
	MOV	r6,r0				;keep bitmap
	MOV	r0,#gpio_139			;check mapped in
common32
	BL	check_protect_i2c		;
	CMP	r0,#-1				;error
	BEQ	%FT10				;
	BL	get_logical_and_pin		;
	CMP	r0,#-1				;
	BEQ	%FT10				;
573 574 575 576 577
	ADRL	r4,proc_reg_list		;
	ADD	r2,r2,r4			;
	LDRH	r5,[r2,#proc_setdataout]	;
	LDRH	r4,[r2,#proc_cleardataout]	;
	MVN	r3,r6				;invert settings
578
	ANDS	r3,r3,r7			;just our pins
579
	STRNE	r3,[r0,r4]			;unset them
580
	ANDS	r4,r6,r7			;just our pins
581
	STRNE	r4,[r0,r5]			;set them
Robert Sprowson's avatar
Robert Sprowson committed
582
10	Pull	"r0-r10,pc"			; restore registers and exit
583 584 585 586 587 588 589 590
;preserves all registers
exp_bitmap	DCD	expbitmap
;---------------------------------------------
;writeaux32
;r0=bits to set/unset
Write_Aux_32
	CMP	r0,#i2c_flag-1			;check if i2c gpio
	BCS	i2c_WriteByte			;
Robert Sprowson's avatar
Robert Sprowson committed
591
	Push	"r0-r10,lr"			;
592 593 594 595 596 597 598 599 600 601
	LDR	r7,aux_bitmap			;get mask
	MOV	r6,r0				;keep bitmap
	MOV	r0,#gpio_12			;check mapped in
	B	common32
;preserves all registers
aux_bitmap	DCD	auxbitmap
;---------------------------------------------
;writecam32
;r0=bits to set/unset
Write_Cam_32
Robert Sprowson's avatar
Robert Sprowson committed
602
	Push	"r0-r10,lr"			;
603 604 605 606 607 608 609 610 611 612 613
	LDR	r7,cam_bitmap			;get mask
	MOV	r6,r0				;keep bitmap
	MOV	r0,#gpio_96			;check mapped in
	B	common32
;preserves all registers
cam_bitmap	DCD	cambitmap
;---------------------------------------------
;readexpOE32
Read_Exp_OE_32
	CMP	r0,#i2c_flag-1			;check if i2c gpio
	BCS	i2c_ReadBlockOE			;
Robert Sprowson's avatar
Robert Sprowson committed
614
	Push	"r2-r10,lr"			;
615 616 617 618 619 620
	LDR	r5,exp_bitmap			;get mask
	MOV	r0,#gpio_139			;check mapped in
commonoeread32
	BL	get_logical_and_pin		;
	CMP	r0,#-1				;
	BEQ	%FT10				;
621 622 623 624
	ADRL	r4,proc_reg_list		;
	ADD	r2,r2,r4			;
	LDRH	r6,[r2,#proc_oe]		;
	LDR	r0,[r0,r6]			;get register value
625 626
	AND	r0,r0,r5			;just our pins
	MOV	r1,r5				;give user bitmask
Robert Sprowson's avatar
Robert Sprowson committed
627
10	Pull	"r2-r10,pc"			; restore registers and exit
628 629 630 631 632 633 634 635 636
;r0=bitmask of OE register
;r1=bitmask
;preserves all others

;---------------------------------------------
;readauxoe32
Read_Aux_OE_32
	CMP	r0,#i2c_flag-1			;check if i2c gpio
	BCS	i2c_ReadByteOE			;
Robert Sprowson's avatar
Robert Sprowson committed
637
	Push	"r2-r10,lr"			;
638 639 640 641 642 643 644 645 646 647
	LDR	r5,aux_bitmap			;get mask
	MOV	r0,#gpio_12			;check maped in
	B	commonoeread32
;r0=bitmask of OE register
;r1=bitmask
;preserves all others
;---------------------------------------------
;readcamoe32
;r0=bits to set/unset
Read_Cam_OE_32
Robert Sprowson's avatar
Robert Sprowson committed
648
	Push	"r2-r10,lr"			;
649 650 651 652 653 654 655 656 657 658 659 660
	LDR	r5,cam_bitmap			;get mask
	MOV	r0,#gpio_96			;check maped in
	B	commonoeread32
;r0=bitmask of OE register
;r1=bitmask
;preserves all others
;---------------------------------------------
;writeexpOE32
;r0=bits to set/unset
Write_Exp_OE_32
	CMP	r0,#i2c_flag-1			;check if i2c gpio
	BCS	i2c_WriteBlockOE		;
Robert Sprowson's avatar
Robert Sprowson committed
661
	Push	"r0-r10,lr"			;
662 663 664 665 666 667 668 669 670 671
	LDR	r7,exp_bitmap			;get mask
	MOV	r6,r0				;keep bitmap
	MOV	r0,#gpio_139			;check maped in
commonoe32
	BL	check_protect_i2c		;
	CMP	r0,#-1				;error
	BEQ	%FT10				;
	BL	get_logical_and_pin		;
	CMP	r0,#-1				;
	BEQ	%FT10				;
672 673 674 675
	ADRL	r4,proc_reg_list		;
	ADD	r2,r2,r4			;
	LDRH	r5,[r2,#proc_oe]		;
	LDR	r2,[r0,r5]			;get register value
676 677 678 679
	MVN	r3,r7				;opposit mask
	AND	r4,r6,r7			;just our pins
	AND	r2,r2,r3			;clears all our outputs
	ORR	r1,r2,r4			;set/unset our pins
680
	STR	r1,[r0,r5]			;
Robert Sprowson's avatar
Robert Sprowson committed
681
10	Pull	"r0-r10,pc"			; restore registers and exit
682 683 684 685 686 687
;preserves all registers
;---------------------------------------------
;writeauxoe32
;r0=bits to set/unset
Write_Aux_OE_32
	CMP	r0,#i2c_flag-1			;check if i2c gpio
688
	BCS	i2c_WriteByteOE			;
Robert Sprowson's avatar
Robert Sprowson committed
689
	Push	"r0-r10,lr"			;
690 691 692 693 694 695 696 697 698
	LDR	r7,aux_bitmap			;get mask
	MOV	r6,r0				;keep bitmap
	MOV	r0,#gpio_12			;check maped in
	B	commonoe32
;preserves all registers
;---------------------------------------------
;writecamoe32
;r0=bits to set/unset
Write_Cam_OE_32
Robert Sprowson's avatar
Robert Sprowson committed
699
	Push	"r0-r10,lr"			;
700 701 702 703 704 705 706 707
	LDR	r7,cam_bitmap			;get mask
	MOV	r6,r0				;keep bitmap
	MOV	r0,#gpio_96			;check maped in
	B	commonoe32
;preserves all registers
;---------------------------------------------
;r0=GPIO
Address
Robert Sprowson's avatar
Robert Sprowson committed
708
	Push	"r2-r10,lr"			;
709
	BL	get_logical_and_pin		;
Robert Sprowson's avatar
Robert Sprowson committed
710
	Pull	"r2-r10,pc"			;
711 712 713 714 715 716 717 718
;r0=Logical
;r1=Mask
;---------------------------------------------
;sramread
;r0=pointer to sram to get
;r1=pointer to buffer
;r2=size
sramread
Robert Sprowson's avatar
Robert Sprowson committed
719
	Push	"r0-r10,lr"			;
720 721 722 723 724 725 726 727 728 729 730 731 732 733
	ADD	r3,r0,r2			;check address
	CMP	r3,#sramsize			;
	BGE	%FT10				;bad address
	LDR	r3,[r12,#logicalsram]		;sram logical
	CMP	r3, #-1				;
	BEQ	%FT10				;bad address
	MOV	r5,r2				;
	ADD	r2,r2,r0			;add pointer
20	LDRB	r4,[r3,r2]			;get word
	STRB	r4,[r1,r5]			;save it
	SUB	r2,r2,#1			;dec pointer
	SUB	r5,r5,#1			;dec pointer
	CMP	r2,r0				;last byte ?
	BGE	%BT20				;
Robert Sprowson's avatar
Robert Sprowson committed
734
10	Pull	"r0-r10,pc"			;
735 736 737 738 739 740
;---------------------------------------------
;sramwrite
;r0=pointer to sram to write
;r1=pointer to buffer
;r2=size
sramwrite
Robert Sprowson's avatar
Robert Sprowson committed
741
	Push	"r0-r10,lr"			;
742 743 744 745 746 747 748 749 750 751 752 753 754 755
	ADD	r3,r0,r2			;check address
	CMP	r3,#sramsize			;
	BGE	%FT10				;bad address
	LDR	r3,[r12,#logicalsram]		;sram logical
	CMP	r3, #-1				;
	BEQ	%FT10				;bad address
	MOV	r5,r2				;
	ADD	r2,r2,r0			;add pointer
20	LDRB	r4,[r1,r5]			;get word
	STRB	r4,[r3,r2]			;save it
	SUB	r2,r2,#1			;dec pointer
	SUB	r5,r5,#1			;dec pointer
	CMP	r2,r0				;last byte ?
	BGE	%BT20				;
Robert Sprowson's avatar
Robert Sprowson committed
756
10	Pull	"r0-r10,pc"			;
757 758 759 760 761
;---------------------------------------------

;loadconfig
;r0 pointer to list
Load_Config
Robert Sprowson's avatar
Robert Sprowson committed
762
	Push	"r0-r10,lr"			;
763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823
	MOV	r4,r0
10	LDR	r0,[r4],#4			;get first word
	CMP	r0,#-1				;last ?
	BEQ	%FT20
	AND	r3,r0,#&0001F000		;get flags
	AND	r1,r0,#&00000700		;get pin mode
	MOV	r1,r1,LSR #8			;mode to bottom
	TST	r3,#conf_updown			;test updown bit
	ADDNE	r1,r1,#pullenable+pullup	;
	ADDEQ	r1,r1,#pullenable+pulldown	;
	TST	r3,#conf_inenable		;test input enable bit
	ADDEQ	r1,r1,#inputenable		;
	ADDNE	r1,r1,#inputdisable		;
	TST	r0,#i2c_flag			;i2c ?
	AND	r0,r0,#&FF			;just GPIO number
	ADDNE	r0,r0,#i2c_flag			;add flag if needed
	MOV	r5,r0				;keep GPIO
	BL	Write_Mode			;set it
	TST	r3,#conf_io			;test IO bit
	MOVNE	r1,#1				;set flag
	MOVEQ	r1,#0				;
	MOV	r0,r5				;gpio number
	BL	Write_OE			;
	TST	r3,#conf_extended		;test extended bit
	BEQ	%BT10				;get next if not
	TST	r3,#conf_lv0			;
	MOVNE	r1,#1				;set flag
	MOVEQ	r1,#0				;
	MOV	r0,r5				;gpio number
	BL	Write_Level0			;
	TST	r3,#conf_lv1			;
	MOVNE	r1,#1				;set flag
	MOVEQ	r1,#0				;
	MOV	r0,r5				;gpio number
	BL	Write_Level1			;
	TST	r3,#conf_rising			;
	MOVNE	r1,#1				;set flag
	MOVEQ	r1,#0				;
	MOV	r0,r5				;gpio number
	BL	Write_Rising			;
	TST	r3,#conf_falling		;
	MOVNE	r1,#1				;set flag
	MOVEQ	r1,#0				;
	MOV	r0,r5				;gpio number
	BL	Write_Falling			;
	TST	r3,#conf_debounce		;
	MOVNE	r1,#1				;set flag
	MOVEQ	r1,#0				;
	MOV	r0,r5				;gpio number
	BL	Write_DebounceEnable		;
	TST	r3,#conf_irq1			;
	MOVNE	r1,#1				;set flag
	MOVEQ	r1,#0				;
	MOV	r0,r5				;gpio number
	BL	Write_IRQ1			;
	TST	r3,#conf_irq2			;
	MOVNE	r1,#1				;set flag
	MOVEQ	r1,#0				;
	MOV	r0,r5				;gpio number
	BL	Write_IRQ2			;
	B	%BT10				;
Robert Sprowson's avatar
Robert Sprowson committed
824
20	Pull	"r0-r10,pc"			;
825 826 827 828 829 830
;preserves all registers
;---------------------------------------------
;readconfig
;r0 pointer for list or -1 for my space
;r1 extended or normal flag
Read_Config
Robert Sprowson's avatar
Robert Sprowson committed
831
	Push	"r2-r10,lr"			;
832 833 834 835 836 837 838 839 840 841 842 843 844 845
	CMP	r0,#-1				;my space or yours
	ADDEQ	r0,r12,#configdata		;point to my RMA store
	MOV	r7,r0				;save it for later
	MOV	r3,r1				;keep flag
	BL	get_table			;pointer to list of tables
	LDR	r2,[r1,#aux_pins]		;get list of registers
	CMP	r2,#-1				;check if exists
	BLNE	dotableread			;
	LDR	r2,[r1,#exp_pins]		;get list of registers
	CMP	r2,#-1				;check if exists
	BLNE	dotableread			;
	LDR	r2,[r1,#camera_pins]		;get list of registers
	CMP	r2,#-1				;check if exists
	BLNE	dotableread			;
846 847 848
	LDR	r2,[r1,#user_pins]		;get list of registers
	CMP	r2,#-1				;check if exists
	BLNE	dotableread			;
849 850 851 852 853
	BL	i2c_ReadConfig			;do i2c read
	MOV	r4,#-1				;
	STR	r4,[r0]				;end of list
	MOV	r1,r0				;pass pointer to terminator back to user
	MOV	r0,r7				;let user know location
Robert Sprowson's avatar
Robert Sprowson committed
854
	Pull	"r2-r10,pc"			;
855 856 857 858 859
;r0 pointer to list -1 terminated
;r1 pointer to terminator


dotableread
Robert Sprowson's avatar
Robert Sprowson committed
860
	Push	"r1-r10,lr"			;
861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928
	MOV	r4,r0				;
10	LDRB	r0,[r2],#1			;get pin
	CMP	r0,#&FF				;last
	BEQ	%FT20				;do exp port now
	MOV	r5,r0				;save it
	STR	r0,[r4],#1			;start list
	BL	Read_Mode			;get pin mode
	AND	r6,r0,#7			;just mode
	TST	r0,#pullup			;
	MOVNE	r1,#conf_updown			;
	MOVEQ	r1,#0				;
	TST	r0,#pullenable			;
	ADDEQ	r1,r1,#conf_inenable		;
	ADDNE	r1,r1,#0			;
	ORR	r6,r6,r1,LSR #8			;set flags
	MOV	r0,r5				;
	BL	Read_OE				;get the IO mode
	CMP	r0,#1				;test result
	MOVEQ	r0,#conf_io			;
	ORR	r6,r6,r0,LSR #8			;add flag
	CMP	r3,#1				;test extended request
	MOVEQ	r0,#conf_extended		;
	MOVNE	r0,#0				;
	ORR	r6,r6,r0,LSR #8			;
	STRB	r6,[r4],#1			;save flags
	ADDNE	r4,r4,#2			;point to next word
	BNE	%BT10				;
	MOV	r6,#0				;clear flag register
	MOV	r0,r5				;
	BL	Read_Level0			;
	CMP	r0,#1				;test result
	MOVNE	r0,#conf_lv0			;
	ORR	r6,r6,r0,LSR #16		;add flag
	MOV	r0,r5				;
	BL	Read_Level1			;
	CMP	r0,#1				;test result
	MOVNE	r0,#conf_lv1			;
	ORR	r6,r6,r0,LSR #16		;add flag
	MOV	r0,r5				;
	BL	Read_Rising			;
	CMP	r0,#1				;test result
	MOVNE	r0,#conf_rising			;
	ORR	r6,r6,r0,LSR #16		;add flag
	MOV	r0,r5				;
	BL	Read_Falling			;
	CMP	r0,#1				;test result
	MOVNE	r0,#conf_falling		;
	ORR	r6,r6,r0,LSR #16		;add flag
	MOV	r0,r5				;
	BL	Read_DebounceEnable		;
	CMP	r0,#1				;test result
	MOVNE	r0,#conf_debounce		;
	ORR	r6,r6,r0,LSR #16		;add flag
	MOV	r0,r5				;
	BL	Read_IRQ1			;
	CMP	r0,#1				;test result
	MOVNE	r0,#conf_irq1			;
	ORR	r6,r6,r0,LSR #16		;add flag
	MOV	r0,r5				;
	BL	Read_IRQ2			;
	CMP	r0,#1				;test result
	MOVNE	r0,#conf_irq2			;
	ORR	r6,r6,r0,LSR #16		;add flag
	STRB	r6,[r4],#1			;save flags
	ADD	r4,r4,#1			;point to next word
	B	%BT10				;get next
20
	MOV	r0,r4				;pass pointer back
Robert Sprowson's avatar
Robert Sprowson committed
929
	Pull	"r1-r10,pc"			;
930 931 932 933

;---------------------------------------------
;r0=0 or 1 1=enable
Enable_I2C
Robert Sprowson's avatar
Robert Sprowson committed
934
	Push	"r0-r10,lr"			;
935 936 937 938
	CMP	r0,#0				;
	BEQ	%FT10				;
	MOV	r3,r0				;keep r0
	BL	get_table			;
939 940
	LDR	r4,[r1,#i2c_pins]		;get list of registers
	CMP	r4,#-1				;no table
941 942
	MOVEQ	r0,#0				;so not protected
	BEQ	%FT10
943
30	LDRB	r0,[r4]				;
944 945 946 947 948
	CMP	r0,#&FF				;
	BEQ	%FT20
	BL	Read_Mode			;get old setting
	BIC	r0,r0,#7			;clear mode
	ORR	r1,r0,#mode0			;set to mode 0
949
	LDRB	r0,[r4],#1			;writeback pointer
950 951 952 953
	BL	Write_Mode			;
	B	%BT30
20	MOV	r0,r3				;get r0
10	STR	r0,[r12,#i2cprotect]		;set flag
Robert Sprowson's avatar
Robert Sprowson committed
954
	Pull	"r0-r10,pc"			;
955 956 957
;preserves all registers
;---------------------------------------------
GPIO_Info
Robert Sprowson's avatar
Robert Sprowson committed
958
	Push	"r3-r10,lr"			;
959 960 961 962
;copy table 2,3,4,5 to RMA
	BL	copy_tables_to_rma
	MOV	r0,#0				;lowest GPIO number
	MOV	r1,#top_gpio			;Highest GPIO number
Robert Sprowson's avatar
Robert Sprowson committed
963
	Pull	"r3-r10,pc"			;
964 965 966 967 968 969 970
;r0=lowest gpio
;r1=higest gpio
;r2=pointer to tables of useable pins
;preserves other registers;---------------------------------------------


	END