Changeset 7fd5e89 in rtems for c/src/lib/libbsp/arm/tms570


Ignore:
Timestamp:
Oct 7, 2014, 2:28:04 PM (5 years ago)
Author:
Sebastian Huber <sebastian.huber@…>
Branches:
4.11, master
Children:
d5cc923f
Parents:
a830cb8
git-author:
Sebastian Huber <sebastian.huber@…> (10/07/14 14:28:04)
git-committer:
Sebastian Huber <sebastian.huber@…> (10/07/14 14:35:13)
Message:

termios: Partially hide rtems_termios_tty

Move interrupt lock to device context and expose only this structure to
the read, write and set attributes device handler. This makes these
device handler independent of the general Termios infrastructure
suitable for direct use in printk() support.

Location:
c/src/lib/libbsp/arm/tms570
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • c/src/lib/libbsp/arm/tms570/console/tms570-sci.c

    ra830cb8 r7fd5e89  
    2727#include <termios.h>
    2828#include <rtems/termiostypes.h>
    29 #include <libchip/sersupp.h>
    3029#include <bsp/tms570-sci.h>
    3130#include <bsp/tms570-sci-driver.h>
     
    4443const tms570_sci_context driver_context_table[] = {
    4544  {
     45    .base = RTEMS_TERMIOS_DEVICE_CONTEXT_INITIALIZER("TMS570 SCI1"),
    4646    .device_name = "/dev/console",
    4747    .regs = &TMS570_SCI,
     
    4949  },
    5050  {
     51    .base = RTEMS_TERMIOS_DEVICE_CONTEXT_INITIALIZER("TMS570 SCI2"),
    5152    .device_name = "/dev/ttyS1",
    5253    .regs = &TMS570_SCI2,
     
    105106        handler,
    106107        NULL,
    107         (void *) ctx
     108        RTEMS_DECONST(rtems_termios_device_context *, &ctx->base)
    108109    );
    109110    if ( sc != RTEMS_SUCCESSFUL ) {
     
    197198 * Sets attributes of the HW peripheral (parity, baud rate, etc.)
    198199 *
    199  * @param[in] tty rtems_termios_tty
     200 * @param[in] base context of the driver
    200201 * @param[in] t termios driver
    201202 * @retval true peripheral setting is changed
    202203 */
    203204static bool tms570_sci_set_attributes(
    204   rtems_termios_tty    *tty,
     205  rtems_termios_device_context *base,
    205206  const struct termios *t
    206207)
    207208{
    208   tms570_sci_context *ctx = rtems_termios_get_device_context(tty);
     209  tms570_sci_context *ctx = (tms570_sci_context *) base;
    209210  rtems_interrupt_lock_context lock_context;
    210211  int32_t bauddiv;
    211212  int32_t baudrate;
    212213
    213   rtems_termios_interrupt_lock_acquire(tty, &lock_context);
     214  rtems_termios_device_lock_acquire(base, &lock_context);
    214215
    215216  ctx->regs->SCIGCR1 &= ~( (1<<7) | (1<<25) | (1<<24) );
     
    246247  ctx->regs->SCIGCR1 |= (1<<7) | (1<<25) | (1<<24);
    247248
    248   rtems_termios_interrupt_lock_release(tty, &lock_context);
     249  rtems_termios_device_lock_release(base, &lock_context);
    249250
    250251  return true;
     
    301302 * so only one character can be written.
    302303 *
    303  * @param[in] tty rtems_termios_tty
     304 * @param[in] base context of the driver
    304305 * @param[in] buf buffer of characters pending to send
    305306 * @param[in] len size of the buffer
     
    307308 */
    308309static void tms570_sci_interrupt_write(
    309   rtems_termios_tty *tty,
     310  rtems_termios_device_context *base,
    310311  const char *buf,
    311312  size_t len
    312313)
    313314{
    314   tms570_sci_context *ctx = rtems_termios_get_device_context(tty);
     315  tms570_sci_context *ctx = (tms570_sci_context *) base;
    315316
    316317  if ( len > 0 ) {
     
    335336 * character to HW peripheral. Writes all characters in the buffer.
    336337 *
    337  * @param[in] tty rtems_termios_tty
     338 * @param[in] base context of the driver
    338339 * @param[in] buf buffer of characters pending to send
    339340 * @param[in] len size of the buffer
     
    341342 */
    342343static void tms570_sci_poll_write(
    343   rtems_termios_tty *tty,
    344   const char        *buf,
    345   size_t             n
    346 )
    347 {
    348   tms570_sci_context *ctx = rtems_termios_get_device_context(tty);
     344  rtems_termios_device_context *base,
     345  const char *buf,
     346  size_t n
     347)
     348{
     349  tms570_sci_context *ctx = (tms570_sci_context *) base;
    349350  size_t i;
    350351
     
    395396 * check if there is recieved character to be read and reads it.
    396397 *
    397  * @param[in] tty rtems_termios_tty (context of the driver)
     398 * @param[in] base context of the driver
    398399 * @retval -1 No character to be read
    399400 * @retval x Read character
    400401 */
    401 static int tms570_sci_poll_read(rtems_termios_tty *tty)
    402 {
    403   tms570_sci_context *ctx = rtems_termios_get_device_context(tty);
     402static int tms570_sci_poll_read(rtems_termios_device_context *base)
     403{
     404  tms570_sci_context *ctx = (tms570_sci_context *) base;
    404405
    405406  /* Check if a character is available */
     
    417418 * This function is called only once when opening the driver.
    418419 *
    419  * @param[in] tty context of the driver
     420 * @param[in] tty Termios control
     421 * @param[in] ctx context of the driver
     422 * @param[in] term Termios attributes
    420423 * @param[in] args
    421424 * @retval false Error occured during initialization
     
    424427static bool tms570_sci_poll_first_open(
    425428  rtems_termios_tty             *tty,
     429  rtems_termios_device_context  *ctx,
     430  struct termios                *term,
    426431  rtems_libio_open_close_args_t *args
    427432)
     
    429434  bool ok;
    430435
    431   rtems_termios_set_best_baud(tty, TMS570_SCI_BAUD_RATE);
    432   ok = tms570_sci_set_attributes(tty, rtems_termios_get_termios(tty));
     436  rtems_termios_set_best_baud(term, TMS570_SCI_BAUD_RATE);
     437  ok = tms570_sci_set_attributes(ctx, term);
    433438  if ( !ok ) {
    434439    return false;
     
    443448 * install and enables interrupts.
    444449 *
    445  * @param[in] tty context of the driver
     450 * @param[in] tty Termios control
     451 * @param[in] base context of the driver
    446452 * @param[in] args
    447453 * @retval false Error occured during initialization
     
    450456static bool tms570_sci_interrupt_first_open(
    451457  rtems_termios_tty             *tty,
     458  rtems_termios_device_context  *base,
     459  struct termios                *term,
    452460  rtems_libio_open_close_args_t *args
    453461)
    454462{
    455   tms570_sci_context *ctx = rtems_termios_get_device_context(tty);
     463  tms570_sci_context *ctx = (tms570_sci_context *) base;
    456464  rtems_status_code sc;
    457465  bool ret;
    458466
    459   ret = tms570_sci_poll_first_open(tty,args);
     467  ret = tms570_sci_poll_first_open(tty, base, term, args);
    460468  if ( ret == false ) {
    461469    return false;
     
    472480    return false;
    473481  }
    474   tms570_sci_enable_interrupts(rtems_termios_get_device_context(tty));
     482  tms570_sci_enable_interrupts(ctx);
    475483  return true;
    476484}
     
    479487 * @brief closes sci peripheral
    480488 *
    481  * @param[in] tty context of the driver
     489 * @param[in] tty Termios control
     490 * @param[in] base context of the driver
    482491 * @param[in] args
    483492 * @retval false Error occured during initialization
     
    486495static void tms570_sci_poll_last_close(
    487496  rtems_termios_tty             *tty,
     497  rtems_termios_device_context  *base,
    488498  rtems_libio_open_close_args_t *args
    489499)
     
    497507 * calls tms570_sci_poll_last_close and disables interrupts
    498508 *
    499  * @param[in] tty context of the driver
     509 * @param[in] tty Termios control
     510 * @param[in] base context of the driver
    500511 * @param[in] args
    501512 * @retval false Error occured during initialization
     
    504515static void tms570_sci_interrupt_last_close(
    505516  rtems_termios_tty             *tty,
     517  rtems_termios_device_context  *base,
    506518  rtems_libio_open_close_args_t *args
    507519)
    508520{
    509   tms570_sci_context *ctx = rtems_termios_get_device_context(tty);
     521  tms570_sci_context *ctx = (tms570_sci_context *) base;
    510522  rtems_interrupt_lock_context lock_context;
    511523
    512524  /* Turn off RX interrupts */
    513   rtems_termios_interrupt_lock_acquire(tty, &lock_context);
     525  rtems_termios_device_lock_acquire(base, &lock_context);
    514526  tms570_sci_disable_interrupts(ctx);
    515   rtems_termios_interrupt_lock_release(tty, &lock_context);
     527  rtems_termios_device_lock_release(base, &lock_context);
    516528
    517529  /* Flush device */
     
    523535  rtems_interrupt_handler_remove(ctx->irq, tms570_sci_interrupt_handler, tty);
    524536
    525   tms570_sci_poll_last_close(tty,args);
     537  tms570_sci_poll_last_close(tty, base, args);
    526538}
    527539
  • c/src/lib/libbsp/arm/tms570/include/tms570-sci-driver.h

    ra830cb8 r7fd5e89  
    3737/* Low-level driver specific data structure */
    3838typedef struct {
     39  rtems_termios_device_context base;
    3940  const char *device_name;
    4041  volatile tms570_sci_t *regs;
Note: See TracChangeset for help on using the changeset viewer.