📄 evmdrv.c
字号:
/*******************************************************************************
*
* Motorola Inc.
* (c) Copyright 2002 Motorola, Inc.
* ALL RIGHTS RESERVED.
*
* $Element: /project/dsp568_sdk/sdk/src/dsp56838evm/nos/bsp/leddrv.c $
* $Author: saa $
* $Revision: /main/2 $
* $VOB: /project/dsp568_sdk $
* $OS: solaris $
*
* Description: source file for the 56838 LED device driver
*
* Notes:
*
******************************************************************************/
#include "bsp.h"
#include "periph.h"
#include "evm.h"
#include "evmdrv.h"
#include "gpioinline.h"
extern const led_Config ledPortMap[];
extern const led_PWM_Config ledPWMMap[];
extern const UWord16 sizeLedMap;
extern const UWord16 sizeLedPWMMap;
/*****************************************************************************/
void LedInit(const led_Config* ledport, int num );
inline void ledPWMInit(volatile arch_sPWM* pPwm);
handle_t ledOpen(const char * pName, int OFlags, ...)
{
led_Config* ledport =(led_Config*) &ledPortMap[0];
int i;
for( i = 0; i < sizeLedMap; i++ )
{
if( BSP_DEVICE_NAME_LED_0 + i == pName )
{
if( i == 0 ) /* first is general device */
{
LedInit(ledport + 1, sizeLedMap - 1);
if (OFlags & O_INVERT_DIRECTION)
ledport->pin = O_INVERT_DIRECTION;
}
else
LedInit(ledport, 1);
return( (handle_t)ledport );
}
ledport++;
}
return( (handle_t)-1 );
}
/*******************************************************************************
*
* NAME: ledPWMOpen
*
* DESCRIPTION: To open pwm device working as led
*
********************************************************************************
* PARAMETERS: pName - Device name, OFlags - flags of led_pwm turning
*
* SIDE EFFECTS: None Known
*
* DESIGNER NOTES:
*
* DEPENDENCIES: None
*
* Example: pwmLed = open(BSP_DEVICE_NAME_LED_PWM, O_INVERT_DIRECTION);
*
*******************************************************************************/
handle_t ledPWMOpen(const char * pName, int OFlags, ...)
{
int i;
for( i = 0; i < sizeLedPWMMap; i++ )
{
if( BSP_DEVICE_NAME_LED_PWM + i == pName )
{
led_PWM_Config* pwmStr =(led_PWM_Config*) &ledPWMMap[i];
ledPWMInit(pwmStr->pPwm);
if ((OFlags & O_INVERT_DIRECTION)&& (i==0))
pwmStr->flags = O_INVERT_DIRECTION;
return((handle_t)pwmStr);
}
}
return( (handle_t)-1 );
}
UWord16 ledIoctlLED_ON( handle_t hndl, unsigned long params )
{
periphBitSet( ((led_Config*)hndl)->pin, &((led_Config*)hndl)->port->DataReg );
}
UWord16 ledIoctlLED_OFF( handle_t hndl, unsigned long params )
{
periphBitClear( ((led_Config*)hndl)->pin, &((led_Config*)hndl)->port->DataReg);
}
UWord16 ledIoctlLED_TOGGLE( handle_t hndl, unsigned long params )
{
periphBitChange( ((led_Config*)hndl)->pin, &((led_Config*)hndl)->port->DataReg);
}
UWord16 ledIoctlGLED_ON( handle_t hndl, unsigned long params )
{
const led_Config* ledport = &ledPortMap[(int)params + 1];
periphBitSet( ledport->pin, &ledport->port->DataReg );
}
UWord16 ledIoctlGLED_OFF( handle_t hndl, unsigned long params )
{
const led_Config* ledport = &ledPortMap[(int)params + 1];
periphBitClear( ledport->pin, &ledport->port->DataReg );
}
UWord16 ledIoctlGLED_TOGGLE( handle_t hndl, unsigned long params )
{
const led_Config* ledport = &ledPortMap[(int)params + 1];
periphBitChange( ledport->pin, &ledport->port->DataReg );
}
UWord16 ledIoctlINVERT_DIRECTION( handle_t hndl, unsigned long params )
{
if (((led_Config*)hndl)->pin & O_INVERT_DIRECTION)
((led_Config*)hndl)->pin &=~O_INVERT_DIRECTION;
else
((led_Config*)hndl)->pin |= O_INVERT_DIRECTION;
}
UWord16 ledPWMIoctlINVERT_DIRECTION( handle_t hndl, unsigned long params )
{
if (((led_PWM_Config*)hndl)->flags & O_INVERT_DIRECTION)
((led_PWM_Config*)hndl)->flags &=~O_INVERT_DIRECTION;
else
((led_PWM_Config*)hndl)->flags |= O_INVERT_DIRECTION;
}
/*******************************************************************************
*
* NAME: ledWrite
*
* DESCRIPTION: To toggle Led_PWM
*
********************************************************************************
* PARAMETERS: hndl - handle to LED
* buf - state of bar (ON/OFF="\1"/"\0")
* len - length of bar
*
*
* DESIGNER NOTES: None
*
* DEPENDENCIES: None
*
*
*******************************************************************************/
size_t ledWrite( handle_t hndl, const void *buf, size_t len )
{
if(*(const char*)buf)
periphBitSet( ((led_Config*)hndl)->pin, &((led_Config*)hndl)->port->DataReg );
else
periphBitClear( ((led_Config*)hndl)->pin, &((led_Config*)hndl)->port->DataReg);
return 1;
}
/*******************************************************************************
*
* NAME: ledBarWrite
*
* DESCRIPTION: To toggle Led as progress bar
*
********************************************************************************
* PARAMETERS: hndl - handle to ledMap
* buf - state of bar (ON/OFF="\1"/"\0")
* len - length of bar
*
* SIDE EFFECTS: led's station : state len
* ------ 0
* +----- 1
* ++---- 2
* +++--- 3
* ++++-- 4
* +++++- 5
* ++++++ 6
* LED: 012345
* + ON
* - OFF
*
* DESIGNER NOTES: Direction could be inverted!
*
* DEPENDENCIES: None
*
*
*******************************************************************************/
size_t ledBarWrite( handle_t hndl, const void *buf, size_t len )
{
const led_Config* tmpHandl = &ledPortMap[1];
if(*(const char*)buf)
{
if (len>=sizeLedMap)
len = sizeLedMap-1;
if ( ((led_Config*)hndl)->pin & O_INVERT_DIRECTION)
{
for(tmpHandl = &ledPortMap[sizeLedMap-1]; tmpHandl>=&ledPortMap[sizeLedMap-len] ; tmpHandl-- )
{
periphBitSet( tmpHandl->pin, &(tmpHandl->port->DataReg ));
}
for( ; tmpHandl>&ledPortMap[0] ; tmpHandl-- )
{
periphBitClear( tmpHandl->pin, &(tmpHandl->port->DataReg ));
}
}
else
{
for( ; tmpHandl<=&ledPortMap[len] ; tmpHandl++ )
{
periphBitSet( tmpHandl->pin, &(tmpHandl->port->DataReg ));
}
for( ; tmpHandl<=&ledPortMap[sizeLedMap-1] ; tmpHandl++ )
{
periphBitClear( tmpHandl->pin, &(tmpHandl->port->DataReg ));
}
}
}
else
for( ; tmpHandl<=&ledPortMap[sizeLedMap-1] ; tmpHandl++ )
{
periphBitClear( tmpHandl->pin, &(tmpHandl->port->DataReg ));
}
return 1;
}
/*******************************************************************************
*
* NAME: ledPWMWrite
*
* DESCRIPTION: To toggle Led_PWM
*
********************************************************************************
* PARAMETERS: hndl - handle to LED_PWM
* buf - state of bar (ON/OFF="\1"/"\0")
* len - length of bar
*
*
* DESIGNER NOTES: None
*
* DEPENDENCIES: None
*
*
*******************************************************************************/
size_t ledPWMWrite( handle_t hndl, const void *buf, size_t len )
{
unsigned int i;
unsigned int flags = ((led_PWM_Config*) hndl)->flags;
for( i = 0; i < 6; i++ )
{
if( flags & 1 )
{
ledPWMSetValue( *(const char*)buf, i );
return 1;
}
flags >>= 1;
}
return 1;
}
void ledPWMSetValue( unsigned int val, unsigned int num )
{
if( val != 0 )
val = 0x7fff;
periphMemWrite( val, (volatile UWord16*)&ArchIO.PwmA.ValueReg[num] );
periphBitSet( 0x0002, &ArchIO.PwmA.ControlReg);
}
UWord16 ledIoctlPWMLED_ON( handle_t hndl, unsigned long params )
{
return ledPWMWrite(hndl, "\0x01", 1 );
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -