summaryrefslogtreecommitdiff
path: root/lib/ultralib/src/os/syncputchars.c
blob: d2d53328aa785352b3e099e12017b400437a9502 (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
#include "PR/os_internal.h"
#include "PR/rdb.h"
#include "PR/rcp.h"
#include "PR/R4300.h"

unsigned int __osRdbSendMessage = 0;
unsigned int __osRdbWriteOK = 1;

void __osSyncPutChars(int type, int length, const char* buf) {
    rdbPacket packet;
    int i;
    u32 mask;

    packet.type = type;
    packet.length = length;

    for (i = 0; i < length; i++) {
        packet.buf[i] = buf[i];
    }

    while (!__osAtomicDec(&__osRdbWriteOK)) {
        ;
    }

    mask = __osDisableInt();
    *(vu32*)RDB_BASE_REG = *(vu32*)&packet;

    while (!(__osGetCause() & CAUSE_IP6)) {
        ;
    }

    *(vu32*)RDB_READ_INTR_REG = 0;
    __osRdbWriteOK++;
    __osRestoreInt(mask);
}