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

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

#include "sysBasic.h"
#include <sys/file.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 useIOlock
 Do use IO lock. 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. 253 9.10.2023
Rev. 227 12.08.2020 : common functions collected and consolidated
Rev. 243 09.09.2022 : typo

This is a supplementary basic library to handle locks and a watchdog.

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

◆ 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

◆ 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

◆ 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
extern

Do use IO lock.

When ON (default) justLock, openLock and closeLock try to fulfil their mission. When OFF they do nothing (except saying OK). flag to use IO (singleton) lock; default on

Do use IO lock.

◆ lockFd

int lockFd
extern

Lock file handle.

Do not use directly.

◆ useWatchdog

int useWatchdog
extern

flag to use watchdog; default ON

flag to use watchdog; default ON