📄 led.c
字号:
#include "vxWorks.h"
#include "vme.h"
#include "memLib.h"
#include "cacheLib.h"
#include "sysLib.h"
#include "config.h"
#include "string.h"
#include "intLib.h"
#include "logLib.h"
#include "stdio.h"
#include "taskLib.h"
#include "vxLib.h"
#include "tyLib.h"
#include "arch/ppc/vxPpcLib.h"
#include "private/vmLibP.h"
#include "drv/multi/ppc860Siu.h"
#include "ads860.h"
#define LED_SINGLE_COLOR 0
#define LED_DOUBLE_COLOR 1
#ifndef TRUE
#define TRUE 1
#endif
#ifndef FALSE
#define FALSE 0
#endif
typedef struct{
int ledType; /* 0 单色 1 双色 */
/* 第一个灯丝的端口 */
int port1; /* 0 a 1 b 2 c 3 d */
int no1;
/* 第二个灯丝的端口 */
int port2; /* 0 a 1 b 2 c 3 d */
int no2;
} LED_CONFIG_TABLE;
static LED_CONFIG_TABLE ledTable[] =
{
{ 1 , 2 , 14 , 2 , 15 },
{ 1 , 2 , 13 , 0 , 8 },
{ 1 , 2 , 5 , 2 , 7 },
{ 1 , 2 , 12 , 0 , 9 },
{ 1 , 2 , 8 , 2 , 9 }
};
static unsigned int ledNum = 5;
/*
初始化led端口
pc 5,7,8,9,12,13,14,15
0x05cf
pa 8,9
0x00c0
par=0
dir=1
so=0
dat=1/0
*/
int BSP_LedInit()
{
int i;
UINT32 immrVal = vxImmrIsbGet();
*PCPAR( immrVal ) &= ~0x05cf;
*PCDIR( immrVal ) |= 0x05cf;
*PCSO( immrVal ) &= ~0x05cf;
*PAPAR( immrVal ) &= ~0x00c0;
*PADIR( immrVal ) |= 0x00c0;
for ( i = 0 ; i < ledNum; i++ )
{
if ( ledTable[i].ledType > 1 )
return FALSE;
if ( ledTable[i].port1 > 3 )
return FALSE;
if ( ledTable[i].no1 > 15 || ledTable[i].no1 < 4 )
return FALSE;
if ( ledTable[i].port2 > 3 )
return FALSE;
if ( ledTable[i].no2 > 15 || ledTable[i].no2 < 4 )
return FALSE;
}
return TRUE;
}
void SetPortA( unsigned int no, unsigned int status )
{
UINT32 immrVal = vxImmrIsbGet();
if( status > 0)
{
*PADAT(immrVal) |= ( 1 << (15-no) );
}
else
{
*PADAT(immrVal) &= ~( 1 << (15-no) );
}
}
void SetPortB( unsigned int no, unsigned int status )
{
UINT32 immrVal = vxImmrIsbGet();
if( status > 0)
{
*PBDAT(immrVal) |= ( 1 << (15-no) );
}
else
{
*PBDAT(immrVal) &= ~( 1 << (15-no) );
}
}
void SetPortC( unsigned int no, unsigned int status )
{
UINT32 immrVal = vxImmrIsbGet();
if( status > 0)
{
*PCDAT(immrVal) |= ( 1 << (15-no) );
}
else
{
*PCDAT(immrVal) &= ~( 1 << (15-no) );
}
}
void SetPortD( unsigned int no, unsigned int status )
{
UINT32 immrVal = vxImmrIsbGet();
if( status > 0)
{
*PDDAT(immrVal) |= ( 1 << (15-no) );
}
else
{
*PDDAT(immrVal) &= ~( 1 << (15-no) );
}
}
/*
输入参数:
num:灯号
status:状态
0 灭 1 红 2 绿 3 黄
返回值
*/
int SetLed( unsigned int num , unsigned int status )
{
if ( num >= ledNum )
return FALSE;
switch ( ledTable[num].port1 )
{
case 0:
SetPortA( ledTable[num].no1 , status&1 );
break;
case 1:
SetPortB( ledTable[num].no1 , status&1 );
break;
case 2:
SetPortC( ledTable[num].no1 , status&1 );
break;
case 3:
SetPortD( ledTable[num].no1 , status&1 );
break;
}
if ( ledTable[num].ledType == LED_DOUBLE_COLOR )
{
switch ( ledTable[num].port2 )
{
case 0:
SetPortA( ledTable[num].no2 , status&2 );
break;
case 1:
SetPortB( ledTable[num].no2 , status&2 );
break;
case 2:
SetPortC( ledTable[num].no2 , status&2 );
break;
case 3:
SetPortD( ledTable[num].no2 , status&2 );
break;
}
}
return TRUE;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -