Esempio n. 1
0
// -----------------------------------------------------------------------------
//! \brief      This routine initializes the transport layer and opens the port
//!             of the device.
//!
//! \param[in]  tRxBuf - pointer to SDI TL Tx Buffer
//! \param[in]  tTxBuf - pointer to SDI TL Rx Buffer
//! \param[in]  sdiCBack - SDI TL call back function to be invoked at the end of 
//!             a UART transaction                     
//!
//! \return     void
// -----------------------------------------------------------------------------
void SDITLUART_initializeTransport(Char *tRxBuf, Char *tTxBuf, sdiCB_t sdiCBack)
{
    // Set UART transport callbacks
    TransportRxBuf = tRxBuf;
    TransportTxBuf = tTxBuf;
    sdiTransmitCB = sdiCBack;

    // Configure UART parameters.
    UART_Params_init(&paramsUART);
    paramsUART.baudRate = SDI_UART_BR;
    paramsUART.readDataMode = UART_DATA_BINARY;
    paramsUART.writeDataMode = UART_DATA_BINARY;
    paramsUART.dataLength = UART_LEN_8;
    paramsUART.stopBits = UART_STOP_ONE;
    paramsUART.readMode = UART_MODE_CALLBACK;
    paramsUART.writeMode = UART_MODE_CALLBACK;
    paramsUART.readEcho = UART_ECHO_OFF;

    paramsUART.readCallback = SDITLUART_readCallBack;
    paramsUART.writeCallback = SDITLUART_writeCallBack;

    //paramsUART.readReturnMode = UART_RETURN_FULL;
    
    // Open / power on the UART.
    uartHandle = UART_open(Board_UART, &paramsUART);
    if(uartHandle != NULL)
    {
      //DEBUG("ERROR in UART_open");
    }
    //Enable Partial Reads on all subsequent UART_read()
    UART_control(uartHandle, UARTCC26XX_RETURN_PARTIAL_ENABLE,  NULL);

    return;
}
Esempio n. 2
0
Void Task_UART(UArg arg0, UArg arg1)
{
    UART_Handle uart;
    UART_Params uartParams;
    const char echoPrompt[] = "\fEchoing characters:\r\n";
    char input;    
    
    UART_Params_init(&uartParams);
    uartParams.writeMode = UART_MODE_BLOCKING;
    uartParams.readMode = UART_MODE_BLOCKING;
    uartParams.writeDataMode = UART_DATA_BINARY;
    uartParams.readDataMode = UART_DATA_BINARY;
    uartParams.readReturnMode = UART_RETURN_FULL;
    uartParams.readEcho = UART_ECHO_OFF;
    uartParams.baudRate = 115200;
    uartParams.parityType = UART_PAR_NONE;
    uartParams.dataLength = UART_LEN_8;
    uartParams.stopBits = UART_STOP_ONE;
    
    uart = UART_open(Board_UART0, &uartParams);
    if (uart == NULL) {
        System_abort("Error opening the UART");
    }

    System_printf("\nTask_UART");
    UART_write(uart, echoPrompt, sizeof(echoPrompt));
    
    // Loop forever echoing 
    while (1) {
        UART_read(uart, &input, 1);
        input++;
        UART_write(uart, &input, 1);
    }
}
Esempio n. 3
0
/*********************************************************************
 * @fn      rpcTransportOpen
 *
 * @brief   opens the serial port to the CC253x.
 *
 * @param   devicePath - path to the UART device
 *
 * @return  status
 */
int32_t rpcTransportOpen(char *_devicePath, uint32_t port)
{
	UART_Params uartParams;
	int32_t ret = -1;

	if (uart == NULL)
	{
		/* Create a UART with data processing off. */
		UART_Params_init(&uartParams);
		uartParams.readMode = UART_MODE_BLOCKING;
		uartParams.writeMode = UART_MODE_BLOCKING;
		uartParams.readTimeout = BIOS_WAIT_FOREVER;
		uartParams.writeTimeout = BIOS_WAIT_FOREVER;
		uartParams.readCallback = NULL;
		uartParams.writeCallback = NULL;
		uartParams.readReturnMode = UART_RETURN_FULL;
		uartParams.writeDataMode = UART_DATA_BINARY;
		uartParams.readDataMode = UART_DATA_BINARY;
		uartParams.readEcho = UART_ECHO_OFF;
		uartParams.baudRate = 115200;
		uartParams.dataLength = UART_LEN_8;
		uartParams.stopBits = UART_STOP_ONE;
		uartParams.parityType = UART_PAR_NONE;

		// init UART driver
		uart = UART_open(EK_TM4C1294XL_UART4, &uartParams);
		if (uart != NULL)
		{
			// return success
			ret = 0;
		}
	}

	return ret;
}
Esempio n. 4
0
uint8 SDITLUART_configureUARTParams(UART_Params *initParams)
{ 
  uint8 status = SUCCESS;
  ICall_CSState key;
  
  SDITLUART_closeUART();
  
  key = ICall_enterCriticalSection();
  
  // Open / power on the UART.
  uartHandle = UART_open(Board_UART, &paramsUART);
  if(uartHandle != NULL)
  {
    //DEBUG("UART_open successful");
  }else{
    //DEBUG("ERROR in UART_open");
    status = FAILURE;
  }
 
  //Enable Partial Reads on all subsequent UART_read()
  status = UART_control(uartHandle, UARTCC26XX_RETURN_PARTIAL_ENABLE,  NULL);
  
  ICall_leaveCriticalSection(key);
  
  #ifndef POWER_SAVING
    //Initiate first read to start polling UART
    SDITLUART_readTransport();
  #endif //POWER_SAVING
  
  return status;
}
Esempio n. 5
0
void cmdTerp() {
	UART_Handle uart;
	UART_Params uartParams;

	UART_Params_init(&uartParams);
	uartParams.writeDataMode = UART_DATA_BINARY;
	uartParams.readDataMode = UART_DATA_BINARY;
	uartParams.readReturnMode = UART_RETURN_FULL;
	uartParams.readEcho = UART_ECHO_OFF;
	uartParams.baudRate = 9600;
	uart = UART_open(Board_UART1, &uartParams);
	globalUART = &uart;

	if (uart == NULL) {
	        System_abort("Error opening the UART");
	}

	char input[2];
	uint8_t duty;

	while(1) {
		UART_write(uart,">",1);
		UART_read(uart,input,1);
		UART_write(uart,input,1);

		cmdExecute(input,duty);
	}
}
// -----------------------------------------------------------------------------
//! \brief      This routine initializes the transport layer and opens the port
//!             of the device.
//!
//! \param[in]  tRxBuf - pointer to NPI TL Tx Buffer
//! \param[in]  tTxBuf - pointer to NPI TL Rx Buffer
//! \param[in]  npiCBack - NPI TL call back function to be invoked at the end of 
//!             a UART transaction                     
//!
//! \return     void
// -----------------------------------------------------------------------------
void NPITLUART_initializeTransport(Char *tRxBuf, Char *tTxBuf, npiCB_t npiCBack)
{
    UART_Params params;

    TransportRxBuf = tRxBuf;
    TransportTxBuf = tTxBuf;
    npiTransmitCB = npiCBack;

    // Configure UART parameters.
    UART_Params_init(&params);
    params.baudRate = NPI_UART_BR;
    params.readDataMode = UART_DATA_BINARY;
    params.writeDataMode = UART_DATA_BINARY;
    params.dataLength = UART_LEN_8;
    params.stopBits = UART_STOP_ONE;
    params.readMode = UART_MODE_CALLBACK;
    params.writeMode = UART_MODE_CALLBACK;
    params.readEcho = UART_ECHO_OFF;

    params.readCallback = NPITLUART_readCallBack;
    params.writeCallback = NPITLUART_writeCallBack;

    // Open / power on the UART.
    uartHandle = UART_open(Board_UART, &params);
    //Enable Partial Reads on all subsequent UART_read()
    UART_control(uartHandle, UARTCC26XX_CMD_RETURN_PARTIAL_ENABLE,  NULL);

    
#ifndef POWER_SAVING
    // This call will start repeated Uart Reads when Power Savings is disabled
    NPITLUART_readTransport();
#endif //!POWER_SAVING
    
    return;
}
/*
 *  ======== echoFxn ========
 *  Task for this function is created statically. See the project's .cfg file.
 */
Void echoFxn(UArg arg0, UArg arg1)
{
    char input;
    UART_Handle uart;
    UART_Params uartParams;
    const char echoPrompt[] = "\fEchoing characters:\r\n";

    /* Create a UART with data processing off. */
    UART_Params_init(&uartParams);
    uartParams.writeDataMode = UART_DATA_BINARY;
    uartParams.readDataMode = UART_DATA_BINARY;
    uartParams.readReturnMode = UART_RETURN_FULL;
    uartParams.readEcho = UART_ECHO_OFF;
    uartParams.baudRate = 9600;
    uart = UART_open(Board_UART0, &uartParams);

    if (uart == NULL) {
        System_abort("Error opening the UART");
    }

    UART_write(uart, echoPrompt, sizeof(echoPrompt));

    /* Loop forever echoing */
    while (1) {
        UART_read(uart, &input, 1);
        UART_write(uart, &input, 1);
    }
}
Esempio n. 8
0
/**
 * @fn      SBL_TL_open
 *
 * @brief   Open device port for communication with the target device. Currently
 *          only supports UART                
 *
 * @param   pType - SBL_DEV_INTERFACE_[UART,SPI]
 * @param   pID - local serial interface ID (i.e. CC2650_UART0)
 *
 * @return  uint8_t - SBL_SUCCESS, SBL_FAILURE
 */
uint8_t SBL_TL_open(uint8_t pType, uint8_t pID)
{
  UART_Params params;
  
  // Currently only support over UART
  if (pType == SBL_DEV_INTERFACE_UART)
  {
    // Configure UART parameters.
    // No parity bit, One stop bit set by default
    UART_Params_init(&params);
    params.baudRate = SBL_UART_BR;
    params.readDataMode = UART_DATA_BINARY;
    params.writeDataMode = UART_DATA_BINARY;
    params.readEcho = UART_ECHO_OFF;
    
    // Open UART port for sending SBL commands
    sblUartHandle = UART_open(pID, &params);
    if (sblUartHandle == NULL)
    {
      return SBL_FAILURE;
    }

    // Work around for UART driver re-open bug. Sometimes there is a mystery byte already
    // read prior to sending any commands to the target device
    UARTCharGetNonBlocking(((UARTCC26XX_HWAttrsV1 const *)(sblUartHandle->hwAttrs))->baseAddr);
    
    return SBL_SUCCESS;
  }

  return SBL_FAILURE;
}
/*********************************************************************
 * @fn      Board_openLCD
 *
 * @brief   Open the UART port and initialize Log callback plugin.
 *
 * @param   none
 *
 * @return  void
 */
void Board_openLCD(void)
{
    UART_Params uartParams;
    UART_Params_init(&uartParams);
    uartParams.baudRate = 115200;
    UART_Handle hUart = UART_open(Board_UART, &uartParams);
    
    UartLog_init(hUart);
}
Esempio n. 10
0
int8_t BtStack_push(const BtStack_Frame* frame)
{
	// special character declarations
	const char escapedEnd[] = {SLIP_ESC, SLIP_ESC_END};	// escaped 0xC0
	const char escapedEsc[] = {SLIP_ESC, SLIP_ESC_ESC};	// escaped 0xDB

	char sendStream[KFP_WORST_SIZE];
	uint8_t sentChar = 0;

	// append start character
	sendStream[0] = SLIP_END;
	sentChar++;

	// iterate through frame adding ESC characters where necessary
	uint8_t i;
	for (i=0; i<KFP_FRAME_SIZE-2; i++)
	{
		switch(frame->b8[i])
		{
		case(SLIP_END):
				// escape END character
				strncat(sendStream, escapedEnd, 2);
				sentChar+=2;
				break;
		case(SLIP_ESC):
				// escape ESC character
				strncat(sendStream, escapedEsc, 2);
				sentChar+=2;
				break;
		default:
				sendStream[sentChar] = frame->b8[i];
				sentChar++;
		}
	}

	// append end character
	sendStream[sentChar] = SLIP_END;
	sentChar++;

	// prepare UART socket
	UART_Handle s;
	UART_Params params;
	UART_Params_init(&params);
	params.baudRate = uartBaud;
	params.writeMode = UART_MODE_BLOCKING;
	params.writeDataMode = UART_DATA_BINARY;
	params.readDataMode = UART_DATA_BINARY;
	params.readReturnMode = UART_RETURN_FULL;
	params.readEcho = UART_ECHO_OFF;
	s = UART_open(Board_BT1, &params);

	// write to socket and close once complete
	int8_t ret = UART_write(s, sendStream, sentChar);
	UART_close(s);

	return ret;
}
Esempio n. 11
0
/*
 *  ======== Board_openUART ========
 *  Initialize the UART driver.
 *  Initialize the UART port's pins.
 *  Open the UART port.
 */
UART_Handle  Board_openUART(UInt uartPortIndex, UART_Params *uartParams)
{
    /* Initialize the UART driver */
    /* By design, UART_init() is idempotent */
    UART_init();

    /* initialize the pins associated with the respective UART */
    switch(uartPortIndex) {
        case 0:
            /* Serial */
            /* enable UART1 clock */
            MAP_PRCMPeripheralClkEnable(PRCM_UARTA1, PRCM_RUN_MODE_CLK);

            /*
             * Configure LaunchPad P2.9 as a UART1: UART1 TX (via USB port)
             *     device pin: 55 (UART1_TX)
             *     Wiring id : 12
             */
            MAP_PinTypeUART(PIN_55, PIN_MODE_6);

            /*
             * Configure LaunchPad P3.3 as a UART1: UART1 RX (via USB port)
             *     device pin: 57 (UART1_RX)
             *     Wiring id : 23
             */
            MAP_PinTypeUART(PIN_57, PIN_MODE_6);
            break;

        case 1:
            /* Serial1 */
            /* enable UART0 clock */
            MAP_PRCMPeripheralClkEnable(PRCM_UARTA0, PRCM_RUN_MODE_CLK);

            /*
             * Configure LaunchPad P1.4 as a UART0: UART0 TX
             *     device pin: 3 (UART0_TX)
             *     Wiring id : 4
             */
            MAP_PinTypeUART(PIN_03, PIN_MODE_7);

            /*
             * Configure LaunchPad P1.3 as a UART0: UART0 RX
             *     device pin: 4 (UART0_RX)
             *     Wiring id : 3
             */
            MAP_PinTypeUART(PIN_04, PIN_MODE_7);
            break;

        default:
            return (NULL);
    }

    /* open the UART */
    return (UART_open(uartPortIndex, uartParams));
}
// -----------------------------------------------------------------------------
//! \brief      This routine initializes the transport layer and opens the port
//!             of the device.
//!
//! \param[in]  portID      ID value for board specific UART port
//! \param[in]  portParams  Parameters used to initialize UART port
//! \param[in]  npiCBack    Trasnport Layer call back function  
//!
//! \return     void
// -----------------------------------------------------------------------------
void NPITLUART_openTransport(uint8_t portID, UART_Params *portParams,
                             npiCB_t npiCBack)
{
  npiTransmitCB = npiCBack;

  // Add call backs UART parameters.
  portParams->readCallback = NPITLUART_readCallBack;
  portParams->writeCallback = NPITLUART_writeCallBack;

  // Open / power on the UART.
  uartHandle = UART_open(portID, portParams);
}
/*******************************************************************************
 * @fn          Main
 *
 * @brief       Application Main
 *
 * input parameters
 *
 * @param       None.
 *
 * output parameters
 *
 * @param       None.
 *
 * @return      None.
 */
int main()
{
#ifdef CACHE_AS_RAM
  // Invalidate cache
  VIMSModeSet( VIMS_BASE, VIMS_MODE_DISABLED );
  // Wait for disabling to be complete
  while ( VIMSModeGet( VIMS_BASE ) != VIMS_MODE_DISABLED );  
  // retain cache during standby
  Power_setConstraint(PowerCC26XX_SB_VIMS_CACHE_RETAIN);
#endif  
  
  RegisterAssertCback(AssertHandler);
  
  PIN_init(BoardGpioInitTable);
  
#ifndef POWER_SAVING
  /* Set constraints for Standby, powerdown and idle mode */
  Power_setConstraint(PowerCC26XX_SB_DISALLOW);
  Power_setConstraint(PowerCC26XX_IDLE_PD_DISALLOW);
#endif //POWER_SAVING
  

#ifdef PRINTF_ENABLED
  // Enable System_printf(..) UART output
    UART_Params uartParams;
    UART_Params_init(&uartParams);
    uartParams.baudRate = 1000000;
    UartPrintf_init(UART_open(Board_UART, &uartParams));

    System_printf("Printf enabled\r\n");
#endif
  /* Initialize ICall module */
  ICall_init();
  
  /* Start tasks of external images - Priority 5 */
  ICall_createRemoteTasks();
  
  /* Kick off profile - Priority 3 */
  GAPRole_createTask();
  
  Keys_createTask();

  /* Kick off application - Priority 1 */
  SimpleTopology_createTask();
  

  /* enable interrupts and start SYS/BIOS */
  BIOS_start();
  
  return 0;
}
Esempio n. 14
0
/*
 *  ======== main ========
 */
int main()
{
  PIN_init(BoardGpioInitTable);

#ifndef POWER_SAVING
    /* Set constraints for Standby, powerdown and idle mode */
    Power_setConstraint(Power_SB_DISALLOW);
    Power_setConstraint(Power_IDLE_PD_DISALLOW);
#endif // POWER_SAVING

    /* Initialize ICall module */
    ICall_init();

    /* Start tasks of external images - Priority 5 */
    ICall_createRemoteTasks();

#ifdef PRINTF_ENABLED
    // Enable System_printf(..) UART output
    UART_Params uartParams;
    UART_Params_init(&uartParams);
    uartParams.baudRate = 921600;
    UartPrintf_init(UART_open(Board_UART, &uartParams));
#endif
    /* Kick off profile - Priority 3 */
    GAPRole_createTask();
    
    SimpleBLEPeripheral_createTask();

#ifdef FEATURE_OAD
    {
      uint8_t counter;
      uint32_t *vectorTable =  (uint32_t*) 0x20000000;
#if defined(__IAR_SYSTEMS_ICC__)
      uint32_t *flashVectors = &__vector_table;
#elif defined(__TI_COMPILER_VERSION__)
      uint32_t *flashVectors = &ti_sysbios_family_arm_m3_Hwi_resetVectors;
#endif //Compiler.
      
      // Write image specific interrupt vectors into RAM vector table.
      for(counter = 0; counter < 15; ++counter)
      {
        *vectorTable++ = *flashVectors++;
      }
    }
#endif //FEATURE_OAD
    
    /* enable interrupts and start SYS/BIOS */
    BIOS_start();
    
    return 0;
}
Esempio n. 15
0
// -----------------------------------------------------------------------------
//! \brief      This routine initializes the transport layer and opens the port
//!             of the device.
//!
//! \param[in]  portID      ID value for board specific UART port
//! \param[in]  portParams  Parameters used to initialize UART port
//! \param[in]  npiCBack    Transport Layer call back function
//!
//! \return     void
// -----------------------------------------------------------------------------
void NPITLUART_openTransport(uint8_t portID, UART_Params *portParams,
                             npiCB_t npiCBack)
{
    npiTransmitCB = npiCBack;

    // Add call backs UART parameters.
    portParams->readCallback = NPITLUART_readCallBack;
    portParams->writeCallback = NPITLUART_writeCallBack;

    // Open / power on the UART.
    uartHandle = UART_open(portID, portParams);
    //Enable Partial Reads on all subsequent UART_read()
    UART_control(uartHandle, UARTCC26XX_CMD_RETURN_PARTIAL_ENABLE,  NULL);
}
Esempio n. 16
0
/**
 * usage: this method does the work, checkes the queue, writes to the UART and post's
 * 		  the Event
 * @method uart_method
 * @author: patrik.szabo
 * @param arg0 - not used param for the task
 * @return *none*
 */
void uart_method(UArg arg0) {

	// char input;
	UART_Handle uart;
	UART_Params uartParams;

	/* Create a UART with data processing off. */
	UART_Params_init(&uartParams);
	uartParams.writeDataMode = UART_DATA_BINARY;
	uartParams.readDataMode = UART_DATA_BINARY;
	uartParams.readReturnMode = UART_RETURN_FULL;
	uartParams.readEcho = UART_ECHO_OFF;
	uartParams.baudRate = 9600;
	uart = UART_open(Board_UART0, &uartParams);

	if (uart == NULL) {
		System_abort("Error opening the UART");
	}

	QueueObject* queueObjectPointer;

	char altData[22] = "";
	char pressData[16] = "";
	char tempData[18] = "";

	while (1) {
		while (!Queue_empty(uartQueue)) {
			queueObjectPointer = Queue_dequeue(uartQueue);
			sprintf(altData, "Altitude: %d | ",
					(int) queueObjectPointer->myInformationPointer->alt);
			System_printf("%s", altData);
			UART_write(uart, altData, sizeof(altData));
			sprintf(pressData, "Pressure: %d | ",
					queueObjectPointer->myInformationPointer->press);
			System_printf("%s", pressData);
			UART_write(uart, pressData, sizeof(pressData));
			sprintf(tempData, "Temparature: %d\n\r",
					queueObjectPointer->myInformationPointer->temp);
			System_printf("%s", tempData);
			UART_write(uart, tempData, sizeof(tempData));
			Event_post(uartReadyEvent, Event_Id_02);
		}
		Task_sleep(500);
	}
}
Esempio n. 17
0
// Main entry point
void main(void)
{
  Uint32 status;

  // Give some time for host to become ready
  UTIL_waitLoop(100000);
  
  // Set RAM pointer to beginning of RAM space
  UTIL_setCurrMemPtr(0);
  
  // Init device PLLs, PSCs, external memory, etc.
  status = DEVICE_init();
  
  // Open UART peripheral for sending out status
  if (status == E_PASS)
  {
    DEVICE_UARTInit(DEVICE_UART_PERIPHNUM);
    hUartInfo = UART_open(DEVICE_UART_PERIPHNUM, hDEVICE_UART_config);
    //DEBUG_printString((String) devString);
    //DEBUG_printString(" initialization passed!\r\n");
  }
  else
  {
    return;
  }
  // Send some information to host
  //DEBUG_printString("TI SFT Version: ");
  //DEBUG_printString(SFT_VERSION_STRING);
  //DEBUG_printString("\r\n");
  
  // Perform UART boot (always assume UART boot since this is only used for serial flashing)
  UARTBOOT_copy();
    
  //DEBUG_printString("   DONE");
  
  //UTIL_waitLoop(10000);

  // FIXME: This should bre replaced with DEVICE_finalize()
  DEVICE_TIMER0Stop();

  // Jump to entry point
  APPEntry = (void (*)(void)) gEntryPoint;
  (*APPEntry)();
}
Esempio n. 18
0
int rs485_init()
{
	UART_Params_init(&uartParams);
	uartParams.writeDataMode = UART_DATA_BINARY  ;
	uartParams.readDataMode = UART_DATA_BINARY  ;
	uartParams.readReturnMode = UART_RETURN_FULL;
	uartParams.readEcho = UART_ECHO_OFF;
	uartParams.baudRate = rs485_baudRate;
	uartParams.readTimeout = rs485_timeout;

	uart2 = UART_open(Board_UART2, &uartParams);

	if (uart2 == NULL ) {
		System_abort("Error opening the UART2");
		return 1;
		}

	return 0;
}
Esempio n. 19
0
void fes1_entry(void)
{
	cpu_init_s();
	timer_init();

    UART_open( fes1_head.prvt_head.uart_port, (void *)fes1_head.prvt_head.uart_ctrl, 24*1000*1000 );
	UART_printf2("begin init dram\n");
	if(init_DRAM(0, (void *)fes1_head.prvt_head.dram_para))
	{
		note_dram_log();
		UART_printf2("init dram ok\n");
	}
	else
	{
	    UART_printf2("init dram fail\n");
	}
	__msdelay(10);

    return;
}
Esempio n. 20
0
/*!
 *  @brief  Opens the UART console
 *
 *  @param  binary Open the UART in binary mode
 *  @return        UART_Handle to the opened UART
 */
UART_Handle UARTConsole_open(bool binary)
{
	UART_Params uartParams;

	/* Create a UART with the parameters below. */
	UART_Params_init(&uartParams);
	if (binary == true)
	{
		uartParams.readEcho = UART_ECHO_OFF;
		uartParams.writeDataMode = UART_DATA_BINARY;
	}
	else
	{
		uartParams.baudRate = 115200;
	}

	handle = UART_open(Board_UART0, &uartParams);

	return (handle);
}
Esempio n. 21
0
/*
 *  ======== openHandle ========
 *  The UART driver will return NULL if there was an error creating a UART 
 *
 *  @param  index  Index into the ports array of UARTPorts
 *  @param  binary Open the UART in binary mode
 *  @return        UART_Handle to the opened UART
 */
static UART_Handle openHandle(Int index, Bool binary)
{
    UART_Params uartParams;
    
    /* Only UART 0 is supported in this example. */
    if (index >= NUM_PORTS) {
        System_printf("UART index %d not supported, valid range is 0-%d", index, (NUM_PORTS - 1));
        return (NULL);
    }

    /* The UART driver only allows creating once, return if its already open. */
    if (ports[index].open) {
        /* Make sure the index is not already opened in the wrong mode */
        if (binary != ports[index].binary) {
            return (NULL);
        }
        ports[index].open++;
        return (ports[index].handle);
    }

    /* Create a UART with the parameters below. */
    UART_Params_init(&uartParams);
    if (binary == TRUE) {
        uartParams.readEcho = UART_ECHO_OFF;
        uartParams.writeDataMode = UART_DATA_BINARY;
        ports[index].binary = TRUE;
    }
    else {
        ports[index].binary = FALSE;
        uartParams.baudRate = 115200;
    }
    ports[index].handle = UART_open(ports[index].base, &uartParams);
    if (ports[index].handle != NULL) {
        ports[index].open = 1;
    }
    
    return (ports[index].handle);
}
static void cli_uart_init(UART_SerialDevice *dev) {
	static UART_Params uartParams;

	if(uart == NULL)
	{
		/* Create a UART with data processing off. */
		UART_Params_init(&uartParams);
		uartParams.writeDataMode = UART_DATA_BINARY;
		uartParams.readDataMode = UART_DATA_BINARY;
		uartParams.readReturnMode = UART_RETURN_FULL;
		uartParams.writeMode = UART_MODE_BLOCKING;
		uartParams.readEcho = UART_ECHO_OFF;
		uartParams.baudRate = 57600;
		uart = UART_open(CLI_UART, &uartParams);

		if (uart == NULL) {
			System_abort("Error opening the UART");
		}

		dev->fntab = &UART_SerialDevice_fntab;
		dev->uart = uart;
	}
}
int sim800_open(){

	UART_Params_init(&uartParams);
	uartParams.writeDataMode = UART_DATA_BINARY;
	uartParams.readDataMode = UART_DATA_BINARY;
	uartParams.readReturnMode = UART_RETURN_FULL;
	uartParams.readTimeout = SIM800_READ_TIMEOUT;
	uartParams.readEcho = UART_ECHO_OFF;
	uartParams.baudRate = SIM800_BAUD_RATE;

	uart = UART_open(Board_UART2_COMM, &uartParams);

	if (uart == NULL) {

		//debug
		GPIO_toggle(Board_LED_GREEN);
		Task_sleep(300);
		GPIO_toggle(Board_LED_GREEN);

		return 0;
	}else{
		return 1;
	}
}
Esempio n. 24
0
void rxFxn(UArg param0, UArg param1)
{
	// Declare state variables
	Bool inFrame = FALSE;
	uint8_t frIndex = 0;

	// Buffers
	char tempRx[1];
	BtStack_Frame tempFr;

	while(TRUE)
	{
		// open socket
		UART_Handle s;
		UART_Params params;
		UART_Params_init(&params);
		params.baudRate = uartBaud;
		params.writeDataMode = UART_DATA_BINARY;
		params.readMode = UART_MODE_BLOCKING;
		params.readDataMode = UART_DATA_BINARY;
		params.readReturnMode = UART_RETURN_FULL;
		params.readEcho = UART_ECHO_OFF;
		s = UART_open(Board_BT1, &params);

		// read UART buffer and decode
		UART_read(s, tempRx, 1);
		switch(tempRx[0])
		{
		case(SLIP_END):
				if (inFrame)
				{
					if (frIndex == (KFP_FRAME_SIZE-2))
					{
						// end of frame, call callback to interpret it
						if (rxCallback != NULL)
						{
							rxCallback(&tempFr);
						}
					}

					// ignore corrupt frames
					frIndex = 0;
					inFrame = FALSE;

					break;
				}
				else
				{
					inFrame = TRUE;		// start new frame
					frIndex = 0;
					break;
				}
		case(SLIP_ESC):
				if (inFrame)
				{
					UART_read(s, tempRx, 1);
					switch(tempRx[0])
					{
					case(SLIP_ESC_END):
							tempFr.b8[frIndex] = SLIP_END;
							frIndex++;
							break;
					case(SLIP_ESC_ESC):
							tempFr.b8[frIndex] = SLIP_ESC;
							frIndex++;
							break;
					default:
						break;	// invalid post ESC character
					}
					break;
				}
				else
				{
					break;		// ignore corrupt frames
				}
		default:
			if (inFrame)
			{
				// standard character store
				tempFr.b8[frIndex] = tempRx[0];
				frIndex++;
				break;
			}
		}
	}
}
Esempio n. 25
0
 /*
  *  ======== echoFxn ========
  *  Task for this function is created statically. See the project's .cfg file.
  */
 Void echoFxn(UArg arg0, UArg arg1)
 {
     char input;
     UART_Params uartPCParams;
     UART_Params uartGSMParams;
     UART_Params uartXBEEParams;

     const char echoPrompt[] = "\fEchoing characters:\r\n";

     // Create a UART for PC
     UART_Params_init(&uartPCParams);
     uartPCParams.readMode = UART_MODE_CALLBACK;
     uartPCParams.writeMode = UART_MODE_CALLBACK;
     uartPCParams.readCallback = &pcReadUARTCallback;
     uartPCParams.writeCallback = &pcWriteUARTCallback;
     uartPCParams.writeDataMode = UART_DATA_BINARY;
     uartPCParams.readDataMode = UART_DATA_BINARY;
     uartPCParams.readReturnMode = UART_RETURN_NEWLINE;
     uartPCParams.readEcho = UART_ECHO_OFF;
     uartPCParams.baudRate = 115200;
     uartPC = UART_open(Board_UART0, &uartPCParams);

     if (uartPC == NULL) {
         System_abort("Error opening the UART");
     }


     // Create a UART for GSM
 	UART_Params_init(&uartGSMParams);
 	uartGSMParams.readMode = UART_MODE_CALLBACK;
     uartGSMParams.writeMode = UART_MODE_CALLBACK;
 	uartGSMParams.readCallback = &gsmReadUARTCallback;
 	uartGSMParams.writeCallback = &gsmWriteUARTCallback;
 	uartGSMParams.writeDataMode = UART_DATA_BINARY;
 	uartGSMParams.readDataMode = UART_DATA_BINARY;
 	uartGSMParams.readReturnMode = UART_RETURN_NEWLINE;
 	uartGSMParams.baudRate = 115200;
 	uartGSM = UART_open(Board_UART1, &uartGSMParams);

 	if (uartGSM == NULL) {
 		System_abort("Error opening the GSM UART");
 	}

     // Create a UART for GSM
 	UART_Params_init(&uartXBEEParams);

 	uartXBEEParams.readMode = UART_MODE_CALLBACK;
     uartXBEEParams.writeMode = UART_MODE_CALLBACK;
 	uartXBEEParams.readCallback = &xbeeReadUARTCallback;
 	uartXBEEParams.writeCallback = &xbeeWriteUARTCallback;
 	uartXBEEParams.writeDataMode = UART_DATA_BINARY;
 	uartXBEEParams.readDataMode = UART_DATA_BINARY;
 	uartXBEEParams.readReturnMode = UART_RETURN_NEWLINE;
 	uartXBEEParams.baudRate = 115200;
 	uartXBEE = UART_open(Board_UART3, &uartXBEEParams);

 	if (uartXBEE == NULL) {
 		System_abort("Error opening the GSM UART");
 	}

     UART_write(uartPC, echoPrompt, sizeof(echoPrompt));


     while (1) {

     	// Read from all the UARTS
         UART_read(uartPC, &input, 1);
         UART_read(uartGSM, &input, 1);
         UART_read(uartXBEE, &input, 1);


     }
 }
Esempio n. 26
0
/**
 * /fn TransferFunction
 * /brief Functions transfers read values from altitude/thermo click via uart7.
 *
 * /param arg0 not used.
 * /param arg1 not used.
 * /return void.
 */
static void TransferFunction(UArg arg0, UArg arg1) {
	TransferMessageType message;
	UInt firedEvents;
	UART_Handle uart7;
	UART_Params uart7Params;
	int length;
	int precision;
	int width;
	float value;
	bool convert;
	int len;
	PositionType* position;
	DateTimeType* dateTime;
	char* destination;

	UART_Params_init(&uart7Params);
	uart7Params.writeDataMode = UART_DATA_BINARY;
	uart7Params.readDataMode = UART_DATA_BINARY;
	uart7Params.readReturnMode = UART_RETURN_FULL;
	uart7Params.readEcho = UART_ECHO_OFF;
	uart7Params.baudRate = 9600;
	uart7 = UART_open(Board_UART3, &uart7Params);

	if (uart7 == NULL) {
		System_abort("Error opening the UART");
	}

	while (true) {
		firedEvents = Event_pend(transferEvent, Event_Id_NONE,
		TRANSFER_MESSAGE_EVENT,
		BIOS_WAIT_FOREVER);
		if (firedEvents & TRANSFER_MESSAGE_EVENT) {
			// Get the posted message.
			// Mailbox_pend() will not block since Event_pend()
			// has guaranteed that a message is available.
			Mailbox_pend(transferMailbox, &message, BIOS_NO_WAIT);
			convert = true;
			switch (message.kind) {
			case TRANSFER_PRESSURE:
				result[0] = ID_PRESSURE;
				value = message.value / 100; /* hPa */
				width = 1;
				precision = PRESSURE_PRECISION;
				if (PRESSURE_PRECISION > 0) {
					width = 3;
				}
				break;
			case TRANSFER_ALTITUDE:
				result[0] = ID_ALTITUDE;
				value = message.value;
				precision = ALTITUDE_PRECISION;
				if (ALTITUDE_PRECISION > 0) {
					width = 3;
				}
				break;
			case TRANSFER_GPS_LOCATION:
				result[0] = ID_LOCATION;
				convert = false;
				position = message.data;
				len = strlen(position->latitude);
				memcpy(&result[1], position->latitude, len);
				destination = result + 1 + len;
				len = strlen(position->longitude);
				memcpy(destination, position->longitude, len);
				destination += len;
				*destination = '\0';
				break;

			case TRANSFER_DATE_TIME:
				result[0] = ID_DATE_TIME;
				convert = false;
				dateTime = message.data;
				len = sizeof(dateTime->dateTimeString);
				memcpy(&result[1], dateTime->dateTimeString, len);
				break;

			default:
				System_printf(
						"Error TransferFunction: Received unknown message %d.\n",
						message.kind);
				System_flush();
				// unknown, nothing special
				continue; /* no break, would be unreachable code */
			}
			if (convert) {
				(void) snprintf(&result[1], 20, "%*.*f", width, precision,
						value);
			} else {
				length = strlen(result) + 1;
			}
			length = strlen(result) + 1;
			UART_write(uart7, &result[0], length);
#ifdef DEBUG
			System_printf("%s transferred.\n", result);
			System_flush();
#endif // DEBUG
		}
	}
}
//must be called from within a task - this function will block!
//returns 1 if modem responds with OK
int hm10_begin(){

	memset(&hm10_rxBuffer, 0, sizeof(hm10_rxBuffer));

	UART_Params_init(&uartParams);
	uartParams.writeDataMode = UART_DATA_BINARY;
	uartParams.readMode = UART_MODE_BLOCKING;
	uartParams.readTimeout = HM10_READ_TIMEOUT;
	uartParams.readDataMode = UART_DATA_BINARY;
	uartParams.readReturnMode = UART_RETURN_FULL;
	uartParams.readEcho = UART_ECHO_OFF;
	uartParams.baudRate = HM10_BAUD_RATE;

	uart = UART_open(Board_UART2_COMM, &uartParams);

	if (uart == NULL) {
		//debug
		GPIO_toggle(Board_LED_GREEN);
		Task_sleep(300);
		GPIO_toggle(Board_LED_GREEN);
		return 0;
	}
	else
	{
		Task_sleep(1000);

		UART_write(uart, hm10_at_wakestring, strlen(hm10_at_wakestring));
		UART_read(uart, hm10_rxBuffer, sizeof(hm10_rxBuffer));
		serial_printf(cli_stdout, "%s\n", hm10_rxBuffer);
		memset(&hm10_rxBuffer, 0, sizeof(hm10_rxBuffer));

		UART_write(uart, hm10_at_pwrm1, strlen(hm10_at_pwrm1));
		UART_read(uart, hm10_rxBuffer, sizeof(hm10_rxBuffer));
		serial_printf(cli_stdout, "%s\n", hm10_rxBuffer);
		memset(&hm10_rxBuffer, 0, sizeof(hm10_rxBuffer));
		Task_sleep(1000);

		UART_write(uart, hm10_at_clear, strlen(hm10_at_clear));
		UART_read(uart, hm10_rxBuffer, sizeof(hm10_rxBuffer));
		serial_printf(cli_stdout, "%s\n", hm10_rxBuffer);
		memset(&hm10_rxBuffer, 0, sizeof(hm10_rxBuffer));
		Task_sleep(500);

		UART_write(uart, hm10_at_imme1, strlen(hm10_at_imme1));
		UART_read(uart, hm10_rxBuffer, sizeof(hm10_rxBuffer));
		serial_printf(cli_stdout, "%s\n", hm10_rxBuffer);
		memset(&hm10_rxBuffer, 0, sizeof(hm10_rxBuffer));
		Task_sleep(1000);

		UART_write(uart, hm10_at_name, strlen(hm10_at_name));
		UART_read(uart, hm10_rxBuffer, sizeof(hm10_rxBuffer));
		serial_printf(cli_stdout, "%s\n", hm10_rxBuffer);
		memset(&hm10_rxBuffer, 0, sizeof(hm10_rxBuffer));
		Task_sleep(1000);

		UART_write(uart, hm10_at, strlen(hm10_at));
		UART_read(uart, hm10_rxBuffer, sizeof(hm10_rxBuffer));
		serial_printf(cli_stdout, "%s\n", hm10_rxBuffer);
		if(!strcmp("OK", hm10_rxBuffer)){
			UART_write(uart, hm10_at_start, strlen(hm10_at_start));
			hm10_end(); // Close UART port to configure Text mode to callback @ newline + CR

			uartParams.writeDataMode = UART_DATA_BINARY;
			/* Experimental: use callback mode such that the comm task is not blocked
			 * while waiting for incoming commands.
			 *
			 * Note: think about using void UART_readCancel 	( 	UART_Handle  	handle	)
			 * WARNING: It is STRONGLY discouraged to call UART_read from its own callback function (UART_MODE_CALLBACK).
			 */
			uartParams.readMode = UART_MODE_CALLBACK;
			uartParams.readCallback = hm10_read_callback;
			uartParams.readTimeout = UART_WAIT_FOREVER; //HM10_READ_TIMEOUT;
			uartParams.readDataMode = UART_DATA_TEXT;
			uartParams.readReturnMode = UART_RETURN_NEWLINE;

			uart = UART_open(Board_UART2_COMM, &uartParams);

			if (uart == NULL)
			{
				//debug
				GPIO_toggle(Board_LED_GREEN);
				Task_sleep(300);
				GPIO_toggle(Board_LED_GREEN);
				return 0;
			}
			else
			{
				hm10_initialised = 1;
				// directly be receptive for commands
				hm10_callback = 0;
				UART_read(uart, hm10_rxBuffer, sizeof(hm10_rxBuffer));
				return 1; //modem can now communicate with us
			}
		}
		else
		{
			return 0;
		}
	}
}
Esempio n. 28
0
/**
 * @brief  Función para inicializar el puerto UART.
 *
 * @return    -
 *
 * Inicializa el puerto UART para poder comunicarse con el modulo zigbee
*/
void ZIGBEE_inicializacion(){
	UART_open(gs_i_puerto_zigbee);
}
Esempio n. 29
0
//taskFxn
void taskFxn(UArg a0, UArg a1) {

  Hwi_Params hwiParams;
  Hwi_Params_init(&hwiParams);
  hwiParams.enableInt = true;

  Hwi_construct(&hwi, INT_AUX_ADC, adcIsr, &hwiParams, NULL);

  UART_Params uParams;
  // Initialize default values
  UART_Params_init(&uParams);
  // Configure custom data, don't care about read params as not used
  // 115.2kBaud, Text, blocking mode
  uHandle = UART_open(Board_UART,&uParams);

  // Set up pins
  pinHandle = PIN_open(&pinState, alsPins);

  // Enable clock for ADC digital and analog interface (not currently enabled in driver)
  AUXWUCClockEnable(AUX_WUC_MODCLKEN0_SOC_M|AUX_WUC_MODCLKEN0_AUX_ADI4_M);
  // Connect AUX IO7 (DIO23) as analog input. Light sensor on SmartRF06EB
  AUXADCSelectInput(ADC_COMPB_IN_AUXIO7);


  // Set up ADC
  AUXADCEnableSync(AUXADC_REF_FIXED, AUXADC_SAMPLE_TIME_2P7_US, AUXADC_TRIGGER_MANUAL);

  // Disallow STANDBY mode while using the ADC.
  Power_setConstraint(Power_SB_DISALLOW);


  while(1) {

    //Sleep 100ms in IDLE mode
    //Task_sleep(100 * 1000 / Clock_tickPeriod);

    // Trigger ADC sampling
    AUXADCGenManualTrigger();

    // Wait in IDLE until done
    Semaphore_pend(hSem, BIOS_WAIT_FOREVER );

    //System_printf("ADC: %d\r\n", singleSample);
    //printf ("ADC: %d\r\n");
    //printf ("ADC\r\n");
  }

  /*


  // Disable ADC
  AUXADCDisable();
  // Allow STANDBY mode again
  Power_releaseConstraint(Power_SB_DISALLOW);

  // Restore pins to values in BoardGpioTable
  PIN_close(pinHandle);

  // Log data through UART



    UART_write(uHandle, &adcSamples[1], SAMPLESIZE);



  // Goto STANDBY forever
  Task_sleep(BIOS_WAIT_FOREVER);
*/
}
Esempio n. 30
0
/*******************************************************************************
*函数名称: Boot0_C_part
*函数原型:void Boot0_C_part( void )
*函数功能: Boot0中用C语言编写的部分的主流程
*入口参数: void
*返 回 值: void
*备    注:
*******************************************************************************/
void Boot0_C_part( void )
{
	__u32 status;
	__s32 dram_size;
	int	index = 0;
	int   ddr_aotu_scan = 0;
	volatile unsigned int *reg_addr = 0;

//	move_RW( );
	clear_ZI( );

	bias_calibration();

    timer_init();
    UART_open( BT0_head.prvt_head.uart_port, (void *)BT0_head.prvt_head.uart_ctrl, 24*1000*1000 );
	//odt_status = check_odt(5);
    if( BT0_head.prvt_head.enable_jtag )
    {
		jtag_init( (normal_gpio_cfg *)BT0_head.prvt_head.jtag_gpio );
    }
	msg("HELLO! BOOT0 is starting!\n");
	print_version();

	{
		__u32 reg_val;
		__u32 fel_flag;

		fel_flag = *(volatile unsigned int *)(0x01f00000 + 0x108);
		//print smp status.
		index = 0;
		while(index < 0x18)
		{
			reg_addr = (volatile unsigned int *)(0x01f00000 + 0x100 + index);
			reg_val = *reg_addr;
	    		*reg_addr = 0;
	    		msg("reg_addr %x =%x\n", reg_addr, reg_val);
	    		index+=0x4;
		}


//		reg_val = *(volatile unsigned int *)(0x01f00000 + 0x108);
//		*(volatile unsigned int *)(0x01f00000 + 0x108) = 0;
//		msg("fel_flag=%x\n", fel_flag);
		if(fel_flag == 0x5AA5A55A)
		{
			msg("eraly jump fel\n");

			pll_reset();
			__msdelay(10);

			jump_to( FEL_BASE );
		}

	}

	mmu_system_init(EGON2_DRAM_BASE, 1 * 1024, EGON2_MMU_BASE);
	mmu_enable();

	//dram_size = init_DRAM(BT0_head.boot_head.platform[7]);                                // 初始化DRAM
//#ifdef  CONFIG_SUN6I_FPGA
//	ddr_aotu_scan = 1;
//	msg("config fpga\n");
//#else
//	ddr_aotu_scan = BT0_head.boot_head.platform[7];
//	msg("not config fpga\n");
//#endif
    ddr_aotu_scan = 0;
#ifdef DEBUG
	{
		int k;

		for(k=0;k<16;k++)
		{
			msg("%x\n", BT0_head.prvt_head.dram_para[k]);
		}
	}
#endif
//	msg("------------before------------\n");
//	dram_para_display();

	dram_size = init_DRAM(ddr_aotu_scan, (void *)BT0_head.prvt_head.dram_para);
	if(dram_size)
	{
		mdfs_save_value((void *)BT0_head.prvt_head.dram_para);
		msg("dram size =%d\n", dram_size);
	}
	else
	{
		msg("initializing SDRAM Fail.\n");
		mmu_disable( );

		pll_reset();
		__msdelay(10);

		jump_to( FEL_BASE );
	}

//	{
//		__u32 reg_val;
//
//		reg_val = *(volatile __u32 *)(0x1c20d20);
//		*(volatile __u32 *)(0x1c20d20) = 0;
//		msg("reg_val=%x, %x\n", reg_val, *(volatile __u32 *)(0x1c20d24));
//		if(reg_val & 0x01)
//		{
//			mmu_disable( );
//			jump_to( 0x40100000 );
//		}
//	}
//	msg("------------end------------\n");
//	dram_para_display();
	#if SYS_STORAGE_MEDIA_TYPE == SYS_STORAGE_MEDIA_NAND_FLASH
		status = load_Boot1_from_nand( );         // 载入Boot1
	#elif SYS_STORAGE_MEDIA_TYPE == SYS_STORAGE_MEDIA_SPI_NOR_FLASH
		status = load_boot1_from_spinor( );         // 载入Boot1
	#elif SYS_STORAGE_MEDIA_TYPE == SYS_STORAGE_MEDIA_SD_CARD
		status = load_boot1_from_sdmmc( (char *)BT0_head.prvt_head.storage_data );  // 载入boot1
	#else
		#error The storage media of Boot1 has not been defined.
	#endif


	msg("Ready to disable icache.\n");

	mmu_disable( );                               // disable instruction cache

	if( status == OK )
	{
//		restart_watch_dog( );                     // restart watch dog
		//跳转boot1之前,把dram的大小写进去
		//set_dram_size(dram_size );
		//跳转之前,把所有的dram参数写到boot1中
		set_dram_para((void *)&BT0_head.prvt_head.dram_para, dram_size);
		msg("Succeed in loading Boot1.\n"
		    "Jump to Boot1.\n");
		jump_to( BOOT1_BASE );                    // 如果载入Boot1成功,跳转到Boot1处执行
	}
	else
	{
//		disable_watch_dog( );                     // disable watch dog

		msg("Fail in loading Boot1.\n"
		    "Jump to Fel.\n");

		pll_reset();
		__msdelay(10);

		jump_to( FEL_BASE );                      // 如果载入Boot1失败,将控制权交给Fel
	}
}