Repo unification
This commit is contained in:
96
firmware/tests/ut_board/ut_ain.c
Normal file
96
firmware/tests/ut_board/ut_ain.c
Normal file
@@ -0,0 +1,96 @@
|
||||
#include "ut_ain.h"
|
||||
|
||||
#include "..\mock_mcu\mock_mcu_hal_r8.h"
|
||||
#include "..\..\src\hw\board\ain.h"
|
||||
|
||||
static const uint8_t NOT_ACCESED_ADC_CH = 255;
|
||||
|
||||
static int ut_bsp_ain_read(uint8_t ain_ch, uint16_t adc_raw, uint16_t exp_out, uint8_t exp_adc_ch)
|
||||
{
|
||||
printf(" Input: Ain-Ch:%d Adc-Raw:%d \n", ain_ch, adc_raw);
|
||||
|
||||
mock_mcu_adc_set_ch(NOT_ACCESED_ADC_CH);
|
||||
mock_mcu_adc_set_raw(adc_raw, exp_adc_ch);
|
||||
|
||||
uint16_t out = bsp_ain_read(ain_ch);
|
||||
|
||||
uint8_t adc_ch = mock_mcu_adc_read_ch();
|
||||
|
||||
printf(" Output: AIN:%d Adc-Ch:%d \n", out, adc_ch);
|
||||
printf("Expected: AIN:%d Adc-Ch:%d \n", exp_out, exp_adc_ch);
|
||||
|
||||
if((out==exp_out)&&(adc_ch==exp_adc_ch))
|
||||
{
|
||||
printf("PASS\n\n");
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("FAIL\n\n");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
int ut_bsp_ain_read_test(void)
|
||||
{
|
||||
printf("******************************************************\n");
|
||||
printf("uint16_t bsp_ain_read(uint8_t ch)\n");
|
||||
|
||||
int test_res;
|
||||
int pass = 1;
|
||||
|
||||
uint8_t ain_ch;
|
||||
uint16_t adc_raw;
|
||||
uint16_t exp_out;
|
||||
uint8_t exp_adc_ch;
|
||||
|
||||
// Normal 1
|
||||
ain_ch = BSP_AIN1;
|
||||
adc_raw = 88;
|
||||
exp_out = 430;
|
||||
exp_adc_ch = MCU_ADC5;
|
||||
test_res = ut_bsp_ain_read(ain_ch, adc_raw, exp_out, exp_adc_ch);
|
||||
if(!test_res) pass = 0;
|
||||
|
||||
// Normal 2
|
||||
ain_ch = BSP_AIN2;
|
||||
adc_raw = 88;
|
||||
exp_out = 430;
|
||||
exp_adc_ch = MCU_ADC4;
|
||||
test_res = ut_bsp_ain_read(ain_ch, adc_raw, exp_out, exp_adc_ch);
|
||||
if(!test_res) pass = 0;
|
||||
|
||||
// Normal 3
|
||||
ain_ch = BSP_AIN3;
|
||||
adc_raw = 500;
|
||||
exp_out = 2443;
|
||||
exp_adc_ch = MCU_ADC8;
|
||||
test_res = ut_bsp_ain_read(ain_ch, adc_raw, exp_out, exp_adc_ch);
|
||||
if(!test_res) pass = 0;
|
||||
|
||||
// Norma 4
|
||||
ain_ch = BSP_AIN4;
|
||||
adc_raw = 1023;
|
||||
exp_out = 4998;
|
||||
exp_adc_ch = MCU_ADC14;
|
||||
test_res = ut_bsp_ain_read(ain_ch, adc_raw, exp_out, exp_adc_ch);
|
||||
if(!test_res) pass = 0;
|
||||
|
||||
// Normal 5
|
||||
ain_ch = BSP_AIN5;
|
||||
adc_raw = 1;
|
||||
exp_out = 4;
|
||||
exp_adc_ch = MCU_ADC15;
|
||||
test_res = ut_bsp_ain_read(ain_ch, adc_raw, exp_out, exp_adc_ch);
|
||||
if(!test_res) pass = 0;
|
||||
|
||||
// Not existing ADC channel
|
||||
ain_ch = 0;
|
||||
adc_raw = 500;
|
||||
exp_out = 0;
|
||||
exp_adc_ch = NOT_ACCESED_ADC_CH;
|
||||
test_res = ut_bsp_ain_read(ain_ch, adc_raw, exp_out, exp_adc_ch);
|
||||
if(!test_res) pass = 0;
|
||||
|
||||
return pass;
|
||||
}
|
||||
9
firmware/tests/ut_board/ut_ain.h
Normal file
9
firmware/tests/ut_board/ut_ain.h
Normal file
@@ -0,0 +1,9 @@
|
||||
#ifndef UT_BOARD_AIN_H_
|
||||
#define UT_BOARD_AIN_H_
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int ut_bsp_ain_read_test(void);
|
||||
|
||||
#endif /* UT_BOARD_AIN_H_ */
|
||||
191
firmware/tests/ut_board/ut_din.c
Normal file
191
firmware/tests/ut_board/ut_din.c
Normal file
@@ -0,0 +1,191 @@
|
||||
#include "ut_din.h"
|
||||
|
||||
#include "..\mock_mcu\mock_mcu_hal_r8.h"
|
||||
#include "..\..\src\hw\board\din.h"
|
||||
|
||||
static const uint8_t NOT_ACCESED_GPIO_CH = 255;
|
||||
|
||||
static int ut_bsp_din_read(uint8_t din_ch, uint8_t gpio_lvl, uint8_t exp_out, uint8_t exp_gpio_ch)
|
||||
{
|
||||
printf(" Input: Din-Ch:%d GPIO-lvl:%d \n", din_ch, gpio_lvl);
|
||||
|
||||
mock_mcu_gpio_set_ch(NOT_ACCESED_GPIO_CH);
|
||||
mock_mcu_gpio_set_input_lvl(gpio_lvl, exp_gpio_ch);
|
||||
|
||||
uint8_t out = bsp_din_read(din_ch);
|
||||
|
||||
uint8_t gpio_ch = mock_mcu_gpio_read_ch();
|
||||
|
||||
printf(" Output: DIN:%d GPIO-Ch:%d \n", out, gpio_ch);
|
||||
printf("Expected: DIN:%d GPIO-Ch:%d \n", exp_out, exp_gpio_ch);
|
||||
|
||||
if((out==exp_out)&&(gpio_ch==exp_gpio_ch))
|
||||
{
|
||||
printf("PASS\n\n");
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("FAIL\n\n");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
int ut_bsp_din_read_test(void)
|
||||
{
|
||||
printf("******************************************************\n");
|
||||
printf("uint8_t bsp_din_read(uint8_t ch)\n");
|
||||
|
||||
int test_res;
|
||||
int pass = 1;
|
||||
|
||||
uint8_t din_ch;
|
||||
uint8_t gpio_lvl;
|
||||
uint8_t exp_out;
|
||||
uint8_t exp_gpio_ch;
|
||||
|
||||
// DIN 1
|
||||
din_ch = BSP_DIN1;
|
||||
gpio_lvl = MCU_GPIO_LOW;
|
||||
exp_out = 0;
|
||||
exp_gpio_ch = MCU_GPIO0;
|
||||
test_res = ut_bsp_din_read(din_ch, gpio_lvl, exp_out, exp_gpio_ch);
|
||||
if(!test_res) pass = 0;
|
||||
|
||||
din_ch = BSP_DIN1;
|
||||
gpio_lvl = MCU_GPIO_HIGH;
|
||||
exp_out = 1;
|
||||
exp_gpio_ch = MCU_GPIO0;
|
||||
test_res = ut_bsp_din_read(din_ch, gpio_lvl, exp_out, exp_gpio_ch);
|
||||
if(!test_res) pass = 0;
|
||||
|
||||
// DIN 2
|
||||
din_ch = BSP_DIN2;
|
||||
gpio_lvl = MCU_GPIO_LOW;
|
||||
exp_out = 0;
|
||||
exp_gpio_ch = MCU_GPIO1;
|
||||
test_res = ut_bsp_din_read(din_ch, gpio_lvl, exp_out, exp_gpio_ch);
|
||||
if(!test_res) pass = 0;
|
||||
|
||||
din_ch = BSP_DIN2;
|
||||
gpio_lvl = MCU_GPIO_HIGH;
|
||||
exp_out = 1;
|
||||
exp_gpio_ch = MCU_GPIO1;
|
||||
test_res = ut_bsp_din_read(din_ch, gpio_lvl, exp_out, exp_gpio_ch);
|
||||
if(!test_res) pass = 0;
|
||||
|
||||
// DIN 3
|
||||
din_ch = BSP_DIN3;
|
||||
gpio_lvl = MCU_GPIO_LOW;
|
||||
exp_out = 0;
|
||||
exp_gpio_ch = MCU_GPIO2;
|
||||
test_res = ut_bsp_din_read(din_ch, gpio_lvl, exp_out, exp_gpio_ch);
|
||||
if(!test_res) pass = 0;
|
||||
|
||||
din_ch = BSP_DIN3;
|
||||
gpio_lvl = MCU_GPIO_HIGH;
|
||||
exp_out = 1;
|
||||
exp_gpio_ch = MCU_GPIO2;
|
||||
test_res = ut_bsp_din_read(din_ch, gpio_lvl, exp_out, exp_gpio_ch);
|
||||
if(!test_res) pass = 0;
|
||||
|
||||
// DIN 4
|
||||
din_ch = BSP_DIN4;
|
||||
gpio_lvl = MCU_GPIO_LOW;
|
||||
exp_out = 0;
|
||||
exp_gpio_ch = MCU_GPIO3;
|
||||
test_res = ut_bsp_din_read(din_ch, gpio_lvl, exp_out, exp_gpio_ch);
|
||||
if(!test_res) pass = 0;
|
||||
|
||||
din_ch = BSP_DIN4;
|
||||
gpio_lvl = MCU_GPIO_HIGH;
|
||||
exp_out = 1;
|
||||
exp_gpio_ch = MCU_GPIO3;
|
||||
test_res = ut_bsp_din_read(din_ch, gpio_lvl, exp_out, exp_gpio_ch);
|
||||
if(!test_res) pass = 0;
|
||||
|
||||
// DIN 5
|
||||
din_ch = BSP_DIN5;
|
||||
gpio_lvl = MCU_GPIO_LOW;
|
||||
exp_out = 1;
|
||||
exp_gpio_ch = MCU_GPIO4;
|
||||
test_res = ut_bsp_din_read(din_ch, gpio_lvl, exp_out, exp_gpio_ch);
|
||||
if(!test_res) pass = 0;
|
||||
|
||||
din_ch = BSP_DIN5;
|
||||
gpio_lvl = MCU_GPIO_HIGH;
|
||||
exp_out = 0;
|
||||
exp_gpio_ch = MCU_GPIO4;
|
||||
test_res = ut_bsp_din_read(din_ch, gpio_lvl, exp_out, exp_gpio_ch);
|
||||
if(!test_res) pass = 0;
|
||||
|
||||
// DIN 6
|
||||
din_ch = BSP_DIN6;
|
||||
gpio_lvl = MCU_GPIO_LOW;
|
||||
exp_out = 1;
|
||||
exp_gpio_ch = MCU_GPIO5;
|
||||
test_res = ut_bsp_din_read(din_ch, gpio_lvl, exp_out, exp_gpio_ch);
|
||||
if(!test_res) pass = 0;
|
||||
|
||||
din_ch = BSP_DIN6;
|
||||
gpio_lvl = MCU_GPIO_HIGH;
|
||||
exp_out = 0;
|
||||
exp_gpio_ch = MCU_GPIO5;
|
||||
test_res = ut_bsp_din_read(din_ch, gpio_lvl, exp_out, exp_gpio_ch);
|
||||
if(!test_res) pass = 0;
|
||||
|
||||
// DIN 7
|
||||
din_ch = BSP_DIN7;
|
||||
gpio_lvl = MCU_GPIO_LOW;
|
||||
exp_out = 1;
|
||||
exp_gpio_ch = MCU_GPIO6;
|
||||
test_res = ut_bsp_din_read(din_ch, gpio_lvl, exp_out, exp_gpio_ch);
|
||||
if(!test_res) pass = 0;
|
||||
|
||||
din_ch = BSP_DIN7;
|
||||
gpio_lvl = MCU_GPIO_HIGH;
|
||||
exp_out = 0;
|
||||
exp_gpio_ch = MCU_GPIO6;
|
||||
test_res = ut_bsp_din_read(din_ch, gpio_lvl, exp_out, exp_gpio_ch);
|
||||
if(!test_res) pass = 0;
|
||||
|
||||
// DIN 7N
|
||||
din_ch = BSP_DIN7N;
|
||||
gpio_lvl = MCU_GPIO_LOW;
|
||||
exp_out = 0;
|
||||
exp_gpio_ch = MCU_GPIO7;
|
||||
test_res = ut_bsp_din_read(din_ch, gpio_lvl, exp_out, exp_gpio_ch);
|
||||
if(!test_res) pass = 0;
|
||||
|
||||
din_ch = BSP_DIN7N;
|
||||
gpio_lvl = MCU_GPIO_HIGH;
|
||||
exp_out = 1;
|
||||
exp_gpio_ch = MCU_GPIO7;
|
||||
test_res = ut_bsp_din_read(din_ch, gpio_lvl, exp_out, exp_gpio_ch);
|
||||
if(!test_res) pass = 0;
|
||||
|
||||
// Wrong channel
|
||||
din_ch = 0;
|
||||
gpio_lvl = MCU_GPIO_LOW;
|
||||
exp_out = 0;
|
||||
exp_gpio_ch = NOT_ACCESED_GPIO_CH;
|
||||
test_res = ut_bsp_din_read(din_ch, gpio_lvl, exp_out, exp_gpio_ch);
|
||||
if(!test_res) pass = 0;
|
||||
|
||||
// DSP OUTPUT DEFINITIONS
|
||||
din_ch = BSP_DIN1;
|
||||
gpio_lvl = MCU_GPIO_LOW;
|
||||
exp_out = BSP_DIN_LOW;
|
||||
exp_gpio_ch = MCU_GPIO0;
|
||||
test_res = ut_bsp_din_read(din_ch, gpio_lvl, exp_out, exp_gpio_ch);
|
||||
if(!test_res) pass = 0;
|
||||
|
||||
din_ch = BSP_DIN1;
|
||||
gpio_lvl = MCU_GPIO_HIGH;
|
||||
exp_out = BSP_DIN_HIGH;
|
||||
exp_gpio_ch = MCU_GPIO0;
|
||||
test_res = ut_bsp_din_read(din_ch, gpio_lvl, exp_out, exp_gpio_ch);
|
||||
if(!test_res) pass = 0;
|
||||
|
||||
return pass;
|
||||
}
|
||||
9
firmware/tests/ut_board/ut_din.h
Normal file
9
firmware/tests/ut_board/ut_din.h
Normal file
@@ -0,0 +1,9 @@
|
||||
#ifndef UT_BOARD_DIN_H_
|
||||
#define UT_BOARD_DIN_H_
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int ut_bsp_din_read_test(void);
|
||||
|
||||
#endif /* UT_BOARD_DIN_H_ */
|
||||
142
firmware/tests/ut_board/ut_dout.c
Normal file
142
firmware/tests/ut_board/ut_dout.c
Normal file
@@ -0,0 +1,142 @@
|
||||
#include "ut_dout.h"
|
||||
|
||||
#include "..\mock_mcu\mock_mcu_hal_r8.h"
|
||||
#include "..\..\src\hw\board\dout.h"
|
||||
|
||||
static const uint8_t NOT_ACCESED_GPIO_CH = 255;
|
||||
static const uint8_t NOT_ACCESED_GPIO_LVL = MCU_GPIO_HIZ;
|
||||
|
||||
static int ut_bsp_dout_write(uint8_t dout_ch, int8_t dout_lvl, int8_t exp_gpio_lvl, uint8_t exp_gpio_ch)
|
||||
{
|
||||
printf(" Input: Dout-Ch:%d Dout-lvl:%d \n", dout_ch, dout_lvl);
|
||||
|
||||
mock_mcu_gpio_set_ch(NOT_ACCESED_GPIO_CH);
|
||||
mock_mcu_gpio_set_output_lvl(NOT_ACCESED_GPIO_LVL, exp_gpio_ch);
|
||||
|
||||
bsp_dout_write(dout_ch, dout_lvl);
|
||||
|
||||
uint8_t gpio_ch = mock_mcu_gpio_read_ch();
|
||||
int8_t gpio_lvl = mock_mcu_gpio_read_output_lvl(gpio_ch);
|
||||
|
||||
printf(" Output: GPIO-lvl:%d GPIO-Ch:%d \n", gpio_lvl, gpio_ch);
|
||||
printf("Expected: GPIO-lvl:%d GPIO-Ch:%d \n", exp_gpio_lvl, exp_gpio_ch);
|
||||
|
||||
if((gpio_lvl==exp_gpio_lvl)&&(gpio_ch==exp_gpio_ch))
|
||||
{
|
||||
printf("PASS\n\n");
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("FAIL\n\n");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
int ut_bsp_dout_write_test(void)
|
||||
{
|
||||
printf("******************************************************\n");
|
||||
printf("void bsp_dout_write(uint8_t ch, int8_t lvl)\n");
|
||||
|
||||
int test_res;
|
||||
int pass = 1;
|
||||
|
||||
uint8_t dout_ch;
|
||||
uint8_t dout_lvl;
|
||||
int8_t exp_gpio_lvl;
|
||||
uint8_t exp_gpio_ch;
|
||||
|
||||
// DOUT 1
|
||||
dout_ch = BSP_DOUT1;
|
||||
dout_lvl = 0;
|
||||
exp_gpio_lvl = MCU_GPIO_LOW;
|
||||
exp_gpio_ch = MCU_GPIO0;
|
||||
test_res = ut_bsp_dout_write(dout_ch, dout_lvl, exp_gpio_lvl, exp_gpio_ch);
|
||||
if(!test_res) pass = 0;
|
||||
|
||||
dout_ch = BSP_DOUT1;
|
||||
dout_lvl = 1;
|
||||
exp_gpio_lvl = MCU_GPIO_HIGH;
|
||||
exp_gpio_ch = MCU_GPIO0;
|
||||
test_res = ut_bsp_dout_write(dout_ch, dout_lvl, exp_gpio_lvl, exp_gpio_ch);
|
||||
if(!test_res) pass = 0;
|
||||
|
||||
dout_ch = BSP_DOUT1;
|
||||
dout_lvl = -1;
|
||||
exp_gpio_lvl = MCU_GPIO_HIZ;
|
||||
exp_gpio_ch = MCU_GPIO0;
|
||||
test_res = ut_bsp_dout_write(dout_ch, dout_lvl, exp_gpio_lvl, exp_gpio_ch);
|
||||
if(!test_res) pass = 0;
|
||||
|
||||
// Defines test
|
||||
dout_ch = BSP_DOUT1;
|
||||
dout_lvl = BSP_DOUT_LOW;
|
||||
exp_gpio_lvl = MCU_GPIO_LOW;
|
||||
exp_gpio_ch = MCU_GPIO0;
|
||||
test_res = ut_bsp_dout_write(dout_ch, dout_lvl, exp_gpio_lvl, exp_gpio_ch);
|
||||
if(!test_res) pass = 0;
|
||||
|
||||
dout_ch = BSP_DOUT1;
|
||||
dout_lvl = BSP_DOUT_HIGH;
|
||||
exp_gpio_lvl = MCU_GPIO_HIGH;
|
||||
exp_gpio_ch = MCU_GPIO0;
|
||||
test_res = ut_bsp_dout_write(dout_ch, dout_lvl, exp_gpio_lvl, exp_gpio_ch);
|
||||
if(!test_res) pass = 0;
|
||||
|
||||
dout_ch = BSP_DOUT1;
|
||||
dout_lvl = BSP_DOUT_HIZ;
|
||||
exp_gpio_lvl = MCU_GPIO_HIZ;
|
||||
exp_gpio_ch = MCU_GPIO0;
|
||||
test_res = ut_bsp_dout_write(dout_ch, dout_lvl, exp_gpio_lvl, exp_gpio_ch);
|
||||
if(!test_res) pass = 0;
|
||||
|
||||
// DOUT 2
|
||||
dout_ch = BSP_DOUT2;
|
||||
dout_lvl = BSP_DOUT_LOW;
|
||||
exp_gpio_lvl = MCU_GPIO_LOW;
|
||||
exp_gpio_ch = MCU_GPIO1;
|
||||
test_res = ut_bsp_dout_write(dout_ch, dout_lvl, exp_gpio_lvl, exp_gpio_ch);
|
||||
if(!test_res) pass = 0;
|
||||
|
||||
// DOUT 3
|
||||
dout_ch = BSP_DOUT3;
|
||||
dout_lvl = BSP_DOUT_HIGH;
|
||||
exp_gpio_lvl = MCU_GPIO_HIGH;
|
||||
exp_gpio_ch = MCU_GPIO2;
|
||||
test_res = ut_bsp_dout_write(dout_ch, dout_lvl, exp_gpio_lvl, exp_gpio_ch);
|
||||
if(!test_res) pass = 0;
|
||||
|
||||
// DOUT 4
|
||||
dout_ch = BSP_DOUT4;
|
||||
dout_lvl = BSP_DOUT_LOW;
|
||||
exp_gpio_lvl = MCU_GPIO_LOW;
|
||||
exp_gpio_ch = MCU_GPIO3;
|
||||
test_res = ut_bsp_dout_write(dout_ch, dout_lvl, exp_gpio_lvl, exp_gpio_ch);
|
||||
if(!test_res) pass = 0;
|
||||
|
||||
// DOUT 5
|
||||
dout_ch = BSP_DOUT5;
|
||||
dout_lvl = BSP_DOUT_HIGH;
|
||||
exp_gpio_lvl = MCU_GPIO_HIGH;
|
||||
exp_gpio_ch = MCU_GPIO7;
|
||||
test_res = ut_bsp_dout_write(dout_ch, dout_lvl, exp_gpio_lvl, exp_gpio_ch);
|
||||
if(!test_res) pass = 0;
|
||||
|
||||
// DOUT 6
|
||||
dout_ch = BSP_DOUT6;
|
||||
dout_lvl = BSP_DOUT_LOW;
|
||||
exp_gpio_lvl = MCU_GPIO_LOW;
|
||||
exp_gpio_ch = MCU_GPIO8;
|
||||
test_res = ut_bsp_dout_write(dout_ch, dout_lvl, exp_gpio_lvl, exp_gpio_ch);
|
||||
if(!test_res) pass = 0;
|
||||
|
||||
// Wrong channel
|
||||
dout_ch = 0;
|
||||
dout_lvl = BSP_DOUT_HIGH;
|
||||
exp_gpio_lvl = NOT_ACCESED_GPIO_LVL;
|
||||
exp_gpio_ch = NOT_ACCESED_GPIO_CH;
|
||||
test_res = ut_bsp_dout_write(dout_ch, dout_lvl, exp_gpio_lvl, exp_gpio_ch);
|
||||
if(!test_res) pass = 0;
|
||||
|
||||
return pass;
|
||||
}
|
||||
9
firmware/tests/ut_board/ut_dout.h
Normal file
9
firmware/tests/ut_board/ut_dout.h
Normal file
@@ -0,0 +1,9 @@
|
||||
#ifndef UT_BOARD_DOUT_H_
|
||||
#define UT_BOARD_DOUT_H_
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int ut_bsp_dout_write_test(void);
|
||||
|
||||
#endif /* UT_BOARD_DOUT_H_ */
|
||||
273
firmware/tests/ut_board/ut_halfbridge.c
Normal file
273
firmware/tests/ut_board/ut_halfbridge.c
Normal file
@@ -0,0 +1,273 @@
|
||||
#include "ut_dout.h"
|
||||
|
||||
#include "..\mock_mcu\mock_mcu_hal_r8.h"
|
||||
#include "..\..\src\hw\board\halfbridge.h"
|
||||
|
||||
static const uint8_t NOT_ACCESED_GPIO_CH = 255;
|
||||
static const uint8_t NOT_ACCESED_GPIO_LVL = MCU_GPIO_HIZ;
|
||||
|
||||
static int ut_bsp_hb_write_low(uint8_t state, int8_t exp_gpio_lvl, uint8_t exp_gpio_ch)
|
||||
{
|
||||
printf(" Input: State:%d \n", state);
|
||||
|
||||
mock_mcu_gpio_set_ch(NOT_ACCESED_GPIO_CH);
|
||||
mock_mcu_gpio_set_output_lvl(NOT_ACCESED_GPIO_LVL, exp_gpio_ch);
|
||||
|
||||
bsp_hb_write_low(state);
|
||||
|
||||
uint8_t gpio_ch = mock_mcu_gpio_read_ch();
|
||||
int8_t gpio_lvl = mock_mcu_gpio_read_output_lvl(gpio_ch);
|
||||
|
||||
printf(" Output: GPIO-lvl:%d GPIO-Ch:%d \n", gpio_lvl, gpio_ch);
|
||||
printf("Expected: GPIO-lvl:%d GPIO-Ch:%d \n", exp_gpio_lvl, exp_gpio_ch);
|
||||
|
||||
if((gpio_lvl==exp_gpio_lvl)&&(gpio_ch==exp_gpio_ch))
|
||||
{
|
||||
printf("PASS\n\n");
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("FAIL\n\n");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
int ut_bsp_hb_write_low_test(void)
|
||||
{
|
||||
printf("******************************************************\n");
|
||||
printf("void bsp_hb_write_low(uint8_t state) \n");
|
||||
|
||||
int test_res;
|
||||
int pass = 1;
|
||||
|
||||
uint8_t state;
|
||||
int8_t exp_gpio_lvl;
|
||||
uint8_t exp_gpio_ch;
|
||||
|
||||
// Low
|
||||
state = 0;
|
||||
exp_gpio_lvl = MCU_GPIO_LOW;
|
||||
exp_gpio_ch = MCU_GPIO15;
|
||||
test_res = ut_bsp_hb_write_low(state, exp_gpio_lvl, exp_gpio_ch);
|
||||
if(!test_res) pass = 0;
|
||||
|
||||
// High
|
||||
state = 1;
|
||||
exp_gpio_lvl = MCU_GPIO_HIGH;
|
||||
exp_gpio_ch = MCU_GPIO15;
|
||||
test_res = ut_bsp_hb_write_low(state, exp_gpio_lvl, exp_gpio_ch);
|
||||
if(!test_res) pass = 0;
|
||||
|
||||
// High
|
||||
state = 255;
|
||||
exp_gpio_lvl = MCU_GPIO_HIGH;
|
||||
exp_gpio_ch = MCU_GPIO15;
|
||||
test_res = ut_bsp_hb_write_low(state, exp_gpio_lvl, exp_gpio_ch);
|
||||
if(!test_res) pass = 0;
|
||||
|
||||
return pass;
|
||||
}
|
||||
|
||||
static const uint8_t NOT_ACCESED_PWM_CH = 255;
|
||||
static const uint8_t NOT_ACCESED_PWM_VAL = 0xFFFF;
|
||||
|
||||
static int ut_bsp_hb_write_pwm(uint16_t pwm, uint16_t exp_pwm, uint8_t exp_pwm_ch)
|
||||
{
|
||||
printf(" Input: PWM:%d \n", pwm);
|
||||
|
||||
mock_mcu_pwm_set_ch(NOT_ACCESED_PWM_CH);
|
||||
mock_mcu_pwm_set_raw(NOT_ACCESED_PWM_VAL, exp_pwm_ch);
|
||||
|
||||
bsp_hb_write_pwm(pwm);
|
||||
|
||||
uint8_t pwm_ch = mock_mcu_pwm_read_ch();
|
||||
uint16_t pwm_value = mock_mcu_pwm_read_raw(pwm_ch);
|
||||
|
||||
printf(" Output: PWM:%d PWM-Ch:%d \n", pwm_value, pwm_ch);
|
||||
printf("Expected: PWM:%d PWM-Ch:%d \n", exp_pwm, exp_pwm_ch);
|
||||
|
||||
if((pwm_value==exp_pwm)&&(pwm_ch==exp_pwm_ch))
|
||||
{
|
||||
printf("PASS\n\n");
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("FAIL\n\n");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
int ut_bsp_hb_write_pwm_test(void)
|
||||
{
|
||||
printf("******************************************************\n");
|
||||
printf("void bsp_hb_write_pwm(uint16_t pwm) \n");
|
||||
|
||||
int test_res;
|
||||
int pass = 1;
|
||||
|
||||
uint16_t pwm;
|
||||
uint16_t exp_pwm;
|
||||
uint8_t exp_pwm_ch;
|
||||
|
||||
// 0
|
||||
pwm = 0;
|
||||
exp_pwm = 0;
|
||||
exp_pwm_ch = MCU_PWM0;
|
||||
test_res = ut_bsp_hb_write_pwm(pwm, exp_pwm, exp_pwm_ch);
|
||||
if(!test_res) pass = 0;
|
||||
|
||||
// 100
|
||||
pwm = 100;
|
||||
exp_pwm = 100;
|
||||
exp_pwm_ch = MCU_PWM0;
|
||||
test_res = ut_bsp_hb_write_pwm(pwm, exp_pwm, exp_pwm_ch);
|
||||
if(!test_res) pass = 0;
|
||||
|
||||
// 95%
|
||||
pwm = 0xFC00;
|
||||
exp_pwm = 0xFC00;
|
||||
exp_pwm_ch = MCU_PWM0;
|
||||
test_res = ut_bsp_hb_write_pwm(pwm, exp_pwm, exp_pwm_ch);
|
||||
if(!test_res) pass = 0;
|
||||
|
||||
// MAX
|
||||
pwm = 0xFFFF;
|
||||
exp_pwm = 0xFC00;
|
||||
exp_pwm_ch = MCU_PWM0;
|
||||
test_res = ut_bsp_hb_write_pwm(pwm, exp_pwm, exp_pwm_ch);
|
||||
if(!test_res) pass = 0;
|
||||
|
||||
return pass;
|
||||
}
|
||||
|
||||
static const uint8_t NOT_ACCESED_ADC_CH = 255;
|
||||
static const uint8_t NOT_ACCESED_ADC_VAL = 0xFFFF;
|
||||
|
||||
static int ut_bsp_hb_read_meas(uint16_t adc_sup_u, uint16_t adc_sup_i, uint16_t adc_out_u, uint16_t adc_out_i, uint8_t low_side_lvl, uint16_t act_pwm, hb_meas_t* exp_meas)
|
||||
{
|
||||
printf(" Input: Out-U:%d Out-I:%d Sup-U:%d Sup-I:%d Low-Lvl:%d PWM:%d \n", adc_out_u, adc_out_i, adc_sup_u, adc_sup_i, low_side_lvl, act_pwm);
|
||||
|
||||
mock_mcu_adc_set_ch(NOT_ACCESED_ADC_CH);
|
||||
mock_mcu_adc_set_raw(adc_sup_u, MCU_ADC2);
|
||||
mock_mcu_adc_set_raw(adc_sup_i, MCU_ADC3);
|
||||
mock_mcu_adc_set_raw(adc_out_u, MCU_ADC1);
|
||||
mock_mcu_adc_set_raw(adc_out_i, MCU_ADC0);
|
||||
|
||||
mock_mcu_gpio_set_ch(NOT_ACCESED_GPIO_CH);
|
||||
mock_mcu_gpio_set_input_lvl(low_side_lvl, MCU_GPIO15);
|
||||
|
||||
mock_mcu_pwm_set_ch(NOT_ACCESED_PWM_CH);
|
||||
mock_mcu_pwm_set_raw(act_pwm, MCU_PWM0);
|
||||
|
||||
hb_meas_t out;
|
||||
|
||||
bsp_hb_read_meas(&out);
|
||||
|
||||
uint8_t adc_ch = mock_mcu_adc_read_ch();
|
||||
uint8_t gpio_ch = mock_mcu_gpio_read_ch();
|
||||
uint8_t pwm_ch = mock_mcu_pwm_read_ch();
|
||||
|
||||
int equal = 1;
|
||||
|
||||
if(out.out_voltage != exp_meas->out_voltage) equal = 0;
|
||||
if(out.out_current != exp_meas->out_current) equal = 0;
|
||||
if(out.sup_voltage != exp_meas->sup_voltage) equal = 0;
|
||||
if(out.sup_current != exp_meas->sup_current) equal = 0;
|
||||
if(out.out_power != exp_meas->out_power) equal = 0;
|
||||
if(out.sup_power != exp_meas->sup_power) equal = 0;
|
||||
if(out.out_impedance != exp_meas->out_impedance) equal = 0;
|
||||
if(out.low_side_ctrl != exp_meas->low_side_ctrl) equal = 0;
|
||||
if(out.pwm != exp_meas->pwm) equal = 0;
|
||||
|
||||
printf(" Output: Out-U:%d Out-I:%d Bat-U:%d Bat-I:%d Out-P:%d Bat-P:%d Out-Z:%d Low:%d PWM:%d \n", out.out_voltage, out.out_current, out.sup_voltage, out.sup_current, out.out_power, out.sup_power, out.out_impedance, out.low_side_ctrl, out.pwm);
|
||||
printf("Expected: Out-U:%d Out-I:%d Bat-U:%d Bat-I:%d Out-P:%d Bat-P:%d Out-Z:%d Low:%d PWM:%d \n", exp_meas->out_voltage, exp_meas->out_current, exp_meas->sup_voltage, exp_meas->sup_current, exp_meas->out_power, exp_meas->sup_power, exp_meas->out_impedance, exp_meas->low_side_ctrl, exp_meas->pwm);
|
||||
|
||||
if((equal)&&(gpio_ch==MCU_GPIO15)&&(pwm_ch==MCU_PWM0)&&(adc_ch!=NOT_ACCESED_ADC_CH))
|
||||
{
|
||||
printf("PASS\n\n");
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("FAIL\n\n");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
int ut_bsp_hb_read_meas_test(void)
|
||||
{
|
||||
printf("******************************************************\n");
|
||||
printf("void bsp_hb_read_meas(hb_meas_t* measurements) \n");
|
||||
|
||||
int test_res;
|
||||
int pass = 1;
|
||||
|
||||
uint16_t adc_sup_u;
|
||||
uint16_t adc_sup_i;
|
||||
uint16_t adc_out_u;
|
||||
uint16_t adc_out_i;
|
||||
uint8_t low_side_lvl;
|
||||
uint16_t act_pwm;
|
||||
hb_meas_t exp_meas;
|
||||
|
||||
// 0
|
||||
adc_sup_u = 0;
|
||||
adc_sup_i = 0;
|
||||
adc_out_u = 0;
|
||||
adc_out_i = 0;
|
||||
low_side_lvl = MCU_GPIO_LOW;
|
||||
act_pwm = 0x0000;
|
||||
exp_meas.out_voltage = 0;
|
||||
exp_meas.out_current = 0;
|
||||
exp_meas.sup_voltage = 0;
|
||||
exp_meas.sup_current = 0;
|
||||
exp_meas.out_power = 0;
|
||||
exp_meas.sup_power = 0;
|
||||
exp_meas.out_impedance = 0xFFFF;
|
||||
exp_meas.low_side_ctrl = 0;
|
||||
exp_meas.pwm = 0;
|
||||
test_res = ut_bsp_hb_read_meas(adc_sup_u, adc_sup_i, adc_out_u, adc_out_i, low_side_lvl, act_pwm, &exp_meas);
|
||||
if(!test_res) pass = 0;
|
||||
|
||||
// Limits
|
||||
adc_sup_u = 1023;
|
||||
adc_sup_i = 1023;
|
||||
adc_out_u = 1023;
|
||||
adc_out_i = 1023;
|
||||
low_side_lvl = MCU_GPIO_HIGH;
|
||||
act_pwm = 457;
|
||||
exp_meas.out_voltage = 20460;
|
||||
exp_meas.out_current = 9997;
|
||||
exp_meas.sup_voltage = 20460;
|
||||
exp_meas.sup_current = 40067;
|
||||
exp_meas.out_power = 0xFFFF;
|
||||
exp_meas.sup_power = 0xFFFF;
|
||||
exp_meas.out_impedance = 2046;
|
||||
exp_meas.low_side_ctrl = 1;
|
||||
exp_meas.pwm = 457;
|
||||
test_res = ut_bsp_hb_read_meas(adc_sup_u, adc_sup_i, adc_out_u, adc_out_i, low_side_lvl, act_pwm, &exp_meas);
|
||||
if(!test_res) pass = 0;
|
||||
|
||||
// Normal
|
||||
adc_sup_u = 600;
|
||||
adc_sup_i = 51;
|
||||
adc_out_u = 300;
|
||||
adc_out_i = 409;
|
||||
low_side_lvl = MCU_GPIO_HIGH;
|
||||
act_pwm = 0xAAAA;
|
||||
exp_meas.out_voltage = 6000;
|
||||
exp_meas.out_current = 3997;
|
||||
exp_meas.sup_voltage = 12000;
|
||||
exp_meas.sup_current = 1997;
|
||||
exp_meas.out_power = 23982;
|
||||
exp_meas.sup_power = 23964;
|
||||
exp_meas.out_impedance = 1501;
|
||||
exp_meas.low_side_ctrl = 1;
|
||||
exp_meas.pwm = 0xAAAA;
|
||||
test_res = ut_bsp_hb_read_meas(adc_sup_u, adc_sup_i, adc_out_u, adc_out_i, low_side_lvl, act_pwm, &exp_meas);
|
||||
if(!test_res) pass = 0;
|
||||
|
||||
return pass;
|
||||
}
|
||||
11
firmware/tests/ut_board/ut_halfbridge.h
Normal file
11
firmware/tests/ut_board/ut_halfbridge.h
Normal file
@@ -0,0 +1,11 @@
|
||||
#ifndef UT_BOARD_HALFBRIDGE_H_
|
||||
#define UT_BOARD_HALFBRIDGE_H_
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int ut_bsp_hb_write_low_test(void);
|
||||
int ut_bsp_hb_write_pwm_test(void);
|
||||
int ut_bsp_hb_read_meas_test(void);
|
||||
|
||||
#endif /* UT_BOARD_HALFBRIDGE_H_ */
|
||||
212
firmware/tests/ut_board/ut_odout.c
Normal file
212
firmware/tests/ut_board/ut_odout.c
Normal file
@@ -0,0 +1,212 @@
|
||||
#include "ut_odout.h"
|
||||
|
||||
#include "..\mock_mcu\mock_mcu_hal_r8.h"
|
||||
#include "..\..\src\hw\board\odout.h"
|
||||
|
||||
static const uint8_t NOT_ACCESED_GPIO_CH = 255;
|
||||
static const uint8_t NOT_ACCESED_GPIO_LVL = MCU_GPIO_HIZ;
|
||||
|
||||
static int ut_bsp_odout_write(uint8_t odout_ch, int8_t odout_lvl, int8_t exp_gpio_lvl, uint8_t exp_gpio_ch)
|
||||
{
|
||||
printf(" Input: ODout-Ch:%d ODout-lvl:%d \n", odout_ch, odout_lvl);
|
||||
|
||||
mock_mcu_gpio_set_ch(NOT_ACCESED_GPIO_CH);
|
||||
mock_mcu_gpio_set_output_lvl(NOT_ACCESED_GPIO_LVL, exp_gpio_ch);
|
||||
|
||||
bsp_odout_write(odout_ch, odout_lvl);
|
||||
|
||||
uint8_t gpio_ch = mock_mcu_gpio_read_ch();
|
||||
int8_t gpio_lvl = mock_mcu_gpio_read_output_lvl(gpio_ch);
|
||||
|
||||
printf(" Output: GPIO-lvl:%d GPIO-Ch:%d \n", gpio_lvl, gpio_ch);
|
||||
printf("Expected: GPIO-lvl:%d GPIO-Ch:%d \n", exp_gpio_lvl, exp_gpio_ch);
|
||||
|
||||
if((gpio_lvl==exp_gpio_lvl)&&(gpio_ch==exp_gpio_ch))
|
||||
{
|
||||
printf("PASS\n\n");
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("FAIL\n\n");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
int ut_bsp_odout_write_test(void)
|
||||
{
|
||||
printf("******************************************************\n");
|
||||
printf("void bsp_odout_write(uint8_t ch, int8_t lvl) \n");
|
||||
|
||||
int test_res;
|
||||
int pass = 1;
|
||||
|
||||
uint8_t odout_ch;
|
||||
uint8_t odout_lvl;
|
||||
int8_t exp_gpio_lvl;
|
||||
uint8_t exp_gpio_ch;
|
||||
|
||||
// Control level - LOW
|
||||
odout_ch = BSP_OD1;
|
||||
odout_lvl = 0;
|
||||
exp_gpio_lvl = MCU_GPIO_HIGH;
|
||||
exp_gpio_ch = MCU_GPIO9;
|
||||
test_res = ut_bsp_odout_write(odout_ch, odout_lvl, exp_gpio_lvl, exp_gpio_ch);
|
||||
if(!test_res) pass = 0;
|
||||
|
||||
// Control level - HIGH
|
||||
odout_ch = BSP_OD1;
|
||||
odout_lvl = 1;
|
||||
exp_gpio_lvl = MCU_GPIO_LOW;
|
||||
exp_gpio_ch = MCU_GPIO9;
|
||||
test_res = ut_bsp_odout_write(odout_ch, odout_lvl, exp_gpio_lvl, exp_gpio_ch);
|
||||
if(!test_res) pass = 0;
|
||||
|
||||
// Control level - HIZ
|
||||
odout_ch = BSP_OD1;
|
||||
odout_lvl = -1;
|
||||
exp_gpio_lvl = MCU_GPIO_LOW;
|
||||
exp_gpio_ch = MCU_GPIO9;
|
||||
test_res = ut_bsp_odout_write(odout_ch, odout_lvl, exp_gpio_lvl, exp_gpio_ch);
|
||||
if(!test_res) pass = 0;
|
||||
|
||||
// Control level DEFINE - LOW
|
||||
odout_ch = BSP_OD1;
|
||||
odout_lvl = BSP_ODOUT_LOW;
|
||||
exp_gpio_lvl = MCU_GPIO_HIGH;
|
||||
exp_gpio_ch = MCU_GPIO9;
|
||||
test_res = ut_bsp_odout_write(odout_ch, odout_lvl, exp_gpio_lvl, exp_gpio_ch);
|
||||
if(!test_res) pass = 0;
|
||||
|
||||
// Control level DEFINE - HIGH
|
||||
odout_ch = BSP_OD1;
|
||||
odout_lvl = BSP_ODOUT_HIGH;
|
||||
exp_gpio_lvl = MCU_GPIO_LOW;
|
||||
exp_gpio_ch = MCU_GPIO9;
|
||||
test_res = ut_bsp_odout_write(odout_ch, odout_lvl, exp_gpio_lvl, exp_gpio_ch);
|
||||
if(!test_res) pass = 0;
|
||||
|
||||
// Control level DEFINE - HIZ
|
||||
odout_ch = BSP_OD1;
|
||||
odout_lvl = BSP_ODOUT_HIZ;
|
||||
exp_gpio_lvl = MCU_GPIO_LOW;
|
||||
exp_gpio_ch = MCU_GPIO9;
|
||||
test_res = ut_bsp_odout_write(odout_ch, odout_lvl, exp_gpio_lvl, exp_gpio_ch);
|
||||
if(!test_res) pass = 0;
|
||||
|
||||
// ODOUT 2
|
||||
odout_ch = BSP_OD2;
|
||||
odout_lvl = 0;
|
||||
exp_gpio_lvl = MCU_GPIO_HIGH;
|
||||
exp_gpio_ch = MCU_GPIO10;
|
||||
test_res = ut_bsp_odout_write(odout_ch, odout_lvl, exp_gpio_lvl, exp_gpio_ch);
|
||||
if(!test_res) pass = 0;
|
||||
|
||||
// ODOUT 3
|
||||
odout_ch = BSP_OD3;
|
||||
odout_lvl = 0;
|
||||
exp_gpio_lvl = MCU_GPIO_HIGH;
|
||||
exp_gpio_ch = MCU_GPIO11;
|
||||
test_res = ut_bsp_odout_write(odout_ch, odout_lvl, exp_gpio_lvl, exp_gpio_ch);
|
||||
if(!test_res) pass = 0;
|
||||
|
||||
// ODOUT 4
|
||||
odout_ch = BSP_OD4;
|
||||
odout_lvl = 0;
|
||||
exp_gpio_lvl = MCU_GPIO_HIGH;
|
||||
exp_gpio_ch = MCU_GPIO12;
|
||||
test_res = ut_bsp_odout_write(odout_ch, odout_lvl, exp_gpio_lvl, exp_gpio_ch);
|
||||
if(!test_res) pass = 0;
|
||||
|
||||
// ODOUT 5
|
||||
odout_ch = BSP_OD5;
|
||||
odout_lvl = 0;
|
||||
exp_gpio_lvl = MCU_GPIO_HIGH;
|
||||
exp_gpio_ch = MCU_GPIO13;
|
||||
test_res = ut_bsp_odout_write(odout_ch, odout_lvl, exp_gpio_lvl, exp_gpio_ch);
|
||||
if(!test_res) pass = 0;
|
||||
|
||||
// ODOUT 6
|
||||
odout_ch = BSP_OD6;
|
||||
odout_lvl = 0;
|
||||
exp_gpio_lvl = MCU_GPIO_HIGH;
|
||||
exp_gpio_ch = MCU_GPIO14;
|
||||
test_res = ut_bsp_odout_write(odout_ch, odout_lvl, exp_gpio_lvl, exp_gpio_ch);
|
||||
if(!test_res) pass = 0;
|
||||
|
||||
// Wrong chanell
|
||||
odout_ch = 0;
|
||||
odout_lvl = 0;
|
||||
exp_gpio_lvl = NOT_ACCESED_GPIO_LVL;
|
||||
exp_gpio_ch = NOT_ACCESED_GPIO_CH;
|
||||
test_res = ut_bsp_odout_write(odout_ch, odout_lvl, exp_gpio_lvl, exp_gpio_ch);
|
||||
if(!test_res) pass = 0;
|
||||
|
||||
return pass;
|
||||
}
|
||||
|
||||
static const uint8_t NOT_ACCESED_PWM_CH = 255;
|
||||
static const uint8_t NOT_ACCESED_PWM_VAL = 0xFFFF;
|
||||
|
||||
static int ut_bsp_odout_write_common(uint8_t percent, uint16_t exp_pwm, uint8_t exp_pwm_ch)
|
||||
{
|
||||
printf(" Input: Percent:%d \n", percent);
|
||||
|
||||
mock_mcu_pwm_set_ch(NOT_ACCESED_PWM_CH);
|
||||
mock_mcu_pwm_set_raw(NOT_ACCESED_PWM_VAL, exp_pwm_ch);
|
||||
|
||||
bsp_odout_write_common(percent);
|
||||
|
||||
uint8_t pwm_ch = mock_mcu_pwm_read_ch();
|
||||
uint16_t pwm_value = mock_mcu_pwm_read_raw(pwm_ch);
|
||||
|
||||
printf(" Output: PWM:%d PWM-Ch:%d \n", pwm_value, pwm_ch);
|
||||
printf("Expected: PWM:%d PWM-Ch:%d \n", exp_pwm, exp_pwm_ch);
|
||||
|
||||
if((pwm_value==exp_pwm)&&(pwm_ch==exp_pwm_ch))
|
||||
{
|
||||
printf("PASS\n\n");
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("FAIL\n\n");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
int ut_bsp_odout_write_common_test(void)
|
||||
{
|
||||
printf("******************************************************\n");
|
||||
printf("void bsp_odout_write_common(uint8_t percent) \n");
|
||||
|
||||
int test_res;
|
||||
int pass = 1;
|
||||
|
||||
uint8_t percent;
|
||||
uint16_t exp_pwm;
|
||||
uint8_t exp_pwm_ch;
|
||||
|
||||
// Zero
|
||||
percent = 0;
|
||||
exp_pwm = 0x0000;
|
||||
exp_pwm_ch = MCU_PWM1;
|
||||
test_res = ut_bsp_odout_write_common(percent, exp_pwm, exp_pwm_ch);
|
||||
if(!test_res) pass = 0;
|
||||
|
||||
// 100
|
||||
percent = 100;
|
||||
exp_pwm = 0xFFFF;
|
||||
exp_pwm_ch = MCU_PWM1;
|
||||
test_res = ut_bsp_odout_write_common(percent, exp_pwm, exp_pwm_ch);
|
||||
if(!test_res) pass = 0;
|
||||
|
||||
// 50
|
||||
percent = 50;
|
||||
exp_pwm = 0x7FFF;
|
||||
exp_pwm_ch = MCU_PWM1;
|
||||
test_res = ut_bsp_odout_write_common(percent, exp_pwm, exp_pwm_ch);
|
||||
if(!test_res) pass = 0;
|
||||
|
||||
return pass;
|
||||
}
|
||||
10
firmware/tests/ut_board/ut_odout.h
Normal file
10
firmware/tests/ut_board/ut_odout.h
Normal file
@@ -0,0 +1,10 @@
|
||||
#ifndef UT_BOARD_ODOUT_H_
|
||||
#define UT_BOARD_ODOUT_H_
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int ut_bsp_odout_write_test(void);
|
||||
int ut_bsp_odout_write_common_test(void);
|
||||
|
||||
#endif /* UT_BOARD_ODOUT_H_ */
|
||||
62
firmware/tests/ut_board/ut_setup.c
Normal file
62
firmware/tests/ut_board/ut_setup.c
Normal file
@@ -0,0 +1,62 @@
|
||||
#include "ut_odout.h"
|
||||
|
||||
#include "..\mock_mcu\mock_mcu_hal_r8.h"
|
||||
#include "..\..\src\hw\board\setup.h"
|
||||
|
||||
static adcClkDiv_t not_accesed_adc_clk = MCU_ADC_DIV128;
|
||||
static timerClkDiv_t not_accesed_pwm_clk = MCU_TIM_DIV1024;
|
||||
static uint16_t not_accesed_pwm_top = 0;
|
||||
static uint8_t not_accesed_pwm_chb_en = 255;
|
||||
|
||||
static int ut_bsp_startup(startupCfg_t* exp_cfg)
|
||||
{
|
||||
printf(" Input: \n");
|
||||
|
||||
startupCfg_t not_accesd_cfg;
|
||||
not_accesd_cfg.adc_clk = not_accesed_adc_clk;
|
||||
not_accesd_cfg.pwm_clk = not_accesed_pwm_clk;
|
||||
not_accesd_cfg.pwm_top = not_accesed_pwm_top;
|
||||
not_accesd_cfg.pwm_chb_en = not_accesed_pwm_chb_en;
|
||||
mock_mcu_startup_write_cfg(¬_accesd_cfg);
|
||||
|
||||
bsp_startup();
|
||||
|
||||
startupCfg_t cfg;
|
||||
mock_mcu_startup_read_cfg(&cfg);
|
||||
|
||||
printf(" Output: ADC-CLK:%d PWN-CLK:%d PWM-TOP:%d PWM-CHB-EN:%d \n", cfg.adc_clk, cfg.pwm_clk, cfg.pwm_top, cfg.pwm_chb_en);
|
||||
printf("Expected: ADC-CLK:%d PWN-CLK:%d PWM-TOP:%d PWM-CHB-EN:%d \n", exp_cfg->adc_clk, exp_cfg->pwm_clk, exp_cfg->pwm_top, exp_cfg->pwm_chb_en);
|
||||
|
||||
if((cfg.adc_clk==exp_cfg->adc_clk)&&(cfg.pwm_clk==exp_cfg->pwm_clk)&&(cfg.pwm_top==exp_cfg->pwm_top)&&(cfg.pwm_chb_en==exp_cfg->pwm_chb_en))
|
||||
{
|
||||
printf("PASS\n\n");
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("FAIL\n\n");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
int ut_bsp_startup_test(void)
|
||||
{
|
||||
printf("******************************************************\n");
|
||||
printf("void bsp_startup(void) \n");
|
||||
|
||||
int test_res;
|
||||
int pass = 1;
|
||||
|
||||
startupCfg_t exp_cfg;
|
||||
|
||||
// Control level - LOW
|
||||
exp_cfg.adc_clk = MCU_ADC_DIV2;
|
||||
exp_cfg.pwm_clk = MCU_TIM_DIV1;
|
||||
exp_cfg.pwm_top = 511;
|
||||
exp_cfg.pwm_chb_en = 1;
|
||||
test_res = ut_bsp_startup(&exp_cfg);
|
||||
if(!test_res) pass = 0;
|
||||
|
||||
return pass;
|
||||
}
|
||||
|
||||
9
firmware/tests/ut_board/ut_setup.h
Normal file
9
firmware/tests/ut_board/ut_setup.h
Normal file
@@ -0,0 +1,9 @@
|
||||
#ifndef UT_BOARD_SETUP_H_
|
||||
#define UT_BOARD_SETUP_H_
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int ut_bsp_startup_test(void);
|
||||
|
||||
#endif /* UT_BOARD_SETUP_H_ */
|
||||
Reference in New Issue
Block a user