MWSDK(TWELITE SDK)
MONO WIRELESS INC.
MWSDK_EN
MWSDK_EN
  • TWELITE SDK (MWSDK) manual
  • Introduction
    • TWELITE SDK Terms of Use
    • Support and response
    • Mono Wireless Software License Agreement
    • Structure of TWELITE SDK
  • Get the latest version
    • TWELITE SDK revision history
  • How to use TWELITE SDK
    • Install TWELITE SDK (MWSDK)
    • Use with VSCode
    • folder structure
    • How to build from the command line
    • About build definitions
      • About Makefile
      • about Version.mk
      • bin file naming conventions
    • program firmware
      • Wiring for firmware programming
      • tweterm.py
  • TWELIET NET API overview
    • Terms
    • TWELITE NET library structure
    • TWENET working flow
      • flow: System start-up
      • flow: Main loop
      • flow: Wireless events
      • flow: Hardware interrupts/events
      • flow: User-defined event processing function
    • Structure of the source code
    • Modules
    • Wireless packets
      • Maximum packet length
      • Addressing conventions
      • Application ID
    • About the network
      • SimpleNet
        • Transmit
        • Receive
      • RelayNet
        • Implementation of the parent device
        • Implementation of repeaters
        • Implementing a child device (MININODES)
        • NB beacon system connection
        • Address of the relay network
        • Static relay with fixed host address
  • TWELITE NET API references
    • The callback functions
      • cbAppColdStart()
      • cbAppWarmStart()
      • cbToCoNet_vMain()
      • cbToCoNet_vRxEvent()
      • cbToCoNet_vTxEvent()
      • cbToCoNet_vNwkEvent()
      • cbToCoNet_vHwEvent()
      • cbToCoNet_u8HwInt()
    • TWELITE NET functions
      • ToCoNet_vMacStart()
      • ToCoNet_bMacTxReq()
      • ToCoNet_u32GetSerial()
      • ToCoNet_u32GetRand()
      • ToCoNet_vSleep()
      • ToCoNet_vDebugInit()
      • ToCoNet_vDebugLevel()
      • ToCoNet_u32GetVersion()
      • ToCoNet_bRegisterAesKey()
      • ToCoNet_vRfConfig()
      • ToCoNet_vChConfig()
      • ToCoNet_Tx_vProcessEventQueue()
      • ToCoNet_u16RcCalib()
    • RelayNet API
      • functions
        • ToCoNet_Nwk_bInit()
        • ToCoNet_Nwk_bStart()
        • ToCoNet_Nwk_bPause()
        • ToCoNet_Nwk_bResume()
        • ToCoNet_Nwk_bTx()
      • Structure
        • tsTxDataApp (relay net)
        • tsRxDataApp (relay net)
        • tsToCoNet_Nwk_Context
      • LayerTree net
        • ToCoNet_NwkLyTr_psConfig()
        • ToCoNet_NwkLyTr_psConfig_MiniNodes()
        • tsToCoNet_NwkLyTr_Context
    • typedef, frequently used macros
    • Structures
      • sToCoNet_AppContext
      • tsRxDataApp
      • tsTxDataApp
    • TWELITE NET macros
      • ToCoNet_REG_MOD_ALL()
      • utils.h
    • User defined event handling functions
      • State
      • Events
      • ToCoNet_Event API
        • ToCoNet_Event_Register_State_Machine()
        • ToCoNet_Event_Process()
        • ToCoNet_Event_SetState()
        • ToCoNet_Event_vKeepStateOnRamHoldSleep()
        • ToCoNet_Event_u32TickFrNewState()
    • Module library
      • ENERGY SCAN
      • NB SCAN
    • PRSEV library
    • global variables
      • uint32 u32TickCount_ms
      • sToCoNet_AppContext (static variable)
    • PANIC
  • HW API reference
    • Peripherals
      • ADC
        • adc.c
      • DIO
      • TickTimer
      • UART
        • SERIAL library
          • SERIAL_vInit()
          • SERIAL_vInitEx()
          • SERIAL_bRxQueueEmpty()
          • SERIAL_i16RxChar()
          • SERIAL_vFlush()
          • tsSerialPortSetup
          • tsUartOpt
        • fprintf library
          • vfPrintf()
          • vPutChar()
          • tsFILE
      • Timer
        • Timer library
          • vTimerConfig()
          • vTimerStart()
          • vTimerStop()
          • vTimerDisable()
          • tsTimerContext
      • WakeTimer
      • I2C
      • SPI
    • Flash, EEPROM
      • EEPROM
      • Flash
  • Utils references, others.
    • ByteQueue
    • u8CCITT8()
    • SPRINTF library
    • BTM library (consecutive reading) DIO input
GitBook提供
このページ内
  • Initialisation
  • Output
  • Input
  1. HW API reference
  2. Peripherals

UART

前へTickTimer次へSERIAL library

最終更新 2 年前

Two UART hardware channels are available for the TWELITE wireless microcontroller. Each of these UART ports has a hardware FIFO buffer of 16 bytes.

SERIAL library (serial.c and uart.c) is the standard method for processing in TWELITE NET, which handles UART interrupts and provides an API for I/O procedures using FIFO memory allocated in the microcontroller.

Initialisation

We store the initialization parameters in the structure and call the function. Here we need to statically allocate a memory area for the FIFO buffer to be used for serial data input and output.

We also provide a structure for output.

tsFILE sSerStream;
tsSerialPortSetup sSerPort;

void vSerialInit(uint32 u32Baud) {
	/* Create the debug port transmit and receive queues */
	static uint8 au8SerialTxBuffer[256];
	static uint8 au8SerialRxBuffer[256];

	/* Initialise the serial port to be used for debug output */
	sSerPort.pu8SerialRxQueueBuffer = au8SerialRxBuffer;
	sSerPort.pu8SerialTxQueueBuffer = au8SerialTxBuffer;
	sSerPort.u32BaudRate = u32Baud;
	sSerPort.u16AHI_UART_RTS_LOW = 0xffff;
	sSerPort.u16AHI_UART_RTS_HIGH = 0xffff;
	sSerPort.u16SerialRxQueueSize = sizeof(au8SerialRxBuffer);
	sSerPort.u16SerialTxQueueSize = sizeof(au8SerialTxBuffer);
	sSerPort.u8SerialPort = UART_PORT_SLAVE;
	sSerPort.u8RX_FIFO_LEVEL = E_AHI_UART_FIFO_LEVEL_1;
	SERIAL_vInit(&sSerPort);

	// for vfPrintf()
	sSerStream.bPutChar = SERIAL_bTxChar;
	sSerStream.u8Device = UART_PORT_SLAVE;
}

Output

The output process may be unstable immediately after initialisation when the system starts or when it returns to sleep. If there is a problem with the operation, please wait some time before outputting.

The following is an example of outputting packet information when receiving a wireless packet.

void cbToCoNet_vRxEvent(tsRxDataApp *pRx) {
	vfPrintf(&sSerStream, LB"[PKT Ad:%04x,Ln:%03d,Seq:%03d,Lq:%03d,Tms:%05d \"",
		pRx->u32SrcAddr,
		pRx->u8Len+4, // Actual payload byte: the network layer uses additional 4 bytes.
		pRx->u8Seq,
		pRx->u8Lqi,
		pRx->u32Tick & 0xFFFF);
	...

Waiting for output to complete may cause instability. In this case, remove this waiting process and check the operation.

If the waiting process is omitted and the output is interrupted, an extra FIFO memory is allocated for the output.

Input

When there is an input, data is put into the FIFO memory registered at the time of initialization in the library. This data is read by SERIAL_bRxQueueEmpty() and SEREAL_i16RxChar().

void cbToCoNet_vMain(void) {
	while (!SERIAL_bRxQueueEmpty(sSerPort.u8SerialPort)) {
		int16 i16Char;

		i16Char = SERIAL_i16RxChar(sSerPort.u8SerialPort);

		vfPrintf(&sSerStream, "\n\r# [%c] --> ", i16Char);
	    SERIAL_vFlush(sSerStream.u8Device);
		...
	}
}

Use or for output. The parameter is a pointer to the tsFILE structure.

If you want to wait for the output to complete, such as when all the output is done and then goes to sleep, you can call the function. This function will block until the output queue is empty.

This process is described in the process.。

tsSerialPortSetup
SERIAL_vInit()
tsFILE
vfPrintf()
vPutChar()
SERIAL_vFlush()
cbToCoNet_vMain()