Paparazzi UAS  v5.15_devel-230-gc96ce27
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 #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  /*
59  * Initializes the SDIO drivers.
60  *
61  * FIXME This could be hardcoded in board file ?
62  */
63  const uint32_t mode = PAL_MODE_ALTERNATE(SDIO_AF) | PAL_STM32_OTYPE_PUSHPULL |
64  PAL_STM32_OSPEED_HIGHEST | PAL_STM32_PUPDR_FLOATING | PAL_STM32_MODE_ALTERNATE;
65 
66  palSetPadMode (SDIO_D0_PORT, SDIO_D0_PIN, mode | PAL_STM32_PUPDR_PULLUP);
67  palSetPadMode (SDIO_D1_PORT, SDIO_D1_PIN, mode | PAL_STM32_PUPDR_PULLUP);
68  palSetPadMode (SDIO_D2_PORT, SDIO_D2_PIN, mode | PAL_STM32_PUPDR_PULLUP);
69  palSetPadMode (SDIO_D3_PORT, SDIO_D3_PIN, mode | PAL_STM32_PUPDR_PULLUP);
70  palSetPadMode (SDIO_CK_PORT, SDIO_CK_PIN, mode);
71  palSetPadMode (SDIO_CMD_PORT, SDIO_CMD_PIN, mode | PAL_STM32_PUPDR_PULLUP);
72  // palSetPadMode (GPIOD, GPIOD_SDIO_CMD, mode);
73 
74  chThdSleepMilliseconds(100);
75 
76 
77  sdcStart(&SDCD1, NULL);
78  while (sdcConnect(&SDCD1) != HAL_SUCCESS) {
79  chThdSleepMilliseconds(100);
80  }
81 
82  cnxState = CONNECT;
83  return TRUE;
84 }
85 
86 
87 bool sdio_disconnect(void)
88 {
89  if (cnxState == STOP)
90  return TRUE;
91  if (sdcDisconnect(&SDCD1)) {
92  return FALSE;
93  }
94  sdcStop (&SDCD1);
95  cnxState = STOP;
96  return TRUE;
97 }
98 
99 bool is_card_inserted(void)
100 {
101  return sdc_lld_is_card_inserted (NULL);
102 }
103 
Definition: sdio_arch.c:45
#define SDIO_D3_PIN
Definition: board.h:567
#define SDIO_CK_PORT
Definition: board.h:568
arch independent SDIO API
#define SDIO_D3_PORT
Definition: board.h:566
#define SDIO_CMD_PIN
Definition: board.h:571
Some architecture independent helper functions for GPIOs.
bool is_card_inserted(void)
Check if a SD card is inserted.
Definition: sdio_arch.c:99
bool sdio_disconnect(void)
Disconnect a SD card on SDIO peripheral.
Definition: sdio_arch.c:87
#define FALSE
Definition: std.h:5
#define SDIO_D0_PORT
SDIO.
Definition: board.h:560
#define TRUE
Definition: std.h:4
bool sdio_connect(void)
Connect a SD card on SDIO peripheral.
Definition: sdio_arch.c:48
#define SDIO_AF
Definition: board.h:572
unsigned long uint32_t
Definition: types.h:18
#define SDIO_CMD_PORT
Definition: board.h:570
#define SDIO_D2_PORT
Definition: board.h:564
#define SDIO_D2_PIN
Definition: board.h:565
#define SDIO_CK_PIN
Definition: board.h:569
static uint8_t mode
mode holds the current sonar mode mode = 0 used at high altitude, uses 16 wave patterns mode = 1 used...
Definition: sonar_bebop.c:69
#define SDIO_D1_PIN
Definition: board.h:563
static enum @0 cnxState
#define SDIO_D0_PIN
Definition: board.h:561
#define SDIO_D1_PORT
Definition: board.h:562