计算机应用 ›› 2014, Vol. 34 ›› Issue (5): 1408-1412.DOI: 10.11772/j.issn.1001-9081.2014.05.1408

• 计算机软件技术 • 上一篇    下一篇

面向嵌入式的协程与脚本化机制

邹昌伟1,王林2   

  1. 1. 福建师范大学 软件学院,福州 350108;
    2. 福建省地震局 地震学会,福州 350003
  • 收稿日期:2013-11-13 修回日期:2013-12-15 出版日期:2014-05-01 发布日期:2014-05-30
  • 通讯作者: 邹昌伟
  • 作者简介:邹昌伟(1981-),男,福建龙岩人,讲师,硕士,主要研究方向:嵌入式系统、信息安全、二进制代码分析;
    王林(1983-),女, 福建福州人,工程师, 硕士,主要研究方向:地理信息系统。
  • 基金资助:

    福建省中青年教师教育科研项目科技B类

Coroutine and scripted mechanism for embedded system

ZOU Changwei1,WANG Lin2   

  1. 1. Faculty of Software, Fujian Normal University, Fuzhou Fujian 350108, China;
    2. Seismological Society, Earthquake Administration of Fujian Province, Fuzhou Fujian 350003, China
  • Received:2013-11-13 Revised:2013-12-15 Online:2014-05-01 Published:2014-05-30
  • Contact: ZOU Changwei

摘要:

针对CortexM3微控制器(MCU)对传统51单片机的部分替代所带来的系统复杂度的增加问题, 提出了一种在无操作系统支持的嵌入式平台上实现并发控制的方法。首先基于上下文无关文法形式化地定义了控制流程的脚本语言, 并实现相应的脚本解释器;然后指出多线程机制是实现多脚本并发执行的充分条件而非必要条件, 通过在MCU自带的定时器中断处理函数中进行并发脚本控制流程的切换,实现了一个能用于嵌入式平台并发编程的协程机制。实验结果表明,该机制能避免对商业多线程库的依赖,降低产品研发成本,在代码可读性方面也有较大提高,使代码烧写次数减少58%左右。在无操作系统和有Linux操作系统支持的嵌入式平台上的分别应用,表明该机制有较好的可移植性和实用性。

Abstract:

Due to the increase of system complexity arising from the partial substitution of the traditional 51 Micro Controller Unit (MCU) with Cortex M3, a method was proposed for concurrent control on embedded system without operating system.First of all, a script language and its corresponding interpreter for concurrent control were implemented via context-free grammar formally; further an proposition was pointed out that multithreading was a sufficient but not necessary condition for concurrent scripts; meanwhile, a coroutine mechanism for concurrent programming on embedded system was constructed by switching script contexts in the interrupt service routine of MCU timer. The experimental results show that the proposed mechanism avoids the dependency on commercial multithreading libraries, which is helpful to decrease the cost of product, promotes the readability of source code and causes a flash programming frequency drop by about 58%.The respective applications on systems with and without operating system demonstrate that this mechanism is portable and practical.

中图分类号: