Problem with messages

hwulf at et-inf.fho-emden.de hwulf at et-inf.fho-emden.de
Tue Mar 20 09:52:15 UTC 2007


Hi,

I'm rather new to RTEMS and I wanted to try out the message queues.
I'm checking the status codes with a hand-written print_status_code()
function. Creating of the message queues is successful, but when
trying to send a message from user_task_1 to user_task_2, RTEMS
says "RTEMS_INVALID_SIZE".

Does anybody have an idea?

The example code is shown below.

Thank you very much and kind regards,
Hank




/******************************************************************************
  *
  * INIT
  *
  *  
****************************************************************************/
rtems_task Init(rtems_task_argument argument)
{
	rtems_status_code status;


	puts("\n\n*** TASK COMMUNICATION TEST ***");
	/*
	 * Building necessary names
	 */
	Task_name[1] = rtems_build_name('T', 'S', 'K', '1');
	Task_name[2] = rtems_build_name('T', 'S', 'K', '2');
	Queue_name[1] = rtems_build_name('Q', 'U', 'E', '1');
	Queue_name[2] = rtems_build_name('Q', 'U', 'E', '2');
//	Semaphore_name[1] = rtems_build_name('S', 'E', 'M', '1');
//	Semaphore_name[2] = rtems_build_name('S', 'E', 'M', '2');

	/*
	 * Create the user tasks
	 */
	status = rtems_task_create(Task_name[1], 1, RTEMS_MINIMUM_STACK_SIZE * 2,
   							 RTEMS_DEFAULT_MODES | RTEMS_PREEMPT | RTEMS_TIMESLICE,
   							 RTEMS_DEFAULT_ATTRIBUTES, &Task_id[ 1 ]);
   	print_status_code(status, "Creating Task 1");

	status = rtems_task_create(Task_name[2], 1, RTEMS_MINIMUM_STACK_SIZE * 2,
   							 RTEMS_DEFAULT_MODES | RTEMS_PREEMPT | RTEMS_TIMESLICE,
   							 RTEMS_DEFAULT_ATTRIBUTES, &Task_id[ 2 ]);
   	print_status_code(status, "Creating Task 2");

	/*
	 * Create the message queues
	 */
	status = rtems_message_queue_create(Queue_name[1], 40, 1,
							RTEMS_LOCAL, &Queue_id[1]);
	print_status_code(status, "Creating Message Queue 1");

	status = rtems_message_queue_create(Queue_name[2], 1, 1,
							RTEMS_FIFO | RTEMS_LOCAL, &Queue_id[2]);
	print_status_code(status, "Creating Message Queue 2");

	/*
	 * Create the semaphores
	 */
//	status = rtems_semaphore_create(Semaphore_name[1], 1,
//							RTEMS_FIFO | RTEMS_BINARY_SEMAPHORE |
//							RTEMS_NO_INHERIT_PRIORITY | RTEMS_NO_PRIORITY_CEILING |
//							RTEMS_LOCAL, 2, &Semaphore_id[1]);
//	print_status_code(status, "Creating Semaphore 1");

//	status = rtems_semaphore_create(Semaphore_name[2], 1,
//							RTEMS_FIFO | RTEMS_BINARY_SEMAPHORE |
//							RTEMS_NO_INHERIT_PRIORITY | RTEMS_NO_PRIORITY_CEILING |
//							RTEMS_LOCAL, 2, &Semaphore_id[2]);
//	print_status_code(status, "Creating Semaphore 2");

	status = rtems_task_start( Task_id[ 1 ], user_task_1, 0 );
//	rtems_task_wake_after( 100 );
	status = rtems_task_start( Task_id[ 2 ], user_task_2, 0 );

//	rtems_task_wake_after( 5000 );

	status = rtems_task_delete( RTEMS_SELF );
}
#include <stdio.h>

/******************************************************************************
  *
  * USER_TASK1
  *
  *  
****************************************************************************/
rtems_task user_task_1(rtems_task_argument unused)
{
//	rtems_id          tid;
//	rtems_unsigned32  task_index;
	rtems_status_code status;
//	rtems_event_set task1_event;
	char buffer[40] = "Hello World!\n";
	rtems_unsigned32 buflen = 40;

	status = rtems_message_queue_send(Queue_id[1], (void*)buffer, buflen);
	print_status_code(status, "Message sent.");
	printf("Task 1: This message was sent to Task 2: %s\n", buffer);
	//rtems_message_queue_receive(Queue_id[1], (void*)&buffer, &buflen,  
RTEMS_WAIT, RTEMS_NO_TIMEOUT);

	rtems_task_wake_after(100);


}

/******************************************************************************
  *
  * USER_TASK2
  *
  *  
****************************************************************************/
rtems_task user_task_2(rtems_task_argument unused)
{
	rtems_id          tid;
	rtems_unsigned32  task_index;
	rtems_status_code status;
	rtems_event_set task2_event = 100;
	char buffer[40] = "Hello World back!\n";
	rtems_unsigned32 buflen = 40;

	//rtems_message_queue_send(Queue_id[1], (void*)&buffer, buflen);
	status = rtems_message_queue_receive(Queue_id[1], (void*)&buffer,  
&buflen, RTEMS_NO_WAIT, 10);
	print_status_code(status, "Message received.");
	//printf("Task 2: This message was received: %s\n", buffer);
	//rtems_task_wake_after(1);
}




More information about the users mailing list