data_nexus.c

00001 #include <includes.h>
00002 
00004 // Define ring buffers for data flow in the CAN-SSP router board
00005 
00006 // CAN receive: The four CAN controllers share a single receive ring buffer
00007 const unsigned short can_rx_frame_buf_len = 64;
00008 CAN_RING can_rx_ring;
00009 CAN_FRAME can_rx_frame_buf[can_rx_frame_buf_len];
00010 
00011 // CAN transmit: Each of the four controllers has its own transmit ring buffer
00012 const unsigned short can_tx_frame_buf_len = 8;
00013 CAN_RING can_tx_ring1;
00014 CAN_FRAME can_tx_frame_buf1[can_tx_frame_buf_len];
00015 CAN_RING can_tx_ring2;
00016 CAN_FRAME can_tx_frame_buf2[can_tx_frame_buf_len];
00017 CAN_RING can_tx_ring3;
00018 CAN_FRAME can_tx_frame_buf3[can_tx_frame_buf_len];
00019 CAN_RING can_tx_ring4;
00020 CAN_FRAME can_tx_frame_buf4[can_tx_frame_buf_len];
00021 
00022 // Set up ring name and buffer for CAN-SSP
00023 // outer board transmit (Error codes, battery voltage, system power, bus loading, etc.)
00024 const unsigned short router_tx_frame_buf_len = 8;
00025 CAN_RING router_tx_ring;
00026 CAN_FRAME router_tx_frame_buf[router_tx_frame_buf_len];
00027 
00029 
00030 void router_data_nexus_init(void)
00031 {
00032   
00033   // Initialize CAN descriptor lists (not used in router board)
00034   can_rx_set_descriptors(NULL, NULL);
00035 
00036   // Initialize common CAN receive ring
00037   can_ring_init(&can_rx_ring, can_rx_frame_buf, can_rx_frame_buf_len);
00038 
00039   // Initialize individual CAN transmit rings, and set channel configurations
00040   // CAN dispatch is "manual" - incoming frames go to the receive ring buffer
00041 
00042   // ********* CAN1 ***********
00043   can_ring_init(&can_tx_ring1, can_tx_frame_buf1, can_tx_frame_buf_len);
00044   can_tx_set_chan_cfg(CHAN_CAN1, (volatile unsigned long *)0xE0044000, &can_tx_ring1);
00045   can_rx_set_chan_cfg(CHAN_CAN1, (volatile unsigned long *)0xE0044000, &can_rx_ring, CAN_DISPATCH_MANUAL);
00046 
00047    // ******** CAN2 ***********
00048   can_ring_init(&can_tx_ring2,can_tx_frame_buf2, can_tx_frame_buf_len);
00049   can_tx_set_chan_cfg(CHAN_CAN2, (volatile unsigned long *)0xE0048000, &can_tx_ring2);
00050   can_rx_set_chan_cfg(CHAN_CAN2, (volatile unsigned long *)0xE0048000, &can_rx_ring,CAN_DISPATCH_MANUAL);
00051 
00052    // ******** CAN3 ***********
00053   can_ring_init(&can_tx_ring3, can_tx_frame_buf3, can_tx_frame_buf_len);
00054   can_tx_set_chan_cfg(CHAN_CAN3, (volatile unsigned long *)0xE004C000, &can_tx_ring3);
00055   can_rx_set_chan_cfg(CHAN_CAN3, (volatile unsigned long *)0xE004C000, &can_rx_ring,CAN_DISPATCH_MANUAL);
00056 
00057    // ******** CAN4 ***********
00058   can_ring_init(&can_tx_ring4, can_tx_frame_buf4, can_tx_frame_buf_len);
00059   can_tx_set_chan_cfg(CHAN_CAN4, (volatile unsigned long *)0xE0050000, &can_tx_ring4);
00060   can_rx_set_chan_cfg(CHAN_CAN4,(volatile unsigned long *)0xE0050000,&can_rx_ring,CAN_DISPATCH_MANUAL);
00061 
00062   // Initialize ring buffer for router board transmit (error codes, voltage, power, CAN bus load, etc.)
00063   can_ring_init(&router_tx_ring, router_tx_frame_buf, router_tx_frame_buf_len);
00064 }
00065 
00067 //Take incoming data from SSP receive buffer and CAN receive buffer.
00068 //Call csr_route_frame to distribute it to the correct locations
00069 void route_frames(void)
00070 {
00071   CAN_FRAME frame;
00072 
00073   //pop one CAN frame pointer from ssp; route if available
00074   if (!csr_pop_ssp_frame(&frame))
00075   {
00076     // **** TEST CODE ****  line below commented out for testing.
00077     csr_route_frame(&frame);
00078   }
00079 
00080   //pop one CAN frame from CAN receive buffer; route if available
00081   if (!can_ring_pop(&can_rx_ring, &frame))
00082   {
00083 // **** TEST CODE ****  line below should be commented out for bench testing with interconnected CAN buses.
00084     csr_route_frame(&frame);
00085   }
00086 
00087   //pop one CAN frame from router board transmit buffer; route if available
00088   if (!can_ring_pop(&router_tx_ring, &frame))
00089   {
00090     csr_route_frame(&frame);
00091   }
00092   
00093 }
00094 
00095 // Build error frame, and push it onto the router board ring buffer for transmission to main brain
00096  void router_error_transmit(void)
00097  {
00098    CAN_FRAME frame;
00099    
00100    //Build CSR error frame
00101    frame.addr = ID_ERROR_CSR;
00102    frame.dlc = 8;
00103    frame.rtr = 0;
00104    frame.chan = CHAN_ROUTER;
00105    frame.payload.w.w1 = error_get_info();
00106    frame.payload.w.w2 = error_get_time();
00107 
00108   //Push frame onto router board (csr) ring buffer
00109    can_ring_push(&router_tx_ring, &frame);
00110  }
Generated on Tue Jun 29 16:36:14 2010 by  doxygen 1.6.3