Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cyg/infra/diag.h>
- #include <cyg/hal/hal_diag.h>
- #include <cyg/hal/at91sam9_common_reg.h>
- #include <cyg/hal/hal_io.h>
- #include <cyg/io/spi_at91.h>
- #include <cyg/hal/hal_arch.h>
- #include <cyg/kernel/kapi.h>
- #include <cyg/hal/hal_cache.h>
- #include <cyg/hal/at91sam9_io.h>
- #include <assert.h>
- #include <math.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <unistd.h>
- #include <string.h>
- #include <sys/types.h>
- #include <sys/socket.h>
- #include <netinet/in.h>
- #include <netdb.h>
- #define STACKSIZE (CYGNUM_HAL_STACK_SIZE_MINIMUM + 32*1024)
- static unsigned char cs_test_stack[STACKSIZE];
- static cyg_handle_t cs_test_handle;
- static cyg_thread cs_test_thread;
- static void cs_test_thread_func(cyg_addrword_t data);
- void start_cs_test()
- {
- cyg_thread_create(12, &cs_test_thread_func, 0, "CS Test Thread",
- cs_test_stack, STACKSIZE,
- &cs_test_handle, &cs_test_thread);
- cyg_thread_resume(cs_test_handle);
- }
- static void
- cs_test_thread_func(cyg_addrword_t data)
- {
- int servSock, clntSock;
- struct sockaddr_in serv_addr;
- FILE *term;
- int num;
- init_all_network_interfaces();
- servSock = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
- assert(servSock > 0);
- bzero((char *) &serv_addr, sizeof(serv_addr));
- serv_addr.sin_family = AF_INET;
- serv_addr.sin_addr.s_addr=htonl(INADDR_ANY); //listen on every interface
- serv_addr.sin_port = htons(23); //we listen on port 23
- /* Bind to the local address */
- if (bind(servSock, (struct sockaddr *) &serv_addr, sizeof(serv_addr)) < 0)
- {
- diag_printf("Could not bind to local adress\n");
- assert(false);
- }
- if (listen(servSock, 1) < 0)
- {
- diag_printf("listen() failed");
- assert(false);
- }
- while(1)
- {
- /* Wait for a client to connect */
- if ((clntSock = accept(servSock, 0,0)) < 0)
- {
- diag_printf("accept() failed");
- assert(false);
- }
- term=fdopen(clntSock, "r+");
- assert(term!=0);
- while(1)
- {
- fprintf(term, "Type a number\n");
- diag_printf("fscanf %d\n", fscanf(term, "%d",&num));
- diag_printf("fprintf1 %d\n",fprintf(term, "Number was %d\n",num));
- diag_printf("fprintf2 %d\n",fprintf(term, "Again - Number was %d\n",num));
- }
- }
- }
- void cyg_user_start(void);
- void cyg_user_start(void)
- {
- start_cs_test();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement