Ejemplo n.º 1
0
/***
 *  rt_socket_init - initialises a new socket structure
 */
int rt_socket_init(struct rtdm_dev_context *context)
{
    struct rtsocket *sock = (struct rtsocket *)&context->dev_private;
    unsigned int    pool_size;


    sock->priority      = SOCK_DEF_PRIO;
    sock->callback_func = NULL;

    rtskb_queue_init(&sock->incoming);

    rtos_nanosecs_to_time(0, &sock->timeout);

    rtos_spin_lock_init(&sock->param_lock);
    rtos_event_sem_init(&sock->wakeup_event);

    if (test_bit(RTDM_CREATED_IN_NRT, &context->context_flags))
        pool_size = rtskb_pool_init(&sock->skb_pool, socket_rtskbs);
    else
        pool_size = rtskb_pool_init_rt(&sock->skb_pool, socket_rtskbs);
    atomic_set(&sock->pool_size, pool_size);

    if (pool_size < socket_rtskbs) {
        /* fix statistics */
        if (pool_size == 0)
            rtskb_pools--;

        rt_socket_cleanup(context);
        return -ENOMEM;
    }

    return 0;
}
Ejemplo n.º 2
0
int __init rtcfg_init_frames(void)
{
    int ret;


    rtskb_queue_init(&rx_queue);
    rtos_event_sem_init(&rx_event);

    if (rtskb_pool_init(&rtcfg_pool, num_rtskbs) < num_rtskbs) {
        ret = -ENOMEM;
        goto error1;
    }

    ret = rtos_task_init(&rx_task, rtcfg_rx_task, 0,
                         RTOS_LOWEST_RT_PRIORITY);
    if (ret < 0)
        goto error1;

    ret = rtdev_add_pack(&rtcfg_packet_type);
    if (ret < 0)
        goto error2;

    return 0;

  error2:
    rtos_task_delete(&rx_task);

  error1:
    rtos_event_sem_delete(&rx_event);
    rtskb_pool_release(&rtcfg_pool);

    return ret;
}
Ejemplo n.º 3
0
int __init rtpc_init(void)
{
    int ret;


    ret = rtos_nrt_signal_init(&rtpc_nrt_signal, rtpc_signal_handler);
    if (ret < 0)
        return ret;

    rtos_event_sem_init(&dispatch_event);

    ret = rtos_task_init(&dispatch_task, rtpc_dispatch_handler, 0,
                         RTOS_LOWEST_RT_PRIORITY);
    if (ret < 0)
        rtos_nrt_signal_delete(&rtpc_nrt_signal);

    return ret;
}
Ejemplo n.º 4
0
int __init nomac_proto_init(void)
{
    int ret;


    rtskb_queue_init(&nrt_rtskb_queue);
    ret = rtos_event_sem_init(&wakeup_sem);
    if (ret < 0)
        return ret;

    ret = rtos_task_init(&wrapper_task, nrt_xmit_task, 0,
                         RTOS_LOWEST_RT_PRIORITY);
    if (ret < 0) {
        rtos_event_sem_delete(&wakeup_sem);
        return ret;
    }

    return 0;
}
Ejemplo n.º 5
0
int init_module(void)
{
    unsigned int            nonblock = 1;
    struct sockaddr_in      local_addr;
    struct rtnet_callback   callback = {sync_callback, NULL};


    rtos_print("rt_event is using the following parameters:\n"
           "    mode    = %s\n"
           "    io      = 0x%04X\n"
           "    irq     = %d\n"
           "    my_ip   = %s\n"
           "    dest_ip = %s\n",
           (mode == MODE_PAR) ? "parallel port" : "serial port",
           io, irq, my_ip, dest_ip);


    tdma = open_rt(rtmac_dev, O_RDONLY);
    if (tdma < 0) {
        rtos_print("ERROR: RTmac/TDMA not loaded!\n");
        return -ENODEV;
    }


    sock = socket_rt(AF_INET,SOCK_DGRAM,0);

    memset(&local_addr, 0, sizeof(struct sockaddr_in));
    local_addr.sin_family      = AF_INET;
    local_addr.sin_port        = htons(SYNC_PORT);
    local_addr.sin_addr.s_addr =
        (strlen(my_ip) != 0) ? rt_inet_aton(my_ip) : INADDR_ANY;
    bind_rt(sock, (struct sockaddr*)&local_addr, sizeof(struct sockaddr_in));

    /* switch to non-blocking */
    ioctl_rt(sock, RTNET_RTIOC_NONBLOCK, &nonblock);

    memset(&dest_addr, 0, sizeof(struct sockaddr_in));
    dest_addr.sin_family      = AF_INET;
    dest_addr.sin_port        = htons(REPORT_PORT);
    dest_addr.sin_addr.s_addr = rt_inet_aton(dest_ip);

    ioctl_rt(sock, RTNET_RTIOC_CALLBACK, &callback);


    rtos_event_sem_init(&event_sem);


    if (rtos_irq_request(&irq_handle, irq, irq_handler, NULL) != 0) {
        rtos_print("ERROR: irq not available!\n");
        rtos_event_sem_delete(&event_sem);
        return -EINVAL;
    }

    if (mode == MODE_PAR) {
        /* trigger interrupt on Acknowledge pin (10) */
        outb(0x10, PAR_CONTROL);
    }
    else {
        /* don't forget to specify io and irq (e.g. 0x3F8 / 4) */

        outb(0x00, SER_LCR);
        outb(0x00, SER_IER);

        /* clear irq sources */
        while ((inb(SER_IIR) & 0x01) == 0) {
            rtos_print("Loop init\n");
            inb(SER_LSR);
            inb(SER_DATA);
            inb(SER_MSR);
        }

        /* enable RTS output and set OUT2 */
        outb(0x0A, SER_MCR);

        /* trigger interrupt on modem status line change */
        outb(0x00, SER_LCR);
        outb(0x0D, SER_IER);
    }

    rtos_irq_enable(&irq_handle);


    return rtos_task_init(&task, event_handler, 0, 10);
}