rasProject_01 / weSweetHome  R. 240
process control       /     RasPi software         by   weinert-automation
Loading...
Searching...
No Matches
weShareMem.c File Reference

Shared memory on Raspberry Pis. More...

#include "weShareMem.h"

Macros

#define ANZ_SEMAS
 Standard semaphore set of three (3..9)
 
#define SEMAPHORE_KEY
 Semaphore unique key "KÇÏfig00".
 
#define SHARED_MEMORY_KEY
 Shared memory key "Buffer00".
 
#define SHARED_MEMORY_SIZE
 Shared memory size; default: 256.
 

Functions

int deleteSemas ()
 Delete the one semaphore set. More...
 
int deleteSharedMem ()
 Delete and detach the shared memory. More...
 
int detachSharedMem ()
 Detach the shared memory.
 
int getSemas ()
 Get the one semaphore set. More...
 
int initialiseSemas ()
 Initialise the one semaphore set. More...
 
void * initialiseSharedMem ()
 Initialise shared memory. More...
 
int semaphoreClt (int const semNum, int const op, semCtlPar_t par)
 Control semaphores of the set. More...
 
int semaphoreLock (int const semNum, int const ms)
 Lock one semaphore of the set. More...
 
int semaphoreOperation (int const semNum, int op, int const ms)
 Operation on one semaphore of the set. More...
 
int semaphoreUnlock (int const semNum)
 Unlock one semaphore of the set. More...
 

Variables

const semCtlPar_t VAL0
 value 0 for SETVAL
 
const semCtlPar_t VAL1
 value 1 for SETVAL
 
const semCtlPar_t VAL9
 value 9 for SETVAL
 

Detailed Description

Shared memory on Raspberry Pis.

Copyright (c) 2017 Albrecht Weinert
weinert-automation.de a-weinert.de
/ / /\
/ /___ / \ |
\ /____\ /____\ | _|__
\ /\ / \ / \| |
\/ \/ \__/ \__/|_

Revision history

Rev. 236 2.02.2021
Rev. 73+ 16.11.2017 : new
Rev. 75 30.11.2017 : signal semaphore initialised to 0
Rev. 188 15.10.2018 : minor typos

cross-compile by:

arm-linux-gnueabihf-gcc -DMCU=BCM2837 -I./include -c -o weRasp/weShareMem.o weRasp/weShareMem.c

For documentation see also the include file weShareMem.h

Function Documentation

◆ getSemas()

int getSemas ( )

Get the one semaphore set.

The one semaphore set, if existing, will be registered and used as is.

Returns
0: OK found existing semaphore set; -1: error (errno set and errorText generated)

◆ initialiseSemas()

int initialiseSemas ( )

Initialise the one semaphore set.

The number of semaphores in the set is ANZ_SEMAS (default three). The one semaphore set, if existing, will be registered and used as is. If this is not possible it will be made and initialised.

Hint: This function has two OK return values!

Returns
1: OK semaphore set made new; 0: OK found existing semaphore set; -1: error (errno set and errorText generated)

◆ deleteSemas()

int deleteSemas ( )

Delete the one semaphore set.

Server operation only.

Returns
0: OK; -1: error (errno set and errorText generated)

◆ semaphoreOperation()

int semaphoreOperation ( int const  semNum,
int const  op,
int  ms 
)

Operation on one semaphore of the set.

Parameters
semNumthe semaphore number in the set (0..ANZ_SEMAS -1)
opthe semaphore operation
msif 2..20000 a timeout in ms
Returns
0: OK; -1: error (errno set and errorText generated)

◆ semaphoreLock()

int semaphoreLock ( int const  semNum,
int  ms 
)

Lock one semaphore of the set.

Parameters
semNumthe semaphore number in the set (0..ANZ_SEMAS -1)
msif 2..20000 a timeout in ms
Returns
0: OK; -1: error (errno set and errorText generated)

◆ semaphoreUnlock()

int semaphoreUnlock ( int const  semNum)

Unlock one semaphore of the set.

Parameters
semNumthe semaphore number in the set (0..ANZ_SEMAS -1)
Returns
0: OK; -1: error (errno set and errorText generated)

◆ semaphoreClt()

int semaphoreClt ( int const  semNum,
int const  op,
semCtlPar_t  par 
)

Control semaphores of the set.

Parameters
semNumthe semaphore number in the set (0..ANZ_SEMAS -1)
opthe semaphore operation, like e.g. SETVAL
parop's parameter if any
Returns
0: OK; -1: error (errno set and errorText generated)

◆ initialiseSharedMem()

void * initialiseSharedMem ( )

Initialise shared memory.

Make or get and attach. return pointer to attached shared memory or (void *)-1

◆ deleteSharedMem()

int deleteSharedMem ( )

Delete and detach the shared memory.

Server operation only.