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