?? dio.c
字號(hào):
case DO_BLINK_EN_INV: /* Blink depends on the complemented user request's state */
en = pdo->DOBypass ? FALSE : TRUE;
break;
}
return (en);
}
#endif
/*$PAGE*/
/*
*********************************************************************************************************
* SET THE STATE OF THE DISCRETE OUTPUT
*
* Description : This function is used to set the state of the discrete output.
* Arguments : n is the discrete output channel (0..DIO_MAX_DO-1).
* state is the desired state of the output:
* FALSE indicates a negated output
* TRUE indicates an asserted output
* Returns : None.
* Notes : The actual output will be complemented if 'DIInv' is set to TRUE.
*********************************************************************************************************
*/
void DOSet (INT8U n, BOOLEAN state)
{
if (n < DIO_MAX_DO) {
OS_ENTER_CRITICAL();
DOTbl[n].DOCtrl = state;
OS_EXIT_CRITICAL();
}
}
/*$PAGE*/
/*
*********************************************************************************************************
* SET THE STATE OF THE BYPASSED OUTPUT
*
* Description : This function is used to set the state of the bypassed output. This function is used to
* override (or bypass) the application software and allow the output to be controlled
* directly. This function is only valid if the bypass switch is open.
* Arguments : n is the discrete output channel (0..DIO_MAX_DO-1).
* state is the desired state of the output:
* FALSE indicates a negated output
* TRUE indicates an asserted output
* Returns : None.
* Notes : 1) The actual output will be complemented if 'DIInv' is set to TRUE.
* 2) In blink mode, this allows blinking to be enabled or not.
*********************************************************************************************************
*/
void DOSetBypass (INT8U n, BOOLEAN state)
{
DIO_DO *pdo;
if (n < DIO_MAX_DO) {
pdo = &DOTbl[n];
OS_ENTER_CRITICAL();
if (pdo->DOBypassEn == TRUE) {
pdo->DOBypass = state;
}
OS_EXIT_CRITICAL();
}
}
/*$PAGE*/
/*
*********************************************************************************************************
* SET THE STATE OF THE OUTPUT BYPASS
*
* Description : This function is used to set the state of the output bypass switch. The output is
* bypassed when the 'switch' is open (i.e. DOBypassEn is set to TRUE).
* Arguments : n is the discrete output channel (0..DIO_MAX_DO-1).
* state is the state of the bypass switch:
* FALSE disables output bypass (i.e. the switch is closed)
* TRUE enables output bypass (i.e. the switch is open)
* Returns : None.
*********************************************************************************************************
*/
void DOSetBypassEn (INT8U n, BOOLEAN state)
{
if (n < DIO_MAX_DO) {
OS_ENTER_CRITICAL();
DOTbl[n].DOBypassEn = state;
OS_EXIT_CRITICAL();
}
}
/*$PAGE*/
/*
*********************************************************************************************************
* SET THE MAXIMUM VALUE FOR THE SYNCHRONOUS COUNTER
*
* Description : This function is used to set the maximum value taken by the synchronous counter which is
* used in the synchronous blink mode.
* Arguments : val is the maximum value for the counter (1..255)
* Returns : None.
*********************************************************************************************************
*/
#if DO_BLINK_MODE_EN
void DOSetSyncCtrMax (INT8U val)
{
OS_ENTER_CRITICAL();
DOSyncCtrMax = val;
DOSyncCtr = val;
OS_EXIT_CRITICAL();
}
#endif
/*$PAGE*/
/*
*********************************************************************************************************
* UPDATE DISCRETE OUT CHANNELS
*
* Description : This function is called to process all of the discrete output channels.
* Arguments : None.
* Returns : None.
*********************************************************************************************************
*/
static void DOUpdate (void)
{
INT8U i;
BOOLEAN out;
DIO_DO *pdo;
pdo = &DOTbl[0];
for (i = 0; i < DIO_MAX_DO; i++) { /* Process all discrete output channels */
if (pdo->DOBypassEn == FALSE) { /* See if DO channel is enabled */
pdo->DOBypass = pdo->DOCtrl; /* Obtain control state from application */
}
out = FALSE; /* Assume that the output will be low unless changed */
switch (pdo->DOModeSel) {
case DO_MODE_LOW: /* Output will in fact be low */
break;
case DO_MODE_HIGH: /* Output will be high */
out = TRUE;
break;
case DO_MODE_DIRECT: /* Output is based on state of user supplied state */
out = pdo->DOBypass;
break;
/*$PAGE*/
#if DO_BLINK_MODE_EN
case DO_MODE_BLINK_SYNC: /* Sync. Blink mode */
if (DOIsBlinkEn(pdo)) { /* See if Blink is enabled ... */
if (pdo->DOA >= DOSyncCtr) { /* ... yes, High when below threshold */
out = TRUE;
}
}
break;
case DO_MODE_BLINK_ASYNC: /* Async. Blink mode */
if (DOIsBlinkEn(pdo)) { /* See if Blink is enabled ... */
if (pdo->DOA >= pdo->DOBCtr) { /* ... yes, High when below threshold */
out = TRUE;
}
}
if (pdo->DOBCtr < pdo->DOB) { /* Update the threshold counter */
pdo->DOBCtr++;
} else {
pdo->DOBCtr = 0;
}
break;
#endif
}
if (pdo->DOInv == TRUE) { /* See if output needs to be inverted ... */
pdo->DOOut = out ? FALSE : TRUE; /* ... yes, complement output */
} else {
pdo->DOOut = out; /* ... no, no inversion! */
}
pdo++; /* Point to next DIO_DO element */
}
#if DO_BLINK_MODE_EN
if (DOSyncCtr < DOSyncCtrMax) { /* Update the synchronous free running ctr */
DOSyncCtr++;
} else {
DOSyncCtr = 0;
}
#endif
}
/*$PAGE*/
#ifndef CFG_C
/*
*********************************************************************************************************
* INITIALIZE PHYSICAL I/Os
*
* Description : This function is by DIOInit() to initialze the physical I/O used by the DIO driver.
* Arguments : None.
* Returns : None.
* Notes : The physical I/O is assumed to be an 82C55 chip initialized as follows:
* Port A = OUT (Discrete outputs)
* Port B = IN (Discrete inputs)
* Port C = OUT (not used)
*********************************************************************************************************
*/
void DIOInitIO (void)
{
outp(0x0303, 0x82); /* Port A = OUT, Port B = IN, Port C = OUT */
}
/*
*********************************************************************************************************
* READ PHYSICAL INPUTS
*
* Description : This function is called to read and map all of the physical inputs used for discrete
* inputs and map these inputs to their appropriate discrete input data structure.
* Arguments : None.
* Returns : None.
*********************************************************************************************************
*/
void DIRd (void)
{
DIO_DI *pdi;
INT8U i;
INT8U in;
INT8U msk;
pdi = &DITbl[0]; /* Point at beginning of discrete inputs */
msk = 0x01; /* Set mask to extract bit 0 */
in = inp(0x0301); /* Read the physical port (8 bits) */
for (i = 0; i < 8; i++) { /* Map all 8 bits to first 8 DI channels */
pdi->DIIn = (BOOLEAN)(in & msk) ? 1 : 0;
msk <<= 1;
pdi++;
}
}
/*$PAGE*/
/*
*********************************************************************************************************
* UPDATE PHYSICAL OUTPUTS
*
* Description : This function is called to map all of the discrete output channels to their appropriate
* physical destinations.
* Arguments : None.
* Returns : None.
*********************************************************************************************************
*/
void DOWr (void)
{
DIO_DO *pdo;
INT8U i;
INT8U out;
INT8U msk;
pdo = &DOTbl[0]; /* Point at first discrete output channel */
msk = 0x01; /* First DO will be mapped to bit 0 */
out = 0x00; /* Local 8 bit port image */
for (i = 0; i < 8; i++) { /* Map first 8 DO to 8 bit port image */
if (pdo->DOOut == TRUE) {
out |= msk;
}
msk <<= 1;
pdo++;
}
outp(0x0300, out); /* Output port image to physical port */
}
#endif
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -