+++ /dev/null
-/* Based on MMCv3/SDv1/SDv2 (in SPI mode) control module (C)ChaN, 2009 \r
-Modifications (C) 2010 Real Time Engineers ltd. */\r
-\r
-#include "FreeRTOS.h"\r
-#include "diskio.h"\r
-\r
-void disk_init_spi( void );\r
-\r
-/* Definitions for MMC/SDC command */\r
-#define CMD0 ( 0x40 + 0 ) /* GO_IDLE_STATE */\r
-#define CMD1 ( 0x40 + 1 ) /* SEND_OP_COND (MMC) */\r
-#define ACMD41 ( 0xC0 + 41 ) /* SEND_OP_COND (SDC) */\r
-#define CMD8 ( 0x40 + 8 ) /* SEND_IF_COND */\r
-#define CMD9 ( 0x40 + 9 ) /* SEND_CSD */\r
-#define CMD10 ( 0x40 + 10 ) /* SEND_CID */\r
-#define CMD12 ( 0x40 + 12 ) /* STOP_TRANSMISSION */\r
-#define ACMD13 ( 0xC0 + 13 ) /* SD_STATUS (SDC) */\r
-#define CMD16 ( 0x40 + 16 ) /* SET_BLOCKLEN */\r
-#define CMD17 ( 0x40 + 17 ) /* READ_SINGLE_BLOCK */\r
-#define CMD18 ( 0x40 + 18 ) /* READ_MULTIPLE_BLOCK */\r
-#define CMD23 ( 0x40 + 23 ) /* SET_BLOCK_COUNT (MMC) */\r
-#define ACMD23 ( 0xC0 + 23 ) /* SET_WR_BLK_ERASE_COUNT (SDC) */\r
-#define CMD24 ( 0x40 + 24 ) /* WRITE_BLOCK */\r
-#define CMD25 ( 0x40 + 25 ) /* WRITE_MULTIPLE_BLOCK */\r
-#define CMD55 ( 0x40 + 55 ) /* APP_CMD */\r
-#define CMD58 ( 0x40 + 58 ) /* READ_OCR */\r
-\r
-/* Port Controls (Platform dependent) */\r
-#define CS_LOW() GPIO0->FIOCLR = ( 1 << 16 ) /* MMC CS = L */\r
-#define CS_HIGH() GPIO0->FIOSET = ( 1 << 16 ) /* MMC CS = H */\r
-\r
-#define SOCKWP ( 0 ) /* Write protect switch. */\r
-#define SOCKINS ( 1 << 29 ) /* Card detect switch. */\r
-#define SOCKPORT ( GPIO4->FIOPIN )\r
-#define FCLK_SLOW() /* Set slow clock (100k-400k) */\r
-#define FCLK_FAST() /* Set fast clock (depends on the CSD) */\r
-\r
-#define xmit_spi( dat ) xchg_spi( dat )\r
-#define rcvr_spi() xchg_spi( 0xFF )\r
-#define rcvr_spi_m( p ) \\r
- SPI->SPDR = 0xFF; \\r
- while( !( SPI->SPSR & ( 1 << 7 ) ) ); /* Check SPIF bit. */ \\r
- *( p ) = ( BYTE ) SPI->SPDR;\r
-\r
-/*-------------------------------------------------------------------------- */\r
-\r
-static volatile DSTATUS Stat = STA_NOINIT; /* Disk status */\r
-static volatile UINT Timer1, Timer2; /* 1000Hz decrement timer */\r
-static UINT CardType;\r
-\r
-static BYTE xchg_spi( BYTE dat )\r
-{\r
- SPI->SPDR = dat;\r
- while( !( SPI->SPSR & ( 1 << 7 ) ) ); /* Check SPIF bit. */\r
- return( BYTE ) SPI->SPDR;\r
-}\r
-\r
-/*-----------------------------------------------------------------------*/\r
-\r
-/* Wait for card ready */\r
-\r
-/*-----------------------------------------------------------------------*/\r
-static BYTE wait_ready( void )\r
-{\r
- BYTE res;\r
-\r
- Timer2 = 500; /* Wait for ready in timeout of 500ms */\r
- rcvr_spi();\r
- do\r
- {\r
- res = rcvr_spi();\r
- } while( (res != 0xFF) && Timer2 );\r
-\r
- return res;\r
-}\r
-\r
-/*-----------------------------------------------------------------------*/\r
-\r
-/* Deselect the card and release SPI bus */\r
-\r
-/*-----------------------------------------------------------------------*/\r
-static void deselect( void )\r
-{\r
- CS_HIGH();\r
- rcvr_spi();\r
-}\r
-\r
-/*-----------------------------------------------------------------------*/\r
-\r
-/* Select the card and wait ready */\r
-\r
-/*-----------------------------------------------------------------------*/\r
-static BOOL select( void ) /* TRUE:Successful, FALSE:Timeout */\r
-{\r
- CS_LOW();\r
- if( wait_ready() != 0xFF )\r
- {\r
- deselect();\r
- return FALSE;\r
- }\r
-\r
- return TRUE;\r
-}\r
-\r
-/*-----------------------------------------------------------------------*/\r
-\r
-/* Power Control (Platform dependent) */\r
-\r
-/*-----------------------------------------------------------------------*/\r
-\r
-/* When the target system does not support socket power control, there */\r
-\r
-/* is nothing to do in these functions and chk_power always returns 1. */\r
-static void power_on( void )\r
-{\r
-#if 0\r
- /* Enable SPI1 */\r
- SPI1CON1 = 0x013B;\r
- SPI1CON2 = 0x0000;\r
- _SPIEN = 1;\r
-#endif\r
-}\r
-\r
-static void power_off( void )\r
-{\r
-#if 0\r
- select(); /* Wait for card ready */\r
- deselect();\r
-\r
- _SPIEN = 0; /* Disable SPI1 */\r
-\r
- Stat |= STA_NOINIT; /* Set STA_NOINIT */\r
-#endif\r
-}\r
-\r
-/*-----------------------------------------------------------------------*/\r
-\r
-/* Receive a data packet from MMC */\r
-\r
-/*-----------------------------------------------------------------------*/\r
-static BOOL rcvr_datablock( BYTE *buff, /* Data buffer to store received data */ UINT btr /* Byte count (must be multiple of 4) */ )\r
-{\r
- BYTE token;\r
-\r
- Timer1 = 100;\r
- do\r
- { /* Wait for data packet in timeout of 100ms */\r
- token = rcvr_spi();\r
- } while( (token == 0xFF) && Timer1 );\r
-\r
- if( token != 0xFE )\r
- {\r
- return FALSE; /* If not valid data token, retutn with error */\r
- }\r
-\r
- do\r
- { /* Receive the data block into buffer */\r
- rcvr_spi_m( buff++ );\r
- rcvr_spi_m( buff++ );\r
- rcvr_spi_m( buff++ );\r
- rcvr_spi_m( buff++ );\r
- } while( btr -= 4 );\r
- rcvr_spi(); /* Discard CRC */\r
- rcvr_spi();\r
-\r
- return TRUE; /* Return with success */\r
-}\r
-\r
-/*-----------------------------------------------------------------------*/\r
-\r
-/* Send a data packet to MMC */\r
-\r
-/*-----------------------------------------------------------------------*/\r
-#if _READONLY == 0\r
-static BOOL xmit_datablock( const BYTE *buff, /* 512 byte data block to be transmitted */ BYTE token /* Data/Stop token */ )\r
-{\r
- BYTE resp;\r
- UINT bc = 512;\r
-\r
- if( wait_ready() != 0xFF )\r
- {\r
- return FALSE;\r
- }\r
-\r
- xmit_spi( token ); /* Xmit data token */\r
- if( token != 0xFD )\r
- { /* Is data token */\r
- do\r
- { /* Xmit the 512 byte data block to MMC */\r
- xmit_spi( *buff++ );\r
- xmit_spi( *buff++ );\r
- } while( bc -= 2 );\r
- xmit_spi( 0xFF ); /* CRC (Dummy) */\r
- xmit_spi( 0xFF );\r
- resp = rcvr_spi(); /* Receive data response */\r
- if( (resp & 0x1F) != 0x05 )\r
- { /* If not accepted, return with error */\r
- return FALSE;\r
- }\r
- }\r
-\r
- return TRUE;\r
-}\r
-\r
-#endif /* _READONLY */\r
-\r
-/*-----------------------------------------------------------------------*/\r
-\r
-/* Send a command packet to MMC */\r
-\r
-/*-----------------------------------------------------------------------*/\r
-static BYTE send_cmd( BYTE cmd, /* Command byte */ DWORD arg /* Argument */ )\r
-{\r
- BYTE n, res;\r
-\r
- if( cmd & 0x80 )\r
- { /* ACMD<n> is the command sequense of CMD55-CMD<n> */\r
- cmd &= 0x7F;\r
- res = send_cmd( CMD55, 0 );\r
- if( res > 1 )\r
- {\r
- return res;\r
- }\r
- }\r
-\r
- /* Select the card and wait for ready */\r
- deselect();\r
- if( !select() )\r
- {\r
- return 0xFF;\r
- }\r
-\r
- /* Send command packet */\r
- xmit_spi( cmd ); /* Start + Command index */\r
- xmit_spi( (BYTE) (arg >> 24) ); /* Argument[31..24] */\r
- xmit_spi( (BYTE) (arg >> 16) ); /* Argument[23..16] */\r
- xmit_spi( (BYTE) (arg >> 8) ); /* Argument[15..8] */\r
- xmit_spi( (BYTE) arg ); /* Argument[7..0] */\r
- n = 0x01; /* Dummy CRC + Stop */\r
- if( cmd == CMD0 )\r
- {\r
- n = 0x95; /* Valid CRC for CMD0(0) */\r
- }\r
-\r
- if( cmd == CMD8 )\r
- {\r
- n = 0x87; /* Valid CRC for CMD8(0x1AA) */\r
- }\r
-\r
- xmit_spi( n );\r
-\r
- /* Receive command response */\r
- if( cmd == CMD12 )\r
- {\r
- rcvr_spi(); /* Skip a stuff byte when stop reading */\r
- }\r
-\r
- n = 10; /* Wait for a valid response in timeout of 10 attempts */\r
- do\r
- {\r
- res = rcvr_spi();\r
- } while( (res & 0x80) && --n );\r
-\r
- return res; /* Return with the response value */\r
-}\r
-\r
-/*--------------------------------------------------------------------------\r
-\r
- Public Functions\r
-\r
----------------------------------------------------------------------------*/\r
-\r
-/*-----------------------------------------------------------------------*/\r
-\r
-/* Initialize Disk Drive */\r
-\r
-/*-----------------------------------------------------------------------*/\r
-DSTATUS disk_initialize( BYTE drv /* Physical drive nmuber (0) */ )\r
-{\r
- BYTE n, cmd, ty, ocr[4];\r
-\r
- if( drv )\r
- {\r
- return STA_NOINIT; /* Supports only single drive */\r
- }\r
-\r
- if( Stat & STA_NODISK )\r
- {\r
- return Stat; /* No card in the socket */\r
- }\r
-\r
- power_on(); /* Force socket power on */\r
- FCLK_SLOW();\r
- for( n = 10; n; n-- )\r
- {\r
- rcvr_spi(); /* 80 dummy clocks */\r
- }\r
-\r
- ty = 0;\r
- if( send_cmd(CMD0, 0) == 1 )\r
- { /* Enter Idle state */\r
- Timer1 = 1000; /* Initialization timeout of 1000 msec */\r
- if( send_cmd(CMD8, 0x1AA) == 1 )\r
- { /* SDv2? */\r
- for( n = 0; n < 4; n++ )\r
- {\r
- ocr[n] = rcvr_spi(); /* Get trailing return value of R7 resp */\r
- }\r
-\r
- if( ocr[2] == 0x01 && ocr[3] == 0xAA )\r
- { /* The card can work at vdd range of 2.7-3.6V */\r
- while( Timer1 && send_cmd(ACMD41, 1UL << 30) );\r
-\r
- /* Wait for leaving idle state (ACMD41 with HCS bit) */\r
- if( Timer1 && send_cmd(CMD58, 0) == 0 )\r
- { /* Check CCS bit in the OCR */\r
- for( n = 0; n < 4; n++ )\r
- {\r
- ocr[n] = rcvr_spi();\r
- }\r
-\r
- ty = ( ocr[0] & 0x40 ) ? CT_SD2 | CT_BLOCK : CT_SD2; /* SDv2 (HC/SC) */\r
- }\r
- }\r
- }\r
- else\r
- { /* SDv1 or MMCv3 */\r
- if( send_cmd(ACMD41, 0) <= 1 )\r
- {\r
- ty = CT_SD1;\r
- cmd = ACMD41; /* SDv1 */\r
- }\r
- else\r
- {\r
- ty = CT_MMC;\r
- cmd = CMD1; /* MMCv3 */\r
- }\r
-\r
- while( Timer1 && send_cmd(cmd, 0) );\r
-\r
- /* Wait for leaving idle state */\r
- if( !Timer1 || send_cmd(CMD16, 512) != 0 )\r
- { /* Set R/W block length to 512 */\r
- ty = 0;\r
- }\r
- }\r
- }\r
-\r
- CardType = ty;\r
- deselect();\r
-\r
- if( ty )\r
- { /* Initialization succeded */\r
- Stat &= ~STA_NOINIT; /* Clear STA_NOINIT */\r
- FCLK_FAST();\r
- }\r
- else\r
- { /* Initialization failed */\r
- power_off();\r
- }\r
-\r
- return Stat;\r
-}\r
-\r
-/*-----------------------------------------------------------------------*/\r
-\r
-/* Get Disk Status */\r
-\r
-/*-----------------------------------------------------------------------*/\r
-DSTATUS disk_status( BYTE drv /* Physical drive nmuber (0) */ )\r
-{\r
- if( drv )\r
- {\r
- return STA_NOINIT; /* Supports only single drive */\r
- }\r
-\r
- return Stat;\r
-}\r
-\r
-/*-----------------------------------------------------------------------*/\r
-\r
-/* Read Sector(s) */\r
-\r
-/*-----------------------------------------------------------------------*/\r
-DRESULT disk_read\r
- (\r
- BYTE drv, /* Physical drive nmuber (0) */\r
- BYTE *buff, /* Pointer to the data buffer to store read data */\r
- DWORD sector, /* Start sector number (LBA) */\r
- BYTE count /* Sector count (1..255) */\r
- )\r
-{\r
- if( drv || !count )\r
- {\r
- return RES_PARERR;\r
- }\r
-\r
- if( Stat & STA_NOINIT )\r
- {\r
- return RES_NOTRDY;\r
- }\r
-\r
- if( !(CardType & CT_BLOCK) )\r
- {\r
- sector *= 512; /* Convert to byte address if needed */\r
- }\r
-\r
- if( count == 1 )\r
- { /* Single block read */\r
- if( (send_cmd(CMD17, sector) == 0) /* READ_SINGLE_BLOCK */ && rcvr_datablock(buff, 512) )\r
- {\r
- count = 0;\r
- }\r
- }\r
- else\r
- { /* Multiple block read */\r
- if( send_cmd(CMD18, sector) == 0 )\r
- { /* READ_MULTIPLE_BLOCK */\r
- do\r
- {\r
- if( !rcvr_datablock(buff, 512) )\r
- {\r
- break;\r
- }\r
-\r
- buff += 512;\r
- } while( --count );\r
- send_cmd( CMD12, 0 ); /* STOP_TRANSMISSION */\r
- }\r
- }\r
-\r
- deselect();\r
-\r
- return count ? RES_ERROR : RES_OK;\r
-}\r
-\r
-/*-----------------------------------------------------------------------*/\r
-\r
-/* Write Sector(s) */\r
-\r
-/*-----------------------------------------------------------------------*/\r
-#if _READONLY == 0\r
-DRESULT disk_write\r
- (\r
- BYTE drv, /* Physical drive nmuber (0) */\r
- const BYTE *buff, /* Pointer to the data to be written */\r
- DWORD sector, /* Start sector number (LBA) */\r
- BYTE count /* Sector count (1..255) */\r
- )\r
-{\r
- if( drv || !count )\r
- {\r
- return RES_PARERR;\r
- }\r
-\r
- if( Stat & STA_NOINIT )\r
- {\r
- return RES_NOTRDY;\r
- }\r
-\r
- if( Stat & STA_PROTECT )\r
- {\r
- return RES_WRPRT;\r
- }\r
-\r
- if( !(CardType & CT_BLOCK) )\r
- {\r
- sector *= 512; /* Convert to byte address if needed */\r
- }\r
-\r
- if( count == 1 )\r
- { /* Single block write */\r
- if( (send_cmd(CMD24, sector) == 0) /* WRITE_BLOCK */ && xmit_datablock(buff, 0xFE) )\r
- {\r
- count = 0;\r
- }\r
- }\r
- else\r
- { /* Multiple block write */\r
- if( CardType & CT_SDC )\r
- {\r
- send_cmd( ACMD23, count );\r
- }\r
-\r
- if( send_cmd(CMD25, sector) == 0 )\r
- { /* WRITE_MULTIPLE_BLOCK */\r
- do\r
- {\r
- if( !xmit_datablock(buff, 0xFC) )\r
- {\r
- break;\r
- }\r
-\r
- buff += 512;\r
- } while( --count );\r
- if( !xmit_datablock(0, 0xFD) )\r
- { /* STOP_TRAN token */\r
- count = 1;\r
- }\r
- }\r
- }\r
-\r
- deselect();\r
-\r
- return count ? RES_ERROR : RES_OK;\r
-}\r
-\r
-#endif /* _READONLY */\r
-\r
-/*-----------------------------------------------------------------------*/\r
-\r
-/* Miscellaneous Functions */\r
-\r
-/*-----------------------------------------------------------------------*/\r
-DRESULT disk_ioctl\r
- (\r
- BYTE drv, /* Physical drive nmuber (0) */\r
- BYTE ctrl, /* Control code */\r
- void *buff /* Buffer to send/receive data block */\r
- )\r
-{\r
- DRESULT res;\r
- BYTE n, csd[16], *ptr = buff;\r
- DWORD csize;\r
-\r
- if( drv )\r
- {\r
- return RES_PARERR;\r
- }\r
-\r
- if( Stat & STA_NOINIT )\r
- {\r
- return RES_NOTRDY;\r
- }\r
-\r
- res = RES_ERROR;\r
- switch( ctrl )\r
- {\r
- case CTRL_SYNC: /* Flush dirty buffer if present */\r
- if( select() )\r
- {\r
- res = RES_OK;\r
- deselect();\r
- }\r
-\r
- break;\r
-\r
- case GET_SECTOR_COUNT: /* Get number of sectors on the disk (WORD) */\r
- if( (send_cmd(CMD9, 0) == 0) && rcvr_datablock(csd, 16) )\r
- {\r
- if( (csd[0] >> 6) == 1 )\r
- { /* SDv2? */\r
- csize = csd[9] + ( (WORD) csd[8] << 8 ) + 1;\r
- *( DWORD * ) buff = ( DWORD ) csize << 10;\r
- }\r
- else\r
- { /* SDv1 or MMCv2 */\r
- n = ( csd[5] & 15 ) + ( (csd[10] & 128) >> 7 ) + ( (csd[9] & 3) << 1 ) + 2;\r
- csize = ( csd[8] >> 6 ) + ( (WORD) csd[7] << 2 ) + ( (WORD) (csd[6] & 3) << 10 ) + 1;\r
- *( DWORD * ) buff = ( DWORD ) csize << ( n - 9 );\r
- }\r
-\r
- res = RES_OK;\r
- }\r
-\r
- break;\r
-\r
- case GET_SECTOR_SIZE: /* Get sectors on the disk (WORD) */\r
- * ( WORD * ) buff = 512;\r
- res = RES_OK;\r
- break;\r
-\r
- case GET_BLOCK_SIZE: /* Get erase block size in unit of sectors (DWORD) */\r
- if( CardType & CT_SD2 )\r
- { /* SDv2? */\r
- if( send_cmd(ACMD13, 0) == 0 )\r
- { /* Read SD status */\r
- rcvr_spi();\r
- if( rcvr_datablock(csd, 16) )\r
- { /* Read partial block */\r
- for( n = 64 - 16; n; n-- )\r
- {\r
- rcvr_spi(); /* Purge trailing data */\r
- }\r
-\r
- * ( DWORD * ) buff = 16UL << ( csd[10] >> 4 );\r
- res = RES_OK;\r
- }\r
- }\r
- }\r
- else\r
- { /* SDv1 or MMCv3 */\r
- if( (send_cmd(CMD9, 0) == 0) && rcvr_datablock(csd, 16) )\r
- { /* Read CSD */\r
- if( CardType & CT_SD1 )\r
- { /* SDv1 */\r
- *( DWORD * ) buff = ( ((csd[10] & 63) << 1) + ((WORD) (csd[11] & 128) >> 7) + 1 ) << ( (csd[13] >> 6) - 1 );\r
- }\r
- else\r
- { /* MMCv3 */\r
- *( DWORD * ) buff = ( (WORD) ((csd[10] & 124) >> 2) + 1 ) * ( ((csd[11] & 3) << 3) + ((csd[11] & 224) >> 5) + 1 );\r
- }\r
-\r
- res = RES_OK;\r
- }\r
- }\r
-\r
- break;\r
-\r
- case MMC_GET_TYPE: /* Get card type flags (1 byte) */\r
- *ptr = CardType;\r
- res = RES_OK;\r
- break;\r
-\r
- case MMC_GET_CSD: /* Receive CSD as a data block (16 bytes) */\r
- if( (send_cmd(CMD9, 0) == 0) /* READ_CSD */ && rcvr_datablock(buff, 16) )\r
- {\r
- res = RES_OK;\r
- }\r
-\r
- break;\r
-\r
- case MMC_GET_CID: /* Receive CID as a data block (16 bytes) */\r
- if( (send_cmd(CMD10, 0) == 0) /* READ_CID */ && rcvr_datablock(buff, 16) )\r
- {\r
- res = RES_OK;\r
- }\r
-\r
- break;\r
-\r
- case MMC_GET_OCR: /* Receive OCR as an R3 resp (4 bytes) */\r
- if( send_cmd(CMD58, 0) == 0 )\r
- { /* READ_OCR */\r
- for( n = 0; n < 4; n++ )\r
- {\r
- *( ( BYTE * ) buff + n ) = rcvr_spi();\r
- }\r
-\r
- res = RES_OK;\r
- }\r
-\r
- break;\r
-\r
- case MMC_GET_SDSTAT: /* Receive SD statsu as a data block (64 bytes) */\r
- if( send_cmd(ACMD13, 0) == 0 )\r
- { /* SD_STATUS */\r
- rcvr_spi();\r
- if( rcvr_datablock(buff, 64) )\r
- {\r
- res = RES_OK;\r
- }\r
- }\r
-\r
- break;\r
-\r
- default:\r
- res = RES_PARERR;\r
- }\r
-\r
- deselect();\r
-\r
- return res;\r
-}\r
-\r
-/*-----------------------------------------------------------------------*/\r
-\r
-/* Device Timer Interrupt Procedure (Platform dependent) */\r
-\r
-/*-----------------------------------------------------------------------*/\r
-\r
-/* This function must be called in period of 1ms */\r
-void disk_timerproc( void )\r
-{\r
- static unsigned long pv;\r
- unsigned long p;\r
- BYTE s;\r
- UINT n;\r
-\r
- n = Timer1; /* 1000Hz decrement timer */\r
- if( n )\r
- {\r
- Timer1 = --n;\r
- }\r
-\r
- n = Timer2;\r
- if( n )\r
- {\r
- Timer2 = --n;\r
- }\r
-\r
- p = pv;\r
- pv = SOCKPORT & ( SOCKWP | SOCKINS ); /* Sample socket switch */\r
-\r
- if( p == pv )\r
- { /* Have contacts stabled? */\r
- s = Stat;\r
-\r
- if( p & SOCKWP )\r
- { /* WP is H (write protected) */\r
- s |= STA_PROTECT;\r
- }\r
- else\r
- { /* WP is L (write enabled) */\r
- s &= ~STA_PROTECT;\r
- }\r
-\r
- if( p & SOCKINS )\r
- { /* INS = H (Socket empty) */\r
- s |= ( STA_NODISK | STA_NOINIT );\r
- }\r
- else\r
- { /* INS = L (Card inserted) */\r
- s &= ~STA_NODISK;\r
- }\r
-\r
- Stat = s;\r
- }\r
-}\r
-\r
-DWORD get_fattime( void )\r
-{\r
- return 0;\r
-}\r
-\r
-void disk_init_spi( void )\r
-{\r
- volatile unsigned long ulDummy;\r
-\r
- /* The SD card is connected using SPI0. Start by enabling power to the\r
- SPI peripheral. */\r
- SC->PCONP |= PCONP_PCSPI;\r
-\r
- /* Also enable the clock to the peripheral. */\r
- SC->PCLKSEL0 &= ~( 0x03 << 16 );\r
- SC->PCLKSEL0 |= ( 0x01 << 16 );\r
-\r
- /* Configure P0.15 as the clock. */\r
- PINCON->PINSEL0 |= ( 0x03 << 30 );\r
-\r
- /* Configure P0.16 as SSEL. */\r
- GPIO0->FIODIR |= ( 0x01 << 16 );\r
- PINCON->PINSEL1 &= ~( 0x03 );\r
-\r
- /* Configure P0.17 as MISO. */\r
- PINCON->PINSEL1 |= ( 0x03 << 2 );\r
-\r
- /* Configure P0.18 as MOSI. */\r
- PINCON->PINSEL1 |= ( 0x03 << 4 );\r
-\r
- /* Configure P4.29 as (presumably) the card detect input. */\r
-// GPIO4->FIODIR &= ~( 1 << 29 );\r
-\r
- /* Set outputs to outputs... */\r
- GPIO0->FIODIR |= ( (1 << 15) | (1 << 16) | (1 << 18) );\r
-\r
- /* ... and inputs to inputs. */\r
- GPIO0->FIODIR &= ~( 1 << 17 );\r
-\r
- /* Ensure SSEL is high. */\r
- CS_HIGH();\r
-\r
- /* Set SPI to master mode. */\r
- SPI->SPCR |= ( 1 << 5 );\r
-\r
- /* Clear all status bits. */\r
- ulDummy = SPI->SPSR;\r
-\r
- /* Set the serial clock frequency. 100MHz / 250 = 400KHz. */\r
- SPI->SPCCR = configCPU_CLOCK_HZ / 250;\r
-}\r
-\r
-\r
+++ /dev/null
-/*-----------------------------------------------------------------------\r
-/ Low level disk interface modlue include file R0.07 (C)ChaN, 2009\r
-/-----------------------------------------------------------------------*/\r
-\r
-#ifndef _DISKIO\r
-\r
-#define _READONLY 0 /* 1: Read-only mode */\r
-#define _USE_IOCTL 1\r
-\r
-#include "fat_integer.h"\r
-\r
-\r
-/* Status of Disk Functions */\r
-typedef BYTE DSTATUS;\r
-\r
-/* Results of Disk Functions */\r
-typedef enum {\r
- RES_OK = 0, /* 0: Successful */\r
- RES_ERROR, /* 1: R/W Error */\r
- RES_WRPRT, /* 2: Write Protected */\r
- RES_NOTRDY, /* 3: Not Ready */\r
- RES_PARERR /* 4: Invalid Parameter */\r
-} DRESULT;\r
-\r
-\r
-/*---------------------------------------*/\r
-/* Prototypes for disk control functions */\r
-\r
-BOOL assign_drives (int argc, char *argv[]);\r
-DSTATUS disk_initialize (BYTE);\r
-DSTATUS disk_status (BYTE);\r
-DRESULT disk_read (BYTE, BYTE*, DWORD, BYTE);\r
-#if _READONLY == 0\r
-DRESULT disk_write (BYTE, const BYTE*, DWORD, BYTE);\r
-#endif\r
-DRESULT disk_ioctl (BYTE, BYTE, void*);\r
-\r
-\r
-\r
-/* Disk Status Bits (DSTATUS) */\r
-\r
-#define STA_NOINIT 0x01 /* Drive not initialized */\r
-#define STA_NODISK 0x02 /* No medium in the drive */\r
-#define STA_PROTECT 0x04 /* Write protected */\r
-\r
-\r
-/* Command code for disk_ioctrl() */\r
-\r
-/* Generic command */\r
-#define CTRL_SYNC 0 /* Mandatory for write functions */\r
-#define GET_SECTOR_COUNT 1 /* Mandatory for only f_mkfs() */\r
-#define GET_SECTOR_SIZE 2 /* Mandatory for multiple sector size cfg */\r
-#define GET_BLOCK_SIZE 3 /* Mandatory for only f_mkfs() */\r
-#define CTRL_POWER 4\r
-#define CTRL_LOCK 5\r
-#define CTRL_EJECT 6\r
-/* MMC/SDC command */\r
-#define MMC_GET_TYPE 10\r
-#define MMC_GET_CSD 11\r
-#define MMC_GET_CID 12\r
-#define MMC_GET_OCR 13\r
-#define MMC_GET_SDSTAT 14\r
-/* ATA/CF command */\r
-#define ATA_GET_REV 20\r
-#define ATA_GET_MODEL 21\r
-#define ATA_GET_SN 22\r
-\r
-/* Card type definitions (CardType) */\r
-\r
-#define CT_MMC 0x01\r
-#define CT_SD1 0x02\r
-#define CT_SD2 0x04\r
-#define CT_SDC (CT_SD1|CT_SD2)\r
-#define CT_BLOCK 0x08\r
-\r
-#define _DISKIO\r
-#endif\r
+++ /dev/null
-/*---------------------------------------------------------------------------/\r
-/ FatFs - FAT file system module configuration file R0.07e (C)ChaN, 2009\r
-/----------------------------------------------------------------------------/\r
-/\r
-/ CAUTION! Do not forget to make clean the project after any changes to\r
-/ the configuration options.\r
-/\r
-/----------------------------------------------------------------------------*/\r
-#ifndef _FFCONFIG\r
-#define _FFCONFIG 0x007E\r
-\r
-\r
-/*---------------------------------------------------------------------------/\r
-/ Function and Buffer Configurations\r
-/----------------------------------------------------------------------------*/\r
-\r
-#define _FS_TINY 0 /* 0 or 1 */\r
-/* When _FS_TINY is set to 1, FatFs uses the sector buffer in the file system\r
-/ object instead of the sector buffer in the individual file object for file\r
-/ data transfer. This reduces memory consumption 512 bytes each file object. */\r
-\r
-\r
-#define _FS_READONLY 0 /* 0 or 1 */\r
-/* Setting _FS_READONLY to 1 defines read only configuration. This removes\r
-/ writing functions, f_write, f_sync, f_unlink, f_mkdir, f_chmod, f_rename,\r
-/ f_truncate and useless f_getfree. */\r
-\r
-\r
-#define _FS_MINIMIZE 0 /* 0, 1, 2 or 3 */\r
-/* The _FS_MINIMIZE option defines minimization level to remove some functions.\r
-/\r
-/ 0: Full function.\r
-/ 1: f_stat, f_getfree, f_unlink, f_mkdir, f_chmod, f_truncate and f_rename\r
-/ are removed.\r
-/ 2: f_opendir and f_readdir are removed in addition to level 1.\r
-/ 3: f_lseek is removed in addition to level 2. */\r
-\r
-\r
-#define _USE_STRFUNC 0 /* 0, 1 or 2 */\r
-/* To enable string functions, set _USE_STRFUNC to 1 or 2. */\r
-\r
-\r
-#define _USE_MKFS 0 /* 0 or 1 */\r
-/* To enable f_mkfs function, set _USE_MKFS to 1 and set _FS_READONLY to 0 */\r
-\r
-\r
-#define _USE_FORWARD 0 /* 0 or 1 */\r
-/* To enable f_forward function, set _USE_FORWARD to 1 and set _FS_TINY to 1. */\r
-\r
-\r
-\r
-/*---------------------------------------------------------------------------/\r
-/ Locale and Namespace Configurations\r
-/----------------------------------------------------------------------------*/\r
-\r
-#define _CODE_PAGE 1250\r
-/* The _CODE_PAGE specifies the OEM code page to be used on the target system.\r
-/ Incorrect setting of the code page can cause a file open failure.\r
-/\r
-/ 932 - Japanese Shift-JIS (DBCS, OEM, Windows)\r
-/ 936 - Simplified Chinese GBK (DBCS, OEM, Windows)\r
-/ 949 - Korean (DBCS, OEM, Windows)\r
-/ 950 - Traditional Chinese Big5 (DBCS, OEM, Windows)\r
-/ 1250 - Central Europe (Windows)\r
-/ 1251 - Cyrillic (Windows)\r
-/ 1252 - Latin 1 (Windows)\r
-/ 1253 - Greek (Windows)\r
-/ 1254 - Turkish (Windows)\r
-/ 1255 - Hebrew (Windows)\r
-/ 1256 - Arabic (Windows)\r
-/ 1257 - Baltic (Windows)\r
-/ 1258 - Vietnam (OEM, Windows)\r
-/ 437 - U.S. (OEM)\r
-/ 720 - Arabic (OEM)\r
-/ 737 - Greek (OEM)\r
-/ 775 - Baltic (OEM)\r
-/ 850 - Multilingual Latin 1 (OEM)\r
-/ 858 - Multilingual Latin 1 + Euro (OEM)\r
-/ 852 - Latin 2 (OEM)\r
-/ 855 - Cyrillic (OEM)\r
-/ 866 - Russian (OEM)\r
-/ 857 - Turkish (OEM)\r
-/ 862 - Hebrew (OEM)\r
-/ 874 - Thai (OEM, Windows)\r
-/ 1 - ASCII only (Valid for non LFN cfg.)\r
-*/\r
-\r
-\r
-#define _USE_LFN 0 /* 0, 1 or 2 */\r
-#define _MAX_LFN 255 /* Maximum LFN length to handle (12 to 255) */\r
-/* The _USE_LFN option switches the LFN support.\r
-/\r
-/ 0: Disable LFN. _MAX_LFN and _LFN_UNICODE have no effect.\r
-/ 1: Enable LFN with static working buffer on the bss. NOT REENTRANT.\r
-/ 2: Enable LFN with dynamic working buffer on the STACK.\r
-/\r
-/ The LFN working buffer occupies (_MAX_LFN + 1) * 2 bytes. When enable LFN,\r
-/ two Unicode handling functions ff_convert() and ff_wtoupper() must be added\r
-/ to the project. */\r
-\r
-\r
-#define _LFN_UNICODE 0 /* 0 or 1 */\r
-/* To switch the character code set on FatFs API to Unicode,\r
-/ enable LFN feature and set _LFN_UNICODE to 1.\r
-*/\r
-\r
-\r
-#define _FS_RPATH 0 /* 0 or 1 */\r
-/* When _FS_RPATH is set to 1, relative path feature is enabled and f_chdir,\r
-/ f_chdrive function are available.\r
-/ Note that output of the f_readdir fnction is affected by this option. */\r
-\r
-\r
-\r
-/*---------------------------------------------------------------------------/\r
-/ Physical Drive Configurations\r
-/----------------------------------------------------------------------------*/\r
-\r
-#define _DRIVES 1\r
-/* Number of volumes (logical drives) to be used. */\r
-\r
-\r
-#define _MAX_SS 512 /* 512, 1024, 2048 or 4096 */\r
-/* Maximum sector size to be handled.\r
-/ Always set 512 for memory card and hard disk but a larger value may be\r
-/ required for floppy disk (512/1024) and optical disk (512/2048).\r
-/ When _MAX_SS is larger than 512, GET_SECTOR_SIZE command must be implememted\r
-/ to the disk_ioctl function. */\r
-\r
-\r
-#define _MULTI_PARTITION 0 /* 0 or 1 */\r
-/* When _MULTI_PARTITION is set to 0, each volume is bound to the same physical\r
-/ drive number and can mount only first primaly partition. When it is set to 1,\r
-/ each volume is tied to the partitions listed in Drives[]. */\r
-\r
-\r
-\r
-/*---------------------------------------------------------------------------/\r
-/ System Configurations\r
-/----------------------------------------------------------------------------*/\r
-\r
-#define _WORD_ACCESS 0 /* 0 or 1 */\r
-/* The _WORD_ACCESS option defines which access method is used to the word\r
-/ data on the FAT volume.\r
-/\r
-/ 0: Byte-by-byte access. Always compatible with all platforms.\r
-/ 1: Word access. Do not choose this unless following condition is met.\r
-/\r
-/ When the byte order on the memory is big-endian or address miss-aligned\r
-/ word access results incorrect behavior, the _WORD_ACCESS must be set to 0.\r
-/ If it is not the case, the value can also be set to 1 to improve the\r
-/ performance and code size. */\r
-\r
-\r
-#define _FS_REENTRANT 1 /* 0 or 1 */\r
-#define _FS_TIMEOUT 1000 /* Timeout period in unit of time ticks */\r
-#define _SYNC_t void * /* O/S dependent type of sync object. e.g. HANDLE, OS_EVENT*, ID and etc.. */\r
-/* The _FS_REENTRANT option switches the reentrancy of the FatFs module.\r
-/\r
-/ 0: Disable reentrancy. _SYNC_t and _FS_TIMEOUT have no effect.\r
-/ 1: Enable reentrancy. Also user provided synchronization handlers,\r
-/ ff_req_grant, ff_rel_grant, ff_del_syncobj and ff_cre_syncobj\r
-/ function must be added to the project. */\r
-\r
-\r
-#endif /* _FFCONFIG */\r
+++ /dev/null
-/*\r
- FreeRTOS V6.0.2 - Copyright (C) 2010 Real Time Engineers Ltd.\r
-\r
- ***************************************************************************\r
- * *\r
- * If you are: *\r
- * *\r
- * + New to FreeRTOS, *\r
- * + Wanting to learn FreeRTOS or multitasking in general quickly *\r
- * + Looking for basic training, *\r
- * + Wanting to improve your FreeRTOS skills and productivity *\r
- * *\r
- * then take a look at the FreeRTOS eBook *\r
- * *\r
- * "Using the FreeRTOS Real Time Kernel - a Practical Guide" *\r
- * http://www.FreeRTOS.org/Documentation *\r
- * *\r
- * A pdf reference manual is also available. Both are usually delivered *\r
- * to your inbox within 20 minutes to two hours when purchased between 8am *\r
- * and 8pm GMT (although please allow up to 24 hours in case of *\r
- * exceptional circumstances). Thank you for your support! *\r
- * *\r
- ***************************************************************************\r
-\r
- This file is part of the FreeRTOS distribution.\r
-\r
- FreeRTOS is free software; you can redistribute it and/or modify it under\r
- the terms of the GNU General Public License (version 2) as published by the\r
- Free Software Foundation AND MODIFIED BY the FreeRTOS exception.\r
- ***NOTE*** The exception to the GPL is included to allow you to distribute\r
- a combined work that includes FreeRTOS without being obliged to provide the\r
- source code for proprietary components outside of the FreeRTOS kernel.\r
- FreeRTOS is distributed in the hope that it will be useful, but WITHOUT\r
- ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or\r
- FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for\r
- more details. You should have received a copy of the GNU General Public \r
- License and the FreeRTOS license exception along with FreeRTOS; if not it \r
- can be viewed here: http://www.freertos.org/a00114.html and also obtained \r
- by writing to Richard Barry, contact details for whom are available on the\r
- FreeRTOS WEB site.\r
-\r
- 1 tab == 4 spaces!\r
-\r
- http://www.FreeRTOS.org - Documentation, latest information, license and\r
- contact details.\r
-\r
- http://www.SafeRTOS.com - A version that is certified for use in safety\r
- critical systems.\r
-\r
- http://www.OpenRTOS.com - Commercial support, development, porting,\r
- licensing and training services.\r
-*/\r
-\r
-/* FreeRTOS.org includes. */\r
-#include "FreeRTOS.h"\r
-\r
-/* Demo application includes. */\r
-#include "partest.h"\r
-\r
-#define partstFIRST_IO ( ( unsigned long ) 0x04 )\r
-#define partstFIO2_BITS ( ( unsigned long ) 0x0000007C )\r
-#define partstFIO1_BITS ( ( unsigned long ) 0xB0000000 )\r
-#define partstNUM_LEDS ( 5 )\r
-#define partstALL_OUTPUTS_OFF ( ( unsigned long ) 0xff )\r
-\r
-/*-----------------------------------------------------------\r
- * Simple parallel port IO routines.\r
- *-----------------------------------------------------------*/\r
-\r
-void vParTestInitialise( void )\r
-{\r
- /* LEDs on ports 1 and 2 to output. */\r
- GPIO2->FIODIR = partstFIO2_BITS;\r
- GPIO1->FIODIR = partstFIO1_BITS;\r
-\r
- /* Start will all LEDs off. */\r
- GPIO2->FIOCLR = partstFIO2_BITS;\r
- GPIO1->FIOCLR = partstFIO1_BITS;\r
-}\r
-/*-----------------------------------------------------------*/\r
-\r
-void vParTestSetLED( unsigned long ulLEDIn, signed long xValue )\r
-{\r
-unsigned long ulLED = partstFIRST_IO;\r
-\r
- /* Used to set and clear LEDs on FIO2. */\r
-\r
- if( ulLEDIn < partstNUM_LEDS )\r
- {\r
- /* Rotate to the wanted bit of port */\r
- ulLED <<= ( unsigned long ) ulLEDIn;\r
-\r
- /* Set of clear the output. */\r
- if( xValue )\r
- {\r
- GPIO2->FIOCLR = ulLED;\r
- }\r
- else\r
- {\r
- GPIO2->FIOSET = ulLED;\r
- }\r
- }\r
-}\r
-/*-----------------------------------------------------------*/\r
-\r
-void vParTestToggleLED( unsigned long ulLEDIn )\r
-{\r
-unsigned long ulLED = partstFIRST_IO, ulCurrentState;\r
-\r
- /* Used to toggle LEDs on FIO2. */\r
-\r
- if( ulLEDIn < partstNUM_LEDS )\r
- {\r
- /* Rotate to the wanted bit of port 0. Only P10 to P13 have an LED\r
- attached. */\r
- ulLED <<= ( unsigned long ) ulLEDIn;\r
-\r
- /* If this bit is already set, clear it, and visa versa. */\r
- ulCurrentState = GPIO2->FIOPIN;\r
- if( ulCurrentState & ulLED )\r
- {\r
- GPIO2->FIOCLR = ulLED;\r
- }\r
- else\r
- {\r
- GPIO2->FIOSET = ulLED;\r
- }\r
- }\r
-}\r
-/*-----------------------------------------------------------*/\r
-\r
-long lParTestGetLEDState( void )\r
-{\r
- /* Returns the state of the LEDs on FIO1. */\r
- if( ( GPIO1->FIOPIN & partstFIO1_BITS ) != 0 )\r
- {\r
- return pdFALSE;\r
- }\r
- else\r
- {\r
- return pdTRUE;\r
- }\r
-}\r
-/*-----------------------------------------------------------*/\r
-\r
-void vParTestSetLEDState( long lState )\r
-{\r
- /* Used to set and clear the LEDs on FIO1. */\r
- if( lState != pdFALSE )\r
- {\r
- GPIO1->FIOSET = partstFIO1_BITS;\r
- }\r
- else\r
- {\r
- GPIO1->FIOCLR = partstFIO1_BITS;\r
- }\r
-}\r
-/*-----------------------------------------------------------*/\r
-\r
+++ /dev/null
-/*\r
- FreeRTOS V6.0.2 - Copyright (C) 2010 Real Time Engineers Ltd.\r
-\r
- ***************************************************************************\r
- * *\r
- * If you are: *\r
- * *\r
- * + New to FreeRTOS, *\r
- * + Wanting to learn FreeRTOS or multitasking in general quickly *\r
- * + Looking for basic training, *\r
- * + Wanting to improve your FreeRTOS skills and productivity *\r
- * *\r
- * then take a look at the FreeRTOS eBook *\r
- * *\r
- * "Using the FreeRTOS Real Time Kernel - a Practical Guide" *\r
- * http://www.FreeRTOS.org/Documentation *\r
- * *\r
- * A pdf reference manual is also available. Both are usually delivered *\r
- * to your inbox within 20 minutes to two hours when purchased between 8am *\r
- * and 8pm GMT (although please allow up to 24 hours in case of *\r
- * exceptional circumstances). Thank you for your support! *\r
- * *\r
- ***************************************************************************\r
-\r
- This file is part of the FreeRTOS distribution.\r
-\r
- FreeRTOS is free software; you can redistribute it and/or modify it under\r
- the terms of the GNU General Public License (version 2) as published by the\r
- Free Software Foundation AND MODIFIED BY the FreeRTOS exception.\r
- ***NOTE*** The exception to the GPL is included to allow you to distribute\r
- a combined work that includes FreeRTOS without being obliged to provide the\r
- source code for proprietary components outside of the FreeRTOS kernel.\r
- FreeRTOS is distributed in the hope that it will be useful, but WITHOUT\r
- ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or\r
- FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for\r
- more details. You should have received a copy of the GNU General Public \r
- License and the FreeRTOS license exception along with FreeRTOS; if not it \r
- can be viewed here: http://www.freertos.org/a00114.html and also obtained \r
- by writing to Richard Barry, contact details for whom are available on the\r
- FreeRTOS WEB site.\r
-\r
- 1 tab == 4 spaces!\r
-\r
- http://www.FreeRTOS.org - Documentation, latest information, license and\r
- contact details.\r
-\r
- http://www.SafeRTOS.com - A version that is certified for use in safety\r
- critical systems.\r
-\r
- http://www.OpenRTOS.com - Commercial support, development, porting,\r
- licensing and training services.\r
-*/\r
-\r
-\r
-/*\r
- * Creates all the demo application tasks, then starts the scheduler. The WEB\r
- * documentation provides more details of the standard demo application tasks\r
- * (which just exist to test the kernel port and provide an example of how to use\r
- * each FreeRTOS API function).\r
- *\r
- * In addition to the standard demo tasks, the following tasks and tests are\r
- * defined and/or created within this file:\r
- *\r
- * "Check" hook - This only executes fully every five seconds from the tick\r
- * hook. Its main function is to check that all the standard demo tasks are\r
- * still operational. The status can be viewed using on the Task Stats page\r
- * served by the WEB server.\r
- *\r
- * "uIP" task - This is the task that handles the uIP stack. All TCP/IP\r
- * processing is performed in this task.\r
- * \r
- * "USB" task - Enumerates the USB device as a CDC class, then echoes back all\r
- * received characters with a configurable offset (for example, if the offset\r
- * is 1 and 'A' is received then 'B' will be sent back). A dumb terminal such\r
- * as Hyperterminal can be used to talk to the USB task.\r
- */\r
-\r
-/* Scheduler includes. */\r
-#include "FreeRTOS.h"\r
-#include "task.h"\r
-\r
-/* Demo app includes. */\r
-#include "BlockQ.h"\r
-#include "integer.h"\r
-#include "blocktim.h"\r
-#include "flash.h"\r
-#include "partest.h"\r
-#include "semtest.h"\r
-#include "PollQ.h"\r
-#include "GenQTest.h"\r
-#include "QPeek.h"\r
-#include "recmutex.h"\r
-\r
-/* File system includes. */\r
-#include "diskio.h"\r
-#include "ff.h"\r
-\r
-/*-----------------------------------------------------------*/\r
-\r
-/* The time between cycles of the 'check' functionality (defined within the\r
-tick hook). */\r
-#define mainCHECK_DELAY ( ( portTickType ) 5000 / portTICK_RATE_MS )\r
-\r
-/* Task priorities. */\r
-#define mainQUEUE_POLL_PRIORITY ( tskIDLE_PRIORITY + 2 )\r
-#define mainSEM_TEST_PRIORITY ( tskIDLE_PRIORITY + 1 )\r
-#define mainBLOCK_Q_PRIORITY ( tskIDLE_PRIORITY + 2 )\r
-#define mainUIP_TASK_PRIORITY ( tskIDLE_PRIORITY + 3 )\r
-#define mainINTEGER_TASK_PRIORITY ( tskIDLE_PRIORITY )\r
-#define mainGEN_QUEUE_TASK_PRIORITY ( tskIDLE_PRIORITY )\r
-#define mainFLASH_TASK_PRIORITY ( tskIDLE_PRIORITY + 2 )\r
-\r
-/* The WEB server has a larger stack as it utilises stack hungry string\r
-handling library calls. */\r
-#define mainBASIC_WEB_STACK_SIZE ( configMINIMAL_STACK_SIZE * 4 )\r
-\r
-/* The message displayed by the WEB server when all tasks are executing\r
-without an error being reported. */\r
-#define mainPASS_STATUS_MESSAGE "All tasks are executing without error."\r
-\r
-/*-----------------------------------------------------------*/\r
-\r
-/*\r
- * Configure the hardware for the demo.\r
- */\r
-static void prvSetupHardware( void );\r
-\r
-/*\r
- * The task that handles the uIP stack. All TCP/IP processing is performed in\r
- * this task.\r
- */\r
-extern void vuIP_Task( void *pvParameters );\r
-\r
-/*\r
- * The task that handles the USB stack.\r
- */\r
-extern void vUSBTask( void *pvParameters );\r
-\r
-/*\r
- * Simply returns the current status message for display on served WEB pages.\r
- */\r
-char *pcGetTaskStatusMessage( void );\r
-\r
-/*-----------------------------------------------------------*/\r
-\r
-/* Holds the status message displayed by the WEB server. */\r
-static char *pcStatusMessage = mainPASS_STATUS_MESSAGE;\r
-\r
-/*-----------------------------------------------------------*/\r
-\r
-int main( void )\r
-{\r
- /* Configure the hardware for use by this demo. */\r
- prvSetupHardware();\r
-\r
- /* Start the standard demo tasks. These are just here to exercise the\r
- kernel port and provide examples of how the FreeRTOS API can be used. */\r
- vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );\r
- vCreateBlockTimeTasks();\r
- vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );\r
- vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );\r
- vStartIntegerMathTasks( mainINTEGER_TASK_PRIORITY );\r
- vStartGenericQueueTasks( mainGEN_QUEUE_TASK_PRIORITY );\r
- vStartQueuePeekTasks();\r
- vStartRecursiveMutexTasks();\r
- vStartLEDFlashTasks( mainFLASH_TASK_PRIORITY );\r
-\r
- /* Create the USB task. */\r
- xTaskCreate( vUSBTask, ( signed char * ) "USB", configMINIMAL_STACK_SIZE, ( void * ) NULL, tskIDLE_PRIORITY, NULL );\r
- \r
- /* Create the uIP task. The WEB server runs in this task. */\r
- xTaskCreate( vuIP_Task, ( signed char * ) "uIP", mainBASIC_WEB_STACK_SIZE, ( void * ) NULL, mainUIP_TASK_PRIORITY, NULL );\r
-\r
- /* Start the scheduler. */\r
- vTaskStartScheduler();\r
-\r
- /* Will only get here if there was insufficient memory to create the idle\r
- task. The idle task is created within vTaskStartScheduler(). */\r
- for( ;; );\r
-}\r
-/*-----------------------------------------------------------*/\r
-\r
-void vApplicationTickHook( void )\r
-{\r
-static unsigned long ulTicksSinceLastDisplay = 0;\r
-\r
- /* Called from every tick interrupt as described in the comments at the top\r
- of this file.\r
-\r
- Have enough ticks passed to make it time to perform our health status\r
- check again? */\r
- ulTicksSinceLastDisplay++;\r
- if( ulTicksSinceLastDisplay >= mainCHECK_DELAY )\r
- {\r
- /* Reset the counter so these checks run again in mainCHECK_DELAY\r
- ticks time. */\r
- ulTicksSinceLastDisplay = 0;\r
-\r
- /* Has an error been found in any task? */\r
- if( xAreGenericQueueTasksStillRunning() != pdTRUE )\r
- {\r
- pcStatusMessage = "An error has been detected in the Generic Queue test/demo.";\r
- }\r
- else if( xAreQueuePeekTasksStillRunning() != pdTRUE )\r
- {\r
- pcStatusMessage = "An error has been detected in the Peek Queue test/demo.";\r
- }\r
- else if( xAreBlockingQueuesStillRunning() != pdTRUE )\r
- {\r
- pcStatusMessage = "An error has been detected in the Block Queue test/demo.";\r
- }\r
- else if( xAreBlockTimeTestTasksStillRunning() != pdTRUE )\r
- {\r
- pcStatusMessage = "An error has been detected in the Block Time test/demo.";\r
- }\r
- else if( xAreSemaphoreTasksStillRunning() != pdTRUE )\r
- {\r
- pcStatusMessage = "An error has been detected in the Semaphore test/demo.";\r
- }\r
- else if( xArePollingQueuesStillRunning() != pdTRUE )\r
- {\r
- pcStatusMessage = "An error has been detected in the Poll Queue test/demo.";\r
- }\r
- else if( xAreIntegerMathsTaskStillRunning() != pdTRUE )\r
- {\r
- pcStatusMessage = "An error has been detected in the Int Math test/demo.";\r
- }\r
- else if( xAreRecursiveMutexTasksStillRunning() != pdTRUE )\r
- {\r
- pcStatusMessage = "An error has been detected in the Mutex test/demo.";\r
- }\r
- }\r
-\r
- disk_timerproc();\r
-}\r
-/*-----------------------------------------------------------*/\r
-\r
-char *pcGetTaskStatusMessage( void )\r
-{\r
- /* Not bothered about a critical section here. */\r
- return pcStatusMessage;\r
-}\r
-/*-----------------------------------------------------------*/\r
-\r
-void prvSetupHardware( void )\r
-{\r
- /* Disable peripherals power. */\r
- SC->PCONP = 0;\r
-\r
- /* Enable GPIO power. */\r
- SC->PCONP = PCONP_PCGPIO;\r
-\r
- /* Disable TPIU. */\r
- PINCON->PINSEL10 = 0;\r
-\r
- /* Setup the peripheral bus to be the same as the PLL output (64 MHz). */\r
- SC->PCLKSEL0 = 0x05555555;\r
-\r
- /* Configure the LEDs. */\r
- vParTestInitialise();\r
-\r
- /* Configure the SPI for communicating with the SD card. */\r
- disk_init_spi();\r
-\r
-{\r
-FATFS fs;\r
-FIL f;\r
-static char c[ 2048 ];\r
-UINT BytesRead;\r
-\r
- f_mount( 0, &fs );\r
- f_open( &f, "/test.htm", FA_READ );\r
- f_read( &f, c, 2048, &BytesRead );\r
-}\r
-\r
-}\r
-/*-----------------------------------------------------------*/\r
-\r
-void vApplicationStackOverflowHook( xTaskHandle *pxTask, signed char *pcTaskName )\r
-{\r
- /* This function will get called if a task overflows its stack. */\r
-\r
- ( void ) pxTask;\r
- ( void ) pcTaskName;\r
-\r
- for( ;; );\r
-}\r
-/*-----------------------------------------------------------*/\r
-\r
-void vConfigureTimerForRunTimeStats( void )\r
-{\r
-const unsigned long TCR_COUNT_RESET = 2, CTCR_CTM_TIMER = 0x00, TCR_COUNT_ENABLE = 0x01;\r
-\r
- /* This function configures a timer that is used as the time base when\r
- collecting run time statistical information - basically the percentage\r
- of CPU time that each task is utilising. It is called automatically when\r
- the scheduler is started (assuming configGENERATE_RUN_TIME_STATS is set\r
- to 1). */\r
-\r
- /* Power up and feed the timer. */\r
- SC->PCONP |= 0x02UL;\r
- SC->PCLKSEL0 = (SC->PCLKSEL0 & (~(0x3<<2))) | (0x01 << 2);\r
-\r
- /* Reset Timer 0 */\r
- TIM0->TCR = TCR_COUNT_RESET;\r
-\r
- /* Just count up. */\r
- TIM0->CTCR = CTCR_CTM_TIMER;\r
-\r
- /* Prescale to a frequency that is good enough to get a decent resolution,\r
- but not too fast so as to overflow all the time. */\r
- TIM0->PR = ( configCPU_CLOCK_HZ / 10000UL ) - 1UL;\r
-\r
- /* Start the counter. */\r
- TIM0->TCR = TCR_COUNT_ENABLE;\r
-}\r
-/*-----------------------------------------------------------*/\r
-\r