FPGA休眠代码分析

void core_sleep(unsigned long int sleep_time)
{
	#define ISE_sleepMode()  asm volatile (	"mbar 16\n\t")
	#include "xtmrctr.h"
	extern XTmrCtr xTickTimerInstance;
//	static unsigned char sleep_flag = 0;
	XTmrCtr_Stop( &xTickTimerInstance, 0);
	vPortDisableInterrupt( XPAR_INTC_0_TMRCTR_0_VEC_ID );
	unsigned long ulCounterValue ;

	ulCounterValue = ( ( sleep_time) - 1UL );

	XTmrCtr_SetResetValue( &xTickTimerInstance, 0, ulCounterValue );
	XTmrCtr_Start( &xTickTimerInstance, 0 );
	vPortEnableInterrupt( XPAR_INTC_0_TMRCTR_0_VEC_ID );
	ISE_sleepMode();

	XTmrCtr_Stop( &xTickTimerInstance, 0);
	vPortDisableInterrupt( XPAR_INTC_0_TMRCTR_0_VEC_ID );
	ulCounterValue = ( ( XPAR_TMRCTR_0_CLOCK_FREQ_HZ/configTICK_RATE_HZ) - 1UL );
	XTmrCtr_SetResetValue( &xTickTimerInstance, 0, ulCounterValue );
	vPortEnableInterrupt( XPAR_INTC_0_TMRCTR_0_VEC_ID );
	XTmrCtr_Start( &xTickTimerInstance, 0 );
}

1、上述代码中,有两种操作, 定时器和SleepMode。刚开始自己也不清楚sleep mode 和定时器有啥关系?但是,你想这样一种场景,如果想让CPU进入低功耗模式一段时间后,自动醒来,怎么办?—— 靠定时器中断唤醒!

所以,事情变得简单了,在合适的时候进入休眠函数 —> 函数中配置定时器的ResetValue —> 开启定时器的中断 —> 进入休眠模式 —> 定时器中断将休眠唤醒 —> 重新配置定时器 —> 进入正常工作模式;

上述流程会循环执行!

2、还有几个问题需要解决
1)什么时候进入休眠函数?
2)休眠函数可以做什么?除了中断,其它模块完全不工作吗?
3)休眠可以被打断吗?对于休眠固定时间的场景,被打断后重新计时休眠还是继续休眠剩余的时间?

3、参考资料
1)关于Sleep Mode

Sleep Mode
Sleep mode is defined at the system level to include the APU in standby mode and multiple controllers being held in reset without a clock.
Going into sleep mode can greatly reduce power consumption. In sleep mode, most function clock groups are turned off or powered off. The only required active devices are one CPU, the snoop control unit (SCU), and a wake-up device. Ideally, the only devices causing dynamic power consumption should be the SCU and the wake-up peripheral device. The wake-up device can be UART, GPIO, or any device that can generate an interrupt.
If the wake-up device is an AXI bus master, which can start transactions targeting the DRAM,additional limitations apply. Because the whole interconnect and the DDR memory are in low power modes and inaccessible, it must be assured that the CPU goes through the full wake-up process before any transactions to the DRAM take place. This guarantees that potential transactions targeting the DRAM are served correctly.

文中提到进入休眠模式可以大大降低功耗, 在睡眠模式下,大多数功能时钟组均已关闭。 唯一需要的活动设备是一个CPU,侦听控制单元(SCU)和唤醒设备。 理想情况下,引起动态功耗的唯一设备应该是SCU和唤醒外围设备。 唤醒设备可以是UART,GPIO或任何可以产生中断的设备。

2)关于Wake-up

Setup Wake-up Events
Every interrupt signaled to the PS can be used as a wake-up event. To make this happen, the wanted interrupt must be enabled in the peripheral and the GIC. A wake-up device must be able to generate the interrupt in sleep mode, which means, that its clocks might not be gated off. See GPIO as Wake-up Event, page 389 for more information.
Refer to the respective chapter for information about available interrupts and how to configure the peripherals to generate them.

能够通知PS端的每个中断都可以用作唤醒事件。 为此,必须在外围设备和GIC中启用所需的中断。 唤醒设备必须能够在睡眠模式下产生中断,这意味着其时钟可能不会被关闭。

3)AXI总线
AXI (Advanced eXtensible Interface) 本是由ARM公司提出的一种总线协议, Xilinx从 6 系列的 FPGA 开始对 AXI 总线提供支持,目前使用 AXI4 版本。

ZYNQ有三种AXI总线:

(A)AXI4:(For high-performance memory-mapped requirements.)主要面向高性能地址映射通信的需求,是面向地址映射的接口,允许最大256轮的数据突发传输;

(B)AXI4-Lite:(For simple, low-throughput memory-mapped communication )是一个轻量级的地址映射单次传输接口,占用很少的逻辑单元。

(C)AXI4-Stream:(For high-speed streaming data.)面向高速流数据传输;去掉了地址项,允许无限制的数据突发传输规模。

4)asm volatile ( “mbar 16\n\t”)

asm volatile(“hlt”);

"asm"表示后面的代码为内嵌汇编,"asm"是"asm"的别名。"volatile"表示编译器不要优化代码,后面的指令 保留原样,"volatile"是它的别名。括号里面是汇编指令。

4、参考博文

MicroBlaze:串口、定时器中断的学习与测试实验
https://blog.csdn.net/mmphhh/article/details/117373413

Linux内核系列—C语言中内嵌汇编 asm volatile,asm__volatile_
https://www.cnblogs.com/sky-heaven/p/5283229.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值