学习环境
(1)开发板
淘宝“开源骚客”矿板,老板人很nice,有问必答,推荐一下。
(2)Vitis版本,V2019.2
(3)Vivado版本,V2019.2
学习方法
参见“开源骚客系列视频”,如下链接:
【开源骚客】ZYNQ 矿板开发教程-低成本开发板学习ZYNQhttps://www.bilibili.com/video/BV1ip4y1v7eC?spm_id_from=333.999.0.0
Helloworld版本
我写的Helloworld版本在原官方Helloworld版本的基础上进行了扩充,主要对C语言的主要语法进行了测试。
主程序如下:test
#include <stdio.h>
#include "platform.h"
#include "xil_printf.h"
#include "test_function.h"
int main()
{
init_platform();
//string
printf("Hello 2249\n\r");
//int
int a = 1;
int b = 2;
printf("%d\n\r",a+b);
//if-else
int c = 3;
int d = 4;
if(c > d)
{
printf("max 3 4 is %d\n\r",c);
}
else
{
printf("max 3 4 is %d\n\r",d);
}
//while
int e = 5;
while(e > 0)
{
printf("e is %d\n\r",e);
e--;
}
//for
int f = 0;
for(f = 0; f < 8; f++)
{
printf("f is %d\n\r",f);
}
//switch-case
int g = 5;
switch(g)
{
case 1:
printf("g is %d\n\r",1);
break;
case 2:
printf("g is %d\n\r",2);
break;
case 3:
printf("g is %d\n\r",3);
default:
printf("g is %d\n\r",0);
break;
}
//function
int h = 12;
int i = 13;
printf("max 4566 g h is %d\n\r", maxab(h,i));
cleanup_platform();
return 0;
}
test_function.h内容如下所示:
/*
* test_function.h
*
* Created on: 2022年2月27日
* Author: a
*/
#ifndef SRC_TEST_FUNCTION_H_
#define SRC_TEST_FUNCTION_H_
int maxab(int a, int b);
#endif /* SRC_TEST_FUNCTION_H_ */
test_function.c内容如下所示:
/*
* test_function.c
*
* Created on: 2022年2月27日
* Author: a
*/
#include "test_function.h"
int maxab(int a, int b)
{
return a > b ? (a) : (b);
}
输出内容如下所示:
[09:28:08.873] Hello 2249
[09:28:08.873]
3
[09:28:09.315]
[09:28:10.097]
max 3 4 is 4
[09:28:10.100]
[09:28:10.970]
e is 5
[09:28:10.970]
e is 4
[09:28:11.442]
[09:28:11.851]
e is 3
[09:28:11.851]
e is 2
[09:28:12.272]
[09:28:12.683]
e is 1
[09:28:12.683]
[09:28:13.437]
f is 0
[09:28:13.437]
f is 1
[09:28:13.784]
[09:28:14.128]
f is 2
[09:28:14.128]
f is 3
[09:28:14.488]
[09:28:14.805]
f is 4
[09:28:14.805]
f is 5
[09:28:15.166]
[09:28:15.529]
f is 6
[09:28:15.529]
[09:28:16.063]
f is 7
[09:28:16.063]
[09:28:16.721]
g is 0
[09:28:16.721]
[09:28:18.999]
max 4566 g h is 13