/********************************************************************* * * SEGGER_RTT_Write * * Function description * Stores a specified number of characters in SEGGER RTT * control block which is then read by the host. * * Parameters * BufferIndex Index of "Up"-buffer to be used (e.g. 0 for "Terminal"). * pBuffer Pointer to character array. Does not need to point to a \0 terminated string. * NumBytes Number of bytes to be stored in the SEGGER RTT control block. * * Return value * Number of bytes which have been stored in the "Up"-buffer. * * Notes * (1) If there is not enough space in the "Up"-buffer, remaining characters of pBuffer are dropped. */ unsigned SEGGER_RTT_Write(unsigned BufferIndex, const void* pBuffer, unsigned NumBytes) { unsigned Status; // INIT(); SEGGER_RTT_LOCK(); // // Call the non-locking write function // Status = SEGGER_RTT_WriteNoLock(BufferIndex, pBuffer, NumBytes); // // Finish up. // SEGGER_RTT_UNLOCK(); // return Status; }
static void serial_tx(void const * p_context, char const * buffer, size_t len) { if (len) { uint32_t idx = 0; uint32_t processed; uint32_t watchdog_counter = 10; do { processed = SEGGER_RTT_WriteNoLock(0, &buffer[idx], len); idx += processed; len -= processed; if (processed == 0) { // If RTT is not connected then ensure that logger does not block watchdog_counter--; if (watchdog_counter == 0) { break; } } } while (len); } }