modmachine.c 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /*
  2. * This file is part of the MicroPython project, http://micropython.org/
  3. *
  4. * The MIT License (MIT)
  5. *
  6. * Copyright (c) 2013-2015 Damien P. George
  7. * Copyright (c) 2016 Paul Sokolovsky
  8. * Copyright (c) 2016 Linaro Limited
  9. *
  10. * Permission is hereby granted, free of charge, to any person obtaining a copy
  11. * of this software and associated documentation files (the "Software"), to deal
  12. * in the Software without restriction, including without limitation the rights
  13. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  14. * copies of the Software, and to permit persons to whom the Software is
  15. * furnished to do so, subject to the following conditions:
  16. *
  17. * The above copyright notice and this permission notice shall be included in
  18. * all copies or substantial portions of the Software.
  19. *
  20. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  21. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  22. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  23. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  24. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  25. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  26. * THE SOFTWARE.
  27. */
  28. #include <stdint.h>
  29. #include <stdio.h>
  30. #include <misc/reboot.h>
  31. #include "py/obj.h"
  32. #include "py/runtime.h"
  33. #include "extmod/machine_mem.h"
  34. #include "extmod/machine_signal.h"
  35. #include "extmod/machine_pulse.h"
  36. #include "extmod/machine_i2c.h"
  37. #include "modmachine.h"
  38. #if MICROPY_PY_MACHINE
  39. STATIC mp_obj_t machine_reset(void) {
  40. sys_reboot(SYS_REBOOT_COLD);
  41. // Won't get here, Zephyr has infiniloop on its side
  42. return mp_const_none;
  43. }
  44. STATIC MP_DEFINE_CONST_FUN_OBJ_0(machine_reset_obj, machine_reset);
  45. STATIC mp_obj_t machine_reset_cause(void) {
  46. printf("Warning: %s is not implemented\n", __func__);
  47. return MP_OBJ_NEW_SMALL_INT(42);
  48. }
  49. STATIC MP_DEFINE_CONST_FUN_OBJ_0(machine_reset_cause_obj, machine_reset_cause);
  50. STATIC const mp_rom_map_elem_t machine_module_globals_table[] = {
  51. { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_umachine) },
  52. #ifdef CONFIG_REBOOT
  53. { MP_ROM_QSTR(MP_QSTR_reset), MP_ROM_PTR(&machine_reset_obj) },
  54. #endif
  55. { MP_ROM_QSTR(MP_QSTR_reset_cause), MP_ROM_PTR(&machine_reset_cause_obj) },
  56. { MP_ROM_QSTR(MP_QSTR_Pin), MP_ROM_PTR(&machine_pin_type) },
  57. { MP_ROM_QSTR(MP_QSTR_Signal), MP_ROM_PTR(&machine_signal_type) },
  58. // reset causes
  59. /*{ MP_ROM_QSTR(MP_QSTR_PWRON_RESET), MP_ROM_INT(REASON_DEFAULT_RST) },*/
  60. };
  61. STATIC MP_DEFINE_CONST_DICT(machine_module_globals, machine_module_globals_table);
  62. const mp_obj_module_t mp_module_machine = {
  63. .base = { &mp_type_module },
  64. .globals = (mp_obj_dict_t*)&machine_module_globals,
  65. };
  66. #endif // MICROPY_PY_MACHINE