/* * Author : Sebastien Levieux * Date : 13/12/2024 */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include "system.h" #include rtems_task Test_task( rtems_task_argument argument ) { uint32_t cpu_self; char *task_name; char name[5]; rtems_id task_id; rtems_status_code status; cpu_set_t cpuset; /* Get the task name */ task_name = rtems_object_get_name( RTEMS_SELF, 5, name ); if(&task_name==NULL) { locked_printf("\n**rtems_object_get_name return NULL**\n"); exit(1); } /* Get the CPU Number */ cpu_self = rtems_scheduler_get_processor(); locked_printf("**Hello World!!! I am task %s and I am executing on CPU%d**\n", task_name, cpu_self); rtems_task_exit(); } void main(void) { char task_num; uint32_t cpu_self; uint32_t cpu_nb; rtems_id task_id; rtems_status_code status; rtems_name task_name; cpu_set_t cpuset; //intialize the semaphore to make locked_printf locked_print_initialize(); //set the affinity of the master task to the processor 0 CPU_ZERO(&cpuset); CPU_SET(0, &cpuset); task_id = rtems_task_self(); status = rtems_task_set_affinity(task_id, sizeof(cpuset), &cpuset); if(status!=RTEMS_SUCCESSFUL){ locked_printf("\n**rtems_task_set_affinity not sucessfull**\n"); exit(1); } cpu_self = rtems_scheduler_get_processor(); locked_printf("\n**The master task running on CPU%d**\n", cpu_self); cpu_nb = rtems_scheduler_get_processor_maximum(); locked_printf("**%d CPU available in this configuration**\n", cpu_nb); /* Create and start tasks for each processor */ for (int i=0; i< rtems_scheduler_get_processor_maximum(); i++ ) { if ( i != cpu_self ) { task_num = '0' + i; task_name = rtems_build_name( 'T', task_num,' ',' '); if(&task_name==NULL) { locked_printf("\n**rtems_build_name return NULL**\n"); exit(1); } status = rtems_task_create( task_name, 1, RTEMS_MINIMUM_STACK_SIZE, RTEMS_DEFAULT_MODES, RTEMS_DEFAULT_ATTRIBUTES, &task_id ); if(status!=RTEMS_SUCCESSFUL){ locked_printf("\n**rtems_task_create not sucessfull**\n"); exit(1); } //set the affinity of the master task to the processor 0 CPU_ZERO(&cpuset); CPU_SET(i, &cpuset); status = rtems_task_set_affinity(task_id, sizeof(cpuset), &cpuset); if(status!=RTEMS_SUCCESSFUL){ locked_printf("\n**rtems_task_set_affinity not sucessfull**\n"); exit(1); } status = rtems_task_start( task_id, Test_task, i+1 ); if(status!=RTEMS_SUCCESSFUL){ locked_printf("\n**rtems_task_start not sucessfull**\n"); exit(1); } } } rtems_task_exit(); }