1 /* 2 * Copyright (c) 2020-2021 Huawei Device Co., Ltd. 3 * 4 * HDF is dual licensed: you can use it either under the terms of 5 * the GPL, or the BSD license, at your option. 6 * See the LICENSE file in the root of this repository for complete details. 7 */ 8 9 #ifndef WATCHDOG_CORE_H 10 #define WATCHDOG_CORE_H 11 12 #include "hdf_base.h" 13 #include "hdf_device_desc.h" 14 #include "osal_spinlock.h" 15 16 #ifdef __cplusplus 17 #if __cplusplus 18 extern "C" { 19 #endif 20 #endif /* __cplusplus */ 21 22 struct WatchdogCntlr; 23 struct WatchdogMethod; 24 25 struct WatchdogCntlr { 26 struct IDeviceIoService service; 27 struct HdfDeviceObject *device; 28 OsalSpinlock lock; 29 struct WatchdogMethod *ops; 30 int16_t wdtId; 31 void *priv; 32 }; 33 34 struct WatchdogMethod { 35 int32_t (*getStatus)(struct WatchdogCntlr *wdt, int32_t *status); 36 int32_t (*setTimeout)(struct WatchdogCntlr *wdt, uint32_t seconds); 37 int32_t (*getTimeout)(struct WatchdogCntlr *wdt, uint32_t *seconds); 38 int32_t (*start)(struct WatchdogCntlr *wdt); 39 int32_t (*stop)(struct WatchdogCntlr *wdt); 40 int32_t (*feed)(struct WatchdogCntlr *wdt); 41 int32_t (*getPriv)(struct WatchdogCntlr *wdt); 42 void (*releasePriv)(struct WatchdogCntlr *wdt); 43 }; 44 45 /** 46 * @brief Add a new WatchdogCntlr to HDF. 47 * 48 * @param cntlr The watchdog controller to be added. 49 * 50 * @return Returns 0 on success; returns a negative value otherwise. 51 * @since 1.0 52 */ 53 int32_t WatchdogCntlrAdd(struct WatchdogCntlr *cntlr); 54 55 /** 56 * @brief Remove the watchdog controller from HDF. 57 * 58 * @param cntlr The watchdog controller to be removed. 59 * 60 * @since 1.0 61 */ 62 void WatchdogCntlrRemove(struct WatchdogCntlr *cntlr); 63 64 65 /** 66 * @brief Turn HdfDeviceObject to an Watchdog. 67 * 68 * @param device Indicates a HdfDeviceObject. 69 * 70 * @return Retrns the pointer of the WatchdogCntlr on success; returns NULL otherwise. 71 * @since 1.0 72 */ WatchdogCntlrFromDevice(const struct HdfDeviceObject * device)73static inline struct WatchdogCntlr *WatchdogCntlrFromDevice(const struct HdfDeviceObject *device) 74 { 75 return (device == NULL) ? NULL : (struct WatchdogCntlr *)device->service; 76 } 77 78 /** 79 * @brief Turn WatchdogCntlr to a HdfDeviceObject. 80 * 81 * @param wdt Indicates the WATCHDOG wdt device. 82 * 83 * @return Retrns the pointer of the HdfDeviceObject on success; returns NULL otherwise. 84 * @since 1.0 85 */ WatchdogCntlrToDevice(const struct WatchdogCntlr * wdt)86static inline struct HdfDeviceObject *WatchdogCntlrToDevice(const struct WatchdogCntlr *wdt) 87 { 88 return (wdt == NULL) ? NULL : wdt->device; 89 } 90 91 int32_t WatchdogCntlrGetStatus(struct WatchdogCntlr *cntlr, int32_t *status); 92 93 int32_t WatchdogCntlrStart(struct WatchdogCntlr *cntlr); 94 95 int32_t WatchdogCntlrStop(struct WatchdogCntlr *cntlr); 96 97 int32_t WatchdogCntlrSetTimeout(struct WatchdogCntlr *cntlr, uint32_t seconds); 98 99 int32_t WatchdogCntlrGetTimeout(struct WatchdogCntlr *cntlr, uint32_t *seconds); 100 101 int32_t WatchdogCntlrFeed(struct WatchdogCntlr *cntlr); 102 103 int32_t WatchdogGetPrivData(struct WatchdogCntlr *cntlr); 104 105 int32_t WatchdogReleasePriv(struct WatchdogCntlr *cntlr); 106 107 #ifdef __cplusplus 108 #if __cplusplus 109 } 110 #endif 111 #endif /* __cplusplus */ 112 113 #endif /* WATCHDOG_CORE_H */ 114