X-Git-Url: https://scm.lunaixsky.com/lunaix-os.git/blobdiff_plain/1eeed1150149b63d6e49e033697454bc12b533b9..6942ebae59c3904674dce6b67cd07c43a3bbe00d:/lunaix-os/hal/char/serial.c diff --git a/lunaix-os/hal/char/serial.c b/lunaix-os/hal/char/serial.c index 826b3a6..7943bb3 100644 --- a/lunaix-os/hal/char/serial.c +++ b/lunaix-os/hal/char/serial.c @@ -3,11 +3,13 @@ #include #include #include +#include -#include +#include #include -#include + +LOG_MODULE("serial") #define lock_sdev(sdev) device_lock((sdev)->dev) #define unlock_sdev(sdev) device_unlock((sdev)->dev) @@ -43,6 +45,8 @@ serial_end_recv(struct serial_dev* sdev) mark_device_done_read(sdev->dev); pwake_one(&sdev->wq_rxdone); + + term_notify_data_avaliable(sdev->tp_cap); } void @@ -162,7 +166,7 @@ __serial_read_async(struct device* dev, void* buf, off_t fpos, size_t len) static int __serial_read_page(struct device* dev, void* buf, off_t fpos) { - return serial_readbuf(serial_device(dev), (u8_t*)buf, MEM_PAGE); + return serial_readbuf(serial_device(dev), (u8_t*)buf, PAGE_SIZE); } static int @@ -181,7 +185,7 @@ __serial_write_async(struct device* dev, void* buf, off_t fpos, size_t len) static int __serial_write_page(struct device* dev, void* buf, off_t fpos) { - return serial_writebuf(serial_device(dev), (u8_t*)buf, MEM_PAGE); + return serial_writebuf(serial_device(dev), (u8_t*)buf, PAGE_SIZE); } static int @@ -220,7 +224,18 @@ __serial_set_speed(struct device* dev, speed_t speed) struct serial_dev* sdev = serial_device(dev); lock_sdev(sdev); - sdev_execmd(sdev, SERIO_SETBRDIV, speed); + sdev_execmd(sdev, SERIO_SETBRDRATE, speed); + + unlock_sdev(sdev); +} + +static void +__serial_set_baseclk(struct device* dev, unsigned int base) +{ + struct serial_dev* sdev = serial_device(dev); + lock_sdev(sdev); + + sdev_execmd(sdev, SERIO_SETBRDBASE, base); unlock_sdev(sdev); } @@ -238,11 +253,21 @@ __serial_set_cntrl_mode(struct device* dev, tcflag_t cflag) #define RXBUF_SIZE 512 +static struct termport_pot_ops tppot_ops = { + .set_cntrl_mode = __serial_set_cntrl_mode, + .set_clkbase = __serial_set_baseclk, + .set_speed = __serial_set_speed +}; + struct serial_dev* serial_create(struct devclass* class, char* if_ident) { - struct serial_dev* sdev = valloc(sizeof(struct serial_dev)); - struct device* dev = device_allocseq(dev_meta(serial_cat), sdev); + struct serial_dev* sdev; + struct device* dev; + + sdev = vzalloc(sizeof(struct serial_dev)); + dev = device_allocseq(dev_meta(serial_cat), sdev); + dev->ops.read = __serial_read; dev->ops.read_page = __serial_read_page; dev->ops.read_async = __serial_read_async; @@ -255,23 +280,18 @@ serial_create(struct devclass* class, char* if_ident) sdev->dev = dev; dev->underlay = sdev; - struct termport_capability* tp_cap = - new_capability(TERMPORT_CAP, struct termport_capability); - tp_cap->set_speed = __serial_set_speed; - tp_cap->set_cntrl_mode = __serial_set_cntrl_mode; - waitq_init(&sdev->wq_rxdone); waitq_init(&sdev->wq_txdone); rbuffer_init(&sdev->rxbuf, valloc(RXBUF_SIZE), RXBUF_SIZE); llist_append(&serial_devs, &sdev->sdev_list); - device_grant_capability(dev, cap_meta(tp_cap)); + register_device_var(dev, class, "%s", if_ident); - register_device(dev, class, "s%d", class->variant); + INFO("interface: %s, %xh:%xh.%d", dev->name_val, + class->fn_grp, class->device, class->variant); - term_create(dev, if_ident); + sdev->tp_cap = term_attach_potens(dev, &tppot_ops, if_ident); - class->variant++; return sdev; }