📄 slic_lindriver.c
字号:
//_______________________________________________________________________________
// Title: SLIC_LINdriver.c Copyright (c) Motorola 2003
//
// Assembler: P&E Microcomputer Systems - CASM08Z (v3.16)
// Compiler: Codewarrior....
//
// Revision History:
// Rev # Date Who Comments
// ------ ----------- ------ ------------------------------------------------
// 0.1 11-Aug-03 MR Initial release -
//
// Filename: LINQL4-C/src/SLIC_LINdriver.c
// Author: Matt Ruff
// Revision: 0.1
//
// Functions: SLIC module routines
//
// History:
//
// Description:
//
// Notes:
//
//_______________________________________________________________________________
#include "global.h"
#include "MC68HC908QL4.h"
#include "SLIC_LINdriver.h"
extern unsigned char temp_msg_buffer[8]; // Temporary storage of SLIC buffer contents
extern unsigned char LINdata;
extern unsigned char LINID;
extern unsigned char BusOff;
extern unsigned char LINSleep;
//+-----------------------------------------------------------------------------+
//| SLIC_Init - Initializes SLIC module |
//| |
//| Configures SLIC for: |
//| 1. LIN or BTM mode operation |
//| 2. Clock Operation in MCU Wait Mode |
//| 3. Receive filter prescaler adjustment for data rate |
//| 4. Bit timing setting (BTM mode) |
//+-----------------------------------------------------------------------------+
void SLIC_Init(void)
{
SLCC1_INITREQ = 0; // Clear INITREQ bit in SLIC
while(SLCS_INITACK==1){;;} // Wait for INITACK to clear
SLCC2_SLCWCM = 0; // Wait Clock Mode
// 0 - SLIC clocks continue in CPU WAIT
// 1 - SLIC clocks stop in CPU WAIT
// SLCP = 0x80; // RX Filter Prescaler
// This is only used if a value other
// than the default is desired.
// 00 - div 1
// 01 - div 2
// 10 - div 3 (default setting)
// 11 - div 4
SLCC2_SLCE = 1; // Enable SLIC module
}
//+-----------------------------------------------------------------------------+
//| |
//| SLIC_ISR - Interrupt Service Routine |
//| |
//| Main handler for SLIC interrupts |
//| |
//+-----------------------------------------------------------------------------+
//____________________________SLIC_ISR_____________
#pragma TRAP_PROC
void SLIC_ISR(void)
{
unsigned char temp_SLCSV = 0;
char ID_found = 0; // If ID not found, set IMSG
char temp = PTB_PTB0;
temp_SLCSV = SLCSV; // Read SLCSV value
switch(temp_SLCSV) // switch is temporary measure
{
case 0x00: //___________No Interrupts Pending__________________
break;
case 0x04: //___________No Bus Activity________________________
BusOff++;
if (BusOff == 2)
{
LINSleep = 1; // Set LINSleep flag
BusOff = 0; // Reset BusOff counter
}
break;
case 0x08: //___________TX Buffer Empty - Checksum Sent_______
break;
case 0x0C: //___________TX Buffer Empty_______________________
break;
case 0x10: //___________RX Buffer Full - Checksum OK__________
//_________________________________________________________________________TEST____________
if(SLCID==0x97) // Test message from master
{ // --------- test code....
temp_msg_buffer[0] = SLCD0; // Load RAM from RX buffers
temp_msg_buffer[1] = SLCD1; // Load RAM from RX buffers
}
//_________________________________________________________________________TEST________
break;
case 0x14: //___________RX Buffer Full - No errors____________
break;
case 0x18: //___________Bit-Error_____________________________
break;
case 0x1C: //___________RX Buffer Overrun_____________________
break;
case 0x20: //___________<reserved>____________________________
break;
case 0x24: //___________Checksum Error________________________
break;
case 0x28: //___________Byte Framing Error____________________
break;
case 0x2C: //___________ID received correctly - parity OK_____
// Perform ID lookup
//_________________________________________________________________________
if(SLCID==LINID) // Check ID
{
ID_found = 1; // Set ID found flag
SLCD0 = LINdata; // Load TX buffers
SLCD1 = 0;
SLCDLC = 0xC1; // Write DLC code to start TX - STD CHECKSUM
}
//_________________________________________________________________________
if(SLCID==0x97) // Test message from master
{ // --------- test code....
ID_found = 1; // Set ID found flag
SLCDLC = 0x41; // Write DLC code = RX, STANDARD CHECKSUM, 2 bytes
}
//_________________________________________________________________________
if (ID_found == 0)
{
#warning "ALPHA SAMPLE WORKAROUND"
SLCDLC = 0x00; // Alpha sample workaround - write DLC = 0 before IMSG=1;
SLCC1_IMSG = 1; // Set IMSG bit to ignore ID if not found!
}
ID_found = 0; // reset ID_found (should do anyway on re-entry into ISR)
LINSleep = 0; // Clear LINSleep flag - there is bus activity
break;
case 0x30: //___________ID Parity Error______________________
break;
case 0x34: //___________Inconsistent-Synch-Field Error_______
break;
case 0x38: //___________<reserved>___________________________
break;
case 0x3C: //___________Wakeup_______________________________
break;
} //___ end switch temp_SLCSV
SLCS_SLCF = 1; // Clear SLIC interrupt flag
} //_______________________________________________end_SLIC_ISR_______
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -