From: <sen...@us...> - 2009-03-31 22:39:43
|
Revision: 373 http://open2x.svn.sourceforge.net/open2x/?rev=373&view=rev Author: senquack Date: 2009-03-31 22:39:39 +0000 (Tue, 31 Mar 2009) Log Message: ----------- Relaunchd, the Open2X menu relaunching daemon (for use with the process killer) Added Paths: ----------- trunk/utils/relaunchd/ trunk/utils/relaunchd/Makefile trunk/utils/relaunchd/mmsp2_regs.h trunk/utils/relaunchd/relaunchd.c Added: trunk/utils/relaunchd/Makefile =================================================================== --- trunk/utils/relaunchd/Makefile (rev 0) +++ trunk/utils/relaunchd/Makefile 2009-03-31 22:39:39 UTC (rev 373) @@ -0,0 +1,41 @@ +CFLAGS=-c -O3 -g -Wall -DPLATFORM_GP2X -mcpu=arm920t -mtune=arm920 -ffast-math -W -Wall -pthread -msoft-float +#CFLAGS=-c -O0 -g -Wall -DPLATFORM_GP2X -mcpu=arm920t -mtune=arm920 -ffast-math -W -Wall -pthread -msoft-float + +#LDFLAGS=-L/opt/open2x/gcc-4.1.1-glibc-2.3.6/lib -Wl,-rpath,/opt/open2x/gcc-4.1.1-glibc-2.3.6/lib -static -lgcc -lm -lc -ldl -larmmem -msoft-float -O2 +LDFLAGS=-L/opt/open2x/gcc-4.1.1-glibc-2.3.6/lib -Wl,-rpath,/opt/open2x/gcc-4.1.1-glibc-2.3.6/lib -lgcc -lm -lc -ldl -msoft-float -O2 + +SOURCES=relaunchd.c + + +OBJECTS=$(SOURCES:.c=.o) +EXECUTABLEGP=relaunchd + +CC=arm-open2x-linux-gcc +STRIP=arm-open2x-linux-strip +CFLAGS+=-I/opt/open2x/gcc-4.1.1-glibc-2.3.6/include/ \ + -I/opt/open2x/gcc-4.1.1-glibc-2.3.6/arm-open2x-linux/include/ \ + -I/opt/open2x/gcc-4.1.1-glibc-2.3.6/include/SDL -D_REENTRANT \ + -msoft-float -DPLATFORM_GP2X + +all: + make gpversion + +gpversion: $(SOURCES) $(EXECUTABLEGP) + + +$(EXECUTABLEGP): $(OBJECTS) +# $(CC) $(LDFLAGS) -static $(OBJECTS) -o $@ $(GPLDFLAGS) + $(CC) $(LDFLAGS) $(OBJECTS) -o $@ $(GPLDFLAGS) + $(STRIP) $@ + + + +.c.o: + $(CC) $(CFLAGS) $< -o $@ + +cleanobjs: + rm -f $(OBJECTS) + +clean: + -rm -f relaunchd *~ *.o *.bak + Added: trunk/utils/relaunchd/mmsp2_regs.h =================================================================== --- trunk/utils/relaunchd/mmsp2_regs.h (rev 0) +++ trunk/utils/relaunchd/mmsp2_regs.h 2009-03-31 22:39:39 UTC (rev 373) @@ -0,0 +1,194 @@ +/* + * MMSP2 (MP2520F) Registers + * Only listed needed regs for HW blit stuff + * + * 2005-12-20 Paeryn + */ + + +#ifndef _MMSP2_REG_H_ +#define _MMSP2_REG_H_ + +/* + * Blitter registers + */ + +#define MESGDSTCTRL (0x0000>>2) +#define MESG_DSTENB (1<<6) +#define MESG_BSTBPP 0x60 +#define MESG_DSTBPP_8 (0<<5) +#define MESG_DSTBPP_16 (1<<5) + +#define MESGDSTADDR (0x0004>>2) +#define MESGDSTSTRIDE (0x0008>>2) +#define MESGSRCCTRL (0x000C>>2) +#define MESG_INVIDEO (1<<8) +#define MESG_SRCENB (1<<7) +#define MESG_SRCBPP 0x60 +#define MESG_SRCBPP_8 (0<<5) +#define MESG_SRCBPP_16 (1<<5) +#define MESG_SRCBPP_1 (1<<6) + +#define MESGSRCADDR (0x0010>>2) +#define MESGSRCSTRIDE (0x0014>>2) +#define MESGSRCFORCOLOR (0x0018>>2) +#define MESGSRCBACKCOLOR (0x001C>>2) +#define MESGPATCTRL (0x0020>>2) +#define MESG_PATMONO (1<<6) +#define MESG_PATENB (1<<5) +#define MESG_PATBPP 0x18 +#define MESG_PATBPP_8 (0<<3) +#define MESG_PATBPP_16 (1<<3) +#define MESG_PATBPP_1 (1<<4) +#define MESG_YOFFSET 0x07 + +#define MESGFORCOLOR (0x0024>>2) +#define MESGBACKCOLOR (0x0028>>2) +#define MESGSIZE (0x002C>>2) +#define MESG_HEIGHT 16 +#define MESG_WIDTH 0 + +#define MESGCTRL (0x0030>>2) +#define MESG_TRANSPCOLOR 16 +#define MESG_TRANSPEN (1<<11) +#define MESG_FFCLR (1<<10) +#define MESG_YDIR (1<< 9) +#define MESG_YDIR_NEG (0<< 9) +#define MESG_YDIR_POS (1<< 9) +#define MESG_XDIR (1<< 8) +#define MESG_XDIR_NEG (0<< 8) +#define MESG_XDIR_POS (1<< 8) +#define MESG_ROP 0xFF + +#define MESGSTATUS (0x0034>>2) +#define MESG_BUSY (1<<0) + +#define MESGFIFOSTATUS (0x0038>>2) +#define MESG_FULL (1<<31) +#define MESG_REMAIN 0x1f + +#define MESGFIFO (0x003C>>2) +#define MESGPAT (0x0080>>2) + +/* + * Basic ROPs + */ +#define MESG_ROP_NULL 0xAA +#define MESG_ROP_COPY 0xCC +#define MESG_ROP_PAT 0xF0 + + +/* + * Control registers + */ +#define SYSCLKENREG (0x0904>>1) +#define FASTIOCLK (1<<10) + +#define VCLKENREG (0x090A>>1) +#define GRPCLK (1<<2) + +#define SC_STATUS (0x1802>>1) +#define SC_DISP_FIELD (1<<7) + +#define GPIOB_PINLVL (0x1182>>1) +#define GPIOB_VSYNC (1<<4) + +#define DPC_CNTL (0x2800>>1) +#define DPC_INTERLACE (1<<5) +#define DPC_X_MAX (0x2816>>1) +#define DPC_Y_MAX (0x2818>>1) +#define DPC_V_SYNC (0x2920>>1) +#define DPC_VSFLDPOL (1<<6) +#define DPC_VSFLDEN (1<<7) +#define DPC_CLKCNTL (0x2848>>1) + +#define MLC_OVLAY_CNTR (0x2880>>1) +#define DISP_BOTH_PATH (1<<15) +#define DISP_OVLY2SCALE (1<<14) +#define DISP_FLD_POL (1<<13) +#define DISP_GAMM_BYPATH (1<<12) +#define DISP_SWAP (1<<11) +#define DISP_CURSOR (1<< 9) +#define DISP_SUBPICTURE (1<< 8) +#define DISP_OSD (1<< 7) +#define DISP_STL5EN (1<< 6) +#define DISP_STL4EN (1<< 5) +#define DISP_STL3EN (1<< 4) +#define DISP_STL2EN (1<< 3) +#define DISP_STL1EN (1<< 2) +#define DISP_VLBON (1<< 1) +#define DISP_VLAON (1<< 0) + +#define MLC_STL_CNTL (0x28DA>>1) +#define MLC_STL_BPP 9 +#define MLC_STL_BPP_4 0x00AA +#define MLC_STL_BPP_8 0x02AA +#define MLC_STL_BPP_16 0x04AA +#define MLC_STL_BPP_24 0x06AA +#define MLC_STL5ACT (1<<8) +#define MLC_STL4ACT (1<<6) +#define MLC_STL3ACT (1<<6) +#define MLC_STL2ACT (1<<4) +#define MLC_STL1ACT (1<<0) +#define MLC_STL_DEFAULT 0xAA + +#define MLC_STL_MIXMUX (0x28DC>>1) +#define MLC_STL5_MIXMUX 8 +#define MLC_STL4_MIXMUX 6 +#define MLC_STL3_MIXMUX 4 +#define MLC_STL2_MIXMUX 2 +#define MLC_STL1_MIXMUX 0 + +#define MLC_STL_ALPHAL (0x28DE>>1) +#define MLC_STL3_ALPHA 8 +#define MLC_STL2_ALPHA 4 +#define MLC_STL1_ALPHA 0 + +#define MLC_STL_ALPHAH (0x28E0>>1) +#define MLC_STL5_ALPHA 4; +#define MLC_STL4_ALPHA 0; + +#define MLC_STL1_STX (0x28E2>>1) +#define MLC_STL1_ENDX (0x28E4>>1) +#define MLC_STL1_STY (0x28E6>>1) +#define MLC_STL1_ENDY (0x28E8>>1) +#define MLC_STL2_STX (0x28EA>>1) +#define MLC_STL2_ENDX (0x28EC>>1) +#define MLC_STL2_STY (0x28EE>>1) +#define MLC_STL2_ENDY (0x28F0>>1) +#define MLC_STL3_STX (0x28F2>>1) +#define MLC_STL3_ENDX (0x28F4>>1) +#define MLC_STL3_STY (0x28F6>>1) +#define MLC_STL3_ENDY (0x28F8>>1) +#define MLC_STL4_STX (0x28FA>>1) +#define MLC_STL4_ENDX (0x28FC>>1) +#define MLC_STL4_STY (0x28FE>>1) +#define MLC_STL4_ENDY (0x2900>>1) +#define MLC_STL_CKEY_GB (0x2902>>1) +#define MLC_STL_CKEYG 8 +#define MLC_STL_CKEYB 0 +#define MLC_STL_CKEY_R (0x2904>>1) +#define MLC_STL_HSC (0x2906>>1) +#define MLC_STL_VSCL (0x2908>>1) +#define MLC_STL_VSCH (0x290A>>1) +#define MLC_STL_HW (0x290C>>1) +#define MLC_STL_OADRL (0x290E>>1) +#define MLC_STL_OADRH (0x2910>>1) +#define MLC_STL_EADRL (0x2912>>1) +#define MLC_STL_EADRH (0x2914>>1) +#define MLC_STL_PALLT_A (0x2958>>1) +#define MLC_STL_PALLT_D (0x295A>>1) + +#define MLC_HWC_CNTL (0x291E>>1) +#define MLC_HWC_STX (0x2920>>1) +#define MLC_HWC_STY (0x2922>>1) +#define MLC_HWC_FGR (0x2924>>1) +#define MLC_HWC_FB (0x2926>>1) +#define MLC_HWC_BGR (0x2928>>1) +#define MLC_HWC_BB (0x292A>>1) +#define MLC_HWC_OADRL (0x292C>>1) +#define MLC_HWC_OADRH (0x292E>>1) +#define MLC_HWC_EADRL (0x2930>>1) +#define MLC_HWC_EADRH (0x2932>>1) + +#endif Added: trunk/utils/relaunchd/relaunchd.c =================================================================== --- trunk/utils/relaunchd/relaunchd.c (rev 0) +++ trunk/utils/relaunchd/relaunchd.c 2009-03-31 22:39:39 UTC (rev 373) @@ -0,0 +1,210 @@ +/* relaunchd.c Menu relaunching daemon for Open2X. + Copyright (C) 2008 Dan Silsby (Senor Quack) + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +*/ +#include <stdlib.h> +#include <stdio.h> +#include <string.h> +#include <fcntl.h> +#include <sys/ioctl.h> +#include <sys/mman.h> +#include <linux/fb.h> +#include <unistd.h> +#include <stropts.h> +#include <errno.h> +#include <time.h> +#include <signal.h> +#include <sys/types.h> +#include <sys/stat.h> +#include "mmsp2_regs.h" + +// GET_GMENU2X_RELAUNCH_NEEDED allows the gmenu2x relaunch daemon to see if the process killer +// has indicated a relaunch of gmenu2x is needed. Once the daemon relaunches GMenu2X, it will +// issue the ioctl SET_GMENU2X_RELAUNCH_NEEDED with the argument 0 to reset this flag. +#define GP2X_GET_GMENU2X_RELAUNCH_NEEDED 92 +#define GP2X_SET_GMENU2X_RELAUNCH_NEEDED 93 + +#define DEFAULT_DELAY 2 // 2 second delay +#define MIN_DELAY 1 +#define MAX_DELAY 10 +#define DEBUG 1 + +extern int errno; + +int delay = DEFAULT_DELAY; +//char scriptname[256]; +char *scriptname = "/usr/sbin/relaunchd_script"; + +int relaunch_needed(void) +{ + int gpiodev = open("/dev/GPIO",O_RDONLY); + if (gpiodev == -1) + { +#if DEBUG + printf("Error opening /dev/GPIO during poll.\n"); +#endif + return 0; + } + + int retval = (ioctl(gpiodev, GP2X_GET_GMENU2X_RELAUNCH_NEEDED, 0) == 1); + close(gpiodev); + return retval; +} + +void reset_relaunch_flag(void) +{ + int new_flag = 0; + int gpiodev = open("/dev/GPIO",O_WRONLY); + if (gpiodev == -1) + { +#if DEBUG + printf("Error opening /dev/GPIO during reset.\n"); +#endif + return; + } + + ioctl(gpiodev, GP2X_SET_GMENU2X_RELAUNCH_NEEDED, &new_flag); + close(gpiodev); +} + +void loop (void) +{ + struct timespec timereq, timerem; + timereq.tv_sec = delay; + timereq.tv_nsec = 0; + + while (1) + { + nanosleep(&timereq, &timerem); + + if (relaunch_needed()) + { +#if DEBUG + printf("Relaunch needed, killing all gmenu2x processes..\n"); +#endif + system("killall gmenu2x"); + +#if DEBUG + printf("Executing %s..\n", scriptname); +#endif + if (system(scriptname) == -1) + { +#if DEBUG + printf("Error during relaunch\n"); +#endif + } + + reset_relaunch_flag(); + } + } +} + +void displayhelp (void) +{ + printf("Open2X menu relaunching daemon written by Senor Quack v1.0\n"); + printf(" Copyright (C) 2009 Daniel Silsby\n\n"); + printf("OPTIONS:\n"); + printf("-h\t\tDisplay help and version info\n"); +// printf("-sSCRIPTNAME\tRelaunch script (full pathname required)\n"); + printf("-dSECS\t\tSleep this many seconds inbetween polls. Valid range: %d..%d\n", + MIN_DELAY, MAX_DELAY); + printf("\t\t\t(if not specified, default is %d seconds)\n", DEFAULT_DELAY); +} + +int main(int argc, char *argv[]) +{ + signal(SIGINT,&exit); + signal(SIGTERM, &exit); + signal(SIGHUP, SIG_IGN); + +// scriptname[0] = 0; + int cur_arg = 1; + while (cur_arg < argc) + { + // We have been passed command-line parameters + switch (argv[cur_arg][1]) + { + case 'h': + displayhelp(); + return(0); + break; + case 'd': + if (strlen(&argv[cur_arg][2]) <= 2) + { + delay = atoi(&argv[cur_arg][2]); + if (delay < MIN_DELAY || delay > MAX_DELAY) + { + printf("ERROR: delay out of range\n\n"); + displayhelp(); + exit(1); + } + } else + { + printf("ERROR: bad delay given\n\n"); + displayhelp(); + exit(1); + } + break; +// case 's': +// if (strlen(&argv[cur_arg][2]) < 250) +// { +// strcpy(scriptname, &argv[cur_arg][2]); +// struct stat tmp; +// if (stat(scriptname, &tmp)) +// { +// printf("ERROR: file %s does not exist.\n\n", scriptname); +// displayhelp(); +// exit(1); +// } +// strcat(scriptname, "&"); // run in background +// } else +// { +// printf("ERROR: script name too long\n\n"); +// displayhelp(); +// exit(1); +// } +// break; + default: + // invalid parameter + printf("ERROR: invalid parameter passed\n\n"); + displayhelp(); + exit(1); + } // switch + cur_arg++; + } // while (argc > 1) + +// if (scriptname[0] == 0) +// { +// // No script specified +// printf("ERROR: no relaunch script specified\n\n"); +// displayhelp(); +// exit(1); +// } + + struct stat tmp; + if (stat(scriptname, &tmp)) + { + printf("ERROR: relaunching script %s is missing.\n\n", scriptname); + exit(1); + } + + // main loop + loop(); + + return 0; +} + This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |