PICSimLab - Programmable IC Simulator Laboratory 0.9.2
PICSimLab - API
Loading...
Searching...
No Matches
sdcard.h
1/* ########################################################################
2
3 PICSimLab - Programmable IC Simulator Laboratory
4
5 ########################################################################
6
7 Copyright (c) : 2020-2024 Luis Claudio GambĂ´a Lopes <lcgamboa@yahoo.com>
8
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2, or (at your option)
12 any later version.
13
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22
23 For e-mail suggestions : lcgamboa@yahoo.com
24 ######################################################################## */
25
26#ifndef SDCARD
27#define SDCARD
28
29#include <stdio.h>
30#include "bitbang_spi.h"
31
32// SD card commands
33#define CMD0 0X00
34#define CMD1 0X01
35// no spi #define CMD2 0X02 /** ALL_SEND_CID - Asks any card to send the CID. */
36// no spi #define CMD3 0X03 /** SEND_RELATIVE_ADDR - Ask the card to publish a new RCA. */
37// #define CMD6 0X06 /** SWITCH_FUNC - Switch Function Command */
38// no spi #define CMD7 0X07 /** SELECT/DESELECT_CARD - toggles between the stand-by and transfer states. */
39#define CMD8 0X08
40#define CMD9 0X09
41#define CMD10 0X0A
42#define CMD12 0X0C
43#define CMD13 0X0D
44#define CMD16 0X10
45#define CMD17 0X11
46#define CMD18 0X12
47#define CMD24 0X18
48#define CMD25 0X19
49#define CMD32 0X20
50#define CMD33 0X21
51#define CMD38 0X26
52#define CMD55 0X37
53#define CMD58 0X3A
54#define CMD59 0X3B
55// no spi #define ACMD6 0X06 /** SET_BUS_WIDTH - Defines the data bus width for data transfer. */
56#define ACMD13 0X0D
57#define ACMD23 0X17
58#define ACMD41 0X29
59#define ACMD42 0X2A
60#define ACMD51 0X33
61
62#define MAX_REPLY 72
63
64typedef struct {
65 FILE* fd;
66 unsigned char card_present;
67 bitbang_spi_t bb_spi;
68 unsigned long arg;
69 unsigned char cmd;
70 unsigned char crc;
71 unsigned short replyc;
72 unsigned char reply[MAX_REPLY];
73 unsigned char ap_cmd;
74 unsigned short data_rc;
75 unsigned short data_wc;
76 unsigned char multi_rd;
77 unsigned char multi_wr;
78 unsigned long disk_size; // in kb
79 unsigned long ebstart;
80 unsigned long ebend;
81 unsigned char R1;
82 unsigned char crc_on;
83 unsigned int cmd_count; // used for boot
84 unsigned char cmd_buff[5];
85 unsigned short crc16;
86} sdcard_t;
87
88void sdcard_rst(sdcard_t* sd);
89void sdcard_init(sdcard_t* sd);
90void sdcard_end(sdcard_t* sd);
91void sdcard_set_card_present(sdcard_t* sd, unsigned char cp);
92void sdcard_set_filename(sdcard_t* sd, const char* fname);
93
94unsigned short sdcard_io(sdcard_t* sd, unsigned char mosi, unsigned char clk, unsigned char ss);
95
96#endif // SDCARD
Definition bitbang_spi.h:35
Definition sdcard.h:64