Init
This commit is contained in:
		
						commit
						04850f0aa8
					
				|  | @ -0,0 +1,18 @@ | |||
| //
 | ||||
| // Created by xemon on 01.09.22.
 | ||||
| //
 | ||||
| 
 | ||||
| #ifndef SERIALPORT_SERIALPORT_H | ||||
| #define SERIALPORT_SERIALPORT_H | ||||
| 
 | ||||
| #include "SerialPortIO.h" | ||||
| 
 | ||||
| uint16_t SerialPortReceive(tSerialPortIO *io, uint8_t *data, uint16_t size, uint32_t timeout); | ||||
| 
 | ||||
| uint16_t SerialPortReceiveTo(tSerialPortIO *io, uint8_t *data, uint16_t size, uint8_t symbol, uint32_t timeout); | ||||
| 
 | ||||
| uint16_t SerialPortTransmit(tSerialPortIO *io, uint8_t *data, uint16_t size, uint32_t timeout); | ||||
| 
 | ||||
| void SerialPortClearRxBuffer(tSerialPortIO *io); | ||||
| 
 | ||||
| #endif //SERIALPORT_SERIALPORT_H
 | ||||
|  | @ -0,0 +1,43 @@ | |||
| //
 | ||||
| // Created by xemon on 01.09.22.
 | ||||
| //
 | ||||
| 
 | ||||
| #include "SerialPort.h" | ||||
| #include "SystemDelayInterface.h" | ||||
| 
 | ||||
| uint16_t SerialPortReceive(tSerialPortIO *io, uint8_t *data, uint16_t size, uint32_t timeout) { | ||||
|     return io->receive(io->env, data, size, timeout); | ||||
| } | ||||
| 
 | ||||
| void SerialPortClearRxBuffer(tSerialPortIO *io) { | ||||
|     uint8_t byte; | ||||
|     uint32_t antiSpamTimeout = SystemGetMs() + 10; | ||||
|     while ((antiSpamTimeout > SystemGetMs()) && io->receive(io->env, &byte, 1, 0)); | ||||
| } | ||||
| 
 | ||||
| uint16_t SerialPortReceiveTo(tSerialPortIO *io, uint8_t *data, uint16_t size, uint8_t symbol, uint32_t timeout) { | ||||
| 
 | ||||
|     uint8_t dataToSymbol; | ||||
|     int i = 0; | ||||
| 
 | ||||
|     uint32_t endMs = SystemGetMs() + timeout; | ||||
|     uint32_t leftMs; | ||||
| 
 | ||||
|     while (size && ((timeout == SystemWaitForever) || (endMs > SystemGetMs()))) { | ||||
| 
 | ||||
|         leftMs = (timeout == SystemWaitForever) ? SystemWaitForever : endMs - SystemGetMs(); | ||||
|         if (SerialPortReceive(io, &dataToSymbol, 1, leftMs)) { | ||||
|             size--; | ||||
|             data[i] = dataToSymbol; | ||||
|             i++; | ||||
|             if (dataToSymbol == symbol) { | ||||
|                 break; | ||||
|             } | ||||
|         } | ||||
|     } | ||||
|     return i; | ||||
| } | ||||
| 
 | ||||
| uint16_t SerialPortTransmit(tSerialPortIO *io, uint8_t *data, uint16_t size, uint32_t timeout) { | ||||
|     return io->transmit(io->env, data, size, timeout); | ||||
| } | ||||
|  | @ -0,0 +1,22 @@ | |||
| { | ||||
|   "dep": [ | ||||
|     { | ||||
|       "type": "git", | ||||
|       "provider": "NAVIGATOR_UVEOS_NATION_TELIT", | ||||
|       "repo": "SerialPortInterface" | ||||
|     }, | ||||
|     { | ||||
|       "type": "git", | ||||
|       "provider": "NAVIGATOR_UVEOS_NATION_TELIT", | ||||
|       "repo": "SystemDelayInterface" | ||||
|     } | ||||
|   ], | ||||
|   "cmake": { | ||||
|     "inc_dirs": [ | ||||
|       "Inc" | ||||
|     ], | ||||
|     "srcs": [ | ||||
|       "Src/**.c" | ||||
|     ] | ||||
|   } | ||||
| } | ||||
		Loading…
	
		Reference in New Issue