Chinaunix首页 | 论坛 | 博客
  • 博客访问: 236735
  • 博文数量: 40
  • 博客积分: 2010
  • 博客等级: 大尉
  • 技术积分: 322
  • 用 户 组: 普通用户
  • 注册时间: 2008-06-05 19:46
个人简介

文章分类

全部博文(40)

文章存档

2022年(1)

2018年(2)

2013年(5)

2011年(1)

2010年(14)

2009年(5)

2008年(12)

分类:

2010-03-03 16:00:55

 

1、在/ecos3.0上建立目录default_lib

2、修改已完成的redboot,把模板改为default,保存为ecos.ecc

3、由于暂时用不上网络,并且在链接时由于库里有网络会出错,搜索ecos.ecc文件中含有ETH的字段,都注释掉

4、编译库文件

../tools/bin/ecosconfig tree
make

生成的库文件在目录/ecos3.0/default_lib/ecos_install中。

5、编译示例程序的hellotwothreads

(1)修改/ecos3.0/examples中的Makefile文件,修改库文件路径,并注释掉其他程序的编译

INSTALL_DIR=/ecos-3.0/default_lib/ecos_install/
OUT_DIR=./output

include $(INSTALL_DIR)/include/pkgconf/ecos.mak

XCC           = $(ECOS_COMMAND_PREFIX)gcc
XCXX          = $(XCC)
XLD           = $(XCC)

CFLAGS        = -I$(INSTALL_DIR)/include
CXXFLAGS      = $(CFLAGS)
LDFLAGS       = -nostartfiles -L$(INSTALL_DIR)/lib -Ttarget.ld

# RULES

.PHONY: all clean

all: hello twothreads

clean:
 -rm -f hello hello.o twothreads twothreads.o

%.o: %.c
 $(XCC) -c -o $*.o $(CFLAGS) $(ECOS_GLOBAL_CFLAGS) $<

%.o: %.cxx
 $(XCXX) -c -o $*.o $(CXXFLAGS) $(ECOS_GLOBAL_CFLAGS) $<

%.o: %.C
 $(XCXX) -c -o $*.o $(CXXFLAGS) $(ECOS_GLOBAL_CFLAGS) $<

%.o: %.cc
 $(XCXX) -c -o $*.o $(CXXFLAGS) $(ECOS_GLOBAL_CFLAGS) $<

hello: hello.o
 $(XLD) $(LDFLAGS) $(ECOS_GLOBAL_LDFLAGS) -o $@ $@.o

twothreads: twothreads.o
 $(XLD) $(LDFLAGS) $(ECOS_GLOBAL_LDFLAGS) -o $@ $@.o

 

(2)make,编译hello.ctwothreads.c

hello.c:

/* this is a simple hello world program */
#include

int main(void)
{
  printf("Hello, eCos world!\n");
  return 0;
}

 

twotreads.c:

#include

#include
#include
#include

/* now declare (and allocate space for) some kernel objects,
   like the two threads we will use */
cyg_thread thread_s[2];  /* space for two thread objects */

char stack[2][4096];  /* space for two 4K stacks */

/* now the handles for the threads */
cyg_handle_t simple_threadA, simple_threadB;

/* and now variables for the procedure which is the thread */
cyg_thread_entry_t simple_program;

/* and now a mutex to protect calls to the C library */
cyg_mutex_t cliblock;

/* we install our own startup routine which sets up threads */
void cyg_user_start(void)
{
  printf("Entering twothreads' cyg_user_start() function\n");

  cyg_mutex_init(&cliblock);

  cyg_thread_create(4, simple_program, (cyg_addrword_t) 0,
      "Thread A", (void *) stack[0], 4096,
      &simple_threadA, &thread_s[0]);
  cyg_thread_create(4, simple_program, (cyg_addrword_t) 1,
      "Thread B", (void *) stack[1], 4096,
      &simple_threadB, &thread_s[1]);

  cyg_thread_resume(simple_threadA);
  cyg_thread_resume(simple_threadB);
}

/* this is a simple program which runs in a thread */
void simple_program(cyg_addrword_t data)
{
  int message = (int) data;
  int delay;

  printf("Beginning execution; thread data is %d\n", message);

  cyg_thread_delay(200);

  for (;;) {
    delay = 200 + (rand() % 50);

/* note: printf() must be protected by a
       call to cyg_mutex_lock() */
    cyg_mutex_lock(&cliblock); {
      printf("Thread %d: and now a delay of %d clock ticks\n",
      message, delay);
    }
    cyg_mutex_unlock(&cliblock);
    cyg_thread_delay(delay);
  }
}

 

(3)将生成的hellotwothreads转成bin文件

xscale-elf-objcopy -O binary hello hello.bin

xscale-elf-objcopy -O binary twothreads twothreads.bin

 

(4)按照《IXP425开发板的使用手册》将hello.bintwothreads.bin烧入falsh中,重起开发板

hello.bin运行结果:

Hello, eCos world!

 

twothreads.bin运行结果:

Entering twothreads' cyg_user_start() function
Beginning execution; thread data is 0
Beginning execution; thread data is 1
Thread 0: and now a delay of 239 clock ticks
Thread 1: and now a delay of 230 clock ticks
Thread 1: and now a delay of 221 clock ticks
Thread 0: and now a delay of 214 clock ticks

… …

阅读(2009) | 评论(0) | 转发(1) |
给主人留下些什么吧!~~