/*---------------------------------------------------------------------------------------------------------------------- Function: SspWriteData Description: Queues a data array for transfer on the target SSP peripheral. Requires: - psSspPeripheral_ has been requested and holds a valid pointer to a transmit buffer; even if a transmission is in progress, the node in the buffer that is currently being sent will not be destroyed during this function. - The chip select line of the SSP device should be asserted - u32Size_ is the number of bytes in the data array - u8Data_ points to the first byte of the data array Promises: - adds the data message at psSspPeripheral_->pTransmitBuffer that will be sent by the SSP application when it is available. - Returns the message token assigned to the message; 0 is returned if the message cannot be queued in which case G_u32MessagingFlags can be checked for the reason */ u32 SspWriteData(SspPeripheralType* psSspPeripheral_, u32 u32Size_, u8* pu8Data_) { u8 u8FullCycles; u8 u8Remainder; u32 u32Index = 0; u32 u32Token; u8FullCycles = u32Size_ / MAX_TX_MESSAGE_LENGTH; u8Remainder = u32Size_ % MAX_TX_MESSAGE_LENGTH; /* Slice up the data to the allowable message size */ for(u8 i = 0; i < u8FullCycles; i++) { u32Token = QueueMessage(MAX_TX_MESSAGE_LENGTH, pu8Data_ + u32Index, &psSspPeripheral_->pTransmitBuffer); if(!u32Token) { return(0); } /* Only update the index if pu8Data_ isn't pointed at the dummy array since that data should be repeated */ if(pu8Data_ != &SSP_au8Dummies[0]) { u32Index += MAX_TX_MESSAGE_LENGTH; } /* If the system is initializing, manually cycle the SSP task through one iteration to send the message */ if(G_u32SystemFlags & _SYSTEM_INITIALIZING) { SspManualMode(); } } /* Complete the remaining bytes and assign the token to this message */ u32Token = QueueMessage(u8Remainder, pu8Data_ + u32Index, &psSspPeripheral_->pTransmitBuffer); if(u32Token) { if(G_u32SystemFlags & _SYSTEM_INITIALIZING) { SspManualMode(); } } return(u32Token); } /* end SspWriteData() */
/*---------------------------------------------------------------------------------------------------------------------- Function: SspWriteData Description: Queues a data array for transfer on the target SSP peripheral. Requires: - psSspPeripheral_ has been requested and holds a valid pointer to a transmit buffer; even if a transmission is in progress, the node in the buffer that is currently being sent will not be destroyed during this function. - The chip select line of the SSP device should be asserted - u32Size_ is the number of bytes in the data array - u8Data_ points to the first byte of the data array Promises: - adds the data message at psSspPeripheral_->psTransmitBuffer that will be sent by the SSP application when it is available. - Returns the message token assigned to the message; 0 is returned if the message cannot be queued in which case G_u32MessagingFlags can be checked for the reason */ u32 SspWriteData(SspPeripheralType* psSspPeripheral_, u32 u32Size_, u8* pu8Data_) { u32 u32Token; u32Token = QueueMessage(&psSspPeripheral_->psTransmitBuffer, u32Size_, pu8Data_); if( u32Token == 0 ) { return(0); } /* If the system is initializing, manually cycle the SSP task through one iteration to send the message */ if(G_u32SystemFlags & _SYSTEM_INITIALIZING) { SspManualMode(); } return(u32Token); } /* end SspWriteData() */
/*---------------------------------------------------------------------------------------------------------------------- Function: SspWriteByte Description: Queues a single byte for transfer on the target SSP peripheral. Requires: - psSspPeripheral_ has been requested. - The chip select line of the SSP device should be asserted Promises: - Creates a 1-byte message at psSspPeripheral_->psTransmitBuffer that will be sent by the SSP application when it is available. - Returns the message token assigned to the message */ u32 SspWriteByte(SspPeripheralType* psSspPeripheral_, u8 u8Byte_) { u32 u32Token; u8 u8Data = u8Byte_; u32Token = QueueMessage(&psSspPeripheral_->psTransmitBuffer, 1, &u8Data); if( u32Token != 0 ) { /* If the system is initializing, we want to manually cycle the SSP task through one iteration to send the message */ if(G_u32SystemFlags & _SYSTEM_INITIALIZING) { SspManualMode(); } } return(u32Token); } /* end SspWriteByte() */