μCOS 系列专题—前言

来源:互联网 发布:淘宝返现哪个最好用 编辑:程序博客网 时间:2024/05/17 06:36
我和现在大多数人一样,最早接触的操作系统便是windows98,但是真正对windows操作系统工作机制的思考是10年后的事情了,我从来没想过自己会这么深入地研究操作系统这个东西,甚至也无法想象自己未来将是否会在操作系统这方面有更远的发展,我深知:无论未来怎样,对于事物更加本质的探索和研究将始终贯穿于我的一生。
微软公司从1985年发布的Windows 1.0到现在Windows10经历了众多版本变更,如今Windows操作系统已经已经非常强大和复杂,在我看来,单凭个人的力量想要穷其一生彻底搞透windows的全部内容恐怕只能是一个幻想罢了,windows系统是人类历史的丰富积淀,是集体智慧的伟大结晶,是层层垒起的宏伟大厦。因此,在一些人看来,深入研究windows的工作机制有点“钻牛角尖”的味道,这就好比你现在去研究欧姆定律、麦克斯韦方程似乎是脑子进了水。尽管当时的负面建议很多,但是这并不能阻止一个脑子发烧的年轻人探索事物内因机理的好奇心和荷尔蒙。因此,这条路注定充满了艰辛与坎坷,特别是对一个从零开始且无理论基础的年轻人来说,必定会走很多弯路,而且这些弯路在现在看来似乎极其可笑和幼稚。在最终确定了总的方向后,一场声势浩荡万里长征便地开始了,从人生的精彩和意义上来说,过程似乎显得比结果更加丰富和重要。
“游戏、办公软件、操作系统、电路板、芯片、数字电路、无线电、通信网络、编程语言、编译器、二进制……”这些在当时的我看好毫无关联的东西,如今都已经成为串联成了一个整体。在知识的海洋里,经过不懈地学习和探索,我终于能够勉强地将这些遗落各地的“珍珠”找寻出来,并一个一个地串在一起。迷茫和郁闷的时候,也只有当年探索有果时的震撼和兴奋尚还温存,在冰冷的现实打击下,在无助的呐喊晕厥后,唯有这些美好的回忆支撑着我保持清醒的意识,唯有那对事物本质的求知若渴精神支撑着我保持清醒的头脑。
日本国际政治活动家、农学家、教育家新渡户稻造在它《修养》一书的序言中讲了一个故事:古时候,有一个知识渊博的儒生,读破万卷书,无所不知,无所不晓。可是无奈他的才能没法活用,渊博的学问也只是藏而不用。后来,随着年纪的增长,记忆力衰退,不仅是读过的书,就连所见所闻也都忘的一干二净。和人见过面后,过上一段时间,就记不清人家的姓名和容貌,最后,连自己的年龄都忘了。更甚的是,和别人讲话也分不清高下清卑、男女老幼。世人嘲笑他,称他为“忘却先生”。
为了缅怀过去,为了慰藉自己,为了重振精神,我想用文字记录下那逝去的美好瞬间,分享自己摸索事物的一点心得,也期望能够为身处迷途中的同道中人一点帮助。在生活中个,也认识不少的朋友,他们因为各方面的原因阴差阳错,走上了一条自己根本不想要的道路,他们尝试着去改变,却身陷囹吾,毕竟摸着石头过河如履薄冰,也许这就是痛并快乐着的真实写照吧。
作为文章的引子,感慨颇多,现在进入正题。这个系列的博文主要是通过μCOSII来讲述我学习操作系统的整个过程,和院校派的学习方式不同,我从自身的一系列的疑问出发,经过逐步探索,逐渐挖掘出了与操作系统相关的一些列知识,比如时序逻辑电路、CPU组成和工作机制、指令体系、协议接口、编程语言、设计模式、编译器、正则表达式、链接器、重定位、操作系统、任务调度、进程、线程、内存管理、垃圾回收、图形库、驱动程序、数据库、网络协议栈、MFC、CLR、JVM、COM、C/S和B/S等等。当然,很多的知识点只是概要的串了起来,在这系列博文中,我将毕其一生精力对每个知识点进行逐步深入地探索,不断进行补充和完善,也希望在这方面经验丰富的朋友们提出宝贵意见和指导,咱们共同学习共同提高。
说起μCOS II,我不得不再次推崇一下作者的故事,它给予我们这些自学者无比的信心和动力,可以说正是他开篇讲述的故事深深地打动了我,坚定了我学习的信心。下面贴出原文,让我们来一起回味一下:
Many years ago, I designed aproduct based on an Intel 80C188 at Dynalco Controls, and I needed a real-timekernel. I had been using a well-known kernel (I’ll call it kernel A) in my workfor a previous employer, but it was too expensive for the application I wasdesigning. I found a lower cost kernel ($1,000 at the time), I’ll call itkernel B, and started the design. I spent about two months trying to get acouple of very simple tasks to run. I was calling the vendor almost on a dailybasis for help to make it work. The vendor claimed that kernel B was written inC (the language); however, I had to initialize every single object usingassembly language code. Although the vendor was very patient, I decided that Ihad enough. The product was falling behind schedule, and I really didn’t wantto spend my time debugging this low-cost kernel. It turns out that I was one ofthe vendor’s first customers, and the kernel really was not fully tested anddebugged.
To get back on track, Idecided to go back and use kernel A. The cost was about $5,000 for fivedevelopment seats, and I had to pay a per-usage fee of about $200 for each unitthat was shipped. This was a lot of money at the time, but it bought some peaceof mind. I got the kernel up and running in about two days. Three months intothe project, one of my engineers discovered what looked like a bug in thekernel. I sent the code to the vendor, and sure enough, the bug was confirmedas being in the kernel. The vendor provided a 90-day warranty, but that hadexpired, so in order to get support, I had to pay an additional $500 per yearfor maintenance. I argued with the salesperson for a few months that theyshould fix the bug since I was actually doing them a favor. They wouldn’tbudge. Finally, I gave in and bought the maintenance contract, and the vendorfixed the bug six months later. Yes, six months later! I was furious and, mostimportantly, late delivering the product. In all, it took close to a year toget the product to work reliably with kernel A. I must admit, however, that Ihave had no problems with it since.
As this was going on, Inaively thought that it couldn’t be that difficult to write a kernel. All itneeds to do is save and restore processor registers. That’s when I decided totry to write my own kernel (part time, nights and weekends). It took me about ayear to get the kernel to work as well, and in some ways better, than kernel A.I didn’t want to start a company and sell it because there were already about50 kernels out there, so why have another one?
Then I thought of writing apaper for a magazine. First I went to C User’s Journal (CUJ) because the kernelwas written in C. I had heard CUJ was offering $100 per published page whenother magazines were only paying $75 per page. My paper had 70 or so pages, sothat would be nice compensation for all the time I spent working on my kernel.Unfortunately, the article was rejected for two reasons. First, the article wastoo long, and the magazine didn’t want to publish a series. Second, they didn’twant “another kernel article.”
I decided to turn to EmbeddedSystems Programming (ESP) magazine because my kernel was designed for embeddedsystems. I contacted the editor of ESP (Mr. Tyler Sperry) and told him that Ihad a kernel I wanted to publish in his magazine. I got the same response fromTyler that I did from CUJ: “Not another kernel article?” I told him that thiskernel was different — it was preemptive, it was comparable to many commercialkernels, and the source code could be posted on the ESP BBS (Bulletin BoardService). I was calling Tyler two or three times a week, basically begging himto publish my article. He finally gave in, probably because he was tired of mycalls. My article was edited down from 70 pages to about 30 pages and waspublished in two consecutive months (May and June 1992). The article wasprobably the most popular article in 1992. ESP had over 500 downloads of thecode from the BBS in the first month. Tyler may have feared for his lifebecause kernel vendors were upset that he published a kernel in his magazine. Iguess that these vendors must have recognized the quality and capabilities ofµC/OS (called µCOS then). The article was really the first that exposed theinternal workings of a real-time kernel, so some of the secrets were out.
About the time the articlecame out in ESP, I got a call from Dr. Bernard (Berney) Williams at CMP Books,CMP Media, Inc. (publisher of CUJ) six months after the initial contact withCUJ. He had left a message with my wife and told her that he was interested inthe article. I called him back and said, “Don’t you think you are a little bitlate with this? The article is being published in ESP.” Berney said, “No, No,you don’t understand. Because the article is so long, I want to make a book outof it.” Initially, Berney simply wanted to publish what I had (as is), so thebook would only have 80 pages or so. I told him that if I was going to write abook, I wanted to do it right. I then spent about six months adding content towhat is now known as the first edition. In all, the book published at about 250pages. I changed the name from µCOS to µC/OS because ESP readers had beencalling it “mucus,” which didn’t sound too healthy. Come to think of it, maybeit was a kernel vendor that first came up with the name. Anyway, µC/OS, TheReal-Time Kernel was born. Sales were somewhat slow to start. Berney and I hadprojected about 4,000 to 5,000 copies would be sold in the life of the book,but at the rate it was selling, I thought we’d be lucky if it sold 2,000copies. Berney insisted that these things take time to get known, so hecontinued advertising in CUJ for about a year.
A month or so before the bookcame out, I went to my first Embedded Systems Conference (ESC) in Santa Clara,California (September 1992). I met Tyler Sperry for the first time, and Ishowed him a copy of the first draft of my book. He very quickly glanced at itand asked if I would like to speak at the next Embedded Systems Conference inAtlanta. Not knowing any better, I said I would and asked him what I shouldtalk about. He suggested “Using Small Real-Time Kernels.” On the trip back fromCalifornia, I was thinking, “What did I get myself into? I’ve never spoken infront of a bunch of people before. What if I make a fool of myself? What ifwhat I speak about is common knowledge? People pay good money to attend thisconference.” For the next six months, I prepared my lecture. At the conference,I had more than 70 attendees. In the first twenty minutes I must have lost onepound of sweat. After my lecture, about 15 people or so came up to me to saythat they were very pleased with the lecture and liked my book. I was invitedback to the conference but could not attend the one in Santa Clara that year(1993) since my wife was due to have our second child, Sabrina. I was able toattend the next conference in Boston (1994), and I have been a regular speakerat ESC ever since. For the past couple of years, I’ve been on the conferenceAdvisory Committee. I now do at least three lectures at every conference andeach has attendance between 100 and 300 people. My lectures are almost alwaysranked among the top 10% at the conference.
To date, well over 25,000copies of my µC/OS and µC/OS-II books have been sold around the world. I havereceived and answered thousands of e-mails from over 44 countries. I still tryto answer every single one. I believe that if you take the time to write me, Iowe you a response. In 1995, µC/OS, The Real-Time Kernel was translated intoJapanese and published in Japan in a magazine called Interface. In 2001,µC/OS-II was translated to Chinese. AKorean translation cam out in early 2002. A Japanese translation is in the works and should be available in 2002.
µC/OS and µC/OS-II have beenported to over 40 different processor architectures and the number of ports isincreasing. You should consult theMicrium web site to see if the processor you intend to use is available.
Back in 1992, I never imaginedthat writing an article would change my life as it has. I met a lot of veryinteresting people and made a number of good friends in the process.
Thanks for chosing this bookand I hope you enjoy it!