Exemple #1
0
int main(void)
{
    /** If you look here and hope to find out how this program works,
    you should look inside headerfiles for function headers to know what they do
    mainly look inside the robot_config.c and inside the struct S_robot.
    S_robot is is the core of everything
    */

    S_robot* r = &R; // global= extern S_robot R;
    INIT_clk();
    INIT_leds();

    r->STARTED = 0;
    ROBOT_initButtons(r);
    // Chose a program to run
    E_lifeStyleSelector life = ROBOT_getLifeStyle(&R);
    switch(life)
    {
        case(IAM_BUGGED_ROBOT):
            main_debug(r); break;
        case(IAM_SUMO_WARRIOR):
            main_sumo(r); break;
        case(IAM_LINE_SNIFFER):
            //main_line(r); break;
        default:
            main_debug(r);
    }

    // followin' code could not ever been executed
    INIT_leds();
	while (1) {
        gpio_toggle(PLED,LEDGREEN0|LEDORANGE1|LEDRED2|LEDBLUE3);
        mswait(500);
	}

	return 0;
}
/*!	\fn __attribute__((no_instrument_function)) void not_main(void)
 *	\brief The main, or not so main function. 
 * 
 * 	not_main is a thing i picked up from some example code online and haven't done anything with it since :S This is the entry point of the c program. 
 */
__attribute__((no_instrument_function)) void not_main(void)
{	
	/* board initialisation */
	uart_init();
	spi_pin_init();
	
	flag = 0;
	
	struct mpu60x0_stateType mpu60x0_state[NUM_FACES];
	for (int i=0; i<NUM_FACES; i++)
	{
		mpu60x0_state[i].gyro_rate = INV_MPU60x0_FSR_250DPS;
		mpu60x0_state[i].accel_rate = INV_MPU60x0_FS_02G;
		mpu60x0_state[i].filter_cutoff = INV_MPU60x0_FILTER_256HZ_NOLPF2;
	}
	
	int init_failed = 0;
	/* initialise all mpu 6000 boards */
	for (int i=0; i<NUM_FACES; i++)
	{
		if (!mpu60x0_init(shape_cs_mappings[i], &(mpu60x0_state[i])))
		{
			init_failed = 1;
			printf("MPUDev: %d failed\n", i);
		}
	}
	if (init_failed)
		return;
		
	//Configure SD Status LED for output
	gpio_function_select(16, GPIO_FUNC_OUTPUT);
	
	int mode = select_mode();
	printf("mode is: %d\n", mode);	
	
	/* interrupt pin config */
	gpio_set_interrupts();
	
	c_enable_irq();
	
	//assign function to handle gpio_irqs
	register_irq_handler ( GPIO_INT0, gpio_irq );
	register_irq_handler ( GPIO_INT1, gpio_irq );
	register_irq_handler ( GPIO_INT2, gpio_irq );
	register_irq_handler ( GPIO_INT3, gpio_irq );
	
	//enable irq handling on gpio interrupts
	enable_interrupt_for_irq(GPIO_INT0);
	enable_interrupt_for_irq(GPIO_INT1);
	enable_interrupt_for_irq(GPIO_INT2);
	enable_interrupt_for_irq(GPIO_INT3);
	
	flag = 0;
	
	unsigned int prevTs = 0;
	GPIO_OUTPUT_LEVEL prevLevel = GPIO_OUTPUT_HIGH;
	
	switch (mode)
	{
		case 0:
			main_readings(mpu60x0_state);
			return;
		case 1:
			static_calibration(mpu60x0_state);
			return;		
		case 2:
			main_debug(mpu60x0_state);
			return;
		default:
			printf("invalid mode\n");
			return;
	}
}
Exemple #3
0
int main(int argc, char *argv[])
{
	int ret = -1;

#if 1
#ifndef DEEBE_RELEASE
	FILE *try_log = fopen(LOG_FILENAME, "wt");
	if (NULL != try_log)
		fp_log = try_log;
	else
		fp_log = stdout;

	try_log = NULL;
#endif
#else
	fp_log = stdout;
#endif

	/* Signal handlers */
	signal_handle_sigio = main_sigio;
	signal_handle_sigrtmin = main_sigrtmin;
	signal_handle_sigchld = main_sigchld;

	if (0 != cmdline_init(argc, argv)) {
		/* start the watchdog timer */
		if (cmdline_watchdog_minutes > 0) {
			/* watchdog is in seconds, for *= 60 */
			long seconds = 60 * cmdline_watchdog_minutes;
			if (!watchdog_init(seconds)) {
				/*
				 * Only report this error if timer_create
				 * is supported.  If it isn't then the watchdog
				 * functionality is simulated in the network
				 * code where read or connect delays are
				 * expected.
				 */
#ifdef HAVE_TIMER_CREATE
				fprintf(stderr, "Problem initializing watchdog timer for %ld seconds\n",
					seconds);
				/*
				 * watchdog_init does not turn on the
				 * the signal unless it is successful
				 * so we do not have to disable it
				 */
#endif
			}
		}

		if (cmdline_port_fwd > 0)
			ret = main_forward();
		else
			ret = main_debug();
	}
	cmdline_cleanup();

	if (fp_log) {
		if (fp_log != stdout) {
			fflush(fp_log);
			fclose(fp_log);
			fp_log = stdout;
		}
	}
	return ret;
}