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

Function ls1c_spi_set_clock

bsp/loongson/ls1cdev/libraries/ls1c_spi.c:137–158  ·  view source on GitHub ↗

* 设置时钟 * @spi_base 基地址 * @max_hz 最大频率,单位hz */

Source from the content-addressed store, hash-verified

135 * @max_hz 最大频率,单位hz
136 */
137void ls1c_spi_set_clock(void *spi_base, unsigned long max_hz)
138{
139 unsigned int div = 0;
140 unsigned char val = 0;
141
142 // 获取分频系数
143 div = ls1c_spi_get_div(max_hz);
144
145 // 设置spr
146 val = reg_read_8(spi_base + LS1C_SPI_SPCR_OFFSET);
147 val &= (~LS1C_SPI_SPCR_SPR_MASK); // spr清零
148 val |= (div & LS1C_SPI_SPCR_SPR_MASK); // 设置新的spr
149 reg_write_8(val, spi_base + LS1C_SPI_SPCR_OFFSET);
150
151 // 设置spre
152 val = reg_read_8(spi_base + LS1C_SPI_SPER_OFFSET);
153 val &= (~LS1C_SPI_SPER_SPRE_MASK); // spre清零
154 val |= ((div >> 2) & LS1C_SPI_SPER_SPRE_MASK); // 设置新的spre
155 reg_write_8(val, spi_base + LS1C_SPI_SPER_OFFSET);
156
157 return ;
158}
159
160
161/*

Callers 1

configureFunction · 0.85

Calls 3

ls1c_spi_get_divFunction · 0.85
reg_read_8Function · 0.70
reg_write_8Function · 0.70

Tested by

no test coverage detected