flinklib
flinklib: flink C library for Linux
wd.c
Go to the documentation of this file.
1 /*******************************************************************
2  * _________ _____ _____ ____ _____ ___ ____ *
3  * |_ ___ | |_ _| |_ _| |_ \|_ _| |_ ||_ _| *
4  * | |_ \_| | | | | | \ | | | |_/ / *
5  * | _| | | _ | | | |\ \| | | __'. *
6  * _| |_ _| |__/ | _| |_ _| |_\ |_ _| | \ \_ *
7  * |_____| |________| |_____| |_____|\____| |____||____| *
8  * *
9  *******************************************************************
10  * *
11  * flink userspace library, subdevice function "watchdog" *
12  * *
13  *******************************************************************/
14 
24 #include "flinklib.h"
25 #include "types.h"
26 #include "error.h"
27 #include "log.h"
28 
35 int flink_wd_get_baseclock(flink_subdev* subdev, uint32_t* base_clk) {
36  uint32_t offset;
37 
38  printf("Reading base clock from watchdog subdevice %d\n", subdev->id);
39 
40  offset = HEADER_SIZE + SUBHEADER_SIZE;
41  dbg_print(" --> calculated offset is 0x%x!\n", offset);
42 
43  if(flink_read(subdev, offset, REGISTER_WITH, base_clk) != REGISTER_WITH) {
44  libc_error();
45  return EXIT_ERROR;
46  }
47 
48  return EXIT_SUCCESS;
49 }
50 
57 int flink_wd_get_status(flink_subdev* subdev, uint8_t* status){
58  uint32_t offset;
59 
60  dbg_print("Reading WD status from subdevice %d\n", subdev->id);
61 
63  dbg_print(" --> calculated offset is 0x%x!\n", offset);
64 
65  if(flink_read_bit(subdev, offset, 0, status)) {
66  libc_error();
67  return EXIT_ERROR;
68  }
69 
70  return EXIT_SUCCESS;
71 }
72 
79 int flink_wd_set_counter(flink_subdev* subdev, uint32_t counter){
80  uint32_t offset;
81 
82  dbg_print("Setting WD counter on subdevice %d to %d (%x)\n", subdev->id, counter, counter);
83 
84  offset = HEADER_SIZE + SUBHEADER_SIZE + 2 * REGISTER_WITH;
85  dbg_print(" --> calculated offset is 0x%x!\n", offset);
86 
87  if(flink_write(subdev, offset, REGISTER_WITH, &counter) != REGISTER_WITH) {
88  libc_error();
89  return EXIT_ERROR;
90  }
91 
92  return EXIT_SUCCESS;
93 }
94 
101  uint32_t offset;
102  uint8_t arm = 1;
103 
104  dbg_print("[DEBUG] Arming WD (subdevice %d)\n", subdev->id);
105 
107  dbg_print(" --> calculated offset is 0x%x!\n", offset);
108 
109  if(flink_write_bit(subdev, offset, 1, &arm)) {
110  libc_error();
111  return EXIT_ERROR;
112  }
113 
114  return EXIT_SUCCESS;
115 }
Data structures for flink devices and subdevices.
int flink_wd_get_status(flink_subdev *subdev, uint8_t *status)
Reads the status word of a watchdog subdevice.
Definition: wd.c:57
#define EXIT_ERROR
Definition: flinklib.h:129
ssize_t flink_read(flink_subdev *subdev, uint32_t offset, uint8_t size, void *rdata)
Read from a flink subdevice.
Definition: lowlevel.c:71
Error handling.
#define REGISTER_WITH
Definition: flinklib.h:50
#define HEADER_SIZE
Definition: flinklib.h:51
int flink_write_bit(flink_subdev *subdev, uint32_t offset, uint8_t bit, void *wdata)
Write a single bit to a flink subdevice.
Definition: lowlevel.c:187
#define EXIT_SUCCESS
Definition: flinklib.h:128
int flink_read_bit(flink_subdev *subdev, uint32_t offset, uint8_t bit, void *rdata)
Read a single bit from a flink subdevice.
Definition: lowlevel.c:149
int flink_wd_arm(flink_subdev *subdev)
Starts the watchdog counter.
Definition: wd.c:100
#define SUBHEADER_SIZE
Definition: flinklib.h:52
void libc_error(void)
Definition: error.c:56
int flink_wd_set_counter(flink_subdev *subdev, uint32_t counter)
Presets the watchdog counter.
Definition: wd.c:79
Debug utilities.
int flink_wd_get_baseclock(flink_subdev *subdev, uint32_t *base_clk)
Reads the base clock of a watchdog subdevice.
Definition: wd.c:35
ssize_t flink_write(flink_subdev *subdev, uint32_t offset, uint8_t size, void *wdata)
Write to a flink subdevice.
Definition: lowlevel.c:110
#define dbg_print(fmt,...)
Definition: log.h:29