summaryrefslogtreecommitdiff
path: root/src/os/osEepromLongWrite.c
blob: ff89a5c3a41bea3a74f74f96f6af7625e3a57cb9 (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
#include "libultra_internal.h"
#include "controller.h"

extern u8 D_80365D20;
extern OSTimer D_80196548;
extern OSMesgQueue _osContMesgQueue;
extern OSMesg _osContMesgBuff[4];

// exactly the same as osEepromLongRead except for osEepromWrite call
s32 osEepromLongWrite(OSMesgQueue* mq, u8 address, u8* buffer, s32 nbytes) {
    s32 result = 0;
    if (address > 0x40) {
        return -1;
    }

    while (nbytes > 0) {
        result = osEepromWrite(mq, address, buffer);
        if (result != 0) {
            return result;
        }

        nbytes -= EEPROM_BLOCK_SIZE;
        address++;
        buffer += EEPROM_BLOCK_SIZE;
        osSetTimer(&D_80196548, 12000 * osClockRate / 1000000, 0, &_osContMesgQueue, _osContMesgBuff);
        osRecvMesg(&_osContMesgQueue, NULL, OS_MESG_BLOCK);
    }

    return result;
}