Esempio n. 1
0
void main_cdc_config(uint8_t port, usb_cdc_line_coding_t * cfg)
{
	switch(port){
		case 0: // COMM0
			uart_config(&USART_COMM0, cfg);
		break;
		case 1: // XBEE direct TODO
			uart_config(&USART_XBEE, cfg);
		break;
	}
}
/******************************************************************************
 * FunctionName : uart_init
 * Description  : user interface for init uart
 * Parameters   : UartBautRate uart0_br - uart0 bautrate
 *                UartBautRate uart1_br - uart1 bautrate
 * Returns      : NONE
 *******************************************************************************/
void ICACHE_FLASH_ATTR uart_init (UartBautRate uart0_br, UartBautRate uart1_br)
{
	// rom use 74880 baut_rate, here reinitialize
	UartDev.baut_rate = uart0_br;
	uart_config (UART0);
	UartDev.baut_rate = uart1_br;
	uart_config (UART1);
	ETS_UART_INTR_ENABLE();

	// install uart1 putc callback
	os_install_putc1 ((void *)uart1_write_char);
}
Esempio n. 3
0
int main(void)
{
    LEDS_CONFIGURE(1U << READ_ALL_INDICATOR);
    LEDS_OFF(1U << READ_ALL_INDICATOR);

    // Start internal LFCLK XTAL oscillator - it is needed by BSP to handle
    // buttons with the use of APP_TIMER and for "read_all" ticks generation
    // (by RTC).
    lfclk_config();

    bsp_config();
    uart_config();

    printf("\n\rTWI master example\r\n");

    twi_config();

    // Initialize sensors.
    APP_ERROR_CHECK(app_twi_perform(&m_app_twi, lm75b_init_transfers,
        LM75B_INIT_TRANSFER_COUNT, NULL));
    APP_ERROR_CHECK(app_twi_perform(&m_app_twi, mma7660_init_transfers,
        MMA7660_INIT_TRANSFER_COUNT, NULL));

    rtc_config();

    while (true)
    {
        __WFI();
    }
}
Esempio n. 4
0
File: ui.c Progetto: gstroe/Arm
void ui_usb_enum_event(USBH_device_t *dev, USBH_enum_status_t status)
{
	ui_enum_status = status;

	switch (dev->speed) {
	case UHD_SPEED_HIGH:
		ui_device_speed_blink = 250;
		break;

	case UHD_SPEED_FULL:
		ui_device_speed_blink = 500;
		break;

	case UHD_SPEED_LOW:
	default:
		ui_device_speed_blink = 1000;
		break;
	}

	if (ui_enum_status == UHC_ENUM_SUCCESS) {
		/* USB Device CDC connected
		   Open and configure UART and USB CDC ports */
		CDCLineCoding cfg = {
			.dwDTERate   = (115200),
			.bCharFormat = CDCLineCoding_ONESTOPBIT,
			.bParityType = CDCLineCoding_NOPARITY,
			.bDataBits   = 8,
		};
		TRACE_INFO("USART OPEN");
		uart_open();
		uart_config(&cfg);
		uhi_cdc_open(0, &cfg);
	}
}
Esempio n. 5
0
File: main.c Progetto: tkadom/TWBLE
int main(void)
{

    LEDS_CONFIGURE(LEDS_MASK);
    LEDS_OFF(LEDS_MASK);
    nrf_gpio_cfg_output(WAVE_ON_PIN_NUMBER); // on this pin 2Hz wave will be generated

#ifdef BSP_BUTTON_0
    // configure pull-up on first button
    nrf_gpio_cfg_input(BSP_BUTTON_0, NRF_GPIO_PIN_PULLUP);
#endif

    APP_GPIOTE_INIT(1);

    uart_config();

    lpcomp_init();

    printf("\n\rLPCOMP driver usage example\r\n");

    while (true)
    {
        print_statistics();
        LEDS_ON(BSP_LED_1_MASK);
        NRF_GPIO->OUTCLR = (1 << WAVE_ON_PIN_NUMBER);
        nrf_delay_ms(100); // generate 100 ms pulse on selected pin
        print_statistics();
        LEDS_OFF(BSP_LED_1_MASK);
        NRF_GPIO->OUTSET = (1 << WAVE_ON_PIN_NUMBER);
        nrf_delay_ms(400);
    }
}
Esempio n. 6
0
File: ui.c Progetto: InSoonPark/asf
void ui_usb_enum_event(uhc_device_t *dev, uhc_enum_status_t status)
{
	ui_enum_status = status;
	switch (dev->speed) {
	case UHD_SPEED_HIGH:
		ui_device_speed_blink = 250;
		break;
	case UHD_SPEED_FULL:
		ui_device_speed_blink = 500;
		break;
	case UHD_SPEED_LOW:
	default:
		ui_device_speed_blink = 1000;
		break;
	}
	if (ui_enum_status == UHC_ENUM_SUCCESS) {
		// USB Device CDC connected
		// Open and configure UART and USB CDC ports
		usb_cdc_line_coding_t cfg = {
			.dwDTERate   = CPU_TO_LE32(115200),
			.bCharFormat = CDC_STOP_BITS_1,
			.bParityType = CDC_PAR_NONE,
			.bDataBits   = 8,
		};
		uart_open();
		uart_config(&cfg);
		uhi_cdc_open(0, &cfg);
	}
}
Esempio n. 7
0
/******************************************************************************
 * FunctionName : uart_init
 * Description  : user interface for init uart
 * Parameters   : UartBautRate uart0_br - uart0 bautrate
 *                UartBautRate uart1_br - uart1 bautrate
 * Returns      : NONE
*******************************************************************************/
void ICACHE_FLASH_ATTR
uart_init(UartBautRate uart0_br, UartBautRate uart1_br)
{
  // rom use 74880 baut_rate, here reinitialize
  UartDev.baut_rate = uart0_br;
  uart_config(UART0);
  UartDev.baut_rate = uart1_br;
  uart_config(UART1);
  for (int i=0; i<4; i++) uart_tx_one_char(UART1, '\n');
  for (int i=0; i<4; i++) uart_tx_one_char(UART0, '\n');
  ETS_UART_INTR_ENABLE();

  // install uart1 putc callback
  os_install_putc1((void *)uart0_write_char);

  uart_recvTaskNum = register_usr_task(uart_recvTask);
}
Esempio n. 8
0
int main (void)
{
	sysclk_init();
	board_init();
	uart_config((uint32_t)UART_BAUDRATE);
	init_adc();
	pwm_setup();
	dac_setup();
	start_coms();					//Run state machine
	
	
}
Esempio n. 9
0
void main ( void )  {


xdata unsigned char ram_buffer[128];



uint8_t  i,k ;
uint16_t addr;

addr = 0x0000;

i=0;

uart_config(BR_9600_6MHZ);

printf("\r 8051s UART Test Program \n\r")	;

while(1) {

   for ( i =0; i< 20; i++) {
      k = uart_getchar();
      ram_buffer[i] = k;
      uart_putchar(k);
      printf("\n\r");

}


printf("Captured 20 data in RAM ");
printf("\r\n");
k = uart_getchar();

printf(" Buffer COntents : ");
for ( k=0 ; k < i ; k++) {
	uart_putchar(ram_buffer[k]);

}
printf("\n\r");
 printf(" Completed ");



 while(1)
  {
 	 ;
  }
}

}
int main(void)
{
    //configure trigger GPIO
    nrf_gpio_cfg_output(TRIGGER_GPIO_PIN_NO);
    nrf_gpio_pin_clear(TRIGGER_GPIO_PIN_NO);
    nrf_gpio_cfg_output(12);
    nrf_gpio_pin_clear(12);
    //prepare led GPIO by setting its GPIO to output
    nrf_gpio_cfg_output(LED_GPIO_NO);

    //configure UART (38400, 8N1, appropriate ports)
    uart_config(TX_PIN_NO, RX_PIN_NO);
    dbg_setDebugFct(uart_putstring_nonl);

    dbg_debugModule("Starting...\n");

    //initialize TOF measurement timer
    timer1_init();

    //initialize TOF GPIO
    gpio_init();

    //initialize HFCLK for radio (TimeToEdge uses it as well, but configures elsewhere)
    //hfclkInit();

    BTNS_INIT(1, gbtnsDataPtr);
    //init buttons handling
    btns_addGpioteBtn(gbtnsDataPtr, TD_BTN_S1_IO_NO, TD_BTN_S1_IO_CHANNEL, termdev_priv_btnPress, gbtnsDataPtr);
//    btns_addGpioteBtn(gbtnsDataPtr, TD_BTN_S2_IO_NO, TD_BTN_S2_IO_CHANNEL, termdev_priv_btnPress, gbtnsDataPtr);

    __enable_irq();

    dbg_debugModule("Started.\n");

    uint32_t counter = 0;
    while (1 == 1) {
        if (0 != timer_delay_ready) {
            timer_delay_ready = 0;
            dbg_debugModule("STOPPED: TOF: %d\n", timer_delay);
        }

    }

    return 0;
}
Esempio n. 11
0
/**
 * @brief Function for main application entry.
 */
int main(void) {
    uart_config();
    printf("\033[2J\033[;H MPU9150 example. Compiled @ %s\r\n", __TIME__);
    
	twi_init();
    mpu_init();
    
    accel_values_t acc_values;
    uint32_t sample_number = 0;
    while(1) {
        
        mpu9150_read_accel(&acc_values);										// Read accelerometer sensor values
        
		// Clear terminal and print values
        printf("\033[2J\033[;HSample # %d\r\nX: %06d\r\nY: %06d\r\nZ: %06d", ++sample_number, acc_values.x, acc_values.y, acc_values.z);
        nrf_delay_ms(250);
    }
}
Esempio n. 12
0
/**
 * @brief Function for main application entry.
 */
int main(void)
{
    ret_code_t ret_code;
    nrf_gpio_cfg_output(LED_1);
    nrf_gpio_pin_set(LED_1);
    nrf_gpio_cfg_output(LED_2);
    nrf_gpio_pin_set(LED_2);
    uart_config();
    printf("\033[2J\033[;H\r\n* Example to find TWI devices connected to \r\n* the TWI bus and their addresses\r\n\r\n");
    twi_init();
    
    uint8_t dummy_data = 0x55;
    // Itterate through all possible 7-bit TWI addresses
    for(uint8_t i = 0; i <= 0x7F; i++)
    {
        device_address = i;
        // Send dummy data. If a device is present on this particular address a TWI EVT_DONE event is 
        // received in the twi event handler and a message is printed to UART
        ret_code = nrf_drv_twi_tx(&twi_instance, i, &dummy_data, 1, false);
        APP_ERROR_CHECK(ret_code);
        // Delay 10 ms to allow TWI transfer to complete and UART to print messages before starting new transfer
        nrf_delay_ms(10);
    }
    if(device_found)
    {
        // Blinke LED_1 rapidly if device is found
        while(true)
        {
            nrf_gpio_pin_toggle(LED_1);
            nrf_delay_ms(1000);
        }
    }
    else
    {
        // Disable LED_1 if device is NOT found
        nrf_gpio_cfg_default(LED_1);
        printf("*****************\n\rNO DEVICES FOUND!\r\n*****************\n\r");
        while(true)
        {
            nrf_gpio_pin_toggle(LED_2);
            nrf_delay_ms(100);;
        }      
    }
}
Esempio n. 13
0
int connect_serial(char port, int baudrate)
{// currently only support baud rate 115200
	const char *arm_path[] = { "/dev/ttyUSB0", "/dev/ttyUSB1", "/dev/ttyUSB2" };

	g_sdk_uart_fd = open(arm_path[port], O_RDWR | O_NOCTTY);
	if (g_sdk_uart_fd < 0)
	{
		printf("open UART ERROR ???\n");
		return -1;
	}
	printf("open uart ok! fd:%d\n", g_sdk_uart_fd);
	if (uart_config(g_sdk_uart_fd, baudrate, 8, 'N', 1) < 0)
	{
		printf("UART config ERROR ???\n");
		return -1;
	}

	return 0;
}
Esempio n. 14
0
/**
 * @brief Function for main application entry.
 */
int main(void)
{
    adc_config();

    uart_config();

    printf("\n\rADC HAL simple example\r\n");

    printf("Current sample value:\r\n");

    nrf_adc_start();

    while (true)
    {
        // enter into sleep mode
        __SEV();
        __WFE();
        __WFE();
    }
}
int CRobotBodyManager::Init()
{

	int ret;
	init_console();
	ret = uart_open();
	if (ret < 0) {
		//uart 연결 실패시
		printf("FAIL : UART \n");
	}

	uart_config(UART1, 115200, 8, UART_PARNONE, 1); //uart 채널 설정
	m_pStateManager->Init(); //state manager 초기화
	CMessageCommManager::GetSingleton()->Connect(COMM_TYPE_ROT_TO_MGR); // rot -> mgr 파이프 연결
	CMessageCommManager::GetSingleton()->Connect(COMM_TYPE_MGR_TO_ROT); // mgr -> rot 파이프 연결
	CRobotControlManager::GetSingleton()->Init(); //robot control manager 초기화
	m_pTimeManager->Init(); //timer manager 초기화

	return 0;
}
Esempio n. 16
0
bool uart_init_device (unsigned dev)
{
    /* set GPIOs, clock enable? etc */

    switch (dev)
    {
        case 0:
        {
            S3C2440_GPIO_CONFIG (GPHCON, 2, GPIO_FUNCTION);
            S3C2440_GPIO_CONFIG (GPHCON, 3, GPIO_FUNCTION);
            S3C2440_GPIO_PULLUP (GPHUP, 2, GPIO_PULLUP_DISABLE);
            S3C2440_GPIO_PULLUP (GPHUP, 3, GPIO_PULLUP_DISABLE);
            break;
        }
        case 1:
        {
            S3C2440_GPIO_CONFIG (GPHCON, 4, GPIO_FUNCTION);
            S3C2440_GPIO_CONFIG (GPHCON, 5, GPIO_FUNCTION);
            S3C2440_GPIO_PULLUP (GPHUP, 4, GPIO_PULLUP_DISABLE);
            S3C2440_GPIO_PULLUP (GPHUP, 5, GPIO_PULLUP_DISABLE);
            break;
        }
        case 2:
        {
            S3C2440_GPIO_CONFIG (GPHCON, 6, GPIO_FUNCTION);
            S3C2440_GPIO_CONFIG (GPHCON, 7, GPIO_FUNCTION);
            S3C2440_GPIO_PULLUP (GPHUP, 6, GPIO_PULLUP_DISABLE);
            S3C2440_GPIO_PULLUP (GPHUP, 7, GPIO_PULLUP_DISABLE);
            break;
        }
        default:
            return false;
    }
    
    /* set a default configuration */
    uart_config (dev, 115200, 8, UART_NO_PARITY, UART_1_STOP_BIT); 
    return true;
}
Esempio n. 17
0
int main(void) {

	BT_ERROR Error;

	BT_HANDLE hUART = BT_DeviceOpen("uart1", &Error);

	uart_config(hUART);

	BT_UartEnable(hUART);
	BT_SetStandardHandle(hUART);

	BT_kPrint("BootThunder started...");

	BT_HANDLE hVolume = BT_DeviceOpen("mmc00", &Error);
	while(!hVolume) {
		BT_ThreadSleep(5);
		hVolume = BT_DeviceOpen("mmc00", &Error);
	}

	BT_Mount(hVolume, "/sd0/");

	signal_booted();

	Error = BT_ShellScript("/sd0/boot.cfg");
	if(Error) {
		BT_kPrint("No kernel shell script found, jumping to terminal shell");
	}

	// If we got here then script wasn't found, or didn't boot! Create a shell.
	sprintf(buffer, "boot --core 0 %08x", jtag_loop);
	BT_ShellCommand(buffer);

	while(1) {
		BT_ThreadSleep(1000);
	}

	return 0;
}
Esempio n. 18
0
/**
 * @brief Function for main application entry.
 */
int main(void)
{
    adc_config();

    uart_config();

    printf("\n\rADC HAL simple example\r\n");

    printf("Current sample value:\r\n");

    while (true)
    {
			  // trigger next ADC conversion
			  nrf_adc_start();
        // enter into sleep mode
        __SEV();
        __WFE();
        __WFE();
			
			  nrf_delay_ms(100);	
				printf("%d\r\n", (int)adc_sample); // out ADC result
    }
}
Esempio n. 19
0
/**
 * This function will startup RT-Thread RTOS.
 */
void rtthread_startup(void)
{
	/* init board */
	rt_hw_board_init();

	/* show version */
	rt_show_version();

#ifdef RT_USING_HEAP
    rt_system_heap_init((void*)HEAP_BEGIN, (void*)HEAP_END);
#endif
	
    /* initialize scheduler system */
    rt_system_scheduler_init();
	
    /* initialize system timer*/
    rt_system_timer_init();
	
	  wifi_low_level();
	  uart_config();
    /* initialize application */
    rt_application_init();

    /* initialize timer thread */
    rt_system_timer_thread_init();

    /* initialize idle thread */
    rt_thread_idle_init();

    /* start scheduler */
    rt_system_scheduler_start();

    /* never reach here */
    return ;

}
Esempio n. 20
0
void ui_usb_enum_event(uhc_device_t *dev, uhc_enum_status_t status)
{
	ui_enum_status = status;
	if (ui_enum_status == UHC_ENUM_SUCCESS) {
		switch (dev->speed) {
		case UHD_SPEED_HIGH:
			ui_device_speed_blink = 250;
			break;

		case UHD_SPEED_FULL:
			ui_device_speed_blink = 500;
			break;

		case UHD_SPEED_LOW:
		default:
			ui_device_speed_blink = 1000;
			break;
		}
		/* USB Device CDC connected
		   Open and configure UART and USB CDC ports */
		usb_cdc_line_coding_t cfg = {
			.dwDTERate   = CPU_TO_LE32(19200),
			.bCharFormat = CDC_STOP_BITS_1,
			.bParityType = CDC_PAR_NONE,
			.bDataBits   = 8,
		};
		uart_open();
		uart_config(&cfg);
		uhi_cdc_open(0, &cfg);
	}
}

void ui_usb_wakeup_event(void)
{
#ifdef USB_HOST_LPM_SUPPORT
	ui_disable_asynchronous_interrupt();
#endif
}

void ui_usb_sof_event(void)
{
#ifdef USB_HOST_LPM_SUPPORT
	bool b_btn_state;
	static bool btn_suspend_and_remotewakeup = false;
#endif

	static uint16_t counter_sof = 0;

	if (ui_enum_status == UHC_ENUM_SUCCESS) {
		/* Display device enumerated and in active mode */
		if (++counter_sof > ui_device_speed_blink) {
			counter_sof = 0;
			if (!ui_data_transfer) {
				LED_Toggle(LED_0_PIN);
			}
		}
#ifdef USB_HOST_LPM_SUPPORT
		/* Scan button to enter in suspend mode and remote wakeup */
		b_btn_state = !port_pin_get_input_level(BUTTON_0_PIN);
		if (b_btn_state != btn_suspend_and_remotewakeup) {
			/* Button have changed */
			btn_suspend_and_remotewakeup = b_btn_state;
			if (b_btn_state) {
				/* Button has been pressed */
				ui_enable_asynchronous_interrupt();
				LED_Off(LED_0_PIN);
                uhc_suspend_lpm(true, HIRD_800_US);
				return;
			}
		}
#endif // #ifdef USB_HOST_LPM_SUPPORT
	}
}
Esempio n. 21
0
int main(int argc, char **argv)
{
	int x, y;
	char ch;
	int ret;
    unsigned char buff[5] = {0,};
	unsigned int buf_addr;
	unsigned short (*img_buf)[256];
	
	if(argc <= 1) {
		printf("Usage 1 : imgproc_test -rd     <Read Image Data>\n");
		printf("Usage 2 : imgproc_test -dp     <Display to LCD>\n");
		printf("Usage 3 : imgproc_test -dp2    <Display 2 Frame>\n");
		exit(1);
	}
	eagle_camera_off(); // 커널에서 동작되는 Camera OFF : comment by yyb[110909]
	
	//[[ molink_yyb_110909_BEGIN -- 로봇 몸체와의 통신을 위한 UART 초기화
	ret = uart_open();
	if (ret < 0) return EXIT_FAILURE;
	uart_config(UART1, 115200, 8, UART_PARNONE, 1);
	//]] molink_yyb_110909_END -- 로봇 몸체와의 통신을 위한 UART 초기화

	ret = ImageProcess_Open(); // 이미지 처리를 위한 드라이버 Open : comment by yyb[110909]
	if (ret < 0) return EXIT_FAILURE;

	Delay(0xffffff);

	if(strcmp("-rd", argv[1]) == 0) {

		ret = ReadImageFromFPGA(&buf_addr); // FPGA로부터 1Frame(180x120)의 이미지 Read : comment by yyb[110909]
		if (ret < 0) return EXIT_FAILURE;
		img_buf = (unsigned short (*)[256])buf_addr; 

		//TEST
		GetDistance(img_buf);
		GetGradient(img_buf);		
	}
	else if(strcmp("-dp", argv[1]) == 0) {
		ret = ImgDisplayToLCD(); // FPGA로 부터 읽어온 이미지를 LCD에 실시간으로  Display : comment by yyb[110909]
		if (ret < 0) return EXIT_FAILURE;
		
		printf("\nPress Enter Key to STOP the test !!!");
		
		ch = getchar();
		ImgDisplayQuit(); // LCD Display 종료 : comment by yyb[110909]
		printf("\nTest is Stopped\n");
	}
	else if(strcmp("-dp2", argv[1]) == 0) {
		ClearScreen(255, 255, 255); // LCD 화면을 백색으로 Clear : comment by yyb[110909]
		gFlip(); // 그래픽 처리된 내용을 LCD에 보여줌 : comment by yyb[110909]
		ClearScreen(255, 255, 255);
		gFlip();
		ClearScreen(255, 255, 255);
		gFlip();
		ClearScreen(255, 255, 255);
		gFlip();
		printf("Clear Screen!\n");

		ret = ReadImageFromFPGA(&buf_addr);
		if (ret < 0) return EXIT_FAILURE;

		printf("Image Load from FPGA!\n");

		draw_value.imgbuf_en = 0; // 읽어 온 데이터를 처리하지 않고 그대로 다시 LCD에 보여줄 때 설정 : comment by yyb[110909]
		ClearScreen(255, 255, 255);
		draw_img_from_buffer((unsigned short *)buf_addr, 160, 130, 1.8, 0); // buf_addr에 들어 있는 내용을 1.8배 확대하여 0도 회전하고 중심을 (160, 130)로 하여  Display : comment by yyb[110909]
//		gFlip();
		printf("1. Draw Image to LCD!\n");
//    }


		printf("\nPress Enter Key to load image again !!!");
		ch = getchar();
		
		ret = ReadImageFromFPGA(&buf_addr);
		if (ret < 0) return EXIT_FAILURE;
		img_buf = (unsigned short (*)[256])buf_addr;
		printf("Image Load from FPGA!\n");

		//////////////////////////////////////////////////////////////////
		// img_buf의 데이터에 대한 이미지 처리 과정이 이 위치에서 이루어짐 //
		//////////////////////////////////////////////////////////////////
		
		draw_value.imgbuf_en = 1; // 읽어 온 데이터를 처리하고, 처리된 데이터를 LCD에 보여줄 때 설정 : comment by yyb[110909]
		draw_img_from_buffer((unsigned short *)buf_addr, 160, 360, 1.8, 0);
		gFlip();
		printf("2. Draw Image to LCD!\n");

		printf("\nPress Enter Key to STOP the test !!!");
		ch = getchar();
		printf("\nTest is Stopped\n");
		
	}
	else {
		printf("Usage 1 : imgproc_test -rd     <Read Image Data>\n");
		printf("Usage 2 : imgproc_test -dp     <Display to LCD>\n");
		printf("Usage 3 : imgproc_test -dp2    <Display 2 Frame>\n");
		exit(-1);
	}
	
	uart_close();
	close(devfb);

	eagle_camera_on(); // 커널에서 동작되는 Camera ON : comment by yyb[110909]

	return(0);
}
Esempio n. 22
0
/**
 * \brief
 *
 * \param
 *
 * \return void
 */
void uart_config(void)
{
	const sam_uart_opt_t uart_settings = {
		.ul_mck = sysclk_get_peripheral_hz(),
		.ul_baudrate = 19200,
		.ul_mode = UART_MR_PAR_NO
	};

	sysclk_enable_peripheral_clock(ID_UART);
	uart_init( BOARD_UART, &uart_settings );

}
/**
 * \brief
 *
 * \param
 *
 * \return void
 */
void usart0_config(void)
{

	const sam_usart_opt_t usart_0_settings = {
		.baudrate = 19200,
		.char_length = US_MR_CHRL_8_BIT,
		.parity_type = US_MR_PAR_NO,
		.stop_bits = US_MR_NBSTOP_1_BIT,
		.channel_mode = US_MR_CHMODE_NORMAL,
		/* This field is only used in IrDA mode. */
		.irda_filter = 0
	};
	sysclk_enable_peripheral_clock(BOART_ID_USART0);
	usart_init_rs232(BOARD_USART0, &usart_0_settings, sysclk_get_peripheral_hz());

	/* Disable all the interrupts. */
	usart_disable_interrupt(BOARD_USART0, 0xffffffff);

	/* Enable the receiver and transmitter. */
	usart_enable_tx(BOARD_USART0);
	usart_enable_rx(BOARD_USART0);

	/* Configure and enable interrupt of USART. */
	NVIC_EnableIRQ(USART0_IRQn);

	usart_enable_interrupt(BOARD_USART0, US_IER_RXRDY);
}

/**
 * \brief
 *
 * \param
 *
 * \return void
 */
void usart1_config(void)
{
	const sam_usart_opt_t usart_1_settings = {
		.baudrate = 115200,
		.char_length = US_MR_CHRL_8_BIT,
		.parity_type = US_MR_PAR_NO,
		.stop_bits = US_MR_NBSTOP_1_BIT,
		.channel_mode = US_MR_CHMODE_NORMAL,
		/* This field is only used in IrDA mode. */
		.irda_filter = 0
	};

	sysclk_enable_peripheral_clock( BOART_ID_USART1 );
	usart_init_rs232( BOARD_USART1, &usart_1_settings, sysclk_get_peripheral_hz() );

	/* Disable all the interrupts. */
	usart_disable_interrupt(BOARD_USART1, 0xffffffff);

	/* Enable the receiver and transmitter. */
	usart_enable_tx(BOARD_USART1);
	usart_enable_rx(BOARD_USART1);

	/* Configure and enable interrupt of USART. */
	NVIC_EnableIRQ( USART1_IRQn );

	usart_enable_interrupt( BOARD_USART1, US_IER_RXRDY);
}

/**
 * \brief
 *
 * \param uxPriority
 *
 * \return void
 */
void vStartUartTaskLauncher( unsigned portBASE_TYPE uxPriority )
{
	/* Spawn the Sentinel task. */
	xTaskCreate( vUartTask, (const signed portCHAR *)"SPILAUNCH",
				TASK_RADIO_STACK_SIZE, NULL, uxPriority,
				(xTaskHandle *)NULL );
}

/**
 * \brief UART handle task..
 *
 * \param
 * \param
 *
 * \return None
 */
portTASK_FUNCTION_PROTO( vUartTask, pvParameters )
{
	uint8_t	i, sms_text[] = "AT\r";

	(void)pvParameters;

	/* Initialize UART model.*/
	uart_config();
	usart0_config();
	usart1_config();

	gpio_set_pin_low( PIO_PA17_IDX );

	for (;;)
	{
		vTaskDelay(1000);

		uart_write( BOARD_UART, '1' );
		usart_serial_write_packet( BOARD_USART1, sms_text, sizeof(sms_text) );
	}
}

/**
 * \brief
 *
 * \param
 *
 * \return void
 */
void USART0_Handler(void)
{
	uint32_t ul_status;

	/* Read USART Status. */
	ul_status = usart_get_status( BOARD_USART0 );

	/* Receive buffer is full. */
	if (ul_status & US_CSR_RXRDY)
	{
		usart_read( BOARD_USART0, (uint32_t *)&gs_ul_read_buffer[0] );
	}
}
Esempio n. 23
0
//*****************************************************************************
//
// This example demonstrates how to send a string of data to the UART.
//
//*****************************************************************************
int
main(void)
{
	delay_init(48);
	uart_config();
	led_init();
	#if 0
	ind_cnn_init();	
	config conf;
	conf.local_ip[0]=192;
	conf.local_ip[1]=168;
	conf.local_ip[2]=1;
	conf.local_ip[3]=13;
	conf.local_port[0]=11;
	conf.local_port[1]=34;
	conf.sub_msk[0]=255;
	conf.sub_msk[1]=255;
	conf.sub_msk[2]=255;
	conf.sub_msk[3]=0;
	conf.gw[0]=192;
	conf.gw[1]=168;
	conf.gw[2]=1;
	conf.gw[3]=1;
	conf.mac[0]=0xe3;
	conf.mac[1]=0x90;
	conf.mac[2]=0x12;
	conf.mac[3]=0x2d;
	conf.mac[4]=0xef;
	conf.mac[5]=0x33;
	conf.remote_ip[0]=192;
	conf.remote_ip[1]=168;
	conf.remote_ip[2]=1;
	conf.remote_ip[3]=122;
	conf.remote_port[0]=0xef;
	conf.remote_port[1]=33;
	conf.protol=NET_PROTOL_TCP;
	conf.server_mode=CLIENT_MODE;
	conf.uart_baud=BAUD_115200;
	ind_out(1);
	delay(5);
	config_param(CONFIG_LOCAL_IP,&conf);
	config_param(CONFIG_LOCAL_PORT,&conf);
	config_param(CONFIG_GW,&conf);
	config_param(CONFIG_SUB_MSK,&conf);
	config_param(CONFIG_MAC,&conf);
	config_param(CONFIG_REMOTE_IP,&conf);
	config_param(CONFIG_REMOTE_PORT,&conf);
	config_param(CONFIG_PROTOL,&conf);
	config_param(CONFIG_SERVER_MODE,&conf);
	config_param(CONFIG_UART_BAUD,&conf);
	//read_param();
	delay(5);
	ind_out(0);
	uart_send('A');
	#endif
	GPIO_SetBits(GPIOF, GPIO_Pin_0);
	GPIO_SetBits(GPIOA, GPIO_Pin_4);
	delay_ms(100);
	GPIO_ResetBits(GPIOA, GPIO_Pin_4);
	delay_ms(100);
	GPIO_SetBits(GPIOA, GPIO_Pin_4);
	delay_ms(100);
	E2promWriteByte(0x40,0x04,0x8a);
	E2promWriteByte(0x40,0x04,0x01);
    //
    // Loop forever echoing data through the UART.
    //

    while(1)
    {
		rt_hw_led1_on();
		//uart_send('A');
		//ind_out(0);
		delay_ms(50);
		rt_hw_led1_off();
		//uart_send('B');
		//ind_out(1);
		delay_ms(50);
    }
}
Esempio n. 24
0
/** @brief Function for main application entry.
 */
int main(void)
{ 
    radio_tests_t test     = RADIO_TEST_NOP;
    radio_tests_t cur_test = RADIO_TEST_NOP;

    init();
    uart_config(TX_PIN_NUMBER, RX_PIN_NUMBER);
    uart_putstring((const uint8_t *)"RF Test\r\n");
    
    NVIC_EnableIRQ(TIMER0_IRQn);
    __enable_irq();
    
    while (true)
    {
        __WFI();
        switch (uart_get())
        {
            case 'a':
                while (true)
                {
                    uart_putstring((const uint8_t *)"Enter start channel \
                                   (two decimal digits, 00 to 80):");
                    channel_start_ = get_dec2();
                    if (channel_start_ <= 80)
                    break;
                    uart_putstring((const uint8_t *)"Channel must be between 0 and 80\r\n");
                }
                test = cur_test;
                break;

            case 'b':
                while (true)
                {
                    uart_putstring((const uint8_t *)"Enter end channel \
                                   (two decimal digits, 00 to 80):");
                    channel_end_ = get_dec2();
                    if (channel_end_ <= 80)
                    {
                        break;
                    }
                uart_putstring((const uint8_t *)"Channel must be between 0 and 80\r\n");
                }
                test = cur_test;
                break;

            case 'c':
                test = RADIO_TEST_TXCC;
                break;

            case 'd':
                while (true)
                {
                    uart_putstring((const uint8_t *)"Enter delay in ms \
                                   (two decimal digits, 01 to 99):");
                    delayms_ = get_dec2();
                    if ((delayms_ > 0) && (delayms_ < 100))   
                    {
                        break;
                    }
                    uart_putstring((const uint8_t *)"Delay must be between 1 and 99\r\n");
                }
                test = cur_test;
                break;

            case 'e':
                radio_sweep_end();
                cur_test = RADIO_TEST_NOP;
                break;

            case 'm':
                get_datarate();
                test = cur_test;
                break;

            case 'o':
                test = RADIO_TEST_TXMC;
                uart_putstring((const uint8_t *)"TX modulated carrier\r\n");
                break;

            case 'p':
                get_power();
                test = cur_test;
                break;

            case 'r':
                test = RADIO_TEST_RXSWEEP;
                uart_putstring((const uint8_t *)"RX Sweep\r\n");
                break;

            case 's':
                print_parameters();
                break;

            case 't':
                test = RADIO_TEST_TXSWEEP;
                uart_putstring((const uint8_t *)"TX Sweep\r\n");
                break;

            case 'x':
                test = RADIO_TEST_RXC;
                uart_putstring((const uint8_t *)"RX constant carrier\r\n");
                break;

            case 'h':
                // Fall through.
        
            default:
                help();
                break;
        }
    
        switch (test)
        {
            case RADIO_TEST_TXCC:
                if (sweep)
                {
                    radio_sweep_end();
                    sweep = false;
                }
                radio_tx_carrier(txpower_, mode_, channel_start_);
                cur_test = test;
                test     = RADIO_TEST_NOP;
                break;

            case RADIO_TEST_TXMC:
                if (sweep)
                {
                    radio_sweep_end();
                    sweep = false;
                }
                radio_modulated_tx_carrier(txpower_, mode_, channel_start_);
                cur_test = test;
                test     = RADIO_TEST_NOP;
                break;

            case RADIO_TEST_TXSWEEP:
                radio_tx_sweep_start(txpower_, mode_, channel_start_, channel_end_, delayms_);
                sweep    = true;
                cur_test = test;
                test     = RADIO_TEST_NOP;
                break;

            case RADIO_TEST_RXC:
                if (sweep)
                {
                    radio_sweep_end();
                    sweep = false;
                }
                radio_rx_carrier(mode_, channel_start_);
                cur_test = test;
                test     = RADIO_TEST_NOP;
                break;  

            case RADIO_TEST_RXSWEEP:
                radio_rx_sweep_start(mode_, channel_start_, channel_end_, delayms_);
                sweep    = true;
                cur_test = test;
                test     = RADIO_TEST_NOP;
                break;

            case RADIO_TEST_NOP:
                // Fall through.
            default:
                // No implementation needed.
                break;
        }
    }
}
int main(int argc,char **argv)
{	
	uart_config();
	gsm_init();
	sendMessage("18664307310", "4E2D");
	global.isReceivedMsg = false;
	pthread_mutex_init(&global.db, NULL);
	if((global.shmid=shmget(IPC_PRIVATE,MAX_BUFFER_SIZE,0666))<0)
	{
		perror("create share-memory");
		exit(1);
	}
	//create receive message Thread
	pthread_t listenClientThreadID;
	//pthread_create(&listenClientThreadID,NULL,listen_client_connect_thread_func,NULL);
	//pthread_detach(listenClientThreadID);

	int read_length = 0;
	char buffer[MAX_BUFFER_SIZE]={0};
	char command[MAX_BUFFER_SIZE] ={0};
	char *share_msg_info_addr;
	
	if((share_msg_info_addr = shmat(global.shmid,0,0))==(void *)-1)
	{
		perror("Parent: shmat:");
		exit(1);
	}
	
	while(true)
	{			
		if(global.isReceivedMsg)
		{
			sendMessage("18664307310", "4E2D");
			global.isReceivedMsg = false;
		}
		if((read_length=read(global.fd,buffer,sizeof(buffer)))>0)
		{
			if(strstr(buffer,"0891"))
			{
				// 1. get the messgae info
				message_info_t rcv_info = handler_receive_msg(strstr(buffer,"0891"));
				// 2.share memory
				memset(buffer,0,sizeof(buffer));
				sprintf(buffer,"%s,%s,%s\0",rcv_info.send_number,rcv_info.send_time,rcv_info.send_content);
				memset(share_msg_info_addr,0,sizeof(share_msg_info_addr));
				memcpy(share_msg_info_addr,buffer,strlen(buffer));
				// 3.save log
				save_gsm_log(rcv_info);
				// 4.delete it from SIM
				memset(buffer,0,sizeof(buffer));
				sprintf(buffer,"AT+CMGD=%s\r\0",rcv_msg_sim_index);
				write(global.fd,buffer,strlen(buffer));
				global.isReceivedMsg = true;
			}
			else if(strstr(buffer,"CMTI:"))//new message is coming
			{
				memset(command,0,sizeof(command));
				strcpy(command,buffer);
				printf("new message : %s\n",buffer);
				memset(buffer,0,sizeof(buffer));
				strtok(command,",");
				strcpy(rcv_msg_sim_index,strtok(NULL,","));
				sprintf(buffer,"AT+CMGR=%s\r\0",rcv_msg_sim_index);
				write(global.fd,buffer,strlen(buffer));  //read new message command
			}
			else
			{
				printf("buffer is: %s\n",buffer);
			}
			memset(buffer,0,sizeof(buffer));
		}
	}
	return 0;
}
Esempio n. 26
0
int main(int argc, char **argv)
{
	char ch;
	int ret;
	int decfd1, decfd2;
	volatile int  x, y;
//	int img_addr=0;
	struct saa7111_data_info video_dec;
	struct disp_coordinate disp_xy;

    unsigned char buff[5] = {0,};
// 	RGB(565) Setting
	unsigned char RGB565_Buff[0x18] = { 
							0x00,	//sub_addr00 : chip version
							0x00,	//sub_addr01 : not used
							0xc0,	//sub_addr02
							0x23,	//sub_addr03
							0x00,	//sub_addr04
							0x00,	//sub_addr05
							0xde,	//sub_addr06
							0xdc,	//sub_addr07
							0x40,	//sub_addr08
							0x01,	//sub_addr09
							0x80,	//sub_addr0a
							0x47,	//sub_addr0b
 							0x40,	//sub_addr0c
							0x00,	//sub_addr0d
							0x01,	//sub_addr0e
							0x00,	//sub_addr0f
							0x00,	//sub_addr10
							0x0c,	//sub_addr11
							0x01,	//sub_addr12
							0x00,	//sub_addr13
							0x00,	//sub_addr14
							0x00,	//sub_addr15
							0x00,	//sub_addr16
							0x00	//sub_addr17
						};

	if(argc <= 1) {
		printf("Usage 1 : imgproc_test -rd     <Read Image Data>\n");
		printf("Usage 2 : imgproc_test -dp     <Display to Monitor>\n");
		printf("Usage 3 : imgproc_test -xy     [x coordinate] [y coordinate]\n");
		exit(1);
	}
	
	ret = uart_open();
	if (ret < 0) return EXIT_FAILURE;
	
	uart_config(UART1, 115200, 8, UART_PARNONE, 1);
	

	decfd1 = open("/dev/saa7111", O_RDWR);
	if(decfd1 < 0) {
		fprintf(stderr, "/dev/saa7111 open failed!!\n");
		exit(1);
	}
	
	video_dec.addr = 0x2;
	video_dec.buf = RGB565_Buff;
	video_dec.len = sizeof(RGB565_Buff) - 2;

	if ( ioctl(decfd1, SAA7111_WR_REGS, &video_dec) ) {
		fprintf(stderr, "ioctl write error\n");
		exit(1);
	}
	printf("Video Output : <RGB565 Format> Complete!\n");
	close(decfd1);
	
	decfd2 = open("/dev/imgproc", O_RDWR);
	if(decfd2 < 0) {
		printf("/dev/imgproc open failed!!\n");
		exit(1);
	}
	Delay(0xffffff);
	
	if(strcmp("-rd", argv[1]) == 0) {
//		if ( ioctl(decfd2, RD_IMG_DATA, buff) ) {
		if ( ioctl(decfd2, RD_IMG_DATA, &bf) ) {
			printf("ioctl RD_IMG_DATA error\n");
			exit(1);
		}
//		memcpy(&img_addr, buff, 4);
//		printf("img_addr=0x%x\n", img_addr);

		for(y=0; y<120; y++) {
			for(x=0; x<180; x++) {
//				sprintf((char *)buff, "%04x", *(unsigned short *)(img_addr+(y*360)+(x*2)));
				sprintf((char *)buff, "%04x", bf[y][x]);
				uart1_buffer_write(buff, 4);
//				printf("%s", buff);
//				Delay(10000);
			}
		}
	    printf("\t read 1 frame imgae data completely\n");
	}
	else if(strcmp("-dp", argv[1]) == 0) {
		if ( ioctl(decfd2, DISPLAY_IMG_DATA, 0) ) {
		    printf("ioctl DISPLAY_IMG_DATA error\n");
		    exit(1);
		}
		printf("\nPress Enter Key to STOP the test !!!");
		ch = getchar();
		ioctl(decfd2, DISABLE_IMG_IRQ, 0);
		printf("\nTest is Stopped\n");
	}
	else if(strcmp("-xy", argv[1]) == 0) {
		if(argc < 4) {
			printf("Usage  : imgproc_test -xy [x coordinate] [y coordinate]\n");
			exit(1);
		}

		if ( ioctl(decfd2, RD_IMG_DATA, &bf) ) {
			printf("ioctl RD_IMG_DATA error\n");
			exit(1);
		}
//		Delay(1000);
		printf("Image Load from FPGA!\n");
		
		if ( ioctl(decfd2, DISPLAY_RESOLUTION, SCREEN_640_480) ) {
			printf("Resolution set fail!!!\n");
			exit(1);
		}
		printf("Resolution set complete!\n");
		
		if ( ioctl(decfd2, CLEAR_SCREEN, 0) ) {
			printf("Clear Screen fail!!!\n");
			exit(1);
		}
		printf("Clear Screen!\n");
		
		disp_xy.x = atoi(argv[2]);
		disp_xy.y = atoi(argv[3]);
		disp_xy.img_buf = (unsigned short *)&bf[0][0];

		if( ioctl(decfd2, DISPLAY_IMG_DRAW, &disp_xy) ) {
			printf("Draw Image to Monitor -> fail!!!\n");
			exit(1);
		}
		printf("1. Draw Image to Monitor!\n");

		printf("\nPress Enter Key to load image again !!!");
		ch = getchar();

		if ( ioctl(decfd2, RD_IMG_DATA, &bf) ) {
			printf("ioctl RD_IMG_DATA error\n");
			exit(1);
		}
		printf("Image Load from FPGA!\n");
		
		if ( ioctl(decfd2, DISPLAY_RESOLUTION, SCREEN_640_480) ) {
			printf("Resolution set fail!!!\n");
			exit(1);
		}
		printf("Resolution set complete!\n");

		disp_xy.x = atoi(argv[2])+180;
		disp_xy.y = atoi(argv[3]);
		disp_xy.img_buf = (unsigned short *)&bf[0][0];

		if( ioctl(decfd2, DISPLAY_IMG_DRAW, &disp_xy) ) {
			printf("Draw Image to Monitor -> fail!!!\n");
			exit(1);
		}
		printf("2. Draw Image to Monitor!\n");
		
	}
	else {
		printf("Usage 1 : imgproc_test -rd     <Read Image Data>\n");
		printf("Usage 2 : saa7111_test -dp  <Display to Monitor>\n");
		printf("Usage 3 : imgproc_test -xy     [x coordinate] [y coordinate]\n");
		exit(-1);
	}
	
	uart_close();
	close(decfd2);

	return(0);
}