Unit tests for LIN service.
Copyright (c) 2011-2018 Microchip Technology Inc. and its subsidiaries.
#include "asf.h"
#include <stdint.h>
#include <stdbool.h>
#include <board.h>
#include <sysclk.h>
#include <lin.h>
#include <string.h>
#include <unit_test/suite.h>
#include <stdio_serial.h>
#include <conf_test.h>
#include <conf_board.h>
Macros | |
#define | LIN_FIRST_BYTE 0x55 |
First byte for test. More... | |
#define | LIN_FRAME_ID_12 0x12 |
LIN frame number. More... | |
#define | LIN_MASTER_NODE_NUM 0 |
LIN master node number. More... | |
#define | TC_CHANNEL 0 |
Timer counter channel used. More... | |
#define | TC_FREQ 20 |
Timer counter frequency in Hz. More... | |
Functions | |
static void | configure_tc (void) |
Configure Timer Counter 0 (TC0) to generate an interrupt every 200ms. More... | |
static void | delay_ms (uint32_t ul_dly_ticks) |
Delay number of tick Systicks (happens every 1 ms). More... | |
static void | lin_master_task_ID12 (void) |
lin_master_task_ID12. More... | |
int | main (void) |
Run LIN service unit tests. More... | |
static void | run_lin_test (const struct test_case *test) |
Test LIN transmit. More... | |
void | SysTick_Handler (void) |
SysTick handler. More... | |
void | TC0_Handler (void) |
Interrupt handler for TC0. More... | |
void | USART0_Handler (void) |
Interrupt handler for USART. More... | |
Variables | |
static volatile uint32_t | gs_ul_ms_ticks = 0U |
Systick Counter. More... | |
uint8_t | lin_data_node [8] |
Local Buffer for emission. More... | |
static uint32_t | ul_LIN_int_flag =0 |
LIN interrupt received flag. More... | |
#define LIN_FIRST_BYTE 0x55 |
First byte for test.
Referenced by lin_master_task_ID12().
#define LIN_FRAME_ID_12 0x12 |
LIN frame number.
Referenced by lin_master_task_ID12(), and run_lin_test().
#define LIN_MASTER_NODE_NUM 0 |
LIN master node number.
Referenced by lin_master_task_ID12(), and run_lin_test().
#define TC_CHANNEL 0 |
Timer counter channel used.
#define TC_FREQ 20 |
Timer counter frequency in Hz.
Referenced by configure_tc().
|
static |
Configure Timer Counter 0 (TC0) to generate an interrupt every 200ms.
This interrupt will be used to flush USART input and echo back.
References pmc_enable_periph_clk(), sysclk_get_cpu_hz(), tc_enable_interrupt(), tc_find_mck_divisor(), TC_FREQ, tc_init(), and tc_write_rc().
Referenced by run_lin_test().
|
static |
Delay number of tick Systicks (happens every 1 ms).
References gs_ul_ms_ticks.
Referenced by run_lin_test().
|
static |
lin_master_task_ID12.
References lin_data_node, LIN_FIRST_BYTE, LIN_FRAME_ID_12, LIN_MASTER_NODE_NUM, and lin_send_cmd().
Referenced by TC0_Handler().
int main | ( | void | ) |
Run LIN service unit tests.
References uart_rs232_options::baudrate, board_init(), DEFINE_TEST_ARRAY, DEFINE_TEST_CASE, DEFINE_TEST_SUITE, NULL, run_lin_test(), stdio_serial_init(), sysclk_enable_peripheral_clock(), sysclk_get_cpu_hz(), sysclk_init(), test_suite_run(), and usart_serial_options.
|
static |
Test LIN transmit.
This test initializes the LIN and start a transmit.
test | Current test case. |
References configure_tc(), delay_ms(), gpio_set_pin_high, st_lin_message::lin_cmd, lin_data_node, LIN_FRAME_ID_12, lin_init(), LIN_MASTER_NODE_NUM, lin_register_descriptor(), pmc_enable_periph_clk(), PUBLISH, sysclk_get_cpu_hz(), tc_start(), test_assert_true, st_lin_message::uc_dlc, st_lin_message::uc_id, st_lin_message::uc_pt_data, st_lin_message::uc_status, ul_LIN_int_flag, and usart_enable_interrupt().
Referenced by main().
void SysTick_Handler | ( | void | ) |
SysTick handler.
References gs_ul_ms_ticks.
void TC0_Handler | ( | void | ) |
Interrupt handler for TC0.
Record the number of bytes received, and then restart a read transfer on the USART if the transfer was stopped.
References lin_master_task_ID12(), and tc_get_status().
void USART0_Handler | ( | void | ) |
Interrupt handler for USART.
Echo the bytes received and start the next receive.
References ul_LIN_int_flag, usart_disable_interrupt(), and usart_get_status().
|
static |
Systick Counter.
Referenced by delay_ms(), and SysTick_Handler().
uint8_t lin_data_node[8] |
Local Buffer for emission.
Referenced by lin_master_task_ID12(), main(), and run_lin_test().
|
static |
LIN interrupt received flag.
Referenced by run_lin_test(), and USART0_Handler().