µTasker Forum

µTasker Forum => µTasker general => Topic started by: tr111 on July 24, 2009, 08:43:19 AM

Title: why the task never run with the (DELAY_LIMIT)(NO_DELAY_RESERVE_MONO)
Post by: tr111 on July 24, 2009, 08:43:19 AM
    I want use the udp,and the code is that !
   
   
Code: [Select]

    #include "config.h"

#define OWN_TASK             TASK_UDP

#define UDP_BUFFER_SIZE        200                                        // buffer size for UDP test message
#define MY_UDP_PORT            1999

#define E_TIMER_NEXT_MESSAGE   1

typedef struct stUDP_MESSAGE
{
    unsigned short usLength;
    UDP_HEADER     tUDP_Header;                                          // reserve header space
    unsigned char  ucUDP_Message[UDP_BUFFER_SIZE];                       // reserve message space
} UDP_MESSAGE;

static int fnUDPListner(USOCKET SocketNr, unsigned char ucEvent, unsigned char *ucIP, unsigned short usPortNr, unsigned char *data, unsigned short usLength)
{
    return 0;
}

void fnUDPWORK(TTASKTABLE *ptrTaskTable) 
{
    static USOCKET MyUDP_Socket = -1;
    static UDP_MESSAGE *ptrUDP_Frame;
    const unsigned char ucIP[IPV4_LENGTH]= {192, 168, 0, 37};
    QUEUE_HANDLE        PortIDInternal = ptrTaskTable->TaskID;           // queue ID for task input
    unsigned char       ucInputMessage[HEADER_LENGTH];                   // reserve space for receiving messages

    if (MyUDP_Socket < 0) {                                              // only perform once
        ptrUDP_Frame    = uMalloc(sizeof(UDP_MESSAGE));                  // get some memory for UDP frame   
        MyUDP_Socket = fnGetUDP_socket(TOS_MINIMISE_DELAY, fnUDPListner, (UDP_OPT_SEND_CS | UDP_OPT_CHECK_CS));
        fnBindSocket(MyUDP_Socket, MY_UDP_PORT);
        uMemcpy(&ptrUDP_Frame->ucUDP_Message, "Hello World", UDP_BUFFER_SIZE);
        fnSendUDP(MyUDP_Socket, (unsigned char *)ucIP, MY_UDP_PORT, (unsigned char*)&ptrUDP_Frame->tUDP_Header, sizeof("Hello World"), OWN_TASK);
        uTaskerMonoTimer( OWN_TASK, (DELAY_LIMIT)(10*SEC), E_TIMER_NEXT_MESSAGE );
    }

    while ( fnRead( PortIDInternal, ucInputMessage, HEADER_LENGTH )) {   // check input queue
        switch ( ucInputMessage[MSG_SOURCE_TASK] ) {                     // switch depending on message source
        case TIMER_EVENT:
            if (E_TIMER_NEXT_MESSAGE == ucInputMessage[MSG_TIMER_EVENT]) {
                fnSendUDP(MyUDP_Socket, (unsigned char *)ucIP, MY_UDP_PORT, (unsigned char*)&ptrUDP_Frame->tUDP_Header, sizeof("Hello World"), OWN_TASK);
                uTaskerMonoTimer( OWN_TASK, (DELAY_LIMIT)(10*SEC), E_TIMER_NEXT_MESSAGE );
            }
            break;

        case  TASK_ARP:
            fnRead( PortIDInternal, ucInputMessage, ucInputMessage[MSG_CONTENT_LENGTH]); // read the contents
            switch (ucInputMessage[ 0 ]) {                               // ARP sends us either ARP resolution success or failed
                case ARP_RESOLUTION_SUCCESS:                             // IP address has been resolved (repeat UDP frame).
                    fnSendUDP(MyUDP_Socket, (unsigned char *)ucIP, MY_UDP_PORT, (unsigned char*)&ptrUDP_Frame->tUDP_Header, sizeof("Hello World"), OWN_TASK);
                    break;

                case ARP_RESOLUTION_FAILED:                              // IP address could not be resolved...
                    break;
            }
            break;
        }
    }
}

in the TaskConfig.h
#define TASK_UDP             'e'                                      // UART2 task

const UTASK_TASK ctNodes[] = { 

...
...

TASK_UDP,

}

in the const UTASKTABLEINIT ctTaskTable[] = {.....
.......
.......
.......

{ "eUDP", fnUDPWORK, MEDIUM_QUE,   (DELAY_LIMIT)(NO_DELAY_RESERVE_MONO),0, UTASKER_STOP},//udp

}


I find the fnUDPWORK never run at (DELAY_LIMIT)(NO_DELAY_RESERVE_MONO),!!!!!
but set (DELAY_LIMIT)(0.2 * SEC) the fnUDPWORK will run ,
why????????


Title: Re: why the task never run with the (DELAY_LIMIT)(NO_DELAY_RESERVE_MONO)
Post by: tr111 on July 24, 2009, 09:11:11 AM
I find the why!

the will run the one time!
{ "eUDP", fnUDPWORK, MEDIUM_QUE,   (DELAY_LIMIT)(NO_DELAY_RESERVE_MONO), 0, UTASKER_ACTIVATE},

if set the uTaskerStateChange(TASK_UDP, UTASKER_ACTIVATE) at the other task,
it will run more times!