atsamd: Add a get_pclock_frequency() helper function
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
parent
8f763d80b7
commit
c5fc264a07
|
@ -43,6 +43,13 @@ enable_pclock(uint32_t pclk_id, uint32_t pm_id)
|
||||||
(&PM->APBAMASK.reg)[pm_port] |= pm_bit;
|
(&PM->APBAMASK.reg)[pm_port] |= pm_bit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Return the frequency of the given peripheral clock
|
||||||
|
uint32_t
|
||||||
|
get_pclock_frequency(uint32_t pclk_id)
|
||||||
|
{
|
||||||
|
return FREQ_MAIN;
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
SystemInit(void)
|
SystemInit(void)
|
||||||
{
|
{
|
||||||
|
|
|
@ -4,7 +4,6 @@
|
||||||
//
|
//
|
||||||
// This file may be distributed under the terms of the GNU GPLv3 license.
|
// This file may be distributed under the terms of the GNU GPLv3 license.
|
||||||
|
|
||||||
#include "autoconf.h" // CONFIG_CLOCK_FREQ
|
|
||||||
#include "internal.h" // enable_pclock
|
#include "internal.h" // enable_pclock
|
||||||
#include "command.h" // shutdown
|
#include "command.h" // shutdown
|
||||||
#include "gpio.h" // i2c_setup
|
#include "gpio.h" // i2c_setup
|
||||||
|
@ -38,8 +37,8 @@ i2c_init(void)
|
||||||
| SERCOM_I2CM_STATUS_MEXTTOUT
|
| SERCOM_I2CM_STATUS_MEXTTOUT
|
||||||
| SERCOM_I2CM_CTRLA_MODE_I2C_MASTER);
|
| SERCOM_I2CM_CTRLA_MODE_I2C_MASTER);
|
||||||
si->CTRLA.reg = areg;
|
si->CTRLA.reg = areg;
|
||||||
uint32_t baud = (CONFIG_CLOCK_FREQ / I2C_FREQ
|
uint32_t freq = get_pclock_frequency(SERCOM3_GCLK_ID_CORE);
|
||||||
- 10 - CONFIG_CLOCK_FREQ*TIME_RISE/1000000000) / 2;
|
uint32_t baud = (freq/I2C_FREQ - 10 - freq*TIME_RISE/1000000000) / 2;
|
||||||
si->BAUD.reg = baud;
|
si->BAUD.reg = baud;
|
||||||
si->CTRLA.reg = areg | SERCOM_I2CM_CTRLA_ENABLE;
|
si->CTRLA.reg = areg | SERCOM_I2CM_CTRLA_ENABLE;
|
||||||
while (si->SYNCBUSY.reg & SERCOM_I2CM_SYNCBUSY_ENABLE)
|
while (si->SYNCBUSY.reg & SERCOM_I2CM_SYNCBUSY_ENABLE)
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
#define GPIO2BIT(PIN) (1<<((PIN) % 32))
|
#define GPIO2BIT(PIN) (1<<((PIN) % 32))
|
||||||
|
|
||||||
void enable_pclock(uint32_t pclk_id, uint32_t pm_id);
|
void enable_pclock(uint32_t pclk_id, uint32_t pm_id);
|
||||||
|
uint32_t get_pclock_frequency(uint32_t pclk_id);
|
||||||
void gpio_peripheral(uint32_t gpio, char ptype, int32_t pull_up);
|
void gpio_peripheral(uint32_t gpio, char ptype, int32_t pull_up);
|
||||||
|
|
||||||
#endif // internal.h
|
#endif // internal.h
|
||||||
|
|
|
@ -4,7 +4,6 @@
|
||||||
//
|
//
|
||||||
// This file may be distributed under the terms of the GNU GPLv3 license.
|
// This file may be distributed under the terms of the GNU GPLv3 license.
|
||||||
|
|
||||||
#include "autoconf.h" // CONFIG_SERIAL_BAUD
|
|
||||||
#include "board/serial_irq.h" // serial_rx_data
|
#include "board/serial_irq.h" // serial_rx_data
|
||||||
#include "internal.h" // enable_pclock
|
#include "internal.h" // enable_pclock
|
||||||
#include "samd21.h" // SERCOM0
|
#include "samd21.h" // SERCOM0
|
||||||
|
@ -28,7 +27,8 @@ serial_init(void)
|
||||||
| SERCOM_USART_CTRLA_RXPO(3));
|
| SERCOM_USART_CTRLA_RXPO(3));
|
||||||
su->CTRLA.reg = areg;
|
su->CTRLA.reg = areg;
|
||||||
su->CTRLB.reg = SERCOM_USART_CTRLB_TXEN | SERCOM_USART_CTRLB_RXEN;
|
su->CTRLB.reg = SERCOM_USART_CTRLB_TXEN | SERCOM_USART_CTRLB_RXEN;
|
||||||
uint32_t baud8 = CONFIG_CLOCK_FREQ / (2 * CONFIG_SERIAL_BAUD);
|
uint32_t freq = get_pclock_frequency(SERCOM0_GCLK_ID_CORE);
|
||||||
|
uint32_t baud8 = freq / (2 * CONFIG_SERIAL_BAUD);
|
||||||
su->BAUD.reg = (SERCOM_USART_BAUD_FRAC_BAUD(baud8 / 8)
|
su->BAUD.reg = (SERCOM_USART_BAUD_FRAC_BAUD(baud8 / 8)
|
||||||
| SERCOM_USART_BAUD_FRAC_FP(baud8 % 8));
|
| SERCOM_USART_BAUD_FRAC_FP(baud8 % 8));
|
||||||
NVIC_SetPriority(SERCOM0_IRQn, 0);
|
NVIC_SetPriority(SERCOM0_IRQn, 0);
|
||||||
|
|
|
@ -4,7 +4,6 @@
|
||||||
//
|
//
|
||||||
// This file may be distributed under the terms of the GNU GPLv3 license.
|
// This file may be distributed under the terms of the GNU GPLv3 license.
|
||||||
|
|
||||||
#include "autoconf.h" // CONFIG_CLOCK_FREQ
|
|
||||||
#include "internal.h" // enable_pclock
|
#include "internal.h" // enable_pclock
|
||||||
#include "command.h" // shutdown
|
#include "command.h" // shutdown
|
||||||
#include "gpio.h" // spi_setup
|
#include "gpio.h" // spi_setup
|
||||||
|
@ -47,7 +46,7 @@ spi_setup(uint32_t bus, uint8_t mode, uint32_t rate)
|
||||||
| SERCOM_SPI_CTRLA_DIPO(0)
|
| SERCOM_SPI_CTRLA_DIPO(0)
|
||||||
| SERCOM_SPI_CTRLA_DOPO(1)
|
| SERCOM_SPI_CTRLA_DOPO(1)
|
||||||
| SERCOM_SPI_CTRLA_ENABLE);
|
| SERCOM_SPI_CTRLA_ENABLE);
|
||||||
uint32_t baud = CONFIG_CLOCK_FREQ / (2 * rate) - 1;
|
uint32_t baud = get_pclock_frequency(SERCOM4_GCLK_ID_CORE) / (2 * rate) - 1;
|
||||||
spi_init(ctrla, baud);
|
spi_init(ctrla, baud);
|
||||||
return (struct spi_config){ .ctrla = ctrla, .baud = baud };
|
return (struct spi_config){ .ctrla = ctrla, .baud = baud };
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue