/* ** =================================================================== ** Method : AS2_ASerialLdd2_OnBlockSent (component AsynchroSerial) ** ** Description : ** This event is called after the last character from the output ** buffer is moved to the transmitter. ** This method is internal. It is used by Processor Expert only. ** =================================================================== */ void ASerialLdd2_OnBlockSent(LDD_TUserData *UserDataPtr) { word OnFlags = 0x00U; /* Temporary variable for flags */ (void)UserDataPtr; /* Parameter is not used, suppress unused argument warning */ if ((SerFlag & RUNINT_FROM_TX) != 0U) { /* Is flag "running int from TX" set? */ OnFlags |= ON_TX_CHAR; /* Set flag "OnTxChar" */ } OutIndexR++; if (OutIndexR >= AS2_OUT_BUF_SIZE) { /* Is the index out of the transmit buffer? */ OutIndexR = 0x00U; /* Set index on the first item into the transmit buffer */ } AS2_OutLen--; /* Decrease number of chars in the transmit buffer */ if (AS2_OutLen != 0U) { /* Is number of bytes in the transmit buffer greater then 0? */ SerFlag |= RUNINT_FROM_TX; /* Set flag "running int from TX"? */ (void)ASerialLdd2_SendBlock(ASerialLdd2_DeviceDataPtr, (LDD_TData *)&OutBuffer[OutIndexR], 1U); /* Send one data byte */ } else { SerFlag &= (byte)~(RUNINT_FROM_TX); /* Clear "running int from TX" and "full TX buff" flags */ if (!(OnFreeTxBufSemaphore)) { /* Is the OnFreeTXBuf flag blocked ?*/ OnFlags |= ON_FREE_TX; /* If not, set the OnFreeTxBuf flag */ } } if ((OnFlags & ON_TX_CHAR) != 0x00U) { /* Is flag "OnTxChar" set? */ AS2_OnTxChar(); /* If yes then invoke user event */ } if ((OnFlags & ON_FREE_TX) != 0x00U) { /* Is flag "OnFreeTxBuf" set? */ AS2_OnFreeTxBuf(); /* If yes then invoke user event */ } }
/* ** =================================================================== ** Method : AS2_SendBlock (component AsynchroSerial) ** Description : ** Sends a block of characters to the channel. ** This method is available only if non-zero length of the ** output buffer is defined and the transmitter property is ** enabled. ** Parameters : ** NAME - DESCRIPTION ** * Ptr - Pointer to the block of data to send ** Size - Size of the block ** * Snd - Pointer to number of data that are sent ** (moved to buffer) ** Returns : ** --- - Error code, possible codes: ** ERR_OK - OK ** ERR_SPEED - This device does not work in ** the active speed mode ** ERR_TXFULL - It was not possible to send ** requested number of bytes ** =================================================================== */ byte AS2_SendBlock(AS2_TComData *Ptr, word Size, word *Snd) { word count = 0x00U; /* Number of sent chars */ AS2_TComData *TmpPtr = Ptr; /* Temporary output buffer pointer */ bool tmpOnFreeTxBufSemaphore = OnFreeTxBufSemaphore; /* Local copy of OnFreeTxBufSemaphore state */ while ((count < Size) && (AS2_OutLen < AS2_OUT_BUF_SIZE)) { /* While there is some char desired to send left and output buffer is not full do */ EnterCritical(); /* Enter the critical section */ OnFreeTxBufSemaphore = TRUE; /* Set the OnFreeTxBufSemaphore to block OnFreeTxBuf calling */ AS2_OutLen++; /* Increase number of bytes in the transmit buffer */ OutBuffer[OutIndexW++] = *TmpPtr++; /* Store char to buffer */ if (OutIndexW >= AS2_OUT_BUF_SIZE) { /* Is the index out of the transmit buffer? */ OutIndexW = 0x00U; /* Set index to the first item in the transmit buffer */ } count++; /* Increase the count of sent data */ if ((count == Size) || (AS2_OutLen == AS2_OUT_BUF_SIZE)) { /* Is the last desired char put into buffer or the buffer is full? */ if (!tmpOnFreeTxBufSemaphore) { /* Was the OnFreeTxBufSemaphore clear before enter the method? */ OnFreeTxBufSemaphore = FALSE; /* If yes then clear the OnFreeTxBufSemaphore */ } } if ((SerFlag & RUNINT_FROM_TX) == 0U) { SerFlag |= RUNINT_FROM_TX; /* Set flag "running int from TX"? */ (void)ASerialLdd2_SendBlock(ASerialLdd2_DeviceDataPtr, (LDD_TData *)&OutBuffer[OutIndexR], 1U); /* Send one data byte */ } ExitCritical(); /* Exit the critical section */ } *Snd = count; /* Return number of sent chars */ if (count != Size) { /* Is the number of sent chars less then desired number of chars */ return ERR_TXFULL; /* If yes then error */ } return ERR_OK; /* OK */ }
/* ** =================================================================== ** 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 */ ASerialLdd2_Main(ASerialLdd2_DeviceDataPtr); OutBuffer = Chr; /* Save character */ if (ASerialLdd2_SendBlock(ASerialLdd2_DeviceDataPtr, (LDD_TData *)&OutBuffer, 1U) == ERR_BUSY) { /* Send one data byte */ OutBuffer = TmpChr; /* If is device busy, restore OutBuffer value */ return ERR_TXFULL; } ASerialLdd2_Main(ASerialLdd2_DeviceDataPtr); return ERR_OK; /* OK */ }
/* ** =================================================================== ** Method : HWEnDi (component AsynchroSerial) ** ** Description : ** Enables or disables the peripheral(s) associated with the bean. ** The method is called automatically as a part of the Enable and ** Disable methods and several internal methods. ** This method is internal. It is used by Processor Expert only. ** =================================================================== */ static void HWEnDi(void) { if (EnUser) { /* Enable device? */ (void)ASerialLdd2_Enable(ASerialLdd2_DeviceDataPtr); /* Enable device */ (void)ASerialLdd2_ReceiveBlock(ASerialLdd2_DeviceDataPtr, &BufferRead, 1U); /* Receive one data byte */ if ((COREUART_OutLen) != 0U) { /* Is number of bytes in the transmit buffer greater then 0? */ SerFlag |= RUNINT_FROM_TX; /* Set flag "running int from TX"? */ (void)ASerialLdd2_SendBlock(ASerialLdd2_DeviceDataPtr, (LDD_TData *)&OutBuffer[OutIndexR], 1U); /* Send one data byte */ } } else { (void)ASerialLdd2_Disable(ASerialLdd2_DeviceDataPtr); /* Disable device */ } }
/* ** =================================================================== ** Method : COREUART_ASerialLdd2_OnBlockSent (component AsynchroSerial) ** ** Description : ** This event is called after the last character from the output ** buffer is moved to the transmitter. ** This method is internal. It is used by Processor Expert only. ** =================================================================== */ void ASerialLdd2_OnBlockSent(LDD_TUserData *UserDataPtr) { (void)UserDataPtr; /* Parameter is not used, suppress unused argument warning */ OutIndexR++; if (OutIndexR >= COREUART_OUT_BUF_SIZE) { /* Is the index out of the transmit buffer? */ OutIndexR = 0x00U; /* Set index on the first item into the transmit buffer */ } COREUART_OutLen--; /* Decrease number of chars in the transmit buffer */ if (COREUART_OutLen != 0U) { /* Is number of bytes in the transmit buffer greater then 0? */ SerFlag |= RUNINT_FROM_TX; /* Set flag "running int from TX"? */ (void)ASerialLdd2_SendBlock(ASerialLdd2_DeviceDataPtr, (LDD_TData *)&OutBuffer[OutIndexR], 1U); /* Send one data byte */ } else { SerFlag &= (byte)~(RUNINT_FROM_TX); /* Clear "running int from TX" and "full TX buff" flags */ } }
/* ** =================================================================== ** Method : AS2_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 AS2_SendChar(AS2_TComData Chr) { if (AS2_OutLen == AS2_OUT_BUF_SIZE) { /* Is number of chars in buffer is the same as a size of the transmit buffer */ return ERR_TXFULL; /* If yes then error */ } EnterCritical(); /* Disable global interrupts */ AS2_OutLen++; /* Increase number of bytes in the transmit buffer */ OutBuffer[OutIndexW++] = Chr; /* Store char to buffer */ if (OutIndexW >= AS2_OUT_BUF_SIZE) { /* Is the pointer out of the transmit buffer */ OutIndexW = 0x00U; /* Set index to first item in the transmit buffer */ } if ((SerFlag & RUNINT_FROM_TX) == 0U) { SerFlag |= RUNINT_FROM_TX; /* Set flag "running int from TX"? */ (void)ASerialLdd2_SendBlock(ASerialLdd2_DeviceDataPtr, (LDD_TData *)&OutBuffer[OutIndexR], 1U); /* Send one data byte */ } ExitCritical(); /* Enable global interrupts */ return ERR_OK; /* OK */ }