?? leds.c
字號:
/****************************************************************************
Copyright (C) Cambridge Silicon Radio Ltd. 2006
This file was autogenerated by ledparse and
provides simple LED indications
*/
#include "leds.h"
#include "headset_private.h"
#include <pio.h>
#include <message.h>
#include <panic.h>
#ifdef DEBUG_LEDS
#define LED_DEBUG(x) DEBUG(x)
#else
#define LED_DEBUG(x)
#endif
#define ON (0x1)
#define OFF (0x0)
#define RPT (0x1)
#define LED_UPDATE_MSG (0x0)
typedef struct ledEntryTag
{
uint16 PioMask ; /*mask of pio's*/
unsigned On:1 ;
unsigned Time:15 ; /* ms */
}ledEntry_t ;
typedef struct ledHeaderTag
{
unsigned num_entries:8 ;
unsigned reserved:7 ;
unsigned repeat:1 ;
} ledHeader_t;
typedef struct ledbTag
{
ledHeader_t header ;
ledEntry_t * entries ;
} led_t ;
/*All of The LED pins used*/
static const int gLedPinsUsed = LED_BLUE | LED_RED ;
/*LEDS_OFF*/
static const ledEntry_t pattern_LEDS_OFF [ 1 ] =
{
{ LED_BLUE | LED_RED , OFF , 0 }
};
/*RED_BLUE_ALT_RPT_FAST*/
static const ledEntry_t pattern_RED_BLUE_ALT_RPT_FAST [ 4 ] =
{
{ LED_RED , ON , 100 } ,
{ LED_RED , OFF , 0 } ,
{ LED_BLUE , ON , 100 } ,
{ LED_BLUE , OFF , 0 }
};
/*BLUE_ON*/
static const ledEntry_t pattern_BLUE_ON [ 1 ] =
{
{ LED_BLUE , ON , 0 }
};
/*RED_ON*/
static const ledEntry_t pattern_RED_ON [ 1 ] =
{
{ LED_RED , ON , 0 }
};
/*BLUE_TWO_FLASHES*/
static const ledEntry_t pattern_BLUE_TWO_FLASHES [ 4 ] =
{
{ LED_BLUE , ON , 2000 } ,
{ LED_BLUE , OFF , 200 } ,
{ LED_BLUE , ON , 2000 } ,
{ LED_BLUE , OFF , 200 }
};
/*BLUE_ONE_SEC_ON_RPT*/
static const ledEntry_t pattern_BLUE_ONE_SEC_ON_RPT [ 2 ] =
{
{ LED_BLUE , ON , 1000 } ,
{ LED_BLUE , OFF , 2000 }
};
/*RED_TWO_FLASHES*/
static const ledEntry_t pattern_RED_TWO_FLASHES [ 4 ] =
{
{ LED_RED , ON , 2000 } ,
{ LED_RED , OFF , 200 } ,
{ LED_RED , ON , 2000 } ,
{ LED_RED , OFF , 200 }
};
/*RED_TWO_FLASHES_FAST*/
static const ledEntry_t pattern_RED_TWO_FLASHES_FAST [ 4 ] =
{
{ LED_RED , ON , 200 } ,
{ LED_RED , OFF , 200 } ,
{ LED_RED , ON , 200 } ,
{ LED_RED , OFF , 200 }
};
/*RED_ONE_SEC_ON_RPT*/
static const ledEntry_t pattern_RED_ONE_SEC_ON_RPT [ 2 ] =
{
{ LED_RED , ON , 1000 } ,
{ LED_RED , OFF , 2000 }
};
/*RED_BLUE_ONE_SEC_ON_RPT*/
static const ledEntry_t pattern_RED_BLUE_ONE_SEC_ON_RPT [ 2 ] =
{
{ LED_RED | LED_BLUE , ON , 1000 } ,
{ LED_RED | LED_BLUE , OFF , 2000 }
};
/*RED_CONT_BLUE_ONE_SEC_ON_RPT*/
static const ledEntry_t pattern_RED_CONT_BLUE_ONE_SEC_ON_RPT [ 3 ] =
{
{ LED_RED , ON , 0 } ,
{ LED_BLUE , ON , 1000 } ,
{ LED_BLUE , OFF , 2000 }
};
/*BLUE_FOUR_FLASHES_FAST*/
static const ledEntry_t pattern_BLUE_FOUR_FLASHES_FAST [ 8 ] =
{
{ LED_BLUE , ON , 200 } ,
{ LED_BLUE , OFF , 200 } ,
{ LED_BLUE , ON , 200 } ,
{ LED_BLUE , OFF , 200 } ,
{ LED_BLUE , ON , 200 } ,
{ LED_BLUE , OFF , 200 },
{ LED_BLUE , ON , 200 } ,
{ LED_BLUE , OFF , 200 }
};
/*BLUE_SHORT_ON_RPT*/
static const ledEntry_t pattern_BLUE_SHORT_ON_RPT [ 2 ] =
{
{ LED_BLUE , ON , 200 } ,
{ LED_BLUE , OFF , 2000 }
};
/*RED_BLUE_SHORT_ON_RPT*/
static const ledEntry_t pattern_RED_BLUE_SHORT_ON_RPT [ 2 ] =
{
{ LED_BLUE | LED_RED , ON , 200 } ,
{ LED_BLUE | LED_RED, OFF , 2000 }
};
/*RED_CONT_BLUE_SHORT_ON_RPT*/
static const ledEntry_t pattern_RED_CONT_BLUE_SHORT_ON_RPT [ 3 ] =
{
{ LED_RED , ON , 0 } ,
{ LED_BLUE , ON , 200 } ,
{ LED_BLUE , OFF , 2000 }
};
#define LED_NUM_PATTERNS ( 15 )
/*The LED entries*/
static const led_t gLeds [ LED_NUM_PATTERNS ] =
{
{ { 1, 0x00 , RPT }, (ledEntry_t *) pattern_LEDS_OFF } ,
{ { 4, 0x00 , RPT }, (ledEntry_t *) pattern_RED_BLUE_ALT_RPT_FAST } ,
{ { 1, 0x00 , RPT }, (ledEntry_t *) pattern_BLUE_ON } ,
{ { 1, 0x00 , RPT }, (ledEntry_t *) pattern_RED_ON } ,
{ { 4, 0x00 , OFF }, (ledEntry_t *) pattern_BLUE_TWO_FLASHES } ,
{ { 2, 0x00 , RPT }, (ledEntry_t *) pattern_BLUE_ONE_SEC_ON_RPT } ,
{ { 4, 0x00 , OFF }, (ledEntry_t *) pattern_RED_TWO_FLASHES } ,
{ { 4, 0x00 , OFF }, (ledEntry_t *) pattern_RED_TWO_FLASHES_FAST } ,
{ { 2, 0x00 , RPT }, (ledEntry_t *) pattern_RED_ONE_SEC_ON_RPT } ,
{ { 2, 0x00 , RPT }, (ledEntry_t *) pattern_RED_BLUE_ONE_SEC_ON_RPT },
{ { 3, 0x00 , RPT }, (ledEntry_t *) pattern_RED_CONT_BLUE_ONE_SEC_ON_RPT },
{ { 8, 0x00 , OFF }, (ledEntry_t *) pattern_BLUE_FOUR_FLASHES_FAST },
{ { 2, 0x00 , RPT }, (ledEntry_t *) pattern_BLUE_SHORT_ON_RPT } ,
{ { 2, 0x00 , RPT }, (ledEntry_t *) pattern_RED_BLUE_SHORT_ON_RPT } ,
{ { 3, 0x00 , RPT }, (ledEntry_t *) pattern_RED_CONT_BLUE_SHORT_ON_RPT }
};
/*END_OF_INSERTED_CODE*/
/*the leds task data*/
typedef struct
{
TaskData task;
LedPattern_t gCurrentPattern ; /*which of the patterns we are currently playing*/
uint16 gCurrentPatternPosition ; /*how far through the current pattern we are*/
LedPattern_t gRepeatingPattern ; /*the currently repeating pattern*/
uint16 gRepeatingPatternPosition ; /*how far through the repeating pattern we were*/
} LedState_t;
/*This is the main LED state - initialised when used*/
LedState_t * LED = NULL ;
/*local functions*/
static void ledsInit ( void ) ;
static void ledsSet ( uint16 pLedMask , bool pOnOrOff ) ;
static void ledsSetPio ( uint16 pPIOMask , bool pOnOrOff ) ;
static void ledsHandler (Task task, MessageId id, Message data) ;
static bool ledsConfigPattern ( LedPattern_t pNewPattern ) ;
/****************************************************************************
NAME
ledsPlay
DESCRIPTION
Play an LED pattern.
If a repeating pattern is already playing
- then this will be interuppted and the new pattern (non repeating or repeating)
will be played. If the new pattern is non-repeating then the interrupted
pattern will be resumed after completion of the non-repeating pattern
If a non-repeating pattern is currently playing
- if the new pattern is also a non-repeating pattern, then returns false
(caller is responsible for queuing LEDS)
- if the new pattern is a repeating pattern, then this will be played on completion
of the non-repeating current pattern
RETURNS
void
*/
bool ledsPlay ( LedPattern_t pNewPattern )
{
bool lUpdate ;
/*Init the LED structure if required*/
if ( ! LED )
{
ledsInit() ;
}
/*ensure range is valid*/
if (pNewPattern > (LED_NUM_PATTERNS-1) )
return FALSE ;
/*fn which configs the requested pattern if possible*/
lUpdate = ledsConfigPattern ( pNewPattern ) ;
if (lUpdate)
{
MessageFlushTask ( &LED->task ) ;
LED_DEBUG(("LED: Play [%d]\n", pNewPattern)) ;
ledsSet ( gLedPinsUsed , OFF ) ;
MessageSend ( &LED->task , LED_UPDATE_MSG , 0 ) ;
}
return lUpdate ;
}
/****************************************************************************
NAME
ledsHandler
DESCRIPTION
Update the LED playback
Turn the Leds On or Off according to the next element in the pattern
If the pattern has completed and is non repeating, then restarts the pattern
RETURNS
void
*/
static void ledsHandler(Task task, MessageId id, Message data)
{
/* LED_DEBUG(("LED: [%d][%d][%d]\n " , LED->gCurrentPattern , LED->gCurrentPatternPosition , gLeds[LED->gCurrentPattern].header.num_entries )) ;*/
switch (id)
{
case ( LED_UPDATE_MSG ) :
{
/*LED_DEBUG(("LED Mask[%x] On[%d] Time[%d]\n" , gLeds[LED->gCurrentPattern].entries[LED->gCurrentPatternPosition].PioMask ,
gLeds[LED->gCurrentPattern].entries[LED->gCurrentPatternPosition].On ,
gLeds[LED->gCurrentPattern].entries[LED->gCurrentPatternPosition].Time)) ; */
/*the pattern has completed*/
if (LED->gCurrentPatternPosition >= gLeds[LED->gCurrentPattern].header.num_entries)
{
if (gLeds[LED->gCurrentPattern].header.repeat)
{ /*reset the repeating pattern*/
LED_DEBUG(("LED: Repeat\n")) ;
LED->gCurrentPatternPosition = 0 ;
}
else
{ /*one shot pattern is complete*//*return to playing the repeating pattern*/
LED->gCurrentPattern = LED->gRepeatingPattern ;
LED->gCurrentPatternPosition = LED->gRepeatingPatternPosition ;
if (gLeds[LED->gCurrentPattern].header.repeat)
{ /*reset the repeating pattern*/
LED_DEBUG(("LED: Repeat 2\n")) ;
LED->gCurrentPatternPosition = 0 ;
}
}
}
/*Cancel all pending LED update messages*/
MessageFlushTask ( task ) ;
ledsSet ( gLeds[LED->gCurrentPattern].entries[LED->gCurrentPatternPosition].PioMask ,
gLeds[LED->gCurrentPattern].entries[LED->gCurrentPatternPosition].On ) ;
/*only send a message if we are not a permanently on or off pattern*/
if ( ( gLeds[LED->gCurrentPattern].header.num_entries) != 1 )
{
MessageSendLater ( task , LED_UPDATE_MSG , 0 , (gLeds[LED->gCurrentPattern].entries[LED->gCurrentPatternPosition].Time ) ) ;
}
LED->gCurrentPatternPosition ++ ;
}
break ;
default:
break ;
}
}
/****************************************************************************
NAME
ledsInit
DESCRIPTION
initialise the LED Library
RETURNS
void
*/
static void ledsInit( void )
{
LED = PanicUnlessNew ( LedState_t ) ;
LED->task.handler = ledsHandler;
LED->gCurrentPatternPosition = 0 ;
LED->gCurrentPattern = 0 ;
LED->gCurrentPatternPosition = 0 ;
LED->gRepeatingPattern = 0 ;
LED->gRepeatingPatternPosition = 0 ;
}
/****************************************************************************
NAME
ledsSet
DESCRIPTION
Set / Clear the LED pins or PIOs
RETURNS
void
*/
static void ledsSet (uint16 pLedMask , bool pOnOrOff )
{
uint16 lMask = 0xffff ;
#ifdef SPECIAL_LED_PINS
/* LED pins are special cases*/
if ( pLedMask & 0x8000 )
PioSetLed0 ( pOnOrOff ) ;
if ( pLedMask & 0x4000 )
PioSetLed1 ( pOnOrOff ) ;
/*set the remaining pios*/
lMask = 0x3fff ;
#endif
/*set the pios*/
ledsSetPio ( ( pLedMask & lMask ) , pOnOrOff ) ;
}
/****************************************************************************
NAME
ledsSetPio
DESCRIPTION
Fn to set / clear the mask of PIOs required
RETURNS
void
*/
static void ledsSetPio ( uint16 pPioMask , bool pOnOrOff )
{
uint16 lPinVals = 0 ;
if ( pOnOrOff == TRUE )
{
lPinVals = pPioMask ;
}
else
{
lPinVals = 0x0000;/*clr the corresponding bit*/
}
/*(mask,bits) setting bit to a '1' sets the corresponding port as an output*/
PioSetDir( pPioMask , pPioMask );
/*set the value of the pin to the corresponding value*/
PioSet ( pPioMask , lPinVals ) ;
}
/****************************************************************************
NAME
ledsConfigPattern
DESCRIPTION
Fn to configure the led that has been requested, returns false if the led cannot
be played at this time
RETURNS
bool (is an update to the LEDS required)
*/
static bool ledsConfigPattern ( LedPattern_t pNewPattern )
{
bool lUpdate = TRUE ;
LED_DEBUG(("LED: Play Curr[%x] New [%x]\n" , gLeds[LED->gCurrentPattern].header.repeat ,
gLeds[pNewPattern].header.repeat )) ;
/*if current pattern is repeating*/
if ( gLeds[LED->gCurrentPattern].header.repeat )
{
LED_DEBUG(("1\n")) ;
/*if new pattern is repeating*/
if ( gLeds[pNewPattern].header.repeat )
{ /*then interrupt the pattern with the new repeating pattern*/
LED_DEBUG(("2\n")) ;
LED->gCurrentPatternPosition = 0 ;
LED->gCurrentPattern = pNewPattern ;
LED->gRepeatingPattern = pNewPattern ;
LED->gRepeatingPatternPosition = 0 ;
}
else /*interrupt the current pattern with a repeating pattern*/
{
LED_DEBUG(("3\n")) ;
/*then store the current pattern to be resumed*/
LED->gRepeatingPattern = LED->gCurrentPattern ;
LED->gRepeatingPatternPosition = LED->gCurrentPatternPosition ;
/*and start the requested pattern*/
LED->gCurrentPattern = pNewPattern ;
LED->gCurrentPatternPosition = 0 ;
}
}
else /*current pattern is non repeating*/
{
/*if the new pattern is repeating*/
if ( gLeds[pNewPattern].header.repeat )
{ /*then store this to be resumed*/
LED_DEBUG(("4\n")) ;
LED->gRepeatingPattern = pNewPattern ;
LED->gRepeatingPatternPosition = 0 ;
}
else /*the new pattern is also non-repeating and cant be currently played*/
{
LED_DEBUG(("5\n")) ;
lUpdate = FALSE ;
}
}
return lUpdate ;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -