EE445M RTOS
Taken at the University of Texas Spring 2015
can Class Reference

#include <canpp.hpp>

Inheritance diagram for can:
Inheritance graph
Collaboration diagram for can:
Collaboration graph

Public Member Functions

 can ()
 
 can (memory_address_t can_base, uint32_t can_interrupt, bool can_sender, uint32_t msg_length)
 
virtual void start (void)
 
virtual void stop (void)
 
virtual uint32_t ack (void)
 
void pack (uint8_t *dest, uint32_t data, uint8_t offset=0)
 
void transmit (uint8_t *data, uint32_t length, uint32_t id=1)
 
void get (uint8_t *data)
 
void error_tx (void)
 
- Public Member Functions inherited from interruptable
 interruptable ()
 

Public Attributes

semaphore recv_sem
 

Private Member Functions

void set_timing (void)
 
void init (void)
 
uint32_t count_message (void)
 

Private Attributes

memory_address_t base
 
uint32_t interrupt
 
bool sender
 
tCANMsgObject sCANMessage
 
uint32_t errors_tx
 
uint32_t errors_rx
 
uint32_t messages_sent
 
uint32_t messages_received
 

Detailed Description

Definition at line 21 of file canpp.hpp.

Constructor & Destructor Documentation

can::can ( )

Definition at line 39 of file canpp.cpp.

39 {}
can::can ( memory_address_t  can_base,
uint32_t  can_interrupt,
bool  can_sender,
uint32_t  msg_length 
)

Initialize a can node.

Definition at line 41 of file canpp.cpp.

References base, CAN_MSG_OBJ, can_sender, init(), interrupt, sCANMessage, and sender.

42  {
43 
45  base = can_base;
46  interrupt = can_interrupt;
47 
48  init();
49 
50  switch(can_sender) {
51  case true:
52  sCANMessage.ui32MsgID = 1;
53  sCANMessage.ui32MsgIDMask = 0;
54  sCANMessage.ui32Flags = MSG_OBJ_TX_INT_ENABLE;
55  sCANMessage.ui32MsgLen = msg_length;
56  break;
57  case false:
58  // Initialize a message object to be used for receiving CAN messages with
59  // any CAN ID. In order to receive any CAN ID, the ID and mask must both
60  // be set to 0, and the ID filter enabled.
61  sCANMessage.ui32MsgID = 0;
62  sCANMessage.ui32MsgIDMask = 0;
63  sCANMessage.ui32Flags = MSG_OBJ_RX_INT_ENABLE | MSG_OBJ_USE_ID_FILTER;
64  sCANMessage.ui32MsgLen = msg_length;
65  // Load the message object into the CAN peripheral. Once
66  // loaded the CAN will receive any message on the bus, and an
67  // interrupt will occur. Use message object 1 for receiving
68  // messages (this is distinct from the CAN ID).
69  CANMessageSet(base, CAN_MSG_OBJ, &sCANMessage, MSG_OBJ_TYPE_RX);
70  break;
71  default: while(1) {}
72  }
73 }
tCANMsgObject sCANMessage
Definition: canpp.hpp:27
memory_address_t base
Definition: canpp.hpp:23
const bool can_sender
Definition: move-main.cpp:58
void init(void)
Definition: canpp.cpp:17
uint32_t interrupt
Definition: canpp.hpp:24
#define CAN_MSG_OBJ
Definition: canpp.cpp:15
bool sender
Definition: canpp.hpp:25

Here is the call graph for this function:

Member Function Documentation

uint32_t can::ack ( void  )
virtual

Acknowledge CAN interrupt

Implements interruptable.

Definition at line 146 of file canpp.cpp.

References base, and count_message().

Referenced by CAN0_Handler().

146  {
147 
148  /* Read the CAN interrupt status to find the cause of the interrupt */
149  uint32_t ui32Status = CANIntStatus(base, CAN_INT_STS_CAUSE);
150  CANIntClear(base, ui32Status);
151  count_message();
152  return ui32Status;
153 }
memory_address_t base
Definition: canpp.hpp:23
uint32_t count_message(void)
Definition: canpp.cpp:135

Here is the call graph for this function:

Here is the caller graph for this function:

uint32_t can::count_message ( void  )
private

Add a message to the global count.

Definition at line 135 of file canpp.cpp.

References messages_received, messages_sent, and sender.

Referenced by ack().

135  {
136 
137  uint32_t ret;
138  switch(sender) {
139  case true: ret = ++messages_sent; break;
140  case false: ret = ++messages_received; break;
141  default: while(1) {}
142  }
143  return ret;
144 }
uint32_t messages_sent
Definition: canpp.hpp:31
uint32_t messages_received
Definition: canpp.hpp:32
bool sender
Definition: canpp.hpp:25

Here is the caller graph for this function:

void can::error_tx ( void  )

Register a tx error.

Definition at line 97 of file canpp.cpp.

References errors_tx.

Referenced by CAN0_Handler().

97  {
98 
99  ++errors_tx;
100 }
uint32_t errors_tx
Definition: canpp.hpp:29

Here is the caller graph for this function:

void can::get ( uint8_t *  data)

Set mailbox for received can message data.

Definition at line 102 of file canpp.cpp.

References base, errors_rx, and sCANMessage.

Referenced by can_handler().

102  {
103 
104  sCANMessage.pui8MsgData = data;
105  CANMessageGet(base, 1, &sCANMessage, 0);
106  if(sCANMessage.ui32Flags & MSG_OBJ_DATA_LOST) {
107  ++errors_rx;
108  }
109 }
uint32_t errors_rx
Definition: canpp.hpp:30
tCANMsgObject sCANMessage
Definition: canpp.hpp:27
memory_address_t base
Definition: canpp.hpp:23

Here is the caller graph for this function:

void can::init ( void  )
private

Shared init between constructors.

Definition at line 17 of file canpp.cpp.

References base, ctlsys::enable_periph(), errors_rx, errors_tx, interrupt, messages_received, messages_sent, recv_sem, and start().

Referenced by can().

17  {
18 
19  errors_rx = 0;
20  errors_tx = 0;
21  messages_sent = 0;
23 
24  SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
26  GPIOPinConfigure(GPIO_PB4_CAN0RX);
27  GPIOPinConfigure(GPIO_PB5_CAN0TX);
28  GPIOPinTypeCAN(GPIO_PORTB_BASE, GPIO_PIN_4 | GPIO_PIN_5);
29 
30  CANInit(base);
31 
32  recv_sem = semaphore();
33 
34  CANBitRateSet(base, SysCtlClockGet(), 500000);
35  IntEnable(interrupt);
36  start();
37 }
uint32_t errors_tx
Definition: canpp.hpp:29
uint32_t messages_sent
Definition: canpp.hpp:31
virtual void start(void)
Definition: canpp.cpp:85
semaphore recv_sem
Definition: canpp.hpp:69
uint32_t errors_rx
Definition: canpp.hpp:30
memory_address_t base
Definition: canpp.hpp:23
uint32_t interrupt
Definition: canpp.hpp:24
uint32_t messages_received
Definition: canpp.hpp:32
static void enable_periph(uint32_t sys_periph)
Definition: ctlsysctl.hpp:24

Here is the call graph for this function:

Here is the caller graph for this function:

void can::pack ( uint8_t *  dest,
uint32_t  data,
uint8_t  offset = 0 
)

Definition at line 111 of file canpp.cpp.

111  {
112 
113  uint8_t i;
114  for(i=0; i<sizeof(data); ++i) {
115  /* todo: perfect the endian-swap */
116  *(dest+offset) = (uint8_t) (data & (0xFF << (i*4)));
117  }
118 }
void can::set_timing ( void  )
private

Configure CAN for 1 Mbit operation – http://bit.ly/1CW7hUO

Definition at line 75 of file canpp.cpp.

References base.

75  {
76 
77  tCANBitClkParms psClkParms;
78  psClkParms.ui32SyncPropPhase1Seg = 5; /* from 2 to 16 */
79  psClkParms.ui32Phase2Seg = 2; /* from 1 to 8 */
80  psClkParms.ui32QuantumPrescaler = 1; /* from 1 to 1023 */
81  psClkParms.ui32SJW = 2; /* from 1 to 4 */
82  CANBitTimingSet(base, &psClkParms);
83 }
memory_address_t base
Definition: canpp.hpp:23
void can::start ( void  )
virtual

Start CAN transmissions.

Implements interruptable.

Definition at line 85 of file canpp.cpp.

References base.

Referenced by init().

85  {
86 
87  CANIntEnable(base, CAN_INT_MASTER | CAN_INT_ERROR | CAN_INT_STATUS);
88  CANEnable(base);
89 }
memory_address_t base
Definition: canpp.hpp:23

Here is the caller graph for this function:

void can::stop ( void  )
virtual

Stop CAN transmissions.

Implements interruptable.

Definition at line 91 of file canpp.cpp.

References base.

91  {
92 
93  CANIntDisable(base, CAN_INT_MASTER | CAN_INT_ERROR | CAN_INT_STATUS);
94  CANDisable(base);
95 }
memory_address_t base
Definition: canpp.hpp:23
void can::transmit ( uint8_t *  data,
uint32_t  length,
uint32_t  id = 1 
)

Transmit a message via CAN.

note this function will cause the message to be transmtted immediately.

Definition at line 122 of file canpp.cpp.

References base, CAN_MSG_OBJ, and sCANMessage.

Referenced by can_transmitter().

122  {
123 
124  sCANMessage.ui32MsgID = id;
125  sCANMessage.ui32MsgIDMask = 0;
126  sCANMessage.ui32Flags = MSG_OBJ_TX_INT_ENABLE;
127  sCANMessage.ui32MsgLen = length;
128  sCANMessage.pui8MsgData = data;
129 
130  CANMessageSet(base, CAN_MSG_OBJ, &sCANMessage, MSG_OBJ_TYPE_TX);
131 
132  /* todo: resend if errors occured */
133 }
tCANMsgObject sCANMessage
Definition: canpp.hpp:27
memory_address_t base
Definition: canpp.hpp:23
#define CAN_MSG_OBJ
Definition: canpp.cpp:15

Here is the caller graph for this function:

Member Data Documentation

memory_address_t can::base
private

Definition at line 23 of file canpp.hpp.

Referenced by ack(), can(), get(), init(), set_timing(), start(), stop(), and transmit().

uint32_t can::errors_rx
private

Definition at line 30 of file canpp.hpp.

Referenced by get(), and init().

uint32_t can::errors_tx
private

Definition at line 29 of file canpp.hpp.

Referenced by error_tx(), and init().

uint32_t can::interrupt
private

Definition at line 24 of file canpp.hpp.

Referenced by can(), and init().

uint32_t can::messages_received
private

Definition at line 32 of file canpp.hpp.

Referenced by count_message(), and init().

uint32_t can::messages_sent
private

Definition at line 31 of file canpp.hpp.

Referenced by count_message(), and init().

semaphore can::recv_sem

Definition at line 69 of file canpp.hpp.

Referenced by CAN0_Handler(), can_handler(), and init().

tCANMsgObject can::sCANMessage
private

Definition at line 27 of file canpp.hpp.

Referenced by can(), get(), and transmit().

bool can::sender
private

Definition at line 25 of file canpp.hpp.

Referenced by can(), and count_message().


The documentation for this class was generated from the following files: