FreeRTOS中文入门手册
FreeRTOS中文入门手册方便初学者入门学习,讲的很好,很值得学习第一章任务管理Designed For Micr。 contr。11exs;概览附录中提供了使用源代码的实用信息小型多任务嵌入式系统简介不同的多任务系统有不同的侧重点。以工作站和桌面电脑为例:·早期的处理器非常昂贵,所以那时的多仟务用于实现在单处理器上支持多用户。这类系统中的调度算法侧重于让每个用户公平共享处理器时间。随着处理器功能越来越强大,价格却更偏宜,所以每个用户都可以独占一个或多个处理器。这类系统的调度算法则设计为计用户可以同时运行多个应用程序,而计算机也不会显得反应迟钝。例如某个用户可能同时运行了一个字处理程序,一个电子表格,一个邮件客户端和一个浏览器,并且期望每个应用程序任何时候都能对输入有足够快的响应时间。桌面电脑的输入处珒可以归类为软实时。为了保证用户的最佳体验,计算机对每个输入的响应应当限定在一个恰当的时间范围——但是如果响应时间超出了限定范闱,并不会让人觉得这合电脑无法使用。比如说,键盘操作必须在键按下后的某个时间内作出明显的提示。但如果按键提示超出了这个时间,会使得这个系统看起来响应人慢,而不致于说这台电脑不能使用。仅仅从单处理器运行多线程这一点来说,实时嵌入式系统中的多任务与桌面电脑的多任务从概念上来讲是相似的。但实时嵌入式系统的侧重点却不同于桌面电脑特别是当嵌入式系统期望提供硬实时行为的时候。硬实时功能必须在给定的时间限制之内完成——如果无法做到即意味着整个系统的绝对失败。汽车的安全气囊触发机制就是一个硬实吋功能的例子。安全气囊在撞击发生后给定时间限制内必须弹出。如果响应时间超出了这个时间限制,会使得驾驶员受到伤害,而这原本是可以避免的大多数嵌入式系统不仅能满足硬实时要求,也能满足软实时要求。Designed For Micr。 contr。11exs;术语说明在屮,每个执行线程都被称为任务。在嵌入式社区屮,对此并没有个公允的术语,但我更喜欢用任务而不是线程,因为从以前的经验米看,线程具有更多的特定含义本章的目的是让读者充分了解:在应用程序中,如何为各仟务分配处理时间。●在任意给定时刻,如何选择任务投入运行。●任务优先级如何影响系统行为。●任务存在哪些状态。此外,还期望能够让读者解:●如何实现一个任务。●如何创建一个或多个任务的实例●如何使用任务参数。如何改变一个已创建任务的优先级●如何删除任务。●如何实现周期性处理。空闲任务何时运行,可以用来干什么本章所介绍的概念是理解如何使用的基础,也是理解基于的应用程序行为方式的基础——因此,本章也是这本书中最为详尽的一章Designed For Micr。 contr。11exs;任务函数任务是由语言数实现的。唯一特别的只是任务的函数原犁,其必须返回而且带有一个指针参数。其数原型参见程序清单。void ATaskFunction( void *pvParameters )程序清单任务函数原型每个任务都是在自己权限氾围内的一个小程序。其具有程序入口,通常会运行在一个死循环中,也不会退出。一个典型的任务结构如程序清单所示。仟务不允许以任何方式从实现函数中返回一一它们绝不能有条语句,也不能执行到函数末尾。如果一个任务不再需要,可以显式地将其删除。这也在程序清单展现个任务函数可以用来创建若干个任务—创建出的任务均是独立的执行实例,拥有属于自己的栈空间,以及属于自己的自动变量栈变量,即任务函数本身定义的变量v。 d ATaskFunction(v。1d* pArameters)/*可以像普通函数一样定义变量。用这个函数创延的每个任务实例都有一个属于自己的 vAria1b1 eExamp1e变量。但如果 varial1e3 xample被定义为 static,这一点则不成立-这种情况下只存在一个变量,所有的任务实例将会共享这个变量。int ivariableExample =0;/*仨务通常实现在一个死循环中。*/for(ii)/*完成任务功能的代码将放在这里。*//*如果任务的具体实现会跳出上面的死循环,则此任务必须在函数运行完之前朋除。传入NUL参数表示删除的是当前任务*vTaskDelete( NULL程序清单典型的任务函数结构Designed For Micr。 contr。11exs;顶层任务状态应用程序可以包含多个任务。如果运行应用程序的微控制器只有一个核那么在任意给定时间,实际上只会有一个仼务被执行。这就意味着一个任务可以有一个或两个状态,即运行状态和非运行状态。我们先考虑这种最简单的模型——但请牢记这其实是过于简单,我们硝后将会看到非运行状态实际上又可划分为若千个子状态。当某个任务处于运行态时,处理器就正在执行它的代码。当一个任务处于非运行态时,该任务进行休眠,它的所有状态都被妥善保存,以便在下一次调试器决定让它进入运行态时可以恢复执行。当任务恢复执行时,其将精确地从离开运行态时正准备执行的那一条指令开始执行。A tasks that areOnly one tasknot currentcan be in theRunning are in theRunning state atNot Running Stateany one timeNot RunningRunning图顶层任务状态及状态转移任务从非运行态转移到运行态被称为切换入或切入或交换入相反,任务从运行态转移到非运行态被称为切换出或切出或交换出的调度器是能让任务切入切出的唯一实体。Designed For Micr。 contr。11exs;创建任务函数创建仟务使用的函数这可能是所有数中最复杂的函数,但不幸的是这也是我们第一个遇到的函数。但我们必须首先掌控任务因为它们是多任务系统中最基本的组件。本书中的所有示例程序都会用到,所以会有人量的例子可以参考。附录:描述川到的数据类型和命名约定。portBASE TYPE xTaskCreate( paTASK CODE pvTaskCodeconst signed port CHAR conist pcNameunsigned portSHORT usstackDepthunsigned portEASE TYPE uxPriorityxTaskHandle *pxCreatedTask程序清单函数原型表参数与返回值参数名描述任务只是永不退出的函数,实现常通常是个死循环。参数只一个指向任务的实现函数的指针效果上仅仅是函数名具有描述性的任务名。这个参数不会被使用。其只是单纯地用于辅助调试。识别一个具有可读性的名字总是比通过句柄来识别容易得多。应用程序可以通讨定义常量来定义任务名的最大长度—一包括结朿符。如果传入的字符串长度超过了这个最大值,字符串将会自动被截断。Designed For Micr。 contr。11exs;当任务创建时,内核会分为每个任务分配属于任务自己的唯一状态。值用于告诉内核为它分配多人的栈空间。这个值指定的是栈空间可以保存多少个字,而不是多少个字节比如说,如果是位宽的栈空间,传入的值为则将会分配字节的栈空间。栈深度乘以栈宽度的绩果万不能超过~个类型变量所能表达的最人值。应川程序通过定义常量来决定空闲任条任用的栈空间大小。在为微控制器架构提供的应用程序中,赋予此常量的值是对所有任务的最小建议值如果你的任务会使用大量栈空间,那么你应当赋予一个更大的值。没有任何简单的方法可以决定一个任务到底需要多大的栈空间。计算出来虽然是可能的,但人多数用户会先简单地赋予一个自认为合理的值,然后利用提供的特性来确证分配的空间既不欠缺也不浪费。第六章包括了一些信息,可以知道如何去查询任务使用了多少栈空问。仟务函数接受一个指向的指钅的值即是传递到任务中的值。这篇文档中的一些范例程序将会示范这个参数可以如何使用指定任务执行的优先级。优先级的取值范围可以从最低优先级到最高优先级是一个由用户定义的常量。优生级号并没有上限除了受限于采用的数据类型和系统的有效内存空间,但最妊使用实际需要的最小数值以避免内在浪费。如果的值超过了,将会导致实际赋给任务的优先级被自动封顶到最大合法值。Designed For Micr。 contr。11exs;用于传出任务的句柄。这个句枢将在调川中对该创建出来的任务进行引用,比如改变任务优先级,或者删除仟务。如果应用程序中不会用到这个任务的包柄,则川以被设为返回值有两个可能的返回值:表明任务创建成功。由于内存堆空间不足,无法分配足够的空间来保存任务结构数据和任务栈,因此无法创建任务。第五章将提供更多有关内存管理方面的信息。例创建任务附录:包含一些关于示例程序生成工具的信息。本例演示了创建并启动两个任务的必要步骤。这两个任务只是周期性地打印输出守符串,采用原始的空循环方式来产生周期延迟。两者在创建时指定了相同的优先级,并且在实现上除输出的字符串外完全一样—程序清单4和程序清单5是这两个仟务对应的实现代码。Designed For Micr。 contr。11ers;
- 2020-12-09下载
- 积分:1
使用CC2591作为CC2530的功放
使用CC2591作为CC2530的功放, CC2591 PAThe absolute maximum ratings and operating conditions listed in the CC2530 datasheet [1]and the CC2591 datasheet [4] must be followed at all times. Stress exceeding one or more ofthese limiting values may cause permanent damage to any of the devicesNote that these characteristics are only valid when using the recommended register settingspresented in Section 4.6 and in Chapter 8, and the CC2530 - EM reference designOperating Frequency240524835MHzOperating Supply Voltage2036VOperating Temperature-40CTC=25C, VDD=3.0V, f=2440 MHz if nothing else is stated. All parameters are measuredon the CC2530-Cc2591EM reference design [11] with a 50 Q2 loadReceive CurrentWait for sync, -90 dBm input levelWait for sync, -50 dBm input level24mATXPOWER OXE5166mATXPOWER OXD5149mATXPOWER OXC5138mATXPOWER OXB5127mATransmit currentTXPOWER OXA5115ATXPOWER = 0X95100mATXPOWER = 0X8594ATXPOWE=0×75mATXPOWE=0×6579APower Down Current PM2UAISTRUMENTSPage 3 of 19SWRA308ATC=25C, Vdd=3.0V, f= 2440 MHz if nothing else is stated. All parameters are measuredon the CC2530-CC2591 EM reference design with a 50 Q2 loadReceive Sensitivity HGM 1 %PER, IEEE 802. 15.4[6] requires -85 dBm-988dBmReceive Sensitivity LGM1 PER, IEEE 802. 15.4 [6] requires -85 dBm-90.4dBmSaturationlEEE 802.15. 4 [6] requires-20 dBm10dBmWanted signal 3 db above the sensitivity levelIEEE 802.15.4 modulated interferer at ieee 802.15.4 channelsInterferer Rejection+5 MHz from wanted signal, IEEE 802. 15. 4 [6] requires 0 dBdB+10 MHz from wanted signal, IEEE 802. 15. 4 [6] requires 30 dB49dB+20 MHz from wanted signal wanted signal at- 82d BmdBdue to in the external lna and the offset in cc2530 the rssi readouts from cc2530CC2591 is different from rssi offset values for a standalone cc2530 design the offsetvalues are shown in table 4.4High Gain Mode79LoW Gain mode67Real rssi Register value-Rssl offsetISTRUMENTSPage 4 of 19SWRA308ATc=25C, Vdd=3.0V, f=2440 MHz if nothing else is stated All parameters are measuredon the CC2530-CC2591 EM reference design with a 50 Q2 load Radiated measurements aredone with the kit antennaRadiated Emissionwith TXPOWer Oxe5Conducted 2. RF (FCC restricted band)-462|dBmConducted 3. RF(FCC restricted band46.5 dBmComplies withFCC 15.247. SeeChapter 7 for moredetails about regulatoryRadiated 2.RF(FCC restricted band)42.2dBmrequirements andcomplianceIEEE 802.15.4[6]requires max.35%%Measured as defined by IEEE 802.15. 4 6TXPOWER OxE5. f= EEE 802.15. 4 channels13TXPOWER= OXD5. f= EEE 802.15.4 channelsTXPOWER= OXC5 f= EEE 802.15.4 channelsMax error∨ ectorTXPOWER OxB5 f= IEEE 802.15. 4 channelsMagnitude(EVM)TXPOWER OxA5. f= IEEE 802.15.4 channelsTXPOWER 0X95. f= IEEE 802. 15.4 channels643333%%%%%%%TXPOWER= 0x85. f= iEEE 802. 15.4 channelsTXPOWER =0x75 f= IEEE 802. 15.4 channels%TXPOWER= 065. f= iEEE 802. 15.4 channelsThe RF output power of the CC2530- CC2591 EM is controlled by the 7-bit value in theCC2530 TXPOWER register. Table 4.6 shows the typical output power and currentconsumption for the recommended power settings The results are given for Tc= 25 C, Vdd3.0V and f= 2440 MHz, and are measured on the cC2530-CC2591 EM reference designwith a 50 Q2 load. For recommendations for the remaining CC2530 registers, see Chapter 8 oruse the settings given by SmartRF StudioOXE520166OxD519149OxC18138OxB517127OxA5161150x95141000x8513940X75860x651079Note that the recommended power settings given in Table 4.6 are a subset of all the possibleTXPOWER register settings. However, using other settings than those recommended mightINSTRUMENTSPage 5 of 19SWRA308Aresult in suboptimal performance in areas like current consumption, EVM, and spuriousemissionTc=25C, Vdd=3.0V, f=2440 MHz if nothing else is stated All parameters are measuredon the CC2530-CC2591EM reference design with a 50 32 load2221-2V201918171611121314151617181920212223242526251510OxE5OxC5OxA50X850x65540-30-20-1001020304050607080ISTRUMENTSPage 6 of 19SWRA308A98Avg 3.6VAva 3vAvg 2V110111213141516171819202122232425261023.6V-1062V-110-40-30-20-100102030405060708070604020-Wanted signal at:-82 dBm10ISTRUMENTSPage 7 of 19SWRA308ACC2530-CC2591EM High Gain ModeC C2530-CC2591EM Low Gain Mode- CC2530EM40000-100110100908070-60-50-40-30-20-100The IEEE standard 802.15. 4 [8] requires the transmitted spectral power to be less than thelimits specified in table 4.7If-fc>3.5 MHz-20 dB-30 dBmThe results below are given for Tc=25 C, Vdd=3.0V and f= 2440 MHz, and are measuredon the CC2530-CC259 1EM reference design with a 50 Q loadIEEE absoluteChannel 182432.52435243752442524452447.5ISTRUMENTSPage 8 of 19SWRA308AOnly a few external components are required for the CC2530-CC2591 reference design. Atypical application circuit is shown below in Figure 5.1. Note that the application circuit figuredoes not show how the board layout should be done. The board layout will greatly influencethe RF performance of the CC2530-CC2591EM. TI provides a compact CC2530CC2591 EM reference design that it is highly recommended to follow. The layout, stack-upand schematic for the CC2591 need to be copied exactly to obtain good performance. Notethat the reference design also includes bill of materials with manufacturers and part numbersL102 L10=TI INF inductorVDD13cc2530LA 1RF PANTCC2591 RF NFNPA EN(P1 1)i工工I NA FNP:1HGM ENPO 7)T:1Proper power supply decoupling must be used for optimum performance. In Figure 5.1, onlythe decoupling components for the CC2591 are shown. This is because, in addition todecoupling, the parallel capacitors C11, C101, and C131 together with, L101, L102, TL11TL101 and TL131 also work as RF loads. These therefore ensure the optimal performancefrom the CC2591. C161 decouples the AvDD blAs power.The placement and size of the decoupling components, the power supply filtering and thePCB transmission lines are very important to achieve the best performance Details about theimportance of copying the CC2530-CC2591EM reference design exactly and potentialconsequences of changes are explained in chapter 6The RF input/output of CC2530 is high impedance and differential. The CC2591 includes abalun and a matching network in addition to the PA, LNa and RF switches which makes theinterface to the CC2530 seamless. Only a few components between the CC2530 andCC2591 necessary for RF matching For situation with extreme mismatch(VSWR 6: 1 till 12: 1out-of-band as shown in Figure 6.2) it is recommended to include all the components asshown in Figure 5.1ISTRUMENTSPage 9 of 19SWRA308ANote that the PCB transmission lines that connect the two devices also are part of the RFmatching. It is therefore important to copy the distance between the devices, the transmissionlines and the stack-up of the PCB according to the reference design to ensure optimumperformanceThe network between the CC2591 and the antenna(L111, C112, C111 C113 and L112matches the CC2591 to a 50 2 load and provides filtering to pass regulatory demands. C111also works as a dc-blockR151 is a bias resistor the bias resistor is used to set an accurate bias current for internaluse in the cc2591The TI reference design contains two antenna options. As default, the Sma connector isconnected to the output of CC2591 through a 0 Q2 resistor. This resistor can be soldered offand rotated 90 clockwise in order to connect to the PCB antenna, which is a planar invertedF antenna(PIFA). Note that all testing and characterization has been done using the SMAconnector. The PCB antenna has only been functionally tested by establishing a link betweentwo EMs. Please refer to the antenna selection guide [6] and the Inverted F antenna designnote [7 for further details on the antenna solutionsISTRUMENTSPage 10 of 19SWRA308A
- 2020-11-30下载
- 积分:1