?? can_lib.c
字號:
}
CANCONCH |= 0x08;
}
/*F***************************************************************************
* FUNCTION_NAME: SendCanMsg
*----------------------------------------------------------------------------
* FUNCTION_AUTHOR: BERTHY J.S.
* FUNCTION_DATE : 28/09/99
*----------------------------------------------------------------------------
* FUNCTION_PURPOSE: Send message
* The identifier to send is declared in the globale variable can_id_tx,
* data to transmit are declared in the globale variable pt_candata_tx
* The configuration is defined in globale variable conf_tx.
* FUNCTION_INPUTS : void
* FUNCTION_OUTPUTS: void
*----------------------------------------------------------------------------
* GLOBAL VARIABLES USED :
* - conf_tx
* - pt_candata_tx
* - can_tx_id
******************************************************************************
* The variable conf_tx must contain information:
* - on ide:
* standart(NOT_IDE) or
* extended (IDE)
* - on rtr:
* remote frame(RTR) or
* data frame(NO_RTR)
* - on dlc: size of data dlc_t.
*
* Exemple of declaration:
* ----------------------
*
* conf_tx = IDE | NO_RTR | DLC_6
*
******************************************************************************
* NOTE:
* It's very important to make sure that channel is free.
* No verification are perform by this function.
*
* Exemple of use:
* ---------------
*
* CAN_SET_CHANNEL(CHANNEL_7);
* canid_tx.std = frame1.id.std;
* conf_tx = frame1.ctrl;
* pt_candata_tx= frame1.pt_donne;
* CANIE2 |= (1 << CHANNEL_7);
* SendCanMsg();
******************************************************************************/
void SendCanMsg (void)
{
Uchar dlc, i;
CAN_IT_DISABLE;
CANSTCH = 0x00;
CANCONCH = conf;
if (ide == TRUE)
{
CANIDT1 = CAN_SET_EXT_ID_28_21 (can_tx_id.ext);
CANIDT2 = CAN_SET_EXT_ID_20_13 (can_tx_id.ext);
CANIDT3 = CAN_SET_EXT_ID_12_5 (can_tx_id.ext);
CANIDT4 = CAN_SET_EXT_ID_4_0 (can_tx_id.ext);
}
else
{
CANIDT1 = CAN_SET_STD_ID_10_4 (can_tx_id.std);
CANIDT2 = CAN_SET_STD_ID_3_0 (can_tx_id.std);
}
/* load data to tx. */
dlc = (conf & MSK_CTRL_DLC);
for (i=dlc; i!=0; i--)
{
CANMSG = *pt_candata_tx++;
}
ENABLE_CHANNEL_TX;
CAN_IT_ENABLE;
}
/*F***************************************************************************
* FUNCTION_NAME: ReadCanMsg
*----------------------------------------------------------------------------
* FUNCTION_AUTHOR: BERTHY J.S.
* FUNCTION_DATE : 28/09/99
*----------------------------------------------------------------------------
* FUNCTION_PURPOSE: Copy message received on num_channel in structure
* of type st_can_msg_t, and configured the channel with the
* new configuration given by next_conf, past in parameter
* FUNCTION_INPUTS : Uchar next_conf:
* - CHANNEL_DISABLE
* - CHANNEL_RX_ENABLE (re-enable the channel in reception)
* - CHANNEL_RXB_ENABLE(re-enable the channel
* in buffer mode)
* FUNCTION_OUTPUTS: void
*----------------------------------------------------------------------------
* GLOBAL VARIABLES USED :
* - conf_rx
* - pt_st_can_rx
******************************************************************************
* NOTE:
******************************************************************************/
void ReadCanMsg (Uchar next_conf)
{
Uchar * pt_local;
Uchar dlc, i;
pt_st_can_rx->ctrl = CANCONCH;
conf_rx = CANCONCH;
if(ide)
{
pt_st_can_rx->id.tab[0] = CANIDT1 >> 3;
pt_st_can_rx->id.tab[1] = (CANIDT1 << 5) | (CANIDT2 >> 3);
pt_st_can_rx->id.tab[2] = (CANIDT2 << 5) | (CANIDT3 >> 3);
pt_st_can_rx->id.tab[3] = (CANIDT3 << 5) | (CANIDT4 >> 3);
}
else
{
pt_st_can_rx->id.std = (CANIDT1 << 3) | (CANIDT2 >> 5);
}
pt_local = pt_st_can_rx->pt_donne;
dlc = (conf_rx & MSK_CTRL_DLC);
for (i=dlc; i!=0; i--)
{
*pt_local++ = CANMSG;
}
/*---------- New configuration for this channel. */
b_var_read = next_conf;
if (NEW_CONF_CH_DISABLE)
{
CANCONCH |= (MSK_CANCONCH_CONF & CH_DISABLE); /* Reception disable.*/
}
else if(NEW_CONF_CH_RX_ENABLE)
{
CANCONCH |= (MSK_CANCONCH_CONF & CH_RxENA); /* Reception enable.*/
}
else /* CHANNEL_RXB_ENABLE */
{
CANCONCH |= (MSK_CANCONCH_CONF & CH_RxBENA); /* Buffer enable.*/
}
}
/*F***************************************************************************
* FUNCTION_NAME: FindFirstChIt
*----------------------------------------------------------------------------
* FUNCTION_AUTHOR: BERTHY J.S.
* FUNCTION_DATE :
*----------------------------------------------------------------------------
* FUNCTION_PURPOSE: This function return the first channel with an interrupt
* request. The big priority start with the lowest channel
* value (CHANNEL_0).
* FUNCTION_INPUTS : void
* FUNCTION_OUTPUTS: Uchar num_channel: return the channel number of the first
* it find in CANSIT registers.
*****************************************************************************
* NOTE:
******************************************************************************/
Uchar FindFirstChIt (void)
{
Uchar num_channel = NO_CHANNEL;
if (CANSIT2)
{
bit_var = CANSIT2;
if(bit_0)
{
num_channel = CHANNEL_0;
}
else if (bit_1)
{
num_channel = CHANNEL_1;
}
else if (bit_2)
{
num_channel = CHANNEL_2;
}
else if (bit_3)
{
num_channel = CHANNEL_3;
}
else if (bit_4)
{
num_channel = CHANNEL_4;
}
else if (bit_5)
{
num_channel = CHANNEL_5;
}
else if (bit_6)
{
num_channel = CHANNEL_6;
}
else
{
num_channel = CHANNEL_7;
}
}
else if (CANSIT1)
{
bit_var = CANSIT1;
if(bit_0)
{
num_channel = CHANNEL_8;
}
else if (bit_1)
{
num_channel = CHANNEL_9;
}
else if (bit_2)
{
num_channel = CHANNEL_10;
}
else if (bit_3)
{
num_channel = CHANNEL_11;
}
else if (bit_4)
{
num_channel = CHANNEL_12;
}
else if (bit_5)
{
num_channel = CHANNEL_13;
}
else if (bit_6)
{
num_channel = CHANNEL_14;
}
}
return(num_channel);
}
/*F***************************************************************************
* FUNCTION_NAME: fct_can_it
*-----------------------------------------------------------------------------
* FUNCTION_AUTHOR: BERTHY J.S.
* FUNCTION_DATE :
*-----------------------------------------------------------------------------
* FUNCTION_PURPOSE: function called on can interrupt
* The first task of this function is to identified whish channel
* generate the interrupt, and the second is to identified whish kind
* of interrupt is generated (rxok, txok, error, buffer full).
* FUNCTION_INPUTS : void
* FUNCTION_OUTPUTS: void
******************************************************************************
* NOTE:
******************************************************************************/
void fct_can_it (void)
{
Uchar channel;
Uchar save_canpage;
// Save the courant CANPAGE
save_canpage = CANPAGE;
channel = FindFirstChIt();
if (channel != NO_CHANNEL)
{
CAN_SET_CHANNEL(channel);
bit_var = CANSTCH;
/* Tx or Rx interrupt*/
if (IT_RXOK)
{
#ifdef USER_CAN_FCT_IT_RXOK
can_fct_it_rxok();
#endif /* USER_CAN_FCT_IT_RXOK */
}
else if (IT_TXOK)
{
#ifdef USER_CAN_FCT_IT_TXOK
can_fct_it_txok();
#endif /* USER_CAN_FCT_IT_TXOK */
}
/* Error Analysis */
if(!IT_RXOK && !IT_TXOK)
{
#ifdef USER_CAN_FCT_IT_ERROR
can_fct_it_error();
#endif /* USER_CAN_FCT_IT_ERROR */
}
/* Raz all flag */
CANSTCH = 0x00;
}
else
{
/* No Channel match with the interrupt => General it*/
#ifdef USER_CAN_FCT_IT_GEN
can_fct_it_gen();
#endif /* USER_CAN_FCT_IT_GEN */
CANGIT &= 0xF0;
}
// restore the old config
CANPAGE = save_canpage;
}
/*F***************************************************************************
* FUNCTION_NAME: fct_tim_ovf_it
*----------------------------------------------------------------------------
* FUNCTION_AUTHOR: BERTHY J.S.
* FUNCTION_DATE :
*----------------------------------------------------------------------------
* FUNCTION_PURPOSE: function called on ovf_tim
* FUNCTION_INPUTS : void
* FUNCTION_OUTPUTS: void
******************************************************************************
* NOTE:
/******************************************************************************/
void fct_tim_ovf_it (void)
{
#ifdef USER_CAN_FCT_IT_TIMOVF
can_fct_it_timovf();
#endif /* USER_CAN_FCT_IT_TIMOVF */
CANGIT &= ~MSK_CANGIT_OVRTIM;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -