Drivers for Raspberry Pi Peripherals.
More...
|
file | gpio.c |
| Implementation of functions for manipulating GPIO registers.
|
|
file | led.c |
| Implementation of functions for manipulating a LED to a GPIO pin.
|
|
file | mmio.c |
| Implementation of MMIO functions.
|
|
file | timer.c |
| Implementation of basic System Timer functions.
|
|
file | uart.c |
| Implementation of basic UART functions.
|
|
file | gpio.h |
| Definition of functions for manipulating GPIO registers.
|
|
file | led.h |
| Definition of functions for manipulating a LED to a GPIO pin.
|
|
file | mmio.h |
| Definition of MMIO functions.
|
|
file | timer.h |
| Definition of basic System Timer functions.
|
|
file | uart.h |
| Definition of basic UART functions.
|
|
Drivers for Raspberry Pi Peripherals.
◆ LED_MSEC_IRQ
The pulse time in milliseconds for the LED IRQ.
◆ LED_PIN
Raspi 3, 4 -> GPIO 17 (LED Connected on physical pin 11)
- Warning
- This should change according to the pin you have the LED connected.
◆ MAX_INPUT_LENGTH
#define MAX_INPUT_LENGTH 80 |
Maximum length for the serial input.
- Warning
- It is a temporary solution, because of no support for dynamic allocation of memory.
- See also
- console(), uart_gets(), process.c
◆ delay()
void delay |
( |
int32_t |
count | ) |
|
Delays count of clock cycles.
- Parameters
-
◆ gpio_pin_clear()
int gpio_pin_clear |
( |
uint8_t |
pin_num | ) |
|
◆ gpio_pin_set()
int gpio_pin_set |
( |
uint8_t |
pin_num | ) |
|
◆ gpio_pin_set_func()
int gpio_pin_set_func |
( |
uint8_t |
pin_num, |
|
|
gpio_func |
func |
|
) |
| |
Sets the Alternative Function func for GPIO pin at pin_num, using GPFSELn ( GPFSEL0 - GPFSEL5).
- Parameters
-
pin_num | GPIO pin number. |
func | Alternative Function. |
- Returns
- On success: 0
- On failure: -1
- See also
- gpio_func, peripherals/gpio.h
◆ led_blink_sos()
void led_blink_sos |
( |
uint8_t |
pin_num, |
|
|
uint32_t |
msec |
|
) |
| |
Makes LED at pin_num, to blink an SOS message, with an msec interval (in milliseconds).
- Parameters
-
pin_num | GPIO pin number. |
msec | Time to sleep in milliseconds. |
- See also
- led_on(), led_off(), timer_msleep()
◆ led_blink_times()
void led_blink_times |
( |
uint8_t |
pin_num, |
|
|
size_t |
count, |
|
|
uint32_t |
msec |
|
) |
| |
Makes LED at pin_num, to blink count times, for msec milliseconds.
- Parameters
-
pin_num | GPIO pin number. |
count | Number of times to blink. |
msec | Time to sleep in milliseconds. |
- See also
- led_pulse()
Example
◆ led_init()
int led_init |
( |
uint8_t |
pin_num | ) |
|
Sets pin_num GPIO pin as Output.
- Parameters
-
- Returns
- On success: 0
- On failure: -1
- See also
- gpio_pin_set_func()
◆ led_off()
void led_off |
( |
uint8_t |
pin_num | ) |
|
◆ led_on()
void led_on |
( |
uint8_t |
pin_num | ) |
|
◆ led_on_ms()
void led_on_ms |
( |
uint8_t |
pin_num, |
|
|
uint32_t |
msec |
|
) |
| |
Turns LED at pin_num ON for msec milliseconds.
- Parameters
-
pin_num | GPIO pin number. |
msec | Time to sleep in milliseconds. |
- See also
- led_on(), led_off(), timer_msleep()
◆ led_pulse()
void led_pulse |
( |
uint8_t |
pin_num, |
|
|
uint32_t |
msec |
|
) |
| |
Makes LED at pin_num, to blink once for msec milliseconds.
- Parameters
-
pin_num | GPIO pin number. |
msec | Time to sleep in milliseconds. |
- See also
- led_on(), led_off(), timer_msleep()
◆ mmio_read()
uint32_t mmio_read |
( |
uint64_t |
reg | ) |
|
Memory-Mapped I/O input.
- Parameters
-
reg | 64-bit register address. |
- Returns
- 32-bit data.
Reads register at reg address and returns its data.
◆ mmio_write()
void mmio_write |
( |
uint64_t |
reg, |
|
|
uint32_t |
data |
|
) |
| |
Memory-Mapped I/O output.
- Parameters
-
reg | 64-bit register address. |
data | 32-bit data. |
Writes the data value to the register at reg address.
◆ timer_1_init()
void timer_1_init |
( |
uint32_t |
msec | ) |
|
Initializes System Timer 1, with a time interval of msec milliseconds.
- Parameters
-
msec | Time interval in milliseconds. |
Initialization steps:
- Sets time interval to be msec milliseconds.
- Reads current counter value from TIMER_CLO.
- Increases it by an interval ( interval_1).
- Sets this value to be compared for System Timer 1 Interrupt.
- See also
- peripherals/timer.h
◆ timer_1_stop()
◆ timer_3_init()
void timer_3_init |
( |
uint32_t |
msec | ) |
|
Initializes System Timer 3, with a time interval of msec milliseconds.
- Parameters
-
msec | Time interval in milliseconds. |
Initialization steps:
- Sets time interval to be msec milliseconds.
- Reads current counter value from TIMER_CLO.
- Increases it by an interval ( interval_3).
- Sets this value to be compared for System Timer 3 Interrupt.
- See also
- peripherals/timer.h
◆ timer_3_stop()
◆ timer_get_ticks()
uint64_t timer_get_ticks |
( |
| ) |
|
Reads the 64-bit free running counter value that contains, the number of ticks since the system's initialization.
- Returns
- Number of ticks.
Reads the values from the TIMER_CHI and TIMER_CLO registers, and creates the full 64-bit counter value by left shifting the 32 high bits.
- See also
- peripherals/timer.h
◆ timer_msleep()
void timer_msleep |
( |
uint32_t |
msec | ) |
|
Sleeps for msec milliseconds, using the timers free running counter.
- Parameters
-
msec | Time interval in milliseconds. |
Get counters current calue from timer_get_ticks() and waits until msec have passed from start.
- Note
- Blocking function.
- See also
- timer_get_ticks()
◆ uart_getc()
unsigned char uart_getc |
( |
| ) |
|
Gets a byte to the UART (serial input).
- Returns
- The byte received from the UART.
First waits for the UART to have received something, and then reads the contents of the AUX_MU_IO_REG register
- See also
- peripherals/aux.h
◆ uart_gets()
Gets a string from the UART (serial input).
- Returns
- A pointer to a static char array, that the string is saved.
Reads in a loop a byte from the serial input using the uart_getc() function until a New Line (\n
) or a Carriage Return (\r
) char is received. Echoes back each char to the serial output.
- Note
- Gets up to MAX_INPUT_LENGTH chars.
-
Always appends a null terminator (
\0
) at the end of the string.
- See also
- uart_getc(), MAX_INPUT_LENGTH
◆ uart_init()
Initializes the UART interface based on the running device.
Basic configuration:
- Sets Alternative Function 5 for GPIO pins 14, 15, in order to enable mini UART.
- Disables pull up/down resistors for pins 14, 15.
- Enables mini UART.
- Disables auto flow control and disables receiver and transmitter.
- Enables receive and transmit interrupts.
- Clears the receive and transmit FIFO, and enables FIFO.
- Enables 8 bit mode.
- Sets RTS line to be always high.
- Sets baud rate at 115200.
- Enables transmitter and receiver.
- See also
- peripherals/gpio.h, peripherals/aux.h
◆ uart_putc()
void uart_putc |
( |
unsigned char |
c | ) |
|
Sends a byte to the UART (serial output).
- Parameters
-
c | The byte sent to the UART. |
First waits for the UART to become ready to transmit, and then writes the byte c to the AUX_MU_IO_REG register.
- See also
- peripherals/aux.h
◆ uart_puts()
void uart_puts |
( |
const char * |
str | ) |
|
Sends a string to the UART (serial output).
- Parameters
-
str | A string pointer for the string to send to the UART. |
Iterates over the string and prints each char to the serial output.
- Note
- If a new New Line (
\n
) char is found, it appends a Carriage Return (\r
) char, so there is no need to include the \r
char in the str string.
- See also
- uart_putc()