⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ledif.c

📁 这个是单片机4200的ui程序
💻 C
字号:
/*
 *  Start of Zoran Standard Header
 *  Copyright (c) 2005 Zoran Corporation
 *  
 *  
 *  All rights reserved.  Proprietary and confidential.
 *  
 *  DESCRIPTION for ledif.c
 *      low level LED handler for the Combo user interface board.
 *  
 *  NEW HISTORY COMMENT (description must be followed by a blank line)
 *  <Enter change description here>

 *  ===== HISTORY of changes in //depot/imgeng/sw/se_gw/ui/fs/comboui/ledif.c
 *  
 *  19/Aug/05 #2  dstrauss  Use hwAccess routines to protect hardware accesses.
 *  5/Aug/05 #1  dstrauss Created
 *  
 *  End of Zoran Standard Header
 */

#include "sys.h"
#include "ts.h"
#include "ledif.h"
#include "hwaccess.h"

/* There are 9 LEDs on the Combo UI board attached to
 * two byte-addressable addresses on the system bus.
 * Address 1 controls 8 of the LEDs and address 2
 * controls the 9th LED.  A "1" bit at the appropriate
 * bit position turns the LED off; a "0" bit turns it on.
 *
 * On the top end, callers specify how to set, clear, or toggle
 * the LEDs via a 32-bit-wide interface.  This allows us to
 * control up the 32 LEDs, but of course we only pay attention
 * to the low-order 9 bits.
 *
 */

/* Structure for controlling the LEDs */
typedef struct s_LEDControlStruct {
  Uint8 *LED1addr;              /* where the first LED address is */
  Uint8 *LED2addr;              /* where the second LED address is */
  Uint8  LED1val;               /* current state of the actual hardware */
  Uint8  LED2val;               /* current state of the actual hardware */
  Uint32 LEDStates;             /* abstracted state of all the LED's */
  tsSemaphore LEDSemaphore;     /* access semaphore */
  Bool   initialized;           /* set once we've been initialized */
} LEDControlStruct;

/* Where the LEDs are in the hardware. */

/* at address 1 */
#define LEDHdwQualityNormal  (1<<0)
#define LEDHdwQualityBest    (1<<1)
#define LEDHdwScanTypeText   (1<<2)
#define LEDHdwScanTypeNormal (1<<3)
#define LEDHdwScanTypePhoto  (1<<4)
#define LEDHdwFaxSFine       (1<<5)
#define LEDHdwFaxFine        (1<<6)
#define LEDHdwFaxNormal      (1<<7)

/* at address 2 */
#define LEDHdwQualityDraft   (1<<7)


static LEDControlStruct LEDControl;

void LEDIFinit(void)
{
  LEDControl.LEDSemaphore = INVALIDSEM;
  LEDControl.initialized = FALSE;
  LEDControl.LED1addr = (Uint8 *)0xec0000e0;
  LEDControl.LED2addr = (Uint8 *)0xec0000c0;
  hwAccessLock(FALSE);         /* lock out other accesses */
  *LEDControl.LED1addr = LEDControl.LED1val = 0xff; /* turn off LEDs */
  *LEDControl.LED2addr = LEDControl.LED2val = 0xff; /* turn off LEDs */
  hwAccessUnlock(FALSE);       /* allow other accesses */
  LEDControl.LEDStates = 0;     /* turn off abstracted LEDs */
  LEDControl.LEDSemaphore = TaskSemCreate(1);
  ASSERT( LEDControl.LEDSemaphore != INVALIDSEM);
  if (LEDControl.LEDSemaphore != INVALIDSEM) {
    /* If we got a semaphore, indicate we've been initialized */
    LEDControl.initialized = TRUE;
  }
}


/******************************************************************************
* Name:        LEDIFSetLEDs
*
* Description: Turn LED(s) on and/or off
*
* Parameters:  states   - bitmapped image of LEDs to turn on and/or off.
*                         A "1" bit means to turn the LED on.
*              mask     - bitmapped mask of LEDs to do something to.
*                         A "0" bit means to leave the state of that
*                         LED alone.
*
* Return:      API_OK   - command succeeded.
*              API_FAIL - command failed, interface not initialized.
*
******************************************************************************/

API_RET LEDIFSetLEDs(Uint32 states, Uint32 mask)
{
  Uint8 newval1;
  Uint8 newval2;

  if (!LEDControl.initialized) {
    return (API_FAIL);
  }

  /* Wait for the LED semaphore */
  TASKSEMWAIT(LEDControl.LEDSemaphore);

  /* get current settings */
  newval1 = LEDControl.LED1val;
  newval2 = LEDControl.LED2val;

  /* Build up the new values one LED at a time.  This isn't
   * particularly elegant code, but mapping the abstraction onto the
   * actual hardware is not a particularly elegant problem.
   */
  if (mask & LEDQualityDraft) {
    if (states & LEDQualityDraft) {
      /* turn the LED on (turn the bit off) */
      newval2 &= ~(LEDHdwQualityDraft);
    } else {
      /* turn the LED off (turn the bit on) */
      newval2 |= LEDHdwQualityDraft;
    }
  }
  if (mask & LEDQualityNormal) {
    if (states & LEDQualityNormal) {
      /* turn the LED on (turn the bit off) */
      newval1 &= ~(LEDHdwQualityNormal);
    } else {
      /* turn the LED off (turn the bit on) */
      newval1 |= LEDHdwQualityNormal;
    }
  }
  if (mask & LEDQualityBest) {
    if (states & LEDQualityBest) {
      /* turn the LED on (turn the bit off) */
      newval1 &= ~(LEDHdwQualityBest);
    } else {
      /* turn the LED off (turn the bit on) */
      newval1 |= LEDHdwQualityBest;
    }
  }
  if (mask & LEDScanTypeText) {
    if (states & LEDScanTypeText) {
      /* turn the LED on (turn the bit off) */
      newval1 &= ~(LEDHdwScanTypeText);
    } else {
      /* turn the LED off (turn the bit on) */
      newval1 |= LEDHdwScanTypeText;
    }
  }
  if (mask & LEDScanTypeNormal) {
    if (states & LEDScanTypeNormal) {
      /* turn the LED on (turn the bit off) */
      newval1 &= ~(LEDHdwScanTypeNormal);
    } else {
      /* turn the LED off (turn the bit on) */
      newval1 |= LEDHdwScanTypeNormal;
    }
  }
  if (mask & LEDScanTypePhoto) {
    if (states & LEDScanTypePhoto) {
      /* turn the LED on (turn the bit off) */
      newval1 &= ~(LEDHdwScanTypePhoto);
    } else {
      /* turn the LED off (turn the bit on) */
      newval1 |= LEDHdwScanTypePhoto;
    }
  }
  if (mask & LEDFaxSFine) {
    if (states & LEDFaxSFine) {
      /* turn the LED on (turn the bit off) */
      newval1 &= ~(LEDHdwFaxSFine);
    } else {
      /* turn the LED off (turn the bit on) */
      newval1 |= LEDHdwFaxSFine;
    }
  }
  if (mask & LEDFaxFine) {
    if (states & LEDFaxFine) {
      /* turn the LED on (turn the bit off) */
      newval1 &= ~(LEDHdwFaxFine);
    } else {
      /* turn the LED off (turn the bit on) */
      newval1 |= LEDHdwFaxFine;
    }
  }
  if (mask & LEDFaxNormal) {
    if (states & LEDFaxNormal) {
      /* turn the LED on (turn the bit off) */
      newval1 &= ~(LEDHdwFaxNormal);
    } else {
      /* turn the LED off (turn the bit on) */
      newval1 |= LEDHdwFaxNormal;
    }
  }

  if (newval1 != LEDControl.LED1val || newval2 != LEDControl.LED2val) {
    hwAccessLock(FALSE);      /* lock out other accesses */
    if (newval1 != LEDControl.LED1val) {
      *LEDControl.LED1addr = LEDControl.LED1val = newval1;
    }
    if (newval2 != LEDControl.LED2val) {
      *LEDControl.LED2addr = LEDControl.LED2val = newval2;
    }
    hwAccessUnlock(FALSE);    /* allow accesses */
  }
  /* Release the LED semaphore */
  TASKSEMSIGNAL(LEDControl.LEDSemaphore);

  return (API_OK);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -