Ejemplo n.º 1
0
/**
 * Start an ADC convertion.
 * If a kernel is present, preempt until convertion is complete, otherwise
 * a busy wait on ADCS bit is done.
 */
uint16_t adc_hw_read(void)
{
	// Ensure another convertion is not running.
	ASSERT(!(ADCSRA & BV(ADSC)));

	// Start convertion
	ADCSRA |= BV(ADSC);

	#if CONFIG_KERN
		// Ensure IRQs enabled.
		IRQ_ASSERT_ENABLED();
		adc_process = proc_current();
		sig_wait(SIG_ADC_COMPLETE);
	#else
		//Wait in polling until is done
		while (ADCSRA & BV(ADSC)) ;
	#endif

	return(ADC);
}
Ejemplo n.º 2
0
void NORETURN context_switch(void)
{
	IRQ_ENABLE;
	timer_init();
	proc_init();

	#if CONFIG_USE_HP_TIMER
		ser_init(&out, CONFIG_CTX_DEBUG_PORT);
		ser_setbaudrate(&out, CONFIG_CTX_DEBUG_BAUDRATE);
	#endif

	#if CONFIG_USE_LED
		LED_INIT();
	#endif

	proc_forbid();
	hp_proc = proc_new(hp_process, NULL, PROC_STACK_SIZE, hp_stack);
	lp_proc = proc_new(lp_process, NULL, PROC_STACK_SIZE, lp_stack);
	main_proc = proc_current();
	proc_setPri(hp_proc, 2);
	proc_setPri(lp_proc, 1);
	proc_permit();

	while (1)
	{
		timer_delay(100);

		sig_send(lp_proc, SIG_USER0);
		sig_wait(SIG_USER0);

		#if CONFIG_USE_HP_TIMER
			kfile_printf(&out.fd,
				"Switch: %lu.%lu usec\n\r",
				hptime_to_us((end - start)),
				hptime_to_us((end - start) * 1000) % 1000);
		#endif
	}
}
Ejemplo n.º 3
0
/**
 * Sleep until any of the signals in \a sigs or \a timeout ticks elapse.
 * If the timeout elapse a SIG_TIMEOUT is added to the received signal(s).
 * \return the signal(s) that have awoken the process.
 * \note Caller must check return value to check which signal awoke the process.
 */
sigmask_t sig_waitTimeout(sigmask_t sigs, ticks_t timeout)
{
	Timer t;
	sigmask_t res;
	cpu_flags_t flags;

	ASSERT(!sig_check(SIG_TIMEOUT));
	ASSERT(!(sigs & SIG_TIMEOUT));
	/* IRQ are needed to run timer */
	ASSERT(IRQ_ENABLED());

	timer_set_event_signal(&t, proc_current(), SIG_TIMEOUT);
	timer_setDelay(&t, timeout);
	timer_add(&t);
	res = sig_wait(SIG_TIMEOUT | sigs);

	IRQ_SAVE_DISABLE(flags);
	/* Remove timer if sigs occur before timer signal */
	if (!(res & SIG_TIMEOUT) && !sig_check(SIG_TIMEOUT))
		timer_abort(&t);
	IRQ_RESTORE(flags);
	return res;
}
Ejemplo n.º 4
0
/// Return the name of the currently running process
const char *proc_currentName(void)
{
	return proc_name(proc_current());
}
Ejemplo n.º 5
0
/**
 * Run signal test
 */
int msg_testRun(void)
{
	MsgPort test_portMain;
	TestMsg msg0;
	TestMsg msg1;
	TestMsg msg2;
	TestMsg msg3;
	TestMsg msg4;
	TestMsg msg5;
	TestMsg *reply;

	// Allocate and start the test process
    struct Process *recv0 = RECV_INIT_PROC(0);
    struct Process *recv1 = RECV_INIT_PROC(1);
    struct Process *recv2 = RECV_INIT_PROC(2);
    struct Process *recv3 = RECV_INIT_PROC(3);
    struct Process *recv4 = RECV_INIT_PROC(4);
    struct Process *recv5 = RECV_INIT_PROC(5);

	kprintf("Run Message test..\n");

	// Init port and message
    RECV_INIT_MSG(Main, proc_current(), SIG_SINGLE);
    RECV_INIT_MSG(0, recv0, SIG_USER0);
    RECV_INIT_MSG(1, recv1, SIG_USER1);
    RECV_INIT_MSG(2, recv2, SIG_USER2);
    RECV_INIT_MSG(3, recv3, SIG_USER3);
    RECV_INIT_MSG(4, recv4, SIG_SYSTEM5);
    RECV_INIT_MSG(5, recv5, SIG_SYSTEM6);

	// Fill-in first message and send it out.
	fill_msg(&msg0, INC_PROC_T0, DELAY_PROC_T0, 0);
	fill_msg(&msg1, INC_PROC_T1, DELAY_PROC_T1, 0);
	fill_msg(&msg2, INC_PROC_T2, DELAY_PROC_T2, 0);
	fill_msg(&msg3, INC_PROC_T3, DELAY_PROC_T3, 0);
	fill_msg(&msg4, INC_PROC_T4, DELAY_PROC_T4, 0);
	fill_msg(&msg5, INC_PROC_T5, DELAY_PROC_T5, 0);


	// Send and wait the message
	for (int i = 0; i < 23; ++i)
    {
		process_num = 0;
		SEND_MSG(0);
		SEND_MSG(1);
		SEND_MSG(2);
		SEND_MSG(3);
		SEND_MSG(4);
		SEND_MSG(5);
		while(1)
		{
			sigmask_t sigs = sig_waitTimeout(SIG_SINGLE, ms_to_ticks(TEST_TIME_OUT_MS));
			if (sigs & SIG_SINGLE)
			{
				// Wait for a reply...
				while ((reply = (TestMsg *)msg_get(&test_portMain)))
				{
					count += reply->result;
					kprintf("Main recv[%d] count[%d]\n", reply->result, count);
				}
			}
			
			if (process_num == 6)
				break;

			if (sigs & SIG_TIMEOUT)
			{
				kputs("Main: sig timeout\n");
				goto error;
			}
		}
    }

	if(count == MAX_GLOBAL_COUNT)
	{
		kprintf("Message test finished..ok!\n");
		return 0;
	}
	
error:
	kprintf("Message test finished..fail!\n");
	return -1;
}