Skip to content
Snippets Groups Projects
Select Git revision
  • efffdade330455c23dbc93f460c509efabdc0e36
  • master default protected
  • schneider/ir
  • rahix/user-space-ctx
  • schneider/iaq-python
  • schneider/ble-mini-demo
  • schneider/ble-ecg-stream-visu
  • schneider/mp-exception-print
  • schneider/sleep-display
  • schneider/deepsleep4
  • schneider/deepsleep2
  • schneider/deepsleep
  • schneider/ble-central
  • rahix/bluetooth-app-favorite
  • schneider/v1.17-changelog
  • schneider/ancs
  • schneider/png
  • schneider/freertos-list-debug
  • schneider/212-reset-hardware-when-entering-repl
  • schneider/bonding-fail-if-full
  • schneider/ble-fixes-2020-3
  • v1.18
  • v1.17
  • v1.16
  • v1.15
  • v1.14
  • v1.13
  • v1.12
  • v1.11
  • v1.10
  • v1.9
  • v1.8
  • v1.7
  • v1.6
  • v1.5
  • v1.4
  • v1.3
  • v1.2
  • v1.1
  • v1.0
  • release-1
41 results

modules.h

Blame
  • mphalport.c 2.18 KiB
    #include <stdint.h>
    
    #include "py/lexer.h"
    #include "py/mpconfig.h"
    #include "py/mperrno.h"
    #include "py/mpstate.h"
    #include "py/obj.h"
    #include "py/runtime.h"
    
    #include "mxc_delay.h"
    #include "max32665.h"
    #include "tmr.h"
    
    #include "epicardium.h"
    
    /******************************************************************************
     * Serial Communication
     */
    
    /* Receive single character */
    int mp_hal_stdin_rx_chr(void)
    {
    	return (int)epic_uart_read_chr();
    }
    
    /* Send string of given length */
    void mp_hal_stdout_tx_strn(const char* str, mp_uint_t len)
    {
    	epic_uart_write_str(str, len);
    }
    
    bool do_interrupt = false;
    
    /* Timer Interrupt used for control char notification */
    void TMR5_IRQHandler(void)
    {
    	TMR_IntClear(MXC_TMR5);
    
    	if (do_interrupt) {
    		/* Taken from lib/micropython/micropython/lib/utils/interrupt_char.c */
    		MP_STATE_VM(mp_pending_exception) =
    			MP_OBJ_FROM_PTR(&MP_STATE_VM(mp_kbd_exception));
    #if MICROPY_ENABLE_SCHEDULER
    		if (MP_STATE_VM(sched_state) == MP_SCHED_IDLE) {
    			MP_STATE_VM(sched_state) = MP_SCHED_PENDING;
    		}
    #endif
    	}
    }
    
    void mp_hal_set_interrupt_char(char c)
    {
    	if (c != -1) {
    		mp_obj_exception_clear_traceback(
    			MP_OBJ_FROM_PTR(&MP_STATE_VM(mp_kbd_exception))
    		);
    	}
    	do_interrupt = (c == 0x03);
    }
    
    /******************************************************************************
     * Time & Delay
     */
    
    void mp_hal_delay_ms(mp_uint_t ms)
    {
    	mxc_delay(ms * 1000);
    }
    
    void mp_hal_delay_us(mp_uint_t us)
    {
    	mxc_delay(us);
    }
    
    /******************************************************************************
     * Fatal Errors
     */
    
    extern NORETURN void * Reset_Handler (void);
    
    void NORETURN nlr_jump_fail(void* val)
    {
    	char msg[] = " >>> nlr_jump_fail <<<\r\n";
    	epic_uart_write_str(msg, sizeof(msg));
    
    	Reset_Handler();
    }
    
    /******************************************************************************
     * Stubs
     */
    
    mp_lexer_t* mp_lexer_new_from_file(const char* filename)
    {
    	/* TODO: Do we need an implementation for this? */
    	mp_raise_OSError(MP_ENOENT);
    }
    
    mp_obj_t mp_builtin_open(size_t n_args, const mp_obj_t* args, mp_map_t* kwargs)
    {
    	/* TODO: Once fs is implemented, get this working as well */
    	return mp_const_none;
    }
    MP_DEFINE_CONST_FUN_OBJ_KW(mp_builtin_open_obj, 1, mp_builtin_open);