Files

109 lines
2.5 KiB
C

#include <stdio.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <string.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <unistd.h>
#include <sys/types.h>
#include <fcntl.h>
#include<time.h>
#include <sys/mman.h>
uint32_t g_count = 256;
int g_size = 0x4;
unsigned long g_paddr = 0xC001B000;
volatile unsigned int *din;
int key_down(void)
{
int key;
key = *din;
key = key>>31;
if(!key) {
usleep(20000);
key = *din;
key = key>>31;
}
return !key;
}
int main(int argc, char **argv)
{
int i, j=0;
int rtn, errno;
volatile unsigned int *inout;
volatile unsigned int *pad;
int rec_st = 0;
int fd;
void * mem;
void * aligned_vaddr;
unsigned long aligned_paddr;
uint32_t aligned_size;
unsigned int tmp;
/* Align address to access size */
g_paddr &= ~(g_size - 1);
aligned_paddr = g_paddr & ~(4096 - 1);
aligned_size = g_paddr - aligned_paddr + (g_count * g_size);
aligned_size = (aligned_size + 4096 - 1) & ~(4096 - 1);
if ((fd = open("/dev/mem", O_RDWR, 0)) < 0) {
printf("open /dev/mem failed\r\n");
return 1;
}
aligned_vaddr = mmap(NULL, aligned_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, aligned_paddr);
if (aligned_vaddr == NULL) {
printf("Error mapping address\n");
close(fd);
return 1;
}
mem = (void *)((uint32_t)aligned_vaddr + (g_paddr - aligned_paddr));
inout = (volatile unsigned int *)(mem+0x4);
//pull = (volatile unsigned int *)(mem+0x);
pad = (volatile unsigned int *)(mem+0x24);
din = (volatile unsigned int *)(mem+0x18);
tmp = *inout;
tmp &= ~0xC0000000;
*inout = tmp; //B30 B31 input
tmp = *pad;
tmp &= ~0xF0000000;
*pad = tmp; //B30 B31 input
//system("touch /tmp/rec");
system("echo ""REC OFF"" > /tmp/rec");
while(1) {
if(key_down()) {
if(rec_st) {
printf("kill record process\n");
system("pkill.sh ffmpeg");
system("pkill.sh write_ts");
system("echo ""REC OFF"" > /tmp/rec");
//system("/usr/exe/out/bin/pkill.sh write_ts");
//system("/usr/exe/out/bin/pkill.sh write_ts");
} else {
system("/mnt/write_ts &");
system("echo ""REC ON"" > /tmp/rec");
}
rec_st = !rec_st;
sleep(1);
}
usleep(20000);
}
munmap(aligned_vaddr, aligned_size);
close(fd);
return 0;
}