Esempio n. 1
0
int main(int argc, char *argv[]) {
	uint8_t buf[1024];
	size_t n;
#ifdef FRSKY
	frsky_state_t fs;
#endif
	telemetry_data_t td;
	telemetry_init(&td);

	render_init();

	long long prev_time = current_timestamp();
	while(1) {
		FD_ZERO(&set);
		FD_SET(STDIN_FILENO, &set);
		timeout.tv_sec = 0;
		//read 100ms
		timeout.tv_usec = 100*1000;
		n = select(STDIN_FILENO + 1, &set, NULL, NULL, &timeout);
		//printf("%d\n",n);
		if(n > 0) {
			n = read(STDIN_FILENO, buf, sizeof(buf));

			if(n == 0) {
			//	break; //EOF
			}

			if(n<0) {
				perror("read");
				exit(-1);
			}
#ifdef FRSKY
			frsky_parse_buffer(&fs, &td, buf, n);
#elif defined(LTM)
			ltm_read(&td, buf, n);
#elif defined(MAVLINK)
			mavlink_read(&td, buf, n);
#endif
		}

	#ifdef DEBUG
		prev_time = current_timestamp();
		render(&td);
		long long took = current_timestamp() - prev_time;
		printf("Render took %lldms to execute.\n", took);
	#else
		render(&td);
	#endif

	}

	return 0;
}
Esempio n. 2
0
int main(void) {
    // leds:
    led_init();

    // init clock sources:
    clocksource_init();

    // init ios
    io_init();

    // init debug
    debug_init();

    // init wdt timer
    wdt_init();

    // enable timeout routines
    timeout_init();

    // init storage
    storage_init();

    // init frsky core
    frsky_init();

    // init adc
    adc_init();

    // init output
#ifdef SBUS_ENABLED
    sbus_init();
#else  // SBUS_ENABLED
    ppm_init();
#endif  // SBUS_ENABLED

    // init failsafe
    failsafe_init();

    // init telemetry
    telemetry_init();

    // run main
    debug("main: init done\n");

    // frsky_frame_sniffer();
    frsky_main();

    debug("main: frsky main ended?! THIS SHOULD NOT HAPPEN!");
    while (1) {}
}
Esempio n. 3
0
int main(void) {
    // Set the system clock to the full 120MHz
    uint32_t sysClkFreq = SysCtlClockFreqSet(SYSCTL_XTAL_25MHZ | SYSCTL_OSC_MAIN | SYSCTL_USE_PLL | SYSCTL_CFG_VCO_480, 120000000);


    debug_init(sysClkFreq);
    status_led_init();
    network_driver_init(sysClkFreq);
    networking_init();
    telemetry_init();
    transducer_init();
    thermocouple_init();
    solenoid_init();

    debug_print("Initialization complete. starting main loop.\r\n");

    // Set up the SysTick timer and its interrupts
    SysTickPeriodSet(6000); // 40 kHz
    SysTickIntRegister(sys_tick);
    SysTickIntEnable();
    SysTickEnable();

    uint32_t loopIterations = 0;
    uint32_t frame_start = systick_clock;



    while(1) {
        status_led_periodic();
        network_driver_periodic();
        telemetry_periodic();
        solenoid_periodic();

        //	debug_print_u32(systick_clock);

        //count loop iterations per second
        loopIterations++;
        if(systick_clock - frame_start >= 1000) {
            loops_per_second = loopIterations;
            loopIterations = 0;
            frame_start = systick_clock;
        }

    }
}
Esempio n. 4
0
    // Create temp dir
    char template[] = "/tmp/tmpdir.XXXXXX";
    char *tmp_dirname = mkdtemp(template);
    assert(tmp_dirname);

    char testpath[30];
    strcpy(testpath, tmp_dirname);
    strcat(testpath, "/path/to/dir");
    char mvpath[33];
    strcpy(mvpath, tmp_dirname);
    strcat(mvpath, "/path/to/mv_dir");
    char touchpath[38];
    strcpy(touchpath, mvpath);
    strcat(touchpath, "/test");

    Telemetry telemetry = telemetry_init(&host);

    Directory dir = directory_new(&host, &testpath);
    assert(!directory_exists(&dir, &host));

    DirectoryOpts opts = { .do_recursive = true };

    directory_create(&dir, &host, &opts);
    assert(directory_exists(&dir, &host));
    char create_check_cmd[33];
    strcpy(create_check_cmd, "ls ");
    strcat(create_check_cmd, testpath);
    int create_check = system(create_check_cmd);
    assert(create_check != -1 && WEXITSTATUS(create_check) == 0);

    directory_mv(&dir, &host, &);
Esempio n. 5
0
void
kernel_bootstrap(void)
{
	kern_return_t	result;
	thread_t	thread;
	char		namep[16];

	printf("%s\n", version); /* log kernel version */

#define kernel_bootstrap_kprintf(x...) /* kprintf("kernel_bootstrap: " x) */

	if (PE_parse_boot_argn("-l", namep, sizeof (namep))) /* leaks logging */
		turn_on_log_leaks = 1;

	PE_parse_boot_argn("trace", &new_nkdbufs, sizeof (new_nkdbufs));

	PE_parse_boot_argn("trace_wake", &wake_nkdbufs, sizeof (wake_nkdbufs));

	/* i386_vm_init already checks for this ; do it aagin anyway */
        if (PE_parse_boot_argn("serverperfmode", &serverperfmode, sizeof (serverperfmode))) {
                serverperfmode = 1;
        }
	scale_setup();

	kernel_bootstrap_kprintf("calling vm_mem_bootstrap\n");
	vm_mem_bootstrap();

	kernel_bootstrap_kprintf("calling cs_init\n");
	cs_init();

	kernel_bootstrap_kprintf("calling vm_mem_init\n");
	vm_mem_init();

	machine_info.memory_size = (uint32_t)mem_size;
	machine_info.max_mem = max_mem;
	machine_info.major_version = version_major;
	machine_info.minor_version = version_minor;

#if CONFIG_TELEMETRY
	kernel_bootstrap_kprintf("calling telemetry_init\n");
	telemetry_init();
#endif

	kernel_bootstrap_kprintf("calling stackshot_lock_init\n");	
	stackshot_lock_init();

	kernel_bootstrap_kprintf("calling sched_init\n");
	sched_init();

	kernel_bootstrap_kprintf("calling wait_queue_bootstrap\n");
	wait_queue_bootstrap();

	kernel_bootstrap_kprintf("calling ipc_bootstrap\n");
	ipc_bootstrap();

#if CONFIG_MACF
	mac_policy_init();
#endif
	kernel_bootstrap_kprintf("calling ipc_init\n");
	ipc_init();

	/*
	 * As soon as the virtual memory system is up, we record
	 * that this CPU is using the kernel pmap.
	 */
	kernel_bootstrap_kprintf("calling PMAP_ACTIVATE_KERNEL\n");
	PMAP_ACTIVATE_KERNEL(master_cpu);

	kernel_bootstrap_kprintf("calling mapping_free_prime\n");
	mapping_free_prime();						/* Load up with temporary mapping blocks */

	kernel_bootstrap_kprintf("calling machine_init\n");
	machine_init();

	kernel_bootstrap_kprintf("calling clock_init\n");
	clock_init();

	ledger_init();

	/*
	 *	Initialize the IPC, task, and thread subsystems.
	 */
	kernel_bootstrap_kprintf("calling task_init\n");
	task_init();

	kernel_bootstrap_kprintf("calling thread_init\n");
	thread_init();
	
	/*
	 *	Create a kernel thread to execute the kernel bootstrap.
	 */
	kernel_bootstrap_kprintf("calling kernel_thread_create\n");
	result = kernel_thread_create((thread_continue_t)kernel_bootstrap_thread, NULL, MAXPRI_KERNEL, &thread);

	if (result != KERN_SUCCESS) panic("kernel_bootstrap: result = %08X\n", result);

	thread->state = TH_RUN;
	thread_deallocate(thread);

	kernel_bootstrap_kprintf("calling load_context - done\n");
	load_context(thread);
	/*NOTREACHED*/
}
Esempio n. 6
0
void
kernel_bootstrap(void)
{
	kern_return_t	result;
	thread_t	thread;
	char		namep[16];

	printf("%s\n", version); /* log kernel version */

	if (PE_parse_boot_argn("-l", namep, sizeof (namep))) /* leaks logging */
		turn_on_log_leaks = 1;

	PE_parse_boot_argn("trace", &new_nkdbufs, sizeof (new_nkdbufs));
	PE_parse_boot_argn("trace_wake", &wake_nkdbufs, sizeof (wake_nkdbufs));
	PE_parse_boot_argn("trace_panic", &write_trace_on_panic, sizeof(write_trace_on_panic));
	PE_parse_boot_argn("trace_typefilter", &trace_typefilter, sizeof(trace_typefilter));

	scale_setup();

	kernel_bootstrap_log("vm_mem_bootstrap");
	vm_mem_bootstrap();

	kernel_bootstrap_log("cs_init");
	cs_init();

	kernel_bootstrap_log("vm_mem_init");
	vm_mem_init();

	machine_info.memory_size = (uint32_t)mem_size;
	machine_info.max_mem = max_mem;
	machine_info.major_version = version_major;
	machine_info.minor_version = version_minor;


#if CONFIG_TELEMETRY
	kernel_bootstrap_log("telemetry_init");
	telemetry_init();
#endif

#if CONFIG_CSR
	kernel_bootstrap_log("csr_init");
	csr_init();
#endif

	kernel_bootstrap_log("stackshot_lock_init");	
	stackshot_lock_init();

	kernel_bootstrap_log("sched_init");
	sched_init();

	kernel_bootstrap_log("waitq_bootstrap");
	waitq_bootstrap();

	kernel_bootstrap_log("ipc_bootstrap");
	ipc_bootstrap();

#if CONFIG_MACF
	kernel_bootstrap_log("mac_policy_init");
	mac_policy_init();
#endif

	kernel_bootstrap_log("ipc_init");
	ipc_init();

	/*
	 * As soon as the virtual memory system is up, we record
	 * that this CPU is using the kernel pmap.
	 */
	kernel_bootstrap_log("PMAP_ACTIVATE_KERNEL");
	PMAP_ACTIVATE_KERNEL(master_cpu);

	kernel_bootstrap_log("mapping_free_prime");
	mapping_free_prime();						/* Load up with temporary mapping blocks */

	kernel_bootstrap_log("machine_init");
	machine_init();

	kernel_bootstrap_log("clock_init");
	clock_init();

	ledger_init();

	/*
	 *	Initialize the IPC, task, and thread subsystems.
	 */
#if CONFIG_COALITIONS
	kernel_bootstrap_log("coalitions_init");
	coalitions_init();
#endif

	kernel_bootstrap_log("task_init");
	task_init();

	kernel_bootstrap_log("thread_init");
	thread_init();

#if CONFIG_ATM
	/* Initialize the Activity Trace Resource Manager. */
	kernel_bootstrap_log("atm_init");
	atm_init();
#endif

#if CONFIG_BANK
	/* Initialize the BANK Manager. */
	kernel_bootstrap_log("bank_init");
	bank_init();
#endif
	
	/* initialize the corpse config based on boot-args */
	corpses_init();

	/*
	 *	Create a kernel thread to execute the kernel bootstrap.
	 */
	kernel_bootstrap_log("kernel_thread_create");
	result = kernel_thread_create((thread_continue_t)kernel_bootstrap_thread, NULL, MAXPRI_KERNEL, &thread);

	if (result != KERN_SUCCESS) panic("kernel_bootstrap: result = %08X\n", result);

	thread->state = TH_RUN;
	thread->last_made_runnable_time = mach_absolute_time();
	thread_deallocate(thread);

	kernel_bootstrap_log("load_context - done");
	load_context(thread);
	/*NOTREACHED*/
}