cartdma.c 2 KB
#include <PR/bcp.h>
#include <PR/bbsim.h>

#include <PR/os.h>

#define PRINTF		osSyncPrintf

/*
 * Thread and stack structures
 */
#define IDLE_STACKSIZE 4096
char   idleStack[IDLE_STACKSIZE] __attribute__ ((aligned (8)));

static OSThread idleThread;
static char     idleThreadStack[IDLE_STACKSIZE] __attribute__ ((aligned (8)));

static void	idleproc(char *);

extern void *_ftext;

const u32 dmaTestData[] = {
        0x00010203,
        0x04050607,
        0x08090a0b,
        0x0c0d0e0f,
        0x10111213,
        0x14151617,
        0x18191a1b,
        0x1c1d1e1f
};

void boot()
{
    osInitialize();
    osCreateThread(&idleThread, 1, (void(*)(void *))idleproc, (void *)0,
                   idleThreadStack+IDLE_STACKSIZE, 8);
    osStartThread(&idleThread);
}

void idleproc(char *argv)
{
    int i;
    u32 val;

    PRINTF("Entered idle thread...\n");

    PRINTF("dmaTestData[0] = %08x\n",((u32 *)K0_TO_K1(&dmaTestData))[0]);

    val = (u32)((u32)(&dmaTestData) - (u32)(&_ftext));
    PRINTF("Offset = %08x\n",val);

    PRINTF("DRAM address: %08x\n",PHYS_TO_K1(0x100000));

    for(i=0;i<sizeof(dmaTestData);i+=4){
        *(u32 *)PHYS_TO_K1(0x100000+i) = i;
    }

    for(i=0;i<sizeof(dmaTestData);i+=4){
        PRINTF("%08x\n",*(u32 *)PHYS_TO_K1(0x100000+i));
    }


    IO_WRITE(PI_STATUS_REG,0);
    PRINTF("PI_STATUS_REG = %08x\n",IO_READ(PI_STATUS_REG));

    /* try a dma */
    IO_WRITE(PI_DRAM_ADDR_REG, 0x100000);
    IO_WRITE(PI_CART_ADDR_REG, PI_DOM1_ADDR2 + val);
    IO_WRITE(PI_WR_LEN_REG, sizeof(dmaTestData)-1);
    while(IO_READ(PI_STATUS_REG) & (PI_STATUS_IO_BUSY | PI_STATUS_DMA_BUSY)) {
        if (IO_READ(PI_STATUS_REG) & PI_STATUS_ERROR){
            PRINTF("DMA Failed!!!\n");
            break;
        }
    }
    
    for(i=0;i<sizeof(dmaTestData);i+=4){
        PRINTF("%08x\n",*(u32 *)PHYS_TO_K1(0x100000+i));
    }

 exit:
    PRINTF("\nAPP FINISHED\n");
    /* power off (cannot do this since not in secure mode) */
    IO_WRITE(PI_GPIO_REG, 0|(1 << PI_GPIO_ENABLE_SHIFT));
    while(1){}
}