User Tools

Site Tools


developersguide:driverprogramming

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
developersguide:driverprogramming [2016/02/04 14:29]
lionelsambuc Corrected configuration file name
developersguide:driverprogramming [2022/02/10 14:58] (current)
stux add mknod /dev/time c 18 0
Line 59: Line 59:
 } }
 </​code>​ </​code>​
-Ignore the sef_startup() call for now. We'll explain its purpose later. ​Now try to see if everything compiles correctly:+Ignore the sef_startup() call for now. We'll explain its purpose later.
  
-<code bash> +In addition, we must create ​//​hello.conf//​ file. It contains the permissions for the service. Each device driver typically only needs to access one real hardware device, and uses a few functions provided by Minix. To give our simple hello try-out driver enough permissions to experiment with, create //​hello.conf//​ with:
-# make clean +
-# make +
-# make install +
-</​code>​ +
-If you did not receive any errors, it is time to try and run the device driver. Before we do that, we must create ​the //​hello.conf//​ file. It contains the permissions for the service. Each device driver typically only needs to access one real hardware device, and uses a few functions provided by Minix. To give our simple hello try-out driver enough permissions to experiment with, create //​hello.conf//​ with:+
  
 //​hello.conf//:​ //​hello.conf//:​
Line 85: Line 80:
 }; };
 </​code>​ </​code>​
-Starting, stopping and restarting device drivers must be done using the **service(8)** command. To start the hello program, enter the following command:+Now try to see if everything compiles correctly:​ 
 + 
 +<code bash> 
 +# make clean 
 +# make 
 +# make install 
 +</​code>​ 
 +If you did not receive any errors, it is time to try and run the device driver. ​Starting, stopping and restarting device drivers must be done using the **minix-service(8)** command. To start the hello program, enter the following command:
  
 <code bash> <code bash>
-# service up /​service/​hello+#minix-service up /​service/​hello
 Hello, World! Hello, World!
 RS: restarting /​service/​hello,​ restarts 0 RS: restarting /​service/​hello,​ restarts 0
 </​code>​ </​code>​
-And what a surprise, it displays the //Hello, World!// message :-) Stop the driver with:+And what a surprise, it displays the //Hello, World!// message :-) in the kernel log. Check with writing the contents of /​var/​log/​messages. ​Stop the driver with:
  
 <code bash> <code bash>
-# service down hello+#minix-service down hello
 </​code>​ </​code>​
 We received another message as well from the so-called //​Reincarnation Server// (RS). In Minix as a [[http://​en.wikipedia.org/​wiki/​Microkernel|microkernel]],​ device drivers are separate programs which send and receive message to communicate with the other operating system components. Device drivers, like any other program, may contain bugs and could crash at any point in time. The Reincarnation server will attempt to restart device drivers when it notices they are abruptly killed by the kernel due to a crash, or in our case when they exit(2) unexpectedly. You can see the Reincarnation Server in the process list as **rs**, if you use the **ps(1)** command. The Reincarnation Server sends keep-a-live messages to each running device driver on the system periodically,​ to ensure they are still responsible and not i.e. stuck in an infinite loop. We received another message as well from the so-called //​Reincarnation Server// (RS). In Minix as a [[http://​en.wikipedia.org/​wiki/​Microkernel|microkernel]],​ device drivers are separate programs which send and receive message to communicate with the other operating system components. Device drivers, like any other program, may contain bugs and could crash at any point in time. The Reincarnation server will attempt to restart device drivers when it notices they are abruptly killed by the kernel due to a crash, or in our case when they exit(2) unexpectedly. You can see the Reincarnation Server in the process list as **rs**, if you use the **ps(1)** command. The Reincarnation Server sends keep-a-live messages to each running device driver on the system periodically,​ to ensure they are still responsible and not i.e. stuck in an infinite loop.
Line 300: Line 302:
 Finally, the //main()// function executes //​chardriver_task()//​ to let //​libchardriver//​ start processing user requests and invoke our driver callback functions. Finally, the //main()// function executes //​chardriver_task()//​ to let //​libchardriver//​ start processing user requests and invoke our driver callback functions.
  
-Now compile the program again using the same commands as in example 1, and start the driver with the **service(8)** command. We supply ''​-dev /​dev/​hello''​ to indicate that the newly started driver is responsible for the major device identified by /dev/hello - namely, major 17, which we picked earlier.+Now compile the program again using the same commands as in example 1, and start the driver with the **minix-service(8)** command. We supply ''​-dev /​dev/​hello''​ to indicate that the newly started driver is responsible for the major device identified by /dev/hello - namely, major 17, which we picked earlier.
  
 <code bash> <code bash>
-# service up /usr/sbin/hello -dev /dev/hello+minix-service up /service/hello -dev /dev/hello
 Hello, World! Hello, World!
 </​code>​ </​code>​
Line 321: Line 323:
 If you get the message above, the hello driver works!** :D ** If you get the message above, the hello driver works!** :D **
  
-Now let's try to restart the driver with the **service(8)** command to simulate a failure:+Now let's try to restart the driver with the **minix-service(8)** command to simulate a failure:
  
 <code bash> <code bash>
-# service refresh hello+minix-service refresh hello
 Hello, World! Hello, World!
 Hey, I've just been restarted! Hey, I've just been restarted!
Line 348: Line 350:
 #endif /* __HELLO_H */ #endif /* __HELLO_H */
 </​code>​ </​code>​
-Now recompile it and update the driver with the **service(8)** command:+Now recompile it and update the driver with the **minix-service(8)** command:
  
 <code bash> <code bash>
Line 354: Line 356:
 # make # make
 # make install # make install
-# service update /usr/sbin/hello -state 1    # request an update state where no work is in progress (i.e. SEF_LU_STATE_WORK_FREE=1)+minix-service update /service/hello -state 1    # request an update state where no work is in progress (i.e. SEF_LU_STATE_WORK_FREE=1)
 Hello, New World! Hello, New World!
 Hey, I'm a new version! Hey, I'm a new version!
Line 439: Line 441:
 struct chardriver time_tab = struct chardriver time_tab =
 { {
-        ​*cdr_open = time_open,​ +        ​.cdr_open = time_open,​ 
-        ​*cdr_close = time_close,​ +        ​.cdr_close = time_close,​ 
-        ​*cdr_read = time_read,+        ​.cdr_read = time_read,
 }; };
  
Line 579: Line 581:
 SRCS=   ​time.c SRCS=   ​time.c
  
-FILES=$(PROG).conf +FILES=${PROG}.conf 
-FILESNAME=$(PROG)+FILESNAME=${PROG}
 FILESDIR=/​etc/​system.conf.d FILESDIR=/​etc/​system.conf.d
  
 DPADD+= ${LIBCHARDRIVER} ${LIBSYS} DPADD+= ${LIBCHARDRIVER} ${LIBSYS}
 LDADD+= -lchardriver -lsys LDADD+= -lchardriver -lsys
- 
- 
  
 .include <​minix.service.mk>​ .include <​minix.service.mk>​
 </​code>​ </​code>​
  
-Now we need to give the new time device driver access to the CMOS ports 0x70 and 0x71 using the time.conf file mentioned in the Makefile. Putting it in /​etc/​system.d/​ lets service read it. This is the contents:+Now we need to give the new time device driver access to the CMOS ports 0x70 and 0x71 using the //time.conf// file mentioned in the Makefile. Putting it in /​etc/​system.d/​ lets service read it. This is the contents:
  
 <​code>​ <​code>​
Line 623: Line 623:
     install ​ /​service/​time     install ​ /​service/​time
     install ​ /​etc/​system.conf.d/​time     install ​ /​etc/​system.conf.d/​time
-# service up /​service/​time -dev /dev/time+mknod /dev/time c 18 0 
 +# minix-service up /​service/​time -dev /dev/time
 # cat /​dev/​time ​ # cat /​dev/​time ​
 2014-09-10 15:48:21 2014-09-10 15:48:21
developersguide/driverprogramming.1454592583.txt.gz · Last modified: 2016/02/04 14:29 by lionelsambuc