/* ** =================================================================== ** Method : SM1_SMasterLdd1_OnBlockSent (component SynchroMaster) ** ** Description : ** This event is called after the last character from the output ** buffer is moved to the transmitter. This event is available ** only if the SendBlock method is enabled. The event services ** the event of the inherited component and eventually invokes ** other events. ** This method is internal. It is used by Processor Expert only. ** =================================================================== */ void SMasterLdd1_OnBlockSent(LDD_TUserData *UserDataPtr) { register byte Flags = 0U; /* 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? */ Flags |= ON_TX_CHAR ; /* Set the OnTXChar flag */ } OutIndexR++; if (OutIndexR >= SM1_OUT_BUF_SIZE) { /* Is the index out of the transmit buffer? */ OutIndexR = 0x00U; /* Set index on the first item into the transmit buffer */ } SM1_OutLen--; /* Decrease number of chars in the transmit buffer */ if (SM1_OutLen != 0U) { /* Is number of bytes in the transmit buffer greater then 0? */ SerFlag |= RUNINT_FROM_TX; /* Set flag "running int from TX"? */ (void)SMasterLdd1_SendBlock(SMasterLdd1_DeviceDataPtr, (LDD_TData *)&OutBuffer[OutIndexR], 1U); /* Send one data byte */ } else { SerFlag &= (byte)~(RUNINT_FROM_TX | FULL_TX); /* Clear "running int from TX" and "full TX buff" flags */ if (!(OnFreeTxBufSemaphore)) { /* Is the OnFreeTXBuf flag blocked ?*/ Flags |= ON_FREE_TX; /* If not, set the OnFreeTxBuf flag */ } } if ((Flags & ON_TX_CHAR) != 0U) { /* Is flag "OnTxChar" set? */ SM1_OnTxChar(); /* Invoke user event */ } if ((Flags & ON_FREE_TX) != 0U) { /* Is flag "OnFreeTxBuf" set? */ SM1_OnFreeTxBuf(); /* Invoke user event */ } }
/* ** =================================================================== ** Method : SM1_SendBlock (component SynchroMaster) ** Description : ** Send a block of characters to the channel. This method is ** only available if a non-zero length of output buffer is ** defined. ** 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_DISABLED - Device is disabled (only if ** output DMA is supported and enabled) ** ERR_TXFULL - It was not possible to send ** requested number of bytes ** =================================================================== */ byte SM1_SendBlock(SM1_TComData *Ptr, word Size, word *Snd) { word count = 0x00U; /* Number of sent chars */ SM1_TComData *TmpPtr = Ptr; /* Temporary output buffer pointer */ bool tmpOnFreeTxBufSemaphore = OnFreeTxBufSemaphore; /* Local copy of OnFreeTxBufSemaphore state */ while((count < Size) && (SM1_OutLen < SM1_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 */ SM1_OutLen++; /* Increase number of bytes in the transmit buffer */ OutBuffer[OutIndexW++] = *TmpPtr++; /* Store char to buffer */ if (OutIndexW >= SM1_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) || (SM1_OutLen == SM1_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 ((EnUser) && ((SerFlag & RUNINT_FROM_TX) == 0U)) { /* Is the device enabled by user? */ SerFlag |= RUNINT_FROM_TX; /* Set flag "running int from TX"? */ (void)SMasterLdd1_SendBlock(SMasterLdd1_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 : SM1_SendBlock (component SynchroMaster) ** Description : ** Send a block of characters to the channel. This method is ** only available if a non-zero length of output buffer is ** defined. ** 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_DISABLED - Device is disabled (only if ** output DMA is supported and enabled) ** ERR_TXFULL - It was not possible to send ** requested number of bytes ** =================================================================== */ byte SM1_SendBlock(SM1_TComData *Ptr, word Size, word *Snd) { word count = 0x00U; /* Number of sent chars */ SM1_TComData *TmpPtr = Ptr; /* Temporary output buffer pointer */ while((count < Size) && (SM1_OutLen < SM1_OUT_BUF_SIZE)) { /* While there is some char desired to send left and output buffer is not full do */ EnterCritical(); /* Enter the critical section */ SM1_OutLen++; /* Increase number of bytes in the transmit buffer */ OutBuffer[OutIndexW++] = *TmpPtr++; /* Store char to buffer */ if (OutIndexW >= SM1_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 ((SerFlag & RUNINT_FROM_TX) == 0U) { SerFlag |= RUNINT_FROM_TX; /* Set flag "running int from TX"? */ (void)SMasterLdd1_SendBlock(SMasterLdd1_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 : SM1_SMasterLdd1_OnBlockSent (component SynchroMaster) ** ** Description : ** This event is called after the last character from the output ** buffer is moved to the transmitter. This event is available ** only if the SendBlock method is enabled. The event services ** the event of the inherited component and eventually invokes ** other events. ** This method is internal. It is used by Processor Expert only. ** =================================================================== */ void SMasterLdd1_OnBlockSent(LDD_TUserData *UserDataPtr) { (void)UserDataPtr; /* Parameter is not used, suppress unused argument warning */ OutIndexR++; if (OutIndexR >= SM1_OUT_BUF_SIZE) { /* Is the index out of the transmit buffer? */ OutIndexR = 0x00U; /* Set index on the first item into the transmit buffer */ } SM1_OutLen--; /* Decrease number of chars in the transmit buffer */ if (SM1_OutLen != 0U) { /* Is number of bytes in the transmit buffer greater then 0? */ SerFlag |= RUNINT_FROM_TX; /* Set flag "running int from TX"? */ (void)SMasterLdd1_SendBlock(SMasterLdd1_DeviceDataPtr, (LDD_TData *)&OutBuffer[OutIndexR], 1U); /* Send one data byte */ } else { SerFlag &= (byte)~(RUNINT_FROM_TX | FULL_TX); /* Clear "running int from TX" and "full TX buff" flags */ } }
/* ** =================================================================== ** Method : SM1_SendChar (component SynchroMaster) ** Description : ** Sends one character to the channel. ** 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_DISABLED - Device is disabled (only if ** output DMA is supported and enabled) ** ERR_TXFULL - Transmitter is full ** =================================================================== */ byte SM1_SendChar(SM1_TComData Chr) { if (SM1_OutLen == SM1_OUT_BUF_SIZE) { /* Is number of chars in buffer the same as the size of transmit buffer? */ return ERR_TXFULL; /* If yes then error */ } EnterCritical(); /* Disable global interrupts */ SM1_OutLen++; /* Increase number of bytes in the transmit buffer */ OutBuffer[OutIndexW++] = Chr; /* Store char to buffer */ if (OutIndexW >= SM1_OUT_BUF_SIZE) { /* Is the index out of the transmit buffer? */ OutIndexW = 0x00U; /* Set index to the first item in the transmit buffer */ } if ((EnUser) && ((SerFlag & RUNINT_FROM_TX) == 0U)) { /* Is the device enabled by user? */ SerFlag |= RUNINT_FROM_TX; /* Set flag "running int from TX"? */ (void)SMasterLdd1_SendBlock(SMasterLdd1_DeviceDataPtr, (LDD_TData *)&OutBuffer[OutIndexR], 1U); /* Send one data byte */ } ExitCritical(); /* Enable global interrupts */ return ERR_OK; }
/* ** =================================================================== ** Method : HWEnDi (component SynchroMaster) ** ** Description : ** Enables or disables the peripheral(s) associated with the ** component. 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)SMasterLdd1_Enable(SMasterLdd1_DeviceDataPtr); /* Enable SPI device */ if (SetAttributeCmd) { /* Is request change SPI attribute in enable code? */ SetAttributeCmd = FALSE; /* Disable settings SPI attribute in enable code */ SMasterLdd1_SelectConfiguration(SMasterLdd1_DeviceDataPtr, 0x00U, SpiClockfeatures); /* Set SPI attribute index. */ } (void)SMasterLdd1_ReceiveBlock(SMasterLdd1_DeviceDataPtr, &BufferRead, 1U); /* Receive one data byte */ if ((SM1_OutLen) != 0U) { /* Is number of bytes in the transmit buffer greater then 0? */ SerFlag |= RUNINT_FROM_TX; /* Set flag "running int from TX"? */ (void)SMasterLdd1_SendBlock(SMasterLdd1_DeviceDataPtr, (LDD_TData *)&OutBuffer[OutIndexR], 1U); /* Send one data byte */ } } else { SerFlag &= (byte)~(RUNINT_FROM_TX); /* Clear RUNINT_FROM_TX flag */ (void)SMasterLdd1_Disable(SMasterLdd1_DeviceDataPtr); /* Disable device */ } }