flexPTP 1.0
An IEEE 1588 PTP implementation designed for microcontrollers
Loading...
Searching...
No Matches
flexptp_options_stm32h743_etherlib.h
Go to the documentation of this file.
1#ifndef FLEXPTP_OPTIONS_STM32H743_H_
2#define FLEXPTP_OPTIONS_STM32H743_H_
3
4#define ETHLIB
5
6// -------------------------------------------
7// --- DEFINES FOR PORTING IMPLEMENTATION ----
8// -------------------------------------------
9
10// Include LwIP/EtherLib headers here
11
12#include <etherlib/etherlib.h>
13
14// Give a printf-like printing implementation MSG(...)
15// Give a maskable printing implementation CLILOG(en,...)
16// Provide an SPRINTF-implementation SPRINTF(str,n,fmt,...)
17
18#include "utils.h"
19
20// Include hardware port files and fill the defines below to port the PTP stack to a physical hardware:
21// - PTP_HW_INIT(increment, addend): function initializing timestamping hardware
22// - PTP_MAIN_OSCILLATOR_FREQ_HZ: clock frequency fed into the timestamp unit [Hz]
23// - PTP_INCREMENT_NSEC: hardware clock increment [ns]
24// - PTP_UPDATE_CLOCK(s,ns): function jumping clock by defined value (negative time value means jumping backward)
25// - PTP_SET_ADDEND(addend): function writing hardware clock addend register
26
27#include "eth_hw_drv.h"
28
29#define PTP_MAIN_OSCILLATOR_FREQ_HZ (200000000)
30#define PTP_INCREMENT_NSEC (5)
31
32#include <stdlib.h>
33
34#define PTP_HW_INIT(increment, addend) ptphw_init(increment, addend)
35#define PTP_UPDATE_CLOCK(s,ns) ETHHW_UpdatePTPTime(ETH, labs(s), abs(ns), (s * NANO_PREFIX + ns) < 0)
36#define PTP_SET_CLOCK(s,ns) ETHHW_InitPTPTime(ETH, labs(s), abs(ns))
37#define PTP_SET_ADDEND(addend) ETHHW_SetPTPAddend(ETH, addend)
38#define PTP_HW_GET_TIME(pt) ptphw_gettime(pt)
39
40// Include the clock servo (controller) and define the following:
41// - PTP_SERVO_INIT(): function initializing clock servo
42// - PTP_SERVO_DEINIT(): function deinitializing clock servo
43// - PTP_SERVO_RESET(): function reseting clock servo
44// - PTP_SERVO_RUN(d): function running the servo, input: master-slave time difference (error), return: clock tuning value in PPB
45//
46
48
49#define PTP_SERVO_INIT() pd_ctrl_init()
50#define PTP_SERVO_DEINIT() pd_ctrl_deinit()
51#define PTP_SERVO_RESET() pd_ctrl_reset()
52#define PTP_SERVO_RUN(d,pscd) pd_ctrl_run(d,pscd)
53
54// Optionally add interactive, tokenizing CLI-support
55// - CLI_REG_CMD(cmd_hintline,n_cmd,n_min_arg,cb): function for registering CLI-commands
56// cmd_hintline: text line printed in the help beginning with the actual command, separated from help text by \t charaters
57// n_cmd: number of tokens (words) the command consists of
58// n_arg: minimal number of arguments must be passed with the command
59// cb: callback function cb(const CliToken_Type *ppArgs, uint8_t argc)
60// return: cmd id (can be null, if discarded)
61
62#include "cli.h"
63
64#define CLI_REG_CMD(cmd_hintline,n_cmd,n_min_arg,cb) CLI_REG_CMD(cmd_hintline, n_cmd, n_min_arg, cb)
65
66// -------------------------------------------
67
68#define CLILOG(en, ...) { if (en) MSG(__VA_ARGS__); }
69
70#define ONOFF(str) ((!strcmp(str, "on")) ? 1 : ((!strcmp(str, "off")) ? 0 : -1))
71
72// -------------------------------------------
73
74#endif // FLEXPTP_OPTIONS_STM32H743_H_