armOS  0.1.0
Minimal ARM Operating System for the Raspberry Pi - Documentation generated for Pi 4.
drivers

Drivers for Raspberry Pi Peripherals. More...

Files

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.
 

Macros

#define LED_PIN   17
 
#define LED_MSEC_IRQ   200
 
#define MAX_INPUT_LENGTH   80
 

Functions

int gpio_pin_set_func (uint8_t pin_num, gpio_func func)
 
int gpio_pin_set (uint8_t pin_num)
 
int gpio_pin_clear (uint8_t pin_num)
 
int led_init (uint8_t pin_num)
 
void led_on (uint8_t pin_num)
 
void led_off (uint8_t pin_num)
 
void led_on_ms (uint8_t pin_num, uint32_t msec)
 
void led_pulse (uint8_t pin_num, uint32_t msec)
 
void led_blink_times (uint8_t pin_num, size_t count, uint32_t msec)
 
void led_blink_sos (uint8_t pin_num, uint32_t msec)
 
void mmio_write (uint64_t reg, uint32_t data)
 
uint32_t mmio_read (uint64_t reg)
 
void delay (int32_t count)
 
void timer_1_init (uint32_t msec)
 
void timer_3_init (uint32_t msec)
 
void timer_1_stop ()
 
void timer_3_stop ()
 
uint64_t timer_get_ticks ()
 
void timer_msleep (uint32_t msec)
 
void uart_init ()
 
void uart_putc (unsigned char c)
 
unsigned char uart_getc ()
 
void uart_puts (const char *str)
 
char * uart_gets ()
 

Detailed Description

Drivers for Raspberry Pi Peripherals.

Macro Definition Documentation

◆ LED_MSEC_IRQ

#define LED_MSEC_IRQ   200

The pulse time in milliseconds for the LED IRQ.

◆ LED_PIN

#define LED_PIN   17

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

Function Documentation

◆ delay()

void delay ( int32_t  count)

Delays count of clock cycles.

Parameters
countNumber of cycles.

◆ gpio_pin_clear()

int gpio_pin_clear ( uint8_t  pin_num)

Clears the GPIO pin (Low) at pin_num, using GPCLRn ( GPCLR0, GPCLR1).

Parameters
pin_numGPIO pin number.
Returns
  • On success: 0
  • On failure: -1
See also
peripherals/gpio.h

◆ gpio_pin_set()

int gpio_pin_set ( uint8_t  pin_num)

Sets the GPIO pin (High) at pin_num, using GPSETn ( GPSET0, GPSET1).

Parameters
pin_numGPIO pin number.
Returns
  • On success: 0
  • On failure: -1
See also
peripherals/gpio.h

◆ 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_numGPIO pin number.
funcAlternative 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_numGPIO pin number.
msecTime 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_numGPIO pin number.
countNumber of times to blink.
msecTime 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
pin_numGPIO pin number.
Returns
  • On success: 0
  • On failure: -1
See also
gpio_pin_set_func()

◆ led_off()

void led_off ( uint8_t  pin_num)

Turns LED at pin_num OFF.

Parameters
pin_numGPIO pin number.
See also
gpio_pin_clear()

◆ led_on()

void led_on ( uint8_t  pin_num)

Turns LED at pin_num ON.

Parameters
pin_numGPIO pin number.
See also
gpio_pin_set()

◆ 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_numGPIO pin number.
msecTime 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_numGPIO pin number.
msecTime 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
reg64-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
reg64-bit register address.
data32-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
msecTime 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()

void timer_1_stop ( )

Disables System Timer 1.

Set 0 to compare register TIMER_C1, in order to stop timer interrupts.

See also
peripherals/timer.h

◆ timer_3_init()

void timer_3_init ( uint32_t  msec)

Initializes System Timer 3, with a time interval of msec milliseconds.

Parameters
msecTime 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()

void timer_3_stop ( )

Disables System Timer 3.

Set 0 to compare register TIMER_C3, in order to stop timer interrupts.

See also
peripherals/timer.h

◆ 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
msecTime 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()

char* 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()

void 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
cThe 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
strA 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()
LED_PIN
#define LED_PIN
Definition: led.h:25
led_blink_times
void led_blink_times(uint8_t pin_num, size_t count, uint32_t msec)
Definition: led.c:109