GitOS
Operating system exercise
Loading...
Searching...
No Matches
serial.c File Reference
#include "serial.h"
#include <stddef.h>
#include "../../common/io.h"
#include "../../common/string.h"
#include "../../common/status.h"

Macros

#define ERROR_I(value)   (int)(value)
 

Functions

int ser_Init (uint16_t port, uint16_t divisor)
 Initializes specified Serial port.
 
int ser_TransmitEmpty (uint16_t port)
 Checks if Transmitter holding register is empty (can write)
 
void ser_PrintChar (uint16_t port, char c)
 Prints single character to Serial port.
 
void ser_PrintString (uint16_t port, const char *str)
 Prints string to specified Serial port.
 
int ser_Received (uint16_t port)
 Checks if port has unread value.
 
char ser_ReadChar (uint16_t port)
 Reads single character from Serial port.
 

Macro Definition Documentation

◆ ERROR_I

#define ERROR_I (   value)    (int)(value)

Function Documentation

◆ ser_Init()

int ser_Init ( uint16_t  port,
uint16_t  divisor 
)

Initializes specified Serial port.

Parameters
portSerial port address pointer
divisor0-65535 divisor for 115200 base speed
Returns
int Status

References ALL_OK, EIO, outb(), ser_PrintChar(), ser_ReadChar(), and ser_Received().

◆ ser_PrintChar()

void ser_PrintChar ( uint16_t  port,
char  c 
)

Prints single character to Serial port.

Parameters
portSerial port pointer
cCharacter to write

References outb(), and ser_TransmitEmpty().

◆ ser_PrintString()

void ser_PrintString ( uint16_t  port,
const char *  str 
)

Prints string to specified Serial port.

Parameters
portSerial port pointer
strString to write

References ser_PrintChar(), and strlen().

◆ ser_ReadChar()

char ser_ReadChar ( uint16_t  port)

Reads single character from Serial port.

Parameters
portSerial port pointer
Returns
char Read character

References inb().

◆ ser_Received()

int ser_Received ( uint16_t  port)

Checks if port has unread value.

Parameters
portSerial port pointer
Returns
int 1 if can read

References inb().

◆ ser_TransmitEmpty()

int ser_TransmitEmpty ( uint16_t  port)

Checks if Transmitter holding register is empty (can write)

Parameters
portSerial port pointer
Returns
int 1 if empty

References inb().