Skip to content

Commit 36be122

Browse files
committed
ports/cheriot-rtos: Addressed pr comments.
Signed-off-by: Jacob Trevor <[email protected]>
1 parent 984b8d8 commit 36be122

File tree

4 files changed

+23
-28
lines changed

4 files changed

+23
-28
lines changed

ports/cheriot-rtos/hal/i2c.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,6 @@ extern "C" bool i2c_blocking_read(volatile OpenTitanI2c *i2c, uint8_t addr, uint
1111
return i2c->blocking_read(addr, buf, len);
1212
}
1313

14-
extern "C" void i2c_blocking_write(volatile OpenTitanI2c *i2c, uint8_t addr, uint8_t *buf, uint32_t len, bool skipStop) {
15-
i2c->blocking_write(addr, buf, len, skipStop);
16-
}
17-
1814
extern "C" bool i2c_check_success(volatile OpenTitanI2c *i2c) {
1915
while (!i2c->format_is_empty()) {
2016
}
@@ -25,6 +21,13 @@ extern "C" bool i2c_check_success(volatile OpenTitanI2c *i2c) {
2521
return true;
2622
}
2723

28-
extern "C" void i2c_send_address(volatile OpenTitanI2c *i2c, uint8_t addr) {
24+
extern "C" bool i2c_blocking_write(volatile OpenTitanI2c *i2c, uint8_t addr, uint8_t *buf, uint32_t len, bool skipStop) {
25+
i2c->blocking_write(addr, buf, len, skipStop);
26+
return i2c_check_success(i2c);
27+
}
28+
29+
30+
extern "C" bool i2c_send_address(volatile OpenTitanI2c *i2c, uint8_t addr) {
2931
i2c->blocking_write_byte(OpenTitanI2c::FormatDataStart | OpenTitanI2c::FormatDataStop | (addr << 1) | 1u);
32+
return i2c_check_success(i2c);
3033
}

ports/cheriot-rtos/hal/uart.cpp

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
#include "timer.h"
44

55
extern "C" uint8_t uart_get_rx_level(volatile OpenTitanUart<115'200> *block) {
6-
return (block->fifoStatus >> 16) & 0xff;
6+
return block->receive_fifo_level();
77
}
88

99
extern "C" uint8_t uart_get_tx_level(volatile OpenTitanUart<115'200> *block) {
10-
return block->fifoStatus & 0xff;
10+
return block->transmit_fifo_level();
1111
}
1212

1313
extern "C" bool uart_is_readable(volatile OpenTitanUart<115'200> *block) {
@@ -18,7 +18,7 @@ extern "C" bool uart_is_writable(volatile OpenTitanUart<115'200> *block) {
1818
return block->can_write();
1919
}
2020

21-
extern "C" bool uart_read(volatile OpenTitanUart<115'200> *block, uint8_t *out, uint32_t timeout_ms) {
21+
extern "C" bool uart_timeout_read(volatile OpenTitanUart<115'200> *block, uint8_t *out, uint32_t timeout_ms) {
2222
uint32_t t_end = get_time() + MS_TO_CLOCK_CYCLES(timeout_ms);
2323

2424
while (!block->can_read()) {
@@ -31,10 +31,8 @@ extern "C" bool uart_read(volatile OpenTitanUart<115'200> *block, uint8_t *out,
3131
return true;
3232
}
3333

34-
extern "C" void uart_write(volatile OpenTitanUart<115'200> *block, uint8_t data) {
35-
while (!block->can_write()) {
36-
}
37-
block->wData = data;
34+
extern "C" void uart_blocking_write(volatile OpenTitanUart<115'200> *block, uint8_t data) {
35+
block->blocking_write(data);
3836
}
3937

4038
extern "C" void uart_init(volatile OpenTitanUart<115'200> *block, uint32_t baudrate) {

ports/cheriot-rtos/machine_i2c.c

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,9 @@
77
typedef struct OpenTitanI2c open_titan_i2c_t;
88

99
extern void i2c_setup(volatile open_titan_i2c_t *i2c, uint32_t freq_kHz);
10-
extern void i2c_send_address(volatile open_titan_i2c_t *i2c, uint8_t addr);
10+
extern bool i2c_send_address(volatile open_titan_i2c_t *i2c, uint8_t addr);
1111
extern bool i2c_blocking_read(volatile open_titan_i2c_t *i2c, uint8_t addr, uint8_t *buf, uint32_t len);
12-
extern void i2c_blocking_write(volatile open_titan_i2c_t *i2c, uint8_t addr, uint8_t *buf, uint32_t len, bool skipStop);
13-
14-
extern bool i2c_check_success(volatile open_titan_i2c_t *i2c);
15-
12+
extern bool i2c_blocking_write(volatile open_titan_i2c_t *i2c, uint8_t addr, uint8_t *buf, uint32_t len, bool skipStop);
1613

1714
typedef struct _machine_i2c_obj_t {
1815
mp_obj_base_t base;
@@ -22,15 +19,18 @@ typedef struct _machine_i2c_obj_t {
2219

2320
#define I2C_DEFAULT_FREQ (400000)
2421

22+
#define SPI_BLOCK_0 (0x80200000)
23+
#define SPI_BLOCK_1 (0x80201000)
24+
2525
static void machine_i2c_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
2626
machine_i2c_obj_t *self = (machine_i2c_obj_t *)MP_OBJ_TO_PTR(self_in);
2727
const char *name;
2828

29-
switch ((uint32_t)self->i2c_block) {
30-
case 2149580800:
29+
switch ((ptraddr_t)self->i2c_block) {
30+
case SPI_BLOCK_0:
3131
name = "0";
3232
break;
33-
case 2149584896:
33+
case SPI_BLOCK_1:
3434
name = "1";
3535
break;
3636
default:
@@ -100,15 +100,13 @@ static int machine_i2c_transfer_single(mp_obj_base_t *self_in, uint16_t addr, si
100100
bool success;
101101

102102
if (len == 0) {
103-
i2c_send_address(self->i2c_block, addr);
104-
success = i2c_check_success(self->i2c_block);
103+
success = i2c_send_address(self->i2c_block, addr);
105104

106105
} else if (flags & MP_MACHINE_I2C_FLAG_READ) {
107106
success = i2c_blocking_read(self->i2c_block, addr, buf, len);
108107

109108
} else {
110-
i2c_blocking_write(self->i2c_block, addr, buf, len, !stop);
111-
success = i2c_check_success(self->i2c_block);
109+
success = i2c_blocking_write(self->i2c_block, addr, buf, len, !stop);
112110
}
113111
return success ? len : -5;
114112
}

ports/cheriot-rtos/machine_uart.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,6 @@ static mp_obj_t mp_machine_uart_make_new(const mp_obj_type_t *type, size_t n_arg
126126
}
127127

128128

129-
// TODO this one too
130129
static void mp_machine_uart_deinit(machine_uart_obj_t *self) {
131130

132131
}
@@ -200,6 +199,3 @@ static mp_uint_t mp_machine_uart_ioctl(mp_obj_t self_in, mp_uint_t request, uint
200199
}
201200
return ret;
202201
}
203-
204-
205-
#define MICROPY_PY_MACHINE_UART_CLASS_CONSTANTS

0 commit comments

Comments
 (0)