?? demo.c
字號:
#include <stdio.h>
#include <stdlib.h>
//#include <sys/types.h>
//#include <sys/stat.h>
#include <sys/ioctl.h>
#include <fcntl.h>
//#include <stdlib.h>
#include <errno.h>
#include <time.h>
#include <unistd.h>
//#include <sys/wait.h>
//#include <pthread.h>
//#include <asm/ioctl.h>
//#include <linux/videodev.h>
#include <linux/rtc.h>
//#include <linux/tw2834.h>
int main()
{
int rtc_fd;
char p[100];
char * time;
struct rtc_time tm={
.tm_sec=30, /* 0~59 */
.tm_min=12, /* 0~59 */
.tm_hour=14, /* 0~23 */
.tm_mday=24, /* 1~*,depend on month */
.tm_mon=0, /* 0~11 */
.tm_year=2008, /* >1970 */
.tm_wday=4 /* 0~6 */
};
rtc_fd=open("/dev/rtc",O_RDWR);
if(rtc_fd<0){
perror("open rtc device:");
exit(EXIT_FAILURE);
}
#if 0
if(ioctl(rtc_fd,RTC_8593_INIT,NULL)<0){
printf("Init rtc pcf8593 error!\n");
exit(EXIT_FAILURE);
}
if(ioctl(rtc_fd,RTC_SET_TIME,&tm)<0){
printf("Write rtc pcf8593 error!\n");
exit(EXIT_FAILURE);
}
#else
if(ioctl(rtc_fd,RTC_RD_TIME,&tm)<0){
printf("Read rtc pcf8593 error!\n");
exit(EXIT_FAILURE);
}
strftime(p,100,"%c",&tm);
// printf("The rtc time is %s\n",asctime(&tm));
printf("The rtc time is %s\n",p);
#endif
close(rtc_fd);
return 0;
}
#if 0
void main()
{
int tw2834_dev,ioctl_ret=0;
unsigned int rdata=0;
//struct tw2834_ioinfo tw2834_ioinfo;
//tw2834_ioinfo.slave_addr= 0x84;
//tw2834_ioinfo.
tw2834_dev = open("/dev/tw2834",O_RDWR);
if (tw2834_dev == -1 )
{
printf("Cannt open file \n");
exit(0);
}
printf("The device id is %d \n",tw2834_dev);
ioctl_ret=ioctl(tw2834_dev,TEST_READ,&rdata);
printf("ioctl return %d \n",ioctl_ret);
printf("The read value is %d \n", rdata);
close(tw2834_dev);
}
#endif
#if 0
#include <linux/init.h>
#include <linux/module.h>
static int hello_init(void)
{
printk( "Hello, linux world \n");
return 0;
}
//KERN_ALERT
static void hello_exit(void)
{
printk( "Goodbye, linux world \n");
}
//KERN_ALERT
module_init(hello_init);
module_exit(hello_exit);
MODULE_LICENSE(" Dual BSD/GPL ");
#endif
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -