helos1/driver/irq/pic/serial/serial.h

48 lines
1.2 KiB
C
Raw Normal View History

2021-11-05 14:12:05 +08:00
#pragma once
2021-11-14 19:43:04 +08:00
#include "../../../../util/queue.h"
#include "../../../../smp/condiction.h"
2021-11-05 14:12:05 +08:00
#include "stdbool.h"
#ifdef __cplusplus
extern "C" {
#endif
2021-11-14 19:43:04 +08:00
// Default buffer size for serial input
#ifndef PIC_SERIAL_DEFAULT_BUFFERSIZE
#define PIC_SERIAL_DEFAULT_BUFFERSIZE 16
#endif
2021-11-05 14:12:05 +08:00
// Serial port state.
//
// Line protocol defaults to 8N1 (8 bits, no parity, one stop bit)
typedef struct {
int port; // IO Port
2021-11-14 19:43:04 +08:00
int irq; // IRQ, 0 for disable
2021-11-05 14:12:05 +08:00
bool ok; // Is the port usable?
2021-11-14 19:43:04 +08:00
queue_Queue buffer; // input byte buffer
smp_Condition *cond; // input wait condiction
2021-11-05 14:12:05 +08:00
} pic_serial_Port;
extern pic_serial_Port pic_serial_COM1, pic_serial_COM2;
// Init initializes a serial port. Returns true if success.
//
// TODO lineFlags is ignored by now, always 8N1
bool pic_serial_Init(pic_serial_Port *port, int baudrate, int lineFlags);
2021-11-14 19:43:04 +08:00
// InitInput initializes input for a serial port. Returns true if success.
bool pic_serial_InitInput(pic_serial_Port *port);
2021-11-05 14:12:05 +08:00
// Write writes a string to a serial port, if the port is usable.
//
// Writes n chars. If n is 0, writes until it reaches NUL.
void pic_serial_Write(pic_serial_Port *port, const char *str, int n);
#ifdef __cplusplus
}
#endif