int send_command(int instance, char * command_ptr, int byteCountBuff, int wait_time,char * response,int recieve_size){
	PRINTF("\r\nInside send command\r\n");
	int i =0, x;
	for(x=0;x<200;x++)
		response[x]=0;
	UART_DRV_SendDataBlocking(instance, command_ptr, byteCountBuff, wait_time);
	printf("Sent\r\n");
	printf("Size of response1 %d\r\n",sizeof(response));
	returnValue = UART_DRV_ReceiveDataBlocking (instance,response,recieve_size,wait_time);//Buffer size in bytes to accept all of the me
	printf("Size of response2 %d\r\n",sizeof(response));
	if(returnValue == kStatus_UART_Success){
		PRINTF("Fn Recieved:\r\n");
		while(response[i] != '\0')
		{
			 PRINTF("%c",response[i]);
			 i++;
		}
		PRINTF("\r\n");

		if(strstr(*response,"OK") || strstr(*response,">") || strstr(*response,"+CMSG:")  == 0){
			printf("Response matches\r\n");
			return 0;
		}

		 //return -2;
	}
}
コード例 #2
0
ファイル: task_lpm.c プロジェクト: kylemanna/kinetis-sdk1
/*!
 * @brief get input charater.
 *
 */
char getInput()
{
    char ch;
    /* We use GETCHAR() for BM and UART Blocking technic for other RTOS. */
#if (defined FSL_RTOS_BM) || ((defined FSL_RTOS_MQX)&&(MQX_COMMON_CONFIG != MQX_LITE_CONFIG))
    ch = GETCHAR();
#else
    UART_DRV_ReceiveDataBlocking(BOARD_DEBUG_UART_INSTANCE, (uint8_t*)(&ch), 1, OSA_WAIT_FOREVER);
#endif // FSL_RTOS_BM
    return ch;
}
コード例 #3
0
ファイル: nio_serial.c プロジェクト: nevinxu/HM502B2
static int nio_serial_read(void *dev_context, void *fp_context, void *buf, size_t nbytes)
{

    NIO_SERIAL_DEV_CONTEXT_STRUCT *serial_dev_context = (NIO_SERIAL_DEV_CONTEXT_STRUCT *)dev_context;
    #if PLATFORM_LPUART_ENABLED
    if (kStatus_UART_Success != LPUART_DRV_ReceiveDataBlocking(serial_dev_context->instance, buf, nbytes, OSA_WAIT_FOREVER))
    #else
    if (kStatus_UART_Success != UART_DRV_ReceiveDataBlocking(serial_dev_context->instance, buf, nbytes, OSA_WAIT_FOREVER))
    #endif
    {
        errno = EIO;
    }
    return (nbytes - serial_dev_context->uart_state.rxSize);
}
int main(void)
{
	uart_state_t uartState; // user provides memory for the driver state structure
	uart_user_config_t uartConfig;
	long int x;

	char AT[] = "\nAT";
	char rxBuff[10];
	uint32_t byteCountBuff = 0;
    //Initialise the FRDM-KL26Z Board
	hardware_init();
	configure_uart_pins(0);	//instance 0 is UART1???
	// Call OSA_Init to setup LP Timer for timeout
	OSA_Init();


	uartConfig.baudRate = 9600;
	uartConfig.bitCountPerChar = kUart8BitsPerChar;
	uartConfig.parityMode = kUartParityDisabled;
	uartConfig.stopBitCount = kUartOneStopBit;

	UART_DRV_Init(1, &uartState,&uartConfig);

	//Print message to serial terminal
	PRINTF("First Embedded Systems Lab_Aonghus\r\n");
	PRINTF("Type a character and it will be echoed back\r\n\n");
	int i = 0;
	byteCountBuff = sizeof(AT);
    while(1) {
    	//UART_DRV_SendDataBlocking(1, AT, byteCountBuff, 16000u);
    	 while(UART_DRV_ReceiveDataBlocking ( 1, rxBuff, sizeof(rxBuff),16000u) == kStatus_UART_Success )
    	 {
    		 for(i=0;i<sizeof(rxBuff);i++)
    		 PRINTF("%c",rxBuff[i]);
    	 }
    	// if(UART_DRV_GetTransmitStatus (1,sizeof(rxBuff)) == kStatus_UART_Success ){

    	// }


    	for(x=0;x<10000000;x++);
    }
    /* Never leave main */
    return 0;
}
コード例 #5
0
ファイル: MicoDriverUart.c プロジェクト: 70year/MICO
static OSStatus platform_uart_receive_bytes( mico_uart_t uart, void* data, uint32_t size, uint32_t timeout )
{
    uart_status_t retVal = kStatus_UART_Success;
    uart = MICO_UART_1; //test
  /* Reset DMA transmission result. The result is assigned in interrupt handler */
#if ADD_OS_CODE
   uart_interfaces[uart].rx_dma_result = kGeneralErr;
#endif
#ifdef UART_IRQ_APP   
   retVal = UART_DRV_ReceiveDataBlocking(BOARD_APP_UART_INSTANCE, data, size, timeout);
  // if(UART_DRV_ReceiveData(BOARD_APP_UART_INSTANCE, data,size )==kStatus_UART_Success){  
#else   
  //  if(UART_DRV_EdmaReceiveData(BOARD_DEBUG_UART_INSTANCE, data, size)==kStatus_UART_Success){
   retVal = UART_DRV_EdmaReceiveDataBlocking(BOARD_APP_UART_INSTANCE, data, size, timeout);//
#endif
   if(retVal == kStatus_UART_Success) { 
#if ADD_OS_CODE
        #ifndef NO_MICO_RTOS
            mico_rtos_set_semaphore( &uart_interfaces[uart].rx_complete );
        #else
            uart_interfaces[uart ].rx_complete = true;
        #endif
#endif
  return kNoErr;
    }
  if ( timeout > 0 )
   {
#if ADD_OS_CODE
#ifndef NO_MICO_RTOS
    mico_rtos_get_semaphore( &uart_interfaces[uart].rx_complete, timeout );
#else
    uart_interfaces[uart].rx_complete = false;
    int delay_start = mico_get_time_no_os();
    while(uart_interfaces[uart].rx_complete == false){
      if(mico_get_time_no_os() >= delay_start + timeout && timeout != MICO_NEVER_TIMEOUT){
        break;
      }
    }    
#endif
    return uart_interfaces[uart].rx_dma_result;
#endif
  }   
  return kGeneralErr;              // kNoErr;
}
コード例 #6
0
ファイル: hello_world.c プロジェクト: martinmarcos/Firmware
int main (void)
{
    /***************************************************************************
     *  RX buffers
     **************************************************************************/
    /*! @param receiveBuff Buffer used to hold received data */
    uint8_t receiveBuff[19] = {0};

    /* Initialize standard SDK demo application pins */
    hardware_init();

    /* Configure the UART TX/RX pins */
    configure_uart_pins(BOARD_DEBUG_UART_INSTANCE);

#ifdef USE_STDIO_FUNCTIONS
    /* Call this function to initialize the console UART.  This function
       enables the use of STDIO functions (printf, scanf, etc.) */
    dbg_uart_init();
    
    /*  Print the initial banner */
    printf("\r\nHello World!\n\n\r");

    while(1)
    {
        /********************************************
         * Main routine that simply echoes received
         * characters forever
         *********************************************/

        /* First, get character.  */
        receiveBuff[0] = getchar();
        
        /* Now echo the received character */
        putchar(receiveBuff[0]);
    }
#else
    /***************************************************************************
     * UART configuration and state structures
     **************************************************************************/
    /*! @param uartConfig UART configuration structure */
    /*! @param uartState UARt state structure which is used internally by the*/
    /*! by the UART driver to keep track of the UART states */
    uart_user_config_t uartConfig;
    uart_state_t uartState;
    
    /***************************************************************************
     *  TX buffers
     **************************************************************************/
    /*! @param sourceBuff Buffer used to hold the string to be transmitted */
    uint8_t sourceBuff[19] = {"\r\nHello World!\n\n\r"};
    
    /* Configure the UART for 115200, 8 data bits, No parity, and one stop bit*/
    uartConfig.baudRate = 115200;
    uartConfig.bitCountPerChar = kUart8BitsPerChar;
    uartConfig.parityMode = kUartParityDisabled;
    uartConfig.stopBitCount = kUartOneStopBit;
    
    /* Must call the OSA Init function to use Communication drivers */
    OSA_Init();
    
    /* Initialize the UART module */
    UART_DRV_Init(BOARD_DEBUG_UART_INSTANCE, &uartState, &uartConfig);
    
    /*  Print the initial banner */
    UART_DRV_SendDataBlocking(BOARD_DEBUG_UART_INSTANCE, sourceBuff, 17, 200);

    while(1)
    {
        /********************************************
         * Main routine that simply echoes received
         * characters forever
         *********************************************/

        /* First, get character.  */
        UART_DRV_ReceiveDataBlocking(BOARD_DEBUG_UART_INSTANCE, receiveBuff, 1, 
                                     OSA_WAIT_FOREVER);

        /* Now, stuff the buffer for the TX side and send the character*/
        sourceBuff[0] = receiveBuff[0];

        /* Now echo the received character */
        UART_DRV_SendDataBlocking(BOARD_DEBUG_UART_INSTANCE, sourceBuff, 1, 
                                  200);
    }
#endif
}