Skip to content
Snippets Groups Projects
main.c 748 B
Newer Older
  • Learn to ignore specific revisions
  • rahix's avatar
    rahix committed
    #include "py/runtime.h"
    #include "py/gc.h"
    #include "lib/utils/pyexec.h"
    
    #include "py/stackctrl.h"
    #include <stdio.h>
    
    rahix's avatar
    rahix committed
    
    
    #include "max32665.h"
    
    
    /* Defined in linker script */
    extern void *__StackTop, *__StackLimit;
    extern void *__HeapBase, *__HeapLimit;
    
    rahix's avatar
    rahix committed
    int main(void)
    {
    
    	if (0) {
    		mp_stack_set_top(&__StackTop);
    		mp_stack_set_limit((mp_int_t)&__StackLimit);
    	}
    
    rahix's avatar
    rahix committed
    
    
    	/* TMR5 is used to notify on keyboard interrupt */
    	NVIC_EnableIRQ(TMR5_IRQn);
    
    
    rahix's avatar
    rahix committed
    	while (1) {
    
    		gc_init(&__HeapBase, &__HeapLimit);
    
    
    		mp_init();
    		pyexec_friendly_repl();
    		mp_deinit();
    
    rahix's avatar
    rahix committed
    	}
    }
    
    void gc_collect(void)
    {
    
    	void *sp = (void *)__get_MSP();
    
    rahix's avatar
    rahix committed
    
    	gc_collect_start();
    
    rahix's avatar
    rahix committed
    	gc_collect_root(
    
    		sp,
    		((mp_uint_t)&__StackTop - (mp_uint_t)sp) / sizeof(mp_uint_t)
    
    rahix's avatar
    rahix committed
    	);
    
    rahix's avatar
    rahix committed
    	gc_collect_end();
    }