1
+ #include " EthernetClock.h"
2
+ #include " pins_arduino.h"
3
+
4
+ #if defined(ETHERNET_CLK_PIN)
5
+
6
+ EthernetClock::EthernetClock () {
7
+ pinPeripheral (ETHERNET_CLK_PIN, (uint32_t ) (IOPORT_CFG_PERIPHERAL_PIN | IOPORT_PERIPHERAL_AGT));
8
+
9
+ this ->TIMER_ETHERNET_extend .count_source = AGT_CLOCK_PCLKB;
10
+ this ->TIMER_ETHERNET_extend .agto = AGT_PIN_CFG_START_LEVEL_LOW;
11
+ this ->TIMER_ETHERNET_extend .agtoab_settings_b .agtoa = AGT_PIN_CFG_DISABLED;
12
+ this ->TIMER_ETHERNET_extend .agtoab_settings_b .agtob = AGT_PIN_CFG_DISABLED;
13
+ this ->TIMER_ETHERNET_extend .measurement_mode = AGT_MEASURE_DISABLED;
14
+ this ->TIMER_ETHERNET_extend .agtio_filter = AGT_AGTIO_FILTER_NONE;
15
+ this ->TIMER_ETHERNET_extend .enable_pin = AGT_ENABLE_PIN_NOT_USED;
16
+ this ->TIMER_ETHERNET_extend .trigger_edge = AGT_TRIGGER_EDGE_RISING;
17
+
18
+ this ->TIMER_ETHERNET_cfg .mode = TIMER_MODE_PERIODIC;
19
+ this ->TIMER_ETHERNET_cfg .period_counts = (uint32_t ) 0x1 ;
20
+ this ->TIMER_ETHERNET_cfg .duty_cycle_counts = 0x00 ;
21
+ this ->TIMER_ETHERNET_cfg .source_div = (timer_source_div_t ) 0 ;
22
+ this ->TIMER_ETHERNET_cfg .channel = ETHERNET_AGT_TIMER_CHANNEL;
23
+ this ->TIMER_ETHERNET_cfg .p_callback = NULL ;
24
+ this ->TIMER_ETHERNET_cfg .p_context = NULL ;
25
+ this ->TIMER_ETHERNET_cfg .p_extend = &TIMER_ETHERNET_extend;
26
+ this ->TIMER_ETHERNET_cfg .cycle_end_ipl = (BSP_IRQ_DISABLED);
27
+ this ->TIMER_ETHERNET_cfg .cycle_end_irq = FSP_INVALID_VECTOR;
28
+ }
29
+
30
+ fsp_err_t EthernetClock::start () {
31
+ fsp_err_t err = R_AGT_Open (&this ->TIMER_ETHERNET_ctrl ,&this ->TIMER_ETHERNET_cfg );
32
+ if (err != FSP_SUCCESS) {
33
+ return err;
34
+ }
35
+ err = R_AGT_Enable (&this ->TIMER_ETHERNET_ctrl );
36
+ if (err != FSP_SUCCESS) {
37
+ return err;
38
+ }
39
+ err = R_AGT_Start (&this ->TIMER_ETHERNET_ctrl );
40
+ if (err != FSP_SUCCESS) {
41
+ return err;
42
+ }
43
+
44
+ FspTimer::set_timer_is_used (AGT_TIMER, ETHERNET_AGT_TIMER_CHANNEL);
45
+ return err;
46
+ }
47
+
48
+ fsp_err_t EthernetClock::stop () {
49
+ fsp_err_t err = R_AGT_Stop (&this ->TIMER_ETHERNET_ctrl );
50
+ if (err != FSP_SUCCESS) {
51
+ return err;
52
+ } else {
53
+ err = R_AGT_Close (&this ->TIMER_ETHERNET_ctrl );
54
+ if (err != FSP_SUCCESS) {
55
+ return err;
56
+ } else {
57
+ err = R_AGT_Disable (&this ->TIMER_ETHERNET_ctrl );
58
+ if (err != FSP_SUCCESS) {
59
+ return err;
60
+ }
61
+ }
62
+ }
63
+ }
64
+
65
+ #else
66
+
67
+ EthernetClock::EthernetClock () {
68
+ }
69
+
70
+ fsp_err_t EthernetClock::start () {
71
+ return FSP_SUCCESS;
72
+ }
73
+
74
+ fsp_err_t EthernetClock::stop () {
75
+ return FSP_SUCCESS;
76
+ }
77
+
78
+ #endif
0 commit comments