在Windows上原型设计和模拟嵌入式软件 [英] Prototyping and simulating embedded software on Windows

查看:270
本文介绍了在Windows上原型设计和模拟嵌入式软件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找桌面Windows上深入嵌入的C代码的原型(虚拟原型),仿真和测试的工具和技术,包括构建由按钮,LED和LCD显示(包括分段和图形)组成的逼真的嵌入式前面板)



我对一个可能的低级方法特别感兴趣,使用纯C代码和原始的Win32 API而不是MFC,.NET / C#,vxWidgets或Qt 。我也想使用免费开发工具,如Visual C ++ Express与Platform SDK和ResEdit来编辑资源。



我正在寻找代码示例来渲染图形液晶显示器(从单色到24位颜色),具有高效的像素级接口,多段液晶显示屏以及自动绘制的按钮,可以响应沮丧和释放事件。

解决方案

我很惊讶,我原来的问题引发了许多误解和不利评论。在一台机器(例如PC)上开发深入嵌入式C代码并将其运行在另一台机器(嵌入式微控制器)上的策略被称为双重定位,并且非常普遍。例如,在PC上开发和测试深度嵌入的代码是James Grenning最近的一本书嵌入式C的测试驱动开发的基石。



避免使用双重目标的目标硬件瓶颈



请注意,双重定位并不意味着嵌入式设备与PC无关。这不意味着模拟必须与嵌入式目标CPU的周期精确。



双重定位只意味着从第一天起,您的嵌入式代码(通常在C中)旨在运行至少两个平台:最终目标硬件和PC。所有你真正需要的是两个C编译器:一个用于PC,另一个用于嵌入式设备。



然而,双重定位策略确实需要一种特定的设计方式嵌入式软件,使得任何目标硬件依赖性通过通常称为板支持包(BSP)的定义明确的接口来处理。该接口至少有两个实现:一个用于实际目标,一个用于PC,例如运行Windows。通过这样的接口,嵌入式代码的大部分可以完全不知道哪个BSP实现被链接,因此可以在PC上快速开发,但也可以在目标硬件上运行,而不会有任何变化。



虽然一些嵌入式程序员可以将双重定位视为一个自负的负担,但更有经验的开发人员普遍认为,注意软件和硬件之间的界限是实际上是有益的,因为它导致更多的模块化,更便携和更可维护的软件,使用寿命更长。双重目标的投资也在快速加速的编译运行调试周期中立即得到回报,在强大的PC上,速度更快,生产力更高,而运行代码的可见性有限。



前面板Win32 GUI工具包



不平凡的用户界面,经常遇到将嵌入式前面板表示为PC上的GUI元素的问题。问题是如此常见,我真的很惊讶,没有人可以推荐现有的库或开源项目,它将为基本元素(如LCD,按钮和LED)提供一个简单的C-only接口。这真的不是那么复杂,但是似乎每个嵌入式开发人员都必须重新发明这个轮子。



所以,帮助嵌入式开发人员对原型设计感兴趣嵌入式设备在Windows上,我创建了一个前面板Win32 GUI工具包,并根据GPL开源许可证在线发布(请参阅 http ://www.state-machine.com/win32 )。此工具箱仅依赖于C中的原始Win32 API,目前提供以下元素:


  1. 点阵显示,有效像素可寻址的显示器,例如图形LCD,OLED等,具有高达24位的色彩


  2. 分段显示的段显示,如段LCD,以及具有通用的自定义位图的段的LED段。


  3. 拥有自定义按钮,具有自定义按下和释放位图,并能够生成单独的事件沮丧和释放时。


该工具包附有一个示例和一个应用笔记(参见 http://www.state-machine.com/win32/AN_Win32-GUI.pdf ),显示如何处理所有者绘制的输入按钮,常规按钮,键盘和鼠标。您还可以在 http://www.state-machine.com/win32/front_panel.html



关于前面板Win32 GUI工具包的大小和复杂性,上述GUI元素的实现只需要大约250行。例如,所有的输入源和大量的注释大约是300行。该工具包已经通过免费的Visual C ++ Express 2010(使用Express Edition Platform SDK)和免费的ResEdit资源编辑器进行了测试。



享受!


I am looking for tools and techniques for prototyping (virtual prototyping), simulation, and testing of deeply embedded C code on desktop Windows, including building realistic embedded front panels consisting of buttons, LEDs, and LCD displays (both segmented and graphic).

I'm specifically interested in a possibly low-level approach, using pure C code and raw Win32 API rather than MFC, .NET/C#, vxWidgets or Qt. I'd also like to use free development tools, such as Visual C++ Express with Platform SDK and ResEdit for editing resources.

I'm looking for code examples to render graphic LCDs (from monochrome to 24-bit color) with efficient pixel-level interface, multi-segment LCDs, and owner-drawn buttons that respond both to "depressed" and "released" events.

解决方案

I am surprised that my original question triggered so many misunderstandings and adverse comments. The strategy of developing deeply embedded C code on one machine (e.g., a PC) and running it on another (the embedded microcontroller) is called "dual targeting" and is really quite common. For example, developing and testing deeply embedded code on the PC is the cornerstone of the recent book "Test-Driven Development for Embedded C" by James Grenning.

Avoiding Target Hardware Bottleneck with Dual Targeting

Please note that dual targeting does not mean that the embedded device has anything to do with the PC. Neither it means that the simulation must be cycle-exact with the embedded target CPU.

Dual targeting simply means that from day one, your embedded code (typically in C) is designed to run on at least two platforms: the final target hardware and your PC. All you really need for this is two C compilers: one for the PC and another for the embedded device.

However, the dual targeting strategy does require a specific way of designing the embedded software such that any target hardware dependencies are handled through a well-defined interface often called the Board Support Package (BSP). This interface has at least two implementations: one for the actual target and one for the PC, for example running Windows. With such interface in place, the bulk of the embedded code can remain completely unaware which BSP implementation it is linked to and so it can be developed quickly on the PC, but can also run on the target hardware without any changes.

While some embedded programmers can view dual targeting as a self-inflicted burden, the more experienced developers generally agree that paying attention to the boundaries between software and hardware is actually beneficial, because it results in more modular, more portable, and more maintainable software with much longer useful lifetime. The investment in dual targeting has also an immediate payback in the vastly accelerated compile-run-debug cycle, which is much faster and more productive on the powerful PC compared to much slower, recourse-constrained deeply embedded target with limited visibility into the running code.

Front Panel Win32 GUI Toolkit

When developing embedded code for devices with non-trivial user interfaces, one often runs into the problem of representing the embedded front panels as GUI elements on the PC. The problem is so common, that I'm really surprised that nobody here could recommend an existing library or an open source project, which would provide a simple C-only interface to the basic elements, such as LCDs, buttons, and LEDs. This is really not that complicated, yet it seems that every embedded developer has to re-invent this wheel over and over again.

So, to help embedded developers interested in prototyping embedded devices on Windows, I have created a "Front Panel Win32 GUI Toolkit" and have posted it online under the GPL open source license (see http://www.state-machine.com/win32). This toolkit relies only on the raw Win32 API in C and currently provides the following elements:

  1. Dot-matrix display for an efficient, pixel-addressable displays such as graphical LCDs, OLEDs, etc. with up to 24-bit color

  2. Segment display for segmented display such as segment LCDs, and segment LEDs with generic, custom bitmaps for the segments.

  3. Owner-drawn buttons with custom "depressed" and "released" bitmaps and capable of generating separate events when depressed and when released.

The toolkit comes with an example and an App Note (see http://www.state-machine.com/win32/AN_Win32-GUI.pdf), showing how to handle input from the owner-drawn buttons, regular buttons, keyboard, and the mouse. You can also view an animated demo at http://www.state-machine.com/win32/front_panel.html.

Regarding the size and complexity of the "Front Panel Win32 GUI Toolkit", the implementation of the aforementioned GUI elements takes only about 250 lines of C. The example with all sources of input and a lot of comments amounts to some 300 lines of C. The toolkit has been tested with the free Visual C++ Express 2010 (with the Express Edition Platform SDK) and the free ResEdit resource editor.

Enjoy!

这篇关于在Windows上原型设计和模拟嵌入式软件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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