Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fwxv 211 write uv cutoff smoke tests #196

Merged
merged 32 commits into from
Jul 26, 2023
Merged
Show file tree
Hide file tree
Changes from 31 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions fwxv
Submodule fwxv added at 93065f
2 changes: 2 additions & 0 deletions projects/uv_cutoff/inc/uv_cutoff.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ typedef enum UVCutoffState {
UV_CUTOFF_ACTIVE = 0,
UV_CUTOFF_DISCONNECTED,
} UVCutoffState;

void uv_ligc() {}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is this for?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed a backspace after uv_ligc to resolve an error which scons lint threw.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry what was the error? I don't think uv_ligc is used anywhere

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed uv_ligc () {} -> uv_ligc() {}.
scons lint said to remove an extra space after uv_ligc.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an entirely new line. It shouldn't be here if you're not using it

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should just delete this

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had forgot to make this change, it'll be their in the new PR.

15 changes: 11 additions & 4 deletions scons/build.scons
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,12 @@ def proj_bin(proj_name, is_smoke=False):
###########################################################
# Header file generation from jinja templates
###########################################################
def generate_can_files(env, target=[], source=[], project=TARGET):
def generate_can_files(env, target=[], source=[], project=TARGET, is_smoke=False):
source_yaml = BOARDS_DIR.File(project + ".yaml")
project_can_dir = OBJ_DIR.Dir("projects").Dir(project).Dir("can")
if is_smoke:
project_can_dir = OBJ_DIR.Dir("smoke").Dir(project).Dir("can")
else:
project_can_dir = OBJ_DIR.Dir("projects").Dir(project).Dir("can")
source_dir = project_can_dir.Dir("src")
header_dir = project_can_dir.Dir("inc")
source += [BOARDS_DIR, TEMPLATES_DIR, GENERATOR]
Expand Down Expand Up @@ -126,15 +129,19 @@ for entry in PROJ_DIRS + LIB_DIRS + SMOKE_DIRS:
config = parse_config(entry)

if config["can"]:
is_smoke = entry in SMOKE_DIRS
can_location_name = entry.name
if (entry.name == "power_distribution"):
can_location_name += "_" + str(GetOption("location"))

# Add Autogenerated files
can_sources, can_header_dir = generate_can_files(env, project=can_location_name)
can_sources, can_header_dir = generate_can_files(env, project=can_location_name, is_smoke=is_smoke)
srcs += can_sources
inc_dirs.append(can_header_dir)


if "include" in config:
for i in config["include"]:
inc_dirs.append(Dir(i))

# Glob the source files from OBJ_DIR because it's a variant dir
# See: https://scons.org/doc/1.2.0/HTML/scons-user/x3346.html
Expand Down
Empty file added smoke/uv_cutoff/README.md
Empty file.
10 changes: 10 additions & 0 deletions smoke/uv_cutoff/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"libs": [
"FreeRTOS",
"ms-common"
],
"include": [
"#/projects/uv_cutoff/inc"
],
"can": true
}
168 changes: 168 additions & 0 deletions smoke/uv_cutoff/src/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
#include <stdio.h>

#include "can.h"
#include "assert.h"
#include "gpio.h"
#include "can_board_ids.h"
#include "delay.h"
#include "interrupt.h"
#include "log.h"
#include "misc.h"
#include "soft_timer.h"
#include "tasks.h"
#include "uv_cutoff.h"
#include "uv_cutoff_getters.h"
#include "uv_cutoff_setters.h"

// TODO(devAdhiraj): update with actual ports and pins
#define UV_CUTOFF_PORT GPIO_PORT_A
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should look at the UV cutoff schematic to find out these pins. If you can't, then just put random ones for now to get your test passing though.

#define UV_CUTOFF_PIN 4

#define HORN_PORT GPIO_PORT_B
#define HORN_PIN 14

#define LIGHTS_PORT GPIO_PORT_B
#define LIGHTS_PIN 13

static const GpioAddress uv_status = { .port = UV_CUTOFF_PORT, .pin = UV_CUTOFF_PIN };

static const GpioAddress horn = { .port = HORN_PORT, .pin = HORN_PIN };

static const GpioAddress lights = { .port = LIGHTS_PORT, .pin = LIGHTS_PIN };

StatusCode status;
GpioState state_val;
int lights_check = 0;

static UVCutoffState state = UV_CUTOFF_ACTIVE;

void uv_smoke_logic() {
GpioState uv_value;

if (gpio_get_state(&uv_status, &uv_value) != STATUS_CODE_OK) {
LOG_CRITICAL("Error reading UV_cutoff pin!\n");
return;
}
if (uv_value == GPIO_STATE_LOW) {
state = UV_CUTOFF_DISCONNECTED;
} else {
state = UV_CUTOFF_ACTIVE;
}

set_uv_cutoff_notification_signal1(state);

if (state == UV_CUTOFF_DISCONNECTED) {
return;
}

if (get_horn_and_lights_horn_state()) {
status = gpio_set_state(&horn, GPIO_STATE_LOW);
if (status == STATUS_CODE_OK) {
gpio_get_state(&horn, &state_val);
}
} else {
status = gpio_set_state(&horn, GPIO_STATE_HIGH);
if (status == STATUS_CODE_OK) {
gpio_get_state(&horn, &state_val);
}

}

if(lights_check) {
if (get_horn_and_lights_lights_state()) {
status = gpio_set_state(&lights, GPIO_STATE_LOW);
if (status == STATUS_CODE_OK) {
gpio_get_state(&lights, &state_val);
}

} else {
status = gpio_set_state(&lights, GPIO_STATE_HIGH);
if (status == STATUS_CODE_OK) {
gpio_get_state(&lights, &state_val);
}
}
}

}

TASK(smoke_task, TASK_MIN_STACK_SIZE) {
//
//TEST 1 - Disconnected UV status
LOG_DEBUG("Running test for UV Disconnected state\n");
gpio_set_state(&uv_status,GPIO_STATE_LOW);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also if you could add a LOG_DEBUG before every test just so we know which test is being run

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Haven't pushed it yet.

uv_smoke_logic();
assert( g_tx_struct.uv_cutoff_notification_signal1 == UV_CUTOFF_DISCONNECTED );
LOG_DEBUG("uv_cutoff notification signal set to 'UV_CUTOFF_DISCONNECTED'\n");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also can you add a 1s delay after ever test? Makes it easier to see in hw

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yup, made this change. Yet to push it.

delay_ms(1000);
//TEST 2 - Active UV status
LOG_DEBUG("Running test for UV Active state\n");
gpio_set_state(&uv_status,GPIO_STATE_HIGH);
uv_smoke_logic();
assert( g_tx_struct.uv_cutoff_notification_signal1 == UV_CUTOFF_ACTIVE );
LOG_DEBUG("uv_cutoff notification signal set to 'UV_CUTOFF_ACTIVE'\n");
delay_ms(1000);
//TEST 3 - Horn state HIGH
LOG_DEBUG("Running test for Horn in state HIGH\n");
gpio_set_state(&uv_status,GPIO_STATE_HIGH);
gpio_set_state(&horn,GPIO_STATE_HIGH);
g_rx_struct.horn_and_lights_horn_state = GPIO_STATE_HIGH;
lights_check = 0;
uv_smoke_logic();
assert(status == STATUS_CODE_OK);
assert(state_val == GPIO_STATE_LOW);
LOG_DEBUG("horn state set to LOW\n");
delay_ms(1000);
//TEST 4 - Lights state HIGH
LOG_DEBUG("Running test for Lights in state HIGH\n");
gpio_set_state(&uv_status,GPIO_STATE_HIGH);
gpio_set_state(&lights,GPIO_STATE_HIGH);
g_rx_struct.horn_and_lights_lights_state = GPIO_STATE_HIGH;
lights_check = 1;
uv_smoke_logic();
assert(status == STATUS_CODE_OK);
assert(state_val == GPIO_STATE_LOW);
LOG_DEBUG("lights state set to LOW\n");
delay_ms(1000);
//TEST 5 - Horn state LOW
LOG_DEBUG("Running test for Horn in state LOW\n");
gpio_set_state(&uv_status,GPIO_STATE_HIGH);
gpio_set_state(&horn,GPIO_STATE_LOW);
g_rx_struct.horn_and_lights_horn_state = GPIO_STATE_LOW;
lights_check = 0;
uv_smoke_logic();
assert(status == STATUS_CODE_OK);
assert(state_val == GPIO_STATE_HIGH);
LOG_DEBUG("horn state set to HIGH\n");
delay_ms(1000);
//TEST 6 - Lights state LOW
LOG_DEBUG("Running test for Lights in state LOW\n");
gpio_set_state(&uv_status,GPIO_STATE_HIGH);
gpio_set_state(&lights,GPIO_STATE_LOW);
g_rx_struct.horn_and_lights_lights_state = GPIO_STATE_LOW;
lights_check = 1;
uv_smoke_logic();
assert(status == STATUS_CODE_OK);
assert(state_val == GPIO_STATE_HIGH);
LOG_DEBUG("lights state set to HIGH\n");
delay_ms(1000);
LOG_DEBUG("All tasks completed!\n");
}

int main() {
tasks_init();
log_init();

gpio_init();

//IT SHOULD BE GPIO_INPUT_PULL_UP BUT CHANGED FOR TESTING PURPOSES ONLY
gpio_init_pin(&uv_status, GPIO_OUTPUT_PUSH_PULL, GPIO_STATE_HIGH);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Write a comment here saying that is should be GPIO_INPUT_PULL_UP , but you're faking that for now.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed :)

gpio_init_pin(&horn, GPIO_OUTPUT_PUSH_PULL, GPIO_STATE_LOW);
gpio_init_pin(&lights, GPIO_OUTPUT_PUSH_PULL, GPIO_STATE_LOW);

tasks_init_task(smoke_task, TASK_PRIORITY(1), NULL);

tasks_start();

LOG_DEBUG("UV cutoff task!\n");
return 0;
}
Loading