git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@83 35acf78f-673a-0410-8e92-d51de3d6d3f4

master
gdisirio 2007-11-03 16:25:52 +00:00
parent 50cd4e00ef
commit aece9ea5fc
6 changed files with 110 additions and 24 deletions

View File

@ -80,3 +80,13 @@ void PlaySound(int freq, t_time duration) {
chSysUnlock();
}
void PlaySoundWait(int freq, t_time duration) {
TC *tc = T1Base;
StopCounter(tc);
tc->TC_MR0 = tc->TC_MR1 = (PCLK / (freq * 2));
StartCounter(tc);
chThdSleep(duration);
StopCounter(tc);
}

View File

@ -22,6 +22,7 @@
void InitBuzzer(void);
void PlaySound(int freq, t_time duration);
void PlaySoundWait(int freq, t_time duration);
extern EventSource BuzzerSilentEventSource;

View File

@ -55,8 +55,6 @@ static t_msg Thread2(void *arg) {
return 0;
}
static BYTE8 rwbuf[512];
static void TimerHandler(t_eventid id) {
t_msg TestThread(void *p);
@ -68,32 +66,50 @@ static void TimerHandler(t_eventid id) {
if (!(IO0PIN & 0x00008000)) // Button 1
PlaySound(1000, 100);
if (!(IO0PIN & 0x00010000)) { // Button 2
MMCCSD data;
chFDDWrite(&COM1, (BYTE8 *)"Hello World!\r\n", 14);
if (mmcInit())
return;
if (mmcGetSize(&data))
return;
if (mmcBlockRead(0x200000, rwbuf))
return;
PlaySound(2000, 100);
}
}
}
static void InsertHandler(t_eventid id) {
static BYTE8 rwbuf[512];
MMCCSD data;
PlaySoundWait(1000, 100);
PlaySoundWait(2000, 100);
if (mmcInit())
return;
/* Card ready, do stuff.*/
if (mmcGetSize(&data))
return;
if (mmcBlockRead(0x200000, rwbuf))
return;
}
static void RemoveHandler(t_eventid id) {
PlaySoundWait(2000, 100);
PlaySoundWait(1000, 100);
}
static BYTE8 waThread3[UserStackSize(128)];
static EvTimer evt;
static t_evhandler evhndl[1] = {
TimerHandler
static t_evhandler evhndl[] = {
TimerHandler,
InsertHandler,
RemoveHandler
};
static t_msg Thread3(void *arg) {
struct EventListener el;
struct EventListener el0, el1, el2;
evtInit(&evt, 500);
evtRegister(&evt, &el, 0);
evtStart(&evt);
mmcStartPolling();
evtRegister(&evt, &el0, 0);
chEvtRegister(&MMCInsertEventSource, &el1, 1);
chEvtRegister(&MMCRemoveEventSource, &el2, 2);
while (TRUE)
chEvtWait(ALL_EVENTS, evhndl);
return 0;

View File

@ -24,7 +24,10 @@
#include "mmcsd.h"
static EventSource MMCInsertEventSource;
EventSource MMCInsertEventSource, MMCRemoveEventSource;
static VirtualTimer vt;
static int cnt;
/*
* Subsystem initialization.
@ -32,6 +35,56 @@ static EventSource MMCInsertEventSource;
void InitMMC(void) {
chEvtInit(&MMCInsertEventSource);
chEvtInit(&MMCRemoveEventSource);
cnt = POLLING_INTERVAL;
}
void tmrfunc(void *par) {
if (cnt) {
if (!(IO1PIN & (1 << 25))) {
if (!--cnt)
chEvtSendI(&MMCInsertEventSource);
}
else
cnt = POLLING_INTERVAL;
}
else {
if (IO1PIN & (1 << 25)) {
cnt = POLLING_INTERVAL;
chEvtSendI(&MMCRemoveEventSource);
}
}
chVTSetI(&vt, 10, tmrfunc, NULL);
}
void mmcStartPolling(void) {
chSysLock();
if (!chVTIsArmedI(&vt)) {
chVTSetI(&vt, 10, tmrfunc, NULL);
cnt = POLLING_INTERVAL;
}
chSysUnlock();
}
void mmcStopPolling(void) {
chSysLock();
if (chVTIsArmedI(&vt)) {
chVTResetI(&vt);
cnt = POLLING_INTERVAL;
}
chSysUnlock();
}
BOOL mmcCardInserted (void) {
return cnt == 0;
}
static void sendhdr(BYTE8 cmd, ULONG32 arg) {

View File

@ -23,26 +23,31 @@
#define NICE_WAITING
/* Following times are 10mS units.*/
#define CMD0_RETRY 10
#define CMD1_RETRY 100
#define CMD0_RETRY 10
#define CMD1_RETRY 100
#define POLLING_INTERVAL 10
/* Byte transfer time units.*/
#define MMC_WAIT_DATA 10000
#define MMC_WAIT_DATA 10000
#define CMDGOIDLE 0
#define CMDINIT 1
#define CMDREADCSD 9
#define CMDREAD 17
#define CMDWRITE 24
#define CMDGOIDLE 0
#define CMDINIT 1
#define CMDREADCSD 9
#define CMDREAD 17
#define CMDWRITE 24
typedef struct {
ULONG32 csize;
ULONG32 rdblklen;
} MMCCSD;
extern EventSource MMCInsertEventSource, MMCRemoveEventSource;
void InitMMC(void);
BOOL mmcInit(void);
void mmcStartPolling(void);
void mmcStopPolling(void);
BYTE8 mmcSendCommand(BYTE8 cmd, ULONG32 arg);
BOOL mmcGetSize(MMCCSD *data);
BOOL mmcBlockRead(ULONG32 blknum, BYTE8 *buf);

View File

@ -42,7 +42,8 @@ AVR-AT90CANx-GCC - Port on AVR AT90CAN128, not complete yet.
- Added SSP (SPI1) and ext.interrupts definitions to the lpc214x.h file.
- Added SSP driver for the LPC2148.
- Added experimental MMC/SD block driver to the LPC2148 demo in order to
support file systems.
support file systems. The driver features also events generation on card
insert/remove, hot plugging supported.
- Added missing chThdSuspend() declararion in threads.h.
*** 0.3.5 ***