硬件设置演示应用程序包含通 UART 发送和接收字符的任务。 一个任务发送的字符必须由另一个任务接收。 如果任何字符丢失或接收顺序错误, 则会标记错误情况。有两种常见方法 可以确保所发送的每个字符均能被收到。 第一种是 使用环回连接器,将发送引脚链接到接收引脚。 第二种是 将 UART 连接到回显服务器。 SP605 硬件使用 UART 到 USB 转换器,因而无法安装环回连接器。 因此, 在这种情况下,UART 必须连接到外部回显服务器。 在开发过程中, 可使用免费 (Windows) Comm Echo 实用程序实现此目的。 Comm Echo 可从 http://www.serialporttool.com/CommEcho.htm 下载。 下一节描述了所需的网络设置。 此演示应用程序使用内置于 SP605 硬件的 LED 和按钮, 因此无需其他硬件设置。 网络设置分配给 SP605 硬件的 IP 地址 由 configIP_ADDR0 到 configIP_ADDR3 之间的常量进行设置。这些常量 位于 FreeRTOSConfig.h 标头文件(位于 FreeRTOS/Demo/MicroBlaze_Spartan-6_EthernetLite/SDKProjects/RTOSDemo 目录中)底部。 定义 MAC 地址和网络掩码的常量位于同一 文件的同一位置。Web 浏览器和 SP605 硬件使用的 IP 地址必须 兼容。为此,可以将二者 IP 地址中的前三个八进制数 设置成相同的值。例如,如果运行 Web 浏览器的计算机所用 IP 地址是 192.168.0.1,则可以为 SP605 开发板指定 192.168.0.2 到 192.168.0.254 范围内的任何地址 (同一网络上已经存在的地址除外)。 分配给 SP605 的 MAC 地址 在其所连接的网络上必须具有唯一性。 将演示应用程序项目导入 SDK Eclipse 工作区要将 Xilinx 软件开发套件 (SDK) 项目导入现有或新的 Eclipse 工作区,请执行以下操作:
构建演示应用程序
使用 SDK 工具运行演示应用程序
预期行为
Web 服务器的使用提供的每个页面顶部都有一个菜单,内含指向其他各页面的链接。
提供的网页提供的第三个页面显示了一张大 JPG 图像。
FreeRTOS 内核配置和使用详细信息应用程序须提供的回调函数
实现中断服务程序 (ISR)实现 ISR 的函数是普通的 C 函数,但必须符合以下 原型。
void ISRFunctionName( void *ISRParameter ); ISR 的切换上下文ISR 通常会使任务解除阻塞 状态。 例如,在任务处理到达队列数据 的情况下。 队列为空时,没有要处理的数据,任务 可能会选择进入阻塞状态,以等待更多数据可用。 如果此时 ISR 将数据发送到队列, 则任务将自动解除阻止状态,因为队列不再为空。如果 ISR 导致任务解除阻塞状态,并且 解除阻塞状态的任务优先级高于 或等于当前执行的任务(被中断的任务),则 应在 ISR 中执行上下文切换, 以确保 ISR 直接返回到新解除阻塞的 更高优先级任务。 ISR 中断一个任务, 而返回到另一个任务。 宏 portYIELD_FROM_ISR() 是 taskYIELD() 的中断安全版本。 该宏 需要一个参数(如果不为零),该参数将间接导致 上下文切换。 以下是 portYIELD_FROM_ISR() 的使用示例, 该示例取自官方演示应用程序中的 serial. c 文件:
/* Note that this function is called from the UART interrupt handler, it is not itself an interrupt handler, so its prototype does not have to match that required by all interrupt handlers. */ static void prvRxHandler( void *pvUnused, UBaseType_t uxByteCount ) { signed char cRxedChar; BaseType_t xHigherPriorityTaskWoken = pdFALSE; /* While there are characters to process. */ while( XUartLite_IsReceiveEmpty( xUartLiteInstance.RegBaseAddress ) == pdFALSE ) { /* Obtain the next character. */ cRxedChar = XUartLite_ReadReg( xUartLiteInstance.RegBaseAddress, XUL_RX_FIFO_OFFSET); /* Place the received character in the received queue. If writing to the queue causes a task to leave the Blocked state, and the task has a priority equal to or above the priority of the interrupted task, then xHigherPriorityTaskWoken will automatically get set to pdTRUE inside the xQueueSendFromISR() function itself. */ xQueueSendFromISR( xRxedChars, &cRxedChar, &xHigherPriorityTaskWoken ); } /* Call portYIELD_FROM_ISR(), passing in xHigherPriorityTaskWoken. If xHigherPriorityTaskWoken was set to pdTRUE inside xQueueSendFromISR(), then calling portYIELD_FROM_ISR() here will cause the ISR to return directly to the newly unblocked task. If xHigherPriorityTaskWoken has retained its initialised value of pdFALSE, then calling portYIELD_FROM_ISR() here will have no effect. */ portYIELD_FROM_ISR( xHigherPriorityTaskWoken ); }
安装并启用 ISR以下函数分别用于安装、启用和禁用 中断(在中断控制器中)。 具有类似功能的 Xilinx BSP 库函数 不得使用。如何使用这些函数的示例包含在 vApplicationSetupTimerInterrupt() 的实现中,该实现位于 main-full.c 和 main-blinky.c 中。 另一个示例包含在 main-blinky.c 中 prvSetupHardware() 的实现中。
/* * Installs pxHandler as the interrupt handler for the peripheral specified by * the ucInterruptID parameter. * * ucInterruptID: * * The ID of the peripheral that will have pxHandler assigned as its interrupt * handler. Peripheral IDs are defined in the xparameters.h header file, which * is itself part of the BSP project. For example, in the official demo * application for this port, xparameters.h defines the following IDs for the * four possible interrupt sources: * * XPAR_INTC_0_UARTLITE_1_VEC_ID - for the UARTlite peripheral. * XPAR_INTC_0_TMRCTR_0_VEC_ID - for the AXI Timer 0 peripheral. * XPAR_INTC_0_EMACLITE_0_VEC_ID - for the Ethernet lite peripheral. * XPAR_INTC_0_GPIO_1_VEC_ID - for the button inputs. * * * pxHandler: * * A pointer to the interrupt handler function itself. This must be a void * function that takes a (void *) parameter. * * * pvCallBackRef: * * The parameter passed into the handler function. In many cases this will not * be used and can be NULL. Some times it is used to pass in a reference to * the peripheral instance variable, so it can be accessed from inside the * handler function. * * * pdPASS is returned if the function executes successfully. Any other value * being returned indicates that the function did not execute correctly. */ BaseType_t xPortInstallInterruptHandler( unsigned char ucInterruptID, XInterruptHandler pxHandler, void *pvCallBackRef ); /* * Enables the interrupt, within the interrupt controller, for the peripheral * specified by the ucInterruptID parameter. * * ucInterruptID: * * The ID of the peripheral that will have its interrupt enabled in the * interrupt controller. Peripheral IDs are defined in the xparameters.h header * file, which is itself part of the BSP project. For example, in the official * demo application for this port, xparameters.h defines the following IDs for * the four possible interrupt sources: * * XPAR_INTC_0_UARTLITE_1_VEC_ID - for the UARTlite peripheral. * XPAR_INTC_0_TMRCTR_0_VEC_ID - for the AXI Timer 0 peripheral. * XPAR_INTC_0_EMACLITE_0_VEC_ID - for the Ethernet lite peripheral. * XPAR_INTC_0_GPIO_1_VEC_ID - for the button inputs. * */ void vPortEnableInterrupt( unsigned char ucInterruptID ); /* * Disables the interrupt, within the interrupt controller, for the peripheral * specified by the ucInterruptID parameter. * * ucInterruptID: * * The ID of the peripheral that will have its interrupt disabled in the * interrupt controller. Peripheral IDs are defined in the xparameters.h header * file, which is itself part of the BSP project. For example, in the official * demo application for this port, xparameters.h defines the following IDs for * the four possible interrupt sources: * * XPAR_INTC_0_UARTLITE_1_VEC_ID - for the UARTlite peripheral. * XPAR_INTC_0_TMRCTR_0_VEC_ID - for the AXI Timer 0 peripheral. * XPAR_INTC_0_EMACLITE_0_VEC_ID - for the Ethernet lite peripheral. * XPAR_INTC_0_GPIO_1_VEC_ID - for the button inputs. * */ void vPortDisableInterrupt( unsigned char ucInterruptID ); 异常处理(仅适用于高级用户)要启用 FreeRTOS 异常处理,首先必须将 MicroBlaze 本身 配置为包含异常处理功能,其次 必须在 FreeRTOSConfig.h 中将 configINSTALL_EXCEPTION_HANDLERS 设置为 1。 将 configINSTALL_EXCEPTION_HANDLERS 设置为 1 会 导致 RTOS 内核消耗的代码和数据空间增加。提供以下函数来安装 FreeRTOS 异常处理程序, 并在发生异常时分别处理。 的功能 FreeRTOS 异常处理程序 本身的功能在 portmacro.h 中的函数原型上方的注释中进行了描述,复制如下: 在 main-full.c 和 main-blinky.c 中 都提供了 vApplicationExceptionRegisterDump() 的示例实现。
/* * vPortExceptionsInstallHandlers() is only available when the MicroBlaze * is configured to include exception functionality, and * configINSTALL_EXCEPTION_HANDLERS is set to 1 in FreeRTOSConfig.h. * * vPortExceptionsInstallHandlers() installs the FreeRTOS exception handler * for every possible exception cause. * * vPortExceptionsInstallHandlers() can be called explicitly from application * code. After that is done, the default FreeRTOS exception handler that will * have been installed can be replaced for any specific exception cause by using * the standard Xilinx library function microblaze_register_exception_handler(). * * If vPortExceptionsInstallHandlers() is not called explicitly by the * application, it will be called automatically by the RTOS kernel the first time * xPortInstallInterruptHandler() is called. At that time, any exception * handlers that may have already been installed will be replaced. * * See the description of vApplicationExceptionRegisterDump() for information * on the processing performed by the FreeRTOS exception handler. */ void vPortExceptionsInstallHandlers( void ); /* * The FreeRTOS exception handler fills an xPortRegisterDump structure (defined * in portmacro.h) with the MicroBlaze context, as it was at the time the * exception occurred. The exception handler then calls * vApplicationExceptionRegisterDump(), passing in a reference to the completed * xPortRegisterDump structure as its parameter. * * The FreeRTOS kernel provides its own implementation of * vApplicationExceptionRegisterDump(), but the RTOS kernel provided implementation * is declared as being 'weak'. The weak definition allows the application * writer to provide their own implementation, should they wish to use the * register dump information. For example, an implementation could be provided * that writes the register dump data to a display, or a UART port. */ void vApplicationExceptionRegisterDump( xPortRegisterDump *xRegisterDump ); RTOS 移植特定配置RTOS 内核和演示行为可使用 FreeRTOS/Demo/MicroBlaze_Spartan-6_EthernetLite/SDKProjects/RTOSDemo/FreeRTOSConfig.h 文件中包含的配置常量进行定制。 这些配置常量大多数用于所有 FreeRTOS 移植, 并在本网站的自定义页面 和《FreeRTOS 参考手册》中进行了说明。以下常量特定于此移植:
/* If configINSTALL_EXCEPTION_HANDLERS is set to 1, then the RTOS kernel will automatically install its own exception handlers before the RTOS kernel is started, if the application writer has not already caused them to be installed using the vPortExceptionsInstallHandlers() API function. vPortExceptionsInstallHandlers() is described on this web page. */ #define configINSTALL_EXCEPTION_HANDLERS 1 /* configINTERRUPT_CONTROLLER_TO_USE must be set to the ID of the interrupt controller that is going to be used directly by FreeRTOS itself. Most hardware designs will only include on interrupt controller, so can use the same setting as shown here. XPAR_INTC_SINGLE_DEVICE_ID is itself defined in the xparameters.h header file, which is part of the Xilinx BSP library project. */ #define configINTERRUPT_CONTROLLER_TO_USE XPAR_INTC_SINGLE_DEVICE_ID 内存分配Source/Portable/MemMang/heap_3.c 包含在 MicroBlaze 演示应用程序的 makefile 中, 以提供 RTOS 内核所需的内存分配。 请参阅 API 文档的内存管理部分, 获取完整信息。heap_3.c 使用 从 RTOS 调度程序锁定区中调用的标准 malloc() 和 free() 函数,从而保证线程安全。 总可用堆 大小是在位于 DemoMicroBlaze_Spartan-6_EthernetLiteSDKProjectsRTOSDemosrc 目录下的链接器脚本顶部设置的。
Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.
|