Fix #ifdefs in port.c to call xxx_reset() rroutines properly. Remove most uses of EXPRESS_BOARD.

This commit is contained in:
Dan Halbert 2019-02-18 22:44:31 -05:00
parent ef802c91e7
commit 9c24c804fb
13 changed files with 118 additions and 99 deletions

View File

@ -11,7 +11,7 @@
//! <2012/12/20> V1.1.0 //! <2012/12/20> V1.1.0
//! 1. Optimize code //! 1. Optimize code
//! 2. Add reg_dhcp_cbfunc() //! 2. Add reg_dhcp_cbfunc()
//! 3. Add DHCP_stop() //! 3. Add DHCP_stop()
//! 4. Integrate check_DHCP_state() & DHCP_run() to DHCP_run() //! 4. Integrate check_DHCP_state() & DHCP_run() to DHCP_run()
//! 5. Don't care system endian //! 5. Don't care system endian
//! 6. Add comments //! 6. Add comments
@ -22,30 +22,30 @@
//! //!
//! Copyright (c) 2013, WIZnet Co., LTD. //! Copyright (c) 2013, WIZnet Co., LTD.
//! All rights reserved. //! All rights reserved.
//! //!
//! Redistribution and use in source and binary forms, with or without //! Redistribution and use in source and binary forms, with or without
//! modification, are permitted provided that the following conditions //! modification, are permitted provided that the following conditions
//! are met: //! are met:
//! //!
//! * Redistributions of source code must retain the above copyright //! * Redistributions of source code must retain the above copyright
//! notice, this list of conditions and the following disclaimer. //! notice, this list of conditions and the following disclaimer.
//! * Redistributions in binary form must reproduce the above copyright //! * Redistributions in binary form must reproduce the above copyright
//! notice, this list of conditions and the following disclaimer in the //! notice, this list of conditions and the following disclaimer in the
//! documentation and/or other materials provided with the distribution. //! documentation and/or other materials provided with the distribution.
//! * Neither the name of the <ORGANIZATION> nor the names of its //! * Neither the name of the <ORGANIZATION> nor the names of its
//! contributors may be used to endorse or promote products derived //! contributors may be used to endorse or promote products derived
//! from this software without specific prior written permission. //! from this software without specific prior written permission.
//! //!
//! THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" //! THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
//! AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE //! AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
//! IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE //! IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
//! ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE //! ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
//! LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR //! LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
//! CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF //! CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
//! SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS //! SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
//! INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN //! INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
//! CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) //! CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
//! ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF //! ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
//! THE POSSIBILITY OF SUCH DAMAGE. //! THE POSSIBILITY OF SUCH DAMAGE.
// //
//***************************************************************************** //*****************************************************************************
@ -59,7 +59,7 @@
#ifdef _DHCP_DEBUG_ #ifdef _DHCP_DEBUG_
#include <stdio.h> #include <stdio.h>
#endif #endif
/* DHCP state machine. */ /* DHCP state machine. */
#define STATE_DHCP_INIT 0 ///< Initialize #define STATE_DHCP_INIT 0 ///< Initialize
@ -70,7 +70,7 @@
#define STATE_DHCP_RELEASE 5 ///< No use #define STATE_DHCP_RELEASE 5 ///< No use
#define STATE_DHCP_STOP 6 ///< Stop processing DHCP #define STATE_DHCP_STOP 6 ///< Stop processing DHCP
#define DHCP_FLAGSBROADCAST 0x8000 ///< The broadcast value of flags in @ref RIP_MSG #define DHCP_FLAGSBROADCAST 0x8000 ///< The broadcast value of flags in @ref RIP_MSG
#define DHCP_FLAGSUNICAST 0x0000 ///< The unicast value of flags in @ref RIP_MSG #define DHCP_FLAGSUNICAST 0x0000 ///< The unicast value of flags in @ref RIP_MSG
/* DHCP message OP code */ /* DHCP message OP code */
@ -99,7 +99,7 @@
#define OPT_SIZE 312 /// Max OPT size of @ref RIP_MSG #define OPT_SIZE 312 /// Max OPT size of @ref RIP_MSG
#define RIP_MSG_SIZE (236+OPT_SIZE) /// Max size of @ref RIP_MSG #define RIP_MSG_SIZE (236+OPT_SIZE) /// Max size of @ref RIP_MSG
/* /*
* @brief DHCP option and value (cf. RFC1533) * @brief DHCP option and value (cf. RFC1533)
*/ */
enum enum
@ -171,7 +171,7 @@ enum
/* /*
* @brief DHCP message format * @brief DHCP message format
*/ */
typedef struct { typedef struct {
uint8_t op; ///< @ref DHCP_BOOTREQUEST or @ref DHCP_BOOTREPLY uint8_t op; ///< @ref DHCP_BOOTREQUEST or @ref DHCP_BOOTREPLY
uint8_t htype; ///< @ref DHCP_HTYPE10MB or @ref DHCP_HTYPE100MB uint8_t htype; ///< @ref DHCP_HTYPE10MB or @ref DHCP_HTYPE100MB
@ -182,7 +182,7 @@ typedef struct {
uint16_t flags; ///< @ref DHCP_FLAGSBROADCAST or @ref DHCP_FLAGSUNICAST uint16_t flags; ///< @ref DHCP_FLAGSBROADCAST or @ref DHCP_FLAGSUNICAST
uint8_t ciaddr[4]; ///< @ref Request IP to DHCP sever uint8_t ciaddr[4]; ///< @ref Request IP to DHCP sever
uint8_t yiaddr[4]; ///< @ref Offered IP from DHCP server uint8_t yiaddr[4]; ///< @ref Offered IP from DHCP server
uint8_t siaddr[4]; ///< No use uint8_t siaddr[4]; ///< No use
uint8_t giaddr[4]; ///< No use uint8_t giaddr[4]; ///< No use
uint8_t chaddr[16]; ///< DHCP client 6bytes MAC address. Others is filled to zero uint8_t chaddr[16]; ///< DHCP client 6bytes MAC address. Others is filled to zero
uint8_t sname[64]; ///< No use uint8_t sname[64]; ///< No use
@ -205,7 +205,7 @@ uint8_t DHCP_allocated_dns[4] = {0, }; // DNS address from DHCP
int8_t dhcp_state = STATE_DHCP_INIT; // DHCP state int8_t dhcp_state = STATE_DHCP_INIT; // DHCP state
int8_t dhcp_retry_count = 0; int8_t dhcp_retry_count = 0;
uint32_t dhcp_lease_time = INFINITE_LEASETIME; uint32_t dhcp_lease_time = INFINITE_LEASETIME;
volatile uint32_t dhcp_tick_1s = 0; // unit 1 second volatile uint32_t dhcp_tick_1s = 0; // unit 1 second
@ -215,7 +215,7 @@ uint32_t DHCP_XID; // Any number
RIP_MSG* pDHCPMSG; // Buffer pointer for DHCP processing RIP_MSG* pDHCPMSG; // Buffer pointer for DHCP processing
uint8_t HOST_NAME[] = DCHP_HOST_NAME; uint8_t HOST_NAME[] = DCHP_HOST_NAME;
uint8_t DHCP_CHADDR[6]; // DHCP Client MAC address. uint8_t DHCP_CHADDR[6]; // DHCP Client MAC address.
@ -306,9 +306,9 @@ void makeDHCPMSG(void)
*(ptmp+0) = (uint8_t)((DHCP_XID & 0xFF000000) >> 24); *(ptmp+0) = (uint8_t)((DHCP_XID & 0xFF000000) >> 24);
*(ptmp+1) = (uint8_t)((DHCP_XID & 0x00FF0000) >> 16); *(ptmp+1) = (uint8_t)((DHCP_XID & 0x00FF0000) >> 16);
*(ptmp+2) = (uint8_t)((DHCP_XID & 0x0000FF00) >> 8); *(ptmp+2) = (uint8_t)((DHCP_XID & 0x0000FF00) >> 8);
*(ptmp+3) = (uint8_t)((DHCP_XID & 0x000000FF) >> 0); *(ptmp+3) = (uint8_t)((DHCP_XID & 0x000000FF) >> 0);
pDHCPMSG->secs = DHCP_SECS; pDHCPMSG->secs = DHCP_SECS;
ptmp = (uint8_t*)(&pDHCPMSG->flags); ptmp = (uint8_t*)(&pDHCPMSG->flags);
*(ptmp+0) = (uint8_t)((DHCP_FLAGSBROADCAST & 0xFF00) >> 8); *(ptmp+0) = (uint8_t)((DHCP_FLAGSBROADCAST & 0xFF00) >> 8);
*(ptmp+1) = (uint8_t)((DHCP_FLAGSBROADCAST & 0x00FF) >> 0); *(ptmp+1) = (uint8_t)((DHCP_FLAGSBROADCAST & 0x00FF) >> 0);
@ -356,16 +356,16 @@ void send_DHCP_DISCOVER(void)
uint16_t i; uint16_t i;
uint8_t ip[4]; uint8_t ip[4];
uint16_t k = 0; uint16_t k = 0;
makeDHCPMSG(); makeDHCPMSG();
k = 4; // because MAGIC_COOKIE already made by makeDHCPMSG() k = 4; // because MAGIC_COOKIE already made by makeDHCPMSG()
// Option Request Param // Option Request Param
pDHCPMSG->OPT[k++] = dhcpMessageType; pDHCPMSG->OPT[k++] = dhcpMessageType;
pDHCPMSG->OPT[k++] = 0x01; pDHCPMSG->OPT[k++] = 0x01;
pDHCPMSG->OPT[k++] = DHCP_DISCOVER; pDHCPMSG->OPT[k++] = DHCP_DISCOVER;
// Client identifier // Client identifier
pDHCPMSG->OPT[k++] = dhcpClientIdentifier; pDHCPMSG->OPT[k++] = dhcpClientIdentifier;
pDHCPMSG->OPT[k++] = 0x07; pDHCPMSG->OPT[k++] = 0x07;
@ -376,10 +376,10 @@ void send_DHCP_DISCOVER(void)
pDHCPMSG->OPT[k++] = DHCP_CHADDR[3]; pDHCPMSG->OPT[k++] = DHCP_CHADDR[3];
pDHCPMSG->OPT[k++] = DHCP_CHADDR[4]; pDHCPMSG->OPT[k++] = DHCP_CHADDR[4];
pDHCPMSG->OPT[k++] = DHCP_CHADDR[5]; pDHCPMSG->OPT[k++] = DHCP_CHADDR[5];
// host name // host name
pDHCPMSG->OPT[k++] = hostName; pDHCPMSG->OPT[k++] = hostName;
pDHCPMSG->OPT[k++] = 0; // fill zero length of hostname pDHCPMSG->OPT[k++] = 0; // fill zero length of hostname
for(i = 0 ; HOST_NAME[i] != 0; i++) for(i = 0 ; HOST_NAME[i] != 0; i++)
pDHCPMSG->OPT[k++] = HOST_NAME[i]; pDHCPMSG->OPT[k++] = HOST_NAME[i];
pDHCPMSG->OPT[k++] = DHCP_CHADDR[3]; pDHCPMSG->OPT[k++] = DHCP_CHADDR[3];
@ -432,18 +432,18 @@ void send_DHCP_REQUEST(void)
ip[0] = DHCP_SIP[0]; ip[0] = DHCP_SIP[0];
ip[1] = DHCP_SIP[1]; ip[1] = DHCP_SIP[1];
ip[2] = DHCP_SIP[2]; ip[2] = DHCP_SIP[2];
ip[3] = DHCP_SIP[3]; ip[3] = DHCP_SIP[3];
} }
else else
{ {
ip[0] = 255; ip[0] = 255;
ip[1] = 255; ip[1] = 255;
ip[2] = 255; ip[2] = 255;
ip[3] = 255; ip[3] = 255;
} }
k = 4; // because MAGIC_COOKIE already made by makeDHCPMSG() k = 4; // because MAGIC_COOKIE already made by makeDHCPMSG()
// Option Request Param. // Option Request Param.
pDHCPMSG->OPT[k++] = dhcpMessageType; pDHCPMSG->OPT[k++] = dhcpMessageType;
pDHCPMSG->OPT[k++] = 0x01; pDHCPMSG->OPT[k++] = 0x01;
@ -467,7 +467,7 @@ void send_DHCP_REQUEST(void)
pDHCPMSG->OPT[k++] = DHCP_allocated_ip[1]; pDHCPMSG->OPT[k++] = DHCP_allocated_ip[1];
pDHCPMSG->OPT[k++] = DHCP_allocated_ip[2]; pDHCPMSG->OPT[k++] = DHCP_allocated_ip[2];
pDHCPMSG->OPT[k++] = DHCP_allocated_ip[3]; pDHCPMSG->OPT[k++] = DHCP_allocated_ip[3];
pDHCPMSG->OPT[k++] = dhcpServerIdentifier; pDHCPMSG->OPT[k++] = dhcpServerIdentifier;
pDHCPMSG->OPT[k++] = 0x04; pDHCPMSG->OPT[k++] = 0x04;
pDHCPMSG->OPT[k++] = DHCP_SIP[0]; pDHCPMSG->OPT[k++] = DHCP_SIP[0];
@ -485,7 +485,7 @@ void send_DHCP_REQUEST(void)
pDHCPMSG->OPT[k++] = DHCP_CHADDR[4]; pDHCPMSG->OPT[k++] = DHCP_CHADDR[4];
pDHCPMSG->OPT[k++] = DHCP_CHADDR[5]; pDHCPMSG->OPT[k++] = DHCP_CHADDR[5];
pDHCPMSG->OPT[k - (i+3+1)] = i+3; // length of hostname pDHCPMSG->OPT[k - (i+3+1)] = i+3; // length of hostname
pDHCPMSG->OPT[k++] = dhcpParamRequest; pDHCPMSG->OPT[k++] = dhcpParamRequest;
pDHCPMSG->OPT[k++] = 0x08; pDHCPMSG->OPT[k++] = 0x08;
pDHCPMSG->OPT[k++] = subnetMask; pDHCPMSG->OPT[k++] = subnetMask;
@ -503,7 +503,7 @@ void send_DHCP_REQUEST(void)
#ifdef _DHCP_DEBUG_ #ifdef _DHCP_DEBUG_
printf("> Send DHCP_REQUEST\r\n"); printf("> Send DHCP_REQUEST\r\n");
#endif #endif
WIZCHIP_EXPORT(sendto)(DHCP_SOCKET, (uint8_t *)pDHCPMSG, RIP_MSG_SIZE, ip, DHCP_SERVER_PORT); WIZCHIP_EXPORT(sendto)(DHCP_SOCKET, (uint8_t *)pDHCPMSG, RIP_MSG_SIZE, ip, DHCP_SERVER_PORT);
} }
@ -514,11 +514,11 @@ void send_DHCP_DECLINE(void)
int i; int i;
uint8_t ip[4]; uint8_t ip[4];
uint16_t k = 0; uint16_t k = 0;
makeDHCPMSG(); makeDHCPMSG();
k = 4; // because MAGIC_COOKIE already made by makeDHCPMSG() k = 4; // because MAGIC_COOKIE already made by makeDHCPMSG()
*((uint8_t*)(&pDHCPMSG->flags)) = ((DHCP_FLAGSUNICAST & 0xFF00)>> 8); *((uint8_t*)(&pDHCPMSG->flags)) = ((DHCP_FLAGSUNICAST & 0xFF00)>> 8);
*((uint8_t*)(&pDHCPMSG->flags)+1) = (DHCP_FLAGSUNICAST & 0x00FF); *((uint8_t*)(&pDHCPMSG->flags)+1) = (DHCP_FLAGSUNICAST & 0x00FF);
@ -577,15 +577,15 @@ int8_t parseDHCPMSG(void)
uint8_t * p; uint8_t * p;
uint8_t * e; uint8_t * e;
uint8_t type; uint8_t type = 0;
uint8_t opt_len; uint8_t opt_len;
if((len = getSn_RX_RSR(DHCP_SOCKET)) > 0) if((len = getSn_RX_RSR(DHCP_SOCKET)) > 0)
{ {
len = WIZCHIP_EXPORT(recvfrom)(DHCP_SOCKET, (uint8_t *)pDHCPMSG, len, svr_addr, &svr_port); len = WIZCHIP_EXPORT(recvfrom)(DHCP_SOCKET, (uint8_t *)pDHCPMSG, len, svr_addr, &svr_port);
#ifdef _DHCP_DEBUG_ #ifdef _DHCP_DEBUG_
printf("DHCP message : %d.%d.%d.%d(%d) %d received. \r\n",svr_addr[0],svr_addr[1],svr_addr[2], svr_addr[3],svr_port, len); printf("DHCP message : %d.%d.%d.%d(%d) %d received. \r\n",svr_addr[0],svr_addr[1],svr_addr[2], svr_addr[3],svr_port, len);
#endif #endif
} }
else return 0; else return 0;
if (svr_port == DHCP_SERVER_PORT) { if (svr_port == DHCP_SERVER_PORT) {
@ -624,7 +624,7 @@ int8_t parseDHCPMSG(void)
break; break;
case routersOnSubnet : case routersOnSubnet :
p++; p++;
opt_len = *p++; opt_len = *p++;
DHCP_allocated_gw[0] = *p++; DHCP_allocated_gw[0] = *p++;
DHCP_allocated_gw[1] = *p++; DHCP_allocated_gw[1] = *p++;
DHCP_allocated_gw[2] = *p++; DHCP_allocated_gw[2] = *p++;
@ -632,8 +632,8 @@ int8_t parseDHCPMSG(void)
p = p + (opt_len - 4); p = p + (opt_len - 4);
break; break;
case dns : case dns :
p++; p++;
opt_len = *p++; opt_len = *p++;
DHCP_allocated_dns[0] = *p++; DHCP_allocated_dns[0] = *p++;
DHCP_allocated_dns[1] = *p++; DHCP_allocated_dns[1] = *p++;
DHCP_allocated_dns[2] = *p++; DHCP_allocated_dns[2] = *p++;
@ -647,7 +647,7 @@ int8_t parseDHCPMSG(void)
dhcp_lease_time = (dhcp_lease_time << 8) + *p++; dhcp_lease_time = (dhcp_lease_time << 8) + *p++;
dhcp_lease_time = (dhcp_lease_time << 8) + *p++; dhcp_lease_time = (dhcp_lease_time << 8) + *p++;
dhcp_lease_time = (dhcp_lease_time << 8) + *p++; dhcp_lease_time = (dhcp_lease_time << 8) + *p++;
#ifdef _DHCP_DEBUG_ #ifdef _DHCP_DEBUG_
dhcp_lease_time = 10; dhcp_lease_time = 10;
#endif #endif
break; break;
@ -740,7 +740,7 @@ uint8_t DHCP_run(void)
case STATE_DHCP_LEASED : case STATE_DHCP_LEASED :
ret = DHCP_IP_LEASED; ret = DHCP_IP_LEASED;
if ((dhcp_lease_time != INFINITE_LEASETIME) && ((dhcp_lease_time/2) < dhcp_tick_1s)) { if ((dhcp_lease_time != INFINITE_LEASETIME) && ((dhcp_lease_time/2) < dhcp_tick_1s)) {
#ifdef _DHCP_DEBUG_ #ifdef _DHCP_DEBUG_
printf("> Maintains the IP address \r\n"); printf("> Maintains the IP address \r\n");
#endif #endif
@ -750,7 +750,7 @@ uint8_t DHCP_run(void)
OLD_allocated_ip[1] = DHCP_allocated_ip[1]; OLD_allocated_ip[1] = DHCP_allocated_ip[1];
OLD_allocated_ip[2] = DHCP_allocated_ip[2]; OLD_allocated_ip[2] = DHCP_allocated_ip[2];
OLD_allocated_ip[3] = DHCP_allocated_ip[3]; OLD_allocated_ip[3] = DHCP_allocated_ip[3];
DHCP_XID++; DHCP_XID++;
send_DHCP_REQUEST(); send_DHCP_REQUEST();
@ -765,21 +765,21 @@ uint8_t DHCP_run(void)
ret = DHCP_IP_LEASED; ret = DHCP_IP_LEASED;
if (type == DHCP_ACK) { if (type == DHCP_ACK) {
dhcp_retry_count = 0; dhcp_retry_count = 0;
if (OLD_allocated_ip[0] != DHCP_allocated_ip[0] || if (OLD_allocated_ip[0] != DHCP_allocated_ip[0] ||
OLD_allocated_ip[1] != DHCP_allocated_ip[1] || OLD_allocated_ip[1] != DHCP_allocated_ip[1] ||
OLD_allocated_ip[2] != DHCP_allocated_ip[2] || OLD_allocated_ip[2] != DHCP_allocated_ip[2] ||
OLD_allocated_ip[3] != DHCP_allocated_ip[3]) OLD_allocated_ip[3] != DHCP_allocated_ip[3])
{ {
ret = DHCP_IP_CHANGED; ret = DHCP_IP_CHANGED;
dhcp_ip_update(); dhcp_ip_update();
#ifdef _DHCP_DEBUG_ #ifdef _DHCP_DEBUG_
printf(">IP changed.\r\n"); printf(">IP changed.\r\n");
#endif #endif
} }
#ifdef _DHCP_DEBUG_ #ifdef _DHCP_DEBUG_
else printf(">IP is continued.\r\n"); else printf(">IP is continued.\r\n");
#endif #endif
reset_DHCP_timeout(); reset_DHCP_timeout();
dhcp_state = STATE_DHCP_LEASED; dhcp_state = STATE_DHCP_LEASED;
} else if (type == DHCP_NAK) { } else if (type == DHCP_NAK) {
@ -809,7 +809,7 @@ void DHCP_stop(void)
uint8_t check_DHCP_timeout(void) uint8_t check_DHCP_timeout(void)
{ {
uint8_t ret = DHCP_RUNNING; uint8_t ret = DHCP_RUNNING;
if (dhcp_retry_count < MAX_DHCP_RETRY) { if (dhcp_retry_count < MAX_DHCP_RETRY) {
if (dhcp_tick_next < dhcp_tick_1s) { if (dhcp_tick_next < dhcp_tick_1s) {
@ -818,7 +818,7 @@ uint8_t check_DHCP_timeout(void)
// printf("<<timeout>> state : STATE_DHCP_DISCOVER\r\n"); // printf("<<timeout>> state : STATE_DHCP_DISCOVER\r\n");
send_DHCP_DISCOVER(); send_DHCP_DISCOVER();
break; break;
case STATE_DHCP_REQUEST : case STATE_DHCP_REQUEST :
// printf("<<timeout>> state : STATE_DHCP_REQUEST\r\n"); // printf("<<timeout>> state : STATE_DHCP_REQUEST\r\n");
@ -827,10 +827,10 @@ uint8_t check_DHCP_timeout(void)
case STATE_DHCP_REREQUEST : case STATE_DHCP_REREQUEST :
// printf("<<timeout>> state : STATE_DHCP_REREQUEST\r\n"); // printf("<<timeout>> state : STATE_DHCP_REREQUEST\r\n");
send_DHCP_REQUEST(); send_DHCP_REQUEST();
break; break;
default : default :
break; break;
} }
@ -892,7 +892,7 @@ int8_t check_DHCP_leasedIP(void)
return 0; return 0;
} }
} }
void DHCP_init(uint8_t s, DHCP_INIT_BUFFER_TYPE* buf) void DHCP_init(uint8_t s, DHCP_INIT_BUFFER_TYPE* buf)
{ {
@ -903,11 +903,11 @@ void DHCP_init(uint8_t s, DHCP_INIT_BUFFER_TYPE* buf)
// assign temporary mac address, you should be set SHAR before call this function. // assign temporary mac address, you should be set SHAR before call this function.
DHCP_CHADDR[0] = 0x00; DHCP_CHADDR[0] = 0x00;
DHCP_CHADDR[1] = 0x08; DHCP_CHADDR[1] = 0x08;
DHCP_CHADDR[2] = 0xdc; DHCP_CHADDR[2] = 0xdc;
DHCP_CHADDR[3] = 0x00; DHCP_CHADDR[3] = 0x00;
DHCP_CHADDR[4] = 0x00; DHCP_CHADDR[4] = 0x00;
DHCP_CHADDR[5] = 0x00; DHCP_CHADDR[5] = 0x00;
setSHAR(DHCP_CHADDR); setSHAR(DHCP_CHADDR);
} }
DHCP_SOCKET = s; // SOCK_DHCP DHCP_SOCKET = s; // SOCK_DHCP
@ -941,7 +941,7 @@ void getIPfromDHCP(uint8_t* ip)
{ {
ip[0] = DHCP_allocated_ip[0]; ip[0] = DHCP_allocated_ip[0];
ip[1] = DHCP_allocated_ip[1]; ip[1] = DHCP_allocated_ip[1];
ip[2] = DHCP_allocated_ip[2]; ip[2] = DHCP_allocated_ip[2];
ip[3] = DHCP_allocated_ip[3]; ip[3] = DHCP_allocated_ip[3];
} }
@ -950,7 +950,7 @@ void getGWfromDHCP(uint8_t* ip)
ip[0] =DHCP_allocated_gw[0]; ip[0] =DHCP_allocated_gw[0];
ip[1] =DHCP_allocated_gw[1]; ip[1] =DHCP_allocated_gw[1];
ip[2] =DHCP_allocated_gw[2]; ip[2] =DHCP_allocated_gw[2];
ip[3] =DHCP_allocated_gw[3]; ip[3] =DHCP_allocated_gw[3];
} }
void getSNfromDHCP(uint8_t* ip) void getSNfromDHCP(uint8_t* ip)
@ -958,7 +958,7 @@ void getSNfromDHCP(uint8_t* ip)
ip[0] = DHCP_allocated_sn[0]; ip[0] = DHCP_allocated_sn[0];
ip[1] = DHCP_allocated_sn[1]; ip[1] = DHCP_allocated_sn[1];
ip[2] = DHCP_allocated_sn[2]; ip[2] = DHCP_allocated_sn[2];
ip[3] = DHCP_allocated_sn[3]; ip[3] = DHCP_allocated_sn[3];
} }
void getDNSfromDHCP(uint8_t* ip) void getDNSfromDHCP(uint8_t* ip)
@ -966,14 +966,10 @@ void getDNSfromDHCP(uint8_t* ip)
ip[0] = DHCP_allocated_dns[0]; ip[0] = DHCP_allocated_dns[0];
ip[1] = DHCP_allocated_dns[1]; ip[1] = DHCP_allocated_dns[1];
ip[2] = DHCP_allocated_dns[2]; ip[2] = DHCP_allocated_dns[2];
ip[3] = DHCP_allocated_dns[3]; ip[3] = DHCP_allocated_dns[3];
} }
uint32_t getDHCPLeasetime(void) uint32_t getDHCPLeasetime(void)
{ {
return dhcp_lease_time; return dhcp_lease_time;
} }

View File

@ -102,9 +102,9 @@ ifeq ($(DEBUG), 1)
# Turn on Python modules useful for debugging (e.g. uheap, ustack). # Turn on Python modules useful for debugging (e.g. uheap, ustack).
CFLAGS += -ggdb CFLAGS += -ggdb
# You may want to disable -flto if it interferes with debugging. # You may want to disable -flto if it interferes with debugging.
# CFLAGS += -flto CFLAGS += -flto
# You may want to enable these flags to make setting breakpoints easier. # You may want to enable these flags to make setting breakpoints easier.
CFLAGS += -fno-inline -fno-ipa-sra # CFLAGS += -fno-inline -fno-ipa-sra
ifeq ($(CHIP_FAMILY), samd21) ifeq ($(CHIP_FAMILY), samd21)
CFLAGS += -DENABLE_MICRO_TRACE_BUFFER CFLAGS += -DENABLE_MICRO_TRACE_BUFFER
endif endif
@ -112,7 +112,7 @@ else
# -finline-limit can shrink the image size. # -finline-limit can shrink the image size.
# -finline-limit=80 or so is similar to not having it on. # -finline-limit=80 or so is similar to not having it on.
# There is no simple default value, though. # There is no simple default value, though.
ifdef INTERNAL_FLASH_FILESYSTEM ifeq ($(INTERNAL_FLASH_FILESYSTEM),1)
CFLAGS += -finline-limit=50 CFLAGS += -finline-limit=50
endif endif
ifdef CFLAGS_INLINE_LIMIT ifdef CFLAGS_INLINE_LIMIT

View File

@ -4,7 +4,6 @@ USB_PID = 0xEDBE
USB_PRODUCT = "SAM32" USB_PRODUCT = "SAM32"
USB_MANUFACTURER = "maholli" USB_MANUFACTURER = "maholli"
QSPI_FLASH_FILESYSTEM = 0
INTERNAL_FLASH_FILESYSTEM = 1 INTERNAL_FLASH_FILESYSTEM = 1
LONGINT_IMPL = MPZ LONGINT_IMPL = MPZ

View File

@ -31,6 +31,7 @@
#include "py/runtime.h" #include "py/runtime.h"
#include "shared-bindings/analogio/AnalogOut.h" #include "shared-bindings/analogio/AnalogOut.h"
#include "shared-bindings/audioio/AudioOut.h"
#include "shared-bindings/microcontroller/Pin.h" #include "shared-bindings/microcontroller/Pin.h"
#include "supervisor/shared/translate.h" #include "supervisor/shared/translate.h"
@ -138,5 +139,17 @@ void common_hal_analogio_analogout_set_value(analogio_analogout_obj_t *self,
} }
void analogout_reset(void) { void analogout_reset(void) {
// AudioOut resets the DAC in case its been used for audio which requires special handling. // audioout_reset also resets the DAC, and does a smooth ramp down to avoid clicks
// if it was enabled, so do that instead if AudioOut is enabled.
#if CIRCUITPY_AUDIOIO
audioout_reset();
#else
#ifdef SAMD21
while (DAC->STATUS.reg & DAC_STATUS_SYNCBUSY) {}
#endif
#ifdef SAMD51
while (DAC->SYNCBUSY.reg & DAC_SYNCBUSY_SWRST) {}
#endif
DAC->CTRLA.reg |= DAC_CTRLA_SWRST;
#endif
} }

View File

@ -194,20 +194,23 @@ safe_mode_t port_init(void) {
void reset_port(void) { void reset_port(void) {
reset_sercoms(); reset_sercoms();
#if defined(EXPRESS_BOARD) && !defined(__SAMR21G18A__) #if CIRCUITPY_AUDIOIO
audio_dma_reset(); audio_dma_reset();
audioout_reset(); audioout_reset();
#if !defined(__SAMD51G19A__) && !defined(__SAMD51G18A__) #endif
#if CIRCUITPY_AUDIOBUSIO
i2sout_reset(); i2sout_reset();
#endif
//pdmin_reset(); //pdmin_reset();
#endif #endif
#ifdef SAMD21
#if CIRCUITPY_TOUCHIO
touchin_reset(); touchin_reset();
#endif #endif
eic_reset(); eic_reset();
#if CIRCUITPY_PULSEIO
pulseout_reset(); pulseout_reset();
pwmout_reset(); pwmout_reset();
#endif
#if CIRCUITPY_ANALOGIO #if CIRCUITPY_ANALOGIO
analogin_reset(); analogin_reset();

View File

@ -37,7 +37,7 @@
#define MICROPY_HW_LED_STATUS (&pin_P1_15) #define MICROPY_HW_LED_STATUS (&pin_P1_15)
#ifdef QSPI_FLASH_FILESYSTEM #if QSPI_FLASH_FILESYSTEM
#define MICROPY_QSPI_DATA0 NRF_GPIO_PIN_MAP(0, 17) #define MICROPY_QSPI_DATA0 NRF_GPIO_PIN_MAP(0, 17)
#define MICROPY_QSPI_DATA1 NRF_GPIO_PIN_MAP(0, 22) #define MICROPY_QSPI_DATA1 NRF_GPIO_PIN_MAP(0, 22)
#define MICROPY_QSPI_DATA2 NRF_GPIO_PIN_MAP(0, 23) #define MICROPY_QSPI_DATA2 NRF_GPIO_PIN_MAP(0, 23)
@ -46,7 +46,7 @@
#define MICROPY_QSPI_CS NRF_GPIO_PIN_MAP(0, 20) #define MICROPY_QSPI_CS NRF_GPIO_PIN_MAP(0, 20)
#endif #endif
#ifdef SPI_FLASH_FILESYSTEM #if SPI_FLASH_FILESYSTEM
#define SPI_FLASH_MOSI_PIN &pin_P0_17 #define SPI_FLASH_MOSI_PIN &pin_P0_17
#define SPI_FLASH_MISO_PIN &pin_P0_22 #define SPI_FLASH_MISO_PIN &pin_P0_22
#define SPI_FLASH_SCK_PIN &pin_P0_19 #define SPI_FLASH_SCK_PIN &pin_P0_19

View File

@ -39,7 +39,7 @@
#define MICROPY_HW_RGB_LED_GREEN (&pin_P0_14) #define MICROPY_HW_RGB_LED_GREEN (&pin_P0_14)
#define MICROPY_HW_RGB_LED_BLUE (&pin_P0_15) #define MICROPY_HW_RGB_LED_BLUE (&pin_P0_15)
#ifdef QSPI_FLASH_FILESYSTEM #if QSPI_FLASH_FILESYSTEM
#define MICROPY_QSPI_DATA0 NRF_GPIO_PIN_MAP(0, 20) #define MICROPY_QSPI_DATA0 NRF_GPIO_PIN_MAP(0, 20)
#define MICROPY_QSPI_DATA1 NRF_GPIO_PIN_MAP(0, 21) #define MICROPY_QSPI_DATA1 NRF_GPIO_PIN_MAP(0, 21)
#define MICROPY_QSPI_DATA2 NRF_GPIO_PIN_MAP(0, 22) #define MICROPY_QSPI_DATA2 NRF_GPIO_PIN_MAP(0, 22)
@ -48,7 +48,7 @@
#define MICROPY_QSPI_CS NRF_GPIO_PIN_MAP(0, 17) #define MICROPY_QSPI_CS NRF_GPIO_PIN_MAP(0, 17)
#endif #endif
#ifdef SPI_FLASH_FILESYSTEM #if SPI_FLASH_FILESYSTEM
#define SPI_FLASH_MOSI_PIN &pin_P0_20 #define SPI_FLASH_MOSI_PIN &pin_P0_20
#define SPI_FLASH_MISO_PIN &pin_P0_21 #define SPI_FLASH_MISO_PIN &pin_P0_21
#define SPI_FLASH_SCK_PIN &pin_P0_19 #define SPI_FLASH_SCK_PIN &pin_P0_19

View File

@ -39,7 +39,7 @@
#define MICROPY_HW_RGB_LED_GREEN (&pin_P0_14) #define MICROPY_HW_RGB_LED_GREEN (&pin_P0_14)
#define MICROPY_HW_RGB_LED_BLUE (&pin_P0_15) #define MICROPY_HW_RGB_LED_BLUE (&pin_P0_15)
#ifdef QSPI_FLASH_FILESYSTEM #if QSPI_FLASH_FILESYSTEM
#define MICROPY_QSPI_DATA0 NRF_GPIO_PIN_MAP(0, 20) #define MICROPY_QSPI_DATA0 NRF_GPIO_PIN_MAP(0, 20)
#define MICROPY_QSPI_DATA1 NRF_GPIO_PIN_MAP(0, 21) #define MICROPY_QSPI_DATA1 NRF_GPIO_PIN_MAP(0, 21)
#define MICROPY_QSPI_DATA2 NRF_GPIO_PIN_MAP(0, 22) #define MICROPY_QSPI_DATA2 NRF_GPIO_PIN_MAP(0, 22)
@ -48,7 +48,7 @@
#define MICROPY_QSPI_CS NRF_GPIO_PIN_MAP(0, 17) #define MICROPY_QSPI_CS NRF_GPIO_PIN_MAP(0, 17)
#endif #endif
#ifdef SPI_FLASH_FILESYSTEM #if SPI_FLASH_FILESYSTEM
#define SPI_FLASH_MOSI_PIN &pin_P0_20 #define SPI_FLASH_MOSI_PIN &pin_P0_20
#define SPI_FLASH_MISO_PIN &pin_P0_21 #define SPI_FLASH_MISO_PIN &pin_P0_21
#define SPI_FLASH_SCK_PIN &pin_P0_19 #define SPI_FLASH_SCK_PIN &pin_P0_19

View File

@ -39,7 +39,7 @@
#define MICROPY_HW_RGB_LED_GREEN (&pin_P0_14) #define MICROPY_HW_RGB_LED_GREEN (&pin_P0_14)
#define MICROPY_HW_RGB_LED_BLUE (&pin_P0_15) #define MICROPY_HW_RGB_LED_BLUE (&pin_P0_15)
#ifdef QSPI_FLASH_FILESYSTEM #if QSPI_FLASH_FILESYSTEM
#define MICROPY_QSPI_DATA0 NRF_GPIO_PIN_MAP(0, 20) #define MICROPY_QSPI_DATA0 NRF_GPIO_PIN_MAP(0, 20)
#define MICROPY_QSPI_DATA1 NRF_GPIO_PIN_MAP(0, 21) #define MICROPY_QSPI_DATA1 NRF_GPIO_PIN_MAP(0, 21)
#define MICROPY_QSPI_DATA2 NRF_GPIO_PIN_MAP(0, 22) #define MICROPY_QSPI_DATA2 NRF_GPIO_PIN_MAP(0, 22)
@ -48,7 +48,7 @@
#define MICROPY_QSPI_CS NRF_GPIO_PIN_MAP(0, 17) #define MICROPY_QSPI_CS NRF_GPIO_PIN_MAP(0, 17)
#endif #endif
#ifdef SPI_FLASH_FILESYSTEM #if SPI_FLASH_FILESYSTEM
#define SPI_FLASH_MOSI_PIN &pin_P0_20 #define SPI_FLASH_MOSI_PIN &pin_P0_20
#define SPI_FLASH_MISO_PIN &pin_P0_21 #define SPI_FLASH_MISO_PIN &pin_P0_21
#define SPI_FLASH_SCK_PIN &pin_P0_19 #define SPI_FLASH_SCK_PIN &pin_P0_19

View File

@ -49,7 +49,7 @@
// Quad mode: If all DATA0 --> DATA3 are valid // Quad mode: If all DATA0 --> DATA3 are valid
// Dual mode: If DATA0 and DATA1 are valid while either DATA2 and/or DATA3 are invalid // Dual mode: If DATA0 and DATA1 are valid while either DATA2 and/or DATA3 are invalid
// Single mode: If only DATA0 is valid // Single mode: If only DATA0 is valid
#ifdef QSPI_FLASH_FILESYSTEM #if QSPI_FLASH_FILESYSTEM
#define MICROPY_QSPI_DATA0 NRF_GPIO_PIN_MAP(0, 20) #define MICROPY_QSPI_DATA0 NRF_GPIO_PIN_MAP(0, 20)
#define MICROPY_QSPI_DATA1 NRF_GPIO_PIN_MAP(0, 21) #define MICROPY_QSPI_DATA1 NRF_GPIO_PIN_MAP(0, 21)
#define MICROPY_QSPI_DATA2 NRF_GPIO_PIN_MAP(0, 22) #define MICROPY_QSPI_DATA2 NRF_GPIO_PIN_MAP(0, 22)
@ -58,7 +58,7 @@
#define MICROPY_QSPI_CS NRF_GPIO_PIN_MAP(0, 17) #define MICROPY_QSPI_CS NRF_GPIO_PIN_MAP(0, 17)
#endif #endif
#ifdef SPI_FLASH_FILESYSTEM #if SPI_FLASH_FILESYSTEM
#define SPI_FLASH_MOSI_PIN &pin_P0_20 #define SPI_FLASH_MOSI_PIN &pin_P0_20
#define SPI_FLASH_MISO_PIN &pin_P0_21 #define SPI_FLASH_MISO_PIN &pin_P0_21
#define SPI_FLASH_SCK_PIN &pin_P0_19 #define SPI_FLASH_SCK_PIN &pin_P0_19

View File

@ -49,7 +49,7 @@
// Quad mode: If all DATA0 --> DATA3 are valid // Quad mode: If all DATA0 --> DATA3 are valid
// Dual mode: If DATA0 and DATA1 are valid while either DATA2 and/or DATA3 are invalid // Dual mode: If DATA0 and DATA1 are valid while either DATA2 and/or DATA3 are invalid
// Single mode: If only DATA0 is valid // Single mode: If only DATA0 is valid
/*#ifdef QSPI_FLASH_FILESYSTEM /*#if QSPI_FLASH_FILESYSTEM
#define MICROPY_QSPI_DATA0 NRF_GPIO_PIN_MAP(0, 20) #define MICROPY_QSPI_DATA0 NRF_GPIO_PIN_MAP(0, 20)
#define MICROPY_QSPI_DATA1 NRF_GPIO_PIN_MAP(0, 21) #define MICROPY_QSPI_DATA1 NRF_GPIO_PIN_MAP(0, 21)
#define MICROPY_QSPI_DATA2 NRF_GPIO_PIN_MAP(0, 22) #define MICROPY_QSPI_DATA2 NRF_GPIO_PIN_MAP(0, 22)
@ -58,7 +58,7 @@
#define MICROPY_QSPI_CS NRF_GPIO_PIN_MAP(0, 17) #define MICROPY_QSPI_CS NRF_GPIO_PIN_MAP(0, 17)
#endif #endif
#ifdef SPI_FLASH_FILESYSTEM #if SPI_FLASH_FILESYSTEM
#define SPI_FLASH_MOSI_PIN &pin_P0_20 #define SPI_FLASH_MOSI_PIN &pin_P0_20
#define SPI_FLASH_MISO_PIN &pin_P0_21 #define SPI_FLASH_MISO_PIN &pin_P0_21
#define SPI_FLASH_SCK_PIN &pin_P0_19 #define SPI_FLASH_SCK_PIN &pin_P0_19

View File

@ -21,6 +21,4 @@ endif
NRF_DEFINES += -DNRF52840_XXAA -DNRF52840 NRF_DEFINES += -DNRF52840_XXAA -DNRF52840
QSPI_FLASH_FILESYSTEM = 0 INTERNAL_FLASH_FILESYSTEM = 1
EXTERNAL_FLASH_DEVICE_COUNT = 0
EXTERNAL_FLASH_DEVICES =

View File

@ -17,6 +17,17 @@ ifndef $(NO_USB)
NO_USB = $(wildcard supervisor/usb.c) NO_USB = $(wildcard supervisor/usb.c)
endif endif
ifneq ($(INTERNAL_FLASH_FILESYSTEM),)
CFLAGS += -DINTERNAL_FLASH_FILESYSTEM=$(INTERNAL_FLASH_FILESYSTEM)
endif
ifneq ($(QSPI_FLASH_FILESYSTEM),)
# EXPRESS_BOARD is obsolete and should be removed when samd-peripherals is updated.
CFLAGS += -DQSPI_FLASH_FILESYSTEM=$(QSPI_FLASH_FILESYSTEM) -DEXPRESS_BOARD
endif
ifneq ($(SPI_FLASH_FILESYSTEM),)
# EXPRESS_BOARD is obsolete and should be removed when samd-peripherals is updated.
CFLAGS += -DSPI_FLASH_FILESYSTEM=$(SPI_FLASH_FILESYSTEM) -DEXPRESS_BOARD
endif
# Choose which flash filesystem impl to use. # Choose which flash filesystem impl to use.
# (Right now INTERNAL_FLASH_FILESYSTEM and SPI_FLASH_FILESYSTEM are mutually exclusive. # (Right now INTERNAL_FLASH_FILESYSTEM and SPI_FLASH_FILESYSTEM are mutually exclusive.
@ -27,11 +38,10 @@ ifdef EXTERNAL_FLASH_DEVICES
SRC_SUPERVISOR += supervisor/shared/external_flash/external_flash.c SRC_SUPERVISOR += supervisor/shared/external_flash/external_flash.c
ifeq ($(SPI_FLASH_FILESYSTEM),1) ifeq ($(SPI_FLASH_FILESYSTEM),1)
CFLAGS += -DSPI_FLASH_FILESYSTEM
SRC_SUPERVISOR += supervisor/shared/external_flash/spi_flash.c SRC_SUPERVISOR += supervisor/shared/external_flash/spi_flash.c
else
endif endif
ifeq ($(QSPI_FLASH_FILESYSTEM),1) ifeq ($(QSPI_FLASH_FILESYSTEM),1)
CFLAGS += -DQSPI_FLASH_FILESYSTEM
SRC_SUPERVISOR += supervisor/qspi_flash.c supervisor/shared/external_flash/qspi_flash.c SRC_SUPERVISOR += supervisor/qspi_flash.c supervisor/shared/external_flash/qspi_flash.c
endif endif
else else