From: Lawrence S. <ljs...@us...> - 2022-04-28 23:22:55
|
This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "A pseudo Operating System for the Dreamcast.". The branch, master has been updated via 81ec331be28e755ce34dc02bf6a1b0d1bf0559b0 (commit) via 3df13d4cc68c20e9d53645e54326b8966078bc97 (commit) via 0ebbd92dc1c07618e671901e6a906f35897a3522 (commit) via d371a30efb673ee92d972a8af4a23aab81402b83 (commit) via e29c3eb8015f2f5200bc0655c2782e4d10db4ba7 (commit) from f0b2c9517541c308af1f5920bf87411a82a9ed56 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit 81ec331be28e755ce34dc02bf6a1b0d1bf0559b0 Merge: f0b2c95 3df13d4 Author: Luke Benstead <ka...@gm...> Date: Thu Apr 28 09:37:26 2022 +0100 Merge pull request #74 from KallistiOS/modem-tx-fixes Modem transmission fixes commit 3df13d4cc68c20e9d53645e54326b8966078bc97 Author: Luke Benstead <ka...@gm...> Date: Thu Apr 28 09:36:36 2022 +0100 Fix incorrect TXFNF register This fixes sporadic modem transmission failures. This commit also changes the logic slightly so we block waiting for CTS rather than returning and sending nothing in the event the modem wasn't ready. commit 0ebbd92dc1c07618e671901e6a906f35897a3522 Author: Luke Benstead <ka...@gm...> Date: Thu Apr 28 09:36:22 2022 +0100 Add a FIXME commit d371a30efb673ee92d972a8af4a23aab81402b83 Author: Luke Benstead <ka...@gm...> Date: Thu Apr 28 09:36:09 2022 +0100 Reset mintCounter when we reset the timeout commit e29c3eb8015f2f5200bc0655c2782e4d10db4ba7 Author: Luke Benstead <ka...@gm...> Date: Thu Apr 28 09:35:48 2022 +0100 Add a modem PPP example ----------------------------------------------------------------------- Summary of changes: addons/libppp/ppp_modem.c | 1 + examples/dreamcast/modem/{basic => ppp}/Makefile | 7 +- examples/dreamcast/modem/ppp/example1.c | 127 +++++++++++++++++++++++ kernel/arch/dreamcast/hardware/modem/mdata.c | 43 ++++---- kernel/arch/dreamcast/hardware/modem/mintr.c | 1 + 5 files changed, 153 insertions(+), 26 deletions(-) copy examples/dreamcast/modem/{basic => ppp}/Makefile (74%) create mode 100644 examples/dreamcast/modem/ppp/example1.c diff --git a/addons/libppp/ppp_modem.c b/addons/libppp/ppp_modem.c index ddcaa05..3d9a2e8 100644 --- a/addons/libppp/ppp_modem.c +++ b/addons/libppp/ppp_modem.c @@ -39,6 +39,7 @@ static int ppp_modem_tx(ppp_device_t *self, const uint8_t *data, size_t len, /* As long as we have something to send, do so. */ while(done < len) { + /* FIXME: This will loop infinitely if modem_write_data always fails */ done += modem_write_data((unsigned char *)data + done, (int)len - done); } diff --git a/examples/dreamcast/modem/basic/Makefile b/examples/dreamcast/modem/ppp/Makefile similarity index 74% copy from examples/dreamcast/modem/basic/Makefile copy to examples/dreamcast/modem/ppp/Makefile index 8d2e9f2..31f1a1b 100644 --- a/examples/dreamcast/modem/basic/Makefile +++ b/examples/dreamcast/modem/ppp/Makefile @@ -1,8 +1,3 @@ -# -# Basic modem test program -# Copyright (C)2003 Nick Kochakian -# - TARGET = example1.elf OBJS = example1.o @@ -18,7 +13,7 @@ rm-elf: -rm -f $(TARGET) romdisk.* $(TARGET): $(OBJS) - kos-cc -o $(TARGET) $(OBJS) + kos-cc -o $(TARGET) $(OBJS) -lppp run: $(TARGET) $(KOS_LOADER) $(TARGET) diff --git a/examples/dreamcast/modem/ppp/example1.c b/examples/dreamcast/modem/ppp/example1.c new file mode 100644 index 0000000..e85815b --- /dev/null +++ b/examples/dreamcast/modem/ppp/example1.c @@ -0,0 +1,127 @@ +/* KallistiOS ##version## + + example1.c + Copyright (C)2022 Luke Benstead + + Modem PPP example (intended for DreamPi connection) +*/ + +#include <stdio.h> +#include <kos.h> +#include <netdb.h> +#include <arpa/inet.h> +#include <sys/socket.h> +#include <kos/net.h> +#include <ppp/ppp.h> +#include <time.h> + +KOS_INIT_FLAGS(INIT_DEFAULT | INIT_NET); + + +int main() { + char buffer[1024]; + + int err; + struct addrinfo *ai; + struct addrinfo hints; + + const struct sockaddr* addr_ptr; + socklen_t addr_len; + struct sockaddr_in addr4; + struct sockaddr_in6 addr6; + + time_t start; + int total_bytes = 0; + + if(!modem_init()) { + printf("modem_init failed!\n"); + return 1; + } + + ppp_init(); + + printf("Dialing connection\n"); + err = ppp_modem_init("555", 0, NULL); + if(err != 0) { + printf("Couldn't dial a connection (%d)\n", err); + return 1; + } + + printf("Establishing PPP link\n"); + ppp_set_login("dream", "cast"); + + err = ppp_connect(); + if(err != 0) { + printf("Couldn't establish PPP link (%d)\n", err); + return 1; + } + + /* Make a DNS lookup for google */ + memset(&hints, 0, sizeof(hints)); + hints.ai_family = AF_INET; + err = getaddrinfo("google.com", "80", &hints, &ai); + if(err != 0) { + printf("Unable to perform DNS lookup (%d)\n", err); + return 1; + } + + /* Get the first address v4 or v6, whatever */ + if(ai->ai_family == AF_INET) { + addr4 = *(struct sockaddr_in *) ai->ai_addr; + addr4.sin_family = AF_INET; + addr4.sin_port = htons(80); + addr_ptr = (const struct sockaddr*) &addr4; + addr_len = sizeof(struct sockaddr_in); + } else if(ai->ai_family == AF_INET6) { + addr6 = *(struct sockaddr_in6 *) ai->ai_addr; + addr6.sin6_family = AF_INET6; + addr6.sin6_port = htons(80); + addr_ptr = (const struct sockaddr*) &addr6; + addr_len = sizeof(struct sockaddr_in6); + } else { + printf("Unexpected IP family\n"); + return 1; + } + + freeaddrinfo(ai); + + /* Make a POST request to Google to make sure things are working */ + const char* req = "POST / HTTP/1.1\r\nHost: www.google.com\r\nContent-Type: application/x-www-form-urlencoded\r\nContent-Length: 27\r\n\r\nfield1=value1&field2=value2\r\n\r\n"; + + int s = socket(AF_INET, SOCK_STREAM, 0); + err = connect(s, addr_ptr, addr_len); + + for(int i = 0; i < 10; ++i) { + sleep(1); + printf("Sending request: %d. Response follows: \n\n\n\n", i); + int sent = send(s, req, strlen(req), 0); + if(sent == -1) { + printf("Error sending request\n"); + return 1; + } else if(sent != strlen(req)) { + printf("Error sending full request\n"); + return 1; + } + + start = time(NULL); + total_bytes = 0; + while(1) { + int bytes = recv(s, buffer, 1024, MSG_DONTWAIT); + if(bytes <= 0) { + if(total_bytes) { + /* We received something previously so we're done */ + break; + } else if(time(NULL) > start + 30) { + printf("Timeout while waiting for response\n"); + usleep(10); + break; + } + } else { + total_bytes += bytes; + printf("%s", buffer); + } + } + } + + return 0; +} diff --git a/kernel/arch/dreamcast/hardware/modem/mdata.c b/kernel/arch/dreamcast/hardware/modem/mdata.c index f153f77..f576627 100644 --- a/kernel/arch/dreamcast/hardware/modem/mdata.c +++ b/kernel/arch/dreamcast/hardware/modem/mdata.c @@ -177,30 +177,33 @@ void modemDataInternalHandleOutgoingData(void) { return; /* CTS needs to be set before any data can be copied into TBUFFER */ - if(modemRead(REGLOC(0xF)) & 0x20) { - /* Copy data from the local TX FIFO buffer into the MDP's TX FIFO buffer - while there's data in the local buffer and there's space in the MDP's - buffer */ - counter = 0; - - while((modemRead(REGLOC(0x1D)) & 0x2) && bufferLength > 0 && - counter < MODEM_DATA_LIMIT) { /* Checks TXFNF */ - /* Read a byte from the chain buffer */ - if(readFromChainBuffer(txBuffer, &data, 1) != 1) - assert(0); /* This should never happen */ + while(!(modemRead(REGLOC(0xF)) & 0x20)) { + thd_pass(); + } - /* Write the byte to TBUFFER */ - modemWrite(REGLOC(0x10), data); + /* Copy data from the local TX FIFO buffer into the MDP's TX FIFO buffer + while there's data in the local buffer and there's space in the MDP's + buffer */ + counter = 0; - bufferLength--; - counter++; - } + while((modemRead(REGLOC(0x0D)) & 0x2) && bufferLength > 0 && + counter < MODEM_DATA_LIMIT) { /* Checks TXFNF */ + /* Read a byte from the chain buffer */ + if(readFromChainBuffer(txBuffer, &data, 1) != 1) + assert(0); /* This should never happen */ - /* If the buffer was emptied then generate the corresponding event - if the event handler is set */ - if(bufferLength <= 0 && modemCfg.eventHandler) - modemCfg.eventHandler(MODEM_EVENT_TX_EMPTY); + /* Write the byte to TBUFFER */ + modemWrite(REGLOC(0x10), data); + + bufferLength--; + counter++; } + + /* If the buffer was emptied then generate the corresponding event + if the event handler is set */ + if(bufferLength <= 0 && modemCfg.eventHandler) + modemCfg.eventHandler(MODEM_EVENT_TX_EMPTY); + } /* Internal. Called by the interrupt service routine to update the receive diff --git a/kernel/arch/dreamcast/hardware/modem/mintr.c b/kernel/arch/dreamcast/hardware/modem/mintr.c index 32e2f54..f9258b4 100644 --- a/kernel/arch/dreamcast/hardware/modem/mintr.c +++ b/kernel/arch/dreamcast/hardware/modem/mintr.c @@ -33,6 +33,7 @@ void mintDelayCallback(void) { if(mintCounter >= 5) { modemIntResetTimeoutTimer(); modemIntShutdownTimeoutTimer(); + mintCounter = 0; /* Reset the counter for subsequent connections */ modemCfg.flags &= ~MODEM_CFG_FLAG_CONNECTING; modemCfg.flags |= MODEM_CFG_FLAG_CONNECTED; hooks/post-receive -- A pseudo Operating System for the Dreamcast. |