[PATCH] Updated Legacy code in arm csb336

Gedare Bloom gedare at rtems.org
Mon Jul 8 17:49:16 UTC 2013


Yes do keep notes and blog about the troubles you face. Later it might
be useful to define a "BSP conventions" wiki page and make updates to
the BSP developer's guide, which is IMO one of the handiest references
for RTEMS kernel developers at the moment.

On Mon, Jul 8, 2013 at 1:09 PM, Joel Sherrill <joel.sherrill at oarcorp.com> wrote:
> I think you addressed Sebastian's comments.
>
> Sebastian .. anything else?
>
> Vipul.. I hope you are keeping notes. They will get easier
> and easier. :)
>
> --joel
>
>
> On 7/8/2013 12:05 PM, Vipul Nayyar wrote:
>>
>> ---
>>   c/src/lib/libbsp/arm/csb336/console/uart.c    | 134
>> +++++++++++++++-----------
>>   c/src/lib/libbsp/arm/csb336/network/network.c |  46 +++------
>>   2 files changed, 92 insertions(+), 88 deletions(-)
>>
>> diff --git a/c/src/lib/libbsp/arm/csb336/console/uart.c
>> b/c/src/lib/libbsp/arm/csb336/console/uart.c
>> index 4dc409b..d1b4e72 100644
>> --- a/c/src/lib/libbsp/arm/csb336/console/uart.c
>> +++ b/c/src/lib/libbsp/arm/csb336/console/uart.c
>> @@ -13,12 +13,12 @@
>>   #include <libchip/sersupp.h>
>>   #include <rtems/error.h>
>>   #include <rtems/bspIo.h>
>> +#include <assert.h>
>>   #include <termios.h>
>>   #include <rtems/irq.h>
>>   #include <bsp/irq.h>
>>   #include <mc9328mxl.h>
>>
>> -
>>   /* Define this to use interrupt driver UART driver */
>>   #define USE_INTERRUPTS 1
>>
>> @@ -34,18 +34,21 @@ static int imx_uart_set_attrs(int, const struct
>> termios *);
>>   static void imx_uart_init(int minor);
>>   static void imx_uart_set_baud(int, int);
>>   static ssize_t imx_uart_poll_write(int, const char *, size_t);
>> +static int imx_uart_poll_read_char(int minor);
>> +static void imx_uart_poll_write_char(int minor, char c);
>> +static void _BSP_output_char(char c);
>> +static int _BSP_poll_char(void);
>>
>>   #if defined(USE_INTERRUPTS)
>>   static void imx_uart_tx_isr(rtems_irq_hdl_param);
>>   static void imx_uart_rx_isr(rtems_irq_hdl_param);
>> -static void imx_uart_isr_on(const rtems_irq_connect_data *irq);
>> -static void imx_uart_isr_off(const rtems_irq_connect_data *irq);
>> -static int imx_uart_isr_is_on(const rtems_irq_connect_data *irq);
>> +static void imx_uart_isr_on(const rtems_irq_number);
>> +static void imx_uart_isr_off(const rtems_irq_number);
>>   static ssize_t imx_uart_intr_write(int, const char *, size_t);
>> +static rtems_vector_number imx_uart_name_transmit(int minor);
>> +static rtems_vector_number imx_uart_name_receive(int minor);
>>   #endif
>>
>> -
>> -
>>   /* TERMIOS callbacks */
>>   #if defined(USE_INTERRUPTS)
>>   rtems_termios_callbacks imx_uart_cbacks = {
>> @@ -71,11 +74,6 @@ rtems_termios_callbacks imx_uart_cbacks = {
>>   };
>>   #endif
>>
>> -#if defined(USE_INTERRUPTS)
>> -static rtems_irq_connect_data imx_uart_tx_isr_data[NUM_DEVS];
>> -static rtems_irq_connect_data imx_uart_rx_isr_data[NUM_DEVS];
>> -#endif
>> -
>>   typedef struct {
>>       int minor;
>>       mc9328mxl_uart_regs_t * regs;
>> @@ -184,17 +182,9 @@ static void imx_uart_init(int minor)
>>       imx_uart_data[minor].idx   = 0;
>>
>>       if (minor == 0) {
>> -#if defined(USE_INTERRUPTS)
>> -        imx_uart_tx_isr_data[minor].name = BSP_INT_UART1_TX;
>> -        imx_uart_rx_isr_data[minor].name = BSP_INT_UART1_RX;
>> -#endif
>>           imx_uart_data[minor].regs =
>>               (mc9328mxl_uart_regs_t *) MC9328MXL_UART1_BASE;
>>       } else if (minor == 1) {
>> -#if defined(USE_INTERRUPTS)
>> -        imx_uart_tx_isr_data[minor].name = BSP_INT_UART2_TX;
>> -        imx_uart_rx_isr_data[minor].name = BSP_INT_UART2_RX;
>> -#endif
>>           imx_uart_data[minor].regs =
>>               (mc9328mxl_uart_regs_t *) MC9328MXL_UART2_BASE;
>>       } else {
>> @@ -202,20 +192,6 @@ static void imx_uart_init(int minor)
>>                       __FUNCTION__, __LINE__, minor);
>>       }
>>
>> -#if defined(USE_INTERRUPTS)
>> -    imx_uart_tx_isr_data[minor].hdl    = imx_uart_tx_isr;
>> -    imx_uart_tx_isr_data[minor].handle = &imx_uart_data[minor];
>> -    imx_uart_tx_isr_data[minor].on     = imx_uart_isr_on;
>> -    imx_uart_tx_isr_data[minor].off    = imx_uart_isr_off;
>> -    imx_uart_tx_isr_data[minor].isOn   = imx_uart_isr_is_on;
>> -
>> -    imx_uart_rx_isr_data[minor].hdl    = imx_uart_rx_isr;
>> -    imx_uart_rx_isr_data[minor].handle  = &imx_uart_data[minor];
>> -    imx_uart_rx_isr_data[minor].on     = imx_uart_isr_on;
>> -    imx_uart_rx_isr_data[minor].off    = imx_uart_isr_off;
>> -    imx_uart_rx_isr_data[minor].isOn   = imx_uart_isr_is_on;
>> -#endif
>> -
>>       imx_uart_data[minor].regs->cr1 = (
>>           MC9328MXL_UART_CR1_UARTCLKEN |
>>           MC9328MXL_UART_CR1_UARTEN);
>> @@ -243,13 +219,31 @@ static void imx_uart_init(int minor)
>>   static int imx_uart_first_open(int major, int minor, void *arg)
>>   {
>>       rtems_libio_open_close_args_t *args = arg;
>> +    rtems_status_code status = RTEMS_SUCCESSFUL;
>>
>>       imx_uart_data[minor].tty   = args->iop->data1;
>>
>> -#if defined(USE_INTERRUPTS)
>> -    BSP_install_rtems_irq_handler(&imx_uart_tx_isr_data[minor]);
>> -    BSP_install_rtems_irq_handler(&imx_uart_rx_isr_data[minor]);
>> -
>> +#if defined(USE_INTERRUPTS)
>> +    status = rtems_interrupt_handler_install(
>> +        imx_uart_name_transmit(minor),
>> +        "UART",
>> +        RTEMS_INTERRUPT_UNIQUE,
>> +        imx_uart_tx_isr,
>> +        &imx_uart_data[minor]
>> +    );
>> +    assert(status == RTEMS_SUCCESSFUL);
>> +    imx_uart_isr_on(imx_uart_name_transmit(minor));
>> +
>> +    status = rtems_interrupt_handler_install(
>> +        imx_uart_name_receive(minor),
>> +        "UART",
>> +        RTEMS_INTERRUPT_UNIQUE,
>> +        imx_uart_rx_isr,
>> +        &imx_uart_data[minor]
>> +    );
>> +    assert(status == RTEMS_SUCCESSFUL);
>> +    imx_uart_isr_on(imx_uart_name_receive(minor));
>> +
>>       imx_uart_data[minor].regs->cr1 |= MC9328MXL_UART_CR1_RRDYEN;
>>   #endif
>>
>> @@ -259,8 +253,23 @@ static int imx_uart_first_open(int major, int minor,
>> void *arg)
>>   static int imx_uart_last_close(int major, int minor, void *arg)
>>   {
>>   #if defined(USE_INTERRUPTS)
>> -    BSP_remove_rtems_irq_handler(&imx_uart_tx_isr_data[minor]);
>> -    BSP_remove_rtems_irq_handler(&imx_uart_rx_isr_data[minor]);
>> +    rtems_status_code status = RTEMS_SUCCESSFUL;
>> +
>> +    imx_uart_isr_off(imx_uart_name_transmit(minor));
>> +    status = rtems_interrupt_handler_remove(
>> +        imx_uart_name_transmit(minor),
>> +        imx_uart_tx_isr,
>> +        &imx_uart_data[minor]
>> +    );
>> +    assert(status == RTEMS_SUCCESSFUL);
>> +
>> +    imx_uart_isr_off(imx_uart_name_receive(minor));
>> +    status = rtems_interrupt_handler_remove(
>> +        imx_uart_name_receive(minor),
>> +        imx_uart_rx_isr,
>> +        &imx_uart_data[minor]
>> +    );
>> +    assert(status == RTEMS_SUCCESSFUL);
>>   #endif
>>
>>       return 0;
>> @@ -317,22 +326,13 @@ static int imx_uart_set_attrs(int minor, const
>> struct termios *t)
>>   }
>>
>>   #if defined(USE_INTERRUPTS)
>> -static void imx_uart_isr_on(const rtems_irq_connect_data *irq)
>> +static void imx_uart_isr_on(const rtems_irq_number name)
>>   {
>> -    MC9328MXL_AITC_INTENNUM = irq->name;
>> +    MC9328MXL_AITC_INTENNUM = name;
>>   }
>> -static void imx_uart_isr_off(const rtems_irq_connect_data *irq)
>> +static void imx_uart_isr_off(const rtems_irq_number name)
>>   {
>> -    MC9328MXL_AITC_INTDISNUM = irq->name;
>> -}
>> -static int imx_uart_isr_is_on(const rtems_irq_connect_data *irq)
>> -{
>> -    int irq_num = (int)irq->name;
>> -    if (irq_num < 32) {
>> -        return MC9328MXL_AITC_INTENABLEL & (1 << irq_num);
>> -    } else {
>> -        return MC9328MXL_AITC_INTENABLEH & (1 << (irq_num - 32));
>> -    }
>> +    MC9328MXL_AITC_INTDISNUM = name;
>>   }
>>
>>   static void imx_uart_rx_isr(rtems_irq_hdl_param param)
>> @@ -369,6 +369,28 @@ static void imx_uart_tx_isr(rtems_irq_hdl_param
>> param)
>>           rtems_termios_dequeue_characters(uart_data->tty, len);
>>       }
>>   }
>> +
>> +static rtems_vector_number imx_uart_name_transmit(int minor)
>> +{
>> +    if (minor == 0) {
>> +        return BSP_INT_UART1_TX;
>> +    } else if (minor == 1) {
>> +        return BSP_INT_UART2_TX;
>> +    }
>> +
>> +    assert(0);
>> +}
>> +
>> +static rtems_vector_number imx_uart_name_receive(int minor)
>> +{
>> +    if (minor == 0) {
>> +        return BSP_INT_UART1_RX;
>> +    } else if (minor == 1) {
>> +        return BSP_INT_UART2_RX;
>> +    }
>> +
>> +    assert(0);
>> +}
>>   #endif
>>
>>   /*
>> @@ -417,7 +439,7 @@ static void imx_uart_set_baud(int minor, int baud)
>>   /*
>>    * Polled, non-blocking read from UART
>>    */
>> -int imx_uart_poll_read_char(int minor)
>> +static int imx_uart_poll_read_char(int minor)
>>   {
>>       return imx_uart_poll_read(minor);
>>   }
>> @@ -425,7 +447,7 @@ int imx_uart_poll_read_char(int minor)
>>   /*
>>    * Polled, blocking write from UART
>>    */
>> -void  imx_uart_poll_write_char(int minor, char c)
>> +static void  imx_uart_poll_write_char(int minor, char c)
>>   {
>>       imx_uart_poll_write(minor, &c, 1);
>>   }
>> @@ -433,7 +455,7 @@ void  imx_uart_poll_write_char(int minor, char c)
>>   /*
>>    * Functions for printk() and friends.
>>    */
>> -void _BSP_output_char(char c)
>> +static void _BSP_output_char(char c)
>>   {
>>       poll_write(c);
>>       if (c == '\n') {
>> @@ -443,7 +465,7 @@ void _BSP_output_char(char c)
>>
>>   BSP_output_char_function_type BSP_output_char = _BSP_output_char;
>>
>> -int _BSP_poll_char(void)
>> +static int _BSP_poll_char(void)
>>   {
>>       return poll_read();
>>   }
>> diff --git a/c/src/lib/libbsp/arm/csb336/network/network.c
>> b/c/src/lib/libbsp/arm/csb336/network/network.c
>> index e513595..f93fcc8 100644
>> --- a/c/src/lib/libbsp/arm/csb336/network/network.c
>> +++ b/c/src/lib/libbsp/arm/csb336/network/network.c
>> @@ -19,6 +19,7 @@
>>   #include <errno.h>
>>   #include <rtems/error.h>
>>   #include <rtems/bspIo.h>
>> +#include <assert.h>
>>
>>   #include <sys/param.h>
>>   #include <sys/mbuf.h>
>> @@ -39,19 +40,8 @@
>>   #define START_TRANSMIT_EVENT    RTEMS_EVENT_2
>>
>>   static void enet_isr(rtems_irq_hdl_param);
>> -static void enet_isr_on(const rtems_irq_connect_data *unused);
>> -static void enet_isr_off(const rtems_irq_connect_data *unused);
>> -static int enet_isr_is_on(const rtems_irq_connect_data *irq);
>> -
>> -/* Replace the first value with the clock's interrupt name. */
>> -rtems_irq_connect_data mc9328mxl_enet_isr_data = {
>> -    .name    = BSP_INT_GPIO_PORTA,
>> -    .hdl     = enet_isr,
>> -    .handle  = (void *)BSP_INT_GPIO_PORTA,
>> -    .on      = enet_isr_on,
>> -    .off     = enet_isr_off,
>> -    .isOn    = enet_isr_is_on,
>> -};
>> +static void enet_isr_on(void);
>> +
>>   typedef struct {
>>     unsigned long rx_packets;        /* total packets received         */
>>     unsigned long tx_packets;        /* total packets transmitted      */
>> @@ -238,6 +228,7 @@ void  mc9328mxl_enet_init_hw(mc9328mxl_enet_softc_t
>> *sc)
>>   {
>>       uint16_t stat;
>>       uint16_t my = 0;
>> +    rtems_status_code status = RTEMS_SUCCESSFUL;
>>
>>       lan91c11x_write_reg(LAN91C11X_RCR, LAN91C11X_RCR_RST);
>>       lan91c11x_write_reg(LAN91C11X_RCR, 0);
>> @@ -334,7 +325,15 @@ void  mc9328mxl_enet_init_hw(mc9328mxl_enet_softc_t
>> *sc)
>>       MC9328MXL_GPIOA_IMR |= bit(3);
>>
>>       /* Install the interrupt handler */
>> -    BSP_install_rtems_irq_handler(&mc9328mxl_enet_isr_data);
>> +    status = rtems_interrupt_handler_install(
>> +        BSP_INT_GPIO_PORTA,
>> +        "Network",
>> +        RTEMS_INTERRUPT_UNIQUE,
>> +        enet_isr,
>> +        (void *)BSP_INT_GPIO_PORTA
>> +    );
>> +    assert(status == RTEMS_SUCCESSFUL);
>> +    enet_isr_on();
>>
>>   } /* mc9328mxl_enet_init_hw() */
>>
>> @@ -602,7 +601,7 @@ void mc9328mxl_enet_stats (mc9328mxl_enet_softc_t *sc)
>>
>>
>>   /* Enables mc9328mxl_enet interrupts. */
>> -static void enet_isr_on(const rtems_irq_connect_data *unused)
>> +static void enet_isr_on(void)
>>   {
>>       /* Enable interrupts */
>>       MC9328MXL_AITC_INTENNUM = MC9328MXL_INT_GPIO_PORTA;
>> @@ -610,23 +609,6 @@ static void enet_isr_on(const rtems_irq_connect_data
>> *unused)
>>       return;
>>   }
>>
>> -/* Disables enet interrupts */
>> -static void enet_isr_off(const rtems_irq_connect_data *unused)
>> -{
>> -    /* disable all various TX/RX interrupts */
>> -    MC9328MXL_AITC_INTDISNUM = MC9328MXL_INT_GPIO_PORTA;
>> -
>> -    return;
>> -}
>> -
>> -/* Tests to see if mc9328mxl_enet interrupts are enabled, and returns
>> non-0 if so.
>> - * If interrupt is not enabled, returns 0.
>> - */
>> -static int enet_isr_is_on(const rtems_irq_connect_data *irq)
>> -{
>> -    return MC9328MXL_AITC_INTENABLEL & (1 << MC9328MXL_INT_GPIO_PORTA);
>> -}
>> -
>>   /*  Driver ioctl handler */
>>   static int
>>   mc9328mxl_enet_ioctl (struct ifnet *ifp, ioctl_command_t command,
>> caddr_t data)
>> --
>> 1.7.11.7
>>
>> _______________________________________________
>> rtems-devel mailing list
>> rtems-devel at rtems.org
>> http://www.rtems.org/mailman/listinfo/rtems-devel
>
>
>
> --
> Joel Sherrill, Ph.D.             Director of Research & Development
> joel.sherrill at OARcorp.com        On-Line Applications Research
> Ask me about RTEMS: a free RTOS  Huntsville AL 35805
> Support Available                (256) 722-9985
>
>
> _______________________________________________
> rtems-devel mailing list
> rtems-devel at rtems.org
> http://www.rtems.org/mailman/listinfo/rtems-devel



More information about the devel mailing list