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