taler-xotp_fw

xOTP generator firmware
Log | Files | Refs | Submodules | README

clockInterface.h (2519B)


      1 /**
      2  * @file clockInterface.h
      3  * @author Adrian STEINER (steia19@bfh.ch)
      4  * @brief Clock interface class to get and set the current time from the device
      5  * time.
      6  * @version 0.1
      7  * @date 17-02-2025
      8  *
      9  * @copyright (C) 2025 Adrian STEINER
     10  * This program is free software: you can redistribute it and/or modify
     11  * it under the terms of the GNU General Public License as published by
     12  * the Free Software Foundation, either version 3 of the License, or
     13  * (at your option) any later version.
     14  *
     15  * This program is distributed in the hope that it will be useful,
     16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
     17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     18  * GNU General Public License for more details.
     19  *
     20  * You should have received a copy of the GNU General Public License
     21  * along with this program.  If not, see <https: //www.gnu.org/licenses/>.
     22  *
     23  */
     24 
     25 #ifndef CLOCK_INTERFACE_H
     26 #define CLOCK_INTERFACE_H
     27 
     28 #ifdef __cplusplus
     29 extern "C" {
     30 #endif
     31 
     32 #include <stdint.h>
     33 
     34 /**
     35  * @brief Clock power callback function
     36  *
     37  */
     38 typedef void (*clockPwrCB)(void);
     39 
     40 /**
     41  * @brief Clock get current time callback function
     42  *
     43  * @return Returns the current time, 0 in case of an error
     44  *
     45  */
     46 typedef uint64_t (*clockGetTimeCB)(void);
     47 
     48 /**
     49  * @brief Set the current time to the clock
     50  * @param uint64_t the time to set
     51  *
     52  */
     53 typedef uint8_t (*clockSetTimeCB)(uint64_t);
     54 
     55 /**
     56  * @brief Clock interface handler
     57  *
     58  */
     59 typedef struct {
     60   uint64_t lastUpdateTime;    ///< Saves the last time when setUnixTime was used
     61   clockPwrCB powerOn;         ///< Enables the clock
     62   clockPwrCB powerOff;        ///< Disables the clock
     63   clockGetTimeCB getUnixTime; ///< Get the current unix time
     64   clockSetTimeCB setUnixTime; ///< Set (synchronize) the current unix time
     65 } clockInterface;
     66 
     67 /**
     68  * @brief Initialise the clock interface
     69  *
     70  * @param interfaceHandler The clock interface structure to initialise
     71  * @param powerOnCB Clock power on callback
     72  * @param powerOffCB Clock power off callback
     73  * @param getUnixTimeCB Clock get time callback
     74  * @param setUnixTimeCB Clock set time callback
     75  * @return uint8_t EXIT_SUCCESS in success, EXIT_FAILURE otherwise
     76  */
     77 uint8_t clock_initInterface(clockInterface *interfaceHandler,
     78                             clockPwrCB powerOnCB,
     79                             clockPwrCB powerOffCB,
     80                             clockGetTimeCB getUnixTimeCB,
     81                             clockSetTimeCB setUnixTimeCB);
     82 
     83 #ifdef __cplusplus
     84 }
     85 #endif
     86 
     87 #endif /* CLOCK_INTERFACE_H*/