You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by GitBox <gi...@apache.org> on 2021/01/13 09:46:29 UTC

[GitHub] [incubator-nuttx] liangzhanggb commented on a change in pull request #2669: arch/risc-v/bl602 : add gpioirq、 i2c(master) driver.

liangzhanggb commented on a change in pull request #2669:
URL: https://github.com/apache/incubator-nuttx/pull/2669#discussion_r556389708



##########
File path: arch/risc-v/src/bl602/bl602_i2c.c
##########
@@ -0,0 +1,1049 @@
+/****************************************************************************
+ * arch/risc-v/src/bl602/bl602_i2c.c
+ *
+ * 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.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <sys/types.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdint.h>
+#include <stdbool.h>
+#include <errno.h>
+#include <debug.h>
+#include <time.h>
+
+#include <nuttx/arch.h>
+#include <nuttx/irq.h>
+#include <nuttx/clock.h>
+#include <nuttx/semaphore.h>
+#include <nuttx/i2c/i2c_master.h>
+
+#include <arch/board/board.h>
+#include "riscv_arch.h"
+
+#include "hardware/bl602_i2c.h"
+#include "hardware/bl602_glb.h"
+#include "bl602_gpio.h"
+#include "bl602_i2c.h"
+#include "bl602_glb.h"
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+#define I2C0 0
+
+#define PUT_UINT32_LE(n, b, i) \
+  { \
+    (b)[(i)]     = (uint8_t)((n)); \
+    (b)[(i) + 1] = (uint8_t)((n) >> 8); \
+    (b)[(i) + 2] = (uint8_t)((n) >> 16); \
+    (b)[(i) + 3] = (uint8_t)((n) >> 24); \
+  }
+
+#define SYS_TEMCORE_CLOCK_GET (*((volatile uint32_t *)(0x4000F108)))
+
+/* I2C state */
+
+#define EV_I2C_END_INT    0
+#define EV_I2C_TXF_INT    1
+#define EV_I2C_RXF_INT    3
+#define EV_I2C_FER_INT    4
+#define EV_I2C_ARB_INT    5
+#define EV_I2C_NAK_INT    6
+#define EV_I2C_UNKNOW_INT 0xff
+
+/* I2C Device hardware configuration */
+
+struct bl602_i2c_config_s
+{
+  uint32_t reg_base; /* I2C register base address */
+  uint8_t  irq;      /* Interrupt ID */
+  uint32_t clk_freq; /* i2c freq */
+};
+
+/* I2C Device Private Data */
+
+struct bl602_i2c_priv_s
+{
+  const struct i2c_ops_s *ops; /* Standard I2C operations */
+
+  /* Port configuration */
+
+  const struct bl602_i2c_config_s *config;
+
+  uint8_t  subflag;  /* Sub address flag */
+  uint32_t subaddr;  /* Sub address */
+  uint8_t  sublen;   /* Sub address length */
+  sem_t    sem_excl; /* Mutual exclusion semaphore */
+  sem_t    sem_isr;  /* Interrupt wait semaphore */
+
+  /* I2C work state */
+
+  uint8_t i2cstate;
+
+  struct i2c_msg_s *msgv; /* Message list */
+
+  uint8_t msgid; /* Current message ID */
+  ssize_t bytes; /* Processed data bytes */
+  int     refs;  /* Reference count */
+};
+
+/****************************************************************************
+ * Private Function Prototypes
+ ****************************************************************************/
+
+static int bl602_i2c_transfer(FAR struct i2c_master_s *dev,
+                              FAR struct i2c_msg_s *   msgs,
+                              int                      count);
+
+#ifdef CONFIG_I2C_RESET
+static int bl602_i2c_reset(FAR struct i2c_master_s *dev);
+#endif
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+/* I2C interface */
+
+static const struct i2c_ops_s bl602_i2c_ops =
+{
+  .transfer = bl602_i2c_transfer,
+#ifdef CONFIG_I2C_RESET
+  .reset = bl602_i2c_reset
+#endif
+};
+
+/* I2C device structures */
+
+#ifdef CONFIG_BL602_I2C0
+static const struct bl602_i2c_config_s bl602_i2c0_config =
+{
+  .reg_base = BL602_I2C_BASE,
+  .irq      = BL602_IRQ_I2C,
+  .clk_freq = 500,

Review comment:
       I have fixed it ,Thanks.
   
   arch/risc-v/src/bl602/bl602_i2c.c
   #define I2C_DEFAULT_FREQUENCY 100000




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to 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