示例#1
0
//configuration of interrupt
void NVIC_Configuration(void)
{
  //Set the Vector Table base location
  NVIC_init();

  //2 bits for Preemption Priority and 2 bits for Sub Priority
  NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
}
示例#2
0
int main(void)
{
	GPIO_init();
	Timer_init();
	PWM_init();
	ADC_init();
	NVIC_init();

	// infinite loop
	while (1)
	{
		
	}
}
示例#3
0
//configuration of interrupt on openmotestm32
void NVIC_Configuration(void)
{
    //Set the Vector Table base location
    NVIC_init();
  
    //2 bits for Preemption Priority and 2 bits for Sub Priority
    NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
    
    //configure every module on openmotestm32
//     NVIC_uart();
//     NVIC_spi();
//     NVIC_bsptimer();
//     NVIC_rtctimer();
//     NVIC_radiotimer();
    //NVIC_radio();
}
示例#4
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();
}
示例#5
0
int main(void)
{
	struct note_struct happy_birthday[25];
	struct note_struct sweep[8];

	happy_birthday[0].note = NOTE_D;
	happy_birthday[0].delay = 250;
	happy_birthday[1].note = NOTE_D;
	happy_birthday[1].delay = 250;
	happy_birthday[2].note = NOTE_E;
	happy_birthday[2].delay = 300;
	happy_birthday[3].note = NOTE_D;
	happy_birthday[3].delay = 250;
	happy_birthday[4].note = NOTE_G;
	happy_birthday[4].delay = 250;
	happy_birthday[5].note = NOTE_F_SHARP;
	happy_birthday[5].delay = 350;
	happy_birthday[6].note = NOTE_D;
	happy_birthday[6].delay = 250;
	happy_birthday[7].note = NOTE_D;
	happy_birthday[7].delay = 250;
	happy_birthday[8].note = NOTE_E;
	happy_birthday[8].delay = 300;
	happy_birthday[9].note = NOTE_D;
	happy_birthday[9].delay = 250;
	happy_birthday[10].note = NOTE_A;
	happy_birthday[10].delay = 250;
	happy_birthday[11].note = NOTE_G;
	happy_birthday[11].delay = 350;
	happy_birthday[12].note = NOTE_D;
	happy_birthday[12].delay = 250;
	happy_birthday[13].note = NOTE_D;
	happy_birthday[13].delay = 250;
	happy_birthday[14].note = NOTE_DH;
	happy_birthday[14].delay = 300;
	happy_birthday[15].note = NOTE_B;
	happy_birthday[15].delay = 250;
	happy_birthday[16].note = NOTE_G;
	happy_birthday[16].delay = 250;
	happy_birthday[17].note = NOTE_F_SHARP;
	happy_birthday[17].delay = 250;
	happy_birthday[18].note = NOTE_E;
	happy_birthday[18].delay = 350;
	happy_birthday[19].note = NOTE_CH;
	happy_birthday[19].delay = 250;
	happy_birthday[20].note = NOTE_CH;
	happy_birthday[20].delay = 250;
	happy_birthday[21].note = NOTE_B;
	happy_birthday[21].delay = 300;
	happy_birthday[22].note = NOTE_G;
	happy_birthday[22].delay = 250;
	happy_birthday[23].note = NOTE_A;
	happy_birthday[23].delay = 250;
	happy_birthday[24].note = NOTE_G;
	happy_birthday[24].delay = 350;

	sweep[0].note = NOTE_C;
	sweep[0].delay = 500;
	sweep[1].note = NOTE_D;
	sweep[1].delay = 500;
	sweep[2].note = NOTE_E;
	sweep[2].delay = 500;
	sweep[3].note = NOTE_F;
	sweep[3].delay = 500;
	sweep[4].note = NOTE_G;
	sweep[4].delay = 500;
	sweep[5].note = NOTE_A;
	sweep[5].delay = 500;
	sweep[6].note = NOTE_B;
	sweep[6].delay = 500;
	sweep[7].note = NOTE_C*2;
	sweep[7].delay = 500;

	GPIO_init();
	Timer_init();
	PWM_init();
	ADC_init();
	NVIC_init();

	// infinite loop
	while (1)
	{
		if (g_enable_play)
		{
			if (g_mode == MODE2)
			{
				Play_song(happy_birthday, sizeof(happy_birthday)/sizeof(struct note_struct));
			}
			else if (g_mode == MODE3)
			{
				Play_song(sweep, sizeof(sweep)/sizeof(struct note_struct));
			}
			g_enable_play = 0;
			PWM_set_duty_cycle(100);	// Turn off speaker
		}

		if (g_mode == MODE1 && ADC_changed)
		{
			//PWM_set_duty_cycle((ADC_value*100)/MAX_ADC_VALUE);
			//PWM_load = (((ADC_value*100)/MAX_ADC_VALUE)*MAX_PWM_LOAD)/100/4;
			PWM_load = map_ADC_to_load();
			PWM_set_load(PWM_load);
			PWM_set_duty_cycle(95);
			ADC_changed = 0;
		}
	}
	while(1);
}