00001 /* $Id: CAN.c,v 1.00 2005/15/11 08:30:00 BorisK Exp $ 00002 * 00003 * Copyright (C) 2005 ONTRACK s.r.o. 00004 * 00005 * This program is free software; you can redistribute it and/or 00006 * modify it under the terms of the GNU General Public License 00007 * as published by the Free Software Foundation; either version 2 00008 * of the License, or (at your option) any later version. 00009 * 00010 * This program is distributed in the hope that it will be useful, 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 * GNU General Public License for more details. 00014 * 00015 * You should have received a copy of the GNU General Public License 00016 * along with this program; if not, write to the Free Software 00017 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 00018 * 02111-1307, USA. 00019 * 00020 * Written by Boris Kralik <kralikbo@yahoo.com>, 2005. 00021 */ 00022 #include "CAN.h" 00023 #include "status.h" 00024 void CAN1_Init(void) 00025 { 00026 PCB_PINSEL1 &= 0x7FFFF; 00027 PCB_PINSEL1 |= (1 << 18);//Set pin P0.25 as RD1 00028 SCB_PCONP |= (1 << 13); 00029 CAN1_MOD = 0x00000001; //Set CAN controller into reset 00030 CAN1_BTR = 0x001C001D; //Set bit timing to 125k 00031 CAN1_IER = 0x00000005; 00032 CAN1_MOD = 0x00000000; //Release CAN controller 00033 WD_Reset(); 00034 } 00035 00036 void CAN2_Init() 00037 { 00038 uint16_t uiStatus=0; 00039 PCB_PINSEL1 &= 0xE7FFF; 00040 PCB_PINSEL1 |= ((1 << 16)|(1 << 14));//set pin P0.23 as RD2, P0.24 as TD2, 00041 SCB_PCONP |= (1 << 14); 00042 CAN2_MOD = 0x00000001; //Set CAN controller into reset 00043 CAN2_BTR = 0x001C001D; //Set bit timing to 125k 00044 CAN2_IER = 0x00000005; 00045 CAN2_MOD = 0x00000000; //Release CAN controller 00046 WD_Reset(); 00047 } 00048 00049 void CAN4_Init(void) 00050 { 00051 PCB_PINSEL0 |= ((1 << 24)|(1 << 25) | (1 << 26) | (1 << 27)); //Set P0.12 (RD4) and P0.13 (TD4) as CAN 00052 SCB_PCONP |= (1 << 16); 00053 CAN4_MOD = 0x00000001; //Set CAN controller into reset 00054 CAN4_BTR = 0x001C001D; //Set bit timing to 125k 00055 CAN4_IER = 0x00000005; 00056 CAN4_MOD = 0x00000000; //Release CAN controller 00057 WD_Reset(); 00058 } 00059 00060 uint16_t CAN1_Off(uint16_t uiStatus) 00061 { 00062 CAN1_MOD |= (1 << 0); 00063 SCB_PCONP &= 0xCFFF; 00064 uiStatus &= 0xDF; 00065 #if 0 00066 printf("\n\r\tuiStatus=0x%X"); 00067 #endif 00068 WD_Reset(); 00069 return uiStatus; 00070 } 00071 00072 uint16_t CAN2_Off( uint16_t uiStatus) 00073 { 00074 CAN2_MOD |= (1 << 0); 00075 SCB_PCONP &= 0xBFFF; 00076 uiStatus &= 0xBF; 00077 #if 1 00078 printf("\n\r\tuiStatus=0x%X"); 00079 #endif 00080 WD_Reset(); 00081 return uiStatus; 00082 } 00083 00084 uint16_t CAN4_Off(uint16_t uiStatus) 00085 { 00086 CAN4_MOD |= (1 << 0); 00087 SCB_PCONP &= 0x7FFF; 00088 uiStatus &= 0x7F; 00089 #if 1 00090 printf("\n\r\tuiStatus=0x%X"); 00091 #endif 00092 WD_Reset(); 00093 return uiStatus; 00094 } 00095 uint16_t CAN_Off(uint16_t uiStatus) 00096 { 00097 uiStatus = CAN1_Off(uiStatus); 00098 uiStatus = CAN2_Off(uiStatus); 00099 uiStatus = CAN4_Off(uiStatus); 00100 #if 1 00101 printf("\n\r\tCAN_Off:uiStatus=0x%X"); 00102 #endif 00103 WD_Reset(); 00104 return uiStatus; 00105 }
1.4.7