Revision dd56d656
| core/src/aos_system.c | ||
|---|---|---|
| 239 | 239 |
#else /* (AMIROOS_CFG_SSSP_ENABLE == true) */ |
| 240 | 240 |
_printSystemInfoLine(stream, "AMiRo-OS" , SYSTEM_INFO_NAMEWIDTH, "%u.%u.%u %s", AMIROOS_VERSION_MAJOR, AMIROOS_VERSION_MINOR, AMIROOS_VERSION_PATCH, AMIROOS_RELEASE_TYPE); |
| 241 | 241 |
#endif /* (AMIROOS_CFG_SSSP_ENABLE == true) */ |
| 242 |
_printSystemInfoLine(stream, "AMiRo-LLD" , SYSTEM_INFO_NAMEWIDTH, "%u.%u.%u %s (periphAL %u.%u)", AMIRO_LLD_VERSION_MAJOR, AMIRO_LLD_VERSION_MINOR, AMIRO_LLD_VERSION_PATCH, AMIRO_LLD_RELEASE_TYPE, PERIPHAL_VERSION_MAJOR, PERIPHAL_VERSION_MINOR);
|
|
| 242 |
_printSystemInfoLine(stream, "AMiRo-LLD" , SYSTEM_INFO_NAMEWIDTH, "%u.%u.%u %s (periphAL %u.%u)", AMIROLLD_VERSION_MAJOR, AMIROLLD_VERSION_MINOR, AMIROLLD_VERSION_PATCH, AMIROLLD_RELEASE_TYPE, PERIPHAL_VERSION_MAJOR, PERIPHAL_VERSION_MINOR);
|
|
| 243 | 243 |
_printSystemInfoLine(stream, "ChibiOS/RT" , SYSTEM_INFO_NAMEWIDTH, "%u.%u.%u %s", CH_KERNEL_MAJOR, CH_KERNEL_MINOR, CH_KERNEL_PATCH, (CH_KERNEL_STABLE == 1) ? "stable" : "non-stable"); |
| 244 | 244 |
_printSystemInfoLine(stream, "ChibiOS/HAL", SYSTEM_INFO_NAMEWIDTH, "%u.%u.%u %s", CH_HAL_MAJOR, CH_HAL_MINOR, CH_HAL_PATCH, (CH_HAL_STABLE == 1) ? "stable" : "non-stable"); |
| 245 | 245 |
_printSystemInfoLine(stream, "build type", SYSTEM_INFO_NAMEWIDTH,"%s", (AMIROOS_CFG_DBG == true) ? "debug" : "release"); |
| modules/DiWheelDrive_1-1/alldconf.h | ||
|---|---|---|
| 29 | 29 |
#define ALLDCONF_H |
| 30 | 30 |
|
| 31 | 31 |
/* |
| 32 |
* compatibility guards
|
|
| 32 |
* common configuration
|
|
| 33 | 33 |
*/ |
| 34 |
#define _AMIRO_LLD_CFG_ |
|
| 35 |
#define AMIRO_LLD_CFG_VERSION_MAJOR 1 |
|
| 36 |
#define AMIRO_LLD_CFG_VERSION_MINOR 1 |
|
| 37 |
|
|
| 38 |
/** |
|
| 39 |
* @brief Width of the apalTime_t data type. |
|
| 40 |
* |
|
| 41 |
* @details Possible values are 8, 16, 32, and 64 bits. |
|
| 42 |
* By definition time is represented at microsecond precision. |
|
| 43 |
*/ |
|
| 44 |
#define AMIROLLD_CFG_TIME_SIZE 32 |
|
| 34 |
#include <aos_alldconf.h> |
|
| 45 | 35 |
|
| 46 | 36 |
#endif /* ALLDCONF_H */ |
| 47 | 37 |
|
| modules/DiWheelDrive_1-2/alldconf.h | ||
|---|---|---|
| 29 | 29 |
#define ALLDCONF_H |
| 30 | 30 |
|
| 31 | 31 |
/* |
| 32 |
* compatibility guards
|
|
| 32 |
* common configuration
|
|
| 33 | 33 |
*/ |
| 34 |
#define _AMIRO_LLD_CFG_ |
|
| 35 |
#define AMIRO_LLD_CFG_VERSION_MAJOR 1 |
|
| 36 |
#define AMIRO_LLD_CFG_VERSION_MINOR 1 |
|
| 37 |
|
|
| 38 |
/** |
|
| 39 |
* @brief Width of the apalTime_t data type. |
|
| 40 |
* |
|
| 41 |
* @details Possible values are 8, 16, 32, and 64 bits. |
|
| 42 |
* By definition time is represented at microsecond precision. |
|
| 43 |
*/ |
|
| 44 |
#define AMIROLLD_CFG_TIME_SIZE 32 |
|
| 34 |
#include <aos_alldconf.h> |
|
| 45 | 35 |
|
| 46 | 36 |
#endif /* ALLDCONF_H */ |
| 47 | 37 |
|
| modules/LightRing_1-0/alldconf.h | ||
|---|---|---|
| 29 | 29 |
#define ALLDCONF_H |
| 30 | 30 |
|
| 31 | 31 |
/* |
| 32 |
* compatibility guards
|
|
| 32 |
* common configuration
|
|
| 33 | 33 |
*/ |
| 34 |
#define _AMIRO_LLD_CFG_ |
|
| 35 |
#define AMIRO_LLD_CFG_VERSION_MAJOR 1 |
|
| 36 |
#define AMIRO_LLD_CFG_VERSION_MINOR 1 |
|
| 37 |
|
|
| 38 |
/** |
|
| 39 |
* @brief Width of the apalTime_t data type. |
|
| 40 |
* |
|
| 41 |
* @details Possible values are 8, 16, 32, and 64 bits. |
|
| 42 |
* By definition time is represented at microsecond precision. |
|
| 43 |
*/ |
|
| 44 |
#define AMIROLLD_CFG_TIME_SIZE 32 |
|
| 34 |
#include <aos_alldconf.h> |
|
| 45 | 35 |
|
| 46 | 36 |
#endif /* ALLDCONF_H */ |
| 47 | 37 |
|
| modules/LightRing_1-2/alldconf.h | ||
|---|---|---|
| 28 | 28 |
#ifndef ALLDCONF_H |
| 29 | 29 |
#define ALLDCONF_H |
| 30 | 30 |
|
| 31 |
/* |
|
| 32 |
* compatibility guards |
|
| 33 |
*/ |
|
| 34 |
#define _AMIRO_LLD_CFG_ |
|
| 35 |
#define AMIRO_LLD_CFG_VERSION_MAJOR 1 |
|
| 36 |
#define AMIRO_LLD_CFG_VERSION_MINOR 1 |
|
| 37 |
|
|
| 38 |
/** |
|
| 39 |
* @brief Width of the apalTime_t data type. |
|
| 40 |
* |
|
| 41 |
* @details Possible values are 8, 16, 32, and 64 bits. |
|
| 42 |
* By definition time is represented at microsecond precision. |
|
| 43 |
*/ |
|
| 44 |
#define AMIROLLD_CFG_TIME_SIZE 32 |
|
| 45 |
|
|
| 46 | 31 |
/** |
| 47 | 32 |
* @brief TLC5947 chained configuration |
| 48 | 33 |
*/ |
| 49 | 34 |
#define TLC5947_LLD_CHAINED 3 |
| 50 | 35 |
|
| 36 |
/* |
|
| 37 |
* common configuration |
|
| 38 |
*/ |
|
| 39 |
#include <aos_alldconf.h> |
|
| 40 |
|
|
| 51 | 41 |
#endif /* ALLDCONF_H */ |
| 52 | 42 |
|
| 53 | 43 |
/** @} */ |
| modules/NUCLEO-F103RB/alldconf.h | ||
|---|---|---|
| 29 | 29 |
#define ALLDCONF_H |
| 30 | 30 |
|
| 31 | 31 |
/* |
| 32 |
* compatibility guards
|
|
| 32 |
* common configuration
|
|
| 33 | 33 |
*/ |
| 34 |
#define _AMIRO_LLD_CFG_ |
|
| 35 |
#define AMIRO_LLD_CFG_VERSION_MAJOR 1 |
|
| 36 |
#define AMIRO_LLD_CFG_VERSION_MINOR 1 |
|
| 37 |
|
|
| 38 |
/** |
|
| 39 |
* @brief Width of the apalTime_t data type. |
|
| 40 |
* |
|
| 41 |
* @details Possible values are 8, 16, 32, and 64 bits. |
|
| 42 |
* By definition time is represented at microsecond precision. |
|
| 43 |
*/ |
|
| 44 |
#define AMIROLLD_CFG_TIME_SIZE 32 |
|
| 34 |
#include <aos_alldconf.h> |
|
| 45 | 35 |
|
| 46 | 36 |
#endif /* ALLDCONF_H */ |
| 47 | 37 |
|
| modules/NUCLEO-F401RE/alldconf.h | ||
|---|---|---|
| 29 | 29 |
#define ALLDCONF_H |
| 30 | 30 |
|
| 31 | 31 |
/* |
| 32 |
* compatibility guards
|
|
| 32 |
* common configuration
|
|
| 33 | 33 |
*/ |
| 34 |
#define _AMIRO_LLD_CFG_ |
|
| 35 |
#define AMIRO_LLD_CFG_VERSION_MAJOR 1 |
|
| 36 |
#define AMIRO_LLD_CFG_VERSION_MINOR 1 |
|
| 37 |
|
|
| 38 |
/** |
|
| 39 |
* @brief Width of the apalTime_t data type. |
|
| 40 |
* |
|
| 41 |
* @details Possible values are 8, 16, 32, and 64 bits. |
|
| 42 |
* By definition time is represented at microsecond precision. |
|
| 43 |
*/ |
|
| 44 |
#define AMIROLLD_CFG_TIME_SIZE 32 |
|
| 34 |
#include <aos_alldconf.h> |
|
| 45 | 35 |
|
| 46 | 36 |
#endif /* ALLDCONF_H */ |
| 47 | 37 |
|
| modules/NUCLEO-F767ZI/alldconf.h | ||
|---|---|---|
| 29 | 29 |
#define ALLDCONF_H |
| 30 | 30 |
|
| 31 | 31 |
/* |
| 32 |
* compatibility guards
|
|
| 32 |
* common configuration
|
|
| 33 | 33 |
*/ |
| 34 |
#define _AMIRO_LLD_CFG_ |
|
| 35 |
#define AMIRO_LLD_CFG_VERSION_MAJOR 1 |
|
| 36 |
#define AMIRO_LLD_CFG_VERSION_MINOR 1 |
|
| 37 |
|
|
| 38 |
/** |
|
| 39 |
* @brief Width of the apalTime_t data type. |
|
| 40 |
* |
|
| 41 |
* @details Possible values are 8, 16, 32, and 64 bits. |
|
| 42 |
* By definition time is represented at microsecond precision. |
|
| 43 |
*/ |
|
| 44 |
#define AMIROLLD_CFG_TIME_SIZE 32 |
|
| 34 |
#include <aos_alldconf.h> |
|
| 45 | 35 |
|
| 46 | 36 |
#endif /* ALLDCONF_H */ |
| 47 | 37 |
|
| modules/NUCLEO-L476RG/alldconf.h | ||
|---|---|---|
| 29 | 29 |
#define ALLDCONF_H |
| 30 | 30 |
|
| 31 | 31 |
/* |
| 32 |
* compatibility guards
|
|
| 32 |
* common configuration
|
|
| 33 | 33 |
*/ |
| 34 |
#define _AMIRO_LLD_CFG_ |
|
| 35 |
#define AMIRO_LLD_CFG_VERSION_MAJOR 1 |
|
| 36 |
#define AMIRO_LLD_CFG_VERSION_MINOR 1 |
|
| 37 |
|
|
| 38 |
/** |
|
| 39 |
* @brief Width of the apalTime_t data type. |
|
| 40 |
* |
|
| 41 |
* @details Possible values are 8, 16, 32, and 64 bits. |
|
| 42 |
* By definition time is represented at microsecond precision. |
|
| 43 |
*/ |
|
| 44 |
#define AMIROLLD_CFG_TIME_SIZE 32 |
|
| 34 |
#include <aos_alldconf.h> |
|
| 45 | 35 |
|
| 46 | 36 |
#endif /* ALLDCONF_H */ |
| 47 | 37 |
|
| modules/PowerManagement_1-1/alldconf.h | ||
|---|---|---|
| 28 | 28 |
#ifndef ALLDCONF_H |
| 29 | 29 |
#define ALLDCONF_H |
| 30 | 30 |
|
| 31 |
/* |
|
| 32 |
* compatibility guards |
|
| 33 |
*/ |
|
| 34 |
#define _AMIRO_LLD_CFG_ |
|
| 35 |
#define AMIRO_LLD_CFG_VERSION_MAJOR 1 |
|
| 36 |
#define AMIRO_LLD_CFG_VERSION_MINOR 1 |
|
| 37 |
|
|
| 38 |
/** |
|
| 39 |
* @brief Width of the apalTime_t data type. |
|
| 40 |
* |
|
| 41 |
* @details Possible values are 8, 16, 32, and 64 bits. |
|
| 42 |
* By definition time is represented at microsecond precision. |
|
| 43 |
*/ |
|
| 44 |
#define AMIROLLD_CFG_TIME_SIZE 32 |
|
| 45 |
|
|
| 46 | 31 |
/** |
| 47 | 32 |
* @brief BQ27500 hardware version |
| 48 | 33 |
*/ |
| ... | ... | |
| 55 | 40 |
#define PKxxxExxx_LLD_FREQUENCY_SPEC 4000 |
| 56 | 41 |
#define PKxxxExxx_LLD_FREQUENCY_MAX 6000 |
| 57 | 42 |
|
| 43 |
/* |
|
| 44 |
* common configuration |
|
| 45 |
*/ |
|
| 46 |
#include <aos_alldconf.h> |
|
| 47 |
|
|
| 58 | 48 |
#endif /* ALLDCONF_H */ |
| 59 | 49 |
|
| 60 | 50 |
/** @} */ |
| modules/PowerManagement_1-2/alldconf.h | ||
|---|---|---|
| 28 | 28 |
#ifndef ALLDCONF_H |
| 29 | 29 |
#define ALLDCONF_H |
| 30 | 30 |
|
| 31 |
/* |
|
| 32 |
* compatibility guards |
|
| 33 |
*/ |
|
| 34 |
#define _AMIRO_LLD_CFG_ |
|
| 35 |
#define AMIRO_LLD_CFG_VERSION_MAJOR 1 |
|
| 36 |
#define AMIRO_LLD_CFG_VERSION_MINOR 1 |
|
| 37 |
|
|
| 38 |
/** |
|
| 39 |
* @brief Width of the apalTime_t data type. |
|
| 40 |
* |
|
| 41 |
* @details Possible values are 8, 16, 32, and 64 bits. |
|
| 42 |
* By definition time is represented at microsecond precision. |
|
| 43 |
*/ |
|
| 44 |
#define AMIROLLD_CFG_TIME_SIZE 32 |
|
| 45 |
|
|
| 46 | 31 |
/** |
| 47 | 32 |
* @brief BQ27500 hardware version |
| 48 | 33 |
*/ |
| ... | ... | |
| 55 | 40 |
#define PKxxxExxx_LLD_FREQUENCY_SPEC 4000 |
| 56 | 41 |
#define PKxxxExxx_LLD_FREQUENCY_MAX 6000 |
| 57 | 42 |
|
| 43 |
/* |
|
| 44 |
* common configuration |
|
| 45 |
*/ |
|
| 46 |
#include <aos_alldconf.h> |
|
| 47 |
|
|
| 58 | 48 |
#endif /* ALLDCONF_H */ |
| 59 | 49 |
|
| 60 | 50 |
/** @} */ |
| modules/STM32F407G-DISC1/alldconf.h | ||
|---|---|---|
| 29 | 29 |
#define ALLDCONF_H |
| 30 | 30 |
|
| 31 | 31 |
/* |
| 32 |
* compatibility guards
|
|
| 32 |
* common configuration
|
|
| 33 | 33 |
*/ |
| 34 |
#define _AMIRO_LLD_CFG_ |
|
| 35 |
#define AMIRO_LLD_CFG_VERSION_MAJOR 1 |
|
| 36 |
#define AMIRO_LLD_CFG_VERSION_MINOR 1 |
|
| 37 |
|
|
| 38 |
/** |
|
| 39 |
* @brief Width of the apalTime_t data type. |
|
| 40 |
* |
|
| 41 |
* @details Possible values are 8, 16, 32, and 64 bits. |
|
| 42 |
* By definition time is represented at microsecond precision. |
|
| 43 |
*/ |
|
| 44 |
#define AMIROLLD_CFG_TIME_SIZE 32 |
|
| 34 |
#include <aos_alldconf.h> |
|
| 45 | 35 |
|
| 46 | 36 |
#endif /* ALLDCONF_H */ |
| 47 | 37 |
|
| periphery-lld/AMiRo-LLD | ||
|---|---|---|
| 1 |
Subproject commit bb7c53481afaa76d993538c5e2b2eae430cfb441 |
|
| 1 |
Subproject commit 1304b12bd859603ad9f9b68493e1a3257f5e4595 |
|
| periphery-lld/aos_alldconf.h | ||
|---|---|---|
| 1 |
/* |
|
| 2 |
AMiRo-OS is an operating system designed for the Autonomous Mini Robot (AMiRo) platform. |
|
| 3 |
Copyright (C) 2016..2019 Thomas Schöpping et al. |
|
| 4 |
|
|
| 5 |
This program is free software: you can redistribute it and/or modify |
|
| 6 |
it under the terms of the GNU General Public License as published by |
|
| 7 |
the Free Software Foundation, either version 3 of the License, or |
|
| 8 |
(at your option) any later version. |
|
| 9 |
|
|
| 10 |
This program is distributed in the hope that it will be useful, |
|
| 11 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 12 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
| 13 |
GNU General Public License for more details. |
|
| 14 |
|
|
| 15 |
You should have received a copy of the GNU General Public License |
|
| 16 |
along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
| 17 |
*/ |
|
| 18 |
|
|
| 19 |
/** |
|
| 20 |
* @file |
|
| 21 |
* @brief Common AMiRo-LLD configuration file for all modules. |
|
| 22 |
* @details Contains common AMiRo-LLD settings. |
|
| 23 |
* @{
|
|
| 24 |
*/ |
|
| 25 |
|
|
| 26 |
#ifndef AOS_ALLDCONF_H |
|
| 27 |
#define AOS_ALLDCONF_H |
|
| 28 |
|
|
| 29 |
#define _AMIRO_LLD_CFG_ |
|
| 30 |
#define AMIRO_LLD_CFG_VERSION_MAJOR 1 |
|
| 31 |
#define AMIRO_LLD_CFG_VERSION_MINOR 1 |
|
| 32 |
|
|
| 33 |
#include <aosconf.h> |
|
| 34 |
#include <hal.h> |
|
| 35 |
|
|
| 36 |
/** |
|
| 37 |
* @brief Width of the apalTime_t data type. |
|
| 38 |
* |
|
| 39 |
* @details Possible values are 8, 16, 32, and 64 bits. |
|
| 40 |
* By definition time is represented at microsecond precision. |
|
| 41 |
*/ |
|
| 42 |
#if !defined(AMIROLLD_CFG_TIME_SIZE) |
|
| 43 |
#define AMIROLLD_CFG_TIME_SIZE 32 |
|
| 44 |
#endif |
|
| 45 |
|
|
| 46 |
/** |
|
| 47 |
* @brief Flag to enable/disable DBG API. |
|
| 48 |
*/ |
|
| 49 |
#if !defined(AMIROLLD_CFG_DBG) |
|
| 50 |
#define AMIROLLD_CFG_DBG AMIROOS_CFG_DBG |
|
| 51 |
#endif |
|
| 52 |
|
|
| 53 |
/** |
|
| 54 |
* @brief Flag to enable/disable GPIO API. |
|
| 55 |
*/ |
|
| 56 |
#if !defined(AMIROLLD_CFG_GPIO) |
|
| 57 |
#if (HAL_USE_PAL == TRUE) |
|
| 58 |
#define AMIROLLD_CFG_GPIO true |
|
| 59 |
#else |
|
| 60 |
#define AMIROLLD_CFG_GPIO false |
|
| 61 |
#endif |
|
| 62 |
#endif |
|
| 63 |
|
|
| 64 |
/** |
|
| 65 |
* @brief Flag to enable/disable PWM API. |
|
| 66 |
*/ |
|
| 67 |
#if !defined(AMIROLLD_CFG_PWM) |
|
| 68 |
#if (HAL_USE_PWM == TRUE) |
|
| 69 |
#define AMIROLLD_CFG_PWM true |
|
| 70 |
#else |
|
| 71 |
#define AMIROLLD_CFG_PWM false |
|
| 72 |
#endif |
|
| 73 |
#endif |
|
| 74 |
|
|
| 75 |
/** |
|
| 76 |
* @brief Flag to enable/disable QEI API. |
|
| 77 |
*/ |
|
| 78 |
#if !defined(AMIROLLD_CFG_QEI) |
|
| 79 |
#if (HAL_USE_QEI == TRUE) |
|
| 80 |
#define AMIROLLD_CFG_QEI true |
|
| 81 |
#else |
|
| 82 |
#define AMIROLLD_CFG_QEI false |
|
| 83 |
#endif |
|
| 84 |
#endif |
|
| 85 |
|
|
| 86 |
/** |
|
| 87 |
* @brief Flag to enable/disable I2C API. |
|
| 88 |
*/ |
|
| 89 |
#if !defined(AMIROLLD_CFG_I2C) |
|
| 90 |
#if (HAL_USE_I2C == TRUE) |
|
| 91 |
#define AMIROLLD_CFG_I2C true |
|
| 92 |
#else |
|
| 93 |
#define AMIROLLD_CFG_I2C false |
|
| 94 |
#endif |
|
| 95 |
#endif |
|
| 96 |
|
|
| 97 |
/** |
|
| 98 |
* @brief Flag to enable/disable SPI API. |
|
| 99 |
*/ |
|
| 100 |
#if !defined(AMIROLLD_CFG_SPI) |
|
| 101 |
#if (HAL_USE_SPI == TRUE) |
|
| 102 |
#define AMIROLLD_CFG_SPI true |
|
| 103 |
#else |
|
| 104 |
#define AMIROLLD_CFG_SPI false |
|
| 105 |
#endif |
|
| 106 |
#endif |
|
| 107 |
|
|
| 108 |
/** |
|
| 109 |
* @brief Hook macro to insert a custom header to periphAL.h file. |
|
| 110 |
*/ |
|
| 111 |
#if !defined(AMIROLLD_CFG_PERIPHAL_HEADER) |
|
| 112 |
#define AMIROLLD_CFG_PERIPHAL_HEADER <aos_periphAL.h> |
|
| 113 |
#endif |
|
| 114 |
|
|
| 115 |
#endif /* AOS_ALLDCONF_H */ |
|
| 116 |
|
|
| 117 |
/** @} */ |
|
| periphery-lld/aos_periphAL.c | ||
|---|---|---|
| 1 |
/* |
|
| 2 |
AMiRo-OS is an operating system designed for the Autonomous Mini Robot (AMiRo) platform. |
|
| 3 |
Copyright (C) 2016..2019 Thomas Schöpping et al. |
|
| 4 |
|
|
| 5 |
This program is free software: you can redistribute it and/or modify |
|
| 6 |
it under the terms of the GNU General Public License as published by |
|
| 7 |
the Free Software Foundation, either version 3 of the License, or |
|
| 8 |
(at your option) any later version. |
|
| 9 |
|
|
| 10 |
This program is distributed in the hope that it will be useful, |
|
| 11 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 12 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
| 13 |
GNU General Public License for more details. |
|
| 14 |
|
|
| 15 |
You should have received a copy of the GNU General Public License |
|
| 16 |
along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
| 17 |
*/ |
|
| 18 |
|
|
| 19 |
#include <periphAL.h> |
|
| 20 |
|
|
| 21 |
/*============================================================================*/ |
|
| 22 |
/* DEBUG */ |
|
| 23 |
/*============================================================================*/ |
|
| 24 |
|
|
| 25 |
#if (AMIROOS_CFG_DBG == true) |
|
| 26 |
|
|
| 27 |
#include <amiroos.h> |
|
| 28 |
#include <chprintf.h> |
|
| 29 |
|
|
| 30 |
void apalDbgAssertMsg(const bool c, const char* fmt, ...) |
|
| 31 |
{
|
|
| 32 |
if (!c) {
|
|
| 33 |
va_list ap; |
|
| 34 |
|
|
| 35 |
va_start(ap, fmt); |
|
| 36 |
chvprintf((BaseSequentialStream*)&aos.iostream, fmt, ap); |
|
| 37 |
va_end(ap); |
|
| 38 |
chThdExit(MSG_RESET); |
|
| 39 |
} |
|
| 40 |
|
|
| 41 |
return; |
|
| 42 |
} |
|
| 43 |
|
|
| 44 |
int apalDbgPrintf(const char* fmt, ...) |
|
| 45 |
{
|
|
| 46 |
va_list ap; |
|
| 47 |
|
|
| 48 |
va_start(ap, fmt); |
|
| 49 |
const int chars = chvprintf((BaseSequentialStream*)&aos.iostream, fmt, ap); |
|
| 50 |
va_end(ap); |
|
| 51 |
|
|
| 52 |
return chars; |
|
| 53 |
} |
|
| 54 |
|
|
| 55 |
#endif /* (AMIROOS_CFG_DBG == true) */ |
|
| 56 |
|
|
| 57 |
/*============================================================================*/ |
|
| 58 |
/* TIMING */ |
|
| 59 |
/*============================================================================*/ |
|
| 60 |
|
|
| 61 |
#if (AMIROOS_CFG_DBG == true) |
|
| 62 |
|
|
| 63 |
void apalSleep(apalTime_t us) |
|
| 64 |
{
|
|
| 65 |
// check if the specified time can be represented by the system |
|
| 66 |
apalDbgAssert(us <= chTimeI2US(TIME_INFINITE)); |
|
| 67 |
|
|
| 68 |
const sysinterval_t interval = chTimeUS2I(us); |
|
| 69 |
// TIME_IMMEDIATE makes no sense and would even cause system halt |
|
| 70 |
if (interval != TIME_IMMEDIATE) {
|
|
| 71 |
chThdSleep(interval); |
|
| 72 |
} |
|
| 73 |
|
|
| 74 |
return; |
|
| 75 |
} |
|
| 76 |
|
|
| 77 |
#endif /* (AMIROOS_CFG_DBG == true) */ |
|
| 78 |
|
|
| 79 |
/*============================================================================*/ |
|
| 80 |
/* GPIO */ |
|
| 81 |
/*============================================================================*/ |
|
| 82 |
|
|
| 83 |
#if (HAL_USE_PAL == TRUE) |
|
| 84 |
|
|
| 85 |
apalExitStatus_t apalGpioRead(apalGpio_t* gpio, apalGpioState_t* const val) |
|
| 86 |
{
|
|
| 87 |
apalDbgAssert(gpio != NULL); |
|
| 88 |
apalDbgAssert(val != NULL); |
|
| 89 |
|
|
| 90 |
*val = (palReadLine(gpio->line) == PAL_HIGH) ? APAL_GPIO_HIGH : APAL_GPIO_LOW; |
|
| 91 |
|
|
| 92 |
return APAL_STATUS_OK; |
|
| 93 |
} |
|
| 94 |
|
|
| 95 |
apalExitStatus_t apalGpioWrite(apalGpio_t* gpio, const apalGpioState_t val) |
|
| 96 |
{
|
|
| 97 |
apalDbgAssert(gpio != NULL); |
|
| 98 |
|
|
| 99 |
// palWriteLine() is not guaranteed to be atomic, thus the scheduler is locked. |
|
| 100 |
syssts_t sysstatus = chSysGetStatusAndLockX(); |
|
| 101 |
palWriteLine(gpio->line, (val == APAL_GPIO_HIGH) ? PAL_HIGH : PAL_LOW); |
|
| 102 |
chSysRestoreStatusX(sysstatus); |
|
| 103 |
|
|
| 104 |
return APAL_STATUS_OK; |
|
| 105 |
} |
|
| 106 |
|
|
| 107 |
apalExitStatus_t apalGpioToggle(apalGpio_t* gpio) |
|
| 108 |
{
|
|
| 109 |
apalDbgAssert(gpio != NULL); |
|
| 110 |
|
|
| 111 |
// palWriteLine() is not guaranteed to be atomic, thus the scheduler is locked. |
|
| 112 |
syssts_t sysstatus = chSysGetStatusAndLockX(); |
|
| 113 |
palWriteLine(gpio->line, (palReadLine(gpio->line) == PAL_HIGH) ? PAL_LOW : PAL_HIGH); |
|
| 114 |
chSysRestoreStatusX(sysstatus); |
|
| 115 |
|
|
| 116 |
return APAL_STATUS_OK; |
|
| 117 |
} |
|
| 118 |
|
|
| 119 |
apalExitStatus_t apalGpioIsInterruptEnabled(apalGpio_t* gpio, bool* const enabled) |
|
| 120 |
{
|
|
| 121 |
apalDbgAssert(gpio != NULL); |
|
| 122 |
apalDbgAssert(enabled != NULL); |
|
| 123 |
|
|
| 124 |
*enabled = palIsLineEventEnabledX(gpio->line); |
|
| 125 |
|
|
| 126 |
return APAL_STATUS_OK; |
|
| 127 |
} |
|
| 128 |
|
|
| 129 |
apalExitStatus_t apalControlGpioGet(const apalControlGpio_t* const cgpio, apalControlGpioState_t* const val) |
|
| 130 |
{
|
|
| 131 |
apalDbgAssert(cgpio != NULL); |
|
| 132 |
apalDbgAssert(cgpio->gpio != NULL); |
|
| 133 |
apalDbgAssert(val != NULL); |
|
| 134 |
|
|
| 135 |
*val = ((palReadLine(cgpio->gpio->line) == PAL_HIGH) ^ (cgpio->meta.active == APAL_GPIO_ACTIVE_HIGH)) ? APAL_GPIO_OFF : APAL_GPIO_ON; |
|
| 136 |
|
|
| 137 |
return APAL_STATUS_OK; |
|
| 138 |
} |
|
| 139 |
|
|
| 140 |
apalExitStatus_t apalControlGpioSet(const apalControlGpio_t* const cgpio, const apalControlGpioState_t val) |
|
| 141 |
{
|
|
| 142 |
apalDbgAssert(cgpio != NULL); |
|
| 143 |
apalDbgAssert(cgpio->gpio != NULL); |
|
| 144 |
apalDbgAssert(cgpio->meta.direction == APAL_GPIO_DIRECTION_OUTPUT || cgpio->meta.direction == APAL_GPIO_DIRECTION_BIDIRECTIONAL); |
|
| 145 |
|
|
| 146 |
// palWriteLine() is not guaranteed to be atomic, thus the scheduler is locked. |
|
| 147 |
syssts_t sysstatus = chSysGetStatusAndLockX(); |
|
| 148 |
palWriteLine(cgpio->gpio->line, ((cgpio->meta.active == APAL_GPIO_ACTIVE_HIGH) ^ (val == APAL_GPIO_ON)) ? PAL_LOW : PAL_HIGH); |
|
| 149 |
chSysRestoreStatusX(sysstatus); |
|
| 150 |
|
|
| 151 |
return APAL_STATUS_OK; |
|
| 152 |
} |
|
| 153 |
|
|
| 154 |
apalExitStatus_t apalControlGpioSetInterrupt(const apalControlGpio_t* const cgpio, const bool enable) |
|
| 155 |
{
|
|
| 156 |
apalDbgAssert(cgpio != NULL); |
|
| 157 |
apalDbgAssert(cgpio->gpio != NULL); |
|
| 158 |
|
|
| 159 |
if (enable) {
|
|
| 160 |
apalDbgAssert(pal_lld_get_line_event(cgpio->gpio->line) != NULL); |
|
| 161 |
palEnableLineEvent(cgpio->gpio->line, APAL2CH_EDGE(cgpio->meta.edge)); |
|
| 162 |
} else {
|
|
| 163 |
palDisableLineEvent(cgpio->gpio->line); |
|
| 164 |
} |
|
| 165 |
|
|
| 166 |
return APAL_STATUS_OK; |
|
| 167 |
} |
|
| 168 |
|
|
| 169 |
#endif /* (HAL_USE_PAL == TRUE) */ |
|
| 170 |
|
|
| 171 |
/*============================================================================*/ |
|
| 172 |
/* PWM */ |
|
| 173 |
/*============================================================================*/ |
|
| 174 |
|
|
| 175 |
#if (HAL_USE_PWM == TRUE) |
|
| 176 |
|
|
| 177 |
apalExitStatus_t apalPWMSet(apalPWMDriver_t* pwm, const apalPWMchannel_t channel, const apalPWMwidth_t width) |
|
| 178 |
{
|
|
| 179 |
apalDbgAssert(pwm != NULL); |
|
| 180 |
|
|
| 181 |
pwmEnableChannel(pwm, (pwmchannel_t)channel, pwm->period * ((float)width / (float)APAL_PWM_WIDTH_MAX) + 0.5f); |
|
| 182 |
|
|
| 183 |
return APAL_STATUS_OK; |
|
| 184 |
} |
|
| 185 |
|
|
| 186 |
apalExitStatus_t apalPWMGetFrequency(apalPWMDriver_t* pwm, apalPWMfrequency_t* const frequency) |
|
| 187 |
{
|
|
| 188 |
apalDbgAssert(pwm != NULL); |
|
| 189 |
apalDbgAssert(frequency != NULL); |
|
| 190 |
|
|
| 191 |
*frequency = pwm->config->frequency; |
|
| 192 |
|
|
| 193 |
return APAL_STATUS_OK; |
|
| 194 |
} |
|
| 195 |
|
|
| 196 |
apalExitStatus_t apalPWMGetPeriod(apalPWMDriver_t* pwm, apalPWMperiod_t* const period) |
|
| 197 |
{
|
|
| 198 |
apalDbgAssert(pwm != NULL); |
|
| 199 |
apalDbgAssert(period != NULL); |
|
| 200 |
|
|
| 201 |
*period = pwm->period; |
|
| 202 |
|
|
| 203 |
return APAL_STATUS_OK; |
|
| 204 |
} |
|
| 205 |
|
|
| 206 |
#endif /* (HAL_USE_PWM == TRUE) */ |
|
| 207 |
|
|
| 208 |
/*============================================================================*/ |
|
| 209 |
/* QEI */ |
|
| 210 |
/*============================================================================*/ |
|
| 211 |
|
|
| 212 |
#if (HAL_USE_QEI == TRUE) |
|
| 213 |
|
|
| 214 |
apalExitStatus_t apalQEIGetDirection(apalQEIDriver_t* qei, apalQEIDirection_t* const direction) |
|
| 215 |
{
|
|
| 216 |
apalDbgAssert(qei != NULL); |
|
| 217 |
apalDbgAssert(direction != NULL); |
|
| 218 |
|
|
| 219 |
*direction = (qei_lld_get_direction(qei)) ? APAL_QEI_DIRECTION_DOWN : APAL_QEI_DIRECTION_UP; |
|
| 220 |
|
|
| 221 |
return APAL_STATUS_OK; |
|
| 222 |
} |
|
| 223 |
|
|
| 224 |
apalExitStatus_t apalQEIGetPosition(apalQEIDriver_t* qei, apalQEICount_t* const position) |
|
| 225 |
{
|
|
| 226 |
apalDbgAssert(qei != NULL); |
|
| 227 |
apalDbgAssert(position != NULL); |
|
| 228 |
|
|
| 229 |
*position = qei_lld_get_position(qei); |
|
| 230 |
|
|
| 231 |
return APAL_STATUS_OK; |
|
| 232 |
} |
|
| 233 |
|
|
| 234 |
apalExitStatus_t apalQEIGetRange(apalQEIDriver_t* qei, apalQEICount_t* const range) |
|
| 235 |
{
|
|
| 236 |
apalDbgAssert(qei != NULL); |
|
| 237 |
apalDbgAssert(range != NULL); |
|
| 238 |
|
|
| 239 |
*range = qei_lld_get_range(qei); |
|
| 240 |
|
|
| 241 |
return APAL_STATUS_OK; |
|
| 242 |
} |
|
| 243 |
|
|
| 244 |
#endif /* (HAL_USE_QEI == TRUE) */ |
|
| 245 |
|
|
| 246 |
/*============================================================================*/ |
|
| 247 |
/* I2C */ |
|
| 248 |
/*============================================================================*/ |
|
| 249 |
|
|
| 250 |
#if (HAL_USE_I2C == TRUE) || defined(__DOXYGEN__) |
|
| 251 |
|
|
| 252 |
apalExitStatus_t apalI2CMasterTransmit(apalI2CDriver_t* i2cd, const apalI2Caddr_t addr, const uint8_t* const txbuf, const size_t txbytes, uint8_t* const rxbuf, const size_t rxbytes, const apalTime_t timeout) |
|
| 253 |
{
|
|
| 254 |
apalDbgAssert(i2cd != NULL); |
|
| 255 |
|
|
| 256 |
#if (I2C_USE_MUTUAL_EXCLUSION == TRUE) |
|
| 257 |
// check whether the I2C driver was locked externally |
|
| 258 |
const bool i2cd_locked_external = i2cd->mutex.owner == currp; |
|
| 259 |
if (!i2cd_locked_external) {
|
|
| 260 |
i2cAcquireBus(i2cd); |
|
| 261 |
} |
|
| 262 |
#endif /* (I2C_USE_MUTUAL_EXCLUSION == TRUE) */ |
|
| 263 |
|
|
| 264 |
#pragma GCC diagnostic push |
|
| 265 |
#pragma GCC diagnostic ignored "-Wtype-limits" |
|
| 266 |
#if defined(STM32F1XX_I2C) |
|
| 267 |
// Due to a hardware limitation, for STM32F1 platform the minimum number of bytes that can be received is two. |
|
| 268 |
msg_t status = MSG_OK; |
|
| 269 |
if (rxbytes == 1) {
|
|
| 270 |
uint8_t buffer[2]; |
|
| 271 |
status = i2cMasterTransmitTimeout(i2cd, addr, txbuf, txbytes, buffer, 2, ((timeout >= TIME_INFINITE) ? TIME_INFINITE : TIME_US2I(timeout)) ); |
|
| 272 |
rxbuf[0] = buffer[0]; |
|
| 273 |
} else {
|
|
| 274 |
status = i2cMasterTransmitTimeout(i2cd, addr, txbuf, txbytes, rxbuf, rxbytes, ((timeout >= TIME_INFINITE) ? TIME_INFINITE : TIME_US2I(timeout)) ); |
|
| 275 |
} |
|
| 276 |
#else /* defined(STM32F1XX_I2C) */ |
|
| 277 |
const msg_t status = i2cMasterTransmitTimeout(i2cd, addr, txbuf, txbytes, rxbuf, rxbytes, ((timeout >= TIME_INFINITE) ? TIME_INFINITE : TIME_US2I(timeout)) ); |
|
| 278 |
#endif /* defined(STM32F1XX_I2C) */ |
|
| 279 |
#pragma GCC diagnostic pop |
|
| 280 |
|
|
| 281 |
#if (I2C_USE_MUTUAL_EXCLUSION == TRUE) |
|
| 282 |
if (!i2cd_locked_external) {
|
|
| 283 |
i2cReleaseBus(i2cd); |
|
| 284 |
} |
|
| 285 |
#endif /* (I2C_USE_MUTUAL_EXCLUSION == TRUE) */ |
|
| 286 |
|
|
| 287 |
switch (status) |
|
| 288 |
{
|
|
| 289 |
case MSG_OK: |
|
| 290 |
#if defined(STM32F1XX_I2C) |
|
| 291 |
return (rxbytes != 1) ? APAL_STATUS_OK : APAL_STATUS_WARNING; |
|
| 292 |
#else /* defined(STM32F1XX_I2C) */ |
|
| 293 |
return APAL_STATUS_OK; |
|
| 294 |
#endif /* defined(STM32F1XX_I2C) */ |
|
| 295 |
case MSG_TIMEOUT: |
|
| 296 |
return APAL_STATUS_TIMEOUT; |
|
| 297 |
case MSG_RESET: |
|
| 298 |
default: |
|
| 299 |
return APAL_STATUS_ERROR; |
|
| 300 |
} |
|
| 301 |
} |
|
| 302 |
|
|
| 303 |
apalExitStatus_t apalI2CMasterReceive(apalI2CDriver_t* i2cd, const apalI2Caddr_t addr, uint8_t* const rxbuf, const size_t rxbytes, const apalTime_t timeout) |
|
| 304 |
{
|
|
| 305 |
apalDbgAssert(i2cd != NULL); |
|
| 306 |
|
|
| 307 |
#if (I2C_USE_MUTUAL_EXCLUSION == TRUE) |
|
| 308 |
// check whether the I2C driver was locked externally |
|
| 309 |
const bool i2cd_locked_external = i2cd->mutex.owner == currp; |
|
| 310 |
if (!i2cd_locked_external) {
|
|
| 311 |
i2cAcquireBus(i2cd); |
|
| 312 |
} |
|
| 313 |
#endif /* (I2C_USE_MUTUAL_EXCLUSION == TRUE) */ |
|
| 314 |
|
|
| 315 |
#pragma GCC diagnostic push |
|
| 316 |
#pragma GCC diagnostic ignored "-Wtype-limits" |
|
| 317 |
#if defined(STM32F1XX_I2C) |
|
| 318 |
// Due to a hardware limitation, for STM32F1 platform the minimum number of bytes that can be received is two. |
|
| 319 |
msg_t status = MSG_OK; |
|
| 320 |
if (rxbytes == 1) {
|
|
| 321 |
uint8_t buffer[2]; |
|
| 322 |
status = i2cMasterReceiveTimeout(i2cd, addr, buffer, 2, ((timeout >= TIME_INFINITE) ? TIME_INFINITE : TIME_US2I(timeout)) ); |
|
| 323 |
rxbuf[0] = buffer[0]; |
|
| 324 |
} else {
|
|
| 325 |
status = i2cMasterReceiveTimeout(i2cd, addr, rxbuf, rxbytes, ((timeout >= TIME_INFINITE) ? TIME_INFINITE : TIME_US2I(timeout)) ); |
|
| 326 |
} |
|
| 327 |
#else /* defined(STM32F1XX_I2C) */ |
|
| 328 |
const msg_t status = i2cMasterReceiveTimeout(i2cd, addr, rxbuf, rxbytes, ((timeout >= TIME_INFINITE) ? TIME_INFINITE : TIME_US2I(timeout)) ); |
|
| 329 |
#endif /* defined(STM32F1XX_I2C) */ |
|
| 330 |
#pragma GCC diagnostic pop |
|
| 331 |
|
|
| 332 |
#if (I2C_USE_MUTUAL_EXCLUSION == TRUE) |
|
| 333 |
if (!i2cd_locked_external) {
|
|
| 334 |
i2cReleaseBus(i2cd); |
|
| 335 |
} |
|
| 336 |
#endif /* (I2C_USE_MUTUAL_EXCLUSION == TRUE) */ |
|
| 337 |
|
|
| 338 |
switch (status) |
|
| 339 |
{
|
|
| 340 |
case MSG_OK: |
|
| 341 |
#if defined(STM32F1XX_I2C) |
|
| 342 |
return (rxbytes != 1) ? APAL_STATUS_OK : APAL_STATUS_WARNING; |
|
| 343 |
#else /* defined(STM32F1XX_I2C) */ |
|
| 344 |
return APAL_STATUS_OK; |
|
| 345 |
#endif /* defined(STM32F1XX_I2C) */ |
|
| 346 |
case MSG_TIMEOUT: |
|
| 347 |
return APAL_STATUS_TIMEOUT; |
|
| 348 |
case MSG_RESET: |
|
| 349 |
default: |
|
| 350 |
return APAL_STATUS_ERROR; |
|
| 351 |
} |
|
| 352 |
} |
|
| 353 |
|
|
| 354 |
#endif /* (HAL_USE_I2C == TRUE) */ |
|
| 355 |
|
|
| 356 |
/*============================================================================*/ |
|
| 357 |
/* SPI */ |
|
| 358 |
/*============================================================================*/ |
|
| 359 |
|
|
| 360 |
#if (HAL_USE_SPI == TRUE) || defined(__DOXYGEN__) |
|
| 361 |
|
|
| 362 |
apalExitStatus_t apalSPITransmit(apalSPIDriver_t* spid, const uint8_t* const data, const size_t length) |
|
| 363 |
{
|
|
| 364 |
apalDbgAssert(spid != NULL); |
|
| 365 |
|
|
| 366 |
#if (SPI_USE_MUTUAL_EXCLUSION == TRUE) |
|
| 367 |
// check whether the SPI driver was locked externally |
|
| 368 |
const bool spid_locked_external = spid->mutex.owner == currp; |
|
| 369 |
if (!spid_locked_external) {
|
|
| 370 |
spiAcquireBus(spid); |
|
| 371 |
} |
|
| 372 |
#endif /* (SPI_USE_MUTUAL_EXCLUSION == TRUE) */ |
|
| 373 |
|
|
| 374 |
spiSelect(spid); |
|
| 375 |
spiSend(spid, length, data); |
|
| 376 |
spiUnselect(spid); |
|
| 377 |
|
|
| 378 |
#if (SPI_USE_MUTUAL_EXCLUSION == TRUE) |
|
| 379 |
if (!spid_locked_external) {
|
|
| 380 |
spiReleaseBus(spid); |
|
| 381 |
} |
|
| 382 |
#endif /* (SPI_USE_MUTUAL_EXCLUSION == TRUE) */ |
|
| 383 |
|
|
| 384 |
return APAL_STATUS_OK; |
|
| 385 |
} |
|
| 386 |
|
|
| 387 |
apalExitStatus_t apalSPIReceive(apalSPIDriver_t* spid, uint8_t* const data, const size_t length) |
|
| 388 |
{
|
|
| 389 |
apalDbgAssert(spid != NULL); |
|
| 390 |
|
|
| 391 |
#if (SPI_USE_MUTUAL_EXCLUSION == TRUE) |
|
| 392 |
// check whether the SPI driver was locked externally |
|
| 393 |
const bool spid_locked_external = spid->mutex.owner == currp; |
|
| 394 |
if (!spid_locked_external) {
|
|
| 395 |
spiAcquireBus(spid); |
|
| 396 |
} |
|
| 397 |
#endif /* (SPI_USE_MUTUAL_EXCLUSION == TRUE) */ |
|
| 398 |
|
|
| 399 |
spiSelect(spid); |
|
| 400 |
spiReceive(spid, length, data); |
|
| 401 |
spiUnselect(spid); |
|
| 402 |
|
|
| 403 |
#if (SPI_USE_MUTUAL_EXCLUSION == TRUE) |
|
| 404 |
if (!spid_locked_external) {
|
|
| 405 |
spiReleaseBus(spid); |
|
| 406 |
} |
|
| 407 |
#endif /* (SPI_USE_MUTUAL_EXCLUSION == TRUE) */ |
|
| 408 |
|
|
| 409 |
return APAL_STATUS_OK; |
|
| 410 |
} |
|
| 411 |
|
|
| 412 |
apalExitStatus_t apalSPITransmitAndReceive(apalSPIDriver_t* spid, const uint8_t* const txData , uint8_t* const rxData, const size_t txLength, const size_t rxLength) |
|
| 413 |
{
|
|
| 414 |
apalDbgAssert(spid != NULL); |
|
| 415 |
|
|
| 416 |
#if (SPI_USE_MUTUAL_EXCLUSION == TRUE) |
|
| 417 |
// check whether the SPI driver was locked externally |
|
| 418 |
const bool spid_locked_external = spid->mutex.owner == currp; |
|
| 419 |
if (!spid_locked_external) {
|
|
| 420 |
spiAcquireBus(spid); |
|
| 421 |
} |
|
| 422 |
#endif /* (SPI_USE_MUTUAL_EXCLUSION == TRUE) */ |
|
| 423 |
|
|
| 424 |
spiSelect(spid); |
|
| 425 |
spiSend(spid, txLength, txData); |
|
| 426 |
spiReceive(spid, rxLength, rxData); |
|
| 427 |
spiUnselect(spid); |
|
| 428 |
|
|
| 429 |
#if (SPI_USE_MUTUAL_EXCLUSION == TRUE) |
|
| 430 |
if (!spid_locked_external) {
|
|
| 431 |
spiReleaseBus(spid); |
|
| 432 |
} |
|
| 433 |
#endif /* (SPI_USE_MUTUAL_EXCLUSION == TRUE) */ |
|
| 434 |
|
|
| 435 |
return APAL_STATUS_OK; |
|
| 436 |
} |
|
| 437 |
|
|
| 438 |
apalExitStatus_t apalSPIExchange(apalSPIDriver_t* spid, const uint8_t* const txData , uint8_t* const rxData, const size_t length) |
|
| 439 |
{
|
|
| 440 |
apalDbgAssert(spid != NULL); |
|
| 441 |
|
|
| 442 |
#if (SPI_USE_MUTUAL_EXCLUSION == TRUE) |
|
| 443 |
// check whether the SPI driver was locked externally |
|
| 444 |
const bool spid_locked_external = spid->mutex.owner == currp; |
|
| 445 |
if (!spid_locked_external) {
|
|
| 446 |
spiAcquireBus(spid); |
|
| 447 |
} |
|
| 448 |
#endif /* (SPI_USE_MUTUAL_EXCLUSION == TRUE) */ |
|
| 449 |
|
|
| 450 |
spiSelect(spid); |
|
| 451 |
spiExchange(spid, length, txData, rxData); |
|
| 452 |
spiUnselect(spid); |
|
| 453 |
|
|
| 454 |
#if (SPI_USE_MUTUAL_EXCLUSION == TRUE) |
|
| 455 |
if (!spid_locked_external) {
|
|
| 456 |
spiReleaseBus(spid); |
|
| 457 |
} |
|
| 458 |
#endif /* (SPI_USE_MUTUAL_EXCLUSION == TRUE) */ |
|
| 459 |
|
|
| 460 |
return APAL_STATUS_OK; |
|
| 461 |
} |
|
| 462 |
|
|
| 463 |
apalExitStatus_t apalSPIReconfigure(apalSPIDriver_t* spid, const apalSPIConfig_t* config) |
|
| 464 |
{
|
|
| 465 |
apalDbgAssert(spid != NULL); |
|
| 466 |
apalDbgAssert(config != NULL); |
|
| 467 |
|
|
| 468 |
#if (SPI_USE_MUTUAL_EXCLUSION == TRUE) |
|
| 469 |
// check whether the SPI driver was locked externally |
|
| 470 |
const bool spid_locked_external = spid->mutex.owner == currp; |
|
| 471 |
if (!spid_locked_external) {
|
|
| 472 |
spiAcquireBus(spid); |
|
| 473 |
} |
|
| 474 |
#endif /* (SPI_USE_MUTUAL_EXCLUSION == TRUE) */ |
|
| 475 |
|
|
| 476 |
spiStop(spid); |
|
| 477 |
spiStart(spid, config); |
|
| 478 |
|
|
| 479 |
#if (SPI_USE_MUTUAL_EXCLUSION == TRUE) |
|
| 480 |
if (!spid_locked_external) {
|
|
| 481 |
spiReleaseBus(spid); |
|
| 482 |
} |
|
| 483 |
#endif /* (SPI_USE_MUTUAL_EXCLUSION == TRUE) */ |
|
| 484 |
|
|
| 485 |
return APAL_STATUS_OK; |
|
| 486 |
} |
|
| 487 |
|
|
| 488 |
#endif /* (HAL_USE_SPI == TRUE) */ |
|
| periphery-lld/aos_periphAL.h | ||
|---|---|---|
| 1 |
/* |
|
| 2 |
AMiRo-OS is an operating system designed for the Autonomous Mini Robot (AMiRo) platform. |
|
| 3 |
Copyright (C) 2016..2019 Thomas Schöpping et al. |
|
| 4 |
|
|
| 5 |
This program is free software: you can redistribute it and/or modify |
|
| 6 |
it under the terms of the GNU General Public License as published by |
|
| 7 |
the Free Software Foundation, either version 3 of the License, or |
|
| 8 |
(at your option) any later version. |
|
| 9 |
|
|
| 10 |
This program is distributed in the hope that it will be useful, |
|
| 11 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 12 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
| 13 |
GNU General Public License for more details. |
|
| 14 |
|
|
| 15 |
You should have received a copy of the GNU General Public License |
|
| 16 |
along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
| 17 |
*/ |
|
| 18 |
|
|
| 19 |
#ifndef AMIROOS_PERIPHAL_H |
|
| 20 |
#define AMIROOS_PERIPHAL_H |
|
| 21 |
|
|
| 22 |
/*============================================================================*/ |
|
| 23 |
/* DEPENDENCIES */ |
|
| 24 |
/*============================================================================*/ |
|
| 25 |
|
|
| 26 |
#include <aosconf.h> |
|
| 27 |
#include <hal.h> |
|
| 28 |
|
|
| 29 |
/*============================================================================*/ |
|
| 30 |
/* DEBUG */ |
|
| 31 |
/*============================================================================*/ |
|
| 32 |
|
|
| 33 |
#if (AMIROOS_CFG_DBG != true) |
|
| 34 |
|
|
| 35 |
#define apalDbgAssert(condition) |
|
| 36 |
|
|
| 37 |
#define apalDbgPrintf(fmt, ...) 0 |
|
| 38 |
|
|
| 39 |
#endif /* (AMIROOS_CFG_DBG == true) */ |
|
| 40 |
|
|
| 41 |
/*============================================================================*/ |
|
| 42 |
/* TIMING */ |
|
| 43 |
/*============================================================================*/ |
|
| 44 |
|
|
| 45 |
#if (AMIROOS_CFG_DBG != true) |
|
| 46 |
|
|
| 47 |
#define apalSleep(us) chThdSleep(chTimeUS2I((apalTime_t)us)) |
|
| 48 |
|
|
| 49 |
#endif /* (AMIROOS_CFG_DBG == true) */ |
|
| 50 |
|
|
| 51 |
/*============================================================================*/ |
|
| 52 |
/* GPIO */ |
|
| 53 |
/*============================================================================*/ |
|
| 54 |
|
|
| 55 |
#if (HAL_USE_PAL == TRUE) || defined(__DOXYGEN__) |
|
| 56 |
|
|
| 57 |
/** |
|
| 58 |
* @brief GPIO driver type. |
|
| 59 |
*/ |
|
| 60 |
typedef struct {
|
|
| 61 |
ioline_t line; |
|
| 62 |
} PACKED_VAR apalGpio_t; |
|
| 63 |
|
|
| 64 |
/** |
|
| 65 |
* @brief Converts an apalGpioEdge_t to an ChibiOS PAL edge. |
|
| 66 |
*/ |
|
| 67 |
#define APAL2CH_EDGE(edge) \ |
|
| 68 |
((edge == APAL_GPIO_EDGE_RISING) ? PAL_EVENT_MODE_RISING_EDGE : \ |
|
| 69 |
(edge == APAL_GPIO_EDGE_FALLING) ? PAL_EVENT_MODE_FALLING_EDGE : \ |
|
| 70 |
(edge == APAL_GPIO_EDGE_BOTH) ? PAL_EVENT_MODE_BOTH_EDGES : \ |
|
| 71 |
PAL_EVENT_MODE_DISABLED) |
|
| 72 |
|
|
| 73 |
#endif /* (HAL_USE_PAL == TRUE) */ |
|
| 74 |
|
|
| 75 |
/*============================================================================*/ |
|
| 76 |
/* PWM */ |
|
| 77 |
/*============================================================================*/ |
|
| 78 |
|
|
| 79 |
#if (HAL_USE_PWM == TRUE) || defined (__DOXYGEN__) |
|
| 80 |
|
|
| 81 |
/** |
|
| 82 |
* @brief PWM driver type. |
|
| 83 |
*/ |
|
| 84 |
typedef PWMDriver apalPWMDriver_t; |
|
| 85 |
|
|
| 86 |
#endif /* (HAL_USE_PWM == TRUE) */ |
|
| 87 |
|
|
| 88 |
/*============================================================================*/ |
|
| 89 |
/* QEI */ |
|
| 90 |
/*============================================================================*/ |
|
| 91 |
|
|
| 92 |
#if (HAL_USE_QEI == TRUE) || defined (__DOXYGEN__) |
|
| 93 |
|
|
| 94 |
/** |
|
| 95 |
* @brief QEI driver type. |
|
| 96 |
*/ |
|
| 97 |
typedef QEIDriver apalQEIDriver_t; |
|
| 98 |
|
|
| 99 |
#endif /* (HAL_USE_QEI == TRUE) */ |
|
| 100 |
|
|
| 101 |
/*============================================================================*/ |
|
| 102 |
/* I2C */ |
|
| 103 |
/*============================================================================*/ |
|
| 104 |
|
|
| 105 |
#if (HAL_USE_I2C == TRUE) || defined(__DOXYGEN__) |
|
| 106 |
|
|
| 107 |
/** |
|
| 108 |
* @brief I2C driver type. |
|
| 109 |
*/ |
|
| 110 |
typedef I2CDriver apalI2CDriver_t; |
|
| 111 |
|
|
| 112 |
#endif /* (HAL_USE_I2C == TRUE) */ |
|
| 113 |
|
|
| 114 |
/*============================================================================*/ |
|
| 115 |
/* SPI */ |
|
| 116 |
/*============================================================================*/ |
|
| 117 |
|
|
| 118 |
#if (HAL_USE_SPI == TRUE) || defined(__DOXYGEN__) |
|
| 119 |
|
|
| 120 |
/** |
|
| 121 |
* @brief SPI driver type. |
|
| 122 |
*/ |
|
| 123 |
typedef SPIDriver apalSPIDriver_t; |
|
| 124 |
|
|
| 125 |
/** |
|
| 126 |
* @brief SPI confguration type. |
|
| 127 |
*/ |
|
| 128 |
typedef SPIConfig apalSPIConfig_t; |
|
| 129 |
|
|
| 130 |
#endif /* (HAL_USE_SPI == TRUE) */ |
|
| 131 |
|
|
| 132 |
#endif /* AMIROOS_PERIPHAL_H */ |
|
| periphery-lld/periphAL.c | ||
|---|---|---|
| 1 |
/* |
|
| 2 |
AMiRo-OS is an operating system designed for the Autonomous Mini Robot (AMiRo) platform. |
|
| 3 |
Copyright (C) 2016..2019 Thomas Schöpping et al. |
|
| 4 |
|
|
| 5 |
This program is free software: you can redistribute it and/or modify |
|
| 6 |
it under the terms of the GNU General Public License as published by |
|
| 7 |
the Free Software Foundation, either version 3 of the License, or |
|
| 8 |
(at your option) any later version. |
|
| 9 |
|
|
| 10 |
This program is distributed in the hope that it will be useful, |
|
| 11 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 12 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
| 13 |
GNU General Public License for more details. |
|
| 14 |
|
|
| 15 |
You should have received a copy of the GNU General Public License |
|
| 16 |
along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
| 17 |
*/ |
|
| 18 |
|
|
| 19 |
#include <amiro-lld.h> |
|
| 20 |
|
|
| 21 |
#if (AMIROOS_CFG_DBG == true) || defined(__DOXYGEN__) |
|
| 22 |
|
|
| 23 |
#include <amiroos.h> |
|
| 24 |
#include <chprintf.h> |
|
| 25 |
|
|
| 26 |
/** |
|
| 27 |
* @brief Assert function to check a given condition and print a message string. |
|
| 28 |
* |
|
| 29 |
* @param[in] c The condition to check. |
|
| 30 |
* @param[in] fmt Formatted message string to print. |
|
| 31 |
*/ |
|
| 32 |
void _apalDbgAssertMsg(const bool c, const char* fmt, ...) |
|
| 33 |
{
|
|
| 34 |
if (!c) {
|
|
| 35 |
va_list ap; |
|
| 36 |
|
|
| 37 |
va_start(ap, fmt); |
|
| 38 |
chvprintf((BaseSequentialStream*)&aos.iostream, fmt, ap); |
|
| 39 |
va_end(ap); |
|
| 40 |
chThdExit(MSG_RESET); |
|
| 41 |
} |
|
| 42 |
return; |
|
| 43 |
} |
|
| 44 |
|
|
| 45 |
/** |
|
| 46 |
* @brief Printf function for messages printed only in debug builds. |
|
| 47 |
* |
|
| 48 |
* @param[in] fmt Formatted string to print. |
|
| 49 |
*/ |
|
| 50 |
void apalDbgPrintf(const char* fmt, ...) |
|
| 51 |
{
|
|
| 52 |
va_list ap; |
|
| 53 |
|
|
| 54 |
va_start(ap, fmt); |
|
| 55 |
chvprintf((BaseSequentialStream*)&aos.iostream, fmt, ap); |
|
| 56 |
va_end(ap); |
|
| 57 |
|
|
| 58 |
return; |
|
| 59 |
} |
|
| 60 |
|
|
| 61 |
#endif /* (AMIROOS_CFG_DBG == true) */ |
|
| periphery-lld/periphAL.h | ||
|---|---|---|
| 1 |
/* |
|
| 2 |
AMiRo-OS is an operating system designed for the Autonomous Mini Robot (AMiRo) platform. |
|
| 3 |
Copyright (C) 2016..2019 Thomas Schöpping et al. |
|
| 4 |
|
|
| 5 |
This program is free software: you can redistribute it and/or modify |
|
| 6 |
it under the terms of the GNU General Public License as published by |
|
| 7 |
the Free Software Foundation, either version 3 of the License, or |
|
| 8 |
(at your option) any later version. |
|
| 9 |
|
|
| 10 |
This program is distributed in the hope that it will be useful, |
|
| 11 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 12 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
| 13 |
GNU General Public License for more details. |
|
| 14 |
|
|
| 15 |
You should have received a copy of the GNU General Public License |
|
| 16 |
along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
| 17 |
*/ |
|
| 18 |
|
|
| 19 |
#ifndef AMIROOS_PERIPHAL_H |
|
| 20 |
#define AMIROOS_PERIPHAL_H |
|
| 21 |
|
|
| 22 |
#include <amiro-lld.h> |
|
| 23 |
|
|
| 24 |
/*============================================================================*/ |
|
| 25 |
/* VERSION */ |
|
| 26 |
/*============================================================================*/ |
|
| 27 |
|
|
| 28 |
/** |
|
| 29 |
* @brief The periphery abstraction layer interface major version. |
|
| 30 |
* @note Changes of the major version imply incompatibilities. |
|
| 31 |
*/ |
|
| 32 |
#define PERIPHAL_VERSION_MAJOR 1 |
|
| 33 |
|
|
| 34 |
/** |
|
| 35 |
* @brief The periphery abstraction layer interface minor version. |
|
| 36 |
* @note A higher minor version implies new functionalty, but all old interfaces are still available. |
|
| 37 |
*/ |
|
| 38 |
#define PERIPHAL_VERSION_MINOR 1 |
|
| 39 |
|
|
| 40 |
/*============================================================================*/ |
|
| 41 |
/* DEPENDENCIES */ |
|
| 42 |
/*============================================================================*/ |
|
| 43 |
|
|
| 44 |
#include <aosconf.h> |
|
| 45 |
#include <hal.h> |
|
| 46 |
|
|
| 47 |
/*============================================================================*/ |
|
| 48 |
/* DEBUG */ |
|
| 49 |
/*============================================================================*/ |
|
| 50 |
|
|
| 51 |
#if (AMIROOS_CFG_DBG == true) || defined(__DOXYGEN__) |
|
| 52 |
|
|
| 53 |
#if defined(__cplusplus) |
|
| 54 |
extern "C" {
|
|
| 55 |
#endif /* defined(__cplusplus) */ |
|
| 56 |
void _apalDbgAssertMsg(const bool c, const char* fmt, ...); |
|
| 57 |
void apalDbgPrintf(const char* fmt, ...); |
|
| 58 |
#if defined(__cplusplus) |
|
| 59 |
} |
|
| 60 |
#endif /* defined(__cplusplus) */ |
|
| 61 |
|
|
| 62 |
/** |
|
| 63 |
* @brief Assert function to check a given condition. |
|
| 64 |
* |
|
| 65 |
* @param[in] c The condition to check. |
|
| 66 |
*/ |
|
| 67 |
#define apalDbgAssert(c) _apalDbgAssertMsg(c, "%s(%u): apalDbgAssert failed", __FILE__, __LINE__) |
|
| 68 |
|
|
| 69 |
|
|
| 70 |
#else /* (AMIROOS_CFG_DBG != true) */ |
|
| 71 |
|
|
| 72 |
#define apalDbgAssert(condition) \ |
|
| 73 |
(void)(condition) |
|
| 74 |
|
|
| 75 |
#define apalDbgAssertMsg(condition, fmt, ...) \ |
|
| 76 |
(void)(condition); \ |
|
| 77 |
(void)(fmt) |
|
| 78 |
|
|
| 79 |
#define apalDbgPrintf(fmt, ...) \ |
|
| 80 |
(void)(fmt) |
|
| 81 |
|
|
| 82 |
#endif /* (AMIROOS_CFG_DBG == true) */ |
|
| 83 |
|
|
| 84 |
/*============================================================================*/ |
|
| 85 |
/* GENERAL */ |
|
| 86 |
/*============================================================================*/ |
|
| 87 |
|
|
| 88 |
/** |
|
| 89 |
* @brief Delay execution by a specific number of microseconds. |
|
| 90 |
* |
|
| 91 |
* @param[in] us Time to sleep until execution continues in microseconds. |
|
| 92 |
*/ |
|
| 93 |
static inline void apalSleep(apalTime_t us) |
|
| 94 |
{
|
|
| 95 |
// check if the specified time can be represented by the system |
|
| 96 |
apalDbgAssert(us <= chTimeI2US(TIME_INFINITE)); |
|
| 97 |
|
|
| 98 |
const sysinterval_t interval = chTimeUS2I(us); |
|
| 99 |
// TIME_IMMEDIATE makes no sense and would even cause system halt |
|
| 100 |
if (interval != TIME_IMMEDIATE) {
|
|
| 101 |
chThdSleep(interval); |
|
| 102 |
} |
|
| 103 |
return; |
|
| 104 |
} |
|
| 105 |
|
|
| 106 |
/*============================================================================*/ |
|
| 107 |
/* GPIO */ |
|
| 108 |
/*============================================================================*/ |
|
| 109 |
|
|
| 110 |
#if (HAL_USE_PAL == TRUE) || defined (__DOXYGEN__) |
|
| 111 |
|
|
| 112 |
/** |
|
| 113 |
* @brief GPIO driver type. |
|
| 114 |
*/ |
|
| 115 |
struct apalGpio_t {
|
|
| 116 |
ioline_t line; |
|
| 117 |
} PACKED_VAR; |
|
| 118 |
|
|
| 119 |
/** |
|
| 120 |
* @brief Read the current value of a GPIO pin. |
|
| 121 |
* |
|
| 122 |
* @param[in] gpio GPIO to read. |
|
| 123 |
* @param[out] val Current value of the GPIO. |
|
| 124 |
* |
|
| 125 |
* @return The status indicates whether the function call was successful. |
|
| 126 |
*/ |
|
| 127 |
static inline apalExitStatus_t apalGpioRead(apalGpio_t* gpio, apalGpioState_t* const val) |
|
| 128 |
{
|
|
| 129 |
apalDbgAssert(gpio != NULL); |
|
| 130 |
apalDbgAssert(val != NULL); |
|
| 131 |
|
|
| 132 |
*val = (palReadLine(gpio->line) == PAL_HIGH) ? APAL_GPIO_HIGH : APAL_GPIO_LOW; |
|
| 133 |
return APAL_STATUS_OK; |
|
| 134 |
} |
|
| 135 |
|
|
| 136 |
/** |
|
| 137 |
* @brief Set the value of a GPIO pin. |
|
| 138 |
* |
|
| 139 |
* @param[in] gpio GPIO to write. |
|
| 140 |
* @param[in] val Value to set for the GPIO. |
|
| 141 |
* |
|
| 142 |
* @return The status indicates whether the function call was successful. |
|
| 143 |
*/ |
|
| 144 |
static inline apalExitStatus_t apalGpioWrite(apalGpio_t* gpio, const apalGpioState_t val) |
|
| 145 |
{
|
|
| 146 |
apalDbgAssert(gpio != NULL); |
|
| 147 |
|
|
| 148 |
// palWriteLine() is not guaranteed to be atomic, thus the scheduler is locked. |
|
| 149 |
syssts_t sysstatus = chSysGetStatusAndLockX(); |
|
| 150 |
palWriteLine(gpio->line, (val == APAL_GPIO_HIGH) ? PAL_HIGH : PAL_LOW); |
|
| 151 |
chSysRestoreStatusX(sysstatus); |
|
| 152 |
return APAL_STATUS_OK; |
|
| 153 |
} |
|
| 154 |
|
|
| 155 |
/** |
|
| 156 |
* @brief Toggle the output of a GPIO. |
|
| 157 |
* |
|
| 158 |
* @param[in] gpio GPIO to toggle. |
|
| 159 |
* |
|
| 160 |
* @return The status indicates whether the function call was successful. |
|
| 161 |
*/ |
|
| 162 |
static inline apalExitStatus_t apalGpioToggle(apalGpio_t* gpio) |
|
| 163 |
{
|
|
| 164 |
apalDbgAssert(gpio != NULL); |
|
| 165 |
|
|
| 166 |
// palWriteLine() is not guaranteed to be atomic, thus the scheduler is locked. |
|
| 167 |
syssts_t sysstatus = chSysGetStatusAndLockX(); |
|
| 168 |
palWriteLine(gpio->line, (palReadLine(gpio->line) == PAL_HIGH) ? PAL_LOW : PAL_HIGH); |
|
| 169 |
chSysRestoreStatusX(sysstatus); |
|
| 170 |
return APAL_STATUS_OK; |
|
| 171 |
} |
|
| 172 |
|
|
| 173 |
/** |
|
| 174 |
* @brief Return the interrupt enable status of the GPIO. |
|
| 175 |
* |
|
| 176 |
* @param[in] gpio GPIO to check. |
|
| 177 |
* @param[out] enabled Flag, indicating whether interrupt is enabled for the GPIO. |
|
| 178 |
* |
|
| 179 |
* @return The status indicates whether the function call was successful. |
|
| 180 |
*/ |
|
| 181 |
static inline apalExitStatus_t apalGpioIsInterruptEnabled(apalGpio_t* gpio, bool* const enabled) |
|
| 182 |
{
|
|
| 183 |
apalDbgAssert(gpio != NULL); |
|
| 184 |
apalDbgAssert(enabled != NULL); |
|
| 185 |
|
|
| 186 |
*enabled = palIsLineEventEnabledX(gpio->line); |
|
| 187 |
return APAL_STATUS_OK; |
|
| 188 |
} |
|
| 189 |
|
|
| 190 |
/** |
|
| 191 |
* @brief Get the current on/off state of a control GPIO. |
|
| 192 |
* |
|
| 193 |
* @param[in] gpio Control GPIO to read. |
|
| 194 |
* @param[out] val Current activation status of the control GPIO. |
|
| 195 |
* |
|
| 196 |
* @return The status indicates whether the function call was successful. |
|
| 197 |
*/ |
|
| 198 |
static inline apalExitStatus_t apalControlGpioGet(const apalControlGpio_t* const cgpio, apalControlGpioState_t* const val) |
|
| 199 |
{
|
|
| 200 |
apalDbgAssert(cgpio != NULL); |
|
| 201 |
apalDbgAssert(cgpio->gpio != NULL); |
|
| 202 |
apalDbgAssert(val != NULL); |
|
| 203 |
|
|
| 204 |
*val = ((palReadLine(cgpio->gpio->line) == PAL_HIGH) ^ (cgpio->meta.active == APAL_GPIO_ACTIVE_HIGH)) ? APAL_GPIO_OFF : APAL_GPIO_ON; |
|
| 205 |
return APAL_STATUS_OK; |
|
| 206 |
} |
|
| 207 |
|
|
| 208 |
/** |
|
| 209 |
* @brief Turn a control GPIO 'on' or 'off' respectively. |
|
| 210 |
* |
|
| 211 |
* @param[in] gpio Control GPIO to set. |
|
| 212 |
* @param[in] val Activation value to set for the control GPIO. |
|
| 213 |
* |
|
| 214 |
* @return The status indicates whether the function call was successful. |
|
| 215 |
*/ |
|
| 216 |
static inline apalExitStatus_t apalControlGpioSet(const apalControlGpio_t* const cgpio, const apalControlGpioState_t val) |
|
| 217 |
{
|
|
| 218 |
apalDbgAssert(cgpio != NULL); |
|
| 219 |
apalDbgAssert(cgpio->gpio != NULL); |
|
| 220 |
apalDbgAssert(cgpio->meta.direction == APAL_GPIO_DIRECTION_OUTPUT || cgpio->meta.direction == APAL_GPIO_DIRECTION_BIDIRECTIONAL); |
|
| 221 |
|
|
| 222 |
// palWriteLine() is not guaranteed to be atomic, thus the scheduler is locked. |
|
| 223 |
syssts_t sysstatus = chSysGetStatusAndLockX(); |
|
| 224 |
palWriteLine(cgpio->gpio->line, ((cgpio->meta.active == APAL_GPIO_ACTIVE_HIGH) ^ (val == APAL_GPIO_ON)) ? PAL_LOW : PAL_HIGH); |
|
| 225 |
chSysRestoreStatusX(sysstatus); |
|
| 226 |
return APAL_STATUS_OK; |
|
| 227 |
} |
|
| 228 |
|
|
| 229 |
/** |
|
| 230 |
* @brief Converts an apalGpioEdge_t to an ChibiOS PAL edge. |
|
| 231 |
*/ |
|
| 232 |
#define APAL2CH_EDGE(edge) \ |
|
| 233 |
((edge == APAL_GPIO_EDGE_RISING) ? PAL_EVENT_MODE_RISING_EDGE : \ |
|
| 234 |
(edge == APAL_GPIO_EDGE_FALLING) ? PAL_EVENT_MODE_FALLING_EDGE : \ |
|
| 235 |
(edge == APAL_GPIO_EDGE_BOTH) ? PAL_EVENT_MODE_BOTH_EDGES : \ |
|
| 236 |
PAL_EVENT_MODE_DISABLED) |
|
| 237 |
|
|
| 238 |
/** |
|
| 239 |
* @brief Enable or disable the interrupt event functionality. |
|
| 240 |
* |
|
| 241 |
* @param[in] cgpio Control GPIO to set. |
|
| 242 |
* @param[in] enable Flag, indicating whether the interrupt shall be activated (true) or deactivated (false). |
|
| 243 |
* |
|
| 244 |
* @return The status indicates whether the function call was successful. |
|
| 245 |
*/ |
|
| 246 |
static inline apalExitStatus_t apalControlGpioSetInterrupt(const apalControlGpio_t* const cgpio, const bool enable) |
|
| 247 |
{
|
|
| 248 |
apalDbgAssert(cgpio != NULL); |
|
| 249 |
apalDbgAssert(cgpio->gpio != NULL); |
|
| 250 |
|
|
| 251 |
if (enable) {
|
|
| 252 |
apalDbgAssert(pal_lld_get_line_event(cgpio->gpio->line) != NULL); |
|
| 253 |
palEnableLineEvent(cgpio->gpio->line, APAL2CH_EDGE(cgpio->meta.edge)); |
|
| 254 |
} else {
|
|
| 255 |
palDisableLineEvent(cgpio->gpio->line); |
|
| 256 |
} |
|
| 257 |
|
|
| 258 |
return APAL_STATUS_OK; |
|
| 259 |
} |
|
| 260 |
|
|
| 261 |
#endif /* (HAL_USE_PAL == TRUE) */ |
|
| 262 |
|
|
| 263 |
/*============================================================================*/ |
|
| 264 |
/* PWM */ |
|
| 265 |
/*============================================================================*/ |
|
| 266 |
|
|
| 267 |
#if (HAL_USE_PWM == TRUE) || defined (__DOXYGEN__) |
|
| 268 |
|
|
| 269 |
/** |
|
| 270 |
* @brief PWM driver type. |
|
| 271 |
*/ |
|
| 272 |
typedef PWMDriver apalPWMDriver_t; |
|
| 273 |
|
|
| 274 |
/** |
|
| 275 |
* @brief Set the PWM with given parameters. |
|
| 276 |
* |
|
| 277 |
* @param[in] pwm PWM driver to set. |
|
| 278 |
* @param[in] channel Channel of the PWM driver to set. |
|
| 279 |
* @param[in] width Width to set the channel to. |
|
| 280 |
* |
|
| 281 |
* @return The status indicates whether the function call was successful. |
|
| 282 |
*/ |
|
| 283 |
static inline apalExitStatus_t apalPWMSet(apalPWMDriver_t* pwm, const apalPWMchannel_t channel, const apalPWMwidth_t width) |
|
| 284 |
{
|
|
| 285 |
apalDbgAssert(pwm != NULL); |
|
| 286 |
|
|
| 287 |
pwmEnableChannel(pwm, (pwmchannel_t)channel, pwm->period * ((float)width / (float)APAL_PWM_WIDTH_MAX) + 0.5f); |
|
| 288 |
return APAL_STATUS_OK; |
|
| 289 |
} |
|
| 290 |
|
|
| 291 |
/** |
|
| 292 |
* @brief Retrieve the current frequency of the PWM. |
|
| 293 |
* |
|
| 294 |
* @param[in] pwm PWM driver to read. |
|
| 295 |
* @param[out] frequency The currently set frequency. |
|
| 296 |
* |
|
| 297 |
* @return The status indicates whether the function call was successful. |
|
| 298 |
*/ |
|
| 299 |
static inline apalExitStatus_t apalPWMGetFrequency(apalPWMDriver_t* pwm, apalPWMfrequency_t* const frequency) |
|
| 300 |
{
|
|
| 301 |
apalDbgAssert(pwm != NULL); |
|
| 302 |
apalDbgAssert(frequency != NULL); |
|
| 303 |
|
|
| 304 |
*frequency = pwm->config->frequency; |
|
| 305 |
return APAL_STATUS_OK; |
|
| 306 |
} |
|
| 307 |
|
|
| 308 |
/** |
|
| 309 |
* @brief Retrieve the current period of the PWM. |
|
| 310 |
* |
|
| 311 |
* @param[in] pwm PWM driver to read. |
|
| 312 |
* @param[out] period The currently set period. |
|
| 313 |
* |
|
| 314 |
* @return The status indicates whether the function call was successful. |
|
| 315 |
*/ |
|
| 316 |
static inline apalExitStatus_t apalPWMGetPeriod(apalPWMDriver_t* pwm, apalPWMperiod_t* const period) |
|
| 317 |
{
|
|
| 318 |
apalDbgAssert(pwm != NULL); |
|
| 319 |
apalDbgAssert(period != NULL); |
|
| 320 |
|
|
| 321 |
*period = pwm->period; |
|
| 322 |
return APAL_STATUS_OK; |
|
| 323 |
} |
|
| 324 |
|
|
| 325 |
#endif /* (HAL_USE_PWM == TRUE) */ |
|
| 326 |
|
|
| 327 |
/*============================================================================*/ |
|
Also available in: Unified diff