Exemplo n.º 1
0
void Keyboard_Handler(void)
{
	// task setup
	INT16U ADSample = 0;
	INT8U Key = NO_KEY;

	// Initialize ACM keyboard for channel 1  
	ACM_Keyb_Setup(Enable, Enable, Rising, ACM_CHANNEL1);

	if (OSSemCreate(0, &sKeyboard) != ALLOC_EVENT_OK)
	{
		while (1){};
	};

	if (OSQueueCreate(&KeyboardBuffer, 64, &qKeyboard) != ALLOC_EVENT_OK)
	{
		while (1){};
	};

	// task main loop
	for (;;)
	{
		// Wait for a keyboard interrupt
		OSSemPend(sKeyboard, 0);
		DelayTask(50);

		// Converts the value of AD to discover the pressed key
		UserEnterCritical();
		ADSample = ADConvert(KEYB_CHANNEL);
		UserExitCritical();

		UserEnterCritical();
		ADSample += ADConvert(KEYB_CHANNEL);
		UserExitCritical();

		ADSample = ADSample >> 1;

		// Find out which key was pressed
		Key = FindKey(ADSample);

		// Copy the key to the keyboard buffer
		if (Key != NO_KEY)
		{
			if (OSQueuePost(qKeyboard, Key) == BUFFER_UNDERRUN)
			{
				// Buffer overflow
				OSCleanQueue(qKeyboard);
			}
		}

		// Enable interrupt to the next key detection
		DelayTask(200);
		ACMEnable();
	}
}
Exemplo n.º 2
0
void Tarefa_termometro(void)
{
	/* task setup */
	INT16U digital_temp = 0;
	INT16U bandgap = 0;
	INT16S temperature = 0;

	ADSetup(NormalPower, HighSpeed, ShortSampleTime, 20, 12);

	/* task main loop */
	for (;;)
	{
		(void) DelayTask(30000); /* 30s */

		//////////////////////////////////////////////////////////////
		// Adquire temperatura do core
		//////////////////////////////////////////////////////////////
		UserEnterCritical();
		digital_temp = ADConvert(TEMP_SENSOR_CH);
		UserExitCritical();

		UserEnterCritical();
		bandgap = ADConvert(BANDGAP_CH);
		UserExitCritical();

		digital_temp = (1170 * digital_temp) / bandgap;

		if (digital_temp > 701)
		{
			temperature = 25 - (((digital_temp - 701) * 1000) / 1646);
		}
		else
		{
			temperature = 25 - (((digital_temp - 701) * 1000) / 1769);
		}

		UserEnterCritical();
		CoreTemp = temperature;
		UserExitCritical();
		//////////////////////////////////////////////////////////////         
	}
}
//Gets all the sensor values from sensorenheten via the SPI-bus
void getSensorValues() {
    for(uint8_t i = 0; i < RETRIEVABLE_SENSOR_DATA; ++i) {

        PORTB &= ~_BV(PB3);
        SPI_MasterTransmit(i);
        PORTB |= _BV(PB3);
        _delay_us(10);


        PORTB &= ~_BV(PB3);
        dataValues[i] = SPI_MasterTransmit(0xAA);
        PORTB |= _BV(PB3);
        _delay_us(10);

    }
    ADConvert();
}
Exemplo n.º 4
0
//Gets all the sensor values from sensorenheten via the SPI-bus
void getSensorValues(){
	uint8_t temp = 0;
	for(uint8_t i = 0; i < RETRIEVABLE_SENSOR_DATA; ++i){
		if(i != 1 && i != 5 && i != 6){
		
			PORTB &= ~_BV(PB3);
			SPI_MasterTransmit(i);
			PORTB |= _BV(PB3);
			_delay_us(10);
			
			
			PORTB &= ~_BV(PB3);
			temp = SPI_MasterTransmit(0xAA);
			PORTB |= _BV(PB3);
			
			cli();
			dataValues[i] = temp;
			sei();
			
			_delay_us(10);
		}	
	}
	ADConvert();
}
Exemplo n.º 5
0
void LowSpeedSampling(void *p)
{
	int16s result;
	result = ADConvert();
	SingleSampleSend(result);
}