Fix kernel bug in INIT_LX_SIZE

https://moodle-app2.let.ethz.ch/mod/forum/discuss.php?d=100480
This commit is contained in:
Sparchatus 2022-03-31 12:52:00 +00:00
parent 84d16648d8
commit 16f26e8aa0

View File

@ -126,34 +126,78 @@ aos_rpc_serial_putchar(struct aos_rpc *rpc, char c) {
);
}
// putchar for terminal printing is too slow so we send buffers instead
errval_t
// putchar for terminal printing is too slow so we write buffers instead
// the corresponding interface does not know about errors, just partial writes
size_t
aos_rpc_serial_write(struct aos_rpc *rpc, const char *buf, size_t buf_len) {
errval_t err;
// split the buffer into chunks for sending
size_t total_bytes = 0;
while(buf_len > 0) {
size_t chunk_len = buf_len;
if (chunk_len > RPC_SHARED_SIZE) {
chunk_len = RPC_SHARED_SIZE;
}
size_t chunk_len = MIN(buf_len, RPC_SHARED_SIZE);
memcpy(rpc->shared_mem, buf, chunk_len);
size_t written_bytes;
err = do_aos_rpc(
rpc, RPC_MTYPE_SERIAL_WRITE,
NULL_CAP, chunk_len, 0, 0,
NULL, NULL, NULL, NULL
NULL, NULL, &written_bytes, NULL
);
if (err_is_fail(err)) {
return err;
return total_bytes;
}
total_bytes += written_bytes;
// if the receiver was not able to write all we have given, return for now
if (written_bytes < chunk_len) {
return total_bytes;
}
buf += chunk_len;
buf_len -= chunk_len;
}
return SYS_ERR_OK;
return total_bytes;
}
// getchar for terminal reading is too slow so we read buffers instead
// the corresponding interface does not know about errors, just partial reads
size_t
aos_rpc_serial_read(struct aos_rpc *rpc, const char *buf, size_t buf_len) {
errval_t err;
// split the buffer into chunks for reading
size_t total_bytes = 0;
while(buf_len > 0) {
size_t chunk_len = MIN(buf_len, RPC_SHARED_SIZE);
memcpy(rpc->shared_mem, buf, chunk_len);
size_t written_bytes;
err = do_aos_rpc(
rpc, RPC_MTYPE_SERIAL_WRITE,
NULL_CAP, chunk_len, 0, 0,
NULL, NULL, &written_bytes, NULL
);
if (err_is_fail(err)) {
return total_bytes;
}
total_bytes += written_bytes;
// if the receiver was not able to write all we have given, return for now
if (written_bytes < chunk_len) {
return total_bytes;
}
buf += chunk_len;
buf_len -= chunk_len;
}
return total_bytes;
}
errval_t