Rtems例程解析

来源:互联网 发布:vb cmd 切换目录 编辑:程序博客网 时间:2024/05/17 15:18

分析一:

/*

 *  Simple test program -- simplified version of sample test hello.

 *

 *  $Id: test.c,v 1.1.1.1 2009/08/06 20:25:58 joel Exp $

 */

#include <bsp.h>

#include <stdlib.h>

#include <stdio.h>

rtems_task Init(

  rtems_task_argument ignored

)

{

  printf( "\n\n*** HELLO WORLD TEST ***\n" );

  printf( "Hello World\n" );

  printf( "*** END OF HELLO WORLD TEST ***\n" );

  exit( 0 );

}

/* configuration information */

/* NOTICE: the clock driver is explicitly disabled */

#define CONFIGURE_APPLICATION_DOES_NOT_NEED_CLOCK_DRIVER

#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER

#define CONFIGURE_RTEMS_INIT_TASKS_TABLE

#define CONFIGURE_MAXIMUM_TASKS 1

#define CONFIGURE_INIT

#include <rtems/confdefs.h>

/* end of file */

分析1.

#define CONFIGURE_APPLICATION_DOES_NOT_NEED_CLOCK_DRIVER

#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER

这两个宏,用于选择打开或关闭相关设备的驱动。如第一项,关闭了时钟的驱动程序。第二项,打开了控制台的驱动程序。

分析2.

#define CONFIGURE_RTEMS_INIT_TASKS_TABLE

#define CONFIGURE_MAXIMUM_TASKS 1

第一项,API任务表初始化任务表相关选项。rtems/confdefs.h可以自动生成一个叫做Initialization_tasks的初始化任务表。而该选项就是其中一个控制如何生成该初始化任务表的一个参数。该项用来说明,用户是否希望使用Rtems API初始化任务表。用户可能使用其他API的初始化任务表或线程。默认,这一部分是不定义的,因此用户必须自己为初始化任务选择自己的API。

RTEMS API Confguration Table

typedef struct {

uint32_t maximum_tasks;

uint32_t maximum_timers;

uint32_t maximum_semaphores;

uint32_t maximum_message_queues;

uint32_t maximum_partitions;

uint32_t maximum_regions;

uint32_t maximum_ports;

uint32_t maximum_periods;

uint32_t maximum_barriers;

uint32_t number_of_initialization_tasks;

rtems_initialization_tasks_table *User_initialization_tasks_table;

} rtems_api_configuration_table;

number of initialization tasks

配置的初始化任务数。至少有一个Rtems初始化或者Posix初始化操作,用户的应用程序从这里开始执行。当用rtems/confdefs.h来配置用户应用程序时,该项参数必须配置,以此来说明有一个或多个Rtems初始化程序。

下面这些宏,与单一初始化任务涉及到的内容。

CONFIGURE_INIT_TASK_NAME

CONFIGURE_INIT_TASK_STACK_SIZE 单一初始化任务,堆栈的大小。

CONFIGURE_INIT_TASK_PRIORITY

CONFIGURE_INIT_TASK_ATTRIBUTES 单初始化任务的属性。默认被设置为RTEMS_DEFAULT_

ATTRIBUTES 。

CONFIGURE_INIT_TASK_ENTRY_POINT 初始化任务函数入口地址。默认设置为用C实现的Init例程。

CONFIGURE_INIT_TASK_INITIAL_MODES 初始化任务执行的模式。

这些宏具体是如何完成赋值的?赋值完成后,初始化任务表便有了具体的值。初始化任务表自然是为初始化任务服务。初始化任务在整个系统中又具有什么作用?

分析3.

#define CONFIGURE_INIT 

CONFIGURE_INIT常量必须给予定义,因为这可以让rtems/confdefs.h将配置的数据结构实例化。在一个应用程序中,这个只能定义一次。

分析二:

/*

* This file contains an example of a simple RTEMS

* application. It instantiates the RTEMS Configuration

* Information using confdef.h and contains two tasks:

* a * user initialization task and a simple task.

*

* This example assumes that a board support package exists.

*/

#include <rtems.h>

rtems_task user_application(rtems_task_argument argument);

rtems_task init_task(

rtems_task_argument ignored

)

{

rtems_id tid;

rtems_status_code status;

rtems_name name;

name = rtems_build_name( ’A’, ’P’, ’P’, ’1’ )

status = rtems_task_create(

name, 1, RTEMS_MINIMUM_STACK_SIZE,

RTEMS_NO_PREEMPT, RTEMS_FLOATING_POINT, &tid

);

if ( status != RTEMS_STATUS_SUCCESSFUL ) {

printf( "rtems_task_create failed with status of %d.\n", status );

exit( 1 );

}

status = rtems_task_start( tid, user_application, 0 );

if ( status != RTEMS_STATUS_SUCCESSFUL ) {

printf( "rtems_task_start failed with status of %d.\n", status );

exit( 1 );

}

status = rtems_task_delete( SELF ); /* should not return */

printf( "rtems_task_delete returned with status of %d.\n", status );

exit( 1 );

}

rtems_task user_application(rtems_task_argument argument)336 RTEMS C User’s Guide

{

/* application specific initialization goes here */

while ( 1 ) { /* infinite loop */

/* APPLICATION CODE GOES HERE

*

* This code will typically include at least one

* directive which causes the calling task to

* give up the processor.

*/

}

}

#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER /* for stdio */

#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER /* for time services */

#define CONFIGURE_MAXIMUM_TASKS 2

#define CONFIGURE_INIT_TASK_NAME rtems_build_name( ’E’, ’X’, ’A’, ’M’ )

#define CONFIGURE_RTEMS_INIT_TASKS_TABLE

#define CONFIGURE_INIT

#include <confdefs.h>