Skip to content

Commit

Permalink
add pc host port support
Browse files Browse the repository at this point in the history
  • Loading branch information
Albert Bogdanovic committed Sep 29, 2022
1 parent fdf8c06 commit af553d2
Show file tree
Hide file tree
Showing 8 changed files with 627 additions and 69 deletions.
29 changes: 21 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,14 @@
#
# %LICENSE%
#
# set local path manually as we're including other Makefiles here (as an empty var - TOPDIR)

include ../phoenix-rtos-build/Makefile.common
LWIP_LOCAL_DIR := $(dir $(lastword $(MAKEFILE_LIST)))

# set local path manually as we're including other Makefiles here (as an empty var - TOPDIR)
LOCAL_DIR :=
include ../phoenix-rtos-build/Makefile.common

.DEFAULT_GOAL := all

LWIPOPTS_DIR ?= "include/default-opts"

# default path for the programs to be installed in rootfs
DEFAULT_INSTALL_PATH := /sbin

Expand All @@ -29,12 +27,25 @@ ifeq (${LWIP_G3_BUILD}, yes)
include g3/Makefile
endif

CFLAGS += -Wundef -Iinclude -Ilib-lwip/src/include -I"$(LWIPOPTS_DIR)"
LWIPOPTS_DIR ?= include/default-opts
LWIPPORT_DIR ?= include/

# port specific definitions
include Makefile.contrib

ifeq ("$(TARGET)","host-generic-pc")
DEPS := lwip-port lwip-opts
LOCAL_HEADERS_DIR := $(LWIPDIR)/include
else
# don't install include subdir contents, these are actually internal headers
LOCAL_HEADERS_DIR := nothing
endif

CFLAGS += -Wundef -I$(LWIPPORT_DIR) -I$(LWIPDIR)/include -I$(LWIPOPTS_DIR)

LOCAL_DIR := $(LWIP_LOCAL_DIR)
NAME := lwip-core
SRCS := $(LWIP_SRCS)
# don't install include subdir contents, these are actually internal headers
LOCAL_HEADER_DIR := nothing
include $(static-lib.mk)

# should define NET_DRIVERS and platform driver sources
Expand All @@ -52,7 +63,9 @@ include ipsec/Makefile
endif

include drivers/Makefile
ifneq ("$(TARGET)","host-generic-pc")
include port/Makefile
endif

DEFAULT_COMPONENTS := $(ALL_COMPONENTS)

Expand Down
24 changes: 24 additions & 0 deletions Makefile.contrib
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Makefile for port specific components to include
# INFO: this Makefile being used to create multiple headers tree static libs because static-lib.mk not handle multiple headers dirs include
ifeq ("$(TARGET)","host-generic-pc")
LWIPOPTS_DIR = include/default-opts/unix
LWIPPORT_DIR = contrib/ports/unix/port/include
LWIP_SRCS += contrib/ports/unix/port/sys_arch.c contrib/ports/unix/port/perf.c

# Application components
LWIP_SRCS += contrib/apps/ping/ping.c
LOCAL_HEADERS := contrib/apps/ping/ping.h
else
LWIPOPTS_DIR = include/default-opts
LWIPPORT_DIR = include/
endif

LOCAL_DIR := $(LWIP_LOCAL_DIR)
NAME := lwip-opts
LOCAL_HEADERS_DIR := $(LWIPOPTS_DIR)
include $(static-lib.mk)

LOCAL_DIR := $(LWIP_LOCAL_DIR)
NAME := lwip-port
LOCAL_HEADERS_DIR := $(LWIPPORT_DIR)
include $(static-lib.mk)
10 changes: 10 additions & 0 deletions _targets/Makefile.host-generic
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#
# Makefile for Phoenix-RTOS 3 LwIP
#
# PC host target
#
# Copyright 2022 Phoenix Systems
#

NET_DRIVERS_SUPPORTED := pppos
NET_DRIVERS ?= $(NET_DRIVERS_SUPPORTED)
5 changes: 5 additions & 0 deletions drivers/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ ifneq ($(filter pppos,$(NET_DRIVERS)),)
endif
endif

ifeq ("$(TARGET)","host-generic-pc")
CFLAGS += -Iinclude
LOCAL_HEADERS := ../include/netif-driver.h
endif

NAME := lwip-drivers
LOCAL_SRCS := $(DRIVERS_SRCS)
include $(static-lib.mk)
35 changes: 20 additions & 15 deletions drivers/netif-driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
#include "lwip/stats.h"
#include "lwip/snmp.h"
#include "lwip/ethip6.h"

#include <sys/threads.h>
#include <arch/sys_arch.h>
#include <pthread.h>
#include <errno.h>
#include <stdlib.h>
#include <string.h>
Expand All @@ -30,7 +30,7 @@
struct mdio_bus {
const mdio_bus_ops_t *ops;
void *arg;
handle_t lock;
sys_mutex_t *lock;
};


Expand All @@ -53,7 +53,7 @@ int register_mdio_bus(const mdio_bus_ops_t *ops, void *arg)
if (mdio[i].ops)
continue;

if ((err = mutexCreate(&mdio[i].lock)))
if ((err = sys_mutex_new(mdio[i].lock)))
return err;

mdio[i].ops = ops;
Expand Down Expand Up @@ -123,7 +123,7 @@ int create_netif(char *conf)
*arg++ = 0;

is_ppp = (arg != NULL) && (strncmp(conf, "ppp", 3) == 0);
//printf("netif: driver '%s' args '%s' is_ppp=%d\n", conf, arg, is_ppp);
printf("netif: driver '%s' args '%s' is_ppp=%d\n", conf, arg, is_ppp);

for (drv = net_driver_list; drv != NULL; drv = drv->next)
if (!strcmp(conf, drv->name))
Expand All @@ -140,6 +140,7 @@ int create_netif(char *conf)
return -ENOMEM;

ni = &storage->netif;
netif_default = ni;
storage->cfg = arg;
storage->drv = drv;

Expand Down Expand Up @@ -178,16 +179,19 @@ int mdio_lock_bus(unsigned bus)
{
const struct mdio_bus *pb = mdio_bus(bus);

if (pb)
return mutexLock(pb->lock);
else
if (pb) {
sys_mutex_lock(pb->lock);
return 0;
}
else {
return -ENODEV;
}
}


void mdio_unlock_bus(unsigned bus)
{
mutexUnlock(mdio_bus(bus)->lock);
sys_mutex_unlock(mdio_bus(bus)->lock);
}


Expand All @@ -197,9 +201,9 @@ int mdio_setup(unsigned bus, unsigned max_khz, unsigned min_hold_ns, unsigned op
int err;

if (pb) {
mutexLock(pb->lock);
sys_mutex_lock(pb->lock);
err = pb->ops->setup(pb->arg, max_khz, min_hold_ns, opt_preamble);
mutexUnlock(pb->lock);
sys_mutex_unlock(pb->lock);
} else
err = -ENODEV;

Expand All @@ -213,9 +217,9 @@ uint16_t mdio_read(unsigned bus, unsigned addr, uint16_t reg)
uint16_t v = 0;

if (pb) {
mutexLock(pb->lock);
sys_mutex_lock(pb->lock);
v = pb->ops->read(pb->arg, addr, reg);
mutexUnlock(pb->lock);
sys_mutex_unlock(pb->lock);
}

return v;
Expand All @@ -227,8 +231,9 @@ void mdio_write(unsigned bus, unsigned addr, uint16_t reg, uint16_t val)
const struct mdio_bus *pb = mdio_bus(bus);

if (pb) {
mutexLock(pb->lock);
sys_mutex_lock(pb->lock);
pb->ops->write(pb->arg, addr, reg, val);
mutexUnlock(pb->lock);
sys_mutex_lock(pb->lock);
}
}

Loading

0 comments on commit af553d2

Please sign in to comment.