DSPRelated.com
Forums

DSP/BIOS Task compile issue

Started by balasubramanian vaidhyanathan September 24, 2008
balasub...

the ID in the write task (only one write task) needs to be set to contain the
thread number, not the task number.

R. Williams

---------- Original Message -----------
From: balasubramanian vaidhyanathan
To: William C Bonner , Richard Williams

Cc: c...
Sent: Thu, 25 Sep 2008 07:35:16 -0700 (PDT)
Subject: Re: [c6x] Issue understanding this code

> Hi Richard
>
> Are the three Ids three different tasks. I added three tasks in the
> cdb file and connected this function _write to the properties and
> executed the code still i get only one id.. Can you tell me how to get
> three id printed out?.....
>
> --- On Wed, 9/24/08, Richard Williams wrote:
>
> From: Richard Williams
> Subject: Re: [c6x] Issue understanding this code
> To: i...@yahoo.com, "William C Bonner"
> Cc: c...
> Date: Wednesday, September 24, 2008, 11:32 PM
>
> balasub,,,
>
> I ran the code, I now see why the 'freeQueue' was being initialized
> with
> pointer to messages/
> I.E.
> The QUE_Get() and QUE_Put() only transfer a pointer to a message,
> rather than the actual message content.
>
> So I am wrong in the elimination of the freeQueue.
> Sorry about that.
> BTW:
> The code is also missing the following, probably just after the
> #include statements: void reader(void); // declaration for the reader task
> void writer(Int taskId); // declaration for the writer task
>
> The code is missing the following statements:
> extern SEM_Obj sem;
> extern QUE_Obj msgQueue;
> extern QUE_Obj freeQueue;
> extern LOG_Obj trace;
>
> And each of the writer_Msg variables that I wrote, need to be changed
> to a pointer, etc.
>
> If you want, I can send along a more realistic version.
>
> R. Williams
>
> ---------- Original Message -----------
> From: balasubramanian vaidhyanathan
> To: William C Bonner
> Cc: c...
> Sent: Wed, 24 Sep 2008 15:13:18 -0700 (PDT)
> Subject: [c6x] Issue understanding this code
>
> > Hi
> >
> > Below is the code I yanked out of TI BIOS User guide. Now what i
> > cant understand is this, the writer task has an id. In the document it
> > says there are three writers. So does that mean i have to create three
> > tasks and connect them to _writer and give same priority and run this
> > code so that i can have 3 writers?. I tried running with 2 writers and
> > the code does not behave as told. I ran with only one task and in the
> > reader() task i removed the 2 in the loop and the code exited
> > properly. Please explain.I have highlighted my confusing points in
> bold....
> >
> > regards
> > Bala
> >
> > #include
> > #include
> > #include
> > #include
> > #include
> > #include
> > #include "queuecfg.h"
> > #define NUMMSGS 3 /* number of messages */
> > #define NUMWRITERS 3
> > typedef struct MsgObj {
> > QUE_Elem elem; /* first field for QUE */
> > int id;
> > Char val; /* message value */
> > } MsgObj, *Msg;
> >
> > /*
> > * ======== main =======> > */
> > Void main()
> > {
> > int i;
> > MsgObj *msg;
> > Uns mask;
> > mask=TRC_LOGTSK|TRC_LOGSWI|TRC_STSSWI|TRC_LOGCLK;
> > TRC_enable(TRC_GBLHOST|TRC_GBLTARG|mask);
> > msg=(MsgObj *)MEM_alloc(0,NUMMSGS*sizeof(MsgObj),0);
> > if(msg==MEM_ILLEGAL)
> > {
> > SYS_abort("Memory allocation failed \n");
> > }
> > for(i=0;i > > {
> > QUE_put(&freeQueue,msg);
> > }
> > }
> > /* reader code */
> > void reader()
> > {
> > Msg msg;
> > Int i;
> > for(i=0;i > > {
> > SEM_pend(&sem,SYS_FOREVER);
> > msg=QUE_get(&msgQueue);
> > LOG_printf(&trace,"read '%c' from (%d)
> .",msg->val,msg->id);
> > QUE_put(&freeQueue,msg);
> > }
> > LOG_printf(&trace,"reader done\n");
> > }
> >
> > /* writer code */
> > void writer(Int id)
> > {
> > Msg msg;
> > Int i;
> >
> > for(i=0;i > > {
> > /* Get msg from the free queue*/
> > if(QUE_empty(&freeQueue))
> > {
> >
> > SYS_abort("Empty free queue\n");
> > }
> > msg=QUE_get(&freeQueue);
> > /*fill in value*/
> > msg->id=id;
> > msg->val=(i& 0xf)+'a';
> > LOG_printf(&trace,"(%d) writing
> '%c'...",id,msg->val);
> > QUE_put(&msgQueue,msg);
> > SEM_post(&sem);
> > }
> > LOG_printf(&trace,"Writer is done\n");
> > }
> >
> > --- On Wed, 9/24/08, William C Bonner wrote:
> >
> > From: William C Bonner
> > Subject: Re: [c6x] DSP/BIOS Task compile issue
> > To: "balasubramanian vaidhyanathan"
>
> > Cc: c...
> > Date: Wednesday, September 24, 2008, 11:04 AM
> >
> > When you couldn't get your project to compile, was it giving you
> > errors, or was it simply ignoring your code?
> >
> > I seem to remember something like this from when I was starting with
> > the TI compiler. I am pretty sure I set a flag to cause it to
> > recognize the .cpp extension as a c++ file. The extension used for
> > recognizing a C++ code file varied between compilers for a long time.
> > Many recognized .cc or .C while using .c for standard C code.
> >
> > balasubramanian vaidhyanathan wrote:
> > > I got my trial project to compile... Only because my file name was
> > > .cpp and i changed to .c it compiled.... i find this strange in
> > > DSP/BIOS... Has anyone faced this issue before?
> > >
> > >
> ------- End of Original Message -------
------- End of Original Message -------
If the SEM_pend is happening sometime during the main function then the
behavior is expected. Semaphores and locks do not function until after the
main function returns and the DSP/BIOS finishes initializing.

On Thu, Sep 25, 2008 at 10:43 AM, balasubramanian vaidhyanathan <
i...@yahoo.com> wrote:

> Hi all My code is supposed to pend on a semaphore and i checked the
> semaphore count alsoit is zero. but the code still goes beyond SEM_pend when
> i step through. Why would it behave like this?. If the semaphorecount is
> zero then it should pend forever because ihave time out as SYS_FOREVER....
> Have u faced this issue?> regardsBala
>
>
>
>
>
>
--
Gregory Lee
To add little more to it ,
If application is having only one task with Sem_pend in that and posting is
done from main function , this will cause abnormal behavior , for semaphore
pending and task . If you check the Execution graph details it will
show *"ERROR:
Invalid thread state transition"*

But if you add one more task to above application , i mean empty task with
not even single line of code in that, then Sem_pend will work fine and no
error message also . Sem posting from main function works normally .

This goes to prove that ,Semaphore usage is for task-to-task sync only , ie
only when multiple tasks exists .

- Jai

On Fri, Sep 26, 2008 at 1:56 PM, Gregory Lee wrote:

> If the SEM_pend is happening sometime during the main function then the
> behavior is expected. Semaphores and locks do not function until after the
> main function returns and the DSP/BIOS finishes initializing.
>
> On Thu, Sep 25, 2008 at 10:43 AM, balasubramanian vaidhyanathan <
> i...@yahoo.com> wrote:
>
>> Hi all My code is supposed to pend on a semaphore and i checked the
>> semaphore count alsoit is zero. but the code still goes beyond SEM_pend when
>> i step through. Why would it behave like this?. If the semaphorecount is
>> zero then it should pend forever because ihave time out as SYS_FOREVER....
>> Have u faced this issue?> regardsBala
>>
>>
>>
>>
>>
>>
> --
> Gregory Lee
>
>