MCPcopy Create free account
hub / github.com/RT-Thread/rt-thread / efm_eth_cmd

Function efm_eth_cmd

bsp/efm32/drv_ethernet.c:95–183  ·  view source on GitHub ↗

/ * @brief * Send command to Ethernet device * * @details * * @note * * @param[in] cmd * Command index * * @param[in] addr * Register address * * @param[in/out] data * Pointer to the buffer of register value * * @return * Error code ******************************************************************************/

Source from the content-addressed store, hash-verified

93 * Error code
94 ******************************************************************************/
95static rt_err_t efm_eth_cmd(
96 rt_uint8_t cmd,
97 rt_uint8_t addr,
98 rt_uint8_t *data)
99{
100 RT_ASSERT(spi != RT_NULL);
101
102 rt_uint8_t buf_ins[6], buf_res[2];
103 rt_uint8_t len_ins, len_res;
104
105 len_ins = 0;
106 do
107 {
108 /* Build instruction buffer */
109 /* Check if need to read back */
110 if (cmd == ENC28J60_READ_CTRL_REG)
111 {
112 buf_ins[len_ins++] = 1; /* Instruction length */
113 }
114 /* Byte 0: Check if no address section */
115 if (cmd == ENC28J60_READ_BUF_MEM || cmd == ENC28J60_WRITE_BUF_MEM || \
116 cmd == ENC28J60_SOFT_RESET)
117 {
118 buf_ins[len_ins++] = cmd;
119 }
120 else
121 {
122 buf_ins[len_ins++] = cmd | (addr & ADDR_MASK);
123 }
124 /* Byte 1: Check if data section is present */
125 if (cmd == ENC28J60_WRITE_CTRL_REG || cmd == ENC28J60_BIT_FIELD_SET || \
126 cmd == ENC28J60_BIT_FIELD_CLR || cmd == ENC28J60_WRITE_BUF_MEM)
127 {
128 buf_ins[len_ins++] = *data;
129 }
130
131 /* Check if reading */
132 if (cmd == ENC28J60_READ_CTRL_REG)
133 {
134 *(rt_uint8_t **)(&buf_ins[len_ins]) = buf_res; /* Pointer to RX buffer */
135 len_ins += 4;
136
137 /* Check if MAC or MII register */
138 if (addr & SPRD_MASK)
139 {
140 len_res = 2;
141 }
142 else
143 {
144 len_res = 1;
145 }
146
147 /* Send command and get response */
148 efm_eth_cs(1);
149 if (spi->read(spi, ETH_SPI_RX_SKIP, buf_ins, len_res) == 0)
150 {
151 break;
152 }

Callers 1

efm_eth_sendCmdFunction · 0.85

Calls 3

efm_eth_csFunction · 0.85
readMethod · 0.45
writeMethod · 0.45

Tested by

no test coverage detected