summaryrefslogtreecommitdiff
path: root/lib/ultralib/src/host/readhost.c
blob: 9bc8d8af73377df5e857eaff7dafd0eadbe85ce4 (plain)
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
#ifndef _FINALROM

#include "PR/os_internal.h"
#include "PR/rdb.h"

#include "PRinternal/macros.h"

static int readHostInitialized = FALSE;
static OSMesgQueue readHostMesgQueue ALIGNED(0x8);
static OSMesg readHostMesgBuf[1];

u32 __osRdb_Read_Data_Buf;
u32 __osRdb_Read_Data_Ct;

void osReadHost(void* dramAddr, u32 nbytes) {
    char tstr[4];
    u32 sent = 0;

    if (!readHostInitialized) {
        osCreateMesgQueue(&readHostMesgQueue, readHostMesgBuf, ARRLEN(readHostMesgBuf));
        osSetEventMesg(OS_EVENT_RDB_READ_DONE, &readHostMesgQueue, NULL);
        readHostInitialized = TRUE;
    }

    __osRdb_Read_Data_Buf = dramAddr;
    __osRdb_Read_Data_Ct = nbytes;

    while (sent == 0) {
        sent += __osRdbSend(tstr, 1, RDB_TYPE_GtoH_READY_FOR_DATA);
    }

    osRecvMesg(&readHostMesgQueue, NULL, OS_MESG_BLOCK);
    return;
}

#endif