fix remainSize type

This commit is contained in:
jiangzhengwenjz
2020-04-28 07:27:54 +08:00
parent 2010ed0f12
commit c7d8d5dae2
2 changed files with 24 additions and 27 deletions
+1 -2
View File
@@ -371,8 +371,7 @@ struct NIComm
u16 state; // Communication state of slot u16 state; // Communication state of slot
u16 failCounter; // Count of failed transmissions/receptions (Count is increased when transmission/reception of data does not succeed within 1PF=16.7 ms) u16 failCounter; // Count of failed transmissions/receptions (Count is increased when transmission/reception of data does not succeed within 1PF=16.7 ms)
const u8 *now_p[WINDOW_COUNT]; // Address of current send/receive (The data is divided into WINDOW_COUNT blocks and sent in payloadSize units.) const u8 *now_p[WINDOW_COUNT]; // Address of current send/receive (The data is divided into WINDOW_COUNT blocks and sent in payloadSize units.)
// remainSize is u32 in SDK. This is a hack to match ASM u32 remainSize; // Size of remaining communication data
s32 remainSize; // Size of remaining communication data
u16 errorCode; // Error code u16 errorCode; // Error code
u8 bmSlot; // Expresses the current communication slot in bits u8 bmSlot; // Expresses the current communication slot in bits
// (When sending from the Master, because multiple slaves can be specified with bmSlot, communications are terminated based on the failCounter for each child device) // (When sending from the Master, because multiple slaves can be specified with bmSlot, communications are terminated based on the failCounter for each child device)
+23 -25
View File
@@ -1,3 +1,4 @@
#include <limits.h>
#include "librfu.h" #include "librfu.h"
struct LLSFStruct struct LLSFStruct
@@ -1797,7 +1798,7 @@ static u16 rfu_STC_NI_constructLLSF(u8 bm_slot_id, u8 **dest_pp, struct NIComm *
} }
else else
{ {
if ((u32)NI_comm->remainSize >= NI_comm->payloadSize) if (NI_comm->remainSize >= NI_comm->payloadSize)
size = NI_comm->payloadSize; size = NI_comm->payloadSize;
else else
size = NI_comm->remainSize; size = NI_comm->remainSize;
@@ -2092,34 +2093,31 @@ static void rfu_STC_NI_receive_Sender(u8 NI_slot, u8 bm_flag, const struct RfuLo
else else
NI_comm->now_p[llsf_NI->phase] += NI_comm->payloadSize << 2; NI_comm->now_p[llsf_NI->phase] += NI_comm->payloadSize << 2;
NI_comm->remainSize -= NI_comm->payloadSize; NI_comm->remainSize -= NI_comm->payloadSize;
if (NI_comm->remainSize != 0) switch (NI_comm->remainSize)
if (NI_comm->remainSize >= 0) {
goto _081E30AE; default:
// Above is a hack to avoid optimization over comparison. case 0:
// rfu_STC_NI_constructLLSF uses this field as u32. NI_comm->phase = 0;
// It's equivalent to the following condition: if (NI_comm->state == SLOT_STATE_SEND_START)
// if (NI_comm->remainSize == 0 || NI_comm->remainSize < 0)
{ {
NI_comm->phase = 0; for (i = 0; i < WINDOW_COUNT; ++i)
if (NI_comm->state == SLOT_STATE_SEND_START)
{ {
for (i = 0; i < WINDOW_COUNT; ++i) NI_comm->n[i] = 1;
{ NI_comm->now_p[i] = NI_comm->src + NI_comm->payloadSize * i;
NI_comm->n[i] = 1;
NI_comm->now_p[i] = NI_comm->src + NI_comm->payloadSize * i;
}
NI_comm->remainSize = NI_comm->dataSize;
NI_comm->state = SLOT_STATE_SENDING;
}
else
{
NI_comm->n[0] = 0;
NI_comm->remainSize = 0;
NI_comm->state = SLOT_STATE_SEND_LAST;
} }
NI_comm->remainSize = NI_comm->dataSize;
NI_comm->state = SLOT_STATE_SENDING;
} }
_081E30AE: else
; {
NI_comm->n[0] = 0;
NI_comm->remainSize = 0;
NI_comm->state = SLOT_STATE_SEND_LAST;
}
break;
case 1 ... INT_MAX:
break;
}
} }
else if (NI_comm->state == SLOT_STATE_SEND_LAST) else if (NI_comm->state == SLOT_STATE_SEND_LAST)
{ {