Ecos操作系統查看进程信息

由于最近公司用到了ecos操作系统,所以简单的了解了一下这个RTOS,其相关的社区资源较少,国内基本不用,这里结合手册整理了一部分的内容。本文章主要两部分,一是建立基本的测试进程,而是枚举所有进程并查看相关信息。

如下代码是在原来的基础上增加的进程信息获取,其中堆栈使用的查看需要在ecos系统配置时启用测量堆栈使用,实际上就是启用一个宏定义。图形化配置如下,也可以直接配置宏(不推荐)。

启用堆栈测量1:启用堆栈测量

启用堆栈测量2:

#ifdef CYGFUN_KERNEL_THREADS_STACK_MEASUREMENT
        info->stack_used = thread->measure_stack_usage();
#else
#include <cyg/kernel/kapi.h>
#include <cyg/cpuload/cpuload.h>

#include <stdio.h>
#include <math.h>
#include <stdlib.h>

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

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

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

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


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

cyg_uint32 calibrate;

cyg_cpuload_t cpuload;

cyg_uint32 time_100,time_1000, time_10000;

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

	cyg_mutex_init(&cliblock);

	//cyg_thread_create(1,calcpu, 0,"Thread1",stack[2],4096,&calcpuHandle,&thread_s[2]);

	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_create(3, getTaskInfo, 0,"getTaskInfo", stack[2], 4096,
			&thread_handle, &thread_s[2]);


	cyg_thread_resume(simple_threadA);
	cyg_thread_resume(simple_threadB);
	cyg_thread_resume(thread_handle);


	cyg_thread_delay(10);


	cyg_scheduler_start();

}
void getTaskInfo(cyg_addrword_t data)
{
	cyg_thread_info info;
	cyg_handle_t info_handler;
	cyg_uint16 id = 0;

	while(1)
	{
		while(cyg_thread_get_next(&info_handler, &id))
		{
			cyg_thread_get_info(info_handler,id,&info);
			printf("id:%d\n name:%s\n state:%d\n set_pri:%d\n cur_pri:%d\n stack_used:%d\n",info.id,info.name,info.state,info.set_pri, info.cur_pri,info.stack_used);

		}
		cyg_thread_delay(2000);
	}


}
/* 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);
	}
}

使用如上的工程,重新编译后,将生成的文件扔给redboot加载即可。本人暂时没有arm芯片,使用vmware虚拟机运行ecos,可以看到打印的线程名称,当前状态,设定的优先级和线程当前的优先级以及堆栈的使用情况,当然我这里没有全部显示,所有的线程信息都在cyg_thread_info结构体中,代码和运行结果如图所示:

typedef struct
{
    cyg_handle_t        handle;
    cyg_uint16          id;
    cyg_uint32          state;
    char                *name;
    cyg_priority_t      set_pri;
    cyg_priority_t      cur_pri;
    cyg_addrword_t      stack_base;
    cyg_uint32          stack_size;
    cyg_uint32          stack_used;
} cyg_thread_info;

虚拟机运行结果
另外我会写两篇文章介绍Ecos系统的结构,主要和freertos很不相同,以及在Vmware中运行ecos操作系统,权当普及一下。

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值