亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關(guān)于我們
? 蟲蟲下載站

?? main.c

?? maxim的對sd卡的串行spi模式進行讀寫操作控制的程序源碼
?? C
?? 第 1 頁 / 共 3 頁
字號:
//===========================================================================//=//=  Copyright (C) 2006 MAXIM/Dallas Semiconductor Corporation. //=  All rights Reserved. Printed in U.S.A.//=//=  Permission is hereby granted, free of charge, to any person obtaining a//=  copy of this software and associated documentation files (the //=  "Software"), to deal in the Software without restriction, including//=  without limitation the rights to use, copy, modify, merge, publish,//=  distribute, sublicense, and/or sell copies of the Software, and to//=  permit persons to whom the Software is furnished to do so, subject to//=  the following conditions://=  //=  The above copyright notice and this permission notice shall be included//=  in all copies or substantial portions of the Software source code.//=  //=  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS//=  OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF//=  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.//=  IN NO EVENT SHALL MAXIM/DALLAS SEMICONDUCTOR BE LIABLE FOR ANY CLAIM, //=  DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR //=  OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR //=  THE USE OR OTHER DEALINGS IN THE SOFTWARE.//=//=  Except as contained in this notice, the name of MAXIM/Dallas //=  Semiconductor shall not be used except as stated in the MAXIM/Dallas //=  Semiconductor Branding Policy.//=//=     Description: MAXQ2000 Secure Digital (SD) Card Interface via SPI//=                 //=        Filename: main.c//=//=        Compiler: Rowley CrossWorks C compiler//=//=        Hardware: MAXQ2000 Evaluation Kit (Rev B)//=//===========================================================================#include <MAXQ2000.h>#include <stdio.h>#include <stdio_c.h>#include <stdint.h>#include <string.h>#include <stdarg.h>/* ---- Handy utility macros ---- *//* GETBIT(in,bit) returns bit 0-7 of in to caller */#define GETBIT(in, bit) ((in & (1<<bit)) >> bit)/* CLEARARGS(x) clears the 32-bit SD command argument */#define CLEAR_ARGS(x) x[0] = 0; x[1] = 0; x[2] = 0; x[3] = 0;/* Common command set */#define CMD0_GO_IDLE_STATE          0x00#define CMD1_SEND_OPCOND            0x01#define CMD9_SEND_CSD               0x09#define CMD10_SEND_CID              0x0a#define CMD12_STOP_TRANSMISSION     0x0b#define CMD13_SEND_STATUS           0x0c#define CMD16_SET_BLOCKLEN          0x10#define CMD17_READ_SINGLE_BLOCK     0x11#define CMD18_READ_MULTIPLE_BLOCK   0x12#define CMD24_WRITE_BLOCK           0x18#define CMD25_WRITE_MULTIPLE_BLOCK  0x19#define CMD27_PROGRAM_CSD           0x1b#define CMD28_SET_WRITE_PROT        0x1c#define CMD29_CLR_WRITE_PROT        0x1d#define CMD30_SEND_WRITE_PROT       0x1e#define CMD32_ERASE_WR_BLK_START_ADDR 0x20#define CMD33_ERASE_WR_BLK_END_ADDR   0x21#define CMD38_ERASE                 0x26#define CMD55_APP_CMD               0x37#define CMD56_GEN_CMD               0x38#define CMD58_READ_OCR              0x3a#define CMD59_CRC_ON_OFF            0x3b/* Application-specific commands (always prefixed with CMD55_APP_CMD) */#define ACMD13_SD_STATUS            0x0d#define ACMD22_SEND_NUM_WR_BLOCKS   0x16#define ACMD23_SET_WR_BLK_ERASE_COUNT 0x17#define ACMD41_SEND_OP_COND         0x29#define ACMD42_SET_CLR_CARD_DETECT  0x2a#define ACMD51_SEND_SCR             0x33/* R1 format responses (ORed together as a bit-field) */#define R1_NOERROR   0x00#define R1_IDLE      0x01#define R1_ERASE     0x02#define R1_ILLEGAL   0x04#define R1_CRC_ERR   0x08#define R1_ERASE_SEQ 0x10#define R1_ADDR_ERR  0x20#define R1_PARAM_ERR 0x40/* R2 format responses - second byte only, first is identical to R1 */#define R2_LOCKED    0x01#define R2_WP_FAILED 0x02#define R2_ERROR     0x04#define R2_CTRL_ERR  0x08#define R2_ECC_FAIL  0x10#define R2_WP_VIOL   0x20#define R2_ERASE_PARAM 0x40#define R2_RANGE_ERR 0x80/* CRC-related constants */#define SD_CRC7         0#define SD_CRC16        1#define CRC_OK          0#define CRC_FAIL       -1/* Transfer-related return codes */#define TR_OK           0#define TR_INVALID_ARG -1#define TR_TIMEOUT     -2#define TR_ERROR_TOKEN -3#define TR_NOT_IDLE    -4#define TR_FAILURE     -5/* Misc defines */#define BLOCK_BUFFER_LEN  515#define INPUT_BUFFER_LEN   10/* The following two timeouts should be computed from CSD parameters *//*  in a fully SD-compliant implementation */#define WAIT_R1_TIMEOUT    50#define WAIT_WRITE_TIMEOUT 32768/* Common globals *//* rxbuf is the block buffer used for all operations *//* 515 == 1 R1 response byte + 512 byte block + 2 bytes CRC16 */uint8_t rxbuf[BLOCK_BUFFER_LEN]; /* arg is the 32-bit SD command argument broken into 4 bytes */uint8_t arg[4] = {0x00, 0x00, 0x00, 0x00};/* Most SD cards use a blocksize of 512 bytes and is found in the CSD */uint16_t blocksize = 512; /* Buffer used by the cprintf() macro for strings stored in code space */unsigned char cbuf[80];/* Prototype definition for the assembly routine in copybuf.asm */int asm_copybuffer(unsigned char *dstaddr, const __code char *srcaddr, int len);/* Calls the printf() function after copying code-space string to RAM buffer * * Comments: * *   As the MAXQ2000 has limited RAM, copying all of the static string data *    into RAM reduces the space for the Rowley soft stack. We, therefore,  *    copy only the string needed at the current instant into a single buffer *    and pass this buffer to vprintf() along with the variable argument list. *  * Input arguments: *   *   format - code-space formatting string *   [<arg1> .. <argn>] - additional parameters to printf(str, ...) * * Returns: * *   result code from vprintf * */int cprintf(const __code char *format, ...){  va_list ap;  /* Initialize the varaiable argument list pointer */  va_start(ap, format);  /* Copy the code space string to RAM */  asm_copybuffer(cbuf, format, 80);  /* Call vprintf with our RAM format string plus the varaible argument list */  return vprintf((char *)cbuf, ap);}/* Hook function for Rowley printf() routines to send serial character  * * Input arguments:       * *   x - character to send to console held in lower byte * * Returns: * *   <none> * */int __putchar(int x){  SBUF0 = x;  while (!(SCON0 & 0x02));  SCON0 &= ~0x02;}/* Waits for, and reads, a character over the serial port * * Input arguments:       * *   <none> * * Returns: * *   character received over serial port * */uint8_t readuart(void){  while(!(SCON0 & 1)); /* Wait for RI to go high */  SCON0 &= ~0x01; /* Clear it */  return (uint8_t)SBUF0; /* Pass back the receive buffer */}/* Waits for, and reads, a character over the serial port * * Input arguments:       * *   in - character to transmit out of SPI MOSI pin * * Returns: * *   character received via SPI MISO pin * */uint8_t xferSPI(uint8_t in){  uint8_t out;  /* Caveat lector! This may hang on SPICN.6 and SPICN.7 forever */  while(SPICN & 0x80);           /* Wait for BUSY to be low */  SPICN &= ~0x40;                /* Clear transfer complete */  SPIB = in;                     /* Start the transfer */  while(!(SPICN & 0x40));        /* Wait for Transfer Complete */  out = SPIB;                    /* Copy off what was sent in */  SPICN &= ~0x40;                /* Clear transfer complete */#ifdef SPI_DEBUG  /* This may help during early debugging of the SPI bus */  /* Format is "->(transmitted byte) <-(received byte)" */  cprintf(C"->0x%02x <-0x%02x\r\n", in, out);#endif  return out;}/* Compares R1 expected response with received response * * Input arguments:       * *   r1       - received response *   expected - expected response * * Returns: * *   0 if equal, -1 otherwise * */int check_r1(uint8_t r1, uint8_t expected){  if (r1 != expected) {    cprintf(C"WARNING: R1 status 0x%02x, expecting 0x%02x\r\n", 	   rxbuf[0], expected);    return -1;  }  return 0;}/* Sends idle bytes to card, and waits for 5 consecutive idles from card  * * Input arguments:       * *   timeout - number of characters to wait before giving up * * Returns: * *   TR_OK if equal, TR_TIMEOUT otherwise * */int flush_spi(int timeout){  uint8_t recv;  int i = 0;  /* We unroll the loop to save on variable space. */  while ((i < timeout) && (recv != 0xff)) {    recv = xferSPI(0xff);    if (recv == 0xff) { /* Got 1 so far */      recv = xferSPI(0xff);      if (recv == 0xff) { /* Got 2 so far */	recv = xferSPI(0xff);	if (recv == 0xff) { /* Got 3 so far */	  recv = xferSPI(0xff);	  if (recv == 0xff) { /* Got 4 so far */	    recv = xferSPI(0xff);	  }	}      }    }    i++;  }  if (recv != 0xff) {     /* Only way to reach this is if we timed-out and didn't get 0xff */    return TR_TIMEOUT;  }  return TR_OK;}/* Wait for the start of transmission from the SD card  * * Input arguments:       * *   b      - pointer to buffer of AT LEAST length+1 size *   length - 0 to read only R1, otherwise > 0 to read data response * * Returns: * *   TR_TIMEOUT for timeout, TR_INVALID_ARG for null pointer *   TR_ERROR_TOKEN for length > 0 and error token received *   TR_NOT_IDLE if idle bus was not detected after transfer complete * *   (side effects: b[0] is R1 byte, b[1..length] is data if length > 0) *   (              b[1] is error token if return is TR_ERROR_TOKEN) * *//* Length is # of data bytes to follow R1 response. Status will be in b[0] */int waitForR1(uint8_t *b, uint32_t length){  uint8_t recv = 0xff;  int i = 0;  /* No null pointers allowed */  if (b == NULL) {    return TR_INVALID_ARG;  }  /* Wait for start bit on R1 */  while (GETBIT(recv,7) == 1) {    if (i > WAIT_R1_TIMEOUT) {      return TR_TIMEOUT;    }    recv = xferSPI(0xff);    i++;  }  *b = recv; /* Copy in status */  if (length > 0) {    /* Wait for start token on data portion, if any */    recv = 0xff; i = 0;    while (recv != 0xfe) {      if (i > 50) {	return TR_TIMEOUT;      }      recv = xferSPI(0xff);      if ((recv != 0xff) && (recv != 0xfe)) {	/* Not idle bus and not start token, something else. Bus issue?! */	/* Copy other token into buffer for program to examine */	*(b+1) = recv;	return TR_ERROR_TOKEN;      }      i++;    }        /* Read all bytes */    for (i = 1; i <= length; i++) {      *(b+i) = xferSPI(0xff);    }  }  /* Eight more bit clocks to finish internal SD operations */  recv = xferSPI(0xff);   if (recv != 0xff) {    /* Bus is not idle .. should not happen for single block transfers */    return TR_NOT_IDLE;  }  return 0;}/* CRC-7 as described in the Secure Digital spec  * * Input arguments:       * *   old_crc - 0x00 to start new CRC, or value from previous call to continue *   data    - data byte to add to CRC computation * * Returns: * *   CRC-7 checksum which MUST be augmented by crc_7augment() before use * */uint8_t crc_7(uint8_t old_crc, uint8_t data){  unsigned char new_crc;  int x;  /* CRC-7's polynomial is x^7 + x^3 + 1 */  /* How this works:   *   *  - Feed the bits into the loop MSB first   *  - Shift contents of register left by one, top bit of    *     register becomes x^7 term   *  - If top bit is set, XOR in the poly

?? 快捷鍵說明

復(fù)制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
精品久久国产字幕高潮| 亚洲精品中文在线影院| 国产精品久久久久久一区二区三区| 亚洲精品视频在线观看网站| 久久99精品久久久| 欧美性猛交xxxx乱大交退制版| 国产三级久久久| 丝袜亚洲精品中文字幕一区| 91免费版pro下载短视频| 欧美一区二区视频在线观看2022| 国产精品久久久久久久久快鸭| 久久99国产精品成人| 欧美日韩激情在线| 亚洲美女在线一区| 成人污污视频在线观看| 久久嫩草精品久久久精品一| 日韩电影在线观看一区| 欧美在线free| 亚洲免费av观看| av电影在线观看不卡| 日本一区免费视频| 国产成人免费在线观看不卡| 欧美成人福利视频| 热久久国产精品| 欧美国产日韩亚洲一区| 精品在线一区二区三区| 日韩欧美亚洲另类制服综合在线| 视频一区视频二区中文| 欧美日韩不卡一区二区| 亚洲国产一区二区a毛片| 91福利在线看| 亚洲成人黄色小说| 欧美日韩精品一区二区三区四区| 亚洲成人在线免费| 欧美美女一区二区三区| 午夜影院久久久| 911国产精品| 蜜臀久久99精品久久久画质超高清| 7777精品伊人久久久大香线蕉超级流畅 | 日本欧美一区二区在线观看| 欧美日韩国产小视频在线观看| 一区二区视频在线看| 欧美日韩综合一区| 日本午夜精品视频在线观看 | 日本成人在线电影网| 欧美一区二区三区四区视频| 精品在线你懂的| 国产日韩精品视频一区| 91丨九色porny丨蝌蚪| 一级女性全黄久久生活片免费| 欧美体内she精高潮| 热久久免费视频| 欧美激情艳妇裸体舞| 91免费版在线看| 日韩一区欧美二区| 久久蜜臀精品av| 色就色 综合激情| 成人免费高清在线| 久久99精品久久久久| 精品国偷自产国产一区| 国产一区二区三区久久悠悠色av| 久久久99久久| 一本大道av伊人久久综合| 亚洲高清免费观看高清完整版在线观看| 欧美精品一卡两卡| 国产精品自拍一区| 亚洲精品午夜久久久| 欧美xxxxx牲另类人与| 大白屁股一区二区视频| 一区二区三区在线观看视频| 91精品国产91久久久久久一区二区| 国精产品一区一区三区mba视频| 一色屋精品亚洲香蕉网站| 制服丝袜国产精品| 亚洲欧美日韩人成在线播放| 欧美一级生活片| 成人av电影免费在线播放| 国产乱码精品一区二区三| 亚洲三级理论片| 欧美tickling挠脚心丨vk| a亚洲天堂av| 久久99精品久久久| 亚洲制服丝袜av| 亚洲国产成人一区二区三区| 欧美精品欧美精品系列| 成年人国产精品| 久久精品国产77777蜜臀| 亚洲精品你懂的| 国产精品色在线| 精品久久久久久最新网址| 欧美日韩免费电影| 91亚洲精华国产精华精华液| 国产精品自拍毛片| 蜜臀av一区二区| 亚洲国产精品一区二区www在线| 中文一区一区三区高中清不卡| 欧美大度的电影原声| 欧美在线色视频| 91啪亚洲精品| 成人美女视频在线观看| 国产精品亚洲人在线观看| 青青草97国产精品免费观看| 亚洲不卡在线观看| 亚洲午夜羞羞片| 亚洲国产日韩在线一区模特| 国产精品久久久久7777按摩| 久久精品亚洲麻豆av一区二区| 日韩欧美的一区| 日韩精品一区二区三区swag | 亚洲伊人色欲综合网| 国产精品国产馆在线真实露脸| 久久欧美中文字幕| 精品美女一区二区| 精品国产青草久久久久福利| 欧美成人精品高清在线播放| 欧美一级欧美三级在线观看| 91麻豆精品国产91久久久使用方法 | 精品国产乱码久久久久久久| 欧美成人一区二区三区片免费 | 日韩区在线观看| 日韩午夜在线观看| 日韩精品一区二区在线观看| 欧美大片国产精品| 久久综合一区二区| 国产欧美日本一区视频| 亚洲欧洲一区二区在线播放| 亚洲欧美日韩一区二区三区在线观看 | 日韩精品成人一区二区三区| 青娱乐精品视频| 国产一本一道久久香蕉| 成人久久视频在线观看| 91美女片黄在线观看91美女| 欧美性猛交xxxxxx富婆| 91精品免费在线观看| 欧美zozozo| 国产精品初高中害羞小美女文| 亚洲青青青在线视频| 亚洲综合图片区| 久久av资源站| 白白色亚洲国产精品| 欧美综合一区二区| 日韩一区二区精品| 欧美韩日一区二区三区四区| 一区二区三区四区激情| 美女视频黄频大全不卡视频在线播放 | 国产精品福利一区二区三区| 亚洲激情六月丁香| 看片的网站亚洲| 99久久综合狠狠综合久久| 欧美日韩一区二区三区在线看| 日韩亚洲欧美在线| 国产精品三级在线观看| 午夜婷婷国产麻豆精品| 国产suv精品一区二区6| 91超碰这里只有精品国产| 日本一二三四高清不卡| 日本特黄久久久高潮| 99久久久国产精品免费蜜臀| 欧美老肥妇做.爰bbww视频| 国产亚洲欧洲一区高清在线观看| 亚洲在线免费播放| 国产99久久精品| 91麻豆精品国产91久久久久久 | 亚洲国产精品久久人人爱 | 亚洲欧美日本韩国| 久久精工是国产品牌吗| 欧美怡红院视频| 国产蜜臀97一区二区三区| 日韩va亚洲va欧美va久久| 高清不卡一区二区| 欧美精品久久久久久久多人混战| 久久久久国产精品人| 另类专区欧美蜜桃臀第一页| 色香蕉久久蜜桃| 久久久久久麻豆| 精品一区二区精品| 欧美色中文字幕| 日韩专区一卡二卡| 麻豆国产精品一区二区三区 | 成人一区二区在线观看| 欧美日韩久久不卡| 国产精品国产三级国产普通话99 | 亚洲少妇30p| 处破女av一区二区| 日韩欧美视频在线| 亚洲国产成人porn| 免费视频最近日韩| 欧美三级电影网| 中文字幕一区二区5566日韩| 狠狠久久亚洲欧美| 精品国产百合女同互慰| 日韩中文字幕区一区有砖一区 | 日韩一卡二卡三卡| 一区二区成人在线视频| 不卡的av中国片| 国产精品成人一区二区艾草| 精品一区二区影视| 欧美三级在线视频| 亚洲va天堂va国产va久| 91毛片在线观看|