VxWorks学习笔记-Real-Time Multitasking

VxWorks 学习笔记

§ Real-Time Multitasking

1.Introduction

Real-Time

  • A system is described as being deterministic if its response time is predictable.

  • Deterministic response is the key to real-time performance.

单一任务系统

  • 缺点:1)各个构件无法按照不同的速率执行;2)没有优先级;3)无法抢占;

  • 优点:没有任务切换的开销。

VxWorks如何满足实时要求

  • 多任务

  • 执行速度快:1) 轻量级的任务,上下文切换快; 2)没有系统调用的开销

  • 运行的确定性:基于优先级的抢占式调度确保了高优先级任务的响应速度。

任务的状态

  • Ready

  • Delay: waiting for a mount of time to pass

  • Pend: waiting for an object event

  • Pend & Delay

  • Suspend

多任务内核

  • VxWorks中管理任务的是Wind Kernal

  • 使用TCB跟踪管理任务;

  • TCB数据结构定义:WIND_TCB

  • 获取TCB指针:函数taskTcb()

  • 对每一个PendEvent,有独立的Queue

上下文切换

  • 分为两种类型:SynchronousAsynchronous

  • Asynchronous切换是由ISR引起的任务切换

  • Synchronous需要保存的寄存器少,所以速度更快

  • ISR的优先级比任务高

优先级调度

  • 抢占式调度是基于优先级的,高优先级抢占低优先级的任务

  • 重新调度发生的时刻:1) Kernal calls2) Interrupts (e.g. System clock ticks)

  • 优先级的高低取决于任务计时的要求,而不是任务的重要性

Round-Robin 调度

  • 作用于相同优先级的任务

  • Round-robin scheduling is disabled by default. To allow equal priority tasks to preempt each other, time slicing must be turned on: kernelTimeSlice (ticks)

  • -> clockRate = sysClkRateGet( )

Performance Enhancements

  • All tasks reside in a common address space. 1) Makes intertask communication fast and easy. 2) Makes context switch faster (don’t need to save and restore virtual address contexts). 3) A deviant task can corrupt other tasks.

  • All tasks run in supervisor (privileged) mode. No system call overhead.

Multitasking Facilities

  • Message passing queues for intertask communication within a CPU

  • Network routines for intertask communication between CPU’s

  • Semaphores to protect data which is shared by tasks

  • Timers and other interrupts to trigger task execution

  • I/O system facilities to read/write data to hardware devices

2.任务基础

任务的组成

  • TCB

  • Stack:存储自动变量和函数参数

Creating a Task

  • Allocate memory for the stack and TCB from a memory pool.

  • Initialize the stack.

  • Initialize the TCB.

  • Put task into ready queue.

  • newTid = taskSpawn (“tMyTask”, 150, 0, 20000, myRoutine, arg1, arg2, 0, 0, 0, 0, 0, 0, 0, 0)

Task ID

  • A task id of zero refers to task making call (self).

  • 相关函数:taskIdSelf, taskIdListGet, taskIdVerify

Task Name

  • 相关函数:taskName, taskNameToId

Task Priority

  • Timing requirements rather than hazy ideas about task importance should govern priorities.

  • One can manipulate priorities dynamically with: taskPriorityGet (tid, &priority)taskPrioritySet (tid, priority)

Task Stack

  • Fixed size after creation.

  • The kernel reserves some space from the stack, making the stack space actually available slightly less than the stack space requested.

  • Each byte in a task’s stack is filled with 0xee when the task is created. The checkStack( ) function searches from the end of the stack for this value in order to find the maximum stack usage.

  • VxSim targets add 8000 bytes to the requested stack size, to deal with simulated interrupts, which are handled on the stack of the current task.

Task Option

  • taskOptionsGet

  • taskOptionsSet

Task Creation

  • During time critical code, task creation can be unacceptably time consuming.

  • To reduce creation time, a task can be spawned with the VX_NO_STACK_FILL option bit set.

  • Alternatively, spawn a task at system start-up which blocks immediately, and waits to be made ready when needed.

Task Deletion

  • 相关函数:taskDelete, exit

3.任务控制

Restart

  • 相关函数:taskRestart

  • 通常用于错误恢复

  • 一个任务重起自身时,是由任务tRestart完成

Suspend & Resume

  • 相关函数:taskSuspend, taskResume

Delay

  • 相关函数:taskDelay(ticks)

  • 延迟1/7 秒:taskDelay (sysClkRateGet( ) / 7)

  • sysClkRateGetGet the number of ticks per second of the system clock

Reentrancy and Task Variables

  • Use only stack variables in applications.

  • Protect the resource with a semaphore.

  • Use task variables to make the variable private to a task.

  • Task Variables cause a 32-bit value to be saved and restored on context switches, like a register.

Task Hooks

  • User-defined code can be executed on every context switch, at task creation, or at ask deletion: taskSwitchHookAdd ( ) , taskCreateHookAdd( ), taskDeleteHookAdd ( )

  • VxWorks uses a switch hook to implement task variables.

Task Information

  • -> ti

4.错误码的使用

  • 全局变量errno用来保存当前执行任务的错误状态;

  • 任务上下文切换时,errno会保存到任务的TCB中;

  • 底层函数根据情况设置errno,上层调用函数检查errno的值确定函数调用失败的原因;

  • 错误码格式:模块编码(16bits)+错误类型(16bits)

  • 由错误码获取描述信息:shell命令printErrno, 函数strerror( )

  • 定义用户自己的错误码;

5.系统任务

  • tUsrRoot

  • tLogTask

  • tExcTask

  • tWdbTask

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: 《VxWorks 7 实时网络开发指南》是一份详细介绍VxWorks 7实时网络开发的文档。VxWorks 7是一款实时操作系统,广泛应用于嵌入式系统中。该文档对于开发人员来说非常重要,因为它提供了详细的指导和实例,帮助开发人员了解VxWorks 7的实时网络编程和调试技术。 该文档首先介绍了VxWorks 7的基本概念和体系结构。它详细解释了实时网络的基本原理和特点,并介绍了VxWorks 7的网络协议栈和网络驱动程序。然后,文档介绍了如何在VxWorks 7中创建和配置网络连接,包括IP地址、子网掩码、网关等。此外,文档还介绍了如何使用VxWorks 7的网络API进行数据传输和通信。 在文档的后面部分,还介绍了VxWorks 7网络调试和故障排除的技术和工具。开发人员可以通过使用VxWorks 7的调试接口和命令,了解网络连接的状态和性能,并解决网络故障和性能问题。 总之,《VxWorks 7 实时网络开发指南》是一份非常有用的文档,帮助开发人员理解和应用VxWorks 7的实时网络开发技术。对于需要在VxWorks 7上进行实时网络开发的开发人员来说,这是一本必备的参考书。无论是初学者还是有经验的开发人员,都可以从中获得宝贵的知识和经验。 ### 回答2: vxworks_7_real_time_network.pdf 是一本关于VxWorks 7 实时网络的文件。VxWorks 7 是一个实时操作系统,广泛应用于嵌入式系统和网络设备中。这本文件描述了VxWorks 7 在实时网络领域的特点和功能。 该文件首先介绍了实时网络的基本概念和要求。实时网络是指具有快速、可靠、实时的数据传输能力的网络。实时网络要求能够保证数据的传输具有严格的时限和连续性,以满足实时系统的需求。 随后,文件详细介绍了VxWorks 7 的实时网络特性。VxWorks 7 提供了一套完整的实时网络协议栈,支持多种实时协议,如TCP/IP、UDP、以太网等。同时,VxWorks 7 还提供了灵活的网络配置和管理功能,可以满足不同应用场景的需求。 此外,文件还详细介绍了VxWorks 7 实时网络的性能优化和调优方法。通过合理配置网络参数、优化网络资源分配和调度策略,可以提高实时网络的性能和效率。 最后,文件还提供了一些在实践中的案例和实例,展示了VxWorks 7 实时网络在不同应用领域的应用场景和成功案例。这些案例包括工业控制、无线通信、智能交通等领域。 综上所述,vxworks_7_real_time_network.pdf 是一本介绍VxWorks 7 实时网络特点和功能的文件,它介绍了VxWorks 7 实时网络的基本概念、特性、性能优化方法,并提供了实践案例,对于研究和应用实时网络的人士具有重要的参考价值。 ### 回答3: vxworks_7_real_time_network.pdf是一份有关于VxWorks 7实时网络的文档。VxWorks是一种实时操作系统,主要用于嵌入式系统和网络设备。这个文档提供了关于VxWorks 7在实时网络方面的详细信息。 文档中首先介绍了VxWorks 7的概述和架构。它提供了一个完整的实时操作系统环境,能够满足各种应用的实时需求。然后,文档详细讲解了VxWorks 7实时网络的功能和特性。VxWorks 7提供了丰富的网络协议栈,支持各种通信协议,如TCP/IP、UDP、HTTP等。它还提供了高性能的网络传输机制,可实现实时数据的快速传输。 除此之外,这个文档还介绍了VxWorks 7的网络管理和安全功能。VxWorks 7提供了强大的网络管理工具,可实现对网络配置、监控、故障诊断等的管理。它还支持各种网络安全机制,如加密、认证等,保护系统免受网络攻击。 文档的最后部分讨论了VxWorks 7实时网络的应用场景。它可以广泛应用于工业自动化、智能交通、物联网等领域。无论是对实时性要求高的控制系统,还是需要快速、可靠通信的应用,VxWorks 7都能满足需求。 总之,vxworks_7_real_time_network.pdf是一份关于VxWorks 7实时网络的详细文档,介绍了其架构、功能、特性、管理和安全,以及应用场景。通过阅读这个文档,用户可以了解VxWorks 7在实时网络方面的能力和应用。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值