Chapter 25Embedded systems programming.ppt
《Chapter 25Embedded systems programming.ppt》由会员分享,可在线阅读,更多相关《Chapter 25Embedded systems programming.ppt(36页珍藏版)》请在麦多课文档分享上搜索。
1、Chapter 25 Embedded systems programming,Bjarne S lecture provides a brief overview of what distinguishes embedded systems programming from “ordinary programming.” It then touches upon facilities that become prominent or problems when working “close to the hardware” such as free store use, bit manipu
2、lation, and coding standards. Remember: not all computers are little grey boxes hiding under desks in offices.,2,Stroustrup/Programming Nov13,Overview,Embedded systems Whats special/different predictability Resource management memory Access to hardware Absolute addresses Bits unsigned Coding standar
3、ds,3,Stroustrup/Programming Nov13,Embedded systems,Hard real time Response must occur before the deadline Soft real time Response should occur before the deadline most of the time Often there are plenty of resources to handle the common cases But crises happen and must be handled Predictability is k
4、ey Correctness is even more important than usual “correctness” is not an abstract concept “but I assumed that the hardware worked correctly” is no excuse Over a long time and over a large range of conditions, it simply doesnt,4,Stroustrup/Programming Nov13,Embedded systems,Computers used as part of
5、a larger system That usually doesnt look like a computer That usually controls physical devices Often reliability is critical “Critical” as in “if the system fails someone might die” Often resources (memory, processor capacity) are limited Often real-time response is essential,5,Stroustrup/Programmi
6、ng Nov13,Embedded systems,What are we talking about? Assembly line quality monitors Bar code readers Bread machines Cameras Car assembly robots Cell phones Centrifuge controllers CD players Disk drive controllers “Smart card” processors,6,Fuel injector controls Medical equipment monitors PDAs Printe
7、r controllers Sound systems Rice cookers Telephone switches Water pump controllers Welding machines Windmills Wrist watches ,Stroustrup/Programming Nov13,Do You Need to Know This Stuff ?,Computer Engineers You will build and oversee the building of these systems All “close to the hardware” code rese
8、mbles this The concern for correctness and predictability of embedded systems code is simply a more critical form of what we want for all code Electrical Engineers You will build and oversee the building of these systems. You have to work with the computer guys You have to be able to talk to them Yo
9、u may have to teach them You may have to take over for them Computer scientists youll know how to do this or only work on web applications (and the like),7,Stroustrup/Programming Nov13,Predictability,C+ operations execute in constant, measurable time E.g., you can simply measure the time for an add
10、operation or a virtual function call and thatll be the cost of every such add operation and every virtual function call (pipelining, caching, implicit concurrency makes this somewhat trickier on some modern processors) With the exception of: Free store allocation (new) Exception throw So throw and n
11、ew are typically banned in hard real-time applications Today, I wouldnt fly in a plane that used those In 5 years, well have solved the problem for throw Each individual throw is predictable Not just in C+ programs Similar operations in other languages are similarly avoided,8,Stroustrup/Programming
12、Nov13,Ideals/aims,Given the constraints Keep the highest level of abstraction Dont write glorified assembler code Represent your ideas directly in code As always, try to write the clearest, cleanest, most maintainable code Dont optimize until you have to People far too often optimize prematurely Joh
13、n Bentleys rules for optimization First law: Dont do it Second law (for experts only): Dont do it yet,9,Stroustrup/Programming Nov13,Embedded systems programming,You (usually) have to be much more aware of the resources consumed in embedded systems programming than you have to in “ordinary” programs
14、 Time Space Communication channels Files ROM (Read-Only Memory) Flash memory You must take the time to learn about the way your language features are implemented for a particular platform Hardware Operating system Libraries,10,Stroustrup/Programming Nov13,Embedded systems programming,A lot of this k
15、ind of programming is Looking at specialized features of an RTOS (Real Time Operating System) Using a “Non-hosted environment” (thats one way of saying “a language right on top of hardware without an operating system”) Involving (sometimes complex) device driver architectures Dealing directly with h
16、ardware device interfaces We wont go into details here Thats what specific courses and manuals are for,11,Stroustrup/Programming Nov13,How to live without new,Whats the problem? C+ code refers directly to memory Once allocated, an object cannot be moved (or can it?) Allocation delays The effort need
17、ed to find a new free chunk of memory of a given size depends on what has already been allocated Fragmentation If you have a “hole” (free space) of size N and you allocate an object of size M where MN in it, you now have a fragment of size N-M to deal with After a while, such fragments constitute mu
18、ch of the memory,12,Free space,New object,old object,old object,Stroustrup/Programming Nov13,How to live without new,Solution: pre-allocate Global objects Allocated at startup time Sets aside a fixed amount of memory Stacks Grow and shrink only at the top No fragmentation Constant time operations Po
19、ols of fixed sized objects We can allocate and deallocate in any order No fragmentation Constant time operations,13,Pool:,Stack:,Top of stack,Stroustrup/Programming Nov13,How to live without new,No new (of course) And no malloc() (memory allocation during runtime) either (for those of you who speak
20、C) No standard library containers (they use free store indirectly) Unless you have a special hard-real time implementation Instead Define (or borrow) fixed-sized Pools Define (or borrow) fixed-sized Stacks Do not regress to using arrays and lots of pointers,14,Stroustrup/Programming Nov13,Pool examp
21、le,/ Note: element type known at compile time / allocation times are completely predictable (and short) / the user has to pre-calculate the maximum number of elements needed template class Pool public:Pool(); / make pool of N Ts construct pools only during startupT* get(); / get a T from the pool; r
22、eturn 0 if no free Tsvoid free(T* p); / return a T given out by get() to the pool private:/ keep track of TN array (e.g., a list of free objects) ;Pool sb_pool; Pool indicator_pool;,15,Stroustrup/Programming Nov13,Stack example,/ Note: allocation times completely predictable (and short) / the user h
23、as to pre-calculate the maximum number of elements needed template class Stack public:Stack(); / make an N byte stack construct stacks only during startupvoid* get(int N); / allocate n bytes from the stack; return 0 if no free spacevoid free(void* p); / return the last block returned by get() to the
24、 stack private:/ keep track of an array of N bytes (e.g. a top of stack pointer) ;Stack my_free_store; / 50K worth of storage to be used as a stackvoid* pv1 = my_free_store.get(256 * sizeof(int); / allocate array of ints int* pi = static_cast(pv1); / you have to convert memory to objectsvoid* pv2 =
- 1.请仔细阅读文档,确保文档完整性,对于不预览、不比对内容而直接下载带来的问题本站不予受理。
- 2.下载的文档,不会出现我们的网址水印。
- 3、该文档所得收入(下载+内容+预览)归上传者、原创作者;如果您是本文档原作者,请点此认领!既往收益都归您。
下载文档到电脑,查找使用更方便
2000 积分 0人已下载
下载 | 加入VIP,交流精品资源 |
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- CHAPTER25EMBEDDEDSYSTEMSPROGRAMMINGPPT
