HyperDbg Debugger
Loading...
Searching...
No Matches
usif.c File Reference
#include "common.h"

Macros

#define USIF_FIFO_STAT   0x00000044
 
#define USIF_FIFO_STAT_TXFFS   0x00FF0000
 
#define USIF_FIFO_STAT_RXFFS   0x000000FF
 
#define USIF_TXD   0x00040000
 
#define USIF_RXD   0x00080000
 

Functions

BOOLEAN UsifInitializePort (_In_opt_ _Null_terminated_ PCHAR LoadOptions, _Inout_ PCPPORT Port, BOOLEAN MemoryMapped, UCHAR AccessSize, UCHAR BitWidth)
 
BOOLEAN UsifSetBaud (_Inout_ PCPPORT Port, ULONG Rate)
 
UART_STATUS UsifGetByte (_Inout_ PCPPORT Port, _Out_ PUCHAR Byte)
 
UART_STATUS UsifPutByte (_Inout_ PCPPORT Port, UCHAR Byte, BOOLEAN BusyWait)
 
BOOLEAN UsifRxReady (_Inout_ PCPPORT Port)
 

Macro Definition Documentation

◆ USIF_FIFO_STAT

#define USIF_FIFO_STAT   0x00000044

◆ USIF_FIFO_STAT_RXFFS

#define USIF_FIFO_STAT_RXFFS   0x000000FF

◆ USIF_FIFO_STAT_TXFFS

#define USIF_FIFO_STAT_TXFFS   0x00FF0000

◆ USIF_RXD

#define USIF_RXD   0x00080000

◆ USIF_TXD

#define USIF_TXD   0x00040000

Function Documentation

◆ UsifGetByte()

UART_STATUS UsifGetByte ( _Inout_ PCPPORT Port,
_Out_ PUCHAR Byte )
138{
139 ULONG Stat;
140 ULONG Value;
141
142 *Byte = 0;
143
144 if ((Port == NULL) || (Port->Address == NULL))
145 {
146 return UartNotReady;
147 }
148
149 //
150 // Get FIFO status.
151 //
152
153 Stat = READ_REGISTER_ULONG((PULONG)(Port->Address + USIF_FIFO_STAT));
154
155 //
156 // Is at least one character available?
157 //
158
159 if ((Stat & USIF_FIFO_STAT_RXFFS) != 0)
160 {
161 //
162 // Fetch the data byte.
163 //
164
165 Value = READ_REGISTER_ULONG((PULONG)(Port->Address + USIF_RXD));
166 *Byte = Value & (UCHAR)0xFF;
167 return UartSuccess;
168 }
169
170 return UartNoData;
171}
unsigned char UCHAR
Definition BasicTypes.h:35
unsigned long ULONG
Definition BasicTypes.h:37
RequestedActionOfThePacket Value(0x1) 00000000
#define READ_REGISTER_ULONG
Definition uartp.h:41
#define USIF_RXD
Definition usif.c:25
#define USIF_FIFO_STAT_RXFFS
Definition usif.c:23
#define USIF_FIFO_STAT
Definition usif.c:21

◆ UsifInitializePort()

BOOLEAN UsifInitializePort ( _In_opt_ _Null_terminated_ PCHAR LoadOptions,
_Inout_ PCPPORT Port,
BOOLEAN MemoryMapped,
UCHAR AccessSize,
UCHAR BitWidth )
64{
65 UNREFERENCED_PARAMETER(LoadOptions);
66 UNREFERENCED_PARAMETER(AccessSize);
67 UNREFERENCED_PARAMETER(BitWidth);
68
69 if (MemoryMapped == FALSE)
70 {
71 return FALSE;
72 }
73
74 Port->Flags = 0;
75 return TRUE;
76}
#define TRUE
Definition BasicTypes.h:55
#define FALSE
Definition BasicTypes.h:54

◆ UsifPutByte()

UART_STATUS UsifPutByte ( _Inout_ PCPPORT Port,
UCHAR Byte,
BOOLEAN BusyWait )
200{
201 if ((Port == NULL) || (Port->Address == NULL))
202 {
203 return UartNotReady;
204 }
205
206 //
207 // Wait for port to be free and FIFO not full.
208 //
209
210 if (BusyWait != FALSE)
211 {
212 while (READ_REGISTER_ULONG((PULONG)(Port->Address + USIF_FIFO_STAT)) &
214 ;
215 }
216 else if (READ_REGISTER_ULONG((PULONG)(Port->Address + USIF_FIFO_STAT)) &
218 {
219 return UartNotReady;
220 }
221
222 //
223 // Send the byte.
224 //
225
226 WRITE_REGISTER_ULONG((PULONG)(Port->Address + USIF_TXD), (ULONG)Byte);
227 return UartSuccess;
228}
#define WRITE_REGISTER_ULONG
Definition uartp.h:42
#define USIF_FIFO_STAT_TXFFS
Definition usif.c:22
#define USIF_TXD
Definition usif.c:24

◆ UsifRxReady()

BOOLEAN UsifRxReady ( _Inout_ PCPPORT Port)
250{
251 ULONG Stat;
252
253 if ((Port == NULL) || (Port->Address == NULL))
254 {
255 return FALSE;
256 }
257
258 //
259 // Read the STAT Register to determine if there is any pending
260 // data to read.
261 //
262
263 Stat = READ_REGISTER_ULONG((PULONG)(Port->Address + USIF_FIFO_STAT));
264 if ((Stat & USIF_FIFO_STAT_RXFFS) != 0)
265 {
266 return TRUE;
267 }
268
269 return FALSE;
270}

◆ UsifSetBaud()

BOOLEAN UsifSetBaud ( _Inout_ PCPPORT Port,
ULONG Rate )
101{
102 if ((Port == NULL) || (Port->Address == NULL))
103 {
104 return FALSE;
105 }
106
107 //
108 // Remember the baud rate.
109 //
110
111 Port->BaudRate = Rate;
112 return TRUE;
113}