hi i am implementing tcpnet tcp/ip stack with rtx and i have read the keil instructions. but this code doesnt work and no tcp packet is sent to the pc. i am confused and dont know what to do to eliminate the fault. here is my code
init task :
__task void tcp_init1 (void) { init (); init_TcpNet (); debug_frmwrk_init(); tcp_tick_tsk=os_tsk_create (tcp_tick, 3); tcp_main_tsk=os_tsk_create (tcp_main, 1); tcp_send_rec_tsk=os_tsk_create (tcp_send_rec,2); os_mut_init(mutex_TcpNet); /* Init done, terminate this task. */ os_tsk_delete_self (); }
task 1 :
__task void tcp_tick (void) { os_itv_set (100); while (1) { os_itv_wait (); /* Timer tick every 100 ms */ timer_tick (); os_evt_set(0x0001, tcp_main_tsk); } }
task 2 :
__task void tcp_main (void) { while (1) { os_mut_wait (mutex_TcpNet, 0xffff); os_evt_wait_and(0x0001, 0xFFFF); main_TcpNet (); os_mut_release (mutex_TcpNet); os_tsk_pass (); } }
task 3 :
__task void tcp_send_rec (void) { uint8_t *sendbuf; U16 k; tcp_soc = tcp_get_socket (TCP_TYPE_CLIENT_SERVER | TCP_TYPE_KEEP_ALIVE, 0,30,tcp_callback); tcp_listen (tcp_soc, 1001); for(;;) { os_mut_wait (mutex_TcpNet, 0xffff); switch (tcp_get_state (tcp_soc)) { case TCP_STATE_FREE: case TCP_STATE_CLOSED: case TCP_STATE_LISTEN: tcp_connect (tcp_soc, Rem_IP, 1001, 0); break; case TCP_STATE_CONNECT: if (tcp_check_send (tcp_soc) == __TRUE) { sendbuf = tcp_get_buf(10); //Fill buffer in here for(k=0;k<10;k++) sendbuf[k] = 0x41 + k%10; tcp_send (tcp_soc, sendbuf, 10); } break; } os_mut_release (mutex_TcpNet); } }
i have edited my code and some of problems seems to be solved but still not any paket isnt sent to the pc. my edited code is as below. i transfered the initializing functions from tasks to the starting lines of main function. init task :
__task void tcp_init1 (void) { tcp_tick_tsk=os_tsk_create (tcp_tick, 3); tcp_main_tsk=os_tsk_create (tcp_main, 1); tcp_send_rec_tsk=os_tsk_create (tcp_send_rec,2); os_mut_init(mutex_TcpNet); /* Init done, terminate this task. */ os_tsk_delete_self (); }
__task void tcp_tick (void) { os_itv_set (100); while (1) { os_itv_wait (); /* Timer tick every 100 ms */ timer_tick (); }
__task void tcp_main (void) { while (1) { os_mut_wait (mutex_TcpNet, 0xffff); main_TcpNet (); os_mut_release (mutex_TcpNet); os_tsk_pass (); } }
__task void tcp_send_rec (void) { uint8_t *sendbuf; U16 k; for(;;) { os_mut_wait (mutex_TcpNet, 0xffff); switch (tcp_get_state (tcp_soc)) { case TCP_STATE_FREE: case TCP_STATE_CLOSED: case TCP_STATE_LISTEN: tcp_connect (tcp_soc, Rem_IP, 1001, 0); break; case TCP_STATE_CONNECT: if (tcp_check_send (tcp_soc) == __TRUE) { sendbuf = tcp_get_buf(10); //Fill buffer in here for(k=0;k<10;k++) sendbuf[k] = 0x41 + k%10; tcp_send (tcp_soc, sendbuf, 10); } break; } os_mut_release (mutex_TcpNet); } }
main func.
void main (void) { init (); init_TcpNet (); tcp_soc = tcp_get_socket (TCP_TYPE_CLIENT_SERVER | TCP_TYPE_KEEP_ALIVE, 0, 30,tcp_callback); tcp_listen (tcp_soc, 1001); os_sys_init (tcp_init1); while(1) {} }