mp_flipper_runtime.c 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. gc_init(heap, (uint8_t*)heap + heap_size);
  20. mp_init();
  21. }
  22. void mp_flipper_deinit() {
  23. mp_deinit();
  24. mp_flipper_context_free(mp_flipper_context);
  25. }
  26. // Called if an exception is raised outside all C exception-catching handlers.
  27. void nlr_jump_fail(void* val) {
  28. mp_flipper_nlr_jump_fail(val);
  29. }
  30. #if MICROPY_ENABLE_GC
  31. // Run a garbage collection cycle.
  32. void gc_collect(void) {
  33. gc_collect_start();
  34. gc_helper_collect_regs_and_stack();
  35. gc_collect_end();
  36. }
  37. #endif
  38. #ifndef NDEBUG
  39. // Used when debugging is enabled.
  40. void __assert_func(const char* file, int line, const char* func, const char* expr) {
  41. mp_flipper_assert(file, line, func, expr);
  42. }
  43. void NORETURN __fatal_error(const char* msg) {
  44. mp_flipper_fatal_error(msg);
  45. }
  46. #endif
  47. void mp_flipper_raise_os_error(int error) {
  48. mp_raise_OSError(error);
  49. }
  50. void mp_flipper_raise_os_error_with_filename(int error, const char* filename) {
  51. mp_raise_OSError_with_filename(error, filename);
  52. }