2012-12-10 04:59:55 +04:00
|
|
|
/* vim: tabstop=4 shiftwidth=4 noexpandtab
|
|
|
|
*
|
|
|
|
* Serial communication device
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2012-11-29 11:05:19 +04:00
|
|
|
#include <system.h>
|
|
|
|
#include <fs.h>
|
2013-03-18 03:34:01 +04:00
|
|
|
#include <logging.h>
|
2012-11-29 11:05:19 +04:00
|
|
|
|
|
|
|
uint32_t read_serial(fs_node_t *node, uint32_t offset, uint32_t size, uint8_t *buffer);
|
|
|
|
uint32_t write_serial(fs_node_t *node, uint32_t offset, uint32_t size, uint8_t *buffer);
|
|
|
|
void open_serial(fs_node_t *node, uint8_t read, uint8_t write);
|
|
|
|
void close_serial(fs_node_t *node);
|
|
|
|
|
|
|
|
uint32_t read_serial(fs_node_t *node, uint32_t offset, uint32_t size, uint8_t *buffer) {
|
|
|
|
if (size < 1) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
memset(buffer, 0x00, 1);
|
|
|
|
uint32_t collected = 0;
|
|
|
|
while (collected < size) {
|
2013-03-26 08:48:16 +04:00
|
|
|
while (!serial_rcvd((int)node->device)) {
|
2013-03-18 03:34:01 +04:00
|
|
|
switch_task(1);
|
|
|
|
}
|
|
|
|
debug_print(NOTICE, "Data received from TTY");
|
2013-03-26 08:48:16 +04:00
|
|
|
buffer[collected] = serial_recv((int)node->device);
|
2012-11-29 11:05:19 +04:00
|
|
|
collected++;
|
|
|
|
}
|
|
|
|
return collected;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t write_serial(fs_node_t *node, uint32_t offset, uint32_t size, uint8_t *buffer) {
|
|
|
|
uint32_t sent = 0;
|
|
|
|
while (sent < size) {
|
2013-03-26 08:48:16 +04:00
|
|
|
serial_send((int)node->device, buffer[sent]);
|
2012-11-29 11:05:19 +04:00
|
|
|
sent++;
|
|
|
|
}
|
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
|
|
|
void open_serial(fs_node_t * node, uint8_t read, uint8_t write) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
void close_serial(fs_node_t * node) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
fs_node_t * serial_device_create(int device) {
|
|
|
|
fs_node_t * fnode = malloc(sizeof(fs_node_t));
|
2013-03-15 11:20:55 +04:00
|
|
|
memset(fnode, 0x00, sizeof(fs_node_t));
|
2013-03-26 08:48:16 +04:00
|
|
|
fnode->device= (void *)device;
|
2012-12-01 06:26:47 +04:00
|
|
|
strcpy(fnode->name, "serial");
|
2012-11-29 11:05:19 +04:00
|
|
|
fnode->uid = 0;
|
|
|
|
fnode->gid = 0;
|
2013-03-15 11:52:09 +04:00
|
|
|
fnode->flags = FS_CHARDEVICE;
|
2012-11-29 11:05:19 +04:00
|
|
|
fnode->read = read_serial;
|
|
|
|
fnode->write = write_serial;
|
|
|
|
fnode->open = open_serial;
|
|
|
|
fnode->close = close_serial;
|
|
|
|
fnode->readdir = NULL;
|
|
|
|
fnode->finddir = NULL;
|
2013-03-19 10:57:40 +04:00
|
|
|
fnode->ioctl = NULL; /* TODO ioctls for raw serial devices */
|
2012-12-10 04:59:55 +04:00
|
|
|
|
|
|
|
fnode->atime = now();
|
|
|
|
fnode->mtime = fnode->atime;
|
|
|
|
fnode->ctime = fnode->atime;
|
|
|
|
|
2012-11-29 11:05:19 +04:00
|
|
|
return fnode;
|
|
|
|
}
|
2013-03-15 11:20:55 +04:00
|
|
|
|
|
|
|
void serial_mount_devices() {
|
|
|
|
|
|
|
|
fs_node_t * ttyS0 = serial_device_create(SERIAL_PORT_A);
|
|
|
|
vfs_mount("/dev/ttyS0", ttyS0);
|
|
|
|
|
|
|
|
fs_node_t * ttyS1 = serial_device_create(SERIAL_PORT_B);
|
|
|
|
vfs_mount("/dev/ttyS1", ttyS1);
|
|
|
|
|
|
|
|
fs_node_t * ttyS2 = serial_device_create(SERIAL_PORT_C);
|
|
|
|
vfs_mount("/dev/ttyS2", ttyS2);
|
|
|
|
|
|
|
|
fs_node_t * ttyS3 = serial_device_create(SERIAL_PORT_D);
|
|
|
|
vfs_mount("/dev/ttyS3", ttyS3);
|
|
|
|
|
|
|
|
}
|