Skip to content

Commit

Permalink
Merge pull request #358 from stefanor/heartbeat
Browse files Browse the repository at this point in the history
Apply heartbeat to input FBs
  • Loading branch information
mithro committed Sep 24, 2017
2 parents 28b8f2e + 9466add commit c5cfc97
Show file tree
Hide file tree
Showing 9 changed files with 62 additions and 51 deletions.
31 changes: 31 additions & 0 deletions firmware/framebuffer.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Copyright 2017 Stefano Rivera <stefano@rivera.za.net>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*/

#ifndef __FRAMEBUFFER_H
#define __FRAMEBUFFER_H

#include <stdint.h>
#include "generated/mem.h"

// Largest frame size at 16bpp (ish)
#define FRAMEBUFFER_SIZE (1920*1080*2)
#define FRAMEBUFFER_COUNT 4
#define FRAMEBUFFER_MASK (FRAMEBUFFER_COUNT - 1)
typedef unsigned int fb_ptrdiff_t;
// FIXME: typedef uint16_t framebuffer_t[FRAMEBUFFER_SIZE];

inline unsigned int *fb_ptrdiff_to_main_ram(fb_ptrdiff_t p) {
return (unsigned int *)(MAIN_RAM_BASE + p);
}

#endif /* __FRAMEBUFFER_H */
12 changes: 4 additions & 8 deletions firmware/hdmi_in0.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,13 @@
int hdmi_in0_debug;
int hdmi_in0_fb_index;

#define FRAMEBUFFER_COUNT 4
#define FRAMEBUFFER_MASK (FRAMEBUFFER_COUNT - 1)

#define HDMI_IN0_FRAMEBUFFERS_BASE (0x00000000 + 0x100000)
#define HDMI_IN0_FRAMEBUFFERS_SIZE (1920*1080*2)

//#define CLEAN_COMMUTATION
//#define DEBUG

unsigned int hdmi_in0_framebuffer_base(char n) {
return HDMI_IN0_FRAMEBUFFERS_BASE + n*HDMI_IN0_FRAMEBUFFERS_SIZE;
fb_ptrdiff_t hdmi_in0_framebuffer_base(char n) {
return HDMI_IN0_FRAMEBUFFERS_BASE + n * FRAMEBUFFER_SIZE;
}

static int hdmi_in0_fb_slot_indexes[2];
Expand All @@ -45,7 +41,7 @@ void hdmi_in0_isr(void)
unsigned int address_min, address_max;

address_min = HDMI_IN0_FRAMEBUFFERS_BASE & 0x0fffffff;
address_max = address_min + HDMI_IN0_FRAMEBUFFERS_SIZE*FRAMEBUFFER_COUNT;
address_max = address_min + FRAMEBUFFER_SIZE*FRAMEBUFFER_COUNT;
if((hdmi_in0_dma_slot0_status_read() == DVISAMPLER_SLOT_PENDING)
&& ((hdmi_in0_dma_slot0_address_read() < address_min) || (hdmi_in0_dma_slot0_address_read() > address_max)))
wprintf("dvisampler0: slot0: stray DMA\r\n");
Expand Down Expand Up @@ -163,7 +159,7 @@ void hdmi_in0_clear_framebuffers(void)
int i;
flush_l2_cache();
volatile unsigned int *framebuffer = (unsigned int *)(MAIN_RAM_BASE + HDMI_IN0_FRAMEBUFFERS_BASE);
for(i=0; i<(HDMI_IN0_FRAMEBUFFERS_SIZE*FRAMEBUFFER_COUNT)/4; i++) {
for(i=0; i<(FRAMEBUFFER_SIZE*FRAMEBUFFER_COUNT)/4; i++) {
framebuffer[i] = 0x80108010; /* black in YCbCr 4:2:2*/
}
}
Expand Down
3 changes: 2 additions & 1 deletion firmware/hdmi_in0.h
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
#include <stdbool.h>
#include "framebuffer.h"

#ifndef __HDMI_IN0_H
#define __HDMI_IN0_H

extern int hdmi_in0_debug;
extern int hdmi_in0_fb_index;

unsigned int hdmi_in0_framebuffer_base(char n);
fb_ptrdiff_t hdmi_in0_framebuffer_base(char n);

void hdmi_in0_isr(void);
void hdmi_in0_init_video(int hres, int vres);
Expand Down
12 changes: 4 additions & 8 deletions firmware/hdmi_in1.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,13 @@
int hdmi_in1_debug;
int hdmi_in1_fb_index;

#define FRAMEBUFFER_COUNT 4
#define FRAMEBUFFER_MASK (FRAMEBUFFER_COUNT - 1)

#define HDMI_IN1_FRAMEBUFFERS_BASE (0x01000000 + 0x100000)
#define HDMI_IN1_FRAMEBUFFERS_SIZE (1920*1080*2)

//#define CLEAN_COMMUTATION
//#define DEBUG

unsigned int hdmi_in1_framebuffer_base(char n) {
return HDMI_IN1_FRAMEBUFFERS_BASE + n*HDMI_IN1_FRAMEBUFFERS_SIZE;
fb_ptrdiff_t hdmi_in1_framebuffer_base(char n) {
return HDMI_IN1_FRAMEBUFFERS_BASE + n*FRAMEBUFFER_SIZE;
}

static int hdmi_in1_fb_slot_indexes[2];
Expand All @@ -45,7 +41,7 @@ void hdmi_in1_isr(void)
unsigned int address_min, address_max;

address_min = HDMI_IN1_FRAMEBUFFERS_BASE & 0x0fffffff;
address_max = address_min + HDMI_IN1_FRAMEBUFFERS_SIZE*FRAMEBUFFER_COUNT;
address_max = address_min + FRAMEBUFFER_SIZE*FRAMEBUFFER_COUNT;
if((hdmi_in1_dma_slot0_status_read() == DVISAMPLER_SLOT_PENDING)
&& ((hdmi_in1_dma_slot0_address_read() < address_min) || (hdmi_in1_dma_slot0_address_read() > address_max)))
wprintf("dvisampler1: slot0: stray DMA\r\n");
Expand Down Expand Up @@ -163,7 +159,7 @@ void hdmi_in1_clear_framebuffers(void)
int i;
flush_l2_cache();
volatile unsigned int *framebuffer = (unsigned int *)(MAIN_RAM_BASE + HDMI_IN1_FRAMEBUFFERS_BASE);
for(i=0; i<(HDMI_IN1_FRAMEBUFFERS_SIZE*FRAMEBUFFER_COUNT)/4; i++) {
for(i=0; i<(FRAMEBUFFER_SIZE*FRAMEBUFFER_COUNT)/4; i++) {
framebuffer[i] = 0x80108010; /* black in YCbCr 4:2:2*/
}
}
Expand Down
3 changes: 2 additions & 1 deletion firmware/hdmi_in1.h
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
#include <stdbool.h>
#include "framebuffer.h"

#ifndef __HDMI_IN1_H
#define __HDMI_IN1_H

extern int hdmi_in1_debug;
extern int hdmi_in1_fb_index;

unsigned int hdmi_in1_framebuffer_base(char n);
fb_ptrdiff_t hdmi_in1_framebuffer_base(char n);

void hdmi_in1_isr(void);
void hdmi_in1_init_video(int hres, int vres);
Expand Down
33 changes: 8 additions & 25 deletions firmware/heartbeat.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@
#include <system.h>
#include <time.h>

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

static bool heartbeat_status = false;

Expand All @@ -21,16 +22,16 @@ void hb_status(bool val)
heartbeat_status = val;
}

void hb_service(int sink)
void hb_service(fb_ptrdiff_t fb_offset)
{
static int last_event;
static int counter;
static bool color_v;

if (heartbeat_status==1) {
hb_fill(color_v, fb_offset);
if(elapsed(&last_event, SYSTEM_CLOCK_FREQUENCY/FILL_RATE)) {
counter = counter+1;
hb_fill(color_v, sink);
counter = counter + 1;
if(counter > FILL_RATE/(HEARTBEAT_FREQUENCY*2)) {
color_v = !color_v;
counter = 0;
Expand All @@ -39,30 +40,12 @@ void hb_service(int sink)
}
}

void hb_fill(bool color_v, int sink)
void hb_fill(bool color_v, fb_ptrdiff_t fb_offset)
{
int addr, i, j;
unsigned int color;

volatile unsigned int *framebuffer = (unsigned int *)(MAIN_RAM_BASE + pattern_framebuffer_base());

/*
#ifdef CSR_HDMI_OUT0_BASE
if (sink == VIDEO_OUT_HDMI_OUT0) {
framebuffer = (unsigned int *)(MAIN_RAM_BASE + HDMI_IN0_FRAMEBUFFERS_BASE);
}
#endif
#ifdef CSR_HDMI_OUT1_BASE
if (sink == VIDEO_OUT_HDMI_OUT1) {
framebuffer = (unsigned int *)(MAIN_RAM_BASE + HDMI_IN1_FRAMEBUFFERS_BASE);
}
#endif
#ifdef ENCODER_BASE
if (sink == VIDEO_OUT_ENCODER) {
framebuffer = (unsigned int *)(MAIN_RAM_BASE + encoder_reader_base_read());
}
#endif
*/
unsigned int *framebuffer = fb_ptrdiff_to_main_ram(fb_offset);

/*
8x8 pixel square at right bottom corner
Expand Down
5 changes: 3 additions & 2 deletions firmware/heartbeat.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
#define __HEARTBEAT_H

#include <stdbool.h>
#include "framebuffer.h"

void hb_status(bool val);
void hb_service(int sink) ;
void hb_fill(bool color_v, int sink);
void hb_service(fb_ptrdiff_t fb_offset) ;
void hb_fill(bool color_v, fb_ptrdiff_t fb_offset);

#endif /* __HEARTBEAT_H */
12 changes: 7 additions & 5 deletions firmware/processor.c
Original file line number Diff line number Diff line change
Expand Up @@ -666,8 +666,6 @@ void processor_update(void)
#endif
if(processor_hdmi_out0_source == VIDEO_IN_PATTERN)
hdmi_out0_core_initiator_base_write(pattern_framebuffer_base());

hb_service(VIDEO_OUT_HDMI_OUT0);
#endif

#ifdef CSR_HDMI_OUT1_BASE
Expand All @@ -682,8 +680,6 @@ void processor_update(void)
#endif
if(processor_hdmi_out1_source == VIDEO_IN_PATTERN)
hdmi_out1_core_initiator_base_write(pattern_framebuffer_base());

hb_service(VIDEO_OUT_HDMI_OUT1);
#endif


Expand All @@ -701,9 +697,15 @@ void processor_update(void)
#endif
if(processor_encoder_source == VIDEO_IN_PATTERN)
encoder_reader_base_write(pattern_framebuffer_base());
#endif

hb_service(VIDEO_OUT_ENCODER);
#ifdef CSR_HDMI_IN0_BASE
hb_service(hdmi_in0_framebuffer_base(hdmi_in0_fb_index));
#endif
#ifdef CSR_HDMI_IN1_BASE
hb_service(hdmi_in1_framebuffer_base(hdmi_in1_fb_index));
#endif
hb_service(pattern_framebuffer_base());
}

void processor_service(void)
Expand Down
2 changes: 1 addition & 1 deletion scripts/download-env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ echo ""
echo "Initializing environment"
echo "---------------------------------"
# Install and setup conda for downloading packages
export PATH=$CONDA_DIR/bin:$PATH
export PATH=$CONDA_DIR/bin:$PATH:/sbin
(
echo
echo "Installing conda (self contained Python environment with binary package support)"
Expand Down

0 comments on commit c5cfc97

Please sign in to comment.