[問題] 要如何使一般user也能使用device?

作者: wtchen (沒有存在感的人)   2015-06-16 17:41:07
雖然我問過相關的問題,不過遇到瓶頸只好再問詳細點
我寫了一個module想用rpi的gpio控制一個含3個LED的小電路
/dev 下也有LED_0 LED_1 LED_2
我希望一般user可以寫入這三個file(用0或1)去控制LED的開關
程式碼如下:
https://gist.github.com/gnitnaw/b116f358fa688897fe00
之前不管是用一般user還是root都不能改變/dev/LED_(0,1,2)
改掉一些bug以後,用root可以control了,一般user還是不行
(寫到現在還沒開始ioctl...唉...我的學習速度真慢)
之後可能在kernel學習過程中會有更多問題要上來請教,希望不會違反板規
然後我也會回饋自己所學(拙作請勿見怪)。
我寫了個小程式嘗試去write /dev/LDE_0 :
int main(void)
{
char path[PATH_SIZE], buf[BUF_SIZE];
int i = 0, fd = 0;
snprintf(path, sizeof(path), "/dev/LED_0");
fd = open(path, O_WRONLY);
if (fd < 0) {
perror("Error opening GPIO pin");
exit(EXIT_FAILURE);
}
printf("Set GPIO pins to output, logic level :\n");
strncpy(buf, "1", 1);
buf[1] = '\0';
if (write(fd, buf, sizeof(buf)) < 0) {
perror("write, set pin output");
exit(EXIT_FAILURE);
}
return EXIT_SUCCESS;
}
作者: alongalone (沿著孤單的路)   2015-06-16 18:00:00
write的時候沒有error 發生嗎?
作者: wtchen (沒有存在感的人)   2015-06-16 18:37:00
不能直接用echo嗎?echo得到的訊息是沒有權限
作者: alongalone (沿著孤單的路)   2015-06-16 22:23:00
我覺得你要不要先把tasklet那段code拿掉先看會不會亮;另外你能確定gpio跟led是連結正確的嗎
作者: leolarrel (真.粽子無雙)   2015-06-17 08:56:00
有檢查/dev/LED_0的檔案權限嗎?看來是檔案權限沒打開
作者: wtchen (沒有存在感的人)   2015-06-17 15:52:00
對,權限沒打開沒錯,請問是要手動打開嗎?設成666?
作者: leolarrel (真.粽子無雙)   2015-06-17 18:18:00
設成666應該可以
作者: wtchen (沒有存在感的人)   2015-06-17 20:39:00
成功了,多謝

Links booklink

Contact Us: admin [ a t ] ucptt.com