can someone tell me WHY in this promgram?? - VxWorks

This is a discussion on can someone tell me WHY in this promgram?? - VxWorks ; Hello everyone: I am a novice.In this code segments ,I have some questions to ask,Can anybody help me? Thanks!! *********************************** #include "vxWorks.h" #include "stdio.h" #include "stdlib.h" #include "semLib.h" #include "taskLib.h" #include "sysLib.h" #define STACK_SIZE 2000 SEM_ID dataSemId; int tidSend; int ...

+ Reply to Thread
Results 1 to 5 of 5

Thread: can someone tell me WHY in this promgram??

  1. can someone tell me WHY in this promgram??

    Hello everyone:
    I am a novice.In this code segments ,I have some questions to ask,Can
    anybody help me?
    Thanks!!
    ***********************************
    #include "vxWorks.h"
    #include "stdio.h"
    #include "stdlib.h"
    #include "semLib.h"
    #include "taskLib.h"
    #include "sysLib.h"

    #define STACK_SIZE 2000

    SEM_ID dataSemId;
    int tidSend;
    int tidReceive;

    void progStart(void);
    void taskSend(void);
    void taskReceive(void);
    void SendInit(void);
    void ReceiveInit(void);
    void progStop(void);

    void progStart(void)
    {
    dataSemId=semBCreate(SEM_Q_FIFO,SEM_EMPTY);
    printf("\nAAAAAAAA");
    tidSend=taskSpawn("tSend",200,0,STACK_SIZE,(FUNCPTR)taskSend,0,0,0,0,0,0,0, 0,0,0);
    printf("\nBBBBBBBB"); //After created the "tSend" task WHY not
    executes it while is "printf("\nBBBBBBBB")" ?
    tidReceive=taskSpawn("tReceive",220,0,STACK_SIZE,(FUNCPTR)taskReceive,0,0,0,0,0,0 ,0,0,0,0);
    printf("\nCCCCCCCC");

    return;
    }

    void taskSend(void)
    {
    SendInit();
    while(1)
    {


    taskDelay(sysClkRateGet()*4);
    printf("\nin send cycle");
    semGive(dataSemId);

    }
    printf("\nout send cycle");
    return; //When execute return ? WHY use "return" ?
    }

    void taskReceive(void)
    {
    ReceiveInit();
    while(1)
    {

    semTake(dataSemId,WAIT_FOREVER);
    printf("\nin receive cycle");
    printf("\nReceive a data");
    }
    printf("\nout receive cycle");
    return; //When execute return ? Why use "return" ?
    }

    void SendInit(void)
    {
    printf("\nInitial Send Task");
    return;
    }

    void ReceiveInit(void)
    {
    printf("\nInitial Receive Task");
    return;
    }

    void progStop(void)
    {
    semDelete(dataSemId);
    taskDelete(tidSend);
    taskDelete(tidReceive);
    printf("the end");
    return;
    }

    ************************************
    Use the default VxSim0 at the debug mode execute "progStart"
    the output is:
    AAAAAAAA
    BBBBBBBB
    CCCCCCCC
    Initial Send Task
    Initial Receive Task
    in send cycle
    in receive cycle
    Receive a data
    in send cycle
    in receive cycle
    Receive a data
    in send cycle
    in receive cycle
    Receive a data
    in send cycle
    in receive cycle
    Receive a data
    in send cycle
    in receive cycle
    Receive a datathe end
    **********************


  2. Re: can someone tell me WHY in this promgram??


    cet-4-cet-4@163.com 写道:

    > Hello everyone:
    > I am a novice.In this code segments ,I have some questions to ask,Can
    > anybody help me?
    > Thanks!!
    > ***********************************
    > #include "vxWorks.h"
    > #include "stdio.h"
    > #include "stdlib.h"
    > #include "semLib.h"
    > #include "taskLib.h"
    > #include "sysLib.h"
    >
    > #define STACK_SIZE 2000
    >
    > SEM_ID dataSemId;
    > int tidSend;
    > int tidReceive;
    >
    > void progStart(void);
    > void taskSend(void);
    > void taskReceive(void);
    > void SendInit(void);
    > void ReceiveInit(void);
    > void progStop(void);
    >
    > void progStart(void)
    > {
    > dataSemId=semBCreate(SEM_Q_FIFO,SEM_EMPTY);
    > printf("\nAAAAAAAA");
    > tidSend=taskSpawn("tSend",200,0,STACK_SIZE,(FUNCPTR)taskSend,0,0,0,0,0,0,0, 0,0,0);
    > printf("\nBBBBBBBB"); //After created the "tSend" task WHY not
    > executes it while is "printf("\nBBBBBBBB")" ?
    > tidReceive=taskSpawn("tReceive",220,0,STACK_SIZE,(FUNCPTR)taskReceive,0,0,0,0,0,0 ,0,0,0,0);
    > printf("\nCCCCCCCC");
    >
    > return;
    > }
    >


    Maybe you've used "sp progStart" to run your programme, according to
    the manual, sp will create a task with
    th priority of 100, but your tasks are 200 and 220, you can try 50
    instead.
    > void taskSend(void)
    > {
    > SendInit();
    > while(1)
    > {
    >
    >
    > taskDelay(sysClkRateGet()*4);
    > printf("\nin send cycle");
    > semGive(dataSemId);
    >
    > }
    > printf("\nout send cycle");
    > return; //When execute return ? WHY use "return" ?
    > }


    A task never returns unless you ask to(Kill it). You must have found
    that you never see the string "out send cycle"..


    > void taskReceive(void)
    > {
    > ReceiveInit();
    > while(1)
    > {
    >
    > semTake(dataSemId,WAIT_FOREVER);
    > printf("\nin receive cycle");
    > printf("\nReceive a data");
    > }
    > printf("\nout receive cycle");
    > return; //When execute return ? Why use "return" ?
    > }
    >
    > void SendInit(void)
    > {
    > printf("\nInitial Send Task");
    > return;
    > }
    >
    > void ReceiveInit(void)
    > {
    > printf("\nInitial Receive Task");
    > return;
    > }
    >
    > void progStop(void)
    > {
    > semDelete(dataSemId);
    > taskDelete(tidSend);
    > taskDelete(tidReceive);
    > printf("the end");
    > return;
    > }
    >
    > ************************************
    > Use the default VxSim0 at the debug mode execute "progStart"
    > the output is:
    > AAAAAAAA
    > BBBBBBBB
    > CCCCCCCC
    > Initial Send Task
    > Initial Receive Task
    > in send cycle
    > in receive cycle
    > Receive a data
    > in send cycle
    > in receive cycle
    > Receive a data
    > in send cycle
    > in receive cycle
    > Receive a data
    > in send cycle
    > in receive cycle
    > Receive a data
    > in send cycle
    > in receive cycle
    > Receive a datathe end
    > **********************



  3. Re: can someone tell me WHY in this promgram??


    cet-4-cet-4@163.com 写道:

    > Hello everyone:
    > I am a novice.In this code segments ,I have some questions to ask,Can
    > anybody help me?
    > Thanks!!
    > ***********************************
    > #include "vxWorks.h"
    > #include "stdio.h"
    > #include "stdlib.h"
    > #include "semLib.h"
    > #include "taskLib.h"
    > #include "sysLib.h"
    >
    > #define STACK_SIZE 2000
    >
    > SEM_ID dataSemId;
    > int tidSend;
    > int tidReceive;
    >
    > void progStart(void);
    > void taskSend(void);
    > void taskReceive(void);
    > void SendInit(void);
    > void ReceiveInit(void);
    > void progStop(void);
    >
    > void progStart(void)
    > {
    > dataSemId=semBCreate(SEM_Q_FIFO,SEM_EMPTY);
    > printf("\nAAAAAAAA");
    > tidSend=taskSpawn("tSend",200,0,STACK_SIZE,(FUNCPTR)taskSend,0,0,0,0,0,0,0, 0,0,0);
    > printf("\nBBBBBBBB"); //After created the "tSend" task WHY not
    > executes it while is "printf("\nBBBBBBBB")" ?
    > tidReceive=taskSpawn("tReceive",220,0,STACK_SIZE,(FUNCPTR)taskReceive,0,0,0,0,0,0 ,0,0,0,0);
    > printf("\nCCCCCCCC");
    >
    > return;
    > }
    >


    Maybe you've used "sp progStart" to run your programme, according to
    the manual, sp will create a task with
    th priority of 100, but your tasks are 200 and 220, you can try 50
    instead.
    > void taskSend(void)
    > {
    > SendInit();
    > while(1)
    > {
    >
    >
    > taskDelay(sysClkRateGet()*4);
    > printf("\nin send cycle");
    > semGive(dataSemId);
    >
    > }
    > printf("\nout send cycle");
    > return; //When execute return ? WHY use "return" ?
    > }


    A task never returns unless you ask to(Kill it). You must have found
    that you never see the string "out send cycle"..


    > void taskReceive(void)
    > {
    > ReceiveInit();
    > while(1)
    > {
    >
    > semTake(dataSemId,WAIT_FOREVER);
    > printf("\nin receive cycle");
    > printf("\nReceive a data");
    > }
    > printf("\nout receive cycle");
    > return; //When execute return ? Why use "return" ?
    > }
    >
    > void SendInit(void)
    > {
    > printf("\nInitial Send Task");
    > return;
    > }
    >
    > void ReceiveInit(void)
    > {
    > printf("\nInitial Receive Task");
    > return;
    > }
    >
    > void progStop(void)
    > {
    > semDelete(dataSemId);
    > taskDelete(tidSend);
    > taskDelete(tidReceive);
    > printf("the end");
    > return;
    > }
    >
    > ************************************
    > Use the default VxSim0 at the debug mode execute "progStart"
    > the output is:
    > AAAAAAAA
    > BBBBBBBB
    > CCCCCCCC
    > Initial Send Task
    > Initial Receive Task
    > in send cycle
    > in receive cycle
    > Receive a data
    > in send cycle
    > in receive cycle
    > Receive a data
    > in send cycle
    > in receive cycle
    > Receive a data
    > in send cycle
    > in receive cycle
    > Receive a data
    > in send cycle
    > in receive cycle
    > Receive a datathe end
    > **********************



  4. Re: can someone tell me WHY in this promgram??

    cet-4-cet-4@163.com schrieb:
    > Hello everyone:
    > I am a novice.In this code segments ,I have some questions to ask,Can
    > anybody help me?


    Yes I can, please start asking your questions...


    --
    BaSystem Martin Raabe
    E: Martin.RaabeB-a-S-y-s-t-e-mde

  5. Re: can someone tell me WHY in this promgram??

    Martin Raabe schrieb:
    > cet-4-cet-4@163.com schrieb:
    >> Hello everyone:
    >> I am a novice.In this code segments ,I have some questions to ask,Can
    >> anybody help me?

    >
    > Yes I can, please start asking your questions...


    Oh I have overseen the two questions, excuse me.
    But I can imagine, there are more.

    So to your questions in the comments:
    "When execute return ? WHY use "return" ?"

    Answer:
    In your example the return will never execute, yes.
    the return would be there even if you would not code it due to the
    closing brace.
    The while-loop should always be active in your example, but usually
    there is lot more error handling where there is a good chance that the
    task jumps out of the while loop.
    This could be a reason for the existance of the two lines of code.

    BTW: The code segment

    void progStop(void)
    {
    semDelete(dataSemId);
    taskDelete(tidSend);
    taskDelete(tidReceive);
    printf("the end");
    return;
    }

    is wrong in terms of what to be done first.
    first delete the tasks and the the resource they use, which is the
    semaphore.
    here it only works well since the shell has a higher priority than your
    tasks!

    Take care.


    --
    BaSystem Martin Raabe
    E: Martin.RaabeB-a-S-y-s-t-e-mde

+ Reply to Thread