From 585d6d01cfb8a6864f4875050039e40b4db01c6e Mon Sep 17 00:00:00 2001 From: stefan Date: Wed, 11 Aug 2010 20:42:49 +0000 Subject: [PATCH] - first steps to realize a RCKPC driver git-svn-id: http://svn.lfbs.rwth-aachen.de/svn/scc/trunk/MetalSVM@81 315a16e6-25f9-4109-90ae-ca3045a26c18 --- drivers/Makefile | 14 ++++++++++ drivers/net/Makefile | 21 ++++++++++++++ drivers/net/sccpc.c | 65 ++++++++++++++++++++++++++++++++++++++++++++ kernel/main.c | 47 +++++++++++++++++--------------- 4 files changed, 125 insertions(+), 22 deletions(-) create mode 100644 drivers/Makefile create mode 100644 drivers/net/Makefile create mode 100644 drivers/net/sccpc.c diff --git a/drivers/Makefile b/drivers/Makefile new file mode 100644 index 00000000..3e4b6e45 --- /dev/null +++ b/drivers/Makefile @@ -0,0 +1,14 @@ +SUBDIRS = net + +default: + for i in $(SUBDIRS); do $(MAKE) -C $$i default; done + +all: + for i in $(SUBDIRS); do $(MAKE) -C $$i all; done + +clean: + for i in $(SUBDIRS); do $(MAKE) -C $$i clean; done + +depend: + for i in $(SUBDIRS); do $(MAKE) -C $$i depend; done + diff --git a/drivers/net/Makefile b/drivers/net/Makefile new file mode 100644 index 00000000..dd7c72f2 --- /dev/null +++ b/drivers/net/Makefile @@ -0,0 +1,21 @@ +C_source = sccpc.c + +OBJS += $(patsubst %.c, %.o, $(filter %.c, $(C_source))) +ALLOBJS += $(patsubst %.c, %.o, $(filter %.c, $(C_source))) + +# other implicit rules +%.o : %.c + $(CC) -c $(CFLAGS) -o $@ $< + +default: $(OBJS) + +all: $(OBJS) + +clean: + $(RM) *.o *~ $(NAME) + +depend: + $(CC) -MM $(CFLAGS) $(C_source) > Makefile.dep + +-include Makefile.dep +# DO NOT DELETE diff --git a/drivers/net/sccpc.c b/drivers/net/sccpc.c new file mode 100644 index 00000000..f3b115ae --- /dev/null +++ b/drivers/net/sccpc.c @@ -0,0 +1,65 @@ +/* + * Copyright 2010 Stefan Lankes, Chair for Operating Systems, + * RWTH Aachen University + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * This file is part of MetalSVM. + */ + +#include +#include +#include +#ifdef CONFIG_LWIP +#include +#include +#include +#include + +static struct netif *mynetif; + +/** + * + * + * @return error code + * - ERR_OK: packet transferred to hardware + * - ERR_CONN: no link or link failure + * - ERR_IF: could not transfer to link (hardware buffer full?) + */ +static err_t sccpc_output(struct netif *netif, struct pbuf *p) +{ + return ERR_CONN; +} + +err_t sccpcif_init(struct netif* netif) +{ + mynetif = netif; + + /* administrative details */ + mynetif->name[0] = 'p'; + mynetif->name[1] = 'c'; + mynetif->num = 0; + /* downward functions */ + mynetif->output = ip_output; + mynetif->linkoutput = sccpc_output; + /* maximum transfer unit */ + mynetif->mtu = 1500; + /* broadcast capability */ + mynetif->flags = NETIF_FLAG_LINK_UP; + /* hardware address length */ + mynetif->hwaddr_len = 6; + + return ERR_OK; +} + +#endif diff --git a/kernel/main.c b/kernel/main.c index c63f9578..6d019cb6 100644 --- a/kernel/main.c +++ b/kernel/main.c @@ -37,25 +37,33 @@ #include #include #include -//#include +#endif +#ifdef CONFIG_ROCKCREEK +#include #endif extern int test_init(void); extern const void kernel_start; extern const void kernel_end; -#ifdef CONFIG_LWIP -int STDCALL lwip_task(void* arg) +#if defined(CONFIG_LWIP) && defined(CONFIG_ROCKCREEK) +err_t sccpcif_init(struct netif* netif); + +int STDCALL scc_pc_task(void* arg) { struct netif netif; struct ip_addr ipaddr; struct ip_addr netmask; struct ip_addr gw; - err_t err; sleep(10); kputs("LWIP task is started\n"); + /* Set network address variables */ + IP4_ADDR(&gw, 192,168,1,254); + IP4_ADDR(&ipaddr, 192,168,1,scc_info.pid+1); + IP4_ADDR(&netmask, 255,255,255,0); + stats_init(); /* Clears the structure where runtime statistics are gathered */ sys_init(); mem_init(); /* Initializes the dynamic memory heap defined by MEM_SIZE. */ @@ -67,25 +75,20 @@ int STDCALL lwip_task(void* arg) tcp_init(); /* Clears the TCP PCB list and clears some internal TCP timers. */ /* Bring up the network interface */ - //if (!netif_add(&netif, &ipaddr, &netmask, &gw, NULL, pcnetif_init, ethernet_input)) { - // kputs("Unable to add network interface\n"); - // return NULL; - //} + if (!netif_add(&netif, &ipaddr, &netmask, &gw, NULL, sccpcif_init, ip_input)) { + kputs("Unable to add network interface\n"); + return -1; + } - /* This will bring the interface up and set its IP address when it can acquire one. */ - //err = dhcp_start(&netif); - //if (err != ERR_OK) { - // kprintf("Unable to get IP via DHCP: %s\n", lwip_strerr(err)); - // return NULL; - //} + netif_set_default(&netif); - //if (netif_is_up(&netif)) { - // kputs("Network interface is not up\n"); - // return NULL; - //} + if (netif_is_up(&netif)) { + kputs("Network interface is not up\n"); + return -1; + } - //while(1) { - //} + while(1) { + } return 0; } @@ -94,7 +97,7 @@ int STDCALL lwip_task(void* arg) int main(void) { #ifdef CONFIG_LWIP - tid_t lwip_id; + tid_t pc_id; #endif kprintf("Here is MetalSVM %s\n", METALSVM_VERSION); @@ -128,7 +131,7 @@ int main(void) test_init(); #ifdef CONFIG_LWIP - //create_kernel_task(&lwip_id, lwip_task, NULL); + create_kernel_task(&pc_id, scc_pc_task, NULL); #endif current_task->status = TASK_IDLE;