test.c 720 B

12345678910111213141516171819202122232425262728293031
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <unistd.h>
  4. #include <sys/io.h>
  5. #include <stdint.h>
  6. #include <string.h>
  7. int main(void)
  8. {
  9. unsigned char val;
  10. if (ioperm(0x80, 1, 1) < 0) { //申请 0x80 端口的访问权限
  11. perror("Failed to request I/O port permission");
  12. return 1;
  13. }
  14. /*
  15. outb(0x00,0xA45);
  16. outb(inb(0xA46) | 0x40, 0xA46);//update VBAT
  17. outb(0x00,0xEB);
  18. outb(0x00,0xEB);
  19. outb(0x00,0xEB);
  20. outb(0x28,0xA45);
  21. val = inb(0xA46);//read VBAT
  22. */
  23. outb(0x88, 0x80); //用户空间也有 outb 函数(需链接 libx86)
  24. ioperm(0x80,1,0); //释放权限
  25. //printf("VBAT value = %dmv\n", val * 2 * 11);
  26. return 0;
  27. }