37 #include <sys/types.h> 46 volatile unsigned int *gpio, *pwm, *clk;
63 mem_fd = open(
"/dev/mem", O_RDWR | O_SYNC);
67 debug(
"[%s] Can't open /dev/mem. Are you root?\n", __func__);
83 static volatile unsigned int*
84 map_register (
int mem_fd,
unsigned int addr)
90 if ( (mem = malloc(BLOCK_SIZE + (PAGE_SIZE - 1))) == NULL )
92 debug(
"[%s] Can't allocate memory.\n", __func__);
97 if ( (
unsigned long) mem % PAGE_SIZE )
99 mem += PAGE_SIZE - ((
unsigned long) mem % PAGE_SIZE);
103 map = (
unsigned char *) mmap ((caddr_t) mem,
104 BLOCK_SIZE, PROT_READ | PROT_WRITE,
105 MAP_SHARED | MAP_FIXED, mem_fd, addr);
107 if ( (
long) map < 0 )
109 debug(
"[%s] Can't mmap memory.\n", __func__);
112 return (
volatile unsigned int*) map;
128 mem_fd = open_memory();
131 debug(
"[%s] Can't open /dev/mem.\n", __func__);
136 gpio = map_register(mem_fd, GPIO_BASE);
137 clk = map_register(mem_fd, CLOCK_BASE);
138 pwm = map_register(mem_fd, PWM_BASE);
148 PWMCLK_DIV = 0x5A000000 | (32 << 12);
149 PWMCLK_CNTL = 0x5A000011;
158 PWM0_RANGE = PWM_MAX;
161 PWM_CONTROL = PWM0_ENABLE;
198 if ( value > PWM_MAX )
void pwm_mode(unsigned int mode)
Sets mode for the PWM peripheral.
int pwm_init()
Initialises the PWM peripheral.
void pwm_release()
Releases the PWM peripheral and unmaps the memory.
Header for general library functionality.
void pwm_value(unsigned int value)
Sets PWM value.