De Messemaeker Johan wrote:
>
> Hi,
>
> I'm trying to understand the differences between V1 and V2 of RTL (and
> quite a beginner on RTL in general).
>
> I'd like to port rectangle.c (/examples/v1api/parallel/) to V2 but it
> isn't working.
>
> Where can i find a rewritten version of this example ?
>
> Greetings, Johan
>
Hi Johan,
Here's something similar to make one of the outputs of the parallel port
cycle under RTL2.
Regards, Stuart
////////////////////////////////////////////////////////////////////////////////
//
// Copyright � 1998 Zentropic Computing
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// ZENTROPIC COMPUTING LLC BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
// Except as contained in this notice, the name of the Zentropic Computing LLC
// shall not be used in advertising or otherwise to promote the sale, use or
// other dealings in this Software without prior written authorization from the
// Zentropic Computing LLC
//
// Authors: Stuart Hughes
// Contact: [EMAIL PROTECTED]
// Original date: Fri 22 Oct 1999
// Ident: @(#)$Id$
// Description: flash the parallel port
//
////////////////////////////////////////////////////////////////////////////////
static char id_para_c[] __attribute__ ((unused)) = "@(#)$Id$";
#include <linux/module.h>
#include <asm/io.h>
#include <rtl.h>
#include <posix/pthread.h>
////////////////////////////////////////////////////////////////
// RT module initialisation
///////////////////////////////////////////////////////////////
pthread_t thread;
int init_module(void)
{
void *func(void *arg);
struct sched_param p;
pthread_create (&thread, NULL, func, 0);
pthread_make_periodic_np (thread, gethrtime()+100000, 50000000);
pthread_setfp_np(thread, 1);
p.sched_priority = 1;
pthread_setschedparam (thread, SCHED_FIFO, &p);
return 0;
}
////////////////////////////////////////////////////////////////
// RT thread
///////////////////////////////////////////////////////////////
// debugger test data
typedef struct db_dat_ {
int icounter;
float fcounter;
double dcounter;
int flash_interval;
} DB_DAT;
DB_DAT d = { 0, 0.0f, 0.0, 2 };
#define LPT_PORT 0x378
void parallel(int value, int channel)
{
static int output = 0x0000;
if(value) {
output |= (1 << channel);
} else {
output &= ~(1 << channel);
}
outb(output, LPT_PORT);
}
void *func(void *arg)
{
//char buf[12] = "test"; // would fail, calls implicit memset
char *buf = "wink";
static int led = 1;
while (1) {
// you have to wait here otherwise RTL (pthreads) will run
// one pass before the expected startup pause
pthread_wait_np();
d.icounter++;
d.fcounter += 1.0f;
d.dcounter += 1.0;
if(d.icounter % d.flash_interval == 0) {
led = !led;
parallel(led ,(int)arg);
}
}
}
////////////////////////////////////////////////////////////////
// RT module cleanup
///////////////////////////////////////////////////////////////
void cleanup_module(void)
{
pthread_delete_np(thread);
}
RTSYS = $(shell test -f /usr/src/rtl/rtai; echo $$? )
ifeq ($(RTSYS), 0)
RTFLAGS = -DRTAI
else
RTFLAGS = -D__RT__
endif
KFLAGS = -D__KERNEL__ -DMODULE $(RTFLAGS)
CFLAGS = -I/usr/src/rtl/include -O2 -g -fno-schedule-insns2
all: para_rt.o
para_rt.o : para.c
$(CC) $(CFLAGS) $(KFLAGS) -c -o $@ $^
clean:
rm -f para_rt.o