Merge branch 'master' of ssh://contiki.git.sourceforge.net/gitroot/contiki/contiki
This commit is contained in:
commit
6ffb38103e
242 changed files with 0 additions and 42576 deletions
|
@ -1,292 +0,0 @@
|
|||
###################################################################
|
||||
# toplevel makefile for contiki 2.x
|
||||
#
|
||||
# 2006/06/24 gpz - initial creation
|
||||
#
|
||||
# todo:
|
||||
# - add rules for other/more ports
|
||||
# - add "dist-<target>" rules (for creating tarballs)
|
||||
# - create checks for required tools and give hints on where
|
||||
# to get certain missing stuff
|
||||
# - incase certain targets fail, print a error summary when
|
||||
# all targets are done
|
||||
###################################################################
|
||||
|
||||
# uncomment this for less verbose output
|
||||
#.SILENT:
|
||||
|
||||
MAKE=make
|
||||
ECHO=echo -en
|
||||
CD=cd
|
||||
|
||||
###################################################################
|
||||
# this first rule prints usage info when the make is invoked
|
||||
# without any arguments
|
||||
###################################################################
|
||||
|
||||
.PHONY: usage
|
||||
|
||||
usage:
|
||||
-@$(ECHO) "usage: make <target(s)>\n\n"
|
||||
-@$(ECHO) "available targets are:\n\n"
|
||||
-@$(ECHO) "docs build the documentation\n"
|
||||
-@$(ECHO) "gtk build full featured GTK port\n"
|
||||
-@$(ECHO) "gtk-examples build examples with GTK port\n"
|
||||
-@$(ECHO) "esb build full featured ESB port\n"
|
||||
-@$(ECHO) "esb-examples build examples with ESB port\n"
|
||||
-@$(ECHO) "minimal-net-examples build examples with minimal-net port\n"
|
||||
-@$(ECHO) "native-examples build examples with native port\n"
|
||||
-@$(ECHO) "all build everything\n"
|
||||
-@$(ECHO) "clean cleanup the sourcetree\n"
|
||||
-@$(ECHO) "\nfor more targets and other details look at this makefile.\n"
|
||||
|
||||
###################################################################
|
||||
# the "all" rule can be used to make a clean build from all and
|
||||
# everything. you will need to have all kinds of support tools
|
||||
# installed for this to work!
|
||||
###################################################################
|
||||
|
||||
.PHONY: all dist examples
|
||||
|
||||
all: source-dist docs docs-dist examples c64 esb ethernut1 ethernut2 gtk minimal-net minimal-ppp native netsim
|
||||
|
||||
dist: source-dist docs-dist
|
||||
|
||||
examples: c64-examples esb-examples ethernut1-examples ethernut2-examples gtk-examples minimal-net-examples minimal-ppp-examples native-examples netsim-examples
|
||||
examples-clean: c64-examples-clean esb-examples-clean ethernut1-examples-clean ethernut2-examples-clean gtk-examples-clean minimal-net-examples-clean minimal-ppp-examples-clean native-examples-clean netsim-examples-clean
|
||||
|
||||
###################################################################
|
||||
# general cleanup rule
|
||||
###################################################################
|
||||
|
||||
.PHONY: clean
|
||||
|
||||
clean: docs-clean examples-clean c64-clean esb-clean ethernut1-clean ethernut2-clean gtk-clean minimal-net-clean minimal-ppp-clean native-clean netsim-clean
|
||||
-@$(ECHO) "sourcetree cleaned up.\n"
|
||||
|
||||
###################################################################
|
||||
# rules for building the documentation
|
||||
###################################################################
|
||||
|
||||
.PHONY: docs docs-clean docs-html docs-pdf docs-dist
|
||||
|
||||
docs: docs-html docs-pdf
|
||||
|
||||
docs-doxygen:
|
||||
-@$(CD) doc; $(MAKE) dox
|
||||
|
||||
docs-html: docs-doxygen
|
||||
|
||||
docs-pdf: docs-doxygen
|
||||
-@$(CD) doc; $(MAKE) pdf
|
||||
|
||||
docs-clean:
|
||||
-@$(CD) doc; $(MAKE) clean
|
||||
|
||||
docs-dist:
|
||||
|
||||
###################################################################
|
||||
# rules for building the source distribution
|
||||
###################################################################
|
||||
|
||||
source-dist:
|
||||
|
||||
###################################################################
|
||||
# rules for the C64 port
|
||||
###################################################################
|
||||
|
||||
.PHONY: c64 c64-clean
|
||||
|
||||
c64:
|
||||
-@$(CD) platform/c64; $(MAKE) all
|
||||
|
||||
c64-clean:
|
||||
-@$(CD) platform/c64; $(MAKE) clean
|
||||
|
||||
c64-dist:
|
||||
|
||||
c64-examples: c64-example-webserver c64-example-telnet-server c64-example-test-ipv6
|
||||
|
||||
c64-example-telnet-server:
|
||||
-@$(CD) examples/telnet-server; $(MAKE) TARGET=c64
|
||||
c64-example-webserver:
|
||||
-@$(CD) examples/webserver; $(MAKE) TARGET=c64
|
||||
c64-example-test-ipv6:
|
||||
-@$(CD) examples/test-ipv6; $(MAKE) TARGET=c64
|
||||
|
||||
c64-examples-clean:
|
||||
-@$(CD) examples/telnet-server; $(MAKE) TARGET=c64 clean
|
||||
-@$(CD) examples/webserver; $(MAKE) TARGET=c64 clean
|
||||
-@$(CD) examples/test-ipv6; $(MAKE) TARGET=c64 clean
|
||||
|
||||
###################################################################
|
||||
# rules for the ESB port
|
||||
###################################################################
|
||||
|
||||
.PHONY: esb esb-clean
|
||||
|
||||
esb:
|
||||
-@$(CD) platform/esb; $(MAKE) all
|
||||
|
||||
esb-clean:
|
||||
-@$(CD) platform/esb; $(MAKE) clean
|
||||
|
||||
esb-dist:
|
||||
|
||||
esb-examples:
|
||||
esb-examples-clean:
|
||||
|
||||
###################################################################
|
||||
# rules for the ethernut1 port
|
||||
###################################################################
|
||||
|
||||
.PHONY: ethernut1 ethernut1-clean
|
||||
|
||||
ethernut1:
|
||||
# -@$(CD) platform/ethernut1; $(MAKE) all
|
||||
|
||||
ethernut1-clean:
|
||||
# -@$(CD) platform/ethernut1; $(MAKE) clean
|
||||
|
||||
ethernut1-dist:
|
||||
|
||||
ethernut1-examples:
|
||||
ethernut1-examples-clean:
|
||||
|
||||
###################################################################
|
||||
# rules for the ethernut2 port
|
||||
###################################################################
|
||||
|
||||
.PHONY: ethernut2 ethernut2-clean
|
||||
|
||||
ethernut2:
|
||||
# -@$(CD) platform/ethernut2; $(MAKE) all
|
||||
|
||||
ethernut2-clean:
|
||||
# -@$(CD) platform/ethernut2; $(MAKE) clean
|
||||
|
||||
ethernut2-dist:
|
||||
|
||||
ethernut2-examples:
|
||||
ethernut2-examples-clean:
|
||||
|
||||
###################################################################
|
||||
# rules for the GTK port
|
||||
###################################################################
|
||||
|
||||
.PHONY: gtk gtk-clean
|
||||
|
||||
gtk:
|
||||
-@$(CD) platform/gtk; $(MAKE) all
|
||||
gtk-clean:
|
||||
-@$(CD) platform/gtk; $(MAKE) clean
|
||||
|
||||
gtk-examples: gtk-example-webserver gtk-example-telnet-server gtk-example-test-ipv6
|
||||
|
||||
gtk-example-telnet-server:
|
||||
-@$(CD) examples/telnet-server; $(MAKE) TARGET=gtk
|
||||
gtk-example-webserver:
|
||||
-@$(CD) examples/webserver; $(MAKE) TARGET=gtk
|
||||
gtk-example-test-ipv6:
|
||||
-@$(CD) examples/test-ipv6; $(MAKE) TARGET=gtk
|
||||
|
||||
gtk-examples-clean:
|
||||
-@$(CD) examples/telnet-server; $(MAKE) TARGET=gtk clean
|
||||
-@$(CD) examples/webserver; $(MAKE) TARGET=gtk clean
|
||||
-@$(CD) examples/test-ipv6; $(MAKE) TARGET=gtk clean
|
||||
|
||||
gtk-dist:
|
||||
|
||||
###################################################################
|
||||
# rules for the minimal-net port
|
||||
###################################################################
|
||||
|
||||
.PHONY: minimal-net minimal-net-clean
|
||||
|
||||
minimal-net:
|
||||
# -@$(CD) platform/minimal-net; $(MAKE) all
|
||||
|
||||
minimal-net-clean:
|
||||
# -@$(CD) platform/minimal-net; $(MAKE) clean
|
||||
|
||||
minimal-net-dist:
|
||||
|
||||
minimal-net-examples: minimal-net-example-telnet-server minimal-net-example-webserver minimal-net-example-test-ipv6
|
||||
|
||||
minimal-net-example-telnet-server:
|
||||
-@$(CD) examples/telnet-server; $(MAKE) TARGET=minimal-net
|
||||
minimal-net-example-webserver:
|
||||
-@$(CD) examples/webserver; $(MAKE) TARGET=minimal-net
|
||||
minimal-net-example-test-ipv6:
|
||||
-@$(CD) examples/test-ipv6; $(MAKE) TARGET=minimal-net
|
||||
|
||||
minimal-net-examples-clean:
|
||||
-@$(CD) examples/telnet-server; $(MAKE) TARGET=minimal-net clean
|
||||
-@$(CD) examples/webserver; $(MAKE) TARGET=minimal-net clean
|
||||
-@$(CD) examples/test-ipv6; $(MAKE) TARGET=minimal-net clean
|
||||
|
||||
###################################################################
|
||||
# rules for the minimal-ppp port
|
||||
###################################################################
|
||||
|
||||
.PHONY: minimal-ppp minimal-ppp-clean
|
||||
|
||||
minimal-ppp:
|
||||
-@$(CD) platform/minimal-ppp; $(MAKE) all
|
||||
|
||||
minimal-ppp-clean:
|
||||
-@$(CD) platform/minimal-ppp; $(MAKE) clean
|
||||
|
||||
minimal-ppp-dist:
|
||||
|
||||
minimal-ppp-examples:
|
||||
minimal-ppp-examples-clean:
|
||||
|
||||
###################################################################
|
||||
# rules for the native port
|
||||
###################################################################
|
||||
|
||||
.PHONY: native native-clean
|
||||
|
||||
native:
|
||||
# -@$(CD) platform/native; $(MAKE) all
|
||||
|
||||
native-clean:
|
||||
# -@$(CD) platform/native; $(MAKE) clean
|
||||
|
||||
native-dist:
|
||||
|
||||
native-examples: native-example-telnet-server native-example-webserver native-example-test-ipv6
|
||||
|
||||
native-example-telnet-server:
|
||||
-@$(CD) examples/telnet-server; $(MAKE) TARGET=native
|
||||
native-example-webserver:
|
||||
-@$(CD) examples/webserver; $(MAKE) TARGET=native
|
||||
native-example-test-ipv6:
|
||||
-@$(CD) examples/test-ipv6; $(MAKE) TARGET=native
|
||||
|
||||
native-examples-clean:
|
||||
-@$(CD) examples/telnet-server; $(MAKE) TARGET=native clean
|
||||
-@$(CD) examples/webserver; $(MAKE) TARGET=native clean
|
||||
-@$(CD) examples/test-ipv6; $(MAKE) TARGET=native clean
|
||||
|
||||
###################################################################
|
||||
# rules for the netsim port
|
||||
###################################################################
|
||||
|
||||
.PHONY: netsim netsim-clean
|
||||
|
||||
netsim:
|
||||
# -@$(CD) platform/netsim; $(MAKE) all
|
||||
|
||||
netsim-clean:
|
||||
# -@$(CD) platform/netsim; $(MAKE) clean
|
||||
|
||||
netsim-dist:
|
||||
|
||||
netsim-examples:
|
||||
|
||||
netsim-examples-clean:
|
||||
-@$(CD) examples/telnet-server; $(MAKE) TARGET=netsim clean
|
||||
-@$(CD) examples/webserver; $(MAKE) TARGET=netsim clean
|
||||
-@$(CD) examples/test-ipv6; $(MAKE) TARGET=netsim clean
|
|
@ -1,2 +0,0 @@
|
|||
editor_src = editor.c memb.c ctk-filedialog.c
|
||||
editor_dsc = editor-dsc.c
|
|
@ -1,73 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2004, Adam Dunkels.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. 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.
|
||||
* 3. The name of the author may not be used to endorse or promote
|
||||
* products derived from this software without specific prior
|
||||
* written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
||||
*
|
||||
* This file is part of the Contiki desktop environment
|
||||
*
|
||||
* $Id: editor-dsc.c,v 1.2 2007/09/06 01:36:11 matsutsuka Exp $
|
||||
*
|
||||
*/
|
||||
|
||||
#include "sys/dsc.h"
|
||||
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
#if CTK_CONF_ICON_BITMAPS
|
||||
static unsigned char editoricon_bitmap[3*3*8] = {
|
||||
0x00, 0x7e, 0x40, 0x73, 0x46, 0x4c, 0x18, 0x13,
|
||||
0x00, 0x00, 0xff, 0x81, 0x34, 0xc9, 0x00, 0xb6,
|
||||
0x00, 0x7e, 0x02, 0xce, 0x72, 0x32, 0x18, 0x48,
|
||||
|
||||
0x30, 0x27, 0x24, 0x20, 0x37, 0x24, 0x20, 0x33,
|
||||
0x00, 0x7b, 0x42, 0x00, 0x7b, 0x42, 0x00, 0x3b,
|
||||
0x0c, 0x24, 0x24, 0x04, 0xa4, 0x24, 0x04, 0x4c,
|
||||
|
||||
0x12, 0x19, 0x4c, 0x46, 0x63, 0x40, 0x7c, 0x00,
|
||||
0x22, 0x91, 0x00, 0xc4, 0x81, 0xff, 0x00, 0x00,
|
||||
0x08, 0x18, 0x32, 0x62, 0xc6, 0x02, 0x3e, 0x00
|
||||
};
|
||||
#endif /* CTK_CONF_ICON_BITMAPS */
|
||||
|
||||
#if CTK_CONF_ICON_TEXTMAPS
|
||||
static char editoricon_textmap[9] = {
|
||||
't', 'x', 't',
|
||||
'e', 'd', 'i',
|
||||
't', 'o', 'r'
|
||||
};
|
||||
#endif /* CTK_CONF_ICON_TEXTMAPS */
|
||||
|
||||
#if CTK_CONF_ICONS
|
||||
static struct ctk_icon editor_icon =
|
||||
{CTK_ICON("Editor", editoricon_bitmap, editoricon_textmap)};
|
||||
#endif /* CTK_CONF_ICONS */
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
DSC(editor_dsc,
|
||||
"A simple text editor",
|
||||
"editor.prg",
|
||||
editor_process,
|
||||
&editor_icon);
|
||||
/*-----------------------------------------------------------------------------------*/
|
|
@ -1,42 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2004, Adam Dunkels.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. 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.
|
||||
* 3. The name of the author may not be used to endorse or promote
|
||||
* products derived from this software without specific prior
|
||||
* written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
||||
*
|
||||
* This file is part of the Contiki desktop environment
|
||||
*
|
||||
* $Id: editor-dsc.h,v 1.1 2007/05/23 23:34:33 oliverschmidt Exp $
|
||||
*
|
||||
*/
|
||||
#ifndef __EDITOR_DSC_H__
|
||||
#define __EDITOR_DSC_H__
|
||||
|
||||
#include "sys/dsc.h"
|
||||
|
||||
DSC_HEADER(editor_dsc);
|
||||
|
||||
#endif /* __EDITOR_DSC_H__ */
|
|
@ -1,338 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2004, Adam Dunkels.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. 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.
|
||||
* 3. Neither the name of the Institute 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 INSTITUTE 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 INSTITUTE 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.
|
||||
*
|
||||
* This file is part of the Contiki operating system.
|
||||
*
|
||||
* Author: Adam Dunkels <adam@sics.se>
|
||||
*
|
||||
* $Id: editor.c,v 1.1 2007/05/23 23:34:33 oliverschmidt Exp $
|
||||
*/
|
||||
#define EDITOR_CONF_WIDTH 32
|
||||
#define EDITOR_CONF_HEIGHT 16
|
||||
#define EDITOR_CONF_MAX_FILENAME_LEN 16
|
||||
|
||||
#include "contiki.h"
|
||||
#include "contiki-lib.h"
|
||||
#include "ctk/ctk.h"
|
||||
#include "cfs/cfs.h"
|
||||
|
||||
#include "lib/ctk-filedialog.h"
|
||||
|
||||
#define ISO_nl 0x0a
|
||||
|
||||
PROCESS(editor_process, "Editor");
|
||||
|
||||
static struct ctk_window window;
|
||||
|
||||
#define LINE_LEN 60
|
||||
#define NUM_LINES EDITOR_CONF_HEIGHT
|
||||
|
||||
struct line {
|
||||
struct line *next, *prev;
|
||||
char text[LINE_LEN];
|
||||
};
|
||||
MEMB(linesmem, struct line, NUM_LINES);
|
||||
|
||||
static struct line *lines;
|
||||
|
||||
static struct {
|
||||
unsigned char x, y;
|
||||
struct ctk_label labels[NUM_LINES];
|
||||
|
||||
} editor_state;
|
||||
|
||||
static struct ctk_button openbutton =
|
||||
{CTK_BUTTON(0, 0, 4, "Open")};
|
||||
static char statustext[EDITOR_CONF_WIDTH + 1];
|
||||
static struct ctk_label statuslabel =
|
||||
{CTK_LABEL(0, EDITOR_CONF_HEIGHT + 2, EDITOR_CONF_WIDTH, 1, statustext)};
|
||||
|
||||
static struct ctk_menu menu;
|
||||
static unsigned char menuitem_new, menuitem_open, menuitem_save;
|
||||
|
||||
static char filename[EDITOR_CONF_MAX_FILENAME_LEN];
|
||||
|
||||
|
||||
static struct ctk_filedialog_state filedialog;
|
||||
|
||||
enum {
|
||||
OPEN_EVENT
|
||||
};
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
show_statustext(char *text1, char *text2)
|
||||
{
|
||||
int len;
|
||||
|
||||
len = strlen(text1);
|
||||
if(len < sizeof(statustext)) {
|
||||
strncpy(statustext, text1, sizeof(statustext));
|
||||
strncpy(statustext + len, text2, sizeof(statustext) - len);
|
||||
CTK_WIDGET_REDRAW(&statuslabel);
|
||||
}
|
||||
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
editor_start(void)
|
||||
{
|
||||
unsigned char i;
|
||||
register struct ctk_label *label;
|
||||
struct line *l, *m;
|
||||
|
||||
m = NULL;
|
||||
|
||||
for(i = 0; i < NUM_LINES; ++i) {
|
||||
label = &editor_state.labels[i];
|
||||
l = (struct line *)memb_alloc(&linesmem);
|
||||
|
||||
if(l != NULL) {
|
||||
l->next = NULL;
|
||||
l->prev = m;
|
||||
if(m == NULL) {
|
||||
/* First line */
|
||||
lines = l;
|
||||
} else {
|
||||
m->next = l;
|
||||
}
|
||||
CTK_LABEL_NEW(label, 0, i + 1, EDITOR_CONF_WIDTH, 1, l->text);
|
||||
CTK_WIDGET_SET_FLAG(label, CTK_WIDGET_FLAG_MONOSPACE);
|
||||
CTK_WIDGET_ADD(&window, label);
|
||||
}
|
||||
m = l;
|
||||
}
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
editor_eventhandler(process_event_t ev, process_data_t data)
|
||||
{
|
||||
char *textptr, *textptr2;
|
||||
unsigned char len;
|
||||
|
||||
if(ev == ctk_signal_keypress) {
|
||||
/* CTK_WIDGET_FOCUS(t->label.window, &t->label);*/
|
||||
textptr = &(editor_state.labels[editor_state.y].text[editor_state.x]);
|
||||
*textptr &= 0x7f;
|
||||
CTK_WIDGET_REDRAW(&(editor_state.labels[editor_state.y]));
|
||||
|
||||
switch((ctk_arch_key_t)data) {
|
||||
case CH_CURS_DOWN:
|
||||
++editor_state.y;
|
||||
if(editor_state.y >= EDITOR_CONF_HEIGHT) {
|
||||
editor_state.y = EDITOR_CONF_HEIGHT - 1;
|
||||
}
|
||||
break;
|
||||
case CH_CURS_UP:
|
||||
if(editor_state.y > 0) {
|
||||
--editor_state.y;
|
||||
}
|
||||
break;
|
||||
case CH_CURS_RIGHT:
|
||||
if(editor_state.x < strlen(editor_state.labels[editor_state.y].text)) {
|
||||
++editor_state.x;
|
||||
}
|
||||
break;
|
||||
case CH_CURS_LEFT:
|
||||
if(editor_state.x > 0) {
|
||||
--editor_state.x;
|
||||
} else {
|
||||
if(editor_state.y > 0) {
|
||||
--editor_state.y;
|
||||
editor_state.x = strlen(editor_state.labels[editor_state.y].text);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case CH_ENTER:
|
||||
editor_state.x = 0;
|
||||
++editor_state.y;
|
||||
if(editor_state.y >= EDITOR_CONF_HEIGHT) {
|
||||
editor_state.y = EDITOR_CONF_HEIGHT - 1;
|
||||
}
|
||||
break;
|
||||
case CH_DEL:
|
||||
/* len = t->label.w - t->xpos;
|
||||
if(t->xpos > 0 && len > 0) {
|
||||
strncpy(textptr - 1, textptr,
|
||||
len);
|
||||
*(textptr + len - 1) = 0;
|
||||
--t->xpos;
|
||||
}*/
|
||||
break;
|
||||
default:
|
||||
len = EDITOR_CONF_WIDTH - editor_state.x;
|
||||
if(len > 0) {
|
||||
textptr2 = textptr + len - 1;
|
||||
while(textptr2 + 1 > textptr) {
|
||||
*(textptr2 + 1) = *textptr2;
|
||||
--textptr2;
|
||||
}
|
||||
|
||||
*textptr = (char)data;
|
||||
++editor_state.x;
|
||||
if(editor_state.x == EDITOR_CONF_WIDTH) {
|
||||
editor_state.x = 0;
|
||||
if(editor_state.y < EDITOR_CONF_HEIGHT - 1) {
|
||||
++editor_state.y;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
textptr = &(editor_state.labels[editor_state.y].text[editor_state.x]);
|
||||
*textptr |= 0x80;
|
||||
CTK_WIDGET_REDRAW(&(editor_state.labels[editor_state.y]));
|
||||
/* } else if(s == ctk_signal_widget_activate &&
|
||||
data == (process_data_t)t) {
|
||||
textptr = &(t->label.text[t->ypos * t->label.w + t->xpos]);
|
||||
*textptr &= 0x7f;
|
||||
t->xpos = 0;
|
||||
if(t->ypos < t->label.h - 1) {
|
||||
++t->ypos;
|
||||
}
|
||||
textptr = &(t->label.text[t->ypos * t->label.w + t->xpos]);
|
||||
*textptr |= 0x80;
|
||||
CTK_WIDGET_REDRAW(&t->label);*/
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
open_file(char *name)
|
||||
{
|
||||
int fd;
|
||||
struct line *l;
|
||||
char line[LINE_LEN];
|
||||
char *cptr;
|
||||
int i, len, clen;
|
||||
|
||||
fd = cfs_open(name, 0);
|
||||
if(fd < 0) {
|
||||
show_statustext("Could not open file ", name);
|
||||
return;
|
||||
}
|
||||
|
||||
l = lines;
|
||||
cptr = l->text;
|
||||
clen = LINE_LEN;
|
||||
|
||||
do {
|
||||
/* Read a portion of the input file */
|
||||
len = cfs_read(fd, line, LINE_LEN);
|
||||
|
||||
/* Split the input into lines. */
|
||||
for(i = 0; i < len; ++i) {
|
||||
if(line[i] == ISO_nl ||
|
||||
clen == 0) {
|
||||
*cptr = 0;
|
||||
l = l->next;
|
||||
if(l != NULL) {
|
||||
cptr = l->text;
|
||||
clen = LINE_LEN;
|
||||
} else {
|
||||
len = -1;
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
*cptr++ = line[i];
|
||||
--clen;
|
||||
}
|
||||
}
|
||||
} while(len > 0);
|
||||
|
||||
|
||||
cfs_close(fd);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
quit(void)
|
||||
{
|
||||
ctk_window_close(&window);
|
||||
process_exit(&editor_process);
|
||||
LOADER_UNLOAD();
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
PROCESS_THREAD(editor_process, ev, data)
|
||||
{
|
||||
|
||||
PROCESS_BEGIN();
|
||||
|
||||
memb_init(&linesmem);
|
||||
|
||||
ctk_window_new(&window,
|
||||
EDITOR_CONF_WIDTH + 2,
|
||||
EDITOR_CONF_HEIGHT + 3,
|
||||
"Editor");
|
||||
|
||||
CTK_WIDGET_ADD(&window, &openbutton);
|
||||
CTK_WIDGET_ADD(&window, &statuslabel);
|
||||
|
||||
CTK_WIDGET_FOCUS(&window, &openbutton);
|
||||
|
||||
editor_start();
|
||||
|
||||
ctk_window_open(&window);
|
||||
|
||||
while(1) {
|
||||
PROCESS_WAIT_EVENT();
|
||||
|
||||
if(ctk_filedialog_eventhandler(&filedialog, ev, data)) {
|
||||
|
||||
} else {
|
||||
if(ev == PROCESS_EVENT_EXIT) {
|
||||
quit();
|
||||
} else if(ev == OPEN_EVENT) {
|
||||
/* printf("Open file '%s'\n", (char *)data);*/
|
||||
open_file((char *)data);
|
||||
ctk_window_redraw(&window);
|
||||
} else {
|
||||
|
||||
if(ev == ctk_signal_window_close &&
|
||||
data == (process_data_t)&window) {
|
||||
quit();
|
||||
} else if(ev == ctk_signal_widget_activate) {
|
||||
if(data == (process_data_t)&openbutton) {
|
||||
ctk_filedialog_open(&filedialog, "Open", OPEN_EVENT);
|
||||
}
|
||||
} else {
|
||||
editor_eventhandler(ev, data);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
PROCESS_END();
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/*LOADER_INIT_FUNC(editor_init, arg)
|
||||
{
|
||||
arg_free(arg);
|
||||
id = ek_start(&p);
|
||||
}*/
|
||||
/*---------------------------------------------------------------------------*/
|
|
@ -1,193 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2004, Adam Dunkels.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. 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.
|
||||
* 3. Neither the name of the Institute 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 INSTITUTE 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 INSTITUTE 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.
|
||||
*
|
||||
* This file is part of the Contiki operating system.
|
||||
*
|
||||
* Author: Adam Dunkels <adam@sics.se>
|
||||
*
|
||||
* $Id: httpd-socket.c,v 1.2 2010/10/19 18:29:03 adamdunkels Exp $
|
||||
*/
|
||||
|
||||
#include "contiki.h"
|
||||
#include "cfs.h"
|
||||
#include "socket.h"
|
||||
|
||||
struct httpd_state {
|
||||
struct socket sin, sout;
|
||||
char inputbuf[100];
|
||||
char filename[40];
|
||||
char state;
|
||||
int fd;
|
||||
int ret;
|
||||
char outputbuf[UIP_TCP_MSS];
|
||||
};
|
||||
|
||||
#define STATE_WAITING 0
|
||||
#define STATE_OUTPUT 1
|
||||
|
||||
#define SEND_STRING(s, str) SOCKET_SEND(s, str, strlen(str))
|
||||
MEMB(conns, struct httpd_state, 8);
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static unsigned short
|
||||
generate(void *state)
|
||||
{
|
||||
struct httpd_state *s = (struct httpd_state *)state;
|
||||
|
||||
memcpy(uip_appdata, s->outputbuf, s->ret);
|
||||
|
||||
return s->ret;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static
|
||||
PT_THREAD(handle_output(struct httpd_state *s))
|
||||
{
|
||||
char *ptr;
|
||||
|
||||
SOCKET_BEGIN(&s->sout);
|
||||
|
||||
|
||||
s->fd = cfs_open(s->filename, CFS_READ);
|
||||
if(s->fd < 0) {
|
||||
SEND_STRING(&s->sout, "HTTP/1.0 404 Not found\r\n");
|
||||
SOCKET_CLOSE_EXIT(&s->sout);
|
||||
} else {
|
||||
SEND_STRING(&s->sout, "HTTP/1.0 200 Found\r\n");
|
||||
}
|
||||
ptr = strrchr(s->filename, '.');
|
||||
if(strncmp(".html", ptr, 5) == 0) {
|
||||
SEND_STRING(&s->sout, "Content-type: text/html\r\n");
|
||||
} else if(strncmp(".css", ptr, 4) == 0) {
|
||||
SEND_STRING(&s->sout, "Content-type: text/css\r\n");
|
||||
} else if(strncmp(".png", ptr, 4) == 0) {
|
||||
SEND_STRING(&s->sout, "Content-type: image/png\r\n");
|
||||
} else if(strncmp(".jpg", ptr, 4) == 0) {
|
||||
SEND_STRING(&s->sout, "Content-type: image/jpeg\r\n");
|
||||
} else {
|
||||
SEND_STRING(&s->sout, "Content-type: text/plain\r\n");
|
||||
}
|
||||
SEND_STRING(&s->sout, "Server: Contiki/1.2-devel0\r\n\r\n");
|
||||
|
||||
do {
|
||||
s->ret = cfs_read(s->fd, s->outputbuf, sizeof(s->outputbuf));
|
||||
if(s->ret > 0) {
|
||||
SOCKET_GENERATE_SEND(&s->sout, generate, s);
|
||||
/* SOCKET_SEND(&s->sout, s->outputbuf, s->ret);*/
|
||||
}
|
||||
} while(s->ret > 0);
|
||||
|
||||
|
||||
cfs_close(s->filename);
|
||||
SOCKET_CLOSE(&s->sout);
|
||||
|
||||
SOCKET_END(&s->sout);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static
|
||||
PT_THREAD(handle_input(struct httpd_state *s))
|
||||
{
|
||||
SOCKET_BEGIN(&s->sin);
|
||||
|
||||
SOCKET_READTO(&s->sin, ' ');
|
||||
|
||||
|
||||
if(strncmp(s->inputbuf, "GET ", 4) != 0) {
|
||||
SOCKET_CLOSE_EXIT(&s->sin);
|
||||
}
|
||||
SOCKET_READTO(&s->sin, ' ');
|
||||
|
||||
if(s->inputbuf[0] != '/') {
|
||||
SOCKET_CLOSE_EXIT(&s->sin);
|
||||
}
|
||||
|
||||
if(s->inputbuf[1] == ' ') {
|
||||
strncpy(s->filename, "index.html", sizeof(s->filename));
|
||||
} else {
|
||||
s->inputbuf[SOCKET_DATALEN(&s->sin) - 1] = 0;
|
||||
strncpy(s->filename, &s->inputbuf[1], sizeof(s->filename));
|
||||
}
|
||||
|
||||
s->state = STATE_OUTPUT;
|
||||
|
||||
while(1) {
|
||||
SOCKET_READTO(&s->sin, '\n');
|
||||
|
||||
if(strncmp(s->inputbuf, "Referer:", 8) == 0) {
|
||||
s->inputbuf[SOCKET_DATALEN(&s->sin) - 2] = 0;
|
||||
webserver_log(&s->inputbuf[9]);
|
||||
}
|
||||
}
|
||||
|
||||
SOCKET_END(&s->sin);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
handle_connection(struct httpd_state *s)
|
||||
{
|
||||
handle_input(s);
|
||||
if(s->state == STATE_OUTPUT) {
|
||||
handle_output(s);
|
||||
}
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void
|
||||
httpd_appcall(void *state)
|
||||
{
|
||||
struct httpd_state *s = (struct httpd_state *)state;
|
||||
|
||||
|
||||
if(uip_closed() || uip_aborted() || uip_timedout()) {
|
||||
if(s != NULL) {
|
||||
memb_free(&conns, s);
|
||||
}
|
||||
} else if(uip_connected()) {
|
||||
s = (struct httpd_state *)memb_alloc(&conns);
|
||||
if(s == NULL) {
|
||||
uip_abort();
|
||||
return;
|
||||
}
|
||||
tcp_markconn(uip_conn, s);
|
||||
SOCKET_INIT(&s->sin, s->inputbuf, sizeof(s->inputbuf) - 1);
|
||||
SOCKET_INIT(&s->sout, s->inputbuf, sizeof(s->inputbuf) - 1);
|
||||
s->state = STATE_WAITING;
|
||||
handle_connection(s);
|
||||
} else if(s != NULL) {
|
||||
handle_connection(s);
|
||||
} else {
|
||||
uip_abort();
|
||||
}
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void
|
||||
httpd_init(void)
|
||||
{
|
||||
tcp_listen(UIP_HTONS(80));
|
||||
memb_init(&conns);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
|
@ -1,569 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2002, Adam Dunkels.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. 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.
|
||||
* 3. The name of the author may not be used to endorse or promote
|
||||
* products derived from this software without specific prior
|
||||
* written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
||||
*
|
||||
* This file is part of the "ctk" console GUI toolkit for cc65
|
||||
*
|
||||
* $Id: ctk-conio-service.c,v 1.1 2007/05/23 23:19:10 oliverschmidt Exp $
|
||||
*
|
||||
*/
|
||||
|
||||
#include <conio.h>
|
||||
|
||||
#include "ctk/ctk.h"
|
||||
#include "ctk/ctk-draw.h"
|
||||
|
||||
#include "ctk/ctk-draw-service.h"
|
||||
|
||||
#include "contiki-conf.h"
|
||||
#include <string.h>
|
||||
|
||||
#ifndef NULL
|
||||
#define NULL (void *)0
|
||||
#endif /* NULL */
|
||||
|
||||
static unsigned char sizex, sizey;
|
||||
|
||||
/*unsigned char ctk_draw_windowborder_height = 1;
|
||||
unsigned char ctk_draw_windowborder_width = 1;
|
||||
unsigned char ctk_draw_windowtitle_height = 1;*/
|
||||
|
||||
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
static void
|
||||
cputsn(char *str, unsigned char len)
|
||||
{
|
||||
char c;
|
||||
|
||||
while(len > 0) {
|
||||
--len;
|
||||
c = *str;
|
||||
if(c == 0) {
|
||||
break;
|
||||
}
|
||||
cputc(c);
|
||||
++str;
|
||||
}
|
||||
}
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
static void
|
||||
s_ctk_draw_init(void)
|
||||
{
|
||||
(void)bgcolor(SCREENCOLOR);
|
||||
(void)bordercolor(BORDERCOLOR);
|
||||
screensize(&sizex, &sizey);
|
||||
ctk_draw_clear(0, sizey);
|
||||
}
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
static void
|
||||
draw_widget(struct ctk_widget *w,
|
||||
unsigned char x, unsigned char y,
|
||||
unsigned char clipx,
|
||||
unsigned char clipy,
|
||||
unsigned char clipy1, unsigned char clipy2,
|
||||
unsigned char focus)
|
||||
{
|
||||
unsigned char xpos, ypos, xscroll;
|
||||
unsigned char i, j;
|
||||
char c, *text;
|
||||
unsigned char len, wfocus;
|
||||
|
||||
wfocus = 0;
|
||||
if(focus & CTK_FOCUS_WINDOW) {
|
||||
(void)textcolor(WIDGETCOLOR_FWIN);
|
||||
if(focus & CTK_FOCUS_WIDGET) {
|
||||
(void)textcolor(WIDGETCOLOR_FOCUS);
|
||||
wfocus = 1;
|
||||
}
|
||||
} else if(focus & CTK_FOCUS_DIALOG) {
|
||||
(void)textcolor(WIDGETCOLOR_DIALOG);
|
||||
if(focus & CTK_FOCUS_WIDGET) {
|
||||
(void)textcolor(WIDGETCOLOR_FOCUS);
|
||||
wfocus = 1;
|
||||
}
|
||||
} else {
|
||||
(void)textcolor(WIDGETCOLOR);
|
||||
}
|
||||
|
||||
xpos = x + w->x;
|
||||
ypos = y + w->y;
|
||||
|
||||
switch(w->type) {
|
||||
case CTK_WIDGET_SEPARATOR:
|
||||
if(ypos >= clipy1 && ypos < clipy2) {
|
||||
chlinexy(xpos, ypos, w->w);
|
||||
}
|
||||
break;
|
||||
case CTK_WIDGET_LABEL:
|
||||
text = w->widget.label.text;
|
||||
for(i = 0; i < w->h; ++i) {
|
||||
if(ypos >= clipy1 && ypos < clipy2) {
|
||||
gotoxy(xpos, ypos);
|
||||
cputsn(text, w->w);
|
||||
if(w->w - (wherex() - xpos) > 0) {
|
||||
cclear(w->w - (wherex() - xpos));
|
||||
}
|
||||
}
|
||||
++ypos;
|
||||
text += w->w;
|
||||
}
|
||||
break;
|
||||
case CTK_WIDGET_BUTTON:
|
||||
if(ypos >= clipy1 && ypos < clipy2) {
|
||||
revers(wfocus != 0);
|
||||
cputcxy(xpos, ypos, '[');
|
||||
cputsn(w->widget.button.text, w->w);
|
||||
cputc(']');
|
||||
revers(0);
|
||||
}
|
||||
break;
|
||||
case CTK_WIDGET_HYPERLINK:
|
||||
if(ypos >= clipy1 && ypos < clipy2) {
|
||||
revers(wfocus == 0);
|
||||
gotoxy(xpos, ypos);
|
||||
(void)textcolor(WIDGETCOLOR_HLINK);
|
||||
cputsn(w->widget.button.text, w->w);
|
||||
revers(0);
|
||||
}
|
||||
break;
|
||||
case CTK_WIDGET_TEXTENTRY:
|
||||
text = w->widget.textentry.text;
|
||||
xscroll = 0;
|
||||
if(w->widget.textentry.xpos >= w->w - 1) {
|
||||
xscroll = w->widget.textentry.xpos - w->w + 1;
|
||||
}
|
||||
for(j = 0; j < w->h; ++j) {
|
||||
if(ypos >= clipy1 && ypos < clipy2) {
|
||||
if(w->widget.textentry.state == CTK_TEXTENTRY_EDIT &&
|
||||
w->widget.textentry.ypos == j) {
|
||||
revers(0);
|
||||
cputcxy(xpos, ypos, '>');
|
||||
c = 1;
|
||||
for(i = 0; i < w->w; ++i) {
|
||||
if(c != 0) {
|
||||
c = text[i + xscroll];
|
||||
}
|
||||
revers(i == w->widget.textentry.xpos - xscroll);
|
||||
if(c == 0) {
|
||||
cputc(' ');
|
||||
} else {
|
||||
cputc(c);
|
||||
}
|
||||
}
|
||||
revers(0);
|
||||
cputc('<');
|
||||
} else {
|
||||
revers(wfocus != 0 && j == w->widget.textentry.ypos);
|
||||
cvlinexy(xpos, ypos, 1);
|
||||
gotoxy(xpos + 1, ypos);
|
||||
cputsn(text, w->w);
|
||||
i = wherex();
|
||||
if(i - xpos - 1 < w->w) {
|
||||
cclear(w->w - (i - xpos) + 1);
|
||||
}
|
||||
cvline(1);
|
||||
}
|
||||
}
|
||||
++ypos;
|
||||
text += w->widget.textentry.len + 1;
|
||||
}
|
||||
revers(0);
|
||||
break;
|
||||
case CTK_WIDGET_ICON:
|
||||
if(ypos >= clipy1 && ypos < clipy2) {
|
||||
revers(wfocus != 0);
|
||||
gotoxy(xpos, ypos);
|
||||
if(w->widget.icon.textmap != NULL) {
|
||||
for(i = 0; i < 3; ++i) {
|
||||
gotoxy(xpos, ypos);
|
||||
if(ypos >= clipy1 && ypos < clipy2) {
|
||||
cputc(w->widget.icon.textmap[0 + 3 * i]);
|
||||
cputc(w->widget.icon.textmap[1 + 3 * i]);
|
||||
cputc(w->widget.icon.textmap[2 + 3 * i]);
|
||||
}
|
||||
++ypos;
|
||||
}
|
||||
}
|
||||
x = xpos;
|
||||
|
||||
len = (unsigned char)strlen(w->widget.icon.title);
|
||||
if(x + len >= sizex) {
|
||||
x = sizex - len;
|
||||
}
|
||||
|
||||
gotoxy(x, ypos);
|
||||
if(ypos >= clipy1 && ypos < clipy2) {
|
||||
cputs(w->widget.icon.title);
|
||||
}
|
||||
revers(0);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
static void
|
||||
s_ctk_draw_widget(struct ctk_widget *w,
|
||||
unsigned char focus,
|
||||
unsigned char clipy1,
|
||||
unsigned char clipy2)
|
||||
{
|
||||
struct ctk_window *win = w->window;
|
||||
unsigned char posx, posy;
|
||||
|
||||
posx = win->x + 1;
|
||||
posy = win->y + 2;
|
||||
|
||||
if(w == win->focused) {
|
||||
focus |= CTK_FOCUS_WIDGET;
|
||||
}
|
||||
|
||||
draw_widget(w, posx, posy,
|
||||
posx + win->w,
|
||||
posy + win->h,
|
||||
clipy1, clipy2,
|
||||
focus);
|
||||
|
||||
#ifdef CTK_CONIO_CONF_UPDATE
|
||||
CTK_CONIO_CONF_UPDATE();
|
||||
#endif /* CTK_CONIO_CONF_UPDATE */
|
||||
}
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
static void
|
||||
s_ctk_draw_clear_window(struct ctk_window *window,
|
||||
unsigned char focus,
|
||||
unsigned char clipy1,
|
||||
unsigned char clipy2)
|
||||
{
|
||||
unsigned char i;
|
||||
unsigned char h;
|
||||
|
||||
if(focus & CTK_FOCUS_WINDOW) {
|
||||
(void)textcolor(WINDOWCOLOR_FOCUS);
|
||||
} else {
|
||||
(void)textcolor(WINDOWCOLOR);
|
||||
}
|
||||
|
||||
h = window->y + 2 + window->h;
|
||||
|
||||
/* Clear window contents. */
|
||||
for(i = window->y + 2; i < h; ++i) {
|
||||
if(i >= clipy1 && i < clipy2) {
|
||||
cclearxy(window->x + 1, i, window->w);
|
||||
}
|
||||
}
|
||||
}
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
static void
|
||||
draw_window_contents(struct ctk_window *window, unsigned char focus,
|
||||
unsigned char clipy1, unsigned char clipy2,
|
||||
unsigned char x1, unsigned char x2,
|
||||
unsigned char y1, unsigned char y2)
|
||||
{
|
||||
struct ctk_widget *w;
|
||||
unsigned char wfocus;
|
||||
|
||||
/* Draw inactive widgets. */
|
||||
for(w = window->inactive; w != NULL; w = w->next) {
|
||||
draw_widget(w, x1, y1, x2, y2,
|
||||
clipy1, clipy2,
|
||||
focus);
|
||||
}
|
||||
|
||||
/* Draw active widgets. */
|
||||
for(w = window->active; w != NULL; w = w->next) {
|
||||
wfocus = focus;
|
||||
if(w == window->focused) {
|
||||
wfocus |= CTK_FOCUS_WIDGET;
|
||||
}
|
||||
|
||||
draw_widget(w, x1, y1, x2, y2,
|
||||
clipy1, clipy2,
|
||||
wfocus);
|
||||
}
|
||||
|
||||
#ifdef CTK_CONIO_CONF_UPDATE
|
||||
CTK_CONIO_CONF_UPDATE();
|
||||
#endif /* CTK_CONIO_CONF_UPDATE */
|
||||
}
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
static void
|
||||
s_ctk_draw_window(struct ctk_window *window, unsigned char focus,
|
||||
unsigned char clipy1, unsigned char clipy2,
|
||||
unsigned char draw_borders)
|
||||
{
|
||||
unsigned char x, y;
|
||||
unsigned char h;
|
||||
unsigned char x1, y1, x2, y2;
|
||||
|
||||
if(window->y + 1 >= clipy2) {
|
||||
return;
|
||||
}
|
||||
|
||||
x = window->x;
|
||||
y = window->y + 1;
|
||||
x1 = x + 1;
|
||||
y1 = y + 1;
|
||||
x2 = x1 + window->w;
|
||||
y2 = y1 + window->h;
|
||||
|
||||
if(draw_borders) {
|
||||
|
||||
/* Draw window frame. */
|
||||
if(focus & CTK_FOCUS_WINDOW) {
|
||||
(void)textcolor(WINDOWCOLOR_FOCUS);
|
||||
} else {
|
||||
(void)textcolor(WINDOWCOLOR);
|
||||
}
|
||||
|
||||
if(y >= clipy1) {
|
||||
cputcxy(x, y, CH_ULCORNER);
|
||||
gotoxy(wherex() + window->titlelen + CTK_CONF_WINDOWMOVE * 2, wherey());
|
||||
chline(window->w - (wherex() - x) - 2);
|
||||
cputcxy(x2, y, CH_URCORNER);
|
||||
}
|
||||
|
||||
h = window->h;
|
||||
|
||||
if(clipy1 > y1) {
|
||||
if(clipy1 - y1 < h) {
|
||||
h = clipy1 - y1;
|
||||
y1 = clipy1;
|
||||
} else {
|
||||
h = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if(clipy2 < y1 + h) {
|
||||
if(y1 >= clipy2) {
|
||||
h = 0;
|
||||
} else {
|
||||
h = clipy2 - y1;
|
||||
}
|
||||
}
|
||||
|
||||
cvlinexy(x, y1, h);
|
||||
cvlinexy(x2, y1, h);
|
||||
|
||||
if(y + window->h >= clipy1 &&
|
||||
y + window->h < clipy2) {
|
||||
cputcxy(x, y2, CH_LLCORNER);
|
||||
chlinexy(x1, y2, window->w);
|
||||
cputcxy(x2, y2, CH_LRCORNER);
|
||||
}
|
||||
}
|
||||
|
||||
draw_window_contents(window, focus, clipy1, clipy2,
|
||||
x1, x2, y + 1, y2);
|
||||
}
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
static void
|
||||
s_ctk_draw_dialog(struct ctk_window *dialog)
|
||||
{
|
||||
unsigned char x, y;
|
||||
unsigned char i;
|
||||
unsigned char x1, y1, x2, y2;
|
||||
|
||||
(void)textcolor(DIALOGCOLOR);
|
||||
|
||||
x = dialog->x;
|
||||
y = dialog->y + 1;
|
||||
|
||||
x1 = x + 1;
|
||||
y1 = y + 1;
|
||||
x2 = x1 + dialog->w;
|
||||
y2 = y1 + dialog->h;
|
||||
|
||||
/* Draw dialog frame. */
|
||||
cvlinexy(x, y1,
|
||||
dialog->h);
|
||||
cvlinexy(x2, y1,
|
||||
dialog->h);
|
||||
|
||||
chlinexy(x1, y,
|
||||
dialog->w);
|
||||
chlinexy(x1, y2,
|
||||
dialog->w);
|
||||
|
||||
cputcxy(x, y, CH_ULCORNER);
|
||||
cputcxy(x, y2, CH_LLCORNER);
|
||||
cputcxy(x2, y, CH_URCORNER);
|
||||
cputcxy(x2, y2, CH_LRCORNER);
|
||||
|
||||
/* Clear dialog contents. */
|
||||
for(i = y1; i < y2; ++i) {
|
||||
cclearxy(x1, i, dialog->w);
|
||||
}
|
||||
|
||||
draw_window_contents(dialog, CTK_FOCUS_DIALOG, 0, sizey,
|
||||
x1, x2, y1, y2);
|
||||
}
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
static void
|
||||
s_ctk_draw_clear(unsigned char y1, unsigned char y2)
|
||||
{
|
||||
unsigned char i;
|
||||
|
||||
(void)textcolor(BACKGROUNDCOLOR);
|
||||
for(i = y1; i < y2; ++i) {
|
||||
cclearxy(0, i, sizex);
|
||||
}
|
||||
}
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
static void
|
||||
draw_menu(struct ctk_menu *m, unsigned char open)
|
||||
{
|
||||
unsigned char x, x2, y;
|
||||
|
||||
if(open) {
|
||||
x = x2 = wherex();
|
||||
if(x2 + CTK_CONF_MENUWIDTH > sizex) {
|
||||
x2 = sizex - CTK_CONF_MENUWIDTH;
|
||||
}
|
||||
|
||||
for(y = 0; y < m->nitems; ++y) {
|
||||
if(y == m->active) {
|
||||
(void)textcolor(ACTIVEMENUITEMCOLOR);
|
||||
revers(0);
|
||||
} else {
|
||||
(void)textcolor(MENUCOLOR);
|
||||
revers(1);
|
||||
}
|
||||
gotoxy(x2, y + 1);
|
||||
if(m->items[y].title[0] == '-') {
|
||||
chline(CTK_CONF_MENUWIDTH);
|
||||
} else {
|
||||
cputs(m->items[y].title);
|
||||
}
|
||||
if(x2 + CTK_CONF_MENUWIDTH > wherex()) {
|
||||
cclear(x2 + CTK_CONF_MENUWIDTH - wherex());
|
||||
}
|
||||
}
|
||||
|
||||
gotoxy(x, 0);
|
||||
(void)textcolor(OPENMENUCOLOR);
|
||||
revers(0);
|
||||
}
|
||||
|
||||
cputs(m->title);
|
||||
cputc(' ');
|
||||
(void)textcolor(MENUCOLOR);
|
||||
revers(1);
|
||||
}
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
static void
|
||||
s_ctk_draw_menus(struct ctk_menus *menus)
|
||||
{
|
||||
struct ctk_menu *m;
|
||||
|
||||
/* Draw menus */
|
||||
(void)textcolor(MENUCOLOR);
|
||||
gotoxy(0, 0);
|
||||
revers(1);
|
||||
cputc(' ');
|
||||
for(m = menus->menus->next; m != NULL; m = m->next) {
|
||||
draw_menu(m, m == menus->open);
|
||||
}
|
||||
|
||||
/* Draw desktopmenu */
|
||||
if(wherex() + strlen(menus->desktopmenu->title) + 1 >= sizex) {
|
||||
gotoxy(sizex - (unsigned char)strlen(menus->desktopmenu->title) - 1, 0);
|
||||
} else {
|
||||
cclear(sizex - wherex() -
|
||||
(unsigned char)strlen(menus->desktopmenu->title) - 1);
|
||||
}
|
||||
draw_menu(menus->desktopmenu, menus->desktopmenu == menus->open);
|
||||
|
||||
revers(0);
|
||||
}
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
static unsigned char
|
||||
s_ctk_draw_height(void)
|
||||
{
|
||||
return sizey;
|
||||
}
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
static unsigned char
|
||||
s_ctk_draw_width(void)
|
||||
{
|
||||
return sizex;
|
||||
}
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
static unsigned short
|
||||
s_ctk_mouse_xtoc(unsigned short x)
|
||||
{
|
||||
return x / 8;
|
||||
}
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
static unsigned short
|
||||
s_ctk_mouse_ytoc(unsigned short y)
|
||||
{
|
||||
return y / 8;
|
||||
}
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
|
||||
SERVICE(ctk_conio_service, ctk_draw_service,
|
||||
{ 1,
|
||||
1,
|
||||
1,
|
||||
s_ctk_draw_init,
|
||||
s_ctk_draw_clear,
|
||||
s_ctk_draw_clear_window,
|
||||
s_ctk_draw_window,
|
||||
s_ctk_draw_dialog,
|
||||
s_ctk_draw_widget,
|
||||
s_ctk_draw_menus,
|
||||
s_ctk_draw_width,
|
||||
s_ctk_draw_height,
|
||||
s_ctk_mouse_xtoc,
|
||||
s_ctk_mouse_ytoc });
|
||||
|
||||
/*--------------------------------------------------------------------------*/
|
||||
|
||||
PROCESS(ctk_conio_service_process, "CTK CONIO service");
|
||||
|
||||
PROCESS_THREAD(ctk_conio_service_process, ev, data) {
|
||||
PROCESS_BEGIN();
|
||||
|
||||
s_ctk_draw_init();
|
||||
ctk_restore();
|
||||
|
||||
SERVICE_REGISTER(ctk_conio_service);
|
||||
|
||||
while(ev != PROCESS_EVENT_SERVICE_REMOVED &&
|
||||
ev != PROCESS_EVENT_EXIT) {
|
||||
PROCESS_WAIT_EVENT();
|
||||
}
|
||||
|
||||
SERVICE_REMOVE(ctk_conio_service);
|
||||
|
||||
PROCESS_END();
|
||||
}
|
||||
/*--------------------------------------------------------------------------*/
|
|
@ -1,42 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2006, Swedish Institute of Computer Science.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. 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.
|
||||
* 3. Neither the name of the Institute 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 INSTITUTE 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 INSTITUTE 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.
|
||||
*
|
||||
* This file is part of the Contiki operating system.
|
||||
*
|
||||
* Author: Oliver Schmidt <ol.sc@web.de>
|
||||
*
|
||||
* $Id: ctk-conio-service.h,v 1.1 2007/05/23 23:19:13 oliverschmidt Exp $
|
||||
*/
|
||||
#ifndef __CTK_CONIO_SERVICE_H__
|
||||
#define __CTK_CONIO_SERVICE_H__
|
||||
|
||||
#include "contiki.h"
|
||||
|
||||
PROCESS_NAME(ctk_conio_service_process);
|
||||
|
||||
#endif /* __CTK_CONIO_SERVICE_H__ */
|
|
@ -1,73 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2004, Adam Dunkels.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. 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.
|
||||
* 3. Neither the name of the Institute 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 INSTITUTE 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 INSTITUTE 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.
|
||||
*
|
||||
* This file is part of the Contiki operating system.
|
||||
*
|
||||
* Author: Adam Dunkels <adam@sics.se>
|
||||
*
|
||||
* $Id: ctk-draw-service.h,v 1.1 2007/05/23 23:19:13 oliverschmidt Exp $
|
||||
*/
|
||||
#ifndef __CTK_DRAW_SERVICE_H__
|
||||
#define __CTK_DRAW_SERVICE_H__
|
||||
|
||||
|
||||
#include "ctk/ctk.h"
|
||||
#include "sys/service.h"
|
||||
|
||||
#define ctk_draw_service_name "CTK driver"
|
||||
SERVICE_INTERFACE(ctk_draw_service, {
|
||||
unsigned char windowborder_width;
|
||||
unsigned char windowborder_height;
|
||||
unsigned char windowtitle_height;
|
||||
|
||||
void (* draw_init)(void);
|
||||
void (* draw_clear)(unsigned char clipy1, unsigned char clipy2);
|
||||
void (* draw_clear_window)(struct ctk_window *window,
|
||||
unsigned char focus,
|
||||
unsigned char clipy1,
|
||||
unsigned char clipy2);
|
||||
void (* draw_window)(struct ctk_window *window,
|
||||
unsigned char focus,
|
||||
unsigned char clipy1,
|
||||
unsigned char clipy2,
|
||||
unsigned char draw_borders);
|
||||
void (* draw_dialog)(struct ctk_window *dialog);
|
||||
void (* draw_widget)(struct ctk_widget *widget,
|
||||
unsigned char focus,
|
||||
unsigned char clipy1,
|
||||
unsigned char clipy2);
|
||||
void (* draw_menus)(struct ctk_menus *menus);
|
||||
|
||||
unsigned char (* width)(void);
|
||||
unsigned char (* height)(void);
|
||||
|
||||
unsigned short (* mouse_xtoc)(unsigned short);
|
||||
unsigned short (* mouse_ytoc)(unsigned short);
|
||||
});
|
||||
|
||||
#endif /* __CTK_DRAW_SERVICE_H__ */
|
|
@ -1,173 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2004, Adam Dunkels.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. 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.
|
||||
* 3. Neither the name of the Institute 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 INSTITUTE 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 INSTITUTE 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.
|
||||
*
|
||||
* This file is part of the Contiki operating system.
|
||||
*
|
||||
* Author: Adam Dunkels <adam@sics.se>
|
||||
*
|
||||
* $Id: ctk-draw.c,v 1.1 2007/05/23 23:19:13 oliverschmidt Exp $
|
||||
*/
|
||||
|
||||
|
||||
#include "ctk/ctk-draw.h"
|
||||
#include "ctk/ctk.h"
|
||||
|
||||
#include "ctk/ctk-draw-service.h"
|
||||
|
||||
|
||||
unsigned char ctk_draw_windowborder_width = 1,
|
||||
ctk_draw_windowborder_height = 1,
|
||||
ctk_draw_windowtitle_height = 1;
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void
|
||||
ctk_draw_init(void)
|
||||
{
|
||||
const struct ctk_draw_service *i;
|
||||
struct service *s;
|
||||
|
||||
s = SERVICE_FIND(ctk_draw_service);
|
||||
|
||||
if(s != NULL) {
|
||||
i = s->interface;
|
||||
|
||||
i->draw_init();
|
||||
ctk_draw_windowborder_width = i->windowborder_width;
|
||||
ctk_draw_windowborder_height = i->windowborder_height;
|
||||
ctk_draw_windowtitle_height = i->windowtitle_height;
|
||||
}
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void
|
||||
ctk_draw_clear(unsigned char clipy1, unsigned char clipy2)
|
||||
{
|
||||
SERVICE_CALL(ctk_draw_service, draw_clear(clipy1, clipy2));
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void
|
||||
ctk_draw_clear_window(struct ctk_window *window,
|
||||
unsigned char focus,
|
||||
unsigned char clipy1,
|
||||
unsigned char clipy2)
|
||||
{
|
||||
SERVICE_CALL(ctk_draw_service, draw_clear_window(window, focus,
|
||||
clipy1, clipy2));
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void
|
||||
ctk_draw_window(struct ctk_window *window,
|
||||
unsigned char focus,
|
||||
unsigned char clipy1,
|
||||
unsigned char clipy2,
|
||||
unsigned char draw_borders)
|
||||
{
|
||||
SERVICE_CALL(ctk_draw_service, draw_window(window, focus,
|
||||
clipy1, clipy2, draw_borders));
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void
|
||||
ctk_draw_dialog(struct ctk_window *dialog)
|
||||
{
|
||||
SERVICE_CALL(ctk_draw_service, draw_dialog(dialog));
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void
|
||||
ctk_draw_widget(struct ctk_widget *widget,
|
||||
unsigned char focus,
|
||||
unsigned char clipy1,
|
||||
unsigned char clipy2)
|
||||
{
|
||||
SERVICE_CALL(ctk_draw_service, draw_widget(widget, focus,
|
||||
clipy1, clipy2));
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void
|
||||
ctk_draw_menus(struct ctk_menus *menus)
|
||||
{
|
||||
SERVICE_CALL(ctk_draw_service, draw_menus(menus));
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
unsigned char
|
||||
ctk_draw_width(void)
|
||||
{
|
||||
struct service *s;
|
||||
|
||||
s = SERVICE_FIND(ctk_draw_service);
|
||||
if(s != NULL) {
|
||||
return ((struct ctk_draw_service *)s->interface)->width();
|
||||
}
|
||||
|
||||
return 40;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
unsigned char
|
||||
ctk_draw_height(void)
|
||||
{
|
||||
struct service *s;
|
||||
|
||||
s = SERVICE_FIND(ctk_draw_service);
|
||||
if(s != NULL) {
|
||||
return ((struct ctk_draw_service *)s->interface)->height();
|
||||
}
|
||||
|
||||
return 24;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
unsigned short
|
||||
ctk_mouse_xtoc(unsigned short x)
|
||||
{
|
||||
struct service *s;
|
||||
|
||||
s = SERVICE_FIND(ctk_draw_service);
|
||||
if(s != NULL) {
|
||||
return ((struct ctk_draw_service *)s->interface)->mouse_xtoc(x);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
unsigned short
|
||||
ctk_mouse_ytoc(unsigned short y)
|
||||
{
|
||||
struct service *s;
|
||||
|
||||
s = SERVICE_FIND(ctk_draw_service);
|
||||
if(s != NULL) {
|
||||
return ((struct ctk_draw_service *)s->interface)->mouse_ytoc(y);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void
|
||||
ctk_draw_quit(void)
|
||||
{
|
||||
/* process_post(service.id, EK_EVENT_REQUEST_EXIT, NULL);*/
|
||||
/* process_service_reset(&service); */
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
|
@ -1,96 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2004, Adam Dunkels.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. 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.
|
||||
* 3. Neither the name of the Institute 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 INSTITUTE 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 INSTITUTE 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.
|
||||
*
|
||||
* This file is part of the Contiki operating system.
|
||||
*
|
||||
* Author: Adam Dunkels <adam@sics.se>
|
||||
*
|
||||
* $Id: ctk-graphic-draw.h,v 1.1 2007/05/23 23:19:13 oliverschmidt Exp $
|
||||
*/
|
||||
#ifndef __CTK_GRAPHIC_DRAW_H__
|
||||
#define __CTK_GRAPHIC_DRAW_H__
|
||||
|
||||
enum {
|
||||
CTK_GRAPHIC_DRAW_FONT_NORMAL,
|
||||
CTK_GRAPHIC_DRAW_FONT_BOLD,
|
||||
CTK_GRAPHIC_DRAW_FONT_MENU,
|
||||
CTK_GRAPHIC_DRAW_FONT_MONOSPACE,
|
||||
CTK_GRAPHIC_DRAW_FONT_MONOSPACE_BOLD,
|
||||
};
|
||||
|
||||
enum {
|
||||
CTK_GRAPHIC_DRAW_COLOR_WHITE,
|
||||
CTK_GRAPHIC_DRAW_COLOR_LIGHTGRAY,
|
||||
CTK_GRAPHIC_DRAW_COLOR_MIDGRAY,
|
||||
CTK_GRAPHIC_DRAW_COLOR_DARKGRAY,
|
||||
CTK_GRAPHIC_DRAW_COLOR_BLACK,
|
||||
CTK_GRAPHIC_DRAW_COLOR_BLUE,
|
||||
}
|
||||
|
||||
/*struct ctk_graphic_draw_font;
|
||||
|
||||
extern struct ctk_graphic_draw_font ctk_graphic_draw_font_normal,
|
||||
ctk_graphic_draw_font_bold,
|
||||
ctk_graphic_draw_font_menu,
|
||||
ctk_graphic_draw_font_monospace,
|
||||
ctk_graphic_draw_font_monospace_bold;
|
||||
|
||||
struct ctk_graphic_draw_color;
|
||||
|
||||
extern struct ctk_graphic_draw_color ctk_graphic_draw_color_white,
|
||||
ctk_graphic_draw_color_lightgray,
|
||||
ctk_graphic_draw_color_midgray,
|
||||
ctk_graphic_draw_color_darkgray,
|
||||
ctk_graphic_draw_color_ddarkgray,
|
||||
ctk_graphic_draw_color_black,
|
||||
ctk_graphic_draw_color_blue;
|
||||
*/
|
||||
|
||||
void ctk_graphic_draw_init(void);
|
||||
|
||||
int ctk_graphic_draw_string_width(unsigned char font,
|
||||
char *str, unsigned char monospace);
|
||||
|
||||
void ctk_graphic_draw_string(unsigned char font,
|
||||
unsigned char color,
|
||||
unsigned int x,
|
||||
unsigned int y,
|
||||
char *str,
|
||||
unsigned char monospace);
|
||||
|
||||
void ctk_graphic_draw_line(unsigned char color,
|
||||
unsigned int x1, unsigned int y1,
|
||||
unsigned int x2, unsigned int y2);
|
||||
|
||||
void ctk_graphic_draw_rect(unsigned char color,
|
||||
unsigned char filled,
|
||||
unsigned int x1, unsigned int y1,
|
||||
unsigned int width, unsigned int height);
|
||||
|
||||
|
||||
#endif /* __CTK_GRAPHIC_DRAW_H__ */
|
|
@ -1,809 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2004, Adam Dunkels.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. 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.
|
||||
* 3. The name of the author may not be used to endorse or promote
|
||||
* products derived from this software without specific prior
|
||||
* written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
||||
*
|
||||
* This file is part of the Contiki operating system.
|
||||
*
|
||||
* $Id: ctk-graphic.c,v 1.1 2007/05/23 23:19:13 oliverschmidt Exp $
|
||||
*
|
||||
*/
|
||||
|
||||
#include "ctk-draw-service.h"
|
||||
|
||||
#include "ctk-graphic-draw.h"
|
||||
|
||||
#include "ctk-graphic.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
|
||||
#define WINDOWBORDER_WIDTH 1
|
||||
#define WINDOWBORDER_HEIGHT 1
|
||||
#define WINDOWTITLE_HEIGHT 3
|
||||
#define MENU_HEIGHT 1
|
||||
#define MENUBAR_HEIGHT 12
|
||||
|
||||
#define FONT_BASELINE 12
|
||||
|
||||
#define MENUBAR_FONT_BASELINE 7
|
||||
|
||||
#define RASTER_X 8
|
||||
#define RASTER_Y 14
|
||||
|
||||
#define BUTTON_HEIGHT 12
|
||||
#define BUTTON_X_BORDER 4
|
||||
#define BUTTON_Y_BORDER 1
|
||||
|
||||
#define TEXTENTRY_HEIGHT 12
|
||||
#define TEXTENTRY_X_BORDER 4
|
||||
#define TEXTENTRY_Y_BORDER 1
|
||||
|
||||
static GdkGC *white, *lightgray, *midgray, *darkgray, *ddarkgray, *black,
|
||||
*blue;
|
||||
|
||||
static GdkPixbuf *background, *windowborder, *menubar;
|
||||
|
||||
static void
|
||||
draw_widget(struct ctk_widget *w,
|
||||
unsigned char winx,
|
||||
unsigned char winy,
|
||||
unsigned char clipx,
|
||||
unsigned char clipy,
|
||||
unsigned char clipy1,
|
||||
unsigned char clipy2,
|
||||
unsigned char focus);
|
||||
|
||||
|
||||
/*--------------------------------------------------------------------------*/
|
||||
static void
|
||||
s_ctk_draw_init(void)
|
||||
{
|
||||
GtkWidget *image;
|
||||
|
||||
image = gtk_image_new_from_file("background.png");
|
||||
background = gtk_image_get_pixbuf(GTK_IMAGE(image));
|
||||
|
||||
image = gtk_image_new_from_file("windowborder.png");
|
||||
windowborder = gtk_image_get_pixbuf(GTK_IMAGE(image));
|
||||
|
||||
image = gtk_image_new_from_file("menubar.png");
|
||||
menubar = gtk_image_get_pixbuf(GTK_IMAGE(image));
|
||||
|
||||
ctk_graphic_draw_init();
|
||||
}
|
||||
/*--------------------------------------------------------------------------*/
|
||||
static void
|
||||
s_ctk_draw_clear(unsigned char y1, unsigned char y2)
|
||||
{
|
||||
if(background == NULL) {
|
||||
gdk_draw_rectangle(ctk_gtksim_pixmap,
|
||||
darkgray,
|
||||
TRUE,
|
||||
0,
|
||||
y1 * RASTER_Y + MENUBAR_HEIGHT,
|
||||
CTK_GTKSIM_SCREEN_WIDTH,
|
||||
(y2 - y1) * RASTER_Y);
|
||||
} else {
|
||||
gdk_draw_pixbuf(ctk_gtksim_pixmap,
|
||||
darkgray,
|
||||
background,
|
||||
0,
|
||||
y1 * RASTER_Y,
|
||||
0,
|
||||
y1 * RASTER_Y + MENUBAR_HEIGHT,
|
||||
CTK_GTKSIM_SCREEN_WIDTH,
|
||||
(y2 - y1) * RASTER_Y,
|
||||
NULL, 0, 0);
|
||||
}
|
||||
}
|
||||
/*--------------------------------------------------------------------------*/
|
||||
static void
|
||||
s_ctk_draw_clear_window(struct ctk_window *window,
|
||||
unsigned char focus,
|
||||
unsigned char clipy1,
|
||||
unsigned char clipy2)
|
||||
{
|
||||
int x, y;
|
||||
|
||||
x = window->x;
|
||||
y = window->y + MENU_HEIGHT;
|
||||
|
||||
/* Clear window */
|
||||
if(focus == CTK_FOCUS_WINDOW) {
|
||||
gdk_draw_rectangle(ctk_gtksim_pixmap,
|
||||
white,
|
||||
TRUE,
|
||||
x * RASTER_X - 1,
|
||||
y * RASTER_Y - 1 + MENUBAR_HEIGHT,
|
||||
(window->w + 2 * WINDOWBORDER_WIDTH) * RASTER_X + 2,
|
||||
(window->h + WINDOWTITLE_HEIGHT +
|
||||
WINDOWBORDER_HEIGHT) * RASTER_Y + 2);
|
||||
} else {
|
||||
gdk_draw_rectangle(ctk_gtksim_pixmap,
|
||||
lightgray,
|
||||
TRUE,
|
||||
x * RASTER_X - 1,
|
||||
y * RASTER_Y - 1 + MENUBAR_HEIGHT,
|
||||
(window->w + 2 * WINDOWBORDER_WIDTH) * RASTER_X + 2,
|
||||
(window->h + WINDOWTITLE_HEIGHT +
|
||||
WINDOWBORDER_HEIGHT) * RASTER_Y + 2);
|
||||
}
|
||||
}
|
||||
/*--------------------------------------------------------------------------*/
|
||||
static void
|
||||
s_ctk_draw_window(struct ctk_window *window,
|
||||
unsigned char focus,
|
||||
unsigned char clipy1,
|
||||
unsigned char clipy2)
|
||||
{
|
||||
struct ctk_widget *w;
|
||||
unsigned char wfocus;
|
||||
int x, y, x1, y1, x2, y2;
|
||||
|
||||
x = window->x;
|
||||
y = window->y + MENU_HEIGHT;
|
||||
|
||||
x1 = x + WINDOWBORDER_WIDTH;
|
||||
y1 = y + WINDOWTITLE_HEIGHT;
|
||||
x2 = x1 + window->w;
|
||||
y2 = y1 + window->h;
|
||||
|
||||
/* Draw window border */
|
||||
gdk_draw_rectangle(ctk_gtksim_pixmap,
|
||||
darkgray,
|
||||
FALSE,
|
||||
x * RASTER_X,
|
||||
y * RASTER_Y + MENUBAR_HEIGHT,
|
||||
(window->w + 2 * WINDOWBORDER_WIDTH) * RASTER_X,
|
||||
(window->h + WINDOWTITLE_HEIGHT +
|
||||
WINDOWBORDER_HEIGHT) * RASTER_Y);
|
||||
|
||||
if(ctk_mode_get() == CTK_MODE_WINDOWMOVE) {
|
||||
if(focus == CTK_FOCUS_WINDOW) {
|
||||
gdk_draw_rectangle(ctk_gtksim_pixmap,
|
||||
white,
|
||||
TRUE,
|
||||
x * RASTER_X + 1,
|
||||
y * RASTER_Y + MENUBAR_HEIGHT + 1,
|
||||
(window->w + 2 * WINDOWBORDER_WIDTH) * RASTER_X - 2,
|
||||
(window->h + WINDOWTITLE_HEIGHT +
|
||||
WINDOWBORDER_HEIGHT) * RASTER_Y - 2);
|
||||
} else {
|
||||
gdk_draw_rectangle(ctk_gtksim_pixmap,
|
||||
midgray,
|
||||
TRUE,
|
||||
x * RASTER_X + 1,
|
||||
y * RASTER_Y + MENUBAR_HEIGHT + 1,
|
||||
(window->w + 2 * WINDOWBORDER_WIDTH) * RASTER_X - 2,
|
||||
(window->h + WINDOWTITLE_HEIGHT +
|
||||
WINDOWBORDER_HEIGHT) * RASTER_Y - 2);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if(windowborder == NULL) {
|
||||
gdk_draw_rectangle(ctk_gtksim_pixmap,
|
||||
midgray,
|
||||
TRUE,
|
||||
x * RASTER_X,
|
||||
y * RASTER_Y + MENUBAR_HEIGHT,
|
||||
(window->w + 2 * WINDOWBORDER_WIDTH) * RASTER_X,
|
||||
WINDOWTITLE_HEIGHT * RASTER_Y);
|
||||
} else {
|
||||
gdk_draw_pixbuf(ctk_gtksim_pixmap,
|
||||
midgray,
|
||||
windowborder,
|
||||
0, 0,
|
||||
x * RASTER_X,
|
||||
y * RASTER_Y + MENUBAR_HEIGHT,
|
||||
(window->w + 2 * WINDOWBORDER_WIDTH) * RASTER_X,
|
||||
WINDOWTITLE_HEIGHT * RASTER_Y,
|
||||
NULL, 0, 0);
|
||||
}
|
||||
|
||||
|
||||
gdk_draw_line(ctk_gtksim_pixmap,
|
||||
darkgray,
|
||||
x * RASTER_X,
|
||||
(y + WINDOWTITLE_HEIGHT) * RASTER_Y - 1 + MENUBAR_HEIGHT,
|
||||
(x + window->w + 2 * WINDOWBORDER_WIDTH) * RASTER_X,
|
||||
(y + WINDOWTITLE_HEIGHT) * RASTER_Y - 1 + MENUBAR_HEIGHT);
|
||||
|
||||
|
||||
/* Draw inactive widgets. */
|
||||
for(w = window->inactive; w != NULL; w = w->next) {
|
||||
draw_widget(w, x1, y1, x2, y2,
|
||||
clipy1, clipy2,
|
||||
focus);
|
||||
}
|
||||
|
||||
/* Draw active widgets. */
|
||||
for(w = window->active; w != NULL; w = w->next) {
|
||||
wfocus = focus;
|
||||
if(w == window->focused) {
|
||||
wfocus |= CTK_FOCUS_WIDGET;
|
||||
}
|
||||
|
||||
draw_widget(w, x1, y1, x2, y2,
|
||||
clipy1, clipy2,
|
||||
wfocus);
|
||||
}
|
||||
|
||||
ctk_gtksim_set_redrawflag();
|
||||
}
|
||||
/*--------------------------------------------------------------------------*/
|
||||
static void
|
||||
s_ctk_draw_dialog(struct ctk_window *window)
|
||||
{
|
||||
struct ctk_widget *w;
|
||||
unsigned char wfocus, focus;
|
||||
int x, y, x1, y1, x2, y2;
|
||||
|
||||
focus = CTK_FOCUS_DIALOG;
|
||||
|
||||
x = window->x;
|
||||
y = window->y + MENU_HEIGHT;
|
||||
|
||||
x1 = x + WINDOWBORDER_WIDTH;
|
||||
y1 = y + WINDOWTITLE_HEIGHT;
|
||||
x2 = x1 + window->w;
|
||||
y2 = y1 + window->h;
|
||||
|
||||
/* Draw window border */
|
||||
gdk_draw_rectangle(ctk_gtksim_pixmap,
|
||||
black,
|
||||
FALSE,
|
||||
x * RASTER_X,
|
||||
y * RASTER_Y + MENUBAR_HEIGHT,
|
||||
(window->w + 2 * WINDOWBORDER_WIDTH) * RASTER_X,
|
||||
(window->h + WINDOWTITLE_HEIGHT +
|
||||
WINDOWBORDER_HEIGHT) * RASTER_Y);
|
||||
|
||||
|
||||
|
||||
gdk_draw_rectangle(ctk_gtksim_pixmap,
|
||||
white,
|
||||
TRUE,
|
||||
x * RASTER_X + 1,
|
||||
y * RASTER_Y + 1 + MENUBAR_HEIGHT,
|
||||
(window->w + 2 * WINDOWBORDER_WIDTH) * RASTER_X - 2,
|
||||
(window->h + WINDOWTITLE_HEIGHT +
|
||||
WINDOWBORDER_HEIGHT) * RASTER_Y - 2);
|
||||
|
||||
/* Draw inactive widgets. */
|
||||
for(w = window->inactive; w != NULL; w = w->next) {
|
||||
draw_widget(w, x1, y1, x2, y2,
|
||||
y1, y2,
|
||||
focus);
|
||||
}
|
||||
|
||||
/* Draw active widgets. */
|
||||
for(w = window->active; w != NULL; w = w->next) {
|
||||
wfocus = focus;
|
||||
if(w == window->focused) {
|
||||
wfocus |= CTK_FOCUS_WIDGET;
|
||||
}
|
||||
|
||||
draw_widget(w, x1, y1, x2, y2,
|
||||
y1, y2,
|
||||
wfocus);
|
||||
}
|
||||
|
||||
ctk_gtksim_set_redrawflag();
|
||||
|
||||
}
|
||||
/*--------------------------------------------------------------------------*/
|
||||
static void
|
||||
draw_widget(struct ctk_widget *w,
|
||||
unsigned char winx, unsigned char winy,
|
||||
unsigned char clipx,
|
||||
unsigned char clipy,
|
||||
unsigned char clipy1,
|
||||
unsigned char clipy2,
|
||||
unsigned char focus)
|
||||
{
|
||||
char text[1000];
|
||||
unsigned char x, y;
|
||||
int width, xpos;
|
||||
int i;
|
||||
GdkGC *bgcol, *buttoncol;
|
||||
struct ctk_gtksim_draw_font *buttonfont, *textfont, *textfont_bold;
|
||||
int monospace;
|
||||
|
||||
x = winx + w->x;
|
||||
y = winy + w->y;
|
||||
|
||||
if(focus & CTK_FOCUS_WINDOW) {
|
||||
bgcol = white;
|
||||
} else {
|
||||
bgcol = lightgray;
|
||||
}
|
||||
|
||||
if(focus & CTK_FOCUS_WINDOW) {
|
||||
buttoncol = lightgray;
|
||||
} else {
|
||||
buttoncol = midgray;
|
||||
}
|
||||
|
||||
monospace = w->flags & CTK_WIDGET_FLAG_MONOSPACE;
|
||||
if(monospace) {
|
||||
textfont = &ctk_gtksim_draw_font_monospace;
|
||||
textfont_bold = &ctk_gtksim_draw_font_monospace_bold;
|
||||
} else {
|
||||
textfont = &ctk_gtksim_draw_font_normal;
|
||||
textfont_bold = &ctk_gtksim_draw_font_bold;
|
||||
}
|
||||
|
||||
switch(w->type) {
|
||||
case CTK_WIDGET_SEPARATOR:
|
||||
gdk_draw_line(ctk_gtksim_pixmap,
|
||||
darkgray,
|
||||
x * RASTER_X,
|
||||
y * RASTER_Y + RASTER_Y / 2 + MENUBAR_HEIGHT,
|
||||
(x + w->w) * RASTER_X,
|
||||
y * RASTER_Y + RASTER_Y / 2 + MENUBAR_HEIGHT);
|
||||
break;
|
||||
case CTK_WIDGET_LABEL:
|
||||
gdk_draw_rectangle(ctk_gtksim_pixmap,
|
||||
bgcol,
|
||||
TRUE,
|
||||
x * RASTER_X,
|
||||
y * RASTER_Y + MENUBAR_HEIGHT,
|
||||
w->w * RASTER_X,
|
||||
w->h * RASTER_Y);
|
||||
for(i = 0; i < w->h; ++i) {
|
||||
strncpy(text, &w->widget.label.text[i * w->w], w->w);
|
||||
text[w->w] = 0;
|
||||
ctk_gtksim_draw_string(textfont,
|
||||
&ctk_gtksim_draw_color_black,
|
||||
RASTER_X * x,
|
||||
RASTER_Y * (y + i) + MENUBAR_HEIGHT,
|
||||
text, monospace);
|
||||
}
|
||||
|
||||
break;
|
||||
case CTK_WIDGET_BUTTON:
|
||||
if(w == (struct ctk_widget *)&w->window->titlebutton) {
|
||||
buttonfont = &ctk_gtksim_draw_font_bold;
|
||||
} else {
|
||||
buttonfont = textfont;
|
||||
}
|
||||
|
||||
++x;
|
||||
|
||||
width = ctk_gtksim_draw_string_width(buttonfont,
|
||||
w->widget.button.text,
|
||||
monospace);
|
||||
if(focus == (CTK_FOCUS_WIDGET|CTK_FOCUS_WINDOW)) {
|
||||
gdk_draw_rectangle(ctk_gtksim_pixmap,
|
||||
black,
|
||||
FALSE,
|
||||
x * RASTER_X - BUTTON_X_BORDER,
|
||||
y * RASTER_Y - BUTTON_Y_BORDER + MENUBAR_HEIGHT,
|
||||
w->w * RASTER_X + BUTTON_X_BORDER * 2,
|
||||
BUTTON_HEIGHT + BUTTON_Y_BORDER);
|
||||
/* gdk_draw_rectangle(ctk_gtksim_pixmap,
|
||||
ctk_gtksim_drawing_area->style->black_gc,
|
||||
FALSE,
|
||||
x * RASTER_X - BUTTON_X_BORDER - 1,
|
||||
y * RASTER_Y - BUTTON_Y_BORDER - 1,
|
||||
w->w * RASTER_X + BUTTON_X_BORDER * 2 + 1,
|
||||
RASTER_Y + BUTTON_Y_BORDER * 2 + 1);*/
|
||||
} else {
|
||||
gdk_draw_rectangle(ctk_gtksim_pixmap,
|
||||
darkgray,
|
||||
FALSE,
|
||||
x * RASTER_X - BUTTON_X_BORDER,
|
||||
y * RASTER_Y - BUTTON_Y_BORDER + MENUBAR_HEIGHT,
|
||||
w->w * RASTER_X + BUTTON_X_BORDER * 2,
|
||||
BUTTON_HEIGHT + BUTTON_Y_BORDER);
|
||||
}
|
||||
gdk_draw_rectangle(ctk_gtksim_pixmap,
|
||||
buttoncol,
|
||||
TRUE,
|
||||
x * RASTER_X - BUTTON_X_BORDER + 1,
|
||||
y * RASTER_Y + MENUBAR_HEIGHT,
|
||||
w->w * RASTER_X + BUTTON_X_BORDER * 2 - 2,
|
||||
BUTTON_HEIGHT);
|
||||
|
||||
gdk_draw_line(ctk_gtksim_pixmap,
|
||||
ddarkgray,
|
||||
x * RASTER_X - BUTTON_X_BORDER + 1,
|
||||
y * RASTER_Y + BUTTON_HEIGHT - 1 + MENUBAR_HEIGHT,
|
||||
x * RASTER_X + w->w * RASTER_X + BUTTON_X_BORDER - 1,
|
||||
y * RASTER_Y + BUTTON_HEIGHT - 1 + MENUBAR_HEIGHT);
|
||||
gdk_draw_line(ctk_gtksim_pixmap,
|
||||
ddarkgray,
|
||||
x * RASTER_X + w->w * RASTER_X + BUTTON_X_BORDER - 1,
|
||||
y * RASTER_Y + BUTTON_HEIGHT - 1 + MENUBAR_HEIGHT,
|
||||
x * RASTER_X + w->w * RASTER_X + BUTTON_X_BORDER - 1,
|
||||
y * RASTER_Y + MENUBAR_HEIGHT);
|
||||
|
||||
ctk_gtksim_draw_string(buttonfont,
|
||||
&ctk_gtksim_draw_color_black,
|
||||
RASTER_X * x +
|
||||
(w->w * RASTER_X) / 2 - width / 2,
|
||||
RASTER_Y * y + MENUBAR_HEIGHT,
|
||||
w->widget.button.text,
|
||||
monospace);
|
||||
break;
|
||||
case CTK_WIDGET_HYPERLINK:
|
||||
strncpy(text, w->widget.hyperlink.text, w->w);
|
||||
text[w->w] = 0;
|
||||
width = ctk_gtksim_draw_string_width(textfont, text, monospace);
|
||||
gdk_draw_rectangle(ctk_gtksim_pixmap,
|
||||
bgcol,
|
||||
TRUE,
|
||||
x * RASTER_X,
|
||||
y * RASTER_Y + MENUBAR_HEIGHT,
|
||||
width,
|
||||
RASTER_Y);
|
||||
if(focus & CTK_FOCUS_WIDGET) {
|
||||
ctk_gtksim_draw_string(textfont_bold,
|
||||
&ctk_gtksim_draw_color_blue,
|
||||
RASTER_X * x,
|
||||
RASTER_Y * y + MENUBAR_HEIGHT,
|
||||
text, monospace);
|
||||
} else {
|
||||
ctk_gtksim_draw_string(textfont,
|
||||
&ctk_gtksim_draw_color_blue,
|
||||
RASTER_X * x,
|
||||
RASTER_Y * y + MENUBAR_HEIGHT,
|
||||
text, monospace);
|
||||
}
|
||||
gdk_draw_line(ctk_gtksim_pixmap,
|
||||
blue,
|
||||
x * RASTER_X,
|
||||
y * RASTER_Y + FONT_BASELINE + 1 + MENUBAR_HEIGHT,
|
||||
x * RASTER_X + width,
|
||||
y * RASTER_Y + FONT_BASELINE + 1 + MENUBAR_HEIGHT);
|
||||
|
||||
break;
|
||||
case CTK_WIDGET_TEXTENTRY:
|
||||
strncpy(text, w->widget.textentry.text, sizeof(text));
|
||||
text[w->widget.textentry.xpos] = 0;
|
||||
width = ctk_gtksim_draw_string_width(textfont, text, monospace);
|
||||
gdk_draw_rectangle(ctk_gtksim_pixmap,
|
||||
darkgray,
|
||||
FALSE,
|
||||
x * RASTER_X - TEXTENTRY_X_BORDER + RASTER_X,
|
||||
y * RASTER_Y - TEXTENTRY_Y_BORDER + MENUBAR_HEIGHT,
|
||||
w->w * RASTER_X + TEXTENTRY_X_BORDER * 2 - 1,
|
||||
TEXTENTRY_HEIGHT + TEXTENTRY_Y_BORDER);
|
||||
gdk_draw_rectangle(ctk_gtksim_pixmap,
|
||||
bgcol,
|
||||
TRUE,
|
||||
x * RASTER_X + RASTER_X,
|
||||
y * RASTER_Y + MENUBAR_HEIGHT,
|
||||
w->w * RASTER_X,
|
||||
TEXTENTRY_HEIGHT);
|
||||
ctk_gtksim_draw_string(textfont,
|
||||
&ctk_gtksim_draw_color_black,
|
||||
RASTER_X * x + RASTER_X,
|
||||
RASTER_Y * y + MENUBAR_HEIGHT,
|
||||
w->widget.textentry.text,
|
||||
monospace);
|
||||
if(focus == (CTK_FOCUS_WIDGET|CTK_FOCUS_WINDOW)) {
|
||||
gdk_draw_line(ctk_gtksim_pixmap,
|
||||
black,
|
||||
x * RASTER_X + width + RASTER_X,
|
||||
y * RASTER_Y + MENUBAR_HEIGHT,
|
||||
x * RASTER_X + width + RASTER_X,
|
||||
y * RASTER_Y + TEXTENTRY_HEIGHT - 1 + MENUBAR_HEIGHT);
|
||||
}
|
||||
break;
|
||||
case CTK_WIDGET_ICON:
|
||||
width = ctk_gtksim_draw_string_width(&ctk_gtksim_draw_font_normal,
|
||||
w->widget.icon.title, monospace);
|
||||
|
||||
if(x * RASTER_X + width >= CTK_GTKSIM_SCREEN_WIDTH - RASTER_X) {
|
||||
xpos = CTK_GTKSIM_SCREEN_WIDTH - width - RASTER_X;
|
||||
} else {
|
||||
xpos = x * RASTER_X;
|
||||
}
|
||||
if((focus & CTK_FOCUS_WIDGET) == 0) {
|
||||
gdk_draw_rectangle(ctk_gtksim_pixmap,
|
||||
bgcol,
|
||||
TRUE,
|
||||
x * RASTER_X,
|
||||
y * RASTER_Y + MENUBAR_HEIGHT,
|
||||
24, 24);
|
||||
} else {
|
||||
gdk_draw_rectangle(ctk_gtksim_pixmap,
|
||||
black,
|
||||
TRUE,
|
||||
x * RASTER_X,
|
||||
y * RASTER_Y + MENUBAR_HEIGHT,
|
||||
24, 24);
|
||||
}
|
||||
|
||||
/* gdk_draw_rectangle(ctk_gtksim_pixmap,
|
||||
white,
|
||||
TRUE,
|
||||
xpos,
|
||||
RASTER_Y * y + 24 + 1 + MENUBAR_HEIGHT,
|
||||
width,
|
||||
RASTER_Y);*/
|
||||
|
||||
ctk_gtksim_draw_string(textfont,
|
||||
&ctk_gtksim_draw_color_black,
|
||||
xpos + 1,
|
||||
RASTER_Y * y + 24 + 1 + MENUBAR_HEIGHT,
|
||||
w->widget.icon.title,
|
||||
monospace);
|
||||
ctk_gtksim_draw_string(textfont,
|
||||
&ctk_gtksim_draw_color_white,
|
||||
xpos,
|
||||
RASTER_Y * y + 24 + MENUBAR_HEIGHT,
|
||||
w->widget.icon.title,
|
||||
monospace);
|
||||
|
||||
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------------------------*/
|
||||
static void
|
||||
s_ctk_draw_widget(struct ctk_widget *w,
|
||||
unsigned char focus,
|
||||
unsigned char clipy1,
|
||||
unsigned char clipy2)
|
||||
{
|
||||
struct ctk_window *win = w->window;
|
||||
unsigned char posx, posy;
|
||||
|
||||
posx = win->x + WINDOWBORDER_WIDTH;
|
||||
posy = win->y + WINDOWTITLE_HEIGHT + MENU_HEIGHT;
|
||||
|
||||
if(w == win->focused) {
|
||||
focus |= CTK_FOCUS_WIDGET;
|
||||
}
|
||||
|
||||
draw_widget(w, posx, posy,
|
||||
posx + win->w,
|
||||
posy + win->h,
|
||||
clipy1, clipy2,
|
||||
focus);
|
||||
|
||||
ctk_gtksim_set_redrawflag();
|
||||
}
|
||||
/*--------------------------------------------------------------------------*/
|
||||
static void
|
||||
draw_menu(struct ctk_menu *m, int x, int open)
|
||||
{
|
||||
int i;
|
||||
int xpos;
|
||||
|
||||
if(x >= CTK_GTKSIM_SCREEN_WIDTH / RASTER_X - 16) {
|
||||
xpos = CTK_GTKSIM_SCREEN_WIDTH / RASTER_X - 16;
|
||||
} else {
|
||||
xpos = x;
|
||||
}
|
||||
|
||||
if(open) {
|
||||
|
||||
gdk_draw_rectangle(ctk_gtksim_pixmap,
|
||||
black,
|
||||
TRUE,
|
||||
RASTER_X * x, 0,
|
||||
m->titlelen * RASTER_X,
|
||||
RASTER_Y + MENUBAR_HEIGHT);
|
||||
|
||||
ctk_gtksim_draw_string(&ctk_gtksim_draw_font_menu,
|
||||
&ctk_gtksim_draw_color_white,
|
||||
RASTER_X * x + 2,
|
||||
MENUBAR_FONT_BASELINE,
|
||||
m->title, 0);
|
||||
|
||||
gdk_draw_rectangle(ctk_gtksim_pixmap,
|
||||
white,
|
||||
TRUE,
|
||||
xpos * RASTER_X,
|
||||
RASTER_Y * MENU_HEIGHT + MENUBAR_HEIGHT,
|
||||
(xpos + 16) * RASTER_X,
|
||||
(m->nitems) * RASTER_Y);
|
||||
|
||||
for(i = 0; i < m->nitems; ++i) {
|
||||
if(i == m->active) {
|
||||
gdk_draw_rectangle(ctk_gtksim_pixmap,
|
||||
black,
|
||||
TRUE,
|
||||
RASTER_X * xpos,
|
||||
(MENU_HEIGHT + i) * RASTER_Y + MENUBAR_HEIGHT,
|
||||
(xpos + 16) * RASTER_X,
|
||||
RASTER_Y);
|
||||
ctk_gtksim_draw_string(&ctk_gtksim_draw_font_normal,
|
||||
&ctk_gtksim_draw_color_white,
|
||||
RASTER_X * xpos + 2,
|
||||
(MENU_HEIGHT + i) * RASTER_Y +
|
||||
MENUBAR_HEIGHT,
|
||||
m->items[i].title, 0);
|
||||
|
||||
} else {
|
||||
ctk_gtksim_draw_string(&ctk_gtksim_draw_font_normal,
|
||||
&ctk_gtksim_draw_color_black,
|
||||
RASTER_X * xpos + 2,
|
||||
(MENU_HEIGHT + i) * RASTER_Y + MENUBAR_HEIGHT,
|
||||
m->items[i].title, 0);
|
||||
}
|
||||
|
||||
}
|
||||
} else {
|
||||
/* gdk_draw_rectangle(ctk_gtksim_pixmap,
|
||||
white,
|
||||
TRUE,
|
||||
RASTER_X * x, 0,
|
||||
m->titlelen * RASTER_X, RASTER_Y);*/
|
||||
|
||||
ctk_gtksim_draw_string(&ctk_gtksim_draw_font_menu,
|
||||
&ctk_gtksim_draw_color_black,
|
||||
RASTER_X * x, MENUBAR_FONT_BASELINE,
|
||||
m->title, 0);
|
||||
|
||||
}
|
||||
}
|
||||
/*--------------------------------------------------------------------------*/
|
||||
static void
|
||||
s_ctk_draw_menus(struct ctk_menus *menus)
|
||||
{
|
||||
struct ctk_menu *m;
|
||||
int x;
|
||||
|
||||
if(menubar != NULL) {
|
||||
gdk_draw_pixbuf(ctk_gtksim_pixmap,
|
||||
darkgray,
|
||||
menubar,
|
||||
0, 0,
|
||||
0, 0,
|
||||
CTK_GTKSIM_SCREEN_WIDTH,
|
||||
RASTER_Y + MENUBAR_HEIGHT,
|
||||
NULL, 0, 0);
|
||||
}
|
||||
|
||||
x = 1;
|
||||
for(m = menus->menus->next; m != NULL; m = m->next) {
|
||||
draw_menu(m, x, m == menus->open);
|
||||
x += strlen(m->title);
|
||||
}
|
||||
|
||||
x = CTK_GTKSIM_SCREEN_WIDTH / RASTER_X - strlen(menus->menus->title);
|
||||
draw_menu(menus->menus, x, menus->menus == menus->open);
|
||||
|
||||
|
||||
|
||||
/* gdk_draw_line(ctk_gtksim_pixmap,
|
||||
ctk_gtksim_drawing_area->style->black_gc,
|
||||
0, RASTER_Y,
|
||||
CTK_GTKSIM_SCREEN_WIDTH,
|
||||
RASTER_Y);*/
|
||||
|
||||
ctk_gtksim_set_redrawflag();
|
||||
}
|
||||
/*--------------------------------------------------------------------------*/
|
||||
static unsigned char
|
||||
s_ctk_draw_width(void)
|
||||
{
|
||||
return CTK_GTKSIM_SCREEN_WIDTH / RASTER_X;
|
||||
}
|
||||
/*--------------------------------------------------------------------------*/
|
||||
static unsigned char
|
||||
s_ctk_draw_height(void)
|
||||
{
|
||||
return CTK_GTKSIM_SCREEN_HEIGHT / RASTER_Y;
|
||||
}
|
||||
/*--------------------------------------------------------------------------*/
|
||||
static unsigned short
|
||||
s_ctk_mouse_xtoc(unsigned short x)
|
||||
{
|
||||
return x / RASTER_X;
|
||||
}
|
||||
/*--------------------------------------------------------------------------*/
|
||||
static unsigned short
|
||||
s_ctk_mouse_ytoc(unsigned short y)
|
||||
{
|
||||
if(y < MENUBAR_HEIGHT) {
|
||||
return 0;
|
||||
} else {
|
||||
return (y - MENUBAR_HEIGHT) / RASTER_Y;
|
||||
}
|
||||
}
|
||||
/*--------------------------------------------------------------------------*/
|
||||
static const struct ctk_draw_service_interface interface =
|
||||
{CTK_DRAW_SERVICE_VERSION,
|
||||
WINDOWBORDER_WIDTH,
|
||||
WINDOWBORDER_HEIGHT,
|
||||
WINDOWTITLE_HEIGHT,
|
||||
s_ctk_draw_init,
|
||||
s_ctk_draw_clear,
|
||||
s_ctk_draw_clear_window,
|
||||
s_ctk_draw_window,
|
||||
s_ctk_draw_dialog,
|
||||
s_ctk_draw_widget,
|
||||
s_ctk_draw_menus,
|
||||
s_ctk_draw_width,
|
||||
s_ctk_draw_height,
|
||||
s_ctk_mouse_xtoc,
|
||||
s_ctk_mouse_ytoc,
|
||||
};
|
||||
|
||||
EK_EVENTHANDLER(eventhandler, ev, data);
|
||||
EK_PROCESS(proc, CTK_DRAW_SERVICE_NAME, EK_PRIO_NORMAL,
|
||||
eventhandler, NULL, (void *)&interface);
|
||||
|
||||
/*--------------------------------------------------------------------------*/
|
||||
EK_PROCESS_INIT(ctk_gtksim_service_init, arg)
|
||||
{
|
||||
ek_service_start(CTK_DRAW_SERVICE_NAME, &proc);
|
||||
}
|
||||
/*--------------------------------------------------------------------------*/
|
||||
static GdkGC *
|
||||
get_color(unsigned short r, unsigned short g, unsigned short b)
|
||||
{
|
||||
GdkGCValues values;
|
||||
GdkColor color;
|
||||
|
||||
color.pixel = 0;
|
||||
color.red = r;
|
||||
color.green = g;
|
||||
color.blue = b;
|
||||
|
||||
if(gdk_colormap_alloc_color(gdk_colormap_get_system(),
|
||||
&color, FALSE, TRUE)) {
|
||||
}
|
||||
|
||||
values.foreground = color;
|
||||
|
||||
return gdk_gc_new_with_values(ctk_gtksim_drawing_area->window,
|
||||
&values,
|
||||
GDK_GC_FOREGROUND);
|
||||
}
|
||||
/*--------------------------------------------------------------------------*/
|
||||
EK_EVENTHANDLER(eventhandler, ev, data)
|
||||
{
|
||||
EK_EVENTHANDLER_ARGS(ev, data);
|
||||
|
||||
switch(ev) {
|
||||
case EK_EVENT_INIT:
|
||||
blue = get_color(0, 0, 0xffff);
|
||||
white = get_color(0xffff, 0xffff, 0xffff);
|
||||
lightgray = get_color(0xefff, 0xefff, 0xefff);
|
||||
midgray = get_color(0xdfff, 0xdfff, 0xdfff);
|
||||
darkgray = get_color(0xcfff, 0xcfff, 0xcfff);
|
||||
ddarkgray = get_color(0xafff, 0xafff, 0xafff);
|
||||
black = get_color(0, 0, 0);
|
||||
break;
|
||||
case EK_EVENT_REQUEST_REPLACE:
|
||||
ek_replace((struct ek_proc *)data, NULL);
|
||||
LOADER_UNLOAD();
|
||||
break;
|
||||
}
|
||||
}
|
||||
/*--------------------------------------------------------------------------*/
|
|
@ -1,323 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2002-2004, Adam Dunkels.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. 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.
|
||||
* 3. The name of the author may not be used to endorse or promote
|
||||
* products derived from this software without specific prior
|
||||
* written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
||||
*
|
||||
* This file is part of the Contiki operating system.
|
||||
*
|
||||
* $Id: ctk-mouse.c,v 1.1 2007/05/26 21:38:53 oliverschmidt Exp $
|
||||
*
|
||||
*/
|
||||
|
||||
#include "process.h"
|
||||
#include "cc.h"
|
||||
|
||||
#include "ctk/ctk.h"
|
||||
#include "ctk-draw.h"
|
||||
#include "contiki-conf.h"
|
||||
#include "ctk-mouse.h"
|
||||
|
||||
unsigned short mouse_x, mouse_y, mouse_button;
|
||||
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
EK_POLLHANDLER(ctk_poll)
|
||||
{
|
||||
static ctk_arch_key_t c;
|
||||
static unsigned char i;
|
||||
register struct ctk_window *window;
|
||||
register struct ctk_widget *widget;
|
||||
register struct ctk_widget **widgetptr;
|
||||
|
||||
static unsigned char mxc, myc, mouse_button_changed, mouse_moved,
|
||||
mouse_clicked;
|
||||
static unsigned char menux;
|
||||
register struct ctk_menu *menu;
|
||||
|
||||
mouse_button_changed = mouse_moved = mouse_clicked = 0;
|
||||
|
||||
/* See if there is any change in the buttons. */
|
||||
if(ctk_mouse_button() != mouse_button) {
|
||||
mouse_button = ctk_mouse_button();
|
||||
mouse_button_changed = 1;
|
||||
if(mouse_button == 0) {
|
||||
mouse_clicked = 1;
|
||||
}
|
||||
}
|
||||
|
||||
/* Check if the mouse pointer has moved. */
|
||||
if(ctk_mouse_x() != mouse_x ||
|
||||
ctk_mouse_y() != mouse_y) {
|
||||
mouse_x = ctk_mouse_x();
|
||||
mouse_y = ctk_mouse_y();
|
||||
mouse_moved = 1;
|
||||
}
|
||||
|
||||
mxc = ctk_mouse_xtoc(mouse_x);
|
||||
myc = ctk_mouse_ytoc(mouse_y);
|
||||
|
||||
if(mode == CTK_MODE_SCREENSAVER) {
|
||||
if(mouse_moved || mouse_button_changed) {
|
||||
ek_post(EK_BROADCAST, ctk_signal_screensaver_stop, NULL);
|
||||
mode = CTK_MODE_NORMAL;
|
||||
}
|
||||
} else {
|
||||
|
||||
/* If there is any change in the mouse conditions, find out in
|
||||
which window the mouse pointer currently is in order to send
|
||||
the correct signals, or bring a window to focus. */
|
||||
if(mouse_moved || mouse_button_changed) {
|
||||
ctk_mouse_show();
|
||||
screensaver_timer = 0;
|
||||
|
||||
if(myc == 0) {
|
||||
/* Here we should do whatever needs to be done when the mouse
|
||||
moves around and clicks in the menubar. */
|
||||
if(mouse_clicked) {
|
||||
static unsigned char titlelen;
|
||||
|
||||
/* Find out which menu that the mouse pointer is in. Start
|
||||
with the ->next menu after the desktop menu. We assume
|
||||
that the menus start one character from the left screen
|
||||
side and that the desktop menu is farthest to the
|
||||
right. */
|
||||
menux = 1;
|
||||
for(menu = menus.menus->next;
|
||||
menu != NULL; menu = menu->next) {
|
||||
titlelen = menu->titlelen;
|
||||
if(mxc >= menux && mxc <= menux + titlelen) {
|
||||
break;
|
||||
}
|
||||
menux += titlelen;
|
||||
}
|
||||
|
||||
/* Also check desktop menu. */
|
||||
if(mxc >= width - 7 &&
|
||||
mxc <= width - 1) {
|
||||
menu = &desktopmenu;
|
||||
}
|
||||
|
||||
menus.open = menu;
|
||||
redraw |= REDRAW_MENUPART;
|
||||
}
|
||||
} else {
|
||||
--myc;
|
||||
|
||||
if(menus.open != NULL) {
|
||||
static unsigned char nitems;
|
||||
|
||||
/* Do whatever needs to be done when a menu is open. */
|
||||
|
||||
/* First check if the mouse pointer is in the currently open
|
||||
menu. */
|
||||
if(menus.open == &desktopmenu) {
|
||||
menux = width - CTK_CONF_MENUWIDTH;
|
||||
} else {
|
||||
menux = 1;
|
||||
for(menu = menus.menus->next; menu != menus.open;
|
||||
menu = menu->next) {
|
||||
menux += menu->titlelen;
|
||||
}
|
||||
}
|
||||
|
||||
nitems = menus.open->nitems;
|
||||
/* Find out which of the menu items the mouse is pointing
|
||||
to. */
|
||||
if(mxc >= menux && mxc <= menux + CTK_CONF_MENUWIDTH) {
|
||||
if(myc <= nitems) {
|
||||
menus.open->active = myc;
|
||||
} else {
|
||||
menus.open->active = nitems - 1;
|
||||
}
|
||||
}
|
||||
|
||||
if(mouse_clicked) {
|
||||
if(mxc >= menux && mxc <= menux + CTK_CONF_MENUWIDTH &&
|
||||
myc <= nitems) {
|
||||
redraw |= activate_menu();
|
||||
} else {
|
||||
lastmenu = menus.open;
|
||||
menus.open = NULL;
|
||||
redraw |= REDRAW_MENUPART;
|
||||
}
|
||||
} else {
|
||||
redraw |= REDRAW_MENUS;
|
||||
}
|
||||
} else {
|
||||
|
||||
/* Walk through the windows from top to bottom to see in
|
||||
which window the mouse pointer is. */
|
||||
if(dialog != NULL) {
|
||||
window = dialog;
|
||||
} else {
|
||||
for(window = windows; window != NULL;
|
||||
window = window->next) {
|
||||
|
||||
/* Check if the mouse is within the window. */
|
||||
if(mxc >= window->x &&
|
||||
mxc <= window->x + window->w +
|
||||
2 * ctk_draw_windowborder_width &&
|
||||
myc >= window->y &&
|
||||
myc <= window->y + window->h +
|
||||
ctk_draw_windowtitle_height +
|
||||
ctk_draw_windowborder_height) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* If we didn't find any window, and there are no windows
|
||||
open, the mouse pointer will definately be within the
|
||||
background desktop window. */
|
||||
if(window == NULL) {
|
||||
window = &desktop_window;
|
||||
}
|
||||
|
||||
/* If the mouse pointer moves around outside of the
|
||||
currently focused window (or dialog), we should not have
|
||||
any focused widgets in the focused window so we make sure
|
||||
that there are none. */
|
||||
if(windows != NULL &&
|
||||
window != windows &&
|
||||
windows->focused != NULL){
|
||||
unfocus_widget(windows->focused);
|
||||
}
|
||||
|
||||
if(window != NULL) {
|
||||
/* If the mouse was clicked outside of the current window,
|
||||
we bring the clicked window to front. */
|
||||
if(dialog == NULL &&
|
||||
window != &desktop_window &&
|
||||
window != windows &&
|
||||
mouse_clicked) {
|
||||
/* Bring window to front. */
|
||||
ctk_window_open(window);
|
||||
redraw |= REDRAW_ALL;
|
||||
} else {
|
||||
|
||||
/* Find out which widget currently is under the mouse
|
||||
pointer and give it focus, unless it already has
|
||||
focus. */
|
||||
mxc = mxc - window->x - ctk_draw_windowborder_width;
|
||||
myc = myc - window->y - ctk_draw_windowtitle_height;
|
||||
|
||||
/* See if the mouse pointer is on a widget. If so, it
|
||||
should be selected and, if the button is clicked,
|
||||
activated. */
|
||||
for(widget = window->active; widget != NULL;
|
||||
widget = widget->next) {
|
||||
|
||||
if(mxc >= widget->x &&
|
||||
mxc <= widget->x + widget->w &&
|
||||
(myc == widget->y ||
|
||||
((widget->type == CTK_WIDGET_BITMAP ||
|
||||
widget->type == CTK_WIDGET_ICON) &&
|
||||
(myc >= widget->y &&
|
||||
myc <= widget->y +
|
||||
((struct ctk_bitmap *)widget)->h)))) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* if the mouse is moved in the focused window, we emit
|
||||
a ctk_signal_pointer_move signal to the owner of the
|
||||
window. */
|
||||
if(mouse_moved &&
|
||||
(window != &desktop_window ||
|
||||
windows == NULL)) {
|
||||
|
||||
ek_post(window->owner, ctk_signal_pointer_move, NULL);
|
||||
|
||||
/* If there was a focused widget that is not below the
|
||||
mouse pointer, we remove focus from the widget and
|
||||
redraw it. */
|
||||
if(window->focused != NULL &&
|
||||
widget != window->focused) {
|
||||
unfocus_widget(window->focused);
|
||||
}
|
||||
redraw |= REDRAW_WIDGETS;
|
||||
if(widget != NULL) {
|
||||
select_widget(widget);
|
||||
}
|
||||
}
|
||||
|
||||
if(mouse_button_changed) {
|
||||
ek_post(window->owner, ctk_signal_pointer_button,
|
||||
(ek_data_t)mouse_button);
|
||||
if(mouse_clicked && widget != NULL) {
|
||||
select_widget(widget);
|
||||
redraw |= activate(widget);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(ctk_arch_keyavail()) {
|
||||
ctk_mouse_hide();
|
||||
}
|
||||
|
||||
#if CTK_CONF_WINDOWMOVE
|
||||
} else if(mode == CTK_MODE_WINDOWMOVE) {
|
||||
|
||||
/* If the mouse has moved, we move the window as well. */
|
||||
if(mouse_moved) {
|
||||
|
||||
if(window->w + mxc + 2 >= width) {
|
||||
window->x = width - 2 - window->w;
|
||||
} else {
|
||||
window->x = mxc;
|
||||
}
|
||||
|
||||
if(window->h + myc + ctk_draw_windowtitle_height +
|
||||
ctk_draw_windowborder_height >= height) {
|
||||
window->y = height - window->h -
|
||||
ctk_draw_windowtitle_height - ctk_draw_windowborder_height;
|
||||
} else {
|
||||
window->y = myc;
|
||||
}
|
||||
if(window->y > 0) {
|
||||
--window->y;
|
||||
}
|
||||
|
||||
redraw = REDRAW_ALL;
|
||||
}
|
||||
|
||||
/* Check if the mouse has been clicked, and stop moving the window
|
||||
if so. */
|
||||
if(mouse_button_changed &&
|
||||
mouse_button == 0) {
|
||||
mode = CTK_MODE_NORMAL;
|
||||
redraw = REDRAW_ALL;
|
||||
}
|
||||
#endif /* CTK_CONF_WINDOWMOVE */
|
||||
}
|
||||
}
|
||||
/*-----------------------------------------------------------------------------------*/
|
|
@ -1,123 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2005, Swedish Institute of Computer Science
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. 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.
|
||||
* 3. Neither the name of the Institute 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 INSTITUTE 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 INSTITUTE 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.
|
||||
*
|
||||
* This file is part of the Contiki operating system.
|
||||
*
|
||||
* @(#)$Id: ctk-term-ascii.h,v 1.1 2007/05/26 21:54:33 oliverschmidt Exp $
|
||||
*/
|
||||
/* ascii_control.h
|
||||
*
|
||||
* ASCII CONTROL CHARACTERS
|
||||
* from American National Standard Code for Information Interchange X3.4-1977
|
||||
*
|
||||
* Abbreviations
|
||||
*
|
||||
* CC: communication control
|
||||
* FE: format effector
|
||||
* IS: information separator
|
||||
* Delim: delimiter
|
||||
* Intro: introducer
|
||||
*/
|
||||
|
||||
/* ----------------------------------------------------------------------- */
|
||||
/* C0 (7-bit) set */
|
||||
/* ----------------------------------------------------------------------- */
|
||||
/* mnemonic octal decimal C meaning */
|
||||
/* ----------------------------------------------------------------------- */
|
||||
|
||||
#define ASCII_NUL (000) /* 0 '\0' Null */
|
||||
#define ASCII_SOH (001) /* 1 Start of Heading (CC) */
|
||||
#define ASCII_STX (002) /* 2 Start of Text (CC) */
|
||||
#define ASCII_ETX (003) /* 3 End of Text (CC) */
|
||||
#define ASCII_EOT (004) /* 4 End of Transmission (CC) */
|
||||
#define ASCII_ENQ (005) /* 5 Enquiry (CC) */
|
||||
#define ASCII_ACK (006) /* 6 Acknowledge (CC) */
|
||||
#define ASCII_BEL (007) /* 7 '\a' Bell / Alert */
|
||||
#define ASCII_BS (010) /* 8 '\b' Backspace (FE) */
|
||||
#define ASCII_HT (011) /* 9 '\t' Horizontal Tabulation (FE) */
|
||||
#define ASCII_LF (012) /* 10 '\n' Line Feed / Newline (FE) */
|
||||
#define ASCII_VT (013) /* 11 '\v' Vertical Tabulation (FE) */
|
||||
#define ASCII_FF (014) /* 12 '\f' Form Feed (FE) */
|
||||
#define ASCII_CR (015) /* 13 '\r' Carriage Return (FE) */
|
||||
#define ASCII_SO (016) /* 14 Shift Out */
|
||||
#define ASCII_SI (017) /* 15 Shift In */
|
||||
#define ASCII_DLE (020) /* 16 Data Link Escape (CC) */
|
||||
#define ASCII_DC1 (021) /* 17 Device Control 1 XON */
|
||||
#define ASCII_DC2 (022) /* 18 Device Control 2 */
|
||||
#define ASCII_DC3 (023) /* 19 Device Control 3 XOFF */
|
||||
#define ASCII_DC4 (024) /* 20 Device Control 4 */
|
||||
#define ASCII_NAK (025) /* 21 Negative Acknowledge (CC) */
|
||||
#define ASCII_SYN (026) /* 22 Synchronous Idle (CC) */
|
||||
#define ASCII_ETB (027) /* 23 End of Transmission Block (CC) */
|
||||
#define ASCII_CAN (030) /* 24 Cancel */
|
||||
#define ASCII_EM (031) /* 25 End of Medium */
|
||||
#define ASCII_SUB (032) /* 26 Substitute */
|
||||
#define ASCII_ESC (033) /* 27 Escape */
|
||||
#define ASCII_FS (034) /* 28 File Separator */
|
||||
#define ASCII_GS (035) /* 29 Group Separator */
|
||||
#define ASCII_RS (036) /* 30 Record Separator */
|
||||
#define ASCII_US (037) /* 31 Unit Separator */
|
||||
|
||||
#define ASCII_DEL (0177) /* 127 Delete */
|
||||
|
||||
#define ASCII_NL ASCII_LF /* 10 alias for Newline */
|
||||
|
||||
/* ----------------------------------------------------------------------- */
|
||||
/* C1 (8-bit) set (which have equivalent 7-bit multi-char sequences) */
|
||||
/* ----------------------------------------------------------------------- */
|
||||
/* mnemonic octal decimal 7-bit meaning */
|
||||
/* ----------------------------------------------------------------------- */
|
||||
|
||||
#define ASCII_IND (0204) /* 132 Esc D Index (FE) */
|
||||
#define ASCII_NEL (0205) /* 133 Esc E Next Line (FE) */
|
||||
#define ASCII_SSA (0206) /* 134 Esc F Start Selected Area */
|
||||
#define ASCII_ESA (0207) /* 135 Esc G End Selected Area */
|
||||
#define ASCII_HTS (0210) /* 136 Esc H Horizontal Tab Set (FE) */
|
||||
#define ASCII_HTJ (0211) /* 137 Esc I Horizontal Tab w/Justificat(FE)*/
|
||||
#define ASCII_VTS (0212) /* 138 Esc J Vertical Tab Set (FE) */
|
||||
#define ASCII_PLD (0213) /* 138 Esc K Partial Line Down (FE) */
|
||||
#define ASCII_PLU (0214) /* 140 Esc L Partial Line Up (FE) */
|
||||
#define ASCII_RI (0215) /* 141 Esc M Reverse Index (FE) */
|
||||
#define ASCII_SS2 (0216) /* 142 Esc N Single Shift G2 (Intro) */
|
||||
#define ASCII_SS3 (0217) /* 143 Esc O Single Shift G3 (Intro) */
|
||||
#define ASCII_DCS (0220) /* 144 Esc P Device Control String (Delim) */
|
||||
#define ASCII_PU1 (0221) /* 145 Esc Q Private Use 1 */
|
||||
#define ASCII_PU2 (0222) /* 146 Esc R Private Use 2 */
|
||||
#define ASCII_STS (0223) /* 147 Esc S Set Transmit State */
|
||||
#define ASCII_CCH (0224) /* 148 Esc T Cancel Previous Character */
|
||||
#define ASCII_MW (0225) /* 149 Esc U Message Waiting */
|
||||
#define ASCII_SPA (0226) /* 150 Esc V Start Protected Area */
|
||||
#define ASCII_EPA (0227) /* 151 Esc W End Protected Area */
|
||||
|
||||
#define ASCII_CSI (0233) /* 155 Esc [ Control Sequence Introducer */
|
||||
#define ASCII_ST (0234) /* 156 Esc \ String Terminator (Delim) */
|
||||
#define ASCII_OSC (0235) /* 157 Esc ] Operating System Control (Delim*/
|
||||
#define ASCII_PM (0236) /* 158 Esc ^ Privacy Message (Delim) */
|
||||
#define ASCII_APC (0237) /* 159 Esc _ Application Program Command (De*/
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
|
@ -1,381 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2004, Adam Dunkels.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. 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.
|
||||
* 3. Neither the name of the Institute 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 INSTITUTE 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 INSTITUTE 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.
|
||||
*
|
||||
* This file is part of the Contiki operating system.
|
||||
*
|
||||
* Author: Adam Dunkels <adam@sics.se>
|
||||
*
|
||||
* $Id: ctk-term-in.c,v 1.1 2007/05/26 21:54:33 oliverschmidt Exp $
|
||||
*/
|
||||
#include <string.h>
|
||||
#include "ctk/ctk.h"
|
||||
#include "ctk-term.h"
|
||||
#include "ctk-term-int.h"
|
||||
#include "ctk-term-ascii.h"
|
||||
|
||||
#define PRINTF(x)
|
||||
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
/*
|
||||
* #defines and enums
|
||||
*/
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
|
||||
/* Size of input key buffer */
|
||||
#define NUMKEYS 20
|
||||
|
||||
/* ANSI character classes */
|
||||
enum {ACC_C0, ACC_INTERM, ACC_PARAM, ACC_LOWCASE, ACC_UPCASE,ACC_C1, ACC_G1, ACC_DEL, ACC_SPEC };
|
||||
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
/*
|
||||
* Structures
|
||||
*/
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
|
||||
/* Structure for mapping a character sequence to a key */
|
||||
struct seqmap
|
||||
{
|
||||
const char* seq;
|
||||
const ctk_arch_key_t key;
|
||||
};
|
||||
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
/*
|
||||
* Local variables
|
||||
*/
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
|
||||
static ctk_arch_key_t keys[NUMKEYS];
|
||||
static int firstkey, lastkey;
|
||||
|
||||
/* Sequences starting with ESC [ .... */
|
||||
const static struct seqmap ctrlmap[] =
|
||||
{
|
||||
{"A",CH_CURS_UP},
|
||||
{"B",CH_CURS_DOWN},
|
||||
{"C",CH_CURS_RIGHT},
|
||||
{"D",CH_CURS_LEFT},
|
||||
|
||||
{"11~",CH_F1},
|
||||
{"12~",CH_F2},
|
||||
{"13~",CH_F3},
|
||||
{"14~",CH_F4},
|
||||
// linux console
|
||||
{"[A",CH_F1},
|
||||
{"[B",CH_F2},
|
||||
{"[C",CH_F3},
|
||||
{"[D",CH_F4},
|
||||
{0,0}
|
||||
};
|
||||
|
||||
/* Sequences starting with ESC O .... */
|
||||
const static struct seqmap ss3map[] =
|
||||
{
|
||||
{"A",CH_CURS_UP},
|
||||
{"B",CH_CURS_DOWN},
|
||||
{"C",CH_CURS_RIGHT},
|
||||
{"D",CH_CURS_LEFT},
|
||||
{"P",CH_F1},
|
||||
{"Q",CH_F2},
|
||||
{"R",CH_F3},
|
||||
{"S",CH_F4},
|
||||
{0,0}
|
||||
};
|
||||
|
||||
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
/*
|
||||
* Add a key to the input buffer
|
||||
*/
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
static void
|
||||
enqueue_key(ctk_arch_key_t k)
|
||||
{
|
||||
keys[lastkey] = k;
|
||||
++lastkey;
|
||||
if(lastkey >= NUMKEYS) {
|
||||
lastkey = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
/*
|
||||
* Classify a character
|
||||
*/
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
static unsigned char
|
||||
classify(unsigned char c)
|
||||
{
|
||||
if (0x00 <= c && c <=0x1f) return ACC_C0;
|
||||
if (0x20 <= c && c <=0x2f) return ACC_INTERM;
|
||||
if (0x30 <= c && c <=0x3f) return ACC_PARAM;
|
||||
if (0x40 <= c && c <=0x5f) return ACC_UPCASE;
|
||||
if (0x60 <= c && c <=0x7e) return ACC_LOWCASE;
|
||||
if (c == 0x7f) return ACC_DEL;
|
||||
if (0x90 <= c && c <=0x9f) return ACC_C1;
|
||||
if (c == 0xa0) return ACC_SPEC;
|
||||
if (0xA1 <= c && c <=0xfe) return ACC_G1;
|
||||
if (0x90 <= c && c <=0x9f) return ACC_C1;
|
||||
if (c == 0xff) return ACC_SPEC;
|
||||
return ACC_SPEC;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
/*
|
||||
* Lookup a key sequence in a sequencemap and queue the key if sequence found
|
||||
*/
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
static void
|
||||
lookup_seq(const char* str, const struct seqmap* map)
|
||||
{
|
||||
while (map->seq != 0) {
|
||||
if (strcmp(str,map->seq) == 0) {
|
||||
enqueue_key(map->key);
|
||||
return;
|
||||
}
|
||||
map++;
|
||||
}
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
/* \internal
|
||||
* Parse a character stream
|
||||
* Returns -1 if c is consumed by the state machine 1 else.
|
||||
*/
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
static int
|
||||
parse_input(struct ctk_term_state* st, unsigned char c)
|
||||
{
|
||||
unsigned char cl = classify(c);
|
||||
int ret = -1;
|
||||
switch(st->inputstate) {
|
||||
case ANS_IDLE:
|
||||
switch(cl) {
|
||||
case ACC_C0:
|
||||
{
|
||||
switch(c) {
|
||||
case ASCII_ESC: st->inputstate = ANS_ESCSEQ; break;
|
||||
case ASCII_BS: enqueue_key(CH_DEL); break;
|
||||
case ASCII_HT: enqueue_key(CH_TAB); break;
|
||||
case ASCII_FF: ctk_term_redraw(st); break;
|
||||
case ASCII_CR: enqueue_key(CH_ENTER); break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case ACC_INTERM:
|
||||
case ACC_PARAM:
|
||||
case ACC_LOWCASE:
|
||||
case ACC_UPCASE:
|
||||
case ACC_G1:
|
||||
ret = 1;
|
||||
break;
|
||||
case ACC_C1:
|
||||
if (c == ASCII_CSI) {
|
||||
st->inputstate = ANS_CTRLSEQ;
|
||||
st->ctrlCnt = 0;
|
||||
}
|
||||
else if (c == ASCII_SS3) {
|
||||
st->inputstate = ANS_SS3;
|
||||
st->ctrlCnt = 0;
|
||||
}
|
||||
break;
|
||||
case ACC_DEL:
|
||||
enqueue_key(CH_DEL);
|
||||
break;
|
||||
case ACC_SPEC:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case ANS_ESCSEQ:
|
||||
{
|
||||
switch(cl) {
|
||||
case ACC_C0:
|
||||
case ACC_DEL:
|
||||
break;
|
||||
case ACC_INTERM:
|
||||
st->inputstate = ANS_ESCSEQ_1;
|
||||
break;
|
||||
case ACC_UPCASE:
|
||||
/* C1 control character */
|
||||
if (c == '[') {
|
||||
st->inputstate = ANS_CTRLSEQ;
|
||||
st->ctrlCnt = 0;
|
||||
}
|
||||
else if (c == 'O') {
|
||||
st->inputstate = ANS_SS3;
|
||||
st->ctrlCnt = 0;
|
||||
}
|
||||
else {
|
||||
st->inputstate = ANS_IDLE;
|
||||
}
|
||||
break;
|
||||
case ACC_PARAM:
|
||||
/* Private 2-character sequence */
|
||||
case ACC_LOWCASE:
|
||||
/* Standard 2-character sequence */
|
||||
default:
|
||||
st->inputstate = ANS_IDLE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case ANS_ESCSEQ_1:
|
||||
{
|
||||
switch(cl) {
|
||||
case ACC_C0:
|
||||
case ACC_INTERM:
|
||||
break;
|
||||
case ACC_PARAM:
|
||||
/* Private function*/
|
||||
case ACC_LOWCASE:
|
||||
case ACC_UPCASE:
|
||||
/* Standard function */
|
||||
default:
|
||||
st->inputstate = ANS_IDLE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case ANS_SS3:
|
||||
{
|
||||
switch(cl) {
|
||||
case ACC_PARAM:
|
||||
if (st->ctrlCnt < CTK_TERM_CTRLBUFLEN) st->ctrlbuf[st->ctrlCnt++]=c;
|
||||
break;
|
||||
case ACC_UPCASE:
|
||||
/* VT100 PF seq */
|
||||
if (st->ctrlCnt < CTK_TERM_CTRLBUFLEN) st->ctrlbuf[st->ctrlCnt++]=c;
|
||||
st->inputstate = ANS_IDLE;
|
||||
st->ctrlbuf[st->ctrlCnt] = 0;
|
||||
lookup_seq((const char*)(st->ctrlbuf), ss3map);
|
||||
break;
|
||||
default:
|
||||
st->inputstate = ANS_IDLE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case ANS_CTRLSEQ:
|
||||
{
|
||||
switch(cl) {
|
||||
case ACC_C0:
|
||||
break;
|
||||
case ACC_INTERM:
|
||||
case ACC_PARAM:
|
||||
if (st->ctrlCnt < CTK_TERM_CTRLBUFLEN) st->ctrlbuf[st->ctrlCnt++]=c;
|
||||
break;
|
||||
case ACC_LOWCASE:
|
||||
case ACC_UPCASE:
|
||||
/* Standard control sequence */
|
||||
if (st->ctrlCnt < CTK_TERM_CTRLBUFLEN) st->ctrlbuf[st->ctrlCnt++]=c;
|
||||
/* Cygwin console sends ESC [ [ A for function keys */
|
||||
if (c != '[') {
|
||||
st->ctrlbuf[st->ctrlCnt] = 0;
|
||||
lookup_seq((const char*)(st->ctrlbuf), ctrlmap);
|
||||
st->inputstate = ANS_IDLE;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
st->inputstate = ANS_IDLE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
/*
|
||||
* Initialize the input buffer
|
||||
*/
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
void ctk_term_input_init()
|
||||
{
|
||||
firstkey = lastkey = 0;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
/**
|
||||
* Handles an input character provided by the client
|
||||
*
|
||||
* \param ts State information
|
||||
* \param b Input character
|
||||
*/
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
void ctk_term_input(struct ctk_term_state* ts, unsigned char b)
|
||||
{
|
||||
int ret = parse_input(ts, b);
|
||||
PRINTF(("terminput: 0x%02x\n", b));
|
||||
if (ret > 0) {
|
||||
enqueue_key((ctk_arch_key_t)b);
|
||||
}
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
/**
|
||||
* Checks the key press input queue to see if there are pending
|
||||
* keys. Called by the CTK module.
|
||||
*
|
||||
* \return Zero if no key presses are in buffer, non-zero if there are
|
||||
* key presses in input buffer.
|
||||
*/
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
unsigned char
|
||||
ctk_arch_keyavail(void)
|
||||
{
|
||||
return firstkey != lastkey;
|
||||
}
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
/**
|
||||
* Retrieves key presses from the VNC client. Called by the CTK
|
||||
* module.
|
||||
*
|
||||
* \return The next key in the input queue.
|
||||
*/
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
ctk_arch_key_t
|
||||
ctk_arch_getkey(void)
|
||||
{
|
||||
ctk_arch_key_t key;
|
||||
key = keys[firstkey];
|
||||
|
||||
if(firstkey != lastkey) {
|
||||
++firstkey;
|
||||
if(firstkey >= NUMKEYS) {
|
||||
firstkey = 0;
|
||||
}
|
||||
}
|
||||
|
||||
return key;
|
||||
}
|
||||
|
|
@ -1,99 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2005, Swedish Institute of Computer Science
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. 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.
|
||||
* 3. Neither the name of the Institute 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 INSTITUTE 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 INSTITUTE 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.
|
||||
*
|
||||
* This file is part of the Contiki operating system.
|
||||
*
|
||||
* @(#)$Id: ctk-term-int.h,v 1.1 2007/05/26 21:54:33 oliverschmidt Exp $
|
||||
*/
|
||||
#ifndef __CTK_TERM_INT_H__
|
||||
#define __CTK_TERM_INT_H__
|
||||
|
||||
/* Color definitions */
|
||||
|
||||
#define TERM_BACKGROUNDCOLOR 0
|
||||
#define TERM_WINDOWCOLOR 1
|
||||
#define TERM_SEPARATORCOLOR 7 /*(TERM_WINDOWCOLOR + 6)*/
|
||||
#define TERM_LABELCOLOR 13 /*(TERM_SEPARATORCOLOR + 6)*/
|
||||
#define TERM_BUTTONCOLOR 19 /*(TERM_LABELCOLOR + 6)*/
|
||||
#define TERM_HYPERLINKCOLOR 25 /*(TERM_BUTTONCOLOR + 6)*/
|
||||
#define TERM_TEXTENTRYCOLOR 31 /*(TERM_HYPERLINKCOLOR + 6)*/
|
||||
#define TERM_ICONCOLOR 37 /*(TERM_TEXTENTRYCOLOR + 6)*/
|
||||
#define TERM_MENUCOLOR 43 /*(TERM_ICONCOLOR + 6)*/
|
||||
#define TERM_OPENMENUCOLOR 44/*(TERM_MENUCOLOR + 1)*/
|
||||
#define TERM_ACTIVEMENUCOLOR 45 /*(TERM_OPENMENUCOLOR + 1) */
|
||||
|
||||
/* Structure describing an updated region */
|
||||
struct ctk_term_update {
|
||||
struct ctk_term_update *next;
|
||||
|
||||
#define UPDATE_NONE 0
|
||||
#define UPDATE_PARTS 1
|
||||
#define UPDATE_FULL 2
|
||||
|
||||
unsigned char type;
|
||||
|
||||
unsigned char x, y;
|
||||
unsigned char w, h;
|
||||
};
|
||||
|
||||
/* Character sequence parsing states */
|
||||
enum { ANS_IDLE, ANS_ESCSEQ,ANS_ESCSEQ_1,ANS_SS3, ANS_CTRLSEQ};
|
||||
|
||||
struct ctk_term_state {
|
||||
unsigned char type;
|
||||
unsigned char state;
|
||||
unsigned char height, width;
|
||||
|
||||
/* Variables used when sending screen updates. */
|
||||
unsigned char x, y, x1, y1, x2, y2;
|
||||
unsigned char w, h;
|
||||
unsigned char c1, c2;
|
||||
|
||||
#define CTK_TERM_MAX_UPDATES 8
|
||||
struct ctk_term_update *updates_current;
|
||||
struct ctk_term_update *updates_pending;
|
||||
struct ctk_term_update *updates_free;
|
||||
struct ctk_term_update updates_pool[CTK_TERM_MAX_UPDATES];
|
||||
|
||||
/* Variables used when parsing input sequences */
|
||||
unsigned char inputstate;
|
||||
#define CTK_TERM_CTRLBUFLEN 5
|
||||
unsigned char ctrlbuf[CTK_TERM_CTRLBUFLEN+1];
|
||||
unsigned char ctrlCnt;
|
||||
};
|
||||
|
||||
struct ctk_term_update * ctk_term_update_alloc(struct ctk_term_state *vs);
|
||||
void ctk_term_update_free(struct ctk_term_state *ts, struct ctk_term_update *a);
|
||||
void ctk_term_update_remove(struct ctk_term_state *ts, struct ctk_term_update *a);
|
||||
|
||||
void ctk_term_update_add(struct ctk_term_state *ts, struct ctk_term_update *a);
|
||||
struct ctk_term_update * ctk_term_update_dequeue(struct ctk_term_state *ts);
|
||||
|
||||
void ctk_term_input_init();
|
||||
|
||||
#endif /* __CTK_TERM_INT_H__ */
|
|
@ -1,350 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2005, Swedish Institute of Computer Science
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. 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.
|
||||
* 3. Neither the name of the Institute 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 INSTITUTE 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 INSTITUTE 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.
|
||||
*
|
||||
* This file is part of the Contiki operating system.
|
||||
*
|
||||
* @(#)$Id: ctk-term-out.c,v 1.1 2007/05/26 21:54:33 oliverschmidt Exp $
|
||||
*/
|
||||
#include "libconio.h"
|
||||
#include "ctk-term-int.h"
|
||||
#include <string.h>
|
||||
#include <stdio.h> // sprintf
|
||||
|
||||
#define PRINTF(x)
|
||||
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
/*
|
||||
* #defines and enums
|
||||
*/
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
|
||||
#define CHARS_WIDTH LIBCONIO_CONF_SCREEN_WIDTH
|
||||
#define CHARS_HEIGHT LIBCONIO_CONF_SCREEN_HEIGHT
|
||||
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
/*
|
||||
* Local variables
|
||||
*/
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
|
||||
/* ANSI/VT100 colors
|
||||
0 - None
|
||||
1 - Bold (inc. inten)
|
||||
4 - Underscore
|
||||
7 - Reverse
|
||||
x0 - black
|
||||
x1 - red
|
||||
x2 - green
|
||||
x3 - yellow
|
||||
x4 - blue
|
||||
x5 - magenta
|
||||
x6 - cyan
|
||||
x7 - white
|
||||
x = 3 fg x = 4 bg
|
||||
*/
|
||||
#if 0 /* Colorfull theme */
|
||||
static const char backgroundcolor[] = "\033[0;37;40m";
|
||||
|
||||
static const char wincol[] = "\033[0;37;40m";
|
||||
static const char wincol_f[] = "\033[0;1;37;40m";
|
||||
static const char wincol_d[] = "\033[0;30;47m";
|
||||
|
||||
static const char sepcol[] = "\033[0;37;40m";
|
||||
static const char sepcol_f[] = "\033[0;1;37;40m";
|
||||
static const char sepcol_d[] = "\033[0;30;47m";
|
||||
|
||||
static const char labcol[] = "\033[0;37;40m";
|
||||
static const char labcol_f[] = "\033[1;37;40m";
|
||||
static const char labcol_d[] = "\033[0;30;47m";
|
||||
|
||||
static const char butcol[] = "\033[0;37;40m";
|
||||
static const char butcol_w[] = "\033[0;30;47m";
|
||||
static const char butcol_f[] = "\033[0;1;37;40m";
|
||||
static const char butcol_fw[] = "\033[0;1;37;46m";
|
||||
static const char butcol_d[] = "\033[0;30;47m";
|
||||
static const char butcol_dw[] = "\033[0;37;46m";
|
||||
|
||||
static const char hlcol[] = "\033[0;4;36;40m";
|
||||
static const char hlcol_w[] = "\033[0;4;30;47m";
|
||||
static const char hlcol_f[] = "\033[0;1;4;36;40m";
|
||||
static const char hlcol_fw[] = "\033[0;1;4;37;46m";
|
||||
static const char hlcol_d[] = "\033[0;4;34;47m";
|
||||
static const char hlcol_dw[] = "\033[0;4;37;46m";
|
||||
|
||||
static const char iconcol[] = "\033[0;32;40m";
|
||||
static const char iconcol_w[] = "\033[0;30;42m";
|
||||
|
||||
static const char menucolor[] = "\033[0;37;43m";
|
||||
static const char activemenucolor[] = "\033[0;1;37;43m";
|
||||
#endif
|
||||
|
||||
#if 1 /* B/W theme */
|
||||
static const char backgroundcolor[] = "\033[0m";
|
||||
|
||||
static const char wincol[] = "\033[0m";
|
||||
static const char wincol_f[] = "\033[0;1m";
|
||||
static const char wincol_d[] = "\033[0;7m";
|
||||
|
||||
static const char sepcol[] = "\033[0m";
|
||||
static const char sepcol_f[] = "\033[0;1m";
|
||||
static const char sepcol_d[] = "\033[0;7m";
|
||||
|
||||
static const char labcol[] = "\033[0m";
|
||||
static const char labcol_f[] = "\033[0;1m";
|
||||
static const char labcol_d[] = "\033[0;7m";
|
||||
|
||||
static const char butcol[] = "\033[0m";
|
||||
static const char butcol_w[] = "\033[0m";
|
||||
static const char butcol_f[] = "\033[0;1m";
|
||||
static const char butcol_fw[] = "\033[0;1;7m";
|
||||
static const char butcol_d[] = "\033[0;7m";
|
||||
static const char butcol_dw[] = "\033[0m";
|
||||
|
||||
static const char hlcol[] = "\033[0;4m";
|
||||
static const char hlcol_w[] = "\033[0;4;7m";
|
||||
static const char hlcol_f[] = "\033[0;1;4m";
|
||||
static const char hlcol_fw[] = "\033[0;1;4;7m";
|
||||
static const char hlcol_d[] = "\033[0;4;7m";
|
||||
static const char hlcol_dw[] = "\033[0;4m";
|
||||
|
||||
static const char iconcol[] = "\033[0m";
|
||||
static const char iconcol_w[] = "\033[0;7m";
|
||||
|
||||
static const char menucolor[] = "\033[0;7m";
|
||||
static const char activemenucolor[] = "\033[0m";
|
||||
|
||||
#endif
|
||||
|
||||
static const char* const colortheme[] =
|
||||
{
|
||||
backgroundcolor,
|
||||
|
||||
/* Window colors */
|
||||
wincol, wincol, wincol_f, wincol_f, wincol_d, wincol_d,
|
||||
|
||||
/* Separator colors. */
|
||||
sepcol, sepcol, sepcol_f, sepcol_f, sepcol_d, sepcol_d,
|
||||
|
||||
/* Label colors. */
|
||||
labcol, labcol, labcol_f, labcol_f, labcol_d, labcol_d,
|
||||
|
||||
/* Button colors. */
|
||||
butcol, butcol_w, butcol_f, butcol_fw, butcol_d, butcol_dw,
|
||||
|
||||
/* Hyperlink colors. */
|
||||
hlcol, hlcol_w, hlcol_f, hlcol_fw, hlcol_d, hlcol_dw,
|
||||
|
||||
/* Textentry colors. */
|
||||
butcol, butcol_w, butcol_f, butcol_fw, butcol_d, butcol_dw,
|
||||
|
||||
/* Icon colors */
|
||||
iconcol, iconcol_w, iconcol, iconcol_w, iconcol, iconcol_w,
|
||||
|
||||
/* Menu colors. */
|
||||
menucolor, activemenucolor, activemenucolor
|
||||
};
|
||||
|
||||
static unsigned char
|
||||
screen[CHARS_WIDTH * CHARS_HEIGHT],
|
||||
colorscreen[CHARS_WIDTH * CHARS_HEIGHT];
|
||||
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
/*
|
||||
* Add a character to the screen buffer
|
||||
*/
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
void
|
||||
ctk_term_out_update_screen(unsigned char xpos,
|
||||
unsigned char ypos,
|
||||
unsigned char c,
|
||||
unsigned char color)
|
||||
{
|
||||
if (c < 0x20) c = 0x20;
|
||||
screen[xpos + ypos * CHARS_WIDTH] = c;
|
||||
colorscreen[xpos + ypos * CHARS_WIDTH] = color;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
/*
|
||||
* Check if there are any updated pending. If so, make the first one current
|
||||
*/
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
static void
|
||||
check_updates(struct ctk_term_state* ts)
|
||||
{
|
||||
if (ts->updates_current != NULL) return;
|
||||
ts->updates_current = ctk_term_update_dequeue(ts);
|
||||
if (ts->updates_current != NULL) {
|
||||
ts->x = ts->updates_current->x;
|
||||
ts->y = ts->updates_current->y;
|
||||
ts->w = ts->updates_current->w;
|
||||
ts->h = ts->updates_current->h;
|
||||
ts->x1 = ts->x2 = ts->x;
|
||||
ts->y1 = ts->y2 = ts->y;
|
||||
}
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
/** \internal
|
||||
* Adds a cursor position change to buffer. Returns 0 if string doesn't fit else
|
||||
* number of bytes actually written is returned.
|
||||
*
|
||||
* \param x X coordinate (screen coordinates)
|
||||
* \param y Y coordinate (screen coordinates)
|
||||
* \param buf Output buffer
|
||||
* \param maxlen Maximum number of bytes to store in buffer
|
||||
*/
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
static unsigned short
|
||||
move_to(unsigned char x, unsigned char y, unsigned char* buf, unsigned short maxlen)
|
||||
{
|
||||
if (maxlen < 14) return 0;
|
||||
return (unsigned short)sprintf((char*)buf, "\033[%d;%dH", y+1, x+1);
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
/** \internal
|
||||
* Adds a attribute string to buffer. Returns 0 if string doesn't fit else
|
||||
* number of bytes actually written is returned.
|
||||
*
|
||||
* \param c Color number
|
||||
* \param buf Output buffer
|
||||
* \param maxlen Maximum number of bytes to store in buffer
|
||||
*/
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
static unsigned short
|
||||
set_color(unsigned char c, unsigned char* buf, unsigned short maxlen)
|
||||
{
|
||||
int len = strlen((const char*)colortheme[c]);
|
||||
if (maxlen < len) return 0;
|
||||
memcpy(buf, colortheme[c], len);
|
||||
return len;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
/**
|
||||
* Stores terminal data in buffer provided by caller. Returns number of bytes written
|
||||
* to the output buffer.
|
||||
*
|
||||
* \param ts State information
|
||||
* \param buf Output buffer
|
||||
* \param maxlen Maximum number of bytes to store in buffer
|
||||
*/
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
unsigned short
|
||||
ctk_term_send(struct ctk_term_state* ts,
|
||||
unsigned char* buf,
|
||||
unsigned short maxlen)
|
||||
{
|
||||
unsigned char x, y, x0;
|
||||
unsigned char col, c;
|
||||
unsigned short tmp;
|
||||
unsigned short totlen;
|
||||
|
||||
check_updates(ts);
|
||||
|
||||
if (ts->updates_current == NULL) return 0;
|
||||
|
||||
x0 = ts->x1;
|
||||
col = ts->c1;
|
||||
totlen = 0;
|
||||
/* Loop across the update region starting at (x1,y1) */
|
||||
for(y = ts->y1; y < ts->y + ts->h; ++y) {
|
||||
for(x = x0; x < ts->x + ts->w; ++x) {
|
||||
/* New line ? */
|
||||
if (x == ts->x) {
|
||||
/* Move cursor to start of line */
|
||||
tmp = move_to(x,y,buf,maxlen);
|
||||
if (tmp == 0) goto loopend;
|
||||
buf += tmp;
|
||||
totlen += tmp;
|
||||
maxlen -= tmp;
|
||||
}
|
||||
/* Check color */
|
||||
c = colorscreen[x + y * CHARS_WIDTH];
|
||||
if (c != col) {
|
||||
PRINTF(("colorchange at (%d, %d) to %d\n", x,y,c));
|
||||
/* Send new color information */
|
||||
tmp = set_color(c, buf, maxlen);
|
||||
if (tmp == 0) goto loopend;
|
||||
col = c;
|
||||
buf += tmp;
|
||||
totlen += tmp;
|
||||
maxlen -= tmp;
|
||||
}
|
||||
/* Check remaining space */
|
||||
if (maxlen < 1) goto loopend;
|
||||
/* Add character */
|
||||
*buf = screen[x + y * CHARS_WIDTH];
|
||||
buf++;
|
||||
maxlen--;
|
||||
totlen++;
|
||||
}
|
||||
x0 = ts->x;
|
||||
}
|
||||
loopend:
|
||||
/* Always save current color state */
|
||||
ts->c2 = col;
|
||||
PRINTF(("ending loop at (%d, %d)\n", x,y));
|
||||
/* Check if done */
|
||||
if (x == ts->x+ts->w && y == ts->y+ts->h) {
|
||||
/* Signal done with this update */
|
||||
ts->x2 = ts->y2 = 0;
|
||||
}
|
||||
else {
|
||||
/* Not done. Save state */
|
||||
ts->x2 = x;
|
||||
ts->y2 = y;
|
||||
}
|
||||
return totlen;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
/**
|
||||
* Called by client when the data returned by ctk_term_send() are successfully sent.
|
||||
*
|
||||
* \param ts State information
|
||||
*/
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
void ctk_term_sent(struct ctk_term_state* ts)
|
||||
{
|
||||
if (ts->updates_current != NULL) {
|
||||
/* Check if current update done */
|
||||
if (ts->x2 == 0 && ts->y2 == 0) {
|
||||
/* Yes, free it */
|
||||
ctk_term_update_free(ts, ts->updates_current);
|
||||
ts->updates_current = NULL;
|
||||
}
|
||||
else {
|
||||
/* Nop. Update start posititions */
|
||||
ts->x1 = ts->x2;
|
||||
ts->y1 = ts->y2;
|
||||
}
|
||||
ts->c1 = ts->c2;
|
||||
}
|
||||
}
|
|
@ -1,42 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2005, Swedish Institute of Computer Science
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. 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.
|
||||
* 3. Neither the name of the Institute 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 INSTITUTE 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 INSTITUTE 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.
|
||||
*
|
||||
* This file is part of the Contiki operating system.
|
||||
*
|
||||
* @(#)$Id: ctk-term-out.h,v 1.1 2007/05/26 21:54:33 oliverschmidt Exp $
|
||||
*/
|
||||
#ifndef __CTK_TERM_OUT_H__
|
||||
#define __CTK_TERM_OUT_H__
|
||||
|
||||
void
|
||||
ctk_term_out_update_screen(unsigned char xpos,
|
||||
unsigned char ypos,
|
||||
unsigned char c,
|
||||
unsigned char color);
|
||||
|
||||
#endif /* __CTK_TERM_OUT_H__ */
|
File diff suppressed because it is too large
Load diff
|
@ -1,46 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2005, Swedish Institute of Computer Science
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. 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.
|
||||
* 3. Neither the name of the Institute 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 INSTITUTE 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 INSTITUTE 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.
|
||||
*
|
||||
* This file is part of the Contiki operating system.
|
||||
*
|
||||
* @(#)$Id: ctk-term.h,v 1.1 2007/05/26 21:54:33 oliverschmidt Exp $
|
||||
*/
|
||||
#ifndef __CTK_TERM_H__
|
||||
#define __CTK_TERM_H__
|
||||
|
||||
struct ctk_term_state* ctk_term_alloc_state(void);
|
||||
void ctk_term_dealloc_state(struct ctk_term_state *s);
|
||||
void ctk_term_redraw(struct ctk_term_state *s);
|
||||
void ctk_term_sent(struct ctk_term_state* ts);
|
||||
unsigned short ctk_term_send(struct ctk_term_state* ts,
|
||||
unsigned char* buf,
|
||||
unsigned short maxlen);
|
||||
|
||||
void ctk_term_input(struct ctk_term_state* ts, unsigned char b);
|
||||
|
||||
#endif /* __CTK_TERM_H__ */
|
|
@ -1,58 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2005, Swedish Institute of Computer Science
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. 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.
|
||||
* 3. Neither the name of the Institute 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 INSTITUTE 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 INSTITUTE 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.
|
||||
*
|
||||
* This file is part of the Contiki operating system.
|
||||
*
|
||||
* @(#)$Id: ctk-termarch.h,v 1.1 2007/05/26 21:54:33 oliverschmidt Exp $
|
||||
*/
|
||||
#ifndef __CTK_TERMARCH_H__
|
||||
#define __CTK_TERMARCH_H__
|
||||
|
||||
|
||||
typedef char ctk_arch_key_t;
|
||||
|
||||
unsigned char ctk_arch_keyavail(void);
|
||||
ctk_arch_key_t ctk_arch_getkey(void);
|
||||
|
||||
#define CH_ENTER 0x0d
|
||||
#define CH_DEL 0x08
|
||||
|
||||
#define CH_TAB 0x09
|
||||
|
||||
#define CH_CURS_LEFT 0x11
|
||||
#define CH_CURS_UP 0x12
|
||||
#define CH_CURS_RIGHT 0x13
|
||||
#define CH_CURS_DOWN 0x14
|
||||
|
||||
|
||||
#define CH_F1 0x15
|
||||
#define CH_F2 0x16
|
||||
#define CH_F3 0x17
|
||||
#define CH_F4 0x18
|
||||
|
||||
#endif /* __CTK_TERMARCH_H__ */
|
|
@ -1,110 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2005, Swedish Institute of Computer Science
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. 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.
|
||||
* 3. Neither the name of the Institute 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 INSTITUTE 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 INSTITUTE 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.
|
||||
*
|
||||
* This file is part of the Contiki operating system.
|
||||
*
|
||||
* @(#)$Id: ctk-termserial.c,v 1.1 2007/05/26 21:46:28 oliverschmidt Exp $
|
||||
*/
|
||||
#include "contiki.h"
|
||||
#include "loader.h"
|
||||
#include "ctk-term.h"
|
||||
#include "serial32.h"
|
||||
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
/*
|
||||
* #defines and enums
|
||||
*/
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
#define SIO_POLL(c) (SerialRead(&c) == 1)
|
||||
#define SIO_SEND(c) SerialWrite(c)
|
||||
#define SIO_INIT SerialOpenPort("COM1")
|
||||
|
||||
#ifdef CTK_TERM_CONF_SERIAL_BUFFER_SIZE
|
||||
#define OUTPUT_BUFFER_SIZE CTK_TERM_CONF_SERIAL_BUFFER_SIZE
|
||||
#else
|
||||
#define OUTPUT_BUFFER_SIZE 200
|
||||
#endif
|
||||
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
/*
|
||||
* Local variables
|
||||
*/
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
static ek_id_t id = EK_ID_NONE;
|
||||
|
||||
static struct ctk_term_state* termstate;
|
||||
static unsigned char outbuffer[OUTPUT_BUFFER_SIZE];
|
||||
|
||||
EK_POLLHANDLER(pollhandler);
|
||||
EK_EVENTHANDLER(eventhandler, ev, data);
|
||||
EK_PROCESS(p, "CTK serial server", EK_PRIO_NORMAL,
|
||||
eventhandler, pollhandler, NULL);
|
||||
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
/*
|
||||
* Idle function
|
||||
*/
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
EK_POLLHANDLER(pollhandler)
|
||||
{
|
||||
unsigned char c;
|
||||
unsigned short len;
|
||||
while(SIO_POLL(c)) {
|
||||
ctk_term_input(termstate, c);
|
||||
}
|
||||
|
||||
len = ctk_term_send(termstate, outbuffer, OUTPUT_BUFFER_SIZE);
|
||||
if (len > 0) {
|
||||
unsigned short i;
|
||||
for (i=0; i < len; ++i) {
|
||||
SIO_SEND(outbuffer[i]);
|
||||
}
|
||||
ctk_term_sent(termstate);
|
||||
}
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
/*
|
||||
* Init function
|
||||
*/
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
LOADER_INIT_FUNC(ctk_termserial_init, arg)
|
||||
{
|
||||
arg_free(arg);
|
||||
SIO_INIT;
|
||||
termstate = ctk_term_alloc_state();
|
||||
if (termstate == NULL) return;
|
||||
if(id == EK_ID_NONE) {
|
||||
id = ek_start(&p);
|
||||
}
|
||||
}
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
EK_EVENTHANDLER(eventhandler, ev, data)
|
||||
{
|
||||
|
||||
}
|
|
@ -1,38 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2005, Swedish Institute of Computer Science
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. 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.
|
||||
* 3. Neither the name of the Institute 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 INSTITUTE 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 INSTITUTE 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.
|
||||
*
|
||||
* This file is part of the Contiki operating system.
|
||||
*
|
||||
* @(#)$Id: ctk-termserial.h,v 1.1 2007/05/26 21:46:28 oliverschmidt Exp $
|
||||
*/
|
||||
#ifndef __CTK_TERMSERIAL_H__
|
||||
#define __CTK_TERMSERIAL_H__
|
||||
|
||||
void ctk_termserial_init(char *arg);
|
||||
|
||||
#endif /* __CTK_TERMSERIAL_H__ */
|
|
@ -1,655 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2005, Swedish Institute of Computer Science
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. 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.
|
||||
* 3. Neither the name of the Institute 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 INSTITUTE 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 INSTITUTE 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.
|
||||
*
|
||||
* This file is part of the Contiki operating system.
|
||||
*
|
||||
* @(#)$Id: ctk-termtelnet.c,v 1.2 2010/10/19 18:29:03 adamdunkels Exp $
|
||||
*/
|
||||
#include "contiki.h"
|
||||
#include "loader.h"
|
||||
#include "memb.h"
|
||||
#include "ctk-term.h"
|
||||
#include "contiki-conf.h"
|
||||
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
/*
|
||||
* #defines and enums
|
||||
*/
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
/* Telnet special characters */
|
||||
#define TN_NULL 0
|
||||
#define TN_BL 7
|
||||
#define TN_BS 8
|
||||
#define TN_HT 9
|
||||
#define TN_LF 10
|
||||
#define TN_VT 11
|
||||
#define TN_FF 12
|
||||
#define TN_CR 13
|
||||
|
||||
/* Commands preceeded by TN_IAC */
|
||||
#define TN_SE 240
|
||||
#define TN_NOP 241
|
||||
#define TN_DM 242
|
||||
#define TN_BRK 243
|
||||
#define TN_IP 244
|
||||
#define TN_AO 245
|
||||
#define TN_AYT 246
|
||||
#define TN_EC 247
|
||||
#define TN_EL 248
|
||||
#define TN_GA 249
|
||||
#define TN_SB 250
|
||||
#define TN_WILL 251
|
||||
#define TN_WONT 252
|
||||
#define TN_DO 253
|
||||
#define TN_DONT 254
|
||||
#define TN_IAC 255
|
||||
|
||||
#define TNO_BIN 0
|
||||
#define TNO_ECHO 1
|
||||
#define TNO_SGA 3
|
||||
#define TNO_NAWS 31
|
||||
|
||||
/* Telnet parsing states */
|
||||
enum {
|
||||
TNS_IDLE,
|
||||
TNS_IAC,
|
||||
TNS_OPT,
|
||||
TNS_SB,
|
||||
TNS_SBIAC
|
||||
};
|
||||
|
||||
/* Telnet option negotiation states */
|
||||
enum {
|
||||
TNOS_NO,
|
||||
TNOS_WANTNO_EMPTY,
|
||||
TNOS_WANTNO_OPPOSITE,
|
||||
TNOS_WANTYES_EMPTY,
|
||||
TNOS_WANTYES_OPPOSITE,
|
||||
TNOS_YES
|
||||
};
|
||||
|
||||
/* Telnet session states */
|
||||
enum {
|
||||
TTS_FREE, /* Not allocated */
|
||||
TTS_IDLE, /* No data to send and nothing sent */
|
||||
TTS_SEND_TNDATA, /* Sending telnet data */
|
||||
TTS_SEND_APPDATA /* Sending data from upper layers */
|
||||
};
|
||||
|
||||
/* Number of options supported (we only need ECHO(1) and SGA(3) options) */
|
||||
#define TNSM_MAX_OPTIONS 4
|
||||
|
||||
/* Max option replies in output queue */
|
||||
#define TNQLEN 20
|
||||
|
||||
/* Number of option buffer */
|
||||
#define OPTION_POOL_SIZE 20
|
||||
|
||||
/* Maximum number of telnet sessions */
|
||||
#ifdef CTK_TERM_CONF_MAX_TELNET_CLIENTS
|
||||
#define NUM_CONNS CTK_TERM_CONF_MAX_TELNET_CLIENTS
|
||||
#else
|
||||
#define NUM_CONNS 1
|
||||
#endif
|
||||
|
||||
#ifdef CTK_TERM_CONF_TELNET_PORT
|
||||
#define PORT CTK_TERM_CONF_TELNET_PORT
|
||||
#else
|
||||
#define PORT 23
|
||||
#endif
|
||||
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
/*
|
||||
* Structures
|
||||
*/
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
/* Telnet option state structure */
|
||||
struct TNOption {
|
||||
unsigned char state;
|
||||
unsigned char wants;
|
||||
};
|
||||
|
||||
/* Telnet handling state structure */
|
||||
struct TNSMState
|
||||
{
|
||||
struct TNOption myOpt[TNSM_MAX_OPTIONS];
|
||||
struct TNOption hisOpt[TNSM_MAX_OPTIONS];
|
||||
unsigned char cmd;
|
||||
unsigned char state;
|
||||
};
|
||||
|
||||
/* Telnet session state */
|
||||
struct telnet_state
|
||||
{
|
||||
unsigned char state;
|
||||
unsigned char* sendq[TNQLEN];
|
||||
struct TNSMState tnsm;
|
||||
struct ctk_term_state* termstate;
|
||||
};
|
||||
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
/*
|
||||
* Local variables
|
||||
*/
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
/*static DISPATCHER_UIPCALL(ctk_termtelnet_appcall, state);*/
|
||||
static void ctk_termtelnet_appcall(void *state);
|
||||
|
||||
EK_EVENTHANDLER(eventhandler, ev, data);
|
||||
EK_PROCESS(p, "CTK telnet server", EK_PRIO_NORMAL,
|
||||
eventhandler, NULL, NULL);
|
||||
/*static struct dispatcher_proc p =
|
||||
{DISPATCHER_PROC("CTK telnet server", NULL, NULL,
|
||||
ctk_termtelnet_appcall)};*/
|
||||
|
||||
static ek_id_t id = EK_ID_NONE;
|
||||
|
||||
/* Option negotiation buffer pool */
|
||||
struct size_3 {
|
||||
char size[3];
|
||||
};
|
||||
MEMB(telnetbuf, struct size_3, OPTION_POOL_SIZE);
|
||||
|
||||
static int i,j;
|
||||
static struct telnet_state states[NUM_CONNS];
|
||||
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
/*
|
||||
* Send an option reply on a connection
|
||||
*/
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
static void
|
||||
Reply(struct telnet_state* tns, unsigned char cmd, unsigned char opt)
|
||||
{
|
||||
unsigned char* buf = (unsigned char*)memb_alloc(&telnetbuf);
|
||||
if (buf != 0) {
|
||||
buf[0]=TN_IAC;
|
||||
buf[1]=cmd;
|
||||
buf[2]=opt;
|
||||
for (i=0; i < TNQLEN; i++) {
|
||||
if (tns->sendq[i] == 0) {
|
||||
tns->sendq[i] = buf;
|
||||
return;
|
||||
}
|
||||
}
|
||||
/* Queue is full. Drop it */
|
||||
memb_free(&telnetbuf, (char*)buf);
|
||||
}
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
/*
|
||||
* Prepare for enabling one of remote side options.
|
||||
*/
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
static void
|
||||
EnableHisOpt(struct telnet_state* tns, unsigned char opt)
|
||||
{
|
||||
switch(tns->tnsm.hisOpt[opt].state) {
|
||||
case TNOS_NO:
|
||||
tns->tnsm.hisOpt[opt].wants = 1;
|
||||
tns->tnsm.hisOpt[opt].state = TNOS_WANTYES_EMPTY;
|
||||
Reply(tns, TN_DO, opt);
|
||||
break;
|
||||
case TNOS_WANTNO_EMPTY:
|
||||
tns->tnsm.hisOpt[opt].state = TNOS_WANTNO_OPPOSITE;
|
||||
break;
|
||||
case TNOS_WANTNO_OPPOSITE:
|
||||
break;
|
||||
case TNOS_WANTYES_EMPTY:
|
||||
tns->tnsm.hisOpt[opt].state = TNOS_YES;
|
||||
break;
|
||||
case TNOS_WANTYES_OPPOSITE:
|
||||
tns->tnsm.hisOpt[opt].state = TNOS_WANTYES_EMPTY;
|
||||
break;
|
||||
case TNOS_YES:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
/*
|
||||
* Prepare for enabling one of my options
|
||||
*/
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
static void
|
||||
EnableMyOpt(struct telnet_state* tns, unsigned char opt)
|
||||
{
|
||||
if (opt < TNSM_MAX_OPTIONS) {
|
||||
switch(tns->tnsm.myOpt[opt].state) {
|
||||
case TNOS_NO:
|
||||
tns->tnsm.myOpt[opt].wants = 1;
|
||||
tns->tnsm.myOpt[opt].state = TNOS_WANTYES_EMPTY;
|
||||
Reply(tns, TN_WILL, opt);
|
||||
break;
|
||||
case TNOS_WANTNO_EMPTY:
|
||||
tns->tnsm.myOpt[opt].state = TNOS_WANTNO_OPPOSITE;
|
||||
break;
|
||||
case TNOS_WANTNO_OPPOSITE:
|
||||
break;
|
||||
case TNOS_WANTYES_EMPTY:
|
||||
tns->tnsm.myOpt[opt].state = TNOS_YES;
|
||||
break;
|
||||
case TNOS_WANTYES_OPPOSITE:
|
||||
tns->tnsm.myOpt[opt].state = TNOS_WANTYES_EMPTY;
|
||||
break;
|
||||
case TNOS_YES:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
/*
|
||||
* Implementation of option negotiation using the Q-method
|
||||
*/
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
static void
|
||||
HandleCommand(struct telnet_state* tns, unsigned char cmd, unsigned char opt)
|
||||
{
|
||||
if (opt < TNSM_MAX_OPTIONS) {
|
||||
/* Handling according to RFC 1143 "Q Method" */
|
||||
switch(cmd) {
|
||||
case TN_WILL:
|
||||
switch(tns->tnsm.hisOpt[opt].state) {
|
||||
case TNOS_NO:
|
||||
if (tns->tnsm.hisOpt[opt].wants) {
|
||||
tns->tnsm.hisOpt[opt].state = TNOS_YES;
|
||||
Reply(tns, TN_DO, opt);
|
||||
}
|
||||
else {
|
||||
Reply(tns, TN_DONT, opt);
|
||||
}
|
||||
break;
|
||||
case TNOS_WANTNO_EMPTY:
|
||||
tns->tnsm.hisOpt[opt].state = TNOS_NO;
|
||||
break;
|
||||
case TNOS_WANTNO_OPPOSITE:
|
||||
tns->tnsm.hisOpt[opt].state = TNOS_YES;
|
||||
break;
|
||||
case TNOS_WANTYES_EMPTY:
|
||||
tns->tnsm.hisOpt[opt].state = TNOS_YES;
|
||||
break;
|
||||
case TNOS_WANTYES_OPPOSITE:
|
||||
tns->tnsm.hisOpt[opt].state = TNOS_WANTNO_EMPTY;
|
||||
Reply(tns, TN_DONT, opt);
|
||||
break;
|
||||
case TNOS_YES:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case TN_WONT:
|
||||
switch(tns->tnsm.hisOpt[opt].state) {
|
||||
case TNOS_NO:
|
||||
break;
|
||||
case TNOS_WANTNO_EMPTY:
|
||||
case TNOS_WANTYES_EMPTY:
|
||||
case TNOS_WANTYES_OPPOSITE:
|
||||
tns->tnsm.hisOpt[opt].state = TNOS_NO;
|
||||
break;
|
||||
case TNOS_WANTNO_OPPOSITE:
|
||||
tns->tnsm.hisOpt[opt].state = TNOS_WANTYES_EMPTY;
|
||||
Reply(tns, TN_DO, opt);
|
||||
break;
|
||||
case TNOS_YES:
|
||||
tns->tnsm.hisOpt[opt].state = TNOS_NO;
|
||||
Reply(tns, TN_DONT, opt);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case TN_DO:
|
||||
switch(tns->tnsm.myOpt[opt].state) {
|
||||
case TNOS_NO:
|
||||
if (tns->tnsm.myOpt[opt].wants) {
|
||||
tns->tnsm.myOpt[opt].state = TNOS_YES;
|
||||
Reply(tns, TN_WILL, opt);
|
||||
}
|
||||
else {
|
||||
Reply(tns, TN_WONT, opt);
|
||||
}
|
||||
break;
|
||||
case TNOS_WANTNO_EMPTY:
|
||||
tns->tnsm.myOpt[opt].state = TNOS_NO;
|
||||
break;
|
||||
case TNOS_WANTNO_OPPOSITE:
|
||||
tns->tnsm.myOpt[opt].state = TNOS_YES;
|
||||
break;
|
||||
case TNOS_WANTYES_EMPTY:
|
||||
tns->tnsm.myOpt[opt].state = TNOS_YES;
|
||||
break;
|
||||
case TNOS_WANTYES_OPPOSITE:
|
||||
tns->tnsm.myOpt[opt].state = TNOS_WANTNO_EMPTY;
|
||||
Reply(tns, TN_WONT, opt);
|
||||
break;
|
||||
case TNOS_YES:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case TN_DONT:
|
||||
switch(tns->tnsm.myOpt[opt].state) {
|
||||
case TNOS_NO:
|
||||
break;
|
||||
case TNOS_WANTNO_EMPTY:
|
||||
case TNOS_WANTYES_EMPTY:
|
||||
case TNOS_WANTYES_OPPOSITE:
|
||||
tns->tnsm.myOpt[opt].state = TNOS_NO;
|
||||
break;
|
||||
case TNOS_WANTNO_OPPOSITE:
|
||||
tns->tnsm.myOpt[opt].state = TNOS_WANTYES_EMPTY;
|
||||
Reply(tns, TN_WILL, opt);
|
||||
break;
|
||||
case TNOS_YES:
|
||||
tns->tnsm.myOpt[opt].state = TNOS_NO;
|
||||
Reply(tns, TN_WONT, opt);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
else {
|
||||
switch(cmd) {
|
||||
case TN_WILL:
|
||||
Reply(tns, TN_DONT, opt);
|
||||
break;
|
||||
case TN_WONT:
|
||||
break;
|
||||
case TN_DO:
|
||||
Reply(tns, TN_WONT, opt);
|
||||
break;
|
||||
case TN_DONT:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
/*
|
||||
* Telnet data parsing
|
||||
*/
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
static unsigned char
|
||||
parse_input(struct telnet_state* tns, unsigned char b)
|
||||
{
|
||||
unsigned char ret = 0;
|
||||
switch(tns->tnsm.state) {
|
||||
case TNS_IDLE:
|
||||
if (b == TN_IAC) tns->tnsm.state = TNS_IAC;
|
||||
else ret = 1;
|
||||
break;
|
||||
case TNS_IAC:
|
||||
switch(b) {
|
||||
case TN_SE:
|
||||
case TN_NOP:
|
||||
case TN_DM:
|
||||
case TN_BRK:
|
||||
case TN_IP:
|
||||
case TN_AO:
|
||||
case TN_AYT:
|
||||
case TN_EC:
|
||||
case TN_EL:
|
||||
case TN_GA:
|
||||
tns->tnsm.state = TNS_IDLE;
|
||||
break;
|
||||
case TN_SB:
|
||||
tns->tnsm.state = TNS_SB;
|
||||
break;
|
||||
case TN_WILL:
|
||||
case TN_WONT:
|
||||
case TN_DO:
|
||||
case TN_DONT:
|
||||
tns->tnsm.cmd = b;
|
||||
tns->tnsm.state = TNS_OPT;
|
||||
break;
|
||||
case TN_IAC:
|
||||
tns->tnsm.state = TNS_IDLE;
|
||||
ret = 1;
|
||||
break;
|
||||
default:
|
||||
/* Drop unknown IACs */
|
||||
tns->tnsm.state = TNS_IDLE;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case TNS_OPT:
|
||||
HandleCommand(tns, tns->tnsm.cmd, b);
|
||||
tns->tnsm.state = TNS_IDLE;
|
||||
break;
|
||||
case TNS_SB:
|
||||
if (b == TN_IAC) {
|
||||
tns->tnsm.state = TNS_SBIAC;
|
||||
}
|
||||
break;
|
||||
case TNS_SBIAC:
|
||||
if (b == TN_IAC) {
|
||||
tns->tnsm.state = TNS_SB;
|
||||
}
|
||||
else if (b == TN_SE) {
|
||||
tns->tnsm.state = TNS_IDLE;
|
||||
}
|
||||
else {
|
||||
tns->tnsm.state = TNS_IDLE;
|
||||
}
|
||||
break;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
/*
|
||||
* Initialize telnet machine
|
||||
*/
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
static void
|
||||
telnet_init(struct telnet_state* tns)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < TNSM_MAX_OPTIONS; i++) {
|
||||
tns->tnsm.myOpt[i].state = TNOS_NO;
|
||||
tns->tnsm.myOpt[i].wants = 0;
|
||||
tns->tnsm.hisOpt[i].state = TNOS_NO;
|
||||
tns->tnsm.hisOpt[i].wants = 0;
|
||||
}
|
||||
tns->tnsm.state = TNS_IDLE;
|
||||
}
|
||||
|
||||
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
/*
|
||||
* Allocate a telnet session structure (including terminal state)
|
||||
*/
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
static struct telnet_state*
|
||||
alloc_state()
|
||||
{
|
||||
for (i=0; i < NUM_CONNS; i++) {
|
||||
if (states[i].state == TTS_FREE) {
|
||||
states[i].termstate = ctk_term_alloc_state();
|
||||
if (states[i].termstate != NULL) {
|
||||
for (j = 0; j < TNQLEN; j++) {
|
||||
states[i].sendq[j] = 0;
|
||||
}
|
||||
telnet_init(&states[i]);
|
||||
states[i].state = TTS_IDLE;
|
||||
return &(states[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
/*
|
||||
* Free a telnet session structure (including terminal state)
|
||||
*/
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
static void
|
||||
free_state(struct telnet_state* tns)
|
||||
{
|
||||
if (tns != NULL) {
|
||||
ctk_term_dealloc_state(tns->termstate);
|
||||
tns->state = TTS_FREE;
|
||||
}
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
/*
|
||||
* A packet is successfully sent
|
||||
*/
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
static void
|
||||
acked(struct telnet_state* tns)
|
||||
{
|
||||
/* Were we sending a telnet option packet? */
|
||||
if (tns->state == TTS_SEND_TNDATA) {
|
||||
/* Yes, free it and update queue */
|
||||
if (tns->sendq[0] != 0) {
|
||||
memb_free(&telnetbuf, (char*)(tns->sendq[0]));
|
||||
for (i=1; i < TNQLEN; i++) {
|
||||
tns->sendq[i-1] = tns->sendq[i];
|
||||
}
|
||||
tns->sendq[TNQLEN-1] = 0;
|
||||
/* No options left. Go idle */
|
||||
if (tns->sendq[0] == 0) {
|
||||
tns->state = TTS_IDLE;
|
||||
}
|
||||
}
|
||||
}
|
||||
/* Or were we sending application date ? */
|
||||
else if (tns->state == TTS_SEND_APPDATA) {
|
||||
/* Inform application that data is sent successfully */
|
||||
ctk_term_sent(tns->termstate);
|
||||
tns->state = TTS_IDLE;
|
||||
}
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
/*
|
||||
* Send data on a connections
|
||||
*/
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
static void
|
||||
senddata(struct telnet_state* tns)
|
||||
{
|
||||
/* Check if there are any option packets to send */
|
||||
if (tns->state == TTS_IDLE || tns->state == TTS_SEND_TNDATA) {
|
||||
if (tns->sendq[0] != 0) {
|
||||
tns->state = TTS_SEND_TNDATA;
|
||||
uip_send(tns->sendq[0],3);
|
||||
}
|
||||
}
|
||||
/* Check if terminal wants to send any data */
|
||||
if (tns->state == TTS_IDLE || tns->state == TTS_SEND_APPDATA) {
|
||||
u16_t len = ctk_term_send(tns->termstate, (unsigned char*)uip_appdata, (unsigned short)uip_mss());
|
||||
if (len > 0) {
|
||||
tns->state = TTS_SEND_APPDATA;
|
||||
uip_send(uip_appdata, len);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
/*
|
||||
* uIP callback
|
||||
*/
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
static void
|
||||
ctk_termtelnet_appcall(void *state)
|
||||
{
|
||||
struct telnet_state *tns;
|
||||
|
||||
tns = (struct telnet_state*)(state);
|
||||
|
||||
if(uip_connected()) {
|
||||
if(tns == NULL) {
|
||||
tns = alloc_state();
|
||||
if(tns == NULL) {
|
||||
uip_close();
|
||||
return;
|
||||
}
|
||||
tcp_markconn(uip_conn, (void *)tns);
|
||||
}
|
||||
/* Try to negotiate some options */
|
||||
EnableHisOpt(tns, TNO_SGA);
|
||||
EnableMyOpt(tns,TNO_SGA);
|
||||
EnableMyOpt(tns,TNO_ECHO);
|
||||
/* Request update of screen */
|
||||
ctk_term_redraw(tns->termstate);
|
||||
senddata(tns);
|
||||
} else if(uip_closed() || uip_aborted()) {
|
||||
free_state(tns);
|
||||
return;
|
||||
}
|
||||
|
||||
if (uip_acked()) {
|
||||
acked(tns);
|
||||
}
|
||||
|
||||
if (uip_newdata()) {
|
||||
for(j = 0; j < uip_datalen(); j++) {
|
||||
if (parse_input(tns, uip_appdata[j])) {
|
||||
/* Pass it uppwards */
|
||||
ctk_term_input(tns->termstate, uip_appdata[j]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(uip_rexmit() ||
|
||||
uip_newdata() ||
|
||||
uip_acked()) {
|
||||
senddata(tns);
|
||||
} else if(uip_poll()) {
|
||||
if (tns->state == TTS_IDLE) {
|
||||
senddata(tns);
|
||||
}
|
||||
}
|
||||
}
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
/*
|
||||
* Init function
|
||||
*/
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
LOADER_INIT_FUNC(ctk_termtelnet_init, arg)
|
||||
{
|
||||
arg_free(arg);
|
||||
if(id == EK_ID_NONE) {
|
||||
memb_init(&telnetbuf);
|
||||
for (i=0; i < NUM_CONNS; i++) {
|
||||
states[i].state = TTS_FREE;
|
||||
}
|
||||
id = ek_start(&p);
|
||||
}
|
||||
}
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
EK_EVENTHANDLER(eventhandler, ev, data)
|
||||
{
|
||||
if(ev == EK_EVENT_INIT) {
|
||||
tcp_listen(UIP_HTONS(PORT));
|
||||
} else if(ev == tcpip_event) {
|
||||
ctk_termtelnet_appcall(data);
|
||||
}
|
||||
}
|
|
@ -1,38 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2005, Swedish Institute of Computer Science
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. 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.
|
||||
* 3. Neither the name of the Institute 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 INSTITUTE 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 INSTITUTE 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.
|
||||
*
|
||||
* This file is part of the Contiki operating system.
|
||||
*
|
||||
* @(#)$Id: ctk-termtelnet.h,v 1.1 2007/05/26 21:46:28 oliverschmidt Exp $
|
||||
*/
|
||||
#ifndef __CTK_TERMTELNET_H__
|
||||
#define __CTK_TERMTELNET_H__
|
||||
|
||||
void ctk_termtelnet_init(char *arg);
|
||||
|
||||
#endif /* __CTK_TERMTELNET_H__ */
|
File diff suppressed because it is too large
Load diff
|
@ -1,668 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2005, Swedish Institute of Computer Science
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. 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.
|
||||
* 3. Neither the name of the Institute 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 INSTITUTE 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 INSTITUTE 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.
|
||||
*
|
||||
* This file is part of the Contiki operating system.
|
||||
*
|
||||
* @(#)$Id: cc2420.c,v 1.1 2008/02/24 22:29:08 adamdunkels Exp $
|
||||
*/
|
||||
/*
|
||||
* This code is almost device independent and should be easy to port.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#if defined(__AVR__)
|
||||
#include <avr/io.h>
|
||||
#elif defined(__MSP430__)
|
||||
#include <io.h>
|
||||
#endif
|
||||
|
||||
#include "contiki.h"
|
||||
|
||||
#include "net/uip.h"
|
||||
#include "net/uip-fw.h"
|
||||
#define BUF ((struct uip_tcpip_hdr *)&uip_buf[UIP_LLH_LEN])
|
||||
|
||||
#include "dev/leds.h"
|
||||
|
||||
#include "dev/spi.h"
|
||||
#include "dev/cc2420.h"
|
||||
#include "dev/cc2420_const.h"
|
||||
|
||||
#define NDEBUG
|
||||
#include "lib/assert.h"
|
||||
|
||||
#ifdef NDEBUG
|
||||
#define PRINTF(...) do {} while (0)
|
||||
#else
|
||||
#define PRINTF(...) printf(__VA_ARGS__)
|
||||
#endif
|
||||
|
||||
PROCESS(cc2420_process, "CC2420 driver");
|
||||
PROCESS(cc2420_retransmit_process, "CC2420 retransmit process");
|
||||
|
||||
int cc2420_resend(void); /* Not yet exported. */
|
||||
|
||||
static void neigbour_update(u16_t mac, int retransmissions);
|
||||
|
||||
signed char cc2420_last_rssi;
|
||||
u8_t cc2420_last_correlation;
|
||||
u8_t cc2420_is_input;
|
||||
|
||||
static u8_t receive_on;
|
||||
|
||||
volatile u8_t cc2420_ack_received; /* Naive ACK management. */
|
||||
static u8_t last_used_seq;
|
||||
static u16_t last_dst;
|
||||
|
||||
/* Radio stuff in network byte order. */
|
||||
static u16_t pan_id;
|
||||
|
||||
unsigned
|
||||
cc2420_getreg(enum cc2420_register regname)
|
||||
{
|
||||
unsigned reg;
|
||||
int s = splhigh();
|
||||
FASTSPI_GETREG(regname, reg);
|
||||
splx(s);
|
||||
return reg;
|
||||
}
|
||||
|
||||
void
|
||||
cc2420_setreg(enum cc2420_register regname, unsigned value)
|
||||
{
|
||||
int s = splhigh();
|
||||
FASTSPI_SETREG(regname, value);
|
||||
splx(s);
|
||||
}
|
||||
|
||||
void
|
||||
cc2420_strobe(enum cc2420_register regname)
|
||||
{
|
||||
int s = splhigh();
|
||||
FASTSPI_STROBE(regname);
|
||||
splx(s);
|
||||
}
|
||||
|
||||
unsigned
|
||||
cc2420_status(void)
|
||||
{
|
||||
u8_t status;
|
||||
int s = splhigh();
|
||||
FASTSPI_UPD_STATUS(status);
|
||||
splx(s);
|
||||
return status;
|
||||
}
|
||||
|
||||
#define AUTOACK (1 << 4)
|
||||
#define RXFIFO_PROTECTION (1 << 9)
|
||||
#define CORR_THR(n) (((n) & 0x1f) << 6)
|
||||
#define FIFOP_THR(n) ((n) & 0x7f)
|
||||
#define RXBPF_LOCUR (1 << 13);
|
||||
|
||||
void
|
||||
cc2420_init(void)
|
||||
{
|
||||
u16_t reg;
|
||||
{
|
||||
int s = splhigh();
|
||||
__cc2420_arch_init(); /* Initalize ports and SPI. */
|
||||
DISABLE_FIFOP_INT();
|
||||
FIFOP_INT_INIT();
|
||||
splx(s);
|
||||
}
|
||||
|
||||
/* Turn on voltage regulator and reset. */
|
||||
SET_VREG_ACTIVE();
|
||||
//clock_delay(250); OK
|
||||
SET_RESET_ACTIVE();
|
||||
clock_delay(127);
|
||||
SET_RESET_INACTIVE();
|
||||
//clock_delay(125); OK
|
||||
|
||||
|
||||
/* Turn on the crystal oscillator. */
|
||||
cc2420_strobe(CC2420_SXOSCON);
|
||||
|
||||
/* Turn on automatic packet acknowledgment. */
|
||||
reg = cc2420_getreg(CC2420_MDMCTRL0);
|
||||
reg |= AUTOACK;
|
||||
cc2420_setreg(CC2420_MDMCTRL0, reg);
|
||||
|
||||
/* Change default values as recomended in the data sheet, */
|
||||
/* correlation threshold = 20, RX bandpass filter = 1.3uA. */
|
||||
cc2420_setreg(CC2420_MDMCTRL1, CORR_THR(20));
|
||||
reg = cc2420_getreg(CC2420_RXCTRL1);
|
||||
reg |= RXBPF_LOCUR;
|
||||
cc2420_setreg(CC2420_RXCTRL1, reg);
|
||||
|
||||
/* Set the FIFOP threshold to maximum. */
|
||||
cc2420_setreg(CC2420_IOCFG0, FIFOP_THR(127));
|
||||
|
||||
/* Turn off "Security enable" (page 32). */
|
||||
reg = cc2420_getreg(CC2420_SECCTRL0);
|
||||
reg &= ~RXFIFO_PROTECTION;
|
||||
cc2420_setreg(CC2420_SECCTRL0, reg);
|
||||
|
||||
cc2420_set_chan_pan_addr(11, 0xffff, 0x0000, NULL);
|
||||
}
|
||||
|
||||
int
|
||||
cc2420_send_data_ack(u16_t mac)
|
||||
{
|
||||
struct hdr_802_15 h;
|
||||
|
||||
PRINTF("send_data_ack to %u.%u\n", mac & 0xff, mac >> 8);
|
||||
|
||||
h.len = MAC_HDR_LEN + 2; /* Including footer[2]. */
|
||||
h.fc0 = FC0_TYPE_DATA | FC0_INTRA_PAN;
|
||||
h.fc1 = FC1_DST_16 | FC1_SRC_16;
|
||||
|
||||
h.src = uip_hostaddr.u16[1];
|
||||
h.dst = mac;
|
||||
|
||||
return cc2420_send(&h, 10, NULL, 0);
|
||||
}
|
||||
|
||||
int
|
||||
cc2420_send(struct hdr_802_15 *hdr, u8_t hdr_len,
|
||||
const u8_t *payload, u8_t payload_len)
|
||||
{
|
||||
u8_t spiStatusByte;
|
||||
int s;
|
||||
|
||||
/* struct hdr_802_15::len shall *not* be counted, thus the -1.
|
||||
* 2 == sizeof(footer).
|
||||
*/
|
||||
if (((hdr_len - 1) + payload_len + 2) > MAX_PACKET_LEN)
|
||||
return -1;
|
||||
|
||||
/* This code uses the CC2420 CCA (Clear Channel Assessment) to
|
||||
* implement Carrier Sense Multiple Access with Collision Avoidance
|
||||
* (CSMA-CA) and requires the receiver to be enabled and ready.
|
||||
*/
|
||||
if (!receive_on)
|
||||
return -2;
|
||||
|
||||
/* Wait for previous transmission to finish and RSSI. */
|
||||
do {
|
||||
spiStatusByte = cc2420_status();
|
||||
if (!(spiStatusByte & BV(CC2420_RSSI_VALID))) /* RSSI needed by CCA */
|
||||
continue;
|
||||
} while (spiStatusByte & BV(CC2420_TX_ACTIVE));
|
||||
|
||||
hdr->dst_pan = pan_id; /* Not at fixed position! xxx/bg */
|
||||
last_dst = hdr->dst; /* Not dst either. */
|
||||
last_used_seq++;
|
||||
hdr->seq = last_used_seq;
|
||||
cc2420_ack_received = 0;
|
||||
|
||||
/* Write packet to TX FIFO, appending FCS if AUTOCRC is enabled. */
|
||||
cc2420_strobe(CC2420_SFLUSHTX); /* Cancel send that never started. */
|
||||
s = splhigh();
|
||||
FASTSPI_WRITE_FIFO(hdr, hdr_len);
|
||||
FASTSPI_WRITE_FIFO(payload, payload_len);
|
||||
splx(s);
|
||||
|
||||
/* Send stuff from FIFO now! */
|
||||
process_post_synch(&cc2420_retransmit_process, PROCESS_EVENT_MSG, NULL);
|
||||
|
||||
return UIP_FW_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
* Request packet to be sent using CSMA-CA. Requires that RSSI is
|
||||
* valid.
|
||||
*
|
||||
* Return UIP_FW_DROPPED on failure.
|
||||
*/
|
||||
int
|
||||
cc2420_resend(void)
|
||||
{
|
||||
unsigned i;
|
||||
|
||||
if (FIFOP_IS_1 && !FIFO_IS_1) {
|
||||
process_poll(&cc2420_process);
|
||||
PRINTF("rxfifo overflow!\n");
|
||||
}
|
||||
|
||||
/* The TX FIFO can only hold one packet! Make sure to not overrun
|
||||
* FIFO by waiting for transmission to start here and synchronizing
|
||||
* with the CC2420_TX_ACTIVE check in cc2420_send.
|
||||
*
|
||||
* Note that we may have to wait up to 320 us (20 symbols) before
|
||||
* transmission starts.
|
||||
*/
|
||||
#ifdef TMOTE_SKY
|
||||
#define LOOP_20_SYMBOLS 100 /* 326us (msp430 @ 2.4576MHz) */
|
||||
#elif __AVR__
|
||||
#define LOOP_20_SYMBOLS 500 /* XXX */
|
||||
#endif
|
||||
if (CCA_IS_1) {
|
||||
cc2420_strobe(CC2420_STXONCCA);
|
||||
for (i = LOOP_20_SYMBOLS; i > 0; i--)
|
||||
if (SFD_IS_1) {
|
||||
if (cc2420_status() & BV(CC2420_TX_ACTIVE))
|
||||
return UIP_FW_OK; /* Transmission has started. */
|
||||
else
|
||||
break; /* We must be receiving. */
|
||||
}
|
||||
}
|
||||
|
||||
return UIP_FW_DROPPED; /* Transmission never started! */
|
||||
}
|
||||
|
||||
void
|
||||
cc2420_off(void)
|
||||
{
|
||||
u8_t spiStatusByte;
|
||||
|
||||
if (receive_on == 0)
|
||||
return;
|
||||
receive_on = 0;
|
||||
/* Wait for transmission to end before turning radio off. */
|
||||
do {
|
||||
spiStatusByte = cc2420_status();
|
||||
} while (spiStatusByte & BV(CC2420_TX_ACTIVE));
|
||||
|
||||
cc2420_strobe(CC2420_SRFOFF);
|
||||
DISABLE_FIFOP_INT();
|
||||
}
|
||||
|
||||
void
|
||||
cc2420_on(void)
|
||||
{
|
||||
if (receive_on)
|
||||
return;
|
||||
receive_on = 1;
|
||||
|
||||
cc2420_strobe(CC2420_SRXON);
|
||||
cc2420_strobe(CC2420_SFLUSHRX);
|
||||
ENABLE_FIFOP_INT();
|
||||
}
|
||||
|
||||
void
|
||||
cc2420_set_chan_pan_addr(unsigned channel, /* 11 - 26 */
|
||||
unsigned pan,
|
||||
unsigned addr,
|
||||
const u8_t *ieee_addr)
|
||||
{
|
||||
/*
|
||||
* Subtract the base channel (11), multiply by 5, which is the
|
||||
* channel spacing. 357 is 2405-2048 and 0x4000 is LOCK_THR = 1.
|
||||
*/
|
||||
u8_t spiStatusByte;
|
||||
u16_t f = channel;
|
||||
int s;
|
||||
|
||||
f = 5*(f - 11) + 357 + 0x4000;
|
||||
/*
|
||||
* Writing RAM requires crystal oscillator to be stable.
|
||||
*/
|
||||
do {
|
||||
spiStatusByte = cc2420_status();
|
||||
} while (!(spiStatusByte & (BV(CC2420_XOSC16M_STABLE))));
|
||||
|
||||
pan_id = pan;
|
||||
cc2420_setreg(CC2420_FSCTRL, f);
|
||||
s = splhigh();
|
||||
FASTSPI_WRITE_RAM_LE(&pan, CC2420RAM_PANID, 2, f);
|
||||
FASTSPI_WRITE_RAM_LE(&addr, CC2420RAM_SHORTADDR, 2, f);
|
||||
if (ieee_addr != NULL)
|
||||
FASTSPI_WRITE_RAM_LE(ieee_addr, CC2420RAM_IEEEADDR, 8, f);
|
||||
splx(s);
|
||||
}
|
||||
|
||||
static volatile u8_t rx_fifo_remaining_bytes;
|
||||
static struct hdr_802_15 h;
|
||||
|
||||
/*
|
||||
* Interrupt either leaves frame intact in FIFO or reads *only* the
|
||||
* MAC header and sets rx_fifo_remaining_bytes.
|
||||
*
|
||||
* In order to quickly empty the FIFO ack processing is done at
|
||||
* interrupt priority rather than poll priority.
|
||||
*/
|
||||
int
|
||||
__cc2420_intr(void)
|
||||
{
|
||||
u8_t length;
|
||||
const u8_t *const ack_footer = (u8_t *)&h.dst_pan;
|
||||
|
||||
CLEAR_FIFOP_INT();
|
||||
|
||||
if (spi_busy || rx_fifo_remaining_bytes > 0) {
|
||||
/* SPI bus hardware is currently used elsewhere (UART0 or I2C bus)
|
||||
* or we already have a packet in the works and will have to defer
|
||||
* interrupt processing of this packet in a fake interrupt.
|
||||
*/
|
||||
process_poll(&cc2420_process);
|
||||
return 1;
|
||||
}
|
||||
|
||||
FASTSPI_READ_FIFO_BYTE(length);
|
||||
if (length > MAX_PACKET_LEN) {
|
||||
/* Oops, we must be out of sync. */
|
||||
FASTSPI_STROBE(CC2420_SFLUSHRX);
|
||||
FASTSPI_STROBE(CC2420_SFLUSHRX);
|
||||
return 0;
|
||||
}
|
||||
|
||||
h.len = length;
|
||||
|
||||
if (length < ACK_PACKET_LEN) {
|
||||
FASTSPI_READ_FIFO_GARBAGE(length); /* Rubbish */
|
||||
return 0;
|
||||
}
|
||||
|
||||
FASTSPI_READ_FIFO_NO_WAIT(&h.fc0, 5); /* fc0, fc1, seq, dst_pan */
|
||||
|
||||
/* Is this an ACK packet? */
|
||||
if (length == ACK_PACKET_LEN && (h.fc0 & FC0_TYPE_MASK) == FC0_TYPE_ACK) {
|
||||
if (ack_footer[1] & FOOTER1_CRC_OK) {
|
||||
if (h.seq == last_used_seq) { /* Matching ACK number? */
|
||||
cc2420_ack_received = 1;
|
||||
process_poll(&cc2420_retransmit_process);
|
||||
#if 0
|
||||
cc2420_last_rssi = ack_footer[0];
|
||||
cc2420_last_correlation = ack_footer[1] & FOOTER1_CORRELATION;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (length < (MAC_HDR_LEN + 2)) {
|
||||
FASTSPI_READ_FIFO_GARBAGE(length - 5);
|
||||
return 0;
|
||||
}
|
||||
|
||||
FASTSPI_READ_FIFO_NO_WAIT(&h.dst, 4); /* dst and src */
|
||||
|
||||
/* The payload and footer is now left in the RX FIFO and will be
|
||||
* picked up asynchronously at poll priority in the cc2420_process
|
||||
* below.
|
||||
*/
|
||||
rx_fifo_remaining_bytes = length - MAC_HDR_LEN;
|
||||
process_poll(&cc2420_process);
|
||||
return 1;
|
||||
}
|
||||
|
||||
PROCESS_THREAD(cc2420_process, ev, data)
|
||||
{
|
||||
PROCESS_BEGIN();
|
||||
|
||||
process_start(&cc2420_retransmit_process, NULL);
|
||||
|
||||
while (1) {
|
||||
unsigned len;
|
||||
int s;
|
||||
|
||||
PROCESS_YIELD();
|
||||
|
||||
len = rx_fifo_remaining_bytes;
|
||||
if (len > 0) {
|
||||
/* Read payload and two bytes of footer */
|
||||
if ((len - 2) > (UIP_BUFSIZE - UIP_LLH_LEN) || len < 2) {
|
||||
PRINTF("cc2420_process too big len=%d\n", len);
|
||||
s = splhigh();
|
||||
FASTSPI_READ_FIFO_GARBAGE(len);
|
||||
rx_fifo_remaining_bytes = 0; /* RX FIFO emptied! */
|
||||
splx(s);
|
||||
len = 0;
|
||||
} else {
|
||||
u8_t footer[2];
|
||||
uip_len = 0;
|
||||
s = splhigh();
|
||||
if (len > 2)
|
||||
FASTSPI_READ_FIFO_NO_WAIT(&uip_buf[UIP_LLH_LEN], len - 2);
|
||||
FASTSPI_READ_FIFO_NO_WAIT(footer, 2);
|
||||
rx_fifo_remaining_bytes = 0; /* RX FIFO emptied! */
|
||||
splx(s);
|
||||
if (footer[1] & FOOTER1_CRC_OK) {
|
||||
cc2420_last_rssi = footer[0];
|
||||
cc2420_last_correlation = footer[1] & FOOTER1_CORRELATION;
|
||||
if ((h.fc0 & FC0_TYPE_MASK) == FC0_TYPE_DATA)
|
||||
uip_len = len - 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (len == 2)
|
||||
PRINTF("recv data_ack\n");
|
||||
|
||||
/* Clean up in case of FIFO overflow! This happens for every full
|
||||
* length frame and is signaled by FIFOP = 1 and FIFO = 0.
|
||||
*/
|
||||
if (FIFOP_IS_1 && !FIFO_IS_1) {
|
||||
cc2420_strobe(CC2420_SFLUSHRX);
|
||||
cc2420_strobe(CC2420_SFLUSHRX);
|
||||
}
|
||||
|
||||
if (FIFOP_IS_1) {
|
||||
s = splhigh();
|
||||
__cc2420_intr(); /* Fake interrupt! */
|
||||
splx(s);
|
||||
}
|
||||
|
||||
if (len == 2) { /* A DATA ACK packet. */
|
||||
if (last_dst == h.src)
|
||||
cc2420_ack_received = 1;
|
||||
neigbour_update(h.src, 0);
|
||||
} else if (len > 2 && uip_len > 0
|
||||
&& uip_len == (((u16_t)(BUF->len[0]) << 8) + BUF->len[1])) {
|
||||
/*
|
||||
* If we are the unique receiver send DATA ACK.
|
||||
*/
|
||||
if (h.dst == 0xffff
|
||||
&& uip_ipaddr_cmp(&BUF->destipaddr, &uip_hostaddr))
|
||||
cc2420_send_data_ack(h.src);
|
||||
leds_toggle(LEDS_GREEN);
|
||||
cc2420_is_input = 1;
|
||||
tcpip_input();
|
||||
cc2420_is_input = 0;
|
||||
leds_toggle(LEDS_GREEN);
|
||||
}
|
||||
}
|
||||
|
||||
PROCESS_END();
|
||||
}
|
||||
|
||||
unsigned neigbour_find(u16_t mac);
|
||||
|
||||
/* Must be atleast 2 ticks and larger than 4ms. */
|
||||
#define RETRANSMIT_TIMEOUT 2 /* 31.25ms @ 64Hz */
|
||||
#define MAX_RETRANSMISSIONS 3
|
||||
|
||||
PROCESS_THREAD(cc2420_retransmit_process, ev, data)
|
||||
{
|
||||
static char n;
|
||||
static struct etimer etimer;
|
||||
|
||||
switch (ev) {
|
||||
default:
|
||||
case PROCESS_EVENT_INIT:
|
||||
return PT_WAITING;
|
||||
|
||||
case PROCESS_EVENT_EXIT:
|
||||
return PT_ENDED;
|
||||
|
||||
case PROCESS_EVENT_POLL: /* Cancel future retransmissions. */
|
||||
etimer_stop(&etimer);
|
||||
neigbour_update(last_dst, n);
|
||||
return PT_WAITING;
|
||||
|
||||
case PROCESS_EVENT_MSG: /* Send new packet. */
|
||||
n = -1;
|
||||
|
||||
/* FALLTHROUGH */
|
||||
case PROCESS_EVENT_TIMER:
|
||||
if (last_dst == 0xffff) {
|
||||
n++;
|
||||
clock_delay(1 + (rand() & (2048 - 1)));
|
||||
if (cc2420_resend() == UIP_FW_OK) {
|
||||
PRINTF("REBCAST %d\n", n);
|
||||
return PT_WAITING; /* Final transmission attempt. */
|
||||
}
|
||||
} else {
|
||||
if (cc2420_resend() == UIP_FW_OK) {
|
||||
n++;
|
||||
PRINTF("RETRANS %d to %d.%d\n", n, last_dst & 0xff, last_dst >> 8);
|
||||
}
|
||||
if (n == MAX_RETRANSMISSIONS) {
|
||||
neigbour_update(last_dst, n);
|
||||
return PT_WAITING; /* Final transmission attempt. */
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Schedule retransmission.
|
||||
*/
|
||||
etimer_set(&etimer, RETRANSMIT_TIMEOUT);
|
||||
return PT_WAITING;
|
||||
}
|
||||
/* NOTREACHED */
|
||||
}
|
||||
|
||||
/*
|
||||
* Retransmissions are negexp(alfa=0.5) weighted and stored as 4-bit
|
||||
* fixnums with 2 binals (binary decimals).
|
||||
*/
|
||||
#define SCALE_RETRANS 4
|
||||
#define SCALE_RETRANS_THRESHOLD (3*4)
|
||||
#define MAX_SCALE_RETRANS 15
|
||||
|
||||
/*
|
||||
* Expiration timestamps are 4-bits wide, in units of 2 seconds, and
|
||||
* relative to cc2420_check_remote::toff.
|
||||
*/
|
||||
#define SCALE_DIV_EXPIRE 2
|
||||
#define MAX_EXPIRE 15 /* 30 seconds */
|
||||
#define AGE_INTERVAL 5 /* 10 seconds */
|
||||
|
||||
struct cc2420_neigbour neigbours[NNEIGBOURS];
|
||||
|
||||
/*
|
||||
* Double hash into 3 different positions using a constand step. If we
|
||||
* don't find a match, return a pointer to the oldest entry and use
|
||||
* this position for insertion.
|
||||
*/
|
||||
static struct cc2420_neigbour *
|
||||
lookup(unsigned mac)
|
||||
{
|
||||
unsigned h = (mac + (mac>>8)) % NNEIGBOURS;
|
||||
#define next(h) (h += step, (h >= NNEIGBOURS) ? (h - NNEIGBOURS) : h)
|
||||
|
||||
if (neigbours[h].mac == mac) /* FOUND1 */
|
||||
return &neigbours[h];
|
||||
else {
|
||||
unsigned minexp = h;
|
||||
const unsigned step = ((mac>>9)&0x3) + 1;
|
||||
|
||||
h = next(h);
|
||||
if (neigbours[h].mac == mac) /* FOUND2 */
|
||||
return &neigbours[h];
|
||||
else {
|
||||
if (neigbours[h].expire < neigbours[minexp].expire) minexp = h;
|
||||
h = next(h);
|
||||
if (neigbours[h].mac == mac) /* FOUND3 */
|
||||
return &neigbours[h];
|
||||
else {
|
||||
if (neigbours[h].expire < neigbours[minexp].expire) minexp = h;
|
||||
return &neigbours[minexp];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
neigbour_update(u16_t mac, int nretrans)
|
||||
{
|
||||
struct cc2420_neigbour *t;
|
||||
|
||||
/* Always scale nretrans by constant factor. */
|
||||
if (nretrans == MAX_RETRANSMISSIONS)
|
||||
nretrans = MAX_SCALE_RETRANS;
|
||||
else
|
||||
nretrans *= SCALE_RETRANS; /* xxx/bg overflow! */
|
||||
|
||||
t = lookup(mac);
|
||||
if (t->mac != mac) {
|
||||
t->mac = mac;
|
||||
t->nretrans = nretrans;
|
||||
} else {
|
||||
if ((t->nretrans + nretrans)/2 > MAX_SCALE_RETRANS)
|
||||
t->nretrans = MAX_SCALE_RETRANS;
|
||||
else
|
||||
t->nretrans = (t->nretrans + nretrans)/2;
|
||||
}
|
||||
t->expire = MAX_EXPIRE;
|
||||
return;
|
||||
}
|
||||
|
||||
void
|
||||
cc2420_recv_ok(uip_ipaddr_t *from)
|
||||
{
|
||||
neigbour_update(from->u16[1], 0);
|
||||
}
|
||||
|
||||
/*
|
||||
* +1: remote
|
||||
* 0: local
|
||||
* -1: unknown
|
||||
*/
|
||||
int
|
||||
cc2420_check_remote(u16_t mac)
|
||||
{
|
||||
struct cc2420_neigbour *t;
|
||||
|
||||
/*
|
||||
* Age neigbour table every 5*SCALE_DIV_EXPIRE=10 seconds.
|
||||
*/
|
||||
static clock_time_t toff;
|
||||
unsigned now = ((clock_time() - toff)/CLOCK_SECOND)/SCALE_DIV_EXPIRE;
|
||||
if (now >= AGE_INTERVAL) {
|
||||
unsigned i;
|
||||
|
||||
for (i = 0; i < NNEIGBOURS; i++)
|
||||
if (neigbours[i].expire >= now)
|
||||
neigbours[i].expire -= now;
|
||||
else
|
||||
neigbours[i].mac = 0xffff; /* expired! */
|
||||
toff = clock_time();
|
||||
}
|
||||
|
||||
t = lookup(mac);
|
||||
if (t->mac != mac)
|
||||
return REMOTE_MAYBE; /* unknown */
|
||||
else if (t->nretrans >= SCALE_RETRANS_THRESHOLD)
|
||||
return REMOTE_YES; /* remote */
|
||||
else
|
||||
return REMOTE_NO; /* local */
|
||||
}
|
|
@ -1,144 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2005, Swedish Institute of Computer Science
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. 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.
|
||||
* 3. Neither the name of the Institute 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 INSTITUTE 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 INSTITUTE 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.
|
||||
*
|
||||
* This file is part of the Contiki operating system.
|
||||
*
|
||||
* @(#)$Id: cc2420.h,v 1.1 2008/02/24 22:29:08 adamdunkels Exp $
|
||||
*/
|
||||
|
||||
#ifndef CC2420_H
|
||||
#define CC2420_H
|
||||
|
||||
#define MAX_PACKET_LEN 127
|
||||
#define ACK_PACKET_LEN 5
|
||||
|
||||
/* fc0 */
|
||||
#define FC0_TYPE_MASK 0x07 /* bit0-2 */
|
||||
#define FC0_TYPE_BEACON 0x00 /* bit0-2 */
|
||||
#define FC0_TYPE_DATA 0x01 /* bit0-2 */
|
||||
#define FC0_TYPE_ACK 0x02 /* bit0-2 */
|
||||
#define FC0_TYPE_MAC_CMD 0x03 /* bit0-2 */
|
||||
/* reserved 0x04-0x07 */
|
||||
|
||||
#define FC0_SECURE 0x08 /* bit3 */
|
||||
#define FC0_PENDING 0x10 /* bit4 */
|
||||
#define FC0_REQ_ACK 0x20 /* bit5 */
|
||||
#define FC0_INTRA_PAN 0x40 /* bit6 */
|
||||
/* reserved 0x80 bit7 */
|
||||
|
||||
/* fc1 */
|
||||
/* reserved 0x80 bit8-9 */
|
||||
#define FC1_DST_MASK 0x0c /* bit10-11 */
|
||||
#define FC1_DST_0 0x00 /* bit10-11 */
|
||||
#define FC1_DST_16 0x08 /* bit10-11 */
|
||||
#define FC1_DST_64 0x0c /* bit10-11 */
|
||||
|
||||
/* reserved 0x80 bit12-13 */
|
||||
#define FC1_SRC_MASK 0xc0 /* bit14-15 */
|
||||
#define FC1_SRC_0 0x00 /* bit14-15 */
|
||||
#define FC1_SRC_16 0x80 /* bit14-15 */
|
||||
#define FC1_SRC_64 0xc0 /* bit14-15 */
|
||||
|
||||
/* footer[0] == RSSI, footer[1] == ... */
|
||||
#define FOOTER1_CRC_OK 0x80
|
||||
#define FOOTER1_CORRELATION 0x7f
|
||||
|
||||
/* The hdr_802_15::len byte does not count!!! */
|
||||
#define MAC_HDR_LEN (2 + 1 + 2 + 2 + 2)
|
||||
|
||||
struct hdr_802_15 {
|
||||
u8_t len; /* Not part of MAC header!!! */
|
||||
u8_t fc0;
|
||||
u8_t fc1;
|
||||
u8_t seq;
|
||||
u16_t dst_pan; /* also u8_t ack_footer[2] */
|
||||
u16_t dst;
|
||||
/* optional src_pan */
|
||||
u16_t src;
|
||||
/* u8_t payload[uip_len] */
|
||||
/* u8_t footer[2] */
|
||||
/* no more */
|
||||
};
|
||||
|
||||
struct hdr_802_15_ack {
|
||||
u8_t len;
|
||||
u8_t fc0;
|
||||
u8_t fc1;
|
||||
u8_t seq;
|
||||
u8_t footer[2];
|
||||
/* no more */
|
||||
};
|
||||
|
||||
struct cc2420_neigbour {
|
||||
unsigned mac:16, nretrans:4, expire:4; /* expiration time */
|
||||
#if 0
|
||||
unsigned rssi:6, correlation:6;
|
||||
#endif
|
||||
};
|
||||
|
||||
#define NNEIGBOURS 16
|
||||
extern struct cc2420_neigbour neigbours[NNEIGBOURS];
|
||||
|
||||
PROCESS_NAME(cc2420_process);
|
||||
|
||||
extern struct uip_fw_netif cc2420if;
|
||||
|
||||
extern signed char cc2420_last_rssi;
|
||||
extern u8_t cc2420_last_correlation;
|
||||
extern u8_t cc2420_is_input;
|
||||
extern volatile u8_t cc2420_ack_received;
|
||||
|
||||
void cc2420_init(void);
|
||||
void cc2420_set_chan_pan_addr(unsigned channel, unsigned pan,
|
||||
unsigned addr, const u8_t *ieee_addr);
|
||||
void cc2420_on(void);
|
||||
void cc2420_off(void);
|
||||
|
||||
u8_t cc2420_send_ip(void);
|
||||
u8_t cc2420_send_uaodv(void);
|
||||
int cc2420_send(struct hdr_802_15 *hdr, u8_t hdr_len,
|
||||
const u8_t *p, u8_t p_len);
|
||||
|
||||
/* Called at poll priority. */
|
||||
void cc2420_input(const struct hdr_802_15 *hdr, u8_t hdr_len,
|
||||
const u8_t *payload, u8_t payload_len);
|
||||
|
||||
/* Is mac far away? remote=1, local=0, don't know=-1. */
|
||||
enum { REMOTE_MAYBE = -1, REMOTE_NO = 0, REMOTE_YES = 1 };
|
||||
int cc2420_check_remote(u16_t mac);
|
||||
void cc2420_recv_ok(uip_ipaddr_t *from);
|
||||
|
||||
/*
|
||||
* Machine dependent initialization function and an interrupt service
|
||||
* routine must be provided externally. Call cc2420_intr from the
|
||||
* interrupt service routine.
|
||||
*/
|
||||
void __cc2420_arch_init(void);
|
||||
int __cc2420_intr(void);
|
||||
|
||||
#endif /* CC2420_H */
|
|
@ -1,314 +0,0 @@
|
|||
/* UNFINISHED CODE: the code works, but has yet to be converted into
|
||||
proper C code. It is mostly 6502 assembler for now. */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2001, Adam Dunkels.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. 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.
|
||||
* 3. The name of the author may not be used to endorse or promote
|
||||
* products derived from this software without specific prior
|
||||
* written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
||||
*
|
||||
* This file is part of the C64 RealAudio server demo project.
|
||||
*
|
||||
* $Id: cs8900a.c,v 1.1 2007/05/26 22:00:33 oliverschmidt Exp $
|
||||
*
|
||||
*/
|
||||
|
||||
/* cs8900a.c: device driver for the CS8900a chip in 8-bit mode. Mostly
|
||||
written in 6502 assembler for speed. */
|
||||
|
||||
#include "cs8900a.h"
|
||||
#include "uip.h"
|
||||
#include "uip_arp.h"
|
||||
|
||||
#define UIP_ETHADDR0 0x00
|
||||
#define UIP_ETHADDR1 0x00
|
||||
#define UIP_ETHADDR2 0x00
|
||||
#define UIP_ETHADDR3 0x64
|
||||
#define UIP_ETHADDR4 0x64
|
||||
#define UIP_ETHADDR5 0x64
|
||||
|
||||
extern u8_t *cs8900a_rxtxreg,
|
||||
*cs8900a_txcmd,
|
||||
*cs8900a_txlen,
|
||||
*cs8900a_packetpp,
|
||||
*cs8900a_ppdata;
|
||||
|
||||
static u16_t len;
|
||||
static u8_t r;
|
||||
|
||||
#define WRITE(P, D) do { PACKETPP = (P); \
|
||||
PPDATA = (D); } while(0)
|
||||
|
||||
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
void
|
||||
cs8900a_init(void)
|
||||
{
|
||||
/* Turn on transmission and reception of frames. */
|
||||
WRITE(0x0112, 0x00c0);
|
||||
|
||||
/* Accept valid unicast+broadcast frames. */
|
||||
WRITE(0x0104, 0x0d05);
|
||||
|
||||
/* Set MAC address. */
|
||||
WRITE(0x0158, (ETHADDR1 << 8) | (ETHADDR0));
|
||||
WRITE(0x015a, (ETHADDR3 << 8) | (ETHADDR2));
|
||||
WRITE(0x015c, (ETHADDR5 << 8) | (ETHADDR4));
|
||||
|
||||
}
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
void
|
||||
cs8900a_send(void)
|
||||
{
|
||||
if(uip_len > UIP_BUFSIZE) {
|
||||
return;
|
||||
}
|
||||
|
||||
/* Transmit command. */
|
||||
/* *cs8900a_txcmd = 0x00c0 */
|
||||
asm("lda #$c0");
|
||||
asm("sta %v", cs8900a_txcmd);
|
||||
asm("lda #$00");
|
||||
asm("sta %v+1", cs8900a_txcmd);
|
||||
|
||||
/* *cs8900a_txlen = uip_len */
|
||||
|
||||
asm("lda _uip_len");
|
||||
asm("sta %v", cs8900a_txlen);
|
||||
#if UIP_BUFSIZE > 255
|
||||
asm("lda _uip_len+1");
|
||||
#else
|
||||
asm("lda #0");
|
||||
#endif
|
||||
asm("sta %v+1", cs8900a_txlen);
|
||||
|
||||
asm("ldx #8");
|
||||
asm("tryagain:");
|
||||
/* Check for avaliable buffer space. */
|
||||
asm("lda #$38");
|
||||
asm("sta %v", cs8900a_packetpp);
|
||||
asm("lda #$01");
|
||||
asm("sta %v+1", cs8900a_packetpp);
|
||||
asm("lda %v+1", cs8900a_ppdata);
|
||||
asm("and #1");
|
||||
asm("bne send");
|
||||
|
||||
/* No space avaliable, skip a received frame and try again. */
|
||||
asm("lda #$02");
|
||||
asm("sta %v", cs8900a_packetpp);
|
||||
asm("lda #$01");
|
||||
asm("sta %v+1", cs8900a_packetpp);
|
||||
asm("lda %v", cs8900a_ppdata);
|
||||
asm("ora #$40");
|
||||
asm("sta %v", cs8900a_ppdata);
|
||||
|
||||
asm("dex");
|
||||
asm("bne tryagain");
|
||||
|
||||
asm("bailout:");
|
||||
return;
|
||||
|
||||
/* Send the frame. */
|
||||
asm("send:");
|
||||
|
||||
|
||||
/* First, send 40+14=54 bytes of header. */
|
||||
|
||||
asm("ldx #54");
|
||||
asm("ldy #0");
|
||||
asm("sendloop1:");
|
||||
asm("lda _uip_buf,y");
|
||||
asm("sta %v", cs8900a_rxtxreg);
|
||||
asm("lda _uip_buf+1,y");
|
||||
asm("sta %v+1", cs8900a_rxtxreg);
|
||||
asm("iny");
|
||||
asm("iny");
|
||||
asm("dex");
|
||||
asm("dex");
|
||||
asm("bne sendloop1");
|
||||
|
||||
if(uip_len <= 54) {
|
||||
return;
|
||||
}
|
||||
|
||||
/* Next, send rest of the packet. */
|
||||
|
||||
uip_len -= 54;
|
||||
|
||||
|
||||
asm("lda ptr1");
|
||||
asm("pha");
|
||||
asm("lda ptr1+1");
|
||||
asm("pha");
|
||||
|
||||
asm("lda _uip_appdata");
|
||||
asm("sta ptr1");
|
||||
asm("lda _uip_appdata+1");
|
||||
asm("sta ptr1+1");
|
||||
|
||||
asm("sendloop2:");
|
||||
asm("lda _uip_len");
|
||||
asm("tax");
|
||||
asm("and #1");
|
||||
asm("beq noinc");
|
||||
asm("inx");
|
||||
asm("noinc:");
|
||||
#if UIP_BUFSIZE > 255
|
||||
asm("lda _uip_len+1");
|
||||
#else
|
||||
asm("lda #0");
|
||||
#endif
|
||||
asm("beq nozero");
|
||||
asm("ldx #0");
|
||||
asm("nozero:");
|
||||
asm("ldy #0");
|
||||
asm("sendloop:");
|
||||
asm("lda (ptr1),y");
|
||||
asm("sta %v", cs8900a_rxtxreg);
|
||||
asm("iny");
|
||||
asm("lda (ptr1),y");
|
||||
asm("sta %v+1", cs8900a_rxtxreg);
|
||||
asm("iny");
|
||||
asm("dex");
|
||||
asm("dex");
|
||||
asm("bne sendloop");
|
||||
asm("inc ptr1+1");
|
||||
#if UIP_BUFSIZE > 255
|
||||
asm("dec _uip_len+1");
|
||||
asm("bpl sendloop2");
|
||||
#endif
|
||||
|
||||
asm("pla");
|
||||
asm("sta ptr1+1");
|
||||
asm("pla");
|
||||
asm("sta ptr1");
|
||||
}
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
static void
|
||||
skip_frame(void)
|
||||
{
|
||||
WRITE(0x0102, PPDATA | 0x0040);
|
||||
}
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
u8_t
|
||||
cs8900a_poll(void)
|
||||
{
|
||||
/* Check receiver event register to see if there are any valid
|
||||
unicast frames avaliable. */
|
||||
/* PACKETPP = 0x0124;
|
||||
if(PPDATA & 0x000d == 0x0000) {
|
||||
return 0;
|
||||
}
|
||||
*/
|
||||
asm("lda #$24");
|
||||
asm("sta %v", cs8900a_packetpp);
|
||||
asm("lda #$01");
|
||||
asm("sta %v+1", cs8900a_packetpp);
|
||||
asm("lda %v+1", cs8900a_ppdata);
|
||||
asm("and #$0d");
|
||||
asm("cmp #$00");
|
||||
asm("bne noreturn");
|
||||
/* No frame ready. */
|
||||
return 0;
|
||||
|
||||
asm("noreturn:");
|
||||
/* Process the incoming frame. */
|
||||
|
||||
/* Read receiver event and discard it. */
|
||||
/* dummy = RXTXREG; */
|
||||
|
||||
asm("lda %v+1", cs8900a_rxtxreg);
|
||||
asm("sta _len+1");
|
||||
asm("lda %v", cs8900a_rxtxreg);
|
||||
asm("sta _len");
|
||||
|
||||
/* Read frame length. */
|
||||
/* len = uip_len = RXTXREG; */
|
||||
asm("lda %v+1", cs8900a_rxtxreg);
|
||||
asm("sta _len+1");
|
||||
asm("sta _uip_len+1");
|
||||
asm("lda %v", cs8900a_rxtxreg);
|
||||
asm("sta _len");
|
||||
asm("sta _uip_len");
|
||||
|
||||
|
||||
if(len > UIP_BUFSIZE) {
|
||||
skip_frame();
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Read bytes into uip_buf. */
|
||||
asm("lda ptr1");
|
||||
asm("pha");
|
||||
asm("lda ptr1+1");
|
||||
asm("pha");
|
||||
|
||||
asm("lda #<_uip_buf");
|
||||
asm("sta ptr1");
|
||||
asm("lda #>_uip_buf");
|
||||
asm("sta ptr1+1");
|
||||
|
||||
asm("lda _len+1");
|
||||
asm("beq read256");
|
||||
|
||||
/* Read first 256*n bytes. */
|
||||
asm("ldy #0");
|
||||
asm("read256loop:");
|
||||
asm("lda %v", cs8900a_rxtxreg);
|
||||
asm("sta (ptr1),y");
|
||||
asm("iny");
|
||||
asm("lda %v+1", cs8900a_rxtxreg);
|
||||
asm("sta (ptr1),y");
|
||||
asm("iny");
|
||||
asm("bne read256loop");
|
||||
asm("inc ptr1+1");
|
||||
|
||||
asm("dec _len+1");
|
||||
asm("bne read256loop");
|
||||
|
||||
/* Read last 255 or less bytes. */
|
||||
asm("read256:");
|
||||
asm("lda _len");
|
||||
asm("lsr");
|
||||
asm("bcc noinc");
|
||||
asm("inc _len");
|
||||
asm("noinc:");
|
||||
asm("ldy #$0");
|
||||
asm("readloop:");
|
||||
asm("lda %v", cs8900a_rxtxreg);
|
||||
asm("sta (ptr1),y");
|
||||
asm("iny");
|
||||
asm("lda %v+1", cs8900a_rxtxreg);
|
||||
asm("sta (ptr1),y");
|
||||
asm("iny");
|
||||
asm("cpy _len");
|
||||
asm("bne readloop");
|
||||
|
||||
asm("pla");
|
||||
asm("sta ptr1+1");
|
||||
asm("pla");
|
||||
asm("sta ptr1");
|
||||
return len;
|
||||
}
|
|
@ -1,44 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2004, Adam Dunkels.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. 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.
|
||||
* 3. Neither the name of the Institute 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 INSTITUTE 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 INSTITUTE 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.
|
||||
*
|
||||
* This file is part of the Contiki operating system.
|
||||
*
|
||||
* Author: Adam Dunkels <adam@sics.se>
|
||||
*
|
||||
* $Id: cs8900a.h,v 1.1 2007/05/26 22:00:33 oliverschmidt Exp $
|
||||
*/
|
||||
#ifndef __CS8900A_H__
|
||||
#define __CS8900A_H__
|
||||
|
||||
#include "uip_arch.h"
|
||||
|
||||
void cs8900a_init(void);
|
||||
void cs8900a_send(void);
|
||||
u8_t cs8900a_poll(void);
|
||||
|
||||
#endif /* __CS8900A_H__ */
|
|
@ -1,152 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2006, Swedish Institute of Computer Science
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. 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.
|
||||
* 3. Neither the name of the Institute 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 INSTITUTE 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 INSTITUTE 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.
|
||||
*
|
||||
* @(#)$Id: crtk.c,v 1.1 2007/05/23 23:23:23 oliverschmidt Exp $
|
||||
*/
|
||||
|
||||
/*
|
||||
* RUNES CRTK Implementation
|
||||
* Version 0.3
|
||||
*
|
||||
* Stefanos Zachariadis, UCL, s.zachariadis@cs.ucl.ac.uk
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "crtk.h"
|
||||
|
||||
static Attribute a = { "Author", "Stefanos Zachariadis", NULL };
|
||||
static Entity attributes = { 0, COMPONENT, "crtk", &a, NULL };
|
||||
static int entities;
|
||||
|
||||
static void construct(void) {
|
||||
printf("Instantiating RUNES middleware\n");
|
||||
}
|
||||
|
||||
static void destroy(void) {
|
||||
printf("RUNES Middleware going away...\n");
|
||||
}
|
||||
|
||||
static void printregistry(void) {
|
||||
printf("The Registry Currently Contains:\n");
|
||||
Entity *current;
|
||||
current=&attributes;
|
||||
while(current!=NULL) {
|
||||
Attribute *attrs;
|
||||
attrs=current->attributes;
|
||||
printf("Entity (%d,%d) \n",current->id, current->type);
|
||||
while(attrs!=NULL) {
|
||||
printf(" (%s,%s)\n",attrs->key,(char *)(attrs->value));
|
||||
attrs=attrs->next;
|
||||
}
|
||||
current=current->next;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void delent(Entity *e) {
|
||||
Entity *previous = &attributes; /* Not allowed to delete first! */
|
||||
Entity *current = previous->next;
|
||||
while(current != NULL) {
|
||||
if(e->id == current->id) {
|
||||
previous->next = current->next;
|
||||
current->next = NULL;
|
||||
return;
|
||||
}
|
||||
previous = current;
|
||||
current = current->next;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void putattr(Entity *e, Attribute *a) {
|
||||
Entity *current, *previous = NULL;
|
||||
current=&attributes;
|
||||
while(NULL!=current) {
|
||||
//printf("looping\n");
|
||||
if(e->id==current->id) { //the entity already exists in our databas
|
||||
//we need to see if an attribute with the same key exists
|
||||
Attribute *tmp;
|
||||
for(tmp=current->attributes;tmp->next!=NULL;tmp=tmp->next) {
|
||||
if(strcmp(tmp->key,a->key)==0) { //it does exist
|
||||
tmp->value=a->value;
|
||||
return;
|
||||
}
|
||||
}
|
||||
//we need to add this attribute
|
||||
tmp->next=a;
|
||||
a->next=NULL;
|
||||
return;
|
||||
}
|
||||
previous=current;
|
||||
current=current->next;
|
||||
}
|
||||
e->next=NULL;
|
||||
previous->next=e;
|
||||
e->attributes=a;
|
||||
a->next=NULL;
|
||||
}
|
||||
|
||||
static void getattr(Entity e, char *key, Attribute **atr) {
|
||||
//right, so we're going to go through our registry.
|
||||
Entity *current;
|
||||
current=&attributes;
|
||||
while(current!=NULL) {
|
||||
if(e.id==current->id) { //we found the element
|
||||
Attribute *tmp;
|
||||
for(tmp=current->attributes;tmp!=NULL;tmp=tmp->next) {
|
||||
if(strcmp(tmp->key,key)==0) { //the key does exist
|
||||
*atr=tmp;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
current=current->next;
|
||||
}
|
||||
atr=NULL;
|
||||
}
|
||||
|
||||
static void connect(Interface i, Receptacle *r) {
|
||||
*r=i;
|
||||
}
|
||||
|
||||
|
||||
|
||||
static void instantiate(Entity *e, Attribute *init) {
|
||||
e->id=entities++;
|
||||
putattr(e,init);
|
||||
}
|
||||
|
||||
|
||||
static void getentities(Entity **e) {
|
||||
*e=&attributes;
|
||||
}
|
||||
|
||||
IMPLEMENT_COMPONENT(crtk, { printregistry, delent, putattr, getattr,
|
||||
connect, instantiate, getentities });
|
|
@ -1,150 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2006, Swedish Institute of Computer Science
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. 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.
|
||||
* 3. Neither the name of the Institute 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 INSTITUTE 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 INSTITUTE 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.
|
||||
*
|
||||
* @(#)$Id: crtk.h,v 1.1 2007/05/23 23:23:23 oliverschmidt Exp $
|
||||
*/
|
||||
|
||||
/*
|
||||
* RUNES CRTK header, version 0.3
|
||||
*
|
||||
* Stefanos Zachariadis, UCL, s.zachariadis@cs.ucl.ac.uk
|
||||
*/
|
||||
|
||||
#ifndef CRTK_H
|
||||
#define CRTK_H
|
||||
|
||||
/* For now this file is intimately dependent on sys/service.h. Really
|
||||
* mysterious error messages are generated if one forgets to include
|
||||
* sys/service.h, for this reason it is included here!
|
||||
*/
|
||||
#include "sys/service.h"
|
||||
|
||||
#define COMPONENT 0
|
||||
|
||||
#define INTERFACE 1
|
||||
|
||||
#define RECEPTACLE 2
|
||||
|
||||
typedef const char *Receptacle;
|
||||
|
||||
typedef const void *Interface;
|
||||
|
||||
#if 0
|
||||
typedef struct INTERFACES {
|
||||
Interface *i;
|
||||
struct INTERFACES *next;
|
||||
} Interfaces;
|
||||
#endif
|
||||
|
||||
#if 0
|
||||
typedef struct RECEPTACLES {
|
||||
Receptacle *r;
|
||||
struct RECEPTACLES *next;
|
||||
} Receptacles;
|
||||
#endif
|
||||
|
||||
typedef struct ATTRIBUTE {
|
||||
char *key;
|
||||
void *value;
|
||||
struct ATTRIBUTE *next;
|
||||
} Attribute;
|
||||
|
||||
typedef struct ENTITY {
|
||||
int id;
|
||||
int type;
|
||||
char *name;
|
||||
Attribute *attributes;
|
||||
struct ENTITY *next;
|
||||
} Entity;
|
||||
|
||||
#define INVOKE(receptacle, iface, function) \
|
||||
{ \
|
||||
struct service *service_s; \
|
||||
service_s = service_find(receptacle); \
|
||||
if(service_s != NULL) { \
|
||||
((struct iface *)service_s->interface)->function; \
|
||||
} \
|
||||
}
|
||||
|
||||
#define DECLARE_COMPONENT(compname,interface) \
|
||||
extern struct process compname##_process; \
|
||||
struct compname interface;
|
||||
|
||||
#define DECLARE_INTERFACE(intname,interface)\
|
||||
struct intname interface;
|
||||
|
||||
#define IMPLEMENT_COMPONENT(compname, ...)\
|
||||
static const struct compname compname##_implementation_interface = __VA_ARGS__;\
|
||||
static struct service compname##_implementation = { NULL, NULL, #compname, & compname##_implementation_interface }; \
|
||||
static Entity compname##_entity;\
|
||||
static void construct(void);\
|
||||
static void destroy(void);\
|
||||
PROCESS(compname##_process, #compname"_process"); \
|
||||
PROCESS_THREAD(compname##_process, ev, data) {\
|
||||
static Attribute name = { "template", #compname, NULL };\
|
||||
PROCESS_EXITHANDLER(goto exit);\
|
||||
PROCESS_BEGIN();\
|
||||
compname##_entity.type = COMPONENT;\
|
||||
compname##_entity.name = #compname;\
|
||||
construct();\
|
||||
SERVICE_REGISTER(compname##_implementation);\
|
||||
INVOKE("crtk", crtk, instantiate(&compname##_entity,&name));\
|
||||
PROCESS_YIELD_UNTIL(ev == PROCESS_EVENT_SERVICE_REMOVED);\
|
||||
exit:\
|
||||
destroy();\
|
||||
SERVICE_REMOVE(compname##_implementation);\
|
||||
INVOKE("crtk", crtk, delent(&compname##_entity));\
|
||||
PROCESS_END(); \
|
||||
}
|
||||
|
||||
/* Registry crtk is built upon. */
|
||||
DECLARE_COMPONENT(crtk,
|
||||
{
|
||||
/* prints the contents of the registry. */
|
||||
void (* printregistry)(void);
|
||||
|
||||
/* delete the given entity. */
|
||||
void (* delent)(Entity *e);
|
||||
|
||||
/* adds a new attribute for the given entity. */
|
||||
void (* putattr)(Entity *e, Attribute *a);
|
||||
|
||||
/* searches for an attribute with the given key, for the given entity. */
|
||||
void (* getattr)(Entity e, char *key, Attribute **a);
|
||||
|
||||
/* connects an interface and a receptacle. */
|
||||
void (* connect) (Interface i, Receptacle *r);
|
||||
|
||||
/* instantiates a new component. */
|
||||
void (* instantiate) (Entity *e, Attribute *init);
|
||||
|
||||
/* returns on e all the entities (and their attributes) available. */
|
||||
void (* getentities) (Entity **e);
|
||||
});
|
||||
|
||||
#endif /* CRTK_H */
|
|
@ -1,181 +0,0 @@
|
|||
/**
|
||||
* \file
|
||||
* An experimental CTK text edit widget.
|
||||
* \author Adam Dunkels <adam@dunkels.com>
|
||||
*
|
||||
* This module contains an experimental CTK widget which is
|
||||
* implemented in the application process rather than in the CTK
|
||||
* process. The widget is instantiated in a similar fashion as other
|
||||
* CTK widgets, but is different from other widgets in that it
|
||||
* requires a signal handler function to be called by the process
|
||||
* signal handler function.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2003, Adam Dunkels.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. 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.
|
||||
* 3. The name of the author may not be used to endorse or promote
|
||||
* products derived from this software without specific prior
|
||||
* written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
||||
*
|
||||
* This file is part of the Contiki desktop environment
|
||||
*
|
||||
* $Id: ctk-textedit.c,v 1.1 2007/11/20 20:41:54 oliverschmidt Exp $
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#include "ctk-textedit.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
void
|
||||
ctk_textedit_init(struct ctk_textedit *t)
|
||||
{
|
||||
t->xpos = t->ypos = 0;
|
||||
}
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
/**
|
||||
* Add a CTK textedit widget to a window.
|
||||
*
|
||||
* \param w A pointer to the window to which the entry is to be added.
|
||||
* \param t A pointer to the CTK textentry structure.
|
||||
*/
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
void
|
||||
ctk_textedit_add(struct ctk_window *w,
|
||||
struct ctk_textedit *t)
|
||||
{
|
||||
CTK_WIDGET_SET_FLAG(t, CTK_WIDGET_FLAG_MONOSPACE);
|
||||
CTK_WIDGET_ADD(w, t);
|
||||
}
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
/**
|
||||
* The CTK textedit signal handler.
|
||||
*
|
||||
* This function must be called as part of the normal signal handler
|
||||
* of the process that contains the CTK textentry structure.
|
||||
*
|
||||
* \param t A pointer to the CTK textentry structure.
|
||||
* \param s The signal number.
|
||||
* \param data The signal data.
|
||||
*/
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
void
|
||||
ctk_textedit_eventhandler(struct ctk_textedit *t,
|
||||
process_event_t s,
|
||||
process_data_t data)
|
||||
{
|
||||
char *textptr, *textptr2;
|
||||
unsigned char len;
|
||||
|
||||
if(s == ctk_signal_keypress) {
|
||||
CTK_WIDGET_FOCUS(t->label.window, &t->label);
|
||||
textptr = &(t->label.text[t->ypos * t->label.w + t->xpos]);
|
||||
*textptr &= 0x7f;
|
||||
switch((ctk_arch_key_t)data) {
|
||||
case CH_CURS_DOWN:
|
||||
if(t->ypos < t->label.h - 1) {
|
||||
++t->ypos;
|
||||
}
|
||||
break;
|
||||
case CH_CURS_UP:
|
||||
if(t->ypos > 0) {
|
||||
--t->ypos;
|
||||
}
|
||||
break;
|
||||
case CH_CURS_RIGHT:
|
||||
len = strlen(&t->label.text[t->ypos * t->label.w]);
|
||||
if(t->xpos < len) {
|
||||
/* if(t->xpos < t->label.w) {*/
|
||||
++t->xpos;
|
||||
} else {
|
||||
t->xpos = len;
|
||||
}
|
||||
break;
|
||||
case CH_CURS_LEFT:
|
||||
if(t->xpos > 0) {
|
||||
--t->xpos;
|
||||
} else {
|
||||
if(t->ypos > 0) {
|
||||
--t->ypos;
|
||||
t->xpos = t->label.w - 1;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case CH_ENTER:
|
||||
t->xpos = 0;
|
||||
if(t->ypos < t->label.h - 1) {
|
||||
++t->ypos;
|
||||
}
|
||||
break;
|
||||
case CH_DEL:
|
||||
len = t->label.w - t->xpos;
|
||||
if(t->xpos > 0 && len > 0) {
|
||||
strncpy(textptr - 1, textptr,
|
||||
len);
|
||||
*(textptr + len - 1) = 0;
|
||||
--t->xpos;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
len = t->label.w - t->xpos;
|
||||
if(len > 0) {
|
||||
textptr2 = textptr + len - 1;
|
||||
while(textptr2 + 1 > textptr) {
|
||||
*(textptr2 + 1) = *textptr2;
|
||||
--textptr2;
|
||||
}
|
||||
|
||||
*textptr = (char)data;
|
||||
++t->xpos;
|
||||
if(t->xpos == t->label.w) {
|
||||
t->xpos = 0;
|
||||
if(t->ypos < t->label.h - 1) {
|
||||
++t->ypos;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
textptr = &(t->label.text[t->ypos * t->label.w + t->xpos]);
|
||||
*textptr |= 0x80;
|
||||
CTK_WIDGET_REDRAW(&t->label);
|
||||
} else if(s == ctk_signal_widget_activate &&
|
||||
data == (process_data_t)t) {
|
||||
textptr = &(t->label.text[t->ypos * t->label.w + t->xpos]);
|
||||
*textptr &= 0x7f;
|
||||
t->xpos = 0;
|
||||
if(t->ypos < t->label.h - 1) {
|
||||
++t->ypos;
|
||||
}
|
||||
textptr = &(t->label.text[t->ypos * t->label.w + t->xpos]);
|
||||
*textptr |= 0x80;
|
||||
CTK_WIDGET_REDRAW(&t->label);
|
||||
}
|
||||
}
|
||||
/*-----------------------------------------------------------------------------------*/
|
|
@ -1,73 +0,0 @@
|
|||
/**
|
||||
* \file
|
||||
* Header file for the experimental application level CTK textedit widget.
|
||||
* \author Adam Dunkels <adam@dunkels.com>
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2003, Adam Dunkels.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. 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.
|
||||
* 3. The name of the author may not be used to endorse or promote
|
||||
* products derived from this software without specific prior
|
||||
* written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
||||
*
|
||||
* This file is part of the Contiki desktop environment
|
||||
*
|
||||
* $Id: ctk-textedit.h,v 1.1 2007/11/20 20:41:54 oliverschmidt Exp $
|
||||
*
|
||||
*/
|
||||
#ifndef __CTK_TEXTEDIT_H__
|
||||
#define __CTK_TEXTEDIT_H__
|
||||
|
||||
#include "ctk/ctk.h"
|
||||
|
||||
/**
|
||||
* Instantiating macro for the CTK textedit widget.
|
||||
*
|
||||
*
|
||||
* \param tx The x position of the widget.
|
||||
* \param ty The y position of the widget.
|
||||
* \param tw The width of the widget.
|
||||
* \param th The height of the widget.
|
||||
* \param ttext The text buffer to be edited.
|
||||
*/
|
||||
#define CTK_TEXTEDIT(tx, ty, tw, th, ttext) \
|
||||
{CTK_LABEL(tx, ty, tw, th, ttext)}, 0, 0
|
||||
struct ctk_textedit {
|
||||
struct ctk_label label;
|
||||
unsigned char xpos, ypos;
|
||||
};
|
||||
|
||||
void ctk_textedit_init(struct ctk_textedit *t);
|
||||
|
||||
void ctk_textedit_add(struct ctk_window *w,
|
||||
struct ctk_textedit *t);
|
||||
|
||||
void ctk_textedit_eventhandler(struct ctk_textedit *t,
|
||||
process_event_t s,
|
||||
process_data_t data);
|
||||
|
||||
#endif /* __CTK_TEXTEDIT_H__ */
|
|
@ -1,434 +0,0 @@
|
|||
/* Copyright (c) 2002, 2004 Joerg Wunsch
|
||||
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 copyright holders nor the names of
|
||||
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.
|
||||
*/
|
||||
|
||||
|
||||
/* $Id: malloc.c,v 1.1 2008/08/15 19:05:17 adamdunkels Exp $ */
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#ifdef MALLOC_TEST
|
||||
#include "malloc.h"
|
||||
char mymem[256];
|
||||
#else
|
||||
#include "contiki.h"
|
||||
#include "lib/malloc.h"
|
||||
#endif /* !MALLOC_TEST */
|
||||
|
||||
/*
|
||||
* Exported interface:
|
||||
*
|
||||
* When extending the data segment, the allocator will not try to go
|
||||
* beyond the current stack limit, decreased by __malloc_margin bytes.
|
||||
* Thus, all possible stack frames of interrupt routines that could
|
||||
* interrupt the current function, plus all further nested function
|
||||
* calls must not require more stack space, or they'll risk to collide
|
||||
* with the data segment.
|
||||
*/
|
||||
|
||||
char *__malloc_heap_end;
|
||||
|
||||
char *__brkval;
|
||||
struct __freelist *__flp;
|
||||
|
||||
#define handle nx
|
||||
|
||||
void *
|
||||
malloc(size_t len)
|
||||
{
|
||||
struct __freelist *fp1, *fp2;
|
||||
char *cp;
|
||||
size_t s;
|
||||
|
||||
if (len <= 0)
|
||||
return 0;
|
||||
|
||||
len = (len + MALLOC_ROUNDUP) & ~MALLOC_ROUNDUP;
|
||||
|
||||
/*
|
||||
* First, walk the free list and try finding a chunk that
|
||||
* would match exactly. If we found one, we are done. While
|
||||
* walking, note down the size of the largest chunk we found
|
||||
* that would still fit the request -- we need it for step 2.
|
||||
*
|
||||
*/
|
||||
for (s = 0, fp1 = __flp, fp2 = 0;
|
||||
fp1;
|
||||
fp2 = fp1, fp1 = fp1->nx) {
|
||||
if (fp1->sz == len) {
|
||||
/*
|
||||
* Found it. Disconnect the chunk from the
|
||||
* freelist, and return it.
|
||||
*/
|
||||
if (fp2)
|
||||
fp2->nx = fp1->nx;
|
||||
else
|
||||
__flp = fp1->nx;
|
||||
fp1->handle = NULL;
|
||||
return &fp1[1];
|
||||
}
|
||||
if (fp1->sz > len) {
|
||||
if (s == 0 || fp1->sz < s)
|
||||
s = fp1->sz;
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Step 2: If we found a chunk on the freelist that would fit
|
||||
* (but was too large), look it up again and use it, since it
|
||||
* is our closest match now. Since the freelist entry needs
|
||||
* to be split into two entries then, watch out that the
|
||||
* difference between the requested size and the size of the
|
||||
* chunk found is large enough for another freelist entry; if
|
||||
* not, just enlarge the request size to what we have found,
|
||||
* and use the entire chunk.
|
||||
*/
|
||||
if (s) {
|
||||
if (s - len < sizeof(struct __freelist))
|
||||
len = s;
|
||||
for (fp1 = __flp, fp2 = 0;
|
||||
fp1;
|
||||
fp2 = fp1, fp1 = fp1->nx) {
|
||||
if (fp1->sz == s) {
|
||||
if (len == s) {
|
||||
/*
|
||||
* Use entire chunk; same as
|
||||
* above.
|
||||
*/
|
||||
if (fp2)
|
||||
fp2->nx = fp1->nx;
|
||||
else
|
||||
__flp = fp1->nx;
|
||||
fp1->handle = NULL;
|
||||
return &fp1[1];
|
||||
}
|
||||
/*
|
||||
* Split them up. Note that we leave
|
||||
* the first part as the new (smaller)
|
||||
* freelist entry, and return the
|
||||
* upper portion to the caller. This
|
||||
* saves us the work to fix up the
|
||||
* freelist chain; we just need to
|
||||
* fixup the size of the current
|
||||
* entry, and note down the size of
|
||||
* the new chunk before returning it
|
||||
* to the caller.
|
||||
*/
|
||||
cp = (char *)fp1;
|
||||
s -= len;
|
||||
cp += s;
|
||||
fp2 = (struct __freelist *)cp;
|
||||
fp2->sz = len;
|
||||
fp1->sz = s - sizeof(struct __freelist);
|
||||
fp2->handle = NULL;
|
||||
return &fp2[1];
|
||||
}
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Step 3: If the request could not be satisfied from a
|
||||
* freelist entry, just prepare a new chunk. This means we
|
||||
* need to obtain more memory first. The largest address just
|
||||
* not allocated so far is remembered in the brkval variable.
|
||||
* Under Unix, the "break value" was the end of the data
|
||||
* segment as dynamically requested from the operating system.
|
||||
* Since we don't have an operating system, just make sure
|
||||
* that we don't collide with the stack.
|
||||
*/
|
||||
if (__brkval == 0)
|
||||
__brkval = sbrk(len + sizeof(struct __freelist));
|
||||
else if (sbrk(len + sizeof(struct __freelist)) == (void *)-1)
|
||||
return 0; /* There's no help, just fail. :-/ */
|
||||
|
||||
__malloc_heap_end = sbrk(0);
|
||||
|
||||
fp1 = (struct __freelist *)__brkval;
|
||||
__brkval += len + sizeof(struct __freelist);
|
||||
fp1->sz = len;
|
||||
fp1->handle = NULL;
|
||||
return &fp1[1];
|
||||
}
|
||||
|
||||
void
|
||||
free(void *p)
|
||||
{
|
||||
struct __freelist *fp1, *fp2, *fpnew;
|
||||
char *cp1, *cp2, *cpnew;
|
||||
|
||||
/* ISO C says free(NULL) must be a no-op */
|
||||
if (p == 0)
|
||||
return;
|
||||
|
||||
cpnew = p;
|
||||
cpnew -= sizeof(struct __freelist);
|
||||
fpnew = (struct __freelist *)cpnew;
|
||||
fpnew->nx = 0;
|
||||
|
||||
/*
|
||||
* Trivial case first: if there's no freelist yet, our entry
|
||||
* will be the only one on it.
|
||||
*/
|
||||
if (__flp == 0) {
|
||||
__flp = fpnew;
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* Now, find the position where our new entry belongs onto the
|
||||
* freelist. Try to aggregate the chunk with adjacent chunks
|
||||
* if possible.
|
||||
*/
|
||||
for (fp1 = __flp, fp2 = 0;
|
||||
fp1;
|
||||
fp2 = fp1, fp1 = fp1->nx) {
|
||||
if (fp1 < fpnew)
|
||||
continue;
|
||||
cp1 = (char *)fp1;
|
||||
fpnew->nx = fp1;
|
||||
if (((char *)&fpnew[1]) + fpnew->sz == cp1) {
|
||||
/* upper chunk adjacent, assimilate it */
|
||||
fpnew->sz += fp1->sz + sizeof(struct __freelist);
|
||||
fpnew->nx = fp1->nx;
|
||||
}
|
||||
if (fp2 == 0) {
|
||||
/* new head of freelist */
|
||||
__flp = fpnew;
|
||||
return;
|
||||
}
|
||||
break;
|
||||
}
|
||||
/*
|
||||
* Note that we get here either if we hit the "break" above,
|
||||
* or if we fell off the end of the loop. The latter means
|
||||
* we've got a new topmost chunk. Either way, try aggregating
|
||||
* with the lower chunk if possible.
|
||||
*/
|
||||
fp2->nx = fpnew;
|
||||
cp2 = (char *)&fp2[1];
|
||||
if (cp2 + fp2->sz == cpnew) {
|
||||
/* lower junk adjacent, merge */
|
||||
fp2->sz += fpnew->sz + sizeof(struct __freelist);
|
||||
fp2->nx = fpnew->nx;
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef MALLOC_TEST
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
|
||||
void *handles[32];
|
||||
size_t sizes[32];
|
||||
|
||||
|
||||
void *
|
||||
alloc(size_t s)
|
||||
{
|
||||
void *p;
|
||||
|
||||
if ((p = malloc(s)) == 0) {
|
||||
malloc_compact();
|
||||
if ((p = malloc(s)) == 0)
|
||||
return 0;
|
||||
}
|
||||
memset(p, 0xd0, s);
|
||||
return p;
|
||||
}
|
||||
|
||||
void
|
||||
printfreelist(void)
|
||||
{
|
||||
struct __freelist *fp1;
|
||||
int i;
|
||||
|
||||
if (!__flp) {
|
||||
printf("no free list\n");
|
||||
return;
|
||||
}
|
||||
|
||||
for (i = 0, fp1 = __flp; fp1; i++, fp1 = fp1->nx) {
|
||||
printf("free %d @ %u: size %u, next ",
|
||||
i, (char *)fp1 - mymem, fp1->sz);
|
||||
if (fp1->nx)
|
||||
printf("%u\n", (char *)fp1->nx - mymem);
|
||||
else
|
||||
printf("NULL\n");
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
compare(const void *p1, const void *p2)
|
||||
{
|
||||
return *((size_t *)p1) - *((size_t *)p2);
|
||||
}
|
||||
|
||||
void
|
||||
printalloc(void)
|
||||
{
|
||||
int j, k;
|
||||
size_t i;
|
||||
size_t sum, sum2;
|
||||
void *sortedhandles[32];
|
||||
struct __freelist *fp;
|
||||
char *cp;
|
||||
|
||||
for (i = j = k = sum = sum2 = 0;
|
||||
i < sizeof handles / sizeof (void *);
|
||||
i++)
|
||||
if (sizes[i]) {
|
||||
j++;
|
||||
sum += sizes[i];
|
||||
if (handles[i]) {
|
||||
k++;
|
||||
sum2 += sizes[i];
|
||||
}
|
||||
}
|
||||
printf("brkval: %d, %d request%s => sum %u bytes "
|
||||
"(actually %d reqs => %u bytes)\n",
|
||||
(char *)__brkval - mymem, j, j == 1? "": "s", sum, k, sum2);
|
||||
memcpy(sortedhandles, handles, sizeof sortedhandles);
|
||||
qsort(sortedhandles, 32, sizeof(void *), compare);
|
||||
for (i = j = 0; i < sizeof sortedhandles / sizeof (void *); i++)
|
||||
if ((cp = sortedhandles[i])) {
|
||||
cp -= sizeof(struct __freelist);
|
||||
fp = (struct __freelist *)cp;
|
||||
printf("alloc %d @ %u: %u bytes, handle %p\n",
|
||||
j, (char *)fp - mymem, fp->sz, fp->handle);
|
||||
j++;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
printblk(void)
|
||||
{
|
||||
struct __freelist *fp = __flp;
|
||||
struct __freelist *ap = (struct __freelist *)__malloc_heap_start;
|
||||
struct __freelist *end = (struct __freelist *)__brkval;
|
||||
int b = 0;
|
||||
int e = 0;
|
||||
|
||||
if (fp == 0)
|
||||
fp = end;
|
||||
|
||||
alloclist:
|
||||
while (ap < fp) {
|
||||
printf("Alloc %d @ %u: %u bytes, handle %p\n",
|
||||
b, (char *)ap - mymem, ap->sz, ap->handle);
|
||||
ap = (void *)(((char *)ap) + sizeof(struct __freelist) + ap->sz);
|
||||
b++;
|
||||
}
|
||||
|
||||
if (fp < end) {
|
||||
printf("Free %d @ %u: size %u, next ",
|
||||
e, (char *)fp - mymem, fp->sz);
|
||||
if (fp->nx)
|
||||
printf("%u\n", (char *)fp->nx - mymem);
|
||||
else
|
||||
printf("NULL\n");
|
||||
ap = (void *)(((char *)fp) + sizeof(struct __freelist) + fp->sz);
|
||||
fp = fp->nx;
|
||||
if (fp == 0)
|
||||
fp = end;
|
||||
e++;
|
||||
}
|
||||
|
||||
if (ap < end)
|
||||
goto alloclist;
|
||||
}
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
int i, j, k, l, m, om, p, f;
|
||||
size_t s;
|
||||
|
||||
srand(time(0) ^ getpid());
|
||||
|
||||
for (k = 0; k < 100; k++) {
|
||||
memset(handles, 0, sizeof handles);
|
||||
memset(sizes, 0, sizeof sizes);
|
||||
|
||||
j = rand() % 16 + 15;
|
||||
l = rand() % 80 + 7;
|
||||
|
||||
for (i = s = 0; i < j && s < 256; i++) {
|
||||
sizes[i] = rand() % l + 1;
|
||||
s += sizes[i];
|
||||
}
|
||||
j = i;
|
||||
for (m = om = 1, p = 1, f = 0; m < 1000; m++) {
|
||||
for (i = s = 0; i < j; i++)
|
||||
if (handles[i])
|
||||
s++;
|
||||
if (s == (unsigned)j)
|
||||
break;
|
||||
|
||||
if (m / om > 10) {
|
||||
p <<= 1;
|
||||
p |= 1;
|
||||
}
|
||||
|
||||
for (i = 0; i < j; i++)
|
||||
if (rand() & p) {
|
||||
if (!handles[i]) {
|
||||
if ((handles[i] = alloc(sizes[i])) == 0)
|
||||
f++;
|
||||
else if (sizes[i] & 1)
|
||||
malloc_unlock(&handles[i]);
|
||||
}
|
||||
}
|
||||
for (i = 0; i < j; i++) {
|
||||
if (rand() & 1) {
|
||||
free(handles[i]);
|
||||
handles[i] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (f)
|
||||
printf("%d alloc failure%s total\n",
|
||||
f, f == 1? "": "s");
|
||||
printf("After alloc:\n");
|
||||
printalloc();
|
||||
//printfreelist();
|
||||
printblk();
|
||||
for (i = 0; i < j; i++)
|
||||
free(handles[i]);
|
||||
printf("After cleanup:\n");
|
||||
printfreelist();
|
||||
//printblk();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif /* MALLOC_TEST */
|
|
@ -1,88 +0,0 @@
|
|||
/* Copyright (c) 2004, Joerg Wunsch
|
||||
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 copyright holders nor the names of
|
||||
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.
|
||||
*/
|
||||
|
||||
/* $Id: malloc.h,v 1.1 2008/08/15 19:05:17 adamdunkels Exp $ */
|
||||
|
||||
#ifndef MALLOC_H
|
||||
#define MALLOC_H
|
||||
|
||||
#if !defined(__DOXYGEN__)
|
||||
|
||||
struct __freelist {
|
||||
size_t sz;
|
||||
struct __freelist *nx;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Only unlocked memory can be subject to compaction.
|
||||
*
|
||||
* Malloc and realloc return locked memory.
|
||||
*/
|
||||
void malloc_unlock(void **h);
|
||||
void malloc_lock(void **h);
|
||||
void malloc_compact(void);
|
||||
void malloc_compact_one(void);
|
||||
|
||||
void *malloc(size_t size);
|
||||
void *realloc(void *ptr, size_t size);
|
||||
void free(void *ptr);
|
||||
|
||||
extern char *__brkval; /* first location not yet allocated */
|
||||
extern struct __freelist *__flp; /* freelist pointer (head of freelist) */
|
||||
extern char *__malloc_heap_end;
|
||||
|
||||
#define MALLOC_ROUNDUP (sizeof(int) - 1)
|
||||
|
||||
#ifdef MALLOC_TEST
|
||||
/*
|
||||
* When compiling malloc.c/realloc.c natively on a host machine, it will
|
||||
* include a main() that performs a regression test. This is meant as
|
||||
* a debugging aid, where a normal source-level debugger will help to
|
||||
* verify that the various allocator structures have the desired
|
||||
* appearance at each stage.
|
||||
*
|
||||
*/
|
||||
|
||||
extern void *mymalloc(size_t);
|
||||
extern void myfree(void *);
|
||||
extern void *myrealloc(void *, size_t);
|
||||
|
||||
#define malloc mymalloc
|
||||
#define free myfree
|
||||
#define realloc myrealloc
|
||||
|
||||
#define __malloc_heap_start &mymem[0]
|
||||
#define __malloc_heap_end &mymem[256]
|
||||
extern char mymem[];
|
||||
|
||||
#endif /* MALLOC_TEST */
|
||||
|
||||
#endif /* MALLOC_H */
|
|
@ -1,133 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2006, Swedish Institute of Computer Science
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. 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.
|
||||
* 3. Neither the name of the Institute 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 INSTITUTE 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 INSTITUTE 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.
|
||||
*
|
||||
* @(#)$Id: malloc_compact.c,v 1.1 2008/08/15 19:05:17 adamdunkels Exp $
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#ifdef MALLOC_TEST
|
||||
#include "malloc.h"
|
||||
#else
|
||||
#include "contiki.h"
|
||||
#include "lib/malloc.h"
|
||||
#endif /* !MALLOC_TEST */
|
||||
|
||||
#define handle nx
|
||||
|
||||
void
|
||||
malloc_unlock(void **h)
|
||||
{
|
||||
struct __freelist *t = *h;
|
||||
t = &t[-1];
|
||||
t->handle = (void *)h;
|
||||
}
|
||||
|
||||
void
|
||||
malloc_lock(void **h)
|
||||
{
|
||||
struct __freelist *t = *h;
|
||||
t = &t[-1];
|
||||
t->handle = NULL;
|
||||
}
|
||||
|
||||
static int
|
||||
compact1(struct __freelist **flp)
|
||||
{
|
||||
struct __freelist *fp = *flp, *fp2;
|
||||
struct __freelist *ap1, *ap2;
|
||||
struct __freelist *end = (struct __freelist *)__brkval;
|
||||
|
||||
ap1 = (void *)(((char *)fp) + sizeof(struct __freelist) + fp->sz);
|
||||
if (ap1 >= end)
|
||||
return 0;
|
||||
if (ap1->handle == NULL)
|
||||
return 0;
|
||||
|
||||
ap2 = (void *)(((char *)ap1) + sizeof(struct __freelist) + ap1->sz);
|
||||
fp2 = fp->nx;
|
||||
|
||||
if (ap2 != fp2) { /* 2 blocks become 2 */
|
||||
size_t s = fp->sz;
|
||||
|
||||
fp->sz = ap1->sz;
|
||||
fp->handle = ap1->handle;
|
||||
memcpy(&fp[1], &ap1[1], ap1->sz);
|
||||
*(void **)(fp->handle) = &fp[1];
|
||||
|
||||
fp = (void *)(((char *)fp) + sizeof(struct __freelist) + fp->sz);
|
||||
fp->sz = s;
|
||||
fp->nx = fp2;
|
||||
*flp = fp;
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (ap2 == fp2) { /* 3 blocks become 2 */
|
||||
size_t s = fp->sz + fp2->sz + sizeof(struct __freelist);
|
||||
|
||||
fp->sz = ap1->sz;
|
||||
fp->handle = ap1->handle;
|
||||
memcpy(&fp[1], &ap1[1], ap1->sz);
|
||||
*(void **)(fp->handle) = &fp[1];
|
||||
|
||||
fp = (void *)(((char *)fp) + sizeof(struct __freelist) + fp->sz);
|
||||
fp->sz = s;
|
||||
fp->nx = fp2->nx;
|
||||
*flp = fp;
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
malloc_compact(void)
|
||||
{
|
||||
struct __freelist **flp;
|
||||
|
||||
flp = &__flp;
|
||||
while (*flp != NULL) {
|
||||
while (compact1(flp))
|
||||
;
|
||||
flp = &((*flp)->nx);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
malloc_compact_one(void)
|
||||
{
|
||||
struct __freelist **flp;
|
||||
|
||||
flp = &__flp;
|
||||
while (*flp != NULL) {
|
||||
if (compact1(flp))
|
||||
return ;
|
||||
flp = &((*flp)->nx);
|
||||
}
|
||||
}
|
|
@ -1,159 +0,0 @@
|
|||
/* Copyright (c) 2004 Joerg Wunsch
|
||||
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 copyright holders nor the names of
|
||||
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.
|
||||
*/
|
||||
/* $Id: realloc.c,v 1.1 2008/08/15 19:57:13 adamdunkels Exp $ */
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#ifdef MALLOC_TEST
|
||||
#include "malloc.h"
|
||||
#else
|
||||
#include "contiki.h"
|
||||
#include "lib/malloc.h"
|
||||
#endif /* !MALLOC_TEST */
|
||||
|
||||
void *
|
||||
realloc(void *ptr, size_t len)
|
||||
{
|
||||
struct __freelist *fp1, *fp2, *fp3, *ofp3;
|
||||
char *cp, *cp1;
|
||||
void *memp;
|
||||
size_t s, incr;
|
||||
|
||||
/* Trivial case, required by C standard. */
|
||||
if (ptr == 0)
|
||||
return malloc(len);
|
||||
|
||||
if (len < 0)
|
||||
return 0;
|
||||
|
||||
len = (len + MALLOC_ROUNDUP) & ~MALLOC_ROUNDUP;
|
||||
|
||||
cp1 = (char *)ptr;
|
||||
cp1 -= sizeof(struct __freelist);
|
||||
fp1 = (struct __freelist *)cp1;
|
||||
|
||||
cp = (char *)ptr + len; /* new next pointer */
|
||||
if (cp < cp1)
|
||||
/* Pointer wrapped across top of RAM, fail. */
|
||||
return 0;
|
||||
fp2 = (struct __freelist *)cp;
|
||||
|
||||
/*
|
||||
* See whether we are growing or shrinking. When shrinking,
|
||||
* we split off a chunk for the released portion, and call
|
||||
* free() on it. Therefore, we can only shrink if the new
|
||||
* size is at least sizeof(struct __freelist) smaller than the
|
||||
* previous size.
|
||||
*/
|
||||
if (len <= fp1->sz) {
|
||||
/* The first test catches a possible unsigned int
|
||||
* rollover condition. */
|
||||
if (fp1->sz <= sizeof(struct __freelist) ||
|
||||
len > fp1->sz - sizeof(struct __freelist))
|
||||
return ptr;
|
||||
fp2->sz = fp1->sz - len - sizeof(struct __freelist);
|
||||
fp1->sz = len;
|
||||
free(&fp2[1]);
|
||||
return ptr;
|
||||
}
|
||||
|
||||
/*
|
||||
* If we get here, we are growing. First, see whether there
|
||||
* is space in the free list on top of our current chunk.
|
||||
*/
|
||||
incr = len - fp1->sz - sizeof(struct __freelist);
|
||||
cp = (char *)ptr + fp1->sz;
|
||||
fp2 = (struct __freelist *)cp;
|
||||
for (s = 0, ofp3 = 0, fp3 = __flp;
|
||||
fp3;
|
||||
ofp3 = fp3, fp3 = fp3->nx) {
|
||||
if (fp3 == fp2 && fp3->sz >= incr) {
|
||||
/* found something that fits */
|
||||
if (incr <= fp3->sz &&
|
||||
incr > fp3->sz - sizeof(struct __freelist)) {
|
||||
/* it just fits, so use it entirely */
|
||||
fp1->sz += fp3->sz + sizeof(struct __freelist);
|
||||
if (ofp3)
|
||||
ofp3->nx = fp3->nx;
|
||||
else
|
||||
__flp = fp3->nx;
|
||||
return ptr;
|
||||
}
|
||||
/* split off a new freelist entry */
|
||||
cp = (char *)ptr + len;
|
||||
fp2 = (struct __freelist *)cp;
|
||||
fp2->nx = fp3->nx;
|
||||
fp2->sz = fp3->sz - incr - sizeof(struct __freelist);
|
||||
if (ofp3)
|
||||
ofp3->nx = fp2;
|
||||
else
|
||||
__flp = fp2;
|
||||
fp1->sz = len;
|
||||
return ptr;
|
||||
}
|
||||
/*
|
||||
* Find the largest chunk on the freelist while
|
||||
* walking it.
|
||||
*/
|
||||
if (fp3->sz > s)
|
||||
s = fp3->sz;
|
||||
}
|
||||
/*
|
||||
* If we are the topmost chunk in memory, and there was no
|
||||
* large enough chunk on the freelist that could be re-used
|
||||
* (by a call to malloc() below), quickly extend the
|
||||
* allocation area if possible, without need to copy the old
|
||||
* data.
|
||||
*/
|
||||
if (__brkval == (char *)ptr + fp1->sz && len > s) {
|
||||
cp1 = __malloc_heap_end;
|
||||
cp = (char *)ptr + len;
|
||||
if (cp < cp1) {
|
||||
__brkval = cp;
|
||||
fp1->sz = len;
|
||||
return ptr;
|
||||
}
|
||||
/* If that failed, we are out of luck. */
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Call malloc() for a new chunk, then copy over the data, and
|
||||
* release the old region.
|
||||
*/
|
||||
if ((memp = malloc(len)) == 0)
|
||||
return 0;
|
||||
memcpy(memp, ptr, fp1->sz);
|
||||
free(ptr);
|
||||
return memp;
|
||||
}
|
||||
|
|
@ -1,54 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2005, Swedish Institute of Computer Science.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. 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.
|
||||
* 3. Neither the name of the Institute 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 INSTITUTE 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 INSTITUTE 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.
|
||||
*
|
||||
* This file is part of the Contiki operating system.
|
||||
*
|
||||
* $Id: adhoc-service.h,v 1.1 2007/05/23 23:28:19 oliverschmidt Exp $
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file
|
||||
* Header file for the ad hoc routing service
|
||||
* \author
|
||||
* Adam Dunkels <adam@sics.se>
|
||||
*/
|
||||
|
||||
#ifndef __ADHOC_SERVICE_H__
|
||||
#define __ADHOC_SERVICE_H__
|
||||
|
||||
#include "contiki.h"
|
||||
|
||||
SERVICE_INTERFACE(adhoc_service,
|
||||
{
|
||||
void (* send)(uip_ipaddr_t addr, char *buf, int len);
|
||||
process_event_t sent;
|
||||
});
|
||||
|
||||
#define adhoc_service_name "Ad hoc routing service"
|
||||
|
||||
#endif /* __ADHOC_SERVICE_H__ */
|
|
@ -1,68 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2005, Swedish Institute of Computer Science
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. 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.
|
||||
* 3. Neither the name of the Institute 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 INSTITUTE 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 INSTITUTE 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.
|
||||
*
|
||||
* This file is part of the Contiki operating system.
|
||||
*
|
||||
* @(#)$Id: hc-service.c,v 1.1 2007/05/23 23:28:19 oliverschmidt Exp $
|
||||
*/
|
||||
|
||||
#include "hc-service.h"
|
||||
|
||||
static void
|
||||
compress(void)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
static void
|
||||
decompress(void)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
SERVICE(hc_service, { compress, decompress });
|
||||
|
||||
|
||||
PROCESS(hc_service_process, "Header compression");
|
||||
|
||||
PROCESS_THREAD(hc_service_process, ev, data)
|
||||
{
|
||||
PROCESS_BEGIN();
|
||||
|
||||
PROCESS_SET_FLAGS(PROCESS_NO_BROADCAST);
|
||||
|
||||
SERVICE_REGISTER(hc_service);
|
||||
|
||||
while(1) {
|
||||
PROCESS_WAIT_EVENT_UNTIL(ev == PROCESS_EVENT_EXIT);
|
||||
}
|
||||
|
||||
SERVICE_REMOVE(hc_service);
|
||||
|
||||
PROCESS_END();
|
||||
}
|
|
@ -1,45 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2005, Swedish Institute of Computer Science
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. 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.
|
||||
* 3. Neither the name of the Institute 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 INSTITUTE 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 INSTITUTE 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.
|
||||
*
|
||||
* This file is part of the Contiki operating system.
|
||||
*
|
||||
* @(#)$Id: hc-service.h,v 1.1 2007/05/23 23:28:19 oliverschmidt Exp $
|
||||
*/
|
||||
#ifndef __HC_SERVICE_H__
|
||||
#define __HC_SERVICE_H__
|
||||
|
||||
#include "service.h"
|
||||
|
||||
SERVICE_INTERFACE(hc_service, {
|
||||
void (* compress)(void);
|
||||
void (* decompress)(void);
|
||||
});
|
||||
|
||||
#define hc_service_name "Header compression"
|
||||
|
||||
#endif /* __HC_SERVICE_H__ */
|
|
@ -1,381 +0,0 @@
|
|||
/* www.mycal.com
|
||||
*---------------------------------------------------------------------------
|
||||
* ahdlc.c - Ahdlc receive and transmit processor for PPP engine.
|
||||
*
|
||||
*---------------------------------------------------------------------------
|
||||
* Version
|
||||
* 0.1 Original Version Jan 11, 1998
|
||||
*
|
||||
*---------------------------------------------------------------------------
|
||||
*
|
||||
* Copyright (C) 1998, Mycal Labs www.mycal.com
|
||||
*
|
||||
*---------------------------------------------------------------------------
|
||||
*/
|
||||
/*
|
||||
* Copyright (c) 2003, Mike Johnson, Mycal Labs, www.mycal.net
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. 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.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by Mike Johnson/Mycal Labs
|
||||
* www.mycal.net.
|
||||
* 4. The name of the author may not be used to endorse or promote
|
||||
* products derived from this software without specific prior
|
||||
* written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
||||
*
|
||||
* This file is part of the Mycal Modified uIP TCP/IP stack.
|
||||
*
|
||||
* $Id: ahdlc.c,v 1.1 2007/05/26 07:14:39 oliverschmidt Exp $
|
||||
*
|
||||
*/
|
||||
|
||||
/* */
|
||||
/* include files */
|
||||
/* */
|
||||
|
||||
#include "net/uip.h"
|
||||
#include "ppp.h"
|
||||
|
||||
#if 0
|
||||
#define DEBUG1(x)
|
||||
#else
|
||||
#include <stdio.h>
|
||||
#define DEBUG1(x) debug_printf x
|
||||
#endif
|
||||
|
||||
#define PACKET_TX_DEBUG 1
|
||||
|
||||
/*---------------------------------------------------------------------------
|
||||
* ahdlc flags bit defins, for ahdlc_flags variable
|
||||
---------------------------------------------------------------------------*/
|
||||
/* Escaped mode bit */
|
||||
#define AHDLC_ESCAPED 0x1
|
||||
/* Frame is ready bit */
|
||||
#define AHDLC_RX_READY 0x2
|
||||
#define AHDLC_RX_ASYNC_MAP 0x4
|
||||
#define AHDLC_TX_ASYNC_MAP 0x8
|
||||
#define AHDLC_PFC 0x10
|
||||
#define AHDLC_ACFC 0x20
|
||||
|
||||
/*---------------------------------------------------------------------------
|
||||
* Private Local Globals
|
||||
* 10 bytes - standard
|
||||
* - with counters
|
||||
---------------------------------------------------------------------------*/
|
||||
/* running tx CRC */
|
||||
u16_t ahdlc_tx_crc;
|
||||
/* running rx CRC */
|
||||
u16_t ahdlc_rx_crc;
|
||||
/* number of rx bytes processed, cur frame */
|
||||
u16_t ahdlc_rx_count;
|
||||
/* ahdlc state flags, see above */
|
||||
u8_t ahdlc_flags;
|
||||
|
||||
u8_t ahdlc_tx_offline;
|
||||
|
||||
/*
|
||||
* The following can be optimized out
|
||||
*/
|
||||
u8_t *ahdlc_rx_buffer; /* What to do here? +++ */
|
||||
u16_t ahdlc_max_rx_buffer_size;
|
||||
|
||||
/*
|
||||
* Optional statistics counters.
|
||||
*/
|
||||
#ifdef AHDLC_COUNTERS
|
||||
u8_t ahdlc_rx_tobig_error;
|
||||
#endif
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/* Simple and fast CRC16 routine for embedded processors.
|
||||
* Just slightly slower than the table lookup method but consumes
|
||||
* almost no space. Much faster and smaller than the loop and
|
||||
* shift method that is widely used in the embedded space.
|
||||
* Can be optimized even more in .ASM
|
||||
*
|
||||
* data = (crcvalue ^ inputchar) & 0xff;
|
||||
* data = (data ^ (data << 4)) & 0xff;
|
||||
* crc = (crc >> 8) ^ ((data << 8) ^ (data <<3) ^ (data >> 4))
|
||||
*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static u16_t
|
||||
crcadd(u16_t crcvalue, u8_t c)
|
||||
{
|
||||
u16_t b;
|
||||
|
||||
b = (crcvalue ^ c) & 0xFF;
|
||||
b = (b ^ (b << 4)) & 0xFF;
|
||||
b = (b << 8) ^ (b << 3) ^ (b >> 4);
|
||||
|
||||
return ((crcvalue >> 8) ^ b);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/* ahdlc_init(buffer, buffersize) - this initializes the ahdlc engine to
|
||||
* allow for rx frames.
|
||||
*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void
|
||||
ahdlc_init(u8_t *buffer, u16_t maxrxbuffersize)
|
||||
{
|
||||
ahdlc_flags = 0 | AHDLC_RX_ASYNC_MAP;
|
||||
ahdlc_rx_buffer = buffer;
|
||||
ahdlc_max_rx_buffer_size = maxrxbuffersize;
|
||||
/* ahdlc_async_map = 0; */
|
||||
#ifdef AHDLC_COUNTERS
|
||||
ahdlc_rx_tobig_error = 0;
|
||||
ahdl_tx_offline = 0;
|
||||
#endif
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/* ahdlc_rx_ready() - resets the ahdlc engine to the beginning of frame
|
||||
* state.
|
||||
*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void
|
||||
ahdlc_rx_ready(void)
|
||||
{
|
||||
ahdlc_rx_count = 0;
|
||||
ahdlc_rx_crc = 0xffff;
|
||||
ahdlc_flags |= AHDLC_RX_READY;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/* ahdlc receive function - This routine processes incoming bytes and tries
|
||||
* to build a PPP frame.
|
||||
*
|
||||
* Two possible reasons that ahdlc_rx will not process characters:
|
||||
* o Buffer is locked - in this case ahdlc_rx returns 1, char
|
||||
* sending routing should retry.
|
||||
*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
u8_t
|
||||
ahdlc_rx(u8_t c)
|
||||
{
|
||||
static u16_t protocol;
|
||||
|
||||
/* check to see if PPP packet is useable, we should have hardware
|
||||
flow control set, but if host ignores it and sends us a char when
|
||||
the PPP Receive packet is in use, discard the character. +++ */
|
||||
|
||||
if(ahdlc_flags & AHDLC_RX_READY) {
|
||||
/* check to see if character is less than 0x20 hex we really
|
||||
should set AHDLC_RX_ASYNC_MAP on by default and only turn it
|
||||
off when it is negotiated off to handle some buggy stacks. */
|
||||
if((c < 0x20) &&
|
||||
((ahdlc_flags & AHDLC_RX_ASYNC_MAP) == 0)) {
|
||||
/* discard character */
|
||||
DEBUG1(("Discard because char is < 0x20 hex and asysnc map is 0\n"));
|
||||
return 0;
|
||||
}
|
||||
/* are we in escaped mode? */
|
||||
if(ahdlc_flags & AHDLC_ESCAPED) {
|
||||
/* set escaped to FALSE */
|
||||
ahdlc_flags &= ~AHDLC_ESCAPED;
|
||||
|
||||
/* if value is 0x7e then silently discard and reset receive packet */
|
||||
if(c == 0x7e) {
|
||||
ahdlc_rx_ready();
|
||||
return 0;
|
||||
}
|
||||
/* incomming char = itself xor 20 */
|
||||
c = c ^ 0x20;
|
||||
} else if(c == 0x7e) {
|
||||
/* handle frame end */
|
||||
if(ahdlc_rx_crc == CRC_GOOD_VALUE) {
|
||||
DEBUG1(("\nReceiving packet with good crc value, len %d\n",ahdlc_rx_count));
|
||||
/* we hae a good packet, turn off CTS until we are done with
|
||||
this packet */
|
||||
/*CTS_OFF();*/
|
||||
/* remove CRC bytes from packet */
|
||||
ahdlc_rx_count -= 2;
|
||||
|
||||
/* lock PPP buffer */
|
||||
ahdlc_flags &= ~AHDLC_RX_READY;
|
||||
/*
|
||||
* upcall routine must fully process frame before return
|
||||
* as returning signifies that buffer belongs to AHDLC again.
|
||||
*/
|
||||
if((c & 0x1) && (ahdlc_flags & PPP_PFC)) {
|
||||
/* Send up packet */
|
||||
ppp_upcall((u16_t)ahdlc_rx_buffer[0],
|
||||
(u8_t *)&ahdlc_rx_buffer[1],
|
||||
(u16_t)(ahdlc_rx_count - 1));
|
||||
} else {
|
||||
/* Send up packet */
|
||||
ppp_upcall((u16_t)(ahdlc_rx_buffer[0] << 8 | ahdlc_rx_buffer[1]),
|
||||
(u8_t *)&ahdlc_rx_buffer[2], (u16_t)(ahdlc_rx_count - 2));
|
||||
}
|
||||
ahdlc_tx_offline = 0; // The remote side is alive
|
||||
ahdlc_rx_ready();
|
||||
return 0;
|
||||
} else if(ahdlc_rx_count > 3) {
|
||||
DEBUG1(("\nReceiving packet with bad crc value, was 0x%04x len %d\n",ahdlc_rx_crc, ahdlc_rx_count));
|
||||
#ifdef AHDLC_COUNTERS
|
||||
++ahdlc_crc_error;
|
||||
#endif
|
||||
/* Shouldn't we dump the packet and not pass it up? */
|
||||
/*ppp_upcall((u16_t)ahdlc_rx_buffer[0],
|
||||
(u8_t *)&ahdlc_rx_buffer[0], (u16_t)(ahdlc_rx_count+2));
|
||||
dump_ppp_packet(&ahdlc_rx_buffer[0],ahdlc_rx_count);*/
|
||||
|
||||
}
|
||||
ahdlc_rx_ready();
|
||||
return 0;
|
||||
} else if(c == 0x7d) {
|
||||
/* handle escaped chars*/
|
||||
ahdlc_flags |= PPP_ESCAPED;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* try to store char if not to big */
|
||||
if(ahdlc_rx_count >= ahdlc_max_rx_buffer_size /*PPP_RX_BUFFER_SIZE*/) {
|
||||
#ifdef AHDLC_COUNTERS
|
||||
++ahdlc_rx_tobig_error;
|
||||
#endif
|
||||
ahdlc_rx_ready();
|
||||
} else {
|
||||
/* Add CRC in */
|
||||
ahdlc_rx_crc = crcadd(ahdlc_rx_crc, c);
|
||||
/* do auto ACFC, if packet len is zero discard 0xff and 0x03 */
|
||||
if(ahdlc_rx_count == 0) {
|
||||
if((c == 0xff) || (c == 0x03))
|
||||
return 0;
|
||||
}
|
||||
/* Store char */
|
||||
ppp_rx_buffer[ahdlc_rx_count++] = c;
|
||||
}
|
||||
} else {
|
||||
/* we are busy and didn't process the character. */
|
||||
DEBUG1(("Busy/not active\n"));
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/* ahdlc_tx_char(char) - write a character to the serial device,
|
||||
* escape if necessary.
|
||||
*
|
||||
* Relies on local global vars : ahdlc_tx_crc, ahdlc_flags.
|
||||
* Modifies local global vars : ahdlc_tx_crc.
|
||||
*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void
|
||||
ahdlc_tx_char(u16_t protocol, u8_t c)
|
||||
{
|
||||
/* add in crc */
|
||||
ahdlc_tx_crc = crcadd(ahdlc_tx_crc, c);
|
||||
/*
|
||||
* See if we need to escape char, we always escape 0x7d and 0x7e, in the case
|
||||
* of char < 0x20 we only support async map of default or none, so escape if
|
||||
* ASYNC map is not set. We may want to modify this to support a bitmap set
|
||||
* ASYNC map.
|
||||
*/
|
||||
if((c == 0x7d) || (c == 0x7e) ||
|
||||
((c < 0x20) && ((protocol == LCP) ||
|
||||
(ahdlc_flags & PPP_TX_ASYNC_MAP) == 0))) {
|
||||
/* send escape char and xor byte by 0x20 */
|
||||
ppp_arch_putchar(0x7d);
|
||||
c ^= 0x20;
|
||||
}
|
||||
ppp_arch_putchar(c);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/* ahdlc_tx(protocol,buffer,len) - Transmit a PPP frame.
|
||||
* Buffer contains protocol data, ahdlc_tx addes address, control and
|
||||
* protocol data.
|
||||
*
|
||||
* Relies on local global vars : ahdlc_tx_crc, ahdlc_flags.
|
||||
* Modifies local global vars : ahdlc_tx_crc.
|
||||
*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
u8_t
|
||||
ahdlc_tx(u16_t protocol, u8_t *header, u8_t *buffer,
|
||||
u16_t headerlen, u16_t datalen)
|
||||
{
|
||||
u16_t i;
|
||||
u8_t c;
|
||||
|
||||
DEBUG1(("\nAHDLC_TX - transmit frame, protocol 0x%04x, length %d offline %d\n",protocol,datalen+headerlen,ahdlc_tx_offline));
|
||||
if (AHDLC_TX_OFFLINE && (ahdlc_tx_offline++ > AHDLC_TX_OFFLINE)) {
|
||||
ahdlc_tx_offline = 0;
|
||||
DEBUG1(("\nAHDLC_TX to many outstanding TX packets => ppp_reconnect()\n"));
|
||||
ppp_reconnect();
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if PACKET_TX_DEBUG
|
||||
DEBUG1(("\n"));
|
||||
for(i = 0; i < headerlen; ++i) {
|
||||
DEBUG1(("0x%02x ", header[i]));
|
||||
}
|
||||
for(i = 0; i < datalen; ++i) {
|
||||
DEBUG1(("0x%02x ", buffer[i]));
|
||||
}
|
||||
DEBUG1(("\n\n"));
|
||||
#endif
|
||||
|
||||
/* Check to see that physical layer is up, we can assume is some
|
||||
cases */
|
||||
|
||||
/* write leading 0x7e */
|
||||
ppp_arch_putchar(0x7e);
|
||||
|
||||
/* set initial CRC value */
|
||||
ahdlc_tx_crc = 0xffff;
|
||||
/* send HDLC control and address if not disabled or of LCP frame type */
|
||||
/*if((0==(ahdlc_flags & PPP_ACFC)) || ((0xc0==buffer[0]) && (0x21==buffer[1]))) */
|
||||
if((0 == (ahdlc_flags & PPP_ACFC)) || (protocol == LCP)) {
|
||||
ahdlc_tx_char(protocol, 0xff);
|
||||
ahdlc_tx_char(protocol, 0x03);
|
||||
}
|
||||
|
||||
/* Write Protocol */
|
||||
ahdlc_tx_char(protocol,(u8_t)(protocol >> 8));
|
||||
ahdlc_tx_char(protocol,(u8_t)(protocol & 0xff));
|
||||
|
||||
/* write header if it exists */
|
||||
for(i = 0; i < headerlen; ++i) {
|
||||
/* Get next byte from buffer */
|
||||
c = header[i];
|
||||
/* Write it...*/
|
||||
ahdlc_tx_char(protocol, c);
|
||||
}
|
||||
|
||||
/* Write frame bytes */
|
||||
for(i = 0; i < datalen; ++i) {
|
||||
/* Get next byte from buffer */
|
||||
c = buffer[i];
|
||||
/* Write it...*/
|
||||
ahdlc_tx_char(protocol, c);
|
||||
}
|
||||
|
||||
/* send crc, lsb then msb */
|
||||
i = ahdlc_tx_crc ^ 0xffff;
|
||||
ahdlc_tx_char(protocol, (u8_t)(i & 0xff));
|
||||
ahdlc_tx_char(protocol, (u8_t)((i >> 8) & 0xff));
|
||||
|
||||
/* write trailing 0x7e, probably not needed but it doesn't hurt*/
|
||||
ppp_arch_putchar(0x7e);
|
||||
return 0;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
|
@ -1,57 +0,0 @@
|
|||
#ifndef __AHDLC_H__
|
||||
#define __AHDLC_H__
|
||||
|
||||
/*---------------------------------------------------------------------------
|
||||
ahdlc.h - ahdlc header file
|
||||
---------------------------------------------------------------------------
|
||||
Version
|
||||
0.1 Original Version Jan 11, 1998
|
||||
(c)1998 Mycal Labs, All Rights Reserved
|
||||
---------------------------------------------------------------------------*/
|
||||
/*
|
||||
* Copyright (c) 2003, Mike Johnson, Mycal Labs, www.mycal.net
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. 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.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by Mike Johnson/Mycal Labs
|
||||
* www.mycal.net.
|
||||
* 4. The name of the author may not be used to endorse or promote
|
||||
* products derived from this software without specific prior
|
||||
* written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
||||
*
|
||||
* This file is part of the Mycal Modified uIP TCP/IP stack.
|
||||
*
|
||||
* $Id: ahdlc.h,v 1.1 2007/05/26 07:14:39 oliverschmidt Exp $
|
||||
*
|
||||
*/
|
||||
|
||||
#include "net/uip.h"
|
||||
|
||||
void ahdlc_init(u8_t *, u16_t);
|
||||
void ahdlc_rx_ready(void);
|
||||
u8_t ahdlc_rx(u8_t);
|
||||
u8_t ahdlc_tx(u16_t protocol, u8_t *header, u8_t *buffer,
|
||||
u16_t headerlen, u16_t datalen);
|
||||
|
||||
#endif /* __AHDLC_H__ */
|
|
@ -1,462 +0,0 @@
|
|||
/*
|
||||
*---------------------------------------------------------------------------
|
||||
* ipcp.c - PPP IPCP (intrnet protocol) Processor/Handler
|
||||
*
|
||||
*---------------------------------------------------------------------------
|
||||
*
|
||||
* Version
|
||||
* 0.1 Original Version Jun 3, 2000
|
||||
*
|
||||
*---------------------------------------------------------------------------
|
||||
*
|
||||
* Copyright (C) 2000, Mycal Labs www.mycal.com
|
||||
*
|
||||
*---------------------------------------------------------------------------
|
||||
*/
|
||||
/*
|
||||
* Copyright (c) 2003, Mike Johnson, Mycal Labs, www.mycal.net
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. 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.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by Mike Johnson/Mycal Labs
|
||||
* www.mycal.net.
|
||||
* 4. The name of the author may not be used to endorse or promote
|
||||
* products derived from this software without specific prior
|
||||
* written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
||||
*
|
||||
* This file is part of the Mycal Modified uIP TCP/IP stack.
|
||||
*
|
||||
* $Id: ipcp.c,v 1.2 2010/10/19 18:29:03 adamdunkels Exp $
|
||||
*
|
||||
*/
|
||||
|
||||
/* */
|
||||
/* include files */
|
||||
/* */
|
||||
|
||||
#if 0
|
||||
#define DEBUG1(x)
|
||||
#else
|
||||
#include <stdio.h>
|
||||
#define DEBUG1(x) debug_printf x
|
||||
#endif
|
||||
|
||||
#include "net/uip.h"
|
||||
/*#include "time.h"*/
|
||||
#include "ipcp.h"
|
||||
#include "ppp.h"
|
||||
#include "ahdlc.h"
|
||||
|
||||
#define TIMER_expire()
|
||||
#define TIMER_set()
|
||||
#define TIMER_timeout(x) 1
|
||||
|
||||
#ifdef IPCP_GET_PEER_IP
|
||||
uip_ipaddr_t peer_ip_addr;
|
||||
#endif
|
||||
|
||||
#ifdef IPCP_GET_PRI_DNS
|
||||
uip_ipaddr_t pri_dns_addr;
|
||||
#endif
|
||||
|
||||
#ifdef IPCP_GET_SEC_DNS
|
||||
uip_ipaddr_t sec_dns_addr;
|
||||
#endif
|
||||
|
||||
static unsigned long prev_ipcp_seconds = 0;
|
||||
|
||||
/*
|
||||
* Local IPCP state
|
||||
*/
|
||||
u8_t ipcp_state;
|
||||
|
||||
/*
|
||||
* in the future add copression protocol and name servers (possibly for servers only)
|
||||
*/
|
||||
u8_t ipcplist[] = {0x3, 0};
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#if 1
|
||||
void
|
||||
printip(uip_ipaddr_t ip2)
|
||||
{
|
||||
char *ip = (u8_t*)ip2;
|
||||
DEBUG1((" %d.%d.%d.%d ",ip[0],ip[1],ip[2],ip[3]));
|
||||
}
|
||||
#else
|
||||
#define printip(x)
|
||||
#endif
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void
|
||||
ipcp_init(void)
|
||||
{
|
||||
DEBUG1(("ipcp init\n"));
|
||||
ipcp_state = 0;
|
||||
ppp_retry = 0;
|
||||
pppif.ipaddr[0] = pppif.ipaddr[1] = 0;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/*
|
||||
* IPCP RX protocol Handler
|
||||
*/
|
||||
void
|
||||
ipcp_rx(u8_t *buffer, u16_t count)
|
||||
{
|
||||
u8_t *bptr = buffer;
|
||||
IPCPPKT *pkt=(IPCPPKT *)buffer;
|
||||
u16_t len;
|
||||
|
||||
DEBUG1(("IPCP len %d\n",count));
|
||||
|
||||
switch(*bptr++) {
|
||||
case CONF_REQ:
|
||||
/* parce request and see if we can ACK it */
|
||||
++bptr;
|
||||
len = (*bptr++ << 8);
|
||||
len |= *bptr++;
|
||||
/* len-=2; */
|
||||
|
||||
DEBUG1(("check lcplist\n"));
|
||||
if(scan_packet(IPCP, ipcplist, buffer, bptr, (u16_t)(len - 4))) {
|
||||
DEBUG1(("option was bad\n"));
|
||||
} else {
|
||||
DEBUG1(("IPCP options are good\n"));
|
||||
/*
|
||||
* Parse out the results
|
||||
*/
|
||||
/* lets try to implement what peer wants */
|
||||
/* Reject any protocol not */
|
||||
/* Error? if we we need to send a config Reject ++++ this is
|
||||
good for a subroutine*/
|
||||
/* All we should get is the peer IP address */
|
||||
if(IPCP_IPADDRESS == *bptr++) {
|
||||
/* dump length */
|
||||
++bptr;
|
||||
#ifdef IPCP_GET_PEER_IP
|
||||
((u8_t*)peer_ip_addr)[0] = *bptr++;
|
||||
((u8_t*)peer_ip_addr)[1] = *bptr++;
|
||||
((u8_t*)peer_ip_addr)[2] = *bptr++;
|
||||
((u8_t*)peer_ip_addr)[3] = *bptr++;
|
||||
DEBUG1(("Peer IP "));
|
||||
/* printip(peer_ip_addr);*/
|
||||
DEBUG1(("\n"));
|
||||
#else
|
||||
bptr += 4;
|
||||
#endif
|
||||
} else {
|
||||
DEBUG1(("HMMMM this shouldn't happen IPCP1\n"));
|
||||
}
|
||||
|
||||
#if 0
|
||||
if(error) {
|
||||
/* write the config NAK packet we've built above, take on the header */
|
||||
bptr = buffer;
|
||||
*bptr++ = CONF_NAK; /* Write Conf_rej */
|
||||
*bptr++;
|
||||
/*tptr++;*/ /* skip over ID */
|
||||
|
||||
/* Write new length */
|
||||
*bptr++ = 0;
|
||||
*bptr = tptr - buffer;
|
||||
|
||||
/* write the reject frame */
|
||||
DEBUG1(("Writing NAK frame \n"));
|
||||
ahdlc_tx(IPCP, buffer, (u16_t)(tptr - buffer));
|
||||
DEBUG1(("- End NAK Write frame\n"));
|
||||
|
||||
} else {
|
||||
}
|
||||
#endif
|
||||
/*
|
||||
* If we get here then we are OK, lets send an ACK and tell the rest
|
||||
* of our modules our negotiated config.
|
||||
*/
|
||||
ipcp_state |= IPCP_RX_UP;
|
||||
DEBUG1(("Send IPCP ACK!\n"));
|
||||
bptr = buffer;
|
||||
*bptr++ = CONF_ACK; /* Write Conf_ACK */
|
||||
bptr++; /* Skip ID (send same one) */
|
||||
/*
|
||||
* Set stuff
|
||||
*/
|
||||
/* ppp_flags |= tflag; */
|
||||
DEBUG1(("SET- stuff -- are we up? c=%d dif=%d \n", count, (u16_t)(bptr-buffer)));
|
||||
|
||||
/* write the ACK frame */
|
||||
DEBUG1(("Writing ACK frame \n"));
|
||||
/* Send packet ahdlc_txz(procol,header,data,headerlen,datalen); */
|
||||
ahdlc_tx(IPCP, 0, buffer, 0, count /*bptr-buffer*/);
|
||||
DEBUG1(("- End ACK Write frame\n"));
|
||||
|
||||
/* expire the timer to make things happen after a state change */
|
||||
/*timer_expire(); */
|
||||
|
||||
/* } */
|
||||
}
|
||||
break;
|
||||
case CONF_ACK: /* config Ack */
|
||||
DEBUG1(("CONF ACK\n"));
|
||||
/*
|
||||
* Parse out the results
|
||||
*
|
||||
* Dump the ID and get the length.
|
||||
*/
|
||||
/* dump the ID */
|
||||
bptr++;
|
||||
|
||||
/* get the length */
|
||||
len = (*bptr++ << 8);
|
||||
len |= *bptr++;
|
||||
#if 0
|
||||
/* Parse ACK and set data */
|
||||
while(bptr < buffer + len) {
|
||||
switch(*bptr++) {
|
||||
case IPCP_IPADDRESS:
|
||||
/* dump length */
|
||||
bptr++;
|
||||
((u8_t*)ipaddr)[0] = *bptr++;
|
||||
((u8_t*)ipaddr)[1] = *bptr++;
|
||||
((u8_t*)ipaddr)[2] = *bptr++;
|
||||
((u8_t*)ipaddr)[3] = *bptr++;
|
||||
break;
|
||||
case IPCP_PRIMARY_DNS:
|
||||
bptr++;
|
||||
((u8_t*)pri_dns_addr)[0] = *bptr++;
|
||||
((u8_t*)pri_dns_addr)[1] = *bptr++;
|
||||
((u8_t*)pri_dns_addr)[2] = *bptr++;
|
||||
((u8_t*)pri_dns_addr)[3] = *bptr++;
|
||||
break;
|
||||
case IPCP_SECONDARY_DNS:
|
||||
bptr++;
|
||||
((u8_t*)sec_dns_addr)[0] = *bptr++;
|
||||
((u8_t*)sec_dns_addr)[1] = *bptr++;
|
||||
((u8_t*)sec_dns_addr)[2] = *bptr++;
|
||||
((u8_t*)sec_dns_addr)[3] = *bptr++;
|
||||
break;
|
||||
default:
|
||||
DEBUG1(("IPCP CONFIG_ACK problem1\n"));
|
||||
}
|
||||
}
|
||||
#endif
|
||||
ipcp_state |= IPCP_TX_UP;
|
||||
/*ipcp_state &= ~IPCP_RX_UP;*/
|
||||
DEBUG1(("were up! \n"));
|
||||
printip(pppif.ipaddr);
|
||||
#ifdef IPCP_GET_PRI_DNS
|
||||
printip(pri_dns_addr);
|
||||
#endif
|
||||
#ifdef IPCP_GET_SEC_DNS
|
||||
printip(sec_dns_addr);
|
||||
#endif
|
||||
DEBUG1(("\n"));
|
||||
|
||||
/* expire the timer to make things happen after a state change */
|
||||
TIMER_expire();
|
||||
break;
|
||||
case CONF_NAK: /* Config Nack */
|
||||
DEBUG1(("CONF NAK\n"));
|
||||
/* dump the ID */
|
||||
bptr++;
|
||||
/* get the length */
|
||||
len = (*bptr++ << 8);
|
||||
len |= *bptr++;
|
||||
|
||||
/* Parse ACK and set data */
|
||||
while(bptr < buffer + len) {
|
||||
switch(*bptr++) {
|
||||
case IPCP_IPADDRESS:
|
||||
/* dump length */
|
||||
bptr++;
|
||||
((u8_t*)pppif.ipaddr)[0] = *bptr++;
|
||||
((u8_t*)pppif.ipaddr)[1] = *bptr++;
|
||||
((u8_t*)pppif.ipaddr)[2] = *bptr++;
|
||||
((u8_t*)pppif.ipaddr)[3] = *bptr++;
|
||||
uip_fw_register( &pppif );
|
||||
DEBUG1(("My PPP-ipno: (%d.%d.%d.%d)\n", ((u8_t*)pppif.ipaddr)[0], ((u8_t*)pppif.ipaddr)[1], ((u8_t*)pppif.ipaddr)[2], ((u8_t*)pppif.ipaddr)[3]));
|
||||
break;
|
||||
#ifdef IPCP_GET_PRI_DNS
|
||||
case IPCP_PRIMARY_DNS:
|
||||
bptr++;
|
||||
((u8_t*)pri_dns_addr)[0] = *bptr++;
|
||||
((u8_t*)pri_dns_addr)[1] = *bptr++;
|
||||
((u8_t*)pri_dns_addr)[2] = *bptr++;
|
||||
((u8_t*)pri_dns_addr)[3] = *bptr++;
|
||||
break;
|
||||
#endif
|
||||
#ifdef IPCP_GET_SEC_DNS
|
||||
case IPCP_SECONDARY_DNS:
|
||||
bptr++;
|
||||
((u8_t*)sec_dns_addr)[0] = *bptr++;
|
||||
((u8_t*)sec_dns_addr)[1] = *bptr++;
|
||||
((u8_t*)sec_dns_addr)[2] = *bptr++;
|
||||
((u8_t*)sec_dns_addr)[3] = *bptr++;
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
DEBUG1(("IPCP CONFIG_ACK problem 2\n"));
|
||||
}
|
||||
}
|
||||
ppp_id++;
|
||||
printip(pppif.ipaddr);
|
||||
#ifdef IPCP_GET_PRI_DNS
|
||||
printip(pri_dns_addr);
|
||||
#endif
|
||||
#ifdef IPCP_GET_PRI_DNS
|
||||
printip(sec_dns_addr);
|
||||
#endif
|
||||
DEBUG1(("\n"));
|
||||
/* expire the timer to make things happen after a state change */
|
||||
TIMER_expire();
|
||||
break;
|
||||
case CONF_REJ: /* Config Reject */
|
||||
DEBUG1(("CONF REJ\n"));
|
||||
/* Remove the offending options*/
|
||||
ppp_id++;
|
||||
/* dump the ID */
|
||||
bptr++;
|
||||
/* get the length */
|
||||
len = (*bptr++ << 8);
|
||||
len |= *bptr++;
|
||||
|
||||
/* Parse ACK and set data */
|
||||
while(bptr < buffer + len) {
|
||||
switch(*bptr++) {
|
||||
case IPCP_IPADDRESS:
|
||||
ipcp_state |= IPCP_IP_BIT;
|
||||
bptr += 5;
|
||||
break;
|
||||
#ifdef IPCP_GET_PRI_DNS
|
||||
case IPCP_PRIMARY_DNS:
|
||||
ipcp_state |= IPCP_PRI_DNS_BIT;
|
||||
bptr += 5;
|
||||
break;
|
||||
#endif
|
||||
#ifdef IPCP_GET_PRI_DNS
|
||||
case IPCP_SECONDARY_DNS:
|
||||
ipcp_state |= IPCP_SEC_DNS_BIT;
|
||||
bptr += 5;
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
DEBUG1(("IPCP this shoudln't happen 3\n"));
|
||||
}
|
||||
}
|
||||
/* expire the timer to make things happen after a state change */
|
||||
/*timer_expire(); */
|
||||
break;
|
||||
default:
|
||||
DEBUG1(("-Unknown 4\n"));
|
||||
}
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void
|
||||
ipcp_task(u8_t *buffer)
|
||||
{
|
||||
u8_t *bptr;
|
||||
u16_t t;
|
||||
IPCPPKT *pkt;
|
||||
|
||||
/* IPCP tx not up and hasn't timed out then lets see if we need to
|
||||
send a request */
|
||||
if(!(ipcp_state & IPCP_TX_UP) && !(ipcp_state & IPCP_TX_TIMEOUT)) {
|
||||
/* Check if we have a request pending */
|
||||
/*t=get_seconds()-ipcp_tx_time;*/
|
||||
#if 0
|
||||
if(TIMER_timeout(IPCP_TIMEOUT)) {
|
||||
#else
|
||||
if((clock_seconds() - prev_ipcp_seconds) > IPCP_TIMEOUT) {
|
||||
prev_ipcp_seconds = clock_seconds();
|
||||
#endif
|
||||
|
||||
/*
|
||||
* No pending request, lets build one
|
||||
*/
|
||||
pkt=(IPCPPKT *)buffer;
|
||||
|
||||
/* Configure-Request only here, write id */
|
||||
pkt->code = CONF_REQ;
|
||||
pkt->id = ppp_id;
|
||||
|
||||
bptr = pkt->data;
|
||||
|
||||
/*
|
||||
* Write options, we want IP address, and DNS addresses if set.
|
||||
*/
|
||||
|
||||
/* Write zeros for IP address the first time */
|
||||
*bptr++ = IPCP_IPADDRESS;
|
||||
*bptr++ = 0x6;
|
||||
*bptr++ = ((u8_t*)pppif.ipaddr)[0];
|
||||
*bptr++ = ((u8_t*)pppif.ipaddr)[1];
|
||||
*bptr++ = ((u8_t*)pppif.ipaddr)[2];
|
||||
*bptr++ = ((u8_t*)pppif.ipaddr)[3];
|
||||
|
||||
#ifdef IPCP_GET_PRI_DNS
|
||||
if(!(ipcp_state & IPCP_PRI_DNS_BIT)) {
|
||||
/* Write zeros for IP address the first time */
|
||||
*bptr++ = IPCP_PRIMARY_DNS;
|
||||
*bptr++ = 0x6;
|
||||
*bptr++ = ((u8_t*)pri_dns_addr)[0];
|
||||
*bptr++ = ((u8_t*)pri_dns_addr)[1];
|
||||
*bptr++ = ((u8_t*)pri_dns_addr)[2];
|
||||
*bptr++ = ((u8_t*)pri_dns_addr)[3];
|
||||
}
|
||||
#endif
|
||||
#ifdef IPCP_GET_SEC_DNS
|
||||
if(!(ipcp_state & IPCP_SEC_DNS_BIT)) {
|
||||
/* Write zeros for IP address the first time */
|
||||
*bptr++ = IPCP_SECONDARY_DNS;
|
||||
*bptr++ = 0x6;
|
||||
*bptr++ = ((u8_t*)sec_dns_addr)[0];
|
||||
*bptr++ = ((u8_t*)sec_dns_addr)[1];
|
||||
*bptr++ = ((u8_t*)sec_dns_addr)[2];
|
||||
*bptr++ = ((u8_t*)sec_dns_addr)[3];
|
||||
}
|
||||
#endif
|
||||
/* Write length */
|
||||
t = bptr - buffer;
|
||||
/* length here - code and ID + */
|
||||
pkt->len = uip_htons(t);
|
||||
|
||||
DEBUG1(("\n**Sending IPCP Request packet\n"));
|
||||
|
||||
/* Send packet ahdlc_txz(procol,header,data,headerlen,datalen); */
|
||||
ahdlc_tx(IPCP, 0, buffer, 0, t);
|
||||
|
||||
/* Set timer */
|
||||
/*ipcp_tx_time=get_seconds();*/
|
||||
TIMER_set();
|
||||
/* Inc retry */
|
||||
/*ipcp_retry++;*/
|
||||
ppp_retry++;
|
||||
/*
|
||||
* Have we timed out? (combide the timers?)
|
||||
*/
|
||||
if(ppp_retry > IPCP_RETRY_COUNT)
|
||||
ipcp_state &= IPCP_TX_TIMEOUT;
|
||||
}
|
||||
}
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
|
@ -1,95 +0,0 @@
|
|||
#ifndef __IPCP_H__
|
||||
#define __IPCP_H__
|
||||
/* www.mycal.com
|
||||
---------------------------------------------------------------------------
|
||||
IPCP.h - Internet Protocol Control Protocol header file
|
||||
---------------------------------------------------------------------------
|
||||
Version
|
||||
0.1 Original Version June 3, 2000
|
||||
(c)2000 Mycal Labs, All Rights Reserved
|
||||
---------------------------------------------------------------------------
|
||||
*/
|
||||
/*
|
||||
* Copyright (c) 2003, Mike Johnson, Mycal Labs, www.mycal.net
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. 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.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by Mike Johnson/Mycal Labs
|
||||
* www.mycal.net.
|
||||
* 4. The name of the author may not be used to endorse or promote
|
||||
* products derived from this software without specific prior
|
||||
* written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
||||
*
|
||||
* This file is part of the Mycal Modified uIP TCP/IP stack.
|
||||
*
|
||||
* $Id: ipcp.h,v 1.1 2007/05/26 07:14:39 oliverschmidt Exp $
|
||||
*
|
||||
*/
|
||||
#include "net/uip.h"
|
||||
#include "contiki-conf.h"
|
||||
|
||||
/* Config options (move to pppconfig)
|
||||
#define IPCP_RETRY_COUNT 5
|
||||
#define IPCP_TIMEOUT 5
|
||||
*/
|
||||
|
||||
/* IPCP Option Types */
|
||||
#define IPCP_IPADDRESS 0x03
|
||||
#define IPCP_PRIMARY_DNS 0x81
|
||||
#define IPCP_SECONDARY_DNS 0x83
|
||||
|
||||
/* IPCP state machine flags */
|
||||
#define IPCP_TX_UP 0x01
|
||||
#define IPCP_RX_UP 0x02
|
||||
#define IPCP_IP_BIT 0x04
|
||||
#define IPCP_TX_TIMEOUT 0x08
|
||||
#define IPCP_PRI_DNS_BIT 0x08
|
||||
#define IPCP_SEC_DNS_BIT 0x10
|
||||
|
||||
typedef struct _ipcp
|
||||
{
|
||||
u8_t code;
|
||||
u8_t id;
|
||||
u16_t len;
|
||||
u8_t data[0];
|
||||
} IPCPPKT;
|
||||
|
||||
/*
|
||||
* Export IP addresses.
|
||||
*/
|
||||
#if 0 /* moved to mip.c */
|
||||
extern IPAddr our_ipaddr;
|
||||
extern IPAddr peer_ip_addr;
|
||||
extern IPAddr pri_dns_addr;
|
||||
extern IPAddr sec_dns_addr;
|
||||
#endif
|
||||
|
||||
extern u8_t ipcp_state;
|
||||
|
||||
void ipcp_init(void);
|
||||
void ipcp_task(u8_t *buffer);
|
||||
void ipcp_rx(u8_t *, u16_t);
|
||||
|
||||
#endif /* __IPCP_H__ */
|
||||
|
|
@ -1,463 +0,0 @@
|
|||
/* www.mycal.com
|
||||
*---------------------------------------------------------------------------
|
||||
*lcp.c - Link Configuration Protocol Handler. - -
|
||||
*---------------------------------------------------------------------------
|
||||
*Version - 0.1 Original Version June 3, 2000 -
|
||||
*
|
||||
*---------------------------------------------------------------------------
|
||||
*- Copyright (C) 2000, Mycal Labs www.mycal.com - -
|
||||
*---------------------------------------------------------------------------
|
||||
*
|
||||
*
|
||||
*/
|
||||
/*
|
||||
* Copyright (c) 2003, Mike Johnson, Mycal Labs, www.mycal.net
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. 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.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by Mike Johnson/Mycal Labs
|
||||
* www.mycal.net.
|
||||
* 4. The name of the author may not be used to endorse or promote
|
||||
* products derived from this software without specific prior
|
||||
* written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
||||
*
|
||||
* This file is part of the Mycal Modified uIP TCP/IP stack.
|
||||
*
|
||||
* $Id: lcp.c,v 1.2 2010/10/19 18:29:03 adamdunkels Exp $
|
||||
*
|
||||
*/
|
||||
|
||||
/* */
|
||||
/* include files */
|
||||
/* */
|
||||
|
||||
#include "contiki-conf.h"
|
||||
|
||||
/*#include "time.h"*/
|
||||
#include "ppp.h"
|
||||
#include "ahdlc.h"
|
||||
#include "lcp.h"
|
||||
|
||||
#if 0
|
||||
#define DEBUG1(x)
|
||||
#define DEBUG2(x)
|
||||
#else
|
||||
#include <stdio.h>
|
||||
#define DEBUG1(x) debug_printf x
|
||||
#define DEBUG2(x) debug_printf x
|
||||
#endif
|
||||
|
||||
#define TIMER_expire()
|
||||
#define TIMER_set()
|
||||
#define TIMER_timeout(x) 1
|
||||
static unsigned long prev_lcp_seconds = 0;
|
||||
|
||||
|
||||
/*u8_t tflag;
|
||||
u8_t *lcp_buffer;
|
||||
u16_t lcp_tx_time;
|
||||
u8_t lcp_retry;
|
||||
u16_t lcp_timeout=5;*/
|
||||
|
||||
u8_t lcp_state;
|
||||
u16_t ppp_tx_mru = 0;
|
||||
|
||||
/* We need this when we neg our direction.
|
||||
u8_t lcp_tx_options; */
|
||||
|
||||
/*
|
||||
* Define the supported paramets for this module here.
|
||||
*/
|
||||
u8_t lcplist[] = {
|
||||
LPC_MAGICNUMBER,
|
||||
LPC_PFC,
|
||||
LPC_ACFC,
|
||||
LPC_AUTH,
|
||||
LPC_ACCM,
|
||||
LPC_MRU,
|
||||
0};
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/* lcp_init() - Initialize the LCP engine to startup values */
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void
|
||||
lcp_init(void)
|
||||
{
|
||||
lcp_state = 0;
|
||||
ppp_retry = 0;
|
||||
TIMER_expire();
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/* lcp_rx() - Receive an LCP packet and process it.
|
||||
* This routine receives a LCP packet in buffer of length count.
|
||||
* Process it here, support for CONF_REQ, CONF_ACK, CONF_NACK, CONF_REJ or
|
||||
* TERM_REQ.
|
||||
*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void
|
||||
lcp_rx(u8_t *buffer, u16_t count)
|
||||
{
|
||||
u8_t *bptr = buffer, *tptr;
|
||||
u8_t error = 0;
|
||||
u8_t id;
|
||||
u16_t len, j;
|
||||
|
||||
switch(*bptr++) {
|
||||
case CONF_REQ: /* config request */
|
||||
/* parce request and see if we can ACK it */
|
||||
id = *bptr++;
|
||||
len = (*bptr++ << 8);
|
||||
len |= *bptr++;
|
||||
/*len -= 2;*/
|
||||
DEBUG1(("received [LCP Config Request id %u\n",id));
|
||||
if(scan_packet((u16_t)LCP, lcplist, buffer, bptr, (u16_t)(len-4))) {
|
||||
/* must do the -4 here, !scan packet */
|
||||
|
||||
DEBUG1((" options were rejected\n"));
|
||||
} else {
|
||||
/* lets try to implement what peer wants */
|
||||
tptr = bptr = buffer;
|
||||
bptr += 4; /* skip code, id, len */
|
||||
error = 0;
|
||||
/* first scan for unknown values */
|
||||
while(bptr < buffer+len) {
|
||||
switch(*bptr++) {
|
||||
case LPC_MRU: /* mru */
|
||||
j = *bptr++;
|
||||
j -= 2;
|
||||
if(j == 2) {
|
||||
ppp_tx_mru = ((int)*bptr++) << 8;
|
||||
ppp_tx_mru |= *bptr++;
|
||||
DEBUG1(("<mru %d> ",ppp_tx_mru));
|
||||
} else {
|
||||
DEBUG1(("<mru ??> "));
|
||||
}
|
||||
break;
|
||||
case LPC_ACCM: /* */
|
||||
bptr++; /* skip length */
|
||||
j = *bptr++;
|
||||
j += *bptr++;
|
||||
j += *bptr++;
|
||||
j += *bptr++;
|
||||
if(j==0) {
|
||||
// ok
|
||||
DEBUG1(("<asyncmap sum=0x%04x>",j));
|
||||
//ahdlc_flags |= PPP_TX_ASYNC_MAP;
|
||||
} else if(j!=0) {
|
||||
// ok
|
||||
DEBUG1(("<asyncmap sum=0x%04x>, assume 0xffffffff",j));
|
||||
} else {
|
||||
/*
|
||||
* fail we only support default or all zeros
|
||||
*/
|
||||
DEBUG1(("We only support default or all zeros for ACCM "));
|
||||
error = 1;
|
||||
*tptr++ = LPC_ACCM;
|
||||
*tptr++ = 0x6;
|
||||
*tptr++ = 0;
|
||||
*tptr++ = 0;
|
||||
*tptr++ = 0;
|
||||
*tptr++ = 0;
|
||||
}
|
||||
break;
|
||||
case LPC_AUTH:
|
||||
bptr++;
|
||||
if((*bptr++ == 0xc0) && (*bptr++ == 0x23)) {
|
||||
/* negotiate PAP */
|
||||
if (strlen(pap_username) > 0) {
|
||||
DEBUG1(("<auth pap> "));
|
||||
lcp_state |= LCP_RX_AUTH;
|
||||
} else {
|
||||
DEBUG1(("<rej auth pap> "));
|
||||
|
||||
*tptr++ = CONF_REJ;
|
||||
*tptr++; // Keep ID
|
||||
*tptr++ = 0;
|
||||
*tptr++ = 8;
|
||||
*tptr++ = LPC_AUTH;
|
||||
*tptr++ = 0x4;
|
||||
*tptr++ = 0xc0;
|
||||
*tptr++ = 0x23;
|
||||
ahdlc_tx(LCP, 0, buffer, 0, (u16_t)(tptr-buffer));
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
/* we only support PAP */
|
||||
DEBUG1(("<auth ??>"));
|
||||
error = 1;
|
||||
*tptr++ = LPC_AUTH;
|
||||
*tptr++ = 0x4;
|
||||
*tptr++ = 0xc0;
|
||||
*tptr++ = 0x23;
|
||||
}
|
||||
break;
|
||||
case LPC_MAGICNUMBER:
|
||||
DEBUG1(("<magic > "));
|
||||
/*
|
||||
* Compair incoming number to our number (not implemented)
|
||||
*/
|
||||
bptr++; /* for now just dump */
|
||||
bptr++;
|
||||
bptr++;
|
||||
bptr++;
|
||||
bptr++;
|
||||
break;
|
||||
case LPC_PFC:
|
||||
bptr++;
|
||||
DEBUG1(("<pcomp> "));
|
||||
/*tflag|=PPP_PFC;*/
|
||||
break;
|
||||
case LPC_ACFC:
|
||||
bptr++;
|
||||
DEBUG1(("<accomp> "));
|
||||
/*tflag|=PPP_ACFC;*/
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
/* Error? if we we need to send a config Reject ++++ this is good for a subroutine */
|
||||
if(error) {
|
||||
/* write the config NAK packet we've built above, take on the header */
|
||||
bptr = buffer;
|
||||
*bptr++ = CONF_NAK; /* Write Conf_rej */
|
||||
*bptr++;/*tptr++;*/ /* skip over ID */
|
||||
|
||||
/* Write new length */
|
||||
*bptr++ = 0;
|
||||
*bptr = tptr - buffer;
|
||||
|
||||
/* write the reject frame */
|
||||
DEBUG1(("\nWriting NAK frame \n"));
|
||||
// Send packet ahdlc_txz(procol,header,data,headerlen,datalen);
|
||||
ahdlc_tx(LCP, 0, buffer, 0, (u16_t)(tptr-buffer));
|
||||
DEBUG1(("- end NAK Write frame\n"));
|
||||
|
||||
} else {
|
||||
/*
|
||||
* If we get here then we are OK, lets send an ACK and tell the rest
|
||||
* of our modules our negotiated config.
|
||||
*/
|
||||
DEBUG1(("\nSend ACK!\n"));
|
||||
bptr = buffer;
|
||||
*bptr++ = CONF_ACK; /* Write Conf_ACK */
|
||||
bptr++; /* Skip ID (send same one) */
|
||||
/*
|
||||
* Set stuff
|
||||
*/
|
||||
/*ppp_flags|=tflag;*/
|
||||
/* DEBUG2("SET- stuff -- are we up? c=%d dif=%d \n", count, (u16_t)(bptr-buffer)); */
|
||||
|
||||
/* write the ACK frame */
|
||||
DEBUG2(("Writing ACK frame \n"));
|
||||
/* Send packet ahdlc_txz(procol,header,data,headerlen,datalen); */
|
||||
ahdlc_tx(LCP, 0, buffer, 0, count /*bptr-buffer*/);
|
||||
DEBUG2(("- end ACK Write frame\n"));
|
||||
lcp_state |= LCP_RX_UP;
|
||||
|
||||
/* expire the timer to make things happen after a state change */
|
||||
/*timer_expire();*/
|
||||
|
||||
}
|
||||
}
|
||||
break;
|
||||
case CONF_ACK: /* config Ack Anytime we do an ack reset the timer to force send. */
|
||||
DEBUG1(("LCP-ACK - "));
|
||||
/* check that ID matches one sent */
|
||||
if(*bptr++ == ppp_id) {
|
||||
/* Change state to PPP up. */
|
||||
DEBUG1((">>>>>>>> good ACK id up! %d\n",ppp_id));
|
||||
/* copy negotiated values over */
|
||||
|
||||
lcp_state |= LCP_TX_UP;
|
||||
|
||||
/* expire the timer to make things happen after a state change */
|
||||
TIMER_expire();
|
||||
}
|
||||
else
|
||||
DEBUG1(("*************++++++++++ bad id %d\n",ppp_id));
|
||||
break;
|
||||
case CONF_NAK: /* Config Nack */
|
||||
DEBUG1(("LCP-CONF NAK\n"));
|
||||
ppp_id++;
|
||||
break;
|
||||
case CONF_REJ: /* Config Reject */
|
||||
DEBUG1(("LCP-CONF REJ\n"));
|
||||
ppp_id++;
|
||||
break;
|
||||
case TERM_REQ: /* Terminate Request */
|
||||
DEBUG1(("LCP-TERM-REQ -"));
|
||||
bptr = buffer;
|
||||
*bptr++ = TERM_ACK; /* Write TERM_ACK */
|
||||
/* write the reject frame */
|
||||
DEBUG1(("Writing TERM_ACK frame \n"));
|
||||
/* Send packet ahdlc_txz(procol,header,data,headerlen,datalen); */
|
||||
ahdlc_tx(LCP, 0, buffer, 0, count);
|
||||
lcp_state &= ~LCP_TX_UP;
|
||||
lcp_state |= LCP_TERM_PEER;
|
||||
break;
|
||||
case TERM_ACK:
|
||||
DEBUG1(("LCP-TERM ACK\n"));
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void lcp_disconnect(u8_t id) {
|
||||
u8_t buffer[4];
|
||||
u8_t *bptr = buffer;
|
||||
*bptr++ = TERM_REQ;
|
||||
*bptr++ = id;
|
||||
*bptr++ = 0;
|
||||
*bptr++ = 4;
|
||||
ahdlc_tx(LCP, 0, buffer, 0, bptr - buffer);
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/* lcp_task(buffer) - This routine see if a lcp request needs to be sent
|
||||
* out. It uses the passed buffer to form the packet. This formed LCP
|
||||
* request is what we negotiate for sending options on the link.
|
||||
*
|
||||
* Currently we negotiate : Magic Number Only, but this will change.
|
||||
*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void
|
||||
lcp_task(u8_t *buffer)
|
||||
{
|
||||
u8_t *bptr;
|
||||
u16_t t;
|
||||
LCPPKT *pkt;
|
||||
|
||||
/* lcp tx not up and hasn't timed out then lets see if we need to send a request */
|
||||
if(!(lcp_state & LCP_TX_UP) && !(lcp_state & LCP_TX_TIMEOUT)) {
|
||||
/* Check if we have a request pending */
|
||||
/*t=get_seconds()-lcp_tx_time;*/
|
||||
#if 0
|
||||
if(1 == TIMER_timeout(LCP_TX_TIMEOUT)) {
|
||||
#else
|
||||
if((clock_seconds() - prev_lcp_seconds) > LCP_TIMEOUT) {
|
||||
prev_lcp_seconds = clock_seconds();
|
||||
#endif
|
||||
DEBUG1(("\nSending LCP request packet - "));
|
||||
/*
|
||||
* No pending request, lets build one
|
||||
*/
|
||||
pkt = (LCPPKT *)buffer;
|
||||
|
||||
/* Configure-Request only here, write id */
|
||||
pkt->code = CONF_REQ;
|
||||
pkt->id = ppp_id;
|
||||
|
||||
bptr = pkt->data;
|
||||
|
||||
/* Write options */
|
||||
|
||||
/* ACCM */
|
||||
//if((lcp_tx_options & LCP_OPT_ACCM) & 0) {
|
||||
*bptr++ = LPC_ACCM;
|
||||
*bptr++ = 0x6;
|
||||
*bptr++ = 0xff;
|
||||
*bptr++ = 0xff;
|
||||
*bptr++ = 0xff;
|
||||
*bptr++ = 0xff;
|
||||
//}
|
||||
|
||||
#if 0
|
||||
/* Write magic number */
|
||||
DEBUG1(("LPC_MAGICNUMBER -"));
|
||||
*bptr++ = LPC_MAGICNUMBER;
|
||||
*bptr++ = 0x6;
|
||||
/*
|
||||
*bptr++ = random_rand() & 0xff;
|
||||
*bptr++ = random_rand() & 0xff;
|
||||
*bptr++ = random_rand() & 0xff;
|
||||
*bptr++ = random_rand() & 0xff;
|
||||
*/
|
||||
*bptr++ = 0x11;
|
||||
*bptr++ = 0x11;
|
||||
*bptr++ = 0x11;
|
||||
*bptr++ = 0x11;
|
||||
#endif
|
||||
|
||||
#if 0
|
||||
/*
|
||||
* Authentication protocol
|
||||
*/
|
||||
if((lcp_tx_options & LCP_OPT_AUTH) && 0) {
|
||||
/*
|
||||
* If turned on, we only negotiate PAP
|
||||
*/
|
||||
*bptr++ = LPC_AUTH;
|
||||
*bptr++ = 0x4;
|
||||
*bptr++ = 0xc0;
|
||||
*bptr++ = 0x23;
|
||||
}
|
||||
/*
|
||||
* PFC
|
||||
*/
|
||||
if((lcp_tx_options & LCP_OPT_PFC) && 0) {
|
||||
/*
|
||||
* If turned on, we only negotiate PAP
|
||||
*/
|
||||
*bptr++ = LPC_PFC;
|
||||
*bptr++ = 0x2;
|
||||
}
|
||||
/*
|
||||
* ACFC
|
||||
*/
|
||||
if((lcp_tx_options & LCP_OPT_ACFC) && 0) {
|
||||
/*
|
||||
* If turned on, we only negotiate PAP
|
||||
*/
|
||||
*bptr++ = LPC_ACFC;
|
||||
*bptr++ = 0x2;
|
||||
}
|
||||
#endif
|
||||
/* Write length */
|
||||
t = bptr - buffer;
|
||||
pkt->len = uip_htons(t); /* length here - code and ID + */
|
||||
|
||||
DEBUG1((" len %d\n",t));
|
||||
|
||||
/* Send packet */
|
||||
/* Send packet ahdlc_txz(procol,header,data,headerlen,datalen); */
|
||||
ahdlc_tx(LCP, 0, buffer, 0, t);
|
||||
|
||||
/* Set timer */
|
||||
TIMER_set();
|
||||
/*lcp_tx_time=get_seconds();*/
|
||||
/* Inc retry */
|
||||
ppp_retry++;
|
||||
/*
|
||||
* Have we timed out?
|
||||
*/
|
||||
if(ppp_retry > LCP_RETRY_COUNT) {
|
||||
lcp_state &= LCP_TX_TIMEOUT;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
|
@ -1,96 +0,0 @@
|
|||
#ifndef __LCP_H__
|
||||
#define __LCP_H__
|
||||
/* www.mycal.com
|
||||
---------------------------------------------------------------------------
|
||||
LCP.h - LCP header file
|
||||
---------------------------------------------------------------------------
|
||||
Version -
|
||||
0.1 Original Version June 3, 2000
|
||||
(c)2000 Mycal Labs, All Rights Reserved
|
||||
---------------------------------------------------------------------------
|
||||
*/
|
||||
/*
|
||||
* Copyright (c) 2003, Mike Johnson, Mycal Labs, www.mycal.net
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. 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.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by Mike Johnson/Mycal Labs
|
||||
* www.mycal.net.
|
||||
* 4. The name of the author may not be used to endorse or promote
|
||||
* products derived from this software without specific prior
|
||||
* written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
||||
*
|
||||
* This file is part of the Mycal Modified uIP TCP/IP stack.
|
||||
*
|
||||
* $Id: lcp.h,v 1.1 2007/05/26 07:14:39 oliverschmidt Exp $
|
||||
*
|
||||
*/
|
||||
|
||||
#include "net/uip.h"
|
||||
#include "contiki-conf.h"
|
||||
|
||||
/* LCP Option Types */
|
||||
#define LPC_VENDERX 0x0
|
||||
#define LPC_MRU 0x1
|
||||
#define LPC_ACCM 0x2
|
||||
#define LPC_AUTH 0x3
|
||||
#define LPC_QUALITY 0x4
|
||||
#define LPC_MAGICNUMBER 0x5
|
||||
#define LPC_PFC 0x7
|
||||
#define LPC_ACFC 0x8
|
||||
|
||||
/* LCP Negotiated options flag equates */
|
||||
#define LCP_OPT_ACCM 0x1
|
||||
#define LCP_OPT_AUTH 0x2
|
||||
#define LCP_OPT_PFC 0x4
|
||||
#define LCP_OPT_ACFC 0x4
|
||||
|
||||
/* LCP state machine flags */
|
||||
#define LCP_TX_UP 0x1
|
||||
#define LCP_RX_UP 0x2
|
||||
|
||||
#define LCP_RX_AUTH 0x10
|
||||
/* LCP request for auth */
|
||||
#define LCP_TERM_PEER 0x20
|
||||
/* LCP Terminated by peer */
|
||||
#define LCP_RX_TIMEOUT 0x40
|
||||
#define LCP_TX_TIMEOUT 0x80
|
||||
|
||||
typedef struct _lcppkt
|
||||
{
|
||||
u8_t code;
|
||||
u8_t id;
|
||||
u16_t len;
|
||||
u8_t data[0];
|
||||
} LCPPKT;
|
||||
|
||||
/* Exported Vars */
|
||||
extern u8_t lcp_state;
|
||||
|
||||
void lcp_init(void);
|
||||
void lcp_rx(u8_t *, u16_t);
|
||||
void lcp_task(u8_t *buffer);
|
||||
void lcp_disconnect(u8_t id);
|
||||
|
||||
#endif /* __LCP_H__ */
|
|
@ -1,195 +0,0 @@
|
|||
/*www.mycal.net
|
||||
*---------------------------------------------------------------------------
|
||||
*pap.c - PAP processor for the PPP module - -
|
||||
*---------------------------------------------------------------------------
|
||||
*Version - 0.1 Original Version Jun 3, 2000 - -
|
||||
*---------------------------------------------------------------------------
|
||||
*- Copyright (C) 2000, Mycal Labs www.mycal.com - -
|
||||
*---------------------------------------------------------------------------
|
||||
*/
|
||||
/*
|
||||
* Copyright (c) 2003, Mike Johnson, Mycal Labs, www.mycal.net
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. 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.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by Mike Johnson/Mycal Labs
|
||||
* www.mycal.net.
|
||||
* 4. The name of the author may not be used to endorse or promote
|
||||
* products derived from this software without specific prior
|
||||
* written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
||||
*
|
||||
* This file is part of the Mycal Modified uIP TCP/IP stack.
|
||||
*
|
||||
* $Id: pap.c,v 1.2 2010/10/19 18:29:03 adamdunkels Exp $
|
||||
*
|
||||
*/
|
||||
|
||||
/* */
|
||||
/* include files */
|
||||
/* */
|
||||
|
||||
#include <string.h>
|
||||
#include "ppp.h"
|
||||
#include "pap.h"
|
||||
#include "lcp.h"
|
||||
|
||||
#if 0
|
||||
#define DEBUG1(x)
|
||||
#else
|
||||
#include <stdio.h>
|
||||
#define DEBUG1(x) debug_printf x
|
||||
#endif
|
||||
|
||||
/*#include "time.h"*/
|
||||
/*#include "utils.h" */
|
||||
#define TIMER_expire()
|
||||
#define TIMER_set()
|
||||
#define TIMER_timeout(x) 1
|
||||
|
||||
|
||||
u8_t pap_state;
|
||||
|
||||
#ifdef PAP_USERNAME
|
||||
u8_t pap_username[] = PAP_USERNAME;
|
||||
#else
|
||||
u8_t pap_username[PAP_USERNAME_SIZE];
|
||||
#endif
|
||||
|
||||
#ifdef PAP_PASSWORD
|
||||
u8_t pap_password[] = PAP_PASSWORD;
|
||||
#else
|
||||
u8_t pap_password[PAP_PASSWORD_SIZE];
|
||||
#endif
|
||||
|
||||
/*u16_t pap_tx_time;
|
||||
u8_t pap_timeout;*/
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void
|
||||
pap_init(void)
|
||||
{
|
||||
ppp_retry = 0; /* We reuse ppp_retry */
|
||||
pap_state = 0;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/* pap_rx() - PAP RX protocol Handler */
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void
|
||||
pap_rx(u8_t *buffer, u16_t count)
|
||||
{
|
||||
u8_t *bptr=buffer;
|
||||
u8_t len;
|
||||
|
||||
switch(*bptr++) {
|
||||
case CONF_REQ:
|
||||
DEBUG1(("CONF ACK - only for server, no support\n"));
|
||||
break;
|
||||
case CONF_ACK: /* config Ack */
|
||||
DEBUG1(("CONF ACK - PAP good - "));
|
||||
/* Display message if debug */
|
||||
len = *bptr++;
|
||||
*(bptr + len) = 0;
|
||||
DEBUG1((" %s \n",bptr));
|
||||
pap_state |= PAP_TX_UP;
|
||||
/* expire the timer to make things happen after a state change */
|
||||
TIMER_expire();
|
||||
break;
|
||||
case CONF_NAK:
|
||||
DEBUG1(("CONF NAK - Failed Auth - "));
|
||||
pap_state |= PAP_TX_AUTH_FAIL;
|
||||
/* display message if debug */
|
||||
len = *bptr++;
|
||||
*(bptr + len)=0;
|
||||
DEBUG1((" %s \n",bptr));
|
||||
break;
|
||||
}
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/* pap_task() - This task needs to be called every so often during the PAP
|
||||
* negotiation phase. This task sends PAP REQ packets.
|
||||
*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void
|
||||
pap_task(u8_t *buffer)
|
||||
{
|
||||
u8_t *bptr;
|
||||
u16_t t;
|
||||
PAPPKT *pkt;
|
||||
|
||||
/* If LCP is up and PAP negotiated, try to bring up PAP */
|
||||
if(!(pap_state & PAP_TX_UP) && !(pap_state & PAP_TX_TIMEOUT)) {
|
||||
/* Do we need to send a PAP auth packet?
|
||||
Check if we have a request pending*/
|
||||
if(1 == TIMER_timeout(PAP_TIMEOUT)) {
|
||||
/* Check if we have a request pending */
|
||||
/* t=get_seconds()-pap_tx_time;
|
||||
if( t > pap_timeout)
|
||||
{
|
||||
*/
|
||||
/* We need to send a PAP authentication request */
|
||||
DEBUG1(("\nSending PAP Request packet - "));
|
||||
|
||||
/* Build a PAP request packet */
|
||||
pkt = (PAPPKT *)buffer;
|
||||
|
||||
/* Configure-Request only here, write id */
|
||||
pkt->code = CONF_REQ;
|
||||
pkt->id = ppp_id;
|
||||
bptr = pkt->data;
|
||||
|
||||
/* Write options */
|
||||
t = strlen(pap_username);
|
||||
/* Write peer length */
|
||||
*bptr++ = (u8_t)t;
|
||||
bptr = memcpy(bptr, pap_username, t);
|
||||
|
||||
t = strlen(pap_password);
|
||||
*bptr++ = (u8_t)t;
|
||||
bptr = memcpy(bptr, pap_password, t);
|
||||
|
||||
/* Write length */
|
||||
t = bptr - buffer;
|
||||
/* length here - code and ID + */
|
||||
pkt->len = uip_htons(t);
|
||||
|
||||
DEBUG1((" Len %d\n",t));
|
||||
|
||||
/* Send packet */
|
||||
ahdlc_tx(PAP, buffer, 0, t, 0);
|
||||
|
||||
/* Set timer */
|
||||
TIMER_set();
|
||||
|
||||
ppp_retry++;
|
||||
|
||||
/* Have we failed? */
|
||||
if(ppp_retry > 3) {
|
||||
DEBUG1(("PAP - timout\n"));
|
||||
pap_state &= PAP_TX_TIMEOUT;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
|
@ -1,83 +0,0 @@
|
|||
#ifndef __PAP_H__
|
||||
#define __PAP_H__
|
||||
/*
|
||||
www.mycal.com
|
||||
---------------------------------------------------------------------------
|
||||
pap.h - pap header file
|
||||
---------------------------------------------------------------------------
|
||||
Version
|
||||
0.1 Original Version June 3, 2000
|
||||
(c)2000 Mycal Labs, All Rights Reserved
|
||||
---------------------------------------------------------------------------
|
||||
*/
|
||||
/*
|
||||
* Copyright (c) 2003, Mike Johnson, Mycal Labs, www.mycal.net
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. 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.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by Mike Johnson/Mycal Labs
|
||||
* www.mycal.net.
|
||||
* 4. The name of the author may not be used to endorse or promote
|
||||
* products derived from this software without specific prior
|
||||
* written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
||||
*
|
||||
* This file is part of the Mycal Modified uIP TCP/IP stack.
|
||||
*
|
||||
* $Id: pap.h,v 1.1 2007/05/26 07:14:40 oliverschmidt Exp $
|
||||
*
|
||||
*/
|
||||
|
||||
#include "net/uip.h"
|
||||
|
||||
/* PAP state machine flags */
|
||||
/* client only */
|
||||
#define PAP_TX_UP 0x01
|
||||
/* server only */
|
||||
#define PAP_RX_UP 0x02
|
||||
|
||||
#define PAP_RX_AUTH_FAIL 0x10
|
||||
#define PAP_TX_AUTH_FAIL 0x20
|
||||
#define PAP_RX_TIMEOUT 0x80
|
||||
#define PAP_TX_TIMEOUT 0x80
|
||||
|
||||
typedef struct _pappkt {
|
||||
u8_t code;
|
||||
u8_t id;
|
||||
u16_t len;
|
||||
u8_t data[0];
|
||||
} PAPPKT;
|
||||
|
||||
/* Export pap_state */
|
||||
extern u8_t pap_state;
|
||||
|
||||
extern u8_t pap_username[];
|
||||
extern u8_t pap_password[];
|
||||
|
||||
/* Function prototypes */
|
||||
void pap_init(void);
|
||||
void pap_rx(u8_t *, u16_t);
|
||||
void pap_task(u8_t *buffer);
|
||||
|
||||
#endif /* __PAP_H__ */
|
||||
|
|
@ -1,91 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2005, Swedish Institute of Computer Science
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. 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.
|
||||
* 3. Neither the name of the Institute 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 INSTITUTE 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 INSTITUTE 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.
|
||||
*
|
||||
* This file is part of the Contiki operating system.
|
||||
*
|
||||
* @(#)$Id: ppp-service.c,v 1.1 2007/05/26 07:14:40 oliverschmidt Exp $
|
||||
*/
|
||||
|
||||
#if 0
|
||||
#include "net/packet-service.h"
|
||||
#include "ppp.h"
|
||||
|
||||
static void output(u8_t *hdr, u16_t hdrlen, u8_t *data, u16_t datalen);
|
||||
|
||||
static const struct packet_service_state state =
|
||||
{
|
||||
PACKET_SERVICE_VERSION,
|
||||
output
|
||||
};
|
||||
|
||||
EK_EVENTHANDLER(eventhandler, ev, data);
|
||||
EK_POLLHANDLER(pollhandler);
|
||||
EK_PROCESS(proc, PACKET_SERVICE_NAME, EK_PRIO_NORMAL,
|
||||
eventhandler, pollhandler, (void *)&state);
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
EK_PROCESS_INIT(ppp_service_init, arg)
|
||||
{
|
||||
ek_service_start(PACKET_SERVICE_NAME, &proc);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
output(u8_t *hdr, u16_t hdrlen, u8_t *data, u16_t datalen)
|
||||
{
|
||||
ppp_send();
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
EK_EVENTHANDLER(eventhandler, ev, data)
|
||||
{
|
||||
switch(ev) {
|
||||
case EK_EVENT_INIT:
|
||||
case EK_EVENT_REPLACE:
|
||||
// ppp_init();
|
||||
break;
|
||||
case EK_EVENT_REQUEST_REPLACE:
|
||||
ek_replace((struct ek_proc *)data, NULL);
|
||||
LOADER_UNLOAD();
|
||||
break;
|
||||
case EK_EVENT_REQUEST_EXIT:
|
||||
ek_exit();
|
||||
LOADER_UNLOAD();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
EK_POLLHANDLER(pollhandler)
|
||||
{
|
||||
ppp_poll();
|
||||
if(uip_len > 0) {
|
||||
tcpip_input();
|
||||
}
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#endif
|
|
@ -1,440 +0,0 @@
|
|||
/*
|
||||
*---------------------------------------------------------------------------
|
||||
* ppp.c - PPP Processor/Handler -
|
||||
* -
|
||||
*---------------------------------------------------------------------------
|
||||
*
|
||||
* Version -
|
||||
* 0.1 Original Version Jun 3, 2000 -
|
||||
* -
|
||||
*---------------------------------------------------------------------------
|
||||
*/
|
||||
/*
|
||||
* Copyright (c) 2003, Mike Johnson, Mycal Labs, www.mycal.net
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. 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.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by Mike Johnson/Mycal Labs
|
||||
* www.mycal.net.
|
||||
* 4. The name of the author may not be used to endorse or promote
|
||||
* products derived from this software without specific prior
|
||||
* written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
||||
*
|
||||
* This file is part of the Mycal Modified uIP TCP/IP stack.
|
||||
*
|
||||
* $Id: ppp.c,v 1.2 2010/10/19 18:29:03 adamdunkels Exp $
|
||||
*
|
||||
*/
|
||||
|
||||
/* */
|
||||
/* include files */
|
||||
/* */
|
||||
|
||||
|
||||
#include "lcp.h"
|
||||
#include "pap.h"
|
||||
#include "ipcp.h"
|
||||
/*#include "time.h"*/
|
||||
/*#include "mip.h"*/
|
||||
|
||||
#if 0
|
||||
#define DEBUG1(x)
|
||||
#else
|
||||
#include <stdio.h>
|
||||
#define DEBUG1(x) debug_printf x
|
||||
#endif
|
||||
|
||||
/*
|
||||
Set the debug message level
|
||||
*/
|
||||
#define PACKET_RX_DEBUG 1
|
||||
|
||||
/*
|
||||
Include stuff
|
||||
*/
|
||||
/*#include "mTypes.h"*/
|
||||
#include "ppp.h"
|
||||
#include "ahdlc.h"
|
||||
#include "ipcp.h"
|
||||
#include "lcp.h"
|
||||
|
||||
extern int ppp_arch_getchar(u8_t *p);
|
||||
|
||||
|
||||
/*
|
||||
Buffers that this layer needs (this can be optimized out)
|
||||
*/
|
||||
u8_t ppp_rx_buffer[PPP_RX_BUFFER_SIZE];
|
||||
/*u8_t ppp_tx_buffer[PPP_TX_BUFFER_SIZE];*/
|
||||
|
||||
/*
|
||||
* Other state storage (this can be placed in a struct and this could could
|
||||
* support multiple PPP connections, would have to embedded the other ppp
|
||||
* module state also)
|
||||
*/
|
||||
u8_t ppp_flags;
|
||||
u8_t ppp_id;
|
||||
u8_t ppp_retry;
|
||||
|
||||
#if PACKET_RX_DEBUG
|
||||
u16_t ppp_rx_frame_count=0;
|
||||
u16_t ppp_rx_tobig_error;
|
||||
u8_t done; /* temporary variable */
|
||||
#endif
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static u8_t
|
||||
check_ppp_errors(void)
|
||||
{
|
||||
u8_t ret = 0;
|
||||
|
||||
/* Check Errors */
|
||||
if(lcp_state & LCP_TX_TIMEOUT) {
|
||||
ret = 1;
|
||||
}
|
||||
if(lcp_state & LCP_RX_TIMEOUT) {
|
||||
ret = 2;
|
||||
}
|
||||
|
||||
if(pap_state & PAP_TX_AUTH_FAIL) {
|
||||
ret = 3;
|
||||
}
|
||||
if(pap_state & PAP_RX_AUTH_FAIL) {
|
||||
ret = 4;
|
||||
}
|
||||
|
||||
if(pap_state & PAP_TX_TIMEOUT) {
|
||||
ret = 5;
|
||||
}
|
||||
if(pap_state & PAP_RX_TIMEOUT) {
|
||||
ret = 6;
|
||||
}
|
||||
|
||||
if(ipcp_state & IPCP_TX_TIMEOUT) {
|
||||
ret = 7;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/*
|
||||
* Unknown Protocol Handler, sends reject
|
||||
*/
|
||||
static void
|
||||
ppp_reject_protocol(u16_t protocol, u8_t *buffer, u16_t count)
|
||||
{
|
||||
u16_t i;
|
||||
u8_t *dptr, *sptr;
|
||||
LCPPKT *pkt;
|
||||
|
||||
/* first copy rejected packet back, start from end and work forward,
|
||||
+++ Pay attention to buffer managment when updated. Assumes fixed
|
||||
PPP blocks. */
|
||||
DEBUG1(("Rejecting Protocol\n"));
|
||||
if((count + 6) > PPP_RX_BUFFER_SIZE) {
|
||||
/* This is a fatal error +++ do somthing about it. */
|
||||
DEBUG1(("Cannot Reject Protocol, PKT to big\n"));
|
||||
return;
|
||||
}
|
||||
dptr = buffer + count + 6;
|
||||
sptr = buffer + count;
|
||||
for(i = 0; i < count; ++i) {
|
||||
*dptr-- = *sptr--;
|
||||
}
|
||||
|
||||
pkt = (LCPPKT *)buffer;
|
||||
pkt->code = PROT_REJ; /* Write Conf_rej */
|
||||
/*pkt->id = tid++;*/ /* write tid */
|
||||
pkt->len = uip_htons(count + 6);
|
||||
*((u16_t *)(&pkt->data[0])) = uip_htons(protocol);
|
||||
|
||||
ahdlc_tx(LCP, buffer, 0, (u16_t)(count + 6), 0);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#if PACKET_RX_DEBUG
|
||||
void
|
||||
dump_ppp_packet(u8_t *buffer, u16_t len)
|
||||
{
|
||||
int i;
|
||||
|
||||
DEBUG1(("\n"));
|
||||
for(i = 0;i < len; ++i) {
|
||||
if((i & 0x1f) == 0x10) {
|
||||
DEBUG1(("\n"));
|
||||
}
|
||||
DEBUG1(("0x%02x ",buffer[i]));
|
||||
}
|
||||
DEBUG1(("\n\n"));
|
||||
}
|
||||
#endif
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/* Initialize and start PPP engine. This just sets things up to
|
||||
* starting values. This can stay a private method.
|
||||
*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void
|
||||
ppp_init()
|
||||
{
|
||||
#if PACKET_RX_DEBUG
|
||||
ppp_rx_frame_count = 0;
|
||||
done = 0;
|
||||
#endif
|
||||
ppp_flags = 0;
|
||||
pap_init();
|
||||
ipcp_init();
|
||||
lcp_init();
|
||||
ppp_flags = 0;
|
||||
|
||||
ahdlc_init(ppp_rx_buffer, PPP_RX_BUFFER_SIZE);
|
||||
ahdlc_rx_ready();
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/* raise_ppp() - This routine will try to bring up a PPP connection,
|
||||
* It is blocking. In the future we probably want to pass a
|
||||
* structure with all the options on bringing up a PPP link, like
|
||||
* server/client, DSN server, username password for PAP... +++ for
|
||||
* now just use config and bit defines
|
||||
*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#if 0
|
||||
u16_t
|
||||
ppp_raise(u8_t config, u8_t *username, u8_t *password)
|
||||
{
|
||||
u16_t status = 0;
|
||||
|
||||
/* Initialize PPP engine */
|
||||
/* init_ppp(); */
|
||||
pap_init();
|
||||
ipcp_init();
|
||||
lcp_init();
|
||||
|
||||
/* Enable PPP */
|
||||
ppp_flags = PPP_RX_READY;
|
||||
|
||||
/* Try to bring up the layers */
|
||||
while(status == 0) {
|
||||
#ifdef SYSTEM_POLLER
|
||||
/* If the the serial interrupt is not hooked to ahdlc_rx, or the
|
||||
system needs to handle other stuff while were blocking, call
|
||||
the system poller.*/
|
||||
system_poller();
|
||||
#endif
|
||||
|
||||
/* call the lcp task to bring up the LCP layer */
|
||||
lcp_task(ppp_tx_buffer);
|
||||
|
||||
/* If LCP is up, neg next layer */
|
||||
if(lcp_state & LCP_TX_UP) {
|
||||
/* If LCP wants PAP, try to authenticate, else bring up IPCP */
|
||||
if((lcp_state & LCP_RX_AUTH) && (!(pap_state & PAP_TX_UP))) {
|
||||
pap_task(ppp_tx_buffer,username,password);
|
||||
} else {
|
||||
ipcp_task(ppp_tx_buffer);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* If IPCP came up then our link should be up. */
|
||||
if((ipcp_state & IPCP_TX_UP) && (ipcp_state & IPCP_RX_UP)) {
|
||||
break;
|
||||
}
|
||||
|
||||
status = check_ppp_errors();
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
#endif
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void
|
||||
ppp_connect(void)
|
||||
{
|
||||
/* Initialize PPP engine */
|
||||
/* init_ppp(); */
|
||||
pap_init();
|
||||
ipcp_init();
|
||||
lcp_init();
|
||||
|
||||
/* Enable PPP */
|
||||
ppp_flags = PPP_RX_READY;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void
|
||||
ppp_send(void)
|
||||
{
|
||||
/* If IPCP came up then our link should be up. */
|
||||
if((ipcp_state & IPCP_TX_UP) && (ipcp_state & IPCP_RX_UP)) {
|
||||
ahdlc_tx(IPV4, &uip_buf[ UIP_LLH_LEN ], uip_appdata,
|
||||
UIP_TCPIP_HLEN, uip_len - UIP_TCPIP_HLEN);
|
||||
}
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void
|
||||
ppp_poll(void)
|
||||
{
|
||||
u8_t c;
|
||||
|
||||
uip_len = 0;
|
||||
|
||||
if(!(ppp_flags & PPP_RX_READY)) {
|
||||
return;
|
||||
}
|
||||
|
||||
while(uip_len == 0 && ppp_arch_getchar(&c)) {
|
||||
ahdlc_rx(c);
|
||||
}
|
||||
|
||||
/* If IPCP came up then our link should be up. */
|
||||
if((ipcp_state & IPCP_TX_UP) && (ipcp_state & IPCP_RX_UP)) {
|
||||
return;
|
||||
}
|
||||
|
||||
/* call the lcp task to bring up the LCP layer */
|
||||
lcp_task( &uip_buf[ UIP_LLH_LEN ]);
|
||||
|
||||
/* If LCP is up, neg next layer */
|
||||
if((lcp_state & LCP_TX_UP) && (lcp_state & LCP_RX_UP)) {
|
||||
/* If LCP wants PAP, try to authenticate, else bring up IPCP */
|
||||
if((lcp_state & LCP_RX_AUTH) && (!(pap_state & PAP_TX_UP))) {
|
||||
pap_task( &uip_buf[ UIP_LLH_LEN ]);
|
||||
} else {
|
||||
ipcp_task( &uip_buf[ UIP_LLH_LEN ]);
|
||||
}
|
||||
}
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/* ppp_upcall() - this is where valid PPP frames from the ahdlc layer are
|
||||
* sent to be processed and demuxed.
|
||||
*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void
|
||||
ppp_upcall(u16_t protocol, u8_t *buffer, u16_t len)
|
||||
{
|
||||
#if PACKET_RX_DEBUG
|
||||
++ppp_rx_frame_count;
|
||||
dump_ppp_packet(buffer, len);
|
||||
if(ppp_rx_frame_count > 18) {
|
||||
done = 1;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* check to see if we have a packet waiting to be processed */
|
||||
if(ppp_flags & PPP_RX_READY) {
|
||||
/* demux on protocol field */
|
||||
switch(protocol) {
|
||||
case LCP: /* We must support some level of LCP */
|
||||
DEBUG1(("LCP Packet - "));
|
||||
lcp_rx(buffer, len);
|
||||
DEBUG1(("\n"));
|
||||
break;
|
||||
case PAP: /* PAP should be compile in optional */
|
||||
DEBUG1(("PAP Packet - "));
|
||||
pap_rx(buffer, len);
|
||||
DEBUG1(("\n"));
|
||||
break;
|
||||
case IPCP: /* IPCP should be compile in optional. */
|
||||
DEBUG1(("IPCP Packet - "));
|
||||
ipcp_rx(buffer, len);
|
||||
DEBUG1(("\n"));
|
||||
break;
|
||||
case IPV4: /* We must support IPV4 */
|
||||
DEBUG1(("IPV4 Packet---\n"));
|
||||
memcpy( &uip_buf[ UIP_LLH_LEN ], buffer, len);
|
||||
uip_len = len;
|
||||
DEBUG1(("\n"));
|
||||
break;
|
||||
default:
|
||||
DEBUG1(("Unknown PPP Packet Type 0x%04x - ",protocol));
|
||||
ppp_reject_protocol(protocol, buffer, len);
|
||||
DEBUG1(("\n"));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/* scan_packet(list,buffer,len)
|
||||
*
|
||||
* list = list of supported ID's
|
||||
* *buffer pointer to the first code in the packet
|
||||
* length of the codespace
|
||||
*/
|
||||
u16_t
|
||||
scan_packet(u16_t protocol, u8_t *list, u8_t *buffer, u8_t *options, u16_t len)
|
||||
{
|
||||
u8_t *tlist, *bptr;
|
||||
u8_t *tptr;
|
||||
u8_t bad = 0;
|
||||
u8_t i, j, good;
|
||||
|
||||
bptr = tptr = options;
|
||||
/* scan through the packet and see if it has any unsupported codes */
|
||||
while(bptr < options + len) {
|
||||
/* get code and see if it matches somwhere in the list, if not
|
||||
we don't support it */
|
||||
i = *bptr++;
|
||||
|
||||
/* DEBUG2("%x - ",i);*/
|
||||
tlist = list;
|
||||
good = 0;
|
||||
while(*tlist) {
|
||||
/* DEBUG2("%x ",*tlist);*/
|
||||
if(i == *tlist++) {
|
||||
good = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(!good) {
|
||||
/* we don't understand it, write it back */
|
||||
DEBUG1(("We don't understand option 0x%02x\n",i));
|
||||
bad = 1;
|
||||
*tptr++ = i;
|
||||
j = *tptr++ = *bptr++;
|
||||
for(i = 0; i < j - 2; ++i) {
|
||||
*tptr++ = *bptr++;
|
||||
}
|
||||
} else {
|
||||
/* advance over to next option */
|
||||
bptr += *bptr - 1;
|
||||
}
|
||||
}
|
||||
|
||||
/* Bad? if we we need to send a config Reject */
|
||||
if(bad) {
|
||||
/* write the config Rej packet we've built above, take on the header */
|
||||
bptr = buffer;
|
||||
*bptr++ = CONF_REJ; /* Write Conf_rej */
|
||||
bptr++; /* skip over ID */
|
||||
*bptr++ = 0;
|
||||
*bptr = tptr - buffer;
|
||||
/* length right here? */
|
||||
|
||||
/* write the reject frame */
|
||||
DEBUG1(("Writing Reject frame --\n"));
|
||||
ahdlc_tx(protocol, buffer, 0, (u16_t)(tptr - buffer), 0);
|
||||
DEBUG1(("\nEnd writing reject \n"));
|
||||
|
||||
}
|
||||
return bad;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
|
@ -1,132 +0,0 @@
|
|||
#ifndef __PPP_H__
|
||||
#define __PPP_H__
|
||||
/* www.mycal.net
|
||||
---------------------------------------------------------------------------
|
||||
ppp.h - ppp header file
|
||||
---------------------------------------------------------------------------
|
||||
Version
|
||||
0.1 Original Version June 3, 2000
|
||||
(c)2000 Mycal Labs, All Rights Reserved
|
||||
--------------------------------------------------------------------------- */
|
||||
/*
|
||||
* Copyright (c) 2003, Mike Johnson, Mycal Labs, www.mycal.net
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. 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.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by Mike Johnson/Mycal Labs
|
||||
* www.mycal.net.
|
||||
* 4. The name of the author may not be used to endorse or promote
|
||||
* products derived from this software without specific prior
|
||||
* written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
||||
*
|
||||
* This file is part of the Mycal Modified uIP TCP/IP stack.
|
||||
*
|
||||
* $Id: ppp.h,v 1.1 2007/05/26 07:14:40 oliverschmidt Exp $
|
||||
*
|
||||
*/
|
||||
#include "net/uip.h"
|
||||
#include "net/uip-fw.h"
|
||||
#include "contiki-conf.h"
|
||||
#include "ahdlc.h"
|
||||
#include "lcp.h"
|
||||
#include "ipcp.h"
|
||||
#include "pap.h"
|
||||
#include "ppp_arch.h"
|
||||
#include "ppp_process.h"
|
||||
/*#include "mip.h"*/
|
||||
|
||||
/* moved to pppconfig.h
|
||||
#define PPP_RX_BUFFER_SIZE 1024
|
||||
#define PPP_TX_BUFFER_SIZE 64*/
|
||||
|
||||
#define CRC_GOOD_VALUE 0xf0b8
|
||||
|
||||
/* ppp_rx_status values */
|
||||
#define PPP_RX_IDLE 0
|
||||
#define PPP_READY 1
|
||||
|
||||
/* ppp flags */
|
||||
#define PPP_ESCAPED 0x1
|
||||
#define PPP_RX_READY 0x2
|
||||
#define PPP_RX_ASYNC_MAP 0x8
|
||||
#define PPP_TX_ASYNC_MAP 0x8
|
||||
#define PPP_PFC 0x10
|
||||
#define PPP_ACFC 0x20
|
||||
|
||||
/* Supported PPP Protocols */
|
||||
#define LCP 0xc021
|
||||
#define PAP 0xc023
|
||||
#define IPCP 0x8021
|
||||
#define IPV4 0x0021
|
||||
|
||||
/* LCP codes packet types */
|
||||
#define CONF_REQ 0x1
|
||||
#define CONF_ACK 0x2
|
||||
#define CONF_NAK 0x3
|
||||
#define CONF_REJ 0x4
|
||||
#define TERM_REQ 0x5
|
||||
#define TERM_ACK 0x6
|
||||
#define PROT_REJ 0x8
|
||||
|
||||
/* Raise PPP config bits */
|
||||
#define USE_PAP 0x1
|
||||
#define USE_NOACCMBUG 0x2
|
||||
#define USE_GETDNS 0x4
|
||||
|
||||
#define ppp_setusername(un) strncpy(pap_username, (un), PAP_USERNAME_SIZE)
|
||||
#define ppp_setpassword(pw) strncpy(pap_password, (pw), PAP_PASSWORD_SIZE)
|
||||
|
||||
/*
|
||||
* Export Variables
|
||||
*/
|
||||
/*extern u8_t ppp_tx_buffer[PPP_TX_BUFFER_SIZE];*/
|
||||
extern u8_t ppp_rx_buffer[];
|
||||
extern u8_t ppp_rx_count;
|
||||
|
||||
extern struct uip_fw_netif pppif;
|
||||
|
||||
/*extern u16_t ppp_crc_error;*/
|
||||
|
||||
extern u8_t ppp_flags;
|
||||
extern u8_t ppp_status;
|
||||
/*extern u16_t ppp_rx_crc; */
|
||||
extern u16_t ppp_rx_tobig_error;
|
||||
extern u8_t ppp_lcp_state;
|
||||
|
||||
extern u8_t ppp_id;
|
||||
extern u8_t ppp_retry;
|
||||
|
||||
/*
|
||||
* Function Prototypes
|
||||
*/
|
||||
void ppp_init(void);
|
||||
void ppp_connect(void);
|
||||
|
||||
void ppp_send(void);
|
||||
void ppp_poll(void);
|
||||
|
||||
void ppp_upcall(u16_t, u8_t *, u16_t);
|
||||
u16_t scan_packet(u16_t, u8_t *list, u8_t *buffer, u8_t *options, u16_t len);
|
||||
|
||||
#endif /* __PPP_H__ */
|
|
@ -1,234 +0,0 @@
|
|||
/*
|
||||
* $Id: ppp_process.c,v 1.1 2007/05/26 07:14:40 oliverschmidt Exp $
|
||||
*/
|
||||
|
||||
#include "contiki.h"
|
||||
#include "contiki-net.h"
|
||||
#include "net/ppp/ppp.h"
|
||||
|
||||
PROCESS(ppp_process, "PPP");
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Note, that the UART RX-FIFO must be polled often enough so we don't get an
|
||||
// overrun at the used baudrate.
|
||||
//-----------------------------------------------------------------------------
|
||||
#define PPP_POLL_INTERVAL (CLOCK_SECOND / 256)
|
||||
#define AT_TIMEOUT (2 * CLOCK_SECOND / PPP_POLL_INTERVAL)
|
||||
#define AT_RX_BUF 64
|
||||
|
||||
enum {
|
||||
AT_CONNECT_DIRECT,
|
||||
AT_CONNECT_AUTO,
|
||||
AT_CONNECT_MANUAL
|
||||
} At_connect;
|
||||
|
||||
enum {
|
||||
AT_IDLE,
|
||||
AT_CONNECT,
|
||||
AT_CONNECT1,
|
||||
AT_CONNECT2,
|
||||
AT_CONNECTED,
|
||||
AT_RESET,
|
||||
AT_RESET1,
|
||||
AT_RESET2,
|
||||
AT_RESET3,
|
||||
AT_RESET4,
|
||||
AT_RESET5
|
||||
};
|
||||
|
||||
static struct etimer pppTimer;
|
||||
static u8_t at_state;
|
||||
static u8_t at_connect_mode = AT_CONNECT_MODE;
|
||||
static int at_timeout = -1;
|
||||
static u8_t at_rxBuf[ AT_RX_BUF ];
|
||||
|
||||
|
||||
static void
|
||||
at_puts(char *s) {
|
||||
while(*s) {
|
||||
ppp_arch_putchar(*s);
|
||||
s++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static u8_t
|
||||
*at_gets() {
|
||||
static u8_t consumed;
|
||||
int len;
|
||||
int i;
|
||||
|
||||
if (consumed) {
|
||||
consumed = 0;
|
||||
at_rxBuf[0] = 0;
|
||||
}
|
||||
len = strlen(at_rxBuf);
|
||||
|
||||
for (i=len; i<AT_RX_BUF-1; i++) {
|
||||
if ( ppp_arch_getchar(&at_rxBuf[i])) {
|
||||
at_rxBuf[i+1] = 0;
|
||||
if (at_rxBuf[i] == '\n') {
|
||||
//printf("at_gets=(%s)\n", at_rxBuf);
|
||||
consumed = 1;
|
||||
return at_rxBuf;
|
||||
}
|
||||
} else {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
// overflow -> reset the buf
|
||||
at_rxBuf[0] = 0;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
at_poll() {
|
||||
|
||||
static u8_t loopCnt = 0;
|
||||
u8_t *s;
|
||||
|
||||
if (at_timeout > 0) {
|
||||
at_timeout--;
|
||||
}
|
||||
|
||||
if (at_state == AT_CONNECTED) {
|
||||
ppp_poll();
|
||||
if(uip_len > 0) {
|
||||
tcpip_input();
|
||||
}
|
||||
|
||||
if (loopCnt++ > 16) {
|
||||
int i;
|
||||
loopCnt = 0;
|
||||
for (i=0; i<UIP_CONNS; i++) {
|
||||
uip_periodic(i);
|
||||
if(uip_len > 0) {
|
||||
tcpip_output();
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
||||
switch (at_state) {
|
||||
|
||||
case AT_IDLE:
|
||||
switch (at_connect_mode) {
|
||||
|
||||
case AT_CONNECT_DIRECT:
|
||||
at_state = AT_CONNECTED;
|
||||
ppp_connect();
|
||||
break;
|
||||
|
||||
case AT_CONNECT_AUTO:
|
||||
at_state = AT_CONNECT;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case AT_CONNECT:
|
||||
at_gets(); // make the input buffer empty
|
||||
at_puts("ATE1\r\n");
|
||||
at_state = AT_CONNECT1;
|
||||
at_timeout = AT_TIMEOUT;
|
||||
break;
|
||||
|
||||
case AT_CONNECT1:
|
||||
if (at_timeout == 0) {
|
||||
at_state = AT_RESET;
|
||||
} else if ((s=at_gets())) {
|
||||
if (strcmp(s,"OK\r\n") == 0) {
|
||||
at_puts("AT+CGDCONT=1,\"IP\",\"online.telia.se\",\"\",0,0\r\n");
|
||||
at_timeout = AT_TIMEOUT;
|
||||
at_state = AT_CONNECT2;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case AT_CONNECT2:
|
||||
if (at_timeout == 0) {
|
||||
at_state = AT_RESET;
|
||||
} else if ((s=at_gets())) {
|
||||
if (strcmp(s,"OK\r\n") == 0) {
|
||||
at_puts("ATD*99***1#\r\n");
|
||||
at_state = AT_CONNECTED;
|
||||
ppp_connect();
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case AT_RESET:
|
||||
//printf("AT_RESET\n");
|
||||
at_timeout = AT_TIMEOUT;
|
||||
at_state = AT_RESET1;
|
||||
break;
|
||||
|
||||
case AT_RESET1:
|
||||
if (at_timeout == 0) {
|
||||
lcp_disconnect(random_rand() & 0xff);
|
||||
at_timeout = AT_TIMEOUT;
|
||||
at_state = AT_RESET2;
|
||||
}
|
||||
break;
|
||||
|
||||
case AT_RESET2:
|
||||
if (at_timeout == 0) {
|
||||
lcp_disconnect(random_rand() & 0xff);
|
||||
at_timeout = AT_TIMEOUT;
|
||||
at_state = AT_RESET3;
|
||||
}
|
||||
break;
|
||||
|
||||
case AT_RESET3:
|
||||
if (at_timeout == 0) {
|
||||
at_puts("+++");
|
||||
at_timeout = AT_TIMEOUT;
|
||||
at_state = AT_RESET4;
|
||||
}
|
||||
break;
|
||||
|
||||
case AT_RESET4:
|
||||
if (at_timeout == 0) {
|
||||
at_puts("ATZ\r\n");
|
||||
at_timeout = AT_TIMEOUT;
|
||||
at_state = AT_RESET5;
|
||||
}
|
||||
break;
|
||||
|
||||
case AT_RESET5:
|
||||
at_gets(); // make the input buffer empty
|
||||
if (at_timeout == 0) {
|
||||
at_state = AT_IDLE;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ppp_reconnect() {
|
||||
at_state = AT_RESET;
|
||||
uip_fw_unregister(&pppif);
|
||||
}
|
||||
|
||||
|
||||
PROCESS_THREAD(ppp_process, ev, data)
|
||||
{
|
||||
PROCESS_BEGIN();
|
||||
|
||||
at_state = AT_IDLE;
|
||||
at_rxBuf[0] = 0;
|
||||
|
||||
ppp_init();
|
||||
etimer_set(&pppTimer, PPP_POLL_INTERVAL);
|
||||
|
||||
while(1) {
|
||||
PROCESS_WAIT_EVENT_UNTIL(ev == PROCESS_EVENT_TIMER);
|
||||
|
||||
if(etimer_expired(&pppTimer)) {
|
||||
etimer_set(&pppTimer, PPP_POLL_INTERVAL);
|
||||
at_poll();
|
||||
}
|
||||
}
|
||||
|
||||
PROCESS_END();
|
||||
}
|
|
@ -1,3 +0,0 @@
|
|||
#include "contiki.h"
|
||||
|
||||
PROCESS_NAME(ppp_process);
|
|
@ -1,134 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2004, Swedish Institute of Computer Science.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. 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.
|
||||
* 3. Neither the name of the Institute 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 INSTITUTE 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 INSTITUTE 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.
|
||||
*
|
||||
* This file is part of the Contiki operating system.
|
||||
*
|
||||
* Author: Adam Dunkels <adam@sics.se>
|
||||
*
|
||||
* $Id: uipbuf.c,v 1.1 2007/11/18 01:18:50 oliverschmidt Exp $
|
||||
*/
|
||||
|
||||
#if 0 /* This whole file is #ifdef'd out - the contents are to be removed */
|
||||
|
||||
#include "net/uipbuf.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void
|
||||
uipbuf_setup(struct uipbuf_buffer *buf,
|
||||
u8_t *bufptr, u16_t bufsize)
|
||||
{
|
||||
buf->buffer = buf->ptr = bufptr;
|
||||
buf->bufsize = buf->left = bufsize;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
u8_t
|
||||
uipbuf_bufdata(struct uipbuf_buffer *buf, u16_t len,
|
||||
u8_t **dataptr, u16_t *datalen)
|
||||
{
|
||||
if(*datalen < buf->left) {
|
||||
memcpy(buf->ptr, *dataptr, *datalen);
|
||||
buf->ptr += *datalen;
|
||||
buf->left -= *datalen;
|
||||
*dataptr += *datalen;
|
||||
*datalen = 0;
|
||||
return UIPBUF_NOT_FULL;
|
||||
} else if(*datalen == buf->left) {
|
||||
memcpy(buf->ptr, *dataptr, *datalen);
|
||||
buf->ptr += *datalen;
|
||||
buf->left = 0;
|
||||
*dataptr += *datalen;
|
||||
*datalen = 0;
|
||||
return UIPBUF_FULL;
|
||||
} else {
|
||||
memcpy(buf->ptr, *dataptr, buf->left);
|
||||
buf->ptr += buf->left;
|
||||
*datalen -= buf->left;
|
||||
*dataptr += buf->left;
|
||||
buf->left = 0;
|
||||
return UIPBUF_FULL;
|
||||
}
|
||||
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
u8_t
|
||||
uipbuf_bufto(CC_REGISTER_ARG struct uipbuf_buffer *buf, u8_t endmarker,
|
||||
CC_REGISTER_ARG u8_t **dataptr, CC_REGISTER_ARG u16_t *datalen)
|
||||
{
|
||||
u8_t c;
|
||||
/*
|
||||
int len;
|
||||
|
||||
ptr = memchr(*dataptr, endmarker, *datalen);
|
||||
if(ptr != NULL) {
|
||||
len = ptr - *dataptr;
|
||||
} else {
|
||||
len = *datalen;
|
||||
}
|
||||
memcpy(buf->ptr, *dataptr, len);
|
||||
*dataptr += len;
|
||||
*datalen -= len;
|
||||
buf->ptr += len;
|
||||
*/
|
||||
while(buf->left > 0 && *datalen > 0) {
|
||||
c = *buf->ptr = **dataptr;
|
||||
++*dataptr;
|
||||
++buf->ptr;
|
||||
--*datalen;
|
||||
--buf->left;
|
||||
|
||||
if(c == endmarker) {
|
||||
return UIPBUF_FOUND;
|
||||
}
|
||||
}
|
||||
|
||||
if(*datalen == 0) {
|
||||
return UIPBUF_NOT_FOUND;
|
||||
}
|
||||
|
||||
while(*datalen > 0) {
|
||||
c = **dataptr;
|
||||
--*datalen;
|
||||
++*dataptr;
|
||||
|
||||
if(c == endmarker) {
|
||||
return UIPBUF_FOUND | UIPBUF_FULL;
|
||||
}
|
||||
}
|
||||
|
||||
return UIPBUF_FULL;
|
||||
}
|
||||
/*----------------------------------------------------------------------------*/
|
||||
u16_t
|
||||
uipbuf_len(struct uipbuf_buffer *buf)
|
||||
{
|
||||
return buf->bufsize - buf->left;
|
||||
}
|
||||
/*----------------------------------------------------------------------------*/
|
||||
#endif /* 0 */
|
|
@ -1,182 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2004, Swedish Institute of Computer Science.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. 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.
|
||||
* 3. Neither the name of the Institute 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 INSTITUTE 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 INSTITUTE 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.
|
||||
*
|
||||
* This file is part of the Contiki operating system.
|
||||
*
|
||||
* Author: Adam Dunkels <adam@sics.se>
|
||||
*
|
||||
* $Id: uipbuf.h,v 1.1 2007/11/18 01:18:50 oliverschmidt Exp $
|
||||
*/
|
||||
/**
|
||||
* \file
|
||||
* uIP data buffering helper functions.
|
||||
* \author
|
||||
* Adam Dunkels <adam@sics.se>
|
||||
*
|
||||
*/
|
||||
|
||||
#if 0 /* This whole file is #ifdef'd out - the contents are to be removed */
|
||||
|
||||
#ifndef __UIPBUF_H__
|
||||
#define __UIPBUF_H__
|
||||
|
||||
#include "net/uip.h"
|
||||
|
||||
/**
|
||||
* \defgroup uipbuf uIP data buffering helper library.
|
||||
*
|
||||
* The event driven API that uIP uses can be tricky to use when
|
||||
* dealing with incoming TCP data. The data can be split over any
|
||||
* number of incoming segments and uIP does not provide any stream
|
||||
* abstraction by itself. To remedy this, the uIP data buffering
|
||||
* helper library provides a set of functions that make buffering data
|
||||
* easier.
|
||||
*
|
||||
* The data buffering library provides a structure that holds a
|
||||
* pointer to a buffer and the state of the buffer, as well as a set
|
||||
* of functions for manipulating the buffer state. The functions are
|
||||
* intended to facilitate buffering of both data that is of a known
|
||||
* size and data that is terminated by a specified byte.
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* Return value of the buffering functions that indicates that a
|
||||
* buffer was not filled by incoming data.
|
||||
*
|
||||
* \hideinitializer
|
||||
*/
|
||||
#define UIPBUF_NOT_FULL 0
|
||||
#define UIPBUF_NOT_FOUND 0
|
||||
|
||||
/**
|
||||
* Return value of the buffering functions that indicates that a
|
||||
* buffer was completely filled by incoming data.
|
||||
*
|
||||
* \hideinitializer
|
||||
*/
|
||||
#define UIPBUF_FULL 1
|
||||
|
||||
/**
|
||||
* Return value of the buffering functions that indicates that an
|
||||
* end-marker byte was found.
|
||||
*
|
||||
* \hideinitializer
|
||||
*/
|
||||
#define UIPBUF_FOUND 2
|
||||
|
||||
/**
|
||||
* The structure that holds the state of a uIP buffer.
|
||||
*
|
||||
* This structure holds the state of a uIP buffer. The structure has
|
||||
* no user-visible elements, but is used through the functions
|
||||
* provided by the library.
|
||||
*
|
||||
* \hideinitializer
|
||||
*/
|
||||
struct uipbuf_buffer {
|
||||
u8_t *ptr, *buffer;
|
||||
unsigned short left, bufsize;
|
||||
};
|
||||
|
||||
/**
|
||||
* Set up a new uIP buffer structure.
|
||||
*
|
||||
* This function is used for setting up a uIP buffer structure with a
|
||||
* specified size. The function should be called the first time a uIP
|
||||
* buffer is used. The caller must provide the memory for holding the
|
||||
* buffered bytes and the size of the buffer memory.
|
||||
*
|
||||
* \param buf A pointer to a uipbuf_buffer structure that is to be
|
||||
* initialized.
|
||||
*
|
||||
* \param bufptr A pointer to the memory for holding the buffered
|
||||
* data.
|
||||
*
|
||||
* \param size The size of the buffer memory.
|
||||
*
|
||||
*/
|
||||
void uipbuf_setup(struct uipbuf_buffer *buf,
|
||||
u8_t *bufptr, u16_t size);
|
||||
|
||||
/**
|
||||
* Buffer data until the buffer is full.
|
||||
*
|
||||
* This function puts data into the buffer, but no more than the
|
||||
* buffer can hold.
|
||||
*
|
||||
* \param buf A pointer to the ::uipbuf_buffer structure that holds
|
||||
* the state of the buffer.
|
||||
*
|
||||
* \param dataptr A pointer to the data that is to be buffered.
|
||||
*
|
||||
* \param datalen The length of the data that is to be buffered.
|
||||
*
|
||||
* \return If the buffer was not filled, the value UIPBUF_NOT_FULL
|
||||
* is returned. If the buffer was filled, the number of bytes that
|
||||
* could not be buffered is returned. If the buffer was exactly filled
|
||||
* with the data, the value of 0 is returned.
|
||||
*
|
||||
*/
|
||||
u8_t uipbuf_bufdata(struct uipbuf_buffer *buf, u16_t len,
|
||||
u8_t **dataptr, u16_t *datalen);
|
||||
|
||||
/**
|
||||
* Buffer data until a specific character is found or the buffer is full.
|
||||
*
|
||||
* This function puts data into the buffer until a specific marker
|
||||
* byte is found. The marker byte is put into the buffer at the end of
|
||||
* the data.
|
||||
*
|
||||
* \param buf A pointer to the ::uipbuf_buffer structure that holds
|
||||
* the state of the buffer.
|
||||
*
|
||||
* \param dataptr A pointer to the data that is to be buffered.
|
||||
*
|
||||
* \param datalen The length of the data that is to be buffered.
|
||||
*
|
||||
* \param byte The end-marker byte that indicates the end of the data
|
||||
* that is to be buffered.
|
||||
*
|
||||
* \return This function returns the number of protruding bytes after
|
||||
* the end-marker byte, if the marker was found. If the marker was not
|
||||
* found and all of the data was buffered, the value of
|
||||
* UIPBUF_NOT_FOUND is returned. If the marker was not found, but the
|
||||
* data made the buffer fill up, the value of UIPBUF_FULL is returned.
|
||||
*
|
||||
*/
|
||||
u8_t uipbuf_bufto(struct uipbuf_buffer *buf, u8_t endmarker,
|
||||
u8_t **dataptr, u16_t *datalen);
|
||||
|
||||
u16_t uipbuf_len(struct uipbuf_buffer *buf);
|
||||
|
||||
/** @} */
|
||||
|
||||
#endif /* __UIPBUF_H__ */
|
||||
#endif /* 0 */
|
|
@ -1,111 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2005, Swedish Institute of Computer Science
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. 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.
|
||||
* 3. Neither the name of the Institute 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 INSTITUTE 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 INSTITUTE 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.
|
||||
*
|
||||
* This file is part of the Contiki operating system.
|
||||
*
|
||||
* @(#)$Id: service.c,v 1.1 2007/05/26 23:24:24 oliverschmidt Exp $
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "contiki.h"
|
||||
|
||||
/**
|
||||
* \addtogroup service
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file
|
||||
* Implementation of the Contiki service mechanism.
|
||||
* \author
|
||||
* Adam Dunkels <adam@sics.se>
|
||||
*/
|
||||
|
||||
static struct service *services_list = NULL;
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void
|
||||
service_register(struct service *s)
|
||||
{
|
||||
struct service *existing;
|
||||
|
||||
|
||||
s->p = PROCESS_CURRENT();
|
||||
|
||||
existing = service_find(s->name);
|
||||
if(existing != NULL) {
|
||||
service_remove(existing);
|
||||
}
|
||||
|
||||
s->next = services_list;
|
||||
services_list = s;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void
|
||||
service_remove(struct service *s)
|
||||
{
|
||||
struct service *t;
|
||||
|
||||
|
||||
/* Check if service is first on the list. */
|
||||
if(s == services_list) {
|
||||
services_list = s->next;
|
||||
|
||||
/* Post a notification to the owner process. */
|
||||
process_post(s->p, PROCESS_EVENT_SERVICE_REMOVED, s);
|
||||
|
||||
} else {
|
||||
for(t = services_list; t != NULL && t->next != s; t = t->next);
|
||||
if(t != NULL) {
|
||||
t->next = s->next;
|
||||
|
||||
/* Post a notification to the owner process. */
|
||||
process_post(s->p, PROCESS_EVENT_SERVICE_REMOVED, s);
|
||||
}
|
||||
}
|
||||
|
||||
s->next = NULL;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
struct service *
|
||||
service_find(const char *name)
|
||||
{
|
||||
struct service *s;
|
||||
|
||||
|
||||
for(s = services_list; s != NULL; s = s->next) {
|
||||
if(strcmp(s->name, name) == 0) {
|
||||
return s;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
||||
/** @} */
|
|
@ -1,195 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2005, Swedish Institute of Computer Science
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. 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.
|
||||
* 3. Neither the name of the Institute 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 INSTITUTE 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 INSTITUTE 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.
|
||||
*
|
||||
* This file is part of the Contiki operating system.
|
||||
*
|
||||
* @(#)$Id: service.h,v 1.1 2007/05/26 23:24:24 oliverschmidt Exp $
|
||||
*/
|
||||
|
||||
/** \addtogroup sys
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* \defgroup service The Contiki service mechanism
|
||||
*
|
||||
* The Contiki service mechanism enables cross-process functions. A
|
||||
* service that is registered by one process can be accessed by other
|
||||
* processes in the system. Services can be transparently replaced at
|
||||
* run-time.
|
||||
*
|
||||
* A service has an interface that callers use to access the service's
|
||||
* functions. This interface typically is defined in a header file
|
||||
* that is included by all users of the service. A service interface
|
||||
* is defined with the SERVICE_INTERFACE() macro.
|
||||
*
|
||||
* A service implementation is declared with the SERVICE() macro. The
|
||||
* SERVICE() statement specifies the actual functions that are used to
|
||||
* implement the service.
|
||||
*
|
||||
* Every service has a controlling process. The controlling process
|
||||
* registers the service with the system when it starts, and is also
|
||||
* notified if the service is removed or replaced. A process may
|
||||
* register any number of services.
|
||||
*
|
||||
* Service registration is done with a SERVICE_REGISTER()
|
||||
* statement. If a service with the same name is already registered,
|
||||
* this is removed before the new service is registered.
|
||||
*
|
||||
* The SERVICE_CALL() macro is used to call a service. If the service
|
||||
* to be called is not registered, the SERVICE_CALL() statement does
|
||||
* nothing. The SERVICE_FIND() function can be used to check if a
|
||||
* particular service exists before calling SERVICE_CALL().
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file
|
||||
* Header file for the Contiki service mechanism.
|
||||
* \author
|
||||
* Adam Dunkels <adam@sics.se>
|
||||
*/
|
||||
|
||||
#ifndef __SERVICE_H__
|
||||
#define __SERVICE_H__
|
||||
|
||||
#include "contiki.h"
|
||||
|
||||
struct service {
|
||||
struct service *next;
|
||||
struct process *p;
|
||||
const char *name;
|
||||
const void *interface;
|
||||
};
|
||||
|
||||
/**
|
||||
* \name Service declaration and defition
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* Define the name and interface of a service.
|
||||
*
|
||||
* This statement defines the name and interface of a service.
|
||||
*
|
||||
* \param name The name of the service.
|
||||
*
|
||||
* \param interface A list of function declarations that comprises the
|
||||
* service interface. This list must be enclosed by curly brackets and
|
||||
* consist of declarations of function pointers separated by
|
||||
* semicolons.
|
||||
*
|
||||
* \hideinitializer
|
||||
*/
|
||||
#define SERVICE_INTERFACE(name, interface) struct name interface;
|
||||
|
||||
#if ! CC_NO_VA_ARGS
|
||||
/**
|
||||
* \brief Define an implementation of a service interface.
|
||||
* \param name The name of this particular instance of the service, for use with SERVICE_REGISTER().
|
||||
* \param service_name The name of the service, from the SERVICE_INTERFACE().
|
||||
* \param ... A structure containing the functions that implements the service.
|
||||
*
|
||||
* This statement defines the name of this implementation
|
||||
* of the service and defines the functions that actually
|
||||
* implement the functions offered by the service.
|
||||
*
|
||||
* \hideinitializer
|
||||
*/
|
||||
#define SERVICE(name, service_name, ...) \
|
||||
static struct service_name name##_interface = __VA_ARGS__ ; \
|
||||
struct service name = { NULL, NULL, service_name##_name, & name##_interface }
|
||||
#endif
|
||||
|
||||
/** @} */
|
||||
|
||||
/**
|
||||
* \name Calling a service
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* Call a function from a specified service, if it is registered.
|
||||
*
|
||||
*
|
||||
* \param service_name The name of the service that is to be called.
|
||||
*
|
||||
* \param function The function that is to be called. This is a full
|
||||
* function call, including parameters.
|
||||
*
|
||||
* \hideinitializer
|
||||
*/
|
||||
#define SERVICE_CALL(service_name, function) \
|
||||
{ \
|
||||
struct service *service_s; \
|
||||
service_s = service_find(service_name##_name); \
|
||||
if(service_s != NULL) { \
|
||||
((const struct service_name *)service_s->interface)->function; \
|
||||
} \
|
||||
}
|
||||
|
||||
/* @} */
|
||||
|
||||
#define SERVICE_EXISTS(service_name) (service_find(service_name##_name) != NULL)
|
||||
|
||||
/**
|
||||
* \name Service registration and removal
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* Register a service.
|
||||
*
|
||||
* \hideinitializer
|
||||
*/
|
||||
#define SERVICE_REGISTER(name) service_register(&name)
|
||||
|
||||
/**
|
||||
* Remove a service.
|
||||
*
|
||||
* \hideinitializer
|
||||
*/
|
||||
#define SERVICE_REMOVE(service_name) service_remove(&service_name)
|
||||
|
||||
/** @} */
|
||||
|
||||
/**
|
||||
* Find service.
|
||||
*
|
||||
* \hideinitializer
|
||||
*/
|
||||
#define SERVICE_FIND(service_name) service_find(service_name##_name)
|
||||
|
||||
CCIF void service_register(struct service *s);
|
||||
CCIF void service_remove(struct service *s);
|
||||
struct service *service_find(const char *name);
|
||||
|
||||
#endif /* __SERVICE_H__ */
|
||||
/** @} */
|
||||
/** @} */
|
|
@ -1,73 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2003, Adam Dunkels.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. 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.
|
||||
* 3. The name of the author may not be used to endorse or promote
|
||||
* products derived from this software without specific prior
|
||||
* written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
||||
*
|
||||
* This file is part of the Contiki desktop environment
|
||||
*
|
||||
* $Id: memstat-dsc.c,v 1.2 2007/09/06 01:36:12 matsutsuka Exp $
|
||||
*
|
||||
*/
|
||||
|
||||
#include "sys/dsc.h"
|
||||
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
#if CTK_CONF_ICON_BITMAPS
|
||||
static unsigned char memstaticon_bitmap[3*3*8] = {
|
||||
0x00, 0x7f, 0x43, 0x4c, 0x58, 0x53, 0x60, 0x6f,
|
||||
0x00, 0xff, 0x00, 0x7e, 0x00, 0xff, 0x00, 0xff,
|
||||
0x00, 0xfe, 0xc2, 0x32, 0x1a, 0xca, 0x06, 0xf6,
|
||||
|
||||
0x40, 0x5f, 0x40, 0x5f, 0x40, 0x5f, 0x40, 0x4f,
|
||||
0x00, 0xff, 0x00, 0xff, 0x00, 0xfc, 0x01, 0xf3,
|
||||
0x02, 0xfa, 0x02, 0x82, 0x3e, 0xfe, 0xfe, 0xfe,
|
||||
|
||||
0x60, 0x67, 0x50, 0x59, 0x4c, 0x43, 0x7f, 0x00,
|
||||
0x07, 0xe7, 0x0f, 0xef, 0x0f, 0x0f, 0xff, 0x00,
|
||||
0x8e, 0x06, 0x06, 0x06, 0x8e, 0xfe, 0xfe, 0x00
|
||||
};
|
||||
#endif /* CTK_CONF_ICON_BITMAPS */
|
||||
|
||||
#if CTK_CONF_ICON_TEXTMAPS
|
||||
static char memstaticon_textmap[9] = {
|
||||
'0', '0', '1',
|
||||
'0', '1', '0',
|
||||
'1', '0', '1'
|
||||
};
|
||||
#endif /* CTK_CONF_ICON_TEXTMAPS */
|
||||
|
||||
#if CTK_CONF_ICONS
|
||||
static struct ctk_icon memstat_icon =
|
||||
{CTK_ICON("Memory stats", memstaticon_bitmap, memstaticon_textmap)};
|
||||
#endif /* CTK_CONF_ICONS */
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
DSC(memstat_dsc,
|
||||
"Memory stats",
|
||||
"memstat.prg",
|
||||
memstat_init,
|
||||
&memstat_icon);
|
||||
/*-----------------------------------------------------------------------------------*/
|
|
@ -1,42 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2003, Adam Dunkels.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. 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.
|
||||
* 3. The name of the author may not be used to endorse or promote
|
||||
* products derived from this software without specific prior
|
||||
* written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
||||
*
|
||||
* This file is part of the Contiki desktop environment
|
||||
*
|
||||
* $Id: memstat-dsc.h,v 1.1 2007/05/23 23:47:44 oliverschmidt Exp $
|
||||
*
|
||||
*/
|
||||
#ifndef __MEMSTAT_DSC_H__
|
||||
#define __MEMSTAT_DSC_H__
|
||||
|
||||
#include "sys/dsc.h"
|
||||
|
||||
DSC_HEADER(memstat_dsc);
|
||||
|
||||
#endif /* __MEMSTAT_DSC_H__ */
|
|
@ -1,127 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2002, Adam Dunkels.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. 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.
|
||||
* 3. The name of the author may not be used to endorse or promote
|
||||
* products derived from this software without specific prior
|
||||
* written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
||||
*
|
||||
* This file is part of the Contiki desktop environment
|
||||
*
|
||||
* $Id: memstat.c,v 1.1 2007/05/23 23:47:44 oliverschmidt Exp $
|
||||
*
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "contiki.h"
|
||||
#include "ctk/ctk.h"
|
||||
|
||||
static struct ctk_window window;
|
||||
static struct ctk_label freemsg =
|
||||
{CTK_LABEL(2, 0, 12, 1, "Free memory:")};
|
||||
static char freemem[6];
|
||||
static struct ctk_label freenum =
|
||||
{CTK_LABEL(18, 0, 5, 1, freemem)};
|
||||
|
||||
static struct ctk_label lblockmsg =
|
||||
{CTK_LABEL(2, 2, 14, 1, "Largest block:")};
|
||||
static char lblock[6];
|
||||
static struct ctk_label lblocknum =
|
||||
{CTK_LABEL(18, 2, 5, 1, lblock)};
|
||||
|
||||
static struct ctk_button updatebutton =
|
||||
{CTK_BUTTON(0, 4, 6, "Update")};
|
||||
static struct ctk_button closebutton =
|
||||
{CTK_BUTTON(17, 4, 5, "Close")};
|
||||
|
||||
PROCESS(memstat_process, "Memory statistics");
|
||||
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
static void
|
||||
update(void)
|
||||
{
|
||||
int mem;
|
||||
|
||||
mem = _heapmemavail();
|
||||
freemem[0] = (mem/10000) % 10 + '0';
|
||||
freemem[1] = (mem/1000) % 10 + '0';
|
||||
freemem[2] = (mem/100) % 10 + '0';
|
||||
freemem[3] = (mem/10) % 10 + '0';
|
||||
freemem[4] = (mem) % 10 + '0';
|
||||
|
||||
mem = _heapmaxavail();
|
||||
lblock[0] = (mem/10000) % 10 + '0';
|
||||
lblock[1] = (mem/1000) % 10 + '0';
|
||||
lblock[2] = (mem/100) % 10 + '0';
|
||||
lblock[3] = (mem/10) % 10 + '0';
|
||||
lblock[4] = (mem) % 10 + '0';
|
||||
|
||||
}
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
PROCESS_THREAD(memstat_process, ev, data)
|
||||
{
|
||||
PROCESS_BEGIN();
|
||||
|
||||
ctk_window_new(&window, 24, 5, "Memory stats");
|
||||
/* ctk_window_move(&window, 0, 1);*/
|
||||
|
||||
CTK_WIDGET_ADD(&window, &freemsg);
|
||||
CTK_WIDGET_ADD(&window, &freenum);
|
||||
|
||||
CTK_WIDGET_ADD(&window, &lblockmsg);
|
||||
CTK_WIDGET_ADD(&window, &lblocknum);
|
||||
|
||||
CTK_WIDGET_ADD(&window, &updatebutton);
|
||||
CTK_WIDGET_ADD(&window, &closebutton);
|
||||
|
||||
CTK_WIDGET_FOCUS(&window, &updatebutton);
|
||||
|
||||
update();
|
||||
|
||||
ctk_window_open(&window);
|
||||
|
||||
while(1) {
|
||||
|
||||
PROCESS_WAIT_EVENT();
|
||||
|
||||
if(ev == ctk_signal_button_activate) {
|
||||
if(data == &updatebutton) {
|
||||
update();
|
||||
ctk_window_redraw(&window);
|
||||
} else if(data == &closebutton) {
|
||||
ctk_window_close(&window);
|
||||
break;
|
||||
}
|
||||
} else if((ev == ctk_signal_window_close &&
|
||||
data == &window) ||
|
||||
ev == PROCESS_EVENT_EXIT) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
PROCESS_END();
|
||||
|
||||
}
|
||||
/*-----------------------------------------------------------------------------------*/
|
|
@ -1,6 +0,0 @@
|
|||
#!/bin/sh
|
||||
|
||||
|
||||
egrep -v 'ZP|BSS' contiki-labels | perl -n -e 'if(/^al 0000(.+) \.([^@]+)\n/){if($l{$2} eq ""){$l{$2}=$1;print ".exportzp $2\n$2=\$$1\n";}} elsif(/^al 00(.+) \.([^@]+)\n/){if($l{$2} eq ""){$l{$2}=$1;print ".export $2\n$2=\$$1\n";}}' > contiki-labels.s
|
||||
|
||||
echo '.segment "EXTZP": zeropage' >> contiki-labels.s
|
|
@ -1,57 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2003, Adam Dunkels.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. 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.
|
||||
* 3. The name of the author may not be used to endorse or promote
|
||||
* products derived from this software without specific prior
|
||||
* written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
||||
*
|
||||
* This file is part of the Contiki desktop OS
|
||||
*
|
||||
* $Id: loader-arch-dsc.c,v 1.1 2007/05/23 23:50:02 oliverschmidt Exp $
|
||||
*
|
||||
*/
|
||||
|
||||
#include <stddef.h>
|
||||
#include <modload.h>
|
||||
|
||||
#include "sys/loader.h"
|
||||
|
||||
extern struct mod_ctrl ctrl;
|
||||
|
||||
unsigned char load(const char *name);
|
||||
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
struct dsc *
|
||||
loader_arch_load_dsc(const char *name)
|
||||
{
|
||||
unsigned char r;
|
||||
|
||||
r = load(name);
|
||||
if(r == MLOAD_OK) {
|
||||
return (struct dsc *)ctrl.module;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
/*-----------------------------------------------------------------------------------*/
|
|
@ -1,46 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2003, Adam Dunkels.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. 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.
|
||||
* 3. The name of the author may not be used to endorse or promote
|
||||
* products derived from this software without specific prior
|
||||
* written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
||||
*
|
||||
* This file is part of the Contiki desktop OS
|
||||
*
|
||||
* $Id: loader-arch-dsc.h,v 1.1 2007/05/23 23:50:02 oliverschmidt Exp $
|
||||
*
|
||||
*/
|
||||
#ifndef __LOADER_ARCH_DSC_H__
|
||||
#define __LOADER_ARCH_DSC_H__
|
||||
|
||||
#include "sys/dsc.h"
|
||||
#include <modload.h>
|
||||
|
||||
struct dsc *loader_arch_load_dsc(const char *name);
|
||||
|
||||
#define LOADER_LOAD_DSC(name) loader_arch_load_dsc(name)
|
||||
#define LOADER_UNLOAD_DSC(dsc) mod_free(dsc)
|
||||
|
||||
#endif /* __LOADER_ARCH_DSC_H__ */
|
|
@ -1 +0,0 @@
|
|||
.segment "JUMPTABLE"
|
|
@ -1,8 +0,0 @@
|
|||
.segment "JUMPTABLE"
|
||||
.import _loader_appinit
|
||||
.export _loader_arch_loadaddr
|
||||
_loader_arch_loadaddr:
|
||||
arch: .byte 0,0,0,0,0,0,0,0
|
||||
version: .byte 0,0,0,0,0,0,0,0
|
||||
; jmp _loader_appinit
|
||||
|
|
@ -1,117 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2003, Adam Dunkels.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. 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.
|
||||
* 3. The name of the author may not be used to endorse or promote
|
||||
* products derived from this software without specific prior
|
||||
* written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
||||
*
|
||||
* This file is part of the Contiki desktop OS
|
||||
*
|
||||
* $Id: loader-arch.c,v 1.1 2007/05/23 23:50:02 oliverschmidt Exp $
|
||||
*
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <modload.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "loader.h"
|
||||
|
||||
struct mod_ctrl ctrl = {
|
||||
read /* Read from disk */
|
||||
};
|
||||
|
||||
struct loader_arch_hdr {
|
||||
char arch[8];
|
||||
char version[8];
|
||||
|
||||
char initfunc[1];
|
||||
};
|
||||
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
/* load(name)
|
||||
*
|
||||
* Loads a program from disk and executes it. Code originally written by
|
||||
* Ullrich von Bassewitz.
|
||||
*/
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
unsigned char
|
||||
load(const char *name)
|
||||
{
|
||||
unsigned char res;
|
||||
|
||||
/* Now open the file */
|
||||
ctrl.callerdata = open(name, O_RDONLY);
|
||||
if(ctrl.callerdata < 0) {
|
||||
/* Could not open the file, display an error and return */
|
||||
/* ### */
|
||||
return LOADER_ERR_OPEN;
|
||||
}
|
||||
|
||||
/* Load the module */
|
||||
res = mod_load(&ctrl);
|
||||
|
||||
/* Close the input file */
|
||||
close(ctrl.callerdata);
|
||||
|
||||
/* Check the return code */
|
||||
if(res != MLOAD_OK) {
|
||||
/* Wrong module, out of memory or whatever. Print an error
|
||||
* message and return.
|
||||
*/
|
||||
/* ### */
|
||||
return res;
|
||||
}
|
||||
|
||||
/* We've successfully loaded the module. */
|
||||
|
||||
return LOADER_OK;
|
||||
}
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
unsigned char
|
||||
loader_arch_load(const char *name, char *arg)
|
||||
{
|
||||
unsigned char r;
|
||||
struct loader_arch_hdr *hdr;
|
||||
|
||||
r = load(name);
|
||||
if(r != MLOAD_OK) {
|
||||
return r;
|
||||
}
|
||||
hdr = (struct loader_arch_hdr *)ctrl.module;
|
||||
|
||||
/* Check the program header and see that version and architecture
|
||||
matches. */
|
||||
|
||||
/* Call the init function. */
|
||||
|
||||
if(*hdr->initfunc == 0x4c) {
|
||||
((void (*)(char *))hdr->initfunc)(arg);
|
||||
}
|
||||
|
||||
return LOADER_OK;
|
||||
}
|
||||
/*-----------------------------------------------------------------------------------*/
|
|
@ -1,47 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2003, Adam Dunkels.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. 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.
|
||||
* 3. The name of the author may not be used to endorse or promote
|
||||
* products derived from this software without specific prior
|
||||
* written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
||||
*
|
||||
* This file is part of the Contiki desktop OS
|
||||
*
|
||||
* $Id: loader-arch.h,v 1.1 2007/05/23 23:50:02 oliverschmidt Exp $
|
||||
*
|
||||
*/
|
||||
#ifndef __LOADER_ARCH_H__
|
||||
#define __LOADER_ARCH_H__
|
||||
|
||||
#include <modload.h>
|
||||
|
||||
unsigned char loader_arch_load(const char *name, char *arg);
|
||||
|
||||
extern void *loader_arch_loadaddr;
|
||||
|
||||
#define LOADER_LOAD(name, arg) loader_arch_load(name, arg)
|
||||
#define LOADER_UNLOAD() mod_free(&loader_arch_loadaddr)
|
||||
|
||||
#endif /* __LOADER_ARCH_H__ */
|
|
@ -1,272 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2001, Adam Dunkels.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. 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.
|
||||
* 3. The name of the author may not be used to endorse or promote
|
||||
* products derived from this software without specific prior
|
||||
* written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
||||
*
|
||||
* This file is part of the uIP TCP/IP stack.
|
||||
*
|
||||
* $Id: rs232dev.c,v 1.1 2007/11/19 23:00:56 oliverschmidt Exp $
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* This is a generic implementation of the SLIP protocol over an RS232
|
||||
* (serial) device. While initially intented for the C64, the code can
|
||||
* easily be ported to other platforms as well.
|
||||
*
|
||||
* Huge thanks to Ullrich von Bassewitz <uz@cc65.org> of cc65 fame for
|
||||
* and endless supply of bugfixes, insightsful comments and
|
||||
* suggestions, and improvements to this code!
|
||||
*/
|
||||
|
||||
#include <serial.h>
|
||||
#include <time.h>
|
||||
#include <string.h>
|
||||
|
||||
/* This will include the system specific header files as well */
|
||||
#if defined(__CBM__)
|
||||
# include <cbm.h>
|
||||
#elif defined(__ATARI__)
|
||||
# include <atari.h>
|
||||
#endif
|
||||
|
||||
#include "net/uip.h"
|
||||
|
||||
#define SLIP_END 0300
|
||||
#define SLIP_ESC 0333
|
||||
#define SLIP_ESC_END 0334
|
||||
#define SLIP_ESC_ESC 0335
|
||||
|
||||
|
||||
#define SIO_RECV(c) while(ser_get(&c) == SER_ERR_NO_DATA)
|
||||
#define SIO_POLL(c) (ser_get(&c) != SER_ERR_NO_DATA)
|
||||
#define SIO_SEND(c) ser_put(c)
|
||||
|
||||
#define MAX_SIZE (UIP_BUFSIZE - UIP_LLH_LEN)
|
||||
|
||||
static u8_t slip_buf[MAX_SIZE + 2];
|
||||
|
||||
static u16_t len, tmplen;
|
||||
|
||||
static char loaded = 0;
|
||||
|
||||
#if 1
|
||||
#define printf(x)
|
||||
#else
|
||||
#include <stdio.h>
|
||||
#endif
|
||||
|
||||
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
/*static void
|
||||
rs232_err(char err)
|
||||
{
|
||||
switch(err) {
|
||||
case RS_ERR_OK:
|
||||
printf("RS232 OK\n");
|
||||
break;
|
||||
case RS_ERR_NOT_INITIALIZED:
|
||||
printf("RS232 not initialized\n");
|
||||
break;
|
||||
case RS_ERR_BAUD_TOO_FAST:
|
||||
printf("RS232 baud too fast\n");
|
||||
break;
|
||||
case RS_ERR_BAUD_NOT_AVAIL:
|
||||
printf("RS232 baud rate not available\n");
|
||||
break;
|
||||
case RS_ERR_NO_DATA:
|
||||
printf("RS232 nothing to read\n");
|
||||
break;
|
||||
case RS_ERR_OVERFLOW:
|
||||
printf("RS232 overflow\n");
|
||||
break;
|
||||
}
|
||||
}*/
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
/*
|
||||
* rs232dev_send():
|
||||
*
|
||||
* Sends the packet in the uip_buf and uip_appdata buffers. The first
|
||||
* 40 bytes of the packet (the IP and TCP headers) are read from the
|
||||
* uip_buf buffer, and the following bytes (the application data) are
|
||||
* read from the uip_appdata buffer.
|
||||
*
|
||||
*/
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
void
|
||||
rs232dev_send(void)
|
||||
{
|
||||
u16_t i;
|
||||
u8_t *ptr;
|
||||
u8_t c;
|
||||
|
||||
SIO_SEND(SLIP_END);
|
||||
|
||||
ptr = &uip_buf[UIP_LLH_LEN];
|
||||
for(i = 0; i < uip_len; ++i) {
|
||||
if(i == UIP_TCPIP_HLEN) {
|
||||
ptr = uip_appdata;
|
||||
}
|
||||
c = *ptr++;
|
||||
switch(c) {
|
||||
case SLIP_END:
|
||||
SIO_SEND(SLIP_ESC);
|
||||
SIO_SEND(SLIP_ESC_END);
|
||||
break;
|
||||
case SLIP_ESC:
|
||||
SIO_SEND(SLIP_ESC);
|
||||
SIO_SEND(SLIP_ESC_ESC);
|
||||
break;
|
||||
default:
|
||||
SIO_SEND(c);
|
||||
break;
|
||||
}
|
||||
}
|
||||
SIO_SEND(SLIP_END);
|
||||
}
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
/*
|
||||
* rs232dev_poll():
|
||||
*
|
||||
* Read all avaliable bytes from the RS232 interface into the slip_buf
|
||||
* buffer. If no more bytes are avaliable, it returns with 0 to
|
||||
* indicate that no packet was immediately ready. When a full packet
|
||||
* has been read into the buffer, the packet is copied into the
|
||||
* uip_buf buffer and the length of the packet is returned.
|
||||
*
|
||||
*/
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
u16_t
|
||||
rs232dev_poll(void)
|
||||
{
|
||||
u8_t c;
|
||||
static u8_t lastc;
|
||||
|
||||
if(loaded == 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
while(SIO_POLL(c)) {
|
||||
|
||||
switch(c) {
|
||||
case SLIP_ESC:
|
||||
lastc = c;
|
||||
break;
|
||||
|
||||
case SLIP_END:
|
||||
lastc = c;
|
||||
/* End marker found, we copy our input buffer to the uip_buf
|
||||
buffer and return the size of the packet we copied. */
|
||||
memcpy(&uip_buf[UIP_LLH_LEN], slip_buf, len);
|
||||
tmplen = len;
|
||||
len = 0;
|
||||
return tmplen;
|
||||
|
||||
default:
|
||||
if(lastc == SLIP_ESC) {
|
||||
lastc = c;
|
||||
/* Previous read byte was an escape byte, so this byte will be
|
||||
interpreted differently from others. */
|
||||
switch(c) {
|
||||
case SLIP_ESC_END:
|
||||
c = SLIP_END;
|
||||
break;
|
||||
case SLIP_ESC_ESC:
|
||||
c = SLIP_ESC;
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
lastc = c;
|
||||
}
|
||||
|
||||
slip_buf[len] = c;
|
||||
++len;
|
||||
|
||||
if(len > MAX_SIZE) {
|
||||
len = 0;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
/*
|
||||
* rs232dev_init():
|
||||
*
|
||||
* Initializes the RS232 device and sets the parameters of the device.
|
||||
*
|
||||
*/
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
void
|
||||
rs232dev_init(void)
|
||||
{
|
||||
char err;
|
||||
struct ser_params p;
|
||||
|
||||
err = ser_load_driver("c64-swlink.ser");
|
||||
|
||||
if(err != SER_ERR_OK) {
|
||||
asm("inc $d020");
|
||||
return;
|
||||
}
|
||||
|
||||
p.baudrate = SER_BAUD_9600;
|
||||
p.databits = SER_BITS_8;
|
||||
p.stopbits = SER_STOP_1;
|
||||
p.parity = SER_PAR_NONE;
|
||||
p.handshake = SER_HS_HW;
|
||||
|
||||
err = ser_open(&p);
|
||||
|
||||
if(err != SER_ERR_OK) {
|
||||
asm("inc $d020");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
loaded = 1;
|
||||
|
||||
/* err = rs232_init(0); */
|
||||
/* rs232_err(err);*/
|
||||
/* err = rs232_params(RS_BAUD_9600 | RS_BITS_8 | RS_STOP_1, RS_PAR_NONE);*/
|
||||
/* rs232_err(err);*/
|
||||
|
||||
len = 0;
|
||||
|
||||
return;
|
||||
}
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
void
|
||||
rs232dev_unload(void)
|
||||
{
|
||||
if(loaded){
|
||||
ser_unload();
|
||||
}
|
||||
}
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
|
|
@ -1,48 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2001, Adam Dunkels.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. 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.
|
||||
* 3. The name of the author may not be used to endorse or promote
|
||||
* products derived from this software without specific prior
|
||||
* written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
||||
*
|
||||
* This file is part of the uIP TCP/IP stack.
|
||||
*
|
||||
* $Id: rs232dev.h,v 1.1 2007/11/19 23:00:56 oliverschmidt Exp $
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef __RS232DEV_H__
|
||||
#define __RS232DEV_H__
|
||||
|
||||
#include "net/uip.h"
|
||||
|
||||
void rs232dev_init(void);
|
||||
u8_t rs232dev_read(void);
|
||||
void rs232dev_send(void);
|
||||
|
||||
u16_t rs232dev_poll(void);
|
||||
|
||||
void rs232dev_unload(void);
|
||||
|
||||
#endif /* __RS232DEV_H__ */
|
|
@ -1,81 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2004, Adam Dunkels.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. 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.
|
||||
* 3. The name of the author may not be used to endorse or promote
|
||||
* products derived from this software without specific prior
|
||||
* written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
||||
*
|
||||
* This file is part of the Contiki OS
|
||||
*
|
||||
* $Id: slip-drv.c,v 1.1 2007/11/19 23:00:56 oliverschmidt Exp $
|
||||
*
|
||||
*/
|
||||
|
||||
#include "contiki-net.h"
|
||||
#include "rs232dev.h"
|
||||
|
||||
static u8_t output(void);
|
||||
|
||||
SERVICE(slip_drv_service, packet_service, { output };);
|
||||
|
||||
PROCESS(slip_drv_process, "SLIP driver");
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static u8_t
|
||||
output(void)
|
||||
{
|
||||
rs232dev_send();
|
||||
return 0;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
pollhandler(void)
|
||||
{
|
||||
uip_len = rs232dev_poll();
|
||||
if(uip_len > 0) {
|
||||
tcpip_input();
|
||||
}
|
||||
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
PROCESS_THREAD(slip_drv_process, ev, data)
|
||||
{
|
||||
PROCESS_POLLHANDLER(pollhandler());
|
||||
PROCESS_EXITHANDLER(rs232dev_unload());
|
||||
|
||||
PROCESS_BEGIN();
|
||||
|
||||
rs232dev_init();
|
||||
|
||||
SERVICE_REGISTER(slip_drv_service);
|
||||
|
||||
process_poll(&slip_drv_process);
|
||||
|
||||
while(1) {
|
||||
PROCESS_YIELD();
|
||||
}
|
||||
|
||||
PROCESS_END();
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
|
@ -1,71 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2003, Adam Dunkels.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. 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.
|
||||
* 3. The name of the author may not be used to endorse or promote
|
||||
* products derived from this software without specific prior
|
||||
* written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
||||
*
|
||||
* This file is part of the Contiki desktop environment
|
||||
*
|
||||
* $Id: slip-dsc.c,v 1.1 2007/11/19 23:00:56 oliverschmidt Exp $
|
||||
*
|
||||
*/
|
||||
|
||||
#include "sys/dsc.h"
|
||||
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
#if CTK_CONF_ICON_BITMAPS
|
||||
static unsigned char slipicon_bitmap[3*3*8] = {
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
||||
};
|
||||
#endif /* CTK_CONF_ICON_BITMAPS */
|
||||
|
||||
#if CTK_CONF_ICON_TEXTMAPS
|
||||
static char slipicon_textmap[9] = {
|
||||
'R', 'S', ' ',
|
||||
'2', '3', '2',
|
||||
'/', 'I', 'P'
|
||||
};
|
||||
#endif /* CTK_CONF_ICON_TEXTMAPS */
|
||||
|
||||
#if CTK_CONF_ICONS
|
||||
static struct ctk_icon slip_icon =
|
||||
{CTK_ICON("SLIP driver", slipicon_bitmap, slipicon_textmap)};
|
||||
#endif /* CTK_CONF_ICONS */
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
DSC(slip_dsc,
|
||||
"SLIP driver",
|
||||
"slip.drv",
|
||||
slip_init,
|
||||
&slip_icon);
|
||||
/*-----------------------------------------------------------------------------------*/
|
|
@ -1,120 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2004, Adam Dunkels.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. 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.
|
||||
* 3. The name of the author may not be used to endorse or promote
|
||||
* products derived from this software without specific prior
|
||||
* written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
||||
*
|
||||
* This file is part of the Contiki OS
|
||||
*
|
||||
* $Id: slip-dump-drv.c,v 1.1 2007/11/19 23:00:56 oliverschmidt Exp $
|
||||
*
|
||||
*/
|
||||
|
||||
#include "contiki.h"
|
||||
#include "rs232dev.h"
|
||||
|
||||
#include "packet-service.h"
|
||||
|
||||
#include "tcpdump.h"
|
||||
#include <string.h>
|
||||
#include "ctk/ctk.h"
|
||||
|
||||
static void output(u8_t *hdr, u16_t hdrlen, u8_t *data, u16_t datalen);
|
||||
|
||||
static const struct packet_service_state state =
|
||||
{
|
||||
PACKET_SERVICE_VERSION,
|
||||
output
|
||||
};
|
||||
|
||||
EK_EVENTHANDLER(eventhandler, ev, data);
|
||||
EK_POLLHANDLER(pollhandler);
|
||||
EK_PROCESS(proc, PACKET_SERVICE_NAME ": SLIP", EK_PRIO_HIGH,
|
||||
eventhandler, pollhandler, (void *)&state);
|
||||
|
||||
#define DUMP_WIDTH 38
|
||||
#define DUMP_HEIGHT 20
|
||||
static struct ctk_window window;
|
||||
static char dump[DUMP_WIDTH * DUMP_HEIGHT];
|
||||
static struct ctk_label dumplabel =
|
||||
{CTK_LABEL(0, 0, DUMP_WIDTH, DUMP_HEIGHT, dump)};
|
||||
static void
|
||||
dump_packet(void)
|
||||
{
|
||||
memcpy(dump, &dump[DUMP_WIDTH], DUMP_WIDTH * (DUMP_HEIGHT - 1));
|
||||
tcpdump_print(&dump[DUMP_WIDTH * (DUMP_HEIGHT - 1)], DUMP_WIDTH);
|
||||
CTK_WIDGET_REDRAW(&dumplabel);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
LOADER_INIT_FUNC(slip_service_init, arg)
|
||||
{
|
||||
arg_free(arg);
|
||||
ek_service_start(PACKET_SERVICE_NAME, &proc);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
output(u8_t *hdr, u16_t hdrlen, u8_t *data, u16_t datalen)
|
||||
{
|
||||
rs232dev_send();
|
||||
dump_packet();
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
EK_EVENTHANDLER(eventhandler, ev, data)
|
||||
{
|
||||
switch(ev) {
|
||||
case EK_EVENT_INIT:
|
||||
case EK_EVENT_REPLACE:
|
||||
ctk_window_new(&window, DUMP_WIDTH, DUMP_HEIGHT, "SLIP dump");
|
||||
CTK_WIDGET_ADD(&window, &dumplabel);
|
||||
ctk_window_open(&window);
|
||||
rs232dev_init();
|
||||
break;
|
||||
case EK_EVENT_REQUEST_REPLACE:
|
||||
ctk_window_close(&window);
|
||||
ek_replace((struct ek_proc *)data, NULL);
|
||||
rs232dev_unload();
|
||||
LOADER_UNLOAD();
|
||||
break;
|
||||
case EK_EVENT_REQUEST_EXIT:
|
||||
ctk_window_close(&window);
|
||||
ek_exit();
|
||||
rs232dev_unload();
|
||||
LOADER_UNLOAD();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
EK_POLLHANDLER(pollhandler)
|
||||
{
|
||||
uip_len = rs232dev_poll();
|
||||
if(uip_len > 0) {
|
||||
dump_packet();
|
||||
tcpip_input();
|
||||
}
|
||||
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
|
@ -1,160 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2003, Adam Dunkels.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. 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.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by Adam Dunkels.
|
||||
* 4. The name of the author may not be used to endorse or promote
|
||||
* products derived from this software without specific prior
|
||||
* written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
||||
*
|
||||
* This file is part of the uIP TCP/IP stack.
|
||||
*
|
||||
* $Id: rtl8019as-drv.c,v 1.2 2010/10/19 18:29:03 adamdunkels Exp $
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
/* uip_main.c: initialization code and main event loop. */
|
||||
|
||||
#define NULL (void *)0
|
||||
|
||||
|
||||
|
||||
#include "uip.h"
|
||||
#include "uip_arp.h"
|
||||
#include "uip-signal.h"
|
||||
#include "loader.h"
|
||||
#include "rtl8019dev.h"
|
||||
|
||||
#include "dispatcher.h"
|
||||
#include "ek.h"
|
||||
|
||||
#include "debug.h"
|
||||
|
||||
#define BUF ((struct uip_eth_hdr *)&uip_buf[0])
|
||||
|
||||
static u8_t i, arptimer;
|
||||
static u16_t start, current;
|
||||
|
||||
static void rtl8019_drv_idle(void);
|
||||
static DISPATCHER_SIGHANDLER(rtl8019_drv_sighandler, s, data);
|
||||
static struct dispatcher_proc p =
|
||||
{DISPATCHER_PROC("TCP/IP/RTL8019 driver", rtl8019_drv_idle,
|
||||
rtl8019_drv_sighandler, NULL)};
|
||||
ek_id_t id = EK_ID_NONE;
|
||||
|
||||
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
static void
|
||||
timer(void)
|
||||
{
|
||||
for(i = 0; i < UIP_CONNS; ++i) {
|
||||
uip_periodic(i);
|
||||
if(uip_len > 0) {
|
||||
uip_arp_out();
|
||||
rtl8019as_send();
|
||||
}
|
||||
}
|
||||
|
||||
for(i = 0; i < UIP_UDP_CONNS; i++) {
|
||||
uip_udp_periodic(i);
|
||||
/* If the above function invocation resulted in data that
|
||||
should be sent out on the network, the global variable
|
||||
uip_len is set to a value > 0. */
|
||||
if(uip_len > 0) {
|
||||
uip_arp_out();
|
||||
rtl8019as_send();
|
||||
}
|
||||
}
|
||||
}
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
static void
|
||||
rtl8019_drv_idle(void)
|
||||
{
|
||||
/* Poll Ethernet device to see if there is a frame avaliable. */
|
||||
uip_len = rtl8019as_poll();
|
||||
if(uip_len > 0) {
|
||||
/* A frame was avaliable (and is now read into the uip_buf), so
|
||||
we process it. */
|
||||
if(BUF->type == uip_htons(UIP_ETHTYPE_IP)) {
|
||||
/* debug_print16(uip_len);*/
|
||||
uip_arp_ipin();
|
||||
uip_len -= sizeof(struct uip_eth_hdr);
|
||||
uip_input();
|
||||
/* If the above function invocation resulted in data that
|
||||
should be sent out on the network, the global variable
|
||||
uip_len is set to a value > 0. */
|
||||
if(uip_len > 0) {
|
||||
/* debug_print(PSTR("Sending packet\n"));*/
|
||||
uip_arp_out();
|
||||
rtl8019as_send();
|
||||
}
|
||||
} else if(BUF->type == uip_htons(UIP_ETHTYPE_ARP)) {
|
||||
uip_arp_arpin();
|
||||
/* If the above function invocation resulted in data that
|
||||
should be sent out on the network, the global variable
|
||||
uip_len is set to a value > 0. */
|
||||
if(uip_len > 0) {
|
||||
rtl8019as_send();
|
||||
}
|
||||
}
|
||||
}
|
||||
/* Check the clock so see if we should call the periodic uIP
|
||||
processing. */
|
||||
current = ek_clock();
|
||||
|
||||
if((current - start) >= CLK_TCK/2 ||
|
||||
(current - start) < 0) {
|
||||
timer();
|
||||
start = current;
|
||||
}
|
||||
}
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
LOADER_INIT_FUNC(rtl8019_drv_init)
|
||||
{
|
||||
if(id == EK_ID_NONE) {
|
||||
id = dispatcher_start(&p);
|
||||
|
||||
arptimer = 0;
|
||||
start = ek_clock();
|
||||
|
||||
rtl8019as_init();
|
||||
|
||||
dispatcher_listen(uip_signal_uninstall);
|
||||
}
|
||||
}
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
static
|
||||
DISPATCHER_SIGHANDLER(rtl8019_drv_sighandler, s, data)
|
||||
{
|
||||
DISPATCHER_SIGHANDLER_ARGS(s, data);
|
||||
|
||||
if(s == uip_signal_uninstall) {
|
||||
dispatcher_exit(&p);
|
||||
id = EK_ID_NONE;
|
||||
LOADER_UNLOAD();
|
||||
}
|
||||
}
|
||||
/*-----------------------------------------------------------------------------------*/
|
|
@ -1,51 +0,0 @@
|
|||
;
|
||||
; Copyright (c) 2007, Swedish Institute of Computer Science.
|
||||
; All rights reserved.
|
||||
;
|
||||
; Redistribution and use in source and binary forms, with or without
|
||||
; modification, are permitted provided that the following conditions
|
||||
; are met:
|
||||
; 1. Redistributions of source code must retain the above copyright
|
||||
; notice, this list of conditions and the following disclaimer.
|
||||
; 2. 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.
|
||||
; 3. Neither the name of the Institute 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 INSTITUTE 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 INSTITUTE 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.
|
||||
;
|
||||
; This file is part of the Contiki operating system.
|
||||
;
|
||||
; Author: Oliver Schmidt <ol.sc@web.de>
|
||||
;
|
||||
; $Id: log-asm.S,v 1.1 2010/02/10 07:43:25 oliverschmidt Exp $
|
||||
;
|
||||
;---------------------------------------------------------------------
|
||||
.importzp ptr1
|
||||
.import COUT
|
||||
.export _log_write
|
||||
;---------------------------------------------------------------------
|
||||
_log_write:
|
||||
sta ptr1
|
||||
stx ptr1+1
|
||||
ldy #$00
|
||||
: lda (ptr1),y
|
||||
bne :+
|
||||
rts
|
||||
: ora #$80
|
||||
jsr COUT
|
||||
iny
|
||||
bne :--
|
||||
;---------------------------------------------------------------------
|
|
@ -1,60 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2007, Swedish Institute of Computer Science.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. 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.
|
||||
* 3. Neither the name of the Institute 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 INSTITUTE 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 INSTITUTE 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.
|
||||
*
|
||||
* This file is part of the Contiki operating system.
|
||||
*
|
||||
* Author: Oliver Schmidt <ol.sc@web.de>
|
||||
*
|
||||
* $Id: log.c,v 1.1 2010/02/10 07:43:25 oliverschmidt Exp $
|
||||
*/
|
||||
|
||||
#include "net/uip.h"
|
||||
#include "sys/log.h"
|
||||
|
||||
void __fastcall__ log_write(const char *message);
|
||||
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
#if UIP_LOGGING
|
||||
void
|
||||
uip_log(char *message)
|
||||
{
|
||||
log_write(message);
|
||||
log_write("\r");
|
||||
}
|
||||
#endif /* UIP_LOGGING */
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
#if LOG_CONF_ENABLED
|
||||
void
|
||||
log_message(const char *part1, const char *part2)
|
||||
{
|
||||
log_write(part1);
|
||||
log_write(part2);
|
||||
log_write("\r");
|
||||
}
|
||||
#endif /* LOG_CONF_ENABLED */
|
||||
/*-----------------------------------------------------------------------------------*/
|
|
@ -1,77 +0,0 @@
|
|||
# Copyright (c) 2002, Adam Dunkels.
|
||||
# All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
# modification, are permitted provided that the following conditions
|
||||
# are met:
|
||||
# 1. Redistributions of source code must retain the above copyright
|
||||
# notice, this list of conditions and the following disclaimer.
|
||||
# 2. 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.
|
||||
# 3. The name of the author may not be used to endorse or promote
|
||||
# products derived from this software without specific prior
|
||||
# written permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
||||
#
|
||||
# This file is part of the Contiki desktop environment
|
||||
#
|
||||
# $Id: Makefile,v 1.1 2007/05/23 23:11:23 oliverschmidt Exp $
|
||||
#
|
||||
|
||||
CONTIKI=../..
|
||||
CONTIKICC65=../../cpu/6502
|
||||
|
||||
usage:
|
||||
@echo "Make sure the Contiki sources is in the directory $(CONTIKI)"
|
||||
@echo 'To compile Contiki, use "'$(MAKE)' target" where target'
|
||||
@echo 'is one of the following:'
|
||||
@echo all
|
||||
@echo c64
|
||||
@echo programs
|
||||
@echo d64
|
||||
@echo programs
|
||||
@echo '(Also check the Makefile for more targets to try...)'
|
||||
|
||||
all: clean c64 programs
|
||||
|
||||
programs:
|
||||
$(MAKE) CONTIKI=$(CONTIKI) CONTIKICC65=$(CONTIKICC65) -f Makefile.programs
|
||||
c64:
|
||||
$(MAKE) CONTIKI=$(CONTIKI) CONTIKICC65=$(CONTIKICC65) -f Makefile.c64
|
||||
|
||||
c64-exo:
|
||||
$(MAKE) CONTIKI=$(CONTIKI) CONTIKICC65=$(CONTIKICC65) -f Makefile.c64 contiki-exo
|
||||
|
||||
wget:
|
||||
$(MAKE) CONTIKI=$(CONTIKI) CONTIKICC65=$(CONTIKICC65) -f Makefile.c64-wget
|
||||
|
||||
installer: clean
|
||||
$(MAKE) CONTIKI=$(CONTIKI) CONTIKICC65=$(CONTIKICC65) -f Makefile.installer
|
||||
|
||||
|
||||
CCDEPFLAGS=-D__CBM__ -D__C64__ -DCTK_HIRES -DWITH_UIP -DWITH_LOADER_ARCH -I/usr/local/lib/cc65/include
|
||||
|
||||
include $(CONTIKICC65)/Makefile.cc65
|
||||
|
||||
d64:
|
||||
c1541 -format contiki,00 d64 contiki.d64
|
||||
c1541 -attach contiki.d64 -write contiki
|
||||
c1541 -attach contiki.d64 -write config.cfg
|
||||
c1541 -attach contiki.d64 $(foreach dsc, $(wildcard *.dsc), -write $(dsc))
|
||||
c1541 -attach contiki.d64 $(foreach prg, $(wildcard *.prg), -write $(prg))
|
||||
c1541 -attach contiki.d64 $(foreach sav, $(wildcard *.sav), -write $(sav))
|
||||
c1541 -attach contiki.d64 $(foreach drv, $(wildcard *.drv), -write $(drv))
|
||||
c1541 -attach contiki.d64 $(foreach ser, $(wildcard *.ser), -write $(ser))
|
||||
c1541 -attach contiki.d64 -list
|
|
@ -1,73 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2003, Adam Dunkels.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. 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.
|
||||
* 3. The name of the author may not be used to endorse or promote
|
||||
* products derived from this software without specific prior
|
||||
* written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
||||
*
|
||||
* This file is part of the Contiki desktop environment
|
||||
*
|
||||
* $Id: blueround-dsc.c,v 1.2 2007/09/06 01:36:11 matsutsuka Exp $
|
||||
*
|
||||
*/
|
||||
|
||||
#include "sys/dsc.h"
|
||||
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
#if CTK_CONF_ICON_BITMAPS
|
||||
static unsigned char blueroundicon_bitmap[3*3*8] = {
|
||||
0xfe,0xf8,0xe0,0xc0,0xc0,0x80,0x80,0x00,
|
||||
0x00,0x55,0xaa,0x00,0xaa,0x00,0x00,0x00,
|
||||
0x7f,0x1f,0x07,0x03,0x03,0x01,0x01,0x00,
|
||||
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
||||
|
||||
0x00,0x80,0x80,0xc0,0xc0,0xe0,0xf8,0xfe,
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
||||
0x00,0x01,0x01,0x03,0x03,0x07,0x1f,0x7f
|
||||
};
|
||||
#endif /* CTK_CONF_ICON_BITMAPS */
|
||||
|
||||
#if CTK_CONF_ICON_TEXTMAPS
|
||||
static char blueroundicon_textmap[9] = {
|
||||
'(', '=', ')',
|
||||
'|', 'o', '|',
|
||||
'(', '-', ')'
|
||||
};
|
||||
#endif /* CTK_CONF_ICON_TEXTMAPS */
|
||||
|
||||
#if CTK_CONF_ICONS
|
||||
static struct ctk_icon blueround_icon =
|
||||
{CTK_ICON("Blueround", blueroundicon_bitmap, blueroundicon_textmap)};
|
||||
#endif /* CTK_CONF_ICONS */
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
DSC(blueround_dsc,
|
||||
"Blueround CTK theme",
|
||||
"blueround.prg",
|
||||
blueround_init,
|
||||
&blueround_icon);
|
||||
/*-----------------------------------------------------------------------------------*/
|
|
@ -1,73 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2003, Adam Dunkels.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. 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.
|
||||
* 3. The name of the author may not be used to endorse or promote
|
||||
* products derived from this software without specific prior
|
||||
* written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
||||
*
|
||||
* This file is part of the Contiki desktop environment
|
||||
*
|
||||
* $Id: cgterm-dsc.c,v 1.2 2007/09/06 01:36:11 matsutsuka Exp $
|
||||
*
|
||||
*/
|
||||
|
||||
#include "sys/dsc.h"
|
||||
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
#if CTK_CONF_ICON_BITMAPS
|
||||
static unsigned char cgtermicon_bitmap[3*3*8] = {
|
||||
0x00, 0x7e, 0x40, 0x73, 0x46, 0x4c, 0x18, 0x13,
|
||||
0x00, 0x00, 0xff, 0x81, 0x34, 0xc9, 0x00, 0xb6,
|
||||
0x00, 0x7e, 0x02, 0xce, 0x72, 0x32, 0x18, 0x48,
|
||||
|
||||
0x30, 0x27, 0x24, 0x20, 0x37, 0x24, 0x20, 0x33,
|
||||
0x00, 0x7b, 0x42, 0x00, 0x7b, 0x42, 0x00, 0x3b,
|
||||
0x0c, 0x24, 0x24, 0x04, 0xa4, 0x24, 0x04, 0x4c,
|
||||
|
||||
0x12, 0x19, 0x4c, 0x46, 0x63, 0x40, 0x7c, 0x00,
|
||||
0x22, 0x91, 0x00, 0xc4, 0x81, 0xff, 0x00, 0x00,
|
||||
0x08, 0x18, 0x32, 0x62, 0xc6, 0x02, 0x3e, 0x00
|
||||
};
|
||||
#endif /* CTK_CONF_ICON_BITMAPS */
|
||||
|
||||
#if CTK_CONF_ICON_TEXTMAPS
|
||||
static char cgtermicon_textmap[9] = {
|
||||
'T', 'e', 'l',
|
||||
'n', 'e', 't',
|
||||
'B', 'B', 'S'
|
||||
};
|
||||
#endif /* CTK_CONF_ICON_TEXTMAPS */
|
||||
|
||||
#if CTK_CONF_ICONS
|
||||
static struct ctk_icon cgterm_icon =
|
||||
{CTK_ICON("C/G terminal", cgtermicon_bitmap, cgtermicon_textmap)};
|
||||
#endif /* CTK_CONF_ICONS */
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
DSC(cgterm_dsc,
|
||||
"Program for connecting to C64 Telnet BBSes",
|
||||
"cgterm.prg",
|
||||
cgterm_init,
|
||||
&cgterm_icon);
|
||||
/*-----------------------------------------------------------------------------------*/
|
|
@ -1,242 +0,0 @@
|
|||
#include "contiki-net.h"
|
||||
#include "ctk/ctk-draw.h"
|
||||
|
||||
#include <cbm.h>
|
||||
#include <c64.h>
|
||||
#include <string.h>
|
||||
|
||||
static struct {
|
||||
struct psock sout, sin;
|
||||
struct pt inpt, outpt;
|
||||
char outputbuf[200];
|
||||
char inputbuf[200];
|
||||
unsigned short len;
|
||||
} s;
|
||||
|
||||
#define CURSOR_ON() *(char *)0xcc = 0
|
||||
#define CURSOR_OFF() *(char *)0xcc = 1
|
||||
static void ctkmode(void);
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static
|
||||
PT_THREAD(send(void))
|
||||
{
|
||||
PSOCK_BEGIN(&s.sout);
|
||||
|
||||
PSOCK_SEND(&s.sout, s.outputbuf, s.len);
|
||||
PSOCK_END(&s.sout);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static
|
||||
PT_THREAD(handle_output(void))
|
||||
{
|
||||
ctk_arch_key_t c;
|
||||
char *ptr;
|
||||
|
||||
PT_BEGIN(&s.outpt);
|
||||
|
||||
while(1) {
|
||||
PT_WAIT_UNTIL(&s.outpt, (ctk_mode_get() == CTK_MODE_EXTERNAL) &&
|
||||
kbhit());
|
||||
|
||||
|
||||
ptr = s.outputbuf;
|
||||
s.len = 0;
|
||||
while(kbhit() && s.len < sizeof(s.outputbuf)) {
|
||||
c = cgetc();
|
||||
*ptr = c;
|
||||
++ptr;
|
||||
++s.len;
|
||||
}
|
||||
|
||||
PT_WAIT_THREAD(&s.outpt, send());
|
||||
}
|
||||
PT_END(&s.outpt);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static
|
||||
PT_THREAD(handle_input(void))
|
||||
{
|
||||
unsigned short i;
|
||||
char *ptr;
|
||||
char next;
|
||||
|
||||
next = 1;
|
||||
PT_BEGIN(&s.inpt);
|
||||
|
||||
while(1) {
|
||||
/* Wait until data arrives. */
|
||||
next = 0;
|
||||
PT_WAIT_UNTIL(&s.inpt, next && uip_newdata());
|
||||
|
||||
CURSOR_OFF();
|
||||
/* Print it out on the screen. */
|
||||
ptr = (char *)uip_appdata;
|
||||
for(i = 0; i < uip_len; ++i) {
|
||||
cbm_k_bsout(*ptr);
|
||||
++ptr;
|
||||
}
|
||||
CURSOR_ON();
|
||||
}
|
||||
PT_END(&s.inpt);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
appcall(void *state)
|
||||
{
|
||||
if(uip_closed() || uip_aborted() || uip_timedout()) {
|
||||
ctkmode();
|
||||
} else if(uip_connected()) {
|
||||
} else {
|
||||
handle_input();
|
||||
handle_output();
|
||||
}
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static struct uip_conn *
|
||||
connect(u16_t *host, u16_t port)
|
||||
{
|
||||
PSOCK_INIT(&s.sin, s.inputbuf, sizeof(s.inputbuf));
|
||||
PSOCK_INIT(&s.sout, s.inputbuf, sizeof(s.inputbuf));
|
||||
PT_INIT(&s.inpt);
|
||||
PT_INIT(&s.outpt);
|
||||
return tcp_connect(host, uip_htons(port), NULL);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
PROCESS(cgterm_process, "C/G terminal");
|
||||
|
||||
static struct uip_conn *conn;
|
||||
static u16_t serveraddr[2];
|
||||
static u16_t serverport;
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static struct ctk_window window;
|
||||
static struct ctk_label hostlabel =
|
||||
{CTK_LABEL(0, 0, 4, 1, "Host")};
|
||||
static char host[32];
|
||||
static struct ctk_textentry hostentry =
|
||||
{CTK_TEXTENTRY(5, 0, 20, 1, host, sizeof(host) - 1)};
|
||||
static struct ctk_label portlabel =
|
||||
{CTK_LABEL(27, 0, 4, 1, "Port")};
|
||||
static char port[7];
|
||||
static struct ctk_textentry portentry =
|
||||
{CTK_TEXTENTRY(32, 0, 4, 1, port, sizeof(port) - 1)};
|
||||
static struct ctk_button connectbutton =
|
||||
{CTK_BUTTON(0, 2, 7, "Connect")};
|
||||
static struct ctk_button switchbutton =
|
||||
{CTK_BUTTON(30, 2, 6, "Switch")};
|
||||
static struct ctk_label helplabel =
|
||||
{CTK_LABEL(0, 4, 37, 1, "RUN/STOP to return from terminal view")};
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
ctkmode(void)
|
||||
{
|
||||
ctk_mode_set(CTK_MODE_NORMAL);
|
||||
ctk_draw_init();
|
||||
ctk_desktop_redraw(NULL);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
textmode(void)
|
||||
{
|
||||
ctk_mode_set(CTK_MODE_EXTERNAL);
|
||||
|
||||
VIC.ctrl1 = 0x1b; /* $D011 */
|
||||
VIC.addr = 0x17; /* $D018 */
|
||||
VIC.ctrl2 = 0xc8; /* $D016 */
|
||||
CIA2.pra = 0x03; /* $DD00 */
|
||||
|
||||
VIC.bordercolor = 0x00; /* $D020 */
|
||||
VIC.bgcolor0 = 0x00; /* $D021 */
|
||||
|
||||
CURSOR_ON();
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
pollhandler(void)
|
||||
{
|
||||
if(ctk_mode_get() == CTK_MODE_EXTERNAL) {
|
||||
if(CIA1.prb == 0x7f) {
|
||||
ctkmode();
|
||||
} else if(kbhit() && conn != NULL) {
|
||||
tcpip_poll_tcp(conn);
|
||||
}
|
||||
}
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
PROCESS_THREAD(cgterm_process, ev, data)
|
||||
{
|
||||
u16_t *ipaddr;
|
||||
char *cptr;
|
||||
|
||||
PROCESS_POLLHANDLER(pollhandler());
|
||||
|
||||
PROCESS_BEGIN();
|
||||
|
||||
ctk_window_new(&window, 38, 5, "C/G term");
|
||||
CTK_WIDGET_ADD(&window, &hostlabel);
|
||||
CTK_WIDGET_ADD(&window, &hostentry);
|
||||
CTK_WIDGET_ADD(&window, &portlabel);
|
||||
CTK_WIDGET_ADD(&window, &portentry);
|
||||
CTK_WIDGET_ADD(&window, &connectbutton);
|
||||
CTK_WIDGET_ADD(&window, &switchbutton);
|
||||
CTK_WIDGET_ADD(&window, &helplabel);
|
||||
ctk_window_open(&window);
|
||||
|
||||
while(1) {
|
||||
PROCESS_WAIT_EVENT();
|
||||
|
||||
if(ev == tcpip_event) {
|
||||
appcall(data);
|
||||
} else if(ev == ctk_signal_widget_activate) {
|
||||
|
||||
if(data == &switchbutton) {
|
||||
textmode();
|
||||
} else if(data == &connectbutton) {
|
||||
serverport = 0;
|
||||
for(cptr = port; *cptr != ' ' && *cptr != 0; ++cptr) {
|
||||
if(*cptr < '0' || *cptr > '9') {
|
||||
continue;
|
||||
}
|
||||
serverport = 10 * serverport + *cptr - '0';
|
||||
}
|
||||
|
||||
ipaddr = serveraddr;
|
||||
if(uiplib_ipaddrconv(host, (u8_t *)serveraddr) == 0) {
|
||||
ipaddr = resolv_lookup(host);
|
||||
if(ipaddr == NULL) {
|
||||
resolv_query(host);
|
||||
} else {
|
||||
uip_ipaddr_copy(serveraddr, ipaddr);
|
||||
}
|
||||
}
|
||||
if(ipaddr != NULL) {
|
||||
conn = connect(serveraddr, serverport);
|
||||
if(conn != NULL) {
|
||||
memset((char *)0x0400, 0x20, 40*25);
|
||||
memset((char *)0xd800, 0x01, 40*25);
|
||||
textmode();
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if(ev == resolv_event_found) {
|
||||
ipaddr = resolv_lookup(host);
|
||||
if(ipaddr != NULL) {
|
||||
uip_ipaddr_copy(serveraddr, ipaddr);
|
||||
|
||||
conn = connect(serveraddr, serverport);
|
||||
if(conn != NULL) {
|
||||
memset((char *)0x0400, 0x20, 40*25);
|
||||
memset((char *)0xd800, 0x01, 40*25);
|
||||
textmode();
|
||||
}
|
||||
}
|
||||
} else if(ev == PROCESS_EVENT_EXIT ||
|
||||
ev == ctk_signal_window_close) {
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
ctk_window_close(&window);
|
||||
|
||||
PROCESS_END();
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
|
@ -1,241 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2003, Adam Dunkels.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. 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.
|
||||
* 3. The name of the author may not be used to endorse or promote
|
||||
* products derived from this software without specific prior
|
||||
* written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
||||
*
|
||||
* This file is part of the Contiki desktop OS.
|
||||
*
|
||||
* $Id: config.c,v 1.1 2007/05/23 23:11:24 oliverschmidt Exp $
|
||||
*
|
||||
*/
|
||||
|
||||
#include "program-handler.h"
|
||||
#include "contiki-net.h"
|
||||
#include "cfs/cfs.h"
|
||||
|
||||
struct ptentry {
|
||||
char c;
|
||||
char * (* pfunc)(char *str);
|
||||
};
|
||||
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
static char *
|
||||
parse(char *str, struct ptentry *t)
|
||||
{
|
||||
struct ptentry *p;
|
||||
|
||||
/* Loop over the parse table entries in t in order to find one that
|
||||
matches the first character in str. */
|
||||
for(p = t; p->c != 0; ++p) {
|
||||
if(*str == p->c) {
|
||||
/* Skip rest of the characters up to the first space. */
|
||||
while(*str != ' ') {
|
||||
++str;
|
||||
}
|
||||
|
||||
/* Skip all spaces.*/
|
||||
while(*str == ' ') {
|
||||
++str;
|
||||
}
|
||||
|
||||
/* Call parse table entry function and return. */
|
||||
return p->pfunc(str);
|
||||
}
|
||||
}
|
||||
|
||||
/* Did not find matching entry in parse table. We just call the
|
||||
default handler supplied by the caller and return. */
|
||||
return p->pfunc(str);
|
||||
}
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
static char *
|
||||
skipnewline(char *str)
|
||||
{
|
||||
/* Skip all characters until the newline. */
|
||||
while(*str != '\n') {
|
||||
++str;
|
||||
}
|
||||
|
||||
/* Return a pointer to the first character after the newline. */
|
||||
return str + 1;
|
||||
}
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
static char *
|
||||
nullterminate(char *str)
|
||||
{
|
||||
char *nt;
|
||||
|
||||
/* Nullterminate string. Start with finding newline character. */
|
||||
for(nt = str; *nt != '\r' &&
|
||||
*nt != '\n'; ++nt);
|
||||
|
||||
/* Replace newline with a null char. */
|
||||
*nt = 0;
|
||||
|
||||
/* Remove trailing spaces. */
|
||||
while(nt > str && *(nt - 1) == ' ') {
|
||||
*(nt - 1) = 0;
|
||||
--nt;
|
||||
}
|
||||
|
||||
/* Return pointer to null char. */
|
||||
return nt;
|
||||
}
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
static char *
|
||||
loadfile(char *str)
|
||||
{
|
||||
char *nt;
|
||||
|
||||
nt = nullterminate(str);
|
||||
|
||||
/* Call loader function. */
|
||||
program_handler_load(str, NULL);
|
||||
|
||||
return nt + 1;
|
||||
}
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
static char *
|
||||
screensaverconf(char *str)
|
||||
{
|
||||
char *nt;
|
||||
|
||||
nt = nullterminate(str);
|
||||
program_handler_setscreensaver(str);
|
||||
|
||||
return nt + 1;
|
||||
}
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
static u16_t addr[2];
|
||||
static char *
|
||||
ipaddrconf(char *str)
|
||||
{
|
||||
char *nt;
|
||||
|
||||
nt = nullterminate(str);
|
||||
if(uiplib_ipaddrconv(str, (unsigned char *)addr)) {
|
||||
uip_sethostaddr(addr);
|
||||
}
|
||||
|
||||
return nt + 1;
|
||||
}
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
static char *
|
||||
netmaskconf(char *str)
|
||||
{
|
||||
char *nt;
|
||||
|
||||
nt = nullterminate(str);
|
||||
if(uiplib_ipaddrconv(str, (unsigned char *)addr)) {
|
||||
uip_setnetmask(addr);
|
||||
}
|
||||
|
||||
return nt + 1;
|
||||
}
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
static char *
|
||||
drconf(char *str)
|
||||
{
|
||||
char *nt;
|
||||
|
||||
nt = nullterminate(str);
|
||||
if(uiplib_ipaddrconv(str, (unsigned char *)addr)) {
|
||||
uip_setdraddr(addr);
|
||||
}
|
||||
|
||||
return nt + 1;
|
||||
}
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
static char *
|
||||
dnsconf(char *str)
|
||||
{
|
||||
char *nt;
|
||||
|
||||
nt = nullterminate(str);
|
||||
if(uiplib_ipaddrconv(str, (unsigned char *)addr)) {
|
||||
resolv_conf(addr);
|
||||
}
|
||||
|
||||
return nt + 1;
|
||||
}
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
static struct ptentry configparsetab[] =
|
||||
{{'n', loadfile},
|
||||
{'t', loadfile},
|
||||
{'c', loadfile},
|
||||
{'s', screensaverconf},
|
||||
{'i', ipaddrconf},
|
||||
{'m', netmaskconf},
|
||||
{'r', drconf},
|
||||
{'d', dnsconf},
|
||||
{'#', skipnewline},
|
||||
|
||||
/* Default action */
|
||||
{0, skipnewline}};
|
||||
static void
|
||||
configscript(void)
|
||||
{
|
||||
static char line[40], *lineptr;
|
||||
/* static struct c64_fs_file f;*/
|
||||
int f;
|
||||
|
||||
if((f = cfs_open("config.cfg", 0)) == -1) {
|
||||
return;
|
||||
}
|
||||
|
||||
line[0] = ' ';
|
||||
while(line[0] != '.' &&
|
||||
line[0] != 0) {
|
||||
lineptr = line;
|
||||
do {
|
||||
if(cfs_read(f, lineptr, 1) != 1) {
|
||||
cfs_close(f);
|
||||
return;
|
||||
}
|
||||
++lineptr;
|
||||
} while(*(lineptr - 1) != '\n' &&
|
||||
*(lineptr - 1) != '\r');
|
||||
|
||||
*lineptr = 0;
|
||||
|
||||
if(line[0] != '.' &&
|
||||
line[0] != 0) {
|
||||
parse(line, configparsetab);
|
||||
}
|
||||
|
||||
}
|
||||
cfs_close(f);
|
||||
return;
|
||||
}
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
LOADER_INIT_FUNC(config_init, arg)
|
||||
{
|
||||
arg_free(arg);
|
||||
program_handler_setscreensaver(NULL);
|
||||
configscript();
|
||||
LOADER_UNLOAD();
|
||||
}
|
||||
/*-----------------------------------------------------------------------------------*/
|
|
@ -1,73 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2003, Adam Dunkels.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. 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.
|
||||
* 3. The name of the author may not be used to endorse or promote
|
||||
* products derived from this software without specific prior
|
||||
* written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
||||
*
|
||||
* This file is part of the Contiki desktop environment
|
||||
*
|
||||
* $Id: configedit-dsc.c,v 1.2 2007/09/06 01:36:11 matsutsuka Exp $
|
||||
*
|
||||
*/
|
||||
|
||||
#include "sys/dsc.h"
|
||||
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
#if CTK_CONF_ICON_BITMAPS
|
||||
static unsigned char tcpipconficon_bitmap[3*3*8] = {
|
||||
0x00, 0x79, 0x43, 0x73, 0x47, 0x77, 0x47, 0x6f,
|
||||
0x00, 0xfe, 0xfe, 0xfc, 0xfc, 0xfc, 0xf8, 0xfb,
|
||||
0x00, 0x16, 0x02, 0x00, 0x02, 0x00, 0x00, 0xc2,
|
||||
|
||||
0x48, 0x4c, 0x5f, 0x5f, 0x1f, 0x3f, 0x3f, 0x03,
|
||||
0x79, 0xf0, 0xf0, 0xf0, 0xe0, 0xe0, 0xfe, 0xfc,
|
||||
0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
|
||||
0x77, 0x47, 0x70, 0x43, 0x79, 0x41, 0x7c, 0x00,
|
||||
0xfc, 0xff, 0xfe, 0xff, 0xff, 0xff, 0xf7, 0x00,
|
||||
0x00, 0x80, 0x00, 0x00, 0x00, 0x84, 0xf0, 0x00
|
||||
};
|
||||
#endif /* CTK_CONF_ICON_BITMAPS */
|
||||
|
||||
#if CTK_CONF_ICON_TEXTMAPS
|
||||
static char tcpipconficon_textmap[9] = {
|
||||
'C', 'F', 'G',
|
||||
' ', ' ', ' ',
|
||||
'C', 'F', 'G'
|
||||
};
|
||||
#endif /* CTK_CONF_ICON_TEXTMAPS */
|
||||
|
||||
#if CTK_CONF_ICONS
|
||||
static struct ctk_icon configedit_icon =
|
||||
{CTK_ICON("Configuration", tcpipconficon_bitmap, tcpipconficon_textmap)};
|
||||
#endif /* CTK_CONF_ICONS */
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
DSC(configedit_dsc,
|
||||
"Edit Contiki configuration",
|
||||
"configedit.prg",
|
||||
configedit_init,
|
||||
&configedit_icon);
|
||||
/*-----------------------------------------------------------------------------------*/
|
|
@ -1,42 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2003, Adam Dunkels.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. 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.
|
||||
* 3. The name of the author may not be used to endorse or promote
|
||||
* products derived from this software without specific prior
|
||||
* written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
||||
*
|
||||
* This file is part of the Contiki desktop environment
|
||||
*
|
||||
* $Id: configedit-dsc.h,v 1.1 2007/05/23 23:11:24 oliverschmidt Exp $
|
||||
*
|
||||
*/
|
||||
#ifndef __CONFIGEDIT_DSC_H__
|
||||
#define __CONFIGEDIT_DSC_H__
|
||||
|
||||
#include "sys/dsc.h"
|
||||
|
||||
DSC_HEADER(configedit_dsc);
|
||||
|
||||
#endif /* __CONFIGEDIT_DSC_H__ */
|
|
@ -1,418 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2002, Adam Dunkels.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. 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.
|
||||
* 3. The name of the author may not be used to endorse or promote
|
||||
* products derived from this software without specific prior
|
||||
* written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
||||
*
|
||||
* This file is part of the Contiki desktop environment
|
||||
*
|
||||
* $Id: configedit.c,v 1.1 2007/05/23 23:11:24 oliverschmidt Exp $
|
||||
*
|
||||
*/
|
||||
|
||||
#include "contiki.h"
|
||||
#include "contiki-net.h"
|
||||
|
||||
#include "ctk/ctk-draw-service.h"
|
||||
#include "net/packet-service.h"
|
||||
|
||||
#include "ctk/ctk.h"
|
||||
#include "ctk/ctk-draw.h"
|
||||
|
||||
#include "program-handler.h"
|
||||
|
||||
#include "cfs/cfs.h"
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include <string.h>
|
||||
|
||||
/* TCP/IP configuration window. */
|
||||
static struct ctk_window window;
|
||||
|
||||
#define LABELMAXWIDTH 12
|
||||
|
||||
static struct ctk_label cfslabel =
|
||||
{CTK_LABEL(0, 1, LABELMAXWIDTH, 1, "Disk driver")};
|
||||
static char cfs[25];
|
||||
static struct ctk_textentry cfstextentry =
|
||||
{CTK_TEXTENTRY(LABELMAXWIDTH + 1, 1, 16, 1, cfs, 24)};
|
||||
|
||||
static struct ctk_label themelabel =
|
||||
{CTK_LABEL(0, 3, LABELMAXWIDTH, 1, "CTK theme")};
|
||||
static char theme[25];
|
||||
static struct ctk_textentry themetextentry =
|
||||
{CTK_TEXTENTRY(LABELMAXWIDTH + 1, 3, 16, 1, theme, 24)};
|
||||
|
||||
static struct ctk_label driverlabel =
|
||||
{CTK_LABEL(0, 5, LABELMAXWIDTH, 1, "Net driver")};
|
||||
static char driver[25];
|
||||
static struct ctk_textentry drivertextentry =
|
||||
{CTK_TEXTENTRY(LABELMAXWIDTH + 1, 5, 16, 1, driver, 24)};
|
||||
|
||||
static struct ctk_label screensaverlabel =
|
||||
{CTK_LABEL(0, 7, LABELMAXWIDTH, 1, "Screensaver")};
|
||||
static char screensaver[25];
|
||||
static struct ctk_textentry screensavertextentry =
|
||||
{CTK_TEXTENTRY(LABELMAXWIDTH + 1, 7, 16, 1, screensaver, 24)};
|
||||
|
||||
|
||||
static struct ctk_label ipaddrlabel =
|
||||
{CTK_LABEL(0, 9, LABELMAXWIDTH, 1, "IP address")};
|
||||
static char ipaddr[25];
|
||||
static struct ctk_textentry ipaddrtextentry =
|
||||
{CTK_TEXTENTRY(LABELMAXWIDTH + 1, 9, 16, 1, ipaddr, 24)};
|
||||
static struct ctk_label netmasklabel =
|
||||
{CTK_LABEL(0, 11, LABELMAXWIDTH, 1, "Netmask")};
|
||||
static char netmask[25];
|
||||
static struct ctk_textentry netmasktextentry =
|
||||
{CTK_TEXTENTRY(LABELMAXWIDTH + 1, 11, 16, 1, netmask, 24)};
|
||||
static struct ctk_label gatewaylabel =
|
||||
{CTK_LABEL(0, 13, LABELMAXWIDTH, 1, "Gateway")};
|
||||
static char gateway[25];
|
||||
static struct ctk_textentry gatewaytextentry =
|
||||
{CTK_TEXTENTRY(LABELMAXWIDTH + 1, 13, 16, 1, gateway, 24)};
|
||||
static struct ctk_label dnsserverlabel =
|
||||
{CTK_LABEL(0, 15, LABELMAXWIDTH, 1, "DNS server")};
|
||||
static char dnsserver[25];
|
||||
static struct ctk_textentry dnsservertextentry =
|
||||
{CTK_TEXTENTRY(LABELMAXWIDTH + 1, 15, 16, 1, dnsserver, 24)};
|
||||
|
||||
static struct ctk_button savebutton =
|
||||
{CTK_BUTTON(0, 17, 12, "Save & close")};
|
||||
static struct ctk_button cancelbutton =
|
||||
{CTK_BUTTON(24, 17, 6, "Cancel")};
|
||||
|
||||
PROCESS(configedit_process, "Configuration editor");
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
struct ptentry {
|
||||
char c;
|
||||
char * (* pfunc)(char *str);
|
||||
};
|
||||
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
static char *
|
||||
parse(char *str, struct ptentry *t)
|
||||
{
|
||||
struct ptentry *p;
|
||||
|
||||
/* Loop over the parse table entries in t in order to find one that
|
||||
matches the first character in str. */
|
||||
for(p = t; p->c != 0; ++p) {
|
||||
if(*str == p->c) {
|
||||
/* Skip rest of the characters up to the first space. */
|
||||
while(*str != ' ') {
|
||||
++str;
|
||||
}
|
||||
|
||||
/* Skip all spaces.*/
|
||||
while(*str == ' ') {
|
||||
++str;
|
||||
}
|
||||
|
||||
/* Call parse table entry function and return. */
|
||||
return p->pfunc(str);
|
||||
}
|
||||
}
|
||||
|
||||
/* Did not find matching entry in parse table. We just call the
|
||||
default handler supplied by the caller and return. */
|
||||
return p->pfunc(str);
|
||||
}
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
static char *
|
||||
skipnewline(char *str)
|
||||
{
|
||||
/* Skip all characters until the newline. */
|
||||
while(*str != '\n') {
|
||||
++str;
|
||||
}
|
||||
|
||||
/* Return a pointer to the first character after the newline. */
|
||||
return str + 1;
|
||||
}
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
static char *
|
||||
nullterminate(char *str)
|
||||
{
|
||||
char *nt;
|
||||
|
||||
/* Nullterminate string. Start with finding newline character. */
|
||||
for(nt = str; *nt != '\r' &&
|
||||
*nt != '\n'; ++nt);
|
||||
|
||||
/* Replace newline with a null char. */
|
||||
*nt = 0;
|
||||
|
||||
/* Remove trailing spaces. */
|
||||
while(nt > str && *(nt - 1) == ' ') {
|
||||
*(nt - 1) = 0;
|
||||
--nt;
|
||||
}
|
||||
|
||||
/* Return pointer to null char. */
|
||||
return nt;
|
||||
}
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
static char * __fastcall__
|
||||
copystr(char *dst, char *src, int len)
|
||||
{
|
||||
char *nt = nullterminate(src);
|
||||
strncpy(dst, src, len);
|
||||
return nt + 1;
|
||||
}
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
static char *
|
||||
loaddriver(char *str)
|
||||
{
|
||||
return copystr(driver, str, sizeof(driver));
|
||||
}
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
static char *
|
||||
loadtheme(char *str)
|
||||
{
|
||||
return copystr(theme, str, sizeof(theme));
|
||||
}
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
static char *
|
||||
loadcfs(char *str)
|
||||
{
|
||||
return copystr(cfs, str, sizeof(cfs));
|
||||
}
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
static char *
|
||||
loadscreensaver(char *str)
|
||||
{
|
||||
return copystr(screensaver, str, sizeof(screensaver));
|
||||
}
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
static char *
|
||||
ipaddrconf(char *str)
|
||||
{
|
||||
return copystr(ipaddr, str, sizeof(ipaddr));
|
||||
}
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
static char *
|
||||
netmaskconf(char *str)
|
||||
{
|
||||
return copystr(netmask, str, sizeof(netmask));
|
||||
}
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
static char *
|
||||
drconf(char *str)
|
||||
{
|
||||
return copystr(gateway, str, sizeof(gateway));
|
||||
}
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
static char *
|
||||
dnsconf(char *str)
|
||||
{
|
||||
return copystr(dnsserver, str, sizeof(dnsserver));
|
||||
}
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
static struct ptentry initparsetab[] =
|
||||
{{'n', loaddriver},
|
||||
{'t', loadtheme},
|
||||
{'c', loadcfs},
|
||||
{'s', loadscreensaver},
|
||||
{'i', ipaddrconf},
|
||||
{'m', netmaskconf},
|
||||
{'r', drconf},
|
||||
{'d', dnsconf},
|
||||
{'#', skipnewline},
|
||||
|
||||
/* Default action */
|
||||
{0, skipnewline}};
|
||||
static void
|
||||
initscript(void)
|
||||
{
|
||||
char line[40], *lineptr;
|
||||
/* struct c64_fs_file f;*/
|
||||
int f;
|
||||
|
||||
if((f = cfs_open("config.cfg", 0)) == -1) {
|
||||
return;
|
||||
}
|
||||
line[0] = ' ';
|
||||
while(line[0] != '.' &&
|
||||
line[0] != 0) {
|
||||
lineptr = line;
|
||||
do {
|
||||
if(cfs_read(f, lineptr, 1) != 1) {
|
||||
cfs_close(f);
|
||||
return;
|
||||
}
|
||||
++lineptr;
|
||||
} while(*(lineptr - 1) != '\n' &&
|
||||
*(lineptr - 1) != '\r');
|
||||
|
||||
*lineptr = 0;
|
||||
|
||||
if(line[0] != '.' &&
|
||||
line[0] != 0) {
|
||||
parse(line, initparsetab);
|
||||
}
|
||||
|
||||
}
|
||||
cfs_close(f);
|
||||
return;
|
||||
}
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
static int
|
||||
makeline(char *line, char c, char *str)
|
||||
{
|
||||
int len;
|
||||
|
||||
len = strlen(str);
|
||||
|
||||
line[0] = c;
|
||||
line[1] = ' ';
|
||||
strcpy(&line[2], str);
|
||||
line[2 + len] = '\n';
|
||||
line[3 + len] = 0;
|
||||
return len + 3;
|
||||
}
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
static void
|
||||
savescript(void)
|
||||
{
|
||||
char line[40];
|
||||
/* struct c64_fs_file f;*/
|
||||
int f;
|
||||
|
||||
f = cfs_open("@:config.cfg", CFS_WRITE);
|
||||
if(f == -1) {
|
||||
log_message("Could not open config.cfg", "");
|
||||
return;
|
||||
}
|
||||
if(cfs[0] != 0) {
|
||||
cfs_write(f, line, makeline(line, 'c', cfs));
|
||||
}
|
||||
if(theme[0] != 0) {
|
||||
cfs_write(f, line, makeline(line, 't', theme));
|
||||
}
|
||||
if(driver[0] != 0) {
|
||||
cfs_write(f, line, makeline(line, 'n', driver));
|
||||
}
|
||||
if(ipaddr[0] != 0) {
|
||||
cfs_write(f, line, makeline(line, 'i', ipaddr));
|
||||
}
|
||||
if(netmask[0] != 0) {
|
||||
cfs_write(f, line, makeline(line, 'm', netmask));
|
||||
}
|
||||
if(gateway[0] != 0) {
|
||||
cfs_write(f, line, makeline(line, 'r', gateway));
|
||||
}
|
||||
if(dnsserver[0] != 0) {
|
||||
cfs_write(f, line, makeline(line, 'd', dnsserver));
|
||||
}
|
||||
|
||||
if(screensaver[0] != 0) {
|
||||
cfs_write(f, line, makeline(line, 's', screensaver));
|
||||
}
|
||||
|
||||
strcpy(line, ".\n\0\n\n\n");
|
||||
cfs_write(f, line, strlen(line));
|
||||
|
||||
cfs_close(f);
|
||||
|
||||
}
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
static void
|
||||
quit_services(void)
|
||||
{
|
||||
/* cfs_init_init(NULL);
|
||||
ctk_draw_quit();
|
||||
|
||||
if(ek_service_find(&packetservice) == EK_ERR_OK) {
|
||||
ek_post(packetservice.id, EK_EVENT_REQUEST_EXIT, NULL);
|
||||
ek_service_reset(&packetservice);
|
||||
}*/
|
||||
}
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
PROCESS_THREAD(configedit_process, ev, data)
|
||||
{
|
||||
PROCESS_BEGIN();
|
||||
|
||||
/* Create window. */
|
||||
ctk_window_new(&window, 32, 18, "Config editor");
|
||||
|
||||
CTK_WIDGET_ADD(&window, &cfslabel);
|
||||
CTK_WIDGET_ADD(&window, &cfstextentry);
|
||||
|
||||
CTK_WIDGET_ADD(&window, &themelabel);
|
||||
CTK_WIDGET_ADD(&window, &themetextentry);
|
||||
|
||||
CTK_WIDGET_ADD(&window, &driverlabel);
|
||||
CTK_WIDGET_ADD(&window, &drivertextentry);
|
||||
|
||||
CTK_WIDGET_ADD(&window, &screensaverlabel);
|
||||
CTK_WIDGET_ADD(&window, &screensavertextentry);
|
||||
|
||||
CTK_WIDGET_ADD(&window, &ipaddrlabel);
|
||||
CTK_WIDGET_ADD(&window, &ipaddrtextentry);
|
||||
CTK_WIDGET_ADD(&window, &netmasklabel);
|
||||
CTK_WIDGET_ADD(&window, &netmasktextentry);
|
||||
CTK_WIDGET_ADD(&window, &gatewaylabel);
|
||||
CTK_WIDGET_ADD(&window, &gatewaytextentry);
|
||||
CTK_WIDGET_ADD(&window, &dnsserverlabel);
|
||||
CTK_WIDGET_ADD(&window, &dnsservertextentry);
|
||||
|
||||
CTK_WIDGET_ADD(&window, &savebutton);
|
||||
CTK_WIDGET_ADD(&window, &cancelbutton);
|
||||
|
||||
CTK_WIDGET_FOCUS(&window, &cfstextentry);
|
||||
|
||||
/* Fill the configuration strings with values from the current
|
||||
configuration */
|
||||
initscript();
|
||||
|
||||
ctk_window_open(&window);
|
||||
|
||||
while(1) {
|
||||
PROCESS_WAIT_EVENT();
|
||||
|
||||
if(ev == ctk_signal_button_activate) {
|
||||
if(data == &savebutton) {
|
||||
savescript();
|
||||
quit_services();
|
||||
ctk_window_close(&window);
|
||||
program_handler_load("config.prg", NULL);
|
||||
break;
|
||||
} else if(data == &cancelbutton) {
|
||||
ctk_window_close(&window);
|
||||
break;
|
||||
}
|
||||
} else if(ev == ctk_signal_window_close ||
|
||||
ev == PROCESS_EVENT_EXIT) {
|
||||
ctk_window_close(&window);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
PROCESS_END();
|
||||
}
|
||||
/*-----------------------------------------------------------------------------------*/
|
|
@ -1,71 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2003, Adam Dunkels.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. 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.
|
||||
* 3. The name of the author may not be used to endorse or promote
|
||||
* products derived from this software without specific prior
|
||||
* written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
||||
*
|
||||
* This file is part of the Contiki desktop environment
|
||||
*
|
||||
* $Id: default-dsc.c,v 1.2 2007/09/06 01:36:11 matsutsuka Exp $
|
||||
*
|
||||
*/
|
||||
|
||||
#include "sys/dsc.h"
|
||||
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
#if CTK_CONF_ICON_BITMAPS
|
||||
static unsigned char defaulticon_bitmap[3*3*8] = {
|
||||
0xff,0xff,0xc0,0xcf,0xc0,0xc3,0xc0,0xc0,
|
||||
0xff,0xff,0x00,0xff,0x00,0xff,0x00,0x00,
|
||||
0xff,0xfc,0x00,0xf0,0x00,0xc0,0x00,0x00,
|
||||
0xc0,0xc0,0xc0,0xc0,0xc0,0xc0,0xc0,0xc0,
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
||||
0x0b,0x0b,0x0b,0x0b,0x0b,0x0b,0x0b,0x0b,
|
||||
0xc0,0xc0,0xc0,0xc0,0xc0,0xc0,0x80,0x00,
|
||||
0x00,0x00,0x00,0x00,0xff,0x00,0xff,0xff,
|
||||
0x0b,0x0b,0x0b,0x0b,0xfb,0x03,0xff,0xff
|
||||
};
|
||||
#endif /* CTK_CONF_ICON_BITMAPS */
|
||||
|
||||
#if CTK_CONF_ICON_TEXTMAPS
|
||||
static char defaulticon_textmap[9] = {
|
||||
'+', '=', '+',
|
||||
'|', 'D', '|',
|
||||
'+', '-', '+'
|
||||
};
|
||||
#endif /* CTK_CONF_ICON_TEXTMAPS */
|
||||
|
||||
#if CTK_CONF_ICONS
|
||||
static struct ctk_icon default_icon =
|
||||
{CTK_ICON("Default", defaulticon_bitmap, defaulticon_textmap)};
|
||||
#endif /* CTK_CONF_ICONS */
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
DSC(default_dsc,
|
||||
"Default CTK theme",
|
||||
"default.prg",
|
||||
default_init,
|
||||
&default_icon);
|
||||
/*-----------------------------------------------------------------------------------*/
|
|
@ -1,73 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2003, Adam Dunkels.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. 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.
|
||||
* 3. The name of the author may not be used to endorse or promote
|
||||
* products derived from this software without specific prior
|
||||
* written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
||||
*
|
||||
* This file is part of the Contiki desktop environment
|
||||
*
|
||||
* $Id: enabler-dsc.c,v 1.2 2007/09/06 01:36:11 matsutsuka Exp $
|
||||
*
|
||||
*/
|
||||
|
||||
#include "sys/dsc.h"
|
||||
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
#if CTK_CONF_ICON_BITMAPS
|
||||
static unsigned char enablericon_bitmap[3*3*8] = {
|
||||
0xff,0xff,0xff,0xfc,0xf0,0xf0,0xe0,0xe0,
|
||||
0xff,0xff,0xff,0x00,0x00,0x00,0x00,0x00,
|
||||
0xff,0xff,0xff,0x3f,0x0f,0x0f,0x07,0x07,
|
||||
|
||||
0xe0,0xe0,0xe0,0xe0,0xe0,0xe0,0xe0,0xe0,
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
||||
0x07,0x07,0x07,0x07,0x07,0x07,0x07,0x07,
|
||||
|
||||
0xe0,0xe0,0xf0,0xf0,0xfc,0xff,0xff,0xff,
|
||||
0x00,0x00,0x00,0x00,0x00,0xff,0xff,0xff,
|
||||
0x07,0x07,0x0f,0x0f,0x3f,0xff,0xff,0xff
|
||||
};
|
||||
#endif /* CTK_CONF_ICON_BITMAPS */
|
||||
|
||||
#if CTK_CONF_ICON_TEXTMAPS
|
||||
static char enablericon_textmap[9] = {
|
||||
'(', '=', ')',
|
||||
'|', 'o', '|',
|
||||
'(', '-', ')'
|
||||
};
|
||||
#endif /* CTK_CONF_ICON_TEXTMAPS */
|
||||
|
||||
#if CTK_CONF_ICONS
|
||||
static struct ctk_icon enabler_icon =
|
||||
{CTK_ICON("Enabler", enablericon_bitmap, enablericon_textmap)};
|
||||
#endif /* CTK_CONF_ICONS */
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
DSC(enabler_dsc,
|
||||
"Colorless grayish CTK theme",
|
||||
"enabler.prg",
|
||||
enabler_init,
|
||||
&enabler_icon);
|
||||
/*-----------------------------------------------------------------------------------*/
|
|
@ -1,37 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2004, Adam Dunkels.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. 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.
|
||||
* 3. Neither the name of the Institute 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 INSTITUTE 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 INSTITUTE 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.
|
||||
*
|
||||
* This file is part of the Contiki operating system.
|
||||
*
|
||||
* Author: Adam Dunkels <adam@sics.se>
|
||||
*
|
||||
* $Id: http-user-agent-string.c,v 1.1 2007/05/23 23:11:24 oliverschmidt Exp $
|
||||
*/
|
||||
char http_user_agent_fields[100] =
|
||||
/* "Connection: close\r\nUser-Agent: Contiki/1.1-rc0 (Commodore 64; http://dunkels.com/adam/contiki/)\r\n\r\n" */
|
||||
{0x43, 0x6f, 0x6e, 0x6e, 0x65, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x3a, 0x20, 0x63, 0x6c, 0x6f, 0x73, 0x65, 0xd, 0xa, 0x55, 0x73, 0x65, 0x72, 0x2d, 0x41, 0x67, 0x65, 0x6e, 0x74, 0x3a, 0x20, 0x43, 0x6f, 0x6e, 0x74, 0x69, 0x6b, 0x69, 0x2f, 0x31, 0x2e, 0x31, 0x2d, 0x72, 0x63, 0x30, 0x20, 0x28, 0x43, 0x6f, 0x6d, 0x6d, 0x6f, 0x64, 0x6f, 0x72, 0x65, 0x20, 0x36, 0x34, 0x3b, 0x20, 0x68, 0x74, 0x74, 0x70, 0x3a, 0x2f, 0x2f, 0x64, 0x75, 0x6e, 0x6b, 0x65, 0x6c, 0x73, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x61, 0x64, 0x61, 0x6d, 0x2f, 0x63, 0x6f, 0x6e, 0x74, 0x69, 0x6b, 0x69, 0x2f, 0x29, 0xd, 0xa, 0xd, 0xa, };
|
|
@ -1,35 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2004, Adam Dunkels.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. 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.
|
||||
* 3. Neither the name of the Institute 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 INSTITUTE 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 INSTITUTE 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.
|
||||
*
|
||||
* This file is part of the Contiki operating system.
|
||||
*
|
||||
* Author: Adam Dunkels <adam@sics.se>
|
||||
*
|
||||
* $Id: http-user-agent-string.h,v 1.1 2007/05/23 23:11:24 oliverschmidt Exp $
|
||||
*/
|
||||
extern char http_user_agent_fields[100];
|
|
@ -1,73 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2003, Adam Dunkels.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. 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.
|
||||
* 3. The name of the author may not be used to endorse or promote
|
||||
* products derived from this software without specific prior
|
||||
* written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
||||
*
|
||||
* This file is part of the Contiki desktop environment
|
||||
*
|
||||
* $Id: memstat-dsc.c,v 1.2 2007/09/06 01:36:11 matsutsuka Exp $
|
||||
*
|
||||
*/
|
||||
|
||||
#include "sys/dsc.h"
|
||||
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
#if CTK_CONF_ICON_BITMAPS
|
||||
static unsigned char memstaticon_bitmap[3*3*8] = {
|
||||
0x00, 0x7f, 0x43, 0x4c, 0x58, 0x53, 0x60, 0x6f,
|
||||
0x00, 0xff, 0x00, 0x7e, 0x00, 0xff, 0x00, 0xff,
|
||||
0x00, 0xfe, 0xc2, 0x32, 0x1a, 0xca, 0x06, 0xf6,
|
||||
|
||||
0x40, 0x5f, 0x40, 0x5f, 0x40, 0x5f, 0x40, 0x4f,
|
||||
0x00, 0xff, 0x00, 0xff, 0x00, 0xfc, 0x01, 0xf3,
|
||||
0x02, 0xfa, 0x02, 0x82, 0x3e, 0xfe, 0xfe, 0xfe,
|
||||
|
||||
0x60, 0x67, 0x50, 0x59, 0x4c, 0x43, 0x7f, 0x00,
|
||||
0x07, 0xe7, 0x0f, 0xef, 0x0f, 0x0f, 0xff, 0x00,
|
||||
0x8e, 0x06, 0x06, 0x06, 0x8e, 0xfe, 0xfe, 0x00
|
||||
};
|
||||
#endif /* CTK_CONF_ICON_BITMAPS */
|
||||
|
||||
#if CTK_CONF_ICON_TEXTMAPS
|
||||
static char memstaticon_textmap[9] = {
|
||||
'0', '0', '1',
|
||||
'0', '1', '0',
|
||||
'1', '0', '1'
|
||||
};
|
||||
#endif /* CTK_CONF_ICON_TEXTMAPS */
|
||||
|
||||
#if CTK_CONF_ICONS
|
||||
static struct ctk_icon memstat_icon =
|
||||
{CTK_ICON("Memory stats", memstaticon_bitmap, memstaticon_textmap)};
|
||||
#endif /* CTK_CONF_ICONS */
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
DSC(memstat_dsc,
|
||||
"Memory statistics",
|
||||
"memstat.prg",
|
||||
memstat_init,
|
||||
&memstat_icon);
|
||||
/*-----------------------------------------------------------------------------------*/
|
|
@ -1,54 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2004, Adam Dunkels.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. 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.
|
||||
* 3. Neither the name of the Institute 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 INSTITUTE 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 INSTITUTE 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.
|
||||
*
|
||||
* This file is part of the Contiki operating system.
|
||||
*
|
||||
* Author: Adam Dunkels <adam@sics.se>
|
||||
*
|
||||
* $Id: mtest.c,v 1.1 2007/05/23 23:11:24 oliverschmidt Exp $
|
||||
*/
|
||||
#include "mt.h"
|
||||
|
||||
MTP(t, p, "Test thread");
|
||||
/*--------------------------------------------------------------------------*/
|
||||
#pragma optimize(push, off)
|
||||
static void
|
||||
test(void *data)
|
||||
{
|
||||
while(1) {
|
||||
asm("inc $d020");
|
||||
}
|
||||
}
|
||||
#pragma optimize(pop)
|
||||
/*--------------------------------------------------------------------------*/
|
||||
LOADER_INIT_FUNC(mtest_init, arg)
|
||||
{
|
||||
arg_free(arg);
|
||||
mtp_start(&t, test, NULL);
|
||||
}
|
||||
/*--------------------------------------------------------------------------*/
|
|
@ -1,73 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2003, Adam Dunkels.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. 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.
|
||||
* 3. The name of the author may not be used to endorse or promote
|
||||
* products derived from this software without specific prior
|
||||
* written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
||||
*
|
||||
* This file is part of the Contiki desktop environment
|
||||
*
|
||||
* $Id: plasma-dsc.c,v 1.2 2007/09/06 01:36:11 matsutsuka Exp $
|
||||
*
|
||||
*/
|
||||
|
||||
#include "sys/dsc.h"
|
||||
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
#if CTK_CONF_ICON_BITMAPS
|
||||
static unsigned char plasmaicon_bitmap[3*3*8] = {
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
||||
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
||||
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
|
||||
};
|
||||
#endif /* CTK_CONF_ICON_BITMAPS */
|
||||
|
||||
#if CTK_CONF_ICON_TEXTMAPS
|
||||
static char plasmaicon_textmap[9] = {
|
||||
'.', ' ', '.',
|
||||
' ', 'O', ' ',
|
||||
'.', ' ', '.'
|
||||
};
|
||||
#endif /* CTK_CONF_ICON_TEXTMAPS */
|
||||
|
||||
#if CTK_CONF_ICONS
|
||||
static struct ctk_icon plasma_icon =
|
||||
{CTK_ICON("Plasma", plasmaicon_bitmap, plasmaicon_textmap)};
|
||||
#endif /* CTK_CONF_ICONS */
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
DSC(plasma_dsc,
|
||||
"Screensaver with a plasma",
|
||||
"plasma.sav",
|
||||
plasma_init,
|
||||
&plasma_icon);
|
||||
/*-----------------------------------------------------------------------------------*/
|
|
@ -1,224 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2002-2004, Adam Dunkels.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. 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.
|
||||
* 3. The name of the author may not be used to endorse or promote
|
||||
* products derived from this software without specific prior
|
||||
* written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
||||
*
|
||||
* This file is part of the Contiki desktop environment
|
||||
*
|
||||
* $Id: plasma.c,v 1.1 2007/05/23 23:11:24 oliverschmidt Exp $
|
||||
*
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "ctk/ctk.h"
|
||||
#include "ctk/ctk-draw.h"
|
||||
#include "ctk/ctk-mouse.h"
|
||||
#include "contiki.h"
|
||||
|
||||
static unsigned char sinetab1[256] = {
|
||||
128, 131, 134, 137, 140, 143, 146, 149,
|
||||
152, 156, 159, 162, 165, 168, 171, 174,
|
||||
176, 179, 182, 185, 188, 191, 193, 196,
|
||||
199, 201, 204, 206, 209, 211, 213, 216,
|
||||
218, 220, 222, 224, 226, 228, 230, 232,
|
||||
234, 236, 237, 239, 240, 242, 243, 245,
|
||||
246, 247, 248, 249, 250, 251, 252, 252,
|
||||
253, 254, 254, 255, 255, 255, 255, 255,
|
||||
255, 255, 255, 255, 255, 255, 254, 254,
|
||||
253, 252, 252, 251, 250, 249, 248, 247,
|
||||
246, 245, 243, 242, 240, 239, 237, 236,
|
||||
234, 232, 230, 228, 226, 224, 222, 220,
|
||||
218, 216, 213, 211, 209, 206, 204, 201,
|
||||
199, 196, 193, 191, 188, 185, 182, 179,
|
||||
176, 174, 171, 168, 165, 162, 159, 156,
|
||||
152, 149, 146, 143, 140, 137, 134, 131,
|
||||
128, 124, 121, 118, 115, 112, 109, 106,
|
||||
103, 99, 96, 93, 90, 87, 84, 81,
|
||||
79, 76, 73, 70, 67, 64, 62, 59,
|
||||
56, 54, 51, 49, 46, 44, 42, 39,
|
||||
37, 35, 33, 31, 29, 27, 25, 23,
|
||||
21, 19, 18, 16, 15, 13, 12, 10,
|
||||
9, 8, 7, 6, 5, 4, 3, 3,
|
||||
2, 1, 1, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 1, 1,
|
||||
2, 3, 3, 4, 5, 6, 7, 8,
|
||||
9, 10, 12, 13, 15, 16, 18, 19,
|
||||
21, 23, 25, 27, 29, 31, 33, 35,
|
||||
37, 39, 42, 44, 46, 49, 51, 54,
|
||||
56, 59, 62, 64, 67, 70, 73, 76,
|
||||
78, 81, 84, 87, 90, 93, 96, 99,
|
||||
103, 106, 109, 112, 115, 118, 121, 124,
|
||||
};
|
||||
|
||||
static unsigned char sinetab2[256];
|
||||
static unsigned char sinetab3[256];
|
||||
|
||||
static unsigned char colortab[256];
|
||||
|
||||
static unsigned char colors[16] =
|
||||
{
|
||||
0x00, 0x06, 0x0b, 0x04,
|
||||
0x0a, 0x0f, 0x07, 0x01,
|
||||
0x07, 0x0f, 0x0a, 0x08,
|
||||
0x02, 0x09, 0x00, 0x00,
|
||||
};
|
||||
|
||||
#define XSIZE 25
|
||||
#define YSIZE 25
|
||||
|
||||
#define XADD01 0xfe
|
||||
#define YADD01 0x05
|
||||
|
||||
#define XADD1 0x04
|
||||
#define YADD1 0x02
|
||||
#define XADD2 0xfc
|
||||
#define YADD2 0xf9
|
||||
|
||||
#define XADD 0x03
|
||||
#define YADD 0xfe
|
||||
|
||||
#define MOVADD 0xfb
|
||||
|
||||
static unsigned char xplasma[XSIZE], yplasma[YSIZE];
|
||||
static unsigned char xcnt, ycnt;
|
||||
static unsigned char xcnt01, xcnt02, xcnt1, xcnt2;
|
||||
static unsigned char ycnt01, ycnt02, ycnt1, ycnt2;
|
||||
|
||||
static unsigned char xadd02 = 0x01;
|
||||
static unsigned char yadd02 = 0xfb;
|
||||
|
||||
static unsigned char movcnt;
|
||||
|
||||
PROCESS(plasma_process, "Plasma screensaver");
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
scrninit(void)
|
||||
{
|
||||
unsigned char *ptr, *cptr;
|
||||
static int i;
|
||||
|
||||
/* Make sine tables */
|
||||
for(i = 0; i < 256; ++i) {
|
||||
sinetab2[(unsigned char)i] = sinetab1[(unsigned char)i] / 2;
|
||||
sinetab3[(unsigned char)i] = sinetab1[(unsigned char)i] / 4;
|
||||
}
|
||||
|
||||
/* Make color table */
|
||||
for(i = 0; i < 256; ++i) {
|
||||
colortab[(unsigned char)i] = colors[(unsigned char)i / 16];
|
||||
}
|
||||
|
||||
|
||||
/* Fill screen with inverted spaces. */
|
||||
cptr = COLOR_RAM;
|
||||
for(ptr = (unsigned char *)0x0400;
|
||||
ptr != (unsigned char *)0x07e8;
|
||||
++ptr) {
|
||||
*ptr = 0xa0;
|
||||
*cptr++ = 0x00;
|
||||
}
|
||||
|
||||
VIC.ctrl1 = 0x1b; /* $D011 */
|
||||
VIC.addr = 0x17; /* $D018 */
|
||||
VIC.ctrl2 = 0xc8; /* $D016 */
|
||||
VIC.bordercolor = 0x00; /* $D020 */
|
||||
VIC.bgcolor0 = 0x00; /* $D021 */
|
||||
CIA2.pra = 0x03; /* $DD00 */
|
||||
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
pollhandler(void)
|
||||
{
|
||||
static unsigned char i, x, y;
|
||||
register unsigned char *cptr;
|
||||
|
||||
if(ctk_mode_get() == CTK_MODE_SCREENSAVER) {
|
||||
|
||||
|
||||
xcnt1 = xcnt01;
|
||||
xcnt2 = xcnt02;
|
||||
|
||||
for(i = 0; i < XSIZE; ++i) {
|
||||
xplasma[i] = sinetab1[xcnt1] + sinetab2[xcnt2];
|
||||
xcnt1 += XADD1;
|
||||
xcnt2 += XADD2;
|
||||
}
|
||||
|
||||
ycnt1 = ycnt01;
|
||||
ycnt2 = ycnt02;
|
||||
|
||||
for(i = 0; i < YSIZE; ++i) {
|
||||
yplasma[i] = sinetab1[ycnt1] + sinetab3[ycnt2];
|
||||
ycnt1 += YADD1;
|
||||
ycnt2 += YADD2;
|
||||
}
|
||||
|
||||
xcnt01 += XADD01;
|
||||
xcnt02 += xadd02;
|
||||
ycnt01 += YADD01;
|
||||
ycnt02 += yadd02;
|
||||
|
||||
|
||||
yadd02 = sinetab3[ycnt] / 4;
|
||||
xadd02 = sinetab3[xcnt] / 4;
|
||||
|
||||
ycnt += YADD;
|
||||
xcnt += XADD;
|
||||
|
||||
movcnt += MOVADD;
|
||||
cptr = (unsigned char *)(COLOR_RAM + sinetab1[movcnt]/16);
|
||||
for(y = 0; y < YSIZE; ++y) {
|
||||
for(x = 0; x < XSIZE; ++x) {
|
||||
*cptr = colortab[(xplasma[x] + yplasma[y]) & 0xff];
|
||||
++cptr;
|
||||
}
|
||||
cptr += 40 - XSIZE;
|
||||
}
|
||||
}
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
PROCESS_THREAD(plasma_process, ev, data)
|
||||
{
|
||||
PROCESS_POLLHANDLER(pollhandler());
|
||||
|
||||
PROCESS_BEGIN();
|
||||
|
||||
ctk_mode_set(CTK_MODE_SCREENSAVER);
|
||||
ctk_mouse_hide();
|
||||
|
||||
scrninit();
|
||||
|
||||
PROCESS_WAIT_EVENT_UNTIL(ev == ctk_signal_screensaver_stop ||
|
||||
ev == PROCESS_EVENT_EXIT);
|
||||
ctk_draw_init();
|
||||
ctk_desktop_redraw(NULL);
|
||||
|
||||
PROCESS_END();
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
|
@ -1,73 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2003, Adam Dunkels.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. 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.
|
||||
* 3. The name of the author may not be used to endorse or promote
|
||||
* products derived from this software without specific prior
|
||||
* written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
||||
*
|
||||
* This file is part of the Contiki desktop environment
|
||||
*
|
||||
* $Id: ravenpine-dsc.c,v 1.2 2007/09/06 01:36:11 matsutsuka Exp $
|
||||
*
|
||||
*/
|
||||
|
||||
#include "sys/dsc.h"
|
||||
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
#if CTK_CONF_ICON_BITMAPS
|
||||
static unsigned char ravenpineicon_bitmap[3*3*8] = {
|
||||
0x00,0x3f,0x6a,0x40,0x60,0x40,0x60,0x40,
|
||||
0x00,0xff,0xaa,0x00,0x00,0x00,0x00,0x00,
|
||||
0x00,0xf0,0x20,0x00,0x00,0x00,0x00,0x00,
|
||||
|
||||
0x60,0x40,0x60,0x40,0x60,0x40,0x60,0x40,
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
||||
0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,
|
||||
|
||||
0x60,0x40,0x40,0x40,0x00,0x00,0x00,0x00,
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0xff,0x00,
|
||||
0x02,0x02,0x02,0x02,0x02,0x06,0xfc,0x00
|
||||
};
|
||||
#endif /* CTK_CONF_ICON_BITMAPS */
|
||||
|
||||
#if CTK_CONF_ICON_TEXTMAPS
|
||||
static char ravenpineicon_textmap[9] = {
|
||||
'(', '=', ')',
|
||||
'|', 'o', '|',
|
||||
'(', '-', ')'
|
||||
};
|
||||
#endif /* CTK_CONF_ICON_TEXTMAPS */
|
||||
|
||||
#if CTK_CONF_ICONS
|
||||
static struct ctk_icon ravenpine_icon =
|
||||
{CTK_ICON("Ravenpine", ravenpineicon_bitmap, ravenpineicon_textmap)};
|
||||
#endif /* CTK_CONF_ICONS */
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
DSC(ravenpine_dsc,
|
||||
"Terminal green CTK theme",
|
||||
"ravenpine.prg",
|
||||
ravenpine_init,
|
||||
&ravenpine_icon);
|
||||
/*-----------------------------------------------------------------------------------*/
|
|
@ -1,73 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2003, Adam Dunkels.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. 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.
|
||||
* 3. The name of the author may not be used to endorse or promote
|
||||
* products derived from this software without specific prior
|
||||
* written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
||||
*
|
||||
* This file is part of the Contiki desktop environment
|
||||
*
|
||||
* $Id: springlight-dsc.c,v 1.2 2007/09/06 01:36:11 matsutsuka Exp $
|
||||
*
|
||||
*/
|
||||
|
||||
#include "sys/dsc.h"
|
||||
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
#if CTK_CONF_ICON_BITMAPS
|
||||
static unsigned char springlighticon_bitmap[3*3*8] = {
|
||||
0x00,0x3f,0x6a,0x40,0x60,0x40,0x60,0x40,
|
||||
0x00,0xff,0xaa,0x00,0x00,0x00,0x00,0x00,
|
||||
0x00,0xf0,0x20,0x00,0x00,0x00,0x00,0x00,
|
||||
|
||||
0x60,0x40,0x60,0x40,0x60,0x40,0x60,0x40,
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
||||
0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,
|
||||
|
||||
0x60,0x40,0x40,0x40,0x00,0x00,0x00,0x00,
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0xff,0x00,
|
||||
0x02,0x02,0x02,0x02,0x02,0x06,0xfc,0x00
|
||||
};
|
||||
#endif /* CTK_CONF_ICON_BITMAPS */
|
||||
|
||||
#if CTK_CONF_ICON_TEXTMAPS
|
||||
static char springlighticon_textmap[9] = {
|
||||
'(', '=', ')',
|
||||
'|', 'o', '|',
|
||||
'(', '-', ')'
|
||||
};
|
||||
#endif /* CTK_CONF_ICON_TEXTMAPS */
|
||||
|
||||
#if CTK_CONF_ICONS
|
||||
static struct ctk_icon springlight_icon =
|
||||
{CTK_ICON("Springlight", springlighticon_bitmap, springlighticon_textmap)};
|
||||
#endif /* CTK_CONF_ICONS */
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
DSC(springlight_dsc,
|
||||
"Spring green CTK theme",
|
||||
"springlight.prg",
|
||||
springlight_init,
|
||||
&springlight_icon);
|
||||
/*-----------------------------------------------------------------------------------*/
|
|
@ -1,73 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2003, Adam Dunkels.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. 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.
|
||||
* 3. The name of the author may not be used to endorse or promote
|
||||
* products derived from this software without specific prior
|
||||
* written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
||||
*
|
||||
* This file is part of the Contiki desktop environment
|
||||
*
|
||||
* $Id: ssfire-dsc.c,v 1.2 2007/09/06 01:36:11 matsutsuka Exp $
|
||||
*
|
||||
*/
|
||||
|
||||
#include "sys/dsc.h"
|
||||
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
#if CTK_CONF_ICON_BITMAPS
|
||||
static unsigned char ssfireicon_bitmap[3*3*8] = {
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
||||
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
||||
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
|
||||
};
|
||||
#endif /* CTK_CONF_ICON_BITMAPS */
|
||||
|
||||
#if CTK_CONF_ICON_TEXTMAPS
|
||||
static char ssfireicon_textmap[9] = {
|
||||
'.', ' ', '.',
|
||||
'o', ' ', 'o',
|
||||
'O', ' ', 'O'
|
||||
};
|
||||
#endif /* CTK_CONF_ICON_TEXTMAPS */
|
||||
|
||||
#if CTK_CONF_ICONS
|
||||
static struct ctk_icon ssfire_icon =
|
||||
{CTK_ICON("Fire", ssfireicon_bitmap, ssfireicon_textmap)};
|
||||
#endif /* CTK_CONF_ICONS */
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
DSC(ssfire_dsc,
|
||||
"Screensaver with two fires",
|
||||
"ssfire.sav",
|
||||
ssfire_init,
|
||||
&ssfire_icon);
|
||||
/*-----------------------------------------------------------------------------------*/
|
|
@ -1,163 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2002-2004, Adam Dunkels.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. 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.
|
||||
* 3. The name of the author may not be used to endorse or promote
|
||||
* products derived from this software without specific prior
|
||||
* written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
||||
*
|
||||
* This file is part of the Contiki desktop environment
|
||||
*
|
||||
* $Id: ssfire.c,v 1.1 2007/05/23 23:11:24 oliverschmidt Exp $
|
||||
*
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "ctk/ctk.h"
|
||||
#include "ctk/ctk-draw.h"
|
||||
#include "ctk/ctk-mouse.h"
|
||||
#include "contiki.h"
|
||||
#include "sys/loader.h"
|
||||
|
||||
PROCESS(ssfire_process, "Fire screensaver");
|
||||
|
||||
static unsigned char flames[8*17];
|
||||
|
||||
|
||||
static const unsigned char flamecolors[16] =
|
||||
{COLOR_BLACK, COLOR_BLACK, COLOR_BLACK, COLOR_RED,
|
||||
COLOR_LIGHTRED, COLOR_YELLOW, COLOR_WHITE, COLOR_WHITE,
|
||||
COLOR_WHITE, COLOR_WHITE, COLOR_WHITE, COLOR_WHITE,
|
||||
COLOR_WHITE, COLOR_WHITE, COLOR_WHITE, COLOR_WHITE};
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
fire_init(void)
|
||||
{
|
||||
unsigned char *ptr, *cptr;
|
||||
|
||||
/* Fill screen with inverted spaces. */
|
||||
cptr = COLOR_RAM;
|
||||
for(ptr = (unsigned char *)0x0400;
|
||||
ptr != (unsigned char *)0x07e8;
|
||||
++ptr) {
|
||||
*ptr = 0xa0;
|
||||
*cptr++ = 0x00;
|
||||
}
|
||||
|
||||
SID.v3.freq = 0xffff;
|
||||
SID.v3.ctrl = 0x80;
|
||||
SID.amp = 0;
|
||||
|
||||
VIC.ctrl1 = 0x1b; /* $D011 */
|
||||
VIC.addr = 0x17; /* $D018 */
|
||||
VIC.ctrl2 = 0xc8; /* $D016 */
|
||||
VIC.bordercolor = 0x00; /* $D020 */
|
||||
VIC.bgcolor0 = 0x00; /* $D021 */
|
||||
CIA2.pra = 0x03; /* $DD00 */
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#pragma optimize(push, off)
|
||||
static void
|
||||
fire_burn(void)
|
||||
{
|
||||
/* Calculate new flames. */
|
||||
asm("ldy #$00");
|
||||
loop1:
|
||||
asm("lda %v+7,y", flames);
|
||||
asm("clc");
|
||||
asm("adc %v+8,y", flames);
|
||||
asm("adc %v+9,y", flames);
|
||||
asm("adc %v+16,y", flames);
|
||||
asm("lsr");
|
||||
asm("lsr");
|
||||
asm("sta %v,y", flames);
|
||||
asm("iny");
|
||||
asm("cpy #(8*15)");
|
||||
asm("bne %g", loop1);
|
||||
|
||||
/* Fill last line with pseudo-random data from noise generator on
|
||||
voice 3. */
|
||||
asm("ldy #$05");
|
||||
loop2:
|
||||
asm("ldx #$20");
|
||||
delay:
|
||||
asm("dex");
|
||||
asm("bne %g", delay);
|
||||
asm("lda $D41B");
|
||||
asm("and #$0F");
|
||||
asm("sta %v+8*15+1,y", flames);
|
||||
asm("dey");
|
||||
asm("bpl %g", loop2);
|
||||
}
|
||||
#pragma optimize(pop)
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static unsigned char *flameptr, *colorptr1, *colorptr2;
|
||||
static unsigned char x, y;
|
||||
|
||||
static void
|
||||
pollhandler(void)
|
||||
{
|
||||
|
||||
if(ctk_mode_get() == CTK_MODE_SCREENSAVER) {
|
||||
|
||||
fire_burn();
|
||||
|
||||
/* Display flames on screen. */
|
||||
flameptr = flames;
|
||||
colorptr1 = COLOR_RAM + 40*10;
|
||||
colorptr2 = colorptr1 + 0x20;
|
||||
for(y = 0; y < 15; ++y) {
|
||||
for(x = 0; x < 8; ++x) {
|
||||
colorptr1[x] = colorptr2[x] = flamecolors[flameptr[x]];
|
||||
}
|
||||
colorptr1 += 0x28;
|
||||
colorptr2 += 0x28;
|
||||
flameptr += 8;
|
||||
}
|
||||
}
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
PROCESS_THREAD(ssfire_process, ev, data)
|
||||
{
|
||||
PROCESS_POLLHANDLER(pollhandler());
|
||||
|
||||
PROCESS_BEGIN();
|
||||
|
||||
ctk_mode_set(CTK_MODE_SCREENSAVER);
|
||||
ctk_mouse_hide();
|
||||
fire_init();
|
||||
|
||||
|
||||
PROCESS_WAIT_EVENT_UNTIL(ev == ctk_signal_screensaver_stop ||
|
||||
ev == PROCESS_EVENT_EXIT);
|
||||
|
||||
ctk_draw_init();
|
||||
ctk_desktop_redraw(NULL);
|
||||
|
||||
PROCESS_END();
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
|
@ -1,52 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2003, Adam Dunkels.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. 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.
|
||||
* 3. The name of the author may not be used to endorse or promote
|
||||
* products derived from this software without specific prior
|
||||
* written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
||||
*
|
||||
* This file is part of the Contiki desktop environment
|
||||
*
|
||||
* $Id: themeloader.c,v 1.1 2007/05/23 23:11:25 oliverschmidt Exp $
|
||||
*
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "loader.h"
|
||||
#include "ctk-draw.h"
|
||||
#include "ctk-hires-theme.h"
|
||||
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
LOADER_INIT_FUNC(themeloader_init, arg)
|
||||
{
|
||||
arg_free(arg);
|
||||
|
||||
memcpy(ctk_hires_theme_ptr, &ctk_hires_theme,
|
||||
sizeof(struct ctk_hires_theme));
|
||||
ctk_draw_init();
|
||||
LOADER_UNLOAD();
|
||||
}
|
||||
/*-----------------------------------------------------------------------------------*/
|
|
@ -1,16 +0,0 @@
|
|||
|
||||
;---------------------------------------------------------------------
|
||||
.importzp ptr1, ptr2, ptr3, ptr4, sreg
|
||||
.importzp sp
|
||||
|
||||
.import _vnc_draw_datalen
|
||||
.import _vnc_draw_dataptr
|
||||
.import _vnc_draw_bitmapptr
|
||||
.import _vnc_draw_x
|
||||
.import _vnc_draw_y
|
||||
;---------------------------------------------------------------------
|
||||
.bss
|
||||
;---------------------------------------------------------------------
|
||||
.data
|
||||
;---------------------------------------------------------------------
|
||||
.code
|
|
@ -1,42 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2003, Adam Dunkels.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. 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.
|
||||
* 3. The name of the author may not be used to endorse or promote
|
||||
* products derived from this software without specific prior
|
||||
* written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
||||
*
|
||||
* This file is part of the Contiki VNC client
|
||||
*
|
||||
* $Id: vnc-draw-asm.h,v 1.1 2007/05/23 23:11:26 oliverschmidt Exp $
|
||||
*
|
||||
*/
|
||||
#ifndef __VNC_DRAW_ASM_H__
|
||||
#define __VNC_DRAW_ASM_H__
|
||||
|
||||
#include "vnc-draw.h"
|
||||
|
||||
void vnc_draw_asm_pixelline(void);
|
||||
|
||||
#endif /* __VNC_DRAW_ASM_H__ */
|
|
@ -1,689 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2003, Adam Dunkels.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. 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.
|
||||
* 3. The name of the author may not be used to endorse or promote
|
||||
* products derived from this software without specific prior
|
||||
* written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
||||
*
|
||||
* This file is part of the Contiki VNC client
|
||||
*
|
||||
* $Id: vnc-draw.c,v 1.1 2007/05/23 23:11:26 oliverschmidt Exp $
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
|
||||
#include "vnc-draw.h"
|
||||
#include "vnc-draw-asm.h"
|
||||
|
||||
#include "vnc-conf.h"
|
||||
|
||||
|
||||
static unsigned char conv[256];
|
||||
|
||||
static unsigned char oratab[8] =
|
||||
{ 0x80, 0x40, 0x20, 0x10,
|
||||
0x08, 0x04, 0x02, 0x01 };
|
||||
static unsigned char andtab[8] =
|
||||
{ 0x7f, 0xbf, 0xdf, 0xef,
|
||||
0xf7, 0xfb, 0xfd, 0xfe };
|
||||
|
||||
static u8_t *bitmapptrtab[VNC_CONF_VIEWPORT_HEIGHT];
|
||||
|
||||
static unsigned short viewport_x,
|
||||
viewport_y, viewport_w, viewport_h;
|
||||
|
||||
u8_t vnc_draw_bitmap[(VNC_CONF_VIEWPORT_WIDTH / 8) *
|
||||
VNC_CONF_VIEWPORT_HEIGHT];
|
||||
|
||||
|
||||
|
||||
u16_t vnc_draw_x;
|
||||
u16_t vnc_draw_y;
|
||||
u8_t *vnc_draw_dataptr;
|
||||
u8_t *vnc_draw_bitmapptr;
|
||||
u16_t vnc_draw_datalen;
|
||||
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
void
|
||||
vnc_draw_pixel(u16_t x, u8_t y, u8_t c)
|
||||
{
|
||||
u8_t o, a;
|
||||
|
||||
vnc_draw_bitmapptr = bitmapptrtab[y] + (x & 0x1f8);
|
||||
|
||||
if(c) {
|
||||
o = oratab[x & 7];
|
||||
*vnc_draw_bitmapptr = *vnc_draw_bitmapptr | o;
|
||||
} else {
|
||||
a = andtab[x & 7];
|
||||
*vnc_draw_bitmapptr = *vnc_draw_bitmapptr & a;
|
||||
}
|
||||
}
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
void
|
||||
vnc_draw_pixelline(u16_t x, u16_t y, u8_t *data, u16_t datalen)
|
||||
{
|
||||
u8_t o, a;
|
||||
register u8_t *bitmapptr;
|
||||
|
||||
vnc_draw_x = x - viewport_x;
|
||||
vnc_draw_y = y - viewport_y;
|
||||
|
||||
/* if(vnc_draw_y & 1) {
|
||||
return;
|
||||
} else {
|
||||
vnc_draw_y /= 2;
|
||||
}*/
|
||||
|
||||
|
||||
|
||||
if(vnc_draw_y >= VNC_CONF_VIEWPORT_HEIGHT ||
|
||||
vnc_draw_x >= VNC_CONF_VIEWPORT_WIDTH) {
|
||||
return;
|
||||
}
|
||||
|
||||
vnc_draw_datalen = datalen;
|
||||
|
||||
if(vnc_draw_datalen + vnc_draw_x >= VNC_CONF_VIEWPORT_WIDTH) {
|
||||
vnc_draw_datalen = VNC_CONF_VIEWPORT_WIDTH - vnc_draw_x;
|
||||
if(vnc_draw_datalen == 0) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
vnc_draw_dataptr = data;
|
||||
|
||||
/* vnc_draw_bitmapptr = bitmaptab[vnc_draw_y] +
|
||||
(vnc_draw_x & 0x1f8);*/
|
||||
|
||||
for(; vnc_draw_datalen > 0; --vnc_draw_datalen) {
|
||||
/* vnc_draw_pixel(vnc_draw_x, vnc_draw_y,
|
||||
conv[*vnc_draw_dataptr]);*/
|
||||
|
||||
bitmapptr = bitmapptrtab[vnc_draw_y] + (vnc_draw_x & 0x1f8);
|
||||
|
||||
if(conv[*vnc_draw_dataptr]) {
|
||||
o = oratab[vnc_draw_x & 7];
|
||||
*bitmapptr = *bitmapptr | o;
|
||||
} else {
|
||||
a = andtab[vnc_draw_x & 7];
|
||||
*bitmapptr = *bitmapptr & a;
|
||||
}
|
||||
++vnc_draw_dataptr;
|
||||
++vnc_draw_x;
|
||||
}
|
||||
}
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
void
|
||||
vnc_draw_init(void)
|
||||
{
|
||||
unsigned int tmp;
|
||||
unsigned int i;
|
||||
unsigned short ptr;
|
||||
|
||||
|
||||
/* Create color conversion table. */
|
||||
for(i = 0; i < 256; ++i) {
|
||||
if(((i & 0xc0) > 0xc0) ||
|
||||
((i & 0x38) > 0x18) ||
|
||||
((i & 0x07) > 0x03)) {
|
||||
conv[i] = 0;
|
||||
} else {
|
||||
conv[i] = 1;
|
||||
}
|
||||
}
|
||||
|
||||
memset(vnc_draw_bitmap, 0, sizeof(vnc_draw_bitmap));
|
||||
|
||||
for(i = 0; i < VNC_CONF_VIEWPORT_HEIGHT; ++i) {
|
||||
bitmapptrtab[i] = (u8_t *)((u16_t)vnc_draw_bitmap +
|
||||
((i & 0xfff8)/8) * VNC_CONF_VIEWPORT_WIDTH +
|
||||
(i & 7));
|
||||
}
|
||||
|
||||
viewport_x = 0;
|
||||
viewport_y = 0;
|
||||
|
||||
viewport_w = VNC_CONF_VIEWPORT_WIDTH;
|
||||
viewport_h = VNC_CONF_VIEWPORT_HEIGHT;
|
||||
|
||||
return;
|
||||
}
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
u16_t
|
||||
vnc_draw_viewport_x(void)
|
||||
{
|
||||
return viewport_x;
|
||||
}
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
u16_t
|
||||
vnc_draw_viewport_y(void)
|
||||
{
|
||||
return viewport_y;
|
||||
}
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
u16_t
|
||||
vnc_draw_viewport_w(void)
|
||||
{
|
||||
return viewport_w;
|
||||
}
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
u16_t
|
||||
vnc_draw_viewport_h(void)
|
||||
{
|
||||
return viewport_h;
|
||||
}
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
#if 0
|
||||
signed short
|
||||
c64_mouse_x(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
signed short
|
||||
c64_mouse_y(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
u8_t
|
||||
c64_mouse_buttons(void)
|
||||
{
|
||||
return firebutton;
|
||||
}
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
void
|
||||
c64_set_mouse_x(unsigned short x)
|
||||
{
|
||||
joyx = x;
|
||||
}
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
void
|
||||
c64_set_mouse_y(unsigned short y)
|
||||
{
|
||||
joyy = y;
|
||||
}
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
void
|
||||
c64_set_viewport_x(unsigned short x)
|
||||
{
|
||||
viewport_x = x;
|
||||
}
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
void
|
||||
c64_set_viewport_y(unsigned short y)
|
||||
{
|
||||
viewport_y = y;
|
||||
}
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
|
||||
#endif /* 0 */
|
||||
#if 0
|
||||
#pragma optimize(push, off)
|
||||
void
|
||||
c64_scroll_up(unsigned char c)
|
||||
{
|
||||
asm("lda $f7");
|
||||
asm("pha");
|
||||
asm("lda $f8");
|
||||
asm("pha");
|
||||
asm("lda $f9");
|
||||
asm("pha");
|
||||
asm("lda $fa");
|
||||
asm("pha");
|
||||
asm("lda $fb");
|
||||
asm("pha");
|
||||
asm("lda $fc");
|
||||
asm("pha");
|
||||
asm("lda $fd");
|
||||
asm("pha");
|
||||
asm("lda $fe");
|
||||
asm("pha");
|
||||
|
||||
asm("lda $01");
|
||||
asm("pha");
|
||||
asm("lda #$35");
|
||||
asm("sta $01");
|
||||
|
||||
asm("lda #$80");
|
||||
asm("sta $f7");
|
||||
asm("lda #$a2");
|
||||
asm("sta $f8");
|
||||
asm("lda #$00");
|
||||
asm("sta $f9");
|
||||
asm("lda #$a0");
|
||||
asm("sta $fa");
|
||||
|
||||
asm("lda #$80");
|
||||
asm("sta $fb");
|
||||
asm("lda #$e2");
|
||||
asm("sta $fc");
|
||||
asm("lda #$00");
|
||||
asm("sta $fd");
|
||||
asm("lda #$e0");
|
||||
asm("sta $fe");
|
||||
|
||||
asm("ldy #0");
|
||||
asm("loop:");
|
||||
asm("lda ($f7),y");
|
||||
asm("sta ($f9),y");
|
||||
asm("lda ($fb),y");
|
||||
asm("sta ($fd),y");
|
||||
asm("iny");
|
||||
asm("bne loop");
|
||||
|
||||
asm("inc $f8");
|
||||
asm("inc $fa");
|
||||
asm("inc $fc");
|
||||
asm("inc $fe");
|
||||
|
||||
asm("lda $fc");
|
||||
asm("cmp #$00");
|
||||
asm("bne loop");
|
||||
|
||||
asm("ldy #0");
|
||||
asm("lda #0");
|
||||
asm("sta $fe00,y");
|
||||
asm("sta $be00,y");
|
||||
asm("sta $fcc0,y");
|
||||
asm("sta $bcc0,y");
|
||||
asm("iny");
|
||||
asm("bne *-13");
|
||||
asm("sta $ff00,y");
|
||||
asm("sta $bf00,y");
|
||||
asm("sta $fdc0,y");
|
||||
asm("sta $bdc0,y");
|
||||
asm("iny");
|
||||
asm("cpy #$40");
|
||||
asm("bne *-15");
|
||||
|
||||
|
||||
asm("pla");
|
||||
asm("sta $01");
|
||||
asm("pla");
|
||||
asm("sta $fe");
|
||||
asm("pla");
|
||||
asm("sta $fd");
|
||||
asm("pla");
|
||||
asm("sta $fc");
|
||||
asm("pla");
|
||||
asm("sta $fb");
|
||||
asm("pla");
|
||||
asm("sta $fa");
|
||||
asm("pla");
|
||||
asm("sta $f9");
|
||||
asm("pla");
|
||||
asm("sta $f8");
|
||||
asm("pla");
|
||||
asm("sta $f7");
|
||||
}
|
||||
#pragma optimize(pop)
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
#pragma optimize(push, off)
|
||||
void
|
||||
c64_scroll_down(unsigned char c)
|
||||
{
|
||||
asm("lda $f7");
|
||||
asm("pha");
|
||||
asm("lda $f8");
|
||||
asm("pha");
|
||||
asm("lda $f9");
|
||||
asm("pha");
|
||||
asm("lda $fa");
|
||||
asm("pha");
|
||||
asm("lda $fb");
|
||||
asm("pha");
|
||||
asm("lda $fc");
|
||||
asm("pha");
|
||||
asm("lda $fd");
|
||||
asm("pha");
|
||||
asm("lda $fe");
|
||||
asm("pha");
|
||||
|
||||
|
||||
asm("lda $01");
|
||||
asm("pha");
|
||||
asm("lda #$35");
|
||||
asm("sta $01");
|
||||
|
||||
asm("lda #$c0");
|
||||
asm("sta $fb");
|
||||
asm("lda #$fb");
|
||||
asm("sta $fc");
|
||||
asm("lda #$40");
|
||||
asm("sta $fd");
|
||||
asm("lda #$fe");
|
||||
asm("sta $fe");
|
||||
|
||||
asm("lda #$c0");
|
||||
asm("sta $f7");
|
||||
asm("lda #$bb");
|
||||
asm("sta $f8");
|
||||
asm("lda #$40");
|
||||
asm("sta $f9");
|
||||
asm("lda #$be");
|
||||
asm("sta $fa");
|
||||
|
||||
|
||||
asm("ldy #0");
|
||||
asm("loop:");
|
||||
asm("lda ($fb),y");
|
||||
asm("sta ($fd),y");
|
||||
asm("lda ($f7),y");
|
||||
asm("sta ($f9),y");
|
||||
asm("iny");
|
||||
asm("bne loop");
|
||||
|
||||
asm("dec $f8");
|
||||
asm("dec $fa");
|
||||
asm("dec $fc");
|
||||
asm("dec $fe");
|
||||
|
||||
|
||||
asm("lda $fe");
|
||||
asm("cmp #$df");
|
||||
asm("bne loop");
|
||||
|
||||
asm("ldy #0");
|
||||
asm("lda #0");
|
||||
asm("sta $e000,y");
|
||||
asm("sta $a000,y");
|
||||
asm("sta $e140,y");
|
||||
asm("sta $a140,y");
|
||||
asm("iny");
|
||||
asm("bne *-13");
|
||||
asm("sta $e100,y");
|
||||
asm("sta $a100,y");
|
||||
asm("sta $e240,y");
|
||||
asm("sta $a240,y");
|
||||
asm("iny");
|
||||
asm("cpy #$40");
|
||||
asm("bne *-15");
|
||||
|
||||
asm("pla");
|
||||
asm("sta $01");
|
||||
asm("pla");
|
||||
asm("sta $fe");
|
||||
asm("pla");
|
||||
asm("sta $fd");
|
||||
asm("pla");
|
||||
asm("sta $fc");
|
||||
asm("pla");
|
||||
asm("sta $fb");
|
||||
asm("pla");
|
||||
asm("sta $fa");
|
||||
asm("pla");
|
||||
asm("sta $f9");
|
||||
asm("pla");
|
||||
asm("sta $f8");
|
||||
asm("pla");
|
||||
asm("sta $f7");
|
||||
}
|
||||
#pragma optimize(pop)
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
#pragma optimize(push, off)
|
||||
void
|
||||
c64_scroll_right(unsigned char c)
|
||||
{
|
||||
asm("lda $f7");
|
||||
asm("pha");
|
||||
asm("lda $f8");
|
||||
asm("pha");
|
||||
asm("lda $f9");
|
||||
asm("pha");
|
||||
asm("lda $fa");
|
||||
asm("pha");
|
||||
asm("lda $fb");
|
||||
asm("pha");
|
||||
asm("lda $fc");
|
||||
asm("pha");
|
||||
asm("lda $fd");
|
||||
asm("pha");
|
||||
asm("lda $fe");
|
||||
asm("pha");
|
||||
|
||||
|
||||
asm("lda $01");
|
||||
asm("pha");
|
||||
asm("lda #$35");
|
||||
asm("sta $01");
|
||||
|
||||
asm("lda #$00");
|
||||
asm("sta $f7");
|
||||
asm("lda #$a0");
|
||||
asm("sta $f8");
|
||||
asm("lda #$10");
|
||||
asm("sta $f9");
|
||||
asm("lda #$a0");
|
||||
asm("sta $fa");
|
||||
|
||||
asm("lda #$00");
|
||||
asm("sta $fb");
|
||||
asm("lda #$e0");
|
||||
asm("sta $fc");
|
||||
asm("lda #$10");
|
||||
asm("sta $fd");
|
||||
asm("lda #$e0");
|
||||
asm("sta $fe");
|
||||
|
||||
asm("ldx #0");
|
||||
|
||||
asm("loop3:");
|
||||
|
||||
asm("ldy #$ff");
|
||||
asm("loop:");
|
||||
asm("lda ($f7),y");
|
||||
asm("sta ($f9),y");
|
||||
asm("lda ($fb),y");
|
||||
asm("sta ($fd),y");
|
||||
asm("dey");
|
||||
asm("cpy #$ff");
|
||||
asm("bne loop");
|
||||
|
||||
asm("inc $f8");
|
||||
asm("inc $fa");
|
||||
asm("inc $fc");
|
||||
asm("inc $fe");
|
||||
|
||||
asm("ldy #$30");
|
||||
asm("loop2:");
|
||||
asm("lda ($f7),y");
|
||||
asm("sta ($f9),y");
|
||||
asm("lda ($fb),y");
|
||||
asm("sta ($fd),y");
|
||||
asm("dey");
|
||||
asm("cpy #$ff");
|
||||
asm("bne loop2");
|
||||
|
||||
asm("lda $f7");
|
||||
asm("clc");
|
||||
asm("adc #$40");
|
||||
asm("sta $f7");
|
||||
asm("sta $fb");
|
||||
asm("bcc :+");
|
||||
asm("inc $f8");
|
||||
asm("inc $fc");
|
||||
asm(":");
|
||||
|
||||
asm("lda $f9");
|
||||
asm("clc");
|
||||
asm("adc #$40");
|
||||
asm("sta $f9");
|
||||
asm("sta $fd");
|
||||
asm("bcc :+");
|
||||
asm("inc $fa");
|
||||
asm("inc $fe");
|
||||
asm(":");
|
||||
|
||||
|
||||
|
||||
asm("inx");
|
||||
asm("cpx #24");
|
||||
asm("bne loop3");
|
||||
|
||||
asm("pla");
|
||||
asm("sta $01");
|
||||
asm("pla");
|
||||
asm("sta $fe");
|
||||
asm("pla");
|
||||
asm("sta $fd");
|
||||
asm("pla");
|
||||
asm("sta $fc");
|
||||
asm("pla");
|
||||
asm("sta $fb");
|
||||
asm("pla");
|
||||
asm("sta $fa");
|
||||
asm("pla");
|
||||
asm("sta $f9");
|
||||
asm("pla");
|
||||
asm("sta $f8");
|
||||
asm("pla");
|
||||
asm("sta $f7");
|
||||
}
|
||||
#pragma optimize(pop)
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
#pragma optimize(push, off)
|
||||
void
|
||||
c64_scroll_left(unsigned char c)
|
||||
{
|
||||
asm("lda $f7");
|
||||
asm("pha");
|
||||
asm("lda $f8");
|
||||
asm("pha");
|
||||
asm("lda $f9");
|
||||
asm("pha");
|
||||
asm("lda $fa");
|
||||
asm("pha");
|
||||
asm("lda $fb");
|
||||
asm("pha");
|
||||
asm("lda $fc");
|
||||
asm("pha");
|
||||
asm("lda $fd");
|
||||
asm("pha");
|
||||
asm("lda $fe");
|
||||
asm("pha");
|
||||
|
||||
|
||||
asm("lda $01");
|
||||
asm("pha");
|
||||
asm("lda #$35");
|
||||
asm("sta $01");
|
||||
|
||||
asm("lda #$10");
|
||||
asm("sta $f7");
|
||||
asm("lda #$a0");
|
||||
asm("sta $f8");
|
||||
asm("lda #$00");
|
||||
asm("sta $f9");
|
||||
asm("lda #$a0");
|
||||
asm("sta $fa");
|
||||
|
||||
asm("lda #$10");
|
||||
asm("sta $fb");
|
||||
asm("lda #$e0");
|
||||
asm("sta $fc");
|
||||
asm("lda #$00");
|
||||
asm("sta $fd");
|
||||
asm("lda #$e0");
|
||||
asm("sta $fe");
|
||||
|
||||
asm("ldx #0");
|
||||
asm("loop3:");
|
||||
asm("ldy #0");
|
||||
asm("loop:");
|
||||
asm("lda ($f7),y");
|
||||
asm("sta ($f9),y");
|
||||
asm("lda ($fb),y");
|
||||
asm("sta ($fd),y");
|
||||
asm("iny");
|
||||
asm("bne loop");
|
||||
|
||||
asm("inc $f8");
|
||||
asm("inc $fa");
|
||||
asm("inc $fc");
|
||||
asm("inc $fe");
|
||||
|
||||
asm("ldy #0");
|
||||
asm("loop2:");
|
||||
asm("lda ($f7),y");
|
||||
asm("sta ($f9),y");
|
||||
asm("lda ($fb),y");
|
||||
asm("sta ($fd),y");
|
||||
asm("iny");
|
||||
asm("cpy #$30");
|
||||
asm("bne loop2");
|
||||
|
||||
asm("lda $f7");
|
||||
asm("clc");
|
||||
asm("adc #$40");
|
||||
asm("sta $f7");
|
||||
asm("sta $fb");
|
||||
asm("bcc :+");
|
||||
asm("inc $f8");
|
||||
asm("inc $fc");
|
||||
asm(":");
|
||||
|
||||
asm("lda $f9");
|
||||
asm("clc");
|
||||
asm("adc #$40");
|
||||
asm("sta $f9");
|
||||
asm("sta $fd");
|
||||
asm("bcc :+");
|
||||
asm("inc $fa");
|
||||
asm("inc $fe");
|
||||
asm(":");
|
||||
|
||||
|
||||
asm("inx");
|
||||
asm("cpx #24");
|
||||
asm("bne loop3");
|
||||
|
||||
asm("pla");
|
||||
asm("sta $01");
|
||||
asm("pla");
|
||||
asm("sta $fe");
|
||||
asm("pla");
|
||||
asm("sta $fd");
|
||||
asm("pla");
|
||||
asm("sta $fc");
|
||||
asm("pla");
|
||||
asm("sta $fb");
|
||||
asm("pla");
|
||||
asm("sta $fa");
|
||||
asm("pla");
|
||||
asm("sta $f9");
|
||||
asm("pla");
|
||||
asm("sta $f8");
|
||||
asm("pla");
|
||||
asm("sta $f7");
|
||||
}
|
||||
#pragma optimize(pop)
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
|
||||
#endif /* 0 */
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue