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

Added heartbeat functionality #266

Merged
merged 13 commits into from
Jul 11, 2016
1 change: 1 addition & 0 deletions firmware/lm32/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ OBJECTS=isr.o \
hdmi_in1.o \
hdmi_out0.o \
hdmi_out1.o \
heartbeat.o \
pattern.o \
edid.o \
pll.o \
Expand Down
37 changes: 36 additions & 1 deletion firmware/lm32/ci.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "hdmi_in0.h"
#include "hdmi_in1.h"
#include "processor.h"
#include "heartbeat.h"
#include "pll.h"
#include "ci.h"
#include "encoder.h"
Expand Down Expand Up @@ -54,6 +55,12 @@ static void help_status(void)
puts(" status <on/off> - repeatedly print status message");
}

static void help_heartbeat(void)
{
puts("change heartbeat status (alias: 'h')");
puts(" heartbeat <on/off> - Turn on/off heartbeat feature");
}

#ifdef CSR_HDMI_OUT0_BASE
static void help_output0(void)
{
Expand Down Expand Up @@ -113,6 +120,8 @@ static void help(void)
puts("");
help_video_mode();
puts("");
help_heartbeat();
puts("");
help_hdp_toggle();
puts("");
#ifdef CSR_HDMI_OUT0_BASE
Expand Down Expand Up @@ -230,6 +239,20 @@ static void status_service(void)
}
}

static void heartbeat_enable(void)
{
hb_status(1);
printf("Heartbeat enabled\r\n");

}

static void heartbeat_disable(void)
{
hb_status(0);
printf("Heartbeat disabled\r\n");

}

static void video_matrix_list(void)
{
printf("Video sources:\r\n");
Expand Down Expand Up @@ -536,6 +559,10 @@ void ci_service(void)
#endif
else if(strcmp(token, "debug") == 0)
help_debug();

else if(strcmp(token, "heartbeat") == 0)
help_heartbeat();

else
help();
puts("");
Expand Down Expand Up @@ -596,6 +623,13 @@ void ci_service(void)
else
video_mode_set(atoi(token));
}
else if((strcmp(token, "heartbeat") == 0) || (strcmp(token, "h") == 0)) {
token = get_token(&str);
if((strcmp(token, "on") == 0) )
heartbeat_enable();
else if((strcmp(token, "off") == 0) )
heartbeat_disable();
}
else if(strcmp(token, "hdp_toggle") == 0) {
token = get_token(&str);
hdp_toggle(atoi(token));
Expand Down Expand Up @@ -751,7 +785,8 @@ void ci_service(void)
printf("%s port has no EDID capabilities\r\n", token);
} else
help_debug();
} else {
}
else {
if(status_enabled)
status_disable();
}
Expand Down
3 changes: 0 additions & 3 deletions firmware/lm32/hdmi_in0.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@ int hdmi_in0_fb_index;
#define FRAMEBUFFER_COUNT 4
#define FRAMEBUFFER_MASK (FRAMEBUFFER_COUNT - 1)

#define HDMI_IN0_FRAMEBUFFERS_BASE 0x01000000
#define HDMI_IN0_FRAMEBUFFERS_SIZE 1920*1080*2

//#define CLEAN_COMMUTATION
//#define DEBUG

Expand Down
3 changes: 3 additions & 0 deletions firmware/lm32/hdmi_in0.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
extern int hdmi_in0_debug;
extern int hdmi_in0_fb_index;

#define HDMI_IN0_FRAMEBUFFERS_BASE 0x01000000
#define HDMI_IN0_FRAMEBUFFERS_SIZE 1920*1080*2

unsigned int hdmi_in0_framebuffer_base(char n);

void hdmi_in0_isr(void);
Expand Down
3 changes: 0 additions & 3 deletions firmware/lm32/hdmi_in1.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@ int hdmi_in1_fb_index;
#define FRAMEBUFFER_COUNT 4
#define FRAMEBUFFER_MASK (FRAMEBUFFER_COUNT - 1)

#define HDMI_IN1_FRAMEBUFFERS_BASE 0x02000000
#define HDMI_IN1_FRAMEBUFFERS_SIZE 1920*1080*2

//#define CLEAN_COMMUTATION
//#define DEBUG

Expand Down
3 changes: 3 additions & 0 deletions firmware/lm32/hdmi_in1.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
extern int hdmi_in1_debug;
extern int hdmi_in1_fb_index;

#define HDMI_IN1_FRAMEBUFFERS_BASE 0x02000000
#define HDMI_IN1_FRAMEBUFFERS_SIZE 1920*1080*2

unsigned int hdmi_in1_framebuffer_base(char n);

void hdmi_in1_isr(void);
Expand Down
71 changes: 71 additions & 0 deletions firmware/lm32/heartbeat.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@

#include <generated/csr.h>
#include <generated/mem.h>
#include <hw/flags.h>
#include <system.h>
#include <time.h>

#include "heartbeat.h"
#include "processor.h"
#include "hdmi_in0.h"
#include "hdmi_in1.h"
#include "pattern.h"

static int heartbeat_status = 0;
Copy link
Member

Choose a reason for hiding this comment

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

Can you use a bool for heartbeat_status rather than an int?


void hb_status(int val)
{
if(val==1) {
Copy link
Member

Choose a reason for hiding this comment

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

if(val) {

Copy link
Member

Choose a reason for hiding this comment

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

Actually, can't you just do

void hb_status(bool new_status)
{
  heartbeat_status = new_status;
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was gonna be my next natural step. Corrected.

heartbeat_status = 1;
}
else {
heartbeat_status = 0;
}
}

void hb_service(int source)
{
static int last_event;
static int counter;
if (heartbeat_status==1) {
if(elapsed(&last_event, identifier_frequency_read()/5)) {
Copy link
Member

Choose a reason for hiding this comment

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

Missing space

Copy link
Member

Choose a reason for hiding this comment

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

Your formatting here is all over the place.

hb_fill(counter, source);
if(counter==5)
Copy link
Member

Choose a reason for hiding this comment

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

It's probably better to have a 1 bit counter here, pass it to hb_fill and select color in hb_fill.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good Idea. Changed counter variable to bool.

counter = 6; //BLUE in color_bar[6]
else
counter = 5; //RED in color_bar[5]
}
}
}

void hb_fill(int color_v, int source)
{
int addr, i, j;
volatile unsigned int *framebuffer = (unsigned int *)(MAIN_RAM_BASE + pattern_framebuffer_base());
Copy link
Member

Choose a reason for hiding this comment

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

@shenki What does the volatile here do? Is it saying the pointer can change out under the compiler - or that the thing that the pointer is pointing too can change out under the compiler?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

volatile not explicitly required here, but will be continued to use for consistency. volatile is used when we want our memory accesses for that variable to be ordered.


#ifdef CSR_HDMI_IN0_BASE
Copy link
Member

Choose a reason for hiding this comment

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

You can probably just use hdmi_out0_fi_base0_read or hdmi_out1_fi_base0_read functions to get the framebuffer address. Not need to duplicate these #ifdef that are already in processor.c.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Modified this. This also fixed some irregular toggle in pattern source. And with some changes, also the hdmi_in sources.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Had to add the #ifdef preprocessor commands again, the firmware should compile for all possible boards, hence the travis-ci was giving errors.

if (source == VIDEO_IN_HDMI_IN0) {
framebuffer = (unsigned int *)(MAIN_RAM_BASE + hdmi_in0_framebuffer_base(hdmi_in0_fb_index));
}
#endif
#ifdef CSR_HDMI_IN1_BASE
if (source == VIDEO_IN_HDMI_IN1) {
framebuffer = (unsigned int *)(MAIN_RAM_BASE + hdmi_in1_framebuffer_base(hdmi_in1_fb_index));
}
#endif
if (source == VIDEO_IN_PATTERN) {
framebuffer = (unsigned int *)(MAIN_RAM_BASE + pattern_framebuffer_base());
}
/*
8x8 pixel square at right bottom corner
8 pixel = 4 memory locations in horizoantal
8 pixel = 8 memory locations in vertical
Toggles between the colors defined in color_bar array from pattern.c
*/
addr = 0 + (processor_h_active/2)*(processor_v_active-8) + (processor_h_active/2) - 4;
for (i=0; i<4; i++){
for (j=0; j<8; j++){
framebuffer[addr+i+(processor_h_active/2)*j] = color_bar[color_v];
Copy link
Member

Choose a reason for hiding this comment

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

Do not use color bar but something like that:

uint32_t color;
if (counter == 0)
    color = YCBCR422_BLUE;
else
    color = YCBCR422_RED;
[...]
framebuffer[addr+i+(processor_h_active/2)*j] = color;
[...]

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Corrected.

}
}
}
8 changes: 8 additions & 0 deletions firmware/lm32/heartbeat.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#ifndef __HEARTBEAT_H
#define __HEARTBEAT_H

void hb_status(int val);
void hb_service(int source) ;
void hb_fill(int color_v, int source);

#endif /* __HEARTBEAT_H */
3 changes: 3 additions & 0 deletions firmware/lm32/pattern.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,11 @@
#define YCBCR422_BLUE 0xff1d6f1d
#define YCBCR422_BLACK 0x80108010

#define PATTERN_FRAMEBUFFER_BASE 0x03000000

unsigned int pattern_framebuffer_base(void);

static const unsigned int color_bar[8];
int pattern;

#define COLOR_BAR_PATTERN 0
Expand Down
9 changes: 9 additions & 0 deletions firmware/lm32/processor.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "edid.h"
#include "pll.h"
#include "processor.h"
#include "heartbeat.h"

/*
----------------->>> Time ----------->>>
Expand Down Expand Up @@ -300,6 +301,7 @@ static const struct video_timing video_modes[PROCESSOR_MODE_COUNT] = {

};


void processor_list_modes(char *mode_descriptors)
{
int i;
Expand Down Expand Up @@ -554,12 +556,19 @@ void processor_service(void)
{
#ifdef CSR_HDMI_IN0_BASE
hdmi_in0_service();
hb_service(VIDEO_IN_HDMI_IN0);

#endif
#ifdef CSR_HDMI_IN1_BASE
hdmi_in1_service();
hb_service(VIDEO_IN_HDMI_IN1);

#endif

processor_update();
#ifdef ENCODER_BASE
encoder_service();
#endif

hb_service(VIDEO_IN_PATTERN);
}