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 // putchar for terminal printing is too slow so we write buffers instead
errval_t // 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) { aos_rpc_serial_write(struct aos_rpc *rpc, const char *buf, size_t buf_len) {
errval_t err; errval_t err;
// split the buffer into chunks for sending // split the buffer into chunks for sending
size_t total_bytes = 0;
while(buf_len > 0) { while(buf_len > 0) {
size_t chunk_len = buf_len; size_t chunk_len = MIN(buf_len, RPC_SHARED_SIZE);
if (chunk_len > RPC_SHARED_SIZE) {
chunk_len = RPC_SHARED_SIZE;
}
memcpy(rpc->shared_mem, buf, chunk_len); memcpy(rpc->shared_mem, buf, chunk_len);
size_t written_bytes;
err = do_aos_rpc( err = do_aos_rpc(
rpc, RPC_MTYPE_SERIAL_WRITE, rpc, RPC_MTYPE_SERIAL_WRITE,
NULL_CAP, chunk_len, 0, 0, NULL_CAP, chunk_len, 0, 0,
NULL, NULL, NULL, NULL NULL, NULL, &written_bytes, NULL
); );
if (err_is_fail(err)) { 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 += chunk_len;
buf_len -= 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 errval_t