📄 pwm.h
字号:
/***********************************************************************
* *
* File: pwm.h *
* *
* Purpose: Provides an API to play audio through the PWM with FIFO *
* SOPC Builder Component *
* *
* Author: N. Knight *
* Altera Corporation *
* Aug 2005 *
**********************************************************************/
#ifndef _PWM_H_
#define _PWM_H_
#include "alt_types.h"
/*
* Clock rate of the PWM. Important for calculating sample rates.
* Can be independent of the system clock rate
*/
# define PWM_CLOCK_RATE 112500000 //112.500000 MHz
//#define PWM_CLOCK_RATE 128571429 //128.571429 MHz
//#define PWM_CLOCK_RATE 133332000 //133.332000 MHz
//#define PWM_CLOCK_RATE 150000000 //150.000000 MHz
/* Register map of PWM with FIFO peripheral */
#define PWM_CONTROL_OFFSET 0x0
#define PWM_FIFO_USED_OFFSET 0x4
#define PWM_PERIOD_OFFSET 0x8
#define PWM_DATA_OFFSET 0xC
/* PWM control register values */
#define PWM_STOP 0
#define PWM_GO 1
#define PWM_RESET 2
/* Return values */
#define SUCCESS 0
#define FAIL -1
/* Sets the sampling rate for playback... */
void PWM_SetSamplingRate( alt_u32 new_sample_rate, alt_u32 pwm_base_addr );
/* Plays a given number of samples */
int PWM_PlaySamples( int *left, int *right, alt_u32 num_samples,
alt_u32 sample_period, alt_u32 fifo_size,
alt_u32 pwm_base_addr );
/* Scales a sample for PWM */
int PWM_ScaleSample( int sample, int sampling_period );
/* Stops the playing of samples */
void PWM_Stop( alt_u32 pwm_base_addr );
/* Starts the playing of samples */
void PWM_Start( alt_u32 pwm_base_addr );
/* Reset the PWM, then return it to stopped state */
void PWM_ResetPWM( alt_u32 pwm_base_addr );
#endif /* _PWM_H_ */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -