Beispiel #1
0
Datei: tc.c Projekt: copton/ocram
void collect_run(const char* device, const char* file, unsigned dt)
{
    int sensor = os_sensor_open(device);
    int log = os_flash_open(file, WRITE);

    uint32_t now = os_now();
    while (true) {
        tc_sleep(now + dt);
        now += dt;

        sensor_val_t val;
		while (tc_sensor_read(sensor, &val) != SUCCESS);

        log_to(log, (uint8_t*)&val, sizeof(sensor_val_t));
    }
}
Beispiel #2
0
Datei: tc.c Projekt: copton/ocram
void send_run(const char* channel, const char* file1, const char* file2, unsigned dt)
{
    int log1 = os_flash_open(file1, READ);
    int log2 = os_flash_open(file2, READ);
    int socket = os_connect(channel);
    uint32_t now = os_now();

    while (true) {
        tc_sleep(now + dt);
        now += dt;

        int32_t min = 0x7FFFFFFF;
        int32_t max = 0xFFFFFFFF;

        aggregate_from(log1, &min, &max);
        aggregate_from(log2, &min, &max);

        send_via(socket, min, max); 
    } 
}
Beispiel #3
0
void os_counter_expired_multi(CounterType c)
{
	const AlarmType original = c->dyn->head;						/* The alarm to be handled */
	const os_longtick original_due = original->dyn.c->due;
	const AlarmType next = original->dyn.m->next;
	const TickType cycle = original->dyn.c->cycle;
	const TickType short_now = c->driver->now(c->device);
	const os_longtick long_now = os_now(c, short_now);				/* Time taken here to ensure that overflow takes place from lower now to upper now */
	
	assert(KERNEL_LOCKED());
	assert(!SINGLETON_COUNTER(c));

	OS_API_TRACE_COUNTER_EXPIRED_MULTI(short_now);

	if(next == 0) {
		/* Simple case: one alarm, either to be re-queued or stopped */
		if(cycle) {
			/* $Req: artf1191 artf1197 $ */
			/* Just one cyclic alarm; simply move the event on in time: optimization to avoid need to unstitch then requeue */
			int32 now_to_alarm_due; 
			
			original->dyn.c->due += cycle;		/* Modulo 32-bit arithmetic */
			now_to_alarm_due = original->dyn.c->due - long_now;
			assert(now_to_alarm_due > -((int32)(c->alarmbase.maxallowedvalue)));
			assert(now_to_alarm_due <= c->alarmbase.maxallowedvalue);
		
			if(now_to_alarm_due < 0) {
				now_to_alarm_due = 0;
			}
			c->driver->enable_ints(c->device, short_now, (TickType)now_to_alarm_due);
		}
		else {
			/* Just one alarm now finished; de-queue it and stop the underlying counter */
			c->dyn->head = 0;
			original->dyn.c->running = 0;
			c->driver->disable_ints(c->device);
		}
	}
	else {
		int32 now_to_head_due;
		
		/* More than one alarm in the queue */
		
		/* Unstitch the alarm */		
		c->dyn->head = next;
		/* next->dyn.m->prev is "don't care" since it's now the head of the queue */
		
		if(cycle) {
			os_queue_alarm(c, original_due, original, cycle); /* If it is cyclic then re-queue it in the appropriate place */
		}
		else {
			original->dyn.c->running = 0;
		}
		
		now_to_head_due = c->dyn->head->dyn.c->due - long_now;
		
		assert(now_to_head_due > -((int32)(c->alarmbase.maxallowedvalue)));
		assert(now_to_head_due <= c->alarmbase.maxallowedvalue);
		
		/* Is the head already expired or not? */
		if(now_to_head_due < 0) {
			now_to_head_due = 0;
			/* Head alarm is already due */
		}
		c->driver->enable_ints(c->device, short_now, (TickType)now_to_head_due);
	}
}