Chinaunix首页 | 论坛 | 博客
  • 博客访问: 347151
  • 博文数量: 88
  • 博客积分: 907
  • 博客等级: 准尉
  • 技术积分: 1230
  • 用 户 组: 普通用户
  • 注册时间: 2010-01-26 13:27
文章分类

全部博文(88)

文章存档

2017年(1)

2014年(3)

2013年(29)

2012年(21)

2011年(26)

2010年(8)

分类:

2013-01-11 15:33:57

 

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

… …

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