You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by GitBox <gi...@apache.org> on 2018/12/06 19:42:24 UTC

[GitHub] kasjer closed pull request #1552: hifive1 spi update

kasjer closed pull request #1552: hifive1 spi update
URL: https://github.com/apache/mynewt-core/pull/1552
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/hw/bsp/hifive1/src/hal_bsp.c b/hw/bsp/hifive1/src/hal_bsp.c
index 570289d985..70d65201d3 100644
--- a/hw/bsp/hifive1/src/hal_bsp.c
+++ b/hw/bsp/hifive1/src/hal_bsp.c
@@ -34,6 +34,12 @@
 #endif
 #include <bsp/bsp.h>
 #include <env/freedom-e300-hifive1/platform.h>
+#if MYNEWT_VAL(BUS_DRIVER_PRESENT)
+#include "bus/bus.h"
+#if MYNEWT_VAL(SPI_0) || MYNEWT_VAL(SPI_1) || MYNEWT_VAL(SPI_2)
+#include "bus/spi.h"
+#endif
+#endif
 
 #if MYNEWT_VAL(UART_0)
 static struct uart_dev os_bsp_uart0;
@@ -53,6 +59,21 @@ extern struct fe310_hal_tmr fe310_pwm1;
 extern struct fe310_hal_tmr fe310_pwm0;
 #endif
 
+#if MYNEWT_VAL(BUS_DRIVER_PRESENT)
+#if MYNEWT_VAL(SPI_1)
+static const struct bus_spi_dev_cfg spi1_cfg = {
+    .spi_num = 1,
+};
+static struct bus_spi_dev spi1_bus;
+#endif
+#if MYNEWT_VAL(SPI_2)
+static const struct bus_spi_dev_cfg spi2_cfg = {
+    .spi_num = 2,
+};
+static struct bus_spi_dev spi2_bus;
+#endif
+#endif
+
 /*
  * What memory to include in coredump.
  */
@@ -107,14 +128,23 @@ hal_bsp_init(void)
 #endif
 
 #if MYNEWT_VAL(SPI_1)
+#if MYNEWT_VAL(BUS_DRIVER_PRESENT)
+    rc = bus_spi_dev_create("spi1", &spi1_bus, (struct bus_spi_dev_cfg *)&spi1_cfg);
+    assert(rc == 0);
+#else
     rc = hal_spi_init(1, NULL, HAL_SPI_TYPE_MASTER);
     assert(rc == 0);
 #endif
-
+#endif
 #if MYNEWT_VAL(SPI_2)
+#if MYNEWT_VAL(BUS_DRIVER_PRESENT)
+    rc = bus_spi_dev_create("spi2", &spi2_bus, (struct bus_spi_dev_cfg *)&spi2_cfg);
+    assert(rc == 0);
+#else
     rc = hal_spi_init(2, NULL, HAL_SPI_TYPE_MASTER);
     assert(rc == 0);
 #endif
+#endif
 
 #if MYNEWT_VAL(UART_0)
     rc = os_dev_create((struct os_dev *) &os_bsp_uart0, "uart0",
diff --git a/hw/mcu/sifive/fe310/src/hal_spi.c b/hw/mcu/sifive/fe310/src/hal_spi.c
index 09f0fa65fc..851f7edc05 100644
--- a/hw/mcu/sifive/fe310/src/hal_spi.c
+++ b/hw/mcu/sifive/fe310/src/hal_spi.c
@@ -172,6 +172,13 @@ hal_spi_init(int spi_num, void *usercfg, uint8_t spi_type)
     return (rc);
 }
 
+int
+hal_spi_init_hw(uint8_t spi_num, uint8_t spi_type,
+                const struct hal_spi_hw_settings *cfg)
+{
+    return hal_spi_init(spi_num, NULL, spi_type);
+}
+
 /**
  * Sets the txrx callback (executed at interrupt context) when the
  * buffer is transferred by the master or the slave using the non-blocking API.
@@ -247,7 +254,7 @@ hal_spi_config(int spi_num, struct hal_spi_settings *settings)
     if (settings->data_order == HAL_SPI_LSB_FIRST) {
         fmt |= SPI_FMT_ENDIAN(1);
     }
-    div = get_cpu_freq() / (2 * settings->baudrate);
+    div = get_cpu_freq() / (2 * settings->baudrate * 1000);
     if (div) {
         div--;
     }


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services