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

Macros

#define ULCON   0x00
 
#define UCON   0x04
 
#define UFCON   0x08
 
#define UTRSTAT   0x10
 
#define UERSTAT   0x14
 
#define UFSTAT   0x18
 
#define UTXH   0x20
 
#define URXH   0x24
 
#define UINTP   0x30
 
#define UINTM   0x38
 
#define UFSTAT_TXFE   (1 << 24)
 
#define UTRSTAT_RXFE   (1 << 0)
 
#define UERSTAT_OE   (1 << 0)
 
#define UERSTAT_PE   (1 << 1)
 
#define UERSTAT_FE   (1 << 2)
 
#define UERSTAT_BE   (1 << 3)
 

Functions

BOOLEAN Sam5250SetBaud (_Inout_ PCPPORT Port, ULONG Rate)
 
BOOLEAN Sam5250InitializePort (_In_opt_ _Null_terminated_ PCHAR LoadOptions, _Inout_ PCPPORT Port, BOOLEAN MemoryMapped, UCHAR AccessSize, UCHAR BitWidth)
 
UART_STATUS Sam5250GetByte (_Inout_ PCPPORT Port, _Out_ PUCHAR Byte)
 
UART_STATUS Sam5250PutByte (_Inout_ PCPPORT Port, UCHAR Byte, BOOLEAN BusyWait)
 
BOOLEAN Sam5250RxReady (_Inout_ PCPPORT Port)
 

Variables

UART_HARDWARE_DRIVER Sam5250HardwareDriver
 

Macro Definition Documentation

◆ UCON

#define UCON   0x04

◆ UERSTAT

#define UERSTAT   0x14

◆ UERSTAT_BE

#define UERSTAT_BE   (1 << 3)

◆ UERSTAT_FE

#define UERSTAT_FE   (1 << 2)

◆ UERSTAT_OE

#define UERSTAT_OE   (1 << 0)

◆ UERSTAT_PE

#define UERSTAT_PE   (1 << 1)

◆ UFCON

#define UFCON   0x08

◆ UFSTAT

#define UFSTAT   0x18

◆ UFSTAT_TXFE

#define UFSTAT_TXFE   (1 << 24)

◆ UINTM

#define UINTM   0x38

◆ UINTP

#define UINTP   0x30

◆ ULCON

#define ULCON   0x00

◆ URXH

#define URXH   0x24

◆ UTRSTAT

#define UTRSTAT   0x10

◆ UTRSTAT_RXFE

#define UTRSTAT_RXFE   (1 << 0)

◆ UTXH

#define UTXH   0x20

Function Documentation

◆ Sam5250GetByte()

UART_STATUS Sam5250GetByte ( _Inout_ PCPPORT Port,
_Out_ PUCHAR Byte )
194{
195 ULONG Fsr;
196 ULONG Error;
197 ULONG Value;
198
199 if ((Port == NULL) || (Port->Address == NULL))
200 {
201 return UartNotReady;
202 }
203
204 //
205 // Get FIFO status.
206 //
207
208 Fsr = READ_REGISTER_ULONG((PULONG)(Port->Address + UTRSTAT));
209
210 //
211 // Is at least one character available?
212 //
213
214 if ((Fsr & UTRSTAT_RXFE) != 0)
215 {
216 //
217 // Fetch the data byte and associated error information.
218 //
219
220 Value = READ_REGISTER_ULONG((PULONG)(Port->Address + URXH));
221
222 //
223 // Check for errors. Deliberately don't treat overrun as an error.
224 //
225
226 Error = READ_REGISTER_ULONG((PULONG)(Port->Address + UERSTAT));
227 if ((Error & (UERSTAT_PE | UERSTAT_FE | UERSTAT_BE)) != 0)
228 {
229 *Byte = 0;
230 return UartError;
231 }
232
233 *Byte = Value & (UCHAR)0xFF;
234 return UartSuccess;
235 }
236
237 return UartNoData;
238}
unsigned char UCHAR
Definition BasicTypes.h:35
unsigned long ULONG
Definition BasicTypes.h:37
RequestedActionOfThePacket Value(0x1) 00000000
#define UTRSTAT
Definition sam5250.c:24
#define UERSTAT
Definition sam5250.c:25
#define UERSTAT_FE
Definition sam5250.c:37
#define UTRSTAT_RXFE
Definition sam5250.c:33
#define UERSTAT_BE
Definition sam5250.c:38
#define URXH
Definition sam5250.c:28
#define UERSTAT_PE
Definition sam5250.c:36
#define READ_REGISTER_ULONG
Definition uartp.h:41

◆ Sam5250InitializePort()

BOOLEAN Sam5250InitializePort ( _In_opt_ _Null_terminated_ PCHAR LoadOptions,
_Inout_ PCPPORT Port,
BOOLEAN MemoryMapped,
UCHAR AccessSize,
UCHAR BitWidth )
84{
85 UNREFERENCED_PARAMETER(LoadOptions);
86 UNREFERENCED_PARAMETER(AccessSize);
87 UNREFERENCED_PARAMETER(BitWidth);
88
89 if (MemoryMapped == FALSE)
90 {
91 return FALSE;
92 }
93
94 Port->Flags = 0;
95
96 //
97 // Disable UART.
98 //
99
100 WRITE_REGISTER_ULONG((PULONG)(Port->Address + UCON), 0);
101
102 //
103 // Set word length to 8 bits and disable parity.
104 //
105
106 WRITE_REGISTER_ULONG((PULONG)(Port->Address + ULCON), 0x3);
107
108 //
109 // Enable the FIFO.
110 //
111
112 WRITE_REGISTER_ULONG((PULONG)(Port->Address + UFCON), 0x1);
113
114 //
115 // Mask all interrupts.
116 //
117
118 WRITE_REGISTER_ULONG((PULONG)(Port->Address + UINTM), 0xF);
119
120 //
121 // Clear all interrupts.
122 //
123
124 WRITE_REGISTER_ULONG((PULONG)(Port->Address + UINTP), 0xF);
125
126 //
127 // Enable UART, enable Transmit (mode: 01) and Receive (mode: 01).
128 //
129
130 WRITE_REGISTER_ULONG((PULONG)(Port->Address + UCON), 0x5);
131 return TRUE;
132}
#define TRUE
Definition BasicTypes.h:55
#define FALSE
Definition BasicTypes.h:54
#define UCON
Definition sam5250.c:22
#define ULCON
Definition sam5250.c:21
#define UINTP
Definition sam5250.c:29
#define UINTM
Definition sam5250.c:30
#define UFCON
Definition sam5250.c:23
#define WRITE_REGISTER_ULONG
Definition uartp.h:42

◆ Sam5250PutByte()

UART_STATUS Sam5250PutByte ( _Inout_ PCPPORT Port,
UCHAR Byte,
BOOLEAN BusyWait )
267{
268 if ((Port == NULL) || (Port->Address == NULL))
269 {
270 return UartNotReady;
271 }
272
273 //
274 // Wait for port to be free and FIFO not full.
275 //
276 // _ARM_WORKAROUND_ Modem control is not supported.
277 //
278
279 if (BusyWait != FALSE)
280 {
281 while (READ_REGISTER_ULONG((PULONG)(Port->Address + UFSTAT)) & (UFSTAT_TXFE))
282 ;
283 }
284 else
285 {
286 if (READ_REGISTER_ULONG((PULONG)(Port->Address + UFSTAT)) & (UFSTAT_TXFE))
287 {
288 return UartNotReady;
289 }
290 }
291
292 //
293 // Send the byte.
294 //
295
296 WRITE_REGISTER_ULONG((PULONG)(Port->Address + UTXH), (ULONG)Byte);
297 return UartSuccess;
298}
#define UTXH
Definition sam5250.c:27
#define UFSTAT_TXFE
Definition sam5250.c:32
#define UFSTAT
Definition sam5250.c:26

◆ Sam5250RxReady()

BOOLEAN Sam5250RxReady ( _Inout_ PCPPORT Port)
320{
321 ULONG Flags;
322
323 if ((Port == NULL) || (Port->Address == NULL))
324 {
325 return FALSE;
326 }
327
328 //
329 // Read the Flag Register to determine if there is any pending data to read.
330 //
331
332 Flags = READ_REGISTER_ULONG((PULONG)(Port->Address + UTRSTAT));
333 if ((Flags & UTRSTAT_RXFE) != 0)
334 {
335 return TRUE;
336 }
337
338 return FALSE;
339}

◆ Sam5250SetBaud()

BOOLEAN Sam5250SetBaud ( _Inout_ PCPPORT Port,
ULONG Rate )
156{
157 if ((Port == NULL) || (Port->Address == NULL))
158 {
159 return FALSE;
160 }
161
162 //
163 // There is no way to determine reference clock frequency for this UART so
164 // just remember the desired baud rate but don't do anything else.
165 //
166
167 Port->BaudRate = Rate;
168 return TRUE;
169}

Variable Documentation

◆ Sam5250HardwareDriver

UART_HARDWARE_DRIVER Sam5250HardwareDriver
Initial value:
= {
BOOLEAN Sam5250RxReady(_Inout_ PCPPORT Port)
Definition sam5250.c:301
UART_STATUS Sam5250PutByte(_Inout_ PCPPORT Port, UCHAR Byte, BOOLEAN BusyWait)
Definition sam5250.c:241
BOOLEAN Sam5250SetBaud(_Inout_ PCPPORT Port, ULONG Rate)
Definition sam5250.c:135
BOOLEAN Sam5250InitializePort(_In_opt_ _Null_terminated_ PCHAR LoadOptions, _Inout_ PCPPORT Port, BOOLEAN MemoryMapped, UCHAR AccessSize, UCHAR BitWidth)
Definition sam5250.c:50
UART_STATUS Sam5250GetByte(_Inout_ PCPPORT Port, _Out_ PUCHAR Byte)
Definition sam5250.c:172