diff options
Diffstat (limited to 'c/src/lib/libbsp/m68k/mvme136')
-rw-r--r-- | c/src/lib/libbsp/m68k/mvme136/clock/ckinit.c | 131 | ||||
-rw-r--r-- | c/src/lib/libbsp/m68k/mvme136/console/console.c | 129 | ||||
-rw-r--r-- | c/src/lib/libbsp/m68k/mvme136/include/bsp.h | 20 | ||||
-rw-r--r-- | c/src/lib/libbsp/m68k/mvme136/startup/bspstart.c | 66 |
4 files changed, 279 insertions, 67 deletions
diff --git a/c/src/lib/libbsp/m68k/mvme136/clock/ckinit.c b/c/src/lib/libbsp/m68k/mvme136/clock/ckinit.c index de88fe9252..195d4a11af 100644 --- a/c/src/lib/libbsp/m68k/mvme136/clock/ckinit.c +++ b/c/src/lib/libbsp/m68k/mvme136/clock/ckinit.c @@ -20,9 +20,8 @@ #include <stdlib.h> -#include <rtems.h> #include <bsp.h> -#include <clockdrv.h> +#include <rtems/libio.h> #include <z8036.h> #define MICRVAL 0xe2 /* disable lower chain, no vec */ @@ -35,31 +34,43 @@ #define T1CSRVAL 0xc6 /* enable interrupt, allow and */ /* and trigger countdown */ +#define TIMER 0xfffb0000 +#define RELOAD 0x24 /* clr IP & IUS,allow countdown */ + +#define CLOCK_VECTOR 66 + rtems_unsigned32 Clock_isrs; /* ISRs until next tick */ -volatile rtems_unsigned32 Clock_driver_ticks; - /* ticks since initialization */ + +volatile rtems_unsigned32 Clock_driver_ticks; /* ticks since initialization */ + rtems_isr_entry Old_ticker; -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 ); -void ReInstall_clock( - rtems_isr_entry clock_isr +/* + * These are set by clock driver during its init + */ + +rtems_device_major_number rtems_clock_major = ~0; +rtems_device_minor_number rtems_clock_minor; + +/* + * ISR Handler + */ + +rtems_isr Clock_isr( + rtems_vector_number vector ) { - rtems_unsigned32 isrlevel; + Clock_driver_ticks += 1; + ((volatile struct z8036_map *) TIMER)->CT1_CMD_STATUS = RELOAD; - rtems_interrupt_disable( isrlevel ); - (void) set_vector( clock_isr, 66, 1 ); - rtems_interrupt_enable( isrlevel ); + if ( Clock_isrs == 1 ) { + rtems_clock_tick(); + Clock_isrs = BSP_Configuration.microseconds_per_tick / 1000; + } + else + Clock_isrs -= 1; } void Install_clock( @@ -72,30 +83,42 @@ void Install_clock( Clock_isrs = BSP_Configuration.microseconds_per_tick / 1000; if ( BSP_Configuration.ticks_per_timeslice ) { - Old_ticker = (rtems_isr_entry) set_vector( clock_isr, 66, 1 ); + Old_ticker = (rtems_isr_entry) set_vector( clock_isr, CLOCK_VECTOR, 1 ); timer = (struct z8036_map *) 0xfffb0000; timer->MASTER_INTR = MICRVAL; timer->CT1_MODE_SPEC = T1MSRVAL; - *((rtems_unsigned16 *)0xfffb0016) = MS_COUNT; /* write countdown value */ -/* - timer->CT1_TIME_CONST_MSB = (MS_COUNT >> 8); - timer->CT1_TIME_CONST_LSB = (MS_COUNT & 0xff); -*/ + *((rtems_unsigned16 *)0xfffb0016) = MS_COUNT; /* write countdown value */ + + /* + * timer->CT1_TIME_CONST_MSB = (MS_COUNT >> 8); + * timer->CT1_TIME_CONST_LSB = (MS_COUNT & 0xff); + */ + timer->MASTER_CFG = MCCRVAL; timer->CT1_CMD_STATUS = T1CSRVAL; -/* - * Enable interrupt via VME interrupt mask register - */ + /* + * Enable interrupt via VME interrupt mask register + */ (*(rtems_unsigned8 *)0xfffb0038) &= 0xfd; - atexit( Clock_exit ); } } +void ReInstall_clock( + rtems_isr_entry clock_isr +) +{ + rtems_unsigned32 isrlevel; + + rtems_interrupt_disable( isrlevel ); + (void) set_vector( clock_isr, CLOCK_VECTOR, 1 ); + rtems_interrupt_enable( isrlevel ); +} + void Clock_exit( void ) { volatile struct z8036_map *timer; @@ -109,3 +132,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/mvme136/console/console.c b/c/src/lib/libbsp/m68k/mvme136/console/console.c index 6bfcf84481..e619fc1428 100644 --- a/c/src/lib/libbsp/m68k/mvme136/console/console.c +++ b/c/src/lib/libbsp/m68k/mvme136/console/console.c @@ -14,9 +14,8 @@ #define M136_INIT -#include <rtems.h> -#include "console.h" -#include "bsp.h" +#include <bsp.h> +#include <rtems/libio.h> /* console_initialize * @@ -32,14 +31,24 @@ 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; + _Write_m681 = ( struct w_m681_info * ) M681ADDR; _Read_m681 = ( struct r_m681_info * ) M681ADDR; - *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); + + return RTEMS_SUCCESSFUL; } @@ -112,48 +121,102 @@ void outbyte( } /* - * __read -- read bytes from the serial port. Ignore fd, since - * we only have stdin. + * Open entry point */ -int __read( - int fd, - char *buf, - int nbytes +rtems_device_driver console_open( + rtems_device_major_number major, + rtems_device_minor_number minor, + void * arg ) { - int i = 0; + 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. + */ - for (i = 0; i < nbytes; i++) { - *(buf + i) = inbyte(); - if ((*(buf + i) == '\n') || (*(buf + i) == '\r')) { - (*(buf + i++)) = '\n'; - (*(buf + i)) = 0; +rtems_device_driver console_read( + rtems_device_major_number major, + rtems_device_minor_number minor, + void * arg +) +{ + 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; + + for (count = 0; count < maximum; count++) { + buffer[ count ] = inbyte(); + 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 count; + int maximum; + rtems_libio_rw_args_t *rw_args; + char *buffer; - for (i = 0; i < nbytes; i++) { - if (*(buf + i) == '\n') { - outbyte ('\r'); + rw_args = (rtems_libio_rw_args_t *) arg; + + buffer = rw_args->buffer; + maximum = rw_args->count; + + for (count = 0; count < maximum; count++) { + if ( buffer[ count ] == '\n') { + outbyte('\r'); } - outbyte (*(buf + i)); + outbyte( buffer[ count ] ); } - 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/mvme136/include/bsp.h b/c/src/lib/libbsp/m68k/mvme136/include/bsp.h index 939a09d41e..85d899ee7c 100644 --- a/c/src/lib/libbsp/m68k/mvme136/include/bsp.h +++ b/c/src/lib/libbsp/m68k/mvme136/include/bsp.h @@ -21,6 +21,8 @@ extern "C" { #endif #include <rtems.h> +#include <clockdrv.h> +#include <console.h> #include <iosupp.h> /* @@ -124,6 +126,24 @@ EXTERN volatile struct w_m681_info *_Write_m681; /* M68681 write registers */ extern m68k_isr_entry M68Kvec[]; /* vector table address */ +/* + * 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 + /* functions */ void bsp_cleanup( void ); diff --git a/c/src/lib/libbsp/m68k/mvme136/startup/bspstart.c b/c/src/lib/libbsp/m68k/mvme136/startup/bspstart.c index 916b495520..5f822855e8 100644 --- a/c/src/lib/libbsp/m68k/mvme136/startup/bspstart.c +++ b/c/src/lib/libbsp/m68k/mvme136/startup/bspstart.c @@ -20,12 +20,18 @@ * $Id$ */ -#include <rtems.h> #include <bsp.h> +#include <rtems/libio.h> + #include <libcsupport.h> #include <z8036.h> -#include "stackchk.h" +#include <string.h> +#include <fcntl.h> + +#ifdef STACK_CHECKER_ON +#include <stackchk.h> +#endif /* * The original table from the application and our copy of it with @@ -37,6 +43,8 @@ rtems_configuration_table BSP_Configuration; rtems_cpu_table Cpu_table; +char *rtems_progname; + /* Initialize whatever libc we are using * called from postdriver hook */ @@ -46,6 +54,10 @@ void bsp_libc_init() extern int end; rtems_unsigned32 heap_start; +#ifdef RTEMS_DEBUG + rtems_debug_enable( RTEMS_DEBUG_ALL_MASK ); +#endif + heap_start = (rtems_unsigned32) &end; if (heap_start & (CPU_ALIGNMENT-1)) heap_start = (heap_start + CPU_ALIGNMENT) & ~(CPU_ALIGNMENT-1); @@ -53,6 +65,14 @@ void bsp_libc_init() 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. */ @@ -70,7 +90,34 @@ void bsp_libc_init() #endif } -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 @@ -79,6 +126,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"; + monitors_vector_table = (m68k_isr_entry *)0; /* 135Bug Vectors are at 0 */ m68k_set_vbr( monitors_vector_table ); @@ -104,7 +156,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 */ @@ -147,6 +199,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); + rtems_initialize_executive( &BSP_Configuration, &Cpu_table ); /* does not return */ |