嵌入式项目中如何组织代码? [英] How do you organize code in embedded projects?

查看:160
本文介绍了嵌入式项目中如何组织代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我已经看到很多没有组织的项目。 (主要是硬件工程师,根据我的经验,通常不涉及代码的非功能方面。)



但是,我一直在尝试相应地组织我的代码:


  1. 硬件特定(驱动程序,初始化)

  2. 应用程序具体(不太可能被重用) / li>
  3. 可重复使用,独立于硬件

对于每个模块,我尝试保持其中一个三种类型。



由于嵌入式项目的规模有限,而且强调性能,所以经常会保留这个组织。



对于一些上下文,我目前的项目是一个有限的DSP应用程序,MSP430具有8k闪存和256字节RAM。

解决方案

我已经编写并维护了多种嵌入式产品(30+以上),包括MSP430在内的各种目标微处理器。我最成功的经验法则是:




  • 尝试尽可能模块化通用概念(例如单独的驱动程序代码从应用程序代码)。 - 这将使得项目更容易维护和再利用/移植到未来的另一个目标。

  • 一开始不要担心优化的代码。首先尝试解决域的问题,并优化第二。 - 您的目标微处理可以处理比您预期的更多的东西。

  • 努力确保可读性。虽然大多数嵌入式项目似乎开发周期短,但项目通常比您预期的更长,另一位开发人员无疑必须使用代码。


Highly embedded (limited code and ram size) projects pose unique challenges for code organization.

I have seen quite a few projects with no organization at all. (Mostly by hardware engineers who, in my experience are not typically concerned with non-functional aspects of code.)

However, I have been trying to organize my code accordingly:

  1. hardware specific (drivers, initialization)
  2. application specific (not likely to be reused)
  3. reusable, hardware independent

For each module I try to keep the purpose to one of these three types.

Due to limited size of embedded projects and the emphasis on performance, it is often keep this organization.

For some context, my current project is a limited DSP application on a MSP430 with 8k flash and 256 bytes ram.

解决方案

I've written and maintained multiple embedded products (30+ and counting) on a variety of target micros, including MSP430's. The "rules of thumb" I have been most successful with are:

  • Try to modularize generic concepts as much as possible (e.g. separate driver code from application code). -- It makes for easier maintenance and reuse/porting of a project to another target micro in the future.
  • DO NOT start by worrying about optimized code at the very beginning. Try to solve the domain's problem first and optimize second. -- Your target micro can handle a lot more "stuff" than you might expect.
  • Work to ensure readability. Although most embedded projects seem to have short development-cycles, the projects often live longer than you might expect and another developer will undoubtedly have to work with your code.

这篇关于嵌入式项目中如何组织代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆