Paparazzi UAS  v7.0_unstable
Paparazzi is a free software Unmanned Aircraft System.
sdio_arch.c
Go to the documentation of this file.
1 /*
2  ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010,
3  2011,2012 Giovanni Di Sirio.
4 
5  This file is part of ChibiOS/RT.
6 
7  ChibiOS/RT is free software; you can redistribute it and/or modify
8  it under the terms of the GNU General Public License as published by
9  the Free Software Foundation; either version 3 of the License, or
10  (at your option) any later version.
11 
12  ChibiOS/RT is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License
18  along with this program. If not, see <http://www.gnu.org/licenses/>.
19 
20  ---
21 
22  A special exception to the GPL can be applied should you wish to distribute
23  a combined work that includes ChibiOS/RT, without being obliged to provide
24  the source code for any proprietary components. See the file exception.txt
25  for full details of how and when the exception can be applied.
26  */
27 
35 #include "std.h"
36 #include <string.h>
37 #include <ch.h>
38 #include <hal.h>
39 #include "mcu_periph/sdio.h"
40 #include <stdarg.h>
41 #include "mcu_periph/gpio.h"
42 #include BOARD_CONFIG
43 
44 
45 static enum {STOP, CONNECT} cnxState = STOP;
46 
47 
48 bool sdio_connect(void)
49 {
50  if (!sdc_lld_is_card_inserted(NULL)) {
51  return FALSE;
52  }
53 
54  if (cnxState == CONNECT) {
55  return TRUE;
56  }
57 
58  // Try only 3 times to prevent hanging
59  for (uint8_t i = 0; i < 3; i++) {
60  sdcStart(&SDCD1, NULL);
61  if (sdcConnect(&SDCD1) == HAL_SUCCESS) {
62  cnxState = CONNECT;
63  return TRUE;
64  }
65  sdcStop(&SDCD1);
66  chThdSleepMilliseconds(100);
67  }
68 
69  return FALSE;
70 }
71 
72 
73 bool sdio_disconnect(void)
74 {
75  if (cnxState == STOP) {
76  return TRUE;
77  }
78  if (sdcDisconnect(&SDCD1)) {
79  return FALSE;
80  }
81  sdcStop(&SDCD1);
82  cnxState = STOP;
83  return TRUE;
84 }
85 
86 bool is_card_inserted(void)
87 {
88  return sdc_lld_is_card_inserted(NULL);
89 }
90 
Some architecture independent helper functions for GPIOs.
arch independent SDIO API
@ CONNECT
Definition: sdio_arch.c:45
@ STOP
Definition: sdio_arch.c:45
bool sdio_disconnect(void)
Disconnect a SD card on SDIO peripheral.
Definition: sdio_arch.c:73
bool is_card_inserted(void)
Check if a SD card is inserted.
Definition: sdio_arch.c:86
bool sdio_connect(void)
Connect a SD card on SDIO peripheral.
Definition: sdio_arch.c:48
static enum @0 cnxState
#define TRUE
Definition: std.h:4
#define FALSE
Definition: std.h:5
unsigned char uint8_t
Typedef defining 8 bit unsigned char type.
Definition: vl53l1_types.h:98