EQuestionAnswers.com Computer/Electronics Questions and Answers
C, C++, VC++, COM/DCOM, DLL and more
#Login #Sign up  Facebook Twitter TGoogle+

#Previous Topic #Index #Next Topic

Application code is very simple. We are opening our device which is in the path "/dev/myled". Now there is an infinite loop. First we are reading one byte from device and LSB bit is indicating the status of the LED. Now we are toggling the status and writing back the status to the device. Again we are doing the same using ioctl(). Here reading and writing happends in the device driver read()/write()/ioctl() call back and calls are blocked till interrupt is triggred.

#define IO_READ 0
#define IO_WRITE 1
int main(int argc, char *argv[])
10    int fd;
11    unsigned char status;
12    fd = open ("/dev/myled", O_RDWR);
13    if (fd < 0) {
14      return (-1);
15    }
16    while (1) {
18      read(fd, &status, 1);
19      printf("LED Status %s using read()\n", (status & 1) ? "on" :"off");
20      sleep(1);
21      printf("Turning LED %s using write()\n", (status & 1) ? "off" :"on");
22      status ^= 1;
23      write(fd, &status, 1);
24      sleep(1);
26      ioctl(fd, IO_READ, &status);
27      printf("LED Status %s using ioctl()\n", (status & 1) ? "on" :"off");
28      sleep(1);
29      printf("Turning LED %s using ioctl()\n", (status & 1) ? "off" :"on");
30      status ^= 1;
31      ioctl(fd, IO_WRITE, &status);
32      sleep(1);
33    }
34    close(fd);
35    return 0;
36  }

You have viewed 1 page out of 14. Your learning is 0.00% complete. Login to check your learning progress.

 Vote 0

Similar topics related to this section

Altera FPGA interfacing ARM, ARM CPU internals, ARM CPU, Cache Memory and MMU, ARM bus hierarchy, ARM data, address and control lines, ARM MMIO read, ARM MMIO write, FPGA interfacing with system bus, VHDL/Verilog program, ADS C Code, Linux Direct MMIO App, Linux Device Driver, Linux Application code, Final Demo,

* #1 webmaster Tue 15 Apr/2014 04:50:47(GMT)  Like 0 Unlike 0

Dear Users,

We are pleased to inform you that a forum/blog has been incorporated with www.equestionanswers.com. You are welcomed to add your comments, requests, codes, solutions and feedback to it. Please login(if already a member) or signup(for free) to avail to this facility.


Your message goes here:

My Post:*
Secutiry Code: ******  *
Preview this compose before posting this in discussion forum.
  1. Use [Sxx] code to show smiles. Example [S02]
  2. Use [URL ], example [URL http://www.google.com/]
  3. To display code or un formatted text use [CODE] [/CODE]. Example: [CODE] printf("Hello world"); [/CODE]
 [S01]   [S02]   [S03]   [S04]   [S05]   [S06]   [S07]   [S08] 
 [S09]   [S10]   [S11]   [S12]   [S13]   [S14]   [S15]   [S16] 
 [S17]   [S18]   [S19]   [S20]   [S21]   [S22]   [S23]   [S24] 

Note: Only members are allowed, * fields are mandatory.