Beispiel #1
0
void Timer_initialiser ()
{
	   int t;
	
   /** @todo N'activer que les horloges des timers qui seront utilisés */
   Horloge_activer (HORLOGE_TIMER0);
   Horloge_activer (HORLOGE_TIMER1);
   Horloge_activer (HORLOGE_TIMER2);
   Horloge_activer (HORLOGE_TIMER3);
   Horloge_activer (HORLOGE_TIMER4);
   Horloge_activer (HORLOGE_TIMER5);

   Timer_instances = (Timer*)TIMER_ADRESSE_BASE;
   

   for(t=0; t<TIMER_NOMBRE; t++)
   {
      Timer_arreter (t);
      Timer_acquitter_evenement (t);
      Timer_desactiver_interruptions (t);
      Timer_set_mode (t, TIMER_MODE_PAR_DEFAUT);
      Timer_set_prediviseur (t, TIMER_PREDIVISEUR_PAR_DEFAUT);
      Timer_set_valeur_initiale (t, TIMER_VALEUR_INITIALE_PAR_DEFAUT);
      Timer_set_valeur_finale (t, TIMER_VALEUR_FINALE_PAR_DEFAUT);
   }
}
Beispiel #2
0
void Timer_attendre (int timer, UInt32 duree)
{
	UInt32 postdivision;
   /* Régler le timer pour la durée souhaitée */
   Timer_set_mode (timer, TIMER_INTERVAL);
   postdivision = Timer_set_periode (timer, duree);

   /* Démarrer le timer et remettre à zéro les indicateurs d'état */
   Timer_demarrer (timer);
   Timer_acquitter_evenement (timer);

   /* Laisser le timer tourner pendant le nombre de cycles de comptage
    * déterminé plus haut */
   while(postdivision) {
      while(! Timer_evenement (timer));
      Timer_acquitter_evenement (timer);
      -- postdivision;
   }

   /* C'est fini */
   Timer_arreter (timer);
}
Beispiel #3
0
int main(void)
{
	struct Clock_Struct clock;
	//char str_buf[CLOCK_STRING_LENGTH];

	buffer *rx_buf = NULL;
	buffer *tx_buf = NULL;

	uint8_t bytes_read;

	GPIO_init();
	Timer_init();
	UART_init();
	NVIC_init();

	// 16000000hz
	// 0.0000000625s
	//
	// prescale 16000
	// 1000hz
	// 0.001s

	Clock_reset(&clock);

	Timer_set_mode(WTIMER0A, PERIODIC);
	Timer_set_config(WTIMER0A, INDEPENDENT);
	Timer_set_prescale(WTIMER0A, 16000);
	Timer_set_load(WTIMER0A, _wide_timer_load);
	Timer_enable_interrupt(WTIMER0A);
	Timer_enable(WTIMER0A);

	/*Timer_set_mode(TIMER0A, PERIODIC);
	Timer_set_config(TIMER0A, INDEPENDENT);
	Timer_set_prescale(TIMER0A, 160);
	Timer_set_load(TIMER0A, 50000);
	Timer_enable_interrupt(TIMER0A);
	Timer_enable(TIMER0A);*/

	tx_buf = get_buffer();
	strncpy(tx_buf->buf, "Clock application starting...\n\r", 32);
	tx_buf->fill = 32;
	UART_tx_message(tx_buf);
	tx_buf = NULL;

	tx_buf = get_buffer();
	Clock_to_string(&clock, tx_buf->buf, CLOCK_STRING_LENGTH);
	tx_buf->fill = CLOCK_STRING_LENGTH;
	UART_tx_message(tx_buf);
	tx_buf = NULL;

	while (1)
	{
		if (_output_flag)
		{
			Clock_tick(&clock);
			if (_current_time_message_flag)
			{
				/*str_buf = get_buffer();
				Clock_to_string(&clock, str_buf->buf, CLOCK_STRING_LENGTH);
				str_buf->fill = CLOCK_STRING_LENGTH;
				//UART_out_string(str_buf);
				UART_tx_message(str_buf);*/

				tx_buf = get_buffer();
				Clock_to_string(&clock, tx_buf->buf, CLOCK_STRING_LENGTH);
				tx_buf->fill = CLOCK_STRING_LENGTH;
				UART_tx_message(tx_buf);
				tx_buf = NULL;
			}
			_output_flag = 0;
		}

		// UART RX FIFO is half filled
		if (_rx_fill_flag)
		{
			if (rx_buf == NULL)
			{
				rx_buf = UART_rx_message();
			}

			bytes_read = UART_read_bytes(rx_buf->buf + rx_buf->fill, FILL_LEVEL_BYTES);
			rx_buf->fill += bytes_read;

			_rx_carriage_return_received_flag = received_carriage_return(rx_buf->buf + rx_buf->fill, bytes_read);

			_rx_fill_flag = 0;
		}

		// UART RX FIFO timed out
		if (_rx_timeout_flag)
		{
			if (rx_buf == NULL)
			{
				rx_buf = UART_rx_message();
			}

			bytes_read = UART_read_bytes(rx_buf->buf + rx_buf->fill, FILL_LEVEL_BYTES);
			rx_buf->fill += bytes_read;

			_rx_carriage_return_received_flag = received_carriage_return(rx_buf->buf + rx_buf->fill, bytes_read);
			_rx_timeout_flag = 0;
		}

		if (_rx_carriage_return_received_flag)
		{
			rx_buf->buf[(rx_buf->fill)++] = '\n';
			rx_buf->buf[(rx_buf->fill)++] = '\0';

			_rx_input_flag = 1;
			_rx_carriage_return_received_flag = 0;
		}

		if (_rx_input_flag)
		{
			char h_str[3];
			char m_str[3];
			uint8_t h;
			uint8_t m;

			_rx_input_command_enum = parse_command(rx_buf->buf);
			switch (_rx_input_command_enum)
			{
				case SET_TIME:
					h_str[0] = rx_buf->buf[1];	m_str[0] = rx_buf->buf[4];
					h_str[1] = rx_buf->buf[2];	m_str[1] = rx_buf->buf[5];
					h_str[2] = '\0';			m_str[2] = '\0';
					h = atoi(h_str);
					m = atoi(m_str);
					Clock_set(&clock, h, m, 0);
					break;
				case PAUSE:
					pause_output();
					break;
				case CONTINUE:
					continue_output();
					break;
				case FASTER:
					faster_timer();
					break;
				case SLOWER:
					slower_timer();
					break;
				case INVALID:
				default:
					break;
			}

			tx_buf = rx_buf;
			rx_buf = NULL;

			_rx_input_flag = 0;
		}

		if (tx_buf != NULL)
		{
			if (_rx_input_command_enum != INVALID)
			{
				UART_tx_message(tx_buf);
				tx_buf = NULL;
			}
			else
			{
				release_buffer(tx_buf);
				tx_buf = NULL;
			}
		}

		if (_button_pressed_flag)
		{
			tx_buf = get_buffer();
			strncpy(tx_buf->buf, "Button Pressed\r\n", 17);
			tx_buf->fill = 17;
			UART_tx_message(tx_buf);
			tx_buf = NULL;

			_button_pressed_flag = 0;
		}
	}

	buffer_queue_clean();
}