00001
00044 #include <cfg/os.h>
00045 #include <cfg/clock.h>
00046 #include <dev/board.h>
00047 #include <sys/timer.h>
00048 #include <sys/event.h>
00049
00050 #include <stdlib.h>
00051 #include <string.h>
00052
00053 #include <stdio.h>
00054
00055 #include "tlv320dac.h"
00056 #include "receiver.h"
00057 #include "mp3player.h"
00058
00067 PLAYERINFO * PlayerCreate(PLAYERPLUGIN *plugin)
00068 {
00069 PLAYERINFO *pip;
00070
00071
00072 if ((pip = malloc(sizeof(PLAYERINFO))) != NULL) {
00073 memset(pip, 0, sizeof(PLAYERINFO));
00074
00075 if ((*plugin->pp_create) (pip)) {
00076 free(pip);
00077 pip = NULL;
00078 }
00079 }
00080 return pip;
00081 }
00082
00093 static int PlayerPlugInControl(PLAYERINFO *pip, u_int sst, u_int xst)
00094 {
00095 int retries = 10;
00096
00097
00098 while (pip->pi_status != xst) {
00099 pip->pi_status = sst;
00100 NutEventPost(&pip->pi_cmdevt);
00101 if (NutEventWait(&pip->pi_stsevt, 500)) {
00102 if (retries-- <= 0) {
00103 printf("No player control\n");
00104 return -1;
00105 }
00106 }
00107 }
00108 return 0;
00109 }
00110
00119 u_int PlayerStatus(PLAYERINFO *pip)
00120 {
00121 return pip->pi_status;
00122 }
00123
00132 int PlayerStop(PLAYERINFO *pip)
00133 {
00134 printf("[PSTOP]");
00135 return PlayerPlugInControl(pip, PSTAT_STOP, PSTAT_IDLE);
00136 }
00137
00147 int PlayerStart(PLAYERINFO *pip, RECEIVERINFO *rip)
00148 {
00149 if (PlayerStop(pip)) {
00150 return -1;
00151 }
00152 printf("[PSTART]");
00153 pip->pi_rcvr = rip;
00154
00155 return PlayerPlugInControl(pip, PSTAT_START, PSTAT_RUNNING);
00156 }
00157