[Soekris] Error LED - Idea

Soren Kristensen soren at soekris.com
Mon Feb 18 20:04:50 UTC 2002


Hi Eric,

Eric Anderson wrote:
> 
> Here's the led.c source code.  It works fine under FreeBSD, and reportedly on
> OpenBSD also..

Your code seems to be hardcoded to expect the alias of the SC520's MMCR
registers to be at 0x000DF000.... On newer BIOS'es that is not the case.

The recommended way of accessing the MMCR registers is to use the
location always available at 0xFFFEF000.


Regards,


Soren


> ------------------------------------------------------------------
> Eric Anderson    anderson at centtech.com    Centaur Technology
> If at first you don't succeed, sky diving is probably not for you.
> ------------------------------------------------------------------
> 
>   ------------------------------------------------------------------------
> /*-
>  * Copyright (c) 2001 Centaur Technology, Inc.
>  * All rights reserved.
>  *
>  * Eric P Anderson
>  *
>  * 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 the NetBSD
>  *        Foundation, Inc. and its contributors.
>  * 4. Neither the name of The NetBSD Foundation 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 CENTAUR TECHNOLOGY, INC. 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 REGENTS 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.
>  */
> 
> #include <stdio.h>
> #include <strings.h>
> #include <sys/types.h>
> #include <sys/stat.h>
> #include <fcntl.h>
> #include <unistd.h>
> 
> void usage() {
> 
>   fprintf(stderr, "Usage: led -[on,off]\n");
> 
>   exit(-1);
> }
> 
> main(int argc, char **argv) {
> 
>   int     memfd;
>   off_t   offset;
>   ssize_t bytes;
>   char    data;
> 
>   /* Need 1 arg */
>   if (argc != 2) usage();
> 
>   /* Check arg */
>   if ((!strcmp(argv[1], "-on")) || (!strcmp(argv[1], "-ON"))) {
>     offset = 0x000DFC35;
>   } else if ((!strcmp(argv[1], "-off")) || (!strcmp(argv[1], "-OFF"))) {
>     offset = 0x000DFC39;
>   } else {
>     usage();
>   }
> 
>   /* Open memory driver */
>   memfd = open("/dev/mem", O_RDWR);
> 
>   if (memfd == -1) {
>     fprintf(stderr, "couldn't open /dev/mem! You need to be root.\n");
>     exit(-1);
>   }
> 
>   /* seek to offset */
>   offset = lseek(memfd, offset, SEEK_SET);
> 
>   if (offset == -1) {
>     fprintf(stderr, "lseek to offset %08X failed!\n", offset);
>     exit(-1);
>   }
> 
>   /* write data */
>   data = 0x02;
>   bytes = write(memfd, &data, 1);
> 
>   if (bytes != 1) {
>     fprintf(stderr, "write to offset %08X has failed!\n", offset);
>     exit(-1);
>   }
> 
>   /* success */
>   exit(0);
> 
> }



More information about the Soekris-tech mailing list