diff options
Diffstat (limited to 'nuttx/arch/c5471/src')
-rw-r--r-- | nuttx/arch/c5471/src/up_internal.h | 2 | ||||
-rw-r--r-- | nuttx/arch/c5471/src/up_serial.c | 55 |
2 files changed, 37 insertions, 20 deletions
diff --git a/nuttx/arch/c5471/src/up_internal.h b/nuttx/arch/c5471/src/up_internal.h index 6f6f82c83..390a91454 100644 --- a/nuttx/arch/c5471/src/up_internal.h +++ b/nuttx/arch/c5471/src/up_internal.h @@ -51,7 +51,7 @@ #undef CONFIG_SUPPRESS_INTERRUPTS /* Do not enable interrupts */ #undef CONFIG_SUPPRESS_TIMER_INTS /* No timer */ -#define CONFIG_SUPPRESS_SERIAL_INTS 1 /* Console will poll */ +#undef CONFIG_SUPPRESS_SERIAL_INTS /* Console will poll */ #undef CONFIG_SUPPRESS_UART_CONFIG /* Do not reconfig UART */ #undef CONFIG_DUMP_ON_EXIT /* Dumpt task state on exit */ diff --git a/nuttx/arch/c5471/src/up_serial.c b/nuttx/arch/c5471/src/up_serial.c index 8ab1d6954..c6d6dc58e 100644 --- a/nuttx/arch/c5471/src/up_serial.c +++ b/nuttx/arch/c5471/src/up_serial.c @@ -79,10 +79,11 @@ struct uart_regs_s struct uart_buffer_s { - int head; - int tail; - int size; - char *buffer; + sem_t sem; /* Used to control exclusive access to the buffer */ + sint16 head; /* Index to the head [IN] index in the buffer */ + sint16 tail; /* Index to the tail [OUT] index in the buffer */ + sint16 size; /* The allocated size of the buffer */ + char *buffer; /* Pointer to the allocated buffer memory */ }; struct up_dev_s @@ -608,6 +609,7 @@ static void up_putxmitchar(up_dev_t *dev, int ch) } else { +#if defined(CONFIG_SUPPRESS_INTERRUPTS) || defined(CONFIG_SUPPRESS_SERIAL_INTS) /* Transfer some characters with interrupts disabled */ up_xmitchars(dev); @@ -621,20 +623,23 @@ static void up_putxmitchar(up_dev_t *dev, int ch) { /* Still no space */ -#if defined(CONFIG_SUPPRESS_INTERRUPTS) || defined(CONFIG_SUPPRESS_SERIAL_INTS) up_waittxfifonotfull(dev); + } #else - dev->xmitwaiting = TRUE; + /* Inform the interrupt level logic that we are waiting */ - /* Wait for some characters to be sent from the buffer - * with the TX interrupt disabled. - */ + dev->xmitwaiting = TRUE; + + /* Wait for some characters to be sent from the buffer + * with the TX interrupt enabled. When the TX interrupt + * is enabled, up_xmitchars should execute and remove + * some of the data from the TX buffer. + */ - up_enabletxint(dev); - up_takesem(&dev->xmitsem); - up_disabletxint(dev); + up_enabletxint(dev); + up_takesem(&dev->xmitsem); + up_disabletxint(dev); #endif - } } } } @@ -805,6 +810,10 @@ static ssize_t up_write(struct file *filep, const char *buffer, size_t buflen) up_dev_t *dev = inode->i_private; ssize_t ret = buflen; + /* Only one user can be accessing dev->xmit.head at once */ + + up_takesem(&dev->xmit.sem); + /* Loop while we still have data to copy to the transmit buffer. * we add data to the head of the buffer; up_xmitchars takes the * data from the end of the buffer. @@ -829,13 +838,14 @@ static ssize_t up_write(struct file *filep, const char *buffer, size_t buflen) if (dev->xmit.head != dev->xmit.tail) { +#if defined(CONFIG_SUPPRESS_INTERRUPTS) || defined(CONFIG_SUPPRESS_SERIAL_INTS) up_xmitchars(dev); - if (dev->xmit.head != dev->xmit.tail) - { - up_enabletxint(dev); - } +#else + up_enabletxint(dev); +#endif } + up_givesem(&dev->xmit.sem); return ret; } @@ -849,6 +859,10 @@ static ssize_t up_read(struct file *filep, char *buffer, size_t buflen) up_dev_t *dev = inode->i_private; ssize_t ret = buflen; + /* Only one user can be accessing dev->recv.tail at once */ + + up_takesem(&dev->recv.sem); + /* Loop while we still have data to copy to the receive buffer. * we add data to the head of the buffer; up_xmitchars takes the * data from the end of the buffer. @@ -862,7 +876,7 @@ static ssize_t up_read(struct file *filep, char *buffer, size_t buflen) *buffer++ = dev->recv.buffer[dev->recv.tail]; buflen--; - if (++dev->recv.tail >= dev->recv.size) + if (++(dev->recv.tail) >= dev->recv.size) { dev->recv.tail = 0; } @@ -881,7 +895,7 @@ static ssize_t up_read(struct file *filep, char *buffer, size_t buflen) } up_enablerxint(dev); - + up_takesem(&dev->recv.sem); return ret; } @@ -1068,8 +1082,11 @@ static void up_devinit(up_dev_t *dev, * statically initialized. */ + sem_init(&dev->xmit.sem, 0, 1); dev->xmit.size = txbufsize; dev->xmit.buffer = txbuffer; + + sem_init(&dev->recv.sem, 0, 1); dev->recv.size = rxbufsize; dev->recv.buffer = rxbuffer; |