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

Commit 944d708

Browse files
committed
lorapf: add pygate_reset() to power cycle the module
this will reset the esp32 and the LTE modem on the GPy this requires PIC FW v12
1 parent 2064cbd commit 944d708

File tree

3 files changed

+44
-0
lines changed

3 files changed

+44
-0
lines changed

esp32/mods/modmachine.c

+8
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,13 @@ STATIC mp_obj_t machine_pygate_deinit (void) {
287287
}
288288
STATIC MP_DEFINE_CONST_FUN_OBJ_0(machine_pygate_deinit_obj, machine_pygate_deinit);
289289

290+
291+
STATIC mp_obj_t machine_pygate_reset (void) {
292+
pygate_reset();
293+
return mp_const_none;
294+
}
295+
STATIC MP_DEFINE_CONST_FUN_OBJ_0(machine_pygate_reset_obj, machine_pygate_reset);
296+
290297
STATIC mp_obj_t machine_pygate_debug_level (mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
291298
STATIC const mp_arg_t allowed_args[] = {
292299
{ MP_QSTR_level, MP_ARG_INT, },
@@ -622,6 +629,7 @@ STATIC const mp_rom_map_elem_t machine_module_globals_table[] = {
622629
#ifdef PYGATE_ENABLED
623630
{ MP_OBJ_NEW_QSTR(MP_QSTR_pygate_init), (mp_obj_t)&machine_pygate_init_obj },
624631
{ MP_OBJ_NEW_QSTR(MP_QSTR_pygate_deinit), (mp_obj_t)&machine_pygate_deinit_obj },
632+
{ MP_OBJ_NEW_QSTR(MP_QSTR_pygate_reset), (mp_obj_t)&machine_pygate_reset_obj },
625633
{ MP_OBJ_NEW_QSTR(MP_QSTR_pygate_debug_level), (mp_obj_t)&machine_pygate_debug_level_obj },
626634
{ MP_OBJ_NEW_QSTR(MP_QSTR_pygate_cmd_decode), (mp_obj_t)&machine_pygate_cmd_decode_obj },
627635
{ MP_OBJ_NEW_QSTR(MP_QSTR_pygate_cmd_get), (mp_obj_t)&machine_pygate_cmd_get_obj },

esp32/pygate/lora_pkt_fwd/lora_pkt_fwd.c

+35
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@ License: Revised BSD License, see LICENSE.TXT file include in the project
7171
#include "py/obj.h"
7272
#include "py/mpprint.h"
7373
#include "modmachine.h"
74+
#include "machpin.h"
75+
#include "pins.h"
76+
#include "sx1308-config.h"
7477

7578
/* -------------------------------------------------------------------------- */
7679
/* --- PRIVATE MACROS ------------------------------------------------------- */
@@ -903,6 +906,38 @@ void lora_gw_init(const char* global_conf) {
903906
MSG_INFO("lora_gw_init() done fh=%u high=%u\n", xPortGetFreeHeapSize(), uxTaskGetStackHighWaterMark(NULL));
904907
}
905908

909+
void pygate_reset() {
910+
MSG_INFO("pygate_reset\n");
911+
912+
// pull sx1257 and sx1308 reset high, the PIC FW should power cycle the ESP32 as a result
913+
pin_obj_t* sx1308_rst = SX1308_RST_PIN;
914+
pin_config(sx1308_rst, -1, -1, GPIO_MODE_OUTPUT, MACHPIN_PULL_NONE, 0);
915+
pin_obj_t* sx1257_rst = (&PIN_MODULE_P8);
916+
pin_config(sx1257_rst, -1, -1, GPIO_MODE_OUTPUT, MACHPIN_PULL_NONE, 0);
917+
918+
sx1308_rst->value = 1;
919+
sx1257_rst->value = 1;
920+
921+
pin_set_value(sx1308_rst);
922+
pin_set_value(sx1257_rst);
923+
924+
vTaskDelay(5000 / portTICK_PERIOD_MS);
925+
926+
// if this is still being executed, then it seems the ESP32 reset did not take place
927+
// set the two reset lines low again and stop the lora gw task, to make sure we return to a defined state
928+
MSG_ERROR("pygate_reset failed to reset\n");
929+
sx1308_rst->value = 0;
930+
sx1257_rst->value = 0;
931+
pin_set_value(sx1308_rst);
932+
pin_set_value(sx1257_rst);
933+
934+
if (xLoraGwTaskHndl){
935+
vTaskDelete(xLoraGwTaskHndl);
936+
xLoraGwTaskHndl = NULL;
937+
}
938+
939+
}
940+
906941
int lora_gw_get_debug_level(){
907942
return debug_level;
908943
}

esp32/pygate/lora_pkt_fwd/lora_pkt_fwd.h

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ Maintainer: Michael Coracin
2828
#include "py/mpprint.h"
2929

3030
int lora_gw_init(char *);
31+
void pygate_reset();
3132
int lora_gw_get_debug_level();
3233
void lora_gw_set_debug_level(int level);
3334

0 commit comments

Comments
 (0)