分四部分:按键驱动,声卡驱动,Madplay播放器移植,MP3主播放器处理
按键1:播放,按键2:停止,按键3:上一曲,按键4:下一曲
UA1341内核自带声卡驱动
1.解压内核:
tar zxvf linux.2.6.29.tar.gz
2.清理中间件,配置文件:
cd linux-linux2.6.29;make clean
3.选择参考配置文件:
cp config-mp3.config
4.配置内核:
make menuconfig ARCH=arm
CROSS_COMPILE=arm-linux-
选择声卡驱动:device drivers-->sound card support-->advanced linux sound architecture-->alsa for soc audio support-->UA134x
5.编译内核:
make uImage ARCH=arm
CROSS_COMPILE=arm-linux-
内核映像uImage位于arch/arm/boot
将其拷贝到tftpboot目录
6.解压rootfs.tar.gz并拷贝到nfsroot
7.按键驱动移植:
cd SDK-MP3/driver
make clean;make
cp mini2440_buttons.ko /nfroot/rootfs/mp3
8.madplay移植
见最后
9.播放处理:
cd SDK-MP3/app;make clean;make
cp app-mp3 /nfsroot/rootfs/mp3
10.测试
采用NFS方式起文件系统,加载按键驱动,运行mp3程序:
insmod mini2440_buttons.ko
./app-mp3
会显示播放列表,播放option,1,2,3,4按键控制播放。
主要程序为mp3播放控制程序:
/*
* mp3播放器控制程序
* 功能:
k1:播放、暂停
k2:停止播放
k3:上一首
k4:下一首
* 附加:歌曲自动循环播放
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <signal.h>
#include <sys/select.h>
#include <sys/time.h>
#include <errno.h>
#include <sys/wait.h>
#include <string.h>
#include <sys/ipc.h>
#include <sys/shm.h>
/*共享内存申请标记*/
#define PERM S_IRUSR|S_IWUSR
/*双向循环列表:存放歌曲名*/
struct song
{
char songname[20];
struct song *prev;
struct song *next;
};
/*孙子进程id号*/
pid_t gradchild;
/*子进程id号*/
pid_t pid;
/*共享内存描述标记*/
int shmid;
char *p_addr;
/*播放标记*/
int first_key=1;
int play_flag=0;
/*************************************************
Function name: play
Parameter : struct song *
Description : 播放函数
Return : void
Argument : void
Autor & date : ada 09,12,07
**************************************************/
void play(struct song *currentsong)
{
pid_t fd;
char *c_addr;
char *p;
int len;
char my_song[30]="/mp3/song/";
while(currentsong)
{
/*创建子进程,即孙子进程*/
fd = fork();
if(fd == -1)
{
perror("fork");
exit(1);
}
else if(fd == 0)
{
/*把歌曲名加上根路径*/
strcat(my_song,currentsong->songname);
p = my_song;
len = strlen(p);
/*去掉文件名最后的'
'*/
my_song[len-1]='