Paparazzi UAS  v5.10_stable-5-g83a0da5-dirty
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
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 
42 
43 static enum {STOP, CONNECT} cnxState = STOP;
44 
45 
46 bool sdio_connect(void)
47 {
48  if (!sdc_lld_is_card_inserted (NULL)) {
49  return FALSE;
50  }
51 
52  if (cnxState == CONNECT) {
53  return TRUE;
54  }
55 
56  /*
57  * Initializes the SDIO drivers.
58  *
59  * FIXME hardcoded for Apogee board ?
60  */
61  const uint32_t mode = PAL_MODE_ALTERNATE(12) | PAL_STM32_OTYPE_PUSHPULL |
62  PAL_STM32_OSPEED_HIGHEST | PAL_STM32_PUPDR_FLOATING | PAL_STM32_MODE_ALTERNATE;
63 
64  palSetPadMode (GPIOC, GPIOC_SDIO_D0, mode | PAL_STM32_PUPDR_PULLUP);
65  palSetPadMode (GPIOC, GPIOC_SDIO_D1, mode | PAL_STM32_PUPDR_PULLUP);
66  palSetPadMode (GPIOC, GPIOC_SDIO_D2, mode | PAL_STM32_PUPDR_PULLUP);
67  palSetPadMode (GPIOC, GPIOC_SDIO_D3, mode | PAL_STM32_PUPDR_PULLUP);
68  palSetPadMode (GPIOC, GPIOC_SDIO_CK, mode);
69  palSetPadMode (GPIOD, GPIOD_SDIO_CMD, mode | PAL_STM32_PUPDR_PULLUP);
70  // palSetPadMode (GPIOD, GPIOD_SDIO_CMD, mode);
71 
72  chThdSleepMilliseconds(100);
73 
74 
75  sdcStart(&SDCD1, NULL);
76  while (sdcConnect(&SDCD1) != HAL_SUCCESS) {
77  chThdSleepMilliseconds(100);
78  }
79 
80  cnxState = CONNECT;
81  return TRUE;
82 }
83 
84 
85 bool sdio_disconnect(void)
86 {
87  if (cnxState == STOP)
88  return TRUE;
89  if (sdcDisconnect(&SDCD1)) {
90  return FALSE;
91  }
92  sdcStop (&SDCD1);
93  cnxState = STOP;
94  return TRUE;
95 }
96 
97 bool is_card_inserted(void)
98 {
99  return sdc_lld_is_card_inserted (NULL);
100 }
101 
Definition: sdio_arch.c:43
#define GPIOC_SDIO_CK
Definition: board.h:105
#define GPIOC_SDIO_D1
Definition: board.h:102
arch independent SDIO API
#define GPIOC_SDIO_D0
Definition: board.h:101
#define GPIOC
Definition: gpio_arch.h:34
bool is_card_inserted(void)
Check if a SD card is inserted.
Definition: sdio_arch.c:97
bool sdio_disconnect(void)
Disconnect a SD card on SDIO peripheral.
Definition: sdio_arch.c:85
#define FALSE
Definition: std.h:5
#define TRUE
Definition: std.h:4
bool sdio_connect(void)
Connect a SD card on SDIO peripheral.
Definition: sdio_arch.c:46
#define GPIOD
Definition: gpio_arch.h:35
#define GPIOC_SDIO_D3
Definition: board.h:104
unsigned long uint32_t
Definition: types.h:18
#define GPIOD_SDIO_CMD
Definition: board.h:110
#define GPIOC_SDIO_D2
Definition: board.h:103
static enum @0 cnxState