Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

We’re showing branches in this repository, but you can also compare across forks.

base fork: hartmutbehrens/CAN_Ethernet
base: 5164d891e2
...
head fork: hartmutbehrens/CAN_Ethernet
compare: bce2a5cf2c
  • 2 commits
  • 5 files changed
  • 0 commit comments
  • 1 contributor
Showing with 10 additions and 14 deletions.
  1. +1 −1  c2e_can.c
  2. +2 −3 c2e_main.c
  3. +2 −4 c2e_main.h
  4. +3 −5 c2e_udp.c
  5. +2 −1  config.h
2  c2e_can.c
View
@@ -40,7 +40,7 @@ static void write_to_ringbuf(tCANMsgObject *can_object, uint32_t id)
unsigned char frame[CAN_FRAME_SIZE];
uint32_to_uchar(&frame[0], can_object->ulMsgID); // convert ID to char so that it is suitable to sending over UDP
- memcpy(&frame[4], &(can_object->pucMsgData[id*8]), 8 ); // copy CAN data into frame
+ memcpy(&frame[CAN_DATA_POS], &(can_object->pucMsgData[id*8]), 8 ); // copy CAN data into frame
frame[EXT_FLAG_POS] = (can_object->ulFlags & MSG_OBJ_EXTENDED_ID) ? 1 : 0; // flag to indicate whether CAN message is using extended ID's
frame[RTR_FLAG_POS] = (can_object->ulFlags & MSG_OBJ_REMOTE_FRAME) ? 1 : 0; // flag to indicate whether CAN frame transmission was requested by remote node
RingBufWrite(&g_can_ringbuf, &frame[0], CAN_FRAME_SIZE);
5 c2e_main.c
View
@@ -86,7 +86,7 @@ static uint32_t wait(void)
}
//display a IP address
-void display_ip_address(void)
+static void display_ip_address(void)
{
unsigned char *temp = (unsigned char *)&g_netif->ip_addr.addr;
// Convert the IP Address into a string for display purposes
@@ -95,7 +95,7 @@ void display_ip_address(void)
}
//display state
-void display_state(void)
+static void display_state(void)
{
usprintf(print_buf, "%d ", g_state);
RIT128x96x4StringDraw(print_buf, 110, 10, 15);
@@ -186,7 +186,6 @@ void lwIPHostTimerHandler(void) // This
{
enqueue_event(EV_BROADCAST); // broadcast presence, if no gateways have announced themselves yet
}
-
}
6 c2e_main.h
View
@@ -2,8 +2,6 @@
#define __C2E_CAN_ETHERNET_H
#include <stdint.h>
-
-
static uint32_t fsm_any(void); // catch all state machine function that executes when STATE = ANY and EVENT = ANY
static uint32_t BOARD_init(void); // initialize clock, power, display
static uint32_t INT_init(void); // Master interrupt enable
@@ -13,9 +11,9 @@ static uint32_t handle_IP_change(void); // handle a change in IP address
static uint32_t handle_GW_change(void); // handle an addition of GW
static uint32_t broadcast_presence(void);
static void load_boot_events(void); // enqueue the events required to boot the board
+static void display_state(void); // display state machine state
+static void display_ip_address(void); // display an lwIP address
-void display_state(void); // display state machine state
-void display_ip_address(void); // display an lwIP address
void netif_status_change(struct netif *netif);
void SYSTICK_handler(void);
8 c2e_udp.c
View
@@ -132,18 +132,16 @@ void UDP_send_msg(unsigned char *message, uint32_t size, struct ip_addr *ip_addr
udp_remove(pcb);
}
-static void process_CAN_data(unsigned char *data, uint32_t size)
+static void process_received_data(unsigned char *data, uint32_t size)
{
uint32_t position = 0;
while (position < size) // more than one CAN frame might be embedded
{
- unsigned char CAN_data[8];
uint32_t CAN_id = uchar_to_uint32(&data[CAN_ID_POS]);
- memcpy(&CAN_data,&data[0],8);
uint32_t ext_id_flag = data[EXT_FLAG_POS]; // CAN extended ID flag
uint32_t remote_tx_flag = data[RTR_FLAG_POS];
position += CAN_FRAME_SIZE;
- CAN_transmit(&CAN_data[0], 8, CAN_id, ext_id_flag, remote_tx_flag);
+ CAN_transmit(&data[CAN_DATA_POS], 8, CAN_id, ext_id_flag, remote_tx_flag);
udp_rx_count += 1;
update_count += 1;
}
@@ -168,7 +166,7 @@ void UDP_receive(void *arg, struct udp_pcb *pcb, struct pbuf *p, struct ip_addr
if ( message_starts_with(data, C2E_DATA_ID) ) // received a message with CAN data, so send it out on the CAN i/f
{
uint32_t id_size = sizeof(C2E_DATA_ID);
- process_CAN_data(&data[id_size], (p->len - id_size) );
+ process_received_data(&data[id_size], (p->len - id_size) );
}
if ( message_starts_with(data, C2E_BROADCAST_ID) ) // found a gateway, so add the IP address to the list of known gateways
{
3  config.h
View
@@ -23,7 +23,8 @@ typedef struct
#define CAN_FIFO_SIZE (8 * 8) // size of FIFO buffers allocated to the CAN controller - 8 messages can each hold a max of 8 bytes
#define CAN_BITRATE 1000000 // set CAN bitrate to 1Mbps
#define MAX_CAN_GATEWAYS 4 // number of CAN gateways to keep track of
-#define CAN_ID_POS 0 // position of CAN message ID in CAN frame
+#define CAN_ID_POS 0 // position of CAN message ID in CAN frame
+#define CAN_DATA_POS 4 // position of CAN data in CAN frame
#define EXT_FLAG_POS 12 // position of CAN extended ID flag in CAN frame
#define RTR_FLAG_POS 13 // position of CAN remote transmission flag in CAN frame
#define TRIGGER_THRESHOLD 1 // number of received CAN frames required to trigger a UDP send

No commit comments for this range

Something went wrong with that request. Please try again.