Repo unification
This commit is contained in:
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;
|
||||
}
|
||||
Reference in New Issue
Block a user