Fork me on GitHub

Device-level API

C API Reference mgos_hal.h

#include "mgos_hal.h"

See on GitHub: mgos_hal.h

These interfaces need to be implemented for each hardware platform.


size_t mgos_get_heap_size(void);

Get system memory size.

size_t mgos_get_free_heap_size(void);

Get system free memory.

size_t mgos_get_min_free_heap_size(void);

Get minimal watermark of the system free memory.

size_t mgos_get_fs_memory_usage(void);

Get filesystem memory usage

size_t mgos_get_fs_size(void);

Get filesystem size.

size_t mgos_get_free_fs_size(void);

Get filesystem free space.

void mgos_fs_gc(void);

void mgos_wdt_feed(void);

Feed watchdog

void mgos_wdt_set_timeout(int secs);

Set watchdog timeout

void mgos_wdt_enable(void);

Enable watchdog

void mgos_wdt_disable(void);

Disable watchdog

void mgos_system_restart(int exit_code);

Restart system

void mgos_msleep(uint32_t secs);

Delay routines

void mgos_usleep(uint32_t usecs);

extern void (*mgos_nsleep100)(uint32_t n);

void mgos_ints_disable(void);

void mgos_ints_enable(void);

typedef void (*mgos_cb_t)(void *arg);

Invoke a callback in the main MGOS event loop. Returns true if the callback has been scheduled for execution.

bool mgos_invoke_cb(mgos_cb_t cb, void *arg, bool from_isr);

void mgos_lock(void);

void mgos_unlock(void);

struct mgos_rlock_type *mgos_new_rlock(void);

void mgos_rlock(struct mgos_rlock_type *l);

void mgos_runlock(struct mgos_rlock_type *l);

uint32_t mgos_get_cpu_freq(void);

Get the CPU frequency in Hz

JAVASCRIPT API Reference api_sys.js

load("api_sys.js");


Sys.calloc(nmemb, size)

Allocate a memory region. Note: currently memory allocated this way must be explicitly released with free().

Sys.total_ram()

Return total available RAM in bytes.

Sys.free_ram()

Return free available RAM in bytes.

Sys.reboot(us)

Reboot the system after us microseconds. Return value: none.

Sys.uptime()

Return number of seconds since last reboot.

Sys.usleep(microseconds)

Sleep given number of microseconds. Return value: none.

Sys.wdt_feed()

Feed the watchdog timer. Return value: none.