Code: Select all
asm {
subroutine __ReadLSBytesJCH0
acquire __CLSWMutex0
set __CLSWArgs0.Port, 0
mov __CLSWArgs0.ReturnLen, __RLSBytesCount0
mov __CLSWArgs0.Buffer, __RLSReadBuf0
syscall 21, __CLSWArgs0
mov __RLSBResult0, __CLSWArgs0.Result
release __CLSWMutex0
brtst 4, __RLSBReturn0, __RLSBytesCount0
arrinit __RLSReadBuf0, __constVal0, __RLSBytesCount0
brtst 5, __RLSBError0, __RLSBResult0
set __RLSBIterations0, 20
__RLSBDoCheckStatus0:
acquire __CLSCSMutex0
set __CLSCSArgs0.Port, 0
syscall 23, __CLSCSArgs0
mov __RLSBytesCount0, __CLSCSArgs0.BytesReady
mov __RLSBResult0, __CLSCSArgs0.Result
release __CLSCSMutex0
sub __RLSBIterations0, __RLSBIterations0, __constVal1
brtst 2, __RLSBError0, __RLSBIterations0
brtst 0, __RLSBError0, __RLSBResult0
brtst 4, __RLSBReadyToRead0, __RLSBResult0
wait 1
jmp __RLSBDoCheckStatus0
__RLSBReadyToRead0:
acquire __CLSRMutex0
set __CLSRArgs0.Port, 0
mov __CLSRArgs0.BufferLen, __RLSBytesCount0
syscall 22, __CLSRArgs0
mov __RLSReadBuf0, __CLSRArgs0.Buffer
mov __RLSBResult0, __CLSRArgs0.Result
release __CLSRMutex0
brtst 5, __RLSBError0, __RLSBResult0
mov __RLSLastGoodRead0, __RLSReadBuf0
jmp __RLSBDone0
__RLSBError0:
mov __RLSReadBuf0, __RLSLastGoodRead0
__RLSBDone0:
arrsize __RLSBytesCount0, __RLSReadBuf0
__RLSBReturn0:
subret ____ReadLSBytes0_return
ends
subroutine __ReadLSBytesJCH1
acquire __CLSWMutex1
set __CLSWArgs1.Port, 1
mov __CLSWArgs1.ReturnLen, __RLSBytesCount1
mov __CLSWArgs1.Buffer, __RLSReadBuf1
syscall 21, __CLSWArgs1
mov __RLSBResult1, __CLSWArgs1.Result
release __CLSWMutex1
brtst 4, __RLSBReturn1, __RLSBytesCount1
arrinit __RLSReadBuf1, __constVal0, __RLSBytesCount1
brtst 5, __RLSBError1, __RLSBResult1
set __RLSBIterations1, 20
__RLSBDoCheckStatus1:
acquire __CLSCSMutex1
set __CLSCSArgs1.Port, 1
syscall 23, __CLSCSArgs1
mov __RLSBytesCount1, __CLSCSArgs1.BytesReady
mov __RLSBResult1, __CLSCSArgs1.Result
release __CLSCSMutex1
sub __RLSBIterations1, __RLSBIterations1, __constVal1
brtst 2, __RLSBError1, __RLSBIterations1
brtst 0, __RLSBError1, __RLSBResult1
brtst 4, __RLSBReadyToRead1, __RLSBResult1
wait 1
jmp __RLSBDoCheckStatus1
__RLSBReadyToRead1:
acquire __CLSRMutex1
set __CLSRArgs1.Port, 1
mov __CLSRArgs1.BufferLen, __RLSBytesCount1
syscall 22, __CLSRArgs1
mov __RLSReadBuf1, __CLSRArgs1.Buffer
mov __RLSBResult1, __CLSRArgs1.Result
release __CLSRMutex1
brtst 5, __RLSBError1, __RLSBResult1
mov __RLSLastGoodRead1, __RLSReadBuf1
jmp __RLSBDone1
__RLSBError1:
mov __RLSReadBuf1, __RLSLastGoodRead1
__RLSBDone1:
arrsize __RLSBytesCount1, __RLSReadBuf1
__RLSBReturn1:
subret ____ReadLSBytes1_return
ends
}
byte cmdBuf[] = {0x10, 0x40};
byte outbuf1[];
byte outbuf2[];
task one()
{
byte out;
unsigned long tick;
while (true)
{
int count = 1;
tick = CurrentTick();
asm {
mov __RLSReadBuf0, cmdBuf
mov __RLSBytesCount0, count
subcall __ReadLSBytesJCH0, ____ReadLSBytes0_return
mov count, __RLSBytesCount0
mov outbuf1, __RLSReadBuf0
}
// I2CBytes(S1, cmdBuf, count, outbuf1);
unsigned long ct = CurrentTick();
NumOut(0, LCD_LINE1, tick, true);
if (count > 0)
NumOut(0, LCD_LINE2, outbuf1[0]);
NumOut(0, LCD_LINE3, ct-tick);
NumOut(0, LCD_LINE4, ct);
Wait(SEC_1);
}
}
task two()
{
byte out;
unsigned long tick;
while (true)
{
int count = 1;
tick = CurrentTick();
asm {
mov __RLSReadBuf1, cmdBuf
mov __RLSBytesCount1, count
subcall __ReadLSBytesJCH1, ____ReadLSBytes1_return
mov count, __RLSBytesCount1
mov outbuf2, __RLSReadBuf1
}
// I2CBytes(S1, cmdBuf, count, outbuf1);
unsigned long ct = CurrentTick();
NumOut(0, LCD_LINE5, tick);
if (count > 0)
NumOut(0, LCD_LINE6, outbuf2[0]);
NumOut(0, LCD_LINE7, ct-tick);
NumOut(0, LCD_LINE8, ct);
Wait(SEC_1);
}
}
task main()
{
Precedes(one, two);
SetSensorLowspeed(S1);
SetSensorLowspeed(S2);
}