mirror of https://github.com/rusefi/openblt.git
Refs #847. Enabled firmware updates via TCP/IP in the XMC4700 Relax Kit demo bootloader for Keil MDK for ARM.
git-svn-id: https://svn.code.sf.net/p/openblt/code/trunk@949 5dc33758-31d5-4daf-9ae8-b24bf3d40d73
This commit is contained in:
parent
ffd5a22c07
commit
5b1a1cd8f8
File diff suppressed because it is too large
Load Diff
|
@ -118,7 +118,7 @@
|
|||
* configuring the IP address, network mask and gateway address are no longer needed.
|
||||
*/
|
||||
/** \brief Enable/disable the NET transport layer. */
|
||||
#define BOOT_COM_NET_ENABLE (0)
|
||||
#define BOOT_COM_NET_ENABLE (1)
|
||||
/** \brief Configure number of bytes in the target->host data packet. */
|
||||
#define BOOT_COM_NET_TX_MAX_DATA (64)
|
||||
/** \brief Configure number of bytes in the host->target data packet. */
|
||||
|
@ -185,7 +185,7 @@
|
|||
* firmware update is completed by the bootloader.
|
||||
*/
|
||||
/** \brief Enable/disable support for firmware updates from a locally attached storage.*/
|
||||
#define BOOT_FILE_SYS_ENABLE (1)
|
||||
#define BOOT_FILE_SYS_ENABLE (0)
|
||||
/** \brief Enable/disable logging messages during firmware updates. */
|
||||
#define BOOT_FILE_LOGGING_ENABLE (1)
|
||||
/** \brief Enable/disable a hook function that is called upon detection of an error. */
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -313,7 +313,7 @@
|
|||
</ArmAdsMisc>
|
||||
<Cads>
|
||||
<interw>1</interw>
|
||||
<Optim>2</Optim>
|
||||
<Optim>3</Optim>
|
||||
<oTime>0</oTime>
|
||||
<SplitLS>0</SplitLS>
|
||||
<OneElfS>1</OneElfS>
|
||||
|
@ -337,9 +337,9 @@
|
|||
<v6Rtti>0</v6Rtti>
|
||||
<VariousControls>
|
||||
<MiscControls>--diag_suppress=111</MiscControls>
|
||||
<Define>XMC4700_F144x2048</Define>
|
||||
<Define>XMC4700_F144x2048 XMC_ETH_PHY_KSZ8081RNB</Define>
|
||||
<Undefine></Undefine>
|
||||
<IncludePath>..\..\Boot;..\lib;..\lib\cmsis;..\lib\xmclib\inc;..\lib\FatFS;..\lib\FatFS\SDMMC_BLOCK;..\..\..\..\Source;..\..\..\..\Source\ARMCM4_XMC4;..\..\..\..\Source\third_party\fatfs\src</IncludePath>
|
||||
<IncludePath>..\..\Boot;..\lib;..\lib\cmsis;..\lib\xmclib\inc;..\lib\FatFS;..\lib\FatFS\SDMMC_BLOCK;..\lib\uip;..\..\..\..\Source;..\..\..\..\Source\ARMCM4_XMC4;..\..\..\..\Source\third_party\fatfs\src;..\..\..\..\Source\third_party\uip\uip;..\..\..\..\Source\third_party\uip\apps\dhcpc</IncludePath>
|
||||
</VariousControls>
|
||||
</Cads>
|
||||
<Aads>
|
||||
|
@ -361,7 +361,7 @@
|
|||
</VariousControls>
|
||||
</Aads>
|
||||
<LDads>
|
||||
<umfTarg>1</umfTarg>
|
||||
<umfTarg>0</umfTarg>
|
||||
<Ropi>0</Ropi>
|
||||
<Rwpi>0</Rwpi>
|
||||
<noStLib>0</noStLib>
|
||||
|
@ -370,7 +370,7 @@
|
|||
<TextAddressRange>0x08000000</TextAddressRange>
|
||||
<DataAddressRange>0x20000000</DataAddressRange>
|
||||
<pXoBase></pXoBase>
|
||||
<ScatterFile>..\bin\openblt_xmc4700.sct</ScatterFile>
|
||||
<ScatterFile>..\xmc4700.sct</ScatterFile>
|
||||
<IncludeLibs></IncludeLibs>
|
||||
<IncludeLibsPath></IncludeLibsPath>
|
||||
<Misc></Misc>
|
||||
|
@ -413,6 +413,16 @@
|
|||
<FileType>2</FileType>
|
||||
<FilePath>..\startup_XMC4700.s</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>shared_params.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\shared_params.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>shared_params.h</FileName>
|
||||
<FileType>5</FileType>
|
||||
<FilePath>..\shared_params.h</FilePath>
|
||||
</File>
|
||||
</Files>
|
||||
</Group>
|
||||
<Group>
|
||||
|
@ -1055,6 +1065,36 @@
|
|||
</File>
|
||||
</Files>
|
||||
</Group>
|
||||
<Group>
|
||||
<GroupName>Lib/uip</GroupName>
|
||||
<Files>
|
||||
<File>
|
||||
<FileName>clock-arch.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\lib\uip\clock-arch.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>clock-arch.h</FileName>
|
||||
<FileType>5</FileType>
|
||||
<FilePath>..\lib\uip\clock-arch.h</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>netdev.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\lib\uip\netdev.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>netdev.h</FileName>
|
||||
<FileType>5</FileType>
|
||||
<FilePath>..\lib\uip\netdev.h</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>uip-conf.h</FileName>
|
||||
<FileType>5</FileType>
|
||||
<FilePath>..\lib\uip\uip-conf.h</FilePath>
|
||||
</File>
|
||||
</Files>
|
||||
</Group>
|
||||
<Group>
|
||||
<GroupName>Core</GroupName>
|
||||
<Files>
|
||||
|
@ -1255,6 +1295,96 @@
|
|||
</File>
|
||||
</Files>
|
||||
</Group>
|
||||
<Group>
|
||||
<GroupName>Core/third_party/uip</GroupName>
|
||||
<Files>
|
||||
<File>
|
||||
<FileName>clock.h</FileName>
|
||||
<FileType>5</FileType>
|
||||
<FilePath>..\..\..\..\Source\third_party\uip\uip\clock.h</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>lc.h</FileName>
|
||||
<FileType>5</FileType>
|
||||
<FilePath>..\..\..\..\Source\third_party\uip\uip\lc.h</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>lc-addrlabels.h</FileName>
|
||||
<FileType>5</FileType>
|
||||
<FilePath>..\..\..\..\Source\third_party\uip\uip\lc-addrlabels.h</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>lc-switch.h</FileName>
|
||||
<FileType>5</FileType>
|
||||
<FilePath>..\..\..\..\Source\third_party\uip\uip\lc-switch.h</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>pt.h</FileName>
|
||||
<FileType>5</FileType>
|
||||
<FilePath>..\..\..\..\Source\third_party\uip\uip\pt.h</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>uip.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\..\..\..\Source\third_party\uip\uip\uip.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>uip.h</FileName>
|
||||
<FileType>5</FileType>
|
||||
<FilePath>..\..\..\..\Source\third_party\uip\uip\uip.h</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>uip_arch.h</FileName>
|
||||
<FileType>5</FileType>
|
||||
<FilePath>..\..\..\..\Source\third_party\uip\uip\uip_arch.h</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>uip_arp.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\..\..\..\Source\third_party\uip\uip\uip_arp.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>uip_arp.h</FileName>
|
||||
<FileType>5</FileType>
|
||||
<FilePath>..\..\..\..\Source\third_party\uip\uip\uip_arp.h</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>uip_timer.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\..\..\..\Source\third_party\uip\uip\uip_timer.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>uip_timer.h</FileName>
|
||||
<FileType>5</FileType>
|
||||
<FilePath>..\..\..\..\Source\third_party\uip\uip\uip_timer.h</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>uiplib.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\..\..\..\Source\third_party\uip\uip\uiplib.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>uiplib.h</FileName>
|
||||
<FileType>5</FileType>
|
||||
<FilePath>..\..\..\..\Source\third_party\uip\uip\uiplib.h</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>uipopt.h</FileName>
|
||||
<FileType>5</FileType>
|
||||
<FilePath>..\..\..\..\Source\third_party\uip\uip\uipopt.h</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>dhcpc.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\..\..\..\Source\third_party\uip\apps\dhcpc\dhcpc.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>dhcpc.h</FileName>
|
||||
<FileType>5</FileType>
|
||||
<FilePath>..\..\..\..\Source\third_party\uip\apps\dhcpc\dhcpc.h</FilePath>
|
||||
</File>
|
||||
</Files>
|
||||
</Group>
|
||||
</Groups>
|
||||
</Target>
|
||||
</Targets>
|
||||
|
|
|
@ -0,0 +1,50 @@
|
|||
/*
|
||||
* Copyright (c) 2006, Swedish Institute of Computer Science.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the Institute nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* This file is part of the uIP TCP/IP stack
|
||||
*
|
||||
* $Id: clock-arch.c,v 1.2 2006/06/12 08:00:31 adam Exp $
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file
|
||||
* Implementation of architecture-specific clock functionality
|
||||
* \author
|
||||
* Adam Dunkels <adam@sics.se>
|
||||
*/
|
||||
|
||||
#include "clock-arch.h"
|
||||
#include "boot.h"
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
clock_time_t
|
||||
clock_time(void)
|
||||
{
|
||||
return (clock_time_t)TimerGet();
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
|
@ -0,0 +1,40 @@
|
|||
/*
|
||||
* Copyright (c) 2006, Swedish Institute of Computer Science.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the Institute nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* This file is part of the uIP TCP/IP stack
|
||||
*
|
||||
* $Id: clock-arch.h,v 1.2 2006/06/12 08:00:31 adam Exp $
|
||||
*/
|
||||
|
||||
#ifndef __CLOCK_ARCH_H__
|
||||
#define __CLOCK_ARCH_H__
|
||||
|
||||
typedef int clock_time_t;
|
||||
#define CLOCK_CONF_SECOND 1000
|
||||
|
||||
#endif /* __CLOCK_ARCH_H__ */
|
|
@ -0,0 +1,298 @@
|
|||
/*
|
||||
* Copyright (c) 2001, Swedish Institute of Computer Science.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the Institute nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* Author: Adam Dunkels <adam@sics.se>
|
||||
*
|
||||
* $Id: netdev.c,v 1.8 2006/06/07 08:39:58 adam Exp $
|
||||
*/
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#include "uip.h"
|
||||
#include "uip_arp.h"
|
||||
#include "boot.h"
|
||||
#include "xmc_gpio.h"
|
||||
#include "xmc_eth_mac.h"
|
||||
#include "xmc_eth_phy.h"
|
||||
#include <string.h>
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#define NETDEV_LINKUP_TIMEOUT_MS (5000)
|
||||
|
||||
#define NETDEV_DEFAULT_MACADDR0 (0x08)
|
||||
#define NETDEV_DEFAULT_MACADDR1 (0x00)
|
||||
#define NETDEV_DEFAULT_MACADDR2 (0x27)
|
||||
#define NETDEV_DEFAULT_MACADDR3 (0x69)
|
||||
#define NETDEV_DEFAULT_MACADDR4 (0x5B)
|
||||
#define NETDEV_DEFAULT_MACADDR5 (0x45)
|
||||
|
||||
#define NETDEV_DEFAULT_MACADDR ((uint64_t)NETDEV_DEFAULT_MACADDR0 | \
|
||||
((uint64_t)NETDEV_DEFAULT_MACADDR1 << 8) | \
|
||||
((uint64_t)NETDEV_DEFAULT_MACADDR2 << 16) | \
|
||||
((uint64_t)NETDEV_DEFAULT_MACADDR3 << 24) | \
|
||||
((uint64_t)NETDEV_DEFAULT_MACADDR4 << 32) | \
|
||||
((uint64_t)NETDEV_DEFAULT_MACADDR5 << 40))
|
||||
|
||||
#define ETH_UIP_0_NUM_RX_BUF (4U)
|
||||
#define ETH_UIP_0_NUM_TX_BUF (4U)
|
||||
|
||||
#define ETH_UIP_0_CRS_DV XMC_GPIO_PORT15, 9U
|
||||
#define ETH_UIP_0_RXER XMC_GPIO_PORT2, 4U
|
||||
#define ETH_UIP_0_RXD0 XMC_GPIO_PORT2, 2U
|
||||
#define ETH_UIP_0_RXD1 XMC_GPIO_PORT2, 3U
|
||||
#define ETH_UIP_0_TXEN XMC_GPIO_PORT2, 5U
|
||||
#define ETH_UIP_0_TXD0 XMC_GPIO_PORT2, 8U
|
||||
#define ETH_UIP_0_TXD1 XMC_GPIO_PORT2, 9U
|
||||
#define ETH_UIP_0_RMII_CLK XMC_GPIO_PORT15, 8U
|
||||
#define ETH_UIP_0_MDC XMC_GPIO_PORT2, 7U
|
||||
#define ETH_UIP_0_MDIO XMC_GPIO_PORT2, 0U
|
||||
#define ETH_UIP_0_PIN_LIST_SIZE (10U)
|
||||
|
||||
#define ETH_UIP_0_PHY_ADDR (0)
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#if defined(__ICCARM__)
|
||||
#pragma data_alignment=4
|
||||
static XMC_ETH_MAC_DMA_DESC_t ETH_UIP_0_rx_desc[ETH_UIP_0_NUM_RX_BUF] @ ".iram2";
|
||||
#pragma data_alignment=4
|
||||
static XMC_ETH_MAC_DMA_DESC_t ETH_UIP_0_tx_desc[ETH_UIP_0_NUM_TX_BUF] @ ".iram2";
|
||||
#pragma data_alignment=4
|
||||
static blt_int8u ETH_UIP_0_rx_buf[ETH_UIP_0_NUM_RX_BUF][XMC_ETH_MAC_BUF_SIZE] @ ".iram2";
|
||||
#pragma data_alignment=4
|
||||
static blt_int8u ETH_UIP_0_tx_buf[ETH_UIP_0_NUM_TX_BUF][XMC_ETH_MAC_BUF_SIZE] @ ".iram2";
|
||||
#elif defined(__CC_ARM)
|
||||
static __attribute__((aligned(4))) XMC_ETH_MAC_DMA_DESC_t ETH_UIP_0_rx_desc[ETH_UIP_0_NUM_RX_BUF] __attribute__((section ("RW_IRAM1")));
|
||||
static __attribute__((aligned(4))) XMC_ETH_MAC_DMA_DESC_t ETH_UIP_0_tx_desc[ETH_UIP_0_NUM_TX_BUF] __attribute__((section ("RW_IRAM1")));
|
||||
static __attribute__((aligned(4))) blt_int8u ETH_UIP_0_rx_buf[ETH_UIP_0_NUM_RX_BUF][XMC_ETH_MAC_BUF_SIZE] __attribute__((section ("RW_IRAM1")));
|
||||
static __attribute__((aligned(4))) blt_int8u ETH_UIP_0_tx_buf[ETH_UIP_0_NUM_TX_BUF][XMC_ETH_MAC_BUF_SIZE] __attribute__((section ("RW_IRAM1")));
|
||||
#elif defined(__GNUC__)
|
||||
static __attribute__((aligned(4))) XMC_ETH_MAC_DMA_DESC_t ETH_UIP_0_rx_desc[ETH_UIP_0_NUM_RX_BUF] __attribute__((section ("ETH_RAM")));
|
||||
static __attribute__((aligned(4))) XMC_ETH_MAC_DMA_DESC_t ETH_UIP_0_tx_desc[ETH_UIP_0_NUM_TX_BUF] __attribute__((section ("ETH_RAM")));
|
||||
static __attribute__((aligned(4))) blt_int8u ETH_UIP_0_rx_buf[ETH_UIP_0_NUM_RX_BUF][XMC_ETH_MAC_BUF_SIZE] __attribute__((section ("ETH_RAM")));
|
||||
static __attribute__((aligned(4))) blt_int8u ETH_UIP_0_tx_buf[ETH_UIP_0_NUM_TX_BUF][XMC_ETH_MAC_BUF_SIZE] __attribute__((section ("ETH_RAM")));
|
||||
#else
|
||||
static __attribute__((aligned(4))) XMC_ETH_MAC_DMA_DESC_t ETH_UIP_0_rx_desc[ETH_UIP_0_NUM_RX_BUF];
|
||||
static __attribute__((aligned(4))) XMC_ETH_MAC_DMA_DESC_t ETH_UIP_0_tx_desc[ETH_UIP_0_NUM_TX_BUF];
|
||||
static __attribute__((aligned(4))) blt_int8u ETH_UIP_0_rx_buf[ETH_UIP_0_NUM_RX_BUF][XMC_ETH_MAC_BUF_SIZE];
|
||||
static __attribute__((aligned(4))) blt_int8u ETH_UIP_0_tx_buf[ETH_UIP_0_NUM_TX_BUF][XMC_ETH_MAC_BUF_SIZE];
|
||||
#endif
|
||||
|
||||
const XMC_ETH_PHY_CONFIG_t eth_phy_config =
|
||||
{
|
||||
.interface = XMC_ETH_LINK_INTERFACE_RMII,
|
||||
.enable_auto_negotiate = false,
|
||||
.duplex = XMC_ETH_LINK_DUPLEX_FULL,
|
||||
.speed = XMC_ETH_LINK_SPEED_100M
|
||||
};
|
||||
|
||||
XMC_ETH_MAC_t eth_mac =
|
||||
{
|
||||
.regs = ETH0,
|
||||
.address = NETDEV_DEFAULT_MACADDR,
|
||||
.rx_desc = ETH_UIP_0_rx_desc,
|
||||
.tx_desc = ETH_UIP_0_tx_desc,
|
||||
.rx_buf = Ð_UIP_0_rx_buf[0][0],
|
||||
.tx_buf = Ð_UIP_0_tx_buf[0][0],
|
||||
.num_rx_buf = ETH_UIP_0_NUM_RX_BUF,
|
||||
.num_tx_buf = ETH_UIP_0_NUM_TX_BUF
|
||||
};
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void netdev_init(void)
|
||||
{
|
||||
XMC_ETH_MAC_PORT_CTRL_t port_control;
|
||||
XMC_GPIO_CONFIG_t gpio_config;
|
||||
gpio_config.output_level = XMC_GPIO_OUTPUT_LEVEL_LOW;
|
||||
gpio_config.mode = XMC_GPIO_MODE_INPUT_TRISTATE;
|
||||
|
||||
/* Initialize GPIO pins. */
|
||||
XMC_GPIO_Init(ETH_UIP_0_CRS_DV, &gpio_config);
|
||||
|
||||
gpio_config.mode = XMC_GPIO_MODE_INPUT_TRISTATE;
|
||||
XMC_GPIO_Init(ETH_UIP_0_RXER, &gpio_config);
|
||||
|
||||
gpio_config.mode = XMC_GPIO_MODE_INPUT_TRISTATE;
|
||||
XMC_GPIO_Init(ETH_UIP_0_RXD0, &gpio_config);
|
||||
|
||||
gpio_config.mode = XMC_GPIO_MODE_INPUT_TRISTATE;
|
||||
XMC_GPIO_Init(ETH_UIP_0_RXD1, &gpio_config);
|
||||
|
||||
gpio_config.output_strength = XMC_GPIO_OUTPUT_STRENGTH_STRONG_SHARP_EDGE;
|
||||
gpio_config.mode = XMC_GPIO_MODE_OUTPUT_PUSH_PULL_ALT1;
|
||||
XMC_GPIO_Init(ETH_UIP_0_TXEN, &gpio_config);
|
||||
|
||||
gpio_config.output_strength = XMC_GPIO_OUTPUT_STRENGTH_STRONG_SHARP_EDGE;
|
||||
gpio_config.mode = XMC_GPIO_MODE_OUTPUT_PUSH_PULL_ALT1;
|
||||
XMC_GPIO_Init(ETH_UIP_0_TXD0, &gpio_config);
|
||||
|
||||
gpio_config.output_strength = XMC_GPIO_OUTPUT_STRENGTH_STRONG_SHARP_EDGE;
|
||||
gpio_config.mode = XMC_GPIO_MODE_OUTPUT_PUSH_PULL_ALT1;
|
||||
XMC_GPIO_Init(ETH_UIP_0_TXD1, &gpio_config);
|
||||
|
||||
gpio_config.mode = XMC_GPIO_MODE_INPUT_TRISTATE;
|
||||
XMC_GPIO_Init(ETH_UIP_0_RMII_CLK, &gpio_config);
|
||||
|
||||
gpio_config.output_strength = XMC_GPIO_OUTPUT_STRENGTH_STRONG_SHARP_EDGE;
|
||||
gpio_config.mode = XMC_GPIO_MODE_OUTPUT_PUSH_PULL_ALT1;
|
||||
XMC_GPIO_Init(ETH_UIP_0_MDC, &gpio_config);
|
||||
|
||||
gpio_config.mode = XMC_GPIO_MODE_INPUT_TRISTATE;
|
||||
XMC_GPIO_Init(ETH_UIP_0_MDIO, &gpio_config);
|
||||
|
||||
XMC_GPIO_SetHardwareControl(ETH_UIP_0_MDIO, XMC_GPIO_HWCTRL_PERIPHERAL1);
|
||||
|
||||
port_control.mode = XMC_ETH_MAC_PORT_CTRL_MODE_RMII;
|
||||
port_control.rxd0 = (XMC_ETH_MAC_PORT_CTRL_RXD0_t)0U;
|
||||
port_control.rxd1 = (XMC_ETH_MAC_PORT_CTRL_RXD1_t)0U;
|
||||
port_control.clk_rmii = (XMC_ETH_MAC_PORT_CTRL_CLK_RMII_t)2U;
|
||||
port_control.crs_dv = (XMC_ETH_MAC_PORT_CTRL_CRS_DV_t)2U;
|
||||
port_control.rxer = (XMC_ETH_MAC_PORT_CTRL_RXER_t)0U;
|
||||
port_control.mdio = (XMC_ETH_MAC_PORT_CTRL_MDIO_t)1U;
|
||||
XMC_ETH_MAC_SetPortControl(ð_mac, port_control);
|
||||
}
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void netdev_init_mac(void)
|
||||
{
|
||||
struct uip_eth_addr macAddress;
|
||||
blt_int32u ulLinkTimeOut;
|
||||
|
||||
(void)XMC_ETH_MAC_Init(ð_mac);
|
||||
|
||||
XMC_ETH_MAC_DisableJumboFrame(ð_mac);
|
||||
|
||||
/* Wait for link to become active. */
|
||||
ulLinkTimeOut = TimerGet() + NETDEV_LINKUP_TIMEOUT_MS;
|
||||
while (XMC_ETH_PHY_GetLinkStatus(ð_mac, ETH_UIP_0_PHY_ADDR) == XMC_ETH_LINK_STATUS_DOWN)
|
||||
{
|
||||
/* Check for timeout so that the software program can still start if the ethernet
|
||||
* cable is not connected.
|
||||
*/
|
||||
if (TimerGet() >= ulLinkTimeOut)
|
||||
{
|
||||
break;
|
||||
}
|
||||
/* Service the watchdog. */
|
||||
CopService();
|
||||
}
|
||||
|
||||
XMC_ETH_PHY_Init(ð_mac, ETH_UIP_0_PHY_ADDR, ð_phy_config);
|
||||
XMC_ETH_MAC_SetLink(ð_mac, XMC_ETH_LINK_SPEED_100M, XMC_ETH_LINK_DUPLEX_FULL);
|
||||
XMC_ETH_MAC_EnableTx(ð_mac);
|
||||
XMC_ETH_MAC_EnableRx(ð_mac);
|
||||
|
||||
/* set the default MAC address */
|
||||
macAddress.addr[0] = NETDEV_DEFAULT_MACADDR0;
|
||||
macAddress.addr[1] = NETDEV_DEFAULT_MACADDR1;
|
||||
macAddress.addr[2] = NETDEV_DEFAULT_MACADDR2;
|
||||
macAddress.addr[3] = NETDEV_DEFAULT_MACADDR3;
|
||||
macAddress.addr[4] = NETDEV_DEFAULT_MACADDR4;
|
||||
macAddress.addr[5] = NETDEV_DEFAULT_MACADDR5;
|
||||
uip_setethaddr(macAddress);
|
||||
}
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void netdev_get_mac(unsigned char * mac_addr)
|
||||
{
|
||||
mac_addr[0] = NETDEV_DEFAULT_MACADDR0;
|
||||
mac_addr[1] = NETDEV_DEFAULT_MACADDR1;
|
||||
mac_addr[2] = NETDEV_DEFAULT_MACADDR2;
|
||||
mac_addr[3] = NETDEV_DEFAULT_MACADDR3;
|
||||
mac_addr[4] = NETDEV_DEFAULT_MACADDR4;
|
||||
mac_addr[5] = NETDEV_DEFAULT_MACADDR5;
|
||||
}
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
unsigned int netdev_read(void)
|
||||
{
|
||||
blt_int32u result = 0;
|
||||
blt_int32u framelen;
|
||||
|
||||
/* Check if a new frame was received. */
|
||||
framelen = XMC_ETH_MAC_GetRxFrameSize(ð_mac);
|
||||
/* Only process the frame if the length is valid. */
|
||||
if ((framelen > 0U) && (framelen <= (blt_int32u)XMC_ETH_MAC_BUF_SIZE))
|
||||
{
|
||||
XMC_ETH_MAC_ReadFrame(ð_mac, uip_buf, framelen);
|
||||
result = framelen;
|
||||
}
|
||||
|
||||
/* Give the result back to the caller. */
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void netdev_send(void)
|
||||
{
|
||||
uint8_t *buffer;
|
||||
uint32_t idx;
|
||||
|
||||
/* Only send the frame if the length is valid. */
|
||||
if ((uip_len > 0U) && (uip_len <= (blt_int32u)XMC_ETH_MAC_BUF_SIZE))
|
||||
{
|
||||
if (XMC_ETH_MAC_IsTxDescriptorOwnedByDma(ð_mac))
|
||||
{
|
||||
XMC_ETH_MAC_ResumeTx(ð_mac);
|
||||
}
|
||||
else
|
||||
{
|
||||
buffer = XMC_ETH_MAC_GetTxBuffer(ð_mac);
|
||||
for (idx = 0; idx < uip_len; idx++)
|
||||
{
|
||||
buffer[idx] = uip_buf[idx];
|
||||
}
|
||||
XMC_ETH_MAC_SetTxBufferSize(ð_mac, uip_len);
|
||||
/* Return the Tx descriptor but do not use the XMC_ETH_MAC_ReturnTxDescriptor().
|
||||
* This function enables the 'checksum insertion control' feature by setting the
|
||||
* ETH_MAC_DMA_TDES0_CIC in the eth_mac.tx_desc[eth_mac.tx_index].status. When
|
||||
* this feature is enabled, an incorrect checksum of 0x0000 is always added to
|
||||
* ICMP reponse messages such as the PING reply.
|
||||
*/
|
||||
eth_mac.tx_ts_index = eth_mac.tx_index;
|
||||
eth_mac.tx_desc[eth_mac.tx_index].status |= ETH_MAC_DMA_TDES0_OWN;
|
||||
eth_mac.tx_index++;
|
||||
if (eth_mac.tx_index == eth_mac.num_tx_buf)
|
||||
{
|
||||
eth_mac.tx_index = 0U;
|
||||
}
|
||||
eth_mac.frame_end = NULL;
|
||||
XMC_ETH_MAC_ResumeTx(ð_mac);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,47 @@
|
|||
/*
|
||||
* Copyright (c) 2001, Adam Dunkels.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by Adam Dunkels.
|
||||
* 4. The name of the author may not be used to endorse or promote
|
||||
* products derived from this software without specific prior
|
||||
* written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This file is part of the uIP TCP/IP stack.
|
||||
*
|
||||
* $Id: netdev.h,v 1.1 2002/01/10 06:22:56 adam Exp $
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef __NETDEV_H__
|
||||
#define __NETDEV_H__
|
||||
|
||||
void netdev_init(void);
|
||||
void netdev_init_mac(void);
|
||||
void netdev_get_mac(unsigned char * mac_addr);
|
||||
unsigned int netdev_read(void);
|
||||
void netdev_send(void);
|
||||
|
||||
#endif /* __NETDEV_H__ */
|
|
@ -0,0 +1,160 @@
|
|||
/**
|
||||
* \addtogroup uipopt
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* \name Project-specific configuration options
|
||||
* @{
|
||||
*
|
||||
* uIP has a number of configuration options that can be overridden
|
||||
* for each project. These are kept in a project-specific uip-conf.h
|
||||
* file and all configuration names have the prefix UIP_CONF.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2006, Swedish Institute of Computer Science.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the Institute nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* This file is part of the uIP TCP/IP stack
|
||||
*
|
||||
* $Id: uip-conf.h,v 1.6 2006/06/12 08:00:31 adam Exp $
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file
|
||||
* An example uIP configuration file
|
||||
* \author
|
||||
* Adam Dunkels <adam@sics.se>
|
||||
*/
|
||||
|
||||
#ifndef __UIP_CONF_H__
|
||||
#define __UIP_CONF_H__
|
||||
|
||||
|
||||
/**
|
||||
* 8 bit datatype
|
||||
*
|
||||
* This typedef defines the 8-bit type used throughout uIP.
|
||||
*
|
||||
* \hideinitializer
|
||||
*/
|
||||
typedef unsigned char u8_t;
|
||||
|
||||
/**
|
||||
* 16 bit datatype
|
||||
*
|
||||
* This typedef defines the 16-bit type used throughout uIP.
|
||||
*
|
||||
* \hideinitializer
|
||||
*/
|
||||
typedef unsigned short u16_t;
|
||||
|
||||
/**
|
||||
* Statistics datatype
|
||||
*
|
||||
* This typedef defines the dataype used for keeping statistics in
|
||||
* uIP.
|
||||
*
|
||||
* \hideinitializer
|
||||
*/
|
||||
typedef unsigned short uip_stats_t;
|
||||
|
||||
/**
|
||||
* Maximum number of TCP connections.
|
||||
*
|
||||
* \hideinitializer
|
||||
*/
|
||||
#define UIP_CONF_MAX_CONNECTIONS 1
|
||||
|
||||
/**
|
||||
* Maximum number of listening TCP ports.
|
||||
*
|
||||
* \hideinitializer
|
||||
*/
|
||||
#define UIP_CONF_MAX_LISTENPORTS 1
|
||||
|
||||
/**
|
||||
* UDP support on or off
|
||||
*
|
||||
* \hideinitializer
|
||||
*/
|
||||
#define UIP_CONF_UDP 1
|
||||
|
||||
/**
|
||||
* UDP Maximum Connections
|
||||
*
|
||||
* \hideinitializer
|
||||
*/
|
||||
#define UIP_CONF_UDP_CONNS 1
|
||||
|
||||
/**
|
||||
* UDP checksums on or off
|
||||
*
|
||||
* \hideinitializer
|
||||
*/
|
||||
#define UIP_CONF_UDP_CHECKSUMS 0
|
||||
|
||||
/**
|
||||
* uIP buffer size.
|
||||
*
|
||||
* \hideinitializer
|
||||
*/
|
||||
#define UIP_CONF_BUFFER_SIZE 1600
|
||||
|
||||
/**
|
||||
* CPU byte order.
|
||||
*
|
||||
* \hideinitializer
|
||||
*/
|
||||
#define UIP_CONF_BYTE_ORDER UIP_LITTLE_ENDIAN
|
||||
|
||||
/**
|
||||
* Logging on or off
|
||||
*
|
||||
* \hideinitializer
|
||||
*/
|
||||
#define UIP_CONF_LOGGING 0
|
||||
|
||||
/**
|
||||
* uIP statistics on or off
|
||||
*
|
||||
* \hideinitializer
|
||||
*/
|
||||
#define UIP_CONF_STATISTICS 0
|
||||
|
||||
|
||||
/* Here we include the header file for the application(s) we use in
|
||||
our project. */
|
||||
#include "boot.h"
|
||||
#include "net.h"
|
||||
#include "dhcpc.h"
|
||||
|
||||
#endif /* __UIP_CONF_H__ */
|
||||
|
||||
/** @} */
|
||||
/** @} */
|
|
@ -33,6 +33,7 @@
|
|||
#include "xmc_gpio.h" /* GPIO module */
|
||||
#include "xmc_uart.h" /* UART driver header */
|
||||
#include "xmc_can.h" /* CAN driver header */
|
||||
#include "shared_params.h" /* Shared parameters header */
|
||||
|
||||
|
||||
/****************************************************************************************
|
||||
|
@ -50,10 +51,44 @@ static void PostInit(void);
|
|||
****************************************************************************************/
|
||||
int main(void)
|
||||
{
|
||||
blt_int8u deferredInitRequestFlag = 0;
|
||||
|
||||
/* initialize the microcontroller */
|
||||
Init();
|
||||
/* initialize the shared parameters module */
|
||||
SharedParamsInit();
|
||||
/* initialize the bootloader */
|
||||
BootInit();
|
||||
#if (BOOT_COM_DEFERRED_INIT_ENABLE == 1)
|
||||
/* the bootloader is configured to NOT initialize the TCP/IP network stack by default
|
||||
* to bypass unnecessary delay times before starting the user program. the TCP/IP net-
|
||||
* work tack is now only initialized when: (a) no valid user program is detected, or
|
||||
* (b) a forced backdoor entry occurred (CpuUserProgramStartHook() returned BLT_FALSE).
|
||||
*
|
||||
* these demo bootloader and user programs have one extra feature implemented for
|
||||
* demonstration purposes. the demo user program can detect firmware update requests
|
||||
* from the TCP/IP network in which case it activates the bootloader. But...the
|
||||
* TCP/IP network stack will not be initialized in this situation. for this reason
|
||||
* the shared parameter module was integrated in both the bootloader and user program.
|
||||
* more information about the shared parameter module can be found here:
|
||||
* https://www.feaser.com/en/blog/?p=216
|
||||
*
|
||||
* the shared parameter at the first index (0) contains a flag. this flag is set to
|
||||
* 1, right before the user program activates this bootloader, to explicitly request
|
||||
* the bootloader to initialize the TCP/IP network stack. this makes it possible for
|
||||
* a firmware update to proceed. the code here reads out this flag and performs the
|
||||
* TCP/IP network stack initialization when requested.
|
||||
*/
|
||||
SharedParamsReadByIndex(0, &deferredInitRequestFlag);
|
||||
if (deferredInitRequestFlag == 1)
|
||||
{
|
||||
/* explicitly initialize all communication interface for which the deferred
|
||||
* initialization feature was enabled.
|
||||
*/
|
||||
ComDeferredInit();
|
||||
}
|
||||
#endif
|
||||
|
||||
/* post initialization of the microcontroller */
|
||||
PostInit();
|
||||
|
||||
|
|
|
@ -0,0 +1,301 @@
|
|||
/************************************************************************************//**
|
||||
* \file Demo/ARMCM4_XMC4_XMC4700_Relax_Kit_Keil/Boot/shared_params.c
|
||||
* \brief Shared RAM parameters source file.
|
||||
* \ingroup Boot_ARMCM4_XMC4_XMC4700_Relax_Kit_Keil
|
||||
* \internal
|
||||
*----------------------------------------------------------------------------------------
|
||||
* C O P Y R I G H T
|
||||
*----------------------------------------------------------------------------------------
|
||||
* Copyright (c) 2022 by Feaser http://www.feaser.com All rights reserved
|
||||
*
|
||||
*----------------------------------------------------------------------------------------
|
||||
* L I C E N S E
|
||||
*----------------------------------------------------------------------------------------
|
||||
* This file is part of OpenBLT. OpenBLT is free software: you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as published by the Free
|
||||
* Software Foundation, either version 3 of the License, or (at your option) any later
|
||||
* version.
|
||||
*
|
||||
* OpenBLT is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
||||
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
* PURPOSE. See the GNU General Public License for more details.
|
||||
*
|
||||
* You have received a copy of the GNU General Public License along with OpenBLT. It
|
||||
* should be located in ".\Doc\license.html". If not, contact Feaser to obtain a copy.
|
||||
*
|
||||
* \endinternal
|
||||
****************************************************************************************/
|
||||
|
||||
/****************************************************************************************
|
||||
* Include files
|
||||
****************************************************************************************/
|
||||
#include <stddef.h> /* Standard definitions (NULL). */
|
||||
#include "shared_params.h" /* Shared parameters header. */
|
||||
|
||||
|
||||
/****************************************************************************************
|
||||
* Macro definitions
|
||||
****************************************************************************************/
|
||||
/** \brief Constant parameter buffer identifier. This value is always located as the
|
||||
* start of the buffer to validate the the RAM contains valid shared parameters.
|
||||
*/
|
||||
#define SHARED_PARAMS_BUFFER_ID (0xCE42E7A2u)
|
||||
|
||||
|
||||
/****************************************************************************************
|
||||
* Type definitions
|
||||
****************************************************************************************/
|
||||
/** \brief Layout of the shared parameters RAM buffer. */
|
||||
typedef struct t_shared_params_buffer
|
||||
{
|
||||
/** \brief Fixed buffer identifier to validate that the RAM contains valid shared
|
||||
* parameters.
|
||||
*/
|
||||
uint32_t identifier;
|
||||
/** \brief Array for the actual parameter data. */
|
||||
uint8_t data[SHARED_PARAMS_CFG_BUFFER_DATA_LEN];
|
||||
/** \brief Checksum value of all the bytes in the buffer, excluding this checksum
|
||||
* value of obvious reasons. The checksum is calculated as the Two's
|
||||
* complement of the sum of the bytes.
|
||||
*/
|
||||
uint16_t checksum;
|
||||
} tSharedParamsBuffer;
|
||||
|
||||
|
||||
/****************************************************************************************
|
||||
* Global data declarations
|
||||
****************************************************************************************/
|
||||
/** \brief Declaration of the actual parameter buffer that this module manages.
|
||||
* \warning For the shared RAM parameters to work properly for sharing information
|
||||
* between the bootloader and user program, it is important that this
|
||||
* variable is linked to the exact same RAM address in both the bootloader
|
||||
* and the user program. Additionally, it should be configured such that the
|
||||
* C-startup code does NOT zero its contents during system initialization. This
|
||||
* is the code that runs in the reset event handler, before function main() is
|
||||
* called.
|
||||
* For GCC based embedded toolchains, the solution is to assign this variable
|
||||
* to a custom section, in this case called ".shared". Then in the linker
|
||||
* script, add the following to the SECTIONS:
|
||||
*
|
||||
* .shared (NOLOAD) :
|
||||
* {
|
||||
* . = ALIGN(4);
|
||||
* _sshared = .;
|
||||
* __shared_start__ = _sshared;
|
||||
* *(.shared)
|
||||
* *(.shared.*)
|
||||
* KEEP(*(.shared))
|
||||
* . = ALIGN(4);
|
||||
* _eshared = .;
|
||||
* __shared_end__ = _eshared;
|
||||
* } >SHARED
|
||||
*
|
||||
* Next, add a new MEMORY entry for SHARED at the start of RAM and reduce
|
||||
* the length of the remaining RAM:
|
||||
*
|
||||
* SHARED (xrw) : ORIGIN = 0x200000C0, LENGTH = 64
|
||||
* RAM (xrw) : ORIGIN = 0x20000100, LENGTH = 32K - 192 - 64
|
||||
*
|
||||
* Note that the previous example is for an STM32F0 microcontroller where
|
||||
* the first 192 (0xC0) bytes in RAM are reserved for the user program
|
||||
* vector table.
|
||||
*
|
||||
* \remark This same approach can be applied with other toolchains such as Keil MDK
|
||||
* and IAR EWARM. Consult the compiler and linker user manuals of your
|
||||
* toolchain to find out how to place a RAM variable at a fixed memory address
|
||||
* and to prevent the C-startup code from zeroing its contents.
|
||||
* Here are a few links to get you started:
|
||||
* * IAR EWARM:
|
||||
* https://www.iar.com/support/tech-notes/compiler/
|
||||
* linker-error-for-absolute-located-variable/
|
||||
* * Keil MDK:
|
||||
* http://www.keil.com/support/docs/3480.htm
|
||||
*/
|
||||
static tSharedParamsBuffer sharedParamsBuffer __attribute__((section("shared"),zero_init));
|
||||
|
||||
|
||||
/****************************************************************************************
|
||||
* Function prototypes
|
||||
****************************************************************************************/
|
||||
static bool SharedParamsValidateBuffer(void);
|
||||
static void SharedParamsWriteChecksum(void);
|
||||
static bool SharedParamsVerifyChecksum(void);
|
||||
static uint16_t SharedParamsCalculateChecksum(void);
|
||||
|
||||
|
||||
/************************************************************************************//**
|
||||
** \brief Initializes the shared RAM parameters module.
|
||||
** \return none.
|
||||
**
|
||||
****************************************************************************************/
|
||||
void SharedParamsInit(void)
|
||||
{
|
||||
uint32_t byteIdx;
|
||||
|
||||
/* The shared parameter buffer does not get initialized by the C-startup code. Another
|
||||
* previously running program could have initialized it, in which case it is ready
|
||||
* for use and nothing more needs to be done.
|
||||
*/
|
||||
if (!SharedParamsValidateBuffer())
|
||||
{
|
||||
/* The shared parameter buffer was not yet initialized by a running program. This
|
||||
* typically happens after a cold reset where the RAM contents were lost. In this
|
||||
* case we need to explicitly configure and initialize it, since the C-startup code
|
||||
* was configured to not do this.
|
||||
*
|
||||
* The initialization consists of setting the buffer identifier, zeroing the
|
||||
* actual parameter data and updating the checksum at the end.
|
||||
*/
|
||||
sharedParamsBuffer.identifier = SHARED_PARAMS_BUFFER_ID;
|
||||
for (byteIdx=0; byteIdx < SHARED_PARAMS_CFG_BUFFER_DATA_LEN; byteIdx++)
|
||||
{
|
||||
sharedParamsBuffer.data[byteIdx] = 0;
|
||||
}
|
||||
SharedParamsWriteChecksum();
|
||||
}
|
||||
} /*** end of SharedParamsInit ***/
|
||||
|
||||
|
||||
/************************************************************************************//**
|
||||
** \brief Reads a data byte from the shared parameter buffer at the specified index.
|
||||
** \param idx Index into the parameter data array. A valid value is between 0 and
|
||||
** (SHARED_PARAMS_CFG_BUFFER_DATA_LEN - 1).
|
||||
** \param value Pointer to where the read data value is stored.
|
||||
** \return True if successful, false otherwise.
|
||||
**
|
||||
****************************************************************************************/
|
||||
bool SharedParamsReadByIndex(uint32_t idx, uint8_t * value)
|
||||
{
|
||||
bool result = false;
|
||||
|
||||
/* Only continue if the buffer and the specified parameters are valid. */
|
||||
if ( (SharedParamsValidateBuffer()) &&
|
||||
(idx < SHARED_PARAMS_CFG_BUFFER_DATA_LEN) &&
|
||||
(value != NULL) )
|
||||
{
|
||||
/* Read the value and update the result. */
|
||||
*value = sharedParamsBuffer.data[idx];
|
||||
result = true;
|
||||
}
|
||||
/* Give the result back to the caller. */
|
||||
return result;
|
||||
} /*** end of SharedParamsReadByIndex ***/
|
||||
|
||||
|
||||
/************************************************************************************//**
|
||||
** \brief Writes a data byte to the shared parameter buffer at the specified index.
|
||||
** \param idx Index into the parameter data array. A valid value is between 0 and
|
||||
** (SHARED_PARAMS_CFG_BUFFER_DATA_LEN - 1).
|
||||
** \param value Value to write.
|
||||
** \return True if successful, false otherwise.
|
||||
**
|
||||
****************************************************************************************/
|
||||
bool SharedParamsWriteByIndex(uint32_t idx, uint8_t value)
|
||||
{
|
||||
bool result = false;
|
||||
|
||||
/* Only continue if the buffer and the specified parameters are valid. */
|
||||
if ( (SharedParamsValidateBuffer()) &&
|
||||
(idx < SHARED_PARAMS_CFG_BUFFER_DATA_LEN) )
|
||||
{
|
||||
/* Write the value. */
|
||||
sharedParamsBuffer.data[idx] = value;
|
||||
/* Update the checksum since the contents were just changed. */
|
||||
SharedParamsWriteChecksum();
|
||||
/* Update the result. */
|
||||
result = true;
|
||||
}
|
||||
/* Give the result back to the caller. */
|
||||
return result;
|
||||
} /*** end of SharedParamsWriteByIndex ***/
|
||||
|
||||
|
||||
/************************************************************************************//**
|
||||
** \brief Validates the shared parameter buffer contents by looking at the table
|
||||
** identifier and verifying its checksum.
|
||||
** \return True if successful, false otherwise.
|
||||
**
|
||||
****************************************************************************************/
|
||||
static bool SharedParamsValidateBuffer(void)
|
||||
{
|
||||
bool result = false;
|
||||
|
||||
/* Perform validation. */
|
||||
if ( (sharedParamsBuffer.identifier == SHARED_PARAMS_BUFFER_ID) &&
|
||||
(SharedParamsVerifyChecksum()) )
|
||||
{
|
||||
/* The shared parameter buffer is valid, so update the result value. */
|
||||
result = true;
|
||||
}
|
||||
/* Give the result back to the caller. */
|
||||
return result;
|
||||
} /*** end of SharedParamsValitabeTable ***/
|
||||
|
||||
|
||||
/************************************************************************************//**
|
||||
** \brief Calculates and writes the checksum into the buffer.
|
||||
** \return none.
|
||||
**
|
||||
****************************************************************************************/
|
||||
static void SharedParamsWriteChecksum(void)
|
||||
{
|
||||
/* Calculate and write the checksum. */
|
||||
sharedParamsBuffer.checksum = SharedParamsCalculateChecksum();
|
||||
} /*** end of SharedParamsWriteChecksum ***/
|
||||
|
||||
|
||||
/************************************************************************************//**
|
||||
** \brief Calculates and verifies the checksum that is currently present in the
|
||||
** buffer.
|
||||
** \return True is the checksum is correct, false otherwise.
|
||||
**
|
||||
****************************************************************************************/
|
||||
static bool SharedParamsVerifyChecksum(void)
|
||||
{
|
||||
bool result = false;
|
||||
|
||||
/* Calculate and verify the checksum. */
|
||||
if (SharedParamsCalculateChecksum() == sharedParamsBuffer.checksum)
|
||||
{
|
||||
/* Checksum is correct, so update the result value. */
|
||||
result = true;
|
||||
}
|
||||
/* Give the result back to the caller. */
|
||||
return result;
|
||||
} /*** end of SharedParamsVerifyChecksum ***/
|
||||
|
||||
|
||||
/************************************************************************************//**
|
||||
** \brief Calculates and returns the checksum value for the current contents in the
|
||||
** buffer. The checksum is calculated by taking the sum of all bytes in the
|
||||
** parameter buffer (excluding the checksum at the end) and them taking the
|
||||
** two's complement value of it.
|
||||
** \return The calculated checksum value.
|
||||
**
|
||||
****************************************************************************************/
|
||||
static uint16_t SharedParamsCalculateChecksum(void)
|
||||
{
|
||||
uint16_t result = 0;
|
||||
uint32_t byteIdx;
|
||||
|
||||
/* Add the identifier bytes to the checksum. */
|
||||
result += (uint8_t)sharedParamsBuffer.identifier;
|
||||
result += (uint8_t)(sharedParamsBuffer.identifier >> 8u);
|
||||
result += (uint8_t)(sharedParamsBuffer.identifier >> 16u);
|
||||
result += (uint8_t)(sharedParamsBuffer.identifier >> 24u);
|
||||
/* Loop through the parameter data array. */
|
||||
for (byteIdx=0; byteIdx<SHARED_PARAMS_CFG_BUFFER_DATA_LEN; byteIdx++)
|
||||
{
|
||||
/* Add parameter data byte to the checksum. */
|
||||
result += (uint8_t)sharedParamsBuffer.data[byteIdx];
|
||||
}
|
||||
/* Determine one's complement. */
|
||||
result = ~result;
|
||||
/* Determine two's complement. */
|
||||
result += 1;
|
||||
/* Give the result back to the caller. */
|
||||
return result;
|
||||
} /*** end of SharedParamsCalculateChecksum ***/
|
||||
|
||||
|
||||
/*********************************** end of shared_params.c ****************************/
|
|
@ -0,0 +1,57 @@
|
|||
/************************************************************************************//**
|
||||
* \file Demo/ARMCM4_XMC4_XMC4700_Relax_Kit_Keil/Boot/shared_params.h
|
||||
* \brief Shared RAM parameters header file.
|
||||
* \ingroup Boot_ARMCM4_XMC4_XMC4700_Relax_Kit_Keil
|
||||
* \internal
|
||||
*----------------------------------------------------------------------------------------
|
||||
* C O P Y R I G H T
|
||||
*----------------------------------------------------------------------------------------
|
||||
* Copyright (c) 2022 by Feaser http://www.feaser.com All rights reserved
|
||||
*
|
||||
*----------------------------------------------------------------------------------------
|
||||
* L I C E N S E
|
||||
*----------------------------------------------------------------------------------------
|
||||
* This file is part of OpenBLT. OpenBLT is free software: you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as published by the Free
|
||||
* Software Foundation, either version 3 of the License, or (at your option) any later
|
||||
* version.
|
||||
*
|
||||
* OpenBLT is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
||||
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
* PURPOSE. See the GNU General Public License for more details.
|
||||
*
|
||||
* You have received a copy of the GNU General Public License along with OpenBLT. It
|
||||
* should be located in ".\Doc\license.html". If not, contact Feaser to obtain a copy.
|
||||
*
|
||||
* \endinternal
|
||||
****************************************************************************************/
|
||||
#ifndef SHARED_PARAMS_H
|
||||
#define SHARED_PARAMS_H
|
||||
|
||||
/****************************************************************************************
|
||||
* Include files
|
||||
****************************************************************************************/
|
||||
#include <stdint.h> /* Standard integer types. */
|
||||
#include <stdbool.h> /* Standard boolean types. */
|
||||
|
||||
|
||||
/****************************************************************************************
|
||||
* Configuration macros
|
||||
****************************************************************************************/
|
||||
/** \brief Configuration macro for specifying the size of the data inside the parameter
|
||||
* buffer. This is the length in bytes of the actual parameter data, so
|
||||
* excluding the bufferId and checksum.
|
||||
*/
|
||||
#define SHARED_PARAMS_CFG_BUFFER_DATA_LEN (56u)
|
||||
|
||||
|
||||
/****************************************************************************************
|
||||
* Function prototypes
|
||||
****************************************************************************************/
|
||||
void SharedParamsInit(void);
|
||||
bool SharedParamsReadByIndex(uint32_t idx, uint8_t * value);
|
||||
bool SharedParamsWriteByIndex(uint32_t idx, uint8_t value);
|
||||
|
||||
|
||||
#endif /* SHARED_PARAMS_H */
|
||||
/*********************************** end of shared_params.h ****************************/
|
|
@ -0,0 +1,29 @@
|
|||
; *************************************************************
|
||||
; *** Scatter-Loading Description File generated by uVision ***
|
||||
; *************************************************************
|
||||
|
||||
LR_IROM1 0x08000000 0x0000C000 { ; load region size_region
|
||||
ER_IROM1 0x08000000 0x0000C000 { ; load address = execution address
|
||||
*.o (RESET, +First)
|
||||
*(InRoot$$Sections)
|
||||
.ANY (+RO)
|
||||
.ANY (+XO)
|
||||
}
|
||||
|
||||
; Theoretically it should also be possible to place the shared parameters buffer at
|
||||
; 0x20000000. Testing shows though, that the first few bytes are still changed when
|
||||
; the user program performs a software reset. Therefore it was moved forward by 0x100.
|
||||
RW_IRAM1 0x20000100 UNINIT 0x00000040 { ; no init for shared params
|
||||
*(shared)
|
||||
}
|
||||
|
||||
|
||||
RW_IRAM2 0x20000140 0x0003FEC0 { ; RW data
|
||||
.ANY (+RW +ZI)
|
||||
}
|
||||
|
||||
RW_IRAM3 0x1FFE8000 0x00018000 {
|
||||
.ANY (+RW +ZI)
|
||||
}
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
|
@ -36,6 +36,8 @@
|
|||
#include "boot.h" /* bootloader interface driver */
|
||||
#include "led.h" /* LED driver */
|
||||
#include "timer.h" /* Timer driver */
|
||||
#include "net.h" /* TCP/IP server application */
|
||||
#include "shared_params.h" /* Shared parameters header. */
|
||||
|
||||
|
||||
#endif /* HEADER_H */
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -337,9 +337,9 @@
|
|||
<v6Rtti>0</v6Rtti>
|
||||
<VariousControls>
|
||||
<MiscControls>--diag_suppress=111</MiscControls>
|
||||
<Define>XMC4700_F144x2048</Define>
|
||||
<Define>XMC4700_F144x2048 XMC_ETH_PHY_KSZ8081RNB</Define>
|
||||
<Undefine></Undefine>
|
||||
<IncludePath>..\..\Prog;..\lib;..\lib\cmsis;..\lib\xmclib\inc</IncludePath>
|
||||
<IncludePath>..\..\Prog;..\lib;..\lib\cmsis;..\lib\xmclib\inc;..\lib\uip;..\..\..\..\Source\third_party\uip\uip;..\..\..\..\Source\third_party\uip\apps\dhcpc</IncludePath>
|
||||
</VariousControls>
|
||||
</Cads>
|
||||
<Aads>
|
||||
|
@ -361,7 +361,7 @@
|
|||
</VariousControls>
|
||||
</Aads>
|
||||
<LDads>
|
||||
<umfTarg>1</umfTarg>
|
||||
<umfTarg>0</umfTarg>
|
||||
<Ropi>0</Ropi>
|
||||
<Rwpi>0</Rwpi>
|
||||
<noStLib>0</noStLib>
|
||||
|
@ -370,7 +370,7 @@
|
|||
<TextAddressRange>0x08000000</TextAddressRange>
|
||||
<DataAddressRange>0x20000000</DataAddressRange>
|
||||
<pXoBase></pXoBase>
|
||||
<ScatterFile>..\bin\openblt_xmc4700.sct</ScatterFile>
|
||||
<ScatterFile>..\xmc4700.sct</ScatterFile>
|
||||
<IncludeLibs></IncludeLibs>
|
||||
<IncludeLibsPath></IncludeLibsPath>
|
||||
<Misc></Misc>
|
||||
|
@ -428,6 +428,26 @@
|
|||
<FileType>5</FileType>
|
||||
<FilePath>..\timer.h</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>net.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\net.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>net.h</FileName>
|
||||
<FileType>5</FileType>
|
||||
<FilePath>..\net.h</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>shared_params.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\shared_params.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>shared_params.h</FileName>
|
||||
<FileType>5</FileType>
|
||||
<FilePath>..\shared_params.h</FilePath>
|
||||
</File>
|
||||
</Files>
|
||||
</Group>
|
||||
<Group>
|
||||
|
@ -1020,6 +1040,126 @@
|
|||
</File>
|
||||
</Files>
|
||||
</Group>
|
||||
<Group>
|
||||
<GroupName>Lib/uip</GroupName>
|
||||
<Files>
|
||||
<File>
|
||||
<FileName>clock-arch.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\lib\uip\clock-arch.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>clock-arch.h</FileName>
|
||||
<FileType>5</FileType>
|
||||
<FilePath>..\lib\uip\clock-arch.h</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>netdev.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\lib\uip\netdev.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>netdev.h</FileName>
|
||||
<FileType>5</FileType>
|
||||
<FilePath>..\lib\uip\netdev.h</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>uip-conf.h</FileName>
|
||||
<FileType>5</FileType>
|
||||
<FilePath>..\lib\uip\uip-conf.h</FilePath>
|
||||
</File>
|
||||
</Files>
|
||||
</Group>
|
||||
<Group>
|
||||
<GroupName>third_party/uip</GroupName>
|
||||
<Files>
|
||||
<File>
|
||||
<FileName>clock.h</FileName>
|
||||
<FileType>5</FileType>
|
||||
<FilePath>..\..\..\..\Source\third_party\uip\uip\clock.h</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>lc.h</FileName>
|
||||
<FileType>5</FileType>
|
||||
<FilePath>..\..\..\..\Source\third_party\uip\uip\lc.h</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>lc-addrlabels.h</FileName>
|
||||
<FileType>5</FileType>
|
||||
<FilePath>..\..\..\..\Source\third_party\uip\uip\lc-addrlabels.h</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>lc-switch.h</FileName>
|
||||
<FileType>5</FileType>
|
||||
<FilePath>..\..\..\..\Source\third_party\uip\uip\lc-switch.h</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>pt.h</FileName>
|
||||
<FileType>5</FileType>
|
||||
<FilePath>..\..\..\..\Source\third_party\uip\uip\pt.h</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>uip.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\..\..\..\Source\third_party\uip\uip\uip.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>uip.h</FileName>
|
||||
<FileType>5</FileType>
|
||||
<FilePath>..\..\..\..\Source\third_party\uip\uip\uip.h</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>uip_arch.h</FileName>
|
||||
<FileType>5</FileType>
|
||||
<FilePath>..\..\..\..\Source\third_party\uip\uip\uip_arch.h</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>uip_arp.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\..\..\..\Source\third_party\uip\uip\uip_arp.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>uip_arp.h</FileName>
|
||||
<FileType>5</FileType>
|
||||
<FilePath>..\..\..\..\Source\third_party\uip\uip\uip_arp.h</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>uip_timer.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\..\..\..\Source\third_party\uip\uip\uip_timer.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>uip_timer.h</FileName>
|
||||
<FileType>5</FileType>
|
||||
<FilePath>..\..\..\..\Source\third_party\uip\uip\uip_timer.h</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>uiplib.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\..\..\..\Source\third_party\uip\uip\uiplib.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>uiplib.h</FileName>
|
||||
<FileType>5</FileType>
|
||||
<FilePath>..\..\..\..\Source\third_party\uip\uip\uiplib.h</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>uipopt.h</FileName>
|
||||
<FileType>5</FileType>
|
||||
<FilePath>..\..\..\..\Source\third_party\uip\uip\uipopt.h</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>dhcpc.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\..\..\..\Source\third_party\uip\apps\dhcpc\dhcpc.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>dhcpc.h</FileName>
|
||||
<FileType>5</FileType>
|
||||
<FilePath>..\..\..\..\Source\third_party\uip\apps\dhcpc\dhcpc.h</FilePath>
|
||||
</File>
|
||||
</Files>
|
||||
</Group>
|
||||
</Groups>
|
||||
</Target>
|
||||
</Targets>
|
||||
|
|
|
@ -0,0 +1,50 @@
|
|||
/*
|
||||
* Copyright (c) 2006, Swedish Institute of Computer Science.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the Institute nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* This file is part of the uIP TCP/IP stack
|
||||
*
|
||||
* $Id: clock-arch.c,v 1.2 2006/06/12 08:00:31 adam Exp $
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file
|
||||
* Implementation of architecture-specific clock functionality
|
||||
* \author
|
||||
* Adam Dunkels <adam@sics.se>
|
||||
*/
|
||||
|
||||
#include "header.h" /* generic header */
|
||||
#include "clock-arch.h"
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
clock_time_t
|
||||
clock_time(void)
|
||||
{
|
||||
return (clock_time_t)TimerGet();
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
|
@ -0,0 +1,40 @@
|
|||
/*
|
||||
* Copyright (c) 2006, Swedish Institute of Computer Science.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the Institute nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* This file is part of the uIP TCP/IP stack
|
||||
*
|
||||
* $Id: clock-arch.h,v 1.2 2006/06/12 08:00:31 adam Exp $
|
||||
*/
|
||||
|
||||
#ifndef __CLOCK_ARCH_H__
|
||||
#define __CLOCK_ARCH_H__
|
||||
|
||||
typedef int clock_time_t;
|
||||
#define CLOCK_CONF_SECOND 1000
|
||||
|
||||
#endif /* __CLOCK_ARCH_H__ */
|
|
@ -0,0 +1,296 @@
|
|||
/*
|
||||
* Copyright (c) 2001, Swedish Institute of Computer Science.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the Institute nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* Author: Adam Dunkels <adam@sics.se>
|
||||
*
|
||||
* $Id: netdev.c,v 1.8 2006/06/07 08:39:58 adam Exp $
|
||||
*/
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#include "header.h" /* generic header */
|
||||
#include "uip.h"
|
||||
#include "uip_arp.h"
|
||||
#include "xmc_gpio.h"
|
||||
#include "xmc_eth_mac.h"
|
||||
#include "xmc_eth_phy.h"
|
||||
#include <string.h>
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#define NETDEV_LINKUP_TIMEOUT_MS (5000)
|
||||
|
||||
#define NETDEV_DEFAULT_MACADDR0 (0x08)
|
||||
#define NETDEV_DEFAULT_MACADDR1 (0x00)
|
||||
#define NETDEV_DEFAULT_MACADDR2 (0x27)
|
||||
#define NETDEV_DEFAULT_MACADDR3 (0x69)
|
||||
#define NETDEV_DEFAULT_MACADDR4 (0x5B)
|
||||
#define NETDEV_DEFAULT_MACADDR5 (0x45)
|
||||
|
||||
#define NETDEV_DEFAULT_MACADDR ((uint64_t)NETDEV_DEFAULT_MACADDR0 | \
|
||||
((uint64_t)NETDEV_DEFAULT_MACADDR1 << 8) | \
|
||||
((uint64_t)NETDEV_DEFAULT_MACADDR2 << 16) | \
|
||||
((uint64_t)NETDEV_DEFAULT_MACADDR3 << 24) | \
|
||||
((uint64_t)NETDEV_DEFAULT_MACADDR4 << 32) | \
|
||||
((uint64_t)NETDEV_DEFAULT_MACADDR5 << 40))
|
||||
|
||||
#define ETH_UIP_0_NUM_RX_BUF (4U)
|
||||
#define ETH_UIP_0_NUM_TX_BUF (4U)
|
||||
|
||||
#define ETH_UIP_0_CRS_DV XMC_GPIO_PORT15, 9U
|
||||
#define ETH_UIP_0_RXER XMC_GPIO_PORT2, 4U
|
||||
#define ETH_UIP_0_RXD0 XMC_GPIO_PORT2, 2U
|
||||
#define ETH_UIP_0_RXD1 XMC_GPIO_PORT2, 3U
|
||||
#define ETH_UIP_0_TXEN XMC_GPIO_PORT2, 5U
|
||||
#define ETH_UIP_0_TXD0 XMC_GPIO_PORT2, 8U
|
||||
#define ETH_UIP_0_TXD1 XMC_GPIO_PORT2, 9U
|
||||
#define ETH_UIP_0_RMII_CLK XMC_GPIO_PORT15, 8U
|
||||
#define ETH_UIP_0_MDC XMC_GPIO_PORT2, 7U
|
||||
#define ETH_UIP_0_MDIO XMC_GPIO_PORT2, 0U
|
||||
#define ETH_UIP_0_PIN_LIST_SIZE (10U)
|
||||
|
||||
#define ETH_UIP_0_PHY_ADDR (0)
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#if defined(__ICCARM__)
|
||||
#pragma data_alignment=4
|
||||
static XMC_ETH_MAC_DMA_DESC_t ETH_UIP_0_rx_desc[ETH_UIP_0_NUM_RX_BUF] @ ".iram2";
|
||||
#pragma data_alignment=4
|
||||
static XMC_ETH_MAC_DMA_DESC_t ETH_UIP_0_tx_desc[ETH_UIP_0_NUM_TX_BUF] @ ".iram2";
|
||||
#pragma data_alignment=4
|
||||
static uint8_t ETH_UIP_0_rx_buf[ETH_UIP_0_NUM_RX_BUF][XMC_ETH_MAC_BUF_SIZE] @ ".iram2";
|
||||
#pragma data_alignment=4
|
||||
static uint8_t ETH_UIP_0_tx_buf[ETH_UIP_0_NUM_TX_BUF][XMC_ETH_MAC_BUF_SIZE] @ ".iram2";
|
||||
#elif defined(__CC_ARM)
|
||||
static __attribute__((aligned(4))) XMC_ETH_MAC_DMA_DESC_t ETH_UIP_0_rx_desc[ETH_UIP_0_NUM_RX_BUF] __attribute__((section ("RW_IRAM1")));
|
||||
static __attribute__((aligned(4))) XMC_ETH_MAC_DMA_DESC_t ETH_UIP_0_tx_desc[ETH_UIP_0_NUM_TX_BUF] __attribute__((section ("RW_IRAM1")));
|
||||
static __attribute__((aligned(4))) uint8_t ETH_UIP_0_rx_buf[ETH_UIP_0_NUM_RX_BUF][XMC_ETH_MAC_BUF_SIZE] __attribute__((section ("RW_IRAM1")));
|
||||
static __attribute__((aligned(4))) uint8_t ETH_UIP_0_tx_buf[ETH_UIP_0_NUM_TX_BUF][XMC_ETH_MAC_BUF_SIZE] __attribute__((section ("RW_IRAM1")));
|
||||
#elif defined(__GNUC__)
|
||||
static __attribute__((aligned(4))) XMC_ETH_MAC_DMA_DESC_t ETH_UIP_0_rx_desc[ETH_UIP_0_NUM_RX_BUF] __attribute__((section ("ETH_RAM")));
|
||||
static __attribute__((aligned(4))) XMC_ETH_MAC_DMA_DESC_t ETH_UIP_0_tx_desc[ETH_UIP_0_NUM_TX_BUF] __attribute__((section ("ETH_RAM")));
|
||||
static __attribute__((aligned(4))) uint8_t ETH_UIP_0_rx_buf[ETH_UIP_0_NUM_RX_BUF][XMC_ETH_MAC_BUF_SIZE] __attribute__((section ("ETH_RAM")));
|
||||
static __attribute__((aligned(4))) uint8_t ETH_UIP_0_tx_buf[ETH_UIP_0_NUM_TX_BUF][XMC_ETH_MAC_BUF_SIZE] __attribute__((section ("ETH_RAM")));
|
||||
#else
|
||||
static __attribute__((aligned(4))) XMC_ETH_MAC_DMA_DESC_t ETH_UIP_0_rx_desc[ETH_UIP_0_NUM_RX_BUF];
|
||||
static __attribute__((aligned(4))) XMC_ETH_MAC_DMA_DESC_t ETH_UIP_0_tx_desc[ETH_UIP_0_NUM_TX_BUF];
|
||||
static __attribute__((aligned(4))) uint8_t ETH_UIP_0_rx_buf[ETH_UIP_0_NUM_RX_BUF][XMC_ETH_MAC_BUF_SIZE];
|
||||
static __attribute__((aligned(4))) uint8_t ETH_UIP_0_tx_buf[ETH_UIP_0_NUM_TX_BUF][XMC_ETH_MAC_BUF_SIZE];
|
||||
#endif
|
||||
|
||||
const XMC_ETH_PHY_CONFIG_t eth_phy_config =
|
||||
{
|
||||
.interface = XMC_ETH_LINK_INTERFACE_RMII,
|
||||
.enable_auto_negotiate = false,
|
||||
.duplex = XMC_ETH_LINK_DUPLEX_FULL,
|
||||
.speed = XMC_ETH_LINK_SPEED_100M
|
||||
};
|
||||
|
||||
XMC_ETH_MAC_t eth_mac =
|
||||
{
|
||||
.regs = ETH0,
|
||||
.address = NETDEV_DEFAULT_MACADDR,
|
||||
.rx_desc = ETH_UIP_0_rx_desc,
|
||||
.tx_desc = ETH_UIP_0_tx_desc,
|
||||
.rx_buf = Ð_UIP_0_rx_buf[0][0],
|
||||
.tx_buf = Ð_UIP_0_tx_buf[0][0],
|
||||
.num_rx_buf = ETH_UIP_0_NUM_RX_BUF,
|
||||
.num_tx_buf = ETH_UIP_0_NUM_TX_BUF
|
||||
};
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void netdev_init(void)
|
||||
{
|
||||
XMC_ETH_MAC_PORT_CTRL_t port_control;
|
||||
XMC_GPIO_CONFIG_t gpio_config;
|
||||
gpio_config.output_level = XMC_GPIO_OUTPUT_LEVEL_LOW;
|
||||
gpio_config.mode = XMC_GPIO_MODE_INPUT_TRISTATE;
|
||||
|
||||
/* Initialize GPIO pins. */
|
||||
XMC_GPIO_Init(ETH_UIP_0_CRS_DV, &gpio_config);
|
||||
|
||||
gpio_config.mode = XMC_GPIO_MODE_INPUT_TRISTATE;
|
||||
XMC_GPIO_Init(ETH_UIP_0_RXER, &gpio_config);
|
||||
|
||||
gpio_config.mode = XMC_GPIO_MODE_INPUT_TRISTATE;
|
||||
XMC_GPIO_Init(ETH_UIP_0_RXD0, &gpio_config);
|
||||
|
||||
gpio_config.mode = XMC_GPIO_MODE_INPUT_TRISTATE;
|
||||
XMC_GPIO_Init(ETH_UIP_0_RXD1, &gpio_config);
|
||||
|
||||
gpio_config.output_strength = XMC_GPIO_OUTPUT_STRENGTH_STRONG_SHARP_EDGE;
|
||||
gpio_config.mode = XMC_GPIO_MODE_OUTPUT_PUSH_PULL_ALT1;
|
||||
XMC_GPIO_Init(ETH_UIP_0_TXEN, &gpio_config);
|
||||
|
||||
gpio_config.output_strength = XMC_GPIO_OUTPUT_STRENGTH_STRONG_SHARP_EDGE;
|
||||
gpio_config.mode = XMC_GPIO_MODE_OUTPUT_PUSH_PULL_ALT1;
|
||||
XMC_GPIO_Init(ETH_UIP_0_TXD0, &gpio_config);
|
||||
|
||||
gpio_config.output_strength = XMC_GPIO_OUTPUT_STRENGTH_STRONG_SHARP_EDGE;
|
||||
gpio_config.mode = XMC_GPIO_MODE_OUTPUT_PUSH_PULL_ALT1;
|
||||
XMC_GPIO_Init(ETH_UIP_0_TXD1, &gpio_config);
|
||||
|
||||
gpio_config.mode = XMC_GPIO_MODE_INPUT_TRISTATE;
|
||||
XMC_GPIO_Init(ETH_UIP_0_RMII_CLK, &gpio_config);
|
||||
|
||||
gpio_config.output_strength = XMC_GPIO_OUTPUT_STRENGTH_STRONG_SHARP_EDGE;
|
||||
gpio_config.mode = XMC_GPIO_MODE_OUTPUT_PUSH_PULL_ALT1;
|
||||
XMC_GPIO_Init(ETH_UIP_0_MDC, &gpio_config);
|
||||
|
||||
gpio_config.mode = XMC_GPIO_MODE_INPUT_TRISTATE;
|
||||
XMC_GPIO_Init(ETH_UIP_0_MDIO, &gpio_config);
|
||||
|
||||
XMC_GPIO_SetHardwareControl(ETH_UIP_0_MDIO, XMC_GPIO_HWCTRL_PERIPHERAL1);
|
||||
|
||||
port_control.mode = XMC_ETH_MAC_PORT_CTRL_MODE_RMII;
|
||||
port_control.rxd0 = (XMC_ETH_MAC_PORT_CTRL_RXD0_t)0U;
|
||||
port_control.rxd1 = (XMC_ETH_MAC_PORT_CTRL_RXD1_t)0U;
|
||||
port_control.clk_rmii = (XMC_ETH_MAC_PORT_CTRL_CLK_RMII_t)2U;
|
||||
port_control.crs_dv = (XMC_ETH_MAC_PORT_CTRL_CRS_DV_t)2U;
|
||||
port_control.rxer = (XMC_ETH_MAC_PORT_CTRL_RXER_t)0U;
|
||||
port_control.mdio = (XMC_ETH_MAC_PORT_CTRL_MDIO_t)1U;
|
||||
XMC_ETH_MAC_SetPortControl(ð_mac, port_control);
|
||||
}
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void netdev_init_mac(void)
|
||||
{
|
||||
struct uip_eth_addr macAddress;
|
||||
uint32_t ulLinkTimeOut;
|
||||
|
||||
(void)XMC_ETH_MAC_Init(ð_mac);
|
||||
|
||||
XMC_ETH_MAC_DisableJumboFrame(ð_mac);
|
||||
|
||||
/* Wait for link to become active. */
|
||||
ulLinkTimeOut = TimerGet() + NETDEV_LINKUP_TIMEOUT_MS;
|
||||
while (XMC_ETH_PHY_GetLinkStatus(ð_mac, ETH_UIP_0_PHY_ADDR) == XMC_ETH_LINK_STATUS_DOWN)
|
||||
{
|
||||
/* Check for timeout so that the software program can still start if the ethernet
|
||||
* cable is not connected.
|
||||
*/
|
||||
if (TimerGet() >= ulLinkTimeOut)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
XMC_ETH_PHY_Init(ð_mac, ETH_UIP_0_PHY_ADDR, ð_phy_config);
|
||||
XMC_ETH_MAC_SetLink(ð_mac, XMC_ETH_LINK_SPEED_100M, XMC_ETH_LINK_DUPLEX_FULL);
|
||||
XMC_ETH_MAC_EnableTx(ð_mac);
|
||||
XMC_ETH_MAC_EnableRx(ð_mac);
|
||||
|
||||
/* set the default MAC address */
|
||||
macAddress.addr[0] = NETDEV_DEFAULT_MACADDR0;
|
||||
macAddress.addr[1] = NETDEV_DEFAULT_MACADDR1;
|
||||
macAddress.addr[2] = NETDEV_DEFAULT_MACADDR2;
|
||||
macAddress.addr[3] = NETDEV_DEFAULT_MACADDR3;
|
||||
macAddress.addr[4] = NETDEV_DEFAULT_MACADDR4;
|
||||
macAddress.addr[5] = NETDEV_DEFAULT_MACADDR5;
|
||||
uip_setethaddr(macAddress);
|
||||
}
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void netdev_get_mac(unsigned char * mac_addr)
|
||||
{
|
||||
mac_addr[0] = NETDEV_DEFAULT_MACADDR0;
|
||||
mac_addr[1] = NETDEV_DEFAULT_MACADDR1;
|
||||
mac_addr[2] = NETDEV_DEFAULT_MACADDR2;
|
||||
mac_addr[3] = NETDEV_DEFAULT_MACADDR3;
|
||||
mac_addr[4] = NETDEV_DEFAULT_MACADDR4;
|
||||
mac_addr[5] = NETDEV_DEFAULT_MACADDR5;
|
||||
}
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
unsigned int netdev_read(void)
|
||||
{
|
||||
uint32_t result = 0;
|
||||
uint32_t framelen;
|
||||
|
||||
/* Check if a new frame was received. */
|
||||
framelen = XMC_ETH_MAC_GetRxFrameSize(ð_mac);
|
||||
/* Only process the frame if the length is valid. */
|
||||
if ((framelen > 0U) && (framelen <= (uint32_t)XMC_ETH_MAC_BUF_SIZE))
|
||||
{
|
||||
XMC_ETH_MAC_ReadFrame(ð_mac, uip_buf, framelen);
|
||||
result = framelen;
|
||||
}
|
||||
|
||||
/* Give the result back to the caller. */
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void netdev_send(void)
|
||||
{
|
||||
uint8_t *buffer;
|
||||
uint32_t idx;
|
||||
|
||||
/* Only send the frame if the length is valid. */
|
||||
if ((uip_len > 0U) && (uip_len <= (uint32_t)XMC_ETH_MAC_BUF_SIZE))
|
||||
{
|
||||
if (XMC_ETH_MAC_IsTxDescriptorOwnedByDma(ð_mac))
|
||||
{
|
||||
XMC_ETH_MAC_ResumeTx(ð_mac);
|
||||
}
|
||||
else
|
||||
{
|
||||
buffer = XMC_ETH_MAC_GetTxBuffer(ð_mac);
|
||||
for (idx = 0; idx < uip_len; idx++)
|
||||
{
|
||||
buffer[idx] = uip_buf[idx];
|
||||
}
|
||||
XMC_ETH_MAC_SetTxBufferSize(ð_mac, uip_len);
|
||||
/* Return the Tx descriptor but do not use the XMC_ETH_MAC_ReturnTxDescriptor().
|
||||
* This function enables the 'checksum insertion control' feature by setting the
|
||||
* ETH_MAC_DMA_TDES0_CIC in the eth_mac.tx_desc[eth_mac.tx_index].status. When
|
||||
* this feature is enabled, an incorrect checksum of 0x0000 is always added to
|
||||
* ICMP reponse messages such as the PING reply.
|
||||
*/
|
||||
eth_mac.tx_ts_index = eth_mac.tx_index;
|
||||
eth_mac.tx_desc[eth_mac.tx_index].status |= ETH_MAC_DMA_TDES0_OWN;
|
||||
eth_mac.tx_index++;
|
||||
if (eth_mac.tx_index == eth_mac.num_tx_buf)
|
||||
{
|
||||
eth_mac.tx_index = 0U;
|
||||
}
|
||||
eth_mac.frame_end = NULL;
|
||||
XMC_ETH_MAC_ResumeTx(ð_mac);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,47 @@
|
|||
/*
|
||||
* Copyright (c) 2001, Adam Dunkels.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by Adam Dunkels.
|
||||
* 4. The name of the author may not be used to endorse or promote
|
||||
* products derived from this software without specific prior
|
||||
* written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This file is part of the uIP TCP/IP stack.
|
||||
*
|
||||
* $Id: netdev.h,v 1.1 2002/01/10 06:22:56 adam Exp $
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef __NETDEV_H__
|
||||
#define __NETDEV_H__
|
||||
|
||||
void netdev_init(void);
|
||||
void netdev_init_mac(void);
|
||||
void netdev_get_mac(unsigned char * mac_addr);
|
||||
unsigned int netdev_read(void);
|
||||
void netdev_send(void);
|
||||
|
||||
#endif /* __NETDEV_H__ */
|
|
@ -0,0 +1,160 @@
|
|||
/**
|
||||
* \addtogroup uipopt
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* \name Project-specific configuration options
|
||||
* @{
|
||||
*
|
||||
* uIP has a number of configuration options that can be overridden
|
||||
* for each project. These are kept in a project-specific uip-conf.h
|
||||
* file and all configuration names have the prefix UIP_CONF.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2006, Swedish Institute of Computer Science.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the Institute nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* This file is part of the uIP TCP/IP stack
|
||||
*
|
||||
* $Id: uip-conf.h,v 1.6 2006/06/12 08:00:31 adam Exp $
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file
|
||||
* An example uIP configuration file
|
||||
* \author
|
||||
* Adam Dunkels <adam@sics.se>
|
||||
*/
|
||||
|
||||
#ifndef __UIP_CONF_H__
|
||||
#define __UIP_CONF_H__
|
||||
|
||||
|
||||
/**
|
||||
* 8 bit datatype
|
||||
*
|
||||
* This typedef defines the 8-bit type used throughout uIP.
|
||||
*
|
||||
* \hideinitializer
|
||||
*/
|
||||
typedef unsigned char u8_t;
|
||||
|
||||
/**
|
||||
* 16 bit datatype
|
||||
*
|
||||
* This typedef defines the 16-bit type used throughout uIP.
|
||||
*
|
||||
* \hideinitializer
|
||||
*/
|
||||
typedef unsigned short u16_t;
|
||||
|
||||
/**
|
||||
* Statistics datatype
|
||||
*
|
||||
* This typedef defines the dataype used for keeping statistics in
|
||||
* uIP.
|
||||
*
|
||||
* \hideinitializer
|
||||
*/
|
||||
typedef unsigned short uip_stats_t;
|
||||
|
||||
/**
|
||||
* Maximum number of TCP connections.
|
||||
*
|
||||
* \hideinitializer
|
||||
*/
|
||||
#define UIP_CONF_MAX_CONNECTIONS 1
|
||||
|
||||
/**
|
||||
* Maximum number of listening TCP ports.
|
||||
*
|
||||
* \hideinitializer
|
||||
*/
|
||||
#define UIP_CONF_MAX_LISTENPORTS 1
|
||||
|
||||
/**
|
||||
* UDP support on or off
|
||||
*
|
||||
* \hideinitializer
|
||||
*/
|
||||
#define UIP_CONF_UDP 1
|
||||
|
||||
/**
|
||||
* UDP Maximum Connections
|
||||
*
|
||||
* \hideinitializer
|
||||
*/
|
||||
#define UIP_CONF_UDP_CONNS 1
|
||||
|
||||
/**
|
||||
* UDP checksums on or off
|
||||
*
|
||||
* \hideinitializer
|
||||
*/
|
||||
#define UIP_CONF_UDP_CHECKSUMS 0
|
||||
|
||||
/**
|
||||
* uIP buffer size.
|
||||
*
|
||||
* \hideinitializer
|
||||
*/
|
||||
#define UIP_CONF_BUFFER_SIZE 1600
|
||||
|
||||
/**
|
||||
* CPU byte order.
|
||||
*
|
||||
* \hideinitializer
|
||||
*/
|
||||
#define UIP_CONF_BYTE_ORDER UIP_LITTLE_ENDIAN
|
||||
|
||||
/**
|
||||
* Logging on or off
|
||||
*
|
||||
* \hideinitializer
|
||||
*/
|
||||
#define UIP_CONF_LOGGING 0
|
||||
|
||||
/**
|
||||
* uIP statistics on or off
|
||||
*
|
||||
* \hideinitializer
|
||||
*/
|
||||
#define UIP_CONF_STATISTICS 0
|
||||
|
||||
|
||||
/* Here we include the header file for the application(s) we use in
|
||||
our project. */
|
||||
#include "header.h"
|
||||
#include "net.h"
|
||||
#include "dhcpc.h"
|
||||
|
||||
#endif /* __UIP_CONF_H__ */
|
||||
|
||||
/** @} */
|
||||
/** @} */
|
|
@ -48,14 +48,25 @@ int main(void)
|
|||
{
|
||||
/* initialize the microcontroller */
|
||||
Init();
|
||||
/* initialize the shared parameters module */
|
||||
SharedParamsInit();
|
||||
/* initialize the network application */
|
||||
NetInit();
|
||||
/* initialize the bootloader interface */
|
||||
BootComInit();
|
||||
/* the shared parameter at index 0 is used as a boolean flag to indicate if the
|
||||
* bootloader should initialize the TCP/IP network stack. by default this flag
|
||||
* should be reset.
|
||||
*/
|
||||
SharedParamsWriteByIndex(0, 0);
|
||||
|
||||
/* start the infinite program loop */
|
||||
while (1)
|
||||
{
|
||||
/* toggle LED with a fixed frequency */
|
||||
LedToggle();
|
||||
/* run the network task */
|
||||
NetTask();
|
||||
/* check for bootloader activation request */
|
||||
BootComCheckActivationRequest();
|
||||
}
|
||||
|
|
|
@ -0,0 +1,255 @@
|
|||
/************************************************************************************//**
|
||||
* \file Demo/ARMCM4_XMC4_XMC4700_Relax_Kit_Keil/Prog/net.c
|
||||
* \brief Network application for the uIP TCP/IP stack.
|
||||
* \ingroup Prog_ARMCM4_XMC4_XMC4700_Relax_Kit_Keil
|
||||
* \internal
|
||||
*----------------------------------------------------------------------------------------
|
||||
* C O P Y R I G H T
|
||||
*----------------------------------------------------------------------------------------
|
||||
* Copyright (c) 2022 by Feaser http://www.feaser.com All rights reserved
|
||||
*
|
||||
*----------------------------------------------------------------------------------------
|
||||
* L I C E N S E
|
||||
*----------------------------------------------------------------------------------------
|
||||
* This file is part of OpenBLT. OpenBLT is free software: you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as published by the Free
|
||||
* Software Foundation, either version 3 of the License, or (at your option) any later
|
||||
* version.
|
||||
*
|
||||
* OpenBLT is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
||||
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
* PURPOSE. See the GNU General Public License for more details.
|
||||
*
|
||||
* You have received a copy of the GNU General Public License along with OpenBLT. It
|
||||
* should be located in ".\Doc\license.html". If not, contact Feaser to obtain a copy.
|
||||
*
|
||||
* \endinternal
|
||||
****************************************************************************************/
|
||||
|
||||
/****************************************************************************************
|
||||
* Include files
|
||||
****************************************************************************************/
|
||||
#include "header.h" /* generic header */
|
||||
#include "netdev.h"
|
||||
#include "uip.h"
|
||||
#include "uip_arp.h"
|
||||
|
||||
|
||||
/****************************************************************************************
|
||||
* Macro definitions
|
||||
****************************************************************************************/
|
||||
/** \brief Delta time for the uIP periodic timer. */
|
||||
#define NET_UIP_PERIODIC_TIMER_MS (500)
|
||||
/** \brief Delta time for the uIP ARP timer. */
|
||||
#define NET_UIP_ARP_TIMER_MS (10000)
|
||||
/** \brief Macro for accessing the Ethernet header information in the buffer */
|
||||
#define NET_UIP_HEADER_BUF ((struct uip_eth_hdr *)&uip_buf[0])
|
||||
|
||||
|
||||
/****************************************************************************************
|
||||
* Local data declarations
|
||||
****************************************************************************************/
|
||||
/** \brief Holds the time out value of the uIP periodic timer. */
|
||||
static unsigned long periodicTimerTimeOut;
|
||||
/** \brief Holds the time out value of the uIP ARP timer. */
|
||||
static unsigned long ARPTimerTimeOut;
|
||||
#if (BOOT_COM_NET_DHCP_ENABLE > 0)
|
||||
/** \brief Holds the MAC address which is used by the DHCP client. */
|
||||
static struct uip_eth_addr macAddress;
|
||||
#endif
|
||||
|
||||
|
||||
/************************************************************************************//**
|
||||
** \brief Initializes the TCP/IP network communication interface.
|
||||
** \return none.
|
||||
**
|
||||
****************************************************************************************/
|
||||
void NetInit(void)
|
||||
{
|
||||
uip_ipaddr_t ipaddr;
|
||||
|
||||
/* initialize the network device */
|
||||
netdev_init();
|
||||
/* initialize the timer variables */
|
||||
periodicTimerTimeOut = TimerGet() + NET_UIP_PERIODIC_TIMER_MS;
|
||||
ARPTimerTimeOut = TimerGet() + NET_UIP_ARP_TIMER_MS;
|
||||
/* initialize the uIP TCP/IP stack. */
|
||||
uip_init();
|
||||
#if (BOOT_COM_NET_DHCP_ENABLE == 0)
|
||||
/* set the IP address */
|
||||
uip_ipaddr(ipaddr, BOOT_COM_NET_IPADDR0, BOOT_COM_NET_IPADDR1, BOOT_COM_NET_IPADDR2,
|
||||
BOOT_COM_NET_IPADDR3);
|
||||
uip_sethostaddr(ipaddr);
|
||||
/* set the network mask */
|
||||
uip_ipaddr(ipaddr, BOOT_COM_NET_NETMASK0, BOOT_COM_NET_NETMASK1, BOOT_COM_NET_NETMASK2,
|
||||
BOOT_COM_NET_NETMASK3);
|
||||
uip_setnetmask(ipaddr);
|
||||
/* set the gateway address */
|
||||
uip_ipaddr(ipaddr, BOOT_COM_NET_GATEWAY0, BOOT_COM_NET_GATEWAY1, BOOT_COM_NET_GATEWAY2,
|
||||
BOOT_COM_NET_GATEWAY3);
|
||||
uip_setdraddr(ipaddr);
|
||||
#else
|
||||
/* set the IP address */
|
||||
uip_ipaddr(ipaddr, 0, 0, 0, 0);
|
||||
uip_sethostaddr(ipaddr);
|
||||
/* set the network mask */
|
||||
uip_ipaddr(ipaddr, 0, 0, 0, 0);
|
||||
uip_setnetmask(ipaddr);
|
||||
/* set the gateway address */
|
||||
uip_ipaddr(ipaddr, 0, 0, 0, 0);
|
||||
uip_setdraddr(ipaddr);
|
||||
#endif
|
||||
/* start listening on the configured port for XCP transfers on TCP/IP */
|
||||
uip_listen(HTONS(BOOT_COM_NET_PORT));
|
||||
/* initialize the MAC and set the MAC address */
|
||||
netdev_init_mac();
|
||||
|
||||
#if (BOOT_COM_NET_DHCP_ENABLE > 0)
|
||||
/* initialize the DHCP client application and send the initial request. */
|
||||
netdev_get_mac(&macAddress.addr[0]);
|
||||
dhcpc_init(&macAddress.addr[0], 6);
|
||||
dhcpc_request();
|
||||
#endif
|
||||
} /*** end of NetInit ***/
|
||||
|
||||
|
||||
/************************************************************************************//**
|
||||
** \brief The uIP network application that detects the XCP connect command on the
|
||||
** port used by the bootloader. This indicates that the bootloader should
|
||||
** be activated.
|
||||
** \return none.
|
||||
**
|
||||
****************************************************************************************/
|
||||
void NetApp(void)
|
||||
{
|
||||
unsigned char *newDataPtr;
|
||||
unsigned short newDataLen;
|
||||
|
||||
if (uip_connected())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (uip_newdata())
|
||||
{
|
||||
/* a new XCP command was received. check if this is the connect command and in this
|
||||
* case activate the bootloader. with XCP on TCP/IP the first 4 bytes contain a
|
||||
* counter value in which we are not really interested.
|
||||
*/
|
||||
newDataPtr = uip_appdata;
|
||||
newDataPtr += 4;
|
||||
newDataLen = uip_datalen() - 4;
|
||||
/* check if this was an XCP CONNECT command */
|
||||
if ((newDataPtr[0] == 0xff) && (newDataLen == 2))
|
||||
{
|
||||
/* the shared parameter at index 0 is used as a boolean flag to indicate if the
|
||||
* bootloader should initialize the TCP/IP network stack. we just received a
|
||||
* firmware update request from the TCP/IP network and we are about to active
|
||||
* the bootloader for a firmware update via TCP/IP. At this point we should
|
||||
* set the flag to make sure the bootloader initializes its TCP/IP network stack.
|
||||
*/
|
||||
SharedParamsWriteByIndex(0, 1);
|
||||
/* connection request received so start the bootloader */
|
||||
BootActivate();
|
||||
}
|
||||
}
|
||||
} /*** end of NetApp ***/
|
||||
|
||||
|
||||
/************************************************************************************//**
|
||||
** \brief Runs the TCP/IP server task.
|
||||
** \return none.
|
||||
**
|
||||
****************************************************************************************/
|
||||
void NetTask(void)
|
||||
{
|
||||
unsigned long connection;
|
||||
unsigned long packetLen;
|
||||
|
||||
/* check for an RX packet and read it. */
|
||||
packetLen = netdev_read();
|
||||
if (packetLen > 0)
|
||||
{
|
||||
/* set uip_len for uIP stack usage */
|
||||
uip_len = (unsigned short)packetLen;
|
||||
|
||||
/* process incoming IP packets here. */
|
||||
if (NET_UIP_HEADER_BUF->type == htons(UIP_ETHTYPE_IP))
|
||||
{
|
||||
uip_arp_ipin();
|
||||
uip_input();
|
||||
/* if the above function invocation resulted in data that
|
||||
* should be sent out on the network, the global variable
|
||||
* uip_len is set to a value > 0.
|
||||
*/
|
||||
if (uip_len > 0)
|
||||
{
|
||||
uip_arp_out();
|
||||
netdev_send();
|
||||
uip_len = 0;
|
||||
}
|
||||
}
|
||||
/* process incoming ARP packets here. */
|
||||
else if (NET_UIP_HEADER_BUF->type == htons(UIP_ETHTYPE_ARP))
|
||||
{
|
||||
uip_arp_arpin();
|
||||
|
||||
/* if the above function invocation resulted in data that
|
||||
* should be sent out on the network, the global variable
|
||||
* uip_len is set to a value > 0.
|
||||
*/
|
||||
if (uip_len > 0)
|
||||
{
|
||||
netdev_send();
|
||||
uip_len = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* process TCP/IP Periodic Timer here. */
|
||||
if (TimerGet() >= periodicTimerTimeOut)
|
||||
{
|
||||
periodicTimerTimeOut += NET_UIP_PERIODIC_TIMER_MS;
|
||||
for (connection = 0; connection < UIP_CONNS; connection++)
|
||||
{
|
||||
uip_periodic(connection);
|
||||
/* If the above function invocation resulted in data that
|
||||
* should be sent out on the network, the global variable
|
||||
* uip_len is set to a value > 0.
|
||||
*/
|
||||
if (uip_len > 0)
|
||||
{
|
||||
uip_arp_out();
|
||||
netdev_send();
|
||||
uip_len = 0;
|
||||
}
|
||||
}
|
||||
|
||||
#if UIP_UDP
|
||||
for (connection = 0; connection < UIP_UDP_CONNS; connection++)
|
||||
{
|
||||
uip_udp_periodic(connection);
|
||||
/* If the above function invocation resulted in data that
|
||||
* should be sent out on the network, the global variable
|
||||
* uip_len is set to a value > 0.
|
||||
*/
|
||||
if(uip_len > 0)
|
||||
{
|
||||
uip_arp_out();
|
||||
netdev_send();
|
||||
uip_len = 0;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
/* process ARP Timer here. */
|
||||
if (TimerGet() >= ARPTimerTimeOut)
|
||||
{
|
||||
ARPTimerTimeOut += NET_UIP_ARP_TIMER_MS;
|
||||
uip_arp_timer();
|
||||
}
|
||||
} /*** end of NetServerTask ***/
|
||||
|
||||
|
||||
/*********************************** end of net.c **************************************/
|
|
@ -0,0 +1,61 @@
|
|||
/************************************************************************************//**
|
||||
* \file Demo/ARMCM4_XMC4_XMC4700_Relax_Kit_Keil/Prog/net.h
|
||||
* \brief Network application for the uIP TCP/IP stack.
|
||||
* \ingroup Prog_ARMCM4_XMC4_XMC4700_Relax_Kit_Keil
|
||||
* \internal
|
||||
*----------------------------------------------------------------------------------------
|
||||
* C O P Y R I G H T
|
||||
*----------------------------------------------------------------------------------------
|
||||
* Copyright (c) 2022 by Feaser http://www.feaser.com All rights reserved
|
||||
*
|
||||
*----------------------------------------------------------------------------------------
|
||||
* L I C E N S E
|
||||
*----------------------------------------------------------------------------------------
|
||||
* This file is part of OpenBLT. OpenBLT is free software: you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as published by the Free
|
||||
* Software Foundation, either version 3 of the License, or (at your option) any later
|
||||
* version.
|
||||
*
|
||||
* OpenBLT is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
||||
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
* PURPOSE. See the GNU General Public License for more details.
|
||||
*
|
||||
* You have received a copy of the GNU General Public License along with OpenBLT. It
|
||||
* should be located in ".\Doc\license.html". If not, contact Feaser to obtain a copy.
|
||||
*
|
||||
* \endinternal
|
||||
****************************************************************************************/
|
||||
#ifndef NET_H
|
||||
#define NET_H
|
||||
|
||||
/****************************************************************************************
|
||||
* Macro definitions
|
||||
****************************************************************************************/
|
||||
#ifndef UIP_APPCALL
|
||||
#define UIP_APPCALL NetApp
|
||||
#endif /* UIP_APPCALL */
|
||||
|
||||
|
||||
/****************************************************************************************
|
||||
* Type definitions
|
||||
****************************************************************************************/
|
||||
/** \brief Define the uip_tcp_appstate_t datatype. This is the state of our tcp/ip
|
||||
* application, and the memory required for this state is allocated together
|
||||
* with each TCP connection. One application state for each TCP connection.
|
||||
*/
|
||||
typedef struct net_state
|
||||
{
|
||||
unsigned char unused;
|
||||
} uip_tcp_appstate_t;
|
||||
|
||||
|
||||
/****************************************************************************************
|
||||
* Function prototypes
|
||||
****************************************************************************************/
|
||||
void NetInit(void);
|
||||
void NetApp(void);
|
||||
void NetTask(void);
|
||||
|
||||
|
||||
#endif /* NET_H */
|
||||
/*********************************** end of net.h **************************************/
|
|
@ -0,0 +1,301 @@
|
|||
/************************************************************************************//**
|
||||
* \file Demo/ARMCM4_XMC4_XMC4700_Relax_Kit_Keil/Prog/shared_params.c
|
||||
* \brief Shared RAM parameters source file.
|
||||
* \ingroup Prog_ARMCM4_XMC4_XMC4700_Relax_Kit_Keil
|
||||
* \internal
|
||||
*----------------------------------------------------------------------------------------
|
||||
* C O P Y R I G H T
|
||||
*----------------------------------------------------------------------------------------
|
||||
* Copyright (c) 2022 by Feaser http://www.feaser.com All rights reserved
|
||||
*
|
||||
*----------------------------------------------------------------------------------------
|
||||
* L I C E N S E
|
||||
*----------------------------------------------------------------------------------------
|
||||
* This file is part of OpenBLT. OpenBLT is free software: you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as published by the Free
|
||||
* Software Foundation, either version 3 of the License, or (at your option) any later
|
||||
* version.
|
||||
*
|
||||
* OpenBLT is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
||||
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
* PURPOSE. See the GNU General Public License for more details.
|
||||
*
|
||||
* You have received a copy of the GNU General Public License along with OpenBLT. It
|
||||
* should be located in ".\Doc\license.html". If not, contact Feaser to obtain a copy.
|
||||
*
|
||||
* \endinternal
|
||||
****************************************************************************************/
|
||||
|
||||
/****************************************************************************************
|
||||
* Include files
|
||||
****************************************************************************************/
|
||||
#include <stddef.h> /* Standard definitions (NULL). */
|
||||
#include "shared_params.h" /* Shared parameters header. */
|
||||
|
||||
|
||||
/****************************************************************************************
|
||||
* Macro definitions
|
||||
****************************************************************************************/
|
||||
/** \brief Constant parameter buffer identifier. This value is always located as the
|
||||
* start of the buffer to validate the the RAM contains valid shared parameters.
|
||||
*/
|
||||
#define SHARED_PARAMS_BUFFER_ID (0xCE42E7A2u)
|
||||
|
||||
|
||||
/****************************************************************************************
|
||||
* Type definitions
|
||||
****************************************************************************************/
|
||||
/** \brief Layout of the shared parameters RAM buffer. */
|
||||
typedef struct t_shared_params_buffer
|
||||
{
|
||||
/** \brief Fixed buffer identifier to validate that the RAM contains valid shared
|
||||
* parameters.
|
||||
*/
|
||||
uint32_t identifier;
|
||||
/** \brief Array for the actual parameter data. */
|
||||
uint8_t data[SHARED_PARAMS_CFG_BUFFER_DATA_LEN];
|
||||
/** \brief Checksum value of all the bytes in the buffer, excluding this checksum
|
||||
* value of obvious reasons. The checksum is calculated as the Two's
|
||||
* complement of the sum of the bytes.
|
||||
*/
|
||||
uint16_t checksum;
|
||||
} tSharedParamsBuffer;
|
||||
|
||||
|
||||
/****************************************************************************************
|
||||
* Global data declarations
|
||||
****************************************************************************************/
|
||||
/** \brief Declaration of the actual parameter buffer that this module manages.
|
||||
* \warning For the shared RAM parameters to work properly for sharing information
|
||||
* between the bootloader and user program, it is important that this
|
||||
* variable is linked to the exact same RAM address in both the bootloader
|
||||
* and the user program. Additionally, it should be configured such that the
|
||||
* C-startup code does NOT zero its contents during system initialization. This
|
||||
* is the code that runs in the reset event handler, before function main() is
|
||||
* called.
|
||||
* For GCC based embedded toolchains, the solution is to assign this variable
|
||||
* to a custom section, in this case called ".shared". Then in the linker
|
||||
* script, add the following to the SECTIONS:
|
||||
*
|
||||
* .shared (NOLOAD) :
|
||||
* {
|
||||
* . = ALIGN(4);
|
||||
* _sshared = .;
|
||||
* __shared_start__ = _sshared;
|
||||
* *(.shared)
|
||||
* *(.shared.*)
|
||||
* KEEP(*(.shared))
|
||||
* . = ALIGN(4);
|
||||
* _eshared = .;
|
||||
* __shared_end__ = _eshared;
|
||||
* } >SHARED
|
||||
*
|
||||
* Next, add a new MEMORY entry for SHARED at the start of RAM and reduce
|
||||
* the length of the remaining RAM:
|
||||
*
|
||||
* SHARED (xrw) : ORIGIN = 0x200000C0, LENGTH = 64
|
||||
* RAM (xrw) : ORIGIN = 0x20000100, LENGTH = 32K - 192 - 64
|
||||
*
|
||||
* Note that the previous example is for an STM32F0 microcontroller where
|
||||
* the first 192 (0xC0) bytes in RAM are reserved for the user program
|
||||
* vector table.
|
||||
*
|
||||
* \remark This same approach can be applied with other toolchains such as Keil MDK
|
||||
* and IAR EWARM. Consult the compiler and linker user manuals of your
|
||||
* toolchain to find out how to place a RAM variable at a fixed memory address
|
||||
* and to prevent the C-startup code from zeroing its contents.
|
||||
* Here are a few links to get you started:
|
||||
* * IAR EWARM:
|
||||
* https://www.iar.com/support/tech-notes/compiler/
|
||||
* linker-error-for-absolute-located-variable/
|
||||
* * Keil MDK:
|
||||
* http://www.keil.com/support/docs/3480.htm
|
||||
*/
|
||||
static tSharedParamsBuffer sharedParamsBuffer __attribute__((section("shared"),zero_init));
|
||||
|
||||
|
||||
/****************************************************************************************
|
||||
* Function prototypes
|
||||
****************************************************************************************/
|
||||
static bool SharedParamsValidateBuffer(void);
|
||||
static void SharedParamsWriteChecksum(void);
|
||||
static bool SharedParamsVerifyChecksum(void);
|
||||
static uint16_t SharedParamsCalculateChecksum(void);
|
||||
|
||||
|
||||
/************************************************************************************//**
|
||||
** \brief Initializes the shared RAM parameters module.
|
||||
** \return none.
|
||||
**
|
||||
****************************************************************************************/
|
||||
void SharedParamsInit(void)
|
||||
{
|
||||
uint32_t byteIdx;
|
||||
|
||||
/* The shared parameter buffer does not get initialized by the C-startup code. Another
|
||||
* previously running program could have initialized it, in which case it is ready
|
||||
* for use and nothing more needs to be done.
|
||||
*/
|
||||
if (!SharedParamsValidateBuffer())
|
||||
{
|
||||
/* The shared parameter buffer was not yet initialized by a running program. This
|
||||
* typically happens after a cold reset where the RAM contents were lost. In this
|
||||
* case we need to explicitly configure and initialize it, since the C-startup code
|
||||
* was configured to not do this.
|
||||
*
|
||||
* The initialization consists of setting the buffer identifier, zeroing the
|
||||
* actual parameter data and updating the checksum at the end.
|
||||
*/
|
||||
sharedParamsBuffer.identifier = SHARED_PARAMS_BUFFER_ID;
|
||||
for (byteIdx=0; byteIdx < SHARED_PARAMS_CFG_BUFFER_DATA_LEN; byteIdx++)
|
||||
{
|
||||
sharedParamsBuffer.data[byteIdx] = 0;
|
||||
}
|
||||
SharedParamsWriteChecksum();
|
||||
}
|
||||
} /*** end of SharedParamsInit ***/
|
||||
|
||||
|
||||
/************************************************************************************//**
|
||||
** \brief Reads a data byte from the shared parameter buffer at the specified index.
|
||||
** \param idx Index into the parameter data array. A valid value is between 0 and
|
||||
** (SHARED_PARAMS_CFG_BUFFER_DATA_LEN - 1).
|
||||
** \param value Pointer to where the read data value is stored.
|
||||
** \return True if successful, false otherwise.
|
||||
**
|
||||
****************************************************************************************/
|
||||
bool SharedParamsReadByIndex(uint32_t idx, uint8_t * value)
|
||||
{
|
||||
bool result = false;
|
||||
|
||||
/* Only continue if the buffer and the specified parameters are valid. */
|
||||
if ( (SharedParamsValidateBuffer()) &&
|
||||
(idx < SHARED_PARAMS_CFG_BUFFER_DATA_LEN) &&
|
||||
(value != NULL) )
|
||||
{
|
||||
/* Read the value and update the result. */
|
||||
*value = sharedParamsBuffer.data[idx];
|
||||
result = true;
|
||||
}
|
||||
/* Give the result back to the caller. */
|
||||
return result;
|
||||
} /*** end of SharedParamsReadByIndex ***/
|
||||
|
||||
|
||||
/************************************************************************************//**
|
||||
** \brief Writes a data byte to the shared parameter buffer at the specified index.
|
||||
** \param idx Index into the parameter data array. A valid value is between 0 and
|
||||
** (SHARED_PARAMS_CFG_BUFFER_DATA_LEN - 1).
|
||||
** \param value Value to write.
|
||||
** \return True if successful, false otherwise.
|
||||
**
|
||||
****************************************************************************************/
|
||||
bool SharedParamsWriteByIndex(uint32_t idx, uint8_t value)
|
||||
{
|
||||
bool result = false;
|
||||
|
||||
/* Only continue if the buffer and the specified parameters are valid. */
|
||||
if ( (SharedParamsValidateBuffer()) &&
|
||||
(idx < SHARED_PARAMS_CFG_BUFFER_DATA_LEN) )
|
||||
{
|
||||
/* Write the value. */
|
||||
sharedParamsBuffer.data[idx] = value;
|
||||
/* Update the checksum since the contents were just changed. */
|
||||
SharedParamsWriteChecksum();
|
||||
/* Update the result. */
|
||||
result = true;
|
||||
}
|
||||
/* Give the result back to the caller. */
|
||||
return result;
|
||||
} /*** end of SharedParamsWriteByIndex ***/
|
||||
|
||||
|
||||
/************************************************************************************//**
|
||||
** \brief Validates the shared parameter buffer contents by looking at the table
|
||||
** identifier and verifying its checksum.
|
||||
** \return True if successful, false otherwise.
|
||||
**
|
||||
****************************************************************************************/
|
||||
static bool SharedParamsValidateBuffer(void)
|
||||
{
|
||||
bool result = false;
|
||||
|
||||
/* Perform validation. */
|
||||
if ( (sharedParamsBuffer.identifier == SHARED_PARAMS_BUFFER_ID) &&
|
||||
(SharedParamsVerifyChecksum()) )
|
||||
{
|
||||
/* The shared parameter buffer is valid, so update the result value. */
|
||||
result = true;
|
||||
}
|
||||
/* Give the result back to the caller. */
|
||||
return result;
|
||||
} /*** end of SharedParamsValitabeTable ***/
|
||||
|
||||
|
||||
/************************************************************************************//**
|
||||
** \brief Calculates and writes the checksum into the buffer.
|
||||
** \return none.
|
||||
**
|
||||
****************************************************************************************/
|
||||
static void SharedParamsWriteChecksum(void)
|
||||
{
|
||||
/* Calculate and write the checksum. */
|
||||
sharedParamsBuffer.checksum = SharedParamsCalculateChecksum();
|
||||
} /*** end of SharedParamsWriteChecksum ***/
|
||||
|
||||
|
||||
/************************************************************************************//**
|
||||
** \brief Calculates and verifies the checksum that is currently present in the
|
||||
** buffer.
|
||||
** \return True is the checksum is correct, false otherwise.
|
||||
**
|
||||
****************************************************************************************/
|
||||
static bool SharedParamsVerifyChecksum(void)
|
||||
{
|
||||
bool result = false;
|
||||
|
||||
/* Calculate and verify the checksum. */
|
||||
if (SharedParamsCalculateChecksum() == sharedParamsBuffer.checksum)
|
||||
{
|
||||
/* Checksum is correct, so update the result value. */
|
||||
result = true;
|
||||
}
|
||||
/* Give the result back to the caller. */
|
||||
return result;
|
||||
} /*** end of SharedParamsVerifyChecksum ***/
|
||||
|
||||
|
||||
/************************************************************************************//**
|
||||
** \brief Calculates and returns the checksum value for the current contents in the
|
||||
** buffer. The checksum is calculated by taking the sum of all bytes in the
|
||||
** parameter buffer (excluding the checksum at the end) and them taking the
|
||||
** two's complement value of it.
|
||||
** \return The calculated checksum value.
|
||||
**
|
||||
****************************************************************************************/
|
||||
static uint16_t SharedParamsCalculateChecksum(void)
|
||||
{
|
||||
uint16_t result = 0;
|
||||
uint32_t byteIdx;
|
||||
|
||||
/* Add the identifier bytes to the checksum. */
|
||||
result += (uint8_t)sharedParamsBuffer.identifier;
|
||||
result += (uint8_t)(sharedParamsBuffer.identifier >> 8u);
|
||||
result += (uint8_t)(sharedParamsBuffer.identifier >> 16u);
|
||||
result += (uint8_t)(sharedParamsBuffer.identifier >> 24u);
|
||||
/* Loop through the parameter data array. */
|
||||
for (byteIdx=0; byteIdx<SHARED_PARAMS_CFG_BUFFER_DATA_LEN; byteIdx++)
|
||||
{
|
||||
/* Add parameter data byte to the checksum. */
|
||||
result += (uint8_t)sharedParamsBuffer.data[byteIdx];
|
||||
}
|
||||
/* Determine one's complement. */
|
||||
result = ~result;
|
||||
/* Determine two's complement. */
|
||||
result += 1;
|
||||
/* Give the result back to the caller. */
|
||||
return result;
|
||||
} /*** end of SharedParamsCalculateChecksum ***/
|
||||
|
||||
|
||||
/*********************************** end of shared_params.c ****************************/
|
|
@ -0,0 +1,57 @@
|
|||
/************************************************************************************//**
|
||||
* \file Demo/ARMCM4_XMC4_XMC4700_Relax_Kit_Keil/Prog/shared_params.h
|
||||
* \brief Shared RAM parameters header file.
|
||||
* \ingroup Prog_ARMCM4_XMC4_XMC4700_Relax_Kit_Keil
|
||||
* \internal
|
||||
*----------------------------------------------------------------------------------------
|
||||
* C O P Y R I G H T
|
||||
*----------------------------------------------------------------------------------------
|
||||
* Copyright (c) 2022 by Feaser http://www.feaser.com All rights reserved
|
||||
*
|
||||
*----------------------------------------------------------------------------------------
|
||||
* L I C E N S E
|
||||
*----------------------------------------------------------------------------------------
|
||||
* This file is part of OpenBLT. OpenBLT is free software: you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as published by the Free
|
||||
* Software Foundation, either version 3 of the License, or (at your option) any later
|
||||
* version.
|
||||
*
|
||||
* OpenBLT is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
||||
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
* PURPOSE. See the GNU General Public License for more details.
|
||||
*
|
||||
* You have received a copy of the GNU General Public License along with OpenBLT. It
|
||||
* should be located in ".\Doc\license.html". If not, contact Feaser to obtain a copy.
|
||||
*
|
||||
* \endinternal
|
||||
****************************************************************************************/
|
||||
#ifndef SHARED_PARAMS_H
|
||||
#define SHARED_PARAMS_H
|
||||
|
||||
/****************************************************************************************
|
||||
* Include files
|
||||
****************************************************************************************/
|
||||
#include <stdint.h> /* Standard integer types. */
|
||||
#include <stdbool.h> /* Standard boolean types. */
|
||||
|
||||
|
||||
/****************************************************************************************
|
||||
* Configuration macros
|
||||
****************************************************************************************/
|
||||
/** \brief Configuration macro for specifying the size of the data inside the parameter
|
||||
* buffer. This is the length in bytes of the actual parameter data, so
|
||||
* excluding the bufferId and checksum.
|
||||
*/
|
||||
#define SHARED_PARAMS_CFG_BUFFER_DATA_LEN (56u)
|
||||
|
||||
|
||||
/****************************************************************************************
|
||||
* Function prototypes
|
||||
****************************************************************************************/
|
||||
void SharedParamsInit(void);
|
||||
bool SharedParamsReadByIndex(uint32_t idx, uint8_t * value);
|
||||
bool SharedParamsWriteByIndex(uint32_t idx, uint8_t value);
|
||||
|
||||
|
||||
#endif /* SHARED_PARAMS_H */
|
||||
/*********************************** end of shared_params.h ****************************/
|
|
@ -0,0 +1,29 @@
|
|||
; *************************************************************
|
||||
; *** Scatter-Loading Description File generated by uVision ***
|
||||
; *************************************************************
|
||||
|
||||
LR_IROM1 0x0800C000 0x001F4000 { ; load region size_region
|
||||
ER_IROM1 0x0800C000 0x001F4000 { ; load address = execution address
|
||||
*.o (RESET, +First)
|
||||
*(InRoot$$Sections)
|
||||
.ANY (+RO)
|
||||
.ANY (+XO)
|
||||
}
|
||||
|
||||
; Theoretically it should also be possible to place the shared parameters buffer at
|
||||
; 0x20000000. Testing shows though, that the first few bytes are still changed when
|
||||
; the user program performs a software reset. Therefore it was moved forward by 0x100.
|
||||
RW_IRAM1 0x20000100 UNINIT 0x00000040 { ; no init for shared params
|
||||
*(shared)
|
||||
}
|
||||
|
||||
|
||||
RW_IRAM2 0x20000140 0x0003FEC0 { ; RW data
|
||||
.ANY (+RW +ZI)
|
||||
}
|
||||
|
||||
RW_IRAM3 0x1FFE8000 0x00018000 {
|
||||
.ANY (+RW +ZI)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue