Beaglebone black PWM using C

前端 未结 2 1770
甜味超标
甜味超标 2021-01-22 18:38

I wrote a sample pwm function in C for beaglebone black. Whenever I make a function call in other modules or in main(), I end up in segmentation fault. Kindly help where I am ma

2条回答
  •  情书的邮戳
    2021-01-22 19:01

    There are several issues with this code - some of which are already described in the comments.

    • There is a variable name collision. input_no is both passed into the function as well as defined within the function.
    • Both do-while loops are potentially infinite. Both loops have an end condition dependent on count which is not modified in the body of either loop. Additionally, the condition in the first of these loops is always true regardless of the value of count.
    • The return value of all fopen calls is never checked. If any of these calls fail, then subsequent file operations are called with null file pointers.
    • count is not defined or initialized anywhere in this code. Is it defined globally?
    • One of your calls to fopen is made outside the body of the switch statement - it'd be best to move its corresponding close call outside as well.

提交回复
热议问题