📄 dram.c
字号:
/* dram.c Copyright (C) Christian Wolff for convergence integrated media. 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., 675 Mass Ave, Cambridge, MA 02139, USA.*/ ///////////////////////////////// // // // L64021 DRAM Memory Access // // ///////////////////////////////////#define __NO_VERSION__#include "dram.h"#include "l64021.h"#define EMERGENCYCOUNTER 5 // where: 21 bit DRAM Word-Address, 4 word aligned // size: bytes (8 byte aligned, remainder will be filled with fill value) // data: fill value// returns 0 on success, -1 on collision with DMA transferint DRAMFillByte(struct cvdv_cards *card, u32 where, int size, u8 data){ int i, j, k, n; u8 volatile flag; size = (size >> 3) + ((size & 7) ? 1 : 0); // 8 bytes at a time, padding with garbage where >>= 2; // 8 byte aligned data DecoderSetByte(card, 0x0C1, 0x08);//TODO: 0x80? DecoderWriteByte(card, 0x0C6, (u8) ((where >> 16) & 0x00000007L)); DecoderWriteByte(card, 0x0C5, (u8) ((where >> 8) & 0x000000FFL)); DecoderWriteByte(card, 0x0C4, (u8) (where & 0x000000FFL)); i = 0; for (j = 0; j < size; j++) { for (k = 0; k < 8; k++) { n = EMERGENCYCOUNTER; do { // wait if FIFO full flag = DecoderReadByte(card, 0x0C0); } while ((flag & 0x08) && n--); if (n<0) return -1; DecoderWriteByte(card, 0x0C3, data); } } flag = DecoderReadByte(card, 0x0C0); n = EMERGENCYCOUNTER; do { // wait for FIFO empty flag = DecoderReadByte(card, 0x0C0); } while (!(flag & 0x04) && n--); return ((n>=0) ? 0 : -1);} // where: 21 bit DRAM Word-Address, 8 byte aligned // size: bytes (8 byte aligned, remainder will be filled with garbage) // swap: 0=normal mode, 1=write each 8 bytes on reverse order (7,6,5,4,3,2,1,0,15,14,13,etc.)// returns 0 on success, -1 on collision with DMA transferint DRAMWriteByte(struct cvdv_cards *card, u32 where, int size, u8 * data, int swapburst){ int i, j, k, n; u8 volatile flag; size = (size >> 3) + ((size & 7) ? 1 : 0); // 8 bytes at a time, padding with garbage where >>= 2; // 8 byte aligned data MDEBUG(4, ": Moving %d 64-bit-words to DRAM 0x%08X\n",size,where); //if (swap) DecoderDelByte(card,0x0C1,0x08); // byte swapping of 8 byte bursts //else DecoderSetByte(card,0x0C1,0x08); // no byte swapping DecoderSetByte(card, 0x0C1, 0x08); // no byte swapping DecoderWriteByte(card, 0x0C6, (u8) ((where >> 16) & 0x00000007L)); DecoderWriteByte(card, 0x0C5, (u8) ((where >> 8) & 0x000000FFL)); DecoderWriteByte(card, 0x0C4, (u8) (where & 0x000000FFL)); i = 0; if (swapburst) { for (j = 0; j < size; j++) { for (k = 7; k >= 0; k--) { n = EMERGENCYCOUNTER; do { // wait if FIFO full flag = DecoderReadByte(card, 0x0C0); } while ((flag & 0x08) && n--); if (n<0) return -1; DecoderWriteByte(card, 0x0C3, data[i + k]); } i += 8; } } else { for (j = 0; j < size; j++) { for (k = 0; k < 8; k++) { n = EMERGENCYCOUNTER; do { // wait if FIFO full flag = DecoderReadByte(card, 0x0C0); } while ((flag & 0x08) && n--); if (n<0) return -1; DecoderWriteByte(card, 0x0C3, data[i++]); } } } flag = DecoderReadByte(card, 0x0C0); n = EMERGENCYCOUNTER; do { // wait for FIFO empty flag = DecoderReadByte(card, 0x0C0); } while (!(flag & 0x04) && n--); return ((n>=0) ? 0 : -1);} // where: 21 bit DRAM Word-Address, 4 word aligned // size: words (4 word aligned, remainder will be filled with garbage) // swap: 0=normal mode, 1=write each 8 bytes on reverse order (7,6,5,4,3,2,1,0,15,14,13,etc.)// returns 0 on success, -1 on collision with DMA transferint DRAMWriteWord(struct cvdv_cards *card, u32 where, int size, u16 * data, int swap){ int i, j, k, n; u8 volatile flag; size = (size >> 2) + ((size & 3) ? 1 : 0); // 4 words at a time, padding with garbage where >>= 2; // 8 byte aligned data MDEBUG(4, ": Moving %d 64-bit-words to DRAM 0x%08X\n",size,where);//TODO: swap manually if (swap) DecoderDelByte(card, 0x0C1, 0x08); // byte swapping of 8 byte bursts else DecoderSetByte(card, 0x0C1, 0x08); // no byte swapping DecoderWriteByte(card, 0x0C6, (u8) ((where >> 16) & 0x00000007L)); DecoderWriteByte(card, 0x0C5, (u8) ((where >> 8) & 0x000000FFL)); DecoderWriteByte(card, 0x0C4, (u8) (where & 0x000000FFL)); i = 0; for (j = 0; j < size; j++) { for (k = 0; k < 4; k++) { n = EMERGENCYCOUNTER; do { // wait if FIFO full flag = DecoderReadByte(card, 0x0C0); } while ((flag & 0x08) && n--); if (n<0) return -1; DecoderWriteByte(card, 0x0C3, data[i] >> 8); n = EMERGENCYCOUNTER; do { // wait if FIFO full flag = DecoderReadByte(card, 0x0C0); } while ((flag & 0x08) && n--); if (n<0) return -1; DecoderWriteByte(card, 0x0C3, data[i++]); } } flag = DecoderReadByte(card, 0x0C0); n = EMERGENCYCOUNTER; do { // wait for FIFO empty flag = DecoderReadByte(card, 0x0C0); } while (!(flag & 0x04) && n--); return ((n>=0) ? 0 : -1);} // where: 21 bit DRAM Word-Address, 8 byte aligned // size: bytes // swap: 0=normal mode, 1=write each 8 bytes on reverse order (7,6,5,4,3,2,1,0,15,14,13,etc.)// returns 0 on success, -1 on collision with DMA transferint DRAMReadByte(struct cvdv_cards *card, u32 where, int size, u8 * data, int swap){ int i, j, rsize, n; u8 volatile flag; rsize = size & 7; // padding bytes size = size >> 3; // 8 bytes at a time where >>= 2; // 8 byte aligned data MDEBUG(4, ": Moving %d 64-bit-words to DRAM 0x%08X\n",size,where);//TODO: swap manually if (swap) DecoderDelByte(card, 0x0C1, 0x08); // byte swapping of 8 byte bursts else DecoderSetByte(card, 0x0C1, 0x08); // no byte swapping DecoderWriteByte(card, 0x0C9, (u8) ((where >> 16) & 0x00000007L)); DecoderWriteByte(card, 0x0C8, (u8) ((where >> 8) & 0x000000FFL)); DecoderWriteByte(card, 0x0C7, (u8) (where & 0x000000FFL)); i = 0; for (j = 0; j < size; j++) { n = EMERGENCYCOUNTER; do { // wait if FIFO empty flag = DecoderReadByte(card, 0x0C0); } while ((flag & 0x01) && n--); if (n<0) // WARNING nicht if(!n) return -1; data[i++] = DecoderReadByte(card, 0x0C2); data[i++] = DecoderReadByte(card, 0x0C2); data[i++] = DecoderReadByte(card, 0x0C2); data[i++] = DecoderReadByte(card, 0x0C2); data[i++] = DecoderReadByte(card, 0x0C2); data[i++] = DecoderReadByte(card, 0x0C2); data[i++] = DecoderReadByte(card, 0x0C2); data[i++] = DecoderReadByte(card, 0x0C2); } n = EMERGENCYCOUNTER; do { // wait if FIFO empty flag = DecoderReadByte(card, 0x0C0); } while ((flag & 0x01) && n--); if (n<0) return -1; for (j = 0; j < rsize; j++) data[i++] = DecoderReadByte(card, 0x0C2); flag = DecoderReadByte(card, 0x0C0); n = EMERGENCYCOUNTER; do { // wait for FIFO full flag = DecoderReadByte(card, 0x0C0); } while (!(flag & 0x02) && n--); return ((n>=0) ? 0 : -1);} // where: 21 bit DRAM Word-Address, 4 word aligned // size: words // swap: 0=normal mode, 1=write each 8 bytes on reverse order (7,6,5,4,3,2,1,0,15,14,13,etc.)// returns 0 on success, -1 on collision with DMA transferint DRAMReadWord(struct cvdv_cards *card, u32 where, int size, u16 * data, int swap){ int i, j, rsize, n; u8 volatile flag; u8 b; rsize = size & 3; // padding words size >>= 2; // 4 words at a time where >>= 2; // 8 byte aligned data MDEBUG(4, ": Reading %d 64-bit-words and %d 16-bit-words from DRAM 0x%08X\n", size,rsize,where);//TODO: swap manually if (swap) DecoderDelByte(card, 0x0C1, 0x08); // byte swapping of 8 byte bursts else DecoderSetByte(card, 0x0C1, 0x08); // no byte swapping
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -