From dfd631cb67bf200991186fb33f4b1d4ab708ca6e Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sun, 20 Dec 2009 14:07:05 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@1448 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- demos/ARM7-LPC214x-GCC/Makefile | 37 ++-- demos/ARM7-LPC214x-GCC/board.c | 90 ---------- demos/ARM7-LPC214x-GCC/board.h | 77 -------- demos/ARM7-LPC214x-GCC/buzzer.c | 92 ---------- demos/ARM7-LPC214x-GCC/buzzer.h | 35 ---- demos/ARM7-LPC214x-GCC/main.c | 85 +-------- demos/ARM7-LPC214x-GCC/mmcsd.c | 388 ---------------------------------------- demos/ARM7-LPC214x-GCC/mmcsd.h | 66 ------- 8 files changed, 28 insertions(+), 842 deletions(-) delete mode 100644 demos/ARM7-LPC214x-GCC/board.c delete mode 100644 demos/ARM7-LPC214x-GCC/board.h delete mode 100644 demos/ARM7-LPC214x-GCC/buzzer.c delete mode 100644 demos/ARM7-LPC214x-GCC/buzzer.h delete mode 100644 demos/ARM7-LPC214x-GCC/mmcsd.c delete mode 100644 demos/ARM7-LPC214x-GCC/mmcsd.h (limited to 'demos/ARM7-LPC214x-GCC') diff --git a/demos/ARM7-LPC214x-GCC/Makefile b/demos/ARM7-LPC214x-GCC/Makefile index 9d44185a4..a1056cbd7 100644 --- a/demos/ARM7-LPC214x-GCC/Makefile +++ b/demos/ARM7-LPC214x-GCC/Makefile @@ -44,22 +44,22 @@ LDSCRIPT = ch.ld # Imported source files CHIBIOS = ../.. -include ${CHIBIOS}/os/hal/hal.mk -include ${CHIBIOS}/os/hal/platforms/LPC214x/platform.mk -include ${CHIBIOS}/os/ports/GCC/ARM7/port.mk -include ${CHIBIOS}/os/kernel/kernel.mk -include ${CHIBIOS}/test/test.mk +include $(CHIBIOS)/boards/OLIMEX_LPC_P2148/board.mk +include $(CHIBIOS)/os/hal/platforms/LPC214x/platform.mk +include $(CHIBIOS)/os/hal/hal.mk +include $(CHIBIOS)/os/ports/GCC/ARM7/port.mk +include $(CHIBIOS)/os/kernel/kernel.mk +include $(CHIBIOS)/test/test.mk # C sources that can be compiled in ARM or THUMB mode depending on the global # setting. -CSRC = ${PORTSRC} \ - ${KERNSRC} \ - ${TESTSRC} \ - ${HALSRC} \ - ${PLATFORMSRC} \ - ${CHIBIOS}/os/hal/platforms/LPC214x/lpc214x_ssp.c \ - ${CHIBIOS}/os/various/evtimer.c \ - board.c buzzer.c mmcsd.c main.c +CSRC = $(PORTSRC) \ + $(KERNSRC) \ + $(TESTSRC) \ + $(HALSRC) \ + $(PLATFORMSRC) \ + $(BOARDSRC) \ + main.c # C++ sources that can be compiled in ARM or THUMB mode depending on the global # setting. @@ -87,11 +87,12 @@ TCPPSRC = # List ASM source files here ASMSRC = $(PORTASM) \ - ${CHIBIOS}/os/ports/GCC/ARM7/LPC214x/vectors.s + $(CHIBIOS)/os/ports/GCC/ARM7/LPC214x/vectors.s -INCDIR = $(PORTINC) $(KERNINC) $(TESTINC) $(HALINC) $(PLATFORMINC) \ - ${CHIBIOS}/os/various \ - ${CHIBIOS}/os/ports/GCC/ARM7/LPC214x +INCDIR = $(PORTINC) $(KERNINC) $(TESTINC) \ + $(HALINC) $(PLATFORMINC) $(BOARDINC) \ + $(CHIBIOS)/os/various \ + $(CHIBIOS)/os/ports/GCC/ARM7/LPC214x # # Project, sources and paths @@ -179,4 +180,4 @@ ULIBS = # End of user defines ############################################################################## -include ${CHIBIOS}/os/ports/GCC/ARM/rules.mk +include $(CHIBIOS)/os/ports/GCC/ARM/rules.mk diff --git a/demos/ARM7-LPC214x-GCC/board.c b/demos/ARM7-LPC214x-GCC/board.c deleted file mode 100644 index f81d2329a..000000000 --- a/demos/ARM7-LPC214x-GCC/board.c +++ /dev/null @@ -1,90 +0,0 @@ -/* - ChibiOS/RT - Copyright (C) 2006-2007 Giovanni Di Sirio. - - This file is part of ChibiOS/RT. - - ChibiOS/RT 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 3 of the License, or - (at your option) any later version. - - ChibiOS/RT 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, see . -*/ - -#include "ch.h" -#include "hal.h" - -#include "lpc214x_ssp.h" -#include "mmcsd.h" -#include "buzzer.h" - -#define VAL_TC0_PRESCALER 0 - -/* - * Timer 0 IRQ handling here. - */ -static CH_IRQ_HANDLER(T0IrqHandler) { - - CH_IRQ_PROLOGUE(); - T0IR = 1; /* Clear interrupt on match MR0. */ - - chSysLockFromIsr(); - chSysTimerHandlerI(); - chSysUnlockFromIsr(); - - VICVectAddr = 0; - CH_IRQ_EPILOGUE(); -} - -/* - * Early initialization code. - * This initialization is performed just after reset before BSS and DATA - * segments initialization. - */ -void hwinit0(void) { - - lpc214x_clock_init(); -} - -/* - * Late initialization code. - * This initialization is performed after BSS and DATA segments initialization - * and before invoking the main() function. - */ -void hwinit1(void) { - - /* - * HAL initialization. - */ - halInit(); - - /* - * System Timer initialization, 1ms intervals. - */ - SetVICVector(T0IrqHandler, 0, SOURCE_Timer0); - VICIntEnable = INTMASK(SOURCE_Timer0); - TC *timer = T0Base; - timer->TC_PR = VAL_TC0_PRESCALER; - timer->TC_MR0 = (PCLK / CH_FREQUENCY) / (VAL_TC0_PRESCALER + 1); - timer->TC_MCR = 3; /* Interrupt and clear TC on match MR0. */ - timer->TC_TCR = 2; /* Reset counter and prescaler. */ - timer->TC_TCR = 1; /* Timer enabled. */ - - /* - * Other subsystems. - */ - ssp_init(); - InitMMC(); - InitBuzzer(); - - /* - * ChibiOS/RT initialization. - */ - chSysInit(); -} diff --git a/demos/ARM7-LPC214x-GCC/board.h b/demos/ARM7-LPC214x-GCC/board.h deleted file mode 100644 index b66ce235d..000000000 --- a/demos/ARM7-LPC214x-GCC/board.h +++ /dev/null @@ -1,77 +0,0 @@ -/* - ChibiOS/RT - Copyright (C) 2006-2007 Giovanni Di Sirio. - - This file is part of ChibiOS/RT. - - ChibiOS/RT 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 3 of the License, or - (at your option) any later version. - - ChibiOS/RT 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, see . -*/ - -#ifndef _BOARD_H_ -#define _BOARD_H_ - -#define BOARD_OLIMEX_LCP_P2148 - -/* - * The following values are implementation dependent. You may change them in - * order to match your HW. - */ -#define FOSC 12000000 -#define CCLK 48000000 -#define PCLK 12000000 - -/* - * Pins configuration for Olimex LPC-P2148. - * - * PINSEL0 - * P0 P0 P0 P0 P0 P0 RXD TXD SSE MOS MIS SCK SDA SCL RXD TXD - * 15 14 13 12 11 10 1 1 L0 I0 O0 0 0 0 0 0 - * 00 00 00 00 00 00 01 01 01 01 01 01 01 01 01 01 - * IN IN OUT OUT OUT OUT -- -- -- -- -- -- -- -- -- -- - * 0 0 1 1 1 1 0 0 0 0 0 0 0 0 0 0 - * - * PINSEL1 - * P0 AD P0 P0 -- -- AO -- VB P0 P0 P0 MOS MIS SCK P0 - * 31 03 29 28 -- -- UT -- US 22 21 20 I1 O1 1 16 - * 00 01 00 00 00 00 10 00 01 00 00 00 10 10 10 00 - * OUT -- OUT OUT -- -- -- -- -- OUT OUT OUT -- -- -- IN - * 1 0 1 1 0 0 0 0 0 1 1 1 0 0 0 0 - * - * PINSEL2 - * -- -- -- -- -- -- -- -- -- -- -- -- -- -- GP DBG -- - * -- -- -- -- -- -- -- -- -- -- -- -- -- -- IO -- - * 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0 1 00 - * -- -- -- -- -- -- -- -- -- -- -- -- -- -- IN -- -- - */ -#define VAL_PINSEL0 0x00055555 -#define VAL_PINSEL1 0x100840A8 -#define VAL_PINSEL2 0x00000004 -#define VAL_FIO0DIR 0xB0703C00 -#define VAL_FIO1DIR 0x00000000 -#define VAL_FIO0PIN 0xFFFFFFFF -#define VAL_FIO1PIN 0xFFFFFFFF - -#define PA_LED1 10 -#define PA_LED2 11 -#define PA_BUZZ1 12 -#define PA_BUZZ2 13 -#define PA_BSL 14 -#define PA_BUTTON1 15 -#define PA_BUTTON2 16 -#define PA_SSEL1 20 -#define PA_LEDUSB 31 - -#define PB_WP1 24 -#define PB_CP1 25 - -#endif /* _BOARD_H_ */ diff --git a/demos/ARM7-LPC214x-GCC/buzzer.c b/demos/ARM7-LPC214x-GCC/buzzer.c deleted file mode 100644 index 2e7c0bd98..000000000 --- a/demos/ARM7-LPC214x-GCC/buzzer.c +++ /dev/null @@ -1,92 +0,0 @@ -/* - ChibiOS/RT - Copyright (C) 2006-2007 Giovanni Di Sirio. - - This file is part of ChibiOS/RT. - - ChibiOS/RT 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 3 of the License, or - (at your option) any later version. - - ChibiOS/RT 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, see . -*/ - -/* - * Buzzer driver for Olimex LPC-P2148. - * Uses the timer 1 for wave generation and a Virtual Timer for the sound - * duration. - * The driver also generates an event when the sound is done and the buzzer - * goes silent. - */ - -#include "ch.h" -#include "hal.h" - -#include "buzzer.h" - -EventSource BuzzerSilentEventSource; - -#define StartCounter(t) ((t)->TC_EMR = 0xF1, (t)->TC_TCR = 1) -#define StopCounter(t) ((t)->TC_EMR = 0, (t)->TC_TCR = 2) - -void InitBuzzer(void) { - - chEvtInit(&BuzzerSilentEventSource); - - /* - * Switches P0.12 and P0.13 to MAT1.0 and MAT1.1 functions. - * Enables Timer1 clock. - */ - PINSEL0 &= 0xF0FFFFFF; - PINSEL0 |= 0x0A000000; - PCONP = (PCONP & PCALL) | PCTIM1; - - /* - * Timer setup. - */ - TC *tc = T1Base; - StopCounter(tc); - tc->TC_CTCR = 0; // Clock source is PCLK. - tc->TC_PR = 0; // Prescaler disabled. - tc->TC_MCR = 2; // Clear TC on match MR0. -} - -static void stop(void *p) { - - StopCounter((TC *)p); - chEvtBroadcastI(&BuzzerSilentEventSource); -} - -void PlaySound(int freq, systime_t duration) { - static VirtualTimer bvt; - TC *tc = T1Base; - - chSysLock(); - - if (chVTIsArmedI(&bvt)) { // If a sound is already being played - chVTResetI(&bvt); // then aborts it. - StopCounter(tc); - } - - tc->TC_MR0 = tc->TC_MR1 = (PCLK / (freq * 2)); - StartCounter(tc); - chVTSetI(&bvt, duration, stop, tc); - - chSysUnlock(); -} - -void PlaySoundWait(int freq, systime_t duration) { - TC *tc = T1Base; - - StopCounter(tc); - tc->TC_MR0 = tc->TC_MR1 = (PCLK / (freq * 2)); - StartCounter(tc); - chThdSleep(duration); - StopCounter(tc); -} diff --git a/demos/ARM7-LPC214x-GCC/buzzer.h b/demos/ARM7-LPC214x-GCC/buzzer.h deleted file mode 100644 index 734cb1a44..000000000 --- a/demos/ARM7-LPC214x-GCC/buzzer.h +++ /dev/null @@ -1,35 +0,0 @@ -/* - ChibiOS/RT - Copyright (C) 2006-2007 Giovanni Di Sirio. - - This file is part of ChibiOS/RT. - - ChibiOS/RT 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 3 of the License, or - (at your option) any later version. - - ChibiOS/RT 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, see . -*/ - -#ifndef _BUZZER_H_ -#define _BUZZER_H_ - -#ifdef __cplusplus -extern "C" { -#endif - void InitBuzzer(void); - void PlaySound(int freq, systime_t duration); - void PlaySoundWait(int freq, systime_t duration); -#ifdef __cplusplus -} -#endif - -extern EventSource BuzzerSilentEventSource; - -#endif /* _BUZZER_H_ */ diff --git a/demos/ARM7-LPC214x-GCC/main.c b/demos/ARM7-LPC214x-GCC/main.c index d0a69b3d7..00aca0ec7 100644 --- a/demos/ARM7-LPC214x-GCC/main.c +++ b/demos/ARM7-LPC214x-GCC/main.c @@ -20,10 +20,6 @@ #include "ch.h" #include "hal.h" #include "test.h" -#include "evtimer.h" - -#include "mmcsd.h" -#include "buzzer.h" #define BOTH_BUTTONS (PAL_PORT_BIT(PA_BUTTON1) | PAL_PORT_BIT(PA_BUTTON2)) @@ -63,73 +59,11 @@ static msg_t Thread2(void *arg) { return 0; } -static WORKING_AREA(waTestThread, 128); - -/* - * Executed as event handler at 500mS intervals. - */ -static void TimerHandler(eventid_t id) { - - (void)id; - if (!(palReadPort(IOPORT1) & BOTH_BUTTONS)) { - Thread *tp = chThdCreateStatic(waTestThread, sizeof(waTestThread), - NORMALPRIO, TestThread, &SD1); - chThdWait(tp); - PlaySound(500, MS2ST(100)); - } - else { - if (!palReadPad(IOPORT1, PA_BUTTON1)) - PlaySound(1000, MS2ST(100)); - if (!palReadPad(IOPORT1, PA_BUTTON2)) { - sdWrite(&SD1, (uint8_t *)"Hello World!\r\n", 14); - PlaySound(2000, MS2ST(100)); - } - } -} - -/* - * Plays sounds when a MMC/SD card is inserted, then initializes the MMC - * driver and reads a sector. - */ -static void InsertHandler(eventid_t id) { - static uint8_t rwbuf[512]; - MMCCSD data; - - (void)id; - PlaySoundWait(1000, MS2ST(100)); - PlaySoundWait(2000, MS2ST(100)); - if (mmcInit()) - return; - /* Card ready, do stuff.*/ - if (mmcGetSize(&data)) - return; - if (mmcRead(rwbuf, 0)) - return; - PlaySound(440, MS2ST(200)); -} - -/* - * Plays sounds when a MMC/SD card is removed. - */ -static void RemoveHandler(eventid_t id) { - - (void)id; - PlaySoundWait(2000, MS2ST(100)); - PlaySoundWait(1000, MS2ST(100)); -} - /* * Entry point, note, the main() function is already a thread in the system * on entry. */ int main(int argc, char **argv) { - static const evhandler_t evhndl[] = { - TimerHandler, - InsertHandler, - RemoveHandler - }; - static EvTimer evt; - struct EventListener el0, el1, el2; (void)argc; (void)argv; @@ -149,16 +83,15 @@ int main(int argc, char **argv) { } /* - * Normal main() activity, in this demo it serves events generated by - * various sources. + * Normal main() thread activity, in this demo it does nothing except + * sleeping in a loop and check the buttons state. */ - evtInit(&evt, MS2ST(500)); /* Initializes an event timer object. */ - evtStart(&evt); /* Starts the event timer. */ - chEvtRegister(&evt.et_es, &el0, 0); /* Registers on the timer event source. */ - mmcStartPolling(); /* Starts the MMC connector polling. */ - chEvtRegister(&MMCInsertEventSource, &el1, 1); - chEvtRegister(&MMCRemoveEventSource, &el2, 2); - while (TRUE) /* Just serve events. */ - chEvtDispatch(evhndl, chEvtWaitOne(ALL_EVENTS)); + while (TRUE) { + if (!palReadPad(IOPORT1, PA_BUTTON1)) + sdWrite(&SD1, (uint8_t *)"Hello World!\r\n", 14); + if (!palReadPad(IOPORT1, PA_BUTTON2)) + TestThread(&SD1); + chThdSleepMilliseconds(500); + } return 0; } diff --git a/demos/ARM7-LPC214x-GCC/mmcsd.c b/demos/ARM7-LPC214x-GCC/mmcsd.c deleted file mode 100644 index 220d9c88a..000000000 --- a/demos/ARM7-LPC214x-GCC/mmcsd.c +++ /dev/null @@ -1,388 +0,0 @@ -/* - ChibiOS/RT - Copyright (C) 2006-2007 Giovanni Di Sirio. - - This file is part of ChibiOS/RT. - - ChibiOS/RT 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 3 of the License, or - (at your option) any later version. - - ChibiOS/RT 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, see . -*/ - -#include "ch.h" -#include "hal.h" - -#include "lpc214x_ssp.h" -#include "mmcsd.h" - -EventSource MMCInsertEventSource, MMCRemoveEventSource; - -static VirtualTimer vt; -static int cnt; - -/* - * Subsystem initialization. - */ -void InitMMC(void) { - - chEvtInit(&MMCInsertEventSource); - chEvtInit(&MMCRemoveEventSource); - cnt = POLLING_INTERVAL; -} - -void tmrfunc(void *par) { - - (void)par; - if (cnt) { - if (!palReadPad(IOPORT2, PB_CP1)) { - if (!--cnt) - chEvtBroadcastI(&MMCInsertEventSource); - } - else - cnt = POLLING_INTERVAL; - } - else { - if (palReadPad(IOPORT2, PB_CP1)) { - cnt = POLLING_INTERVAL; - chEvtBroadcastI(&MMCRemoveEventSource); - } - } - chVTSetI(&vt, 10, tmrfunc, NULL); -} - -/* - * Starts the card polling service. - */ -void mmcStartPolling(void) { - - chSysLock(); - - if (!chVTIsArmedI(&vt)) { - chVTSetI(&vt, 10, tmrfunc, NULL); - cnt = POLLING_INTERVAL; - } - - chSysUnlock(); -} - -/* - * Stops the card polling service. - */ -void mmcStopPolling(void) { - - chSysLock(); - - if (chVTIsArmedI(&vt)) { - chVTResetI(&vt); - cnt = POLLING_INTERVAL; - } - - chSysUnlock(); -} - -/* - * Returns TRUE if the card is safely inserted in the reader. - */ -bool_t mmcCardInserted (void) { - - return cnt == 0; -} - -static void wait(void) { - int i; - uint8_t buf[4]; - - for (i = 0; i < 16; i++) { - sspRW(buf, NULL, 1); - if (buf[0] == 0xFF) - break; - } - /* Looks like it is a loooong wait.*/ - while (TRUE) { - sspRW(buf, NULL, 1); - if (buf[0] == 0xFF) - break; -#ifdef NICE_WAITING - chThdSleep(1); /* Trying to be nice with the other threads.*/ -#endif - } -} - -static void sendhdr(uint8_t cmd, uint32_t arg) { - uint8_t buf[6]; - - /* - * Wait for the bus to become idle if a write operation was in progress. - */ - wait(); - - 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. */ - sspRW(NULL, buf, 6); -} - -static uint8_t recvr1(void) { - int i; - uint8_t r1[1]; - - for (i = 0; i < 9; i++) { - sspRW(r1, NULL, 1); - if (r1[0] != 0xFF) - return r1[0]; - } - return 0xFF; /* Timeout.*/ -} - -static bool_t getdata(uint8_t *buf, uint32_t n) { - int i; - - for (i = 0; i < MMC_WAIT_DATA; i++) { - sspRW(buf, NULL, 1); - if (buf[0] == 0xFE) { - sspRW(buf, NULL, n); - sspRW(NULL, NULL, 2); /* CRC ignored.*/ - return FALSE; - } - } - return TRUE; /* Timeout.*/ -} - -/* - * Initializes a card after the power up by selecting the SPI mode. - */ -bool_t mmcInit(void) { - - /* - * Starting initialization with slow clock mode. - */ - ssp_setup(254, CR0_DSS8BIT | CR0_FRFSPI | CR0_CLOCKRATE(0), 0); - - /* - * SPI mode selection. - */ - sspRW(NULL, NULL, 16); /* 128 clock pulses without ~CS asserted. */ - int i = 0; - while (TRUE) { - if (mmcSendCommand(CMDGOIDLE, 0) == 0x01) - break; - if (++i >= CMD0_RETRY) - return TRUE; - chThdSleep(10); - } - - /* - * Initialization. - */ - i = 0; - while (TRUE) { - uint8_t b = mmcSendCommand(CMDINIT, 0); - if (b == 0x00) - break; - if (b != 0x01) - return TRUE; - if (++i >= CMD1_RETRY) - return TRUE; - chThdSleep(10); - } - - /* - * Full speed. - */ - ssp_setup(2, CR0_DSS8BIT | CR0_FRFSPI | CR0_CLOCKRATE(0), 0); - return FALSE; -} - -/* - * Sends a simple command and returns a R1-type response. - */ -uint8_t mmcSendCommand(uint8_t cmd, uint32_t arg) { - uint8_t r1; - - sspAcquireBus(); - sendhdr(cmd, arg); - r1 = recvr1(); - sspReleaseBus(); - return r1; -} - -/* - * Reads the card info record. - * @param data the pointer to a \p MMCCSD structure - * @return \p TRUE if an error happened - */ -bool_t mmcGetSize(MMCCSD *data) { - uint8_t buf[16]; - - sspAcquireBus(); - sendhdr(CMDREADCSD, 0); - if (recvr1() != 0x00) { - sspReleaseBus(); - return TRUE; - } - if (getdata(buf, 16)) { - sspReleaseBus(); - return TRUE; - } - sspReleaseBus(); - - /* csize * multiplier */ - data->csize = (((buf[6] & 3) << 10) | (buf[7] << 2) | (buf[8] >> 6)) * - (1 << (2 + (((buf[9] & 3) << 1) | (buf[10] >> 7)))); - data->rdblklen = 1 << (buf[5] & 15); - return FALSE; -} - -/* - * Reads a block. - * @param blknum the block number - * @param buf the pointer to the read buffer - * @return \p TRUE if an error happened - */ -bool_t mmcRead(uint8_t *buf, uint32_t blknum) { - - sspAcquireBus(); - sendhdr(CMDREAD, blknum << 9); - if (recvr1() != 0x00) { - sspReleaseBus(); - return TRUE; - } - if (getdata(buf, 512)) { - sspReleaseBus(); - return TRUE; - } - sspReleaseBus(); - return FALSE; -} - -/* - * Reads multiple blocks. - * @param blknum the initial block - * @param n the number of blocks - * @param buf the pointer to the read buffer - * @return \p TRUE if an error happened - */ -bool_t mmcReadMultiple(uint8_t *buf, uint32_t blknum, uint32_t n) { - static const uint8_t stopcmd[] = {0x40 | CMDSTOP, 0, 0, 0, 0, 1, 0xFF}; - - sspAcquireBus(); - sendhdr(CMDREADMULTIPLE, blknum << 9); - if (recvr1() != 0x00) { - sspReleaseBus(); - return TRUE; - } - while (n) { - if (getdata(buf, 512)) { - sspReleaseBus(); - return TRUE; - } - buf += 512; - n--; - } - sspRW(NULL, (uint8_t *)stopcmd, sizeof(stopcmd)); - if (recvr1() != 0x00) { - sspReleaseBus(); - return TRUE; - } - sspReleaseBus(); - return FALSE; -} - -/* - * Writes a block. - * @param blknum the block number - * @param buf the pointer to the write buffer - * @return \p TRUE if an error happened - * @note The function DOES NOT wait for the SPI bus to become free after - * sending the data, the bus check is done before sending commands to - * the card, this allows to not make useless busy waiting. The invoking - * thread can do other things while the data is being written. - */ -bool_t mmcWrite(uint8_t *buf, uint32_t blknum) { - static const uint8_t start[] = {0xFF, 0xFE}; - uint8_t b[4]; - - sspAcquireBus(); - sendhdr(CMDWRITE, blknum << 9); - if (recvr1() != 0x00) { - sspReleaseBus(); - return TRUE; - } - sspRW(NULL, (uint8_t *)start, 2); /* Data prologue.*/ - sspRW(NULL, buf, 512); /* Data.*/ - sspRW(NULL, NULL, 2); /* CRC ignored in this version.*/ - sspRW(b, NULL, 1); - sspReleaseBus(); - if ((b[0] & 0x1F) != 0x05) - return TRUE; - return FALSE; -} - -/* - * Writes multiple blocks. - * @param blknum the initial block - * @param n the number of blocks - * @param buf the pointer to the write buffer - * @return \p TRUE if an error happened - * @note The function DOES NOT wait for the SPI bus to become free after - * sending the data, the bus check is done before sending commands to - * the card, this allows to not make useless busy waiting. The invoking - * thread can do other things while the data is being written. - */ -bool_t mmcWriteMultiple(uint8_t *buf, uint32_t blknum, uint32_t n) { - static const uint8_t start[] = {0xFF, 0xFC}, - stop[] = {0xFD, 0xFF}; - uint8_t b[4]; - - sspAcquireBus(); - sendhdr(CMDWRITEMULTIPLE, blknum << 9); - if (recvr1() != 0x00) { - sspReleaseBus(); - return TRUE; - } - while (n) { - sspRW(NULL, (uint8_t *)start, sizeof(start)); /* Data prologue.*/ - sspRW(NULL, buf, 512); /* Data.*/ - sspRW(NULL, NULL, 2); /* CRC ignored in this version.*/ - sspRW(b, NULL, 1); - if ((b[0] & 0x1F) != 0x05) { - sspReleaseBus(); - return TRUE; - } - wait(); - buf += 512; - n--; - } - sspRW(NULL, (uint8_t *)stop, sizeof(stop)); /* Stops the transfer.*/ - sspReleaseBus(); - return FALSE; -} - -/* - * Makes sure that pending operations are completed before returning. - */ -void mmcSynch(void) { - uint8_t buf[4]; - - sspAcquireBus(); - while (TRUE) { - sspRW(buf, NULL, 1); - if (buf[0] == 0xFF) - break; -#ifdef NICE_WAITING - chThdSleep(1); /* Trying to be nice with the other threads.*/ -#endif - } - sspReleaseBus(); -} diff --git a/demos/ARM7-LPC214x-GCC/mmcsd.h b/demos/ARM7-LPC214x-GCC/mmcsd.h deleted file mode 100644 index d7ab4b348..000000000 --- a/demos/ARM7-LPC214x-GCC/mmcsd.h +++ /dev/null @@ -1,66 +0,0 @@ -/* - ChibiOS/RT - Copyright (C) 2006-2007 Giovanni Di Sirio. - - This file is part of ChibiOS/RT. - - ChibiOS/RT 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 3 of the License, or - (at your option) any later version. - - ChibiOS/RT 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, see . -*/ - -#ifndef _MMCSD_H_ -#define _MMCSD_H_ - -#define NICE_WAITING - -#define CMD0_RETRY 10 -#define CMD1_RETRY 100 -#define POLLING_INTERVAL 10 -#define MMC_WAIT_DATA 10000 - -#define CMDGOIDLE 0 -#define CMDINIT 1 -#define CMDREADCSD 9 -#define CMDSTOP 12 -#define CMDREAD 17 -#define CMDREADMULTIPLE 18 -#define CMDWRITE 24 -#define CMDWRITEMULTIPLE 25 - -typedef struct { - uint32_t csize; - uint32_t rdblklen; -} MMCCSD; - -extern EventSource MMCInsertEventSource, MMCRemoveEventSource; - -#ifdef __cplusplus -} -#endif - void InitMMC(void); - - bool_t mmcInit(void); - void mmcStartPolling(void); - void mmcStopPolling(void); - bool_t mmcCardInserted (void); - uint8_t mmcSendCommand(uint8_t cmd, uint32_t arg); - bool_t mmcGetSize(MMCCSD *data); - bool_t mmcRead(uint8_t *buf, uint32_t blknum); - bool_t mmcReadMultiple(uint8_t *buf, uint32_t blknum, uint32_t n); - bool_t mmcWrite(uint8_t *buf, uint32_t blknum); - bool_t mmcWriteMultiple(uint8_t *buf, uint32_t blknum, uint32_t n); - void mmcSynch(void); -#ifdef __cplusplus -} -#endif - -#endif /* _MMCSD_H_*/ -- cgit v1.2.3