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

Process control helpers for Raspberry Pi: lock and watchdog. More...

#include "weLockWatch.h"

Functions

void closeLock (void)
 Unlock the lock file

 
int initWatchdog (void)
 Get and initialise or arm the watchdog. More...
 
int justInitWatchdog (void)
 Get and initialise or arm the watchdog. More...
 
int justLock (char const *lckPiGpioFil)
 Open and lock the lock file. More...
 
int openLock (char const *lckPiGpioFil, uint8_t const perr)
 Open and lock the lock file. More...
 
void stopWatchdog (void)
 Stop and disarm the watchdog. More...
 
void triggerWatchdog (void)
 Trigger the watchdog. More...
 

Variables

int lockFd
 Lock file handle. More...
 
int retCode
 Basic start-up function failure. More...
 
int useIOlock
 flag to use IO (singleton) lock; default on More...
 
int useWatchdog
 flag to use watchdog; default on More...
 

Detailed Description

Process control helpers for Raspberry Pi: lock and watchdog.

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

Revision history

Rev. 236 2.02.2021
Rev. 227 12.08.2020 : common functions collected and consolidated

cross-compile by:

arm-linux-gnueabihf-gcc -DF_CPU=1500000000 -DPLATFORM=raspberry_04
-DMCU=BCM2711 -DTARGET=pi4you -I./include
-c -o weRasp/weLockWatch.o weRasp/weLockWatch.c

This is a supplementary library basic library to be used in conjunction with the pigpio library (link: -lpigpiod_if2 -lrt). For documentation see the include file weLOckWatch.h .

Function Documentation

◆ justLock()

int justLock ( char const *  lckPiGpioFil)

Open and lock the lock file.

This function is the basic implementation of openLock. Applications not wanting its optional logging or doing their own should use this function directly.

Parameters
lckPiGpioFillock file name
Returns
0: OK, locked; 97: fd does not exist; 98: can't be locked

◆ openLock()

int openLock ( char const *  lckPiGpioFil,
uint8_t const  perr 
)

Open and lock the lock file.

This function may use logging and streams not available on smaller applications. Those applications not wanting that optional logging or doing their own should use the function justLock().

Parameters
lckPiGpioFillock file path name
perrmake error message when lock file does not exist or can't be locked
Returns
0: OK, locked; 97: fd does not exist; 98: can't be locked

◆ justInitWatchdog()

int justInitWatchdog ( void  )

Get and initialise or arm the watchdog.

This function justInitWatchdog() is the basic implementation of initWatchdog() without logging failure.

Returns
0: watchdog OK or not to be used (useWatchdog OFF); 1: error while trying to get the watchdog

◆ initWatchdog()

int initWatchdog ( void  )

Get and initialise or arm the watchdog.

If the watchdog is to be used, i.e. useWatchdog is ON. this function tries to get it. Otherwise it does nothing but return 0 (success).

On no success 1 is returned and useWatchdog is set OFF and the misfortune is logged. Use justInitWatchdog() :: for silence.

Returns
0: watchdog OK or not to be used (useWatchdog OFF); 1: error while trying to get the watchdog

◆ stopWatchdog()

void stopWatchdog ( void  )

Stop and disarm the watchdog.

If the watchdog is to be used, i.e. useWatchdog is ON, this function stops and disarms it.
useWatchdog is then OFF .

◆ triggerWatchdog()

void triggerWatchdog ( void  )

Trigger the watchdog.

If the watchdog is to be used, i.e. useWatchdog is ON, this function triggers it.
If the watchdog is armed (by initWatchdog()) not triggering it at least once about every 15 s will lead to system reset.

Variable Documentation

◆ useIOlock

int useIOlock

flag to use IO (singleton) lock; default on

Do use IO lock.

◆ lockFd

int lockFd

Lock file handle.

Do not use directly.

◆ retCode

int retCode

Basic start-up function failure.

Allows for compact code without saving the (error) return:
if (openLock(lckPiGpioPth, ON)) return retCode;

Storage for return/error codes. Used by: openLock(char const *, uint8_t) theCyclistStart(int) theCyclistWaitEnd()

Value: 0: OK, else: error

◆ useWatchdog

int useWatchdog

flag to use watchdog; default on

flag to use watchdog; default ON