Skip to content
This repository was archived by the owner on Sep 16, 2024. It is now read-only.

Commit 7b83c6d

Browse files
author
Islam Wahdan
authored
Merge pull request #276 from pycom/rc8_update
2 parents 48ba355 + 8dc29d1 commit 7b83c6d

File tree

7 files changed

+489
-122
lines changed

7 files changed

+489
-122
lines changed

esp32/frozen/LTE/sqnsupgrade.py

Lines changed: 98 additions & 34 deletions
Large diffs are not rendered by default.

esp32/mods/machuart.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@
7171
#define UART_TRIGGER_RX_FULL (0x04)
7272
#define UART_TRIGGER_TX_DONE (0x08)
7373

74+
#define MACH_UART_CHECK_INIT(self) \
75+
if(!(self->init)) {nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_OSError, "UART not Initialized!"));}
76+
7477
/******************************************************************************
7578
DECLARE PRIVATE FUNCTIONS
7679
******************************************************************************/
@@ -89,6 +92,7 @@ struct _mach_uart_obj_t {
8992
uint8_t uart_id;
9093
uint8_t rx_timeout;
9194
uint8_t n_pins;
95+
bool init;
9296
};
9397

9498
/******************************************************************************
@@ -265,6 +269,7 @@ STATIC bool uart_rx_wait (mach_uart_obj_t *self) {
265269

266270
STATIC void mach_uart_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
267271
mach_uart_obj_t *self = self_in;
272+
MACH_UART_CHECK_INIT(self)
268273
if (self->config.baud_rate > 0) {
269274
mp_printf(print, "UART(%u, baudrate=%u, bits=", self->uart_id, self->config.baud_rate);
270275
switch (self->config.data_bits) {
@@ -430,6 +435,9 @@ STATIC mp_obj_t mach_uart_init_helper(mach_uart_obj_t *self, const mp_arg_val_t
430435
// configure the rx timeout threshold
431436
self->uart_reg->conf1.rx_tout_thrhd = self->rx_timeout & UART_RX_TOUT_THRHD_V;
432437

438+
// Init Done
439+
self->init = true;
440+
433441
return mp_const_none;
434442

435443
error:
@@ -494,25 +502,30 @@ STATIC mp_obj_t mach_uart_deinit(mp_obj_t self_in) {
494502
uart_driver_delete(self->uart_id);
495503
}
496504

505+
self->init = false;
506+
497507
return mp_const_none;
498508
}
499509
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mach_uart_deinit_obj, mach_uart_deinit);
500510

501511
STATIC mp_obj_t mach_uart_any(mp_obj_t self_in) {
502512
mach_uart_obj_t *self = self_in;
513+
MACH_UART_CHECK_INIT(self)
503514
return mp_obj_new_int(uart_rx_any(self));
504515
}
505516
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mach_uart_any_obj, mach_uart_any);
506517

507518
STATIC mp_obj_t mach_uart_wait_tx_done(mp_obj_t self_in, mp_obj_t timeout_ms) {
508519
mach_uart_obj_t *self = self_in;
520+
MACH_UART_CHECK_INIT(self)
509521
TickType_t timeout_ticks = mp_obj_get_int_truncated(timeout_ms) / portTICK_PERIOD_MS;
510522
return uart_wait_tx_done(self->uart_id, timeout_ticks) == ESP_OK ? mp_const_true : mp_const_false;
511523
}
512524
STATIC MP_DEFINE_CONST_FUN_OBJ_2(mach_uart_wait_tx_done_obj, mach_uart_wait_tx_done);
513525

514526
STATIC mp_obj_t mach_uart_sendbreak(mp_obj_t self_in, mp_obj_t bits) {
515527
mach_uart_obj_t *self = self_in;
528+
MACH_UART_CHECK_INIT(self)
516529
pin_obj_t * pin = (pin_obj_t *)((mp_obj_t *)self->pins)[0];
517530

518531
uint32_t isrmask = MICROPY_BEGIN_ATOMIC_SECTION();
@@ -571,6 +584,7 @@ STATIC MP_DEFINE_CONST_DICT(mach_uart_locals_dict, mach_uart_locals_dict_table);
571584

572585
STATIC mp_uint_t mach_uart_read(mp_obj_t self_in, void *buf_in, mp_uint_t size, int *errcode) {
573586
mach_uart_obj_t *self = self_in;
587+
MACH_UART_CHECK_INIT(self)
574588
byte *buf = buf_in;
575589

576590
// make sure we want at least 1 char
@@ -598,6 +612,7 @@ STATIC mp_uint_t mach_uart_read(mp_obj_t self_in, void *buf_in, mp_uint_t size,
598612

599613
STATIC mp_uint_t mach_uart_write(mp_obj_t self_in, const void *buf_in, mp_uint_t size, int *errcode) {
600614
mach_uart_obj_t *self = self_in;
615+
MACH_UART_CHECK_INIT(self)
601616
const char *buf = buf_in;
602617

603618
// write the data
@@ -609,6 +624,7 @@ STATIC mp_uint_t mach_uart_write(mp_obj_t self_in, const void *buf_in, mp_uint_t
609624

610625
STATIC mp_uint_t mach_uart_ioctl(mp_obj_t self_in, mp_uint_t request, mp_uint_t arg, int *errcode) {
611626
mach_uart_obj_t *self = self_in;
627+
MACH_UART_CHECK_INIT(self)
612628
mp_uint_t ret;
613629

614630
if (request == MP_STREAM_POLL) {

esp32/mods/modlora.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2359,7 +2359,7 @@ static int lora_socket_socket (mod_network_socket_obj_t *s, int *_errno) {
23592359
#ifdef LORA_OPENTHREAD_ENABLED
23602360
// if mesh is enabled, assume socket is for mesh, not for LoraWAN
23612361
if (lora_mesh_ready()) {
2362-
return mesh_socket_open(_errno);
2362+
return mesh_socket_open(s, _errno);
23632363
}
23642364
#endif // #ifdef LORA_OPENTHREAD_ENABLED
23652365

@@ -2387,7 +2387,7 @@ static int lora_socket_socket (mod_network_socket_obj_t *s, int *_errno) {
23872387
static void lora_socket_close (mod_network_socket_obj_t *s) {
23882388
s->sock_base.u.sd = -1;
23892389
#ifdef LORA_OPENTHREAD_ENABLED
2390-
mesh_socket_close();
2390+
mesh_socket_close(s);
23912391
#endif // #ifdef LORA_OPENTHREAD_ENABLED
23922392
}
23932393

@@ -2457,7 +2457,7 @@ static int lora_socket_recvfrom (mod_network_socket_obj_t *s, byte *buf, mp_uint
24572457

24582458
#ifdef LORA_OPENTHREAD_ENABLED
24592459
if (lora_mesh_ready()) {
2460-
return mesh_socket_recvfrom(buf, len, ip, port, _errno);
2460+
return mesh_socket_recvfrom(s, buf, len, ip, port, _errno);
24612461
}
24622462
#endif // #ifdef LORA_OPENTHREAD_ENABLED
24632463

@@ -2523,7 +2523,7 @@ static int lora_socket_bind(mod_network_socket_obj_t *s, byte *ip, mp_uint_t por
25232523

25242524
#ifdef LORA_OPENTHREAD_ENABLED
25252525
if (lora_mesh_ready()) {
2526-
return mesh_socket_bind(ip, port, _errno);
2526+
return mesh_socket_bind(s, ip, port, _errno);
25272527
}
25282528
#endif // #ifdef LORA_OPENTHREAD_ENABLED
25292529

@@ -2567,7 +2567,7 @@ static int lora_socket_sendto(struct _mod_network_socket_obj_t *s, const byte *b
25672567

25682568
#ifdef LORA_OPENTHREAD_ENABLED
25692569
if (lora_mesh_ready()) {
2570-
return mesh_socket_sendto(buf, len, ip, port, _errno);
2570+
return mesh_socket_sendto(s, buf, len, ip, port, _errno);
25712571
}
25722572
#endif // #ifdef LORA_OPENTHREAD_ENABLED
25732573

0 commit comments

Comments
 (0)