| Electronic Components Datasheet Search |
|
UM0851 Datasheet(PDF) 109 Page - STMicroelectronics |
|
|
|||||||||||||||||||||||||||||
UM0851 Datasheet(HTML) 109 Page - STMicroelectronics |
|
109 / 245 page ![]() UM0851 Communication device drivers Doc ID 16604 Rev 2 109/245 void (*write_reg)(struct net_device *dev, enum c_regs reg, u16 val); #ifdef CCAN_DEBUG unsigned int bufstat[MAX_OBJECT + 1]; #endif }; To write and read the CAN IP registers the APIs spr_can_write_reg() and spr_can_read_reg() are used respectively: static u16 spr_can_read_reg(struct net_device *dev, enum c_regs reg); static void spr_can_write_reg(struct net_device *dev, enum c_regs reg, u16 val); 4.9.5 User-land applications over the CAN driver This section describes how to design a simple application that accesses the services provided by the CAN driver. For designing a typical user-land application that uses the CAN driver, the following steps should be followed: To open a socket for communicating over a CAN network: 1. Pass PF_CAN as the first argument to the socket() system call. Currently, there are two CAN protocols to choose from, the raw socket protocol (RAW) and the broadcast manager (BCM): /* Open a RAW socket */ s = socket(PF_CAN, SOCK_RAW, CAN_RAW); /* Open a BCM socket */ s = socket(PF_CAN, SOCK_DGRAM, CAN_BCM); 2. Now, bind the socket to a CAN interface using the bind() system call. An example of binding a raw socket to the CAN interface can0 is given below: int s; struct sockaddr_can addr; struct ifreq ifr; s = socket(PF_CAN, SOCK_RAW, CAN_RAW); strcpy(ifr.ifr_name, "can0" ); ioctl(s, SIOCGIFINDEX, &ifr); addr.can_family = AF_CAN; addr.can_ifindex = ifr.ifr_ifindex; bind(s, (struct sockaddr *)&addr, sizeof(addr)); 3. After binding (CAN_RAW) or connecting (CAN_BCM) the socket, you can read and write from/to the socket using read() and write() APIs respectively: /* Read nbytes from a CAN socket */ nbytes = read(s, &frame, sizeof(struct can_frame)); /* Write nbytes to a CAN socket */ nbytes = write(s, &frame, sizeof(struct can_frame)); You can also use other standard APIs like send(), sendto(), sendmsg() and recv() to perform the desired operations on the socket. |
|
Link URL |
| Does ALLDATASHEET help your business so far? [ DONATE ] |
About Alldatasheet | Advertisement | Contact us | Privacy Policy | Link to Datasheet | Link Exchange | Manufacturer List All Rights Reserved©Alldatasheet.com |
| Russian : Alldatasheetru.com | Korean : Alldatasheet.co.kr | Spanish : Alldatasheet.es | French : Alldatasheet.fr | Italian : Alldatasheetit.com Portuguese : Alldatasheetpt.com | Polish : Alldatasheet.pl | Vietnamese : Alldatasheet.vn Indian : Alldatasheet.in | Mexican : Alldatasheet.com.mx | British : Alldatasheet.co.uk | New Zealand : Alldatasheet.co.nz |
|
Family Site : ic2ic.com |
icmetro.com |