/* send target length data use poll mode, with time out.  */
int32_t serial_send_blocked(serial_t *obj, char *ptxbuf, uint32_t len, uint32_t timeout_ms)
/* send target length data use poll mode, with time out.  */
int32_t serial_send_blocked(serial_t *obj, char *ptxbuf, uint32_t len, uint32_t timeout_ms)
{
	UART_TypeDef* UARTx = UART_DEV_TABLE[obj->uart_idx].UARTx;
	uint32_t cnt = 0;
	uint32_t startcount = SYSTIMER_TickGet();
	obj->tx_len = len;
	while (1) {
		while (!serial_writable(obj));
		UART_CharPut(UARTx, *ptxbuf);
		ptxbuf++;
		cnt++;
		if (cnt == len) {
			break;
		}
		if (SYSTIMER_GetPassTime(startcount) > timeout_ms) {
			break;
		}
	}
	return cnt;
}