PDK-5118: Board: Enabled I2C init functions in am64x board library
authorM V Pratap Reddy <x0257344@ti.com>
Fri, 6 Nov 2020 15:07:50 +0000 (20:37 +0530)
committerSivaraj R <sivaraj@ti.com>
Sat, 7 Nov 2020 06:21:38 +0000 (00:21 -0600)
packages/ti/board/src/am64x_evm/board_i2c_io_exp.c
packages/ti/board/src/am64x_evm/board_init.c
packages/ti/board/src/am64x_evm/board_lld_init.c
packages/ti/board/src/am64x_evm/board_utils.c
packages/ti/board/src/am64x_evm/include/board_cfg.h
packages/ti/board/src/am64x_evm/include/board_i2c_io_exp.h
packages/ti/board/src/am64x_evm/include/board_internal.h
packages/ti/board/src/am64x_evm/include/board_utils.h

index fc61441ac3de2405a90266a505eb35f022f1bf47..a034af98783df380e72e1333e469670fd7af0e94 100755 (executable)
@@ -1,5 +1,5 @@
 /******************************************************************************\r
- * Copyright (c) 2018 Texas Instruments Incorporated - http://www.ti.com\r
+ * Copyright (c) 2020 Texas Instruments Incorporated - http://www.ti.com\r
  *\r
  *  Redistribution and use in source and binary forms, with or without\r
  *  modification, are permitted provided that the following conditions\r
@@ -40,6 +40,9 @@
 \r
 #include "board_i2c_io_exp.h"\r
 \r
+I2C_Handle gIoExpI2cHandle = NULL;\r
+extern Board_I2cInitCfg_t gBoardI2cInitCfg;\r
+\r
 /**\r
  *  \brief    Reads the current configuration of direction port.\r
  *\r
@@ -61,6 +64,70 @@ Board_STATUS Board_i2cIoExpReadDirPort(uint8_t slaveAddr,
                                        i2cIoExpPortNumber_t portNum,\r
                                        uint8_t *data)\r
 {\r
+    Board_STATUS ret = BOARD_SOK;\r
+    uint8_t subAddr;\r
+    I2C_Transaction transaction;\r
+\r
+    if(gIoExpI2cHandle == NULL)\r
+    {\r
+        return BOARD_INVALID_PARAM;\r
+    }\r
+\r
+    if (ioExpType == THREE_PORT_IOEXP)\r
+    {\r
+        if(portNum == PORTNUM_0)\r
+        {\r
+            subAddr = BOARD_3PORT_IOEXP_PORT0_CONFIGURATION_CMD;\r
+        }\r
+        else if(portNum == PORTNUM_1)\r
+        {\r
+            subAddr = BOARD_3PORT_IOEXP_PORT1_CONFIGURATION_CMD;\r
+        }\r
+        else if(portNum == PORTNUM_2)\r
+        {\r
+            subAddr = BOARD_3PORT_IOEXP_PORT2_CONFIGURATION_CMD;\r
+        }\r
+        else\r
+        {\r
+            return BOARD_INVALID_PARAM;\r
+        }\r
+    }\r
+    else\r
+    {\r
+        return BOARD_INVALID_PARAM;\r
+    }\r
+\r
+    /* Initializes the I2C transaction structure with default values */\r
+    I2C_transactionInit(&transaction);\r
+\r
+    /*Control Byte followed by read bit */\r
+    transaction.slaveAddress = slaveAddr;\r
+    transaction.writeBuf     = &subAddr;\r
+    transaction.readBuf      = data;\r
+    transaction.writeCount   = 1;\r
+    transaction.readCount    = 0;\r
+\r
+    BOARD_delay(200);\r
+\r
+    ret = I2C_transfer(gIoExpI2cHandle, &transaction);\r
+    if(ret != I2C_STS_SUCCESS)\r
+    {\r
+        ret = BOARD_I2C_TRANSFER_FAIL;\r
+        return ret;\r
+    }\r
+\r
+    transaction.writeCount   = 0;\r
+    transaction.readCount    = 1;\r
+\r
+    BOARD_delay(20000);\r
+\r
+    ret = I2C_transfer(gIoExpI2cHandle, &transaction);\r
+    if(ret != I2C_STS_SUCCESS)\r
+    {\r
+        ret = BOARD_I2C_TRANSFER_FAIL;\r
+        return ret;\r
+    }\r
+\r
     return BOARD_SOK;\r
 }\r
 \r
@@ -72,6 +139,8 @@ Board_STATUS Board_i2cIoExpReadDirPort(uint8_t slaveAddr,
  *                                      X_PORT_IOEXP - Total number of ports\r
  *                                                     in slave device.\r
  *  \param    portNum         [IN]      Port number of the i2c slave device\r
+ *                                      PORTNUM_NONE - Used for single ported\r
+ *                                                      slave devices\r
  *                                      PORTNUM_X    - Port number of a slave\r
  *                                                     device.\r
  *  \param    data            [IN/OUT]  Pointer to the data buffer to store\r
@@ -85,6 +154,74 @@ Board_STATUS Board_i2cIoExpReadOutputPort(uint8_t slaveAddr,
                                           i2cIoExpPortNumber_t portNum,\r
                                           uint8_t *data)\r
 {\r
+    Board_STATUS ret = BOARD_SOK;\r
+    uint8_t subAddr;\r
+    I2C_Transaction transaction;\r
+\r
+    if(gIoExpI2cHandle == NULL)\r
+    {\r
+        return BOARD_INVALID_PARAM;\r
+    }\r
+\r
+    if(portNum == PORTNUM_NONE)\r
+    {\r
+        subAddr = BOARD_IO_EXP_INPUT_PORT0_ADDR;\r
+    }\r
+    else if (ioExpType == THREE_PORT_IOEXP)\r
+    {\r
+        if(portNum == PORTNUM_0)\r
+        {\r
+            subAddr = BOARD_3PORT_IOEXP_PORT0_OUTPUT_CMD;\r
+        }\r
+        else if(portNum == PORTNUM_1)\r
+        {\r
+            subAddr = BOARD_3PORT_IOEXP_PORT1_OUTPUT_CMD;\r
+        }\r
+        else if(portNum == PORTNUM_2)\r
+        {\r
+            subAddr = BOARD_3PORT_IOEXP_PORT2_OUTPUT_CMD;\r
+        }\r
+        else\r
+        {\r
+            return BOARD_INVALID_PARAM;\r
+        }\r
+    }\r
+    else\r
+    {\r
+        return BOARD_INVALID_PARAM;\r
+    }\r
+\r
+    /* Initializes the I2C transaction structure with default values */\r
+    I2C_transactionInit(&transaction);\r
+\r
+    /*Control Byte followed by read bit */\r
+    transaction.slaveAddress = slaveAddr;\r
+    transaction.writeBuf     = &subAddr;\r
+    transaction.readBuf      = data;\r
+    transaction.writeCount   = 1;\r
+    transaction.readCount    = 0;\r
+\r
+    BOARD_delay(200);\r
+\r
+    ret = I2C_transfer(gIoExpI2cHandle, &transaction);\r
+    if(ret != I2C_STS_SUCCESS)\r
+    {\r
+        ret = BOARD_I2C_TRANSFER_FAIL;\r
+        return ret;\r
+    }\r
+\r
+    transaction.writeCount   = 0;\r
+    transaction.readCount    = 1;\r
+\r
+    BOARD_delay(20000);\r
+\r
+    ret = I2C_transfer(gIoExpI2cHandle, &transaction);\r
+    if(ret != I2C_STS_SUCCESS)\r
+    {\r
+        ret = BOARD_I2C_TRANSFER_FAIL;\r
+        return ret;\r
+    }\r
+\r
     return BOARD_SOK;\r
 }\r
 \r
@@ -109,6 +246,70 @@ Board_STATUS Board_i2cIoExpReadInputPort(uint8_t slaveAddr,
                                          i2cIoExpPortNumber_t portNum,\r
                                          uint8_t *data)\r
 {\r
+    Board_STATUS ret = BOARD_SOK;\r
+    uint8_t subAddr;\r
+    I2C_Transaction transaction;\r
+\r
+    if(gIoExpI2cHandle == NULL)\r
+    {\r
+        return BOARD_INVALID_PARAM;\r
+    }\r
+\r
+    if (ioExpType == THREE_PORT_IOEXP)\r
+    {\r
+        if(portNum == PORTNUM_0)\r
+        {\r
+            subAddr = BOARD_3PORT_IOEXP_PORT0_INPUT_CMD;\r
+        }\r
+        else if(portNum == PORTNUM_1)\r
+        {\r
+            subAddr = BOARD_3PORT_IOEXP_PORT1_INPUT_CMD;\r
+        }\r
+        else if(portNum == PORTNUM_2)\r
+        {\r
+            subAddr = BOARD_3PORT_IOEXP_PORT2_INPUT_CMD;\r
+        }\r
+        else\r
+        {\r
+            return BOARD_INVALID_PARAM;\r
+        }\r
+    }\r
+    else\r
+    {\r
+        return BOARD_INVALID_PARAM;\r
+    }\r
+\r
+    /* Initializes the I2C transaction structure with default values */\r
+    I2C_transactionInit(&transaction);\r
+\r
+    /*Control Byte followed by read bit */\r
+    transaction.slaveAddress = slaveAddr;\r
+    transaction.writeBuf     = &subAddr;\r
+    transaction.readBuf      = data;\r
+    transaction.writeCount   = 1;\r
+    transaction.readCount    = 0;\r
+\r
+    BOARD_delay(200);\r
+\r
+    ret = I2C_transfer(gIoExpI2cHandle, &transaction);\r
+    if(ret != I2C_STS_SUCCESS)\r
+    {\r
+        ret = BOARD_I2C_TRANSFER_FAIL;\r
+        return ret;\r
+    }\r
+\r
+    transaction.writeCount   = 0;\r
+    transaction.readCount    = 1;\r
+\r
+    BOARD_delay(20000);\r
+\r
+    ret = I2C_transfer(gIoExpI2cHandle, &transaction);\r
+    if(ret != I2C_STS_SUCCESS)\r
+    {\r
+        ret = BOARD_I2C_TRANSFER_FAIL;\r
+        return ret;\r
+    }\r
+\r
     return BOARD_SOK;\r
 }\r
 \r
@@ -132,6 +333,59 @@ Board_STATUS Board_i2cIoExpSetPortDirection(uint8_t slaveAddr,
                                             i2cIoExpPortNumber_t portNum,\r
                                             uint8_t data)\r
 {\r
+    Board_STATUS ret = BOARD_SOK;\r
+    uint8_t dataBuff[2] = {0};\r
+    I2C_Transaction transaction;\r
+\r
+    if(gIoExpI2cHandle == NULL)\r
+    {\r
+        return BOARD_INVALID_PARAM;\r
+    }\r
+\r
+    if (ioExpType == THREE_PORT_IOEXP)\r
+    {\r
+        if(portNum == PORTNUM_0)\r
+        {\r
+            dataBuff[0] = BOARD_3PORT_IOEXP_PORT0_CONFIGURATION_CMD;\r
+        }\r
+        else if(portNum == PORTNUM_1)\r
+        {\r
+            dataBuff[0] = BOARD_3PORT_IOEXP_PORT1_CONFIGURATION_CMD;\r
+        }\r
+        else if(portNum == PORTNUM_2)\r
+        {\r
+            dataBuff[0] = BOARD_3PORT_IOEXP_PORT2_CONFIGURATION_CMD;\r
+        }\r
+        else\r
+        {\r
+            return -1;\r
+        }\r
+    }\r
+    else\r
+    {\r
+        return -1;\r
+    }\r
+\r
+    dataBuff[1] = data;\r
+\r
+    /* Initializes the I2C transaction structure with default values */\r
+    I2C_transactionInit(&transaction);\r
+\r
+    /* Control Byte followed by write bit */\r
+    transaction.slaveAddress = slaveAddr;\r
+    transaction.writeBuf     = &dataBuff;\r
+    transaction.writeCount   = 2;\r
+    transaction.readCount    = 0;\r
+\r
+    BOARD_delay(200);\r
+\r
+    ret = I2C_transfer(gIoExpI2cHandle, &transaction);\r
+    if(ret != I2C_STS_SUCCESS)\r
+    {\r
+        ret = BOARD_I2C_TRANSFER_FAIL;\r
+        return ret;\r
+    }\r
+\r
     return BOARD_SOK;\r
 }\r
 \r
@@ -159,6 +413,68 @@ Board_STATUS Board_i2cIoExpSetPinDirection(uint8_t slaveAddr,
                                            i2cIoExpPinNumber_t pinNum,\r
                                            i2cIoExpPinDirection_t direction)\r
 {\r
+    Board_STATUS ret = BOARD_SOK;\r
+    uint8_t dataBuff[2] = {0};\r
+    uint8_t data;\r
+    I2C_Transaction transaction;\r
+\r
+    if(gIoExpI2cHandle == NULL)\r
+    {\r
+        return BOARD_INVALID_PARAM;\r
+    }\r
+\r
+    if (ioExpType == THREE_PORT_IOEXP)\r
+    {\r
+        if(portNum == PORTNUM_0)\r
+        {\r
+            dataBuff[0] = BOARD_3PORT_IOEXP_PORT0_CONFIGURATION_CMD;\r
+        }\r
+        else if(portNum == PORTNUM_1)\r
+        {\r
+            dataBuff[0] = BOARD_3PORT_IOEXP_PORT1_CONFIGURATION_CMD;\r
+        }\r
+        else if(portNum == PORTNUM_2)\r
+        {\r
+            dataBuff[0] = BOARD_3PORT_IOEXP_PORT2_CONFIGURATION_CMD;\r
+        }\r
+        else\r
+        {\r
+            return BOARD_INVALID_PARAM;\r
+        }\r
+    }\r
+    else\r
+    {\r
+        return BOARD_INVALID_PARAM;\r
+    }\r
+\r
+    Board_i2cIoExpReadDirPort(slaveAddr, ioExpType, portNum, &data);\r
+    if(direction == PIN_DIRECTION_OUTPUT)\r
+    {\r
+        dataBuff[1] = ((data & ~(1 << pinNum)) | (0 << pinNum));\r
+    }\r
+    else\r
+    {\r
+        dataBuff[1] = ((data & ~(1 << pinNum)) | (1 << pinNum));\r
+    }\r
+\r
+    /* Initializes the I2C transaction structure with default values */\r
+    I2C_transactionInit(&transaction);\r
+\r
+    /* Control Byte followed by write bit */\r
+    transaction.slaveAddress = slaveAddr;\r
+    transaction.writeBuf     = &dataBuff;\r
+    transaction.writeCount   = 2;\r
+    transaction.readCount    = 0;\r
+\r
+    BOARD_delay(200);\r
+\r
+    ret = I2C_transfer(gIoExpI2cHandle, &transaction);\r
+    if(ret != I2C_STS_SUCCESS)\r
+    {\r
+        ret = BOARD_I2C_TRANSFER_FAIL;\r
+        return ret;\r
+    }\r
+\r
     return BOARD_SOK;\r
 }\r
 \r
@@ -170,6 +486,8 @@ Board_STATUS Board_i2cIoExpSetPinDirection(uint8_t slaveAddr,
  *                                      X_PORT_IOEXP - Total number of ports\r
  *                                                     in slave device.\r
  *  \param    portNum         [IN]      Port number of the i2c slave device\r
+ *                                      PORTNUM_NONE - Used for single ported\r
+ *                                                      slave devices\r
  *                                      PORTNUM_X    - Port number of a slave\r
  *                                                     device.\r
  *  \param    data            [IN]      Signal level data of the pins to be\r
@@ -183,6 +501,62 @@ Board_STATUS Board_i2cIoExpWritePort(uint8_t slaveAddr,
                                      i2cIoExpPortNumber_t portNum,\r
                                      uint8_t data)\r
 {\r
+    Board_STATUS ret = BOARD_SOK;\r
+    uint8_t dataBuff[2] = {0};\r
+    I2C_Transaction transaction;\r
+\r
+    if(gIoExpI2cHandle == NULL)\r
+    {\r
+        return BOARD_INVALID_PARAM;\r
+    }\r
+    if(portNum == PORTNUM_NONE)\r
+    {\r
+        dataBuff[0] = BOARD_IO_EXP_CMD_DIRECT_LOAD_DATA_OUPTUT;\r
+    }\r
+    else if(ioExpType == THREE_PORT_IOEXP)\r
+    {\r
+        if(portNum == PORTNUM_0)\r
+        {\r
+            dataBuff[0] = BOARD_3PORT_IOEXP_PORT0_OUTPUT_CMD;\r
+        }\r
+        else if(portNum == PORTNUM_1)\r
+        {\r
+            dataBuff[0] = BOARD_3PORT_IOEXP_PORT1_OUTPUT_CMD;\r
+        }\r
+        else if(portNum == PORTNUM_2)\r
+        {\r
+            dataBuff[0] = BOARD_3PORT_IOEXP_PORT2_OUTPUT_CMD;\r
+        }\r
+        else\r
+        {\r
+            return BOARD_INVALID_PARAM;\r
+        }\r
+    }\r
+    else\r
+    {\r
+        return BOARD_INVALID_PARAM;\r
+    }\r
+\r
+    dataBuff[1] = data;\r
+\r
+    /* Initializes the I2C transaction structure with default values */\r
+    I2C_transactionInit(&transaction);\r
+\r
+    /* Control Byte followed by write bit */\r
+    transaction.slaveAddress = slaveAddr;\r
+    transaction.writeBuf     = &dataBuff;\r
+    transaction.writeCount   = 2;\r
+    transaction.readCount    = 0;\r
+\r
+    BOARD_delay(200);\r
+\r
+    ret = I2C_transfer(gIoExpI2cHandle, &transaction);\r
+    if(ret != I2C_STS_SUCCESS)\r
+    {\r
+        ret = BOARD_I2C_TRANSFER_FAIL;\r
+        return ret;\r
+    }\r
+\r
     return BOARD_SOK;\r
 }\r
 \r
@@ -211,7 +585,20 @@ Board_STATUS Board_i2cIoExpPinLevelSet(uint8_t slaveAddr,
                                        i2cIoExpPinNumber_t pinNum,\r
                                        i2cIoExpSignalLevel_t signalLevel)\r
 {\r
-    return BOARD_SOK;\r
+    Board_STATUS ret = BOARD_SOK;\r
+    uint8_t dataBuff;\r
+    uint8_t data;\r
+\r
+    ret = Board_i2cIoExpReadOutputPort(slaveAddr, ioExpType, portNum, &data);\r
+    if(ret != BOARD_SOK)\r
+    {\r
+        ret = BOARD_I2C_TRANSFER_FAIL;\r
+        return ret;\r
+    }\r
+\r
+    dataBuff = (signalLevel << pinNum);\r
+    data = ((data & ~(1 << pinNum)) | dataBuff);\r
+    return (Board_i2cIoExpWritePort(slaveAddr, ioExpType, portNum, data));\r
 }\r
 \r
 /**\r
@@ -238,6 +625,18 @@ Board_STATUS Board_i2cIoExpPinLevelGet(uint8_t slaveAddr,
                                        i2cIoExpPinNumber_t pinNum,\r
                                        uint8_t *signalLevel)\r
 {\r
+    Board_STATUS ret = BOARD_SOK;\r
+    uint8_t data;\r
+\r
+    ret = Board_i2cIoExpReadInputPort(slaveAddr, ioExpType, portNum, &data);\r
+    if(ret != BOARD_SOK)\r
+    {\r
+        ret = BOARD_I2C_TRANSFER_FAIL;\r
+        return ret;\r
+    }\r
+\r
+    *signalLevel = (((1 << pinNum) & (data)) >> pinNum);\r
+\r
     return BOARD_SOK;\r
 }\r
 \r
@@ -251,6 +650,17 @@ Board_STATUS Board_i2cIoExpInit(void)
 {\r
     Board_STATUS ret = BOARD_SOK;\r
 \r
+    /* If handle not opened yet, initializes i2c */\r
+    if (gIoExpI2cHandle == NULL)\r
+    {\r
+        gIoExpI2cHandle = Board_getI2CHandle(gBoardI2cInitCfg.socDomain,\r
+                                             gBoardI2cInitCfg.i2cInst);\r
+        if(gIoExpI2cHandle == NULL)\r
+        {\r
+            ret = BOARD_I2C_OPEN_FAIL;\r
+        }\r
+    }\r
+\r
     return ret;\r
 }\r
 \r
@@ -260,5 +670,7 @@ Board_STATUS Board_i2cIoExpInit(void)
  */\r
 void Board_i2cIoExpDeInit(void)\r
 {\r
-\r
+    /* Closing the i2c IO Exp Instance */\r
+    Board_i2cDeInit();\r
+    gIoExpI2cHandle = NULL;\r
 }\r
index 03fbaec030f4ba53fb98e1254107a38a0c12a1b5..2981dfab7e943d81f3ba7e5f3f09628b9bf30850 100644 (file)
@@ -56,8 +56,6 @@
 #include "board_internal.h"\r
 #include <ti/drv/sciclient/sciclient.h>\r
 \r
-Board_gblObj Board_obj = {NULL};\r
-\r
 static bool gBoardSysInitDone = 0;\r
 \r
 /**\r
index 72ec71ba16fc3f921df81b19ad82dae1547632a2..3c9599f777b325dcdc3d4dcd1bcce8f735453a55 100644 (file)
@@ -1,5 +1,5 @@
 /******************************************************************************\r
- * Copyright (c) 2019 Texas Instruments Incorporated - http://www.ti.com\r
+ * Copyright (c) 2020 Texas Instruments Incorporated - http://www.ti.com\r
  *\r
  *  Redistribution and use in source and binary forms, with or without\r
  *  modification, are permitted provided that the following conditions\r
  */\r
 \r
 #include "board_internal.h"\r
+#include "board_utils.h"\r
 #include "board_cfg.h"\r
 \r
+extern Board_I2cInitCfg_t gBoardI2cInitCfg;\r
+\r
+extern Board_initParams_t gBoardInitParams;\r
+static uint32_t gUARTBaseAddr = 0;\r
+static uint32_t gUARTClkFreq = 0;\r
+\r
+uint32_t gBoardI2cBaseAddr[BOARD_SOC_DOMAIN_MAX][I2C_HWIP_MAX_CNT] =\r
+    {{CSL_I2C0_CFG_BASE, CSL_I2C1_CFG_BASE, CSL_I2C3_CFG_BASE},\r
+     {CSL_MCU_I2C0_CFG_BASE, CSL_MCU_I2C1_CFG_BASE, 0}};\r
+\r
+Board_I2cObj_t gBoardI2cObj[BOARD_I2C_PORT_CNT] = {\r
+    {NULL, BOARD_SOC_DOMAIN_MAIN, 0, 0},\r
+    {NULL, BOARD_SOC_DOMAIN_MAIN, 1, 0},\r
+    {NULL, BOARD_SOC_DOMAIN_MAIN, 3, 0},\r
+};\r
+\r
+uint32_t gBoardUartBaseAddr[BOARD_SOC_DOMAIN_MAX][BOARD_UART_PER_CNT] =\r
+    {{CSL_UART0_BASE, CSL_UART1_BASE, CSL_UART3_BASE},\r
+     {CSL_MCU_UART0_BASE, CSL_MCU_UART1_BASE, 0}};\r
+\r
+/**\r
+ *  \brief   This function initializes the i2c instance connected to the\r
+ *           board Id EEPROM.\r
+ *\r
+ *  This function disables the interrupt mode as the Board i2c instance \r
+ *  doesn't require interrupt mode and restores back original at the end.\r
+ *\r
+ *  \param   i2cInst        [IN]        I2C instance.\r
+ *\r
+ *  \return  Board_STATUS in case of success or appropriate error code.\r
+ *\r
+ */\r
+Board_STATUS Board_internalInitI2C(uint8_t i2cInst)\r
+{\r
+    return BOARD_SOK;\r
+}\r
+\r
+/**\r
+  *  \brief   Returns base address of given I2C instance\r
+  *\r
+  *  \param   instNum [IN] I2C instance\r
+  *\r
+  *  \param   domain  [IN] Domain of I2C controller\r
+  *                           BOARD_SOC_DOMAIN_MAIN - Main Domain\r
+  *                           BOARD_SOC_DOMAIN_MCU - MCU domain\r
+  *\r
+  *  \return  Valid base address in case of success or 0\r
+  *\r
+  */\r
+static uint32_t Board_getI2cBaseAddr(uint8_t instNum,\r
+                                     uint8_t domain)\r
+{\r
+    uint32_t baseAddr = 0;\r
+\r
+    if((instNum < I2C_HWIP_MAX_CNT) &&\r
+       (domain <= BOARD_SOC_DOMAIN_MCU))\r
+    {\r
+        baseAddr = gBoardI2cBaseAddr[domain][instNum];\r
+    }\r
+\r
+    return (baseAddr);\r
+}\r
+\r
+/**\r
+  *  \brief   Returns base address of given UART instance\r
+  *\r
+  *  \param   instNum [IN] UART instance\r
+  *\r
+  *  \param   domain  [IN] Domain of UART controller\r
+  *                           BOARD_SOC_DOMAIN_MAIN - Main Domain\r
+  *                           BOARD_SOC_DOMAIN_MCU - MCU domain\r
+  *\r
+  *  \return  Valid base address in case of success or 0\r
+  *\r
+  */\r
+static uint32_t Board_getUartBaseAddr(uint8_t instNum,\r
+                                      uint8_t domain)\r
+{\r
+    uint32_t baseAddr = 0;\r
+\r
+    if((instNum < BOARD_UART_PER_CNT) &&\r
+       (domain <= BOARD_SOC_DOMAIN_MCU))\r
+    {\r
+        baseAddr = gBoardUartBaseAddr[domain][instNum];\r
+    }\r
+\r
+    return (baseAddr);\r
+}\r
+\r
 /**\r
  *  \brief   This function initializes the default UART instance for use for\r
  *           console operations.\r
  */\r
 Board_STATUS Board_uartStdioInit(void)\r
 {\r
-    UART_stdioInit(BOARD_UART_INSTANCE);\r
+    UART_HwAttrs uart_cfg;\r
+    uint32_t uartInst;\r
+    uint32_t uartBaseAddr;\r
+    uint32_t socDomainUART;\r
+    uint32_t socDomainCore;\r
+\r
+    uartInst      = gBoardInitParams.uartInst;\r
+    socDomainUART = gBoardInitParams.uartSocDomain;\r
+\r
+    socDomainCore = Board_getSocDomain();\r
+\r
+    /* Disable the UART interrupt */\r
+    UART_socGetInitCfg(uartInst, &uart_cfg);\r
+\r
+    if(socDomainUART != socDomainCore)\r
+    {\r
+        uartBaseAddr = Board_getUartBaseAddr(uartInst, socDomainUART);\r
+        if(uartBaseAddr != 0)\r
+        {\r
+            gUARTBaseAddr = uart_cfg.baseAddr;\r
+            uart_cfg.baseAddr = uartBaseAddr;\r
+        }\r
+        else\r
+        {\r
+            return BOARD_INVALID_PARAM;\r
+        }\r
+\r
+        gUARTClkFreq = uart_cfg.frequency;\r
+        if(socDomainUART == BOARD_SOC_DOMAIN_MAIN)\r
+        {\r
+            uart_cfg.frequency = BOARD_UART_CLK_MAIN;\r
+        }\r
+    }\r
+\r
+    uart_cfg.enableInterrupt = false;\r
+    UART_socSetInitCfg(uartInst, &uart_cfg);\r
+\r
+    UART_stdioInit(uartInst);\r
 \r
     return BOARD_SOK;\r
 }\r
 \r
 /**\r
- *  \brief   This function initializes the i2c instance connected to the\r
- *           board Id EEPROM.\r
+ *  \brief   This function is to get the i2c handle of the requested\r
+ *           instance of the specifed domain\r
  *\r
- *  This function disables the interrupt mode as the Board i2c instance \r
- *  doesn't require interrupt mode and restores back original at the end.\r
+ *  \param   domainType [IN] Domain of I2C controller\r
+ *                             BOARD_SOC_DOMAIN_MAIN - Main Domain\r
+ *                             BOARD_SOC_DOMAIN_MCU - MCU domain\r
  *\r
- *  \param   i2cInst        [IN]        I2C instance.\r
+ *  \param   i2cInst    [IN]        I2C instance\r
+ *\r
+ *  \return  Valid I2C handle in case of success or NULL in case of failure.\r
+ *\r
+ */\r
+I2C_Handle Board_getI2CHandle(uint8_t domainType,\r
+                              uint32_t i2cInst)\r
+{\r
+    Board_STATUS status;\r
+    Board_I2cInitCfg_t i2cCfg;\r
+\r
+    i2cCfg.i2cInst    = i2cInst;\r
+    i2cCfg.socDomain  = domainType;\r
+    i2cCfg.enableIntr = false;\r
+    Board_setI2cInitConfig(&i2cCfg);\r
+\r
+    status = Board_i2cInit();\r
+    if(status != BOARD_SOK)\r
+    {\r
+        return NULL;\r
+    }\r
+\r
+    return (gBoardI2cObj[i2cInst].i2cHandle);\r
+}\r
+\r
+/**\r
+ *  \brief   This function is to release the i2c handle acquired using\r
+ *           Board_getI2CHandle function\r
+ *\r
+ *  \param   hI2c [IN] I2C handle\r
  *\r
  *  \return  Board_STATUS in case of success or appropriate error code.\r
  *\r
  */\r
-Board_STATUS Board_internalInitI2C(uint8_t i2cInst)\r
+Board_STATUS Board_releaseI2CHandle(I2C_Handle hI2c)\r
+{\r
+    Board_STATUS status = BOARD_FAIL;\r
+    I2C_HwAttrs i2c_cfg;\r
+    uint32_t coreDomain;\r
+    uint32_t i2cInst;\r
+\r
+    if(hI2c != NULL)\r
+    {\r
+        for (i2cInst = 0; i2cInst < BOARD_I2C_PORT_CNT; i2cInst++)\r
+        {\r
+            if((hI2c == gBoardI2cObj[i2cInst].i2cHandle))\r
+            {\r
+                break;\r
+            }\r
+        }\r
+\r
+        if(i2cInst != BOARD_I2C_PORT_CNT)\r
+        {\r
+            I2C_close(gBoardI2cObj[i2cInst].i2cHandle);\r
+            gBoardI2cObj[i2cInst].i2cHandle = NULL;\r
+\r
+            coreDomain = Board_getSocDomain();\r
+\r
+            if(gBoardI2cObj[i2cInst].i2cDomain != coreDomain)\r
+            {\r
+                I2C_socGetInitCfg(i2cInst, &i2c_cfg);\r
+                i2c_cfg.baseAddr = gBoardI2cObj[i2cInst].i2cBaseAddr;\r
+                I2C_socSetInitCfg(i2cInst, &i2c_cfg);\r
+            }\r
+\r
+            status = BOARD_SOK;\r
+        }\r
+    }\r
+\r
+    return status;\r
+}\r
+\r
+/**\r
+  *  \brief   This function initializes the i2c instance set using\r
+  *           Board_setI2cInitConfig API.\r
+  *\r
+  *  \return  Board_STATUS in case of success or appropriate error code.\r
+  *\r
+  */\r
+Board_STATUS Board_i2cInit(void)\r
+{\r
+    I2C_Params i2cParams;\r
+    I2C_HwAttrs i2c_cfg;\r
+    uint32_t i2cInst;\r
+    uint32_t i2cBaseAddr;\r
+    uint32_t i2cDomain;\r
+    uint32_t coreDomain;\r
+\r
+    i2cInst   = gBoardI2cInitCfg.i2cInst;\r
+    i2cDomain = gBoardI2cInitCfg.socDomain;\r
+\r
+    if(gBoardI2cObj[i2cInst].i2cHandle == NULL)\r
+    {\r
+        coreDomain = Board_getSocDomain();\r
+\r
+        I2C_init();\r
+        I2C_socGetInitCfg(i2cInst, &i2c_cfg);\r
+\r
+        if(i2cDomain != coreDomain)\r
+        {\r
+            i2cBaseAddr = Board_getI2cBaseAddr(i2cInst, i2cDomain);\r
+            if(i2cBaseAddr != 0)\r
+            {\r
+                gBoardI2cObj[i2cInst].i2cBaseAddr = i2c_cfg.baseAddr;\r
+                i2c_cfg.baseAddr                  = i2cBaseAddr;\r
+            }\r
+            else\r
+            {\r
+                return BOARD_INVALID_PARAM;\r
+            }\r
+        }\r
+\r
+        i2c_cfg.enableIntr = gBoardI2cInitCfg.enableIntr;\r
+\r
+        I2C_socSetInitCfg(i2cInst, &i2c_cfg);\r
+        I2C_Params_init(&i2cParams);\r
+\r
+        gBoardI2cObj[i2cInst].i2cHandle = I2C_open(i2cInst, &i2cParams);\r
+        if (gBoardI2cObj[i2cInst].i2cHandle == NULL)\r
+        {\r
+            return BOARD_I2C_OPEN_FAIL;\r
+        }\r
+\r
+        gBoardI2cObj[i2cInst].i2cDomain = i2cDomain;\r
+        gBoardI2cObj[i2cInst].instNum   = i2cInst;\r
+    }\r
+    else\r
+    {\r
+        if(gBoardI2cObj[i2cInst].i2cDomain != i2cDomain)\r
+        {\r
+            return BOARD_I2C_OPEN_FAIL;\r
+        }\r
+    }\r
+\r
+    return BOARD_SOK;\r
+}\r
+\r
+/**\r
+ *  \brief   This function is used to close the initialized board I2C handle.\r
+ */\r
+Board_STATUS Board_i2cDeInit(void)\r
 {\r
+    uint32_t coreDomain;\r
+    I2C_HwAttrs i2c_cfg;\r
+    uint32_t i2cInst;\r
+\r
+    i2cInst = gBoardI2cInitCfg.i2cInst;\r
+\r
+    if(gBoardI2cObj[i2cInst].i2cHandle != NULL)\r
+    {\r
+        I2C_close(gBoardI2cObj[i2cInst].i2cHandle);\r
+        gBoardI2cObj[i2cInst].i2cHandle = NULL;\r
+\r
+        coreDomain = Board_getSocDomain();\r
+\r
+        if(gBoardI2cObj[i2cInst].i2cDomain != coreDomain)\r
+        {\r
+            I2C_socGetInitCfg(i2cInst, &i2c_cfg);\r
+            i2c_cfg.baseAddr = gBoardI2cObj[i2cInst].i2cBaseAddr;\r
+            I2C_socSetInitCfg(i2cInst, &i2c_cfg);\r
+        }\r
+    }\r
+\r
     return BOARD_SOK;\r
 }\r
 \r
@@ -77,5 +361,20 @@ Board_STATUS Board_internalInitI2C(uint8_t i2cInst)
  */\r
 Board_STATUS Board_uartDeInit(void)\r
 {\r
+    UART_HwAttrs uart_cfg;\r
+    uint32_t socDomainCore;\r
+\r
+    UART_stdioDeInit();\r
+\r
+    socDomainCore = Board_getSocDomain();\r
+\r
+    if(gBoardInitParams.uartSocDomain != socDomainCore)\r
+    {\r
+        UART_socGetInitCfg(gBoardInitParams.uartInst, &uart_cfg);\r
+        uart_cfg.baseAddr  = gUARTBaseAddr;\r
+        uart_cfg.frequency = gUARTClkFreq;\r
+        UART_socSetInitCfg(gBoardInitParams.uartInst, &uart_cfg);\r
+    }\r
+\r
     return BOARD_SOK;\r
 }\r
index a479901d1c4edf5187fac7708cb43d32802381ac..7835f7f5f88a1030d617d2f5ea7e069f090e6d98 100755 (executable)
@@ -166,6 +166,30 @@ bool Board_detectBoard(uint32_t boardID)
     return 0;\r
 }\r
 \r
+/**\r
+ * \brief Function to get the SoC domain\r
+ *\r
+ *  This function returns the domain of the SoC core on which\r
+ *  it is executing.\r
+ *\r
+ * \return   SoC domain of the core.\r
+ *\r
+ */\r
+uint32_t Board_getSocDomain(void)\r
+{\r
+    uint32_t socDomain;\r
+\r
+#if defined (BUILD_MPU)\r
+    socDomain = BOARD_SOC_DOMAIN_MAIN;\r
+#elif defined (BUILD_MCU)\r
+    socDomain = BOARD_SOC_DOMAIN_MCU;\r
+#else\r
+    #error "Unsupported core id"\r
+#endif\r
+\r
+  return socDomain;\r
+}\r
+\r
 /**\r
  *  \brief    Function to generate delay in micro seconds\r
  *\r
index 7220529761a28d1b2056d7a6d4b8106b5cbc5a20..6cafd0d0cf484c124bfd1e3688800cb1f12db294 100644 (file)
@@ -106,6 +106,12 @@ extern "C" {
 #endif\r
 #endif\r
 \r
+/* Clock frequency for UART module */\r
+#define BOARD_UART_CLK_MAIN                             (48000000U)\r
+\r
+/** @brief Number of UART instances */\r
+#define BOARD_UART_PER_CNT                              (6U)\r
+\r
 /* ICSSG UART instance number */\r
 #define BOARD_ICSSG_UART_INSTANCE                       (4U)\r
 \r
index 72df7edfb17460d2f78c3d7802ca60645f11f283..6d0f821cf4a14194a34a3f7984a275523b5031da 100644 (file)
@@ -1,5 +1,5 @@
 /******************************************************************************\r
- * Copyright (c) 2019 Texas Instruments Incorporated - http://www.ti.com\r
+ * Copyright (c) 2020 Texas Instruments Incorporated - http://www.ti.com\r
  *\r
  *  Redistribution and use in source and binary forms, with or without\r
  *  modification, are permitted provided that the following conditions\r
@@ -45,6 +45,7 @@
 #define _BOARD_I2C_IO_EXP_H_\r
 \r
 #include "board_internal.h"\r
+#include "board_utils.h"\r
 \r
 #ifdef __cplusplus\r
 extern "C" {\r
@@ -55,33 +56,7 @@ extern "C" {
 #include <stdlib.h>\r
 #include <string.h>\r
 \r
-/* Input command for single port IO expander */\r
-#define BOARD_1PORT_IOEXP_INPUT_CMD                             (0x00U)\r
-\r
-/* Output command for single port IO expander */\r
-#define BOARD_1PORT_IOEXP_OUTPUT_CMD                            (0x01U)\r
-\r
-/* Polarity inversion command for single port IO expander */\r
-#define BOARD_1PORT_IOEXP_POLARITY_CMD                          (0x02U)\r
-\r
-/* Configuration command for single port IO expander */\r
-#define BOARD_1PORT_IOEXP_CONFIGURATION_CMD                     (0x03U)\r
-\r
-/* Input commands for two port IO expander */\r
-#define BOARD_2PORT_IOEXP_PORT0_INPUT_CMD                       (0x00U)\r
-#define BOARD_2PORT_IOEXP_PORT1_INPUT_CMD                       (0x01U)\r
-\r
-/* Output commands for two port IO expander */\r
-#define BOARD_2PORT_IOEXP_PORT0_OUTPUT_CMD                      (0x02U)\r
-#define BOARD_2PORT_IOEXP_PORT1_OUTPUT_CMD                      (0x03U)\r
-\r
-/* Polarity inversion commands for two port IO expander */\r
-#define BOARD_2PORT_IOEXP_PORT0_POLARITY_CMD                    (0x04U)\r
-#define BOARD_2PORT_IOEXP_PORT1_POLARITY_CMD                    (0x05U)\r
-\r
-/* Configuration commands for two port IO expander */\r
-#define BOARD_2PORT_IOEXP_PORT0_CONFIGURATION_CMD               (0x06U)\r
-#define BOARD_2PORT_IOEXP_PORT1_CONFIGURATION_CMD               (0x07U)\r
+#define BOARD_IO_EXP_INPUT_PORT0_ADDR                           (0x00)\r
 \r
 /* Input commands for three port IO expander */\r
 #define BOARD_3PORT_IOEXP_PORT0_INPUT_CMD                       (0x00U)\r
@@ -102,6 +77,10 @@ extern "C" {
 #define BOARD_3PORT_IOEXP_PORT0_CONFIGURATION_CMD               (0x0CU)\r
 #define BOARD_3PORT_IOEXP_PORT1_CONFIGURATION_CMD               (0x0DU)\r
 #define BOARD_3PORT_IOEXP_PORT2_CONFIGURATION_CMD               (0x0EU)\r
+/* This command is used to write data to the data shift register and transfer\r
+   it to the output storage register immediately (extra load 22H command not\r
+   needed) */\r
+#define BOARD_IO_EXP_CMD_DIRECT_LOAD_DATA_OUPTUT                (0x44)\r
 \r
 /**\r
  *  \enum    i2cIoExpType_t\r
@@ -110,9 +89,7 @@ extern "C" {
  */\r
 typedef enum\r
 {\r
-    ONE_PORT_IOEXP = 0,\r
-    TWO_PORT_IOEXP,\r
-    THREE_PORT_IOEXP\r
+    THREE_PORT_IOEXP = 0\r
 }i2cIoExpType_t;\r
 \r
 /**\r
@@ -124,7 +101,8 @@ typedef enum
 {\r
     PORTNUM_0 = 0,\r
     PORTNUM_1,\r
-    PORTNUM_2\r
+    PORTNUM_2,\r
+    PORTNUM_NONE\r
 }i2cIoExpPortNumber_t;\r
 \r
 /**\r
index 7df311b632d891185e4894af5baaa63fa1eac550..7776c604da5e811411b11fc18ee336f20a21c687 100644 (file)
@@ -82,23 +82,20 @@ extern "C" {
  *****************************************************************************/\r
 extern I2C_config_list I2C_config;\r
 \r
-typedef struct\r
+typedef struct Board_I2cObj_s\r
 {\r
-    I2C_Handle i2cHandle;\r
-} Board_gblObj;\r
-\r
-extern Board_gblObj Board_obj;\r
+    I2C_Handle    i2cHandle;\r
+    uint8_t       i2cDomain;\r
+    uint32_t      instNum;\r
+    uint32_t      i2cBaseAddr;\r
+} Board_I2cObj_t;\r
 \r
 /****************************************************************************/\r
 \r
 #define KICK0_UNLOCK_VAL                     (0x68EF3490U)\r
 #define KICK1_UNLOCK_VAL                     (0xD172BC5AU)\r
 \r
-/* The below macro are for temporary use only, Once the CSL macros are \r
- *  added these can be removed */ \r
-\r
-#define MAIN_PSC_ADDR_OFFSET                 (0x80000000U)  //J7ES_TODO: Need to update\r
-#define WAKEUP_PSC_ADDR_OFFSET               (0x20000000U)  //J7ES_TODO: Need to update\r
+#define BOARD_I2C_PORT_CNT                   (I2C_HWIP_MAX_CNT)\r
 \r
 /*****************************************************************************\r
  * Function Prototypes                                                       *\r
@@ -211,6 +208,42 @@ Board_STATUS Board_uartDeInit(void);
  */\r
 Board_STATUS Board_internalInitI2C(uint8_t i2cInst);\r
 \r
+/**\r
+ *  \brief   This function is used to close all the initialized board I2C handles.\r
+ *\r
+ *  \return  Board_STATUS in case of success or appropriate error code.\r
+ */\r
+Board_STATUS Board_i2cDeInit(void);\r
+\r
+/**\r
+  *  \brief   This function initializes the i2c instance connected to\r
+  *           different control modules on the board\r
+  *\r
+  *  This function disables the interrupt mode as the Board i2c instance\r
+  *  doesn't require interrupt mode and restores back original at the end.\r
+  *\r
+  *  \return  Board_STATUS in case of success or appropriate error code.\r
+  *\r
+  */\r
+Board_STATUS Board_i2cInit(void);\r
+\r
+/**\r
+ *  \brief   This function is to get the i2c handle of the requested\r
+ *           instance of the specifed domain\r
+ *\r
+ *  \param   domainType [IN] Domain of I2C controller\r
+ *                             BOARD_SOC_DOMAIN_MAIN - Main Domain\r
+ *                             BOARD_SOC_DOMAIN_WKUP - Wakeup domain\r
+ *                             BOARD_SOC_DOMAIN_MCU - MCU domain\r
+ *\r
+ *  \param   i2cInst    [IN]        I2C instance\r
+ *\r
+ *  \return  Board_STATUS in case of success or appropriate error code.\r
+ *\r
+ */\r
+I2C_Handle Board_getI2CHandle(uint8_t domainType,\r
+                              uint32_t i2cInst);\r
+\r
 /**\r
  * \brief  Unlocks MMR registers\r
  *\r
index a0fc266352249d9f7b31b9325dfe479571e3a717..351e006a6709ad6b0af17c23fc4759578543a22f 100755 (executable)
@@ -161,6 +161,17 @@ Board_STATUS Board_getI2cInitConfig(Board_I2cInitCfg_t *i2cCfg);
  */
 Board_STATUS Board_setI2cInitConfig(Board_I2cInitCfg_t *i2cCfg);
 
+/**
+ * \brief Function to get the SoC domain
+ *
+ *  This function returns the domain of the SoC core on which
+ *  it is executing.
+ *
+ * \return   SoC domain of the core.
+ *
+ */
+uint32_t Board_getSocDomain(void);
+
 /**
  *  \brief    Function to generate delay in micro seconds
  *