Zynq开发实践(SDK之FreeRTOS使用)

【 声明:版权所有,欢迎转载,请勿用于商业用途。 联系信箱:feixiaoxing @163.com】

        zynq即使作为裸机使用,其实也是非常方便的。之前我们开发tf卡的时候,sdk本身除了提供了底层的驱动之外,还准备了xliffs文件系统,也就是fatfs的变型版本。这就意味着如果tf卡插入到卡槽里面,我们就可以直接读写里面的文件了。当然,不仅仅是fs,zynq本身还移植好了rtos,即开源的freertos,使用上面还是非常方便的。今天就来看看freertos怎么使用,为后面的使用做好准备。

1、创建工程,准备block design

        这部分和之前创建工程一样,创建的时候选择020clg400-2。创建好了之后,添加block design,添加processor z7,然后就是删除三条线(clock、reset、gp0),最后就是添加串口、以及ddr3(选择16位)。

2、完成vivado工程,准备导出

        接下来就是“Generate output products”、“Create wrapper”,虽然这里没有用到pl,最好也养成习惯,单击“Generate bitstream”文件。最后就是导出工程,选择“include bitfile”,导出sdk即可。

3、打开sdk,准备开发

        这里打开sdk之后,开始准备创建hello world工程。唯一的区别就是,之前创建的是standalone工程,也就是逻辑程序、while-1程序,现在是rtos,这是需要注意的。

        单击好了之后,可以选择下一步,这里面有很多工程可以选择,主要就是hello world和一些带lwip的程序,

        中间因为block design设计的时候没有eth phy,所以这里的lwip还用不起来。所以,我们暂时可以先选择freertos版本的hello world工程。

4、freertos库在什么地方

        本身freertos没有放在应用工程里面,而是和xliffs一样,放在了对应的bsp工程里面。这部分可以在bsp里面好好找一下。这里观察发现,freertos被命名成了freertos10_xilinx_v1_2,中间的port移植都是官方已经做好了的,比如上下文切换、汇编的处理等等,这一点和xliffs很像。

5、main.c做了什么

        整个测试代码还是比较简单的。基本上代码读下来,就是创建了一个发送任务,然后创建了一个接收任务,再创建了queue用于通信。接着就是创建定时器、使能定时器,开始调度。等发送任务、接收任务运行了差不多10s之后,定时器回调触发,清除定时器,把两个任务kill掉,就是这么一个demo。main函数最后的for(;;),可以忽略,这是rtos永远不会到达的地方。

int main( void )
{
	const TickType_t x10seconds = pdMS_TO_TICKS( DELAY_10_SECONDS );

	xil_printf( "Hello from Freertos example main\r\n" );

	/* Create the two tasks.  The Tx task is given a lower priority than the
	Rx task, so the Rx task will leave the Blocked state and pre-empt the Tx
	task as soon as the Tx task places an item in the queue. */
	xTaskCreate( 	prvTxTask, 					/* The function that implements the task. */
					( const char * ) "Tx", 		/* Text name for the task, provided to assist debugging only. */
					configMINIMAL_STACK_SIZE, 	/* The stack allocated to the task. */
					NULL, 						/* The task parameter is not used, so set to NULL. */
					tskIDLE_PRIORITY,			/* The task runs at the idle priority. */
					&xTxTask );

	xTaskCreate( prvRxTask,
				 ( const char * ) "GB",
				 configMINIMAL_STACK_SIZE,
				 NULL,
				 tskIDLE_PRIORITY + 1,
				 &xRxTask );

	/* Create the queue used by the tasks.  The Rx task has a higher priority
	than the Tx task, so will preempt the Tx task and remove values from the
	queue as soon as the Tx task writes to the queue - therefore the queue can
	never have more than one item in it. */
	xQueue = xQueueCreate( 	1,						/* There is only one space in the queue. */
							sizeof( HWstring ) );	/* Each space in the queue is large enough to hold a uint32_t. */

	/* Check the queue was created. */
	configASSERT( xQueue );

	/* Create a timer with a timer expiry of 10 seconds. The timer would expire
	 after 10 seconds and the timer call back would get called. In the timer call back
	 checks are done to ensure that the tasks have been running properly till then.
	 The tasks are deleted in the timer call back and a message is printed to convey that
	 the example has run successfully.
	 The timer expiry is set to 10 seconds and the timer set to not auto reload. */
	xTimer = xTimerCreate( (const char *) "Timer",
							x10seconds,
							pdFALSE,
							(void *) TIMER_ID,
							vTimerCallback);
	/* Check the timer was created. */
	configASSERT( xTimer );

	/* start the timer with a block time of 0 ticks. This means as soon
	   as the schedule starts the timer will start running and will expire after
	   10 seconds */
	xTimerStart( xTimer, 0 );

	/* Start the tasks and timer running. */
	vTaskStartScheduler();

	/* If all is well, the scheduler will now be running, and the following line
	will never be reached.  If the following line does execute, then there was
	insufficient FreeRTOS heap memory available for the idle and/or timer tasks
	to be created.  See the memory management section on the FreeRTOS web site
	for more details. */
	for( ;; );
}

        最后,就是有兴趣的同学可以实际上板子验证下,毕竟自己分析一下流程,得到的东西更多。下面截图就是在定时器的函数里面添加断点时,函数回调和变量是个什么情况。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

嵌入式-老费

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值