Example #1
0
int
main (void)
{
	/* Initialize GPIO (sets up clock) */
	GPIOInit ();

	/* Set LED port pin to output */
	GPIOSetDir (LED_PORT, LED_BIT, 1);
	GPIOSetValue (LED_PORT, LED_BIT, LED_OFF);

	/* Init Power Management Routines */
	pmu_init ();

	/* UART setup */
	UARTInit (115200, 0);

	/* CDC USB Initialization */
	init_usbserial ();

	/* Init RFID */
	rfid_init ();

	/* Init emulation triggers */
	trigger_init ();

	/* RUN RFID loop */
	loop_rfid ();

	return 0;
}
Example #2
0
static void notify_issue (gpointer data)
{
        log_debug("trigger watch destroyed\n!");
	/* clean up & restart trigger */
	trigger_stop();
	trigger_init();
}
Example #3
0
// Init everything in isr.
void isr_init() {
  adcBufferInit();  // init the local adcBuffer.
	trigger_init();
	transmitter_init();
	hitLedTimer_init();
	lockoutTimer_init();
}
Example #4
0
int main(int argc, char **argv)//内核发生热插拔时会执行一次/proc/sys/kernel/hotplug。
{///sbin/mdev > /proc/sys/kernel/hotplug,本质上内核发生一次热插拔时执行一次/sbin/mdev
	int ch;
	char *dbglvl = getenv("DBGLVL");

	if (dbglvl) {
		debug = atoi(dbglvl);
		unsetenv("DBGLVL");
	}

	while ((ch = getopt(argc, argv, "d:s:h:")) != -1) {
		switch (ch) {
		case 'h':
			return hotplug_run(optarg);//执行hotplug_run(/etc/hotplug-preinit.json):
		case 's':
			ubus_socket = optarg;
			break;
		case 'd':
			debug = atoi(optarg);
			break;
		default:
			return usage(argv[0]);
		}
	}
	uloop_init();
	procd_signal();
	trigger_init();
	if (getpid() != 1)
		procd_connect_ubus();
	else
		procd_state_next();//进程pid=1才执行procd_state_next,这才是开机启动流程中的procd,负责解析/etc/inittab文件并据此依次启动系统。
	uloop_run();

	return 0;
}
Example #5
0
void *
thread_trigger(void *c_handle)
{
	struct radclock_handle *handle;
	int err;

	JDEBUG

	/* Deal with UNIX signal catching */
	init_thread_signal_mgt();
	
	/* Clock handle to be able to read global data */
	handle = (struct radclock_handle *) c_handle;

	/* Initialise the trigger thread.
	 * If this fails, we commit a collective suicide
	 */
	err = trigger_init(handle);
	if (err)
		handle->pthread_flag_stop = PTH_STOP_ALL;
	
	while ((handle->pthread_flag_stop & PTH_TRIGGER_STOP) != PTH_TRIGGER_STOP) {

		/*
		 * Check if processing thread did grab the lock, we don't want to lock
		 * repeatidly for ever. If we marked data ready to be processed, then
		 * the processing thread has to do his job. We signal again in case the
		 * processing thread hadn't be listening before (at startup for
		 * example), then we sleep a little and probably get rescheduled.
		 */
		if (handle->wakeup_data_ready == 1 && !VM_SLAVE(handle)) {
			pthread_cond_signal(&handle->wakeup_cond);
			usleep(50);
			continue;
		}

		/* Lock the pthread_mutex we share with the processing thread */
		pthread_mutex_lock(&handle->wakeup_mutex);

		/* Do our job */
		trigger_work(handle);

		/* Raise wakeup_dat_ready flag.
		 * Signal the processing thread, and unlock mutex to give the processing
		 * thread a chance at it. To be sure it grabs the lock we sleep for a
		 * little while ...
		 */
		handle->wakeup_data_ready = 1;
		pthread_cond_signal(&handle->wakeup_cond);
		pthread_mutex_unlock(&handle->wakeup_mutex);
	}

	/* Thread exit
	 * In case we pass into the continue statement but then ordered to die, make
	 * sure we release the lock (and maybe silently fail)
	 */
	verbose(LOG_NOTICE, "Thread trigger is terminating.");	
	pthread_exit(NULL);
}
Example #6
0
int camera_on(){
    if(!w_init())error("bcm2835 missing");
    sphere_init(stepper_init(RHO_SLEEP,RHO_STEP,RHO_DIR,RHO_M0,RHO_M1,RHO_MODE,RHO_STEPS,"ρ"),
                stepper_init(THETA_SLEEP,THETA_STEP,THETA_DIR,THETA_M0,THETA_M1,THETA_MODE,THETA_STEPS,"θ"),
                stepper_init(PHI_SLEEP,PHI_STEP,PHI_DIR,PHI_M0,PHI_M1,PHI_MODE,PHI_STEPS,"φ"),
                "ο");
    trigger_init("μ");
    camera_init("δ");
}
Example #7
0
void _init_func(void)
{
	trigger_init();
	rc632_init();
	rc632_test(NULL);
	DEBUGP("opening reader ");
#if 1
	rh = rfid_reader_open(NULL, RFID_READER_OPENPCD);
	DEBUGP("rh=%p ", rh);
#endif
	led_switch(2, 1);
}
Example #8
0
int triggers_load(Trigger triggers[], Logger * loggers[]){
    char fname[] = "XX.jso";

    for (int i=0; i < TRIGGERS; i++) {
        sprintf(fname, "%i.jso", i);
        aJsonObject * cfile = file_read("/triggers", fname);
        if (cfile != NULL) {
            trigger_load(i, cfile, loggers);
            aJson.deleteItem(cfile);
        } else {
            trigger_init(i);
        }
    }
    return TRIGGERS;
}
Example #9
0
int main()
{
	// Setup
	led_init();
	trigger_init();
	uart_init();
	comm_init();
	aes128_init(key, &ctx);

	// Globally enable interrupts
	sei();

	// Tell the cardreader we're there
	protocol_send_ATR();

	// Cardreader comm loop
	for(;;)
	{
		protocol_challenge_response();
	}
}
Example #10
0
void trigger_load(int idx, aJsonObject *msg, Logger * loggers[]){
    //Init new trigger from aJSON
    //extract the ajson from ajson using
    //aJsonObject* msg = aJson.getObjectItem(root, "trigger");
    if (idx != NONE && triggers[idx].output != NONE) {
        Serial.print(F("Clean up trigger "));
        Serial.println(idx, DEC);
        trigger_set_default_state(idx);
    }
    trigger_init(idx);

    aJsonObject * cnfobj = aJson.getObjectItem(msg, "t_since");
    if (cnfobj && cnfobj->type == aJson_Int) {
        triggers[idx].t_since = cnfobj->valueint;
    }

    cnfobj = aJson.getObjectItem(msg, "t_until");
    if (cnfobj && cnfobj->type == aJson_Int) {
        triggers[idx].t_until = cnfobj->valueint;
    }

    cnfobj = aJson.getObjectItem(msg, "active");
    if (cnfobj && cnfobj->type == aJson_Int) {
        triggers[idx].active = cnfobj->valueint;
    }

    cnfobj = aJson.getObjectItem(msg, "on_value");
    if (cnfobj) {
        if (cnfobj->type == aJson_Int) {
            triggers[idx].on_value = cnfobj->valueint;
            triggers[idx].on_cmp = '>';
        } else if (cnfobj->type == aJson_String)  {
            triggers[idx].on_value = atoi(cnfobj->valuestring + 1);
            triggers[idx].on_cmp = cnfobj->valuestring[0];

            if (strchr(cnfobj->valuestring, '!') != NULL)
                triggers[idx].important = true;

        } else {
            triggers[idx].on_value = MINVALUE;
        }
    }

    cnfobj = aJson.getObjectItem(msg, "off_value");
    if (cnfobj) {
        if (cnfobj->type == aJson_Int) {
            triggers[idx].off_value = cnfobj->valueint;
            triggers[idx].off_cmp = '<';
        } else if (cnfobj->type == aJson_String)  {
            triggers[idx].off_value = atoi(cnfobj->valuestring + 1);
            triggers[idx].off_cmp = cnfobj->valuestring[0];

            if (strchr(cnfobj->valuestring, '!') != NULL)
                triggers[idx].important = true;

        } else {
            triggers[idx].off_value = MINVALUE;
        }
    }

    cnfobj = aJson.getObjectItem(msg, "sensor");
    if (cnfobj && cnfobj->type == aJson_Int) {
        triggers[idx].sensor = cnfobj->valueint;
        if (triggers[idx].sensor < -1 || triggers[idx].sensor > LOGGERS)
            triggers[idx].sensor = NONE;
    } else {
        triggers[idx].sensor = NONE;
    }

    cnfobj = aJson.getObjectItem(msg, "output");
    if (cnfobj && cnfobj->type == aJson_Int) {
        triggers[idx].output = cnfobj->valueint;
        if (triggers[idx].output < -1 || triggers[idx].output > OUTPUTS)
            triggers[idx].output = NONE;

    } else {
        triggers[idx].output = NONE;
    }

    if (triggers[idx].sensor >=0 && triggers[idx].sensor < LOGGERS) {
        triggers[idx]._logger = loggers[triggers[idx].sensor];
    } else {
        triggers[idx]._logger = NULL;
    }
    outputs.revive(triggers[idx].output, idx);
}
Example #11
0
// --------------------------------------------------------------------------------------
//	Create a new mine, set global variables.
int create_new_mine(void)
{
	int	s;
	vms_vector	sizevec;
	vms_matrix	m1 = IDENTITY_MATRIX;
	
	// initialize_mine_arrays();
	
	//	gamestate_not_restored = 1;
	
	// Clear refueling center code
	fuelcen_reset();
	hostage_init_all();
	
	init_all_vertices();
	
	Current_level_num = 0;		//0 means not a real level
	Current_level_name[0] = 0;
	Gamesave_current_version = LEVEL_FILE_VERSION;
	
	Cur_object_index = -1;
	reset_objects(1);		//just one object, the player
	
	num_groups = 0;
	current_group = -1;
	
	
	Num_vertices = 0;		// Number of vertices in global array.
	Highest_vertex_index = 0;
	Num_segments = 0;		// Number of segments in global array, will get increased in med_create_segment
	Highest_segment_index = 0;
	Cursegp = Segments;	// Say current segment is the only segment.
	Curside = WBACK;		// The active side is the back side
	Markedsegp = 0;		// Say there is no marked segment.
	Markedside = WBACK;	//	Shouldn't matter since Markedsegp == 0, but just in case...
	for (s=0;s<MAX_GROUPS+1;s++) {
		GroupList[s].num_segments = 0;		
		GroupList[s].num_vertices = 0;		
		Groupsegp[s] = NULL;
		Groupside[s] = 0;
	}
	
	Num_robot_centers = 0;
	Num_open_doors = 0;
	wall_init();
	trigger_init();
	
	// Create New_segment, which is the segment we will be adding at each instance.
	med_create_new_segment(vm_vec_make(&sizevec,DEFAULT_X_SIZE,DEFAULT_Y_SIZE,DEFAULT_Z_SIZE));		// New_segment = Segments[0];
	//	med_create_segment(Segments,0,0,0,DEFAULT_X_SIZE,DEFAULT_Y_SIZE,DEFAULT_Z_SIZE,vm_mat_make(&m1,F1_0,0,0,0,F1_0,0,0,0,F1_0));
	med_create_segment(Segments,0,0,0,DEFAULT_X_SIZE,DEFAULT_Y_SIZE,DEFAULT_Z_SIZE,&m1);
	
	N_found_segs = 0;
	N_selected_segs = 0;
	N_warning_segs = 0;
	
	//--repair-- create_local_segment_data();
	
	ControlCenterTriggers.num_links = 0;
	
	create_new_mission();
	
    //editor_status("New mine created.");
	return	0;			// say no error
}
Example #12
0
int swpa_device_register_callback_venus( void (*dsp_alarm)(void *puser, int info), void *puser)
{
    g_dsp_alarm = dsp_alarm;
    g_puser = puser;
    return trigger_init() >= 0 ? SWPAR_OK : SWPAR_FAIL;
}
Example #13
0
/**
 * Bootloader main entry
 */
int main(void)
{
	uint8_t boot_region = 0; /* Real boot region at this time */
#ifdef DBG_USE_USART
	uint8_t load_region = 0; /* Real region to put loaded data */
#endif
	struct regions_info info;
	void *app_addr = NULL;
	uint32_t app_size = 0;
	enum trigger_modes trigger;
	bool app_valid = false;

	wdt_disable(WDT);
	sysclk_init();
	board_init();

	/* First turn on the led to indicate the bootloader run. */
	ioport_set_pin_dir(DBG_LED_PIN, IOPORT_DIR_OUTPUT);
	ioport_set_pin_level(DBG_LED_PIN, DBG_LED_PIN_ON_LEVEL);

	dbg_init();
	dbg_print("\r\n\n----------------------\r\n");
	dbg_print("%s Bootloader\r\n", BOARD_NAME);
	dbg_print("Boot region: %x, size %dK\r\n", BOOT0_START, BOOT_SIZE /
			1024);
	dbg_print("App  region: %x, size %dK\r\n", APP0_START,
			(int)APP_SIZE / 1024);
	dbg_print(" - Code %dK + Info %dK\r\n", (int)APP_CODE_SIZE,
			(int)INFO_SIZE);
	dbg_print("----------------------\r\n");

	/* bootloader initialize */
	dbg_print("bl: init ...\r\n");
	trigger_init();
	memory_init();
	media_init(file_list, MEDIA_FILE_LIST_LEN);
	dbg_print("bl: init done\r\n");

	boot_region = _app_boot_get();
	dbg_print("bl: current boot region %d\r\n", (int)boot_region);

#ifdef MEM_LOCK_BOOT_REGION
	dbg_print("bl: lock boot region ...\r\n");
	memory_lock((void *)BOOT0_START, (void *)BOOT0_END);
	dbg_print("bl: lock boot region done\r\n");
#endif

	/* load regions information
	 * Single flash: from last page
	 * Dual flash (remap) : from last page of last physical flash
	 * Dual flash (mirror): from last page of boot flash
	 */
	dbg_print("bl: read regions info ...\r\n");
	region_info_read((void *)INFO_ADDR(true), &info); /* Read for boot */

	app_addr = (void *)(APP_START(boot_region));
	app_valid = region_check_valid(app_addr,
			info.length[boot_region], info.signature[boot_region]);
	dbg_print("bl: read regions info done\r\n");
	dbg_print("bl: trigger flag %s\r\n", trigger_modes_str[info.trigger]);
	dbg_print("bl: region\t%8d\t%8d\r\n", 0, 1);
	dbg_print("bl: size\t%8d\t%8d\r\n", (int)info.length[0],
			(int)info.length[1]);
	dbg_print("bl: sign\t%8x\t%8x\r\n", (unsigned)info.signature[0],
			(unsigned)info.signature[1]);
	dbg_print("bl: boot\t       %c\t       %c\r\n", boot_region ? ' ' : 'Y',
			boot_region ? 'Y' : ' ');
	dbg_print("bl: App @ %d, %x - data %x ...\r\n", (int)boot_region,
			(unsigned)app_addr, (unsigned)*(uint32_t *)app_addr);
	dbg_print("bl: App valid: %c\r\n", app_valid ? 'Y' : 'N');

#ifdef DBG_USE_INFO_EDIT
	/* InfoEdit */
	_app_info_edit(&info);
#endif

	/* bootloader trigger check */
	dbg_print("bl: trigger ...\r\n");
	trigger = trigger_poll(&info);
	dbg_print("bl: trigger mode %s\r\n", trigger_modes_str[trigger]);
	if (TRIGGER_BOOT == trigger) {
		goto main_run_app_check;
	}

	/* Now any other trigger load file to update application directly */
#ifdef DBG_USE_LED
	_app_led_blink(100, 1);
#endif
	/* Update media file information */
	if (info.boot_file_name[0]) {
		dbg_print("bl: boot file assigned, set it\r\n");
		media_set_file_name(info.boot_file_name);
	}

main_load_app:
	/* load new firmware */
#ifdef DBG_USE_USART
	load_region = boot_region;
	dbg_print("bl: download @ %d ...\r\n", load_region);
#endif
	app_size = _app_load(&info, true);
	if (app_size == 0) {
		_app_led_error();
		dbg_print("bl: download fail, retry\r\n");
		goto main_load_app;
	} else {
		dbg_print("bl: download done, size %d\r\n", (int)app_size);
	}

main_run_app_check:

	/* Is application valid */
	dbg_print("bl: check app @ %d is valid\r\n", (int)info.boot_region);
	app_valid = region_check_valid(app_addr, info.length[info.boot_region],
			info.signature[info.boot_region]);
	if (!app_valid) {
		dbg_print("bl: application is not valid\r\n");
		_app_led_error();
		dbg_print("bl: reload firmware\r\n");
		goto main_load_app;
	}

	dbg_print("bl: application is valid, run\r\n");


	/* Turn off the led before jump to the app. */
	_app_led_off(DBG_LED_PIN);

	/* cleanup */
	dbg_print("bl: cleanup ...\r\n");
	media_cleanup();
	trigger_cleanup();
	memory_cleanup();
	dbg_print("bl: cleanup done\r\n");

	/* load application */
	dbg_print("bl: load application ...\r\n\n");

#ifdef DBG_USE_USART
	delay_ms(50); /* Wait USART lines idle */

	dbg_cleanup();

	delay_ms(50);
#endif

	/* run application */
	_app_exec(app_addr);

	return (int)app_addr;
}