]> granicus.if.org Git - esp-idf/blob - components/ethernet/emac_dev.h
component/bt: bug fix of lack of checking bluetooth stack status inside API functions
[esp-idf] / components / ethernet / emac_dev.h
1 // Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6
7 //     http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 #ifndef _EMAC_DEV_H_
16 #define _EMAC_DEV_H_
17
18 #include <stdint.h>
19 #include "soc/emac_reg_v2.h"
20
21 #ifdef __cplusplus
22 extern "C" {
23 #endif
24
25 #define EMAC_INTR_ENABLE_BIT (EMAC_TRANSMIT_INTERRUPT_ENABLE | EMAC_RECEIVE_INTERRUPT_ENABLE | EMAC_RECEIVE_BUFFER_UNAVAILABLE_ENABLE | EMAC_NORMAL_INTERRUPT_SUMMARY_ENABLE)
26
27 struct dma_desc {
28     uint32_t desc0;
29     uint32_t desc1;
30     uint32_t desc2;
31     uint32_t desc3;
32 };
33
34 struct dma_extended_desc {
35     struct dma_desc basic;
36     uint32_t desc4;
37     uint32_t desc5;
38     uint32_t desc6;
39     uint32_t desc7;
40 };
41
42 void emac_enable_clk(bool enable);
43 void emac_set_clk_rmii(void);
44 void emac_set_clk_mii(void);
45 void emac_reset(void);
46 void emac_set_gpio_pin_rmii(void);
47 void emac_set_gpio_pin_mii(void);
48 uint32_t emac_read_mac_version(void);
49 void emac_dma_init(void);
50 void emac_mac_init(void);
51 void emac_enable_dma_tx(void);
52 void emac_enable_dma_rx(void);
53 void emac_disable_dma_tx(void);
54 void emac_disable_dma_rx(void);
55
56 uint32_t inline emac_read_tx_cur_reg(void)
57 {
58     return REG_READ(EMAC_DMATXCURRDESC_REG);
59 }
60
61 uint32_t inline emac_read_rx_cur_reg(void)
62 {
63     return REG_READ(EMAC_DMARXCURRDESC_REG);
64 }
65
66 void inline emac_poll_tx_cmd(void)
67 {
68     //write any to wake up dma
69     REG_WRITE(EMAC_DMATXPOLLDEMAND_REG, 1);
70 }
71
72 void inline emac_poll_rx_cmd(void)
73 {
74     //write any to wake up dma
75     REG_WRITE(EMAC_DMARXPOLLDEMAND_REG, 1);
76 }
77
78 void inline emac_disable_rx_intr(void)
79 {
80     REG_CLR_BIT(EMAC_DMAINTERRUPT_EN_REG,EMAC_RECEIVE_INTERRUPT_ENABLE);
81 }
82
83 void inline emac_enable_rx_intr(void)
84 {
85     REG_SET_BIT(EMAC_DMAINTERRUPT_EN_REG,EMAC_RECEIVE_INTERRUPT_ENABLE);
86 }
87
88 void inline emac_disable_rx_unavail_intr(void)
89 {
90     REG_CLR_BIT(EMAC_DMAINTERRUPT_EN_REG,EMAC_RECEIVE_BUFFER_UNAVAILABLE_ENABLE);
91 }
92
93 void inline emac_enable_rx_unavail_intr(void)
94 {
95     REG_SET_BIT(EMAC_DMAINTERRUPT_EN_REG,EMAC_RECEIVE_BUFFER_UNAVAILABLE_ENABLE);  
96 }
97
98 #ifdef __cplusplus
99 }
100 #endif
101
102 #endif
103