| 516 | /*-----------------------------------------------------------*/ |
| 517 | |
| 518 | size_t xStreamBufferSend( StreamBufferHandle_t xStreamBuffer, |
| 519 | const void * pvTxData, |
| 520 | size_t xDataLengthBytes, |
| 521 | TickType_t xTicksToWait ) |
| 522 | { |
| 523 | StreamBuffer_t * const pxStreamBuffer = xStreamBuffer; |
| 524 | size_t xReturn, xSpace = 0; |
| 525 | size_t xRequiredSpace = xDataLengthBytes; |
| 526 | TimeOut_t xTimeOut; |
| 527 | size_t xMaxReportedSpace = 0; |
| 528 | |
| 529 | configASSERT( pvTxData ); |
| 530 | configASSERT( pxStreamBuffer ); |
| 531 | |
| 532 | /* The maximum amount of space a stream buffer will ever report is its length |
| 533 | * minus 1. */ |
| 534 | xMaxReportedSpace = pxStreamBuffer->xLength - ( size_t ) 1; |
| 535 | |
| 536 | /* This send function is used to write to both message buffers and stream |
| 537 | * buffers. If this is a message buffer then the space needed must be |
| 538 | * increased by the amount of bytes needed to store the length of the |
| 539 | * message. */ |
| 540 | if( ( pxStreamBuffer->ucFlags & sbFLAGS_IS_MESSAGE_BUFFER ) != ( uint8_t ) 0 ) |
| 541 | { |
| 542 | xRequiredSpace += sbBYTES_TO_STORE_MESSAGE_LENGTH; |
| 543 | |
| 544 | /* Overflow? */ |
| 545 | configASSERT( xRequiredSpace > xDataLengthBytes ); |
| 546 | |
| 547 | /* If this is a message buffer then it must be possible to write the |
| 548 | * whole message. */ |
| 549 | if( xRequiredSpace > xMaxReportedSpace ) |
| 550 | { |
| 551 | /* The message would not fit even if the entire buffer was empty, |
| 552 | * so don't wait for space. */ |
| 553 | xTicksToWait = ( TickType_t ) 0; |
| 554 | } |
| 555 | else |
| 556 | { |
| 557 | mtCOVERAGE_TEST_MARKER(); |
| 558 | } |
| 559 | } |
| 560 | else |
| 561 | { |
| 562 | /* If this is a stream buffer then it is acceptable to write only part |
| 563 | * of the message to the buffer. Cap the length to the total length of |
| 564 | * the buffer. */ |
| 565 | if( xRequiredSpace > xMaxReportedSpace ) |
| 566 | { |
| 567 | xRequiredSpace = xMaxReportedSpace; |
| 568 | } |
| 569 | else |
| 570 | { |
| 571 | mtCOVERAGE_TEST_MARKER(); |
| 572 | } |
| 573 | } |
| 574 | |
| 575 | if( xTicksToWait != ( TickType_t ) 0 ) |
no test coverage detected