完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
作为一个普遍的问题,是否有一个简单的方法启动子程序,然后让它运行在后台?没有操作系统或代码臃肿。我怀疑这是直接可能的,但是某种方式的编码会有这样的感觉。RunnIn背景(计算);----- &,当计算完成时,访问ISR。可能是所谓的“共同例程”是答案,我不确定。
以上来自于百度翻译 以下为原文 As a general question - Is there a simple way to start a subroutine, then leave it running in the backgound? No operating system or code bloat. I doubt it is possible directly, but some way of coding that feels like this would do. RUN_IN_BACKGROUND(calculation); ----->Trip an ISR when 'calculation' is done. It might be that so-called 'co-routines' are the answer, I'm not sure. |
|
相关推荐
12个回答
|
|
我认为使用标准的C例程和上下文保存是不安全的,这可能使它们不可重入:但是如果你编写或复制了所有相关的空间…那行得通。
以上来自于百度翻译 以下为原文 I'd say it not safe using standard C routines and context saving, which maye make them not-reentrant: but if you write, or duplicate, all the relevant space... that will work. |
|
|
|
当你在一个非实时操作系统中说“背景”时,我不确定你的意思,那么通常的代码方式是使用一个“超级循环”,比如这个方法,定时器和串行端口触发ISRS,它收集一些数据,然后设置一个标志,表示有数据准备处理。SerialIO进程和TimeRePoad函数检查标志并执行所需的处理。如果在while(1)循环中的一个函数的处理需要花费太长的时间,那么其他函数将落后,那么您可以用状态机将其拆分,转换为
以上来自于百度翻译 以下为原文 I am not sure what you mean when you say "background" in a non-RTOS system, then normal way to code is to use a "superloop" something like void main(void) { timer_init(); serial_init(); while(1) { serial_process(); timer_process(); } } In this method, the timer and serial ports trigger ISRs, which gather some data then set a flag to say there is data ready for processing. The serial_process and timer_process functions check the flag and perform the required processing. If the processing for one of the functions in the while(1) loop would take too long, so the other functions would fall behind, then you can split it up with a state machine, changing something_process() { take_a_long_time1(); take_a_long_time2(); take_a_long_time3(); } to something_process() { switch(state) { case FIRST: take_a_long_time1(); state = SECOND; break; case SECOND: take_a_long_time2(); state = THIRD; break; case THIRD: take_a_long_time3(); state = DONE; break; } } |
|
|
|
感谢你们两个-这是对第一个响应的回答(只看到第二个回复)是的,编译器的重新入侵者/函数代码复制可能是个问题。一些MAL代码(例如图形)将主线代码转换成子程序…子程序具有静态局部变量,并作为状态机工作。子程序通过“策略间隔”的“让步”控制来协同工作,即:子例程发出一个“返回(当前状态)”。主线代码一直调用子程序,直到它看起来是一个“完成”的值。也许,如果一个定时器ISR自动调用子程序,这将是我想要的部分:空主(空){…RealBaseTebug任务(慢任务);…}//MimTimeReSISR {…如果(0)!{ReuMeBeBeLead TaskSo)} //任务完成{//调用用户定义的“回调函数”(*pFuleSyFrimePosiple Posiple)();“} //TimeRo.IsR.R.R./TimeR.IsR.R.R./TimeR.I.”但是,“大奖”是找到一种“预编译”预编译函数(例如,Sqt())的方法;我想这可能是不可能的。
以上来自于百度翻译 以下为原文 Thanks to both of you - this is a reply to the first response (only just seen second reply) Yes, re-entrancy/function code duplication by the compiler can be a problem. Some of the MAL code (graphics for instance) moves main-line code into a subroutine... The subroutine has static local variables, and works as a state machine. The subroutine co-operates by 'yielding' control at 'strategic intervals'. That is: The sub-routine issues a 'return(current_state)'. Main-line code keeps calling the subroutine until it seems a 'finished' value. Maybe, if a timer ISR calls the subroutine automatically, that would be partly what I'd like: void main(void) { ... BeginBackgroundTask(Slow_Task); ... }//main Timer_ISR { ... if(0 != Background_Result) { ResumeBackgroundTask() } else //Task completed { //Invoke a user-defined "callback funtion" (*pfUser_FunctionPointer)(); } }//Timer_ISR However, the 'Big Prize' is to find a way of 'chopping up' a pre-compiled funtion (eg sqrt()); I guess that might not be possible. |
|
|
|
这就是RTOS可以为你或至少支持抢先多任务的人所做的事情。但是,这听起来好像你不能忍受任务切换开销。
以上来自于百度翻译 以下为原文 That's what an RTOS can do for you or at least the ones that support preemptive multitasking. However, it doesn't sound like you can live with the task switching overhead. |
|
|
|
假设我有一个编译器函数列表来调用a=Sin(x);A+= COS(a);a=Sin(a);…Etjo可以将RTOS包打包成一个可中断的任务吗?它必须跳入调用堆栈等,以便恢复任务上下文。这可以为2任务系统以简单的方式完成吗?比如XC16有什么特别的吗?
以上来自于百度翻译 以下为原文 Say I have a list of compiler functions to call a = sin(x); a += cos(a); a -= sin(a); ...etc How can an RTOS package all that into an interruptable task? It must dive into the call stack and so forth in order to restore task context. Can this be done in a simple way for a 2 task system? Something specific to XC16 for instance? |
|
|
|
每个任务都有自己的堆栈,整个执行上下文在任务切换(因此开销)上被保存/恢复。简单的是相对的,有一个学习曲线。有几个RTOS产品与XC16一起工作。FreeRTOS是我最喜欢的价格(名字的线索),但其他的是可用的。
以上来自于百度翻译 以下为原文 Each task has its own stack and the whole execution context is saved/restored on task switching (hence the overhead). Simple is relative, there is a learning curve. There are several RTOS products which work with XC16. FreeRTOS is my favourite price (clue's in the name) but others are available. |
|
|
|
我想知道FreeRTOS是否会添加太多不必要的特性,因此复杂性和大小。我很想避免一个操作系统(我想)“额外的特性”,这将使它更难理解(即使我不使用它们)。基本上,有一个“自由、轻量级、难以置信的简单任务切换器”吗?或者,这可以用一小部分函数手工完成吗?
以上来自于百度翻译 以下为原文 I'm wondering if FreeRTOS would add too many unwanted features, hence complexity and size. I'm keen to avoid an operating system with (I guess) "extra features" which will make understanding it harder (even if I do not use them). Is the bulk of FreeRTOS code dedicated to task switching? Basically, is there a "free, very lightweight and unbelievably simple task-switcher" ? Or, can this be done "by hand" with a small file of functions? |
|
|
|
很可能。但是,您可以关闭配置文件中的大部分特性,因此可以实现一个非常基本的任务切换器。我明白您的意思,所有的特性都在文档中,即使您不必使用它们或启用它们。如果你关闭所有其他功能,那么我想是的,但是切换器大概不到代码的10%,剩下的是信号量、计时器、消息队列等。这是我所使用的所有RTOS的真实情况。人们已经推出了他们自己的任务切换器,但绝不是一个简单的工作。
以上来自于百度翻译 以下为原文 Quite possibly. You can, however, turn off most of the features in the configuration file, so a pretty basic task switcher can be achieved. I see what you mean, all the features are in the documentation even though you don't have to use them or enable them. Not really. If you turn all the other features off, then I suppose yes, but the switcher is probably less than 10% of the code and the rest is semaphores, timers, message queues etc. This is pretty much true of all the RTOS I have used. Not that I'm aware of. People have rolled their own task switchers, but it is by no means a simple job. |
|
|
|
它不是在单线程MPU的后台,它只是由于速度而出现的。当前运行的程序在ISR上被冻结。这个芯片有一个DSP,您可以在一个指令中执行Sin和COS和快速绘制线。创建一个Q15 COS表,并且很容易完成x,y QuANTANTS。
以上来自于百度翻译 以下为原文 It's not in the background on a single threaded mpu. It only appears that way due to the speed. The current running program is frozen on an isr. This chip has a DSP and you can do sin and cos in one instruction and fast line drawing. Create a Q15 cos table and it's fairly ease to do the x,y quantrants |
|
|
|
为了令人信服,RTOS的上下文切换时间对力的威力是无关紧要的。当一秒钟可以做1100万个上下文切换时,除非你正在运行一个平滑的手工拨号ASM代码。E.HTML.你可能想看看QKEntHyp://www. CuasalSt.To//IT现在是免费的。相当快
以上来自于百度翻译 以下为原文 To be trueful, the context switching time of a RTOS is insignificant to the power of the force. when one can do 11 million context switches in a second, the it really isn't an issue unless you are running flat out hand tweeked asm code. data here. http://www.avix-rt.com/Products/Performance/performance.html you might want to look at qKernel http://www.quasarsoft.com/ it is now free. pretty darn fast |
|
|
|
你可以让大的慢程序在主程序中运行,并从中断中做其他事情。如果你计算好时机,就不会有问题了。当然,你不需要RTOS。
以上来自于百度翻译 以下为原文 You can let the big slow routines run in the main, and do everything else from interrupts. If you calculate your timing well, it won't be a problem. You certainly do not need RTOS for this. |
|
|
|
另一种方法是回顾你真正想要做的功能。你真的需要浮动/双精度(或其他)吗?如果范围/域合适,你可以使用查找表吗?可以使用定点值(通常比浮点处理更快)吗?苏珊
以上来自于百度翻译 以下为原文 The other approach is to review what you really want to do with the functions. Do you really need floating/double precision (or whatever)? Can you use look-up tables if the range/domain is appropriate? Can you use fixed-point values (which are typically faster to process than floating point)? Susan |
|
|
|
只有小组成员才能发言,加入小组>>
5248 浏览 9 评论
2036 浏览 8 评论
1956 浏览 10 评论
请问是否能把一个ADC值转换成两个字节用来设置PWM占空比?
3217 浏览 3 评论
请问电源和晶体值之间有什么关系吗?PIC在正常条件下运行4MHz需要多少电压?
2264 浏览 5 评论
786浏览 1评论
677浏览 1评论
有偿咨询,关于MPLAB X IPE烧录PIC32MX所遇到的问题
603浏览 1评论
PIC Kit3出现目标设备ID(00000000)与预期的设备ID(02c20000)不匹配。是什么原因
684浏览 0评论
581浏览 0评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-27 03:41 , Processed in 1.444284 second(s), Total 100, Slave 84 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号