first version with network support (not working)

This commit is contained in:
Jörg Deckert 2013-12-10 16:11:08 +01:00
parent 33b686a09e
commit 8ac257b97a
8 changed files with 1511 additions and 0 deletions

173
lib/adm-lan.spin Normal file
View File

@ -0,0 +1,173 @@
{{ LAN-Funktionen für Administra }}
CON 'Signaldefinitionen --------------------------------------------------------------------------
'signaldefinitionen administra (todo: nach glob-con.spin auslagern!!!)
#14, A_NETCS,A_NETSCK,A_NETSI,A_NETSO 'Pins zum ENC28J60
CON 'NVRAM Konstanten --------------------------------------------------------------------------
' todo: nach glob-con.spin auslagern!!!
#4, NVRAM_IPADDR
#8, NVRAM_IPMASK
#12, NVRAM_IPGW
#16, NVRAM_IPDNS
#20, NVRAM_IPBOOT
#24, NVRAM_HIVE ' 4 Bytes
CON
' buffer sizes, must be a power of 2
rxlen = 2048
txlen = 128
VAR
byte ftp_bufrx1[rxlen] ' buffers for connection to server
byte ftp_buftx1[txlen]
byte ftp_bufrx2[rxlen] ' buffers for connection from server
byte ftp_buftx2[txlen]
byte strTemp[128]
OBJ
gc : "glob-con" 'globale konstanten
num : "glob-numbers" 'Number Engine
rtc : "adm-rtc" 'RTC-Engine
com : "adm-com" 'serielle schnittstelle (nur zum Debugging genutzt)
sock : "api_telnet_serial" 'TCP Socket Funktionen
PUB start | hiveid, hivestr, strpos, macpos
ip_addr := rtc.getNVSRAM(NVRAM_IPADDR)
ip_addr[1] := rtc.getNVSRAM(NVRAM_IPADDR+1)
ip_addr[2] := rtc.getNVSRAM(NVRAM_IPADDR+2)
ip_addr[3] := rtc.getNVSRAM(NVRAM_IPADDR+3)
ip_subnet := rtc.getNVSRAM(NVRAM_IPMASK)
ip_subnet[1] := rtc.getNVSRAM(NVRAM_IPMASK+1)
ip_subnet[2] := rtc.getNVSRAM(NVRAM_IPMASK+2)
ip_subnet[3] := rtc.getNVSRAM(NVRAM_IPMASK+3)
ip_gateway := rtc.getNVSRAM(NVRAM_IPGW)
ip_gateway[1] := rtc.getNVSRAM(NVRAM_IPGW+1)
ip_gateway[2] := rtc.getNVSRAM(NVRAM_IPGW+2)
ip_gateway[3] := rtc.getNVSRAM(NVRAM_IPGW+3)
ip_dns := rtc.getNVSRAM(NVRAM_IPDNS)
ip_dns[1] := rtc.getNVSRAM(NVRAM_IPDNS+1)
ip_dns[2] := rtc.getNVSRAM(NVRAM_IPDNS+2)
ip_dns[3] := rtc.getNVSRAM(NVRAM_IPDNS+3)
hiveid := rtc.getNVSRAM(NVRAM_HIVE)
hiveid := hiveid + rtc.getNVSRAM(NVRAM_HIVE+1) << 8
hiveid := hiveid + rtc.getNVSRAM(NVRAM_HIVE+2) << 16
hiveid := hiveid + rtc.getNVSRAM(NVRAM_HIVE+3) << 24
hivestr := num.ToStr(hiveid, num#DEC)
strpos := strsize(hivestr)
macpos := 5
repeat while (strpos AND macpos)
strpos--
if(strpos)
strpos--
mac_addr[macpos] := num.FromStr(hivestr+strpos, num#HEX)
byte[hivestr+strpos] := 0
macpos--
sock.start(A_NETCS,A_NETSCK,A_NETSI,A_NETSO, -1, @mac_addr, @ip_addr)
PUB stop
sock.stop
PUB ftpOpen(addr) : connected 'FTP-Verbindung öffnen
com.str(string("ftpOpen Start",13,10))
repeat 5 'mehrmals probieren, falls z.B. TCP-Engine-Cog noch nicht bereit
sock.connect(addr, 21, @ftp_bufrx1, rxlen, @ftp_buftx1, txlen)
'sock.resetBuffers
if connected := sock.waitConnectTimeout(1500)
'todo: einfügen? if getResponse(string("220"))
if getResponse(string("220 "))
com.str(string("Send: USER anonymous",13,10))
sock.str(string("USER anonymous",13,10))
if getResponse(string("230 "))
quit
else
sock.close
PUB ftpClose 'FTP-Verbindung schließen
com.str(string("Send: QUIT",13,10))
sock.str(string("QUIT",13,10))
getResponse(string("221 "))
sock.close
PUB ftpOpenData(addr,port) : connected
PUB ftpCloseData
PUB ftpBoot 'zum Boot-Server verbinden
ip_boot := rtc.getNVSRAM(NVRAM_IPBOOT) << 24
ip_boot := ip_boot + rtc.getNVSRAM(NVRAM_IPBOOT+1) << 16
ip_boot := ip_boot + rtc.getNVSRAM(NVRAM_IPBOOT+2) << 8
ip_boot := ip_boot + rtc.getNVSRAM(NVRAM_IPBOOT+3)
if ip_boot
if ftpOpen(ip_boot)
ftpClose
PUB ftpListName 'Verzeichniseintrag lesen
return
PRI getResponse (strOk) : respOk | len
respOk := FALSE
repeat
readLine
com.str(@strTemp)
com.str(string(13,10))
if strsize(@strTemp) == 0
quit
'byte[@strTemp+strsize(strOk)] := 0
strTemp[strsize(strOk)] := 0
com.str(string("StrOk: "))
com.str(strOk)
com.str(string("StrComp: "))
com.str(@strTemp)
com.str(string(13,10))
if strcomp(@strTemp, strOk)
respOk := TRUE
return respOk
PRI readLine | i, ch
repeat i from 0 to 126
ch := sock.rxtime(500)
if ch == 13
ch := sock.rxtime(500)
if ch == -1 or ch == 10
quit
strTemp[i] := ch
strTemp[i] := 0
return i
DAT
long ' long alignment for addresses
ip_addr byte 10, 1, 1, 1 'ip
ip_subnet byte 255, 255, 255, 0 'subnet-maske
ip_gateway byte 10, 1, 1, 254 'gateway
ip_dns byte 10, 1, 1, 254 'dns
ip_boot long 0 'boot-server (IP address in long)
mac_addr byte $c0, $de, $ba, $be, $00, $00 'mac-adresse

View File

@ -0,0 +1 @@
{{ PropTCP Sockets - FullDuplexSerial API Layer -------------------------------------------- Copyright (c) 2006-2009 Harrison Pham <harrison@harrisonpham.com> 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. The latest version of this software can be obtained from http://hdpham.com/PropTCP and http://obex.parallax.com/}}'' NOTICE: All buffer sizes must be a power of 2!OBJ tcp : "driver_socket" VAR long handle word listenport byte listening long ptrrxbuff, ptrtxbuff word rxlen, txlenPUB start(cs, sck, si, so, xtalout, macptr, ipconfigptr) tcp.start(cs, sck, si, so, xtalout, macptr, ipconfigptr)PUB stop tcp.stopPUB connect(ipaddr, remoteport, _ptrrxbuff, _rxlen, _ptrtxbuff, _txlen) {if tcp.isValidHandle(handle) close} listening := false handle := -1 handle := tcp.connect(ipaddr, remoteport, _ptrrxbuff, _rxlen, _ptrtxbuff, _txlen) return handle PUB listen(port, _ptrrxbuff, _rxlen, _ptrtxbuff, _txlen) {if tcp.isValidHandle(handle) close} listenport := port ptrrxbuff := _ptrrxbuff rxlen := _rxlen ptrtxbuff := _ptrtxbuff txlen := _txlen listening := true handle := -1 handle := tcp.listen(listenport, ptrrxbuff, rxlen, ptrtxbuff, txlen) return handlePUB relisten if listening ifnot tcp.isValidHandle(handle) listen(listenport, ptrrxbuff, rxlen, ptrtxbuff, txlen)PUB isConnected return tcp.isConnected(handle)PUB rxcount return tcp.getReceiveBufferCount(handle)PUB resetBuffers tcp.resetBuffers(handle)PUB waitConnectTimeout(ms) : connected | t t := cnt repeat until (connected := isConnected) or (((cnt - t) / (clkfreq / 1000)) > ms)PUB close tcp.close(handle) handle := -1PUB rxflush repeat while rxcheck => 0PUB rxcheck : rxbyte {if listening relisten rxbyte := tcp.readByteNonBlocking(handle) else} rxbyte := tcp.readByteNonBlocking(handle) if (not tcp.isConnected(handle)) and (rxbyte == -1) abort tcp#ERRSOCKETCLOSEDPUB rxtime(ms) : rxbyte | t t := cnt repeat until (rxbyte := rxcheck) => 0 or (cnt - t) / (clkfreq / 1000) > msPUB rx : rxbyte repeat while (rxbyte := rxcheck) < 0PUB rxdatatime(ptr, maxlen, ms) : len | t t := cnt repeat until (len := tcp.readDataNonBlocking(handle, ptr, maxlen)) => 0 or (cnt - t) / (clkfreq / 1000) > msPUB rxdata(ptr, maxlen) return tcp.readData(handle, ptr, maxlen)PUB txflush tcp.flush(handle)PUB txcheck(txbyte) {if listening relisten} ifnot tcp.isConnected(handle) abort tcp#ERRSOCKETCLOSED return tcp.writeByteNonBlocking(handle, txbyte)PUB tx(txbyte) repeat while txcheck(txbyte) < 0PUB txdata(ptr, len) {if listening relisten} tcp.writeData(handle, ptr, len)PUB str(stringptr) txdata(stringptr, strsize(stringptr)) PUB dec(value) | i'' Print a decimal number if value < 0 -value tx("-") i := 1_000_000_000 repeat 10 if value => i tx(value / i + "0") value //= i result~~ elseif result or i == 1 tx("0") i /= 10PUB hex(value, digits)'' Print a hexadecimal number value <<= (8 - digits) << 2 repeat digits tx(lookupz((value <-= 4) & $F : "0".."9", "A".."F"))PUB bin(value, digits)'' Print a binary number value <<= 32 - digits repeat digits tx((value <-= 1) & 1 + "0")

1
lib/driver_enc28j60.spin Normal file

File diff suppressed because one or more lines are too long

1
lib/driver_socket.spin Normal file

File diff suppressed because one or more lines are too long

View File

@ -163,6 +163,13 @@ A_AYS = %00000000_00000000_00000010_00000000
a_rtcPauseForSec 'Pauses execution for a number of seconds. Returns a puesdo random value derived from the current clock frequency and the time when called. Number - Number of seconds to pause for between 0 and 2,147,483,647.
a_rtcPauseForMSec '58 'Pauses execution for a number of milliseconds. Returns a puesdo random value derived from the current clock frequency and the time when called. Number - Number of milliseconds to pause for between 0 and 2,147,483,647.
' ---------------------------------------------- NET-FUNKTIONEN
#71, a_lanStart 'Start Network
a_lanStop 'Stop Network
a_lanFTPOpen 'FTP-Verbindung öffnen
a_lanFTPClose 'FTP-Verbindung schließen
a_lanFTPNextFile 'Verzeichniseintrag lesen
' ---------------------------------------------- CHIP-MANAGMENT
#92, a_mgrSetSound 'soundsubsysteme verwalten
a_mgrGetSpec 'spezifikation abfragen

View File

@ -1026,7 +1026,21 @@ PUB pauseForMilliseconds(number) 'Pauses execution for a
return bus_getlong1
CON ''------------------------------------------------- LAN_LAUFWERKSFUNKTIONEN
PUB lanstart 'LAN starten
''funktionsgruppe : lan
''funktion : TCP-Netzwerk starten
''busprotokoll : -
bus_putchar1(gc#a_lanStart)
PUB lanstop 'LAN beenden
''funktionsgruppe : lan
''funktion : TCP-Netzwerk beenden
''busprotokoll : -
bus_putchar1(gc#a_lanStop)
CON ''------------------------------------------------- Hydra Sound System

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,173 @@
{{
┌──────────────────────────────────────────────────────────────────────────────────────────────────────┐
│ Autor: Jörg Deckert │
│ Copyright (c) 2013 Jörg Deckert │
│ See end of file for terms of use. │
│ Die Nutzungsbedingungen befinden sich am Ende der Datei │
└──────────────────────────────────────────────────────────────────────────────────────────────────────┘
Informationen : hive-project.de
Kontakt : joergd@bitquell.de
System : TriOS
Name : flash
Chip : Regnatix
Typ : Programm
Version :
Subversion :
Funktion : IP-Konfiguration in NVRAM ablegen
Komponenten : -
COG's : -
Logbuch :
11.06.2013-joergd - erste Version, basierend auf time.spin
Kommandoliste :
Notizen :
}}
OBJ
ios: "reg-ios"
str: "glob-string"
num: "glob-numbers" 'Number Engine
CON
_CLKMODE = XTAL1 + PLL16X
_XINFREQ = 5_000_000
CON 'NVRAM Konstanten --------------------------------------------------------------------------
#4, NVRAM_IPADDR
#8, NVRAM_IPMASK
#12, NVRAM_IPGW
#16, NVRAM_IPDNS
#20, NVRAM_IPBOOT
#24, NVRAM_HIVE ' 4 Bytes
VAR
byte parastr[64]
PUB main
ios.start 'ios initialisieren
ios.printnl
ios.parastart 'parameterübergabe starten
repeat while ios.paranext(@parastr) 'parameter einlesen
if byte[@parastr][0] == "/" 'option?
case byte[@parastr][1]
"?": ios.print(@help)
"l": cmd_listcfg
"a": if ios.paranext(@parastr)
cmd_setaddr(NVRAM_IPADDR, @parastr)
"m": if ios.paranext(@parastr)
cmd_setaddr(NVRAM_IPMASK, @parastr)
"g": if ios.paranext(@parastr)
cmd_setaddr(NVRAM_IPGW, @parastr)
"d": if ios.paranext(@parastr)
cmd_setaddr(NVRAM_IPDNS, @parastr)
"b": if ios.paranext(@parastr)
cmd_setaddr(NVRAM_IPBOOT, @parastr)
"i": if ios.paranext(@parastr)
cmd_sethive(num.FromStr(@parastr, num#DEC))
other: ios.print(@help)
ios.stop
PRI cmd_listcfg | hiveid 'nvram: IP-Konfiguration anzeigen
ios.print(string(" IP-Adresse: "))
listaddr(NVRAM_IPADDR)
ios.print(string("/"))
listaddr(NVRAM_IPMASK)
ios.printnl
ios.print(string(" Gateway: "))
listaddr(NVRAM_IPGW)
ios.printnl
ios.print(string(" DNS-Server: "))
listaddr(NVRAM_IPDNS)
ios.printnl
ios.print(string(" Boot-Server: "))
listaddr(NVRAM_IPBOOT)
ios.printnl
ios.print(string(" Hive-Id: "))
hiveid := ios.getNVSRAM(NVRAM_HIVE)
hiveid := hiveid + ios.getNVSRAM(NVRAM_HIVE+1) << 8
hiveid := hiveid + ios.getNVSRAM(NVRAM_HIVE+2) << 16
hiveid := hiveid + ios.getNVSRAM(NVRAM_HIVE+3) << 24
ios.print(str.trimCharacters(num.ToStr(hiveid, num#DEC)))
ios.printnl
PRI listaddr (nvidx) | count 'nvram: IP-Adresse setzen
repeat count from 0 to 3
if(count)
ios.print(string("."))
ios.print(str.trimCharacters(num.ToStr(ios.getNVSRAM(nvidx+count), num#DEC)))
PRI cmd_setaddr (nvidx, ipaddr) | pos, count 'nvram: IP-Adresse setzen
count := 0
repeat while ipaddr
pos := str.findCharacter(ipaddr, ".")
if(pos)
byte[pos++] := 0
ios.setNVSRAM(nvidx+count++, num.FromStr(ipaddr, num#DEC))
ipaddr := pos
if(count == 4)
quit
ios.lanstart
cmd_listcfg
PRI cmd_sethive (hiveid) 'nvram: IP-Adresse setzen
ios.setNVSRAM(NVRAM_HIVE, hiveid & $FF)
ios.setNVSRAM(NVRAM_HIVE+1, (hiveid >> 8) & $FF)
ios.setNVSRAM(NVRAM_HIVE+2, (hiveid >> 16) & $FF)
ios.setNVSRAM(NVRAM_HIVE+3, (hiveid >> 24) & $FF)
ios.lanstart
cmd_listcfg
DAT 'sys: helptext
help byte "/? : Hilfe",13
byte "/l : Konfiguration anzeigen",13
byte "/a <a.b.c.d> : IP-Adresse setzen",13
byte "/m <x.x.x.x> : Netzwerk-Maske setzen",13
byte "/g <e.f.g.h> : Gateway setzen",13
byte "/d <i.j.k.l> : DNS-Server setzen",13
byte "/b <m.n.o.p> : Boot-Server setzen",13
byte "/i <Id> : Hive-Id setzen",13
byte 0
DAT 'lizenz
{{
┌──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
│ TERMS OF USE: MIT License │
├──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┤
│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. │
└──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
}}