Beaglebone PWM negro con C

Escribí una función pwm de muestra en C para beaglebone black. Cada vez que hago una llamada a la función en otros módulos o en main (), termino en un fallo de segmentación. Ayuda amablemente donde estoy cometiendo el error y cómo lidiar con este problema. Debajo está el código.

int trigger_pwm_output(unsigned input_no )
{
    FILE *pwm,*duty,*period,*run;``
    uint16_t input=0;
    uint8_t input_no=0,input_state=0;
    unsigned int duty_cycle =500000;
    pwm = fopen("/sys/devices/bone_capemgr.9/slots", "w");
    fseek(pwm,0,SEEK_SET);
    fprintf(pwm,"am33xx_pwm");
    fflush(pwm);



    switch(input_no)
    {
        case 0:

            fprintf(pwm,"bone_pwm_P8_13");
            fflush(pwm);
            period = fopen("/sys/devices/ocp.3/pwm_test_P8_13.15/period", "w");
            fseek(period,0,SEEK_SET);
            fprintf(period,"%d",500000);
            fflush(period);

            duty = fopen("/sys/devices/ocp.3/pwm_test_P8_13.15/duty", "w");
            fseek(duty,0,SEEK_SET);
            run = fopen("/sys/devices/ocp.3/pwm_test_P8_13.15/run", "w");
            fseek(run,0,SEEK_SET);
            fprintf(run,"%d",0);
            fflush(run);

            fseek(run,0,SEEK_SET);
            count++;
                do 
                {
                    duty_cycle += 10;
                    fprintf(duty,"%d",duty_cycle);
                }while(count > 0) || (count < 10));
                fflush(duty);
                fprintf(run,"%d",1);
                fflush(run);

            fclose(pwm);
            fclose(duty);
            fclose(period);
            fclose(run);
            break;
        case 1:
            fprintf(pwm,"bone_pwm_P8_19");
            fflush(pwm);
            period = fopen("/sys/devices/ocp.3/pwm_test_P8_19.16/period", "w");
            fseek(period,0,SEEK_SET);
            fprintf(period,"%d",500000);
            fflush(period);

            duty = fopen("/sys/devices/ocp.3/pwm_test_P8_19.16/duty", "w");
            fseek(duty,0,SEEK_SET);
            run = fopen("/sys/devices/ocp.3/pwm_test_P8_19.16/run", "w");
            fseek(run,0,SEEK_SET);
            fprintf(run,"%d",0);
            fflush(run);

            fseek(run,0,SEEK_SET);
            --count;
            do 
            {
                duty_cycle += 10;
                fprintf(duty,"%d",duty_cycle);
            }while(count <10);
            fflush(duty);
            fprintf(run,"%d",1);
            fflush(run);



            fclose(pwm);
            fclose(duty);
            fclose(period);
            fclose(run);
            break;



    }
    return 0;
}

`

Respuestas a la pregunta(2)

Su respuesta a la pregunta