⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 io.asm

📁 Hardware and firmware for a DSP based digital audio MP3 player with USB pen drive funtionality, usin
💻 ASM
字号:
;/*
; * DSPdap-flash - DSP based Digital Audio Player, EEPROM flasher
; * Copyright (C) 2004-2007 Roger Quadros <rogerquads @ yahoo . com>
; * http://dspdap.sourceforge.net
; *
; * This program is free software; you can redistribute it and/or modify
; * it under the terms of the GNU General Public License as published by
; * the Free Software Foundation; either version 2 of the License, or
; * (at your option) any later version.
; *
; * This program is distributed in the hope that it will be useful,
; * but WITHOUT ANY WARRANTY; without even the implied warranty of
; * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
; * GNU General Public License for more details.
; *
; * You should have received a copy of the GNU General Public License
; * along with this program; if not, write to the Free Software
; * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
; *
; * $Id: IO.asm,v 1.2 2007/06/03 08:54:03 Roger Exp $
; */

	.mmregs
	.ref	_CF_CheckDrqStatus
	
	.global	_LED_on		;export LED_on function
	.global	_LED_off	;export LED_off function
	.global _write_mem
	.global _read_mem
	.global _config_EMIF
	.global _get_AGPIO
	.global _read_sector	

	.text

IODIR	.set 3400h		;IODIR register address
IODATA	.set 3401h		;IODATA register address
EBSR	.set 6C00h		;EBSR reg. address
AGPIOEN .set 4400h
AGPIODIR .set 4401h
AGPIODATA .set 4402h
EGCR	.set 0800h
EMI_RST .set 0801h
CE0_1	.set 0803h
CE0_2	.set 0804h
CE0_3	.set 0805h

;----------------------------------------------------------------------
;Prototype:		void LED_on(void)
;Description:	Turns ON led by making port GPIO4 high
;----------------------------------------------------------------------
_LED_on:	
	or	#0010h, port(#IODATA)	;set only GPIO4
	ret
	
;----------------------------------------------------------------------
;Prototype:		void LED_off(void)
;Description:	Turns OFF led by making port GPIO4 low
;----------------------------------------------------------------------
_LED_off:	
	and	#~(0010h), port(#IODATA)	;reset only GPIO4
	ret
	
	
;----------------------------------------------------------------------
;Prototype:		void write_ex(long mem_addr, int data)
;Description:	writes the 16-bit word in data into the external memory
;				loacation whose address is specified in mem_ptr
;----------------------------------------------------------------------

_write_mem:
	;1st arg(32-bit) is in AC0  and 2nd arg is in T0
	
	mov XAR0, AC1	;save upper 7 bits of XAR0
		
	mov AC0, XAR0	;move 23-bits of AC0 into XAR0
	mov T0, *AR0	;move T0 contents into memory pointed by AR0
	
	mov AC1, XAR0	;recover upper 7 bits of XAR0
	ret

;----------------------------------------------------------------------
;Prototype:		int read_ex(long mem_addr)
;Description:	reads the 16-bit word from the external memory
;				loacation whose address is specified in mem_ptr
;				and returns the read word.
;----------------------------------------------------------------------

_read_mem:
	;1st arg(32-bit) is in AC0
	mov XAR0, AC1	;save upper 7 bits of XAR0
	
	mov AC0, XAR0	;move 23-bits of AC0 into XAR0
	mov *AR0, T0	;move contents of memory pointed by AR0 into T0
	
	mov AC1, XAR0	;recover upper 7 bits of XAR0
	ret

;----------------------------------------------------------------------
;Prototype:		int read_sector(long mem_addr, unsigned int *buffer)
;Description:	reads 256 words from external memory
;				loacation whose address is specified in mem_addr
;				into the data buffer.
;Returns: 0 for success, 1 for error (DRQ was not set)
;----------------------------------------------------------------------

_read_sector:
	;int read_sector(long mem_addr, unsigned int *buffer)
	
	;1st arg(32-bit) is in AC0  and 2nd arg (data pointer) is in XAR0
	
	pshboth	AC0		;save arguments as they are in registers that may be modified by called function
	pshboth XAR0	;
	call _CF_CheckDrqStatus		;DRQ status is returned in T0
	popboth XAR0	;recover arguments
	popboth AC0		;

	.newblock	;forget earlier lables
	
	;now if DRQ == 1 means CF is ready for data else
	;if DRQ == 0 then flag error and return.
	bcc $1,T0 == #1
	mov #1, T0	;return value = 1
	ret			;exit

$1	;DRQ == 1 so read data

	mov XAR1, AC1	;save upper 7 bits of XAR1
		
	mov AC0, XAR1	;move 23-bits of AC0 into XAR1
	
	;now source pointer is in XAR1 and destination pointer is XAR0

	rpt #255		;repeat next instruction 256 times
	mov *AR1, *AR0+

	nop
	mov AC1, XAR1	;recover upper 7 bits of XAR1
	xor T0, T0	;clear T0.. return value = 0
	ret			;exit
	
;----------------------------------------------------------------------
;Prototype:		void config_EMIF()
;Description:	configures the EMIF in DATA EMIF mode and sets
;				A0-A2 and A12, A13 as address pins and other 
;				pins A3-A11 as GPIO pins
;----------------------------------------------------------------------

_config_EMIF:

;	mov	#1200h, port(#EBSR)	;set bits 1,0 to 0 for DATA EMIF mode
	mov	#1201h, port(#EBSR)	;set bits 1,0 to 0 for Full EMIF mode
	nop
	nop
	mov #0h, port(#AGPIOEN) ;configure A0-A2,A12,A13 for address and others for GPIO
	nop
	nop
	mov #0h, port(#AGPIODIR)	;configure all GPIO pins as i/p
	nop
	nop
	mov #0h,	port(#AGPIODATA)
	nop
	nop
	
		;configure CE0 space memory type and read/write timings
	mov #0020h, port(#EGCR)
	nop
	nop
	mov #1014h, port(#CE0_1)
	nop
	nop
	mov #0014h, port(#CE0_2)
	nop
	nop
	mov #0h,	port(#CE0_3)
	nop
	nop

	ret
		


;----------------------------------------------------------------------
;Prototype:		int get_AGPIO()
;Description:	returns the AGPIODATA register contents
;----------------------------------------------------------------------	

_get_AGPIO:

	mov port(#AGPIODATA), T0	;return value is in T0
	ret
	

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -