git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@81 35acf78f-673a-0410-8e92-d51de3d6d3f4
This commit is contained in:
parent
e7e0e2d2d3
commit
d0cc4f2406
|
@ -23,6 +23,7 @@
|
|||
#include "vic.h"
|
||||
#include "lpc214x_serial.h"
|
||||
#include "lpc214x_ssp.h"
|
||||
#include "mmcsd.h"
|
||||
|
||||
#include "buzzer.h"
|
||||
|
||||
|
@ -135,6 +136,7 @@ void hwinit(void) {
|
|||
*/
|
||||
InitSerial();
|
||||
InitSSP();
|
||||
InitMMC();
|
||||
InitBuzzer();
|
||||
}
|
||||
|
||||
|
|
|
@ -21,7 +21,8 @@
|
|||
|
||||
#include "lpc214x.h"
|
||||
#include "lpc214x_serial.h"
|
||||
#include "lpc214x_ssp.h"
|
||||
//#include "lpc214x_ssp.h"
|
||||
#include "mmcsd.h"
|
||||
#include "buzzer.h"
|
||||
#include "evtimer.h"
|
||||
|
||||
|
@ -56,7 +57,7 @@ static t_msg Thread2(void *arg) {
|
|||
}
|
||||
|
||||
static void TimerHandler(t_eventid id) {
|
||||
static BYTE8 sspbuf[16];
|
||||
// static BYTE8 sspbuf[16];
|
||||
t_msg TestThread(void *p);
|
||||
|
||||
if (!(IO0PIN & 0x00018000)) { // Both buttons
|
||||
|
@ -67,8 +68,11 @@ static void TimerHandler(t_eventid id) {
|
|||
if (!(IO0PIN & 0x00008000)) // Button 1
|
||||
PlaySound(1000, 100);
|
||||
if (!(IO0PIN & 0x00010000)) { // Button 2
|
||||
sspRW(sspbuf, (BYTE8 *)"Hello World!\r\n", 14);
|
||||
chFDDWrite(&COM1, sspbuf, 14);
|
||||
// sspRW(sspbuf, (BYTE8 *)"Hello World!\r\n", 14);
|
||||
// chFDDWrite(&COM1, sspbuf, 14);
|
||||
chFDDWrite(&COM1, (BYTE8 *)"Hello World!\r\n", 14);
|
||||
if (!mmcInit())
|
||||
PlaySound(2000, 500);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,7 +26,7 @@
|
|||
|
||||
static EventSource MMCInsertEventSource;
|
||||
|
||||
void MMCInit(void) {
|
||||
void InitMMC(void) {
|
||||
|
||||
chEvtInit(&MMCInsertEventSource);
|
||||
}
|
||||
|
@ -47,11 +47,11 @@ BOOL mmcInit(void) {
|
|||
sspRW(NULL, NULL, 16); /* 128 clock pulses without ~CS asserted. */
|
||||
int i = 0;
|
||||
while (TRUE) {
|
||||
chThdSleep(10);
|
||||
if (mmcSendCommand(0, 0) == 0x01)
|
||||
break;
|
||||
if (++i >= CMD0_RETRY)
|
||||
return TRUE;
|
||||
chThdSleep(10);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -59,15 +59,14 @@ BOOL mmcInit(void) {
|
|||
*/
|
||||
i = 0;
|
||||
while (TRUE) {
|
||||
BYTE8 b;
|
||||
chThdSleep(10);
|
||||
b = mmcSendCommand(0, 0);
|
||||
BYTE8 b = mmcSendCommand(1, 0);
|
||||
if (b == 0x00)
|
||||
break;
|
||||
if (b != 0x01)
|
||||
return TRUE;
|
||||
if (++i >= CMD1_RETRY)
|
||||
return TRUE;
|
||||
chThdSleep(10);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -77,21 +76,41 @@ BOOL mmcInit(void) {
|
|||
return FALSE;
|
||||
}
|
||||
|
||||
static void sendhdr(BYTE8 cmd, ULONG32 arg) {
|
||||
BYTE8 buf[8];
|
||||
|
||||
buf[0] = 0xFF;
|
||||
buf[1] = 0x40 | cmd;
|
||||
buf[2] = arg >> 24;
|
||||
buf[3] = arg >> 16;
|
||||
buf[4] = arg >> 8;
|
||||
buf[5] = arg;
|
||||
buf[6] = 0x95; /* Valid for CMD0 ingnored by other commands. */
|
||||
buf[7] = 0xFF;
|
||||
sspRW(NULL, buf, 8);
|
||||
}
|
||||
|
||||
static BYTE8 recvr1(void) {
|
||||
int i;
|
||||
BYTE8 r1[1];
|
||||
|
||||
for (i = 0; i < 8; i++) {
|
||||
sspRW(r1, NULL, 1);
|
||||
if (r1[0] != 0xFF)
|
||||
return r1[0];
|
||||
}
|
||||
return 0xFF;
|
||||
}
|
||||
|
||||
/*
|
||||
* Sends a simple command and returns a R1-type response.
|
||||
*/
|
||||
BYTE8 mmcSendCommand(BYTE8 cmd, ULONG32 arg) {
|
||||
BYTE8 buf[6];
|
||||
BYTE8 r1;
|
||||
|
||||
buf[0] = 0x40 | cmd;
|
||||
buf[1] = arg >> 24;
|
||||
buf[2] = arg >> 16;
|
||||
buf[3] = arg >> 8;
|
||||
buf[4] = arg;
|
||||
buf[5] = 0x95; /* Valid for CMD0 ingnored by other commands. */
|
||||
sspAcquireBus();
|
||||
sspRW(NULL, buf, 6);
|
||||
sspRW(buf, NULL, 1);
|
||||
sendhdr(cmd, arg);
|
||||
r1 = recvr1();
|
||||
sspReleaseBus();
|
||||
return buf[0];
|
||||
return r1;
|
||||
}
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
#define CMD0_RETRY 10
|
||||
#define CMD1_RETRY 100
|
||||
|
||||
void MMCInit(void);
|
||||
void InitMMC(void);
|
||||
|
||||
BOOL mmcInit(void);
|
||||
BYTE8 mmcSendCommand(BYTE8 cmd, ULONG32 arg);
|
||||
|
|
|
@ -32,15 +32,14 @@ void sspAcquireBus(void) {
|
|||
chSemWait(&me);
|
||||
#endif
|
||||
IO0CLR = 1 << 20;
|
||||
|
||||
}
|
||||
|
||||
void sspReleaseBus(void) {
|
||||
|
||||
IO0SET = 1 << 20;
|
||||
#ifdef SSP_USE_MUTEX
|
||||
chSemSignal(&me);
|
||||
#endif
|
||||
IO0SET = 1 << 20;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -103,7 +102,7 @@ void InitSSP(void) {
|
|||
PCONP = (PCONP & PCALL) | PCSPI1;
|
||||
|
||||
/* Clock = PCLK / 2 (fastest). */
|
||||
SetSSP(2, CR0_DSS8BIT | CR0_FRFSPI | CR0_CLOCKRATE(0), CR1_LBM);
|
||||
SetSSP(2, CR0_DSS8BIT | CR0_FRFSPI | CR0_CLOCKRATE(0), 0);
|
||||
|
||||
#ifdef SSP_USE_MUTEX
|
||||
chSemInit(&me, 1);
|
||||
|
|
Loading…
Reference in New Issue