/* ** =================================================================== ** Method : Inhr1_SendChar (component AsynchroSerial) ** Description : ** Sends one character to the channel. If the component is ** temporarily disabled (Disable method) SendChar method only ** stores data into an output buffer. In case of a zero output ** buffer size, only one character can be stored. Enabling the ** component (Enable method) starts the transmission of the ** stored data. This method is available only if the ** transmitter property is enabled. ** Parameters : ** NAME - DESCRIPTION ** Chr - Character to send ** Returns : ** --- - Error code, possible codes: ** ERR_OK - OK ** ERR_SPEED - This device does not work in ** the active speed mode ** ERR_TXFULL - Transmitter is full ** =================================================================== */ byte Inhr1_SendChar(Inhr1_TComData Chr) { Inhr1_TComData TmpChr = OutBuffer; /* Save OutBuffer value */ ASerialLdd1_Main(ASerialLdd1_DeviceDataPtr); OutBuffer = Chr; /* Save character */ if (ASerialLdd1_SendBlock(ASerialLdd1_DeviceDataPtr, (LDD_TData *)&OutBuffer, 1U) == ERR_BUSY) { /* Send one data byte */ OutBuffer = TmpChr; /* If is device busy, restore OutBuffer value */ return ERR_TXFULL; } ASerialLdd1_Main(ASerialLdd1_DeviceDataPtr); return ERR_OK; /* OK */ }
/* ** =================================================================== ** Method : Inhr1_RecvChar (component AsynchroSerial) ** Description : ** If any data is received, this method returns one character, ** otherwise it returns an error code (it does not wait for ** data). This method is enabled only if the receiver property ** is enabled. ** [Note:] Because the preferred method to handle error and ** break exception in the interrupt mode is to use events ** <OnError> and <OnBreak> the return value ERR_RXEMPTY has ** higher priority than other error codes. As a consequence the ** information about an exception in interrupt mode is returned ** only if there is a valid character ready to be read. ** Parameters : ** NAME - DESCRIPTION ** * Chr - Pointer to a received character ** Returns : ** --- - Error code, possible codes: ** ERR_OK - OK ** ERR_SPEED - This device does not work in ** the active speed mode ** ERR_RXEMPTY - No data in receiver ** ERR_BREAK - Break character is detected ** (only when the <Interrupt service> property ** is disabled and the <Break signal> property ** is enabled) ** ERR_COMMON - common error occurred (the ** <GetError> method can be used for error ** specification) ** =================================================================== */ byte Inhr1_RecvChar(Inhr1_TComData *Chr) { byte Result = ERR_OK; /* Return error code */ LDD_SERIAL_TError SerialErrorMask; /* Serial error mask variable */ ASerialLdd1_Main(ASerialLdd1_DeviceDataPtr); if (ASerialLdd1_GetError(ASerialLdd1_DeviceDataPtr, &SerialErrorMask) == ERR_OK) { /* Get error state */ if (SerialErrorMask != 0U) { Result = ERR_COMMON; /* If yes then set common error value */ } else { if (ASerialLdd1_GetReceivedDataNum(ASerialLdd1_DeviceDataPtr) == 0U) { /* Is not received char? */ return ERR_RXEMPTY; /* If yes then error is returned */ } } } *Chr = BufferRead; /* Read the char */ (void)ASerialLdd1_ReceiveBlock(ASerialLdd1_DeviceDataPtr, &BufferRead, 1U); /* Receive one data byte */ ASerialLdd1_Main(ASerialLdd1_DeviceDataPtr); return Result; /* Return error code */ }
/* ** =================================================================== ** Method : Inhr1_GetCharsInRxBuf (component AsynchroSerial) ** Description : ** Returns the number of characters in the input buffer. This ** method is available only if the receiver property is enabled. ** Parameters : None ** Returns : ** --- - The number of characters in the input ** buffer. ** =================================================================== */ word Inhr1_GetCharsInRxBuf(void) { ASerialLdd1_Main(ASerialLdd1_DeviceDataPtr); return (word)ASerialLdd1_GetReceivedDataNum(ASerialLdd1_DeviceDataPtr); /* Return number of chars in the receive buffer */ }
/* ** =================================================================== ** Method : AS1_GetCharsInTxBuf (component AsynchroSerial) ** Description : ** Returns the number of characters in the output buffer. This ** method is available only if the transmitter property is ** enabled. ** Parameters : None ** Returns : ** --- - The number of characters in the output ** buffer. ** =================================================================== */ word AS1_GetCharsInTxBuf(void) { ASerialLdd1_Main(ASerialLdd1_DeviceDataPtr); return ((word)(ASerialLdd1_GetSentDataNum(ASerialLdd1_DeviceDataPtr) != 0x00U) ? 0U:1U); /* Return number of chars in the transmit buffer */ }