Source code for kernel driver handling. More...
Go to the source code of this file.
Macros | |
#define | PAGE_SIZE /* 4096 */ |
The page size for memory maps. | |
#define | PRU_INTC_GER_REG /* &h010 */ |
Global interrupt enable register. | |
#define | PRU_INTC_HIEISR_REG /* &h034 */ |
Host interrupt enable indexed set register. | |
#define | PRU_INTC_SRSR0_REG /* &h200 */ |
System event status register 0-31. | |
#define | PRU_INTC_SRSR1_REG /* &h204 */ |
System event status register 32-63. | |
#define | PRU_INTC_SECR0_REG /* &h280 */ |
System event enable/clear register 0-31. | |
#define | PRU_INTC_SECR1_REG /* &h284 */ |
System event enable/clear register 32-63. | |
#define | PRU_INTC_ESR0_REG /* &h300 */ |
System event enable set register 0-31. | |
#define | PRU_INTC_ESR1_REG /* &h304 */ |
System event enable set register 0-31. | |
#define | PRU_INTC_CMR0_REG /* &h400 */ |
The channel map register. | |
#define | PRU_INTC_HMR0_REG /* &h800 */ |
Host interrupt map register, channels 0 to 3. | |
#define | PRU_INTC_SIPR0_REG /* &hD00 */ |
System event polarity register, events 0 to 31. | |
#define | PRU_INTC_SIPR1_REG /* &hD04 */ |
System event polarity register, events 32 to 63. | |
#define | PRU_INTC_SITR0_REG /* &hD80 */ |
System event type register, events 0 to 31. | |
#define | PRU_INTC_SITR1_REG /* &hD84 */ |
System event type register, events 31 to 63. | |
#define | MAX_HOSTS_SUPPORTED /* 10 */ |
The maximal number of host events. | |
#define | PRUSS_UIO_PARAM_VAL_LEN /* 20 */ |
The size of the read buffer. | |
#define | KERNEL_PINMUX_PINS /* "/sys/kernel/debug/pinctrl/44e10800.pinmux/pinmux-pins" */ |
The file with pinmux information. | |
#define | KERNEL_PINMUX_PINX /* "/sys/kernel/debug/pinctrl/44e10800.pinmux-pinctrl-single/pinmux-pins" */ |
Alternative file with pinmux information. | |
#define | O_ACCMODE /* &o003 */ |
File acess mode. | |
#define | O_RDONLY /* &o0 */ |
File read only mode. | |
#define | O_WRONLY /* &o1 */ |
File write only mode. | |
#define | O_RDWR /* &o2 */ |
File read/write mode. | |
#define | O_CREAT /* &o100 ' Not fcntl. */ |
File create mode. | |
#define | O_EXCL /* &o200 ' Not fcntl. */ |
Fail if file exists. | |
#define | O_NOCTTY /* &o400 ' Not fcntl. */ |
No tty mode. | |
#define | O_TRUNC /* &o1000 ' Not fcntl. */ |
File truncate to 0. | |
#define | O_APPEND /* &o2000 */ |
File append mode. | |
#define | O_NONBLOCK /* &o4000 */ |
File non blocking mode. | |
#define | O_NDELAY /* O_NONBLOCK */ |
File no delay mode. | |
#define | O_SYNC /* &o4010000 */ |
File write IO mode. | |
#define | PROT_READ /* &h1 ' */ |
Page can be read. | |
#define | PROT_WRITE /* &h2 */ |
Page can be written. | |
#define | PROT_EXEC /* &h4 */ |
Page can be executed. | |
#define | PROT_NONE /* &h0 */ |
Page can not be accessed. | |
#define | PROT_GROWSDOWN /* &h01000000 */ |
Extend change to start of growsdown vma (mprotect only) | |
#define | PROT_GROWSUP /* &h02000000 */ |
Extend change to start of growsup vma (mprotect only) | |
#define | MAP_SHARED /* &h01 */ |
Share changes. | |
#define | MAP_PRIVATE /* &h02 */ |
Changes are private. | |
#define | MAP_TYPE /* &h0f */ |
Mask for type of mapping. | |
Typedefs | |
typedef UInt32 | size_t |
The size type. | |
typedef Int32 | ssize_t |
The signed size type. | |
typedef Int32 | off_t |
The offset type. | |
typedef ANY_PTR | addr_t |
The adress type. | |
typedef UInt8_PTR | caddr_t |
The character adress type. | |
Functions | |
FUNCTION_CDECL_ALIAS_AS_caddr_t | mmap (BYVAL_AS_addr_t, BYVAL_AS_size_t, BYVAL_AS_Int32, BYVAL_AS_Int32, BYVAL_AS_Int32, BYVAL_AS_off_t) |
Internal: declaration for C runtime function mmap(). | |
FUNCTION_CDECL_ALIAS_AS_ANY_PTR | memcpy (BYVAL_AS_ANY_PTR, BYVAL_AS_ANY_PTR, BYVAL_AS_size_t) |
Internal: declaration for C runtime function memcpy(). | |
FUNCTION_CDECL_ALIAS_AS_Int32 | munmap (BYVAL_AS_ANY_PTR, BYVAL_AS_size_t) |
Internal: declaration for C runtime function munmap(). | |
FUNCTION_CDECL_ALIAS_AS_Int32 | open_ (BYVAL_AS_CONST_ZSTRING_PTR, BYVAL_AS_Int32,...) |
Internal: declaration for C runtime function open(). | |
FUNCTION_CDECL_ALIAS_AS_ssize_t | read_ (BYVAL_AS_Int32, BYVAL_AS_ANY_PTR, BYVAL_AS_size_t) |
Internal: declaration for C runtime function read(). | |
FUNCTION_CDECL_ALIAS_AS_Int32 | close_ (BYVAL_AS_Int32) |
Internal: declaration for C runtime function close(). | |
SUB_CDECL | __prussintc_set_cmr (BYVAL_AS_UInt32_PTR Intc, BYVAL_AS_UInt16 Event, BYVAL_AS_UInt16 Ch) |
Internal: set CMR register. More... | |
SUB_CDECL | __prussintc_set_hmr (BYVAL_AS_UInt32_PTR Intc, BYVAL_AS_UInt16 Ch, BYVAL_AS_UInt16 Host) |
Internal: set HMR register. More... | |
FUNCTION_CDECL_AS_Int32 | __prussdrv_memmap_init (BYVAL_AS_Int32 IrqFd) |
Internal: initialize memory pointers. More... | |
FUNCTION_CDECL_ALIAS_AS_Int32 | prussdrv_open (BYVAL_AS_UInt32 Irq) |
Open an kernel driver interrupt file. More... | |
FUNCTION_CDECL_ALIAS_AS_Int32 | prussdrv_pru_enable (BYVAL_AS_UInt32 PruId, BYVAL_AS_UInt32 PCnt=0) |
Enable one PRU subsystem. More... | |
FUNCTION_CDECL_ALIAS_AS_Int32 | prussdrv_pru_disable (BYVAL_AS_UInt32 PruId) |
Disable one PRU. More... | |
FUNCTION_CDECL_ALIAS_AS_Int32 | prussdrv_pru_reset (BYVAL_AS_UInt32 PruId) |
Reset one PRU. More... | |
FUNCTION_CDECL_ALIAS_AS_ZSTRING_PTR | prussdrv_pru_resume (BYVAL_AS_UInt32 PruId) |
Resume one PRU. More... | |
FUNCTION_CDECL_ALIAS_AS_Int32 | prussdrv_pru_write_memory (BYVAL_AS_UInt32 RamId, BYVAL_AS_UInt32 Offs, BYVAL_AS_CONST_UInt32_PTR Dat, BYVAL_AS_UInt32 Size) |
Write data to PRUSS memory. More... | |
FUNCTION_CDECL_ALIAS_AS_Int32 | prussdrv_pruintc_init (BYVAL_AS_CONST_tpruss_intc_initdata_PTR DatIni) |
Initialize the interrupt controller. More... | |
SUB_CDECL_ALIAS | prussdrv_pru_send_event (BYVAL_AS_UInt32 Event) |
Send a system event to PRUSS. More... | |
FUNCTION_CDECL_ALIAS_AS_UInt32 | prussdrv_pru_wait_event (BYVAL_AS_UInt32 Irq) |
Wait for an event. More... | |
SUB_CDECL_ALIAS | prussdrv_pru_clear_event (BYVAL_AS_UInt32 Irq, BYVAL_AS_UInt32 Event) |
Clear a pending system event. More... | |
SUB_CDECL_ALIAS | prussdrv_map_extmem (BYVAL_AS_ANY_PTR_PTR Addr) |
Map external ram (ERam). More... | |
FUNCTION_CDECL_ALIAS_AS_UInt32 | prussdrv_extmem_sIze () |
Get size of external memory. More... | |
FUNCTION_CDECL_ALIAS_AS_Int32 | prussdrv_map_prumem (BYVAL_AS_UInt32 RamId, BYVAL_AS_ANY_PTR_PTR Addr) |
Adress pointer mapping. More... | |
FUNCTION_CDECL_ALIAS_AS_UInt32 | prussdrv_get_phys_addr (BYVAL_AS_CONST_ANY_PTR Addr) |
Compute physical adress. More... | |
SUB_CDECL_ALIAS | prussdrv_exIt () |
End the driver session. More... | |
FUNCTION_CDECL_AS_ZSTRING_PTR | find_claims (BYVAL_AS_UInt32 Typ) |
Fetch pinmuxing claims from kernel. More... | |
FUNCTION_CDECL_AS_ZSTRING_PTR | setPin_lkm (BYVAL_AS_Pruio__PTR Top, BYVAL_AS_UInt8 Ball, BYVAL_AS_UInt8 Mo) |
Set a new pin configuration for Pocket BeagleBone(internal). More... | |
FUNCTION_CDECL_AS_ZSTRING_PTR | setPin_lkm_bb (BYVAL_AS_Pruio__PTR Top, BYVAL_AS_UInt8 Ball, BYVAL_AS_UInt8 Mo) |
Set a new pin configuration for BeagleBone boards(internal). More... | |
FUNCTION_CDECL_AS_ZSTRING_PTR | setPin_save (BYVAL_AS_Pruio__PTR Top, BYVAL_AS_UInt8 Ball, BYVAL_AS_UInt8 Mo) |
Set a new pin configuration (internal). More... | |
FUNCTION_CDECL_AS_ZSTRING_PTR | setPin_nogo (BYVAL_AS_Pruio__PTR Top, BYVAL_AS_UInt8 Ball, BYVAL_AS_UInt8 Mo) |
Pinmuxing callback for setPin interface (internal). More... | |
FUNCTION_CDECL_AS_ZSTRING_PTR | setPin_dtbo (BYVAL_AS_Pruio__PTR Top, BYVAL_AS_UInt8 Ball, BYVAL_AS_UInt8 Mo) |
Pinmuxing for old style device tree multipins (internal). More... | |
Variables | |
tprussdrv | PRUSSDRV |
The data structure, global at module level. | |
Source code for kernel driver handling.
In previous versions libpruio was dependant on libprussdrv, a driver library for the uio_pruss
kernel module. Since this driver isn't available in the upstream Debian repositories, compiling from source was required for users. Once I started to fix some downsides in the original library code, I came up with this code here, reduced to the bare minimum and mostly compatible to the original API. Find further information on the PRUSS, the pasm assembler and the original prussdrv function in the am335x_pru_package at GitHub.
In the second part the utility functions for the new loadable kernel module are included.
Definition in file pruio_prussdrv.bas.
FUNCTION_CDECL_AS_Int32 __prussdrv_memmap_init | ( | BYVAL_AS_Int32 | IrqFd | ) |
Internal: initialize memory pointers.
This internal function reads the files from uio_pruss
kernel driver and computes pointers to the different memory areas. In contrast to the original libprussdrv code, the function here gets called only once.
Definition at line 189 of file pruio_prussdrv.bas.
SUB_CDECL __prussintc_set_cmr | ( | BYVAL_AS_UInt32_PTR | Intc, |
BYVAL_AS_UInt16 | Event, | ||
BYVAL_AS_UInt16 | Ch | ||
) |
Internal: set CMR register.
Intc | The interrupt controller number. |
Event | The event number. |
Ch | The channel to set |
This is an internal service function.
Definition at line 158 of file pruio_prussdrv.bas.
SUB_CDECL __prussintc_set_hmr | ( | BYVAL_AS_UInt32_PTR | Intc, |
BYVAL_AS_UInt16 | Ch, | ||
BYVAL_AS_UInt16 | Host | ||
) |
Internal: set HMR register.
Intc | The interrupt controller number. |
Ch | The channel to set |
Host | The host number. |
This is an internal service function.
Definition at line 173 of file pruio_prussdrv.bas.
FUNCTION_CDECL_AS_ZSTRING_PTR find_claims | ( | BYVAL_AS_UInt32 | Typ | ) |
Fetch pinmuxing claims from kernel.
The function greps the kernel claim for CPU balls by parsing the output from /sys/kernel/debug/pinctrl/44e10800.pinmux/pinmux-pins
. Free and claimed CPU balls (named pins by kernel) get identified, and the owners of claimed balls get collected in a STRING
variable in a condensed form. Each owner name is stored only once, no double entries.
Definition at line 599 of file pruio_prussdrv.bas.
SUB_CDECL_ALIAS prussdrv_exIt | ( | ) |
End the driver session.
The procedure unmaps all memory and closes all interrupt files.
Definition at line 576 of file pruio_prussdrv.bas.
FUNCTION_CDECL_ALIAS_AS_UInt32 prussdrv_extmem_sIze | ( | ) |
Get size of external memory.
The procedure returns the size of the external memory. The kernel driver uio_pruss
allocates a block of coherent memory. This function returns the size if this block. See section ERam for details.
Definition at line 517 of file pruio_prussdrv.bas.
FUNCTION_CDECL_ALIAS_AS_UInt32 prussdrv_get_phys_addr | ( | BYVAL_AS_CONST_ANY_PTR | Addr | ) |
Compute physical adress.
Addr | Memory pointer or mmap value |
The function computes the physical adress from a prussdrv memory pointer or from an value returned form a mmap() call.
Definition at line 556 of file pruio_prussdrv.bas.
SUB_CDECL_ALIAS prussdrv_map_extmem | ( | BYVAL_AS_ANY_PTR_PTR | Addr | ) |
Map external ram (ERam).
Addr | The pointer to set. |
The procedure maps the external memory allocated by the uio_pruss
kernel driver to pointer parameter. Memory is then accessed by an array.
Definition at line 503 of file pruio_prussdrv.bas.
FUNCTION_CDECL_ALIAS_AS_Int32 prussdrv_map_prumem | ( | BYVAL_AS_UInt32 | RamId, |
BYVAL_AS_ANY_PTR_PTR | Addr | ||
) |
Adress pointer mapping.
RamId | The memory ID. |
Addr | The pointer to set. |
The procedure maps PRU memory (DRAM, IRAM, SHARED) to the pointer parameter. Memory is then accessed by an array.
Definition at line 535 of file pruio_prussdrv.bas.
FUNCTION_CDECL_ALIAS_AS_Int32 prussdrv_open | ( | BYVAL_AS_UInt32 | Irq | ) |
Open an kernel driver interrupt file.
Irq | The interrupt number. |
The function tries to open an interrupt file dev/uio[0-7]
, corresponding to Host[2-9] of the PRU INTC. In case of a problem a negative error number gets returned.
At least one call to that function is mandatory, since it initializes the memory. Call it again for each interrupt you need. A single call to prussdrv_exIt() closes all open files.
Definition at line 250 of file pruio_prussdrv.bas.
SUB_CDECL_ALIAS prussdrv_pru_clear_event | ( | BYVAL_AS_UInt32 | Irq, |
BYVAL_AS_UInt32 | Event | ||
) |
Clear a pending system event.
Irq | The host interrupt. |
Event | The system event. |
The procedure clears an event, previously sent from PRU to ARM. Once a system event occurs, the registers have to get released, in order to get ready for the next event.
Definition at line 487 of file pruio_prussdrv.bas.
FUNCTION_CDECL_ALIAS_AS_Int32 prussdrv_pru_disable | ( | BYVAL_AS_UInt32 | PruId | ) |
Disable one PRU.
PruId | The PRUSS number. |
The function disables a PRU subsystem by stopping its clock.
Definition at line 292 of file pruio_prussdrv.bas.
FUNCTION_CDECL_ALIAS_AS_Int32 prussdrv_pru_enable | ( | BYVAL_AS_UInt32 | PruId, |
BYVAL_AS_UInt32 | PCnt = 0 |
||
) |
Enable one PRU subsystem.
PruId | The PRU number. |
PCnt | The byte adress where to start (defaults to 0 = zero). |
The function enables a PRU subsystem by starting its clock. Parameter PCnt
specifies a byte address where to start, as used in function prussdrv_pru_write_memory().
.origin 7
the matching PCnt
value is 28 = 7 * 4.Definition at line 274 of file pruio_prussdrv.bas.
FUNCTION_CDECL_ALIAS_AS_Int32 prussdrv_pru_reset | ( | BYVAL_AS_UInt32 | PruId | ) |
Reset one PRU.
PruId | The PRUSS number. |
The function forces a reset at a PRU subsystem by writing 0 (zero) to the control register.
Definition at line 309 of file pruio_prussdrv.bas.
FUNCTION_CDECL_ALIAS_AS_ZSTRING_PTR prussdrv_pru_resume | ( | BYVAL_AS_UInt32 | PruId | ) |
Resume one PRU.
PruId | The PRUSS number. |
The function restarts a PRUSS after SLP 1
or HALT
command. The PRU re-starts executing the next instruction.
Definition at line 326 of file pruio_prussdrv.bas.
SUB_CDECL_ALIAS prussdrv_pru_send_event | ( | BYVAL_AS_UInt32 | Event | ) |
Send a system event to PRUSS.
Event | The interrupt number to send. |
The procedure sets the interrupt registers to send an event to the PRUSS.
Definition at line 454 of file pruio_prussdrv.bas.
FUNCTION_CDECL_ALIAS_AS_UInt32 prussdrv_pru_wait_event | ( | BYVAL_AS_UInt32 | Irq | ) |
Wait for an event.
Irq | The event number to wait for. |
The function blocks the calling thread until the corresponding event input occurs.
Definition at line 470 of file pruio_prussdrv.bas.
FUNCTION_CDECL_ALIAS_AS_Int32 prussdrv_pru_write_memory | ( | BYVAL_AS_UInt32 | RamId, |
BYVAL_AS_UInt32 | Offs, | ||
BYVAL_AS_CONST_UInt32_PTR | Dat, | ||
BYVAL_AS_UInt32 | Size | ||
) |
Write data to PRUSS memory.
RamId | The ID of the memory. |
Offs | The offset to start at. |
Dat | A pointer to the data. |
Size | The size of data in bytes. |
The function writes a chunk of data to PRUSS memory (DRam, IRam or SRam), depending on parameter RamId. The start writing position gets specified by parameter Offs.
Definition at line 350 of file pruio_prussdrv.bas.
FUNCTION_CDECL_ALIAS_AS_Int32 prussdrv_pruintc_init | ( | BYVAL_AS_CONST_tpruss_intc_initdata_PTR | DatIni | ) |
Initialize the interrupt controller.
DatIni | Data structure to initialize |
The function initializes and enables the PRU interrupt controller. The input is a structure of arrays that determine which system events are enabled and how each is mapped to a host event. This structure is pre-defined as a member variable PTR PruIo::IntcInit in header file src/pruio/pruio.bi
. Experts can adapted the default arrays to meet custom needs before the CTOR PruIo::PruIo() call, but note that wrong settings can cause serious malfunctions.
Definition at line 385 of file pruio_prussdrv.bas.
FUNCTION_CDECL_AS_ZSTRING_PTR setPin_dtbo | ( | BYVAL_AS_Pruio__PTR | Top, |
BYVAL_AS_UInt8 | Ball, | ||
BYVAL_AS_UInt8 | Mo | ||
) |
Pinmuxing for old style device tree multipins (internal).
Top | The PruIo instance. |
Ball | The CPU ball number (use macros from pruio_pins.bi). |
Mo | The new modus to set, or PRUIO_PIN_RESET to reset |
Like function setPin_lkm(), this function sets a new pin mode for a CPU ball. Therefor the SysFs files from the OCP pinmux helper are used. That means the pinmux capabilities are handled by the kernel. You have to load an overlay blob and export the pins, before you can set one of the prepared configurations.
The SysFs folder tree changed between kernel versions 3.8 and 4.x. This function handles either of the folder structures. When the desired pin (ball) isn't available in the overlay blob, an error message gets returned, containing the pin number (or CPU ball#) and the missing state.
Definition at line 818 of file pruio_prussdrv.bas.
FUNCTION_CDECL_AS_ZSTRING_PTR setPin_lkm | ( | BYVAL_AS_Pruio__PTR | Top, |
BYVAL_AS_UInt8 | Ball, | ||
BYVAL_AS_UInt8 | Mo | ||
) |
Set a new pin configuration for Pocket BeagleBone(internal).
Top | The toplevel PruIo instance. |
Ball | The CPU ball number (use macros from pruio_pins.bi). |
Mo | The new modus to set. |
Callback function for PruIo::setPin() interface to set a new pin (or CPU ball) configuration on PocketBeagleBone hardware, using the new style LKM (loadable kernel module) method.
Since the double pins at this hardware are connections between digital and analog pins, no special action is required regarding pinmuxing (as in for BeagleBone hardware).
It's used when the constructor PruIo::PruIo() finds the SysFs entry from the LKM, and has write access (needs administrator privileges = sudo ...
). Since
There're no restriction for pinmuxing. Each CPU ball in the range zero to PRUIO_AZ_BALL can get set to any mode. Even claimed pins or CPU balls can get set to defined or undefined modes. The function executes faster than device tree pinmuxing (no OPEN ... CLOSE
), boot-time is shorter (no overlay loading) and less memory is used.
Definition at line 665 of file pruio_prussdrv.bas.
FUNCTION_CDECL_AS_ZSTRING_PTR setPin_lkm_bb | ( | BYVAL_AS_Pruio__PTR | Top, |
BYVAL_AS_UInt8 | Ball, | ||
BYVAL_AS_UInt8 | Mo | ||
) |
Set a new pin configuration for BeagleBone boards(internal).
Top | The toplevel PruIo instance. |
Ball | The CPU ball number (use macros from pruio_pins.bi). |
Mo | The new modus to set. |
Callback function for PruIo::setPin() interface to set a new pin (or CPU ball) configuration on BeagleBone hardware (Black, BlackWireless, Green, White), using the new style LKM (loadable kernel module) method.
Since this hardware has some digital header pins with double CPU ball connections, both CPU balls have to be set. First, the unused CPU ball gets configured to gpio input mode without pull-up/pull-down resistor, before the other pin gets set to the desired mode.
Definition at line 700 of file pruio_prussdrv.bas.
FUNCTION_CDECL_AS_ZSTRING_PTR setPin_nogo | ( | BYVAL_AS_Pruio__PTR | Top, |
BYVAL_AS_UInt8 | Ball, | ||
BYVAL_AS_UInt8 | Mo | ||
) |
Pinmuxing callback for setPin interface (internal).
Top | The PruIo instance. |
Ball | The CPU ball number (use macros from pruio_pins.bi). |
Mo | The new modus to set, or PRUIO_PIN_RESET to reset |
This function is a dummy for the setPin interface in PruIo structure. It gets used when no pinmuxing capability was found on the system: neither a universal device tree overlay was loaded, nor the loadable kernel module is available (may be loaded, but no administrator privileges). The function does nothing, but returns an error message.
Definition at line 789 of file pruio_prussdrv.bas.
FUNCTION_CDECL_AS_ZSTRING_PTR setPin_save | ( | BYVAL_AS_Pruio__PTR | Top, |
BYVAL_AS_UInt8 | Ball, | ||
BYVAL_AS_UInt8 | Mo | ||
) |
Set a new pin configuration (internal).
Top | The PruIo instance. |
Ball | The CPU ball number (use macros from pruio_pins.bi). |
Mo | The new modus to set, or PRUIO_PIN_RESET to reset |
Callback function for the PruIo::setPin() interface. It's a wrapper around setPin_lkm() functions, that checks the pin claiming of the kernel first. Only mode changes for unclaimed pins (or CPU balls) get executed.
Claims from the kernel get fetched once by calling the function with an invalid Ball parameter (> PRUIO_AZ_BALL
). This gets executed by the constructor PruIo::PruIo(). The function doesn't notice changes in kernel claiming at runtime. You can re-fetch the claims when needed.
Definition at line 752 of file pruio_prussdrv.bas.