/* vim: tabstop=4 shiftwidth=4 noexpandtab * * Serial communication device * */ #include #include #include 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, unsigned int flags); 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) { while (!serial_rcvd((int)node->device)) { switch_task(1); } #if 0 debug_print(NOTICE, "Data received from TTY, have %d, need %d", collected+1, size); #endif buffer[collected] = serial_recv((int)node->device); 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) { serial_send((int)node->device, buffer[sent]); sent++; } return size; } void open_serial(fs_node_t * node, unsigned int flags) { 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)); memset(fnode, 0x00, sizeof(fs_node_t)); fnode->device= (void *)device; strcpy(fnode->name, "serial"); fnode->uid = 0; fnode->gid = 0; fnode->flags = FS_CHARDEVICE; fnode->read = read_serial; fnode->write = write_serial; fnode->open = open_serial; fnode->close = close_serial; fnode->readdir = NULL; fnode->finddir = NULL; fnode->ioctl = NULL; /* TODO ioctls for raw serial devices */ fnode->atime = now(); fnode->mtime = fnode->atime; fnode->ctime = fnode->atime; return fnode; } void serial_mount_devices(void) { 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); }