summaryrefslogtreecommitdiffstats
path: root/c/src/lib/libbsp/m68k/idp
diff options
context:
space:
mode:
Diffstat (limited to 'c/src/lib/libbsp/m68k/idp')
-rw-r--r--c/src/lib/libbsp/m68k/idp/clock/ckinit.c129
-rw-r--r--c/src/lib/libbsp/m68k/idp/console/console.c176
-rw-r--r--c/src/lib/libbsp/m68k/idp/include/bsp.h19
-rw-r--r--c/src/lib/libbsp/m68k/idp/startup/bspstart.c61
4 files changed, 303 insertions, 82 deletions
diff --git a/c/src/lib/libbsp/m68k/idp/clock/ckinit.c b/c/src/lib/libbsp/m68k/idp/clock/ckinit.c
index b27e9bbe38..7966fc61d1 100644
--- a/c/src/lib/libbsp/m68k/idp/clock/ckinit.c
+++ b/c/src/lib/libbsp/m68k/idp/clock/ckinit.c
@@ -26,9 +26,8 @@
#include <stdlib.h>
-#include <rtems.h>
-#include <clockdrv.h>
#include <bsp.h>
+#include <rtems/libio.h>
rtems_unsigned32 Clock_isrs; /* ISRs until next tick */
volatile rtems_unsigned32 Clock_driver_ticks;
@@ -39,30 +38,53 @@ extern rtems_configuration_table Configuration;
extern void led_putnum();
void Disable_clock();
-#define TIMER_VECTOR 0x4D
+#define CLOCK_VECTOR 0x4D
-rtems_device_driver Clock_initialize(
- rtems_device_major_number major,
- rtems_device_minor_number minor,
- void *pargp,
- rtems_id tid,
- rtems_unsigned32 *rval
-)
-{
- Install_clock( Clock_isr );
-}
+void Clock_exit( void );
+
+/*
+ * These are set by clock driver during its init
+ */
+
+rtems_device_major_number rtems_clock_major = ~0;
+rtems_device_minor_number rtems_clock_minor;
+
-void ReInstall_clock( clock_isr )
-rtems_isr_entry clock_isr;
-{
- rtems_unsigned32 isrlevel = 0 ;
+/*
+ * ISR Handler
+ *
+ *
+ * ((1ms * 6.5 MHz) / 2^5) = 203.125) where 6.5 MHz is the clock rate of the
+ * MC68230, 2^5 is the prescaler factor, and 1ms is the common interrupt
+ * interval for the Clock_isr routine.
+ * Therefore, 203 (decimal) is the number to program into the CPRH-L registers
+ * of the MC68230 for countdown. However, I have found that 193 instead of
+ * 203 provides greater accuracy -- why? The crystal should be more accurate
+ * than that
+ */
- rtems_interrupt_disable( isrlevel );
- (void) set_vector( clock_isr, TIMER_VECTOR, 1 );
- rtems_interrupt_enable( isrlevel );
+rtems_isr Clock_isr(
+ rtems_vector_number vector
+)
+{
+ Clock_driver_ticks += 1;
+ /* acknowledge interrupt
+ TSR = 1; */
+ MC68230_WRITE (TSR, 1);
+
+ if ( Clock_isrs == 1 ) {
+ rtems_clock_tick();
+ /* Cast to an integer so that 68EC040 IDP which doesn't have an FPU doesn't
+ have a heart attack -- if you use newlib1.6 or greater and get
+ libgcc.a for gcc with software floating point support, this is not
+ a problem */
+ Clock_isrs =
+ (int)(BSP_Configuration.microseconds_per_tick / 1000);
+ }
+ else
+ Clock_isrs -= 1;
}
-/* The following was added for debugging purposes */
void Disable_clock()
{
/* Disable timer */
@@ -77,7 +99,7 @@ rtems_isr_entry clock_isr;
if ( Configuration.ticks_per_timeslice ) {
/* led_putnum('c'); * for debugging purposes */
- Old_ticker = (rtems_isr_entry) set_vector( clock_isr, TIMER_VECTOR, 1 );
+ Old_ticker = (rtems_isr_entry) set_vector( clock_isr, CLOCK_VECTOR, 1 );
/* Disable timer for initialization */
MC68230_WRITE (TCR, 0x00);
@@ -85,8 +107,8 @@ rtems_isr_entry clock_isr;
/* some PI/T initialization stuff here -- see comment in the ckisr.c
file in this directory to understand why I use the values that I do */
/* Set up the interrupt vector on the MC68230 chip:
- TIVR = TIMER_VECTOR; */
- MC68230_WRITE (TIVR, TIMER_VECTOR);
+ TIVR = CLOCK_VECTOR; */
+ MC68230_WRITE (TIVR, CLOCK_VECTOR);
/* Set CPRH through CPRL to 193 (not 203) decimal for countdown--see ckisr.c
CPRH = 0x00;
@@ -108,6 +130,17 @@ rtems_isr_entry clock_isr;
}
}
+void ReInstall_clock( clock_isr )
+rtems_isr_entry clock_isr;
+{
+ rtems_unsigned32 isrlevel = 0 ;
+
+ rtems_interrupt_disable( isrlevel );
+ (void) set_vector( clock_isr, CLOCK_VECTOR, 1 );
+ rtems_interrupt_enable( isrlevel );
+}
+
+/* The following was added for debugging purposes */
void Clock_exit( void )
{
rtems_unsigned8 data;
@@ -123,3 +156,51 @@ void Clock_exit( void )
/* do not restore old vector */
}
}
+
+rtems_device_driver Clock_initialize(
+ rtems_device_major_number major,
+ rtems_device_minor_number minor,
+ void *pargp
+)
+{
+ Install_clock( Clock_isr );
+
+ /*
+ * make major/minor avail to others such as shared memory driver
+ */
+
+ rtems_clock_major = major;
+ rtems_clock_minor = minor;
+
+ return RTEMS_SUCCESSFUL;
+}
+
+rtems_device_driver Clock_control(
+ rtems_device_major_number major,
+ rtems_device_minor_number minor,
+ void *pargp
+)
+{
+ rtems_libio_ioctl_args_t *args = pargp;
+
+ if (args == 0)
+ goto done;
+
+ /*
+ * This is hokey, but until we get a defined interface
+ * to do this, it will just be this simple...
+ */
+
+ if (args->command == rtems_build_name('I', 'S', 'R', ' '))
+ {
+ Clock_isr(CLOCK_VECTOR);
+ }
+ else if (args->command == rtems_build_name('N', 'E', 'W', ' '))
+ {
+ ReInstall_clock(args->buffer);
+ }
+
+done:
+ return RTEMS_SUCCESSFUL;
+}
+
diff --git a/c/src/lib/libbsp/m68k/idp/console/console.c b/c/src/lib/libbsp/m68k/idp/console/console.c
index 7bb720c120..5540d26fcd 100644
--- a/c/src/lib/libbsp/m68k/idp/console/console.c
+++ b/c/src/lib/libbsp/m68k/idp/console/console.c
@@ -11,17 +11,15 @@
#define MIDP_INIT
-#include "rtems.h"
-#include "console.h"
-#include "bsp.h"
+#include <bsp.h>
+#include <rtems/libio.h>
-#include "ringbuf.h"
+#include <ringbuf.h>
Ring_buffer_t Buffer[ 2 ];
rtems_isr C_Receive_ISR(rtems_vector_number vector);
-
/* console_initialize
*
* This routine initializes the console IO driver.
@@ -36,18 +34,44 @@ rtems_isr C_Receive_ISR(rtems_vector_number vector);
rtems_device_driver console_initialize(
rtems_device_major_number major,
rtems_device_minor_number minor,
- void *arg,
- rtems_id self,
- rtems_unsigned32 *status
+ void *arg
)
{
+ rtems_status_code status;
Ring_buffer_Initialize( &Buffer[ 0 ] );
Ring_buffer_Initialize( &Buffer[ 1 ] );
init_pit();
- *status = RTEMS_SUCCESSFUL;
+ status = rtems_io_register_name(
+ "/dev/console",
+ major,
+ (rtems_device_minor_number) 0
+ );
+
+ if (status != RTEMS_SUCCESSFUL)
+ rtems_fatal_error_occurred(status);
+
+ status = rtems_io_register_name(
+ "/dev/tty00",
+ major,
+ (rtems_device_minor_number) 0
+ );
+
+ if (status != RTEMS_SUCCESSFUL)
+ rtems_fatal_error_occurred(status);
+
+ status = rtems_io_register_name(
+ "/dev/tty01",
+ major,
+ (rtems_device_minor_number) 1
+ );
+
+ if (status != RTEMS_SUCCESSFUL)
+ rtems_fatal_error_occurred(status);
+
+ return RTEMS_SUCCESSFUL;
}
@@ -151,66 +175,108 @@ void outbyte(
}
/*
- * __read -- read bytes from the serial port. Ignore fd, since
- * we only have stdin.
+ * Open entry point
+ */
+
+rtems_device_driver console_open(
+ rtems_device_major_number major,
+ rtems_device_minor_number minor,
+ void * arg
+)
+{
+ return RTEMS_SUCCESSFUL;
+}
+
+/*
+ * Close entry point
+ */
+
+rtems_device_driver console_close(
+ rtems_device_major_number major,
+ rtems_device_minor_number minor,
+ void * arg
+)
+{
+ return RTEMS_SUCCESSFUL;
+}
+
+/*
+ * read bytes from the serial port. We only have stdin.
*/
-int __read(
- int fd,
- char *buf,
- int nbytes
+rtems_device_driver console_read(
+ rtems_device_major_number major,
+ rtems_device_minor_number minor,
+ void * arg
)
{
- int i = 0;
- int port;
-
- /*
- * Map port A to stdin, stdout, and stderr.
- * Map everything else to port B.
- */
-
- if ( fd <= 2 ) port = 0;
- else port = 1;
-
- for (i = 0; i < nbytes; i++) {
- *(buf + i) = inbyte( port );
- if ((*(buf + i) == '\n') || (*(buf + i) == '\r')) {
- (*(buf + i++)) = '\n';
- (*(buf + i)) = 0;
+ rtems_libio_rw_args_t *rw_args;
+ char *buffer;
+ int maximum;
+ int count = 0;
+
+ rw_args = (rtems_libio_rw_args_t *) arg;
+
+ buffer = rw_args->buffer;
+ maximum = rw_args->count;
+
+ if ( minor > 1 )
+ return RTEMS_INVALID_NUMBER;
+
+ for (count = 0; count < maximum; count++) {
+ buffer[ count ] = inbyte( minor );
+ if (buffer[ count ] == '\n' || buffer[ count ] == '\r') {
+ buffer[ count++ ] = '\n';
+ buffer[ count ] = 0;
break;
}
}
- return (i);
+
+ rw_args->bytes_moved = count;
+ return (count >= 0) ? RTEMS_SUCCESSFUL : RTEMS_UNSATISFIED;
}
/*
- * __write -- write bytes to the serial port. Ignore fd, since
- * stdout and stderr are the same. Since we have no filesystem,
- * open will only return an error.
+ * write bytes to the serial port. Stdout and stderr are the same.
*/
-int __write(
- int fd,
- char *buf,
- int nbytes
+rtems_device_driver console_write(
+ rtems_device_major_number major,
+ rtems_device_minor_number minor,
+ void * arg
)
{
- int i;
- int port;
-
- /*
- * Map port A to stdin, stdout, and stderr.
- * Map everything else to port B.
- */
-
- if ( fd <= 2 ) port = 0;
- else port = 1;
-
- for (i = 0; i < nbytes; i++) {
- if (*(buf + i) == '\n') {
- outbyte ('\r', port );
+ int count;
+ int maximum;
+ rtems_libio_rw_args_t *rw_args;
+ char *buffer;
+
+ rw_args = (rtems_libio_rw_args_t *) arg;
+
+ buffer = rw_args->buffer;
+ maximum = rw_args->count;
+
+ if ( minor > 1 )
+ return RTEMS_INVALID_NUMBER;
+
+ for (count = 0; count < maximum; count++) {
+ if ( buffer[ count ] == '\n') {
+ outbyte('\r', minor );
}
- outbyte (*(buf + i), port );
+ outbyte( buffer[ count ], minor );
}
- return (nbytes);
+ return maximum;
+}
+
+/*
+ * IO Control entry point
+ */
+
+rtems_device_driver console_control(
+ rtems_device_major_number major,
+ rtems_device_minor_number minor,
+ void * arg
+)
+{
+ return RTEMS_SUCCESSFUL;
}
diff --git a/c/src/lib/libbsp/m68k/idp/include/bsp.h b/c/src/lib/libbsp/m68k/idp/include/bsp.h
index 68faeba68c..65fcfe1e6e 100644
--- a/c/src/lib/libbsp/m68k/idp/include/bsp.h
+++ b/c/src/lib/libbsp/m68k/idp/include/bsp.h
@@ -10,6 +10,7 @@
#include <rtems.h>
#include <console.h>
+#include <clockdrv.h>
#include <mc68230.h>
#include <mc68681.h>
@@ -52,6 +53,24 @@
#define EXTERN extern
#endif
+/*
+ * Device Driver Table Entries
+ */
+
+/*
+ * NOTE: Use the standard Console driver entry
+ */
+
+/*
+ * NOTE: Use the standard Clock driver entry
+ */
+
+/*
+ * How many libio files we want
+ */
+
+#define BSP_LIBIO_MAX_FDS 20
+
/* miscellaneous stuff assumed to exist */
extern rtems_configuration_table BSP_Configuration;
diff --git a/c/src/lib/libbsp/m68k/idp/startup/bspstart.c b/c/src/lib/libbsp/m68k/idp/startup/bspstart.c
index a0b738c53e..233449282e 100644
--- a/c/src/lib/libbsp/m68k/idp/startup/bspstart.c
+++ b/c/src/lib/libbsp/m68k/idp/startup/bspstart.c
@@ -20,9 +20,17 @@
* $Id$
*/
-#include <rtems.h>
#include <bsp.h>
+#include <rtems/libio.h>
+
#include <libcsupport.h>
+
+#include <string.h>
+#include <fcntl.h>
+
+#ifdef STACK_CHECKER_ON
+#include <stackchk.h>
+#endif
unsigned char *duart_base;
extern struct duart_regs duart_info;
@@ -41,6 +49,8 @@ rtems_configuration_table BSP_Configuration;
rtems_cpu_table Cpu_table;
+char *rtems_progname;
+
/* Initialize whatever libc we are using
* called from postdriver hook
*/
@@ -56,6 +66,14 @@ void bsp_libc_init()
/* Create 64 KByte memory region for RTEMS executive */
RTEMS_Malloc_Initialize((void *) heap_start, 64 * 1024, 0);
+
+ /*
+ * Init the RTEMS libio facility to provide UNIX-like system
+ * calls for use by newlib (ie: provide __open, __close, etc)
+ * Uses malloc() to get area for the iops, so must be after malloc init
+ */
+
+ rtems_libio_init();
/*
* Set up for the libc handling.
@@ -76,7 +94,33 @@ void bsp_libc_init()
}
-int bsp_start(
+/*
+ * After drivers are setup, register some "filenames"
+ * and open stdin, stdout, stderr files
+ *
+ * Newlib will automatically associate the files with these
+ * (it hardcodes the numbers)
+ */
+
+void
+bsp_postdriver_hook(void)
+{
+ int stdin_fd, stdout_fd, stderr_fd;
+
+ if ((stdin_fd = __open("/dev/console", O_RDONLY, 0)) == -1)
+ rtems_fatal_error_occurred('STD0');
+
+ if ((stdout_fd = __open("/dev/console", O_WRONLY, 0)) == -1)
+ rtems_fatal_error_occurred('STD1');
+
+ if ((stderr_fd = __open("/dev/console", O_WRONLY, 0)) == -1)
+ rtems_fatal_error_occurred('STD2');
+
+ if ((stdin_fd != 0) || (stdout_fd != 1) || (stderr_fd != 2))
+ rtems_fatal_error_occurred('STIO');
+}
+
+int main(
int argc,
char **argv,
char **environp
@@ -85,6 +129,11 @@ int bsp_start(
m68k_isr_entry *monitors_vector_table;
int index;
+ if ((argc > 0) && argv && argv[0])
+ rtems_progname = argv[0];
+ else
+ rtems_progname = "RTEMS";
+
duart_base = (unsigned char *)DUART_ADDR;
/*
@@ -121,7 +170,7 @@ int bsp_start(
Cpu_table.predriver_hook = bsp_libc_init; /* RTEMS resources available */
- Cpu_table.postdriver_hook = NULL;
+ Cpu_table.postdriver_hook = bsp_postdriver_hook;
Cpu_table.idle_task = NULL; /* do not override system IDLE task */
@@ -164,6 +213,12 @@ int bsp_start(
BSP_Configuration.maximum_extensions++;
#endif
+ /*
+ * Tell libio how many fd's we want and allow it to tweak config
+ */
+
+ rtems_libio_config(&BSP_Configuration, BSP_LIBIO_MAX_FDS);
+
/* led_putnum('e'); * for debugging purposes only */
rtems_initialize_executive( &BSP_Configuration, &Cpu_table );/* does not return */