bring bleio PR up to date

This commit is contained in:
Dan Halbert 2018-11-07 14:12:22 -05:00
commit 64d457dad9
78 changed files with 11917 additions and 461 deletions

2
.gitmodules vendored
View File

@ -75,7 +75,7 @@
url = https://github.com/adafruit/Adafruit_CircuitPython_Crickit
[submodule "ports/nrf/nrfx"]
path = ports/nrf/nrfx
url = https://github.com/NordicSemiconductor/nrfx.git
url = https://github.com/adafruit/nrfx.git
[submodule "lib/tinyusb"]
path = lib/tinyusb
url = https://github.com/hathach/tinyusb.git

View File

@ -21,10 +21,10 @@ git:
# that SDK is shortest and add it there. In the case of major re-organizations,
# just try to make the builds "about equal in run time"
env:
- TRAVIS_TESTS="unix docs translations" TRAVIS_BOARDS="feather_huzzah circuitplayground_express pca10056 pca10059 feather_nrf52832 feather_nrf52840_express" TRAVIS_SDK=arm:nrf:esp8266
- TRAVIS_TESTS="unix docs translations" TRAVIS_BOARDS="feather_huzzah circuitplayground_express pca10056 pca10059 feather_nrf52832 feather_nrf52840_express makerdiary_nrf52840_mdk" TRAVIS_SDK=arm:nrf:esp8266
- TRAVIS_BOARDS="metro_m0_express metro_m4_express pirkey_m0 trellis_m4_express trinket_m0" TRAVIS_SDK=arm
- TRAVIS_BOARDS="feather_radiofruit_zigbee gemma_m0 hallowing_m0_express itsybitsy_m0_express itsybitsy_m4_express meowmeow" TRAVIS_SDK=arm
- TRAVIS_BOARDS="feather_m0_express_crickit feather_m0_rfm69 feather_m0_rfm9x feather_m4_express arduino_zero" TRAVIS_SDK=arm
- TRAVIS_BOARDS="feather_m0_express_crickit feather_m0_rfm69 feather_m0_rfm9x feather_m4_express arduino_zero arduino_mkr1300" TRAVIS_SDK=arm
- TRAVIS_BOARDS="circuitplayground_express_crickit feather_m0_adalogger feather_m0_basic feather_m0_express" TRAVIS_SDK=arm
addons:

View File

@ -30,13 +30,21 @@ Supported Boards
Designed for CircuitPython
~~~~~~~~~~~~~~~~~~~~~~~~~~
**M0 Boards**
- `Adafruit CircuitPlayground Express <https://www.adafruit.com/product/3333>`__ (`CircuitPython Guide <https://learn.adafruit.com/adafruit-circuit-playground-express/circuitpython-quickstart>`__)
- `Adafruit Feather M0 Express <https://www.adafruit.com/product/3403>`__ (`CircuitPython Guide <https://learn.adafruit.com/adafruit-feather-m0-express-designed-for-circuit-python-circuitpython/kattni-circuitpython>`__)
- `Adafruit Metro M0 Express <https://www.adafruit.com/product/3505>`_ (`CircuitPython Guide <https://learn.adafruit.com/adafruit-metro-m0-express-designed-for-circuitpython/circuitpython>`__)
- `Adafruit Gemma M0 <https://www.adafruit.com/product/3501>`__ (`CircuitPython Guide <https://learn.adafruit.com/adafruit-gemma-m0/circuitpython>`__)
- `Adafruit Hallowing M0 Express <https://www.adafruit.com/product/3900>`__ (`CircuitPython Guide <https://learn.adafruit.com/adafruit-hallowing/circuitpython>`__)
- `Adafruit ItsyBitsy M0 Express <https://www.adafruit.com/product/3727>`_ (`CircuitPython Guide <https://learn.adafruit.com/introducing-itsy-bitsy-m0/circuitpython>`__)
- `Adafruit Metro M0 Express <https://www.adafruit.com/product/3505>`_ (`CircuitPython Guide <https://learn.adafruit.com/adafruit-metro-m0-express-designed-for-circuitpython/circuitpython>`__)
- `Adafruit Trinket M0 <https://www.adafruit.com/product/3500>`__ (`CircuitPython Guide <https://learn.adafruit.com/adafruit-trinket-m0-circuitpython-arduino/circuitpython>`__)
- `Adafruit Metro M4 <https://www.adafruit.com/product/3382>`__ (`CircuitPython Guide <https://learn.adafruit.com/adafruit-metro-m4-express-featuring-atsamd51/overview>`__)
**M4 Boards**
- `Adafruit Feather M4 Express <https://www.adafruit.com/product/3857>`__ (`CircuitPython Guide <https://learn.adafruit.com/adafruit-feather-m4-express-atsamd51/circuitpython>`__)
- `Adafruit ItsyBitsy M4 Express <https://www.adafruit.com/product/3800>`__ (`CircuitPython Guide <https://learn.adafruit.com/introducing-adafruit-itsybitsy-m4/circuitpython>`__)
- `Adafruit Metro M4 Express <https://www.adafruit.com/product/3382>`__ (`CircuitPython Guide <https://learn.adafruit.com/adafruit-metro-m4-express-featuring-atsamd51/circuitpython>`__)
Other
~~~~~
@ -53,6 +61,12 @@ Other
library <https://github.com/adafruit/Adafruit_CircuitPython_SD>`__)
- `Arduino Zero <https://www.arduino.cc/en/Main/ArduinoBoardZero>`__
"Third-party" or "non-Adafruit" boards
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- `Electronic Cats Meow Meow <https://electroniccats.com/gomeow/>`__
Download
--------

View File

@ -84,6 +84,7 @@ version = release = '0.0.0'
# directories to ignore when looking for source files.
exclude_patterns = ["**/build*",
".venv",
".direnv",
"docs/README.md",
"drivers",
"examples",

View File

@ -138,16 +138,16 @@ Constants
Note that you don't need to specify these in a call to `usocket.socket()`,
because `SOCK_STREAM` socket type automatically selects `IPPROTO_TCP`, and
`SOCK_DGRAM` - `IPPROTO_UDP`. Thus, the only real use of these constants
is as an argument to `setsockopt()`.
is as an argument to `usocket.socket.setsockopt()`.
.. data:: usocket.SOL_*
Socket option levels (an argument to `setsockopt()`). The exact
Socket option levels (an argument to `usocket.socket.setsockopt()`). The exact
inventory depends on a ``MicroPython port``.
.. data:: usocket.SO_*
Socket options (an argument to `setsockopt()`). The exact
Socket options (an argument to `usocket.socket.setsockopt()`). The exact
inventory depends on a ``MicroPython port``.
Constants specific to WiPy:

View File

@ -0,0 +1,6 @@
This is the driver for the WIZnet5x00 series of Ethernet controllers.
Adapted for MicroPython.
Original source: https://github.com/Wiznet/W5500_EVB/tree/master/ioLibrary
Taken on: 30 August 2014

View File

@ -0,0 +1,718 @@
//*****************************************************************************
//
//! \file socket.c
//! \brief SOCKET APIs Implements file.
//! \details SOCKET APIs like as Berkeley Socket APIs.
//! \version 1.0.3
//! \date 2013/10/21
//! \par Revision history
//! <2018/10/09> Nick Moore fixes for CircuitPython
//! <2014/05/01> V1.0.3. Refer to M20140501
//! 1. Implicit type casting -> Explicit type casting.
//! 2. replace 0x01 with PACK_REMAINED in recvfrom()
//! 3. Validation a destination ip in connect() & sendto():
//! It occurs a fatal error on converting unint32 address if uint8* addr parameter is not aligned by 4byte address.
//! Copy 4 byte addr value into temporary uint32 variable and then compares it.
//! <2013/12/20> V1.0.2 Refer to M20131220
//! Remove Warning.
//! <2013/11/04> V1.0.1 2nd Release. Refer to "20131104".
//! In sendto(), Add to clear timeout interrupt status (Sn_IR_TIMEOUT)
//! <2013/10/21> 1st Release
//! \author MidnightCow
//! \copyright
//!
//! Copyright (c) 2013, WIZnet Co., LTD.
//! All rights reserved.
//!
//! Redistribution and use in source and binary forms, with or without
//! modification, are permitted provided that the following conditions
//! are met:
//!
//! * Redistributions of source code must retain the above copyright
//! notice, this list of conditions and the following disclaimer.
//! * 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.
//! * Neither the name of the <ORGANIZATION> 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 COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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.
//
//*****************************************************************************
#include <string.h>
#include "py/mpthread.h"
#include "socket.h"
#define SOCK_ANY_PORT_NUM 0xC000;
static uint16_t sock_any_port = SOCK_ANY_PORT_NUM;
static uint16_t sock_io_mode = 0;
static uint16_t sock_is_sending = 0;
static uint16_t sock_remained_size[_WIZCHIP_SOCK_NUM_] = {0,0,};
static uint8_t sock_pack_info[_WIZCHIP_SOCK_NUM_] = {0,};
#if _WIZCHIP_ == 5200
static uint16_t sock_next_rd[_WIZCHIP_SOCK_NUM_] ={0,};
#endif
#define CHECK_SOCKNUM() \
do{ \
if(sn > _WIZCHIP_SOCK_NUM_) return SOCKERR_SOCKNUM; \
}while(0); \
#define CHECK_SOCKMODE(mode) \
do{ \
if((getSn_MR(sn) & 0x0F) != mode) return SOCKERR_SOCKMODE; \
}while(0); \
#define CHECK_SOCKINIT() \
do{ \
if((getSn_SR(sn) != SOCK_INIT)) return SOCKERR_SOCKINIT; \
}while(0); \
#define CHECK_SOCKDATA() \
do{ \
if(len == 0) return SOCKERR_DATALEN; \
}while(0); \
void WIZCHIP_EXPORT(socket_reset)(void) {
sock_any_port = SOCK_ANY_PORT_NUM;
sock_io_mode = 0;
sock_is_sending = 0;
/*
memset(sock_remained_size, 0, _WIZCHIP_SOCK_NUM_ * sizeof(uint16_t));
memset(sock_pack_info, 0, _WIZCHIP_SOCK_NUM_ * sizeof(uint8_t));
*/
#if _WIZCHIP_ == 5200
memset(sock_next_rd, 0, _WIZCHIP_SOCK_NUM_ * sizeof(uint16_t));
#endif
}
int8_t WIZCHIP_EXPORT(socket)(uint8_t sn, uint8_t protocol, uint16_t port, uint8_t flag)
{
CHECK_SOCKNUM();
switch(protocol)
{
case Sn_MR_TCP :
case Sn_MR_UDP :
case Sn_MR_MACRAW :
break;
#if ( _WIZCHIP_ < 5200 )
case Sn_MR_IPRAW :
case Sn_MR_PPPoE :
break;
#endif
default :
return SOCKERR_SOCKMODE;
}
if((flag & 0x06) != 0) return SOCKERR_SOCKFLAG;
#if _WIZCHIP_ == 5200
if(flag & 0x10) return SOCKERR_SOCKFLAG;
#endif
if(flag != 0)
{
switch(protocol)
{
case Sn_MR_TCP:
if((flag & (SF_TCP_NODELAY|SF_IO_NONBLOCK))==0) return SOCKERR_SOCKFLAG;
break;
case Sn_MR_UDP:
if(flag & SF_IGMP_VER2)
{
if((flag & SF_MULTI_ENABLE)==0) return SOCKERR_SOCKFLAG;
}
#if _WIZCHIP_ == 5500
if(flag & SF_UNI_BLOCK)
{
if((flag & SF_MULTI_ENABLE) == 0) return SOCKERR_SOCKFLAG;
}
#endif
break;
default:
break;
}
}
WIZCHIP_EXPORT(close)(sn);
setSn_MR(sn, (protocol | (flag & 0xF0)));
if(!port)
{
port = sock_any_port++;
if(sock_any_port == 0xFFF0) sock_any_port = SOCK_ANY_PORT_NUM;
}
setSn_PORT(sn,port);
setSn_CR(sn,Sn_CR_OPEN);
while(getSn_CR(sn));
sock_io_mode |= ((flag & SF_IO_NONBLOCK) << sn);
sock_is_sending &= ~(1<<sn);
sock_remained_size[sn] = 0;
sock_pack_info[sn] = 0;
while(getSn_SR(sn) == SOCK_CLOSED);
return (int8_t)sn;
}
int8_t WIZCHIP_EXPORT(close)(uint8_t sn)
{
CHECK_SOCKNUM();
setSn_CR(sn,Sn_CR_CLOSE);
/* wait to process the command... */
while( getSn_CR(sn) );
/* clear all interrupt of the socket. */
setSn_IR(sn, 0xFF);
sock_is_sending &= ~(1<<sn);
sock_remained_size[sn] = 0;
sock_pack_info[sn] = 0;
while(getSn_SR(sn) != SOCK_CLOSED);
return SOCK_OK;
}
int8_t WIZCHIP_EXPORT(listen)(uint8_t sn)
{
CHECK_SOCKNUM();
CHECK_SOCKMODE(Sn_MR_TCP);
CHECK_SOCKINIT();
setSn_CR(sn,Sn_CR_LISTEN);
while(getSn_CR(sn));
while(getSn_SR(sn) != SOCK_LISTEN)
{
if(getSn_CR(sn) == SOCK_CLOSED)
{
WIZCHIP_EXPORT(close)(sn);
return SOCKERR_SOCKCLOSED;
}
}
return SOCK_OK;
}
int8_t WIZCHIP_EXPORT(connect)(uint8_t sn, uint8_t * addr, uint16_t port)
{
CHECK_SOCKNUM();
CHECK_SOCKMODE(Sn_MR_TCP);
CHECK_SOCKINIT();
//M20140501 : For avoiding fatal error on memory align mismatched
//if( *((uint32_t*)addr) == 0xFFFFFFFF || *((uint32_t*)addr) == 0) return SOCKERR_IPINVALID;
{
uint32_t taddr;
taddr = ((uint32_t)addr[0] & 0x000000FF);
taddr = (taddr << 8) + ((uint32_t)addr[1] & 0x000000FF);
taddr = (taddr << 8) + ((uint32_t)addr[2] & 0x000000FF);
taddr = (taddr << 8) + ((uint32_t)addr[3] & 0x000000FF);
if (taddr == 0xFFFFFFFF || taddr == 0) return SOCKERR_IPINVALID;
}
//
if(port == 0) return SOCKERR_PORTZERO;
setSn_DIPR(sn,addr);
setSn_DPORT(sn,port);
#if _WIZCHIP_ == 5200 // for W5200 ARP errata
setSUBR(wizchip_getsubn());
#endif
setSn_CR(sn,Sn_CR_CONNECT);
while(getSn_CR(sn));
if(sock_io_mode & (1<<sn)) return SOCK_BUSY;
while(getSn_SR(sn) != SOCK_ESTABLISHED)
{
if (getSn_SR(sn) == SOCK_CLOSED) {
#if _WIZCHIP_ == 5200 // for W5200 ARP errata
setSUBR((uint8_t*)"\x00\x00\x00\x00");
#endif
return SOCKERR_SOCKCLOSED;
}
if (getSn_IR(sn) & Sn_IR_TIMEOUT)
{
setSn_IR(sn, Sn_IR_TIMEOUT);
#if _WIZCHIP_ == 5200 // for W5200 ARP errata
setSUBR((uint8_t*)"\x00\x00\x00\x00");
#endif
return SOCKERR_TIMEOUT;
}
MICROPY_THREAD_YIELD();
}
#if _WIZCHIP_ == 5200 // for W5200 ARP errata
setSUBR((uint8_t*)"\x00\x00\x00\x00");
#endif
return SOCK_OK;
}
int8_t WIZCHIP_EXPORT(disconnect)(uint8_t sn)
{
CHECK_SOCKNUM();
CHECK_SOCKMODE(Sn_MR_TCP);
setSn_CR(sn,Sn_CR_DISCON);
/* wait to process the command... */
while(getSn_CR(sn));
sock_is_sending &= ~(1<<sn);
if(sock_io_mode & (1<<sn)) return SOCK_BUSY;
while(getSn_SR(sn) != SOCK_CLOSED)
{
if(getSn_IR(sn) & Sn_IR_TIMEOUT)
{
WIZCHIP_EXPORT(close)(sn);
return SOCKERR_TIMEOUT;
}
}
return SOCK_OK;
}
int32_t WIZCHIP_EXPORT(send)(uint8_t sn, uint8_t * buf, uint16_t len)
{
uint8_t tmp=0;
uint16_t freesize=0;
CHECK_SOCKNUM();
CHECK_SOCKMODE(Sn_MR_TCP);
CHECK_SOCKDATA();
tmp = getSn_SR(sn);
if(tmp != SOCK_ESTABLISHED && tmp != SOCK_CLOSE_WAIT) return SOCKERR_SOCKSTATUS;
if( sock_is_sending & (1<<sn) )
{
tmp = getSn_IR(sn);
if(tmp & Sn_IR_SENDOK)
{
setSn_IR(sn, Sn_IR_SENDOK);
#if _WIZCHIP_ == 5200
if(getSn_TX_RD(sn) != sock_next_rd[sn])
{
setSn_CR(sn,Sn_CR_SEND);
while(getSn_CR(sn));
return SOCKERR_BUSY;
}
#endif
sock_is_sending &= ~(1<<sn);
}
else if(tmp & Sn_IR_TIMEOUT)
{
WIZCHIP_EXPORT(close)(sn);
return SOCKERR_TIMEOUT;
}
else return SOCK_BUSY;
}
freesize = getSn_TxMAX(sn);
if (len > freesize) len = freesize; // check size not to exceed MAX size.
while(1)
{
freesize = getSn_TX_FSR(sn);
tmp = getSn_SR(sn);
if ((tmp != SOCK_ESTABLISHED) && (tmp != SOCK_CLOSE_WAIT))
{
WIZCHIP_EXPORT(close)(sn);
return SOCKERR_SOCKSTATUS;
}
if( (sock_io_mode & (1<<sn)) && (len > freesize) ) return SOCK_BUSY;
if(len <= freesize) break;
MICROPY_THREAD_YIELD();
}
wiz_send_data(sn, buf, len);
#if _WIZCHIP_ == 5200
sock_next_rd[sn] = getSn_TX_RD(sn) + len;
#endif
setSn_CR(sn,Sn_CR_SEND);
/* wait to process the command... */
while(getSn_CR(sn));
sock_is_sending |= (1 << sn);
return len;
}
int32_t WIZCHIP_EXPORT(recv)(uint8_t sn, uint8_t * buf, uint16_t len)
{
uint8_t tmp = 0;
uint16_t recvsize = 0;
CHECK_SOCKNUM();
CHECK_SOCKMODE(Sn_MR_TCP);
CHECK_SOCKDATA();
recvsize = getSn_RxMAX(sn);
if(recvsize < len) len = recvsize;
while(1)
{
recvsize = getSn_RX_RSR(sn);
tmp = getSn_SR(sn);
if (tmp != SOCK_ESTABLISHED)
{
if(tmp == SOCK_CLOSE_WAIT)
{
if(recvsize != 0) break;
else if(getSn_TX_FSR(sn) == getSn_TxMAX(sn))
{
// dpgeorge: Getting here seems to be an orderly shutdown of the
// socket, and trying to get POSIX behaviour we return 0 because:
// "If no messages are available to be received and the peer has per
// formed an orderly shutdown, recv() shall return 0".
// TODO this return value clashes with SOCK_BUSY in non-blocking mode.
WIZCHIP_EXPORT(close)(sn);
return 0;
}
}
else
{
WIZCHIP_EXPORT(close)(sn);
return SOCKERR_SOCKSTATUS;
}
}
if((sock_io_mode & (1<<sn)) && (recvsize == 0)) return SOCK_BUSY;
if(recvsize != 0) break;
MICROPY_THREAD_YIELD();
};
if(recvsize < len) len = recvsize;
wiz_recv_data(sn, buf, len);
setSn_CR(sn,Sn_CR_RECV);
while(getSn_CR(sn));
return len;
}
int32_t WIZCHIP_EXPORT(sendto)(uint8_t sn, uint8_t * buf, uint16_t len, uint8_t * addr, uint16_t port)
{
uint8_t tmp = 0;
uint16_t freesize = 0;
CHECK_SOCKNUM();
switch(getSn_MR(sn) & 0x0F)
{
case Sn_MR_UDP:
case Sn_MR_MACRAW:
break;
default:
return SOCKERR_SOCKMODE;
}
CHECK_SOCKDATA();
//M20140501 : For avoiding fatal error on memory align mismatched
//if(*((uint32_t*)addr) == 0) return SOCKERR_IPINVALID;
if ((addr[0] | addr[1] | addr[2] | addr[3]) == 0) return SOCKERR_IPINVALID;
if(port == 0) return SOCKERR_PORTZERO;
tmp = getSn_SR(sn);
if(tmp != SOCK_MACRAW && tmp != SOCK_UDP) return SOCKERR_SOCKSTATUS;
setSn_DIPR(sn,addr);
setSn_DPORT(sn,port);
freesize = getSn_TxMAX(sn);
if (len > freesize) len = freesize; // check size not to exceed MAX size.
while(1)
{
freesize = getSn_TX_FSR(sn);
if(getSn_SR(sn) == SOCK_CLOSED) return SOCKERR_SOCKCLOSED;
if( (sock_io_mode & (1<<sn)) && (len > freesize) ) return SOCK_BUSY;
if(len <= freesize) break;
MICROPY_THREAD_YIELD();
};
wiz_send_data(sn, buf, len);
#if _WIZCHIP_ == 5200 // for W5200 ARP errata
setSUBR(wizchip_getsubn());
#endif
setSn_CR(sn,Sn_CR_SEND);
/* wait to process the command... */
while(getSn_CR(sn));
while(1)
{
tmp = getSn_IR(sn);
if(tmp & Sn_IR_SENDOK)
{
setSn_IR(sn, Sn_IR_SENDOK);
break;
}
//M:20131104
//else if(tmp & Sn_IR_TIMEOUT) return SOCKERR_TIMEOUT;
else if(tmp & Sn_IR_TIMEOUT)
{
setSn_IR(sn, Sn_IR_TIMEOUT);
#if _WIZCHIP_ == 5200 // for W5200 ARP errata
setSUBR((uint8_t*)"\x00\x00\x00\x00");
#endif
return SOCKERR_TIMEOUT;
}
////////////
MICROPY_THREAD_YIELD();
}
#if _WIZCHIP_ == 5200 // for W5200 ARP errata
setSUBR((uint8_t*)"\x00\x00\x00\x00");
#endif
return len;
}
int32_t WIZCHIP_EXPORT(recvfrom)(uint8_t sn, uint8_t * buf, uint16_t len, uint8_t * addr, uint16_t *port)
{
uint8_t mr;
uint8_t head[8];
uint16_t pack_len=0;
CHECK_SOCKNUM();
//CHECK_SOCKMODE(Sn_MR_UDP);
switch((mr=getSn_MR(sn)) & 0x0F)
{
case Sn_MR_UDP:
case Sn_MR_MACRAW:
break;
#if ( _WIZCHIP_ < 5200 )
case Sn_MR_IPRAW:
case Sn_MR_PPPoE:
break;
#endif
default:
return SOCKERR_SOCKMODE;
}
CHECK_SOCKDATA();
if(sock_remained_size[sn] == 0)
{
while(1)
{
pack_len = getSn_RX_RSR(sn);
if(getSn_SR(sn) == SOCK_CLOSED) return SOCKERR_SOCKCLOSED;
if( (sock_io_mode & (1<<sn)) && (pack_len == 0) ) return SOCK_BUSY;
if(pack_len != 0) break;
MICROPY_THREAD_YIELD();
};
}
sock_pack_info[sn] = PACK_COMPLETED;
switch (mr & 0x07)
{
case Sn_MR_UDP :
if(sock_remained_size[sn] == 0)
{
wiz_recv_data(sn, head, 8);
setSn_CR(sn,Sn_CR_RECV);
while(getSn_CR(sn));
// read peer's IP address, port number & packet length
addr[0] = head[0];
addr[1] = head[1];
addr[2] = head[2];
addr[3] = head[3];
*port = head[4];
*port = (*port << 8) + head[5];
sock_remained_size[sn] = head[6];
sock_remained_size[sn] = (sock_remained_size[sn] << 8) + head[7];
sock_pack_info[sn] = PACK_FIRST;
}
if(len < sock_remained_size[sn]) pack_len = len;
else pack_len = sock_remained_size[sn];
//
// Need to packet length check (default 1472)
//
wiz_recv_data(sn, buf, pack_len); // data copy.
break;
case Sn_MR_MACRAW :
if(sock_remained_size[sn] == 0)
{
wiz_recv_data(sn, head, 2);
setSn_CR(sn,Sn_CR_RECV);
while(getSn_CR(sn));
// read peer's IP address, port number & packet length
sock_remained_size[sn] = head[0];
sock_remained_size[sn] = (sock_remained_size[sn] <<8) + head[1];
sock_remained_size[sn] -= 2; // len includes 2 len bytes
if(sock_remained_size[sn] > 1514)
{
WIZCHIP_EXPORT(close)(sn);
return SOCKFATAL_PACKLEN;
}
sock_pack_info[sn] = PACK_FIRST;
}
if(len < sock_remained_size[sn]) pack_len = len;
else pack_len = sock_remained_size[sn];
wiz_recv_data(sn,buf,pack_len);
break;
#if ( _WIZCHIP_ < 5200 )
case Sn_MR_IPRAW:
if(sock_remained_size[sn] == 0)
{
wiz_recv_data(sn, head, 6);
setSn_CR(sn,Sn_CR_RECV);
while(getSn_CR(sn));
addr[0] = head[0];
addr[1] = head[1];
addr[2] = head[2];
addr[3] = head[3];
sock_remained_size[sn] = head[4];
sock_remaiend_size[sn] = (sock_remained_size[sn] << 8) + head[5];
sock_pack_info[sn] = PACK_FIRST;
}
//
// Need to packet length check
//
if(len < sock_remained_size[sn]) pack_len = len;
else pack_len = sock_remained_size[sn];
wiz_recv_data(sn, buf, pack_len); // data copy.
break;
#endif
default:
wiz_recv_ignore(sn, pack_len); // data copy.
sock_remained_size[sn] = pack_len;
break;
}
setSn_CR(sn,Sn_CR_RECV);
/* wait to process the command... */
while(getSn_CR(sn)) ;
sock_remained_size[sn] -= pack_len;
//M20140501 : replace 0x01 with PACK_REMAINED
//if(sock_remained_size[sn] != 0) sock_pack_info[sn] |= 0x01;
if(sock_remained_size[sn] != 0) sock_pack_info[sn] |= PACK_REMAINED;
//
return pack_len;
}
int8_t WIZCHIP_EXPORT(ctlsocket)(uint8_t sn, ctlsock_type cstype, void* arg)
{
uint8_t tmp = 0;
CHECK_SOCKNUM();
switch(cstype)
{
case CS_SET_IOMODE:
tmp = *((uint8_t*)arg);
if(tmp == SOCK_IO_NONBLOCK) sock_io_mode |= (1<<sn);
else if(tmp == SOCK_IO_BLOCK) sock_io_mode &= ~(1<<sn);
else return SOCKERR_ARG;
break;
case CS_GET_IOMODE:
//M20140501 : implict type casting -> explict type casting
//*((uint8_t*)arg) = (sock_io_mode >> sn) & 0x0001;
*((uint8_t*)arg) = (uint8_t)((sock_io_mode >> sn) & 0x0001);
//
break;
case CS_GET_MAXTXBUF:
*((uint16_t*)arg) = getSn_TxMAX(sn);
break;
case CS_GET_MAXRXBUF:
*((uint16_t*)arg) = getSn_RxMAX(sn);
break;
case CS_CLR_INTERRUPT:
if( (*(uint8_t*)arg) > SIK_ALL) return SOCKERR_ARG;
setSn_IR(sn,*(uint8_t*)arg);
break;
case CS_GET_INTERRUPT:
*((uint8_t*)arg) = getSn_IR(sn);
break;
case CS_SET_INTMASK:
if( (*(uint8_t*)arg) > SIK_ALL) return SOCKERR_ARG;
setSn_IMR(sn,*(uint8_t*)arg);
break;
case CS_GET_INTMASK:
*((uint8_t*)arg) = getSn_IMR(sn);
default:
return SOCKERR_ARG;
}
return SOCK_OK;
}
int8_t WIZCHIP_EXPORT(setsockopt)(uint8_t sn, sockopt_type sotype, void* arg)
{
// M20131220 : Remove warning
//uint8_t tmp;
CHECK_SOCKNUM();
switch(sotype)
{
case SO_TTL:
setSn_TTL(sn,*(uint8_t*)arg);
break;
case SO_TOS:
setSn_TOS(sn,*(uint8_t*)arg);
break;
case SO_MSS:
setSn_MSSR(sn,*(uint16_t*)arg);
break;
case SO_DESTIP:
setSn_DIPR(sn, (uint8_t*)arg);
break;
case SO_DESTPORT:
setSn_DPORT(sn, *(uint16_t*)arg);
break;
#if _WIZCHIP_ != 5100
case SO_KEEPALIVESEND:
CHECK_SOCKMODE(Sn_MR_TCP);
#if _WIZCHIP_ > 5200
if(getSn_KPALVTR(sn) != 0) return SOCKERR_SOCKOPT;
#endif
setSn_CR(sn,Sn_CR_SEND_KEEP);
while(getSn_CR(sn) != 0)
{
// M20131220
//if ((tmp = getSn_IR(sn)) & Sn_IR_TIMEOUT)
if (getSn_IR(sn) & Sn_IR_TIMEOUT)
{
setSn_IR(sn, Sn_IR_TIMEOUT);
return SOCKERR_TIMEOUT;
}
}
break;
#if _WIZCHIP_ > 5200
case SO_KEEPALIVEAUTO:
CHECK_SOCKMODE(Sn_MR_TCP);
setSn_KPALVTR(sn,*(uint8_t*)arg);
break;
#endif
#endif
default:
return SOCKERR_ARG;
}
return SOCK_OK;
}
int8_t WIZCHIP_EXPORT(getsockopt)(uint8_t sn, sockopt_type sotype, void* arg)
{
CHECK_SOCKNUM();
switch(sotype)
{
case SO_FLAG:
*(uint8_t*)arg = getSn_MR(sn) & 0xF0;
break;
case SO_TTL:
*(uint8_t*) arg = getSn_TTL(sn);
break;
case SO_TOS:
*(uint8_t*) arg = getSn_TOS(sn);
break;
case SO_MSS:
*(uint8_t*) arg = getSn_MSSR(sn);
case SO_DESTIP:
getSn_DIPR(sn, (uint8_t*)arg);
break;
case SO_DESTPORT:
*(uint16_t*) arg = getSn_DPORT(sn);
break;
#if _WIZCHIP_ > 5200
case SO_KEEPALIVEAUTO:
CHECK_SOCKMODE(Sn_MR_TCP);
*(uint16_t*) arg = getSn_KPALVTR(sn);
break;
#endif
case SO_SENDBUF:
*(uint16_t*) arg = getSn_TX_FSR(sn);
case SO_RECVBUF:
*(uint16_t*) arg = getSn_RX_RSR(sn);
case SO_STATUS:
*(uint8_t*) arg = getSn_SR(sn);
break;
case SO_REMAINSIZE:
if(getSn_MR(sn) == Sn_MR_TCP)
*(uint16_t*)arg = getSn_RX_RSR(sn);
else
*(uint16_t*)arg = sock_remained_size[sn];
break;
case SO_PACKINFO:
CHECK_SOCKMODE(Sn_MR_TCP);
*(uint8_t*)arg = sock_pack_info[sn];
break;
default:
return SOCKERR_SOCKOPT;
}
return SOCK_OK;
}

View File

@ -0,0 +1,472 @@
//*****************************************************************************
//
//! \file socket.h
//! \brief SOCKET APIs Header file.
//! \details SOCKET APIs like as berkeley socket api.
//! \version 1.0.2
//! \date 2013/10/21
//! \par Revision history
//! <2014/05/01> V1.0.2. Refer to M20140501
//! 1. Modify the comment : SO_REMAINED -> PACK_REMAINED
//! 2. Add the comment as zero byte udp data reception in getsockopt().
//! <2013/10/21> 1st Release
//! \author MidnightCow
//! \copyright
//!
//! Copyright (c) 2013, WIZnet Co., LTD.
//! All rights reserved.
//!
//! Redistribution and use in source and binary forms, with or without
//! modification, are permitted provided that the following conditions
//! are met:
//!
//! * Redistributions of source code must retain the above copyright
//! notice, this list of conditions and the following disclaimer.
//! * 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.
//! * Neither the name of the <ORGANIZATION> 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 COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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.
//
//*****************************************************************************
/**
* @defgroup WIZnet_socket_APIs 1. WIZnet socket APIs
* @brief WIZnet socket APIs are based on Berkeley socket APIs, thus it has much similar name and interface.
* But there is a little bit of difference.
* @details
* <b> Comparison between WIZnet and Berkeley SOCKET APIs </b>
* <table>
* <tr> <td><b>API</b></td> <td><b>WIZnet</b></td> <td><b>Berkeley</b></td> </tr>
* <tr> <td>socket()</td> <td>O</td> <td>O</td> </tr>
* <tr> <td><b>bind()</b></td> <td>X</td> <td>O</td> </tr>
* <tr> <td><b>listen()</b></td> <td>O</td> <td>O</td> </tr>
* <tr> <td><b>connect()</b></td> <td>O</td> <td>O</td> </tr>
* <tr> <td><b>accept()</b></td> <td>X</td> <td>O</td> </tr>
* <tr> <td><b>recv()</b></td> <td>O</td> <td>O</td> </tr>
* <tr> <td><b>send()</b></td> <td>O</td> <td>O</td> </tr>
* <tr> <td><b>recvfrom()</b></td> <td>O</td> <td>O</td> </tr>
* <tr> <td><b>sendto()</b></td> <td>O</td> <td>O</td> </tr>
* <tr> <td><b>closesocket()</b></td> <td>O<br>close() & disconnect()</td> <td>O</td> </tr>
* </table>
* There are @b bind() and @b accept() functions in @b Berkeley SOCKET API but,
* not in @b WIZnet SOCKET API. Because socket() of WIZnet is not only creating a SOCKET but also binding a local port number,
* and listen() of WIZnet is not only listening to connection request from client but also accepting the connection request. \n
* When you program "TCP SERVER" with Berkeley SOCKET API, you can use only one listen port.
* When the listen SOCKET accepts a connection request from a client, it keeps listening.
* After accepting the connection request, a new SOCKET is created and the new SOCKET is used in communication with the client. \n
* Following figure shows network flow diagram by Berkeley SOCKET API.
* @image html Berkeley_SOCKET.jpg "<Berkeley SOCKET API>"
* But, When you program "TCP SERVER" with WIZnet SOCKET API, you can use as many as 8 listen SOCKET with same port number. \n
* Because there's no accept() in WIZnet SOCKET APIs, when the listen SOCKET accepts a connection request from a client,
* it is changed in order to communicate with the client.
* And the changed SOCKET is not listening any more and is dedicated for communicating with the client. \n
* If there're many listen SOCKET with same listen port number and a client requests a connection,
* the SOCKET which has the smallest SOCKET number accepts the request and is changed as communication SOCKET. \n
* Following figure shows network flow diagram by WIZnet SOCKET API.
* @image html WIZnet_SOCKET.jpg "<WIZnet SOCKET API>"
*/
#ifndef _WIZCHIP_SOCKET_H_
#define _WIZCHIP_SOCKET_H_
// use this macro for exported names to avoid name clashes
#define WIZCHIP_EXPORT(name) wizchip_ ## name
#include "wizchip_conf.h"
#define SOCKET uint8_t ///< SOCKET type define for legacy driver
#define SOCK_OK 1 ///< Result is OK about socket process.
#define SOCK_BUSY 0 ///< Socket is busy on processing the operation. Valid only Non-block IO Mode.
#define SOCK_FATAL -1000 ///< Result is fatal error about socket process.
#define SOCK_ERROR 0
#define SOCKERR_SOCKNUM (SOCK_ERROR - 1) ///< Invalid socket number
#define SOCKERR_SOCKOPT (SOCK_ERROR - 2) ///< Invalid socket option
#define SOCKERR_SOCKINIT (SOCK_ERROR - 3) ///< Socket is not initialized
#define SOCKERR_SOCKCLOSED (SOCK_ERROR - 4) ///< Socket unexpectedly closed.
#define SOCKERR_SOCKMODE (SOCK_ERROR - 5) ///< Invalid socket mode for socket operation.
#define SOCKERR_SOCKFLAG (SOCK_ERROR - 6) ///< Invalid socket flag
#define SOCKERR_SOCKSTATUS (SOCK_ERROR - 7) ///< Invalid socket status for socket operation.
#define SOCKERR_ARG (SOCK_ERROR - 10) ///< Invalid argument.
#define SOCKERR_PORTZERO (SOCK_ERROR - 11) ///< Port number is zero
#define SOCKERR_IPINVALID (SOCK_ERROR - 12) ///< Invalid IP address
#define SOCKERR_TIMEOUT (SOCK_ERROR - 13) ///< Timeout occurred
#define SOCKERR_DATALEN (SOCK_ERROR - 14) ///< Data length is zero or greater than buffer max size.
#define SOCKERR_BUFFER (SOCK_ERROR - 15) ///< Socket buffer is not enough for data communication.
#define SOCKFATAL_PACKLEN (SOCK_FATAL - 1) ///< Invalid packet length. Fatal Error.
/*
* SOCKET FLAG
*/
#define SF_ETHER_OWN (Sn_MR_MFEN) ///< In \ref Sn_MR_MACRAW, Receive only the packet as broadcast, multicast and own packet
#define SF_IGMP_VER2 (Sn_MR_MC) ///< In \ref Sn_MR_UDP with \ref SF_MULTI_ENABLE, Select IGMP version 2.
#define SF_TCP_NODELAY (Sn_MR_ND) ///< In \ref Sn_MR_TCP, Use to nodelayed ack.
#define SF_MULTI_ENABLE (Sn_MR_MULTI) ///< In \ref Sn_MR_UDP, Enable multicast mode.
#if _WIZCHIP_ == 5500
#define SF_BROAD_BLOCK (Sn_MR_BCASTB) ///< In \ref Sn_MR_UDP or \ref Sn_MR_MACRAW, Block broadcast packet. Valid only in W5500
#define SF_MULTI_BLOCK (Sn_MR_MMB) ///< In \ref Sn_MR_MACRAW, Block multicast packet. Valid only in W5500
#define SF_IPv6_BLOCK (Sn_MR_MIP6B) ///< In \ref Sn_MR_MACRAW, Block IPv6 packet. Valid only in W5500
#define SF_UNI_BLOCK (Sn_MR_UCASTB) ///< In \ref Sn_MR_UDP with \ref SF_MULTI_ENABLE. Valid only in W5500
#endif
#define SF_IO_NONBLOCK 0x01 ///< Socket nonblock io mode. It used parameter in \ref socket().
/*
* UDP & MACRAW Packet Infomation
*/
#define PACK_FIRST 0x80 ///< In Non-TCP packet, It indicates to start receiving a packet.
#define PACK_REMAINED 0x01 ///< In Non-TCP packet, It indicates to remain a packet to be received.
#define PACK_COMPLETED 0x00 ///< In Non-TCP packet, It indicates to complete to receive a packet.
// resets all global state associated with the socket interface
void WIZCHIP_EXPORT(socket_reset)(void);
/**
* @ingroup WIZnet_socket_APIs
* @brief Open a socket.
* @details Initializes the socket with 'sn' passed as parameter and open.
*
* @param sn Socket number. It should be <b>0 ~ @ref \_WIZCHIP_SOCK_NUM_</b>.
* @param protocol Protocol type to operate such as TCP, UDP and MACRAW.
* @param port Port number to be bined.
* @param flag Socket flags as \ref SF_ETHER_OWN, \ref SF_IGMP_VER2, \ref SF_TCP_NODELAY, \ref SF_MULTI_ENABLE, \ref SF_IO_NONBLOCK and so on.\n
* Valid flags only in W5500 : @ref SF_BROAD_BLOCK, @ref SF_MULTI_BLOCK, @ref SF_IPv6_BLOCK, and @ref SF_UNI_BLOCK.
* @sa Sn_MR
*
* @return @b Success : The socket number @b 'sn' passed as parameter\n
* @b Fail :\n @ref SOCKERR_SOCKNUM - Invalid socket number\n
* @ref SOCKERR_SOCKMODE - Not support socket mode as TCP, UDP, and so on. \n
* @ref SOCKERR_SOCKFLAG - Invaild socket flag.
*/
int8_t WIZCHIP_EXPORT(socket)(uint8_t sn, uint8_t protocol, uint16_t port, uint8_t flag);
/**
* @ingroup WIZnet_socket_APIs
* @brief Close a socket.
* @details It closes the socket with @b'sn' passed as parameter.
*
* @param sn Socket number. It should be <b>0 ~ @ref \_WIZCHIP_SOCK_NUM_</b>.
*
* @return @b Success : @ref SOCK_OK \n
* @b Fail : @ref SOCKERR_SOCKNUM - Invalid socket number
*/
int8_t WIZCHIP_EXPORT(close)(uint8_t sn);
/**
* @ingroup WIZnet_socket_APIs
* @brief Listen to a connection request from a client.
* @details It is listening to a connection request from a client.
* If connection request is accepted successfully, the connection is established. Socket sn is used in passive(server) mode.
*
* @param sn Socket number. It should be <b>0 ~ @ref \_WIZCHIP_SOCK_NUM_</b>.
* @return @b Success : @ref SOCK_OK \n
* @b Fail :\n @ref SOCKERR_SOCKINIT - Socket is not initialized \n
* @ref SOCKERR_SOCKCLOSED - Socket closed unexpectedly.
*/
int8_t WIZCHIP_EXPORT(listen)(uint8_t sn);
/**
* @ingroup WIZnet_socket_APIs
* @brief Try to connect a server.
* @details It requests connection to the server with destination IP address and port number passed as parameter.\n
* @note It is valid only in TCP client mode.
* In block io mode, it does not return until connection is completed.
* In Non-block io mode, it return @ref SOCK_BUSY immediately.
*
* @param sn Socket number. It should be <b>0 ~ @ref \_WIZCHIP_SOCK_NUM_</b>.
* @param addr Pointer variable of destination IP address. It should be allocated 4 bytes.
* @param port Destination port number.
*
* @return @b Success : @ref SOCK_OK \n
* @b Fail :\n @ref SOCKERR_SOCKNUM - Invalid socket number\n
* @ref SOCKERR_SOCKMODE - Invalid socket mode\n
* @ref SOCKERR_SOCKINIT - Socket is not initialized\n
* @ref SOCKERR_IPINVALID - Wrong server IP address\n
* @ref SOCKERR_PORTZERO - Server port zero\n
* @ref SOCKERR_TIMEOUT - Timeout occurred during request connection\n
* @ref SOCK_BUSY - In non-block io mode, it returned immediately\n
*/
int8_t WIZCHIP_EXPORT(connect)(uint8_t sn, uint8_t * addr, uint16_t port);
/**
* @ingroup WIZnet_socket_APIs
* @brief Try to disconnect a connection socket.
* @details It sends request message to disconnect the TCP socket 'sn' passed as parameter to the server or client.
* @note It is valid only in TCP server or client mode. \n
* In block io mode, it does not return until disconnection is completed. \n
* In Non-block io mode, it return @ref SOCK_BUSY immediately. \n
* @param sn Socket number. It should be <b>0 ~ @ref \_WIZCHIP_SOCK_NUM_</b>.
* @return @b Success : @ref SOCK_OK \n
* @b Fail :\n @ref SOCKERR_SOCKNUM - Invalid socket number \n
* @ref SOCKERR_SOCKMODE - Invalid operation in the socket \n
* @ref SOCKERR_TIMEOUT - Timeout occurred \n
* @ref SOCK_BUSY - Socket is busy.
*/
int8_t WIZCHIP_EXPORT(disconnect)(uint8_t sn);
/**
* @ingroup WIZnet_socket_APIs
* @brief Send data to the connected peer in TCP socket.
* @details It is used to send outgoing data to the connected socket.
* @note It is valid only in TCP server or client mode. It can't send data greater than socket buffer size. \n
* In block io mode, It doesn't return until data send is completed - socket buffer size is greater than data. \n
* In non-block io mode, It return @ref SOCK_BUSY immediately when socket buffer is not enough. \n
* @param sn Socket number. It should be <b>0 ~ @ref \_WIZCHIP_SOCK_NUM_</b>.
* @param buf Pointer buffer containing data to be sent.
* @param len The byte length of data in buf.
* @return @b Success : The sent data size \n
* @b Fail : \n @ref SOCKERR_SOCKSTATUS - Invalid socket status for socket operation \n
* @ref SOCKERR_TIMEOUT - Timeout occurred \n
* @ref SOCKERR_SOCKMODE - Invalid operation in the socket \n
* @ref SOCKERR_SOCKNUM - Invalid socket number \n
* @ref SOCKERR_DATALEN - zero data length \n
* @ref SOCK_BUSY - Socket is busy.
*/
int32_t WIZCHIP_EXPORT(send)(uint8_t sn, uint8_t * buf, uint16_t len);
/**
* @ingroup WIZnet_socket_APIs
* @brief Receive data from the connected peer.
* @details It is used to read incoming data from the connected socket.\n
* It waits for data as much as the application wants to receive.
* @note It is valid only in TCP server or client mode. It can't receive data greater than socket buffer size. \n
* In block io mode, it doesn't return until data reception is completed - data is filled as <I>len</I> in socket buffer. \n
* In non-block io mode, it return @ref SOCK_BUSY immediately when <I>len</I> is greater than data size in socket buffer. \n
*
* @param sn Socket number. It should be <b>0 ~ @ref \_WIZCHIP_SOCK_NUM_</b>.
* @param buf Pointer buffer to read incoming data.
* @param len The max data length of data in buf.
* @return @b Success : The real received data size \n
* @b Fail :\n
* @ref SOCKERR_SOCKSTATUS - Invalid socket status for socket operation \n
* @ref SOCKERR_SOCKMODE - Invalid operation in the socket \n
* @ref SOCKERR_SOCKNUM - Invalid socket number \n
* @ref SOCKERR_DATALEN - zero data length \n
* @ref SOCK_BUSY - Socket is busy.
*/
int32_t WIZCHIP_EXPORT(recv)(uint8_t sn, uint8_t * buf, uint16_t len);
/**
* @ingroup WIZnet_socket_APIs
* @brief Sends datagram to the peer with destination IP address and port number passed as parameter.
* @details It sends datagram of UDP or MACRAW to the peer with destination IP address and port number passed as parameter.\n
* Even if the connectionless socket has been previously connected to a specific address,
* the address and port number parameters override the destination address for that particular datagram only.
* @note In block io mode, It doesn't return until data send is completed - socket buffer size is greater than <I>len</I>.
* In non-block io mode, It return @ref SOCK_BUSY immediately when socket buffer is not enough.
*
* @param sn Socket number. It should be <b>0 ~ @ref \_WIZCHIP_SOCK_NUM_</b>.
* @param buf Pointer buffer to send outgoing data.
* @param len The byte length of data in buf.
* @param addr Pointer variable of destination IP address. It should be allocated 4 bytes.
* @param port Destination port number.
*
* @return @b Success : The sent data size \n
* @b Fail :\n @ref SOCKERR_SOCKNUM - Invalid socket number \n
* @ref SOCKERR_SOCKMODE - Invalid operation in the socket \n
* @ref SOCKERR_SOCKSTATUS - Invalid socket status for socket operation \n
* @ref SOCKERR_DATALEN - zero data length \n
* @ref SOCKERR_IPINVALID - Wrong server IP address\n
* @ref SOCKERR_PORTZERO - Server port zero\n
* @ref SOCKERR_SOCKCLOSED - Socket unexpectedly closed \n
* @ref SOCKERR_TIMEOUT - Timeout occurred \n
* @ref SOCK_BUSY - Socket is busy.
*/
int32_t WIZCHIP_EXPORT(sendto)(uint8_t sn, uint8_t * buf, uint16_t len, uint8_t * addr, uint16_t port);
/**
* @ingroup WIZnet_socket_APIs
* @brief Receive datagram of UDP or MACRAW
* @details This function is an application I/F function which is used to receive the data in other then TCP mode. \n
* This function is used to receive UDP and MAC_RAW mode, and handle the header as well.
* This function can divide to received the packet data.
* On the MACRAW SOCKET, the addr and port parameters are ignored.
* @note In block io mode, it doesn't return until data reception is completed - data is filled as <I>len</I> in socket buffer
* In non-block io mode, it return @ref SOCK_BUSY immediately when <I>len</I> is greater than data size in socket buffer.
*
* @param sn Socket number. It should be <b>0 ~ @ref \_WIZCHIP_SOCK_NUM_</b>.
* @param buf Pointer buffer to read incoming data.
* @param len The max data length of data in buf.
* When the received packet size <= len, receives data as packet sized.
* When others, receives data as len.
* @param addr Pointer variable of destination IP address. It should be allocated 4 bytes.
* It is valid only when the first call recvfrom for receiving the packet.
* When it is valid, @ref packinfo[7] should be set as '1' after call @ref getsockopt(sn, SO_PACKINFO, &packinfo).
* @param port Pointer variable of destination port number.
* It is valid only when the first call recvform for receiving the packet.
* When it is valid, @ref packinfo[7] should be set as '1' after call @ref getsockopt(sn, SO_PACKINFO, &packinfo).
*
* @return @b Success : This function return real received data size for success.\n
* @b Fail : @ref SOCKERR_DATALEN - zero data length \n
* @ref SOCKERR_SOCKMODE - Invalid operation in the socket \n
* @ref SOCKERR_SOCKNUM - Invalid socket number \n
* @ref SOCKBUSY - Socket is busy.
*/
int32_t WIZCHIP_EXPORT(recvfrom)(uint8_t sn, uint8_t * buf, uint16_t len, uint8_t * addr, uint16_t *port);
/////////////////////////////
// SOCKET CONTROL & OPTION //
/////////////////////////////
#define SOCK_IO_BLOCK 0 ///< Socket Block IO Mode in @ref setsockopt().
#define SOCK_IO_NONBLOCK 1 ///< Socket Non-block IO Mode in @ref setsockopt().
/**
* @defgroup DATA_TYPE DATA TYPE
*/
/**
* @ingroup DATA_TYPE
* @brief The kind of Socket Interrupt.
* @sa Sn_IR, Sn_IMR, setSn_IR(), getSn_IR(), setSn_IMR(), getSn_IMR()
*/
typedef enum
{
SIK_CONNECTED = (1 << 0), ///< connected
SIK_DISCONNECTED = (1 << 1), ///< disconnected
SIK_RECEIVED = (1 << 2), ///< data received
SIK_TIMEOUT = (1 << 3), ///< timeout occurred
SIK_SENT = (1 << 4), ///< send ok
SIK_ALL = 0x1F, ///< all interrupt
}sockint_kind;
/**
* @ingroup DATA_TYPE
* @brief The type of @ref ctlsocket().
*/
typedef enum
{
CS_SET_IOMODE, ///< set socket IO mode with @ref SOCK_IO_BLOCK or @ref SOCK_IO_NONBLOCK
CS_GET_IOMODE, ///< get socket IO mode
CS_GET_MAXTXBUF, ///< get the size of socket buffer allocated in TX memory
CS_GET_MAXRXBUF, ///< get the size of socket buffer allocated in RX memory
CS_CLR_INTERRUPT, ///< clear the interrupt of socket with @ref sockint_kind
CS_GET_INTERRUPT, ///< get the socket interrupt. refer to @ref sockint_kind
CS_SET_INTMASK, ///< set the interrupt mask of socket with @ref sockint_kind
CS_GET_INTMASK ///< get the masked interrupt of socket. refer to @ref sockint_kind
}ctlsock_type;
/**
* @ingroup DATA_TYPE
* @brief The type of socket option in @ref setsockopt() or @ref getsockopt()
*/
typedef enum
{
SO_FLAG, ///< Valid only in getsockopt(), For set flag of socket refer to <I>flag</I> in @ref socket().
SO_TTL, ///< Set/Get TTL. @ref Sn_TTL ( @ref setSn_TTL(), @ref getSn_TTL() )
SO_TOS, ///< Set/Get TOS. @ref Sn_TOS ( @ref setSn_TOS(), @ref getSn_TOS() )
SO_MSS, ///< Set/Get MSS. @ref Sn_MSSR ( @ref setSn_MSSR(), @ref getSn_MSSR() )
SO_DESTIP, ///< Set/Get the destination IP address. @ref Sn_DIPR ( @ref setSn_DIPR(), @ref getSn_DIPR() )
SO_DESTPORT, ///< Set/Get the destination Port number. @ref Sn_DPORT ( @ref setSn_DPORT(), @ref getSn_DPORT() )
#if _WIZCHIP_ != 5100
SO_KEEPALIVESEND, ///< Valid only in setsockopt. Manually send keep-alive packet in TCP mode
#if _WIZCHIP_ > 5200
SO_KEEPALIVEAUTO, ///< Set/Get keep-alive auto transmission timer in TCP mode
#endif
#endif
SO_SENDBUF, ///< Valid only in getsockopt. Get the free data size of Socekt TX buffer. @ref Sn_TX_FSR, @ref getSn_TX_FSR()
SO_RECVBUF, ///< Valid only in getsockopt. Get the received data size in socket RX buffer. @ref Sn_RX_RSR, @ref getSn_RX_RSR()
SO_STATUS, ///< Valid only in getsockopt. Get the socket status. @ref Sn_SR, @ref getSn_SR()
SO_REMAINSIZE, ///< Valid only in getsockopt. Get the remained packet size in other then TCP mode.
SO_PACKINFO ///< Valid only in getsockopt. Get the packet information as @ref PACK_FIRST, @ref PACK_REMAINED, and @ref PACK_COMPLETED in other then TCP mode.
}sockopt_type;
/**
* @ingroup WIZnet_socket_APIs
* @brief Control socket.
* @details Control IO mode, Interrupt & Mask of socket and get the socket buffer information.
* Refer to @ref ctlsock_type.
* @param sn socket number
* @param cstype type of control socket. refer to @ref ctlsock_type.
* @param arg Data type and value is determined according to @ref ctlsock_type. \n
* <table>
* <tr> <td> @b cstype </td> <td> @b data type</td><td>@b value</td></tr>
* <tr> <td> @ref CS_SET_IOMODE \n @ref CS_GET_IOMODE </td> <td> uint8_t </td><td>@ref SOCK_IO_BLOCK @ref SOCK_IO_NONBLOCK</td></tr>
* <tr> <td> @ref CS_GET_MAXTXBUF \n @ref CS_GET_MAXRXBUF </td> <td> uint16_t </td><td> 0 ~ 16K </td></tr>
* <tr> <td> @ref CS_CLR_INTERRUPT \n @ref CS_GET_INTERRUPT \n @ref CS_SET_INTMASK \n @ref CS_GET_INTMASK </td> <td> @ref sockint_kind </td><td> @ref SIK_CONNECTED, etc. </td></tr>
* </table>
* @return @b Success @ref SOCK_OK \n
* @b fail @ref SOCKERR_ARG - Invalid argument\n
*/
int8_t WIZCHIP_EXPORT(ctlsocket)(uint8_t sn, ctlsock_type cstype, void* arg);
/**
* @ingroup WIZnet_socket_APIs
* @brief set socket options
* @details Set socket option like as TTL, MSS, TOS, and so on. Refer to @ref sockopt_type.
*
* @param sn socket number
* @param sotype socket option type. refer to @ref sockopt_type
* @param arg Data type and value is determined according to <I>sotype</I>. \n
* <table>
* <tr> <td> @b sotype </td> <td> @b data type</td><td>@b value</td></tr>
* <tr> <td> @ref SO_TTL </td> <td> uint8_t </td><td> 0 ~ 255 </td> </tr>
* <tr> <td> @ref SO_TOS </td> <td> uint8_t </td><td> 0 ~ 255 </td> </tr>
* <tr> <td> @ref SO_MSS </td> <td> uint16_t </td><td> 0 ~ 65535 </td> </tr>
* <tr> <td> @ref SO_DESTIP </td> <td> uint8_t[4] </td><td> </td></tr>
* <tr> <td> @ref SO_DESTPORT </td> <td> uint16_t </td><td> 0 ~ 65535 </td></tr>
* <tr> <td> @ref SO_KEEPALIVESEND </td> <td> null </td><td> null </td></tr>
* <tr> <td> @ref SO_KEEPALIVEAUTO </td> <td> uint8_t </td><td> 0 ~ 255 </td></tr>
* </table>
* @return
* - @b Success : @ref SOCK_OK \n
* - @b Fail
* - @ref SOCKERR_SOCKNUM - Invalid Socket number \n
* - @ref SOCKERR_SOCKMODE - Invalid socket mode \n
* - @ref SOCKERR_SOCKOPT - Invalid socket option or its value \n
* - @ref SOCKERR_TIMEOUT - Timeout occurred when sending keep-alive packet \n
*/
int8_t WIZCHIP_EXPORT(setsockopt)(uint8_t sn, sockopt_type sotype, void* arg);
/**
* @ingroup WIZnet_socket_APIs
* @brief get socket options
* @details Get socket option like as FLAG, TTL, MSS, and so on. Refer to @ref sockopt_type
* @param sn socket number
* @param sotype socket option type. refer to @ref sockopt_type
* @param arg Data type and value is determined according to <I>sotype</I>. \n
* <table>
* <tr> <td> @b sotype </td> <td>@b data type</td><td>@b value</td></tr>
* <tr> <td> @ref SO_FLAG </td> <td> uint8_t </td><td> @ref SF_ETHER_OWN, etc... </td> </tr>
* <tr> <td> @ref SO_TOS </td> <td> uint8_t </td><td> 0 ~ 255 </td> </tr>
* <tr> <td> @ref SO_MSS </td> <td> uint16_t </td><td> 0 ~ 65535 </td> </tr>
* <tr> <td> @ref SO_DESTIP </td> <td> uint8_t[4] </td><td> </td></tr>
* <tr> <td> @ref SO_DESTPORT </td> <td> uint16_t </td><td> </td></tr>
* <tr> <td> @ref SO_KEEPALIVEAUTO </td> <td> uint8_t </td><td> 0 ~ 255 </td></tr>
* <tr> <td> @ref SO_SENDBUF </td> <td> uint16_t </td><td> 0 ~ 65535 </td></tr>
* <tr> <td> @ref SO_RECVBUF </td> <td> uint16_t </td><td> 0 ~ 65535 </td></tr>
* <tr> <td> @ref SO_STATUS </td> <td> uint8_t </td><td> @ref SOCK_ESTABLISHED, etc.. </td></tr>
* <tr> <td> @ref SO_REMAINSIZE </td> <td> uint16_t </td><td> 0~ 65535 </td></tr>
* <tr> <td> @ref SO_PACKINFO </td> <td> uint8_t </td><td> @ref PACK_FIRST, etc... </td></tr>
* </table>
* @return
* - @b Success : @ref SOCK_OK \n
* - @b Fail
* - @ref SOCKERR_SOCKNUM - Invalid Socket number \n
* - @ref SOCKERR_SOCKOPT - Invalid socket option or its value \n
* - @ref SOCKERR_SOCKMODE - Invalid socket mode \n
* @note
* The option as PACK_REMAINED and SO_PACKINFO is valid only in NON-TCP mode and after call @ref recvfrom(). \n
* When SO_PACKINFO value is PACK_FIRST and the return value of recvfrom() is zero,
* This means the zero byte UDP data(UDP Header only) received.
*/
int8_t WIZCHIP_EXPORT(getsockopt)(uint8_t sn, sockopt_type sotype, void* arg);
#endif // _WIZCHIP_SOCKET_H_

View File

@ -0,0 +1,206 @@
// dpgeorge: this file taken from w5500/w5500.c and adapted to W5200
//*****************************************************************************
//
//! \file w5500.c
//! \brief W5500 HAL Interface.
//! \version 1.0.1
//! \date 2013/10/21
//! \par Revision history
//! <2014/05/01> V1.0.2
//! 1. Implicit type casting -> Explicit type casting. Refer to M20140501
//! Fixed the problem on porting into under 32bit MCU
//! Issued by Mathias ClauBen, wizwiki forum ID Think01 and bobh
//! Thank for your interesting and serious advices.
//! <2013/10/21> 1st Release
//! <2013/12/20> V1.0.1
//! 1. Remove warning
//! 2. WIZCHIP_READ_BUF WIZCHIP_WRITE_BUF in case _WIZCHIP_IO_MODE_SPI_FDM_
//! for loop optimized(removed). refer to M20131220
//! \author MidnightCow
//! \copyright
//!
//! Copyright (c) 2013, WIZnet Co., LTD.
//! All rights reserved.
//!
//! Redistribution and use in source and binary forms, with or without
//! modification, are permitted provided that the following conditions
//! are met:
//!
//! * Redistributions of source code must retain the above copyright
//! notice, this list of conditions and the following disclaimer.
//! * 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.
//! * Neither the name of the <ORGANIZATION> 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 COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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.
//
//*****************************************************************************
#include "w5200.h"
#define SMASK (0x7ff) /* tx buffer mask */
#define RMASK (0x7ff) /* rx buffer mask */
#define SSIZE (2048) /* max tx buffer size */
#define RSIZE (2048) /* max rx buffer size */
#define TXBUF_BASE (0x8000)
#define RXBUF_BASE (0xc000)
#define SBASE(sn) (TXBUF_BASE + SSIZE * (sn)) /* tx buffer base for socket sn */
#define RBASE(sn) (RXBUF_BASE + RSIZE * (sn)) /* rx buffer base for socket sn */
uint8_t WIZCHIP_READ(uint32_t AddrSel) {
WIZCHIP_CRITICAL_ENTER();
WIZCHIP.CS._select();
uint8_t spi_data[4] = {
AddrSel >> 8,
AddrSel,
0x00,
0x01,
};
WIZCHIP.IF.SPI._write_bytes(spi_data, 4);
uint8_t ret;
WIZCHIP.IF.SPI._read_bytes(&ret, 1);
WIZCHIP.CS._deselect();
WIZCHIP_CRITICAL_EXIT();
return ret;
}
void WIZCHIP_WRITE(uint32_t AddrSel, uint8_t wb) {
WIZCHIP_CRITICAL_ENTER();
WIZCHIP.CS._select();
uint8_t spi_data[5] = {
AddrSel >> 8,
AddrSel,
0x80,
0x01,
wb,
};
WIZCHIP.IF.SPI._write_bytes(spi_data, 5);
WIZCHIP.CS._deselect();
WIZCHIP_CRITICAL_EXIT();
}
void WIZCHIP_READ_BUF(uint32_t AddrSel, uint8_t* pBuf, uint16_t len) {
WIZCHIP_CRITICAL_ENTER();
WIZCHIP.CS._select();
uint8_t spi_data[4] = {
AddrSel >> 8,
AddrSel,
0x00 | ((len >> 8) & 0x7f),
len & 0xff,
};
WIZCHIP.IF.SPI._write_bytes(spi_data, 4);
WIZCHIP.IF.SPI._read_bytes(pBuf, len);
WIZCHIP.CS._deselect();
WIZCHIP_CRITICAL_EXIT();
}
void WIZCHIP_WRITE_BUF(uint32_t AddrSel, uint8_t* pBuf, uint16_t len) {
WIZCHIP_CRITICAL_ENTER();
WIZCHIP.CS._select();
uint8_t spi_data[4] = {
AddrSel >> 8,
AddrSel,
0x80 | ((len >> 8) & 0x7f),
len & 0xff,
};
WIZCHIP.IF.SPI._write_bytes(spi_data, 4);
WIZCHIP.IF.SPI._write_bytes(pBuf, len);
WIZCHIP.CS._deselect();
WIZCHIP_CRITICAL_EXIT();
}
uint16_t getSn_TX_FSR(uint8_t sn) {
uint16_t val = 0, val1 = 0;
do {
val1 = (WIZCHIP_READ(Sn_TX_FSR(sn)) << 8) | WIZCHIP_READ(Sn_TX_FSR(sn) + 1);
if (val1 != 0) {
val = (WIZCHIP_READ(Sn_TX_FSR(sn)) << 8) | WIZCHIP_READ(Sn_TX_FSR(sn) + 1);
}
} while (val != val1);
return val;
}
uint16_t getSn_RX_RSR(uint8_t sn) {
uint16_t val = 0, val1 = 0;
do {
val1 = (WIZCHIP_READ(Sn_RX_RSR(sn)) << 8) | WIZCHIP_READ(Sn_RX_RSR(sn) + 1);
if (val1 != 0) {
val = (WIZCHIP_READ(Sn_RX_RSR(sn)) << 8) | WIZCHIP_READ(Sn_RX_RSR(sn) + 1);
}
} while (val != val1);
return val;
}
void wiz_send_data(uint8_t sn, uint8_t *wizdata, uint16_t len) {
if (len == 0) {
return;
}
uint16_t ptr = getSn_TX_WR(sn);
uint16_t offset = ptr & SMASK;
uint32_t addr = offset + SBASE(sn);
if (offset + len > SSIZE) {
// implement wrap-around circular buffer
uint16_t size = SSIZE - offset;
WIZCHIP_WRITE_BUF(addr, wizdata, size);
WIZCHIP_WRITE_BUF(SBASE(sn), wizdata + size, len - size);
} else {
WIZCHIP_WRITE_BUF(addr, wizdata, len);
}
ptr += len;
setSn_TX_WR(sn, ptr);
}
void wiz_recv_data(uint8_t sn, uint8_t *wizdata, uint16_t len) {
if (len == 0) {
return;
}
uint16_t ptr = getSn_RX_RD(sn);
uint16_t offset = ptr & RMASK;
uint16_t addr = RBASE(sn) + offset;
if (offset + len > RSIZE) {
// implement wrap-around circular buffer
uint16_t size = RSIZE - offset;
WIZCHIP_READ_BUF(addr, wizdata, size);
WIZCHIP_READ_BUF(RBASE(sn), wizdata + size, len - size);
} else {
WIZCHIP_READ_BUF(addr, wizdata, len);
}
ptr += len;
setSn_RX_RD(sn, ptr);
}
void wiz_recv_ignore(uint8_t sn, uint16_t len) {
uint16_t ptr = getSn_RX_RD(sn);
ptr += len;
setSn_RX_RD(sn, ptr);
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,247 @@
//*****************************************************************************
//
//! \file w5500.c
//! \brief W5500 HAL Interface.
//! \version 1.0.1
//! \date 2013/10/21
//! \par Revision history
//! <2014/05/01> V1.0.2
//! 1. Implicit type casting -> Explicit type casting. Refer to M20140501
//! Fixed the problem on porting into under 32bit MCU
//! Issued by Mathias ClauBen, wizwiki forum ID Think01 and bobh
//! Thank for your interesting and serious advices.
//! <2013/10/21> 1st Release
//! <2013/12/20> V1.0.1
//! 1. Remove warning
//! 2. WIZCHIP_READ_BUF WIZCHIP_WRITE_BUF in case _WIZCHIP_IO_MODE_SPI_FDM_
//! for loop optimized(removed). refer to M20131220
//! \author MidnightCow
//! \copyright
//!
//! Copyright (c) 2013, WIZnet Co., LTD.
//! All rights reserved.
//!
//! Redistribution and use in source and binary forms, with or without
//! modification, are permitted provided that the following conditions
//! are met:
//!
//! * Redistributions of source code must retain the above copyright
//! notice, this list of conditions and the following disclaimer.
//! * 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.
//! * Neither the name of the <ORGANIZATION> 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 COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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.
//
//*****************************************************************************
//#include <stdio.h>
#include "w5500.h"
#define _W5500_SPI_VDM_OP_ 0x00
#define _W5500_SPI_FDM_OP_LEN1_ 0x01
#define _W5500_SPI_FDM_OP_LEN2_ 0x02
#define _W5500_SPI_FDM_OP_LEN4_ 0x03
////////////////////////////////////////////////////
#define LPC_SSP0 (0)
static void Chip_SSP_ReadFrames_Blocking(int dummy, uint8_t *buf, uint32_t len) {
WIZCHIP.IF.SPI._read_bytes(buf, len);
}
static void Chip_SSP_WriteFrames_Blocking(int dummy, const uint8_t *buf, uint32_t len) {
WIZCHIP.IF.SPI._write_bytes(buf, len);
}
uint8_t WIZCHIP_READ(uint32_t AddrSel)
{
uint8_t ret;
uint8_t spi_data[3];
WIZCHIP_CRITICAL_ENTER();
WIZCHIP.CS._select();
AddrSel |= (_W5500_SPI_READ_ | _W5500_SPI_VDM_OP_);
//WIZCHIP.IF.SPI._write_byte((AddrSel & 0x00FF0000) >> 16);
//WIZCHIP.IF.SPI._write_byte((AddrSel & 0x0000FF00) >> 8);
//WIZCHIP.IF.SPI._write_byte((AddrSel & 0x000000FF) >> 0);
//ret = WIZCHIP.IF.SPI._read_byte();
spi_data[0] = (AddrSel & 0x00FF0000) >> 16;
spi_data[1] = (AddrSel & 0x0000FF00) >> 8;
spi_data[2] = (AddrSel & 0x000000FF) >> 0;
Chip_SSP_WriteFrames_Blocking(LPC_SSP0, spi_data, 3);
Chip_SSP_ReadFrames_Blocking(LPC_SSP0, &ret, 1);
WIZCHIP.CS._deselect();
WIZCHIP_CRITICAL_EXIT();
return ret;
}
void WIZCHIP_WRITE(uint32_t AddrSel, uint8_t wb )
{
uint8_t spi_data[4];
WIZCHIP_CRITICAL_ENTER();
WIZCHIP.CS._select();
AddrSel |= (_W5500_SPI_WRITE_ | _W5500_SPI_VDM_OP_);
//WIZCHIP.IF.SPI._write_byte((AddrSel & 0x00FF0000) >> 16);
//WIZCHIP.IF.SPI._write_byte((AddrSel & 0x0000FF00) >> 8);
//WIZCHIP.IF.SPI._write_byte((AddrSel & 0x000000FF) >> 0);
//WIZCHIP.IF.SPI._write_byte(wb);
spi_data[0] = (AddrSel & 0x00FF0000) >> 16;
spi_data[1] = (AddrSel & 0x0000FF00) >> 8;
spi_data[2] = (AddrSel & 0x000000FF) >> 0;
spi_data[3] = wb;
Chip_SSP_WriteFrames_Blocking(LPC_SSP0, spi_data, 4);
WIZCHIP.CS._deselect();
WIZCHIP_CRITICAL_EXIT();
}
void WIZCHIP_READ_BUF (uint32_t AddrSel, uint8_t* pBuf, uint16_t len)
{
uint8_t spi_data[3];
//uint16_t i;
WIZCHIP_CRITICAL_ENTER();
WIZCHIP.CS._select();
AddrSel |= (_W5500_SPI_READ_ | _W5500_SPI_VDM_OP_);
//WIZCHIP.IF.SPI._write_byte((AddrSel & 0x00FF0000) >> 16);
//WIZCHIP.IF.SPI._write_byte((AddrSel & 0x0000FF00) >> 8);
//WIZCHIP.IF.SPI._write_byte((AddrSel & 0x000000FF) >> 0);
//for(i = 0; i < len; i++)
// pBuf[i] = WIZCHIP.IF.SPI._read_byte();
spi_data[0] = (AddrSel & 0x00FF0000) >> 16;
spi_data[1] = (AddrSel & 0x0000FF00) >> 8;
spi_data[2] = (AddrSel & 0x000000FF) >> 0;
Chip_SSP_WriteFrames_Blocking(LPC_SSP0, spi_data, 3);
Chip_SSP_ReadFrames_Blocking(LPC_SSP0, pBuf, len);
WIZCHIP.CS._deselect();
WIZCHIP_CRITICAL_EXIT();
}
void WIZCHIP_WRITE_BUF(uint32_t AddrSel, uint8_t* pBuf, uint16_t len)
{
uint8_t spi_data[3];
//uint16_t i;
WIZCHIP_CRITICAL_ENTER();
WIZCHIP.CS._select();
AddrSel |= (_W5500_SPI_WRITE_ | _W5500_SPI_VDM_OP_);
//WIZCHIP.IF.SPI._write_byte((AddrSel & 0x00FF0000) >> 16);
//WIZCHIP.IF.SPI._write_byte((AddrSel & 0x0000FF00) >> 8);
//WIZCHIP.IF.SPI._write_byte((AddrSel & 0x000000FF) >> 0);
//for(i = 0; i < len; i++)
// WIZCHIP.IF.SPI._write_byte(pBuf[i]);
spi_data[0] = (AddrSel & 0x00FF0000) >> 16;
spi_data[1] = (AddrSel & 0x0000FF00) >> 8;
spi_data[2] = (AddrSel & 0x000000FF) >> 0;
Chip_SSP_WriteFrames_Blocking(LPC_SSP0, spi_data, 3);
Chip_SSP_WriteFrames_Blocking(LPC_SSP0, pBuf, len);
WIZCHIP.CS._deselect();
WIZCHIP_CRITICAL_EXIT();
}
uint16_t getSn_TX_FSR(uint8_t sn)
{
uint16_t val=0,val1=0;
do
{
val1 = WIZCHIP_READ(Sn_TX_FSR(sn));
val1 = (val1 << 8) + WIZCHIP_READ(WIZCHIP_OFFSET_INC(Sn_TX_FSR(sn),1));
if (val1 != 0)
{
val = WIZCHIP_READ(Sn_TX_FSR(sn));
val = (val << 8) + WIZCHIP_READ(WIZCHIP_OFFSET_INC(Sn_TX_FSR(sn),1));
}
}while (val != val1);
return val;
}
uint16_t getSn_RX_RSR(uint8_t sn)
{
uint16_t val=0,val1=0;
do
{
val1 = WIZCHIP_READ(Sn_RX_RSR(sn));
val1 = (val1 << 8) + WIZCHIP_READ(WIZCHIP_OFFSET_INC(Sn_RX_RSR(sn),1));
if (val1 != 0)
{
val = WIZCHIP_READ(Sn_RX_RSR(sn));
val = (val << 8) + WIZCHIP_READ(WIZCHIP_OFFSET_INC(Sn_RX_RSR(sn),1));
}
}while (val != val1);
return val;
}
void wiz_send_data(uint8_t sn, uint8_t *wizdata, uint16_t len)
{
uint16_t ptr = 0;
uint32_t addrsel = 0;
if(len == 0) return;
ptr = getSn_TX_WR(sn);
//M20140501 : implict type casting -> explict type casting
//addrsel = (ptr << 8) + (WIZCHIP_TXBUF_BLOCK(sn) << 3);
addrsel = ((uint32_t)ptr << 8) + (WIZCHIP_TXBUF_BLOCK(sn) << 3);
//
WIZCHIP_WRITE_BUF(addrsel,wizdata, len);
ptr += len;
setSn_TX_WR(sn,ptr);
}
void wiz_recv_data(uint8_t sn, uint8_t *wizdata, uint16_t len)
{
uint16_t ptr = 0;
uint32_t addrsel = 0;
if(len == 0) return;
ptr = getSn_RX_RD(sn);
//M20140501 : implict type casting -> explict type casting
//addrsel = ((ptr << 8) + (WIZCHIP_RXBUF_BLOCK(sn) << 3);
addrsel = ((uint32_t)ptr << 8) + (WIZCHIP_RXBUF_BLOCK(sn) << 3);
//
WIZCHIP_READ_BUF(addrsel, wizdata, len);
ptr += len;
setSn_RX_RD(sn,ptr);
}
void wiz_recv_ignore(uint8_t sn, uint16_t len)
{
uint16_t ptr = 0;
ptr = getSn_RX_RD(sn);
ptr += len;
setSn_RX_RD(sn,ptr);
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,662 @@
//****************************************************************************/
//!
//! \file wizchip_conf.c
//! \brief WIZCHIP Config Header File.
//! \version 1.0.1
//! \date 2013/10/21
//! \par Revision history
//! <2014/05/01> V1.0.1 Refer to M20140501
//! 1. Explicit type casting in wizchip_bus_readbyte() & wizchip_bus_writebyte()
// Issued by Mathias ClauBen.
//! uint32_t type converts into ptrdiff_t first. And then recoverting it into uint8_t*
//! For remove the warning when pointer type size is not 32bit.
//! If ptrdiff_t doesn't support in your complier, You should must replace ptrdiff_t into your suitable pointer type.
//! <2013/10/21> 1st Release
//! \author MidnightCow
//! \copyright
//!
//! Copyright (c) 2013, WIZnet Co., LTD.
//! All rights reserved.
//!
//! Redistribution and use in source and binary forms, with or without
//! modification, are permitted provided that the following conditions
//! are met:
//!
//! * Redistributions of source code must retain the above copyright
//! notice, this list of conditions and the following disclaimer.
//! * 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.
//! * Neither the name of the <ORGANIZATION> 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 COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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.
//
//*****************************************************************************/
//A20140501 : for use the type - ptrdiff_t
#include <stddef.h>
//
#include "wizchip_conf.h"
#include "socket.h"
/**
* @brief Default function to enable interrupt.
* @note This function help not to access wrong address. If you do not describe this function or register any functions,
* null function is called.
*/
void wizchip_cris_enter(void) {};
/**
* @brief Default function to disable interrupt.
* @note This function help not to access wrong address. If you do not describe this function or register any functions,
* null function is called.
*/
void wizchip_cris_exit(void) {};
/**
* @brief Default function to select chip.
* @note This function help not to access wrong address. If you do not describe this function or register any functions,
* null function is called.
*/
void wizchip_cs_select(void) {};
/**
* @brief Default function to deselect chip.
* @note This function help not to access wrong address. If you do not describe this function or register any functions,
* null function is called.
*/
void wizchip_cs_deselect(void) {};
/**
* @brief Default function to read in direct or indirect interface.
* @note This function help not to access wrong address. If you do not describe this function or register any functions,
* null function is called.
*/
//M20140501 : Explict pointer type casting
//uint8_t wizchip_bus_readbyte(uint32_t AddrSel) { return * ((volatile uint8_t *) AddrSel); };
uint8_t wizchip_bus_readbyte(uint32_t AddrSel) { return * ((volatile uint8_t *)((ptrdiff_t) AddrSel)); };
/**
* @brief Default function to write in direct or indirect interface.
* @note This function help not to access wrong address. If you do not describe this function or register any functions,
* null function is called.
*/
//M20140501 : Explict pointer type casting
//void wizchip_bus_writebyte(uint32_t AddrSel, uint8_t wb) { *((volatile uint8_t*) AddrSel) = wb; };
void wizchip_bus_writebyte(uint32_t AddrSel, uint8_t wb) { *((volatile uint8_t*)((ptrdiff_t)AddrSel)) = wb; };
/**
* @brief Default function to read in SPI interface.
* @note This function help not to access wrong address. If you do not describe this function or register any functions,
* null function is called.
*/
void wizchip_spi_readbytes(uint8_t *buf, uint32_t len) {}
/**
* @brief Default function to write in SPI interface.
* @note This function help not to access wrong address. If you do not describe this function or register any functions,
* null function is called.
*/
void wizchip_spi_writebytes(const uint8_t *buf, uint32_t len) {}
/**
* @\ref _WIZCHIP instance
*/
_WIZCHIP WIZCHIP =
{
.id = _WIZCHIP_ID_,
.if_mode = _WIZCHIP_IO_MODE_,
.CRIS._enter = wizchip_cris_enter,
.CRIS._exit = wizchip_cris_exit,
.CS._select = wizchip_cs_select,
.CS._deselect = wizchip_cs_deselect,
.IF.BUS._read_byte = wizchip_bus_readbyte,
.IF.BUS._write_byte = wizchip_bus_writebyte
// .IF.SPI._read_byte = wizchip_spi_readbyte,
// .IF.SPI._write_byte = wizchip_spi_writebyte
};
#if _WIZCHIP_ == 5200 // for W5200 ARP errata
static uint8_t _SUBN_[4]; // subnet
#endif
static uint8_t _DNS_[4]; // DNS server ip address
static dhcp_mode _DHCP_; // DHCP mode
void reg_wizchip_cris_cbfunc(void(*cris_en)(void), void(*cris_ex)(void))
{
if(!cris_en || !cris_ex)
{
WIZCHIP.CRIS._enter = wizchip_cris_enter;
WIZCHIP.CRIS._exit = wizchip_cris_exit;
}
else
{
WIZCHIP.CRIS._enter = cris_en;
WIZCHIP.CRIS._exit = cris_ex;
}
}
void reg_wizchip_cs_cbfunc(void(*cs_sel)(void), void(*cs_desel)(void))
{
if(!cs_sel || !cs_desel)
{
WIZCHIP.CS._select = wizchip_cs_select;
WIZCHIP.CS._deselect = wizchip_cs_deselect;
}
else
{
WIZCHIP.CS._select = cs_sel;
WIZCHIP.CS._deselect = cs_desel;
}
}
void reg_wizchip_bus_cbfunc(uint8_t(*bus_rb)(uint32_t addr), void (*bus_wb)(uint32_t addr, uint8_t wb))
{
while(!(WIZCHIP.if_mode & _WIZCHIP_IO_MODE_BUS_));
if(!bus_rb || !bus_wb)
{
WIZCHIP.IF.BUS._read_byte = wizchip_bus_readbyte;
WIZCHIP.IF.BUS._write_byte = wizchip_bus_writebyte;
}
else
{
WIZCHIP.IF.BUS._read_byte = bus_rb;
WIZCHIP.IF.BUS._write_byte = bus_wb;
}
}
void reg_wizchip_spi_cbfunc(void (*spi_rb)(uint8_t *, uint32_t), void (*spi_wb)(const uint8_t *, uint32_t))
{
while(!(WIZCHIP.if_mode & _WIZCHIP_IO_MODE_SPI_));
if(!spi_rb || !spi_wb)
{
WIZCHIP.IF.SPI._read_bytes = wizchip_spi_readbytes;
WIZCHIP.IF.SPI._write_bytes = wizchip_spi_writebytes;
}
else
{
WIZCHIP.IF.SPI._read_bytes = spi_rb;
WIZCHIP.IF.SPI._write_bytes = spi_wb;
}
}
int8_t ctlwizchip(ctlwizchip_type cwtype, void* arg)
{
uint8_t tmp = 0;
uint8_t* ptmp[2] = {0,0};
switch(cwtype)
{
case CW_RESET_WIZCHIP:
wizchip_sw_reset();
break;
case CW_INIT_WIZCHIP:
if(arg != 0)
{
ptmp[0] = (uint8_t*)arg;
ptmp[1] = ptmp[0] + _WIZCHIP_SOCK_NUM_;
}
return wizchip_init(ptmp[0], ptmp[1]);
case CW_CLR_INTERRUPT:
wizchip_clrinterrupt(*((intr_kind*)arg));
break;
case CW_GET_INTERRUPT:
*((intr_kind*)arg) = wizchip_getinterrupt();
break;
case CW_SET_INTRMASK:
wizchip_setinterruptmask(*((intr_kind*)arg));
break;
case CW_GET_INTRMASK:
*((intr_kind*)arg) = wizchip_getinterruptmask();
break;
#if _WIZCHIP_ > 5100
case CW_SET_INTRTIME:
setINTLEVEL(*(uint16_t*)arg);
break;
case CW_GET_INTRTIME:
*(uint16_t*)arg = getINTLEVEL();
break;
#endif
case CW_GET_ID:
((uint8_t*)arg)[0] = WIZCHIP.id[0];
((uint8_t*)arg)[1] = WIZCHIP.id[1];
((uint8_t*)arg)[2] = WIZCHIP.id[2];
((uint8_t*)arg)[3] = WIZCHIP.id[3];
((uint8_t*)arg)[4] = WIZCHIP.id[4];
((uint8_t*)arg)[5] = 0;
break;
#if _WIZCHIP_ == 5500
case CW_RESET_PHY:
wizphy_reset();
break;
case CW_SET_PHYCONF:
wizphy_setphyconf((wiz_PhyConf*)arg);
break;
case CW_GET_PHYCONF:
wizphy_getphyconf((wiz_PhyConf*)arg);
break;
case CW_GET_PHYSTATUS:
break;
case CW_SET_PHYPOWMODE:
return wizphy_setphypmode(*(uint8_t*)arg);
#endif
case CW_GET_PHYPOWMODE:
tmp = wizphy_getphypmode();
if((int8_t)tmp == -1) return -1;
*(uint8_t*)arg = tmp;
break;
case CW_GET_PHYLINK:
tmp = wizphy_getphylink();
if((int8_t)tmp == -1) return -1;
*(uint8_t*)arg = tmp;
break;
default:
return -1;
}
return 0;
}
int8_t ctlnetwork(ctlnetwork_type cntype, void* arg)
{
switch(cntype)
{
case CN_SET_NETINFO:
wizchip_setnetinfo((wiz_NetInfo*)arg);
break;
case CN_GET_NETINFO:
wizchip_getnetinfo((wiz_NetInfo*)arg);
break;
case CN_SET_NETMODE:
return wizchip_setnetmode(*(netmode_type*)arg);
case CN_GET_NETMODE:
*(netmode_type*)arg = wizchip_getnetmode();
break;
case CN_SET_TIMEOUT:
wizchip_settimeout((wiz_NetTimeout*)arg);
break;
case CN_GET_TIMEOUT:
wizchip_gettimeout((wiz_NetTimeout*)arg);
break;
default:
return -1;
}
return 0;
}
void wizchip_sw_reset(void)
{
uint8_t gw[4], sn[4], sip[4];
uint8_t mac[6];
getSHAR(mac);
getGAR(gw); getSUBR(sn); getSIPR(sip);
setMR(MR_RST);
getMR(); // for delay
setSHAR(mac);
setGAR(gw);
setSUBR(sn);
setSIPR(sip);
}
int8_t wizchip_init(uint8_t* txsize, uint8_t* rxsize)
{
int8_t i;
int8_t tmp = 0;
wizchip_sw_reset();
if(txsize)
{
tmp = 0;
for(i = 0 ; i < _WIZCHIP_SOCK_NUM_; i++)
tmp += txsize[i];
if(tmp > 16) return -1;
for(i = 0 ; i < _WIZCHIP_SOCK_NUM_; i++)
setSn_TXBUF_SIZE(i, txsize[i]);
}
if(rxsize)
{
tmp = 0;
for(i = 0 ; i < _WIZCHIP_SOCK_NUM_; i++)
tmp += rxsize[i];
if(tmp > 16) return -1;
for(i = 0 ; i < _WIZCHIP_SOCK_NUM_; i++)
setSn_RXBUF_SIZE(i, rxsize[i]);
}
WIZCHIP_EXPORT(socket_reset)();
return 0;
}
void wizchip_clrinterrupt(intr_kind intr)
{
uint8_t ir = (uint8_t)intr;
uint8_t sir = (uint8_t)((uint16_t)intr >> 8);
#if _WIZCHIP_ < 5500
ir |= (1<<4); // IK_WOL
#endif
#if _WIZCHIP_ == 5200
ir |= (1 << 6);
#endif
#if _WIZCHIP_ < 5200
sir &= 0x0F;
#endif
#if _WIZCHIP_ == 5100
ir |= sir;
setIR(ir);
#else
setIR(ir);
setSIR(sir);
#endif
}
intr_kind wizchip_getinterrupt(void)
{
uint8_t ir = 0;
uint8_t sir = 0;
uint16_t ret = 0;
#if _WIZCHIP_ == 5100
ir = getIR();
sir = ir 0x0F;
#else
ir = getIR();
sir = getSIR();
#endif
#if _WIZCHIP_ < 5500
ir &= ~(1<<4); // IK_WOL
#endif
#if _WIZCHIP_ == 5200
ir &= ~(1 << 6);
#endif
ret = sir;
ret = (ret << 8) + ir;
return (intr_kind)ret;
}
void wizchip_setinterruptmask(intr_kind intr)
{
uint8_t imr = (uint8_t)intr;
uint8_t simr = (uint8_t)((uint16_t)intr >> 8);
#if _WIZCHIP_ < 5500
imr &= ~(1<<4); // IK_WOL
#endif
#if _WIZCHIP_ == 5200
imr &= ~(1 << 6);
#endif
#if _WIZCHIP_ < 5200
simr &= 0x0F;
#endif
#if _WIZCHIP_ == 5100
imr |= simr;
setIMR(imr);
#else
setIMR(imr);
setSIMR(simr);
#endif
}
intr_kind wizchip_getinterruptmask(void)
{
uint8_t imr = 0;
uint8_t simr = 0;
uint16_t ret = 0;
#if _WIZCHIP_ == 5100
imr = getIMR();
simr = imr 0x0F;
#else
imr = getIMR();
simr = getSIMR();
#endif
#if _WIZCHIP_ < 5500
imr &= ~(1<<4); // IK_WOL
#endif
#if _WIZCHIP_ == 5200
imr &= ~(1 << 6); // IK_DEST_UNREACH
#endif
ret = simr;
ret = (ret << 8) + imr;
return (intr_kind)ret;
}
int8_t wizphy_getphylink(void)
{
int8_t tmp;
#if _WIZCHIP_ == 5200
if(getPHYSTATUS() & PHYSTATUS_LINK)
tmp = PHY_LINK_ON;
else
tmp = PHY_LINK_OFF;
#elif _WIZCHIP_ == 5500
if(getPHYCFGR() & PHYCFGR_LNK_ON)
tmp = PHY_LINK_ON;
else
tmp = PHY_LINK_OFF;
#else
tmp = -1;
#endif
return tmp;
}
#if _WIZCHIP_ > 5100
int8_t wizphy_getphypmode(void)
{
int8_t tmp = 0;
#if _WIZCHIP_ == 5200
if(getPHYSTATUS() & PHYSTATUS_POWERDOWN)
tmp = PHY_POWER_DOWN;
else
tmp = PHY_POWER_NORM;
#elif _WIZCHIP_ == 5500
if(getPHYCFGR() & PHYCFGR_OPMDC_PDOWN)
tmp = PHY_POWER_DOWN;
else
tmp = PHY_POWER_NORM;
#else
tmp = -1;
#endif
return tmp;
}
#endif
#if _WIZCHIP_ == 5500
void wizphy_reset(void)
{
uint8_t tmp = getPHYCFGR();
tmp &= PHYCFGR_RST;
setPHYCFGR(tmp);
tmp = getPHYCFGR();
tmp |= ~PHYCFGR_RST;
setPHYCFGR(tmp);
}
void wizphy_setphyconf(wiz_PhyConf* phyconf)
{
uint8_t tmp = 0;
if(phyconf->by == PHY_CONFBY_SW)
tmp |= PHYCFGR_OPMD;
else
tmp &= ~PHYCFGR_OPMD;
if(phyconf->mode == PHY_MODE_AUTONEGO)
tmp |= PHYCFGR_OPMDC_ALLA;
else
{
if(phyconf->duplex == PHY_DUPLEX_FULL)
{
if(phyconf->speed == PHY_SPEED_100)
tmp |= PHYCFGR_OPMDC_100F;
else
tmp |= PHYCFGR_OPMDC_10F;
}
else
{
if(phyconf->speed == PHY_SPEED_100)
tmp |= PHYCFGR_OPMDC_100H;
else
tmp |= PHYCFGR_OPMDC_10H;
}
}
setPHYCFGR(tmp);
wizphy_reset();
}
void wizphy_getphyconf(wiz_PhyConf* phyconf)
{
uint8_t tmp = 0;
tmp = getPHYCFGR();
phyconf->by = (tmp & PHYCFGR_OPMD) ? PHY_CONFBY_SW : PHY_CONFBY_HW;
switch(tmp & PHYCFGR_OPMDC_ALLA)
{
case PHYCFGR_OPMDC_ALLA:
case PHYCFGR_OPMDC_100FA:
phyconf->mode = PHY_MODE_AUTONEGO;
break;
default:
phyconf->mode = PHY_MODE_MANUAL;
break;
}
switch(tmp & PHYCFGR_OPMDC_ALLA)
{
case PHYCFGR_OPMDC_100FA:
case PHYCFGR_OPMDC_100F:
case PHYCFGR_OPMDC_100H:
phyconf->speed = PHY_SPEED_100;
break;
default:
phyconf->speed = PHY_SPEED_10;
break;
}
switch(tmp & PHYCFGR_OPMDC_ALLA)
{
case PHYCFGR_OPMDC_100FA:
case PHYCFGR_OPMDC_100F:
case PHYCFGR_OPMDC_10F:
phyconf->duplex = PHY_DUPLEX_FULL;
break;
default:
phyconf->duplex = PHY_DUPLEX_HALF;
break;
}
}
void wizphy_getphystat(wiz_PhyConf* phyconf)
{
uint8_t tmp = getPHYCFGR();
phyconf->duplex = (tmp & PHYCFGR_DPX_FULL) ? PHY_DUPLEX_FULL : PHY_DUPLEX_HALF;
phyconf->speed = (tmp & PHYCFGR_SPD_100) ? PHY_SPEED_100 : PHY_SPEED_10;
}
int8_t wizphy_setphypmode(uint8_t pmode)
{
uint8_t tmp = 0;
tmp = getPHYCFGR();
if((tmp & PHYCFGR_OPMD)== 0) return -1;
tmp &= ~PHYCFGR_OPMDC_ALLA;
if( pmode == PHY_POWER_DOWN)
tmp |= PHYCFGR_OPMDC_PDOWN;
else
tmp |= PHYCFGR_OPMDC_ALLA;
setPHYCFGR(tmp);
wizphy_reset();
tmp = getPHYCFGR();
if( pmode == PHY_POWER_DOWN)
{
if(tmp & PHYCFGR_OPMDC_PDOWN) return 0;
}
else
{
if(tmp & PHYCFGR_OPMDC_ALLA) return 0;
}
return -1;
}
#endif
void wizchip_setnetinfo(wiz_NetInfo* pnetinfo)
{
setSHAR(pnetinfo->mac);
setGAR(pnetinfo->gw);
setSUBR(pnetinfo->sn);
setSIPR(pnetinfo->ip);
#if _WIZCHIP_ == 5200 // for W5200 ARP errata
_SUBN_[0] = pnetinfo->sn[0];
_SUBN_[1] = pnetinfo->sn[1];
_SUBN_[2] = pnetinfo->sn[2];
_SUBN_[3] = pnetinfo->sn[3];
#endif
_DNS_[0] = pnetinfo->dns[0];
_DNS_[1] = pnetinfo->dns[1];
_DNS_[2] = pnetinfo->dns[2];
_DNS_[3] = pnetinfo->dns[3];
_DHCP_ = pnetinfo->dhcp;
}
void wizchip_getnetinfo(wiz_NetInfo* pnetinfo)
{
getSHAR(pnetinfo->mac);
getGAR(pnetinfo->gw);
getSUBR(pnetinfo->sn);
getSIPR(pnetinfo->ip);
#if _WIZCHIP_ == 5200 // for W5200 ARP errata
pnetinfo->sn[0] = _SUBN_[0];
pnetinfo->sn[1] = _SUBN_[1];
pnetinfo->sn[2] = _SUBN_[2];
pnetinfo->sn[3] = _SUBN_[3];
#endif
pnetinfo->dns[0]= _DNS_[0];
pnetinfo->dns[1]= _DNS_[1];
pnetinfo->dns[2]= _DNS_[2];
pnetinfo->dns[3]= _DNS_[3];
pnetinfo->dhcp = _DHCP_;
}
#if _WIZCHIP_ == 5200 // for W5200 ARP errata
uint8_t *wizchip_getsubn(void) {
return _SUBN_;
}
#endif
int8_t wizchip_setnetmode(netmode_type netmode)
{
uint8_t tmp = 0;
#if _WIZCHIP_ != 5500
if(netmode & ~(NM_WAKEONLAN | NM_PPPOE | NM_PINGBLOCK)) return -1;
#else
if(netmode & ~(NM_WAKEONLAN | NM_PPPOE | NM_PINGBLOCK | NM_FORCEARP)) return -1;
#endif
tmp = getMR();
tmp |= (uint8_t)netmode;
setMR(tmp);
return 0;
}
netmode_type wizchip_getnetmode(void)
{
return (netmode_type) getMR();
}
void wizchip_settimeout(wiz_NetTimeout* nettime)
{
setRCR(nettime->retry_cnt);
setRTR(nettime->time_100us);
}
void wizchip_gettimeout(wiz_NetTimeout* nettime)
{
nettime->retry_cnt = getRCR();
nettime->time_100us = getRTR();
}

View File

@ -0,0 +1,554 @@
//*****************************************************************************
//
//! \file wizchip_conf.h
//! \brief WIZCHIP Config Header File.
//! \version 1.0.0
//! \date 2013/10/21
//! \par Revision history
//! <2013/10/21> 1st Release
//! \author MidnightCow
//! \copyright
//!
//! Copyright (c) 2013, WIZnet Co., LTD.
//! All rights reserved.
//!
//! Redistribution and use in source and binary forms, with or without
//! modification, are permitted provided that the following conditions
//! are met:
//!
//! * Redistributions of source code must retain the above copyright
//! notice, this list of conditions and the following disclaimer.
//! * 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.
//! * Neither the name of the <ORGANIZATION> 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 COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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.
//
//*****************************************************************************
/**
* @defgroup extra_functions 2. WIZnet Extra Functions
*
* @brief These functions is optional function. It could be replaced at WIZCHIP I/O function because they were made by WIZCHIP I/O functions.
* @details There are functions of configuring WIZCHIP, network, interrupt, phy, network information and timer. \n
*
*/
#ifndef _WIZCHIP_CONF_H_
#define _WIZCHIP_CONF_H_
#include <stdint.h>
/**
* @brief Select WIZCHIP.
* @todo You should select one, \b 5100, \b 5200 ,\b 5500 or etc. \n\n
* ex> <code> #define \_WIZCHIP_ 5500 </code>
*/
#ifndef _WIZCHIP_
#define _WIZCHIP_ 5200 // 5100, 5200, 5500
#endif
#define _WIZCHIP_IO_MODE_NONE_ 0x0000
#define _WIZCHIP_IO_MODE_BUS_ 0x0100 /**< Bus interface mode */
#define _WIZCHIP_IO_MODE_SPI_ 0x0200 /**< SPI interface mode */
//#define _WIZCHIP_IO_MODE_IIC_ 0x0400
//#define _WIZCHIP_IO_MODE_SDIO_ 0x0800
// Add to
//
#define _WIZCHIP_IO_MODE_BUS_DIR_ (_WIZCHIP_IO_MODE_BUS_ + 1) /**< BUS interface mode for direct */
#define _WIZCHIP_IO_MODE_BUS_INDIR_ (_WIZCHIP_IO_MODE_BUS_ + 2) /**< BUS interface mode for indirect */
#define _WIZCHIP_IO_MODE_SPI_VDM_ (_WIZCHIP_IO_MODE_SPI_ + 1) /**< SPI interface mode for variable length data*/
#define _WIZCHIP_IO_MODE_SPI_FDM_ (_WIZCHIP_IO_MODE_SPI_ + 2) /**< SPI interface mode for fixed length data mode*/
#if (_WIZCHIP_ == 5100)
#define _WIZCHIP_ID_ "W5100\0"
/**
* @brief Define interface mode.
* @todo you should select interface mode as chip. Select one of @ref \_WIZCHIP_IO_MODE_SPI_ , @ref \_WIZCHIP_IO_MODE_BUS_DIR_ or @ref \_WIZCHIP_IO_MODE_BUS_INDIR_
*/
// #define _WIZCHIP_IO_MODE_ _WIZCHIP_IO_MODE_BUS_DIR_
// #define _WIZCHIP_IO_MODE_ _WIZCHIP_IO_MODE_BUS_INDIR_
#define _WIZCHIP_IO_MODE_ _WIZCHIP_IO_MODE_SPI_
#elif (_WIZCHIP_ == 5200)
#define _WIZCHIP_ID_ "W5200\0"
/**
* @brief Define interface mode.
* @todo you should select interface mode as chip. Select one of @ref \_WIZCHIP_IO_MODE_SPI_ or @ref \_WIZCHIP_IO_MODE_BUS_INDIR_
*/
// #define _WIZCHIP_IO_MODE_ _WIZCHIP_IO_MODE_BUS_INDIR_
#define _WIZCHIP_IO_MODE_ _WIZCHIP_IO_MODE_SPI_
#include "w5200/w5200.h"
#elif (_WIZCHIP_ == 5500)
#define _WIZCHIP_ID_ "W5500\0"
/**
* @brief Define interface mode. \n
* @todo Should select interface mode as chip.
* - @ref \_WIZCHIP_IO_MODE_SPI_ \n
* -@ref \_WIZCHIP_IO_MODE_SPI_VDM_ : Valid only in @ref \_WIZCHIP_ == 5500 \n
* -@ref \_WIZCHIP_IO_MODE_SPI_FDM_ : Valid only in @ref \_WIZCHIP_ == 5500 \n
* - @ref \_WIZCHIP_IO_MODE_BUS_ \n
* - @ref \_WIZCHIP_IO_MODE_BUS_DIR_ \n
* - @ref \_WIZCHIP_IO_MODE_BUS_INDIR_ \n
* - Others will be defined in future. \n\n
* ex> <code> #define \_WIZCHIP_IO_MODE_ \_WIZCHIP_IO_MODE_SPI_VDM_ </code>
*
*/
//#define _WIZCHIP_IO_MODE_ _WIZCHIP_IO_MODE_SPI_FDM_
#define _WIZCHIP_IO_MODE_ _WIZCHIP_IO_MODE_SPI_VDM_
#include "w5500/w5500.h"
#else
#error "Unknown defined _WIZCHIP_. You should define one of 5100, 5200, and 5500 !!!"
#endif
#ifndef _WIZCHIP_IO_MODE_
#error "Undefined _WIZCHIP_IO_MODE_. You should define it !!!"
#endif
/**
* @brief Define I/O base address when BUS IF mode.
* @todo Should re-define it to fit your system when BUS IF Mode (@ref \_WIZCHIP_IO_MODE_BUS_,
* @ref \_WIZCHIP_IO_MODE_BUS_DIR_, @ref \_WIZCHIP_IO_MODE_BUS_INDIR_). \n\n
* ex> <code> #define \_WIZCHIP_IO_BASE_ 0x00008000 </code>
*/
#define _WIZCHIP_IO_BASE_ 0x00000000 //
#if _WIZCHIP_IO_MODE_ & _WIZCHIP_IO_MODE_BUS_
#ifndef _WIZCHIP_IO_BASE_
#error "You should be define _WIZCHIP_IO_BASE to fit your system memory map."
#endif
#endif
#if _WIZCHIP_ > 5100
#define _WIZCHIP_SOCK_NUM_ 8 ///< The count of independant socket of @b WIZCHIP
#else
#define _WIZCHIP_SOCK_NUM_ 4 ///< The count of independant socket of @b WIZCHIP
#endif
/********************************************************
* WIZCHIP BASIC IF functions for SPI, SDIO, I2C , ETC.
*********************************************************/
/**
* @ingroup DATA_TYPE
* @brief The set of callback functions for W5500:@ref WIZCHIP_IO_Functions W5200:@ref WIZCHIP_IO_Functions_W5200
*/
typedef struct __WIZCHIP
{
uint16_t if_mode; ///< host interface mode
uint8_t id[6]; ///< @b WIZCHIP ID such as @b 5100, @b 5200, @b 5500, and so on.
/**
* The set of critical section callback func.
*/
struct _CRIS
{
void (*_enter) (void); ///< crtical section enter
void (*_exit) (void); ///< critial section exit
}CRIS;
/**
* The set of @ref\_WIZCHIP_ select control callback func.
*/
struct _CS
{
void (*_select) (void); ///< @ref \_WIZCHIP_ selected
void (*_deselect)(void); ///< @ref \_WIZCHIP_ deselected
}CS;
/**
* The set of interface IO callback func.
*/
union _IF
{
/**
* For BUS interface IO
*/
struct
{
uint8_t (*_read_byte) (uint32_t AddrSel);
void (*_write_byte) (uint32_t AddrSel, uint8_t wb);
}BUS;
/**
* For SPI interface IO
*/
struct
{
void (*_read_bytes) (uint8_t *buf, uint32_t len);
void (*_write_bytes) (const uint8_t *buf, uint32_t len);
}SPI;
// To be added
//
}IF;
}_WIZCHIP;
extern _WIZCHIP WIZCHIP;
/**
* @ingroup DATA_TYPE
* WIZCHIP control type enumration used in @ref ctlwizchip().
*/
typedef enum
{
CW_RESET_WIZCHIP, ///< Resets WIZCHIP by softly
CW_INIT_WIZCHIP, ///< Inializes to WIZCHIP with SOCKET buffer size 2 or 1 dimension array typed uint8_t.
CW_GET_INTERRUPT, ///< Get Interrupt status of WIZCHIP
CW_CLR_INTERRUPT, ///< Clears interrupt
CW_SET_INTRMASK, ///< Masks interrupt
CW_GET_INTRMASK, ///< Get interrupt mask
CW_SET_INTRTIME, ///< Set interval time between the current and next interrupt.
CW_GET_INTRTIME, ///< Set interval time between the current and next interrupt.
CW_GET_ID, ///< Gets WIZCHIP name.
#if _WIZCHIP_ == 5500
CW_RESET_PHY, ///< Resets internal PHY. Valid Only W5000
CW_SET_PHYCONF, ///< When PHY configured by interal register, PHY operation mode (Manual/Auto, 10/100, Half/Full). Valid Only W5000
CW_GET_PHYCONF, ///< Get PHY operation mode in interal register. Valid Only W5000
CW_GET_PHYSTATUS, ///< Get real PHY status on operating. Valid Only W5000
CW_SET_PHYPOWMODE, ///< Set PHY power mode as noraml and down when PHYSTATUS.OPMD == 1. Valid Only W5000
#endif
CW_GET_PHYPOWMODE, ///< Get PHY Power mode as down or normal
CW_GET_PHYLINK ///< Get PHY Link status
}ctlwizchip_type;
/**
* @ingroup DATA_TYPE
* Network control type enumration used in @ref ctlnetwork().
*/
typedef enum
{
CN_SET_NETINFO, ///< Set Network with @ref wiz_NetInfo
CN_GET_NETINFO, ///< Get Network with @ref wiz_NetInfo
CN_SET_NETMODE, ///< Set network mode as WOL, PPPoE, Ping Block, and Force ARP mode
CN_GET_NETMODE, ///< Get network mode as WOL, PPPoE, Ping Block, and Force ARP mode
CN_SET_TIMEOUT, ///< Set network timeout as retry count and time.
CN_GET_TIMEOUT, ///< Get network timeout as retry count and time.
}ctlnetwork_type;
/**
* @ingroup DATA_TYPE
* Interrupt kind when CW_SET_INTRRUPT, CW_GET_INTERRUPT, CW_SET_INTRMASK
* and CW_GET_INTRMASK is used in @ref ctlnetwork().
* It can be used with OR operation.
*/
typedef enum
{
#if _WIZCHIP_ > 5200
IK_WOL = (1 << 4), ///< Wake On Lan by receiving the magic packet. Valid in W500.
#endif
IK_PPPOE_TERMINATED = (1 << 5), ///< PPPoE Disconnected
#if _WIZCHIP_ != 5200
IK_DEST_UNREACH = (1 << 6), ///< Destination IP & Port Unreable, No use in W5200
#endif
IK_IP_CONFLICT = (1 << 7), ///< IP conflict occurred
IK_SOCK_0 = (1 << 8), ///< Socket 0 interrupt
IK_SOCK_1 = (1 << 9), ///< Socket 1 interrupt
IK_SOCK_2 = (1 << 10), ///< Socket 2 interrupt
IK_SOCK_3 = (1 << 11), ///< Socket 3 interrupt
#if _WIZCHIP_ > 5100
IK_SOCK_4 = (1 << 12), ///< Socket 4 interrupt, No use in 5100
IK_SOCK_5 = (1 << 13), ///< Socket 5 interrupt, No use in 5100
IK_SOCK_6 = (1 << 14), ///< Socket 6 interrupt, No use in 5100
IK_SOCK_7 = (1 << 15), ///< Socket 7 interrupt, No use in 5100
#endif
#if _WIZCHIP_ > 5100
IK_SOCK_ALL = (0xFF << 8) ///< All Socket interrpt
#else
IK_SOCK_ALL = (0x0F << 8) ///< All Socket interrpt
#endif
}intr_kind;
#define PHY_CONFBY_HW 0 ///< Configured PHY operation mode by HW pin
#define PHY_CONFBY_SW 1 ///< Configured PHY operation mode by SW register
#define PHY_MODE_MANUAL 0 ///< Configured PHY operation mode with user setting.
#define PHY_MODE_AUTONEGO 1 ///< Configured PHY operation mode with auto-negotiation
#define PHY_SPEED_10 0 ///< Link Speed 10
#define PHY_SPEED_100 1 ///< Link Speed 100
#define PHY_DUPLEX_HALF 0 ///< Link Half-Duplex
#define PHY_DUPLEX_FULL 1 ///< Link Full-Duplex
#define PHY_LINK_OFF 0 ///< Link Off
#define PHY_LINK_ON 1 ///< Link On
#define PHY_POWER_NORM 0 ///< PHY power normal mode
#define PHY_POWER_DOWN 1 ///< PHY power down mode
#if _WIZCHIP_ == 5500
/**
* @ingroup DATA_TYPE
* It configures PHY configuration when CW_SET PHYCONF or CW_GET_PHYCONF in W5500,
* and it indicates the real PHY status configured by HW or SW in all WIZCHIP. \n
* Valid only in W5500.
*/
typedef struct wiz_PhyConf_t
{
uint8_t by; ///< set by @ref PHY_CONFBY_HW or @ref PHY_CONFBY_SW
uint8_t mode; ///< set by @ref PHY_MODE_MANUAL or @ref PHY_MODE_AUTONEGO
uint8_t speed; ///< set by @ref PHY_SPEED_10 or @ref PHY_SPEED_100
uint8_t duplex; ///< set by @ref PHY_DUPLEX_HALF @ref PHY_DUPLEX_FULL
//uint8_t power; ///< set by @ref PHY_POWER_NORM or @ref PHY_POWER_DOWN
//uint8_t link; ///< Valid only in CW_GET_PHYSTATUS. set by @ref PHY_LINK_ON or PHY_DUPLEX_OFF
}wiz_PhyConf;
#endif
/**
* @ingroup DATA_TYPE
* It used in setting dhcp_mode of @ref wiz_NetInfo.
*/
typedef enum
{
NETINFO_STATIC = 1, ///< Static IP configuration by manually.
NETINFO_DHCP ///< Dynamic IP configruation from a DHCP sever
}dhcp_mode;
/**
* @ingroup DATA_TYPE
* Network Information for WIZCHIP
*/
typedef struct wiz_NetInfo_t
{
uint8_t mac[6]; ///< Source Mac Address
uint8_t ip[4]; ///< Source IP Address
uint8_t sn[4]; ///< Subnet Mask
uint8_t gw[4]; ///< Gateway IP Address
uint8_t dns[4]; ///< DNS server IP Address
dhcp_mode dhcp; ///< 1 - Static, 2 - DHCP
}wiz_NetInfo;
/**
* @ingroup DATA_TYPE
* Network mode
*/
typedef enum
{
#if _WIZCHIP_ == 5500
NM_FORCEARP = (1<<1), ///< Force to APP send whenever udp data is sent. Valid only in W5500
#endif
NM_WAKEONLAN = (1<<5), ///< Wake On Lan
NM_PINGBLOCK = (1<<4), ///< Block ping-request
NM_PPPOE = (1<<3), ///< PPPoE mode
}netmode_type;
/**
* @ingroup DATA_TYPE
* Used in CN_SET_TIMEOUT or CN_GET_TIMEOUT of @ref ctlwizchip() for timeout configruation.
*/
typedef struct wiz_NetTimeout_t
{
uint8_t retry_cnt; ///< retry count
uint16_t time_100us; ///< time unit 100us
}wiz_NetTimeout;
/**
*@brief Registers call back function for critical section of I/O functions such as
*\ref WIZCHIP_READ, @ref WIZCHIP_WRITE, @ref WIZCHIP_READ_BUF and @ref WIZCHIP_WRITE_BUF.
*@param cris_en : callback function for critical section enter.
*@param cris_ex : callback function for critical section exit.
*@todo Describe @ref WIZCHIP_CRITICAL_ENTER and @ref WIZCHIP_CRITICAL_EXIT marco or register your functions.
*@note If you do not describe or register, default functions(@ref wizchip_cris_enter & @ref wizchip_cris_exit) is called.
*/
void reg_wizchip_cris_cbfunc(void(*cris_en)(void), void(*cris_ex)(void));
/**
*@brief Registers call back function for WIZCHIP select & deselect.
*@param cs_sel : callback function for WIZCHIP select
*@param cs_desel : callback fucntion for WIZCHIP deselect
*@todo Describe @ref wizchip_cs_select and @ref wizchip_cs_deselect function or register your functions.
*@note If you do not describe or register, null function is called.
*/
void reg_wizchip_cs_cbfunc(void(*cs_sel)(void), void(*cs_desel)(void));
/**
*@brief Registers call back function for bus interface.
*@param bus_rb : callback function to read byte data using system bus
*@param bus_wb : callback function to write byte data using system bus
*@todo Describe @ref wizchip_bus_readbyte and @ref wizchip_bus_writebyte function
*or register your functions.
*@note If you do not describe or register, null function is called.
*/
void reg_wizchip_bus_cbfunc(uint8_t (*bus_rb)(uint32_t addr), void (*bus_wb)(uint32_t addr, uint8_t wb));
/**
*@brief Registers call back function for SPI interface.
*@param spi_rb : callback function to read byte usig SPI
*@param spi_wb : callback function to write byte usig SPI
*@todo Describe \ref wizchip_spi_readbyte and \ref wizchip_spi_writebyte function
*or register your functions.
*@note If you do not describe or register, null function is called.
*/
void reg_wizchip_spi_cbfunc(void (*spi_rb)(uint8_t *, uint32_t), void (*spi_wb)(const uint8_t *, uint32_t));
/**
* @ingroup extra_functions
* @brief Controls to the WIZCHIP.
* @details Resets WIZCHIP & internal PHY, Configures PHY mode, Monitor PHY(Link,Speed,Half/Full/Auto),
* controls interrupt & mask and so on.
* @param cwtype : Decides to the control type
* @param arg : arg type is dependent on cwtype.
* @return 0 : Success \n
* -1 : Fail because of invalid \ref ctlwizchip_type or unsupported \ref ctlwizchip_type in WIZCHIP
*/
int8_t ctlwizchip(ctlwizchip_type cwtype, void* arg);
/**
* @ingroup extra_functions
* @brief Controls to network.
* @details Controls to network environment, mode, timeout and so on.
* @param cntype : Input. Decides to the control type
* @param arg : Inout. arg type is dependent on cntype.
* @return -1 : Fail because of invalid \ref ctlnetwork_type or unsupported \ref ctlnetwork_type in WIZCHIP \n
* 0 : Success
*/
int8_t ctlnetwork(ctlnetwork_type cntype, void* arg);
/*
* The following functions are implemented for internal use.
* but You can call these functions for code size reduction instead of ctlwizchip() and ctlnetwork().
*/
/**
* @ingroup extra_functions
* @brief Reset WIZCHIP by softly.
*/
void wizchip_sw_reset(void);
/**
* @ingroup extra_functions
* @brief Initializes WIZCHIP with socket buffer size
* @param txsize Socket tx buffer sizes. If null, initialized the default size 2KB.
* @param rxsize Socket rx buffer sizes. If null, initialized the default size 2KB.
* @return 0 : succcess \n
* -1 : fail. Invalid buffer size
*/
int8_t wizchip_init(uint8_t* txsize, uint8_t* rxsize);
/**
* @ingroup extra_functions
* @brief Clear Interrupt of WIZCHIP.
* @param intr : @ref intr_kind value operated OR. It can type-cast to uint16_t.
*/
void wizchip_clrinterrupt(intr_kind intr);
/**
* @ingroup extra_functions
* @brief Get Interrupt of WIZCHIP.
* @return @ref intr_kind value operated OR. It can type-cast to uint16_t.
*/
intr_kind wizchip_getinterrupt(void);
/**
* @ingroup extra_functions
* @brief Mask or Unmask Interrupt of WIZCHIP.
* @param intr : @ref intr_kind value operated OR. It can type-cast to uint16_t.
*/
void wizchip_setinterruptmask(intr_kind intr);
/**
* @ingroup extra_functions
* @brief Get Interrupt mask of WIZCHIP.
* @return : The operated OR vaule of @ref intr_kind. It can type-cast to uint16_t.
*/
intr_kind wizchip_getinterruptmask(void);
#if _WIZCHIP_ > 5100
int8_t wizphy_getphylink(void); ///< get the link status of phy in WIZCHIP. No use in W5100
int8_t wizphy_getphypmode(void); ///< get the power mode of PHY in WIZCHIP. No use in W5100
#endif
#if _WIZCHIP_ == 5500
void wizphy_reset(void); ///< Reset phy. Vailid only in W5500
/**
* @ingroup extra_functions
* @brief Set the phy information for WIZCHIP without power mode
* @param phyconf : @ref wiz_PhyConf
*/
void wizphy_setphyconf(wiz_PhyConf* phyconf);
/**
* @ingroup extra_functions
* @brief Get phy configuration information.
* @param phyconf : @ref wiz_PhyConf
*/
void wizphy_getphyconf(wiz_PhyConf* phyconf);
/**
* @ingroup extra_functions
* @brief Get phy status.
* @param phyconf : @ref wiz_PhyConf
*/
void wizphy_getphystat(wiz_PhyConf* phyconf);
/**
* @ingroup extra_functions
* @brief set the power mode of phy inside WIZCHIP. Refer to @ref PHYCFGR in W5500, @ref PHYSTATUS in W5200
* @param pmode Settig value of power down mode.
*/
int8_t wizphy_setphypmode(uint8_t pmode);
#endif
/**
* @ingroup extra_functions
* @brief Set the network information for WIZCHIP
* @param pnetinfo : @ref wizNetInfo
*/
void wizchip_setnetinfo(wiz_NetInfo* pnetinfo);
/**
* @ingroup extra_functions
* @brief Get the network information for WIZCHIP
* @param pnetinfo : @ref wizNetInfo
*/
void wizchip_getnetinfo(wiz_NetInfo* pnetinfo);
#if _WIZCHIP_ == 5200 // for W5200 ARP errata
uint8_t *wizchip_getsubn(void);
#endif
/**
* @ingroup extra_functions
* @brief Set the network mode such WOL, PPPoE, Ping Block, and etc.
* @param pnetinfo Value of network mode. Refer to @ref netmode_type.
*/
int8_t wizchip_setnetmode(netmode_type netmode);
/**
* @ingroup extra_functions
* @brief Get the network mode such WOL, PPPoE, Ping Block, and etc.
* @return Value of network mode. Refer to @ref netmode_type.
*/
netmode_type wizchip_getnetmode(void);
/**
* @ingroup extra_functions
* @brief Set retry time value(@ref RTR) and retry count(@ref RCR).
* @details @ref RTR configures the retransmission timeout period and @ref RCR configures the number of time of retransmission.
* @param nettime @ref RTR value and @ref RCR value. Refer to @ref wiz_NetTimeout.
*/
void wizchip_settimeout(wiz_NetTimeout* nettime);
/**
* @ingroup extra_functions
* @brief Get retry time value(@ref RTR) and retry count(@ref RCR).
* @details @ref RTR configures the retransmission timeout period and @ref RCR configures the number of time of retransmission.
* @param nettime @ref RTR value and @ref RCR value. Refer to @ref wiz_NetTimeout.
*/
void wizchip_gettimeout(wiz_NetTimeout* nettime);
#endif // _WIZCHIP_CONF_H_

View File

@ -0,0 +1,979 @@
//*****************************************************************************
//
//! \file dhcp.c
//! \brief DHCP APIs implement file.
//! \details Processig DHCP protocol as DISCOVER, OFFER, REQUEST, ACK, NACK and DECLINE.
//! \version 1.1.0
//! \date 2013/11/18
//! \par Revision history
//! <2018/10/09> Modified by Nick Moore for CircuitPython
//! <2013/11/18> 1st Release
//! <2012/12/20> V1.1.0
//! 1. Optimize code
//! 2. Add reg_dhcp_cbfunc()
//! 3. Add DHCP_stop()
//! 4. Integrate check_DHCP_state() & DHCP_run() to DHCP_run()
//! 5. Don't care system endian
//! 6. Add comments
//! <2012/12/26> V1.1.1
//! 1. Modify variable declaration: dhcp_tick_1s is declared volatile for code optimization
//! \author Eric Jung & MidnightCow
//! \copyright
//!
//! Copyright (c) 2013, WIZnet Co., LTD.
//! All rights reserved.
//!
//! Redistribution and use in source and binary forms, with or without
//! modification, are permitted provided that the following conditions
//! are met:
//!
//! * Redistributions of source code must retain the above copyright
//! notice, this list of conditions and the following disclaimer.
//! * 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.
//! * Neither the name of the <ORGANIZATION> 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 COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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.
//
//*****************************************************************************
//#include "Ethernet/socket.h"
//#include "Internet/DHCP/dhcp.h"
#include "../../ethernet/socket.h"
#include "dhcp.h"
/* If you want to display debug & processing message, Define _DHCP_DEBUG_ in dhcp.h */
#ifdef _DHCP_DEBUG_
#include <stdio.h>
#endif
/* DHCP state machine. */
#define STATE_DHCP_INIT 0 ///< Initialize
#define STATE_DHCP_DISCOVER 1 ///< send DISCOVER and wait OFFER
#define STATE_DHCP_REQUEST 2 ///< send REQEUST and wait ACK or NACK
#define STATE_DHCP_LEASED 3 ///< ReceiveD ACK and IP leased
#define STATE_DHCP_REREQUEST 4 ///< send REQUEST for maintaining leased IP
#define STATE_DHCP_RELEASE 5 ///< No use
#define STATE_DHCP_STOP 6 ///< Stop processing DHCP
#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
/* DHCP message OP code */
#define DHCP_BOOTREQUEST 1 ///< Request Message used in op of @ref RIP_MSG
#define DHCP_BOOTREPLY 2 ///< Reply Message used i op of @ref RIP_MSG
/* DHCP message type */
#define DHCP_DISCOVER 1 ///< DISCOVER message in OPT of @ref RIP_MSG
#define DHCP_OFFER 2 ///< OFFER message in OPT of @ref RIP_MSG
#define DHCP_REQUEST 3 ///< REQUEST message in OPT of @ref RIP_MSG
#define DHCP_DECLINE 4 ///< DECLINE message in OPT of @ref RIP_MSG
#define DHCP_ACK 5 ///< ACK message in OPT of @ref RIP_MSG
#define DHCP_NAK 6 ///< NACK message in OPT of @ref RIP_MSG
#define DHCP_RELEASE 7 ///< RELEASE message in OPT of @ref RIP_MSG. No use
#define DHCP_INFORM 8 ///< INFORM message in OPT of @ref RIP_MSG. No use
#define DHCP_HTYPE10MB 1 ///< Used in type of @ref RIP_MSG
#define DHCP_HTYPE100MB 2 ///< Used in type of @ref RIP_MSG
#define DHCP_HLENETHERNET 6 ///< Used in hlen of @ref RIP_MSG
#define DHCP_HOPS 0 ///< Used in hops of @ref RIP_MSG
#define DHCP_SECS 0 ///< Used in secs of @ref RIP_MSG
#define INFINITE_LEASETIME 0xffffffff ///< Infinite lease time
#define OPT_SIZE 312 /// Max OPT 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)
*/
enum
{
padOption = 0,
subnetMask = 1,
timerOffset = 2,
routersOnSubnet = 3,
timeServer = 4,
nameServer = 5,
dns = 6,
logServer = 7,
cookieServer = 8,
lprServer = 9,
impressServer = 10,
resourceLocationServer = 11,
hostName = 12,
bootFileSize = 13,
meritDumpFile = 14,
domainName = 15,
swapServer = 16,
rootPath = 17,
extentionsPath = 18,
IPforwarding = 19,
nonLocalSourceRouting = 20,
policyFilter = 21,
maxDgramReasmSize = 22,
defaultIPTTL = 23,
pathMTUagingTimeout = 24,
pathMTUplateauTable = 25,
ifMTU = 26,
allSubnetsLocal = 27,
broadcastAddr = 28,
performMaskDiscovery = 29,
maskSupplier = 30,
performRouterDiscovery = 31,
routerSolicitationAddr = 32,
staticRoute = 33,
trailerEncapsulation = 34,
arpCacheTimeout = 35,
ethernetEncapsulation = 36,
tcpDefaultTTL = 37,
tcpKeepaliveInterval = 38,
tcpKeepaliveGarbage = 39,
nisDomainName = 40,
nisServers = 41,
ntpServers = 42,
vendorSpecificInfo = 43,
netBIOSnameServer = 44,
netBIOSdgramDistServer = 45,
netBIOSnodeType = 46,
netBIOSscope = 47,
xFontServer = 48,
xDisplayManager = 49,
dhcpRequestedIPaddr = 50,
dhcpIPaddrLeaseTime = 51,
dhcpOptionOverload = 52,
dhcpMessageType = 53,
dhcpServerIdentifier = 54,
dhcpParamRequest = 55,
dhcpMsg = 56,
dhcpMaxMsgSize = 57,
dhcpT1value = 58,
dhcpT2value = 59,
dhcpClassIdentifier = 60,
dhcpClientIdentifier = 61,
endOption = 255
};
/*
* @brief DHCP message format
*/
typedef struct {
uint8_t op; ///< @ref DHCP_BOOTREQUEST or @ref DHCP_BOOTREPLY
uint8_t htype; ///< @ref DHCP_HTYPE10MB or @ref DHCP_HTYPE100MB
uint8_t hlen; ///< @ref DHCP_HLENETHERNET
uint8_t hops; ///< @ref DHCP_HOPS
uint32_t xid; ///< @ref DHCP_XID This increase one every DHCP transaction.
uint16_t secs; ///< @ref DHCP_SECS
uint16_t flags; ///< @ref DHCP_FLAGSBROADCAST or @ref DHCP_FLAGSUNICAST
uint8_t ciaddr[4]; ///< @ref Request IP to DHCP sever
uint8_t yiaddr[4]; ///< @ref Offered IP from DHCP server
uint8_t siaddr[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 sname[64]; ///< No use
uint8_t file[128]; ///< No use
uint8_t OPT[OPT_SIZE]; ///< Option
} RIP_MSG;
uint8_t DHCP_SOCKET; // Socket number for DHCP
uint8_t DHCP_SIP[4]; // DHCP Server IP address
// Network information from DHCP Server
uint8_t OLD_allocated_ip[4] = {0, }; // Previous IP address
uint8_t DHCP_allocated_ip[4] = {0, }; // IP address from DHCP
uint8_t DHCP_allocated_gw[4] = {0, }; // Gateway address from DHCP
uint8_t DHCP_allocated_sn[4] = {0, }; // Subnet mask from DHCP
uint8_t DHCP_allocated_dns[4] = {0, }; // DNS address from DHCP
int8_t dhcp_state = STATE_DHCP_INIT; // DHCP state
int8_t dhcp_retry_count = 0;
uint32_t dhcp_lease_time = INFINITE_LEASETIME;
volatile uint32_t dhcp_tick_1s = 0; // unit 1 second
uint32_t dhcp_tick_next = DHCP_WAIT_TIME ;
uint32_t DHCP_XID; // Any number
RIP_MSG* pDHCPMSG; // Buffer pointer for DHCP processing
uint8_t HOST_NAME[] = DCHP_HOST_NAME;
uint8_t DHCP_CHADDR[6]; // DHCP Client MAC address.
/* The default callback function */
void default_ip_assign(void);
void default_ip_update(void);
void default_ip_conflict(void);
/* Callback handler */
void (*dhcp_ip_assign)(void) = default_ip_assign; /* handler to be called when the IP address from DHCP server is first assigned */
void (*dhcp_ip_update)(void) = default_ip_update; /* handler to be called when the IP address from DHCP server is updated */
void (*dhcp_ip_conflict)(void) = default_ip_conflict; /* handler to be called when the IP address from DHCP server is conflict */
void reg_dhcp_cbfunc(void(*ip_assign)(void), void(*ip_update)(void), void(*ip_conflict)(void));
/* send DISCOVER message to DHCP server */
void send_DHCP_DISCOVER(void);
/* send REQEUST message to DHCP server */
void send_DHCP_REQUEST(void);
/* send DECLINE message to DHCP server */
void send_DHCP_DECLINE(void);
/* IP conflict check by sending ARP-request to leased IP and wait ARP-response. */
int8_t check_DHCP_leasedIP(void);
/* check the timeout in DHCP process */
uint8_t check_DHCP_timeout(void);
/* Intialize to timeout process. */
void reset_DHCP_timeout(void);
/* Parse message as OFFER and ACK and NACK from DHCP server.*/
int8_t parseDHCPCMSG(void);
/* The default handler of ip assign first */
void default_ip_assign(void)
{
setSIPR(DHCP_allocated_ip);
setSUBR(DHCP_allocated_sn);
setGAR (DHCP_allocated_gw);
}
/* The default handler of ip changed */
void default_ip_update(void)
{
/* WIZchip Software Reset */
setMR(MR_RST);
getMR(); // for delay
default_ip_assign();
setSHAR(DHCP_CHADDR);
}
/* The default handler of ip changed */
void default_ip_conflict(void)
{
// WIZchip Software Reset
setMR(MR_RST);
getMR(); // for delay
setSHAR(DHCP_CHADDR);
}
/* register the call back func. */
void reg_dhcp_cbfunc(void(*ip_assign)(void), void(*ip_update)(void), void(*ip_conflict)(void))
{
dhcp_ip_assign = default_ip_assign;
dhcp_ip_update = default_ip_update;
dhcp_ip_conflict = default_ip_conflict;
if(ip_assign) dhcp_ip_assign = ip_assign;
if(ip_update) dhcp_ip_update = ip_update;
if(ip_conflict) dhcp_ip_conflict = ip_conflict;
}
/* make the common DHCP message */
void makeDHCPMSG(void)
{
uint8_t bk_mac[6];
uint8_t* ptmp;
uint8_t i;
getSHAR(bk_mac);
pDHCPMSG->op = DHCP_BOOTREQUEST;
pDHCPMSG->htype = DHCP_HTYPE10MB;
pDHCPMSG->hlen = DHCP_HLENETHERNET;
pDHCPMSG->hops = DHCP_HOPS;
ptmp = (uint8_t*)(&pDHCPMSG->xid);
*(ptmp+0) = (uint8_t)((DHCP_XID & 0xFF000000) >> 24);
*(ptmp+1) = (uint8_t)((DHCP_XID & 0x00FF0000) >> 16);
*(ptmp+2) = (uint8_t)((DHCP_XID & 0x0000FF00) >> 8);
*(ptmp+3) = (uint8_t)((DHCP_XID & 0x000000FF) >> 0);
pDHCPMSG->secs = DHCP_SECS;
ptmp = (uint8_t*)(&pDHCPMSG->flags);
*(ptmp+0) = (uint8_t)((DHCP_FLAGSBROADCAST & 0xFF00) >> 8);
*(ptmp+1) = (uint8_t)((DHCP_FLAGSBROADCAST & 0x00FF) >> 0);
pDHCPMSG->ciaddr[0] = 0;
pDHCPMSG->ciaddr[1] = 0;
pDHCPMSG->ciaddr[2] = 0;
pDHCPMSG->ciaddr[3] = 0;
pDHCPMSG->yiaddr[0] = 0;
pDHCPMSG->yiaddr[1] = 0;
pDHCPMSG->yiaddr[2] = 0;
pDHCPMSG->yiaddr[3] = 0;
pDHCPMSG->siaddr[0] = 0;
pDHCPMSG->siaddr[1] = 0;
pDHCPMSG->siaddr[2] = 0;
pDHCPMSG->siaddr[3] = 0;
pDHCPMSG->giaddr[0] = 0;
pDHCPMSG->giaddr[1] = 0;
pDHCPMSG->giaddr[2] = 0;
pDHCPMSG->giaddr[3] = 0;
pDHCPMSG->chaddr[0] = DHCP_CHADDR[0];
pDHCPMSG->chaddr[1] = DHCP_CHADDR[1];
pDHCPMSG->chaddr[2] = DHCP_CHADDR[2];
pDHCPMSG->chaddr[3] = DHCP_CHADDR[3];
pDHCPMSG->chaddr[4] = DHCP_CHADDR[4];
pDHCPMSG->chaddr[5] = DHCP_CHADDR[5];
for (i = 6; i < 16; i++) pDHCPMSG->chaddr[i] = 0;
for (i = 0; i < 64; i++) pDHCPMSG->sname[i] = 0;
for (i = 0; i < 128; i++) pDHCPMSG->file[i] = 0;
// MAGIC_COOKIE
pDHCPMSG->OPT[0] = (uint8_t)((MAGIC_COOKIE & 0xFF000000) >> 24);
pDHCPMSG->OPT[1] = (uint8_t)((MAGIC_COOKIE & 0x00FF0000) >> 16);
pDHCPMSG->OPT[2] = (uint8_t)((MAGIC_COOKIE & 0x0000FF00) >> 8);
pDHCPMSG->OPT[3] = (uint8_t) (MAGIC_COOKIE & 0x000000FF) >> 0;
}
/* SEND DHCP DISCOVER */
void send_DHCP_DISCOVER(void)
{
uint16_t i;
uint8_t ip[4];
uint16_t k = 0;
makeDHCPMSG();
k = 4; // because MAGIC_COOKIE already made by makeDHCPMSG()
// Option Request Param
pDHCPMSG->OPT[k++] = dhcpMessageType;
pDHCPMSG->OPT[k++] = 0x01;
pDHCPMSG->OPT[k++] = DHCP_DISCOVER;
// Client identifier
pDHCPMSG->OPT[k++] = dhcpClientIdentifier;
pDHCPMSG->OPT[k++] = 0x07;
pDHCPMSG->OPT[k++] = 0x01;
pDHCPMSG->OPT[k++] = DHCP_CHADDR[0];
pDHCPMSG->OPT[k++] = DHCP_CHADDR[1];
pDHCPMSG->OPT[k++] = DHCP_CHADDR[2];
pDHCPMSG->OPT[k++] = DHCP_CHADDR[3];
pDHCPMSG->OPT[k++] = DHCP_CHADDR[4];
pDHCPMSG->OPT[k++] = DHCP_CHADDR[5];
// host name
pDHCPMSG->OPT[k++] = hostName;
pDHCPMSG->OPT[k++] = 0; // fill zero length of hostname
for(i = 0 ; HOST_NAME[i] != 0; i++)
pDHCPMSG->OPT[k++] = HOST_NAME[i];
pDHCPMSG->OPT[k++] = DHCP_CHADDR[3];
pDHCPMSG->OPT[k++] = DHCP_CHADDR[4];
pDHCPMSG->OPT[k++] = DHCP_CHADDR[5];
pDHCPMSG->OPT[k - (i+3+1)] = i+3; // length of hostname
pDHCPMSG->OPT[k++] = dhcpParamRequest;
pDHCPMSG->OPT[k++] = 0x06; // length of request
pDHCPMSG->OPT[k++] = subnetMask;
pDHCPMSG->OPT[k++] = routersOnSubnet;
pDHCPMSG->OPT[k++] = dns;
pDHCPMSG->OPT[k++] = domainName;
pDHCPMSG->OPT[k++] = dhcpT1value;
pDHCPMSG->OPT[k++] = dhcpT2value;
pDHCPMSG->OPT[k++] = endOption;
for (i = k; i < OPT_SIZE; i++) pDHCPMSG->OPT[i] = 0;
// send broadcasting packet
ip[0] = 255;
ip[1] = 255;
ip[2] = 255;
ip[3] = 255;
#ifdef _DHCP_DEBUG_
printf("> Send DHCP_DISCOVER\r\n");
#endif
WIZCHIP_EXPORT(sendto)(DHCP_SOCKET, (uint8_t *)pDHCPMSG, RIP_MSG_SIZE, ip, DHCP_SERVER_PORT);
}
/* SEND DHCP REQUEST */
void send_DHCP_REQUEST(void)
{
int i;
uint8_t ip[4];
uint16_t k = 0;
makeDHCPMSG();
if(dhcp_state == STATE_DHCP_LEASED || dhcp_state == STATE_DHCP_REREQUEST)
{
*((uint8_t*)(&pDHCPMSG->flags)) = ((DHCP_FLAGSUNICAST & 0xFF00)>> 8);
*((uint8_t*)(&pDHCPMSG->flags)+1) = (DHCP_FLAGSUNICAST & 0x00FF);
pDHCPMSG->ciaddr[0] = DHCP_allocated_ip[0];
pDHCPMSG->ciaddr[1] = DHCP_allocated_ip[1];
pDHCPMSG->ciaddr[2] = DHCP_allocated_ip[2];
pDHCPMSG->ciaddr[3] = DHCP_allocated_ip[3];
ip[0] = DHCP_SIP[0];
ip[1] = DHCP_SIP[1];
ip[2] = DHCP_SIP[2];
ip[3] = DHCP_SIP[3];
}
else
{
ip[0] = 255;
ip[1] = 255;
ip[2] = 255;
ip[3] = 255;
}
k = 4; // because MAGIC_COOKIE already made by makeDHCPMSG()
// Option Request Param.
pDHCPMSG->OPT[k++] = dhcpMessageType;
pDHCPMSG->OPT[k++] = 0x01;
pDHCPMSG->OPT[k++] = DHCP_REQUEST;
pDHCPMSG->OPT[k++] = dhcpClientIdentifier;
pDHCPMSG->OPT[k++] = 0x07;
pDHCPMSG->OPT[k++] = 0x01;
pDHCPMSG->OPT[k++] = DHCP_CHADDR[0];
pDHCPMSG->OPT[k++] = DHCP_CHADDR[1];
pDHCPMSG->OPT[k++] = DHCP_CHADDR[2];
pDHCPMSG->OPT[k++] = DHCP_CHADDR[3];
pDHCPMSG->OPT[k++] = DHCP_CHADDR[4];
pDHCPMSG->OPT[k++] = DHCP_CHADDR[5];
if(ip[3] == 255) // if(dchp_state == STATE_DHCP_LEASED || dchp_state == DHCP_REREQUEST_STATE)
{
pDHCPMSG->OPT[k++] = dhcpRequestedIPaddr;
pDHCPMSG->OPT[k++] = 0x04;
pDHCPMSG->OPT[k++] = DHCP_allocated_ip[0];
pDHCPMSG->OPT[k++] = DHCP_allocated_ip[1];
pDHCPMSG->OPT[k++] = DHCP_allocated_ip[2];
pDHCPMSG->OPT[k++] = DHCP_allocated_ip[3];
pDHCPMSG->OPT[k++] = dhcpServerIdentifier;
pDHCPMSG->OPT[k++] = 0x04;
pDHCPMSG->OPT[k++] = DHCP_SIP[0];
pDHCPMSG->OPT[k++] = DHCP_SIP[1];
pDHCPMSG->OPT[k++] = DHCP_SIP[2];
pDHCPMSG->OPT[k++] = DHCP_SIP[3];
}
// host name
pDHCPMSG->OPT[k++] = hostName;
pDHCPMSG->OPT[k++] = 0; // length of hostname
for(i = 0 ; HOST_NAME[i] != 0; i++)
pDHCPMSG->OPT[k++] = HOST_NAME[i];
pDHCPMSG->OPT[k++] = DHCP_CHADDR[3];
pDHCPMSG->OPT[k++] = DHCP_CHADDR[4];
pDHCPMSG->OPT[k++] = DHCP_CHADDR[5];
pDHCPMSG->OPT[k - (i+3+1)] = i+3; // length of hostname
pDHCPMSG->OPT[k++] = dhcpParamRequest;
pDHCPMSG->OPT[k++] = 0x08;
pDHCPMSG->OPT[k++] = subnetMask;
pDHCPMSG->OPT[k++] = routersOnSubnet;
pDHCPMSG->OPT[k++] = dns;
pDHCPMSG->OPT[k++] = domainName;
pDHCPMSG->OPT[k++] = dhcpT1value;
pDHCPMSG->OPT[k++] = dhcpT2value;
pDHCPMSG->OPT[k++] = performRouterDiscovery;
pDHCPMSG->OPT[k++] = staticRoute;
pDHCPMSG->OPT[k++] = endOption;
for (i = k; i < OPT_SIZE; i++) pDHCPMSG->OPT[i] = 0;
#ifdef _DHCP_DEBUG_
printf("> Send DHCP_REQUEST\r\n");
#endif
WIZCHIP_EXPORT(sendto)(DHCP_SOCKET, (uint8_t *)pDHCPMSG, RIP_MSG_SIZE, ip, DHCP_SERVER_PORT);
}
/* SEND DHCP DHCPDECLINE */
void send_DHCP_DECLINE(void)
{
int i;
uint8_t ip[4];
uint16_t k = 0;
makeDHCPMSG();
k = 4; // because MAGIC_COOKIE already made by makeDHCPMSG()
*((uint8_t*)(&pDHCPMSG->flags)) = ((DHCP_FLAGSUNICAST & 0xFF00)>> 8);
*((uint8_t*)(&pDHCPMSG->flags)+1) = (DHCP_FLAGSUNICAST & 0x00FF);
// Option Request Param.
pDHCPMSG->OPT[k++] = dhcpMessageType;
pDHCPMSG->OPT[k++] = 0x01;
pDHCPMSG->OPT[k++] = DHCP_DECLINE;
pDHCPMSG->OPT[k++] = dhcpClientIdentifier;
pDHCPMSG->OPT[k++] = 0x07;
pDHCPMSG->OPT[k++] = 0x01;
pDHCPMSG->OPT[k++] = DHCP_CHADDR[0];
pDHCPMSG->OPT[k++] = DHCP_CHADDR[1];
pDHCPMSG->OPT[k++] = DHCP_CHADDR[2];
pDHCPMSG->OPT[k++] = DHCP_CHADDR[3];
pDHCPMSG->OPT[k++] = DHCP_CHADDR[4];
pDHCPMSG->OPT[k++] = DHCP_CHADDR[5];
pDHCPMSG->OPT[k++] = dhcpRequestedIPaddr;
pDHCPMSG->OPT[k++] = 0x04;
pDHCPMSG->OPT[k++] = DHCP_allocated_ip[0];
pDHCPMSG->OPT[k++] = DHCP_allocated_ip[1];
pDHCPMSG->OPT[k++] = DHCP_allocated_ip[2];
pDHCPMSG->OPT[k++] = DHCP_allocated_ip[3];
pDHCPMSG->OPT[k++] = dhcpServerIdentifier;
pDHCPMSG->OPT[k++] = 0x04;
pDHCPMSG->OPT[k++] = DHCP_SIP[0];
pDHCPMSG->OPT[k++] = DHCP_SIP[1];
pDHCPMSG->OPT[k++] = DHCP_SIP[2];
pDHCPMSG->OPT[k++] = DHCP_SIP[3];
pDHCPMSG->OPT[k++] = endOption;
for (i = k; i < OPT_SIZE; i++) pDHCPMSG->OPT[i] = 0;
//send broadcasting packet
ip[0] = 0xFF;
ip[1] = 0xFF;
ip[2] = 0xFF;
ip[3] = 0xFF;
#ifdef _DHCP_DEBUG_
printf("\r\n> Send DHCP_DECLINE\r\n");
#endif
WIZCHIP_EXPORT(sendto)(DHCP_SOCKET, (uint8_t *)pDHCPMSG, RIP_MSG_SIZE, ip, DHCP_SERVER_PORT);
}
/* PARSE REPLY pDHCPMSG */
int8_t parseDHCPMSG(void)
{
uint8_t svr_addr[6];
uint16_t svr_port;
uint16_t len;
uint8_t * p;
uint8_t * e;
uint8_t type;
uint8_t opt_len;
if((len = getSn_RX_RSR(DHCP_SOCKET)) > 0)
{
len = WIZCHIP_EXPORT(recvfrom)(DHCP_SOCKET, (uint8_t *)pDHCPMSG, len, svr_addr, &svr_port);
#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);
#endif
}
else return 0;
if (svr_port == DHCP_SERVER_PORT) {
// compare mac address
if ( (pDHCPMSG->chaddr[0] != DHCP_CHADDR[0]) || (pDHCPMSG->chaddr[1] != DHCP_CHADDR[1]) ||
(pDHCPMSG->chaddr[2] != DHCP_CHADDR[2]) || (pDHCPMSG->chaddr[3] != DHCP_CHADDR[3]) ||
(pDHCPMSG->chaddr[4] != DHCP_CHADDR[4]) || (pDHCPMSG->chaddr[5] != DHCP_CHADDR[5]) )
return 0;
type = 0;
p = (uint8_t *)(&pDHCPMSG->op);
p = p + 240; // 240 = sizeof(RIP_MSG) + MAGIC_COOKIE size in RIP_MSG.opt - sizeof(RIP_MSG.opt)
e = p + (len - 240);
while ( p < e ) {
switch ( *p ) {
case endOption :
p = e; // for break while(p < e)
break;
case padOption :
p++;
break;
case dhcpMessageType :
p++;
p++;
type = *p++;
break;
case subnetMask :
p++;
p++;
DHCP_allocated_sn[0] = *p++;
DHCP_allocated_sn[1] = *p++;
DHCP_allocated_sn[2] = *p++;
DHCP_allocated_sn[3] = *p++;
break;
case routersOnSubnet :
p++;
opt_len = *p++;
DHCP_allocated_gw[0] = *p++;
DHCP_allocated_gw[1] = *p++;
DHCP_allocated_gw[2] = *p++;
DHCP_allocated_gw[3] = *p++;
p = p + (opt_len - 4);
break;
case dns :
p++;
opt_len = *p++;
DHCP_allocated_dns[0] = *p++;
DHCP_allocated_dns[1] = *p++;
DHCP_allocated_dns[2] = *p++;
DHCP_allocated_dns[3] = *p++;
p = p + (opt_len - 4);
break;
case dhcpIPaddrLeaseTime :
p++;
opt_len = *p++;
dhcp_lease_time = *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_
dhcp_lease_time = 10;
#endif
break;
case dhcpServerIdentifier :
p++;
opt_len = *p++;
DHCP_SIP[0] = *p++;
DHCP_SIP[1] = *p++;
DHCP_SIP[2] = *p++;
DHCP_SIP[3] = *p++;
break;
default :
p++;
opt_len = *p++;
p += opt_len;
break;
} // switch
} // while
} // if
return type;
}
uint8_t DHCP_run(void)
{
uint8_t type;
uint8_t ret;
if(dhcp_state == STATE_DHCP_STOP) return DHCP_STOPPED;
if(getSn_SR(DHCP_SOCKET) != SOCK_UDP)
WIZCHIP_EXPORT(socket)(DHCP_SOCKET, Sn_MR_UDP, DHCP_CLIENT_PORT, 0x00);
ret = DHCP_RUNNING;
type = parseDHCPMSG();
switch ( dhcp_state ) {
case STATE_DHCP_INIT :
DHCP_allocated_ip[0] = 0;
DHCP_allocated_ip[1] = 0;
DHCP_allocated_ip[2] = 0;
DHCP_allocated_ip[3] = 0;
send_DHCP_DISCOVER();
dhcp_state = STATE_DHCP_DISCOVER;
break;
case STATE_DHCP_DISCOVER :
if (type == DHCP_OFFER){
#ifdef _DHCP_DEBUG_
printf("> Receive DHCP_OFFER\r\n");
#endif
DHCP_allocated_ip[0] = pDHCPMSG->yiaddr[0];
DHCP_allocated_ip[1] = pDHCPMSG->yiaddr[1];
DHCP_allocated_ip[2] = pDHCPMSG->yiaddr[2];
DHCP_allocated_ip[3] = pDHCPMSG->yiaddr[3];
send_DHCP_REQUEST();
dhcp_state = STATE_DHCP_REQUEST;
} else ret = check_DHCP_timeout();
break;
case STATE_DHCP_REQUEST :
if (type == DHCP_ACK) {
#ifdef _DHCP_DEBUG_
printf("> Receive DHCP_ACK\r\n");
#endif
if (check_DHCP_leasedIP()) {
// Network info assignment from DHCP
dhcp_ip_assign();
reset_DHCP_timeout();
dhcp_state = STATE_DHCP_LEASED;
} else {
// IP address conflict occurred
reset_DHCP_timeout();
dhcp_ip_conflict();
dhcp_state = STATE_DHCP_INIT;
}
} else if (type == DHCP_NAK) {
#ifdef _DHCP_DEBUG_
printf("> Receive DHCP_NACK\r\n");
#endif
reset_DHCP_timeout();
dhcp_state = STATE_DHCP_DISCOVER;
} else ret = check_DHCP_timeout();
break;
case STATE_DHCP_LEASED :
ret = DHCP_IP_LEASED;
if ((dhcp_lease_time != INFINITE_LEASETIME) && ((dhcp_lease_time/2) < dhcp_tick_1s)) {
#ifdef _DHCP_DEBUG_
printf("> Maintains the IP address \r\n");
#endif
type = 0;
OLD_allocated_ip[0] = DHCP_allocated_ip[0];
OLD_allocated_ip[1] = DHCP_allocated_ip[1];
OLD_allocated_ip[2] = DHCP_allocated_ip[2];
OLD_allocated_ip[3] = DHCP_allocated_ip[3];
DHCP_XID++;
send_DHCP_REQUEST();
reset_DHCP_timeout();
dhcp_state = STATE_DHCP_REREQUEST;
}
break;
case STATE_DHCP_REREQUEST :
ret = DHCP_IP_LEASED;
if (type == DHCP_ACK) {
dhcp_retry_count = 0;
if (OLD_allocated_ip[0] != DHCP_allocated_ip[0] ||
OLD_allocated_ip[1] != DHCP_allocated_ip[1] ||
OLD_allocated_ip[2] != DHCP_allocated_ip[2] ||
OLD_allocated_ip[3] != DHCP_allocated_ip[3])
{
ret = DHCP_IP_CHANGED;
dhcp_ip_update();
#ifdef _DHCP_DEBUG_
printf(">IP changed.\r\n");
#endif
}
#ifdef _DHCP_DEBUG_
else printf(">IP is continued.\r\n");
#endif
reset_DHCP_timeout();
dhcp_state = STATE_DHCP_LEASED;
} else if (type == DHCP_NAK) {
#ifdef _DHCP_DEBUG_
printf("> Receive DHCP_NACK, Failed to maintain ip\r\n");
#endif
reset_DHCP_timeout();
dhcp_state = STATE_DHCP_DISCOVER;
} else ret = check_DHCP_timeout();
break;
default :
break;
}
return ret;
}
void DHCP_stop(void)
{
WIZCHIP_EXPORT(close)(DHCP_SOCKET);
dhcp_state = STATE_DHCP_STOP;
}
uint8_t check_DHCP_timeout(void)
{
uint8_t ret = DHCP_RUNNING;
if (dhcp_retry_count < MAX_DHCP_RETRY) {
if (dhcp_tick_next < dhcp_tick_1s) {
switch ( dhcp_state ) {
case STATE_DHCP_DISCOVER :
// printf("<<timeout>> state : STATE_DHCP_DISCOVER\r\n");
send_DHCP_DISCOVER();
break;
case STATE_DHCP_REQUEST :
// printf("<<timeout>> state : STATE_DHCP_REQUEST\r\n");
send_DHCP_REQUEST();
break;
case STATE_DHCP_REREQUEST :
// printf("<<timeout>> state : STATE_DHCP_REREQUEST\r\n");
send_DHCP_REQUEST();
break;
default :
break;
}
dhcp_tick_1s = 0;
dhcp_tick_next = dhcp_tick_1s + DHCP_WAIT_TIME;
dhcp_retry_count++;
}
} else { // timeout occurred
switch(dhcp_state) {
case STATE_DHCP_DISCOVER:
dhcp_state = STATE_DHCP_INIT;
ret = DHCP_FAILED;
break;
case STATE_DHCP_REQUEST:
case STATE_DHCP_REREQUEST:
send_DHCP_DISCOVER();
dhcp_state = STATE_DHCP_DISCOVER;
break;
default :
break;
}
reset_DHCP_timeout();
}
return ret;
}
int8_t check_DHCP_leasedIP(void)
{
uint8_t tmp;
int32_t ret;
//WIZchip RCR value changed for ARP Timeout count control
tmp = getRCR();
setRCR(0x03);
// IP conflict detection : ARP request - ARP reply
// Broadcasting ARP Request for check the IP conflict using UDP sendto() function
ret = WIZCHIP_EXPORT(sendto)(DHCP_SOCKET, (uint8_t *)"CHECK_IP_CONFLICT", 17, DHCP_allocated_ip, 5000);
// RCR value restore
setRCR(tmp);
if(ret == SOCKERR_TIMEOUT) {
// UDP send Timeout occurred : allocated IP address is unique, DHCP Success
#ifdef _DHCP_DEBUG_
printf("\r\n> Check leased IP - OK\r\n");
#endif
return 1;
} else {
// Received ARP reply or etc : IP address conflict occur, DHCP Failed
send_DHCP_DECLINE();
ret = dhcp_tick_1s;
while((dhcp_tick_1s - ret) < 2) ; // wait for 1s over; wait to complete to send DECLINE message;
return 0;
}
}
void DHCP_init(uint8_t s, DHCP_INIT_BUFFER_TYPE* buf)
{
uint8_t zeroip[4] = {0,0,0,0};
getSHAR(DHCP_CHADDR);
if((DHCP_CHADDR[0] | DHCP_CHADDR[1] | DHCP_CHADDR[2] | DHCP_CHADDR[3] | DHCP_CHADDR[4] | DHCP_CHADDR[5]) == 0x00)
{
// assign temporary mac address, you should be set SHAR before call this function.
DHCP_CHADDR[0] = 0x00;
DHCP_CHADDR[1] = 0x08;
DHCP_CHADDR[2] = 0xdc;
DHCP_CHADDR[3] = 0x00;
DHCP_CHADDR[4] = 0x00;
DHCP_CHADDR[5] = 0x00;
setSHAR(DHCP_CHADDR);
}
DHCP_SOCKET = s; // SOCK_DHCP
pDHCPMSG = (RIP_MSG*)buf;
DHCP_XID = 0x12345678;
// WIZchip Netinfo Clear
setSIPR(zeroip);
setSIPR(zeroip);
setGAR(zeroip);
reset_DHCP_timeout();
dhcp_state = STATE_DHCP_INIT;
}
/* Rset the DHCP timeout count and retry count. */
void reset_DHCP_timeout(void)
{
dhcp_tick_1s = 0;
dhcp_tick_next = DHCP_WAIT_TIME;
dhcp_retry_count = 0;
}
void DHCP_time_handler(void)
{
dhcp_tick_1s++;
}
void getIPfromDHCP(uint8_t* ip)
{
ip[0] = DHCP_allocated_ip[0];
ip[1] = DHCP_allocated_ip[1];
ip[2] = DHCP_allocated_ip[2];
ip[3] = DHCP_allocated_ip[3];
}
void getGWfromDHCP(uint8_t* ip)
{
ip[0] =DHCP_allocated_gw[0];
ip[1] =DHCP_allocated_gw[1];
ip[2] =DHCP_allocated_gw[2];
ip[3] =DHCP_allocated_gw[3];
}
void getSNfromDHCP(uint8_t* ip)
{
ip[0] = DHCP_allocated_sn[0];
ip[1] = DHCP_allocated_sn[1];
ip[2] = DHCP_allocated_sn[2];
ip[3] = DHCP_allocated_sn[3];
}
void getDNSfromDHCP(uint8_t* ip)
{
ip[0] = DHCP_allocated_dns[0];
ip[1] = DHCP_allocated_dns[1];
ip[2] = DHCP_allocated_dns[2];
ip[3] = DHCP_allocated_dns[3];
}
uint32_t getDHCPLeasetime(void)
{
return dhcp_lease_time;
}

View File

@ -0,0 +1,152 @@
//*****************************************************************************
//
//! \file dhcp.h
//! \brief DHCP APIs Header file.
//! \details Processig DHCP protocol as DISCOVER, OFFER, REQUEST, ACK, NACK and DECLINE.
//! \version 1.1.0
//! \date 2013/11/18
//! \par Revision history
//! <2013/11/18> 1st Release
//! <2012/12/20> V1.1.0
//! 1. Move unreferenced DEFINE to dhcp.c
//! <2012/12/26> V1.1.1
//! \author Eric Jung & MidnightCow
//! \copyright
//!
//! Copyright (c) 2013, WIZnet Co., LTD.
//! All rights reserved.
//!
//! Redistribution and use in source and binary forms, with or without
//! modification, are permitted provided that the following conditions
//! are met:
//!
//! * Redistributions of source code must retain the above copyright
//! notice, this list of conditions and the following disclaimer.
//! * 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.
//! * Neither the name of the <ORGANIZATION> 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 COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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.
//
//*****************************************************************************
#ifndef _DHCP_H_
#define _DHCP_H_
/*
* @brief
* @details If you want to display debug & processing message, Define _DHCP_DEBUG_
* @note If defined, it depends on <stdio.h>
*/
//#define _DHCP_DEBUG_
/* Retry to processing DHCP */
#define MAX_DHCP_RETRY 2 ///< Maximum retry count
#define DHCP_WAIT_TIME 3 ///< Wait Time 3s (was 10s)
/* UDP port numbers for DHCP */
#define DHCP_SERVER_PORT 67 ///< DHCP server port number
#define DHCP_CLIENT_PORT 68 ///< DHCP client port number
#define MAGIC_COOKIE 0x63825363 ///< Any number. You can be modified it any number
#define DCHP_HOST_NAME "WIZnet\0"
/*
* @brief return value of @ref DHCP_run()
*/
enum
{
DHCP_FAILED = 0, ///< Processing Fail
DHCP_RUNNING, ///< Processing DHCP protocol
DHCP_IP_ASSIGN, ///< First Occupy IP from DHPC server (if cbfunc == null, act as default default_ip_assign)
DHCP_IP_CHANGED, ///< Change IP address by new IP address from DHCP (if cbfunc == null, act as default default_ip_update)
DHCP_IP_LEASED, ///< Stand by
DHCP_STOPPED ///< Stop processing DHCP protocol
};
#define DHCP_INIT_BUFFER_TYPE uint32_t
#define DHCP_INIT_BUFFER_SIZE (137)
/*
* @brief DHCP client initialization (outside of the main loop)
* @param s - socket number
* @param buf - buffer for processing DHCP message
*/
void DHCP_init(uint8_t s, DHCP_INIT_BUFFER_TYPE* buf);
/*
* @brief DHCP 1s Tick Timer handler
* @note SHOULD BE register to your system 1s Tick timer handler
*/
void DHCP_time_handler(void);
/*
* @brief Register call back function
* @param ip_assign - callback func when IP is assigned from DHCP server first
* @param ip_update - callback func when IP is changed
* @prarm ip_conflict - callback func when the assigned IP is conflict with others.
*/
void reg_dhcp_cbfunc(void(*ip_assign)(void), void(*ip_update)(void), void(*ip_conflict)(void));
/*
* @brief DHCP client in the main loop
* @return The value is as the follow \n
* @ref DHCP_FAILED \n
* @ref DHCP_RUNNING \n
* @ref DHCP_IP_ASSIGN \n
* @ref DHCP_IP_CHANGED \n
* @ref DHCP_IP_LEASED \n
* @ref DHCP_STOPPED \n
*
* @note This function is always called by you main task.
*/
uint8_t DHCP_run(void);
/*
* @brief Stop DHCP processing
* @note If you want to restart. call DHCP_init() and DHCP_run()
*/
void DHCP_stop(void);
/* Get Network information assigned from DHCP server */
/*
* @brief Get IP address
* @param ip - IP address to be returned
*/
void getIPfromDHCP(uint8_t* ip);
/*
* @brief Get Gateway address
* @param ip - Gateway address to be returned
*/
void getGWfromDHCP(uint8_t* ip);
/*
* @brief Get Subnet mask value
* @param ip - Subnet mask to be returned
*/
void getSNfromDHCP(uint8_t* ip);
/*
* @brief Get DNS address
* @param ip - DNS address to be returned
*/
void getDNSfromDHCP(uint8_t* ip);
/*
* @brief Get the leased time by DHCP sever
* @return unit 1s
*/
uint32_t getDHCPLeasetime(void);
#endif /* _DHCP_H_ */

View File

@ -0,0 +1,572 @@
//*****************************************************************************
//
//! \file dns.c
//! \brief DNS APIs Implement file.
//! \details Send DNS query & Receive DNS reponse. \n
//! It depends on stdlib.h & string.h in ansi-c library
//! \version 1.1.0
//! \date 2013/11/18
//! \par Revision history
//! <2013/10/21> 1st Release
//! <2013/12/20> V1.1.0
//! 1. Remove secondary DNS server in DNS_run
//! If 1st DNS_run failed, call DNS_run with 2nd DNS again
//! 2. DNS_timerHandler -> DNS_time_handler
//! 3. Remove the unused define
//! 4. Integrated dns.h dns.c & dns_parse.h dns_parse.c into dns.h & dns.c
//! <2013/12/20> V1.1.0
//! <2018/10/04> Modified HAL_GetTick for use with CircuitPython by Nick Moore
//!
//! \author Eric Jung & MidnightCow
//! \copyright
//!
//! Copyright (c) 2013, WIZnet Co., LTD.
//! All rights reserved.
//!
//! Redistribution and use in source and binary forms, with or without
//! modification, are permitted provided that the following conditions
//! are met:
//!
//! * Redistributions of source code must retain the above copyright
//! notice, this list of conditions and the following disclaimer.
//! * 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.
//! * Neither the name of the <ORGANIZATION> 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 COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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.
//
//*****************************************************************************
#include <string.h>
#include <stdlib.h>
#include "tick.h"
//#include "Ethernet/socket.h"
//#include "Internet/DNS/dns.h"
#include "../../ethernet/socket.h"
#include "dns.h"
#ifdef _DNS_DEBUG_
#include <stdio.h>
#endif
#define INITRTT 2000L /* Initial smoothed response time */
#define MAXCNAME (MAX_DOMAIN_NAME + (MAX_DOMAIN_NAME>>1)) /* Maximum amount of cname recursion */
#define TYPE_A 1 /* Host address */
#define TYPE_NS 2 /* Name server */
#define TYPE_MD 3 /* Mail destination (obsolete) */
#define TYPE_MF 4 /* Mail forwarder (obsolete) */
#define TYPE_CNAME 5 /* Canonical name */
#define TYPE_SOA 6 /* Start of Authority */
#define TYPE_MB 7 /* Mailbox name (experimental) */
#define TYPE_MG 8 /* Mail group member (experimental) */
#define TYPE_MR 9 /* Mail rename name (experimental) */
#define TYPE_NULL 10 /* Null (experimental) */
#define TYPE_WKS 11 /* Well-known sockets */
#define TYPE_PTR 12 /* Pointer record */
#define TYPE_HINFO 13 /* Host information */
#define TYPE_MINFO 14 /* Mailbox information (experimental)*/
#define TYPE_MX 15 /* Mail exchanger */
#define TYPE_TXT 16 /* Text strings */
#define TYPE_ANY 255 /* Matches any type */
#define CLASS_IN 1 /* The ARPA Internet */
/* Round trip timing parameters */
#define AGAIN 8 /* Average RTT gain = 1/8 */
#define LAGAIN 3 /* Log2(AGAIN) */
#define DGAIN 4 /* Mean deviation gain = 1/4 */
#define LDGAIN 2 /* log2(DGAIN) */
/* Header for all domain messages */
struct dhdr
{
uint16_t id; /* Identification */
uint8_t qr; /* Query/Response */
#define QUERY 0
#define RESPONSE 1
uint8_t opcode;
#define IQUERY 1
uint8_t aa; /* Authoratative answer */
uint8_t tc; /* Truncation */
uint8_t rd; /* Recursion desired */
uint8_t ra; /* Recursion available */
uint8_t rcode; /* Response code */
#define NO_ERROR 0
#define FORMAT_ERROR 1
#define SERVER_FAIL 2
#define NAME_ERROR 3
#define NOT_IMPL 4
#define REFUSED 5
uint16_t qdcount; /* Question count */
uint16_t ancount; /* Answer count */
uint16_t nscount; /* Authority (name server) count */
uint16_t arcount; /* Additional record count */
};
uint8_t* pDNSMSG; // DNS message buffer
uint8_t DNS_SOCKET; // SOCKET number for DNS
uint16_t DNS_MSGID; // DNS message ID
uint32_t HAL_GetTick(void) {
return ticks_ms;
}
uint32_t hal_sys_tick;
/* converts uint16_t from network buffer to a host byte order integer. */
uint16_t get16(uint8_t * s)
{
uint16_t i;
i = *s++ << 8;
i = i + *s;
return i;
}
/* copies uint16_t to the network buffer with network byte order. */
uint8_t * put16(uint8_t * s, uint16_t i)
{
*s++ = i >> 8;
*s++ = i;
return s;
}
/*
* CONVERT A DOMAIN NAME TO THE HUMAN-READABLE FORM
*
* Description : This function converts a compressed domain name to the human-readable form
* Arguments : msg - is a pointer to the reply message
* compressed - is a pointer to the domain name in reply message.
* buf - is a pointer to the buffer for the human-readable form name.
* len - is the MAX. size of buffer.
* Returns : the length of compressed message
*/
int parse_name(uint8_t * msg, uint8_t * compressed, char * buf, int16_t len)
{
uint16_t slen; /* Length of current segment */
uint8_t * cp;
int clen = 0; /* Total length of compressed name */
int indirect = 0; /* Set if indirection encountered */
int nseg = 0; /* Total number of segments in name */
cp = compressed;
for (;;)
{
slen = *cp++; /* Length of this segment */
if (!indirect) clen++;
if ((slen & 0xc0) == 0xc0)
{
if (!indirect)
clen++;
indirect = 1;
/* Follow indirection */
cp = &msg[((slen & 0x3f)<<8) + *cp];
slen = *cp++;
}
if (slen == 0) /* zero length == all done */
break;
len -= slen + 1;
if (len < 0) return -1;
if (!indirect) clen += slen;
while (slen-- != 0) *buf++ = (char)*cp++;
*buf++ = '.';
nseg++;
}
if (nseg == 0)
{
/* Root name; represent as single dot */
*buf++ = '.';
len--;
}
*buf++ = '\0';
len--;
return clen; /* Length of compressed message */
}
/*
* PARSE QUESTION SECTION
*
* Description : This function parses the question record of the reply message.
* Arguments : msg - is a pointer to the reply message
* cp - is a pointer to the question record.
* Returns : a pointer the to next record.
*/
uint8_t * dns_question(uint8_t * msg, uint8_t * cp)
{
int len;
char name[MAXCNAME];
len = parse_name(msg, cp, name, MAXCNAME);
if (len == -1) return 0;
cp += len;
cp += 2; /* type */
cp += 2; /* class */
return cp;
}
/*
* PARSE ANSER SECTION
*
* Description : This function parses the answer record of the reply message.
* Arguments : msg - is a pointer to the reply message
* cp - is a pointer to the answer record.
* Returns : a pointer the to next record.
*/
uint8_t * dns_answer(uint8_t * msg, uint8_t * cp, uint8_t * ip_from_dns)
{
int len, type;
char name[MAXCNAME];
len = parse_name(msg, cp, name, MAXCNAME);
if (len == -1) return 0;
cp += len;
type = get16(cp);
cp += 2; /* type */
cp += 2; /* class */
cp += 4; /* ttl */
cp += 2; /* len */
switch (type)
{
case TYPE_A:
/* Just read the address directly into the structure */
ip_from_dns[0] = *cp++;
ip_from_dns[1] = *cp++;
ip_from_dns[2] = *cp++;
ip_from_dns[3] = *cp++;
break;
case TYPE_CNAME:
case TYPE_MB:
case TYPE_MG:
case TYPE_MR:
case TYPE_NS:
case TYPE_PTR:
/* These types all consist of a single domain name */
/* convert it to ASCII format */
len = parse_name(msg, cp, name, MAXCNAME);
if (len == -1) return 0;
cp += len;
break;
case TYPE_HINFO:
len = *cp++;
cp += len;
len = *cp++;
cp += len;
break;
case TYPE_MX:
cp += 2;
/* Get domain name of exchanger */
len = parse_name(msg, cp, name, MAXCNAME);
if (len == -1) return 0;
cp += len;
break;
case TYPE_SOA:
/* Get domain name of name server */
len = parse_name(msg, cp, name, MAXCNAME);
if (len == -1) return 0;
cp += len;
/* Get domain name of responsible person */
len = parse_name(msg, cp, name, MAXCNAME);
if (len == -1) return 0;
cp += len;
cp += 4;
cp += 4;
cp += 4;
cp += 4;
cp += 4;
break;
case TYPE_TXT:
/* Just stash */
break;
default:
/* Ignore */
break;
}
return cp;
}
/*
* PARSE THE DNS REPLY
*
* Description : This function parses the reply message from DNS server.
* Arguments : dhdr - is a pointer to the header for DNS message
* buf - is a pointer to the reply message.
* len - is the size of reply message.
* Returns : -1 - Domain name length is too big
* 0 - Fail (Timeout or parse error)
* 1 - Success,
*/
int8_t parseDNSMSG(struct dhdr * pdhdr, uint8_t * pbuf, uint8_t * ip_from_dns)
{
uint16_t tmp;
uint16_t i;
uint8_t * msg;
uint8_t * cp;
msg = pbuf;
memset(pdhdr, 0, sizeof(*pdhdr));
pdhdr->id = get16(&msg[0]);
tmp = get16(&msg[2]);
if (tmp & 0x8000) pdhdr->qr = 1;
pdhdr->opcode = (tmp >> 11) & 0xf;
if (tmp & 0x0400) pdhdr->aa = 1;
if (tmp & 0x0200) pdhdr->tc = 1;
if (tmp & 0x0100) pdhdr->rd = 1;
if (tmp & 0x0080) pdhdr->ra = 1;
pdhdr->rcode = tmp & 0xf;
pdhdr->qdcount = get16(&msg[4]);
pdhdr->ancount = get16(&msg[6]);
pdhdr->nscount = get16(&msg[8]);
pdhdr->arcount = get16(&msg[10]);
/* Now parse the variable length sections */
cp = &msg[12];
/* Question section */
for (i = 0; i < pdhdr->qdcount; i++)
{
cp = dns_question(msg, cp);
if(!cp)
{
#ifdef _DNS_DEBUG_
printf("MAX_DOMAIN_NAME is too small, it should be redefined in dns.h\r\n");
#endif
return -1;
}
}
/* Answer section */
for (i = 0; i < pdhdr->ancount; i++)
{
cp = dns_answer(msg, cp, ip_from_dns);
if(!cp)
{
#ifdef _DNS_DEBUG_
printf("MAX_DOMAIN_NAME is too small, it should be redefined in dns.h\r\n");
#endif
return -1;
}
}
/* Name server (authority) section */
for (i = 0; i < pdhdr->nscount; i++)
{
;
}
/* Additional section */
for (i = 0; i < pdhdr->arcount; i++)
{
;
}
if(pdhdr->rcode == 0) return 1; // No error
else return 0;
}
/*
* MAKE DNS QUERY MESSAGE
*
* Description : This function makes DNS query message.
* Arguments : op - Recursion desired
* name - is a pointer to the domain name.
* buf - is a pointer to the buffer for DNS message.
* len - is the MAX. size of buffer.
* Returns : the pointer to the DNS message.
*/
int16_t dns_makequery(uint16_t op, char * name, uint8_t * buf, uint16_t len)
{
uint8_t *cp;
char *cp1;
char sname[MAXCNAME];
char *dname;
uint16_t p;
uint16_t dlen;
cp = buf;
DNS_MSGID++;
cp = put16(cp, DNS_MSGID);
p = (op << 11) | 0x0100; /* Recursion desired */
cp = put16(cp, p);
cp = put16(cp, 1);
cp = put16(cp, 0);
cp = put16(cp, 0);
cp = put16(cp, 0);
strcpy(sname, name);
dname = sname;
dlen = strlen(dname);
for (;;)
{
/* Look for next dot */
cp1 = strchr(dname, '.');
if (cp1 != NULL) len = cp1 - dname; /* More to come */
else len = dlen; /* Last component */
*cp++ = len; /* Write length of component */
if (len == 0) break;
/* Copy component up to (but not including) dot */
memcpy(cp, dname, len);
cp += len;
if (cp1 == NULL)
{
*cp++ = 0; /* Last one; write null and finish */
break;
}
dname += len+1;
dlen -= len+1;
}
cp = put16(cp, 0x0001); /* type */
cp = put16(cp, 0x0001); /* class */
return ((int16_t)((uint32_t)(cp) - (uint32_t)(buf)));
}
/*
* CHECK DNS TIMEOUT
*
* Description : This function check the DNS timeout
* Arguments : None.
* Returns : -1 - timeout occurred, 0 - timer over, but no timeout, 1 - no timer over, no timeout occur
* Note : timeout : retry count and timer both over.
*/
int8_t check_DNS_timeout(void)
{
static uint8_t retry_count;
uint32_t tick = HAL_GetTick();
if(tick - hal_sys_tick >= DNS_WAIT_TIME * 1000)
{
hal_sys_tick = tick;
if(retry_count >= MAX_DNS_RETRY) {
retry_count = 0;
return -1; // timeout occurred
}
retry_count++;
return 0; // timer over, but no timeout
}
return 1; // no timer over, no timeout occur
}
/* DNS CLIENT INIT */
void DNS_init(uint8_t s, uint8_t * buf)
{
DNS_SOCKET = s; // SOCK_DNS
pDNSMSG = buf; // User's shared buffer
DNS_MSGID = DNS_MSG_ID;
}
/* DNS CLIENT RUN */
int8_t DNS_run(uint8_t * dns_ip, uint8_t * name, uint8_t * ip_from_dns)
{
int8_t ret;
struct dhdr dhp;
uint8_t ip[4];
uint16_t len, port;
int8_t ret_check_timeout;
hal_sys_tick = HAL_GetTick();
// Socket open
WIZCHIP_EXPORT(socket)(DNS_SOCKET, Sn_MR_UDP, 0, 0);
#ifdef _DNS_DEBUG_
printf("> DNS Query to DNS Server : %d.%d.%d.%d\r\n", dns_ip[0], dns_ip[1], dns_ip[2], dns_ip[3]);
#endif
len = dns_makequery(0, (char *)name, pDNSMSG, MAX_DNS_BUF_SIZE);
WIZCHIP_EXPORT(sendto)(DNS_SOCKET, pDNSMSG, len, dns_ip, IPPORT_DOMAIN);
while (1)
{
if ((len = getSn_RX_RSR(DNS_SOCKET)) > 0)
{
if (len > MAX_DNS_BUF_SIZE) len = MAX_DNS_BUF_SIZE;
len = WIZCHIP_EXPORT(recvfrom)(DNS_SOCKET, pDNSMSG, len, ip, &port);
#ifdef _DNS_DEBUG_
printf("> Receive DNS message from %d.%d.%d.%d(%d). len = %d\r\n", ip[0], ip[1], ip[2], ip[3],port,len);
#endif
ret = parseDNSMSG(&dhp, pDNSMSG, ip_from_dns);
break;
}
// Check Timeout
ret_check_timeout = check_DNS_timeout();
if (ret_check_timeout < 0) {
#ifdef _DNS_DEBUG_
printf("> DNS Server is not responding : %d.%d.%d.%d\r\n", dns_ip[0], dns_ip[1], dns_ip[2], dns_ip[3]);
#endif
return 0; // timeout occurred
}
else if (ret_check_timeout == 0) {
#ifdef _DNS_DEBUG_
printf("> DNS Timeout\r\n");
#endif
WIZCHIP_EXPORT(sendto)(DNS_SOCKET, pDNSMSG, len, dns_ip, IPPORT_DOMAIN);
}
}
WIZCHIP_EXPORT(close)(DNS_SOCKET);
// Return value
// 0 > : failed / 1 - success
return ret;
}

View File

@ -0,0 +1,96 @@
//*****************************************************************************
//
//! \file dns.h
//! \brief DNS APIs Header file.
//! \details Send DNS query & Receive DNS reponse.
//! \version 1.1.0
//! \date 2013/11/18
//! \par Revision history
//! <2013/10/21> 1st Release
//! <2013/12/20> V1.1.0
//! 1. Remove secondary DNS server in DNS_run
//! If 1st DNS_run failed, call DNS_run with 2nd DNS again
//! 2. DNS_timerHandler -> DNS_time_handler
//! 3. Move the no reference define to dns.c
//! 4. Integrated dns.h dns.c & dns_parse.h dns_parse.c into dns.h & dns.c
//! <2013/12/20> V1.1.0
//!
//! \author Eric Jung & MidnightCow
//! \copyright
//!
//! Copyright (c) 2013, WIZnet Co., LTD.
//! All rights reserved.
//!
//! Redistribution and use in source and binary forms, with or without
//! modification, are permitted provided that the following conditions
//! are met:
//!
//! * Redistributions of source code must retain the above copyright
//! notice, this list of conditions and the following disclaimer.
//! * 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.
//! * Neither the name of the <ORGANIZATION> 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 COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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.
//
//*****************************************************************************
#ifndef _DNS_H_
#define _DNS_H_
#include <stdint.h>
/*
* @brief Define it for Debug & Monitor DNS processing.
* @note If defined, it depends on <stdio.h>
*/
//#define _DNS_DEBUG_
#define MAX_DNS_BUF_SIZE 256 ///< maximum size of DNS buffer. */
/*
* @brief Maximum length of your queried Domain name
* @todo SHOULD BE defined it equal as or greater than your Domain name length + null character(1)
* @note SHOULD BE careful to stack overflow because it is allocated 1.5 times as MAX_DOMAIN_NAME in stack.
*/
#define MAX_DOMAIN_NAME 32 // for example "www.google.com"
#define MAX_DNS_RETRY 2 ///< Requery Count
#define DNS_WAIT_TIME 4 ///< Wait response time. unit 1s.
#define IPPORT_DOMAIN 53 ///< DNS server port number
#define DNS_MSG_ID 0x1122 ///< ID for DNS message. You can be modified it any number
/*
* @brief DNS process initialize
* @param s : Socket number for DNS
* @param buf : Buffer for DNS message
*/
void DNS_init(uint8_t s, uint8_t * buf);
/*
* @brief DNS process
* @details Send DNS query and receive DNS response
* @param dns_ip : DNS server ip address
* @param name : Domain name to be queried
* @param ip_from_dns : IP address from DNS server
* @return -1 : failed. @ref MAX_DOMIN_NAME is too small \n
* 0 : failed (Timeout or Parse error)\n
* 1 : success
* @note This function blocks until success or fail. max time = @ref MAX_DNS_RETRY * @ref DNS_WAIT_TIME
*/
int8_t DNS_run(uint8_t * dns_ip, uint8_t * name, uint8_t * ip_from_dns);
#endif /* _DNS_H_ */

View File

@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2018-10-21 17:15+0200\n"
"POT-Creation-Date: 2018-11-07 14:10-0500\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
@ -147,74 +147,74 @@ msgstr ""
msgid "invalid arguments"
msgstr ""
#: lib/utils/pyexec.c:97 py/builtinimport.c:253
#: lib/utils/pyexec.c:97 py/builtinimport.c:251
msgid "script compilation not supported"
msgstr ""
#: main.c:143
#: main.c:153
msgid " output:\n"
msgstr ""
#: main.c:157 main.c:230
#: main.c:167 main.c:240
msgid ""
"Auto-reload is on. Simply save files over USB to run them or enter REPL to "
"disable.\n"
msgstr ""
#: main.c:159
#: main.c:169
msgid "Running in safe mode! Auto-reload is off.\n"
msgstr ""
#: main.c:161 main.c:232
#: main.c:171 main.c:242
msgid "Auto-reload is off.\n"
msgstr ""
#: main.c:175
#: main.c:185
msgid "Running in safe mode! Not running saved code.\n"
msgstr ""
#: main.c:191
#: main.c:201
msgid "WARNING: Your code filename has two extensions\n"
msgstr ""
#: main.c:239
#: main.c:249
msgid "You requested starting safe mode by "
msgstr ""
#: main.c:242
#: main.c:252
msgid "To exit, please reset the board without "
msgstr ""
#: main.c:249
#: main.c:259
msgid ""
"You are running in safe mode which means something really bad happened.\n"
msgstr ""
#: main.c:251
#: main.c:261
msgid "Looks like our core CircuitPython code crashed hard. Whoops!\n"
msgstr ""
#: main.c:252
#: main.c:262
msgid "Please file an issue here with the contents of your CIRCUITPY drive:\n"
msgstr ""
#: main.c:255
#: main.c:265
msgid ""
"The microcontroller's power dipped. Please make sure your power supply "
"provides\n"
msgstr ""
#: main.c:256
#: main.c:266
msgid ""
"enough power for the whole circuit and press reset (after ejecting "
"CIRCUITPY).\n"
msgstr ""
#: main.c:260
#: main.c:270
msgid "Press any key to enter the REPL. Use CTRL-D to reload."
msgstr ""
#: main.c:416
#: main.c:426
msgid "soft reboot\n"
msgstr ""
@ -958,19 +958,19 @@ msgstr ""
msgid "bad compile mode"
msgstr ""
#: py/builtinimport.c:338
#: py/builtinimport.c:336
msgid "cannot perform relative import"
msgstr ""
#: py/builtinimport.c:422 py/builtinimport.c:534
#: py/builtinimport.c:420 py/builtinimport.c:532
msgid "module not found"
msgstr ""
#: py/builtinimport.c:425 py/builtinimport.c:537
#: py/builtinimport.c:423 py/builtinimport.c:535
msgid "no module named '%q'"
msgstr ""
#: py/builtinimport.c:512
#: py/builtinimport.c:510
msgid "relative import"
msgstr ""
@ -2339,6 +2339,10 @@ msgstr ""
msgid "RTC calibration is not supported on this board"
msgstr ""
#: shared-bindings/socket/__init__.c:516 shared-module/network/__init__.c:81
msgid "no available NIC"
msgstr ""
#: shared-bindings/storage/__init__.c:77
msgid "filesystem must provide mount method"
msgstr ""
@ -2363,15 +2367,15 @@ msgstr ""
msgid "time.struct_time() takes a 9-sequence"
msgstr ""
#: shared-bindings/time/__init__.c:169 shared-bindings/time/__init__.c:250
#: shared-bindings/time/__init__.c:169 shared-bindings/time/__init__.c:264
msgid "Tuple or struct_time argument required"
msgstr ""
#: shared-bindings/time/__init__.c:174 shared-bindings/time/__init__.c:255
#: shared-bindings/time/__init__.c:174 shared-bindings/time/__init__.c:269
msgid "function takes exactly 9 arguments"
msgstr ""
#: shared-bindings/time/__init__.c:226 shared-bindings/time/__init__.c:259
#: shared-bindings/time/__init__.c:240 shared-bindings/time/__init__.c:273
msgid "timestamp out of range for platform time_t"
msgstr ""

View File

@ -7,7 +7,7 @@ msgid ""
msgstr ""
"Project-Id-Version: \n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2018-10-21 17:15+0200\n"
"POT-Creation-Date: 2018-11-07 14:10-0500\n"
"PO-Revision-Date: 2018-07-27 11:55-0700\n"
"Last-Translator: Sebastian Plamauer\n"
"Language-Team: \n"
@ -93,7 +93,7 @@ msgstr "struct: index außerhalb gültigen Bereichs"
#: extmod/moduheapq.c:38
msgid "heap must be a list"
msgstr "heap muss eine list sein"
msgstr "heap muss eine Liste sein"
#: extmod/moduheapq.c:86 extmod/modutimeq.c:147 extmod/modutimeq.c:172
msgid "empty heap"
@ -147,15 +147,15 @@ msgstr "abort() wurde aufgerufen"
msgid "invalid arguments"
msgstr "ungültige argumente"
#: lib/utils/pyexec.c:97 py/builtinimport.c:253
#: lib/utils/pyexec.c:97 py/builtinimport.c:251
msgid "script compilation not supported"
msgstr "kompilieren von Skripten ist nicht unterstützt"
#: main.c:143
#: main.c:153
msgid " output:\n"
msgstr " Ausgabe:\n"
#: main.c:157 main.c:230
#: main.c:167 main.c:240
msgid ""
"Auto-reload is on. Simply save files over USB to run them or enter REPL to "
"disable.\n"
@ -163,45 +163,45 @@ msgstr ""
"Automatisches Neuladen ist aktiv. Speichere Dateien über USB um sie "
"auszuführen oder verbinde dich mit der REPL um zu deaktivieren.\n"
#: main.c:159
#: main.c:169
msgid "Running in safe mode! Auto-reload is off.\n"
msgstr "Sicherheitsmodus aktiv! Automatisches Neuladen ist deaktiviert.\n"
#: main.c:161 main.c:232
#: main.c:171 main.c:242
msgid "Auto-reload is off.\n"
msgstr "Automatisches Neuladen ist deaktiviert.\n"
#: main.c:175
#: main.c:185
msgid "Running in safe mode! Not running saved code.\n"
msgstr "Sicherheitsmodus aktiv! Gespeicherter Code wird nicht ausgeführt\n"
#: main.c:191
#: main.c:201
msgid "WARNING: Your code filename has two extensions\n"
msgstr "WARNUNG: Der Dateiname deines codes hat zwei Dateityperweiterungen\n"
#: main.c:239
#: main.c:249
msgid "You requested starting safe mode by "
msgstr "Du hast das Starten im Sicherheitsmodus ausgelöst durch "
#: main.c:242
#: main.c:252
msgid "To exit, please reset the board without "
msgstr "Zum beenden bitte resete das board ohne "
msgstr "Zum beenden bitte resette das board ohne "
#: main.c:249
#: main.c:259
msgid ""
"You are running in safe mode which means something really bad happened.\n"
msgstr "Sicherheitsmodus aktive, etwas wirklich schlechtes ist passiert.\n"
msgstr "Sicherheitsmodus aktiv, etwas wirklich schlechtes ist passiert.\n"
#: main.c:251
#: main.c:261
msgid "Looks like our core CircuitPython code crashed hard. Whoops!\n"
msgstr "CircuitPython ist abgestürzt. Ups!\n"
#: main.c:252
#: main.c:262
msgid "Please file an issue here with the contents of your CIRCUITPY drive:\n"
msgstr ""
"Bitte erstelle ein issue hier mit dem Inhalt deines CIRCUITPY-speichers:\n"
#: main.c:255
#: main.c:265
msgid ""
"The microcontroller's power dipped. Please make sure your power supply "
"provides\n"
@ -209,23 +209,23 @@ msgstr ""
"Die Stromversorgung des Mikrocontrollers ist eingebrochen. Stelle sicher,"
"dass deine Stromversorgung\n"
#: main.c:256
#: main.c:266
msgid ""
"enough power for the whole circuit and press reset (after ejecting "
"CIRCUITPY).\n"
msgstr ""
"genug Strom für den ganzen Schaltkreis liefert und drücke reset (nach "
"demsicheren Auswerfen von CIRCUITPY.)\n"
"genug Strom für den ganzen Schaltkreis liefert und drücke reset (nach dem "
"sicheren Auswerfen von CIRCUITPY.)\n"
#: main.c:260
#: main.c:270
msgid "Press any key to enter the REPL. Use CTRL-D to reload."
msgstr ""
"Drücke eine Taste um dich mit der REPL zu verbinden. Drücke Strg-D zum neu "
"laden"
#: main.c:416
#: main.c:426
msgid "soft reboot\n"
msgstr "weicher reboot\n"
msgstr "soft reboot\n"
#: ports/atmel-samd/audio_dma.c:209
#: ports/atmel-samd/common-hal/audiobusio/PDMIn.c:361
@ -268,7 +268,7 @@ msgstr "AnalogOut ist an diesem Pin nicht unterstützt"
#: ports/atmel-samd/common-hal/audiobusio/I2SOut.c:147
#: ports/atmel-samd/common-hal/audiobusio/I2SOut.c:150
msgid "Invalid bit clock pin"
msgstr "Ungülgites bit clock pin"
msgstr "Ungültiges bit clock pin"
#: ports/atmel-samd/common-hal/audiobusio/I2SOut.c:153
msgid "Bit clock and word select must share a clock unit"
@ -284,7 +284,7 @@ msgstr "Ungültiger data pin"
#: ports/atmel-samd/common-hal/audiobusio/PDMIn.c:145
#: ports/atmel-samd/common-hal/audiobusio/PDMIn.c:150
msgid "Serializer in use"
msgstr "Serilaizer wird benutzt"
msgstr "Serializer wird benutzt"
#: ports/atmel-samd/common-hal/audiobusio/I2SOut.c:230
msgid "Clock unit in use"
@ -356,7 +356,7 @@ msgstr "Alle timer werden benutzt"
#: ports/atmel-samd/common-hal/audioio/AudioOut.c:285
msgid "All event channels in use"
msgstr "Alle event Kanälre werden benutzt"
msgstr "Alle event Kanäle werden benutzt"
#: ports/atmel-samd/common-hal/audioio/AudioOut.c:375
#, c-format
@ -381,7 +381,7 @@ msgstr "SDA oder SCL brauchen pull up"
#: ports/atmel-samd/common-hal/busio/I2C.c:121
msgid "Unsupported baudrate"
msgstr "Baudrate wird nicht unterstütz"
msgstr "Baudrate wird nicht unterstützt"
#: ports/atmel-samd/common-hal/busio/UART.c:66
msgid "bytes > 8 bits not supported"
@ -547,23 +547,25 @@ msgstr "Minimale PWM Frequenz ist %dHz"
#, c-format
msgid "Multiple PWM frequencies not supported. PWM already set to %dhz."
msgstr ""
"Mehrere PWM Frequenzen nicht unterstützt. PWM bereits auf %dHz gesetzt."
#: ports/esp8266/common-hal/pulseio/PWMOut.c:77 ports/esp8266/machine_pwm.c:70
#, c-format
msgid "PWM not supported on pin %d"
msgstr ""
msgstr "PWM nicht unterstützt an Pin %d"
#: ports/esp8266/common-hal/pulseio/PulseIn.c:78
msgid "No PulseIn support for %q"
msgstr ""
msgstr "Keine PulseIn Unterstützung für %q"
#: ports/esp8266/common-hal/storage/__init__.c:34
msgid "Unable to remount filesystem"
msgstr ""
msgstr "Dateisystem kann nicht wieder gemounted werden."
#: ports/esp8266/common-hal/storage/__init__.c:38
msgid "Use esptool to erase flash and re-upload Python instead"
msgstr ""
"Benutze esptool um den flash zu löschen und stattdessen Python hochzuladen"
#: ports/esp8266/esp_mphal.c:154
msgid "C-level assert"
@ -572,102 +574,103 @@ msgstr ""
#: ports/esp8266/machine_adc.c:57
#, c-format
msgid "not a valid ADC Channel: %d"
msgstr ""
msgstr "Kein gültiger ADC Kanal: %d"
#: ports/esp8266/machine_hspi.c:131 ports/esp8266/machine_hspi.c:137
msgid "impossible baudrate"
msgstr ""
msgstr "Unmögliche Baudrate"
#: ports/esp8266/machine_pin.c:129
msgid "expecting a pin"
msgstr ""
msgstr "Ein Pin wird erwartet"
#: ports/esp8266/machine_pin.c:284
msgid "Pin(16) doesn't support pull"
msgstr ""
msgstr "Pin(16) unterstützt kein pull"
#: ports/esp8266/machine_pin.c:323
msgid "invalid pin"
msgstr ""
msgstr "Ungültiger Pin"
#: ports/esp8266/machine_pin.c:389
msgid "pin does not have IRQ capabilities"
msgstr ""
msgstr "Pin hat keine IRQ Fähigkeiten"
#: ports/esp8266/machine_rtc.c:185
msgid "buffer too long"
msgstr ""
msgstr "Buffer zu lang"
#: ports/esp8266/machine_rtc.c:209 ports/esp8266/machine_rtc.c:223
#: ports/esp8266/machine_rtc.c:246
msgid "invalid alarm"
msgstr ""
msgstr "Ungültiger Alarm"
#: ports/esp8266/machine_uart.c:169
#, c-format
msgid "UART(%d) does not exist"
msgstr ""
msgstr "UART(%d) existiert nicht"
#: ports/esp8266/machine_uart.c:219
msgid "UART(1) can't read"
msgstr ""
msgstr "UART(1) kann nicht lesen"
#: ports/esp8266/modesp.c:119
msgid "len must be multiple of 4"
msgstr ""
msgstr "len muss ein vielfaches von 4 sein"
#: ports/esp8266/modesp.c:274
#, c-format
msgid "memory allocation failed, allocating %u bytes for native code"
msgstr ""
"Speicherallozierung fehlgeschlagen, alloziere %u Bytes für nativen Code"
#: ports/esp8266/modesp.c:317
msgid "flash location must be below 1MByte"
msgstr ""
msgstr "flash location muss unter 1MByte sein"
#: ports/esp8266/modmachine.c:63
msgid "frequency can only be either 80Mhz or 160MHz"
msgstr ""
msgstr "Die Frequenz kann nur 80Mhz oder 160Mhz sein"
#: ports/esp8266/modnetwork.c:61
msgid "AP required"
msgstr ""
msgstr "AP erforderlich"
#: ports/esp8266/modnetwork.c:61
msgid "STA required"
msgstr ""
msgstr "STA erforderlich"
#: ports/esp8266/modnetwork.c:87
msgid "Cannot update i/f status"
msgstr ""
msgstr "Kann i/f Status nicht updaten"
#: ports/esp8266/modnetwork.c:142
msgid "Cannot set STA config"
msgstr ""
msgstr "Kann STA Konfiguration nicht setzen"
#: ports/esp8266/modnetwork.c:144
msgid "Cannot connect to AP"
msgstr ""
msgstr "Kann nicht zu AP verbinden"
#: ports/esp8266/modnetwork.c:152
msgid "Cannot disconnect from AP"
msgstr ""
msgstr "Kann nicht trennen von AP"
#: ports/esp8266/modnetwork.c:173
msgid "unknown status param"
msgstr ""
msgstr "Unbekannter Statusparameter"
#: ports/esp8266/modnetwork.c:222
msgid "STA must be active"
msgstr ""
msgstr "STA muss aktiv sein"
#: ports/esp8266/modnetwork.c:239
msgid "scan failed"
msgstr ""
msgstr "Scan fehlgeschlagen"
#: ports/esp8266/modnetwork.c:306
msgid "wifi_set_ip_info() failed"
msgstr ""
msgstr "wifi_set_ip_info() fehlgeschlagen"
#: ports/esp8266/modnetwork.c:319
msgid "either pos or kw args are allowed"
@ -726,19 +729,19 @@ msgid "Failed to get local address, error: 0x%08lX"
msgstr ""
#: ports/nrf/common-hal/bleio/Characteristic.c:52
#, c-format
#, fuzzy, c-format
msgid "Failed to write gatts value, status: 0x%08lX"
msgstr ""
msgstr "Kann den Attributwert nicht schreiben. Status: 0x%02x"
#: ports/nrf/common-hal/bleio/Characteristic.c:76
#, c-format
#, fuzzy, c-format
msgid "Failed to notify attribute value, status: 0x%08lX"
msgstr ""
msgstr "Kann den Attributwert nicht mitteilen. Status: 0x%02x"
#: ports/nrf/common-hal/bleio/Characteristic.c:91
#, c-format
#, fuzzy, c-format
msgid "Failed to read attribute value, status: 0x%08lX"
msgstr ""
msgstr "Kann den Attributwert nicht lesen. Status: 0x%02x"
#: ports/nrf/common-hal/bleio/Characteristic.c:119
#: ports/nrf/common-hal/bleio/Device.c:272
@ -748,9 +751,9 @@ msgid "Failed to acquire mutex, status: 0x%08lX"
msgstr ""
#: ports/nrf/common-hal/bleio/Characteristic.c:126
#, c-format
#, fuzzy, c-format
msgid "Failed to write attribute value, status: 0x%08lX"
msgstr ""
msgstr "Kann den Attributwert nicht schreiben. Status: 0x%02x"
#: ports/nrf/common-hal/bleio/Characteristic.c:138
#: ports/nrf/common-hal/bleio/Device.c:284
@ -763,8 +766,9 @@ msgstr ""
#: ports/nrf/common-hal/bleio/Device.c:81
#: ports/nrf/common-hal/bleio/Device.c:114
#, fuzzy
msgid "Can not fit data into the advertisment packet"
msgstr ""
msgstr "Daten können nicht in das advertisement packet eingefügt werden."
#: ports/nrf/common-hal/bleio/Device.c:266
#, c-format
@ -773,40 +777,40 @@ msgstr ""
#: ports/nrf/common-hal/bleio/Device.c:403
#: ports/nrf/common-hal/bleio/Scanner.c:76
#, c-format
#, fuzzy, c-format
msgid "Failed to continue scanning, status: 0x%0xlX"
msgstr ""
msgstr "Der Scanvorgang kann nicht gestartet werden. Status: 0x%02x"
#: ports/nrf/common-hal/bleio/Device.c:436
#, c-format
#, fuzzy, c-format
msgid "Failed to connect, status: 0x%08lX"
msgstr ""
msgstr "Kann nicht verbinden. Status: 0x%02x"
#: ports/nrf/common-hal/bleio/Device.c:513
#, c-format
#, fuzzy, c-format
msgid "Failed to add service, status: 0x%08lX"
msgstr ""
msgstr "Kann advertisement nicht stoppen. Status: 0x%02x"
#: ports/nrf/common-hal/bleio/Device.c:531
#, c-format
#, fuzzy, c-format
msgid "Failed to start advertisment, status: 0x%08lX"
msgstr ""
msgstr "Kann advertisement nicht starten. Status: 0x%02x"
#: ports/nrf/common-hal/bleio/Device.c:549
#, c-format
#, fuzzy, c-format
msgid "Failed to stop advertisment, status: 0x%08lX"
msgstr ""
msgstr "Kann advertisement nicht stoppen. Status: 0x%02x"
#: ports/nrf/common-hal/bleio/Device.c:575
#: ports/nrf/common-hal/bleio/Scanner.c:103
#, c-format
#, fuzzy, c-format
msgid "Failed to start scanning, status: 0x%0xlX"
msgstr ""
msgstr "Der Scanvorgang kann nicht gestartet werden. Status: 0x%02x"
#: ports/nrf/common-hal/bleio/Device.c:592
#, c-format
#, fuzzy, c-format
msgid "Failed to create mutex, status: 0x%0xlX"
msgstr ""
msgstr "Kann den Attributwert nicht lesen. Status: 0x%02x"
#: ports/nrf/common-hal/bleio/Service.c:83
#, c-format
@ -814,19 +818,19 @@ msgid "Failed to add characteristic, status: 0x%08lX"
msgstr ""
#: ports/nrf/common-hal/bleio/UUID.c:97
#, c-format
#, fuzzy, c-format
msgid "Failed to add Vendor Specific UUID, status: 0x%08lX"
msgstr ""
msgstr "Kann keine herstellerspezifische 128-Bit-UUID hinzufügen."
#: ports/nrf/common-hal/bleio/UUID.c:102
msgid "Invalid UUID string length"
msgstr ""
msgstr "Ungültige UUID-Stringlänge"
#: ports/nrf/common-hal/bleio/UUID.c:109
#: shared-bindings/bleio/Characteristic.c:125
#: shared-bindings/bleio/Service.c:105
msgid "Invalid UUID parameter"
msgstr ""
msgstr "Ungültiger UUID-Parameter"
#: ports/nrf/common-hal/busio/I2C.c:96
#, fuzzy
@ -873,11 +877,11 @@ msgstr "Alle timer werden benutzt"
#: ports/unix/modffi.c:138
msgid "Unknown type"
msgstr ""
msgstr "Unbekannter Typ"
#: ports/unix/modffi.c:207 ports/unix/modffi.c:265
msgid "Error in ffi_prep_cif"
msgstr ""
msgstr "Fehler in ffi_prep_cif"
#: ports/unix/modffi.c:270
msgid "ffi_prep_closure_loc"
@ -972,19 +976,19 @@ msgstr ""
msgid "bad compile mode"
msgstr ""
#: py/builtinimport.c:338
#: py/builtinimport.c:336
msgid "cannot perform relative import"
msgstr ""
#: py/builtinimport.c:422 py/builtinimport.c:534
#: py/builtinimport.c:420 py/builtinimport.c:532
msgid "module not found"
msgstr ""
#: py/builtinimport.c:425 py/builtinimport.c:537
#: py/builtinimport.c:423 py/builtinimport.c:535
msgid "no module named '%q'"
msgstr ""
#: py/builtinimport.c:512
#: py/builtinimport.c:510
msgid "relative import"
msgstr ""
@ -2358,6 +2362,10 @@ msgstr ""
msgid "RTC calibration is not supported on this board"
msgstr ""
#: shared-bindings/socket/__init__.c:516 shared-module/network/__init__.c:81
msgid "no available NIC"
msgstr ""
#: shared-bindings/storage/__init__.c:77
msgid "filesystem must provide mount method"
msgstr ""
@ -2382,15 +2390,15 @@ msgstr ""
msgid "time.struct_time() takes a 9-sequence"
msgstr ""
#: shared-bindings/time/__init__.c:169 shared-bindings/time/__init__.c:250
#: shared-bindings/time/__init__.c:169 shared-bindings/time/__init__.c:264
msgid "Tuple or struct_time argument required"
msgstr ""
#: shared-bindings/time/__init__.c:174 shared-bindings/time/__init__.c:255
#: shared-bindings/time/__init__.c:174 shared-bindings/time/__init__.c:269
msgid "function takes exactly 9 arguments"
msgstr ""
#: shared-bindings/time/__init__.c:226 shared-bindings/time/__init__.c:259
#: shared-bindings/time/__init__.c:240 shared-bindings/time/__init__.c:273
msgid "timestamp out of range for platform time_t"
msgstr ""
@ -2517,3 +2525,33 @@ msgstr ""
#: shared-module/struct/__init__.c:83
msgid "too many arguments provided with the given format"
msgstr ""
#~ msgid "Invalid Service type"
#~ msgstr "Ungültiger Diensttyp"
#~ msgid "Can not apply advertisement data. status: 0x%02x"
#~ msgstr "Kann advertisement data nicht anwenden. Status: 0x%02x"
#~ msgid "Can encode UUID into the advertisement packet."
#~ msgstr "Kann UUID in das advertisement packet kodieren."
#~ msgid "Can not encode UUID, to check length."
#~ msgstr "Kann UUID nicht kodieren, um die Länge zu überprüfen."
#~ msgid "Can not apply device name in the stack."
#~ msgstr "Der Gerätename kann nicht im Stack verwendet werden."
#~ msgid "Can not add Characteristic."
#~ msgstr "Kann das Merkmal nicht hinzufügen."
#~ msgid "Can not add Service."
#~ msgstr "Kann den Dienst nicht hinzufügen."
#~ msgid "Can not query for the device address."
#~ msgstr "Kann nicht nach der Geräteadresse suchen."
#~ msgid "Cannot set PPCP parameters."
#~ msgstr "Kann PPCP Parameter nicht setzen."
#~ msgid "Cannot apply GAP parameters."
#~ msgstr "Kann GAP Parameter nicht anwenden."

View File

@ -7,7 +7,7 @@ msgid ""
msgstr ""
"Project-Id-Version: \n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2018-10-21 17:15+0200\n"
"POT-Creation-Date: 2018-11-07 14:10-0500\n"
"PO-Revision-Date: 2018-07-27 11:55-0700\n"
"Last-Translator: \n"
"Language-Team: \n"
@ -147,74 +147,74 @@ msgstr ""
msgid "invalid arguments"
msgstr ""
#: lib/utils/pyexec.c:97 py/builtinimport.c:253
#: lib/utils/pyexec.c:97 py/builtinimport.c:251
msgid "script compilation not supported"
msgstr ""
#: main.c:143
#: main.c:153
msgid " output:\n"
msgstr ""
#: main.c:157 main.c:230
#: main.c:167 main.c:240
msgid ""
"Auto-reload is on. Simply save files over USB to run them or enter REPL to "
"disable.\n"
msgstr ""
#: main.c:159
#: main.c:169
msgid "Running in safe mode! Auto-reload is off.\n"
msgstr ""
#: main.c:161 main.c:232
#: main.c:171 main.c:242
msgid "Auto-reload is off.\n"
msgstr ""
#: main.c:175
#: main.c:185
msgid "Running in safe mode! Not running saved code.\n"
msgstr ""
#: main.c:191
#: main.c:201
msgid "WARNING: Your code filename has two extensions\n"
msgstr ""
#: main.c:239
#: main.c:249
msgid "You requested starting safe mode by "
msgstr ""
#: main.c:242
#: main.c:252
msgid "To exit, please reset the board without "
msgstr ""
#: main.c:249
#: main.c:259
msgid ""
"You are running in safe mode which means something really bad happened.\n"
msgstr ""
#: main.c:251
#: main.c:261
msgid "Looks like our core CircuitPython code crashed hard. Whoops!\n"
msgstr ""
#: main.c:252
#: main.c:262
msgid "Please file an issue here with the contents of your CIRCUITPY drive:\n"
msgstr ""
#: main.c:255
#: main.c:265
msgid ""
"The microcontroller's power dipped. Please make sure your power supply "
"provides\n"
msgstr ""
#: main.c:256
#: main.c:266
msgid ""
"enough power for the whole circuit and press reset (after ejecting "
"CIRCUITPY).\n"
msgstr ""
#: main.c:260
#: main.c:270
msgid "Press any key to enter the REPL. Use CTRL-D to reload."
msgstr ""
#: main.c:416
#: main.c:426
msgid "soft reboot\n"
msgstr ""
@ -958,19 +958,19 @@ msgstr ""
msgid "bad compile mode"
msgstr ""
#: py/builtinimport.c:338
#: py/builtinimport.c:336
msgid "cannot perform relative import"
msgstr ""
#: py/builtinimport.c:422 py/builtinimport.c:534
#: py/builtinimport.c:420 py/builtinimport.c:532
msgid "module not found"
msgstr ""
#: py/builtinimport.c:425 py/builtinimport.c:537
#: py/builtinimport.c:423 py/builtinimport.c:535
msgid "no module named '%q'"
msgstr ""
#: py/builtinimport.c:512
#: py/builtinimport.c:510
msgid "relative import"
msgstr ""
@ -2339,6 +2339,10 @@ msgstr ""
msgid "RTC calibration is not supported on this board"
msgstr ""
#: shared-bindings/socket/__init__.c:516 shared-module/network/__init__.c:81
msgid "no available NIC"
msgstr ""
#: shared-bindings/storage/__init__.c:77
msgid "filesystem must provide mount method"
msgstr ""
@ -2363,15 +2367,15 @@ msgstr ""
msgid "time.struct_time() takes a 9-sequence"
msgstr ""
#: shared-bindings/time/__init__.c:169 shared-bindings/time/__init__.c:250
#: shared-bindings/time/__init__.c:169 shared-bindings/time/__init__.c:264
msgid "Tuple or struct_time argument required"
msgstr ""
#: shared-bindings/time/__init__.c:174 shared-bindings/time/__init__.c:255
#: shared-bindings/time/__init__.c:174 shared-bindings/time/__init__.c:269
msgid "function takes exactly 9 arguments"
msgstr ""
#: shared-bindings/time/__init__.c:226 shared-bindings/time/__init__.c:259
#: shared-bindings/time/__init__.c:240 shared-bindings/time/__init__.c:273
msgid "timestamp out of range for platform time_t"
msgstr ""

View File

@ -7,7 +7,7 @@ msgid ""
msgstr ""
"Project-Id-Version: \n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2018-10-21 17:15+0200\n"
"POT-Creation-Date: 2018-11-07 14:10-0500\n"
"PO-Revision-Date: 2018-08-24 22:56-0500\n"
"Last-Translator: \n"
"Language-Team: \n"
@ -65,7 +65,7 @@ msgstr "string de longitud impar"
#: extmod/modubinascii.c:101
msgid "non-hex digit found"
msgstr "se encontró un digito no hexadecimal"
msgstr "se encontró un digito non-hex"
#: extmod/modubinascii.c:169
msgid "incorrect padding"
@ -81,7 +81,7 @@ msgstr "No se puede obtener inequívocamente sizeof escalar"
#: extmod/moductypes.c:397
msgid "struct: no fields"
msgstr "struct: no fields"
msgstr "struct: sin campos"
#: extmod/moductypes.c:530
msgid "struct: cannot index"
@ -121,7 +121,7 @@ msgstr "certificado inválido"
#: extmod/modutimeq.c:131
msgid "queue overflow"
msgstr "desborde de queue"
msgstr "desbordamiento de queue"
#: extmod/moduzlib.c:98
msgid "compression header"
@ -132,16 +132,14 @@ msgid "invalid dupterm index"
msgstr "index dupterm inválido"
#: extmod/vfs_fat.c:426 py/moduerrno.c:150
#, fuzzy
msgid "Read-only filesystem"
msgstr "sistema de archivos de Solo-Lectura"
msgstr "Sistema de archivos de solo-Lectura"
#: extmod/vfs_posix_file.c:48 ports/unix/file.c:50 py/objstringio.c:43
msgid "I/O operation on closed file"
msgstr "Operación I/O en archivo cerrado"
#: lib/embed/abort_.c:8
#, fuzzy
msgid "abort() called"
msgstr "se llamó abort()"
@ -149,87 +147,86 @@ msgstr "se llamó abort()"
msgid "invalid arguments"
msgstr "argumentos inválidos"
#: lib/utils/pyexec.c:97 py/builtinimport.c:253
#: lib/utils/pyexec.c:97 py/builtinimport.c:251
msgid "script compilation not supported"
msgstr "script de compilación no soportado"
#: main.c:143
#: main.c:153
msgid " output:\n"
msgstr " salida:\n"
#: main.c:157 main.c:230
#, fuzzy
#: main.c:167 main.c:240
msgid ""
"Auto-reload is on. Simply save files over USB to run them or enter REPL to "
"disable.\n"
msgstr ""
"Auto-reload habilitado. Simplemente guarda los archivos via USB para "
"ejecutarlos o entra REPL para desabilitarlos.\n"
"ejecutarlos o entra al REPL para desabilitarlos.\n"
#: main.c:159
#: main.c:169
msgid "Running in safe mode! Auto-reload is off.\n"
msgstr "Ejecutando en modo seguro! Auto-recarga esta deshabilitado.\n"
msgstr "Ejecutando en modo seguro! La auto-recarga esta deshabilitada.\n"
#: main.c:161 main.c:232
#: main.c:171 main.c:242
msgid "Auto-reload is off.\n"
msgstr "Auto-reload deshabilitado.\n"
msgstr "Auto-recarga deshabilitada.\n"
#: main.c:175
#: main.c:185
msgid "Running in safe mode! Not running saved code.\n"
msgstr "Ejecutando en modo seguro! No se esta ejecutando el código guardado.\n"
#: main.c:191
#: main.c:201
msgid "WARNING: Your code filename has two extensions\n"
msgstr "ADVERTENCIA: El nombre de archivo de tu código tiene dos extensiones\n"
#: main.c:239
#: main.c:249
msgid "You requested starting safe mode by "
msgstr "Solicitaste iniciar en modo seguro con "
msgstr "Solicitaste iniciar en modo seguro por "
#: main.c:242
#: main.c:252
msgid "To exit, please reset the board without "
msgstr "Para salir, por favor reinicia la tarjeta sin "
#: main.c:249
#: main.c:259
msgid ""
"You are running in safe mode which means something really bad happened.\n"
msgstr ""
"Estás ejecutando en modo seguro, lo cual significa que algo realmente malo "
"ha sucedido.\n"
#: main.c:251
#: main.c:261
msgid "Looks like our core CircuitPython code crashed hard. Whoops!\n"
msgstr ""
"Parece que nuestro código del núcleo CircuitPython dejó de funcionar. "
"Whoops!\n"
msgstr "Parece que nuestro código CircuitPython dejó de funcionar. Whoops!\n"
#: main.c:252
#: main.c:262
#, fuzzy
msgid "Please file an issue here with the contents of your CIRCUITPY drive:\n"
msgstr ""
"Por favor registra un problema aquí con los contenidos de tu unidad de "
"almacenamiento CIRCUITPY:\n"
"Por favor registra un issue en el siguiente URL con los contenidos de tu "
"unidad de almacenamiento CIRCUITPY:\n"
#: main.c:255
#: main.c:265
msgid ""
"The microcontroller's power dipped. Please make sure your power supply "
"provides\n"
msgstr ""
"La alimentación del microcontrolador cayó. Por favor asegurate de que tu "
"fuente de alimentación provee\n"
#: main.c:256
#: main.c:266
msgid ""
"enough power for the whole circuit and press reset (after ejecting "
"CIRCUITPY).\n"
msgstr ""
"suficiente poder para todo el circuito y pulsa reset (después de expulsar "
"suficiente poder para todo el circuito y presiona reset (después de expulsar "
"CIRCUITPY).\n"
#: main.c:260
#: main.c:270
msgid "Press any key to enter the REPL. Use CTRL-D to reload."
msgstr ""
"Presiona cualquier tecla para entrar al REPL. Usa CTRL-D para recargar."
#: main.c:416
#: main.c:426
msgid "soft reboot\n"
msgstr "reinicio suave\n"
@ -261,7 +258,7 @@ msgstr "Sin bus UART por default"
#: ports/atmel-samd/common-hal/analogio/AnalogIn.c:63
#: ports/nrf/common-hal/analogio/AnalogIn.c:39
msgid "Pin does not have ADC capabilities"
msgstr "pin no tiene capacidades ADC"
msgstr "Pin no tiene capacidad ADC"
#: ports/atmel-samd/common-hal/analogio/AnalogOut.c:49
msgid "No DAC on chip"
@ -278,7 +275,7 @@ msgstr "Pin bit clock inválido"
#: ports/atmel-samd/common-hal/audiobusio/I2SOut.c:153
msgid "Bit clock and word select must share a clock unit"
msgstr "Bit clock y Word select deben compartir la unidad de reloj"
msgstr "Bit clock y word select deben compartir una unidad de reloj"
#: ports/atmel-samd/common-hal/audiobusio/I2SOut.c:156
#: ports/atmel-samd/common-hal/audiobusio/PDMIn.c:130
@ -299,11 +296,11 @@ msgstr "Clock unit está siendo utilizado"
#: ports/atmel-samd/common-hal/audiobusio/I2SOut.c:240
#: ports/atmel-samd/common-hal/audiobusio/PDMIn.c:172
msgid "Unable to find free GCLK"
msgstr "No se pudo encontrar un GCLK disponible"
msgstr "No se pudo encontrar un GCLK libre"
#: ports/atmel-samd/common-hal/audiobusio/I2SOut.c:254
msgid "Too many channels in sample."
msgstr "Demasiados canales en sample"
msgstr "Demasiados canales en sample."
#: ports/atmel-samd/common-hal/audiobusio/I2SOut.c:305
#: ports/atmel-samd/common-hal/audioio/AudioOut.c:417
@ -321,11 +318,11 @@ msgstr "Pin clock inválido"
#: ports/atmel-samd/common-hal/audiobusio/PDMIn.c:134
msgid "Only 8 or 16 bit mono with "
msgstr "Solo mono de 8 o 16 bit con"
msgstr "Solo mono de 8 o 16 bit con "
#: ports/atmel-samd/common-hal/audiobusio/PDMIn.c:167
msgid "sampling rate out of range"
msgstr "velocidad de muestreo fuera de rango"
msgstr "frecuencia de muestreo fuera de rango"
#: ports/atmel-samd/common-hal/audioio/AudioOut.c:132
msgid "DAC already in use"
@ -333,13 +330,13 @@ msgstr "DAC ya está siendo utilizado"
#: ports/atmel-samd/common-hal/audioio/AudioOut.c:136
msgid "Right channel unsupported"
msgstr "El canal derecho no tiene soporte"
msgstr "Canal derecho no soportado"
#: ports/atmel-samd/common-hal/audioio/AudioOut.c:139
#: ports/atmel-samd/common-hal/pulseio/PWMOut.c:116
#: ports/atmel-samd/common-hal/touchio/TouchIn.c:65
msgid "Invalid pin"
msgstr "pin inválido"
msgstr "Pin inválido"
#: ports/atmel-samd/common-hal/audioio/AudioOut.c:147
msgid "Invalid pin for left channel"
@ -351,23 +348,23 @@ msgstr "Pin inválido para canal derecho"
#: ports/atmel-samd/common-hal/audioio/AudioOut.c:154
msgid "Cannot output both channels on the same pin"
msgstr "No es posible utilizar el mismo pin para ambos canales"
msgstr "No se puede tener ambos canales en el mismo pin"
#: ports/atmel-samd/common-hal/audioio/AudioOut.c:243
#: ports/atmel-samd/common-hal/pulseio/PWMOut.c:189
#: ports/atmel-samd/common-hal/pulseio/PulseOut.c:110
#: ports/nrf/common-hal/pulseio/PulseOut.c:107
msgid "All timers in use"
msgstr "Todos los timers están siendo utilizados"
msgstr "Todos los timers en uso"
#: ports/atmel-samd/common-hal/audioio/AudioOut.c:285
msgid "All event channels in use"
msgstr "Todos los canales de eventos están siendo utilizados"
msgstr "Todos los event channels en uso"
#: ports/atmel-samd/common-hal/audioio/AudioOut.c:375
#, c-format
msgid "Sample rate too high. It must be less than %d"
msgstr "Frecuencia de muestreo demasiado alta. Debe ser menor que %d"
msgstr "Frecuencia de muestreo demasiado alta. Debe ser menor a %d"
#: ports/atmel-samd/common-hal/busio/I2C.c:71
msgid "Not enough pins available"
@ -387,25 +384,25 @@ msgstr "SDA o SCL necesitan una pull up"
#: ports/atmel-samd/common-hal/busio/I2C.c:121
msgid "Unsupported baudrate"
msgstr "Baudrate sin soporte"
msgstr "Baudrate no soportado"
#: ports/atmel-samd/common-hal/busio/UART.c:66
msgid "bytes > 8 bits not supported"
msgstr "bytes > 8 bits no son soportados"
msgstr "bytes > 8 bits no soportados"
#: ports/atmel-samd/common-hal/busio/UART.c:72
#: ports/nrf/common-hal/busio/UART.c:82
msgid "tx and rx cannot both be None"
msgstr "tx y rx no pueden ser ambos None"
msgstr "Ambos tx y rx no pueden ser None"
#: ports/atmel-samd/common-hal/busio/UART.c:145
#: ports/nrf/common-hal/busio/UART.c:115
msgid "Failed to allocate RX buffer"
msgstr "Fallo la asignación del buffer RX"
msgstr "Ha fallado la asignación del buffer RX"
#: ports/atmel-samd/common-hal/busio/UART.c:153
msgid "Could not initialize UART"
msgstr "No se pudo inicializar la UART"
msgstr "No se puede inicializar la UART"
#: ports/atmel-samd/common-hal/busio/UART.c:240
#: ports/nrf/common-hal/busio/UART.c:149
@ -420,12 +417,12 @@ msgstr "Sin pin TX"
#: ports/atmel-samd/common-hal/digitalio/DigitalInOut.c:170
#: ports/nrf/common-hal/digitalio/DigitalInOut.c:142
msgid "Cannot get pull while in output mode"
msgstr "No se puede obtener pull mientras en modo de salida"
msgstr "No puede ser pull mientras este en modo de salida"
#: ports/atmel-samd/common-hal/microcontroller/__init__.c:74
#: ports/esp8266/common-hal/microcontroller/__init__.c:64
msgid "Cannot reset into bootloader because no bootloader is present."
msgstr "No se puede reiniciar en bootloader porque no hay bootloader presente."
msgstr "No se puede reiniciar a bootloader porque no hay bootloader presente."
#: ports/atmel-samd/common-hal/pulseio/PWMOut.c:120
#: ports/atmel-samd/common-hal/pulseio/PWMOut.c:369
@ -440,7 +437,7 @@ msgstr "Todos los timers para este pin están siendo utilizados"
#: ports/atmel-samd/common-hal/pulseio/PulseIn.c:110
msgid "No hardware support on pin"
msgstr "pin no tiene soporte en hardware"
msgstr "Sin soporte de hardware en pin"
#: ports/atmel-samd/common-hal/pulseio/PulseIn.c:113
msgid "EXTINT channel already in use"
@ -450,12 +447,12 @@ msgstr "El canal EXTINT ya está siendo utilizado"
#: ports/esp8266/common-hal/pulseio/PulseIn.c:86
#, c-format
msgid "Failed to allocate RX buffer of %d bytes"
msgstr "Fallo la asignación del buffer RX de %d bytes"
msgstr "Falló la asignación del buffer RX de %d bytes"
#: ports/atmel-samd/common-hal/pulseio/PulseIn.c:205
#: ports/esp8266/common-hal/pulseio/PulseIn.c:151
msgid "pop from an empty PulseIn"
msgstr "pop en un PulseIn vacío"
msgstr "pop de un PulseIn vacío"
#: ports/atmel-samd/common-hal/pulseio/PulseIn.c:237
#: ports/esp8266/common-hal/pulseio/PulseIn.c:182 py/obj.c:420
@ -476,7 +473,7 @@ msgstr "El canal EXTINT ya está siendo utilizado"
#: ports/atmel-samd/common-hal/rtc/RTC.c:101
msgid "calibration value out of range +/-127"
msgstr "Valor de calibración fuera de rango +/-127"
msgstr "Valor de calibración fuera del rango +/-127"
#: ports/atmel-samd/common-hal/storage/__init__.c:48
msgid "Cannot remount '/' when USB is active."
@ -504,11 +501,11 @@ msgstr "Error USB"
#: ports/esp8266/common-hal/analogio/AnalogIn.c:43
msgid "Pin %q does not have ADC capabilities"
msgstr "Pin %q no tiene capacidades ADC"
msgstr "Pin %q no tiene capacidades de ADC"
#: ports/esp8266/common-hal/analogio/AnalogOut.c:39
msgid "No hardware support for analog out."
msgstr "Sin soporte de hardware para salida análoga"
msgstr "Sin soporte de hardware para analog out"
#: ports/esp8266/common-hal/busio/SPI.c:72
msgid "Pins not valid for SPI"
@ -528,21 +525,21 @@ msgstr "stop bits inválidos"
#: ports/esp8266/common-hal/digitalio/DigitalInOut.c:200
msgid "ESP8266 does not support pull down."
msgstr "ESP8266 no tiene soporte para pull down"
msgstr "ESP8266 no soporta pull down."
#: ports/esp8266/common-hal/digitalio/DigitalInOut.c:210
msgid "GPIO16 does not support pull up."
msgstr "GPIO16 no tiene soporte para pull up."
msgstr "GPIO16 no soporta pull up."
#: ports/esp8266/common-hal/microcontroller/__init__.c:66
msgid "ESP8226 does not support safe mode."
msgstr "ESP8226 no tiene soporte para modo seguro"
msgstr "ESP8226 no soporta modo seguro."
#: ports/esp8266/common-hal/pulseio/PWMOut.c:54
#: ports/esp8266/common-hal/pulseio/PWMOut.c:113
#, c-format
msgid "Maximum PWM frequency is %dhz."
msgstr "La frecuencia máxima del PWM es %dhz"
msgstr "La frecuencia máxima del PWM es %dhz."
#: ports/esp8266/common-hal/pulseio/PWMOut.c:57
#: ports/esp8266/common-hal/pulseio/PWMOut.c:116
@ -553,7 +550,7 @@ msgstr "La frecuencia mínima del PWM es 1hz"
#, c-format
msgid "Multiple PWM frequencies not supported. PWM already set to %dhz."
msgstr ""
"PWM de múltiples frecuencias no tiene soporte. El PWM ya se estableció a %dhz"
"PWM de múltiples frecuencias no soportado. El PWM ya se estableció a %dhz"
#: ports/esp8266/common-hal/pulseio/PWMOut.c:77 ports/esp8266/machine_pwm.c:70
#, c-format
@ -562,11 +559,11 @@ msgstr "El pin %d no soporta PWM"
#: ports/esp8266/common-hal/pulseio/PulseIn.c:78
msgid "No PulseIn support for %q"
msgstr "%q no tiene soporte para PulseIn"
msgstr "Sin soporte PulseIn para %q"
#: ports/esp8266/common-hal/storage/__init__.c:34
msgid "Unable to remount filesystem"
msgstr "No se pudo montar de nuevo el sistema de archivos"
msgstr "Incapaz de montar de nuevo el sistema de archivos"
#: ports/esp8266/common-hal/storage/__init__.c:38
msgid "Use esptool to erase flash and re-upload Python instead"
@ -591,7 +588,7 @@ msgstr "esperando un pin"
#: ports/esp8266/machine_pin.c:284
msgid "Pin(16) doesn't support pull"
msgstr "Pin(16) no tiene soporte para pull"
msgstr "Pin(16) no soporta para pull"
#: ports/esp8266/machine_pin.c:323
msgid "invalid pin"
@ -599,7 +596,7 @@ msgstr "pin inválido"
#: ports/esp8266/machine_pin.c:389
msgid "pin does not have IRQ capabilities"
msgstr "pin no tiene capacidades IRQ"
msgstr "pin sin capacidades IRQ"
#: ports/esp8266/machine_rtc.c:185
msgid "buffer too long"
@ -626,8 +623,7 @@ msgstr "len debe de ser múltiple de 4"
#: ports/esp8266/modesp.c:274
#, c-format
msgid "memory allocation failed, allocating %u bytes for native code"
msgstr ""
"la asignación de memoria ha fallado, asignando %u bytes para código nativo"
msgstr "falló la asignación de memoria, asignando %u bytes para código nativo"
#: ports/esp8266/modesp.c:317
msgid "flash location must be below 1MByte"
@ -639,11 +635,11 @@ msgstr "la frecuencia solo puede ser 80MHz o 160MHz"
#: ports/esp8266/modnetwork.c:61
msgid "AP required"
msgstr "AP necesario"
msgstr "AP requerido"
#: ports/esp8266/modnetwork.c:61
msgid "STA required"
msgstr "STA necesario"
msgstr "STA requerido"
#: ports/esp8266/modnetwork.c:87
msgid "Cannot update i/f status"
@ -825,7 +821,7 @@ msgstr ""
#: ports/nrf/common-hal/bleio/UUID.c:97
#, fuzzy, c-format
msgid "Failed to add Vendor Specific UUID, status: 0x%08lX"
msgstr "No se puede agregar el UUID de 128-bits Especifico del Vendedor."
msgstr "No se puede agregar el Vendor Specific 128-bit UUID."
#: ports/nrf/common-hal/bleio/UUID.c:102
msgid "Invalid UUID string length"
@ -839,11 +835,11 @@ msgstr "Parámetro UUID inválido"
#: ports/nrf/common-hal/busio/I2C.c:96
msgid "All I2C peripherals are in use"
msgstr "Todos los timers están siendo utilizados"
msgstr "Todos los timers están siendo usados"
#: ports/nrf/common-hal/busio/SPI.c:115
msgid "All SPI peripherals are in use"
msgstr "Todos los timers están siendo utilizados"
msgstr "Todos los timers están siendo usados"
#: ports/nrf/common-hal/busio/UART.c:48
#, c-format
@ -872,21 +868,20 @@ msgid "Can not get temperature. status: 0x%02x"
msgstr "No se puede obtener la temperatura. status: 0x%02x"
#: ports/nrf/common-hal/pulseio/PWMOut.c:161
#, fuzzy
msgid "All PWM peripherals are in use"
msgstr "Todos los timers están siendo utilizados"
msgstr "Todos los periféricos PWM en uso"
#: ports/unix/modffi.c:138
msgid "Unknown type"
msgstr ""
msgstr "Tipo desconocido"
#: ports/unix/modffi.c:207 ports/unix/modffi.c:265
msgid "Error in ffi_prep_cif"
msgstr ""
msgstr "Error en ffi_prep_cif"
#: ports/unix/modffi.c:270
msgid "ffi_prep_closure_loc"
msgstr ""
msgstr "ffi_prep_closure_loc"
#: ports/unix/modffi.c:413
msgid "Don't know how to pass object to native function"
@ -895,30 +890,30 @@ msgstr ""
#: ports/unix/modusocket.c:474
#, c-format
msgid "[addrinfo error %d]"
msgstr ""
msgstr "[addrinfo error %d]"
#: py/argcheck.c:44
msgid "function does not take keyword arguments"
msgstr ""
msgstr "la función no tiene argumentos por palabra clave"
#: py/argcheck.c:54 py/bc.c:85 py/objnamedtuple.c:104
#, c-format
msgid "function takes %d positional arguments but %d were given"
msgstr ""
msgstr "la función toma %d argumentos posicionales pero le fueron dados %d"
#: py/argcheck.c:64
#, c-format
msgid "function missing %d required positional arguments"
msgstr ""
msgstr "a la función le hacen falta %d argumentos posicionales requeridos"
#: py/argcheck.c:72
#, c-format
msgid "function expected at most %d arguments, got %d"
msgstr ""
msgstr "la función esperaba a lo sumo %d argumentos, tiene %d"
#: py/argcheck.c:97
msgid "'%q' argument required"
msgstr ""
msgstr "argumento '%q' requerido"
#: py/argcheck.c:122
msgid "extra positional arguments given"
@ -942,11 +937,11 @@ msgstr ""
#: py/bc.c:197 py/bc.c:215
msgid "unexpected keyword argument"
msgstr ""
msgstr "argumento por palabra clave inesperado"
#: py/bc.c:199
msgid "keywords must be strings"
msgstr ""
msgstr "palabras clave deben ser strings"
#: py/bc.c:206 py/objnamedtuple.c:138
msgid "function got multiple values for argument '%q'"
@ -977,19 +972,19 @@ msgstr ""
msgid "bad compile mode"
msgstr ""
#: py/builtinimport.c:338
#: py/builtinimport.c:336
msgid "cannot perform relative import"
msgstr ""
#: py/builtinimport.c:422 py/builtinimport.c:534
#: py/builtinimport.c:420 py/builtinimport.c:532
msgid "module not found"
msgstr "módulo no encontrado"
#: py/builtinimport.c:425 py/builtinimport.c:537
#: py/builtinimport.c:423 py/builtinimport.c:535
msgid "no module named '%q'"
msgstr "ningún módulo se llama '%q'"
#: py/builtinimport.c:512
#: py/builtinimport.c:510
msgid "relative import"
msgstr "import relativo"
@ -1158,7 +1153,7 @@ msgid "'%s' expects a register"
msgstr ""
#: py/emitinlinethumb.c:211
#, fuzzy, c-format
#, c-format
msgid "'%s' expects a special register"
msgstr "ord espera un carácter"
@ -1202,7 +1197,6 @@ msgid "unsupported Thumb instruction '%s' with %d arguments"
msgstr ""
#: py/emitinlinethumb.c:810
#, fuzzy
msgid "branch not in range"
msgstr "El argumento de chr() no esta en el rango(256)"
@ -1369,14 +1363,12 @@ msgid "File exists"
msgstr ""
#: py/moduerrno.c:148
#, fuzzy
msgid "Unsupported operation"
msgstr "El pin %d no soporta PWM"
msgstr "Operacion no soportada"
#: py/moduerrno.c:149
#, fuzzy
msgid "Invalid argument"
msgstr "argumentos inválidos"
msgstr "Argumento inválido"
#: py/obj.c:90
msgid "Traceback (most recent call last):\n"
@ -1448,9 +1440,8 @@ msgid "%q indices must be integers, not %s"
msgstr ""
#: py/obj.c:423
#, fuzzy
msgid "%q index out of range"
msgstr "struct: index fuera de rango"
msgstr "%w index fuera de rango"
#: py/obj.c:455
msgid "object has no len"
@ -1462,9 +1453,8 @@ msgid "object of type '%s' has no len()"
msgstr ""
#: py/obj.c:496
#, fuzzy
msgid "object does not support item deletion"
msgstr "ESP8226 no soporta modo seguro"
msgstr "object no soporta supresión de item"
#: py/obj.c:499
#, c-format
@ -1523,9 +1513,8 @@ msgid "full"
msgstr ""
#: py/objdeque.c:127
#, fuzzy
msgid "empty"
msgstr "heap vacío"
msgstr "vacío"
#: py/objdict.c:314
msgid "popitem(): dictionary is empty"
@ -1536,9 +1525,8 @@ msgid "dict update sequence has wrong length"
msgstr ""
#: py/objfloat.c:308 py/parsenum.c:331
#, fuzzy
msgid "complex values not supported"
msgstr "script de compilación no soportado"
msgstr "valores complejos no soportados"
#: py/objgenerator.c:108
msgid "can't send non-None value to a just-started generator"
@ -1569,9 +1557,8 @@ msgid "float too big"
msgstr ""
#: py/objint.c:328
#, fuzzy
msgid "long int not supported in this build"
msgstr "AnalogOut no es soportado por el pin dado"
msgstr "long int no soportado en esta compilación"
#: py/objint.c:334 py/objint.c:340 py/objint.c:350 py/objint.c:358
msgid "small int overflow"
@ -1610,9 +1597,8 @@ msgid "can't set attribute"
msgstr ""
#: py/objobject.c:55
#, fuzzy
msgid "__new__ arg must be a user-type"
msgstr "heap debe ser una lista"
msgstr "__new__ arg debe ser un user-type"
#: py/objrange.c:110
msgid "zero step"
@ -1623,9 +1609,8 @@ msgid "pop from an empty set"
msgstr ""
#: py/objslice.c:66
#, fuzzy
msgid "Length must be an int"
msgstr "heap debe ser una lista"
msgstr "Length debe ser un int"
#: py/objslice.c:71
msgid "Length must be non-negative"
@ -1640,9 +1625,8 @@ msgid "Cannot subclass slice"
msgstr ""
#: py/objstr.c:261
#, fuzzy
msgid "bytes value out of range"
msgstr "Valor de calibración fuera de rango +/-127"
msgstr "valor de bytes fuera de rango"
#: py/objstr.c:270
msgid "wrong number of arguments"
@ -1653,18 +1637,16 @@ msgid "join expects a list of str/bytes objects consistent with self object"
msgstr ""
#: py/objstr.c:542 py/objstr.c:647 py/objstr.c:1744
#, fuzzy
msgid "empty separator"
msgstr "heap vacío"
msgstr "separator vacío"
#: py/objstr.c:641
msgid "rsplit(None,n)"
msgstr ""
#: py/objstr.c:713
#, fuzzy
msgid "substring not found"
msgstr "módulo no encontrado"
msgstr "substring no encontrado"
#: py/objstr.c:770
msgid "start/end indices"
@ -1705,14 +1687,12 @@ msgid ""
msgstr ""
#: py/objstr.c:1055 py/objstr.c:1083
#, fuzzy
msgid "tuple index out of range"
msgstr "struct: index fuera de rango"
msgstr "tuple index fuera de rango"
#: py/objstr.c:1071
#, fuzzy
msgid "attributes not supported yet"
msgstr "bytes > 8 bits no soportados"
msgstr "atributos aún no soportados"
#: py/objstr.c:1079
msgid ""
@ -1720,9 +1700,8 @@ msgid ""
msgstr ""
#: py/objstr.c:1171
#, fuzzy
msgid "invalid format specifier"
msgstr "formato inválido"
msgstr "especificador de formato inválido"
#: py/objstr.c:1192
msgid "sign not allowed in string format specifier"
@ -1760,9 +1739,8 @@ msgid "incomplete format key"
msgstr ""
#: py/objstr.c:1482
#, fuzzy
msgid "incomplete format"
msgstr "formato inválido"
msgstr "formato incompleto"
#: py/objstr.c:1490
msgid "not enough arguments for format string"
@ -1800,9 +1778,8 @@ msgid "string indices must be integers, not %s"
msgstr ""
#: py/objstrunicode.c:145 py/objstrunicode.c:164
#, fuzzy
msgid "string index out of range"
msgstr "struct: index fuera de rango"
msgstr "string index fuera de rango"
#: py/objtype.c:358
msgid "__init__() should return None"
@ -1851,9 +1828,8 @@ msgid "type '%q' is not an acceptable base type"
msgstr ""
#: py/objtype.c:1137
#, fuzzy
msgid "multiple inheritance not supported"
msgstr "operación I2C no soportada"
msgstr "herencia multiple no soportada"
#: py/objtype.c:1164
msgid "multiple bases have instance lay-out conflict"
@ -1872,14 +1848,12 @@ msgid "issubclass() arg 1 must be a class"
msgstr ""
#: py/parse.c:726
#, fuzzy
msgid "constant must be an integer"
msgstr "heap debe ser una lista"
msgstr "constant debe ser un entero"
#: py/parse.c:868
#, fuzzy
msgid "Unable to init parser"
msgstr "No se pudo encontrar un GCLK disponible"
msgstr "Incapaz de inicializar el parser"
#: py/parse.c:1170
msgid "unexpected indent"
@ -1895,7 +1869,7 @@ msgstr ""
#: py/parsenum.c:151
msgid "invalid syntax for integer"
msgstr "formato inválido"
msgstr "sintaxis inválido para entero"
#: py/parsenum.c:155
#, c-format
@ -1904,11 +1878,11 @@ msgstr ""
#: py/parsenum.c:339
msgid "invalid syntax for number"
msgstr "argumentos inválidos"
msgstr "sintaxis inválido para número"
#: py/parsenum.c:342
msgid "decimal numbers not supported"
msgstr "bytes > 8 bits no son soportados"
msgstr "números decimales no soportados"
#: py/persistentcode.c:223
msgid ""
@ -1922,7 +1896,7 @@ msgstr ""
#: py/runtime.c:206
msgid "name not defined"
msgstr "módulo no encontrado"
msgstr "name no definido"
#: py/runtime.c:209
msgid "name '%q' is not defined"
@ -1997,9 +1971,8 @@ msgid "exceptions must derive from BaseException"
msgstr ""
#: py/runtime.c:1430
#, fuzzy
msgid "cannot import name %q"
msgstr "ningún módulo se llama '%q'"
msgstr "no se puede importar name '%q'"
#: py/runtime.c:1535
msgid "memory allocation failed, heap is locked"
@ -2019,9 +1992,8 @@ msgid "object not in sequence"
msgstr ""
#: py/stream.c:96
#, fuzzy
msgid "stream operation not supported"
msgstr "operación I2C no soportada"
msgstr "operación stream no soportada"
#: py/vm.c:255
msgid "local variable referenced before assignment"
@ -2192,7 +2164,6 @@ msgid "stop must be 1 or 2"
msgstr ""
#: shared-bindings/digitalio/DigitalInOut.c:211
#, fuzzy
msgid "Invalid direction."
msgstr "Dirección inválida."
@ -2353,9 +2324,8 @@ msgid "index must be int"
msgstr ""
#: shared-bindings/pulseio/PulseIn.c:293
#, fuzzy
msgid "Read-only"
msgstr "Solo lectura"
msgstr "Solo-lectura"
#: shared-bindings/pulseio/PulseOut.c:135
msgid "Array must contain halfwords (type 'H')"
@ -2386,6 +2356,10 @@ msgstr ""
msgid "RTC calibration is not supported on this board"
msgstr ""
#: shared-bindings/socket/__init__.c:516 shared-module/network/__init__.c:81
msgid "no available NIC"
msgstr ""
#: shared-bindings/storage/__init__.c:77
msgid "filesystem must provide mount method"
msgstr ""
@ -2410,15 +2384,15 @@ msgstr ""
msgid "time.struct_time() takes a 9-sequence"
msgstr ""
#: shared-bindings/time/__init__.c:169 shared-bindings/time/__init__.c:250
#: shared-bindings/time/__init__.c:169 shared-bindings/time/__init__.c:264
msgid "Tuple or struct_time argument required"
msgstr ""
#: shared-bindings/time/__init__.c:174 shared-bindings/time/__init__.c:255
#: shared-bindings/time/__init__.c:174 shared-bindings/time/__init__.c:269
msgid "function takes exactly 9 arguments"
msgstr ""
#: shared-bindings/time/__init__.c:226 shared-bindings/time/__init__.c:259
#: shared-bindings/time/__init__.c:240 shared-bindings/time/__init__.c:273
msgid "timestamp out of range for platform time_t"
msgstr ""
@ -2520,14 +2494,12 @@ msgid "Group full"
msgstr ""
#: shared-module/displayio/Group.c:48
#, fuzzy
msgid "Group empty"
msgstr "heap vacío"
msgstr "Group vacío"
#: shared-module/displayio/OnDiskBitmap.c:49
#, fuzzy
msgid "Invalid BMP file"
msgstr "pin inválido"
msgstr "Archivo BMP inválido"
#: shared-module/displayio/OnDiskBitmap.c:59
#, c-format
@ -2566,10 +2538,10 @@ msgstr ""
#~ msgstr "No se puede aplicar el nombre del dispositivo en el stack."
#~ msgid "Can not add Characteristic."
#~ msgstr "No se puede agregar la Característica"
#~ msgstr "No se puede agregar la Característica."
#~ msgid "Can not add Service."
#~ msgstr "No se puede agregar el Servicio"
#~ msgstr "No se puede agregar el Servicio."
#~ msgid "Can not query for the device address."
#~ msgstr "No se puede consultar la dirección del dispositivo."

View File

@ -7,7 +7,7 @@ msgid ""
msgstr ""
"Project-Id-Version: \n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2018-10-21 17:15+0200\n"
"POT-Creation-Date: 2018-11-07 14:10-0500\n"
"PO-Revision-Date: 2018-08-30 23:04-0700\n"
"Last-Translator: Timothy <me@timothygarcia.ca>\n"
"Language-Team: fil\n"
@ -147,15 +147,15 @@ msgstr "abort() tinawag"
msgid "invalid arguments"
msgstr "mali ang mga argumento"
#: lib/utils/pyexec.c:97 py/builtinimport.c:253
#: lib/utils/pyexec.c:97 py/builtinimport.c:251
msgid "script compilation not supported"
msgstr "script kompilasyon hindi supportado"
#: main.c:143
#: main.c:153
msgid " output:\n"
msgstr " output:\n"
#: main.c:157 main.c:230
#: main.c:167 main.c:240
msgid ""
"Auto-reload is on. Simply save files over USB to run them or enter REPL to "
"disable.\n"
@ -163,48 +163,48 @@ msgstr ""
"Ang awtomatikong pag re-reload ay ON. i-save lamang ang mga files sa USB "
"para patakbuhin sila o pasukin ang REPL para i-disable ito.\n"
#: main.c:159
#: main.c:169
msgid "Running in safe mode! Auto-reload is off.\n"
msgstr "Tumatakbo sa safe mode! Awtomatikong pag re-reload ay OFF.\n"
#: main.c:161 main.c:232
#: main.c:171 main.c:242
msgid "Auto-reload is off.\n"
msgstr "Awtomatikong pag re-reload ay OFF.\n"
#: main.c:175
#: main.c:185
msgid "Running in safe mode! Not running saved code.\n"
msgstr "Tumatakbo sa safe mode! Hindi tumatakbo ang nai-save na code.\n"
#: main.c:191
#: main.c:201
msgid "WARNING: Your code filename has two extensions\n"
msgstr "BABALA: Ang pangalan ng file ay may dalawang extension\n"
#: main.c:239
#: main.c:249
msgid "You requested starting safe mode by "
msgstr "Ikaw ang humiling sa safe mode sa pamamagitan ng "
#: main.c:242
#: main.c:252
msgid "To exit, please reset the board without "
msgstr "Para lumabas, paki-reset ang board na wala ang "
#: main.c:249
#: main.c:259
msgid ""
"You are running in safe mode which means something really bad happened.\n"
msgstr ""
"Ikaw ay tumatakbo sa safe mode, ang ibig sabihin nito ay may masamang "
"nangyari.\n"
#: main.c:251
#: main.c:261
msgid "Looks like our core CircuitPython code crashed hard. Whoops!\n"
msgstr "Mukhang ang core CircuitPython code ay nag-crash ng malakas. Aray!\n"
#: main.c:252
#: main.c:262
msgid "Please file an issue here with the contents of your CIRCUITPY drive:\n"
msgstr ""
"Mag-file ng isang isyu dito gamit ang mga nilalaman ng iyong CIRCUITPY "
"drive:\n"
#: main.c:255
#: main.c:265
msgid ""
"The microcontroller's power dipped. Please make sure your power supply "
"provides\n"
@ -212,7 +212,7 @@ msgstr ""
"Ang kapangyarihan ng mikrokontroller ay bumaba. Mangyaring suriin ang power "
"supply \n"
#: main.c:256
#: main.c:266
msgid ""
"enough power for the whole circuit and press reset (after ejecting "
"CIRCUITPY).\n"
@ -220,13 +220,13 @@ msgstr ""
"ay nagbibigay ng sapat na power para sa buong circuit at i-press ang reset "
"(pagkatapos i-eject ang CIRCUITPY).\n"
#: main.c:260
#: main.c:270
msgid "Press any key to enter the REPL. Use CTRL-D to reload."
msgstr ""
"Pindutin ang anumang key upang ipasok ang REPL. Gamitin ang CTRL-D upang i-"
"reload."
#: main.c:416
#: main.c:426
msgid "soft reboot\n"
msgstr "malambot na reboot\n"
@ -983,19 +983,19 @@ msgstr "masamang typecode"
msgid "bad compile mode"
msgstr "masamang mode ng compile"
#: py/builtinimport.c:338
#: py/builtinimport.c:336
msgid "cannot perform relative import"
msgstr "hindi maaring isagawa ang relative import"
#: py/builtinimport.c:422 py/builtinimport.c:534
#: py/builtinimport.c:420 py/builtinimport.c:532
msgid "module not found"
msgstr "module hindi nakita"
#: py/builtinimport.c:425 py/builtinimport.c:537
#: py/builtinimport.c:423 py/builtinimport.c:535
msgid "no module named '%q'"
msgstr "walang module na '%q'"
#: py/builtinimport.c:512
#: py/builtinimport.c:510
msgid "relative import"
msgstr "relative import"
@ -2407,6 +2407,10 @@ msgstr "Hindi supportado ang RTC sa board na ito"
msgid "RTC calibration is not supported on this board"
msgstr "RTC calibration ay hindi supportado ng board na ito"
#: shared-bindings/socket/__init__.c:516 shared-module/network/__init__.c:81
msgid "no available NIC"
msgstr ""
#: shared-bindings/storage/__init__.c:77
msgid "filesystem must provide mount method"
msgstr "ang filesystem dapat mag bigay ng mount method"
@ -2431,15 +2435,15 @@ msgstr "time.struct_time() kumukuha ng 1 argument"
msgid "time.struct_time() takes a 9-sequence"
msgstr "time.struct_time() kumukuha ng 9-sequence"
#: shared-bindings/time/__init__.c:169 shared-bindings/time/__init__.c:250
#: shared-bindings/time/__init__.c:169 shared-bindings/time/__init__.c:264
msgid "Tuple or struct_time argument required"
msgstr "Tuple o struct_time argument kailangan"
#: shared-bindings/time/__init__.c:174 shared-bindings/time/__init__.c:255
#: shared-bindings/time/__init__.c:174 shared-bindings/time/__init__.c:269
msgid "function takes exactly 9 arguments"
msgstr "function kumukuha ng 9 arguments"
#: shared-bindings/time/__init__.c:226 shared-bindings/time/__init__.c:259
#: shared-bindings/time/__init__.c:240 shared-bindings/time/__init__.c:273
msgid "timestamp out of range for platform time_t"
msgstr "wala sa sakop ng timestamp ang platform time_t"

View File

@ -7,7 +7,7 @@ msgid ""
msgstr ""
"Project-Id-Version: 0.1\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2018-10-21 17:15+0200\n"
"POT-Creation-Date: 2018-11-07 14:10-0500\n"
"PO-Revision-Date: 2018-08-14 11:01+0200\n"
"Last-Translator: Pierrick Couturier <arofarn@arofarn.info>\n"
"Language-Team: fr\n"
@ -146,15 +146,15 @@ msgstr "abort() appelé"
msgid "invalid arguments"
msgstr "arguments invalides"
#: lib/utils/pyexec.c:97 py/builtinimport.c:253
#: lib/utils/pyexec.c:97 py/builtinimport.c:251
msgid "script compilation not supported"
msgstr "compilation du script non supporté"
#: main.c:143
#: main.c:153
msgid " output:\n"
msgstr " sortie:\n"
#: main.c:157 main.c:230
#: main.c:167 main.c:240
msgid ""
"Auto-reload is on. Simply save files over USB to run them or enter REPL to "
"disable.\n"
@ -162,46 +162,46 @@ msgstr ""
"Auto-chargement activé. Copiez simplement les fichiers en USB pour les "
"lancer ou entrez sur REPL pour le désactiver.\n"
#: main.c:159
#: main.c:169
msgid "Running in safe mode! Auto-reload is off.\n"
msgstr "Mode sans-échec. Auto-rechargement désactivé.\n"
#: main.c:161 main.c:232
#: main.c:171 main.c:242
msgid "Auto-reload is off.\n"
msgstr "Auto-rechargement désactivé.\n"
#: main.c:175
#: main.c:185
msgid "Running in safe mode! Not running saved code.\n"
msgstr "Mode sans-échec! Le code sauvegardé ne s'éxecute pas.\n"
#: main.c:191
#: main.c:201
msgid "WARNING: Your code filename has two extensions\n"
msgstr "ATTENTION: le nom de fichier de votre code a deux extensions\n"
#: main.c:239
#: main.c:249
msgid "You requested starting safe mode by "
msgstr "Vous avez demandé à démarrer en mode sans-échec par "
#: main.c:242
#: main.c:252
msgid "To exit, please reset the board without "
msgstr "Pour quitter, redémarrez la carte SVP sans "
#: main.c:249
#: main.c:259
msgid ""
"You are running in safe mode which means something really bad happened.\n"
msgstr ""
"Vous êtes en mode sans-échec ce qui signifie que quelque chose demauvais est "
"arrivé.\n"
#: main.c:251
#: main.c:261
msgid "Looks like our core CircuitPython code crashed hard. Whoops!\n"
msgstr "Il semblerait que votre code CircuitPython a durement planté. Oups!\n"
#: main.c:252
#: main.c:262
msgid "Please file an issue here with the contents of your CIRCUITPY drive:\n"
msgstr "SVP, remontez le problème là avec le contenu du lecteur CIRCUITPY:\n"
#: main.c:255
#: main.c:265
msgid ""
"The microcontroller's power dipped. Please make sure your power supply "
"provides\n"
@ -209,7 +209,7 @@ msgstr ""
"L'alimentation du microcontroleur a chuté. Merci de vérifier que votre "
"alimentation fournit\n"
#: main.c:256
#: main.c:266
msgid ""
"enough power for the whole circuit and press reset (after ejecting "
"CIRCUITPY).\n"
@ -217,11 +217,11 @@ msgstr ""
"assez de puissance pour l'ensemble du circuit et appuyez sur 'reset' (après "
"avoir éjecter CIRCUITPY).\n"
#: main.c:260
#: main.c:270
msgid "Press any key to enter the REPL. Use CTRL-D to reload."
msgstr "Appuyez sur une touche pour entrer sur REPL ou CTRL-D pour recharger."
#: main.c:416
#: main.c:426
msgid "soft reboot\n"
msgstr "redémarrage logiciel\n"
@ -976,19 +976,19 @@ msgstr "mauvais code type"
msgid "bad compile mode"
msgstr "mauvais mode de compilation"
#: py/builtinimport.c:338
#: py/builtinimport.c:336
msgid "cannot perform relative import"
msgstr "ne peut pas réaliser un import relatif"
#: py/builtinimport.c:422 py/builtinimport.c:534
#: py/builtinimport.c:420 py/builtinimport.c:532
msgid "module not found"
msgstr "module introuvable"
#: py/builtinimport.c:425 py/builtinimport.c:537
#: py/builtinimport.c:423 py/builtinimport.c:535
msgid "no module named '%q'"
msgstr "pas de module '%q'"
#: py/builtinimport.c:512
#: py/builtinimport.c:510
msgid "relative import"
msgstr "import relatif"
@ -2235,7 +2235,7 @@ msgstr "La longueur doit être entière"
#: shared-bindings/displayio/FourWire.c:55
#: shared-bindings/displayio/FourWire.c:64
msgid "displayio is a work in progress"
msgstr ""
msgstr "displayio est en cours de développement"
#: shared-bindings/displayio/Group.c:65
#, fuzzy
@ -2252,6 +2252,8 @@ msgstr ""
#: shared-bindings/displayio/Palette.c:102
msgid "color buffer must be 3 bytes (RGB) or 4 bytes (RGB + pad byte)"
msgstr ""
"Le tampon couleur doit avoir 3 octets (RVB) ou 4 octets (RVB + octet de "
"padding)"
#: shared-bindings/displayio/Palette.c:106
#, fuzzy
@ -2298,11 +2300,11 @@ msgstr "ne peut convertir %s en entier int"
#: shared-bindings/i2cslave/I2CSlave.c:101
msgid "address out of bounds"
msgstr ""
msgstr "Adresse hors limite"
#: shared-bindings/i2cslave/I2CSlave.c:107
msgid "addresses is empty"
msgstr ""
msgstr "Adresses est vide"
#: shared-bindings/microcontroller/Pin.c:89
#: shared-bindings/neopixel_write/__init__.c:67
@ -2402,6 +2404,11 @@ msgstr "RTC non supportée sur cette carte"
msgid "RTC calibration is not supported on this board"
msgstr "calibration de la RTC non supportée sur cette carte"
#: shared-bindings/socket/__init__.c:516 shared-module/network/__init__.c:81
#, fuzzy
msgid "no available NIC"
msgstr "NIC non disponible"
#: shared-bindings/storage/__init__.c:77
msgid "filesystem must provide mount method"
msgstr "le system de fichier doit fournir une méthode 'mount'"
@ -2426,15 +2433,15 @@ msgstr "time.struct_time() prend exactement 1 argument"
msgid "time.struct_time() takes a 9-sequence"
msgstr "time.struct_time() prend une séquence de longueur 9"
#: shared-bindings/time/__init__.c:169 shared-bindings/time/__init__.c:250
#: shared-bindings/time/__init__.c:169 shared-bindings/time/__init__.c:264
msgid "Tuple or struct_time argument required"
msgstr "Argument de type tuple ou struct_time nécessaire"
#: shared-bindings/time/__init__.c:174 shared-bindings/time/__init__.c:255
#: shared-bindings/time/__init__.c:174 shared-bindings/time/__init__.c:269
msgid "function takes exactly 9 arguments"
msgstr "la fonction prend exactement 9 arguments"
#: shared-bindings/time/__init__.c:226 shared-bindings/time/__init__.c:259
#: shared-bindings/time/__init__.c:240 shared-bindings/time/__init__.c:273
msgid "timestamp out of range for platform time_t"
msgstr "timestamp hors gamme pour la plateforme time_t"
@ -2459,7 +2466,7 @@ msgstr "Impossible d'allouer le 2e tampon"
#: shared-module/audioio/Mixer.c:82
msgid "Voice index too high"
msgstr ""
msgstr "Index de la voix trop grand"
#: shared-module/audioio/Mixer.c:85
msgid "The sample's sample rate does not match the mixer's"
@ -2471,11 +2478,11 @@ msgstr ""
#: shared-module/audioio/Mixer.c:91
msgid "The sample's bits_per_sample does not match the mixer's"
msgstr ""
msgstr "Le bits_per_sample de l'échantillon ne correspond pas au mixer"
#: shared-module/audioio/Mixer.c:100
msgid "The sample's signedness does not match the mixer's"
msgstr ""
msgstr "L'échantillon non signé ne correspond pas au mixer"
#: shared-module/audioio/WaveFile.c:61
msgid "Invalid wave file"
@ -2527,7 +2534,7 @@ msgstr "Pas de transfert sans broches MOSI et MISO"
#: shared-module/displayio/Bitmap.c:49
msgid "Only bit maps of 8 bit color or less are supported"
msgstr ""
msgstr "Seul les mappings en couleur 8 bits (ou moins) sont supportés"
#: shared-module/displayio/Bitmap.c:69
msgid "row must be packed and word aligned"
@ -2535,12 +2542,12 @@ msgstr ""
#: shared-module/displayio/Group.c:39
msgid "Group full"
msgstr ""
msgstr "Group complet"
#: shared-module/displayio/Group.c:48
#, fuzzy
msgid "Group empty"
msgstr "vide"
msgstr "Groupe vide"
#: shared-module/displayio/OnDiskBitmap.c:49
#, fuzzy
@ -2550,12 +2557,12 @@ msgstr "Fichier invalide"
#: shared-module/displayio/OnDiskBitmap.c:59
#, c-format
msgid "Only Windows format, uncompressed BMP supported %d"
msgstr ""
msgstr "Seul le format Windows, BMP non compressé, est supporté %d"
#: shared-module/displayio/OnDiskBitmap.c:64
#, c-format
msgid "Only true color (24 bpp or higher) BMP supported %x"
msgstr ""
msgstr "Seul les BMP 'true color' (24 bpp ou plus) sont supportés %x"
#: shared-module/struct/__init__.c:39
msgid "'S' and 'O' are not supported format types"
@ -2567,11 +2574,11 @@ msgstr "trop d'arguments fournis avec ce format"
#, fuzzy
#~ msgid "palette must be displayio.Palette"
#~ msgstr "la palette doit être longue de 32 octets"
#~ msgstr "palettre doit être displayio.Palette"
#, fuzzy
#~ msgid "value_size must be power of two"
#~ msgstr "'len' doit être un multiple de 4"
#~ msgstr "value_size est une puissance de deux"
#~ msgid "Invalid Service type"
#~ msgstr "Type de service invalide"

View File

@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2018-10-21 17:15+0200\n"
"POT-Creation-Date: 2018-11-07 14:10-0500\n"
"PO-Revision-Date: 2018-10-02 16:27+0200\n"
"Last-Translator: Enrico Paganin <enrico.paganin@mail.com>\n"
"Language-Team: \n"
@ -147,15 +147,15 @@ msgstr "abort() chiamato"
msgid "invalid arguments"
msgstr "argomenti non validi"
#: lib/utils/pyexec.c:97 py/builtinimport.c:253
#: lib/utils/pyexec.c:97 py/builtinimport.c:251
msgid "script compilation not supported"
msgstr "compilazione dello scrip non suportata"
#: main.c:143
#: main.c:153
msgid " output:\n"
msgstr " output:\n"
#: main.c:157 main.c:230
#: main.c:167 main.c:240
msgid ""
"Auto-reload is on. Simply save files over USB to run them or enter REPL to "
"disable.\n"
@ -163,50 +163,50 @@ msgstr ""
"L'auto-reload è attivo. Salva i file su USB per eseguirli o entra nel REPL "
"per disabilitarlo.\n"
#: main.c:159
#: main.c:169
msgid "Running in safe mode! Auto-reload is off.\n"
msgstr "Modalità sicura in esecuzione! Auto-reload disattivato.\n"
#: main.c:161 main.c:232
#: main.c:171 main.c:242
msgid "Auto-reload is off.\n"
msgstr "Auto-reload disattivato.\n"
#: main.c:175
#: main.c:185
msgid "Running in safe mode! Not running saved code.\n"
msgstr "Modalità sicura in esecuzione! Codice salvato non in esecuzione.\n"
#: main.c:191
#: main.c:201
msgid "WARNING: Your code filename has two extensions\n"
msgstr "ATTENZIONE: Il nome del sorgente ha due estensioni\n"
#: main.c:239
#: main.c:249
msgid "You requested starting safe mode by "
msgstr "È stato richiesto l'avvio in modalità sicura da "
#: main.c:242
#: main.c:252
msgid "To exit, please reset the board without "
msgstr "Per uscire resettare la scheda senza "
#: main.c:249
#: main.c:259
msgid ""
"You are running in safe mode which means something really bad happened.\n"
msgstr ""
"Sei nella modalità sicura che significa che qualcosa di molto brutto è "
"successo.\n"
#: main.c:251
#: main.c:261
msgid "Looks like our core CircuitPython code crashed hard. Whoops!\n"
msgstr ""
"Sembra che il codice del core di CircuitPython sia crashato malamente. "
"Whoops!\n"
#: main.c:252
#: main.c:262
msgid "Please file an issue here with the contents of your CIRCUITPY drive:\n"
msgstr ""
"Ti preghiamo di compilare una issue con il contenuto del tuo drie "
"CIRCUITPY:\n"
#: main.c:255
#: main.c:265
msgid ""
"The microcontroller's power dipped. Please make sure your power supply "
"provides\n"
@ -214,7 +214,7 @@ msgstr ""
"La potenza del microcontrollore è calata. Assicurati che l'alimentazione sia "
"attaccata correttamente\n"
#: main.c:256
#: main.c:266
msgid ""
"enough power for the whole circuit and press reset (after ejecting "
"CIRCUITPY).\n"
@ -222,12 +222,12 @@ msgstr ""
"abbastanza potenza per l'intero circuito e premere reset (dopo aver espulso "
"CIRCUITPY).\n"
#: main.c:260
#: main.c:270
msgid "Press any key to enter the REPL. Use CTRL-D to reload."
msgstr ""
"Premi un qualunque tasto per entrare nel REPL. Usa CTRL-D per ricaricare."
#: main.c:416
#: main.c:426
msgid "soft reboot\n"
msgstr "soft reboot\n"
@ -983,19 +983,19 @@ msgstr ""
msgid "bad compile mode"
msgstr ""
#: py/builtinimport.c:338
#: py/builtinimport.c:336
msgid "cannot perform relative import"
msgstr "impossibile effettuare l'importazione relativa"
#: py/builtinimport.c:422 py/builtinimport.c:534
#: py/builtinimport.c:420 py/builtinimport.c:532
msgid "module not found"
msgstr "modulo non trovato"
#: py/builtinimport.c:425 py/builtinimport.c:537
#: py/builtinimport.c:423 py/builtinimport.c:535
msgid "no module named '%q'"
msgstr "nessun modulo chiamato '%q'"
#: py/builtinimport.c:512
#: py/builtinimport.c:510
msgid "relative import"
msgstr "importazione relativa"
@ -2393,6 +2393,11 @@ msgstr "RTC non supportato su questa scheda"
msgid "RTC calibration is not supported on this board"
msgstr "calibrazione RTC non supportata su questa scheda"
#: shared-bindings/socket/__init__.c:516 shared-module/network/__init__.c:81
#, fuzzy
msgid "no available NIC"
msgstr "busio.UART non ancora implementato"
#: shared-bindings/storage/__init__.c:77
msgid "filesystem must provide mount method"
msgstr "il filesystem deve fornire un metodo di mount"
@ -2417,15 +2422,15 @@ msgstr "time.struct_time() prende esattamente un argomento"
msgid "time.struct_time() takes a 9-sequence"
msgstr ""
#: shared-bindings/time/__init__.c:169 shared-bindings/time/__init__.c:250
#: shared-bindings/time/__init__.c:169 shared-bindings/time/__init__.c:264
msgid "Tuple or struct_time argument required"
msgstr "Tupla o struct_time richiesto come argomento"
#: shared-bindings/time/__init__.c:174 shared-bindings/time/__init__.c:255
#: shared-bindings/time/__init__.c:174 shared-bindings/time/__init__.c:269
msgid "function takes exactly 9 arguments"
msgstr "la funzione prende esattamente 9 argomenti"
#: shared-bindings/time/__init__.c:226 shared-bindings/time/__init__.c:259
#: shared-bindings/time/__init__.c:240 shared-bindings/time/__init__.c:273
msgid "timestamp out of range for platform time_t"
msgstr "timestamp è fuori intervallo per il time_t della piattaforma"

View File

@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2018-10-21 17:15+0200\n"
"POT-Creation-Date: 2018-11-07 14:10-0500\n"
"PO-Revision-Date: 2018-10-02 21:14-0000\n"
"Last-Translator: \n"
"Language-Team: \n"
@ -147,74 +147,74 @@ msgstr "abort() chamado"
msgid "invalid arguments"
msgstr "argumentos inválidos"
#: lib/utils/pyexec.c:97 py/builtinimport.c:253
#: lib/utils/pyexec.c:97 py/builtinimport.c:251
msgid "script compilation not supported"
msgstr "compilação de script não suportada"
#: main.c:143
#: main.c:153
msgid " output:\n"
msgstr " saída:\n"
#: main.c:157 main.c:230
#: main.c:167 main.c:240
msgid ""
"Auto-reload is on. Simply save files over USB to run them or enter REPL to "
"disable.\n"
msgstr ""
#: main.c:159
#: main.c:169
msgid "Running in safe mode! Auto-reload is off.\n"
msgstr "Rodando em modo seguro! Atualização automática está desligada.\n"
#: main.c:161 main.c:232
#: main.c:171 main.c:242
msgid "Auto-reload is off.\n"
msgstr "A atualização automática está desligada.\n"
#: main.c:175
#: main.c:185
msgid "Running in safe mode! Not running saved code.\n"
msgstr "Rodando em modo seguro! Não está executando o código salvo.\n"
#: main.c:191
#: main.c:201
msgid "WARNING: Your code filename has two extensions\n"
msgstr "AVISO: Seu arquivo de código tem duas extensões\n"
#: main.c:239
#: main.c:249
msgid "You requested starting safe mode by "
msgstr "Você solicitou o início do modo de segurança"
#: main.c:242
#: main.c:252
msgid "To exit, please reset the board without "
msgstr "Para sair, por favor, reinicie a placa sem "
#: main.c:249
#: main.c:259
msgid ""
"You are running in safe mode which means something really bad happened.\n"
msgstr ""
#: main.c:251
#: main.c:261
msgid "Looks like our core CircuitPython code crashed hard. Whoops!\n"
msgstr ""
#: main.c:252
#: main.c:262
msgid "Please file an issue here with the contents of your CIRCUITPY drive:\n"
msgstr ""
#: main.c:255
#: main.c:265
msgid ""
"The microcontroller's power dipped. Please make sure your power supply "
"provides\n"
msgstr ""
#: main.c:256
#: main.c:266
msgid ""
"enough power for the whole circuit and press reset (after ejecting "
"CIRCUITPY).\n"
msgstr ""
#: main.c:260
#: main.c:270
msgid "Press any key to enter the REPL. Use CTRL-D to reload."
msgstr ""
#: main.c:416
#: main.c:426
msgid "soft reboot\n"
msgstr ""
@ -962,19 +962,19 @@ msgstr ""
msgid "bad compile mode"
msgstr ""
#: py/builtinimport.c:338
#: py/builtinimport.c:336
msgid "cannot perform relative import"
msgstr ""
#: py/builtinimport.c:422 py/builtinimport.c:534
#: py/builtinimport.c:420 py/builtinimport.c:532
msgid "module not found"
msgstr ""
#: py/builtinimport.c:425 py/builtinimport.c:537
#: py/builtinimport.c:423 py/builtinimport.c:535
msgid "no module named '%q'"
msgstr ""
#: py/builtinimport.c:512
#: py/builtinimport.c:510
msgid "relative import"
msgstr ""
@ -2347,6 +2347,10 @@ msgstr "O RTC não é suportado nesta placa"
msgid "RTC calibration is not supported on this board"
msgstr "A calibração RTC não é suportada nesta placa"
#: shared-bindings/socket/__init__.c:516 shared-module/network/__init__.c:81
msgid "no available NIC"
msgstr ""
#: shared-bindings/storage/__init__.c:77
msgid "filesystem must provide mount method"
msgstr "sistema de arquivos deve fornecer método de montagem"
@ -2371,15 +2375,15 @@ msgstr ""
msgid "time.struct_time() takes a 9-sequence"
msgstr ""
#: shared-bindings/time/__init__.c:169 shared-bindings/time/__init__.c:250
#: shared-bindings/time/__init__.c:169 shared-bindings/time/__init__.c:264
msgid "Tuple or struct_time argument required"
msgstr "Tuple or struct_time argument required"
#: shared-bindings/time/__init__.c:174 shared-bindings/time/__init__.c:255
#: shared-bindings/time/__init__.c:174 shared-bindings/time/__init__.c:269
msgid "function takes exactly 9 arguments"
msgstr "função leva exatamente 9 argumentos"
#: shared-bindings/time/__init__.c:226 shared-bindings/time/__init__.c:259
#: shared-bindings/time/__init__.c:240 shared-bindings/time/__init__.c:273
msgid "timestamp out of range for platform time_t"
msgstr "timestamp fora do intervalo para a plataforma time_t"

12
main.c
View File

@ -54,6 +54,10 @@
#include "supervisor/shared/stack.h"
#include "supervisor/serial.h"
#ifdef MICROPY_PY_NETWORK
#include "shared-module/network/__init__.h"
#endif
void do_str(const char *src, mp_parse_input_kind_t input_kind) {
mp_lexer_t *lex = mp_lexer_new_from_str_len(MP_QSTR__lt_stdin_gt_, src, strlen(src), 0);
if (lex == NULL) {
@ -108,10 +112,16 @@ void start_mp(supervisor_allocation* heap) {
mp_obj_list_append(mp_sys_path, MP_OBJ_NEW_QSTR(MP_FROZEN_FAKE_DIR_QSTR));
mp_obj_list_init(mp_sys_argv, 0);
#if MICROPY_PY_NETWORK
network_module_init();
#endif
}
void stop_mp(void) {
#if MICROPY_PY_NETWORK
network_module_deinit();
#endif
}
#define STRING_LIST(...) {__VA_ARGS__, ""}

View File

@ -123,7 +123,6 @@ endif
CFLAGS += $(INC) -Wall -Werror -std=gnu11 -nostdlib $(BASE_CFLAGS) $(CFLAGS_MOD) $(COPT)
ifeq ($(CHIP_FAMILY), samd21)
CFLAGS += \
-mthumb \
@ -287,6 +286,26 @@ SRC_C = \
freetouch/adafruit_ptc.c \
supervisor/shared/memory.c
ifeq ($(MICROPY_PY_NETWORK),1)
CFLAGS += -DMICROPY_PY_NETWORK=1
SRC_MOD += lib/netutils/netutils.c
ifneq ($(MICROPY_PY_WIZNET5K),0)
WIZNET5K_DIR=drivers/wiznet5k
INC += -I$(TOP)/$(WIZNET5K_DIR)
CFLAGS_MOD += -DMICROPY_PY_WIZNET5K=$(MICROPY_PY_WIZNET5K) -D_WIZCHIP_=$(MICROPY_PY_WIZNET5K)
SRC_MOD += $(addprefix $(WIZNET5K_DIR)/,\
ethernet/w$(MICROPY_PY_WIZNET5K)/w$(MICROPY_PY_WIZNET5K).c \
ethernet/wizchip_conf.c \
ethernet/socket.c \
internet/dns/dns.c \
internet/dhcp/dhcp.c \
)
endif # MICROPY_PY_WIZNET5K
endif # MICROPY_PY_NETWORK
# Choose which flash filesystem impl to use.
# (Right now INTERNAL_FLASH_FILESYSTEM and SPI_FLASH_FILESYSTEM are mutually exclusive.
# But that might not be true in the future.)
@ -362,7 +381,6 @@ SRC_LIBM = $(addprefix lib/,\
)
endif
# These don't have corresponding files in each port but are still located in
# shared-bindings to make it clear what the contents of the modules are.
SRC_BINDINGS_ENUMS = \
@ -401,6 +419,13 @@ SRC_SHARED_MODULE = \
uheap/__init__.c \
ustack/__init__.c
ifeq ($(MICROPY_PY_NETWORK),1)
SRC_SHARED_MODULE += socket/__init__.c network/__init__.c
ifneq ($(MICROPY_PY_WIZNET5K),0)
SRC_SHARED_MODULE += wiznet/__init__.c wiznet/wiznet5k.c
endif
endif
# SAMRs don't have a DAC
ifneq ($(CHIP_VARIANT),SAMR21G18A)
SRC_COMMON_HAL += \
@ -443,6 +468,7 @@ ifeq ($(INTERNAL_LIBM),1)
OBJ += $(addprefix $(BUILD)/, $(SRC_LIBM:.c=.o))
endif
OBJ += $(addprefix $(BUILD)/, $(SRC_S:.s=.o))
OBJ += $(addprefix $(BUILD)/, $(SRC_MOD:.c=.o))
SRC_QSTR += $(SRC_C) $(SRC_SUPERVISOR) $(SRC_COMMON_HAL_EXPANDED) $(SRC_SHARED_MODULE_EXPANDED) $(STM_SRC_C)
# Sources that only hold QSTRs after pre-processing.

View File

@ -31,6 +31,7 @@
#include "usb_mass_storage.h"
#include "shared-module/displayio/__init__.h"
#include "shared-module/network/__init__.h"
volatile uint64_t last_finished_tick = 0;
@ -41,6 +42,9 @@ void run_background_tasks(void) {
#ifdef CIRCUITPY_DISPLAYIO
displayio_refresh_display();
#endif
#if MICROPY_PY_NETWORK
network_module_background();
#endif
usb_msc_background();
usb_cdc_background();
last_finished_tick = ticks_ms;

View File

@ -0,0 +1,40 @@
/*
* This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
* Copyright (c) 2017 Scott Shawcroft for Adafruit Industries
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#include "boards/board.h"
#include "mpconfigboard.h"
#include "hal/include/hal_gpio.h"
void board_init(void)
{
}
bool board_requests_safe_mode(void) {
return false;
}
void reset_board(void) {
}

View File

@ -0,0 +1,26 @@
#define MICROPY_HW_BOARD_NAME "Arduino MKR1300"
#define MICROPY_HW_MCU_NAME "samd21g18"
#define MICROPY_PORT_A (PORT_PA24 | PORT_PA25)
#define MICROPY_PORT_B (0)
#define MICROPY_PORT_C (0)
#include "internal_flash.h"
#define CIRCUITPY_INTERNAL_NVM_SIZE 0
#define BOARD_FLASH_SIZE (0x00040000 - 0x2000 - 0x010000)
#define DEFAULT_I2C_BUS_SCL (&pin_PA09)
#define DEFAULT_I2C_BUS_SDA (&pin_PA08)
#define DEFAULT_SPI_BUS_SCK (&pin_PA13)
#define DEFAULT_SPI_BUS_MOSI (&pin_PA12)
#define DEFAULT_SPI_BUS_MISO (&pin_PA15)
#define DEFAULT_UART_BUS_RX (&pin_PB23)
#define DEFAULT_UART_BUS_TX (&pin_PB22)
// USB is always used internally so skip the pin objects for it.
#define IGNORE_PIN_PA24 1
#define IGNORE_PIN_PA25 1

View File

@ -0,0 +1,11 @@
LD_FILE = boards/samd21x18-bootloader.ld
USB_VID = 0x2341
USB_PID = 0x8053
USB_PRODUCT = "Arduino MKR1300"
USB_MANUFACTURER = "Arduino"
INTERNAL_FLASH_FILESYSTEM = 1
LONGINT_IMPL = NONE
CHIP_VARIANT = SAMD21G18A
CHIP_FAMILY = samd21

View File

@ -0,0 +1,44 @@
#include "shared-bindings/board/__init__.h"
#include "board_busses.h"
STATIC const mp_rom_map_elem_t board_global_dict_table[] = {
{ MP_ROM_QSTR(MP_QSTR_A0), MP_ROM_PTR(&pin_PA02) },
{ MP_ROM_QSTR(MP_QSTR_A1), MP_ROM_PTR(&pin_PB02) },
{ MP_ROM_QSTR(MP_QSTR_A2), MP_ROM_PTR(&pin_PB03) },
{ MP_ROM_QSTR(MP_QSTR_A3), MP_ROM_PTR(&pin_PA04) },
{ MP_ROM_QSTR(MP_QSTR_A4), MP_ROM_PTR(&pin_PA05) },
{ MP_ROM_QSTR(MP_QSTR_A5), MP_ROM_PTR(&pin_PA06) },
{ MP_ROM_QSTR(MP_QSTR_A6), MP_ROM_PTR(&pin_PA07) },
{ MP_ROM_QSTR(MP_QSTR_D0), MP_ROM_PTR(&pin_PA22) },
{ MP_ROM_QSTR(MP_QSTR_RX), MP_ROM_PTR(&pin_PB23) },
{ MP_ROM_QSTR(MP_QSTR_D1), MP_ROM_PTR(&pin_PA23) },
{ MP_ROM_QSTR(MP_QSTR_TX), MP_ROM_PTR(&pin_PB22) },
{ MP_ROM_QSTR(MP_QSTR_D2), MP_ROM_PTR(&pin_PA10) },
{ MP_ROM_QSTR(MP_QSTR_D3), MP_ROM_PTR(&pin_PA11) },
{ MP_ROM_QSTR(MP_QSTR_D4), MP_ROM_PTR(&pin_PB10) },
{ MP_ROM_QSTR(MP_QSTR_D5), MP_ROM_PTR(&pin_PB11) },
{ MP_ROM_QSTR(MP_QSTR_D6), MP_ROM_PTR(&pin_PA20) },
{ MP_ROM_QSTR(MP_QSTR_D7), MP_ROM_PTR(&pin_PA21) },
{ MP_ROM_QSTR(MP_QSTR_D8), MP_ROM_PTR(&pin_PA16) },
{ MP_ROM_QSTR(MP_QSTR_D9), MP_ROM_PTR(&pin_PA17) },
{ MP_ROM_QSTR(MP_QSTR_D10), MP_ROM_PTR(&pin_PA19) },
{ MP_ROM_QSTR(MP_QSTR_D11), MP_ROM_PTR(&pin_PA08) },
{ MP_ROM_QSTR(MP_QSTR_D12), MP_ROM_PTR(&pin_PA09) },
{ MP_ROM_QSTR(MP_QSTR_D13), MP_ROM_PTR(&pin_PB23) },
{ MP_ROM_QSTR(MP_QSTR_D14), MP_ROM_PTR(&pin_PB22) },
{ MP_ROM_QSTR(MP_QSTR_BOOT), MP_ROM_PTR(&pin_PB09) }, // NOTE: LORA BOOT
{ MP_ROM_QSTR(MP_QSTR_SDA), MP_ROM_PTR(&pin_PA08) },
{ MP_ROM_QSTR(MP_QSTR_SCL), MP_ROM_PTR(&pin_PA09) },
{ MP_ROM_QSTR(MP_QSTR_SCK), MP_ROM_PTR(&pin_PA13) },
{ MP_ROM_QSTR(MP_QSTR_MOSI), MP_ROM_PTR(&pin_PA12) },
{ MP_ROM_QSTR(MP_QSTR_MISO), MP_ROM_PTR(&pin_PA15) },
{ MP_ROM_QSTR(MP_QSTR_RFM9X_RST), MP_ROM_PTR(&pin_PA27) },
{ MP_ROM_QSTR(MP_QSTR_RFM9X_CS), MP_ROM_PTR(&pin_PA14) },
{ MP_ROM_QSTR(MP_QSTR_VOLTAGE_MONITOR), MP_ROM_PTR(&pin_PB08) },
{ MP_ROM_QSTR(MP_QSTR_BATTERY), MP_ROM_PTR(&pin_PB08) },
{ MP_ROM_QSTR(MP_QSTR_I2C), MP_ROM_PTR(&board_i2c_obj) },
{ MP_ROM_QSTR(MP_QSTR_SPI), MP_ROM_PTR(&board_spi_obj) },
{ MP_ROM_QSTR(MP_QSTR_UART), MP_ROM_PTR(&board_uart_obj) },
};
MP_DEFINE_CONST_DICT(board_module_globals, board_global_dict_table);

View File

@ -0,0 +1,39 @@
/*
* This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
* Copyright (c) 2017 Scott Shawcroft for Adafruit Industries
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#include "boards/board.h"
#include "mpconfigboard.h"
#include "hal/include/hal_gpio.h"
void board_init(void) {
}
bool board_requests_safe_mode(void) {
return false;
}
void reset_board(void) {
}

View File

@ -0,0 +1,39 @@
#define MICROPY_HW_BOARD_NAME "CP32-M4"
#define MICROPY_HW_MCU_NAME "samd51g19"
#define MICROPY_HW_APA102_MOSI (&pin_PA17)
#define MICROPY_HW_APA102_SCK (&pin_PA16)
#define CIRCUITPY_MCU_FAMILY samd51
#define MICROPY_PORT_A (PORT_PA08 | PORT_PA09 | PORT_PA10 | PORT_PA11| PORT_PA16| PORT_PA17)
#define MICROPY_PORT_B ( PORT_PB10 | PORT_PB11)
#define MICROPY_PORT_C (0)
#define MICROPY_PORT_D (0)
#define AUTORESET_DELAY_MS 500
// If you change this, then make sure to update the linker scripts as well to
// make sure you don't overwrite code
#define CIRCUITPY_INTERNAL_NVM_SIZE 8192
#define BOARD_FLASH_SIZE (FLASH_SIZE - 0x4000 - CIRCUITPY_INTERNAL_NVM_SIZE)
#include "external_flash/devices.h"
// these are the labeled pins (SDA, SCL, SCK, MOSI, MISO, etc)
#define EXTERNAL_FLASH_DEVICE_COUNT 1
#define EXTERNAL_FLASH_DEVICES W25Q128JV_PM
#include "external_flash/external_flash.h"
#define DEFAULT_I2C_BUS_SCL (&pin_PB09)
#define DEFAULT_I2C_BUS_SDA (&pin_PB08)
#define DEFAULT_SPI_BUS_SCK (&pin_PA22)
#define DEFAULT_SPI_BUS_MOSI (&pin_PA23)
#define DEFAULT_SPI_BUS_MISO (&pin_PA21)
#define DEFAULT_UART_BUS_RX (&pin_PA12)
#define DEFAULT_UART_BUS_TX (&pin_PA13)

View File

@ -0,0 +1,10 @@
LD_FILE = boards/samd51x19-bootloader-external-flash.ld
USB_VID = 0x239A
USB_PID = 0x8021
USB_PRODUCT = "CP32-M4"
USB_MANUFACTURER = "Nadda-Reel Company LLC"
QSPI_FLASH_FILESYSTEM = 1
CHIP_VARIANT = SAMD51G19A
CHIP_FAMILY = samd51

View File

@ -0,0 +1,41 @@
#include "shared-bindings/board/__init__.h"
#include "board_busses.h"
// This mapping only includes functional names because pins broken
// out on connectors are labeled with their MCU name available from
// microcontroller.pin.
STATIC const mp_rom_map_elem_t board_global_dict_table[] = {
{ MP_OBJ_NEW_QSTR(MP_QSTR_SPEAKER_P), MP_ROM_PTR(&pin_PA02) },
{ MP_OBJ_NEW_QSTR(MP_QSTR_BATTERY), MP_ROM_PTR(&pin_PB08) },
{ MP_OBJ_NEW_QSTR(MP_QSTR_SW3_4), MP_ROM_PTR(&pin_PB09) },
{ MP_OBJ_NEW_QSTR(MP_QSTR_SW1_2), MP_ROM_PTR(&pin_PA04) },
{ MP_OBJ_NEW_QSTR(MP_QSTR_SPEAKER_N), MP_ROM_PTR(&pin_PA05) },
{ MP_OBJ_NEW_QSTR(MP_QSTR_SW9), MP_ROM_PTR(&pin_PA06) },
{ MP_OBJ_NEW_QSTR(MP_QSTR_SW7), MP_ROM_PTR(&pin_PA07) },
{ MP_OBJ_NEW_QSTR(MP_QSTR_BACKLIGHT_PWM), MP_ROM_PTR(&pin_PA12) },
{ MP_OBJ_NEW_QSTR(MP_QSTR_EXT_HDR3), MP_ROM_PTR(&pin_PA13) },
{ MP_OBJ_NEW_QSTR(MP_QSTR_SW5), MP_ROM_PTR(&pin_PA14) },
{ MP_OBJ_NEW_QSTR(MP_QSTR_EXT_HDR4), MP_ROM_PTR(&pin_PA15) },
{ MP_OBJ_NEW_QSTR(MP_QSTR_APA102_SCK), MP_ROM_PTR(&pin_PA16) },
{ MP_OBJ_NEW_QSTR(MP_QSTR_APA102_MOSI), MP_ROM_PTR(&pin_PA17) },
{ MP_OBJ_NEW_QSTR(MP_QSTR_STATUS_LED), MP_ROM_PTR(&pin_PA18) },
{ MP_OBJ_NEW_QSTR(MP_QSTR_SW6), MP_ROM_PTR(&pin_PA19) },
{ MP_OBJ_NEW_QSTR(MP_QSTR_VSPI_CS0), MP_ROM_PTR(&pin_PA20) },
{ MP_OBJ_NEW_QSTR(MP_QSTR_VSPI_MISO), MP_ROM_PTR(&pin_PA21) },
{ MP_OBJ_NEW_QSTR(MP_QSTR_VSPI_SCK), MP_ROM_PTR(&pin_PA22) },
{ MP_OBJ_NEW_QSTR(MP_QSTR_VSPI_MOSI), MP_ROM_PTR(&pin_PA23) },
{ MP_OBJ_NEW_QSTR(MP_QSTR_VSPI_CS1), MP_ROM_PTR(&pin_PB22) },
{ MP_OBJ_NEW_QSTR(MP_QSTR_EXT_HDR5), MP_ROM_PTR(&pin_PB23) },
{ MP_OBJ_NEW_QSTR(MP_QSTR_LCD_DC), MP_ROM_PTR(&pin_PA27) },
{ MP_ROM_QSTR(MP_QSTR_SW8), MP_ROM_PTR(&pin_PB02) },
{ MP_ROM_QSTR(MP_QSTR_SW10), MP_ROM_PTR(&pin_PB03) },
{ MP_ROM_QSTR(MP_QSTR_I2C), MP_ROM_PTR(&board_i2c_obj) },
{ MP_ROM_QSTR(MP_QSTR_SPI), MP_ROM_PTR(&board_spi_obj) },
{ MP_ROM_QSTR(MP_QSTR_UART), MP_ROM_PTR(&board_uart_obj) },
};
MP_DEFINE_CONST_DICT(board_module_globals, board_global_dict_table);

View File

@ -9,3 +9,6 @@ LONGINT_IMPL = MPZ
CHIP_VARIANT = SAMD21G18A
CHIP_FAMILY = samd21
MICROPY_PY_NETWORK = 1
MICROPY_PY_WIZNET5K = 5500

View File

@ -9,3 +9,6 @@ LONGINT_IMPL = MPZ
CHIP_VARIANT = SAMD51J19A
CHIP_FAMILY = samd51
MICROPY_PY_NETWORK = 1
MICROPY_PY_WIZNET5K = 5500

View File

@ -9,3 +9,6 @@ LONGINT_IMPL = MPZ
CHIP_VARIANT = SAMD21G18A
CHIP_FAMILY = samd21
MICROPY_PY_NETWORK = 1
MICROPY_PY_WIZNET5K = 5500

View File

@ -9,3 +9,6 @@ LONGINT_IMPL = MPZ
CHIP_VARIANT = SAMD51J19A
CHIP_FAMILY = samd51
MICROPY_PY_NETWORK = 1
MICROPY_PY_WIZNET5K = 5500

View File

@ -1,19 +1,20 @@
#define MICROPY_HW_BOARD_NAME "Adafruit Trellis M4 Express"
#define MICROPY_HW_MCU_NAME "samd51g19"
#define CIRCUITPY_MCU_FAMILY samd51
// This is for Rev D
#define MICROPY_HW_APA102_MOSI (&pin_PA01)
#define MICROPY_HW_APA102_SCK (&pin_PA00)
#define MICROPY_HW_APA102_MOSI (&pin_PB03)
#define MICROPY_HW_APA102_SCK (&pin_PB02)
#define CIRCUITPY_BITBANG_APA102
// These are pins not to reset.
// QSPI Data pins & DotStar pins
#define MICROPY_PORT_A (PORT_PA00 | PORT_PA01 | PORT_PA08 | PORT_PA09 | PORT_PA10 | PORT_PA11)
// QSPI CS, and QSPI SCK
#define MICROPY_PORT_B (PORT_PB10 | PORT_PB11)
// QSPI Data pins
#define MICROPY_PORT_A (PORT_PA08 | PORT_PA09 | PORT_PA10 | PORT_PA11)
// DotStar Pins, QSPI CS, and QSPI SCK
#define MICROPY_PORT_B (PORT_PB02 | PORT_PB03 | PORT_PB10 | PORT_PB11)
#define MICROPY_PORT_C (0)
#define MICROPY_PORT_D (0)

View File

@ -39,8 +39,8 @@ STATIC const mp_rom_map_elem_t board_global_dict_table[] = {
// NeoPixels
{ MP_OBJ_NEW_QSTR(MP_QSTR_NEOPIXEL), MP_ROM_PTR(&pin_PA27) },
{ MP_ROM_QSTR(MP_QSTR_APA102_MOSI), MP_ROM_PTR(&pin_PA01) },
{ MP_ROM_QSTR(MP_QSTR_APA102_SCK), MP_ROM_PTR(&pin_PA00) },
{ MP_ROM_QSTR(MP_QSTR_APA102_MOSI), MP_ROM_PTR(&pin_PB03) },
{ MP_ROM_QSTR(MP_QSTR_APA102_SCK), MP_ROM_PTR(&pin_PB02) },
{ MP_ROM_QSTR(MP_QSTR_I2C), MP_ROM_PTR(&board_i2c_obj) },
};

View File

@ -180,9 +180,9 @@ typedef struct {
.write_status_register_split = false, \
}
// Settings for the Winbond W25Q16JV 2MiB SPI flash.
// Settings for the Winbond W25Q16JV-IQ 2MiB SPI flash. Note that JV-IM has a different .memory_type (0x70)
// Datasheet: https://www.winbond.com/resource-files/w25q16jv%20spi%20revf%2005092017.pdf
#define W25Q16JV {\
#define W25Q16JV_IQ {\
.total_size = (1 << 21), /* 2 MiB */ \
.start_up_time_us = 5000, \
.manufacturer_id = 0xef, \
@ -197,6 +197,23 @@ typedef struct {
.write_status_register_split = false, \
}
// Settings for the Winbond W25Q16JV-IM 2MiB SPI flash. Note that JV-IQ has a different .memory_type (0x40)
// Datasheet: https://www.winbond.com/resource-files/w25q16jv%20spi%20revf%2005092017.pdf
#define W25Q16JV_IM {\
.total_size = (1 << 21), /* 2 MiB */ \
.start_up_time_us = 5000, \
.manufacturer_id = 0xef, \
.memory_type = 0x70, \
.capacity = 0x15, \
.max_clock_speed_mhz = 133, \
.has_sector_protection = false, \
.supports_fast_read = true, \
.supports_qspi = true, \
.has_quad_enable = true, \
.supports_qspi_writes = true, \
.write_status_register_split = false, \
}
// Settings for the Winbond W25Q32BV 4MiB SPI flash.
// Datasheet: https://www.winbond.com/resource-files/w25q32bv_revi_100413_wo_automotive.pdf
#define W25Q32BV {\
@ -213,6 +230,22 @@ typedef struct {
.supports_qspi_writes = false, \
.write_status_register_split = false, \
}
// Settings for the Winbond W25Q32JV-IM 4MiB SPI flash.
// Datasheet: https://www.winbond.com/resource-files/w25q32jv%20revg%2003272018%20plus.pdf
#define W25Q32JV_IM {\
.total_size = (1 << 22), /* 4 MiB */ \
.start_up_time_us = 5000, \
.manufacturer_id = 0xef, \
.memory_type = 0x70, \
.capacity = 0x16, \
.max_clock_speed_mhz = 133, \
.has_sector_protection = false, \
.supports_fast_read = true, \
.supports_qspi = true, \
.has_quad_enable = true, \
.supports_qspi_writes = true, \
.write_status_register_split = false, \
}
// Settings for the Winbond W25Q64JV-IM 8MiB SPI flash. Note that JV-IQ has a different .memory_type (0x40)
// Datasheet: http://www.winbond.com/resource-files/w25q64jv%20revj%2003272018%20plus.pdf
@ -266,10 +299,10 @@ typedef struct {
}
// Settings for the Winbond W25Q128JV-SQ 8MiB SPI flash. Note that JV-IM has a different .memory_type (0x70)
// Settings for the Winbond W25Q128JV-SQ 16MiB SPI flash. Note that JV-IM has a different .memory_type (0x70)
// Datasheet: https://www.winbond.com/resource-files/w25q128jv%20revf%2003272018%20plus.pdf
#define W25Q128JV_SQ {\
.total_size = (1 << 23), /* 16 MiB */ \
.total_size = (1 << 24), /* 16 MiB */ \
.start_up_time_us = 5000, \
.manufacturer_id = 0xef, \
.memory_type = 0x40, \
@ -284,5 +317,21 @@ typedef struct {
}
// Settings for the Winbond W25Q128JV-PM 16MiB SPI flash. Note that JV-IM has a different .memory_type (0x70)
// Datasheet: https://www.winbond.com/resource-files/w25q128jv%20revf%2003272018%20plus.pdf
#define W25Q128JV_PM {\
.total_size = (1 << 24), /* 16 MiB */ \
.start_up_time_us = 5000, \
.manufacturer_id = 0xef, \
.memory_type = 0x70, \
.capacity = 0x18, \
.max_clock_speed_mhz = 133, \
.has_sector_protection = false, \
.supports_fast_read = true, \
.supports_qspi = true, \
.has_quad_enable = true, \
.supports_qspi_writes = true, \
.write_status_register_split = false, \
}
#endif // MICROPY_INCLUDED_ATMEL_SAMD_EXTERNAL_FLASH_DEVICES_H

View File

@ -20,8 +20,6 @@
#define MICROPY_COMP_CONST (1)
#define MICROPY_COMP_DOUBLE_TUPLE_ASSIGN (1)
#define MICROPY_COMP_TRIPLE_TUPLE_ASSIGN (1)
// Turn off for consistency
#define MICROPY_CPYTHON_COMPAT (0)
#define MICROPY_MEM_STATS (0)
#define MICROPY_DEBUG_PRINTERS (0)
#define MICROPY_ENABLE_GC (1)
@ -57,7 +55,6 @@
#define MICROPY_PY_DESCRIPTORS (1)
#define MICROPY_PY_MATH (0)
#define MICROPY_PY_CMATH (0)
#define MICROPY_PY_IO (0)
#define MICROPY_PY_URANDOM (0)
#define MICROPY_PY_URANDOM_EXTRA_FUNCS (0)
#define MICROPY_PY_STRUCT (0)
@ -67,6 +64,18 @@
#define MICROPY_FLOAT_HIGH_QUALITY_HASH (1)
#define MICROPY_STREAMS_NON_BLOCK (1)
#ifndef MICROPY_PY_NETWORK
#define MICROPY_PY_NETWORK (0)
#endif
#ifndef MICROPY_PY_WIZNET5K
#define MICROPY_PY_WIZNET5K (0)
#endif
#ifndef MICROPY_PY_CC3K
#define MICROPY_PY_CC3K (0)
#endif
// fatfs configuration used in ffconf.h
#define MICROPY_FATFS_ENABLE_LFN (1)
#define MICROPY_FATFS_LFN_CODE_PAGE (437) /* 1=SFN/ANSI 437=LFN/U.S.(OEM) */
@ -84,7 +93,6 @@
#define MICROPY_VFS (1)
#define MICROPY_VFS_FAT (1)
#define MICROPY_PY_MACHINE (1)
#define MICROPY_MODULE_WEAK_LINKS (0)
#define MICROPY_REPL_AUTO_INDENT (1)
#define MICROPY_HW_ENABLE_DAC (1)
#define MICROPY_ENABLE_FINALISER (1)
@ -121,6 +129,9 @@ typedef unsigned mp_uint_t; // must be pointer size
typedef long mp_off_t;
// XXX check we don't need this
#define MICROPY_THREAD_YIELD()
#define MP_PLAT_PRINT_STRN(str, len) mp_hal_stdout_tx_strn_cooked(str, len)
#define mp_type_fileio mp_type_vfs_fat_fileio
@ -140,15 +151,33 @@ typedef long mp_off_t;
#include "include/sam.h"
#ifdef SAMD21
#define CIRCUITPY_MCU_FAMILY samd21
#define CIRCUITPY_MCU_FAMILY samd21
#define MICROPY_PY_SYS_PLATFORM "Atmel SAMD21"
#define PORT_HEAP_SIZE (16384 + 4096)
#define PORT_HEAP_SIZE (16384 + 4096)
#define CIRCUITPY_DEFAULT_STACK_SIZE 4096
#define MICROPY_CPYTHON_COMPAT (0)
#define MICROPY_MODULE_WEAK_LINKS (0)
#define MICROPY_PY_BUILTINS_NOTIMPLEMENTED (0)
#define MICROPY_PY_COLLECTIONS_ORDEREDDICT (0)
#define MICROPY_PY_FUNCTION_ATTRS (0)
#define MICROPY_PY_IO (0)
#define MICROPY_PY_REVERSE_SPECIAL_METHODS (0)
#define MICROPY_PY_SYS_EXC_INFO (0)
#endif
#ifdef SAMD51
#define CIRCUITPY_MCU_FAMILY samd51
#define CIRCUITPY_MCU_FAMILY samd51
#define MICROPY_PY_SYS_PLATFORM "MicroChip SAMD51"
#define PORT_HEAP_SIZE (0x20000) // 128KiB
#define PORT_HEAP_SIZE (0x20000) // 128KiB
#define CIRCUITPY_DEFAULT_STACK_SIZE 8192
#define MICROPY_CPYTHON_COMPAT (1)
#define MICROPY_MODULE_WEAK_LINKS (1)
#define MICROPY_PY_BUILTINS_NOTIMPLEMENTED (1)
#define MICROPY_PY_COLLECTIONS_ORDEREDDICT (1)
#define MICROPY_PY_FUNCTION_ATTRS (1)
#define MICROPY_PY_IO (1)
#define MICROPY_PY_REVERSE_SPECIAL_METHODS (1)
#define MICROPY_PY_SYS_EXC_INFO (1)
#endif
#ifdef LONGINT_IMPL_NONE
@ -194,6 +223,9 @@ extern const struct _mp_obj_module_t gamepad_module;
extern const struct _mp_obj_module_t stage_module;
extern const struct _mp_obj_module_t touchio_module;
extern const struct _mp_obj_module_t usb_hid_module;
extern const struct _mp_obj_module_t network_module;
extern const struct _mp_obj_module_t socket_module;
extern const struct _mp_obj_module_t wiznet_module;
// Internal flash size dependent settings.
#if BOARD_FLASH_SIZE > 192000
@ -234,11 +266,26 @@ extern const struct _mp_obj_module_t usb_hid_module;
#endif
#ifdef CIRCUITPY_DISPLAYIO
#define DISPLAYIO_MODULE { MP_OBJ_NEW_QSTR(MP_QSTR_displayio), (mp_obj_t)&displayio_module },
#define DISPLAYIO_MODULE { MP_OBJ_NEW_QSTR(MP_QSTR_displayio), (mp_obj_t)&displayio_module },
#else
#define DISPLAYIO_MODULE
#define DISPLAYIO_MODULE
#endif
#if MICROPY_PY_NETWORK
#define NETWORK_MODULE { MP_OBJ_NEW_QSTR(MP_QSTR_network), (mp_obj_t)&network_module },
#define SOCKET_MODULE { MP_OBJ_NEW_QSTR(MP_QSTR_socket), (mp_obj_t)&socket_module },
#if MICROPY_PY_WIZNET5K
#define WIZNET_MODULE { MP_OBJ_NEW_QSTR(MP_QSTR_wiznet), (mp_obj_t)&wiznet_module },
#else
#define WIZNET_MODULE
#endif
#else
#define NETWORK_MODULE
#define SOCKET_MODULE
#define WIZNET_MODULE
#endif
#ifndef EXTRA_BUILTIN_MODULES
#define EXTRA_BUILTIN_MODULES \
AUDIOIO_MODULE \
@ -246,6 +293,9 @@ extern const struct _mp_obj_module_t usb_hid_module;
{ MP_OBJ_NEW_QSTR(MP_QSTR_bitbangio), (mp_obj_t)&bitbangio_module }, \
DISPLAYIO_MODULE \
I2CSLAVE_MODULE \
NETWORK_MODULE \
SOCKET_MODULE \
WIZNET_MODULE \
{ MP_OBJ_NEW_QSTR(MP_QSTR_rotaryio), (mp_obj_t)&rotaryio_module }, \
{ MP_OBJ_NEW_QSTR(MP_QSTR_gamepad),(mp_obj_t)&gamepad_module }
#endif
@ -290,6 +340,34 @@ extern const struct _mp_obj_module_t usb_hid_module;
{ MP_OBJ_NEW_QSTR(MP_QSTR_supervisor), (mp_obj_t)&supervisor_module }, \
{ MP_OBJ_NEW_QSTR(MP_QSTR_time), (mp_obj_t)&time_module }, \
{ MP_OBJ_NEW_QSTR(MP_QSTR_usb_hid),(mp_obj_t)&usb_hid_module },
#elif MICROPY_MODULE_WEAK_LINKS
#define MICROPY_PORT_BUILTIN_MODULES \
{ MP_OBJ_NEW_QSTR(MP_QSTR_analogio), (mp_obj_t)&analogio_module }, \
{ MP_OBJ_NEW_QSTR(MP_QSTR_board), (mp_obj_t)&board_module }, \
{ MP_OBJ_NEW_QSTR(MP_QSTR_busio), (mp_obj_t)&busio_module }, \
{ MP_OBJ_NEW_QSTR(MP_QSTR_digitalio), (mp_obj_t)&digitalio_module }, \
{ MP_OBJ_NEW_QSTR(MP_QSTR_microcontroller), (mp_obj_t)&microcontroller_module }, \
{ MP_OBJ_NEW_QSTR(MP_QSTR_neopixel_write),(mp_obj_t)&neopixel_write_module }, \
{ MP_OBJ_NEW_QSTR(MP_QSTR__os), (mp_obj_t)&os_module }, \
{ MP_OBJ_NEW_QSTR(MP_QSTR_pulseio), (mp_obj_t)&pulseio_module }, \
{ MP_OBJ_NEW_QSTR(MP_QSTR_random), (mp_obj_t)&random_module }, \
{ MP_OBJ_NEW_QSTR(MP_QSTR_rtc), (mp_obj_t)&rtc_module }, \
{ MP_OBJ_NEW_QSTR(MP_QSTR_samd),(mp_obj_t)&samd_module }, \
{ MP_OBJ_NEW_QSTR(MP_QSTR_storage), (mp_obj_t)&storage_module }, \
{ MP_OBJ_NEW_QSTR(MP_QSTR_struct), (mp_obj_t)&struct_module }, \
{ MP_OBJ_NEW_QSTR(MP_QSTR_supervisor), (mp_obj_t)&supervisor_module }, \
{ MP_OBJ_NEW_QSTR(MP_QSTR_math), (mp_obj_t)&math_module }, \
{ MP_OBJ_NEW_QSTR(MP_QSTR__time), (mp_obj_t)&time_module }, \
{ MP_OBJ_NEW_QSTR(MP_QSTR_usb_hid),(mp_obj_t)&usb_hid_module }, \
TOUCHIO_MODULE \
EXTRA_BUILTIN_MODULES
#define MICROPY_PORT_BUILTIN_MODULE_WEAK_LINKS \
{ MP_ROM_QSTR(MP_QSTR_errno), MP_ROM_PTR(&mp_module_uerrno) }, \
{ MP_ROM_QSTR(MP_QSTR_io), MP_ROM_PTR(&mp_module_io) }, \
{ MP_ROM_QSTR(MP_QSTR_os), MP_ROM_PTR(&os_module) }, \
{ MP_OBJ_NEW_QSTR(MP_QSTR_time), (mp_obj_t)&time_module }, \
#else
#define MICROPY_PORT_BUILTIN_MODULES \
{ MP_OBJ_NEW_QSTR(MP_QSTR_analogio), (mp_obj_t)&analogio_module }, \
@ -345,6 +423,12 @@ extern const struct _mp_obj_module_t usb_hid_module;
#include "peripherals/samd/dma.h"
#if MICROPY_PY_NETWORK
#define NETWORK_ROOT_POINTERS mp_obj_list_t mod_network_nic_list;
#else
#define NETWORK_ROOT_POINTERS
#endif
#define MICROPY_PORT_ROOT_POINTERS \
const char *readline_hist[8]; \
vstr_t *repl_line; \
@ -352,6 +436,7 @@ extern const struct _mp_obj_module_t usb_hid_module;
mp_obj_t rtc_time_source; \
FLASH_ROOT_POINTERS \
mp_obj_t gamepad_singleton; \
NETWORK_ROOT_POINTERS \
void run_background_tasks(void);
#define MICROPY_VM_HOOK_LOOP run_background_tasks();
@ -360,8 +445,4 @@ void run_background_tasks(void);
#define CIRCUITPY_AUTORELOAD_DELAY_MS 500
#define CIRCUITPY_BOOT_OUTPUT_FILE "/boot_out.txt"
// TODO(tannewt): Make this 6k+ for any non-express M4 boards because they cache sectors on the
// stack.
#define CIRCUITPY_DEFAULT_STACK_SIZE 4096
#endif // __INCLUDED_MPCONFIGPORT_H

View File

@ -16,3 +16,4 @@ endif
INTERNAL_LIBM = 1

View File

@ -302,16 +302,16 @@ sd: $(BUILD)/$(OUTPUT_FILENAME).hex
else ifeq ($(FLASHER), pyocd)
flash: $(BUILD)/$(OUTPUT_FILENAME).hex
pyocd-flashtool -t $(MCU_SUB_VARIANT) $< --sector_erase
pyocd-tool -t $(MCU_SUB_VARIANT) erase $(BOOT_SETTING_ADDR)
pyocd-tool -t $(MCU_SUB_VARIANT) write32 $(BOOT_SETTING_ADDR) 0x00000001
pyocd-tool -t $(MCU_SUB_VARIANT) reset
pyocd-flashtool -t $(MCU_VARIANT) $< --sector_erase
#pyocd-tool -t $(MCU_VARIANT) erase $(BOOT_SETTING_ADDR)
pyocd-tool -t $(MCU_VARIANT) write32 $(BOOT_SETTING_ADDR) 0x00000001
pyocd-tool -t $(MCU_VARIANT) reset
sd: $(BUILD)/$(OUTPUT_FILENAME).hex
pyocd-flashtool -t $(MCU_SUB_VARIANT) --chip_erase
pyocd-flashtool -t $(MCU_SUB_VARIANT) $(SOFTDEV_HEX)
pyocd-flashtool -t $(MCU_SUB_VARIANT) $< --sector_erase
pyocd-tool -t $(MCU_SUB_VARIANT) reset $(BOOT_SETTING_ADDR)
pyocd-flashtool -t $(MCU_VARIANT) --chip_erase
pyocd-flashtool -t $(MCU_VARIANT) $(SOFTDEV_HEX)
pyocd-flashtool -t $(MCU_VARIANT) $< --sector_erase
pyocd-tool -t $(MCU_VARIANT) reset $(BOOT_SETTING_ADDR)
endif

View File

@ -39,6 +39,7 @@ the following links:
* Adafruit [Feather nRF52](boards/feather_nrf52832/README.md): 512KB Flash, 64KB SRAM
* Adafruit [Feather nRF52840](boards/feather_nrf52840_express/README.md): 1MB Flash, 256KB SRAM
* Nordic PCA10056 see [Feather nRF52840](boards/pca10056/README.md)
* MakerDiary NRF52840 MDK see [its README](boards/makerdiary_nrf52840_mdk/README.md)
For all other board targets, see the generic notes below.
@ -80,6 +81,7 @@ pca10040 | s132 | Peripheral and Scanner | [S
pca10056 | s140 | Peripheral and Scanner | [Segger](#segger-targets)
feather_nrf52832 | s132 | Peripheral and Scanner | [UART DFU](#dfu-targets)
feather_nrf52840_express | s140 | Peripheral and Scanner | UF2 bootloader
makerdiary_nrf52840_mdk | s140 | Peripheral and Scanner | pyocd or ARM mbed DAPLink
## Segger Targets

View File

@ -0,0 +1,102 @@
# MakerDiary NRF52840 MDK
Refer to https://github.com/makerdiary/nrf52840-mdk or
https://wiki.makerdiary.com/nrf52840-mdk/ for more details about the device.
Notably, CircuitPython does not currently support QSPI external flash on NRF
devices, so neither does this port - the 64Mb flash device is not used for
anything. Also, don't confuse this with the 64MiB drive that shows up on your
computer - it's actually part of the MSC driver provided by the DAPLink
debugger, and is inaccessible at all from Python land (this drive is where you
can copy `firmware.hex` if you'd prefer to flash that way as opposed to with
`pyocd`. You'll still have access to 256KB of the onboard flash, however, for
storing your Python files, cat pictures, or whatever.
It's also interesting to note that all three LEDs and the "user button" on this
device are wired through sinks, not sources, so flip your boolean expectations
when dealing with `digitalio.DigitalInOut` on this device - `my_led.value =
True` turns the LED off! Likewise, the user button will read `False` when
pressed.
## Installing CircuitPython submodules
Before you can build, you will need to run the following commands once, which
will install the submodules that are part of the CircuitPython ecosystem, and
build the `mpy-cross` tool:
```
$ cd circuitpython
$ git submodule update --init
$ make -C mpy-cross
```
You then need to download the SD and Nordic SDK files via:
> This script relies on `wget`, which must be available from the command line.
```
$ cd ports/nrf
$ ./drivers/bluetooth/download_ble_stack.sh
```
## Note about bootloaders
While most Adafruit devices come with (or can easily be flashed with) an
Adafruit-provided bootloader (supporting niceties like UF2 flashing), this
board comes with DAPLink which (apparently?) handles everything from debugging
to programming the device, as well as the boot sequence. What's particularly
awesome about this board is that there is no physical interaction with the board
required to flash new code (read: CircuitPython builds) - the device is _always_
listening for new firmware uploads (via `pyocd-flashtool`), even if userspace
code is running.
## Building and Flashing CircuitPython
You'll need to have [pyocd](https://github.com/mbedmicro/pyOCD) installed as
appropriate for your system.
```sh
make BOARD=makerdiary_nrf52840_mdk FLASHER=pyocd SD=s140 flash
```
This should give you the following (or very similar) output, and you will see
a DFU blinky pattern on one of the board LEDs:
```
$ make BOARD=makerdiary_nrf52840_mdk FLASHER=pyocd SD=s140 flash
Use make V=1, make V=2 or set BUILD_VERBOSE similarly in your environment to increase build verbosity.
pyocd-flashtool -t nrf52 build-makerdiary_nrf52840_mdk-s140/firmware.hex --sector_erase
INFO:root:DAP SWD MODE initialised
INFO:root:ROM table #0 @ 0xe00ff000 cidr=b105100d pidr=2002c4008
INFO:root:[0]<e000e000:SCS-M4 cidr=b105e00d, pidr=4000bb00c, class=14>
WARNING:root:Invalid coresight component, cidr=0x0
INFO:root:[1]<e0001000: cidr=0, pidr=0, component invalid>
INFO:root:[2]<e0002000:FPB cidr=b105e00d, pidr=4002bb003, class=14>
WARNING:root:Invalid coresight component, cidr=0x1010101
INFO:root:[3]<e0000000: cidr=1010101, pidr=101010101010101, component invalid>
WARNING:root:Invalid coresight component, cidr=0x0
INFO:root:[4]<e0040000: cidr=0, pidr=0, component invalid>
INFO:root:[5]<e0041000:ETM-M4 cidr=b105900d, pidr=4000bb925, class=9, devtype=13, devid=0>
INFO:root:CPU core is Cortex-M4
INFO:root:FPU present
INFO:root:6 hardware breakpoints, 4 literal comparators
INFO:root:4 hardware watchpoints
[====================] 100%
INFO:root:Programmed 237568 bytes (58 pages) at 14.28 kB/s
#pyocd-tool -t nrf52 erase 0xFF000
pyocd-tool -t nrf52 write32 0xFF000 0x00000001
WARNING:root:Invalid coresight component, cidr=0x0
WARNING:root:Invalid coresight component, cidr=0x1010101
WARNING:root:Invalid coresight component, cidr=0x0
pyocd-tool -t nrf52 reset
WARNING:root:Invalid coresight component, cidr=0x0
WARNING:root:Invalid coresight component, cidr=0x1010101
WARNING:root:Invalid coresight component, cidr=0x0
Resetting target
```
Alternatively (and untested by me), it's apparently possible to copy
`firmware.hex` to the MSC device provided by DAPLink and flash that way. Refer
to [the upstream
documentation](https://wiki.makerdiary.com/nrf52840-mdk/getting-started/#drag-n-drop-programming)
for details.

View File

@ -0,0 +1,40 @@
/*
* This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
* Copyright (c) 2017 Scott Shawcroft for Adafruit Industries
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#include "boards/board.h"
#include "usb.h"
void board_init(void) {
usb_init();
}
bool board_requests_safe_mode(void) {
return false;
}
void reset_board(void) {
}

View File

@ -0,0 +1,64 @@
/*
* This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
* Copyright (c) 2016 Glenn Ruben Bakke
* Copyright (c) 2018 Dan Halbert for Adafruit Industries
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#define MAKERDIARYNRF52840MDK
#define MICROPY_HW_BOARD_NAME "MakerDiary nRF52840 MDK"
#define MICROPY_HW_MCU_NAME "nRF52840"
#define MICROPY_PY_SYS_PLATFORM "MakerDiary52840MDK"
#define MICROPY_QSPI_DATA0 (&pin_P1_05)
#define MICROPY_QSPI_DATA1 (&pin_P1_04)
#define MICROPY_QSPI_DATA2 (&pin_P1_02)
#define MICROPY_QSPI_DATA3 (&pin_P1_01)
#define MICROPY_QSPI_SCK (&pin_P1_03)
#define MICROPY_QSPI_CS (&pin_P1_06)
#define CIRCUITPY_AUTORELOAD_DELAY_MS 500
// If you change this, then make sure to update the linker scripts as well to
// make sure you don't overwrite code
#define PORT_HEAP_SIZE (128 * 1024)
// TODO #define CIRCUITPY_INTERNAL_NVM_SIZE 8192
#define BOARD_FLASH_SIZE (FLASH_SIZE - 0x4000 - CIRCUITPY_INTERNAL_NVM_SIZE)
// TODO #include "external_flash/devices.h"
#define EXTERNAL_FLASH_DEVICE_COUNT 1
// Datasheet for when this is implemented:
// http://www.mxic.com.tw/Lists/Datasheet/Attachments/7428/MX25R6435F,%20Wide%20Range,%2064Mb,%20v1.4.pdf
#define EXTERNAL_FLASH_DEVICES MX25R6435F
#define EXTERNAL_FLASH_QSPI_DUAL
// TODO include "external_flash/external_flash.h"
#define BOARD_HAS_CRYSTAL 0
#define DEFAULT_UART_BUS_RX (&pin_P0_19)
#define DEFAULT_UART_BUS_TX (&pin_P0_20)

View File

@ -0,0 +1,16 @@
MCU_SERIES = m4
MCU_VARIANT = nrf52
MCU_SUB_VARIANT = nrf52840
MCU_CHIP = nrf52840
SD ?= s140
SOFTDEV_VERSION ?= 6.1.0
BOOT_SETTING_ADDR = 0xFF000
ifeq ($(SD),)
LD_FILE = boards/nrf52840_1M_256k.ld
else
LD_FILE = boards/adafruit_$(MCU_SUB_VARIANT)_$(SD_LOWER)_v$(firstword $(subst ., ,$(SOFTDEV_VERSION))).ld
endif
NRF_DEFINES += -DNRF52840_XXAA -DNRF52840

View File

@ -0,0 +1,63 @@
#include "shared-bindings/board/__init__.h"
#include "board_busses.h"
STATIC const mp_rom_map_elem_t board_module_globals_table[] = {
{ MP_ROM_QSTR(MP_QSTR_AIN0), MP_ROM_PTR(&pin_P0_02) },
{ MP_ROM_QSTR(MP_QSTR_AIN1), MP_ROM_PTR(&pin_P0_03) },
{ MP_ROM_QSTR(MP_QSTR_AIN2), MP_ROM_PTR(&pin_P0_04) },
{ MP_ROM_QSTR(MP_QSTR_AIN3), MP_ROM_PTR(&pin_P0_05) },
{ MP_ROM_QSTR(MP_QSTR_AIN4), MP_ROM_PTR(&pin_P0_28) },
{ MP_ROM_QSTR(MP_QSTR_AIN5), MP_ROM_PTR(&pin_P0_29) },
{ MP_ROM_QSTR(MP_QSTR_AIN6), MP_ROM_PTR(&pin_P0_30) },
{ MP_ROM_QSTR(MP_QSTR_AIN7), MP_ROM_PTR(&pin_P0_31) },
{ MP_ROM_QSTR(MP_QSTR_AREF), MP_ROM_PTR(&pin_P0_04) },
{ MP_ROM_QSTR(MP_QSTR_VDIV), MP_ROM_PTR(&pin_P0_05) },
{ MP_ROM_QSTR(MP_QSTR_NFC1), MP_ROM_PTR(&pin_P0_09) },
{ MP_ROM_QSTR(MP_QSTR_NFC2), MP_ROM_PTR(&pin_P0_10) },
{ MP_ROM_QSTR(MP_QSTR_P2), MP_ROM_PTR(&pin_P0_02) },
{ MP_ROM_QSTR(MP_QSTR_P3), MP_ROM_PTR(&pin_P0_03) },
{ MP_ROM_QSTR(MP_QSTR_P4), MP_ROM_PTR(&pin_P0_04) },
{ MP_ROM_QSTR(MP_QSTR_P5), MP_ROM_PTR(&pin_P0_05) },
{ MP_ROM_QSTR(MP_QSTR_P6), MP_ROM_PTR(&pin_P0_06) },
{ MP_ROM_QSTR(MP_QSTR_P7), MP_ROM_PTR(&pin_P0_07) },
{ MP_ROM_QSTR(MP_QSTR_P8), MP_ROM_PTR(&pin_P0_08) },
{ MP_ROM_QSTR(MP_QSTR_P9), MP_ROM_PTR(&pin_P0_09) },
{ MP_ROM_QSTR(MP_QSTR_P10), MP_ROM_PTR(&pin_P0_10) },
{ MP_ROM_QSTR(MP_QSTR_P11), MP_ROM_PTR(&pin_P0_11) },
{ MP_ROM_QSTR(MP_QSTR_P12), MP_ROM_PTR(&pin_P0_12) },
{ MP_ROM_QSTR(MP_QSTR_P13), MP_ROM_PTR(&pin_P0_13) },
{ MP_ROM_QSTR(MP_QSTR_P14), MP_ROM_PTR(&pin_P0_14) },
{ MP_ROM_QSTR(MP_QSTR_P15), MP_ROM_PTR(&pin_P0_15) },
{ MP_ROM_QSTR(MP_QSTR_P16), MP_ROM_PTR(&pin_P0_16) },
{ MP_ROM_QSTR(MP_QSTR_P17), MP_ROM_PTR(&pin_P0_17) },
{ MP_ROM_QSTR(MP_QSTR_P21), MP_ROM_PTR(&pin_P0_21) },
{ MP_ROM_QSTR(MP_QSTR_P25), MP_ROM_PTR(&pin_P0_25) },
{ MP_ROM_QSTR(MP_QSTR_P26), MP_ROM_PTR(&pin_P0_26) },
{ MP_ROM_QSTR(MP_QSTR_P27), MP_ROM_PTR(&pin_P0_27) },
{ MP_ROM_QSTR(MP_QSTR_P28), MP_ROM_PTR(&pin_P0_28) },
{ MP_ROM_QSTR(MP_QSTR_P29), MP_ROM_PTR(&pin_P0_29) },
{ MP_ROM_QSTR(MP_QSTR_P30), MP_ROM_PTR(&pin_P0_30) },
{ MP_ROM_QSTR(MP_QSTR_P31), MP_ROM_PTR(&pin_P0_31) },
{ MP_ROM_QSTR(MP_QSTR_SCK), MP_ROM_PTR(&pin_P1_03) },
{ MP_ROM_QSTR(MP_QSTR_CSN), MP_ROM_PTR(&pin_P1_06) },
{ MP_ROM_QSTR(MP_QSTR_IO0), MP_ROM_PTR(&pin_P1_05) },
{ MP_ROM_QSTR(MP_QSTR_IO1), MP_ROM_PTR(&pin_P1_04) },
{ MP_ROM_QSTR(MP_QSTR_IO2), MP_ROM_PTR(&pin_P1_02) },
{ MP_ROM_QSTR(MP_QSTR_IO3), MP_ROM_PTR(&pin_P1_01) },
{ MP_ROM_QSTR(MP_QSTR_TXD), MP_ROM_PTR(&pin_P0_20) },
{ MP_ROM_QSTR(MP_QSTR_RXD), MP_ROM_PTR(&pin_P0_19) },
{ MP_ROM_QSTR(MP_QSTR_LED_RED), MP_ROM_PTR(&pin_P0_23) },
{ MP_ROM_QSTR(MP_QSTR_LED_GREEN), MP_ROM_PTR(&pin_P0_22) },
{ MP_ROM_QSTR(MP_QSTR_LED_BLUE), MP_ROM_PTR(&pin_P0_24) },
{ MP_ROM_QSTR(MP_QSTR_USR_BTN), MP_ROM_PTR(&pin_P1_00) },
};
MP_DEFINE_CONST_DICT(board_module_globals, board_module_globals_table);

@ -1 +1 @@
Subproject commit d4ebe15f58de1442e3eed93b40d13930e7785903
Subproject commit b96950abf27229c2a3b1719d60691321246bfc94

10
py/builtinimport.c Executable file → Normal file
View File

@ -155,11 +155,9 @@ STATIC void do_load_from_lexer(mp_obj_t module_obj, mp_lexer_t *lex) {
#endif
#if MICROPY_PERSISTENT_CODE_LOAD || MICROPY_MODULE_FROZEN_MPY
STATIC void do_execute_raw_code(mp_obj_t module_obj, mp_raw_code_t *raw_code) {
STATIC void do_execute_raw_code(mp_obj_t module_obj, mp_raw_code_t *raw_code, const char *filename) {
#if MICROPY_PY___FILE__
// TODO
//qstr source_name = lex->source_name;
//mp_store_attr(module_obj, MP_QSTR___file__, MP_OBJ_NEW_QSTR(source_name));
mp_store_attr(module_obj, MP_QSTR___file__, MP_OBJ_NEW_QSTR(qstr_from_str(filename)));
#endif
// execute the module in its context
@ -222,7 +220,7 @@ STATIC void do_load(mp_obj_t module_obj, vstr_t *file) {
// its data) in the list of frozen files, execute it.
#if MICROPY_MODULE_FROZEN_MPY
if (frozen_type == MP_FROZEN_MPY) {
do_execute_raw_code(module_obj, modref);
do_execute_raw_code(module_obj, modref, file_str);
return;
}
#endif
@ -235,7 +233,7 @@ STATIC void do_load(mp_obj_t module_obj, vstr_t *file) {
#if MICROPY_PERSISTENT_CODE_LOAD
if (file_str[file->len - 3] == 'm') {
mp_raw_code_t *raw_code = mp_raw_code_load_file(file_str);
do_execute_raw_code(module_obj, raw_code);
do_execute_raw_code(module_obj, raw_code, file_str);
return;
}
#endif

View File

@ -72,7 +72,7 @@ endif
MAKE_FROZEN = $(PYTHON) $(TOP)/tools/make-frozen.py
MPY_CROSS = $(TOP)/mpy-cross/mpy-cross
MPY_TOOL = $(PYTHON) $(TOP)/tools/mpy-tool.py
MPY_TOOL = $(PYTHON3) $(TOP)/tools/mpy-tool.py
PREPROCESS_FROZEN_MODULES = PYTHONPATH=$(TOP)/tools/python-semver $(TOP)/tools/preprocess_frozen_modules.py
all:

View File

@ -130,7 +130,7 @@ xargs -n1 "$(abspath $(MPY_CROSS))" $(MPY_CROSS_FLAGS)
# to build frozen_mpy.c from all .mpy files
# You need to define MPY_TOOL_LONGINT_IMPL in mpconfigport.mk
# if the default will not work (mpz is the default).
$(BUILD)/frozen_mpy.c: $(BUILD)/frozen_mpy $(BUILD)/genhdr/qstrdefs.generated.h
$(BUILD)/frozen_mpy.c: $(BUILD)/frozen_mpy $(BUILD)/genhdr/qstrdefs.generated.h $(TOP)/tools/mpy-tool.py
$(STEPECHO) "Creating $@"
$(Q)$(MPY_TOOL) $(MPY_TOOL_LONGINT_IMPL) -f -q $(BUILD)/genhdr/qstrdefs.preprocessed.h $(shell $(FIND) -L $(BUILD)/frozen_mpy -type f -name '*.mpy') > $@
endif

View File

@ -135,7 +135,7 @@ STATIC mp_obj_t mp_sys_exc_info(void) {
t->items[0] = MP_OBJ_FROM_PTR(mp_obj_get_type(cur_exc));
t->items[1] = cur_exc;
t->items[2] = mp_const_none;
t->items[2] = mp_obj_exception_get_traceback_obj(cur_exc);
return MP_OBJ_FROM_PTR(t);
}
MP_DEFINE_CONST_FUN_OBJ_0(mp_sys_exc_info_obj, mp_sys_exc_info);

View File

@ -717,6 +717,7 @@ bool mp_obj_exception_match(mp_obj_t exc, mp_const_obj_t exc_type);
void mp_obj_exception_clear_traceback(mp_obj_t self_in);
void mp_obj_exception_add_traceback(mp_obj_t self_in, qstr file, size_t line, qstr block);
void mp_obj_exception_get_traceback(mp_obj_t self_in, size_t *n, size_t **values);
mp_obj_t mp_obj_exception_get_traceback_obj(mp_obj_t self_in);
mp_obj_t mp_obj_exception_get_value(mp_obj_t self_in);
mp_obj_t mp_obj_exception_make_new(const mp_obj_type_t *type_in, size_t n_args, size_t n_kw, const mp_obj_t *args);
mp_obj_t mp_alloc_emergency_exception_buf(mp_obj_t size_in);

View File

@ -92,6 +92,9 @@ STATIC void bound_meth_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) {
if (attr == MP_QSTR___name__) {
mp_obj_bound_meth_t *o = MP_OBJ_TO_PTR(self_in);
dest[0] = MP_OBJ_NEW_QSTR(mp_obj_fun_get_name(o->meth));
} else if (attr == MP_QSTR___func__) {
mp_obj_bound_meth_t *o = MP_OBJ_TO_PTR(self_in);
dest[0] = o->meth;
}
}
#endif

View File

@ -30,6 +30,7 @@
#include <stdio.h>
#include "py/objlist.h"
#include "py/objnamedtuple.h"
#include "py/objstr.h"
#include "py/objtuple.h"
#include "py/objtype.h"
@ -531,3 +532,164 @@ void mp_obj_exception_get_traceback(mp_obj_t self_in, size_t *n, size_t **values
*values = self->traceback_data;
}
}
#if MICROPY_PY_SYS_EXC_INFO
STATIC const mp_obj_namedtuple_type_t code_type_obj = {
.base = {
.base = {
.type = &mp_type_type
},
.name = MP_QSTR_code,
.print = namedtuple_print,
.make_new = namedtuple_make_new,
.unary_op = mp_obj_tuple_unary_op,
.binary_op = mp_obj_tuple_binary_op,
.attr = namedtuple_attr,
.subscr = mp_obj_tuple_subscr,
.getiter = mp_obj_tuple_getiter,
.parent = &mp_type_tuple,
},
.n_fields = 15,
.fields = {
MP_QSTR_co_argcount,
MP_QSTR_co_kwonlyargcount,
MP_QSTR_co_nlocals,
MP_QSTR_co_stacksize,
MP_QSTR_co_flags,
MP_QSTR_co_code,
MP_QSTR_co_consts,
MP_QSTR_co_names,
MP_QSTR_co_varnames,
MP_QSTR_co_freevars,
MP_QSTR_co_cellvars,
MP_QSTR_co_filename,
MP_QSTR_co_name,
MP_QSTR_co_firstlineno,
MP_QSTR_co_lnotab,
},
};
STATIC mp_obj_t code_make_new(qstr file, qstr block) {
mp_obj_t elems[15] = {
mp_obj_new_int(0), // co_argcount
mp_obj_new_int(0), // co_kwonlyargcount
mp_obj_new_int(0), // co_nlocals
mp_obj_new_int(0), // co_stacksize
mp_obj_new_int(0), // co_flags
mp_obj_new_bytearray(0, NULL), // co_code
mp_obj_new_tuple(0, NULL), // co_consts
mp_obj_new_tuple(0, NULL), // co_names
mp_obj_new_tuple(0, NULL), // co_varnames
mp_obj_new_tuple(0, NULL), // co_freevars
mp_obj_new_tuple(0, NULL), // co_cellvars
MP_OBJ_NEW_QSTR(file), // co_filename
MP_OBJ_NEW_QSTR(block), // co_name
mp_obj_new_int(1), // co_firstlineno
mp_obj_new_bytearray(0, NULL), // co_lnotab
};
return namedtuple_make_new((const mp_obj_type_t*)&code_type_obj, 15, 0, elems);
}
STATIC const mp_obj_namedtuple_type_t frame_type_obj = {
.base = {
.base = {
.type = &mp_type_type
},
.name = MP_QSTR_frame,
.print = namedtuple_print,
.make_new = namedtuple_make_new,
.unary_op = mp_obj_tuple_unary_op,
.binary_op = mp_obj_tuple_binary_op,
.attr = namedtuple_attr,
.subscr = mp_obj_tuple_subscr,
.getiter = mp_obj_tuple_getiter,
.parent = &mp_type_tuple,
},
.n_fields = 8,
.fields = {
MP_QSTR_f_back,
MP_QSTR_f_builtins,
MP_QSTR_f_code,
MP_QSTR_f_globals,
MP_QSTR_f_lasti,
MP_QSTR_f_lineno,
MP_QSTR_f_locals,
MP_QSTR_f_trace,
},
};
STATIC mp_obj_t frame_make_new(mp_obj_t f_code, int f_lineno) {
mp_obj_t elems[8] = {
mp_const_none, // f_back
mp_obj_new_dict(0), // f_builtins
f_code, // f_code
mp_obj_new_dict(0), // f_globals
mp_obj_new_int(0), // f_lasti
mp_obj_new_int(f_lineno), // f_lineno
mp_obj_new_dict(0), // f_locals
mp_const_none, // f_trace
};
return namedtuple_make_new((const mp_obj_type_t*)&frame_type_obj, 8, 0, elems);
}
STATIC const mp_obj_namedtuple_type_t traceback_type_obj = {
.base = {
.base = {
.type = &mp_type_type
},
.name = MP_QSTR_traceback,
.print = namedtuple_print,
.make_new = namedtuple_make_new,
.unary_op = mp_obj_tuple_unary_op,
.binary_op = mp_obj_tuple_binary_op,
.attr = namedtuple_attr,
.subscr = mp_obj_tuple_subscr,
.getiter = mp_obj_tuple_getiter,
.parent = &mp_type_tuple,
},
.n_fields = 4,
.fields = {
MP_QSTR_tb_frame,
MP_QSTR_tb_lasti,
MP_QSTR_tb_lineno,
MP_QSTR_tb_next,
},
};
STATIC mp_obj_t traceback_from_values(size_t *values, mp_obj_t tb_next) {
int lineno = values[1];
mp_obj_t elems[4] = {
frame_make_new(code_make_new(values[0], values[2]), lineno),
mp_obj_new_int(0),
mp_obj_new_int(lineno),
tb_next,
};
return namedtuple_make_new((const mp_obj_type_t*)&traceback_type_obj, 4, 0, elems);
};
mp_obj_t mp_obj_exception_get_traceback_obj(mp_obj_t self_in) {
mp_obj_exception_t *self = MP_OBJ_TO_PTR(self_in);
if (!mp_obj_is_exception_instance(self)) {
return mp_const_none;
}
size_t n, *values;
mp_obj_exception_get_traceback(self, &n, &values);
if (n == 0) {
return mp_const_none;
}
mp_obj_t tb_next = mp_const_none;
for (size_t i = 0; i < n; i += 3) {
tb_next = traceback_from_values(&values[i], tb_next);
}
return tb_next;
}
#endif

View File

@ -138,6 +138,43 @@ const mp_obj_property_t audioio_wavefile_sample_rate_obj = {
(mp_obj_t)&mp_const_none_obj},
};
//| .. attribute:: bits_per_sample
//|
//| Bits per sample. (read only)
//|
STATIC mp_obj_t audioio_wavefile_obj_get_bits_per_sample(mp_obj_t self_in) {
audioio_wavefile_obj_t *self = MP_OBJ_TO_PTR(self_in);
raise_error_if_deinited(common_hal_audioio_wavefile_deinited(self));
return MP_OBJ_NEW_SMALL_INT(common_hal_audioio_wavefile_get_bits_per_sample(self));
}
MP_DEFINE_CONST_FUN_OBJ_1(audioio_wavefile_get_bits_per_sample_obj, audioio_wavefile_obj_get_bits_per_sample);
const mp_obj_property_t audioio_wavefile_bits_per_sample_obj = {
.base.type = &mp_type_property,
.proxy = {(mp_obj_t)&audioio_wavefile_get_bits_per_sample_obj,
(mp_obj_t)&mp_const_none_obj,
(mp_obj_t)&mp_const_none_obj},
};
//| .. attribute:: channel_count
//|
//| Number of audio channels. (read only)
//|
STATIC mp_obj_t audioio_wavefile_obj_get_channel_count(mp_obj_t self_in) {
audioio_wavefile_obj_t *self = MP_OBJ_TO_PTR(self_in);
raise_error_if_deinited(common_hal_audioio_wavefile_deinited(self));
return MP_OBJ_NEW_SMALL_INT(common_hal_audioio_wavefile_get_channel_count(self));
}
MP_DEFINE_CONST_FUN_OBJ_1(audioio_wavefile_get_channel_count_obj, audioio_wavefile_obj_get_channel_count);
const mp_obj_property_t audioio_wavefile_channel_count_obj = {
.base.type = &mp_type_property,
.proxy = {(mp_obj_t)&audioio_wavefile_get_channel_count_obj,
(mp_obj_t)&mp_const_none_obj,
(mp_obj_t)&mp_const_none_obj},
};
STATIC const mp_rom_map_elem_t audioio_wavefile_locals_dict_table[] = {
// Methods
{ MP_ROM_QSTR(MP_QSTR_deinit), MP_ROM_PTR(&audioio_wavefile_deinit_obj) },
@ -146,6 +183,8 @@ STATIC const mp_rom_map_elem_t audioio_wavefile_locals_dict_table[] = {
// Properties
{ MP_ROM_QSTR(MP_QSTR_sample_rate), MP_ROM_PTR(&audioio_wavefile_sample_rate_obj) },
{ MP_ROM_QSTR(MP_QSTR_bits_per_sample), MP_ROM_PTR(&audioio_wavefile_bits_per_sample_obj) },
{ MP_ROM_QSTR(MP_QSTR_channel_count), MP_ROM_PTR(&audioio_wavefile_channel_count_obj) },
};
STATIC MP_DEFINE_CONST_DICT(audioio_wavefile_locals_dict, audioio_wavefile_locals_dict_table);

View File

@ -40,5 +40,7 @@ void common_hal_audioio_wavefile_deinit(audioio_wavefile_obj_t* self);
bool common_hal_audioio_wavefile_deinited(audioio_wavefile_obj_t* self);
uint32_t common_hal_audioio_wavefile_get_sample_rate(audioio_wavefile_obj_t* self);
void common_hal_audioio_wavefile_set_sample_rate(audioio_wavefile_obj_t* self, uint32_t sample_rate);
uint8_t common_hal_audioio_wavefile_get_bits_per_sample(audioio_wavefile_obj_t* self);
uint8_t common_hal_audioio_wavefile_get_channel_count(audioio_wavefile_obj_t* self);
#endif // MICROPY_INCLUDED_SHARED_BINDINGS_AUDIOIO_WAVEFILE_H

View File

@ -0,0 +1,74 @@
/*
* This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
* Copyright (c) 2014 Damien P. George
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#include <stdio.h>
#include <stdint.h>
#include <string.h>
#include "py/objlist.h"
#include "py/runtime.h"
#include "py/mphal.h"
#include "py/mperrno.h"
#include "lib/netutils/netutils.h"
#include "shared-bindings/network/__init__.h"
#if MICROPY_PY_NETWORK
//| :mod:`network` --- Network Interface Management
//| ===============================================
//|
//| .. module:: network
//| :synopsis: Network Interface Management
//| :platform: SAMD
//|
//| This module provides a registry of configured NICs.
//| It is used by the 'socket' module to look up a suitable
//| NIC when a socket is created.
//|
//| .. function:: route
//|
//| Returns a list of all configured NICs.
//|
STATIC mp_obj_t network_route(void) {
return MP_OBJ_FROM_PTR(&MP_STATE_PORT(mod_network_nic_list));
}
STATIC MP_DEFINE_CONST_FUN_OBJ_0(network_route_obj, network_route);
STATIC const mp_rom_map_elem_t mp_module_network_globals_table[] = {
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_network) },
{ MP_ROM_QSTR(MP_QSTR_route), MP_ROM_PTR(&network_route_obj) },
};
STATIC MP_DEFINE_CONST_DICT(mp_module_network_globals, mp_module_network_globals_table);
const mp_obj_module_t network_module = {
.base = { &mp_type_module },
.globals = (mp_obj_dict_t*)&mp_module_network_globals,
};
#endif // MICROPY_PY_NETWORK

View File

@ -0,0 +1,31 @@
/*
* This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
* Copyright (c) 2013, 2014 Damien P. George
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#ifndef MICROPY_INCLUDED_SHARED_BINDINGS_NETWORK___INIT___H
#define MICROPY_INCLUDED_SHARED_BINDINGS_NETWORK___INIT___H
// nothing
#endif // MICROPY_INCLUDED_SHARED_BINDINGS_NETWORK___INIT___H

View File

@ -0,0 +1,559 @@
/*
* This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
* Copyright (c) 2014 Damien P. George
* 2018 Nick Moore for Adafruit Industries
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#include <stdio.h>
#include <string.h>
#include "py/objtuple.h"
#include "py/objlist.h"
#include "py/runtime.h"
#include "py/stream.h"
#include "py/mperrno.h"
#include "lib/netutils/netutils.h"
#include "shared-module/network/__init__.h"
//| :mod:`socket` --- TCP, UDP and RAW socket support
//| =================================================
//|
//| .. module:: socket
//| :synopsis: TCP, UDP and RAW sockets
//| :platform: SAMD21, SAMD51
//|
//| Create TCP, UDP and RAW sockets for communicating over the Internet.
//|
STATIC const mp_obj_type_t socket_type;
//| .. currentmodule:: socket
//|
//| .. class:: socket(family, type, proto, ...)
//|
//| Create a new socket
//|
//| :param ~int family: AF_INET or AF_INET6
//| :param ~int type: SOCK_STREAM, SOCK_DGRAM or SOCK_RAW
//| :param ~int proto: IPPROTO_TCP, IPPROTO_UDP or IPPROTO_RAW (ignored)
//|
STATIC mp_obj_t socket_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
mp_arg_check_num(n_args, n_kw, 0, 4, false);
// create socket object (not bound to any NIC yet)
mod_network_socket_obj_t *s = m_new_obj_with_finaliser(mod_network_socket_obj_t);
s->base.type = &socket_type;
s->nic = MP_OBJ_NULL;
s->nic_type = NULL;
s->u_param.domain = MOD_NETWORK_AF_INET;
s->u_param.type = MOD_NETWORK_SOCK_STREAM;
s->u_param.fileno = -1;
if (n_args >= 1) {
s->u_param.domain = mp_obj_get_int(args[0]);
if (n_args >= 2) {
s->u_param.type = mp_obj_get_int(args[1]);
if (n_args >= 4) {
s->u_param.fileno = mp_obj_get_int(args[3]);
}
}
}
return MP_OBJ_FROM_PTR(s);
}
STATIC void socket_select_nic(mod_network_socket_obj_t *self, const byte *ip) {
if (self->nic == MP_OBJ_NULL) {
// select NIC based on IP
self->nic = network_module_find_nic(ip);
self->nic_type = (mod_network_nic_type_t*)mp_obj_get_type(self->nic);
// call the NIC to open the socket
int _errno;
if (self->nic_type->socket(self, &_errno) != 0) {
mp_raise_OSError(_errno);
}
}
}
//| .. method:: bind(address)
//|
//| Bind a socket to an address
//|
//| :param ~tuple address: tuple of (remote_address, remote_port)
//|
STATIC mp_obj_t socket_bind(mp_obj_t self_in, mp_obj_t addr_in) {
mod_network_socket_obj_t *self = MP_OBJ_TO_PTR(self_in);
// get address
uint8_t ip[MOD_NETWORK_IPADDR_BUF_SIZE];
mp_uint_t port = netutils_parse_inet_addr(addr_in, ip, NETUTILS_BIG);
// check if we need to select a NIC
socket_select_nic(self, ip);
// call the NIC to bind the socket
int _errno;
if (self->nic_type->bind(self, ip, port, &_errno) != 0) {
mp_raise_OSError(_errno);
}
return mp_const_none;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_2(socket_bind_obj, socket_bind);
//| .. method:: listen(backlog)
//|
//| Set socket to listen for incoming connections
//|
//| :param ~int backlog: length of backlog queue for waiting connetions
//|
STATIC mp_obj_t socket_listen(mp_obj_t self_in, mp_obj_t backlog) {
mod_network_socket_obj_t *self = MP_OBJ_TO_PTR(self_in);
if (self->nic == MP_OBJ_NULL) {
// not connected
// TODO I think we can listen even if not bound...
mp_raise_OSError(MP_ENOTCONN);
}
int _errno;
if (self->nic_type->listen(self, mp_obj_get_int(backlog), &_errno) != 0) {
mp_raise_OSError(_errno);
}
return mp_const_none;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_2(socket_listen_obj, socket_listen);
//| .. method:: accept()
//|
//| Accept a connection on a listening socket of type SOCK_STREAM,
//| creating a new socket of type SOCK_STREAM.
//| Returns a tuple of (new_socket, remote_address)
//|
STATIC mp_obj_t socket_accept(mp_obj_t self_in) {
mod_network_socket_obj_t *self = MP_OBJ_TO_PTR(self_in);
// create new socket object
// starts with empty NIC so that finaliser doesn't run close() method if accept() fails
mod_network_socket_obj_t *socket2 = m_new_obj_with_finaliser(mod_network_socket_obj_t);
socket2->base.type = &socket_type;
socket2->nic = MP_OBJ_NULL;
socket2->nic_type = NULL;
// accept incoming connection
uint8_t ip[MOD_NETWORK_IPADDR_BUF_SIZE];
mp_uint_t port;
int _errno;
if (self->nic_type->accept(self, socket2, ip, &port, &_errno) != 0) {
mp_raise_OSError(_errno);
}
// new socket has valid state, so set the NIC to the same as parent
socket2->nic = self->nic;
socket2->nic_type = self->nic_type;
// make the return value
mp_obj_tuple_t *client = MP_OBJ_TO_PTR(mp_obj_new_tuple(2, NULL));
client->items[0] = MP_OBJ_FROM_PTR(socket2);
client->items[1] = netutils_format_inet_addr(ip, port, NETUTILS_BIG);
return MP_OBJ_FROM_PTR(client);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(socket_accept_obj, socket_accept);
//| .. method:: connect(address)
//|
//| Connect a socket to a remote address
//|
//| :param ~tuple address: tuple of (remote_address, remote_port)
//|
STATIC mp_obj_t socket_connect(mp_obj_t self_in, mp_obj_t addr_in) {
mod_network_socket_obj_t *self = MP_OBJ_TO_PTR(self_in);
// get address
uint8_t ip[MOD_NETWORK_IPADDR_BUF_SIZE];
mp_uint_t port = netutils_parse_inet_addr(addr_in, ip, NETUTILS_BIG);
// check if we need to select a NIC
socket_select_nic(self, ip);
// call the NIC to connect the socket
int _errno;
if (self->nic_type->connect(self, ip, port, &_errno) != 0) {
mp_raise_OSError(_errno);
}
return mp_const_none;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_2(socket_connect_obj, socket_connect);
//| .. method:: send(bytes)
//|
//| Send some bytes to the connected remote address.
//| Suits sockets of type SOCK_STREAM
//|
//| :param ~bytes bytes: some bytes to send
//|
STATIC mp_obj_t socket_send(mp_obj_t self_in, mp_obj_t buf_in) {
mod_network_socket_obj_t *self = MP_OBJ_TO_PTR(self_in);
if (self->nic == MP_OBJ_NULL) {
// not connected
mp_raise_OSError(MP_EPIPE);
}
mp_buffer_info_t bufinfo;
mp_get_buffer_raise(buf_in, &bufinfo, MP_BUFFER_READ);
int _errno;
mp_int_t ret = self->nic_type->send(self, bufinfo.buf, bufinfo.len, &_errno);
if (ret == -1) {
mp_raise_OSError(_errno);
}
return mp_obj_new_int_from_uint(ret);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_2(socket_send_obj, socket_send);
//| .. method:: recv(bufsize)
//|
//| Reads some bytes from the connected remote address.
//| Suits sockets of type SOCK_STREAM
//| Returns a bytes() of length <= bufsize
//|
//| :param ~int bufsize: maximum number of bytes to receive
STATIC mp_obj_t socket_recv(mp_obj_t self_in, mp_obj_t len_in) {
mod_network_socket_obj_t *self = MP_OBJ_TO_PTR(self_in);
if (self->nic == MP_OBJ_NULL) {
// not connected
mp_raise_OSError(MP_ENOTCONN);
}
mp_int_t len = mp_obj_get_int(len_in);
vstr_t vstr;
vstr_init_len(&vstr, len);
int _errno;
mp_int_t ret = self->nic_type->recv(self, (byte*)vstr.buf, len, &_errno);
if (ret == -1) {
mp_raise_OSError(_errno);
}
if (ret == 0) {
return mp_const_empty_bytes;
}
vstr.len = ret;
return mp_obj_new_str_from_vstr(&mp_type_bytes, &vstr);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_2(socket_recv_obj, socket_recv);
//| .. method:: sendto(bytes, address)
//|
//| Send some bytes to a specific address.
//| Suits sockets of type SOCK_DGRAM
//|
//| :param ~bytes bytes: some bytes to send
//| :param ~tuple address: tuple of (remote_address, remote_port)
//|
STATIC mp_obj_t socket_sendto(mp_obj_t self_in, mp_obj_t data_in, mp_obj_t addr_in) {
mod_network_socket_obj_t *self = MP_OBJ_TO_PTR(self_in);
// get the data
mp_buffer_info_t bufinfo;
mp_get_buffer_raise(data_in, &bufinfo, MP_BUFFER_READ);
// get address
uint8_t ip[MOD_NETWORK_IPADDR_BUF_SIZE];
mp_uint_t port = netutils_parse_inet_addr(addr_in, ip, NETUTILS_BIG);
// check if we need to select a NIC
socket_select_nic(self, ip);
// call the NIC to sendto
int _errno;
mp_int_t ret = self->nic_type->sendto(self, bufinfo.buf, bufinfo.len, ip, port, &_errno);
if (ret == -1) {
mp_raise_OSError(_errno);
}
return mp_obj_new_int(ret);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_3(socket_sendto_obj, socket_sendto);
//| .. method:: recvfrom(bufsize)
//|
//| Reads some bytes from the connected remote address.
//| Suits sockets of type SOCK_STREAM
//|
//| Returns a tuple containing
//| * a bytes() of length <= bufsize
//| * a remote_address, which is a tuple of ip address and port number
//|
//| :param ~int bufsize: maximum number of bytes to receive
//|
STATIC mp_obj_t socket_recvfrom(mp_obj_t self_in, mp_obj_t len_in) {
mod_network_socket_obj_t *self = MP_OBJ_TO_PTR(self_in);
if (self->nic == MP_OBJ_NULL) {
// not connected
mp_raise_OSError(MP_ENOTCONN);
}
vstr_t vstr;
vstr_init_len(&vstr, mp_obj_get_int(len_in));
byte ip[4];
mp_uint_t port;
int _errno;
mp_int_t ret = self->nic_type->recvfrom(self, (byte*)vstr.buf, vstr.len, ip, &port, &_errno);
if (ret == -1) {
mp_raise_OSError(_errno);
}
mp_obj_t tuple[2];
if (ret == 0) {
tuple[0] = mp_const_empty_bytes;
} else {
vstr.len = ret;
tuple[0] = mp_obj_new_str_from_vstr(&mp_type_bytes, &vstr);
}
tuple[1] = netutils_format_inet_addr(ip, port, NETUTILS_BIG);
return mp_obj_new_tuple(2, tuple);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_2(socket_recvfrom_obj, socket_recvfrom);
//| .. method:: setsockopt(level, optname, value)
//|
//| Sets socket options
//|
STATIC mp_obj_t socket_setsockopt(size_t n_args, const mp_obj_t *args) {
mod_network_socket_obj_t *self = MP_OBJ_TO_PTR(args[0]);
mp_int_t level = mp_obj_get_int(args[1]);
mp_int_t opt = mp_obj_get_int(args[2]);
const void *optval;
mp_uint_t optlen;
mp_int_t val;
if (mp_obj_is_integer(args[3])) {
val = mp_obj_get_int_truncated(args[3]);
optval = &val;
optlen = sizeof(val);
} else {
mp_buffer_info_t bufinfo;
mp_get_buffer_raise(args[3], &bufinfo, MP_BUFFER_READ);
optval = bufinfo.buf;
optlen = bufinfo.len;
}
int _errno;
if (self->nic_type->setsockopt(self, level, opt, optval, optlen, &_errno) != 0) {
mp_raise_OSError(_errno);
}
return mp_const_none;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(socket_setsockopt_obj, 4, 4, socket_setsockopt);
//| .. method:: settimeout(value)
//|
//| Set the timeout value for this socket.
//|
//| :param ~int value: timeout in seconds. 0 means non-blocking. None means block indefinitely.
//|
STATIC mp_obj_t socket_settimeout(mp_obj_t self_in, mp_obj_t timeout_in) {
mod_network_socket_obj_t *self = MP_OBJ_TO_PTR(self_in);
if (self->nic == MP_OBJ_NULL) {
// not connected
mp_raise_OSError(MP_ENOTCONN);
}
mp_uint_t timeout;
if (timeout_in == mp_const_none) {
timeout = -1;
} else {
#if MICROPY_PY_BUILTINS_FLOAT
timeout = 1000 * mp_obj_get_float(timeout_in);
#else
timeout = 1000 * mp_obj_get_int(timeout_in);
#endif
}
int _errno;
if (self->nic_type->settimeout(self, timeout, &_errno) != 0) {
mp_raise_OSError(_errno);
}
return mp_const_none;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_2(socket_settimeout_obj, socket_settimeout);
//| .. method:: setblocking(flag)
//|
//| Set the blocking behaviour of this socket.
//|
//| :param ~bool flag: False means non-blocking, True means block indefinitely.
//|
// method socket.setblocking(flag)
STATIC mp_obj_t socket_setblocking(mp_obj_t self_in, mp_obj_t blocking) {
if (mp_obj_is_true(blocking)) {
return socket_settimeout(self_in, mp_const_none);
} else {
return socket_settimeout(self_in, MP_OBJ_NEW_SMALL_INT(0));
}
}
STATIC MP_DEFINE_CONST_FUN_OBJ_2(socket_setblocking_obj, socket_setblocking);
STATIC const mp_rom_map_elem_t socket_locals_dict_table[] = {
{ MP_ROM_QSTR(MP_QSTR___del__), MP_ROM_PTR(&mp_stream_close_obj) },
{ MP_ROM_QSTR(MP_QSTR_close), MP_ROM_PTR(&mp_stream_close_obj) },
{ MP_ROM_QSTR(MP_QSTR_bind), MP_ROM_PTR(&socket_bind_obj) },
{ MP_ROM_QSTR(MP_QSTR_listen), MP_ROM_PTR(&socket_listen_obj) },
{ MP_ROM_QSTR(MP_QSTR_accept), MP_ROM_PTR(&socket_accept_obj) },
{ MP_ROM_QSTR(MP_QSTR_connect), MP_ROM_PTR(&socket_connect_obj) },
{ MP_ROM_QSTR(MP_QSTR_send), MP_ROM_PTR(&socket_send_obj) },
{ MP_ROM_QSTR(MP_QSTR_recv), MP_ROM_PTR(&socket_recv_obj) },
{ MP_ROM_QSTR(MP_QSTR_sendto), MP_ROM_PTR(&socket_sendto_obj) },
{ MP_ROM_QSTR(MP_QSTR_recvfrom), MP_ROM_PTR(&socket_recvfrom_obj) },
{ MP_ROM_QSTR(MP_QSTR_setsockopt), MP_ROM_PTR(&socket_setsockopt_obj) },
{ MP_ROM_QSTR(MP_QSTR_settimeout), MP_ROM_PTR(&socket_settimeout_obj) },
{ MP_ROM_QSTR(MP_QSTR_setblocking), MP_ROM_PTR(&socket_setblocking_obj) },
};
STATIC MP_DEFINE_CONST_DICT(socket_locals_dict, socket_locals_dict_table);
mp_uint_t socket_ioctl(mp_obj_t self_in, mp_uint_t request, uintptr_t arg, int *errcode) {
mod_network_socket_obj_t *self = MP_OBJ_TO_PTR(self_in);
if (request == MP_STREAM_CLOSE) {
if (self->nic != MP_OBJ_NULL) {
self->nic_type->close(self);
self->nic = MP_OBJ_NULL;
}
return 0;
}
return self->nic_type->ioctl(self, request, arg, errcode);
}
STATIC const mp_stream_p_t socket_stream_p = {
.ioctl = socket_ioctl,
.is_text = false,
};
STATIC const mp_obj_type_t socket_type = {
{ &mp_type_type },
.name = MP_QSTR_socket,
.make_new = socket_make_new,
.protocol = &socket_stream_p,
.locals_dict = (mp_obj_dict_t*)&socket_locals_dict,
};
//| .. function:: getaddrinfo(host, port)
//|
//| Gets the address information for a hostname and port
//|
//| Returns the appropriate family, socket type, socket protocol and
//| address information to call socket.socket() and socket.connect() with,
//| as a tuple.
//|
STATIC mp_obj_t socket_getaddrinfo(mp_obj_t host_in, mp_obj_t port_in) {
size_t hlen;
const char *host = mp_obj_str_get_data(host_in, &hlen);
mp_int_t port = mp_obj_get_int(port_in);
uint8_t out_ip[MOD_NETWORK_IPADDR_BUF_SIZE];
bool have_ip = false;
if (hlen > 0) {
// check if host is already in IP form
nlr_buf_t nlr;
if (nlr_push(&nlr) == 0) {
netutils_parse_ipv4_addr(host_in, out_ip, NETUTILS_BIG);
have_ip = true;
nlr_pop();
} else {
// swallow exception: host was not in IP form so need to do DNS lookup
}
}
if (!have_ip) {
// find a NIC that can do a name lookup
for (mp_uint_t i = 0; i < MP_STATE_PORT(mod_network_nic_list).len; i++) {
mp_obj_t nic = MP_STATE_PORT(mod_network_nic_list).items[i];
mod_network_nic_type_t *nic_type = (mod_network_nic_type_t*)mp_obj_get_type(nic);
if (nic_type->gethostbyname != NULL) {
int ret = nic_type->gethostbyname(nic, host, hlen, out_ip);
if (ret != 0) {
mp_raise_OSError(ret);
}
have_ip = true;
break;
}
}
}
if (!have_ip) {
nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, translate("no available NIC")));
}
mp_obj_tuple_t *tuple = MP_OBJ_TO_PTR(mp_obj_new_tuple(5, NULL));
tuple->items[0] = MP_OBJ_NEW_SMALL_INT(MOD_NETWORK_AF_INET);
tuple->items[1] = MP_OBJ_NEW_SMALL_INT(MOD_NETWORK_SOCK_STREAM);
tuple->items[2] = MP_OBJ_NEW_SMALL_INT(0);
tuple->items[3] = MP_OBJ_NEW_QSTR(MP_QSTR_);
tuple->items[4] = netutils_format_inet_addr(out_ip, port, NETUTILS_BIG);
return mp_obj_new_list(1, (mp_obj_t*)&tuple);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_2(socket_getaddrinfo_obj, socket_getaddrinfo);
STATIC const mp_rom_map_elem_t socket_globals_table[] = {
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_usocket) },
{ MP_ROM_QSTR(MP_QSTR_socket), MP_ROM_PTR(&socket_type) },
{ MP_ROM_QSTR(MP_QSTR_getaddrinfo), MP_ROM_PTR(&socket_getaddrinfo_obj) },
// class constants
{ MP_ROM_QSTR(MP_QSTR_AF_INET), MP_ROM_INT(MOD_NETWORK_AF_INET) },
{ MP_ROM_QSTR(MP_QSTR_AF_INET6), MP_ROM_INT(MOD_NETWORK_AF_INET6) },
{ MP_ROM_QSTR(MP_QSTR_SOCK_STREAM), MP_ROM_INT(MOD_NETWORK_SOCK_STREAM) },
{ MP_ROM_QSTR(MP_QSTR_SOCK_DGRAM), MP_ROM_INT(MOD_NETWORK_SOCK_DGRAM) },
{ MP_ROM_QSTR(MP_QSTR_SOCK_RAW), MP_ROM_INT(MOD_NETWORK_SOCK_RAW) },
/*
{ MP_ROM_QSTR(MP_QSTR_IPPROTO_IP), MP_ROM_INT(MOD_NETWORK_IPPROTO_IP) },
{ MP_ROM_QSTR(MP_QSTR_IPPROTO_ICMP), MP_ROM_INT(MOD_NETWORK_IPPROTO_ICMP) },
{ MP_ROM_QSTR(MP_QSTR_IPPROTO_IPV4), MP_ROM_INT(MOD_NETWORK_IPPROTO_IPV4) },
{ MP_ROM_QSTR(MP_QSTR_IPPROTO_TCP), MP_ROM_INT(MOD_NETWORK_IPPROTO_TCP) },
{ MP_ROM_QSTR(MP_QSTR_IPPROTO_UDP), MP_ROM_INT(MOD_NETWORK_IPPROTO_UDP) },
{ MP_ROM_QSTR(MP_QSTR_IPPROTO_IPV6), MP_ROM_INT(MOD_NETWORK_IPPROTO_IPV6) },
{ MP_ROM_QSTR(MP_QSTR_IPPROTO_RAW), MP_ROM_INT(MOD_NETWORK_IPPROTO_RAW) },
*/
};
STATIC MP_DEFINE_CONST_DICT(socket_globals, socket_globals_table);
const mp_obj_module_t socket_module = {
.base = { &mp_type_module },
.globals = (mp_obj_dict_t*)&socket_globals,
};

View File

@ -206,6 +206,20 @@ STATIC mp_obj_t time_time(void) {
}
MP_DEFINE_CONST_FUN_OBJ_0(time_time_obj, time_time);
//| .. method:: monotonic_ns(clk_id)
//|
//| Return the time of the specified clock clk_id in nanoseconds. Refer to
//| Clock ID Constants for a list of accepted values for clk_id.
//|
//| :return: the current time
//| :rtype: int
//|
STATIC mp_obj_t time_monotonic_ns(void) {
uint64_t time64 = common_hal_time_monotonic() * 1000000llu;
return mp_obj_new_int_from_ll((long long) time64);
}
MP_DEFINE_CONST_FUN_OBJ_0(time_monotonic_ns_obj, time_monotonic_ns);
//| .. method:: localtime([secs])
//|
//| Convert a time expressed in seconds since Jan 1, 1970 to a struct_time in
@ -280,6 +294,7 @@ STATIC const mp_rom_map_elem_t time_module_globals_table[] = {
#endif // MICROPY_PY_COLLECTIONS
#if MICROPY_LONGINT_IMPL != MICROPY_LONGINT_IMPL_NONE
{ MP_ROM_QSTR(MP_QSTR_time), MP_ROM_PTR(&time_time_obj) },
{ MP_ROM_QSTR(MP_QSTR_monotonic_ns), MP_ROM_PTR(&time_monotonic_ns_obj) },
#endif
};

View File

@ -0,0 +1,69 @@
/*
* This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
* Copyright (c) 2014 Damien P. George
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#include <stdio.h>
#include <stdint.h>
#include <string.h>
#include "py/objlist.h"
#include "py/objproperty.h"
#include "py/runtime.h"
#include "py/mphal.h"
#include "shared-module/network/__init__.h"
//| :mod:`wiznet` --- Support for WizNet hardware
//| =============================================
//|
//| .. module:: wiznet
//| :synopsis: Support for WizNet hardware
//| :platform: SAMD
//|
//| Support for WizNet hardware, including the WizNet 5500 Ethernet adaptor.
//|
//| Libraries
//|
//| .. toctree::
//| :maxdepth: 3
//|
//| wiznet5k
//|
extern const mod_network_nic_type_t mod_network_nic_type_wiznet5k;
STATIC const mp_rom_map_elem_t mp_module_wiznet_globals_table[] = {
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_wiznet) },
#ifdef MICROPY_PY_WIZNET5K
{ MP_ROM_QSTR(MP_QSTR_WIZNET5K), MP_ROM_PTR(&mod_network_nic_type_wiznet5k) },
#endif // MICROPY_PY_WIZNET5K
};
STATIC MP_DEFINE_CONST_DICT(mp_module_wiznet_globals, mp_module_wiznet_globals_table);
const mp_obj_module_t wiznet_module = {
.base = { &mp_type_module },
.globals = (mp_obj_dict_t*)&mp_module_wiznet_globals,
};

View File

@ -0,0 +1,183 @@
/*
* This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
* Copyright (c) 2014 Damien P. George
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#include <stdio.h>
#include <stdint.h>
#include <string.h>
#include "py/objlist.h"
#include "py/objproperty.h"
#include "py/runtime.h"
#include "py/stream.h"
#include "py/mperrno.h"
#include "py/mphal.h"
#include "lib/netutils/netutils.h"
#if MICROPY_PY_WIZNET5K
#include "shared-bindings/digitalio/DigitalInOut.h"
#include "shared-bindings/digitalio/DriveMode.h"
#include "shared-bindings/busio/SPI.h"
#include "shared-module/network/__init__.h"
#include "shared-module/wiznet/wiznet5k.h"
//| .. currentmodule:: wiznet
//|
//| :class:`WIZNET5K` -- wrapper for Wiznet 5500 Ethernet interface
//| ===============================================================
//|
//| .. class:: WIZNET5K(spi, cs, rst)
//|
//| Create a new WIZNET5500 interface using the specified pins
//|
//| :param spi: spi bus to use
//| :param cs: pin to use for Chip Select
//| :param rst: pin to sue for Reset
//|
STATIC mp_obj_t wiznet5k_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
// check arguments
mp_arg_check_num(n_args, n_kw, 3, 3, false);
return wiznet5k_create(args[0], args[1], args[2]);
}
//| .. attribute:: connected
//|
//| is this device physically connected?
//|
STATIC mp_obj_t wiznet5k_connected_get_value(mp_obj_t self_in) {
(void)self_in;
return mp_obj_new_bool(wizphy_getphylink() == PHY_LINK_ON);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(wiznet5k_connected_get_value_obj, wiznet5k_connected_get_value);
const mp_obj_property_t wiznet5k_connected_obj = {
.base.type = &mp_type_property,
.proxy = {(mp_obj_t)&wiznet5k_connected_get_value_obj,
(mp_obj_t)&mp_const_none_obj,
(mp_obj_t)&mp_const_none_obj},
};
//| .. attribute:: dhcp
//|
//| is DHCP active on this device? (set to true to activate DHCP, false to turn it off)
//|
STATIC mp_obj_t wiznet5k_dhcp_get_value(mp_obj_t self_in) {
(void)self_in;
return mp_obj_new_bool(wiznet5k_check_dhcp());
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(wiznet5k_dhcp_get_value_obj, wiznet5k_dhcp_get_value);
STATIC mp_obj_t wiznet5k_dhcp_set_value(mp_obj_t self_in, mp_obj_t value) {
(void)self_in;
if (mp_obj_is_true(value)) {
wiznet5k_start_dhcp();
} else {
wiznet5k_stop_dhcp();
}
return mp_const_none;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_2(wiznet5k_dhcp_set_value_obj, wiznet5k_dhcp_set_value);
const mp_obj_property_t wiznet5k_dhcp_obj = {
.base.type = &mp_type_property,
.proxy = {(mp_obj_t)&wiznet5k_dhcp_get_value_obj,
(mp_obj_t)&wiznet5k_dhcp_set_value_obj,
(mp_obj_t)&mp_const_none_obj},
};
//| .. method:: ifconfig(...)
//|
//| Called without parameters, returns a tuple of
//| (ip_address, subnet_mask, gateway_address, dns_server)
//|
//| Or can be called with the same tuple to set those parameters.
//|
STATIC mp_obj_t wiznet5k_ifconfig(size_t n_args, const mp_obj_t *args) {
wiz_NetInfo netinfo;
ctlnetwork(CN_GET_NETINFO, &netinfo);
if (n_args == 1) {
// get
mp_obj_t tuple[4] = {
netutils_format_ipv4_addr(netinfo.ip, NETUTILS_BIG),
netutils_format_ipv4_addr(netinfo.sn, NETUTILS_BIG),
netutils_format_ipv4_addr(netinfo.gw, NETUTILS_BIG),
netutils_format_ipv4_addr(netinfo.dns, NETUTILS_BIG),
};
return mp_obj_new_tuple(4, tuple);
} else {
// set
mp_obj_t *items;
mp_obj_get_array_fixed_n(args[1], 4, &items);
netutils_parse_ipv4_addr(items[0], netinfo.ip, NETUTILS_BIG);
netutils_parse_ipv4_addr(items[1], netinfo.sn, NETUTILS_BIG);
netutils_parse_ipv4_addr(items[2], netinfo.gw, NETUTILS_BIG);
netutils_parse_ipv4_addr(items[3], netinfo.dns, NETUTILS_BIG);
ctlnetwork(CN_SET_NETINFO, &netinfo);
return mp_const_none;
}
}
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(wiznet5k_ifconfig_obj, 1, 2, wiznet5k_ifconfig);
STATIC const mp_rom_map_elem_t wiznet5k_locals_dict_table[] = {
{ MP_ROM_QSTR(MP_QSTR_ifconfig), MP_ROM_PTR(&wiznet5k_ifconfig_obj) },
{ MP_ROM_QSTR(MP_QSTR_connected), MP_ROM_PTR(&wiznet5k_connected_obj) },
{ MP_ROM_QSTR(MP_QSTR_dhcp), MP_ROM_PTR(&wiznet5k_dhcp_obj) },
};
STATIC MP_DEFINE_CONST_DICT(wiznet5k_locals_dict, wiznet5k_locals_dict_table);
const mod_network_nic_type_t mod_network_nic_type_wiznet5k = {
.base = {
{ &mp_type_type },
.name = MP_QSTR_WIZNET5K,
.make_new = wiznet5k_make_new,
.locals_dict = (mp_obj_dict_t*)&wiznet5k_locals_dict,
},
.gethostbyname = wiznet5k_gethostbyname,
.socket = wiznet5k_socket_socket,
.close = wiznet5k_socket_close,
.bind = wiznet5k_socket_bind,
.listen = wiznet5k_socket_listen,
.accept = wiznet5k_socket_accept,
.connect = wiznet5k_socket_connect,
.send = wiznet5k_socket_send,
.recv = wiznet5k_socket_recv,
.sendto = wiznet5k_socket_sendto,
.recvfrom = wiznet5k_socket_recvfrom,
.setsockopt = wiznet5k_socket_setsockopt,
.settimeout = wiznet5k_socket_settimeout,
.ioctl = wiznet5k_socket_ioctl,
.timer_tick = wiznet5k_socket_timer_tick,
};
#endif // MICROPY_PY_WIZNET5K

View File

@ -141,6 +141,14 @@ void common_hal_audioio_wavefile_set_sample_rate(audioio_wavefile_obj_t* self,
self->sample_rate = sample_rate;
}
uint8_t common_hal_audioio_wavefile_get_bits_per_sample(audioio_wavefile_obj_t* self) {
return self->bits_per_sample;
}
uint8_t common_hal_audioio_wavefile_get_channel_count(audioio_wavefile_obj_t* self) {
return self->channel_count;
}
bool audioio_wavefile_samples_signed(audioio_wavefile_obj_t* self) {
return self->bits_per_sample > 8;
}

View File

@ -0,0 +1,95 @@
/*
* This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
* Copyright (c) 2018 Nick Moore
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#include <stdio.h>
#include "py/objlist.h"
#include "py/runtime.h"
#include "py/mphal.h"
#include "py/mperrno.h"
#include "shared-bindings/random/__init__.h"
#include "shared-module/network/__init__.h"
// mod_network_nic_list needs to be declared in mpconfigport.h
void network_module_init(void) {
mp_obj_list_init(&MP_STATE_PORT(mod_network_nic_list), 0);
}
void network_module_deinit(void) {
}
void network_module_background(void) {
static uint32_t next_tick = 0;
uint32_t this_tick = ticks_ms;
if (this_tick < next_tick) return;
next_tick = this_tick + 1000;
for (mp_uint_t i = 0; i < MP_STATE_PORT(mod_network_nic_list).len; i++) {
mp_obj_t nic = MP_STATE_PORT(mod_network_nic_list).items[i];
mod_network_nic_type_t *nic_type = (mod_network_nic_type_t*)mp_obj_get_type(nic);
if (nic_type->timer_tick != NULL) nic_type->timer_tick(nic);
}
}
void network_module_register_nic(mp_obj_t nic) {
for (mp_uint_t i = 0; i < MP_STATE_PORT(mod_network_nic_list).len; i++) {
if (MP_STATE_PORT(mod_network_nic_list).items[i] == nic) {
// nic already registered
return;
}
}
// nic not registered so add to list
mp_obj_list_append(MP_OBJ_FROM_PTR(&MP_STATE_PORT(mod_network_nic_list)), nic);
}
mp_obj_t network_module_find_nic(const uint8_t *ip) {
// find a NIC that is suited to given IP address
for (mp_uint_t i = 0; i < MP_STATE_PORT(mod_network_nic_list).len; i++) {
mp_obj_t nic = MP_STATE_PORT(mod_network_nic_list).items[i];
// TODO check IP suitability here
//mod_network_nic_type_t *nic_type = (mod_network_nic_type_t*)mp_obj_get_type(nic);
return nic;
}
nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, translate("no available NIC")));
}
void network_module_create_random_mac_address(uint8_t *mac) {
uint32_t rb1 = shared_modules_random_getrandbits(24);
uint32_t rb2 = shared_modules_random_getrandbits(24);
// first octet has multicast bit (0) cleared and local bit (1) set
// everything else is just set randomly
mac[0] = ((uint8_t)(rb1 >> 16) & 0xfe) | 0x02;
mac[1] = (uint8_t)(rb1 >> 8);
mac[2] = (uint8_t)(rb1);
mac[3] = (uint8_t)(rb2 >> 16);
mac[4] = (uint8_t)(rb2 >> 8);
mac[5] = (uint8_t)(rb2);
}

View File

@ -0,0 +1,90 @@
/*
* This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
* Copyright (c) 2013, 2014 Damien P. George
* Copyright (c) 2018 Nick Moore
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
void network_module_create_random_mac_address(uint8_t *mac);
#ifndef MICROPY_INCLUDED_SHARED_MODULE_NETWORK___INIT___H
#define MICROPY_INCLUDED_SHARED_MODULE_NETWORK___INIT___H
#define MOD_NETWORK_IPADDR_BUF_SIZE (4)
#define MOD_NETWORK_AF_INET (2)
#define MOD_NETWORK_AF_INET6 (10)
#define MOD_NETWORK_SOCK_STREAM (1)
#define MOD_NETWORK_SOCK_DGRAM (2)
#define MOD_NETWORK_SOCK_RAW (3)
struct _mod_network_socket_obj_t;
typedef struct _mod_network_nic_type_t {
mp_obj_type_t base;
// API for non-socket operations
int (*gethostbyname)(mp_obj_t nic, const char *name, mp_uint_t len, uint8_t *ip_out);
// API for socket operations; return -1 on error
int (*socket)(struct _mod_network_socket_obj_t *socket, int *_errno);
void (*close)(struct _mod_network_socket_obj_t *socket);
int (*bind)(struct _mod_network_socket_obj_t *socket, byte *ip, mp_uint_t port, int *_errno);
int (*listen)(struct _mod_network_socket_obj_t *socket, mp_int_t backlog, int *_errno);
int (*accept)(struct _mod_network_socket_obj_t *socket, struct _mod_network_socket_obj_t *socket2, byte *ip, mp_uint_t *port, int *_errno);
int (*connect)(struct _mod_network_socket_obj_t *socket, byte *ip, mp_uint_t port, int *_errno);
mp_uint_t (*send)(struct _mod_network_socket_obj_t *socket, const byte *buf, mp_uint_t len, int *_errno);
mp_uint_t (*recv)(struct _mod_network_socket_obj_t *socket, byte *buf, mp_uint_t len, int *_errno);
mp_uint_t (*sendto)(struct _mod_network_socket_obj_t *socket, const byte *buf, mp_uint_t len, byte *ip, mp_uint_t port, int *_errno);
mp_uint_t (*recvfrom)(struct _mod_network_socket_obj_t *socket, byte *buf, mp_uint_t len, byte *ip, mp_uint_t *port, int *_errno);
int (*setsockopt)(struct _mod_network_socket_obj_t *socket, mp_uint_t level, mp_uint_t opt, const void *optval, mp_uint_t optlen, int *_errno);
int (*settimeout)(struct _mod_network_socket_obj_t *socket, mp_uint_t timeout_ms, int *_errno);
int (*ioctl)(struct _mod_network_socket_obj_t *socket, mp_uint_t request, mp_uint_t arg, int *_errno);
void (*timer_tick)(struct _mod_network_socket_obj_t *socket);
} mod_network_nic_type_t;
typedef struct _mod_network_socket_obj_t {
mp_obj_base_t base;
mp_obj_t nic;
mod_network_nic_type_t *nic_type;
union {
struct {
uint8_t domain;
uint8_t type;
int8_t fileno;
} u_param;
mp_uint_t u_state;
};
} mod_network_socket_obj_t;
extern const mod_network_nic_type_t mod_network_nic_type_wiznet5k;
extern const mod_network_nic_type_t mod_network_nic_type_cc3k;
void network_module_init(void);
void network_module_deinit(void);
void network_module_background(void);
void network_module_register_nic(mp_obj_t nic);
mp_obj_t network_module_find_nic(const uint8_t *ip);
#endif // MICROPY_INCLUDED_SHARED_MODULE_NETWORK___INIT___H

View File

View File

View File

@ -0,0 +1,406 @@
/*
* This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
* Copyright (c) 2014 Damien P. George
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#include <stdio.h>
#include <stdint.h>
#include <string.h>
#include "py/objlist.h"
#include "py/objproperty.h"
#include "py/runtime.h"
#include "py/stream.h"
#include "py/mperrno.h"
#include "py/mphal.h"
#include "lib/netutils/netutils.h"
#if MICROPY_PY_WIZNET5K
#include "shared-module/network/__init__.h"
#include "shared-bindings/digitalio/DigitalInOut.h"
#include "shared-bindings/digitalio/DriveMode.h"
#include "shared-bindings/busio/SPI.h"
#include "shared-module/network/__init__.h"
#include "ethernet/wizchip_conf.h"
#include "ethernet/socket.h"
#include "internet/dns/dns.h"
#include "internet/dhcp/dhcp.h"
#include "shared-module/wiznet/wiznet5k.h"
STATIC wiznet5k_obj_t wiznet5k_obj;
STATIC void wiz_cris_enter(void) {
wiznet5k_obj.cris_state = MICROPY_BEGIN_ATOMIC_SECTION();
}
STATIC void wiz_cris_exit(void) {
MICROPY_END_ATOMIC_SECTION(wiznet5k_obj.cris_state);
}
STATIC void wiz_cs_select(void) {
common_hal_digitalio_digitalinout_set_value(&wiznet5k_obj.cs, 0);
}
STATIC void wiz_cs_deselect(void) {
common_hal_digitalio_digitalinout_set_value(&wiznet5k_obj.cs, 1);
}
STATIC void wiz_spi_read(uint8_t *buf, uint32_t len) {
(void)common_hal_busio_spi_read(wiznet5k_obj.spi, buf, len, 0);
}
STATIC void wiz_spi_write(const uint8_t *buf, uint32_t len) {
(void)common_hal_busio_spi_write(wiznet5k_obj.spi, buf, len);
}
int wiznet5k_gethostbyname(mp_obj_t nic, const char *name, mp_uint_t len, uint8_t *out_ip) {
uint8_t dns_ip[MOD_NETWORK_IPADDR_BUF_SIZE] = {8, 8, 8, 8};
uint8_t *buf = m_new(uint8_t, MAX_DNS_BUF_SIZE);
DNS_init(0, buf);
mp_int_t ret = DNS_run(dns_ip, (uint8_t*)name, out_ip);
m_del(uint8_t, buf, MAX_DNS_BUF_SIZE);
if (ret == 1) {
// success
return 0;
} else {
// failure
return -2;
}
}
int wiznet5k_socket_socket(mod_network_socket_obj_t *socket, int *_errno) {
if (socket->u_param.domain != MOD_NETWORK_AF_INET) {
*_errno = MP_EAFNOSUPPORT;
return -1;
}
switch (socket->u_param.type) {
case MOD_NETWORK_SOCK_STREAM: socket->u_param.type = Sn_MR_TCP; break;
case MOD_NETWORK_SOCK_DGRAM: socket->u_param.type = Sn_MR_UDP; break;
default: *_errno = MP_EINVAL; return -1;
}
if (socket->u_param.fileno == -1) {
// get first unused socket number
for (mp_uint_t sn = 0; sn < _WIZCHIP_SOCK_NUM_; sn++) {
if ((wiznet5k_obj.socket_used & (1 << sn)) == 0) {
wiznet5k_obj.socket_used |= (1 << sn);
socket->u_param.fileno = sn;
break;
}
}
if (socket->u_param.fileno == -1) {
// too many open sockets
*_errno = MP_EMFILE;
return -1;
}
}
// WIZNET does not have a concept of pure "open socket". You need to know
// if it's a server or client at the time of creation of the socket.
// So, we defer the open until we know what kind of socket we want.
// use "domain" to indicate that this socket has not yet been opened
socket->u_param.domain = 0;
return 0;
}
void wiznet5k_socket_close(mod_network_socket_obj_t *socket) {
uint8_t sn = (uint8_t)socket->u_param.fileno;
if (sn < _WIZCHIP_SOCK_NUM_) {
wiznet5k_obj.socket_used &= ~(1 << sn);
WIZCHIP_EXPORT(close)(sn);
}
}
int wiznet5k_socket_bind(mod_network_socket_obj_t *socket, byte *ip, mp_uint_t port, int *_errno) {
// open the socket in server mode (if port != 0)
mp_int_t ret = WIZCHIP_EXPORT(socket)(socket->u_param.fileno, socket->u_param.type, port, 0);
if (ret < 0) {
wiznet5k_socket_close(socket);
*_errno = -ret;
return -1;
}
// indicate that this socket has been opened
socket->u_param.domain = 1;
// success
return 0;
}
int wiznet5k_socket_listen(mod_network_socket_obj_t *socket, mp_int_t backlog, int *_errno) {
mp_int_t ret = WIZCHIP_EXPORT(listen)(socket->u_param.fileno);
if (ret < 0) {
wiznet5k_socket_close(socket);
*_errno = -ret;
return -1;
}
return 0;
}
int wiznet5k_socket_accept(mod_network_socket_obj_t *socket, mod_network_socket_obj_t *socket2, byte *ip, mp_uint_t *port, int *_errno) {
for (;;) {
int sr = getSn_SR((uint8_t)socket->u_param.fileno);
if (sr == SOCK_ESTABLISHED) {
socket2->u_param = socket->u_param;
getSn_DIPR((uint8_t)socket2->u_param.fileno, ip);
*port = getSn_PORT(socket2->u_param.fileno);
// WIZnet turns the listening socket into the client socket, so we
// need to re-bind and re-listen on another socket for the server.
// TODO handle errors, especially no-more-sockets error
socket->u_param.domain = MOD_NETWORK_AF_INET;
socket->u_param.fileno = -1;
int _errno2;
if (wiznet5k_socket_socket(socket, &_errno2) != 0) {
//printf("(bad resocket %d)\n", _errno2);
} else if (wiznet5k_socket_bind(socket, NULL, *port, &_errno2) != 0) {
//printf("(bad rebind %d)\n", _errno2);
} else if (wiznet5k_socket_listen(socket, 0, &_errno2) != 0) {
//printf("(bad relisten %d)\n", _errno2);
}
return 0;
}
if (sr == SOCK_CLOSED || sr == SOCK_CLOSE_WAIT) {
wiznet5k_socket_close(socket);
*_errno = MP_ENOTCONN; // ??
return -1;
}
mp_hal_delay_ms(1);
}
}
int wiznet5k_socket_connect(mod_network_socket_obj_t *socket, byte *ip, mp_uint_t port, int *_errno) {
// use "bind" function to open the socket in client mode
if (wiznet5k_socket_bind(socket, ip, 0, _errno) != 0) {
return -1;
}
// now connect
MP_THREAD_GIL_EXIT();
mp_int_t ret = WIZCHIP_EXPORT(connect)(socket->u_param.fileno, ip, port);
MP_THREAD_GIL_ENTER();
if (ret < 0) {
wiznet5k_socket_close(socket);
*_errno = -ret;
return -1;
}
// success
return 0;
}
mp_uint_t wiznet5k_socket_send(mod_network_socket_obj_t *socket, const byte *buf, mp_uint_t len, int *_errno) {
MP_THREAD_GIL_EXIT();
mp_int_t ret = WIZCHIP_EXPORT(send)(socket->u_param.fileno, (byte*)buf, len);
MP_THREAD_GIL_ENTER();
// TODO convert Wiz errno's to POSIX ones
if (ret < 0) {
wiznet5k_socket_close(socket);
*_errno = -ret;
return -1;
}
return ret;
}
mp_uint_t wiznet5k_socket_recv(mod_network_socket_obj_t *socket, byte *buf, mp_uint_t len, int *_errno) {
MP_THREAD_GIL_EXIT();
mp_int_t ret = WIZCHIP_EXPORT(recv)(socket->u_param.fileno, buf, len);
MP_THREAD_GIL_ENTER();
// TODO convert Wiz errno's to POSIX ones
if (ret < 0) {
wiznet5k_socket_close(socket);
*_errno = -ret;
return -1;
}
return ret;
}
mp_uint_t wiznet5k_socket_sendto(mod_network_socket_obj_t *socket, const byte *buf, mp_uint_t len, byte *ip, mp_uint_t port, int *_errno) {
if (socket->u_param.domain == 0) {
// socket not opened; use "bind" function to open the socket in client mode
if (wiznet5k_socket_bind(socket, ip, 0, _errno) != 0) {
return -1;
}
}
MP_THREAD_GIL_EXIT();
mp_int_t ret = WIZCHIP_EXPORT(sendto)(socket->u_param.fileno, (byte*)buf, len, ip, port);
MP_THREAD_GIL_ENTER();
if (ret < 0) {
wiznet5k_socket_close(socket);
*_errno = -ret;
return -1;
}
return ret;
}
mp_uint_t wiznet5k_socket_recvfrom(mod_network_socket_obj_t *socket, byte *buf, mp_uint_t len, byte *ip, mp_uint_t *port, int *_errno) {
uint16_t port2;
MP_THREAD_GIL_EXIT();
mp_int_t ret = WIZCHIP_EXPORT(recvfrom)(socket->u_param.fileno, buf, len, ip, &port2);
MP_THREAD_GIL_ENTER();
*port = port2;
if (ret < 0) {
wiznet5k_socket_close(socket);
*_errno = -ret;
return -1;
}
return ret;
}
int wiznet5k_socket_setsockopt(mod_network_socket_obj_t *socket, mp_uint_t level, mp_uint_t opt, const void *optval, mp_uint_t optlen, int *_errno) {
// TODO
*_errno = MP_EINVAL;
return -1;
}
int wiznet5k_socket_settimeout(mod_network_socket_obj_t *socket, mp_uint_t timeout_ms, int *_errno) {
// TODO
*_errno = MP_EINVAL;
return -1;
/*
if (timeout_ms == 0) {
// set non-blocking mode
uint8_t arg = SOCK_IO_NONBLOCK;
WIZCHIP_EXPORT(ctlsocket)(socket->u_param.fileno, CS_SET_IOMODE, &arg);
}
*/
}
int wiznet5k_socket_ioctl(mod_network_socket_obj_t *socket, mp_uint_t request, mp_uint_t arg, int *_errno) {
if (request == MP_STREAM_POLL) {
int ret = 0;
if (arg & MP_STREAM_POLL_RD && getSn_RX_RSR(socket->u_param.fileno) != 0) {
ret |= MP_STREAM_POLL_RD;
}
if (arg & MP_STREAM_POLL_WR && getSn_TX_FSR(socket->u_param.fileno) != 0) {
ret |= MP_STREAM_POLL_WR;
}
return ret;
} else {
*_errno = MP_EINVAL;
return MP_STREAM_ERROR;
}
}
void wiznet5k_socket_timer_tick(mod_network_socket_obj_t *socket) {
if (wiznet5k_obj.dhcp_active) {
DHCP_time_handler();
DHCP_run();
}
}
void wiznet5k_start_dhcp(void) {
static DHCP_INIT_BUFFER_TYPE dhcp_buf[DHCP_INIT_BUFFER_SIZE];
if (!wiznet5k_obj.dhcp_active) {
// Set up the socket to listen on UDP 68 before calling DHCP_init
WIZCHIP_EXPORT(socket)(0, MOD_NETWORK_SOCK_DGRAM, DHCP_CLIENT_PORT, 0);
DHCP_init(0, dhcp_buf);
wiznet5k_obj.dhcp_active = 1;
}
}
void wiznet5k_stop_dhcp(void) {
if (wiznet5k_obj.dhcp_active) {
wiznet5k_obj.dhcp_active = 0;
DHCP_stop();
WIZCHIP_EXPORT(close)(0);
}
}
bool wiznet5k_check_dhcp(void) {
return wiznet5k_obj.dhcp_active;
}
/// Create and return a WIZNET5K object.
mp_obj_t wiznet5k_create(mp_obj_t spi_in, mp_obj_t cs_in, mp_obj_t rst_in) {
// init the wiznet5k object
wiznet5k_obj.base.type = (mp_obj_type_t*)&mod_network_nic_type_wiznet5k;
wiznet5k_obj.cris_state = 0;
wiznet5k_obj.spi = MP_OBJ_TO_PTR(spi_in);
common_hal_digitalio_digitalinout_construct(&wiznet5k_obj.cs, cs_in);
common_hal_digitalio_digitalinout_construct(&wiznet5k_obj.rst, rst_in);
wiznet5k_obj.socket_used = 0;
/*!< SPI configuration */
// XXX probably should check if the provided SPI is already configured, and
// if so skip configuration?
common_hal_busio_spi_configure(wiznet5k_obj.spi,
10000000, // BAUDRATE 10MHz
1, // HIGH POLARITY
1, // SECOND PHASE TRANSITION
8 // 8 BITS
);
common_hal_digitalio_digitalinout_switch_to_output(&wiznet5k_obj.cs, 1, DRIVE_MODE_PUSH_PULL);
common_hal_digitalio_digitalinout_switch_to_output(&wiznet5k_obj.rst, 1, DRIVE_MODE_PUSH_PULL);
common_hal_digitalio_digitalinout_set_value(&wiznet5k_obj.rst, 0);
mp_hal_delay_us(10); // datasheet says 2us
common_hal_digitalio_digitalinout_set_value(&wiznet5k_obj.rst, 1);
mp_hal_delay_ms(160); // datasheet says 150ms
reg_wizchip_cris_cbfunc(wiz_cris_enter, wiz_cris_exit);
reg_wizchip_cs_cbfunc(wiz_cs_select, wiz_cs_deselect);
reg_wizchip_spi_cbfunc(wiz_spi_read, wiz_spi_write);
// 2k buffer for each socket
uint8_t sn_size[16] = {2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2};
ctlwizchip(CW_INIT_WIZCHIP, sn_size);
wiz_NetInfo netinfo = {
.dhcp = NETINFO_DHCP,
};
network_module_create_random_mac_address(netinfo.mac);
ctlnetwork(CN_SET_NETINFO, (void*)&netinfo);
// seems we need a small delay after init
mp_hal_delay_ms(250);
wiznet5k_start_dhcp();
// register with network module
network_module_register_nic(&wiznet5k_obj);
// return wiznet5k object
return &wiznet5k_obj;
}
#endif // MICROPY_PY_WIZNET5K

View File

@ -0,0 +1,69 @@
/*
* This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
* Copyright (c) 2014 Damien P. George
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#ifndef MICROPY_INCLUDED_SHARED_MODULE_WIZNET_WIZNET5K_H
#define MICROPY_INCLUDED_SHARED_MODULE_WIZNET_WIZNET5K_H
#include "ethernet/wizchip_conf.h"
#include "ethernet/socket.h"
#include "internet/dns/dns.h"
#include "internet/dhcp/dhcp.h"
typedef struct _wiznet5k_obj_t {
mp_obj_base_t base;
mp_uint_t cris_state;
busio_spi_obj_t *spi;
digitalio_digitalinout_obj_t cs;
digitalio_digitalinout_obj_t rst;
uint8_t socket_used;
bool dhcp_active;
} wiznet5k_obj_t;
int wiznet5k_gethostbyname(mp_obj_t nic, const char *name, mp_uint_t len, uint8_t *out_ip);
int wiznet5k_socket_socket(mod_network_socket_obj_t *socket, int *_errno);
void wiznet5k_socket_close(mod_network_socket_obj_t *socket);
int wiznet5k_socket_bind(mod_network_socket_obj_t *socket, byte *ip, mp_uint_t port, int *_errno);
int wiznet5k_socket_listen(mod_network_socket_obj_t *socket, mp_int_t backlog, int *_errno);
int wiznet5k_socket_accept(mod_network_socket_obj_t *socket, mod_network_socket_obj_t *socket2, byte *ip, mp_uint_t *port, int *_errno);
int wiznet5k_socket_connect(mod_network_socket_obj_t *socket, byte *ip, mp_uint_t port, int *_errno);
mp_uint_t wiznet5k_socket_send(mod_network_socket_obj_t *socket, const byte *buf, mp_uint_t len, int *_errno);
mp_uint_t wiznet5k_socket_recv(mod_network_socket_obj_t *socket, byte *buf, mp_uint_t len, int *_errno);
mp_uint_t wiznet5k_socket_sendto(mod_network_socket_obj_t *socket, const byte *buf, mp_uint_t len, byte *ip, mp_uint_t port, int *_errno);
mp_uint_t wiznet5k_socket_recvfrom(mod_network_socket_obj_t *socket, byte *buf, mp_uint_t len, byte *ip, mp_uint_t *port, int *_errno);
int wiznet5k_socket_setsockopt(mod_network_socket_obj_t *socket, mp_uint_t level, mp_uint_t opt, const void *optval, mp_uint_t optlen, int *_errno);
int wiznet5k_socket_settimeout(mod_network_socket_obj_t *socket, mp_uint_t timeout_ms, int *_errno);
int wiznet5k_socket_ioctl(mod_network_socket_obj_t *socket, mp_uint_t request, mp_uint_t arg, int *_errno);
void wiznet5k_socket_timer_tick(mod_network_socket_obj_t *socket);
mp_obj_t wiznet5k_socket_disconnect(mp_obj_t self_in);
mp_obj_t wiznet5k_create(mp_obj_t spi_in, mp_obj_t cs_in, mp_obj_t rst_in);
void wiznet5k_start_dhcp(void);
void wiznet5k_stop_dhcp(void);
bool wiznet5k_check_dhcp(void);
extern const mod_network_nic_type_t mod_network_nic_type_wiznet5k;
#endif // MICROPY_INCLUDED_SHARED_MODULE_WIZNET_WIZNET5K_H

View File

@ -6,6 +6,7 @@ rm -rf ports/nrf/build*
# Alphabetical.
HW_BOARDS="\
arduino_mkr1300 \
arduino_zero \
circuitplayground_express \
circuitplayground_express_crickit \
@ -25,6 +26,7 @@ grandcentral_m4_express \
hallowing_m0_express \
itsybitsy_m0_express \
itsybitsy_m4_express \
makerdiary_nrf52840_mdk \
metro_m0_express \
metro_m4_express \
meowmeow \
@ -82,6 +84,11 @@ for board in $boards; do
(( exit_status = exit_status || $? ))
temp_filename=ports/nrf/build-$board-s140/firmware.uf2
extension=uf2
elif [[ $board == "makerdiary_nrf52840_mdk" ]]; then
make $PARALLEL -C ports/nrf TRANSLATION=$language BOARD=$board SD=s140
(( exit_status = exit_status || $? ))
temp_filename=ports/nrf/build-$board-s140/firmware.hex
extension=hex
else
time make $PARALLEL -C ports/atmel-samd TRANSLATION=$language BOARD=$board
(( exit_status = exit_status || $? ))

View File

@ -78,6 +78,18 @@ MP_BC_LOAD_GLOBAL = 0x1d
MP_BC_LOAD_ATTR = 0x1e
MP_BC_STORE_ATTR = 0x26
# load opcode names
opcode_names = {}
with open("../../py/bc0.h") as f:
for line in f.readlines():
if line.startswith("#define"):
s = line.split(maxsplit=3)
if len(s) < 3:
continue
_, name, value = s[:3]
opcode = int(value.strip("()"), 0)
opcode_names[opcode] = name
def make_opcode_format():
def OC4(a, b, c, d):
return a | (b << 2) | (c << 4) | (d << 6)
@ -252,35 +264,50 @@ class RawCode:
i += 1
RawCode.escaped_names.add(self.escaped_name)
sizes = {"bytecode": 0, "strings": 0, "raw_code_overhead": 0, "const_table_overhead": 0, "string_overhead": 0, "number_overhead": 0}
# emit children first
for rc in self.raw_codes:
rc.freeze(self.escaped_name + '_')
subsize = rc.freeze(self.escaped_name + '_')
for k in sizes:
sizes[k] += subsize[k]
# generate bytecode data
print()
print('// frozen bytecode for file %s, scope %s%s' % (self.source_file.str, parent_name, self.simple_name.str))
print("// bytecode size", len(self.bytecode))
print('STATIC ', end='')
if not config.MICROPY_OPT_CACHE_MAP_LOOKUP_IN_BYTECODE:
print('const ', end='')
print('byte bytecode_data_%s[%u] = {' % (self.escaped_name, len(self.bytecode)))
sizes["bytecode"] += len(self.bytecode)
print(' ', end='')
for i in range(self.ip2):
print(' 0x%02x,' % self.bytecode[i], end='')
print()
print(" // simple name")
print(' ', self.simple_name.qstr_id, '& 0xff,', self.simple_name.qstr_id, '>> 8,')
print(" // source file")
print(' ', self.source_file.qstr_id, '& 0xff,', self.source_file.qstr_id, '>> 8,')
print(" // code info")
print(' ', end='')
for i in range(self.ip2 + 4, self.ip):
print(' 0x%02x,' % self.bytecode[i], end='')
print()
print(" // bytecode")
ip = self.ip
while ip < len(self.bytecode):
f, sz = mp_opcode_format(self.bytecode, ip)
opcode = self.bytecode[ip]
if opcode in opcode_names:
opcode = opcode_names[opcode]
else:
opcode = '0x%02x' % opcode
if f == 1:
qst = self._unpack_qstr(ip + 1).qstr_id
print(' ', '0x%02x,' % self.bytecode[ip], qst, '& 0xff,', qst, '>> 8,')
print(' {}, {} & 0xff, {} >> 8,'.format(opcode, qst, qst))
else:
print(' ', ''.join('0x%02x, ' % self.bytecode[ip + i] for i in range(sz)))
print(' {},{}'.format(opcode, ''.join(' 0x%02x,' % self.bytecode[ip + i] for i in range(1, sz))))
ip += sz
print('};')
@ -295,9 +322,12 @@ class RawCode:
obj_type = 'mp_type_str'
else:
obj_type = 'mp_type_bytes'
print('STATIC const mp_obj_str_t %s = {{&%s}, %u, %u, (const byte*)"%s"};'
print('STATIC const mp_obj_str_t %s = {{&%s}, %u, %u, (const byte*)"%s"}; // %s'
% (obj_name, obj_type, qstrutil.compute_hash(obj, config.MICROPY_QSTR_BYTES_IN_HASH),
len(obj), ''.join(('\\x%02x' % b) for b in obj)))
len(obj), ''.join(('\\x%02x' % b) for b in obj), obj))
sizes["strings"] += len(obj)
sizes["string_overhead"] += 16
elif is_int_type(obj):
if config.MICROPY_LONGINT_IMPL == config.MICROPY_LONGINT_IMPL_NONE:
# TODO check if we can actually fit this long-int into a small-int
@ -321,14 +351,17 @@ class RawCode:
print('STATIC const mp_obj_int_t %s = {{&mp_type_int}, '
'{.neg=%u, .fixed_dig=1, .alloc=%u, .len=%u, .dig=(uint%u_t[]){%s}}};'
% (obj_name, neg, ndigs, ndigs, bits_per_dig, digs))
sizes["number_overhead"] += 16
elif type(obj) is float:
print('#if MICROPY_OBJ_REPR == MICROPY_OBJ_REPR_A || MICROPY_OBJ_REPR == MICROPY_OBJ_REPR_B')
print('STATIC const mp_obj_float_t %s = {{&mp_type_float}, %.16g};'
% (obj_name, obj))
print('#endif')
sizes["number_overhead"] += 8
elif type(obj) is complex:
print('STATIC const mp_obj_complex_t %s = {{&mp_type_complex}, %.16g, %.16g};'
% (obj_name, obj.real, obj.imag))
sizes["number_overhead"] += 12
else:
raise FreezeError(self, 'freezing of object %r is not implemented' % (obj,))
@ -338,8 +371,10 @@ class RawCode:
print('STATIC const mp_rom_obj_t const_table_data_%s[%u] = {'
% (self.escaped_name, const_table_len))
for qst in self.qstrs:
sizes["const_table_overhead"] += 4
print(' MP_ROM_QSTR(%s),' % global_qstrs[qst].qstr_id)
for i in range(len(self.objs)):
sizes["const_table_overhead"] += 4
if type(self.objs[i]) is float:
print('#if MICROPY_OBJ_REPR == MICROPY_OBJ_REPR_A || MICROPY_OBJ_REPR == MICROPY_OBJ_REPR_B')
print(' MP_ROM_PTR(&const_obj_%s_%u),' % (self.escaped_name, i))
@ -353,6 +388,7 @@ class RawCode:
else:
print(' MP_ROM_PTR(&const_obj_%s_%u),' % (self.escaped_name, i))
for rc in self.raw_codes:
sizes["const_table_overhead"] += 4
print(' MP_ROM_PTR(&raw_code_%s),' % rc.escaped_name)
print('};')
@ -376,6 +412,9 @@ class RawCode:
print(' #endif')
print(' },')
print('};')
sizes["raw_code_overhead"] += 16
return sizes
def read_uint(f):
i = 0
@ -467,6 +506,7 @@ def freeze_mpy(base_qstrs, raw_codes):
new[q.qstr_esc] = (len(new), q.qstr_esc, q.str)
new = sorted(new.values(), key=lambda x: x[0])
print('#include "py/bc0.h"')
print('#include "py/mpconfig.h"')
print('#include "py/objint.h"')
print('#include "py/objstr.h"')
@ -523,27 +563,45 @@ def freeze_mpy(base_qstrs, raw_codes):
print(' %u, // allocated entries' % len(new))
print(' %u, // used entries' % len(new))
print(' {')
qstr_size = {"metadata": 0, "data": 0}
for _, _, qstr in new:
qstr_size["metadata"] += config.MICROPY_QSTR_BYTES_IN_LEN + config.MICROPY_QSTR_BYTES_IN_HASH
qstr_size["data"] += len(qstr)
print(' %s,'
% qstrutil.make_bytes(config.MICROPY_QSTR_BYTES_IN_LEN, config.MICROPY_QSTR_BYTES_IN_HASH, qstr))
print(' },')
print('};')
sizes = {}
for rc in raw_codes:
rc.freeze(rc.source_file.str.replace('/', '_')[:-3] + '_')
sizes[rc.source_file.str] = rc.freeze(rc.source_file.str.replace('/', '_')[:-3] + '_')
print()
print('const char mp_frozen_mpy_names[] = {')
qstr_size["filenames"] = 1
for rc in raw_codes:
module_name = rc.source_file.str
print('"%s\\0"' % module_name)
qstr_size["filenames"] += len(module_name) + 1
print('"\\0"};')
print('const mp_raw_code_t *const mp_frozen_mpy_content[] = {')
for rc in raw_codes:
print(' &raw_code_%s,' % rc.escaped_name)
size = sizes[rc.source_file.str]
print(' // Total size:', sum(size.values()))
for k in size:
print(" // {} {}".format(k, size[k]))
print('};')
print()
print('// Total size:', sum([sum(x.values()) for x in sizes.values()]) + sum(qstr_size.values()))
for k in size:
total = sum([x[k] for x in sizes.values()])
print("// {} {}".format(k, total))
for k in qstr_size:
print("// qstr {} {}".format(k, qstr_size[k]))
def main():
import argparse
cmd_parser = argparse.ArgumentParser(description='A tool to work with MicroPython .mpy files.')