summaryrefslogtreecommitdiffstatsabout
diff options
context:
space:
mode:
authorzhangguoqing <zhangguoqing@acoinfo.com>2019-01-22 07:00:24 (GMT)
committer zhangguoqing <zhangguoqing@acoinfo.com>2019-01-22 07:03:33 (GMT)
commit7197f6d705d1fa1d8182bf80202c7212011f9cb2 (patch)
tree4f0dc6b344f7c5b7b1c02ccb2526a9d81fd57933
parent1f0af4e7f7e04e59b6b6adb6d8aa5695ddd9e373 (diff)
downloadbspam335x-7197f6d705d1fa1d8182bf80202c7212011f9cb2.zip
bspam335x-7197f6d705d1fa1d8182bf80202c7212011f9cb2.tar.gz
bspam335x-7197f6d705d1fa1d8182bf80202c7212011f9cb2.tar.bz2
1.Fixed net phy scan and ifparam.ini configuration mac addr bug.
2.Fixed can receive extended frame and set baud rate error. 3.Fixed spi to send bug.
-rw-r--r--SylixOS/bsp/bspLib.c2
-rw-r--r--SylixOS/driver/can/am335x_can.c19
-rw-r--r--SylixOS/driver/netif/cpswif.c47
-rw-r--r--SylixOS/driver/spi/am335x_spi.c45
4 files changed, 102 insertions, 11 deletions
diff --git a/SylixOS/bsp/bspLib.c b/SylixOS/bsp/bspLib.c
index 14db21c..7fc16d4 100644
--- a/SylixOS/bsp/bspLib.c
+++ b/SylixOS/bsp/bspLib.c
@@ -44,7 +44,7 @@ extern VOID bspDebugPutc(CHAR cChar);
static const CHAR _G_pcCpuInfo[] = "TI AM335X (Cortex-A8 Max@1GHz VFPv3 NEON)";
static const CHAR _G_pcCacheInfo[] = "64KBytes L1-Cache(D-32K/I-32K), 256KBytes L2-Cache";
static const CHAR _G_pcPacketInfo[] = BSP_CFG_PLATFORM_NAME;
-static const CHAR _G_pcVersionInfo[] = "BSP version 1.1.0";
+static const CHAR _G_pcVersionInfo[] = "BSP version 1.1.1";
/*********************************************************************************************************
中断相关
*********************************************************************************************************/
diff --git a/SylixOS/driver/can/am335x_can.c b/SylixOS/driver/can/am335x_can.c
index 82e5b98..e8ff67d 100644
--- a/SylixOS/driver/can/am335x_can.c
+++ b/SylixOS/driver/can/am335x_can.c
@@ -284,7 +284,7 @@ static INT __am335xCanStartup (CAN_CHAN *pcanchan)
static INT __am335xCanStartupRx (CAN_CHAN *pcanchan)
{
__PAM335X_CAN_CHAN pCanChan = container_of(pcanchan,
- __AM335X_CAN_CHAN, CANCHAN_canChan);
+ __AM335X_CAN_CHAN, CANCHAN_canChan);
can_frame dcanFrame;
dcanFrame.flag = (CAN_MSG_DIR_RX | CAN_DATA_FRAME);
@@ -391,7 +391,7 @@ static irqreturn_t __am335xCanIsr (__PAM335X_CAN_CHAN pCanChan, ULONG ulVecto
__am335xCanStartup(&pCanChan->CANCHAN_canChan);
}
- if ((uiMsgNum >= (CAN_NUM_OF_MSG_OBJS / 2)) && (uiMsgNum < CAN_NUM_OF_MSG_OBJS)) {
+ if ((uiMsgNum >= (CAN_NUM_OF_MSG_OBJS / 2)) && (uiMsgNum <= CAN_NUM_OF_MSG_OBJS)) {
/* Read a received message from message RAM to interface register */
CANReadMsgObjData(pCanChan->CANCHAN_ulVirtAddrBase, uiMsgNum, (UINT *)auiData,
@@ -588,7 +588,22 @@ static INT __am335xCanIoctl (CAN_CHAN *pcanchan,
/*
* Configure the bit timing values for CAN communication
*/
+ /* Enter the Initialization mode of CAN controller */
+ DCANInitModeSet(pCanChan->CANCHAN_ulVirtAddrBase);
+
+ /* Enable the write access to the DCAN configuration registers */
+ DCANConfigRegWriteAccessControl(pCanChan->CANCHAN_ulVirtAddrBase,
+ DCAN_CONF_REG_WR_ACCESS_ENABLE);
+ /* Wait for Init bit to set */
+ while(!(HWREG(pCanChan->CANCHAN_ulVirtAddrBase + DCAN_CTL) & DCAN_CTL_INIT));
+
+ _PrintFormat("__am335xCanIoctl: CAN_DEV_SET_BAUD %d\n\r", pCanChan->CANCHAN_uiBaud);
CANSetBitTiming(pCanChan->CANCHAN_ulVirtAddrBase, __DCAN_IN_CLK, pCanChan->CANCHAN_uiBaud);
+ /* Disable the write access to the DCAN configuration registers */
+ DCANConfigRegWriteAccessControl(pCanChan->CANCHAN_ulVirtAddrBase,
+ DCAN_CONF_REG_WR_ACCESS_DISABLE);
+ /* Start the CAN transfer */
+ DCANNormalModeSet(pCanChan->CANCHAN_ulVirtAddrBase);
break;
default:
diff --git a/SylixOS/driver/netif/cpswif.c b/SylixOS/driver/netif/cpswif.c
index 7294b39..686d84e 100644
--- a/SylixOS/driver/netif/cpswif.c
+++ b/SylixOS/driver/netif/cpswif.c
@@ -45,6 +45,7 @@
#define __SYLIXOS_KERNEL
#include "config.h"
#include "SylixOS.h"
+#include "net/if_ether.h"
#include "netdev.h"
#include "cpswif.h"
#include "cpswlib.h"
@@ -289,6 +290,7 @@ struct cpswinst{
#ifdef SYLIXOS
LW_HANDLE txlock;
u32_t cppi_ram_size;
+ u32_t phy_valid;
#if BSP_CFG_CPSW_TX_DMA_PBUF > 0
LW_OBJECT_HANDLE tx_pbuf_partition;
PVOID tx_pbuf_pool;
@@ -2110,7 +2112,10 @@ cpswif_phylink_config(struct cpswportif * cpswif, u32_t slv_port_num) {
for (i = 0; i < 32; i++) {
if (MDIOPhyAliveStatusGet(cpswinst->mdio_base) & (1 << i)) {
- break;
+ if (!(cpswinst->phy_valid & (1 << i))) {
+ cpswinst->phy_valid |= (1 << i);
+ break;
+ }
} else {
LWIP_PRINTF("No PHY found at address %d for Port %d of Instance %d.",
i, slv_port_num,
@@ -2129,6 +2134,8 @@ cpswif_phylink_config(struct cpswportif * cpswif, u32_t slv_port_num) {
} else {
cpswinst->port[slv_port_num - 1].phy_addr = i;
}
+ } else {
+ cpswinst->phy_valid |= 1 << cpswinst->port[slv_port_num - 1].phy_addr;
}
#endif
@@ -2169,7 +2176,24 @@ cpswif_phylink_config(struct cpswportif * cpswif, u32_t slv_port_num) {
return err;
}
#endif
+#ifdef SYLIXOS
+void cpswif_mac_addr_random(unsigned char *addr)
+{
+ int i = 0;
+ srand((unsigned)time(NULL));
+ for (i = 0; i < ETH_ALEN; i++) {
+ addr[i] = rand() & 0xff;
+ }
+ addr[0] &= 0xfe; /* clear multicast bit */
+ addr[0] |= 0x02; /* set local assignment bit (IEEE802) */
+}
+static inline int is_valid_ether_addr(unsigned char *addr)
+{
+ const char zaddr[6] = { 0, };
+ return !(addr[0] & 1) && memcmp(addr, zaddr, 6);
+}
+#endif
/**
* Initializes the CPSW port
* @param netdev The cpsw interface
@@ -2392,11 +2416,30 @@ cpswif_inst_init(struct cpswportif *cpswif){
*/
INT cpswif_init(netdev_t *netdev)
{
-
struct cpswportif *cpswif = (struct cpswportif*)(netdev->priv);
static u32_t inst_init_flag = 0;
u32_t inst_num = cpswif->inst_num;
+ if (netdev->hwaddr[0] == 0 &&
+ netdev->hwaddr[1] == 0 &&
+ netdev->hwaddr[2] == 0 &&
+ netdev->hwaddr[3] == 0 &&
+ netdev->hwaddr[4] == 0 &&
+ netdev->hwaddr[5] == 0) {
+ lib_memcpy(netdev->hwaddr, cpswif->eth_addr, netdev->hwaddr_len);
+ } else {
+ if (!is_valid_ether_addr(netdev->hwaddr)) {
+ printk("cpswif_init: invalid user MAC Address use default MAC Address\n");
+ lib_memcpy(netdev->hwaddr, cpswif->eth_addr, netdev->hwaddr_len);
+ } else {
+ lib_memcpy(cpswif->eth_addr, netdev->hwaddr, netdev->hwaddr_len);
+ }
+ }
+ if (!is_valid_ether_addr(netdev->hwaddr)) {
+ printk("cpswif_init: invalid MAC Address use random MAC Address\n");
+ cpswif_mac_addr_random(netdev->hwaddr);
+ lib_memcpy(cpswif->eth_addr, netdev->hwaddr, netdev->hwaddr_len);
+ }
/**
* Initialize an instance only once. Port initialization will be
* done separately.
diff --git a/SylixOS/driver/spi/am335x_spi.c b/SylixOS/driver/spi/am335x_spi.c
index 122bc1c..ea154fd 100644
--- a/SylixOS/driver/spi/am335x_spi.c
+++ b/SylixOS/driver/spi/am335x_spi.c
@@ -30,6 +30,7 @@
#define __MCSPI_CHANNEL_NR (2)
#define __MCSPI_MODULE_INPUT_CLK (48000000)
#define __MCSPI_OUT_FREQ (24000000)
+#define __WAIT_STATE_LOOPS (4000)
/*********************************************************************************************************
McASP 通道类型定义
*********************************************************************************************************/
@@ -64,6 +65,26 @@ static __AM335X_SPI_CHANNEL _G_am335xSpiChannels[__MCSPI_CHANNEL_NR] = {
EDMA3_CHA_MCSPI1_CH0_TX,
},
};
+
+/*********************************************************************************************************
+** 函数名称: __am335xWaitBit
+** 功能描述: 轮询等待状态
+** 输 入 : addReg 寄存器的地址
+** ulStatus 等待状态
+** 输 出 : 超时返回 0
+** 全局变量:
+** 调用模块:
+*********************************************************************************************************/
+static int __am335xWaitBit (addr_t addrReg, unsigned long ulStatus)
+{
+ INT i = __WAIT_STATE_LOOPS;
+
+ do {
+
+ } while ( ( !(HWREG(addrReg) & ulStatus) ) && (--i > 0));
+
+ return (i > 0);
+}
/*********************************************************************************************************
** 函数名称: __am335xSpiDmaDone
** 功能描述: spi DMA 完成回调函数
@@ -94,6 +115,7 @@ static INT __am335xSpiTransferMsg (__PAM335X_SPI_CHANNEL pSpiChannel,
LW_DMA_TRANSACTION dmaTransAction;
INT iError;
UINT uiEvent = 0;
+ addr_t uiStatReg;
if ((pSpiMsg->SPIMSG_pucWrBuffer == LW_NULL &&
pSpiMsg->SPIMSG_pucRdBuffer == LW_NULL) ||
@@ -101,6 +123,8 @@ static INT __am335xSpiTransferMsg (__PAM335X_SPI_CHANNEL pSpiChannel,
return (PX_ERROR);
}
+ uiStatReg = pSpiChannel->SPICHAN_ulVirtAddrBase + MCSPI_CHSTAT(pSpiChannel->SPICHAN_uiChannel);
+
API_SemaphoreCClear(pSpiChannel->SPICHAN_hSignal);
if (pSpiMsg->SPIMSG_pucRdBuffer) {
@@ -139,17 +163,21 @@ static INT __am335xSpiTransferMsg (__PAM335X_SPI_CHANNEL pSpiChannel,
if (pSpiMsg->SPIMSG_pucWrBuffer) {
lib_memset(&dmaTransAction, 0, sizeof(dmaTransAction));
-
+ /*
+ * dma 源地址
+ */
dmaTransAction.DMAT_pucSrcAddress = pSpiMsg->SPIMSG_pucWrBuffer;
if (pSpiMsg->SPIMSG_usFlag & LW_SPI_M_WRBUF_FIX) {
- dmaTransAction.DMAT_iSrcAddrCtl = LW_DMA_ADDR_FIX;
+ dmaTransAction.DMAT_iSrcAddrCtl = LW_DMA_ADDR_FIX; /* 源地址地址不变 */
} else {
- dmaTransAction.DMAT_iSrcAddrCtl = LW_DMA_ADDR_INC;
+ dmaTransAction.DMAT_iSrcAddrCtl = LW_DMA_ADDR_INC; /* 源地址地址增长 */
}
-
+ /*
+ * dma 目的地址
+ */
dmaTransAction.DMAT_pucDestAddress = (UINT8 *)(pSpiChannel->SPICHAN_ulTxRegPhyAddrBase);
- dmaTransAction.DMAT_iDestAddrCtl = LW_DMA_ADDR_FIX;
+ dmaTransAction.DMAT_iDestAddrCtl = LW_DMA_ADDR_FIX; /* 目的地址不变 */
dmaTransAction.DMAT_iTransMode = EDMA3_MAKE_TARNS_MODE(EDMA3_TARNS_MODE_A_SYNC,
EDMA3_TARNS_MODE_TRIG_MODE_EVENT,
@@ -194,6 +222,11 @@ static INT __am335xSpiTransferMsg (__PAM335X_SPI_CHANNEL pSpiChannel,
iError |= API_SemaphoreCPend(pSpiChannel->SPICHAN_hSignal, LW_OPTION_WAIT_INFINITE);
}
+ if (!__am335xWaitBit(uiStatReg, MCSPI_CH_TXFFE)) {
+ printk(KERN_ERR "__am335xSpiTransferMsg(): transfer time out!\n");
+ return (PX_ERROR);
+ }
+
/* Disable the Tx/Rx DMA events for McSPI. */
McSPIDMADisable(pSpiChannel->SPICHAN_ulVirtAddrBase, uiEvent, pSpiChannel->SPICHAN_uiChannel);
@@ -346,7 +379,7 @@ static INT __am335xSpiHwInit(__PAM335X_SPI_CHANNEL pSpiChannel, PAM335X_PINMUX
return (PX_ERROR);
}
- am335xPinMuxSetup(pPinMux);
+ am335xPinMuxSetup(pPinMux); /* 管脚复用 */
/* Reset the McSPI instance.*/
McSPIReset(pSpiChannel->SPICHAN_ulVirtAddrBase);