예제 #1
0
int init_module(void)
{
    unsigned int            local_ip;
    unsigned int            server_ip = rt_inet_aton(server_ip_s);
    struct rtnet_callback   callback  = {echo_rcv, NULL};


    if (strlen(local_ip_s) != 0)
        local_ip = rt_inet_aton(local_ip_s);
    else
        local_ip = INADDR_ANY;

    if (interval < 1) interval = 1;
    if (interval > 1000) interval = 1000;

    if (packetsize < 1) packetsize = 1;
    if (packetsize > 1400) packetsize = 1400;

    printk("***** start of rt_client ***** %s %s *****\n", __DATE__, __TIME__);
    printk("local  ip address %s=%08x\n", local_ip_s, local_ip);
    printk("server ip address %s=%08x\n", server_ip_s, server_ip);
    printk("interval = %d\n", interval);
    printk("packetsize = %d\n", packetsize);
    printk("start timer %d\n", start_timer);

    rtf_create(PRINT, 8000);

    /* create rt-socket */
    sock = socket_rt(AF_INET,SOCK_DGRAM,0);

    /* bind the rt-socket to local_addr */
    memset(&local_addr, 0, sizeof(struct sockaddr_in));
    local_addr.sin_family = AF_INET;
    local_addr.sin_port = htons(RCV_PORT);
    local_addr.sin_addr.s_addr = local_ip;
    bind_rt(sock, (struct sockaddr *)&local_addr, sizeof(struct sockaddr_in));

    /* set server-addr */
    memset(&server_addr, 0, sizeof(struct sockaddr_in));
    server_addr.sin_family = AF_INET;
    server_addr.sin_port = htons(SRV_PORT);
    server_addr.sin_addr.s_addr = server_ip;

    /* set up callback handler */
    ioctl_rt(sock, RTNET_RTIOC_CALLBACK, &callback);

    if (start_timer) {
        rt_set_oneshot_mode();
        start_rt_timer(0);
    }

    rt_task_init(&rt_task,(void *)process,0,4096,10,0,NULL);
    rt_task_make_periodic_relative_ns(&rt_task, 1000000,
                                      (RTIME)interval * 1000000);

    return 0;
}
예제 #2
0
int init_module(void)
{
    unsigned int add_rtskbs = 30;
    int ret;

    unsigned long local_ip;
    unsigned long client_ip;


    if (strlen(local_ip_s) != 0)
        local_ip = rt_inet_aton(local_ip_s);
    else
        local_ip = INADDR_ANY;
    client_ip = rt_inet_aton(client_ip_s);
    if (reply_size < sizeof(nanosecs_t))
        reply_size = sizeof(nanosecs_t);

    rtos_print("local  ip address %s(%8x):%d\n", local_ip_s,
               (unsigned int)local_ip, RCV_PORT);
    rtos_print("client ip address %s(%8x):%d\n", client_ip_s,
               (unsigned int)client_ip, XMT_PORT);
    rtos_print("reply message size=%d\n", reply_size);

    /* create rt-socket */
    rtos_print("create rtsocket\n");
    if ((sock = socket_rt(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0) {
        rtos_print("socket not created\n");
        return sock;
    }

    /* bind the rt-socket to local_addr */
    rtos_print("bind rtsocket to local address:port\n");
    memset(&local_addr, 0, sizeof(struct sockaddr_in));
    local_addr.sin_family = AF_INET;
    local_addr.sin_port = htons(RCV_PORT);
    local_addr.sin_addr.s_addr = local_ip;
    if ((ret = bind_rt(sock, (struct sockaddr *)&local_addr,
                       sizeof(struct sockaddr_in))) < 0) {
        close_rt(sock);
        rtos_print("can't bind rtsocket\n");
        return ret;
    }

    /* set client-addr */
    rtos_print("connect rtsocket to client address:port\n");
    memset(&client_addr, 0, sizeof(struct sockaddr_in));
    client_addr.sin_family = AF_INET;
    client_addr.sin_port = htons(XMT_PORT);
    client_addr.sin_addr.s_addr = client_ip;
    if ((ret = connect_rt(sock, (struct sockaddr *)&client_addr,
                          sizeof(struct sockaddr_in))) < 0) {
        close_rt(sock);
        rtos_print("can't connect rtsocket\n");
        return ret;
    }

    /* extend the socket pool */
    ret = ioctl_rt(sock, RTNET_RTIOC_EXTPOOL, &add_rtskbs);
    if (ret != (int)add_rtskbs) {
        close_rt(sock);
        rtos_print("ioctl_rt(RTNET_RTIOC_EXTPOOL) = %d\n", ret);
        return -1;
    }

    ret = rtos_task_init(&rt_task, (void *)process, 0, 10);

    return ret;
}
int init_module(void)
{
    unsigned int add_rtskbs = 30;
    int ret;

    unsigned long local_ip;
    unsigned long server_ip;


    if (strlen(local_ip_s) != 0)
        local_ip = rt_inet_aton(local_ip_s);
    else
        local_ip = INADDR_ANY;
    server_ip = rt_inet_aton(server_ip_s);

    rtf_create(PRINT_FIFO, 40000);
    rt_sem_init(&tx_sem, 0);

    rt_printk("local  ip address %s=%8x\n", local_ip_s, (unsigned int) local_ip);
    rt_printk("server ip address %s=%8x\n", server_ip_s, (unsigned int) server_ip);

    /* create rt-socket */
    rt_printk("create rtsocket\n");
    if ((sock = socket_rt(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0) {
        rt_printk("socket not created\n");
        return sock;
    }

    /* extend the socket pool */
    ret = ioctl_rt(sock, RTNET_RTIOC_EXTPOOL, &add_rtskbs);
    if (ret != (int)add_rtskbs) {
        close_rt(sock);
        rt_printk("ioctl_rt(RTNET_RTIOC_EXTPOOL) = %d\n", ret);
        return -1;
    }

    /* bind the rt-socket to local_addr */
    local_addr.sin_family = AF_INET;
    local_addr.sin_port = htons(RCV_PORT);
    local_addr.sin_addr.s_addr = local_ip;
    if ((ret = bind_rt(sock, (struct sockaddr *)&local_addr,
                       sizeof(struct sockaddr_in))) < 0) {
        close_rt(sock);
        rt_printk("can't bind rtsocket\n");
        return ret;
    }

    /* set server-addr */
    server_addr.sin_family = AF_INET;
    server_addr.sin_port = htons(SRV_PORT);
    server_addr.sin_addr.s_addr = server_ip;

    rt_task_init(&xmit_task,(void *)process,0,4096,10,0,NULL);
    rt_task_resume(&xmit_task);

    rt_task_init(&recv_task,(void *)echo_rcv,0,4096,9,0,NULL);
    rt_task_resume(&recv_task);

    rt_request_global_irq(parirq, parport_irq_handler);
    rt_startup_irq(parirq);

    outb(0xFF, PAR_DATA);
    outb(0x14 + KHZ0_1, PAR_CONTROL);

    return ret;
}
예제 #4
0
int main(int argc, char *argv[])
{
    int ret;
    unsigned int i;
    struct sockaddr_in local_addr;
    struct in_addr dest_ip;


    while (1) {
        switch (getopt(argc, argv, "d:s:t")) {
            case 'd':
                dest_ip_s = optarg;
                break;

            case 's':
                size = atoi(optarg);
                break;

            case 't':
                start_timer = 1;
                break;

            case -1:
                goto end_of_opt;

            default:
                printf("usage: %s -d <dest_ip> -s <size> -t\n", argv[0]);
                return 0;
        }
    }
 end_of_opt:

    inet_aton(dest_ip_s, &dest_ip);

    if (size > 65505)
        size = 65505;

    signal(SIGTERM, catch_signal);
    signal(SIGINT, catch_signal);
    mlockall(MCL_CURRENT|MCL_FUTURE);

    printf("destination ip address %s=%08x\n", dest_ip_s, dest_ip.s_addr);
    printf("size %d\n", size);
    printf("start timer %d\n", start_timer);

    /* fill output buffer with test pattern */
    for (i = 0; i < sizeof(buffer_out); i++)
        buffer_out[i] = i & 0xFF;

    /* create rt-socket */
    sock = socket_rt(AF_INET,SOCK_DGRAM,0);
    if (sock < 0) {
        printf(" socket_rt() = %d!\n", sock);
        return sock;
    }

    /* extend the socket pool */
    ret = ioctl_rt(sock, RTNET_RTIOC_EXTPOOL, &add_rtskbs);
    if (ret != (int)add_rtskbs) {
        printf(" ioctl_rt(RT_IOC_SO_EXTPOOL) = %d\n", ret);
        close_rt(sock);
        return -1;
    }

    /* bind the rt-socket to a port */
    memset(&local_addr, 0, sizeof(struct sockaddr_in));
    local_addr.sin_family = AF_INET;
    local_addr.sin_port = htons(PORT);
    local_addr.sin_addr.s_addr = INADDR_ANY;
    ret = bind_rt(sock, (struct sockaddr *)&local_addr, sizeof(struct sockaddr_in));
    if (ret < 0) {
        printf(" bind_rt() = %d!\n", ret);
        close_rt(sock);
        return ret;
    }

    /* set destination address */
    memset(&dest_addr, 0, sizeof(struct sockaddr_in));
    dest_addr.sin_family = AF_INET;
    dest_addr.sin_port = htons(PORT);
    dest_addr.sin_addr = dest_ip;

    if (start_timer) {
        rt_timer_start(TM_ONESHOT);
    }

    ret = rt_task_create(&rt_recv_task, "Receiver", 0, 10, 0);
    if (ret != 0) {
        printf(" rt_task_create(recv) = %d!\n", ret);
        close_rt(sock);
        return ret;
    }

    ret = rt_task_create(&rt_xmit_task, "Sender", 0, 9, 0);
    if (ret != 0) {
        printf(" rt_task_create(xmit) = %d!\n", ret);
        close_rt(sock);
        rt_task_delete(&rt_recv_task);
        return ret;
    }

    rt_task_start(&rt_recv_task, recv_msg, NULL);
    rt_task_start(&rt_xmit_task, xmit_msg, NULL);

    pause();

    if (start_timer)
        rt_timer_stop();

    /* Important: First close the socket! */
    while (close_rt(sock) == -EAGAIN) {
        printf("frag-ip: Socket busy - waiting...\n");
        sleep(1);
    }

    rt_task_delete(&rt_xmit_task);
    rt_task_delete(&rt_recv_task);

    return 0;
}
예제 #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);
}
예제 #6
0
int main(int argc, char *argv[]) {
    int sockfd = 0;
    int ret    = 0;

    RT_TASK *lxrtnettsk;
    char msg[] = "This message was sent using rtnet_lxrt.";

    /* Set address structures to zero.  */
    memset(&local_addr, 0, sizeof(struct sockaddr_in));
    memset(&server_addr, 0, sizeof(struct sockaddr_in));

    printf("RTnet, simpleclient for NEWLXRT\n");

    /* Check arguments and set addresses. */
    if (argc == 4) {
        local_addr.sin_family      = AF_INET;
        local_addr.sin_addr.s_addr = INADDR_ANY;
        local_addr.sin_port        = htons(atoi(argv[1]));

        server_addr.sin_family = AF_INET;
        inet_aton(argv[2], &server_addr.sin_addr);
        server_addr.sin_port = htons(atoi(argv[3]));
    } else {
        fprintf(stderr,
            "Usage: "
            "%s <local-port> "
            "<server-ip> <server-port>\n",
            argv[0]);
        exit(1);
    }

    /* Lock allocated memory into RAM. */
    mlockall(MCL_CURRENT|MCL_FUTURE);

    /* Create new socket. */
    sockfd = socket_rt(AF_INET, SOCK_DGRAM, 0);
    if (sockfd < 0) {

        printf("Error opening socket: %d\n", sockfd);
        exit(1);
    }

    /* Initialize a real time buddy. */
    lxrtnettsk = rt_task_init(4800, 1, 0, 0);
    if (NULL == lxrtnettsk) {
        close_rt(sockfd);
        printf("CANNOT INIT MASTER TASK\n");
        exit(1);
    }

    /* Switch over to hard realtime mode. */
    rt_make_hard_real_time();

    /* Bind socket to local address specified as parameter. */
    ret = bind_rt(sockfd, (struct sockaddr *) &local_addr,
                  sizeof(struct sockaddr_in));

    /* Specify destination address for socket; needed for rt_socket_send(). */
    connect_rt(sockfd, (struct sockaddr *) &server_addr,
               sizeof(struct sockaddr_in));

    /* Send a message. */
    send_rt(sockfd, msg, sizeof(msg), 0);

    /* Switch over to soft realtime mode. */
    rt_make_soft_real_time();

    /* Close socket.
     * Note: call must be in soft-mode because socket was created as non-rt! */
    close_rt(sockfd);

    /* Delete realtime buddy. */
    rt_task_delete(lxrtnettsk);

    return 0;
}