1 /**
2  * @file
3  *
4  * @brief Public APIs to get device Information.
5  */
6 
7 /*
8  * Copyright (c) 2018 Alexander Wachter
9  *
10  * SPDX-License-Identifier: Apache-2.0
11  */
12 
13 #ifndef ZEPHYR_INCLUDE_DRIVERS_HWINFO_H_
14 #define ZEPHYR_INCLUDE_DRIVERS_HWINFO_H_
15 
16 /**
17  * @brief Hardware Information Interface
18  * @defgroup hwinfo_interface Hardware Info Interface
19  * @ingroup io_interfaces
20  * @{
21  */
22 
23 #include <zephyr/types.h>
24 #include <sys/types.h>
25 #include <stddef.h>
26 #include <errno.h>
27 #include <zephyr/kernel.h>
28 
29 #ifdef __cplusplus
30 extern "C" {
31 #endif
32 
33 #define RESET_PIN				BIT(0)
34 #define RESET_SOFTWARE				BIT(1)
35 #define RESET_BROWNOUT				BIT(2)
36 #define RESET_POR				BIT(3)
37 #define RESET_WATCHDOG				BIT(4)
38 #define RESET_DEBUG				BIT(5)
39 #define RESET_SECURITY				BIT(6)
40 #define RESET_LOW_POWER_WAKE			BIT(7)
41 #define RESET_CPU_LOCKUP			BIT(8)
42 #define RESET_PARITY				BIT(9)
43 #define RESET_PLL				BIT(10)
44 #define RESET_CLOCK				BIT(11)
45 #define RESET_HARDWARE				BIT(12)
46 #define RESET_USER				BIT(13)
47 #define RESET_TEMPERATURE			BIT(14)
48 
49 /**
50  * @brief Copy the device id to a buffer
51  *
52  * This routine copies "length" number of bytes of the device ID to the buffer.
53  * If the device ID is smaller then length, the rest of the buffer is left unchanged.
54  * The ID depends on the hardware and is not guaranteed unique.
55  *
56  * Drivers are responsible for ensuring that the ID data structure is a
57  * sequence of bytes.  The returned ID value is not supposed to be interpreted
58  * based on vendor-specific assumptions of byte order. It should express the
59  * identifier as a raw byte sequence, doing any endian conversion necessary so
60  * that a hex representation of the bytes produces the intended serial number.
61  *
62  * @param buffer  Buffer to write the ID to.
63  * @param length  Max length of the buffer.
64  *
65  * @retval size of the device ID copied.
66  * @retval -ENOSYS if there is no implementation for the particular device.
67  * @retval any negative value on driver specific errors.
68  */
69 __syscall ssize_t hwinfo_get_device_id(uint8_t *buffer, size_t length);
70 
71 ssize_t z_impl_hwinfo_get_device_id(uint8_t *buffer, size_t length);
72 
73 /**
74  * @brief      Retrieve cause of device reset.
75  *
76  * @param      cause  OR'd `reset_cause` flags
77  *
78  * This routine retrieves the flags that indicate why the device was reset.
79  *
80  * On some platforms the reset cause flags accumulate between successive resets
81  * and this routine may return multiple flags indicating all reset causes
82  * since the device was powered on. If you need to retrieve the cause only for
83  * the most recent reset call `hwinfo_clear_reset_cause` after calling this
84  * routine to clear the hardware flags before the next reset event.
85  *
86  * Successive calls to this routine will return the same value, unless
87  * `hwinfo_clear_reset_cause` has been called.
88  *
89  * @retval zero if successful.
90  * @retval -ENOSYS if there is no implementation for the particular device.
91  * @retval any negative value on driver specific errors.
92  */
93 __syscall int hwinfo_get_reset_cause(uint32_t *cause);
94 
95 int z_impl_hwinfo_get_reset_cause(uint32_t *cause);
96 
97 /**
98  * @brief      Clear cause of device reset.
99  *
100  * Clears reset cause flags.
101  *
102  * @retval zero if successful.
103  * @retval -ENOSYS if there is no implementation for the particular device.
104  * @retval any negative value on driver specific errors.
105  */
106 __syscall int hwinfo_clear_reset_cause(void);
107 
108 int z_impl_hwinfo_clear_reset_cause(void);
109 
110 /**
111  * @brief      Get supported reset cause flags
112  *
113  * @param      supported  OR'd `reset_cause` flags that are supported
114  *
115  * Retrieves all `reset_cause` flags that are supported by this device.
116  *
117  * @retval zero if successful.
118  * @retval -ENOSYS if there is no implementation for the particular device.
119  * @retval any negative value on driver specific errors.
120  */
121 __syscall int hwinfo_get_supported_reset_cause(uint32_t *supported);
122 
123 int z_impl_hwinfo_get_supported_reset_cause(uint32_t *supported);
124 
125 /**
126  * @}
127  */
128 
129 #ifdef __cplusplus
130 }
131 #endif
132 
133 #include <syscalls/hwinfo.h>
134 
135 #endif /* ZEPHYR_INCLUDE_DRIVERS_HWINFO_H_ */
136