Contents
Part description
This is the firmware for the HA-B02 USB/dual-CAN bus interface. It translates and forwards messages back and forth between the host computer and the CAN devices on internal and external buses.
Revisions
HA-P04.01-nortos
Current development revision.
This implementation uses no operating system but a traditional endless loop approach. Currently, it looks like this will be a sufficiently performant implementation for the interface, so for now, this is the implementation where further development takes place.
HA-P04.01
Real-Time Operating System
This implementation is using the FreeRTOS 7.0.0 real-time operating system. No modifications to the RTOS kernel have been neccessary in the current state of development.
Protocol translation
A design decision had to be made where the reformatting of messages between formats used on the USB and formats used on CAN takes place. Because the tasks that watch the incoming data queues (filled by the interrupt handlers) have to parse the incoming messages anyways to classify them to be either forwarded to the other bus or used by the management task, they can also reformat the ones that shall be forwarded to whatever the sending routine needs.
Alternatives that are not used now would have been either a separate task that only reformats and forwards messages, or an internal format to which all messages would be converted by the t_*_rx tasks and from which the t_*_tx tasks would again convert them into whatever they are sending. Both look like additional overhead that is not solving any other problems, and therefore can be left out of the implementation.
Tasks
t_canmgr
The CAN bus requires certain management actions like configuration of the CAN controllers' filter settings, health checks and probably corrective actions like reset or power-down. This task does this kind of housekeeping. It creates and watches an incoming queue for UART- or CAN-based datagrams and can also write to the outgoing CAN/UART queues.
This task does the initial and runtime configuration of the CAN bus. Because the CAN bus must not (and usually cannot) be loaded with payload traffic when the CAN controllers are in configuration mode, this task initially spawns the t_can_tx thread. If a reconfiguration is to be done, it destroys the t_can_tx thread first, reconfigures the CAN controllers by direct access to the SPI port, and then restarts t_can_tx.
t_can_rx
This task waits for incoming CAN bus transmissions (in q_can_in) and classifies them to be either datagrams for use by the host computer or administrative traffic to be handled by the bus manager. According to this classification, it can either re-format them for the host computer and put them on the q_uart_tx queue or forward them to the CAN management thread by putting them on q_canmgr queue.
t_can_tx
This task waits for CAN transmissions to be sent out through either of the CAN buses from q_can_out and sends them to the bus through the MCU's SPI. Functional boundaries and interface between this task and t_spi is yet unclear.
t_spi
This task handles the actual SPI input/output by interfacing with the MCU's SPI hardware registers. It places received datagrams on q_can_in.
I currently have near to no clue how to implement this...
t_uart_rx
This task waits for incoming USB transmissions (from q_uart_in). It classifies them to be either management commands and places them on q_canmgr, or production traffic and places them on q_can_tx after reformatting them for CAN transmission.
t_uart_tx
This task waits for UART transmissions to be sent out to the USB host computer from q_uart_out and sends them to the bus through the MCU's UART.
Queues
q_can_in
Incoming CAN datagrams are placed on this queue by the SPI subsystem's message reception routines (in t_spi), which in turn are triggered from the two CAN controller interrupt handlers. It is consumed by t_can_rx.
q_can_out
CAN datagrams to be sent are placed on this queue by t_canmgr and t_uart_rx. It is consumed by t_can_tx.
q_uart_in
Incoming UART transmissions are placed on this queue by the UART interrupt handler. It is consumed by t_uart_rx.
q_uart_out
UART transmissions to be sent to the host computer are placed on this queue by t_canmgr and t_can_rx. It is consumed by t_uart_tx.
q_canmgr
The CAN bus manager task t_canmgr needs to communicate with CAN devices as well as the host computer. Messages from both interfaces that are not data to be forwarded to the respective other bus are placed on this queue by t_can_rx and t_uart_rx. It is consumed by t_canmgr.
THIS DATA IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS DATA, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
All product and brand names mentioned on there pages and in the source code are registered names and/or trademarks of the respective owner and are mentioned for identification purposes only.
For a full copyright notice, please see this link. For imprint and contact information, please see http://www.thiemo.net/.