#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/mman.h>
#include <sys/ioctl.h>
#include "omap_dsp.h"

#define MBUF_LENGTH 0x1000
#define BLOCK_SIZE  1024

#define DSPMEMDEVNM   "/dev/dspctl/mem"
    
struct fbinfo {
	unsigned short adrh;
	unsigned short adrl;
	unsigned short width;
	unsigned short height;
	unsigned short bpp;
	unsigned short pad;
} fbinfo = {
	.adrh = 0,	// init with illegal adr
	.adrl = 0,
	.width = 800,
	.height = 480,
	.bpp = 16,
};

void usage(char *cmd) 
{
       fprintf(stderr, "%s <input file name> <output file name>\n", cmd);
}

/*
 **************************************************************************
 **************************************************************************
*/

int main(int argc, char **argv)
{
    int count=20;
    FILE *infid, *outfid;
    int fd, fdmem;
    int cnt1, cnt2, ret;
    char *devfn = "/dev/dsptask/framebuffer";
    unsigned short dsp_message;
    char *buf;
    short i;
    unsigned long dspadr= 0x1000000; // needs a hint value
    unsigned short data;
     
    fd = open(devfn, O_RDWR);
    if (fd < 0) {
        fprintf(stderr, "cannot open %s, error %d\n", devfn, fd);
        return 1;
    }
    printf("Opened device\n");

    /* Share some memory here too */
    buf = (char *)mmap((void *) 0, MBUF_LENGTH, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);

/*
	if ((fdmem = open(DSPMEMDEVNM, O_RDWR)) < 0) {
		perror("open dspmem device");
		return 1;
	}
	ret = ioctl(fdmem, OMAP_DSP_MEM_IOCTL_FBEXPORT, &dspadr);
	close(fdmem);
	if (ret < 0) {
		perror("FBEXPORT");
		return 1;
	}    
    
    // now send over the dsp address
    fbinfo.adrh = dspadr >> 16; // update the address as returned from the ioctl above
	fbinfo.adrl = dspadr & 0xffff; // update the address as returned from the ioctl above
*/
	memcpy(buf, &fbinfo, sizeof(struct fbinfo));

	for(data=0;data<9;data++)
	{
    	write(fd, &data, sizeof(data));
    	sleep(1);
	}

    return 0; /* Exit, no errors */
}


