- #include <stdlib.h>
- #include <stdio.h>
- #include <string.h>
- #include <fcntl.h>
- #define SLOT_DIR "/sys/devices/bone_capemgr.9/slots"
- #define PWM1_DIR "/sys/bus/platform/drivers/pwm_test/pwm_test_P8_13.15"
- #define PWM1_duty "/sys/bus/platform/drivers/pwm_test/pwm_test_P8_13.15/duty"
- #define PWM1_period "/sys/bus/platform/drivers/pwm_test/pwm_test_P8_13.15/period"
- #define PWM1_run "/sys/bus/platform/drivers/pwm_test/pwm_test_P8_13.15/run"
- #define MAX_BUF 80
- void main()
- {
- int fd, len;
- char buf[MAX_BUF];
- char ch;
- int i;
- FILE *stream=NULL;
- //Cofig P8.13 PWM
- fd = open(SLOT_DIR, O_WRONLY);
- len = snprintf(buf,sizeof(buf),"bone_pwm_P8_13");
- write(fd,buf,len);
- len = snprintf(buf,sizeof(buf),"am33xx_pwm");
- write(fd,buf,len);
- close(fd);
- //Disable P8.13 PWM
- fd = open(PWM1_run, O_WRONLY);
- len = snprintf(buf,sizeof(buf),"0");
- write(fd,buf,len);
- close(fd);
- //set period 20000000
- fd = open(PWM1_period, O_WRONLY);
- len = snprintf(buf,sizeof(buf),"20000000");
- write(fd,buf,len);
- close(fd);
- //set duty 20000000
- fd = open(PWM1_duty, O_WRONLY);
- len = sprintf(buf,"%d",10000000);;
- write(fd,buf,len);
- close(fd);
- //Enable P8.13 PWM
- fd = open(PWM1_run, O_WRONLY);
- len = snprintf(buf,sizeof(buf),"1");
- write(fd,buf,len);
- close(fd);
- while(1)
- {
- for(i=0;i<10;i++)
- {
- //Disable P8.13 PWM
- fd = open(PWM1_run, O_WRONLY);
- len = snprintf(buf,sizeof(buf),"0");
- write(fd,buf,len);
- close(fd);
- //set duty
- fd = open(PWM1_duty, O_WRONLY);
- len = sprintf(buf,"%d",1000000*i);;
- write(fd,buf,len);
- close(fd);
- //Enable P8.13 PWM
- fd = open(PWM1_run, O_WRONLY);
- len = snprintf(buf,sizeof(buf),"1");
- write(fd,buf,len);
- close(fd);
- usleep(1000000);
- }
- }
- }