mp_flipper_runtime.c 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. #include <string.h>
  2. #include "py/compile.h"
  3. #include "py/runtime.h"
  4. #include "py/persistentcode.h"
  5. #include "py/gc.h"
  6. #include "py/stackctrl.h"
  7. #include "shared/runtime/gchelper.h"
  8. #include "mp_flipper_runtime.h"
  9. #include "mp_flipper_halport.h"
  10. const char* mp_flipper_root_module_path;
  11. void* mp_flipper_context;
  12. void mp_flipper_set_root_module_path(const char* path) {
  13. mp_flipper_root_module_path = path;
  14. }
  15. void mp_flipper_init(void* heap, size_t heap_size, size_t stack_size, void* stack_top) {
  16. mp_flipper_context = mp_flipper_context_alloc();
  17. mp_stack_set_top(stack_top);
  18. mp_stack_set_limit(stack_size);
  19. #if MICROPY_ENABLE_GC
  20. gc_init(heap, (uint8_t*)heap + heap_size);
  21. #endif
  22. mp_init();
  23. }
  24. void mp_flipper_deinit() {
  25. mp_deinit();
  26. mp_flipper_context_free(mp_flipper_context);
  27. }
  28. // Called if an exception is raised outside all C exception-catching handlers.
  29. void nlr_jump_fail(void* val) {
  30. mp_flipper_nlr_jump_fail(val);
  31. }
  32. #if MICROPY_ENABLE_GC
  33. // Run a garbage collection cycle.
  34. void gc_collect(void) {
  35. gc_collect_start();
  36. gc_helper_collect_regs_and_stack();
  37. gc_collect_end();
  38. }
  39. #endif
  40. #ifndef NDEBUG
  41. // Used when debugging is enabled.
  42. void __assert_func(const char* file, int line, const char* func, const char* expr) {
  43. mp_flipper_assert(file, line, func, expr);
  44. }
  45. void NORETURN __fatal_error(const char* msg) {
  46. mp_flipper_fatal_error(msg);
  47. }
  48. #endif
  49. void mp_flipper_raise_os_error(int error) {
  50. mp_raise_OSError(error);
  51. }
  52. void mp_flipper_raise_os_error_with_filename(int error, const char* filename) {
  53. mp_raise_OSError_with_filename(error, filename);
  54. }