Skip to content
Snippets Groups Projects
Select Git revision
  • backslash
  • nickname-match-configs
  • master default protected
  • genofire/leds_rgb_get_state
  • genofire/rockets-state
  • genofire/ble-follow-py
  • plaetzchen/ios-workaround
  • blinkisync-as-preload
  • genofire/haule-ble-fs-deactive
  • schneider/max30001-pycardium
  • schneider/max30001-epicaridum
  • schneider/max30001
  • schneider/stream-locks
  • ios-workarounds
  • schneider/fundamental-test
  • schneider/ble-buffers
  • schneider/maxim-sdk-update
  • ch3/splashscreen
  • koalo/bhi160-works-but-dirty
  • koalo/wip/i2c-for-python
  • v1.9
  • v1.8
  • v1.7
  • v1.6
  • v1.5
  • v1.4
  • v1.3
  • v1.2
  • v1.1
  • v1.0
  • release-1
  • bootloader-v1
  • v0.0
33 results

os.c

Blame
  • Forked from card10 / firmware
    1136 commits behind the upstream repository.
    os.c 4.28 KiB
    #include "epicardium.h"
    
    #include "py/obj.h"
    #include "py/runtime.h"
    
    #include <string.h>
    
    static mp_obj_t mp_os_exit(size_t n_args, const mp_obj_t *args)
    {
    	int ret = 0;
    	if (n_args == 1) {
    		ret = mp_obj_get_int(args[0]);
    	}
    
    	epic_exit(ret);
    
    	/* unreachable */
    	return mp_const_none;
    }
    static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(exit_obj, 0, 1, mp_os_exit);
    
    static mp_obj_t mp_os_exec(mp_obj_t name_in)
    {
    	const char *name_ptr;
    	char name_str[256];
    	size_t len, maxlen;
    
    	name_ptr = mp_obj_str_get_data(name_in, &len);
    
    	/*
    	 * The string retrieved from MicroPython is not NULL-terminated so we
    	 * first need to copy it and add a NULL-byte.
    	 */
    	maxlen = len < (sizeof(name_str) - 1) ? len : (sizeof(name_str) - 1);
    	memcpy(name_str, name_ptr, maxlen);
    	name_str[maxlen] = '\0';
    
    	int ret = epic_exec(name_str);
    
    	/*
    	 * If epic_exec() returns, something went wrong.  We can raise an
    	 * exception in all cases.
    	 */
    	mp_raise_OSError(-ret);
    
    	/* unreachable */
    	return mp_const_none;
    }
    static MP_DEFINE_CONST_FUN_OBJ_1(exec_obj, mp_os_exec);
    
    static mp_obj_t mp_os_reset(void)
    {
    	epic_system_reset();
    
    	/* unreachable */
    	return mp_const_none;
    }
    static MP_DEFINE_CONST_FUN_OBJ_0(reset_obj, mp_os_reset);
    
    static mp_obj_t mp_os_listdir(mp_obj_t py_path)
    {
    	const char *path = mp_obj_str_get_str(py_path);
    	int fd           = epic_file_opendir(path);
    
    	if (fd < 0) {
    		mp_raise_OSError(-fd);
    	}
    	struct epic_stat entry;
    	mp_obj_list_t *list = mp_obj_new_list(0, NULL);
    	for (;;) {