RTCSD_第二次作业_李佳杰

RTCSD 第二次作业 李佳杰


一、准备工作

将项目从老师的仓库Fork到自己的仓库,并clone:

cd ~/work
git clone https://github.com/Is/STM32F429_Discovery_FreeRTOS_9.git

安装QEMU:

cd ~/work
tar xvf gnuarmeclipse-qemu-debian64-2.8.0-201612271623-dev.tgz
chmod -R -w ./qemu
export PATH=~/work/qemu/2.8.0-201612271623-dev/bin/:$PATH

安装GDB:

sudo apt-get install gdb-arm-none-eabi

二、例程编译

在Demo1目录下make,生成elf文件,并运行qemu.sh脚本,结果如下:

./qemu.sh

1240632-20170930114037325-1135614336.png

1240632-20170930114048715-1441529719.png

并运行GDB进行调试,运行qemu_gdb.sh,并打开另一个窗口运行GDB,并调试

arm-none-eabi-gdb


(gdb)target remote localhost:1234
(gdb)continue

执行效果如下:
1240632-20170930114005012-1485928270.png


三、编程作业

1.Sender_Task
每2ms向队列发送一个数字,从1开始依次递增到10000,然后在重新从1开始发送,并保存发送的所有数据的累加值
/**
 * Sender_Task:Send data
 */
void Sender_Task(void *pvParameters)
{
  

    while (1) 
    {
        send_num++;
        xQueueSend(xQueue, &send_num, (TickType_t)0);
        send_sum += send_num;
        if (send_num == 10000)
        {
            send_num = 0;
        }
        /*
        Delay for a period of time. vTaskDelay() places the task into
        the Blocked state until the period has expired.
        The delay period is spacified in 'ticks'. We can convert
        yhis in milisecond with the constant portTICK_RATE_MS.
        */
        vTaskDelay(2 / portTICK_RATE_MS);
  }
}
2.Receiver_Task
每1000ms接受队列里的所有数据,并计算其累加值,并保存
此时设计变量real_send_sum保存当队列中数据接受完成时,Sender_Task发送的数据的总和
/**
 * Receiver_Task: Receive data
 */
void Receiver_Task(void *pvParameters)
{

    while (1) 
    {
        while(xQueueReceive(xQueue, (void *)&receive_num, (TickType_t)0) == pdTRUE)
        {
            receive_sum += receive_num;
        }
        real_send_sum = send_sum;   //save the data sum sended when the data is received
        /*
        Delay for a period of time. vTaskDelay() places the task into
        the Blocked state until the period has expired.
        The delay period is spacified in 'ticks'. We can convert
        yhis in milisecond with the constant portTICK_RATE_MS.
        */
        vTaskDelay(1000 / portTICK_RATE_MS);
  }
}

3.Monitor_Task
每10000ms检查Sender_Task发送的数据是否被Receiver_Task正确接受,若正确接受这绿灯常亮,否则红灯常亮
由于Monitor运行的时候,此时Sender发送的数据有一部分仍然在队列中,尚未被真正接受,所以利用在Receiver_Task中保存的变量real_send_num(存储当队列中数据接受完成时发送的数据的总和)和总共接受的数据总和receiver_sum进行比较,若相等,则数据正确被接受和处理,否则数据的接受处理出错
/**
 * Monitor_Task: Check if Receiver_Task have received the right datas from the Sender_Task
 */
void Monitor_Task(void *pvParameters)
{

    Green_LED_On();
    Red_LED_Off();
    while (1) 
    {
        if(real_send_sum != receive_sum)
        {
            Green_LED_Off();
            Red_LED_On();
        }
        else
        {
            Green_LED_On();
            Red_LED_Off();
        }

        /*
        Delay for a period of time. vTaskDelay() places the task into
        the Blocked state until the period has expired.
        The delay period is spacified in 'ticks'. We can convert
        yhis in milisecond with the constant portTICK_RATE_MS.
        */
        vTaskDelay(10000 / portTICK_RATE_MS);
  }
}

四、gdb调试验证

在Monitor_Task内打断点,查看此时接受到的数据receive_sum,send_sum,real_send_sum的值,可以看到receiver_sum和real_send_sum相等,但与send_sum不等,这是因为Sender_Task发送的数据一部分已经被Receiver_Task正确接受和处理,还有一部分在队列里面等待下次调用Receiver_Task时进行处理,此时可认为已经发送的数据被正确的接受,则绿灯常亮

如下图
1240632-20170930114113247-1169453953.png

1240632-20170930114141825-1133181803.png

github链接(https://github.com/IsEleven/STM32F429_Discovery_FreeRTOS_9.git)

转载于:https://www.cnblogs.com/iseleven/p/7614354.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值