can_test_project/src/hardware_setup.c

00001 #include <includes.h>
00002 
00003 void setup_hardware(void){
00004     
00005   SCS |= 1<<0;//Enable fast gpio on port 0.
00006   SCS |= 1<<1;//Enable fast gpio on port 1.
00007 
00008   /*********************************************************************/
00009   /* Timer0 Initialization                                             */
00010   /*********************************************************************/
00011   //initialize Timer0 for 1 ms ticks
00012   T0PR = 0;//no prescaling
00013   //T0PR = 9;//no prescaling
00014   //TODO: Update this value for 10 MHz clock...currently for 12 MHz (already done?)
00015   T0MR0 = (60000-1);//1 mS
00016   T0TCR = 1;//enabled for counting
00017   T0CTCR = 0;//simple timer
00018   T0MCR = 0x00000003;//interrupt and reset on MR0
00019   
00020   VICVectAddr0 = (unsigned long)timer0_isr;
00021   VICVectCntl0 = 0x20 | 4; /* Timer1 Interrupt */
00022   VICIntEnable = 1 << 4;   /* Enable Timer1 Interrupt */
00023 
00024   /*********************************************************************/
00025   /* CAN Initialization                                             */
00026   /*********************************************************************/  
00027 //  PINSEL1&=~(3<<18);
00028   PINSEL1 |= 1<<18;     // enable CAN controller 1 pin RD1 (TD1 not PINSELable)
00029   FIO0DIR |= 1<<25;//Set 0.25 CAN RD1 To output...wait, why?
00030   C1MOD = 1;
00031 //  C1CMR = 1<<1; //Abort transmission?  Because maybe putting the controller into reset mode isn't enough?
00032   C1CMR = 0;
00033   C1GSR = 0;
00034   C1IER = 0;
00035   //C1BTR = 0;              // default value for BTR
00036   C1BTR = (0<<23)|(2<<20)|(5<<16)|(1<<14)|(0<<10)|(1<<0);
00037   //  C2BTR_bit.BRP = 1;            // osc. freq. = 60MHz  assume VPB = 60MHz
00038   //  C2BTR_bit.SJW = 1;            // Synchronization Jump Width
00039   //  C2BTR_bit.TSEG1 = 5;          // Time Segment1 = 5+1 = 6
00040   //  C2BTR_bit.TSEG2 = 2;          // Time Segment2 = 2+1 = 3
00041   //  C2BTR_bit.SAM = 0;            // sample once, baud rate = 6MHz
00042 
00043    // default values
00044   C1TFI1 = 0;
00045   C1TFI2 = 0;
00046   C1TFI3 = 0;
00047   C1TID1 = 0;
00048   C1TID2 = 0;
00049   C1TID3 = 0;
00050   C1TDA1 = 0;
00051   C1TDA2 = 0;
00052   C1TDA2 = 0; 
00053   C1TDB1 = 0;
00054   C1TDB2 = 0;
00055   C1TDB3 = 0;
00056   
00057  
00058   C1IER |= 1<<1; //Turn on Tx 1 interrupt
00059   C1IER |= 1<<0; //Turn on RX interrupt
00060   
00061 //  C1GSR = 0;//clear error counters
00062   C1MOD = 0;//Turn off RM
00063   
00064   // acceptance filter: bypass
00065   //  AFMR_bit.AccBP=1;
00066   //  AFMR_bit.AccOff=0;
00067   AFMR = 1<<1;
00068 //  IO1DIR|=1<<18;//Enable CAN tranceiver
00069 //  IO1CLR= 1<<18;
00070 
00071   FIO1DIR|=1<<18;//Enable CAN tranceiver
00072   FIO1CLR= 1<<18;
00073   
00074 
00075   
00076   /*********************************************
00077    * Put user initialization code below here.  *
00078    *********************************************/ 
00079   /***********************************************
00080    * Heartbeat Init Section
00081    * Set pin direction to output for driving LEDs
00082    * Set initial LED state
00083    ***********************************************/
00084 
00085  
00086  //Set P0.0 to TXD0 and P0.1 to RXD0 
00087   PINSEL0 &= ~(0xF);
00088   PINSEL0 |= 0x5;
00089  
00090   U0LCR = (1<<7);//DLAB = 1 to enable baud rate changes
00091   //Rate config from Jason for 115.2k, with 1+0.3 frac divider and pclk = 60MHz
00092   U0DLL = 25;
00093   U0DLM = 0;
00094   U0FDR = 3;//DIVADDVAL = 3
00095   U0FDR |= 10<<4;//MULTVAL = 10;
00096   //
00097   
00098   U0LCR = (0<<7)|(3<<0);//DLAB = 0 to disable baud rate changes, Wordsize = 3 for 8 bit words
00099   
00100 //  U0IER = (1<<1);//1: Enable THRE interrupt
00101   
00102   IO0DIR |= 1<<10; //Unassert SHDN_L on uart level shifter
00103   IO0SET = 1<<10;
00104  
00105  
00106  
00107 //  IO1DIR = 1<<23|1<<24|1<<25;
00108 //  IO1SET = 1<<23|1<<24|1<<25; 
00109 //  IO1CLR = 1<<25;
00110 //  IO1SET = 1<<23|1<<24;
00111 
00112   FIO1DIR |= 1<<23|1<<24|1<<25;
00113   FIO1SET = 1<<23|1<<24|1<<25; 
00114   FIO1CLR = 1<<25;
00115   
00116   /********* End Heartbeat Init Section ************/
00117 }
00118 
00119 void timer0_isr(void) __irq {
00120   T0IR = 0xFFFFFFFF;  // Clear ALL Timer0 interrupt flags.
00121   schedule_tick();
00122   VICVectAddr = 0;    // Clear interrupt in VIC.  
00123 }
Generated on Tue Jun 29 16:36:14 2010 by  doxygen 1.6.3