2009-11-29 00:50:13 -08:00
|
|
|
/*
|
2013-03-30 03:32:37 -07:00
|
|
|
ChibiOS/RT - Copyright (C) 2006-2013 Giovanni Di Sirio
|
2009-11-29 00:50:13 -08:00
|
|
|
|
2013-03-30 03:32:37 -07:00
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
2009-11-29 00:50:13 -08:00
|
|
|
|
2013-03-30 03:32:37 -07:00
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
2009-11-29 00:50:13 -08:00
|
|
|
|
2013-03-30 03:32:37 -07:00
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
2009-11-29 00:50:13 -08:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2010-02-07 03:11:45 -08:00
|
|
|
* @file templates/serial_lld.c
|
|
|
|
* @brief Serial Driver subsystem low level driver source template.
|
|
|
|
*
|
2010-10-25 11:48:13 -07:00
|
|
|
* @addtogroup SERIAL
|
2009-11-29 00:50:13 -08:00
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "ch.h"
|
|
|
|
#include "hal.h"
|
|
|
|
|
2010-11-01 10:29:56 -07:00
|
|
|
#if HAL_USE_SERIAL || defined(__DOXYGEN__)
|
2009-11-29 00:50:13 -08:00
|
|
|
|
2011-08-26 06:47:22 -07:00
|
|
|
/*===========================================================================*/
|
|
|
|
/* Driver local definitions. */
|
|
|
|
/*===========================================================================*/
|
|
|
|
|
2009-11-29 00:50:13 -08:00
|
|
|
/*===========================================================================*/
|
2009-12-29 03:12:05 -08:00
|
|
|
/* Driver exported variables. */
|
2009-11-29 00:50:13 -08:00
|
|
|
/*===========================================================================*/
|
|
|
|
|
2013-02-25 05:10:39 -08:00
|
|
|
/**
|
|
|
|
* @brief SD1 driver identifier.
|
|
|
|
*/
|
|
|
|
#if PLATFORM_SERIAL_USE_SD1 || defined(__DOXYGEN__)
|
|
|
|
SerialDriver SD1;
|
|
|
|
#endif
|
|
|
|
|
2009-11-29 00:50:13 -08:00
|
|
|
/*===========================================================================*/
|
2013-02-28 08:23:19 -08:00
|
|
|
/* Driver local variables and types. */
|
2009-11-29 00:50:13 -08:00
|
|
|
/*===========================================================================*/
|
|
|
|
|
2010-02-07 03:11:45 -08:00
|
|
|
/**
|
|
|
|
* @brief Driver default configuration.
|
|
|
|
*/
|
2010-01-02 05:35:55 -08:00
|
|
|
static const SerialConfig default_config = {
|
2013-02-25 05:10:39 -08:00
|
|
|
38400
|
2009-12-29 03:12:05 -08:00
|
|
|
};
|
|
|
|
|
2009-11-29 00:50:13 -08:00
|
|
|
/*===========================================================================*/
|
2009-12-29 03:12:05 -08:00
|
|
|
/* Driver local functions. */
|
2009-11-29 00:50:13 -08:00
|
|
|
/*===========================================================================*/
|
|
|
|
|
|
|
|
/*===========================================================================*/
|
2009-12-29 03:12:05 -08:00
|
|
|
/* Driver interrupt handlers. */
|
2009-11-29 00:50:13 -08:00
|
|
|
/*===========================================================================*/
|
|
|
|
|
|
|
|
/*===========================================================================*/
|
2009-12-29 03:12:05 -08:00
|
|
|
/* Driver exported functions. */
|
2009-11-29 00:50:13 -08:00
|
|
|
/*===========================================================================*/
|
|
|
|
|
|
|
|
/**
|
2010-02-20 23:24:53 -08:00
|
|
|
* @brief Low level serial driver initialization.
|
2010-10-04 10:16:18 -07:00
|
|
|
*
|
|
|
|
* @notapi
|
2009-11-29 00:50:13 -08:00
|
|
|
*/
|
|
|
|
void sd_lld_init(void) {
|
|
|
|
|
2013-02-25 05:10:39 -08:00
|
|
|
#if PLATFORM_SERIAL_USE_SD1
|
|
|
|
/* Driver initialization.*/
|
|
|
|
sdObjectInit(&SD1);
|
|
|
|
#endif /* PLATFORM_SERIAL_USE_SD1 */
|
2009-11-29 00:50:13 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2010-02-07 03:11:45 -08:00
|
|
|
* @brief Low level serial driver configuration and (re)start.
|
2009-11-29 00:50:13 -08:00
|
|
|
*
|
2010-02-07 03:11:45 -08:00
|
|
|
* @param[in] sdp pointer to a @p SerialDriver object
|
2010-04-21 07:11:12 -07:00
|
|
|
* @param[in] config the architecture-dependent serial driver configuration.
|
|
|
|
* If this parameter is set to @p NULL then a default
|
|
|
|
* configuration is used.
|
2010-10-04 10:16:18 -07:00
|
|
|
*
|
|
|
|
* @notapi
|
2009-11-29 00:50:13 -08:00
|
|
|
*/
|
2010-04-19 08:29:44 -07:00
|
|
|
void sd_lld_start(SerialDriver *sdp, const SerialConfig *config) {
|
2009-11-29 00:50:13 -08:00
|
|
|
|
2010-04-19 08:29:44 -07:00
|
|
|
if (config == NULL)
|
|
|
|
config = &default_config;
|
2009-11-29 00:50:13 -08:00
|
|
|
|
2013-02-25 05:10:39 -08:00
|
|
|
if (sdp->state == SD_STOP) {
|
2013-02-27 02:42:09 -08:00
|
|
|
/* Enables the peripheral.*/
|
2013-02-25 05:10:39 -08:00
|
|
|
#if PLATFORM_SERIAL_USE_SD1
|
|
|
|
if (&SD1 == sdp) {
|
|
|
|
|
|
|
|
}
|
|
|
|
#endif /* PLATFORM_SD_USE_SD1 */
|
|
|
|
}
|
|
|
|
/* Configures the peripheral.*/
|
|
|
|
|
2009-11-29 00:50:13 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2010-02-07 03:11:45 -08:00
|
|
|
* @brief Low level serial driver stop.
|
2009-11-29 00:50:13 -08:00
|
|
|
* @details De-initializes the USART, stops the associated clock, resets the
|
|
|
|
* interrupt vector.
|
|
|
|
*
|
2010-02-07 03:11:45 -08:00
|
|
|
* @param[in] sdp pointer to a @p SerialDriver object
|
2010-10-04 10:16:18 -07:00
|
|
|
*
|
|
|
|
* @notapi
|
2009-11-29 00:50:13 -08:00
|
|
|
*/
|
|
|
|
void sd_lld_stop(SerialDriver *sdp) {
|
|
|
|
|
2013-02-25 05:10:39 -08:00
|
|
|
if (sdp->state == SD_READY) {
|
|
|
|
/* Resets the peripheral.*/
|
|
|
|
|
|
|
|
/* Disables the peripheral.*/
|
|
|
|
#if PLATFORM_SERIAL_USE_SD1
|
|
|
|
if (&SD1 == sdp) {
|
|
|
|
|
|
|
|
}
|
|
|
|
#endif /* PLATFORM_SERIAL_USE_SD1 */
|
|
|
|
}
|
2009-11-29 00:50:13 -08:00
|
|
|
}
|
|
|
|
|
2010-11-01 10:29:56 -07:00
|
|
|
#endif /* HAL_USE_SERIAL */
|
2009-11-29 00:50:13 -08:00
|
|
|
|
|
|
|
/** @} */
|