[GitHub] kasjer commented on a change in pull request #1101: HiFive1 add missing peripheral driver

2018-05-18 Thread GitBox
kasjer commented on a change in pull request #1101: HiFive1 add missing 
peripheral driver
URL: https://github.com/apache/mynewt-core/pull/1101#discussion_r189391132
 
 

 ##
 File path: hw/mcu/sifive/fe310/src/hal_spi.c
 ##
 @@ -0,0 +1,384 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+
+#include 
+#include 
+
+#include 
+#include 
+
+#include 
+#include 
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+struct fe310_hal_spi
+{
 
 Review comment:
   done


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:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] kasjer commented on a change in pull request #1101: HiFive1 add missing peripheral driver

2018-05-18 Thread GitBox
kasjer commented on a change in pull request #1101: HiFive1 add missing 
peripheral driver
URL: https://github.com/apache/mynewt-core/pull/1101#discussion_r189391169
 
 

 ##
 File path: hw/mcu/sifive/fe310/src/hal_spi.c
 ##
 @@ -0,0 +1,384 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+
+#include 
+#include 
+
+#include 
+#include 
+
+#include 
+#include 
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+struct fe310_hal_spi
+{
+struct hal_spi_settings spi_cfg;
+
+uint32_t spi_base;
+
+int len;
+int txleft;
+int rxleft;
+
+/* Pointers to tx/rx buffers */
+uint8_t *txbuf;
+uint8_t *rxbuf;
+
+/* Callback and arguments */
+hal_spi_txrx_cb txrx_cb_func;
+void*txrx_cb_arg;
+};
+
+#if MYNEWT_VAL(SPI_1)
+struct fe310_hal_spi fe310_hal_spi1 = {
+.spi_base = SPI1_CTRL_ADDR
+};
+#endif
+
+#if MYNEWT_VAL(SPI_2)
+struct fe310_hal_spi fe310_hal_spi2 = {
+.spi_base = SPI2_CTRL_ADDR
+};
+#endif
+
+static struct fe310_hal_spi *fe310_hal_spis[3] = {
+NULL, /* SPI 0 used to access flash */
+#if MYNEWT_VAL(SPI_1)
+_hal_spi1,
+#else
+NULL,
+#endif
+#if MYNEWT_VAL(SPI_2)
+_hal_spi2,
+#else
+NULL,
+#endif
+};
+
+#define FE310_HAL_SPI_RESOLVE(__n, __v) \
+if ((__n) > 2) {\
+rc = SYS_EINVAL;\
+goto err;   \
+}   \
+(__v) = (struct fe310_hal_spi *) fe310_hal_spis[(__n)]; \
+if ((__v) == NULL) {\
+rc = SYS_EINVAL;\
+goto err;   \
+}
+
+static void
+spi_interrupt_handler(int int_num)
+{
+struct fe310_hal_spi *spi = fe310_hal_spis[int_num - INT_SPI0_BASE];
+uint32_t val;
+for (;;) {
+val = _REG32(spi->spi_base, SPI_REG_RXFIFO);
+if (spi->rxleft && (val & SPI_RXFIFO_EMPTY) == 0) {
+*spi->rxbuf++ = (uint8_t)val;
+spi->rxleft--;
+}
+if (spi->txleft) {
+if (_REG32(spi->spi_base, SPI_REG_TXFIFO) & SPI_TXFIFO_FULL) {
+break;
+}
+_REG32(spi->spi_base, SPI_REG_TXFIFO) = *spi->txbuf++;
+spi->txleft--;
+} else {
+/* Set watermark to 0, interrupt from TX FIFO will be blocked */
+_REG32(spi->spi_base, SPI_REG_TXCTRL) = 0;
+if (!spi->rxleft) {
+plic_disable_interrupt(int_num);
+_REG32(spi->spi_base, SPI_REG_IE) = 0;
+spi->txrx_cb_func(spi->txrx_cb_arg, spi->len);
+break;
+}
+}
+}
+}
+
+int
+hal_spi_init(int spi_num, void *usercfg, uint8_t spi_type)
+{
+int rc;
+struct fe310_hal_spi *spi;
+FE310_HAL_SPI_RESOLVE(spi_num, spi);
+
+/* Check for valid arguments */
+rc = SYS_EINVAL;
+if ((spi_type != HAL_SPI_TYPE_MASTER)) {
+goto err;
+}
+
+plic_set_handler(INT_SPI0_BASE + spi_num, spi_interrupt_handler, 3);
+if (spi_num == 1 && MYNEWT_VAL(SPI_1)) {
+_REG32(GPIO_CTRL_ADDR, GPIO_IOF_SEL) &= ~(7 << 3);
+_REG32(GPIO_CTRL_ADDR, GPIO_IOF_EN) |= (7 << 3);
+} else if (spi_num == 2 && MYNEWT_VAL(SPI_2)) {
+_REG32(GPIO_CTRL_ADDR, GPIO_IOF_SEL) &= ~(7 << 27);
+_REG32(GPIO_CTRL_ADDR, GPIO_IOF_EN) |= (7 << 27);
 
 Review comment:
   Proper defines found at last.


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:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] kasjer commented on a change in pull request #1101: HiFive1 add missing peripheral driver

2018-05-18 Thread GitBox
kasjer commented on a change in pull request #1101: HiFive1 add missing 
peripheral driver
URL: https://github.com/apache/mynewt-core/pull/1101#discussion_r189391159
 
 

 ##
 File path: hw/mcu/sifive/fe310/src/hal_spi.c
 ##
 @@ -0,0 +1,384 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+
+#include 
+#include 
+
+#include 
+#include 
+
+#include 
+#include 
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+struct fe310_hal_spi
+{
+struct hal_spi_settings spi_cfg;
+
+uint32_t spi_base;
+
+int len;
+int txleft;
+int rxleft;
+
+/* Pointers to tx/rx buffers */
+uint8_t *txbuf;
+uint8_t *rxbuf;
+
+/* Callback and arguments */
+hal_spi_txrx_cb txrx_cb_func;
+void*txrx_cb_arg;
+};
+
+#if MYNEWT_VAL(SPI_1)
+struct fe310_hal_spi fe310_hal_spi1 = {
+.spi_base = SPI1_CTRL_ADDR
+};
+#endif
+
+#if MYNEWT_VAL(SPI_2)
+struct fe310_hal_spi fe310_hal_spi2 = {
+.spi_base = SPI2_CTRL_ADDR
+};
+#endif
+
+static struct fe310_hal_spi *fe310_hal_spis[3] = {
+NULL, /* SPI 0 used to access flash */
+#if MYNEWT_VAL(SPI_1)
+_hal_spi1,
+#else
+NULL,
+#endif
+#if MYNEWT_VAL(SPI_2)
+_hal_spi2,
+#else
+NULL,
+#endif
+};
+
+#define FE310_HAL_SPI_RESOLVE(__n, __v) \
+if ((__n) > 2) {\
+rc = SYS_EINVAL;\
+goto err;   \
+}   \
+(__v) = (struct fe310_hal_spi *) fe310_hal_spis[(__n)]; \
+if ((__v) == NULL) {\
+rc = SYS_EINVAL;\
+goto err;   \
+}
+
+static void
+spi_interrupt_handler(int int_num)
+{
+struct fe310_hal_spi *spi = fe310_hal_spis[int_num - INT_SPI0_BASE];
+uint32_t val;
+for (;;) {
 
 Review comment:
   Added sanity cap


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:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] kasjer commented on a change in pull request #1101: HiFive1 add missing peripheral driver

2018-05-18 Thread GitBox
kasjer commented on a change in pull request #1101: HiFive1 add missing 
peripheral driver
URL: https://github.com/apache/mynewt-core/pull/1101#discussion_r189391145
 
 

 ##
 File path: hw/mcu/sifive/fe310/src/hal_spi.c
 ##
 @@ -0,0 +1,384 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+
+#include 
+#include 
+
+#include 
+#include 
+
+#include 
+#include 
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+struct fe310_hal_spi
+{
+struct hal_spi_settings spi_cfg;
+
+uint32_t spi_base;
+
+int len;
+int txleft;
+int rxleft;
+
+/* Pointers to tx/rx buffers */
+uint8_t *txbuf;
+uint8_t *rxbuf;
+
+/* Callback and arguments */
+hal_spi_txrx_cb txrx_cb_func;
+void*txrx_cb_arg;
+};
+
+#if MYNEWT_VAL(SPI_1)
+struct fe310_hal_spi fe310_hal_spi1 = {
+.spi_base = SPI1_CTRL_ADDR
+};
+#endif
+
+#if MYNEWT_VAL(SPI_2)
+struct fe310_hal_spi fe310_hal_spi2 = {
+.spi_base = SPI2_CTRL_ADDR
+};
+#endif
+
+static struct fe310_hal_spi *fe310_hal_spis[3] = {
+NULL, /* SPI 0 used to access flash */
 
 Review comment:
   Mathilda: Is life always this hard, or is it just when you're a kid?
   Léon: Always like this.
   
   SPI0 is always for QSPI flash. Pins can't be configured as GPIO.
   SPI2 is not routed to external Pins (in current hardwarefor now)
   SPI1 is the only SPI that can be used.


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:
us...@infra.apache.org


With regards,
Apache Git Services