static void setupUART(void) { HalUARTInit(); // configure UART uartConfig.configured = TRUE; uartConfig.baudRate = HAL_UART_BR_57600; uartConfig.flowControl = HAL_UART_FLOW_OFF; uartConfig.flowControlThreshold = 0; uartConfig.rx.maxBufSize = 20; uartConfig.tx.maxBufSize = 128; uartConfig.idleTimeout = 0; uartConfig.intEnable = TRUE; uartConfig.callBackFunc = (halUARTCBack_t)uartCallback; //uartConfig.callBackFunc = NULL; //start UART //assumes no issues with starting UART #if (HAL_UART_ISR == 1) (void)HalUARTOpen(HAL_UART_PORT_0, &uartConfig); #else (void)HalUARTOpen(HAL_UART_PORT_1, &uartConfig); #endif //assumes there is no problem with getting these blocks of bytes rxBuffer = osal_mem_alloc(20); //expanded to handle name changes modeSelStr = osal_mem_alloc(3); }
static void activeMode(void) { // Disable pin interrupts and re-enable UART // - HM-10: RX = P1.7 // - HM-11: RX = P0.2 #if (HAL_UART_ISR == 1) //HM-11 P0SEL |= (1 << 2); //select as peripheral pin (void)HalUARTOpen(HAL_UART_PORT_0, &uartConfig); #else //HM-10 P1SEL |= (1 << 7); //select as peripheral pin (void)HalUARTOpen(HAL_UART_PORT_1, &uartConfig); #endif osal_pwrmgr_device( PWRMGR_ALWAYS_ON ); }
/********************************************************************* * @fn GenericApp_Init * * @brief Initialization function for the Generic App Task. * This is called during initialization and should contain * any application specific initialization (ie. hardware * initialization/setup, table initialization, power up * notificaiton ... ). * * @param task_id - the ID assigned by OSAL. This ID should be * used to send messages and set timers. * * @return none */ void uApp_Init( uint8 task_id ) { halUARTCfg_t uartConfig; uApp_TaskID = task_id; /* Setup keys */ HalKeyConfig(false, uApp_HandleKeys); /* Setup UART */ /* UART Configuration */ uartConfig.configured = TRUE; uartConfig.baudRate = HAL_UART_BR_38400; uartConfig.flowControl = 0; uartConfig.flowControlThreshold = 5; uartConfig.rx.maxBufSize = 128; uartConfig.tx.maxBufSize = 128; uartConfig.idleTimeout = 5; uartConfig.intEnable = TRUE; uartConfig.callBackFunc = uApp_UartProcessRxData; /* Start UART */ HalUARTOpen (0, &uartConfig); HalLcdWriteString("uApp started!", false); osal_start_timerEx(uApp_TaskID, UAPP_EVENT_1, 1000); //osal_set_event(uApp_TaskID, UAPP_EVENT_1); }
/************************************************************************************************** * @fn MHMSAppInit * * @brief This function is the application's task initialization. * * input parameters * * None. * * output parameters * * None. * * @return None. ************************************************************************************************** */ void MHMSAppInit(uint8 id) { halUARTCfg_t uartConfig; uartConfig.configured = TRUE; //uartConfig.baudRate = HAL_UART_BR_38400; //MHMS This baud rate is required to communicate with Zigbee Sensor Monitor uartConfig.baudRate = HAL_UART_BR_115200; //MHMS This baud rate is required to communicate with the Pulse sketching program and reworked Mobile health monitor software on PC uartConfig.flowControl = FALSE; uartConfig.flowControlThreshold = 16; uartConfig.rx.maxBufSize = 32; uartConfig.tx.maxBufSize = 254; uartConfig.idleTimeout = 6; uartConfig.intEnable = TRUE; uartConfig.callBackFunc = MHMSUartRx; HalUARTOpen(MHMS_PORT, &uartConfig); MHMSDat[MHMS_TYP_IDX] = (uint8)MHMS_DEVICE_ID; TestDatTx[MHMS_TEST_PAYLOAD_LEN - 3] = (uint8)MHMS_DEVICE_ID; #if defined MHMS_SRC_RTG MHMSDat[MHMS_OPT_IDX] = MHMS_OPT_SRC_RTG; TestDatTx[MHMS_TEST_PAYLOAD_LEN - 1] = MHMS_OPT_SRC_RTG; #endif MHMSTaskId = id; MHMSAddr = INVALID_NODE_ADDR; (void)afRegister((endPointDesc_t *)&MHMS_epDesc); //MHMS registers endpoint object //Initialize Px.y (5.0) to power Pulse sensor P5DIR = 0x1; //Set IO direction as output P5OUT = 0x1; //Set output to high //Setup ADC reference REFCTL0 = REFVSEL_2; // REF Reference Voltage Level Select 2.5V }
/************************************************************************************************** * @fn main * * @brief Start of application. * * @param none * * @return none ************************************************************************************************** */ int main(void) { /* Initialize hardware */ HAL_BOARD_INIT(); /* Initialze the HAL driver */ HalDriverInit(); /* Initialize MAC */ MAC_Init(); /* Initialize the operating system */ osal_init_system(); /* Enable interrupts */ HAL_ENABLE_INTERRUPTS(); /* Setup OSAL Timer */ HalTimerConfig ( OSAL_TIMER, // 16bit timer3 HAL_TIMER_MODE_CTC, // Clear Timer on Compare HAL_TIMER_CHANNEL_SINGLE, // Channel 1 - default HAL_TIMER_CH_MODE_OUTPUT_COMPARE, // Output Compare mode FALSE, // Use interrupt MSA_Main_TimerCallBack); // Channel Mode /* Setup Keyboard callback */ HalKeyConfig(MSA_KEY_INT_ENABLED, MSA_Main_KeyCallback); /* Initialize UART */ UartCnfg.baudRate = HAL_UART_BR_9600; UartCnfg.callBackFunc = HalUARTCBack; UartCnfg.flowControl = FALSE; UartCnfg.flowControlThreshold = 0; /* max Buffer Size in Byte*/ UartCnfg.idleTimeout = 200; /* * halUARTOpen provvederà tramite la funzione halUartAllocBuffers ad allocare e inizializzare * le strutture dati RxUART e TxUART. */ UartCnfg.rx = RxUART; UartCnfg.tx = TxUART; UartCnfg.rx.maxBufSize = UART_MAX_BUFFER_SIZE; UartCnfg.tx.maxBufSize = UART_MAX_BUFFER_SIZE; UartCnfg.intEnable = TRUE ; /* enable or disable the interrupts */ UartCnfg.configured = TRUE; uint8 status = HalUARTOpen(HAL_UART_PORT, &UartCnfg); /* passo l'indirizzo di memoria della struttura dati UartCnfg, Passaggio per riferimento!!!*/ /* Start OSAL */ osal_start_system(); // No Return from here return 0; }
/*************************************************************************************************** * @fn MT_UartInit * * @brief Initialize MT with UART support * * @param None * * @return None ***************************************************************************************************/ void MT_UartInit () { halUARTCfg_t uartConfig; /* Initialize APP ID */ App_TaskID = 0; /* UART Configuration */ uartConfig.configured = TRUE; uartConfig.baudRate = MT_UART_DEFAULT_BAUDRATE; uartConfig.flowControl = MT_UART_DEFAULT_OVERFLOW; uartConfig.flowControlThreshold = MT_UART_DEFAULT_THRESHOLD; uartConfig.rx.maxBufSize = MT_UART_DEFAULT_MAX_RX_BUFF; uartConfig.tx.maxBufSize = MT_UART_DEFAULT_MAX_TX_BUFF; uartConfig.idleTimeout = MT_UART_DEFAULT_IDLE_TIMEOUT; uartConfig.intEnable = TRUE; #if defined (ZTOOL_P1) || defined (ZTOOL_P2) uartConfig.callBackFunc = MT_UartProcessZToolData; uartConfig.callBackFunc = rxCB; HalUARTOpen (SERIAL_APP_PORT, &uartConfig); #elif defined (ZAPP_P1) || defined (ZAPP_P2) uartConfig.callBackFunc = MT_UartProcessZAppData; #else uartConfig.callBackFunc = NULL; #endif HalUARTOpen (SERIAL_APP_PORT, &uartConfig); /* Start UART */ #if defined (MT_UART_DEFAULT_PORT) //HalUARTOpen (MT_UART_DEFAULT_PORT, &uartConfig); #else /* Silence IAR compiler warning */ (void)uartConfig; #endif /* Initialize for ZApp */ #if defined (ZAPP_P1) || defined (ZAPP_P2) /* Default max bytes that ZAPP can take */ MT_UartMaxZAppBufLen = 1; MT_UartZAppRxStatus = MT_UART_ZAPP_RX_READY; #endif }
/********************************************************************* * @fn initUart1 * @brief initial uart1. * @param UART_callback - uart callback. * @return null. */ void initUart1(halUARTCBack_t UART_callback) { halUARTCfg_t uartConfig; uartConfig.configured = TRUE; uartConfig.baudRate = HAL_UART_BR_115200; uartConfig.flowControl = FALSE; uartConfig.flowControlThreshold = 48; uartConfig.rx.maxBufSize = 128; uartConfig.tx.maxBufSize = 128; uartConfig.idleTimeout = 6; uartConfig.intEnable = TRUE; uartConfig.callBackFunc = UART_callback; HalUARTOpen (HAL_UART_PORT_1, &uartConfig); }
//This function initializes the UART void uart_init() { halUARTCfg_t uartConfig; uartConfig.configured = TRUE; // 2x30 don't care - see uart driver. uartConfig.baudRate = HAL_UART_BR_9600; uartConfig.flowControl = TRUE; uartConfig.flowControlThreshold = 48; // 2x30 don't care - see uart driver. uartConfig.rx.maxBufSize = 128; // 2x30 don't care - see uart driver. uartConfig.tx.maxBufSize = 128; // 2x30 don't care - see uart driver. uartConfig.idleTimeout = 6; // 2x30 don't care - see uart driver. uartConfig.intEnable = TRUE; // 2x30 don't care - see uart driver. uartConfig.callBackFunc = UART_CallBack; HalUARTOpen (HAL_UART_PORT_0, &uartConfig); }
unsigned char OS_serial_open(unsigned long baud, unsigned char parity, unsigned char bits, unsigned char stop, unsigned char flow, unsigned short onread, unsigned short onwrite) { halUARTCfg_t config; switch (baud) { case 9600: baud = HAL_UART_BR_9600; break; case 19200: baud = HAL_UART_BR_19200; break; case 38400: baud = HAL_UART_BR_38400; break; case 57600: baud = HAL_UART_BR_57600; break; case 115200: baud = HAL_UART_BR_115200; break; default: return 2; } // Only support port 0, no-parity, 8-bits, 1 stop bit if (parity != 'N' || bits != 8 || stop != 1 || !(flow == 'H' || flow == 'N')) { return 3; } config.configured = 1; config.baudRate = baud; config.flowControl = (flow == 'H' ? 1 : 0); config.flowControlThreshold = 64; config.idleTimeout = 0; config.rx.maxBufSize = 128; config.tx.maxBufSize = 128; config.intEnable = 1; config.callBackFunc = _uartCallback; if (HalUARTOpen(HAL_UART_PORT_0, &config) == HAL_UART_SUCCESS) { serial[0].onread = onread; serial[0].onwrite = onwrite; return 0; } return 1; }
/********************************************************************* * @brief Initialization UART use for receive data from barcode scanner * * @return none */ void UART_PC_Init(void){ halUARTCfg_t uConfig; uConfig.configured = TRUE; uConfig.baudRate = UART_PC_BAUD; uConfig.flowControl = FALSE; uConfig.flowControlThreshold = UART_PC_THRESH; uConfig.rx.maxBufSize = UART_PC_RX_SIZE; uConfig.tx.maxBufSize = UART_PC_TX_SIZE; uConfig.idleTimeout = UART_PC_TIMEOUT; uConfig.intEnable = TRUE; uConfig.callBackFunc = UART_PC_process_evt; HalUARTOpen (UART_PC_PORT, &uConfig); }
/********************************************************************* * @fn SerialApp_Init * * @brief This is called during OSAL tasks' initialization. * * @param task_id - the Task ID assigned by OSAL. * * @return none */ void SerialApp_Init( uint8 task_id ) { halUARTCfg_t uartConfig; SerialApp_MsgID = 0x00; SerialApp_SeqRx = 0xC3; SerialApp_TaskID = task_id; SerialApp_DstAddr.endPoint = 0; SerialApp_DstAddr.addr.shortAddr = 0; SerialApp_DstAddr.addrMode = (afAddrMode_t)AddrNotPresent; SerialApp_RspDstAddr.endPoint = 0; SerialApp_RspDstAddr.addr.shortAddr = 0; SerialApp_RspDstAddr.addrMode = (afAddrMode_t)AddrNotPresent; afRegister( (endPointDesc_t *)&SerialApp_epDesc ); RegisterForKeys( task_id ); uartConfig.configured = TRUE; // 2430 don't care. uartConfig.baudRate = SERIAL_APP_BAUD; uartConfig.flowControl = TRUE; uartConfig.flowControlThreshold = SERIAL_APP_THRESH; uartConfig.rx.maxBufSize = SERIAL_APP_RX_MAX; uartConfig.tx.maxBufSize = SERIAL_APP_TX_MAX; uartConfig.idleTimeout = SERIAL_APP_IDLE; // 2430 don't care. uartConfig.intEnable = TRUE; // 2430 don't care. #if SERIAL_APP_LOOPBACK uartConfig.callBackFunc = rxCB_Loopback; #else uartConfig.callBackFunc = rxCB; #endif HalUARTOpen (SERIAL_APP_PORT, &uartConfig); #if defined ( LCD_SUPPORTED ) HalLcdWriteString( "SerialApp2", HAL_LCD_LINE_2 ); #endif HalLedSet(HAL_LED_1,HAL_LED_MODE_OFF); HalLedSet(HAL_LED_2,HAL_LED_MODE_OFF); HalLedSet(HAL_LED_3,HAL_LED_MODE_OFF); ZDO_RegisterForZDOMsg( SerialApp_TaskID, End_Device_Bind_rsp ); ZDO_RegisterForZDOMsg( SerialApp_TaskID, Match_Desc_rsp ); osal_start_timerEx(SerialApp_TaskID,SERIALAPP_MSG_AUTOMATCH,2000); }
/** * @brief Inicializa UART. * @param pf Puntero a la función callback del UART. */ void initUart(halUARTCBack_t pf) { halUARTCfg_t uartConfig; uartConfig.configured = TRUE; uartConfig.baudRate = HAL_UART_BR_19200; uartConfig.flowControl = FALSE; uartConfig.flowControlThreshold = 48; uartConfig.rx.maxBufSize = RX_BUF_LEN; uartConfig.tx.maxBufSize = 128; uartConfig.idleTimeout = 6; uartConfig.intEnable = TRUE; uartConfig.callBackFunc = pf; HalUARTOpen(HAL_UART_PORT_0, &uartConfig); }
/********************************************************************* * * @fn Monitor_UartInit * * @brief this method init the usart for the coordinator * * * @param None * * @return void */ void Monitor_UartInit() { // create the uart structure halUARTCfg_t uartConfig; // set the parameters uartConfig.configured = TRUE; uartConfig.baudRate = HAL_UART_BR_115200; uartConfig.flowControl = FALSE; uartConfig.flowControlThreshold = 128; uartConfig.rx.maxBufSize = 256; uartConfig.tx.maxBufSize = 256; uartConfig.idleTimeout = 6; uartConfig.intEnable = TRUE; uartConfig.callBackFunc = Monitor_UartCallBack; // open it HalUARTOpen (UART_PORT, &uartConfig); }
void uart_init(uint8 baudrate) { P1SEL = 0x30; PERCFG |= 1; halUARTCfg_t config; config.configured = true; config.baudRate = baudrate; config.flowControl = false; config.flowControlThreshold = 64; config.idleTimeout = 0; // 6 config.rx.maxBufSize = 128; config.tx.maxBufSize = 128; config.intEnable = true; config.callBackFunc = uart0CB; HalUARTOpen(HAL_UART_PORT_0, &config); }
void uart_open(void) { halUARTCfg_t uartConfig; uartConfig.configured = TRUE; uartConfig.baudRate = HAL_UART_BR_115200; uartConfig.flowControl = FALSE; uartConfig.flowControlThreshold = 48; uartConfig.rx.maxBufSize = RX_BUF_MAXLEN; uartConfig.tx.maxBufSize = TX_BUF_MAXLEN; uartConfig.idleTimeout = 1; uartConfig.intEnable = TRUE; uartConfig.callBackFunc = (halUARTCBack_t)&uart_rx_cback; HalUARTOpen (HAL_UART_PORT_1, &uartConfig); }
/************************************************************************************************** * @fn pulseAppInit * * @brief This function is the application's task initialization. * * input parameters * * None. * * output parameters * * None. * * @return None. ************************************************************************************************** */ void pulseAppInit(uint8 id) { halUARTCfg_t uartConfig; uartConfig.configured = TRUE; // 2x30 don't care - see uart driver. uartConfig.baudRate = HAL_UART_BR_38400; //MHMS This baud rate is required to communicate with Zigbee Sensor Monitor //uartConfig.baudRate = HAL_UART_BR_115200; //MHMS This baud rate is required to communicate with the Pulse processing program on PC uartConfig.flowControl = FALSE; uartConfig.flowControlThreshold = 16; // 2x30 don't care - see uart driver. uartConfig.rx.maxBufSize = 32; // 2x30 don't care - see uart driver. uartConfig.tx.maxBufSize = 254; // 2x30 don't care - see uart driver. uartConfig.idleTimeout = 6; // 2x30 don't care - see uart driver. uartConfig.intEnable = TRUE; // 2x30 don't care - see uart driver. uartConfig.callBackFunc = pulseUartRx; HalUARTOpen(PULSE_PORT, &uartConfig); pulseDat[PULSE_TYP_IDX] = (uint8)PULSE_DEVICE_ID; TestDatTx[MHMS_TEST_PAYLOAD_LEN - 3] = (uint8)PULSE_DEVICE_ID; #if defined PULSE_SRC_RTG pulseDat[PULSE_OPT_IDX] = PULSE_OPT_SRC_RTG; TestDatTx[MHMS_TEST_PAYLOAD_LEN - 1] = PULSE_OPT_SRC_RTG; #endif pulseTaskId = id; pulseAddr = INVALID_NODE_ADDR; (void)afRegister((endPointDesc_t *)&PULSE_epDesc); //MHMS registers endpoint object //Initialize Px.y (5.0) to power Pulse sensor P5DIR = 0x1; //Set IO direction as output P5OUT = 0x1; //Set output to high //Test P4DIR = 0x1; P4OUT = 0x1; //Setup ADC reference REFCTL0 = REFVSEL_2; // REF Reference Voltage Level Select 2.5V }
uint8 openUart(uint8 whichport, uint8 baudrate) { uint8 result=0; halUARTCfg_t uartConfig; // Config UART uartConfig.configured = TRUE; // 2x30 don't care - see uart driver. uartConfig.baudRate = baudrate; //SERIAL_APP_BAUD; uartConfig.flowControl = TRUE; uartConfig.flowControlThreshold = 64; //SERIAL_APP_THRESH; // 2x30 don't care - see uart driver. uartConfig.rx.maxBufSize = 128; //SERIAL_APP_RX_SZ; // 2x30 don't care - see uart driver. uartConfig.tx.maxBufSize = 128; //SERIAL_APP_TX_SZ; // 2x30 don't care - see uart driver. uartConfig.idleTimeout = 6; //SERIAL_APP_IDLE; // 2x30 don't care - see uart driver. uartConfig.intEnable = TRUE; // 2x30 don't care - see uart driver. uartConfig.callBackFunc = SerialApp_CallBack; result = HalUARTOpen (whichport, &uartConfig); return result; }
void serial_init(void ) { halUARTCfg_t uartConfig; uartConfig.configured = TRUE; // 2x30 don't care - see uart driver. uartConfig.baudRate = HAL_UART_BR_38400; //38400 uartConfig.flowControl = FALSE; uartConfig.flowControlThreshold = 64; // 64. uartConfig.rx.maxBufSize = 1024; // 128 uartConfig.tx.maxBufSize = 1024; // 128 uartConfig.idleTimeout = 6; // 6 uartConfig.intEnable = TRUE; uartConfig.callBackFunc = Serial_callBack; // Call back function HalUARTOpen (SER_PORT, &uartConfig); }
void zclHomelink_UARTInit(void) { halUARTCfg_t uartConfig; /* UART Configuration */ uartConfig.configured = TRUE; uartConfig.baudRate = HAL_UART_BR_115200; uartConfig.flowControl = HAL_UART_FLOW_OFF; uartConfig.flowControlThreshold = HAL_UART_DMA_RX_MAX >> 1; uartConfig.rx.maxBufSize = HAL_UART_DMA_RX_MAX; uartConfig.tx.maxBufSize = HAL_UART_DMA_RX_MAX; uartConfig.idleTimeout = 50; uartConfig.intEnable = TRUE; uartConfig.callBackFunc = zclHomelink_UARTCallback; /* Start UdART */ HalUARTOpen(HAL_UART_PORT_0, &uartConfig); }
/************************************************************************************************** * @fn zapSBL_Init * * @brief This function is the application's task initialization. * * input parameters * * None. * * output parameters * * None. * * @return None. ************************************************************************************************** */ void zapSBL_Init(uint8 id) { #if ZAP_SBL_EXT_EXEC halUARTCfg_t uartConfig; uartConfig.configured = TRUE; // 2x30 don't care - see uart driver. uartConfig.baudRate = HAL_UART_BR_115200; uartConfig.flowControl = FALSE; uartConfig.flowControlThreshold = 16; // 2x30 don't care - see uart driver. uartConfig.rx.maxBufSize = 254; // 2x30 don't care - see uart driver. uartConfig.tx.maxBufSize = 254; // 2x30 don't care - see uart driver. uartConfig.idleTimeout = 1; // 2x30 don't care - see uart driver. uartConfig.intEnable = TRUE; // 2x30 don't care - see uart driver. uartConfig.callBackFunc = zapSBL_RxExt; HalUARTOpen(ZAP_SBL_EXT_PORT, &uartConfig); #endif zapSBL_TaskId = id; }
/*uart初始化代码,配置串口的波特率、流控制等*/ void SbpHalUARTInit() { halUARTCfg_t uartConfig; // configure UART uartConfig.configured = TRUE; uartConfig.baudRate = SBP_UART_BR; //波特率 uartConfig.flowControl = SBP_UART_FC; //流控制 uartConfig.flowControlThreshold = SBP_UART_FC_THRESHOLD; //流控制阈值,当开启flowControl时,该设置有效 uartConfig.rx.maxBufSize = SBP_UART_RX_BUF_SIZE; //uart接收缓冲区大小 uartConfig.tx.maxBufSize = SBP_UART_TX_BUF_SIZE; //uart发送缓冲区大小 uartConfig.idleTimeout = SBP_UART_IDLE_TIMEOUT; uartConfig.intEnable = SBP_UART_INT_ENABLE; //是否开启中断 uartConfig.callBackFunc = SbpHalUARTReadCallback; //uart接收回调函数,在该函数中读取可用uart数据 // start UART // Note: Assumes no issue opening UART port. (void) HalUARTOpen(SBP_UART_PORT, &uartConfig); return; }
/******************************************************************************* * @fn NPI_InitTransport * * @brief This routine initializes the transport layer and opens the port * of the device. Note that based on project defines, either the * UART, USB (CDC), or SPI driver can be used. * * input parameters * * @param npiCback - User callback function when data is available. * * output parameters * * @param None. * * @return None. */ void NPI_InitTransport( npiCBack_t npiCBack ) { halUARTCfg_t uartConfig; // configure UART uartConfig.configured = TRUE; uartConfig.baudRate = NPI_UART_BR; uartConfig.flowControl = NPI_UART_FC; uartConfig.flowControlThreshold = NPI_UART_FC_THRESHOLD; uartConfig.rx.maxBufSize = NPI_UART_RX_BUF_SIZE; uartConfig.tx.maxBufSize = NPI_UART_TX_BUF_SIZE; uartConfig.idleTimeout = NPI_UART_IDLE_TIMEOUT; uartConfig.intEnable = NPI_UART_INT_ENABLE; uartConfig.callBackFunc = (halUARTCBack_t)npiCBack; // start UART // Note: Assumes no issue opening UART port. (void)HalUARTOpen( NPI_UART_PORT, &uartConfig ); return; }