Two Coding Problems
Ian Caddy
ianc at goanna.iinet.net.au
Thu Jan 12 03:23:35 UTC 2006
Hi Sun Shine,
In answer to your second question, I would say it is because your init
task is running off the end of the task and so the init task is deleted.
Then by the time your second task gets to run, it will find the first
available ID and use it, and this would have been the one that the Init
task was using.
To stop this effect, at the end of your init task, put an endless loop,
such as:
while(1)
{
rtems_task_wake_after(100);
}
or you could just suspend the task instead of deleting it (by running
off the end, such as:
rtems_task_suspend(0);
I hope this helps.
regards,
Ian Caddy
Sun Shine wrote:
> Hi,all
> I have two questions here
>
> 1. How can I get the TCB of a certain task? Is there any directive such
> like "rtems_task_get_tcb"?
>
> 2. I wrote an APP, In Init() I create a new task then start it.The
> function of the new task is to create a new task, too.
> Now the Init Task is named T0, the task created by T0 is named T1, and
> the task created by T1 is named T2.
> When running my app on SPARC leon2, the ID information is as follows:
> T0 ID = a010001
> T1 ID = a010002
> T2 ID = a010001
> I don't know why T2's ID is just the same as T0.
>
> The main functions are here:
>
> rtems_task get_task_info(rtems_task_argument argument)
> {
> rtems_id tid;
> rtems_task_priority priority;
> rtems_status_code status;
> status = rtems_task_ident(RTEMS_SELF, RTEMS_SEARCH_ALL_NODES, &tid);
> status = rtems_task_set_priority(tid,RTEMS_CURRENT_PRIORITY,&priority);
> printf("\tTask ID: %x\tpriority: %d\n",tid,priority);
> status = rtems_task_delete(RTEMS_SELF);
> }
>
> rtems_task create_task(rtems_task_argument argument)
> {
> rtems_name name = rtems_build_name('T','S','T',' ');
> rtems_id tid;
> rtems_task_priority priority;
> rtems_status_code status;
> status = rtems_task_ident(RTEMS_SELF,RTEMS_SEARCH_ALL_NODES,&tid);
> status = rtems_task_set_priority(tid,RTEMS_CURRENT_PRIORITY,&priority);
> status = rtems_task_create(name,priority,RTEMS_MINIMUM_STACK_SIZE,
> RTEMS_PREEMPT,RTEMS_DEFAULT_ATTRIBUTES,&tid);
> if(status!=RTEMS_SUCCESSFUL)
> printf("Create task failed with status %d\n",status);
> else
> printf("Create Task %x with priority %d
> successfully!\n",tid,priority); status =
> rtems_task_start(tid,get_task_info,argument);
> if(status!=RTEMS_SUCCESSFUL)
> printf("\tTask %x (%d) start failed with status
> %d\n",tid,priority,status);
> else
> printf("\tTask %x (%d) start
> successfully!\n",tid,priority); status =
> rtems_task_delete(RTEMS_SELF);
> }
>
> rtems_task Init(rtems_task_argument argument)
> {
> rtems_name task_name;
> rtems_status_code status;
> rtems_id tid;
> rtems_task_priority priority;
>
> status = rtems_task_ident(RTEMS_SELF,RTEMS_SEARCH_ALL_NODES,&tid);
> status = rtems_task_set_priority(tid,RTEMS_CURRENT_PRIORITY,&priority);
>
> printf("\nInit Task ID = %x\tprioirty = %d\n\n",tid,priority);
>
> task_name = rtems_build_name( 'T', 'A', '1', ' ' );
> priority = 1;
> status = rtems_task_create(task_name,
> priority,RTEMS_MINIMUM_STACK_SIZE,
> RTEMS_INTERRUPT_LEVEL(0),RTEMS_DEFAULT_ATTRIBUTES, &tid);
>
> if ( status != RTEMS_SUCCESSFUL )
> {
> printf("\tTask create failed with the status of %d\n",status);
> exit(1);
> }
> else
> {
> printf("\tThe Task just created ID: %x\tpriority: %d\n",tid,priority);
> status = rtems_task_set_priority(tid,RTEMS_CURRENT_PRIORITY,&priority);
> }
> status = rtems_task_start( tid, create_task, 0);
>
> if (status != RTEMS_SUCCESSFUL )
> {
> printf("\tTask %x start failed with the stauts of %d\n",tid,status);
> exit(1);
> } status = rtems_task_delete( RTEMS_SELF );
> }
>
>
> Thanks a lot !
> SunPeng
>
> _________________________________________________________________
> 与联机的朋友进行交流,请使用 MSN Messenger: http://messenger.msn.com/cn
--
Ian Caddy
Goanna Technologies Pty Ltd
+61 8 9221 1860
More information about the users
mailing list