一、声明
自己的代码是10,示例代码:temp:13
以后移植代码可以移植temp13里面的代码,因为有些底层相比于之前是改变了的
二、基础知识
(1)首先要创建一个队列
队列的创建有两种方法:动态分配内存、静态分配内存
- 动态分配内存:xQueueCreate,队列的内存在函数内部动态分配
函数原型如下:
cs
QueueHandle_t xQueueCreate( UBaseType_t uxQueueLength, UBaseType_t uxItemSize );

我们可以在 gamel_task();这个函数里面创建队列,用动态分配内存
首先我们要定义一个全局变量

cs
QueueHandle_t g_xQueuePlatform; /* 挡球板队列 */
xQueueCreate(数据,每个数据的大小);

cs
/* 创建队列:平台任务从里面读到红外数据,... */
g_xQueuePlatform = xQueueCreate(10, sizeof(struct input_data));
数据我们可以随便写一个,每个数据的大小要计算一下
在game1.c的文件夹下方找到typedefs.h这个文件,然后在里面定义一个结构体
cs
struct input_data {
uint32_t dev;
uint32_t val
};

(2)在红外中断里面写队列
要修改driver_ir_receiver.c里面的函数
首先需要添加这三个头文件,然后声明这个变量

cs
#include "FreeRTOS.h"
#include "queue.h"
#include "typedefs.h"
cs
extern QueueHandle_t g_xQueuePlatform; /* 挡球板队列 */
可以把数据写到队列头部,也可以写到尾部,这些函数有两个版本:在任务中使用、在ISR中使用。函数原型如下:
放在中断里面要使用xQueueSendToBack();这个函数
cs
/* 等同于xQueueSendToBack
* 往队列尾部写入数据,如果没有空间,阻塞时间为xTicksToWait
*/
BaseType_t xQueueSend(
QueueHandle_t xQueue,
const void *pvItemToQueue,
TickType_t xTicksToWait
);
/*
* 往队列尾部写入数据,如果没有空间,阻塞时间为xTicksToWait
*/
BaseType_t xQueueSendToBack(
QueueHandle_t xQueue,
const void *pvItemToQueue,
TickType_t xTicksToWait
);
/*
* 往队列尾部写入数据,此函数可以在中断函数中使用,不可阻塞
*/
修改中断里面的函数的时候,首先要定义一下这个变量

在左边的框图里面可以很快就找到这个需要修改的函数,再在里面添加上需要写的代码
cs
struct input_data idata;
cs
/* 写队列 */
idata.dev = 0;
idata.val = 0;
xQueueSendToBackFromISR(g_xQueuePlatform, &idata, NULL);
然后就再在这个函数里面修改一下,首先还是需要先定义一个变量

cs
struct input_data idata;
再修改一下下面的代码
cs
idata.dev = datas[0];
idata.val = datas[2];
xQueueSendToBackFromISR(g_xQueuePlatform, &idata, NULL);
(3)在挡球板的任务里面读队列
使用 xQueueReceive() 函数读队列,读到一个数据后,队列中该数据会被移除。这个函数有两个版本:在任务中使用、在ISR中使用。函数原型如下:
cs
BaseType_t xQueueReceive( QueueHandle_t xQueue,
void * const pvBuffer,
TickType_t xTicksToWait );
BaseType_t xQueueReceiveFromISR(
QueueHandle_t xQueue,
void *pvBuffer,
BaseType_t *pxTaskWoken
);

xQueueReceive(读哪个队列,bufer,portMAX_DELAY) 返回值是pdPASS
记得还要创建一个bufer
cs
struct input_data idata;
cs
if (pdPASS == xQueueReceive(g_xQueuePlatform, &idata, portMAX_DELAY))
cs
data = idata.val;


三、遇见的问题
(1)在keil文件里面找不到tim.c的文件,在SYS里面勾选TIM4是不会生成tim.c文件的,要使用TIM1 2 3这样 才能够在Keil里面生成tim.c的文件
(2)在添加开源项目的代码进去之后lcd的代码报错,是因为开源项目使用的lcd新增了代码,所以要移植开源项目里面的lcd代码进去,这样才不会出现问题
四、补充知识点

有几行就代表有几个八行,0x60 0110 0000 后面的四个是低四位 所以放在上面,所以上面的四个像素点就灭掉,11就代表亮 所以下面四个像素点,有两个像素点会亮
