mirror of
https://github.com/Telecominfraproject/OpenCellular.git
synced 2026-01-14 16:46:23 +00:00
stm32: i2c: Simplify host_send_response()
Simplify this code, so that it does only one pass of the response data, calculating the checksum as it copies. BUG=chrome-os-partner:10535 TEST=manual: build for all boards build and boot on daisy see that keyboard still works Change-Id: I8b0a2ce1632dd4c1ff54736fb636d9a5cf8c9214 Signed-off-by: Simon Glass <sjg@chromium.org> Reviewed-on: https://gerrit.chromium.org/gerrit/25981
This commit is contained in:
@@ -121,36 +121,23 @@ static int i2c_write_raw(int port, void *buf, int len)
|
||||
return len;
|
||||
}
|
||||
|
||||
static void _send_result(int slot, enum ec_status result, int size)
|
||||
{
|
||||
int i;
|
||||
int len = 1;
|
||||
uint8_t sum = 0;
|
||||
|
||||
ASSERT(slot == 0);
|
||||
/* record the error code */
|
||||
host_buffer[0] = result;
|
||||
if (size) {
|
||||
/* compute checksum */
|
||||
for (i = 1; i <= size; i++)
|
||||
sum += host_buffer[i];
|
||||
host_buffer[size + 1] = sum;
|
||||
len = size + 2;
|
||||
}
|
||||
|
||||
/* send the answer to the AP */
|
||||
i2c_write_raw(I2C2, host_buffer, len);
|
||||
}
|
||||
|
||||
void host_send_response(int slot, enum ec_status result, const uint8_t *data,
|
||||
int size)
|
||||
{
|
||||
uint8_t *out = host_get_buffer(slot);
|
||||
uint8_t *out = host_buffer;
|
||||
int sum, i;
|
||||
|
||||
if (size > 0 && data != out)
|
||||
memcpy(out, data, size);
|
||||
ASSERT(slot == 0);
|
||||
*out++ = result;
|
||||
for (i = 0, sum = 0; i < size; i++, data++, out++) {
|
||||
if (data != out)
|
||||
*out = *data;
|
||||
sum += *data;
|
||||
}
|
||||
*out++ = sum & 0xff;
|
||||
|
||||
_send_result(slot, result, size);
|
||||
/* send the answer to the AP */
|
||||
i2c_write_raw(I2C2, host_buffer, out - host_buffer);
|
||||
}
|
||||
|
||||
uint8_t *host_get_buffer(int slot)
|
||||
|
||||
Reference in New Issue
Block a user