[Soekris] Error LED - Idea

Eric Anderson anderson at centtech.com
Mon Feb 18 18:28:05 UTC 2002


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

Eric





Andrew Boothman wrote:
> 
> Andrew Boothman wrote:
> 
> >
> > Could I see the source for that program? I'd be interested to see how
> > to flash the error LED.
> 
> Replying to my own message, the Reply-to: header on my last mail was
> obviously wrong.
> 
> Sorry about that! Please reply to this mail instead.
> 
> Thanks.
> 
> Andrew.

-- 
------------------------------------------------------------------
Eric Anderson	 anderson at centtech.com    Centaur Technology
If at first you don't succeed, sky diving is probably not for you.
------------------------------------------------------------------
-------------- next part --------------
/*-
 * 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