예제 #1
0
void usart_transmit_string(USART_TypeDef* port, const void *data) 
{
	int i;
	u16 data_len;
	int tx_count;
	const char* usart_data;
	q_node_type* q_usart_pkt_ptr;

	usart_data = (char*)data;
	data_len = strlen(usart_data);

	tx_count = (data_len - 1) / USART_TX_DMA_SIZ + 1;

	INTLOCK();


	if( q_get_count(&gbl_qlist_usart1_tx_free) >= tx_count )
	{
		for(i=0;i<tx_count-1;i++)
		{
			if( (q_usart_pkt_ptr = q_remove_tail(&gbl_qlist_usart1_tx_free)) != NULL )
			{
				memcpy(q_usart_pkt_ptr->data, usart_data, USART_TX_DMA_SIZ);
				q_usart_pkt_ptr->len = USART_TX_DMA_SIZ;
				q_add_tail(&gbl_qlist_usart1_tx, q_usart_pkt_ptr);

				data_len = data_len - USART_TX_DMA_SIZ;
				usart_data += USART_TX_DMA_SIZ;

			}
		}

		if( (q_usart_pkt_ptr = q_remove_tail(&gbl_qlist_usart1_tx_free)) != NULL )
		{
			memcpy(q_usart_pkt_ptr->data, usart_data, data_len);
			q_usart_pkt_ptr->len = data_len;
			q_add_tail(&gbl_qlist_usart1_tx, q_usart_pkt_ptr);

		}

		if( usart1_dma_transfering == FALSE )
			usart1_tx_proc();

			
	}	


	INTFREE();
	
}
예제 #2
0
/*******************************************************************************
* Function Name  : main.
* Description    : main routine.
* Input          : None.
* Output         : None.
* Return         : None.
*******************************************************************************/
int main(void)
{

	/* Initialize the Demo */
	bsp_init_rcc();

	bsp_init_gpio();
	bsp_init_interrupt();
#ifdef DEV_KIT_ADC_CONV_TEST
    bsp_init_adc();
    DMA_Initial();
#endif /* DEV_KIT_ADC_CONV_TEST */

#ifdef DEV_KIT_STEP_MOTOR_TEST
    step_motor_enable(DISABLE);
#endif /* DEV_KIT_STEP_MOTOR_TEST */

	register_timer_function(timer2ServiceFunction, timer2_event);
#ifdef DEV_KIT_STEP_MOTOR_TEST
    register_timer_function(timer3ServiceFunction, isr_left_motor_event);
    register_timer_function(timer4ServiceFunction, isr_right_motor_event);    
#endif /* DEV_KIT_STEP_MOTOR_TEST */
	register_rtc_function(rtcServiceFunction, rtc_event);

	bsp_init_timer2();
#ifdef DEV_KIT_STEP_MOTOR_TEST
    bsp_init_timer3(DISABLE);
    bsp_init_timer4(DISABLE);    
#endif /* DEV_KIT_STEP_MOTOR_TEST */

	bsp_init_irq_usart1();
	//bsp_init_dma_usart1();

	// 10msec
	wait_10ms(1);

	// User LED ON
	bsp_led_on(ledUser);
#ifdef DEV_KIT_LED_TEST
    //led_rotate_test();
    s_satus_led_flag = 1; // Go status led
#endif /* DEV_KIT_LED_TEST */
	welcome();
	
	usart1_transmit_string("\r\n*****************************************************************************\r\n");	
	usart1_transmit_string("User led ( on )\r\n");
	usart1_transmit_string("Initialize gpio service.\r\n");
	usart1_transmit_string("Start USART1 service on mode interrupt.\r\n");
	usart1_transmit_string_format("BaudRate = %d, Databit = %dbit, StopBits = %d, Parity = no, FlowControl = none\r\n", 115200, 8, 1);
	usart1_transmit_string("\r\n*****************************************************************************\r\n");		

	display_menu();

	usart1_tx_proc();

	
#ifdef DEV_KIT_I2C_TOUCH_KEY_TEST
    i2c_GPIO_Config();
#endif /* DEV_KIT_I2C_TOUCH_KEY_TEST */

	while( 1 )
	{
#ifdef DEV_KIT_I2C_TOUCH_KEY_TEST
        i2c_Test_Example();
#endif /* DEV_KIT_I2C_TOUCH_KEY_TEST */

        
#ifdef DEV_KIT_ADC_CONV_TEST

//        test_func_adc_conv();
#endif /* DEV_KIT_ADC_CONV_TEST */
        
		if( run_menu_selection() != 0 )
			display_menu();

        motor_all(3000, ACT_GO_FORWARD, NOT_ADJUSMENT); // 300cm
        wait_1ms(2000); // 5seconds

        motor_all(3000, ACT_GO_BACKWARD, NOT_ADJUSMENT);
        wait_1ms(2000);

        motor_all(1000, ACT_GO_FORWARD, ADJUSMENT_FRONT);
        wait_1ms(2000);
        
        robot_turn(TURN_LEFT, TURN_90_DEGREE);
        wait_1ms(2000);

        robot_turn(TURN_RIGHT, TURN_90_DEGREE);
        wait_1ms(2000);
        
        motor_all(10000, ACT_GO_FORWARD, SETTING_ONLY);
        while((g_left_mot.step_count <= MM_TO_STEP(700)) || (g_right_mot.step_count <= MM_TO_STEP(700)))
        {
            if(300 < robot_read_sensor(SENSOR_TOP_AD))
            {
                motor_stop(STOP_EMERGENCY);
                break;
            }
        }
        motor_stop(STOP_NORMAL);
        wait_1ms(3000);

        test_func_robot_turn(TURN_LEFT, 200);
        wait_1ms(3000);

        test_func_robot_smooth_turn(TURN_LEFT);
        wait_1ms(5000);
	}

}