Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

In the lab you will be provided with an auxiliary board which contains 5 push bu

ID: 3623706 • Letter: I

Question

In the lab you will be provided with an auxiliary board which contains 5 push buttons,
3 LEDS. The 5 push buttons and 3 LEDS are connected to the I/O lines associated with port B.

Week 2: Creating a Simple Kernel Module
1. For this part of the lab, you will create a kernel module that simply turns on the red and yellow LEDs of the auxiliary board when it is installed, and turns them off when removed.

Hint:
Remember to use __ioremap when accessing the I/O registers in a kernel module.
2. Something to note about kernel modules is that they do not contain a main(), instead they contain two functions:

int init_module(void)
void cleanup_module(void)

the init_module function contains code that is ran when the module is installed. This function should return 0 unless an error has occurred. Cleanup_module, is the code that is ran when the module is removed.

3. There are three helpful shell commands to use when dealing with modules:

- lsmod: lists all of the modules currently installed in the kernel
- insmod NAME.o: installs the module whose filename is NAME.o
- rmmod NAME: removes the module with name: NAME (notice the .o is not included)

4. Last, to compile the module, you need to define the symbols: MODULE and __KERNEL__. This can be done one of two ways. First, you can define the symbols at the beginning of your source code which would look like #define MODULE. Another way is to define the symbols when you compile in Eclipse by going to the properties and clicking on symbols under the compiler settings.

5. To avoid warnings when installing the module, add the following line to your source code MODULE_LICENSE(“GPL”);

PostLab Questions:
1. Assuming that PortB has 8 I/O lines associated with it, what value would you assign to Port B’s data direction register so that the I/O lines associated with bits 0, 3 and 7 are inputs, and the rest are outputs?

2. Assuming that PortB has 8 I/O lines which are all configured as outputs, what would you write to Port B’s data register so that bits 2, 4, and 5 are set to one, bits 1, 3, and 6 are set to 0 and bits 7 and 0 retain their original value?

Explanation / Answer

int init_module(void) { unsigned long *ptr; unsigned long *pfdr; unsigned long *pfddr; //gets pointer to memory ptr = (unsigned long *)__ioremap(0x80840000, 4096, 0); //offset to port B pfdr = ptr + 0x01; //sets data direction of port B pin 1 to output pfddr = ptr + 0x05;

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote