【第3章】嵌入式软件模型.ppt

  1. 1、本文档共48页,可阅读全部内容。
  2. 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
  3. 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  4. 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
* * * * * * * * * * * * * * * * * * * * * * * * 3.3 Function Queue Scheduling模型 void interrupt HandleDeviceA(void) { !! Take care of Device A QueueAppend(functionsQueue, FunctionA); } void interrupt HandleDeviceB(void) { !! Take care of Device B QueueAppend(functionsQueue, FunctionB); } void FunctionA(void) { !! Handle actions required by device A } void FunctionB(void) { !! Handle actions required by device B } Queue functionsQueue; void main(void) { while(TRUE) { while(QueueHasItems(functionsQueue)) !! Call first function on queue !! Remove the function from queue } } 3.3 Function Queue Scheduling模型 【优点】 main函数可以按照任何优先级策略来调用队列中的函数; 高优先级的功能能得到更多的CPU资源; 回想一下round robin with interrupts,每一轮main循环,高优先级的功能只能得到一次执行机会; 与此相对,低优先级的功能将获得更少的CPU资源,甚至有可能饿死。 3.3 Function Queue Scheduling模型 【缺点】 不能抢占。如果某个低优先级的功能执行时间很长的话,一旦这个功能被执行,高优先级的功能就需要等待很长时间才能执行; 编程复杂。 Function queue的简单演示 函数指针演示 Function queue简单演示 函数指针演示 typedef int (*func) (int, int); int add(int a, int b) { return a+b; } int decrease(int a, int b) { return a-b; } 函数指针演示 01 int main(int argc, char *argv[]) 02 { 03 func f[2]; 04 f[0] = add; 05 f[1] = decrease; 06 int c1 = f[0](1,2); 07 printf(1+2=%d\n, c1); 08 int c2 = f[1](1,2); 09 printf(1-2=%d\n, c2); 10 return 1; 11 } Function Queue简单演示 01 #include vector 02 #include iostream 03 using namespace std; 04 typedef int (*func) (int, int); 05 typedef struct CommandTag 06 { 07 func function; 08 int parameter1; 09 int parameter2; 10 }Command; Function Queue简单演示 01 void functionQueueSimpleDemo() 02 { 03 vectorCommand commands; 04 while(1) 05 { 06 Command com; 07 char comType; 08 cout Input command and parameters. endl Command a means add, d means decrease, “ endl e means break the input loop and execure all commands input. endl; 09 cin comType com.parameter1 com.parameter2; 10 if (comType == e) 11 break;

文档评论(0)

502992 + 关注
实名认证
内容提供者

该用户很懒,什么也没介绍

1亿VIP精品文档

相关文档