# can_adapter

CAN to UART adapter library

Author | William Welch Copyright © 2010, all rights reserved.
Adapted-by |
Compiler | 2.4m

Description

    bridge/gateway between RS232 and CAN bus. Uses ASCII encapsulation,
             compatible with the Socket-CAN SLCAN API, and adapters such as
             LAWICEL and VScom USB-CAN.

Sources

    Socket-CAN, in particular the SLCAN API. http://developer.berlios.de/projects/socketcan/
             also, the LAWICEL CAN-USB and Easylink adapter manuals.

Dependencies

No dependency found

## Summary

### Global variables/contants

- `var volatile byte can_ascii_rxcnt = 0`
- `var volatile byte can_ascii_rxbuf[32]`
- `var bit can_adapter_is_open = 0`

### Procedures

- `can_check_uart_rx(volatile byte out device, byte in ch)`

Private

- `_can_pdec8(volatile byte out device, byte in n)`

### Functions

- `can_open_cmd(volatile byte out device, byte in ascii_buf[32]) return bit`
- `can_closed_cmd(volatile byte out device, byte in ascii_buf[32]) return bit`
- `can_check_can_rx(volatile byte out device, dword in out can_id, byte in out can_data[8], byte in out data_len) return bit`
- `can_modeless_cmd(volatile byte out device, byte in ascii_buf[32]) return bit`

## API details

### Global variables/contants

- `var volatile byte can_ascii_rxcnt = 0`

  No documentation found

- `var volatile byte can_ascii_rxbuf[32]`

  No documentation found

- `var bit can_adapter_is_open = 0`

  No documentation found

### Procedures

- `can_check_uart_rx(volatile byte out device, byte in ch)`

      this routine is used to process incoming characters from the UART.
      the data stream is line-oriented ASCII, with a CR(13) terminator.
      sometimes the data is a command, which may need a reply back out
      the UART.  But most of the time, the data is encapsulated CAN messages
      which need to be sent out the CANbus.
      device: uart data device, e.g. serial_hw_data
      ch:  received ASCII char from UART

Private

- `_can_pdec8(volatile byte out device, byte in n)`

  No documentation found

### Functions

- `can_open_cmd(volatile byte out device, byte in ascii_buf[32]) return bit`

      these commands are only valid while the bridge is 'open'
      this routine is primarily for internal use.

- `can_closed_cmd(volatile byte out device, byte in ascii_buf[32]) return bit`

      these commands are only valid while the bridge is 'closed'
      this routine is primarily for internal use.

- `can_check_can_rx(volatile byte out device, dword in out can_id, byte in out can_data[8], byte in out data_len) return bit`

      this routine encapsulates incoming CANbus messages, and sends the resulting ASCII out to the UART.
      a copy of the CANbus message is also returned to the caller.
      device: uart device, e.g. serial_hw_data

- `can_modeless_cmd(volatile byte out device, byte in ascii_buf[32]) return bit`

      these commands are always available
      this routine is primarily for internal use.

## Related samples

Here are the list of samples which use this library:

18f2585 | 18f2585_can_serial_adapter.jal
18f2585 | 18f2585_canid4_serial_adapter.jal