int main(int argc,char* argv[]) { posix_parse_command_line(argc, argv); // Read the lib and app infusion archives from file di_app_archive = posix_load_infusion_archive(posix_app_infusion_filename); // initialise memory manager void *mem = malloc(HEAPSIZE); ref_t_base_address = (char*)mem - 42; core_init(mem, HEAPSIZE); dj_exec_setRunlevel(RUNLEVEL_RUNNING); wkpf_picokong(di_app_archive); return 0; }
int main() { // Declared in djarchive.c so that the reprogramming code can find it. di_app_archive = (dj_di_pointer)di_app_infusion_archive_data; // initialise serial port avr_serialInit(115200); core_init(mem, HEAPSIZE); dj_exec_setRunlevel(RUNLEVEL_RUNNING); wkpf_picokong((dj_di_pointer)di_app_infusion_archive_data); // Listen to the radio while(true) dj_hook_call(dj_core_pollingHook, NULL); return 0; }
/** * Main function that creates the vm and runs until either all threads stop or runlevel is set to RUNLEVEL_REBOOT * This code was in the main() of each config before, but has been extracted to make rebooting easier. */ void dj_vm_main(void *mem, uint32_t memsize, dj_di_pointer di_lib_infusions_archive_data, dj_di_pointer di_app_infusion_archive_data, dj_named_native_handler handlers[], uint8_t handlers_length) { dj_vm *vm; dj_object * obj; // initialise timer dj_timer_init(); // initialise memory managerw dj_mem_init(mem, memsize); // create a new VM vm = dj_vm_create(); // tell the execution engine to use the newly created VM instance dj_exec_setVM(vm); // set run level before loading libraries since they need to execute initialisation code dj_exec_setRunlevel(RUNLEVEL_RUNNING); dj_vm_loadInfusionArchive(vm, di_lib_infusions_archive_data, handlers, handlers_length); dj_di_pointer di_app_infusion_data = dj_archive_get_file(di_app_infusion_archive_data, 0); dj_vm_loadInfusion(vm, di_app_infusion_data, NULL, 0); // pre-allocate an OutOfMemoryError object obj = dj_vm_createSysLibObject(vm, BASE_CDEF_java_lang_OutOfMemoryError); dj_mem_setPanicExceptionObject(obj); DEBUG_LOG(true, "Darjeeling is go!\n\r"); // start the main execution loop while (dj_vm_countLiveThreads(vm)>0) { dj_vm_schedule(vm); if (vm->currentThread!=NULL) if (vm->currentThread->status==THREADSTATUS_RUNNING) dj_exec_run(RUNSIZE); } DEBUG_LOG(true, "All threads terminated.\n\r"); }
void dj_panic(int32_t panictype) { switch(panictype) { case DJ_PANIC_OUT_OF_MEMORY: DEBUG_LOG(true, "PANIC: out of memory!\n"); break; case DJ_PANIC_ILLEGAL_INTERNAL_STATE: DEBUG_LOG(true, "PANIC: illegal internal state!\n"); break; case DJ_PANIC_UNIMPLEMENTED_FEATURE: DEBUG_LOG(true, "PANIC: unimplemented feature!\n"); break; case DJ_PANIC_UNCAUGHT_EXCEPTION: DEBUG_LOG(true, "PANIC: uncaught exception!\n"); break; case DJ_PANIC_UNSATISFIED_LINK: DEBUG_LOG(true, "PANIC: unsatisfied link!\n"); break; case DJ_PANIC_MALFORMED_INFUSION: DEBUG_LOG(true, "PANIC: malformed infusion!\n"); break; case DJ_PANIC_ASSERTION_FAILURE: DEBUG_LOG(true, "PANIC: assertion failed!\n"); break; case DJ_PANIC_SAFE_POINTER_OVERFLOW: DEBUG_LOG(true, "PANIC: safe pointer overflow!\n"); break; default: DEBUG_LOG(true, "PANIC: unknown panic type %d!\n", panictype); break; } if (dj_exec_getRunlevel() < RUNLEVEL_PANIC) { dj_exec_setRunlevel(panictype); while (true) // Still allow remote access through wkcomm when in panic state. dj_hook_call(dj_core_pollingHook, NULL); } else { exit(panictype); // To avoid getting into a recursive panic. } }