• R/O
  • HTTP
  • SSH
  • HTTPS

提交

标签
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

テスト用のあれこれ共用フォルダ


Commit MetaInfo

修订版f90ce4fadd08bae8233927a7123180a0334db016 (tree)
时间2018-02-20 07:26:14
作者takemasa <suikan@user...>
Commitertakemasa

Log Message

Added error handling to SPI and I2C

更改概述

差异

--- a/stm32_development/murasaki/murasaki/abstracti2cmaster.hpp
+++ b/stm32_development/murasaki/murasaki/abstracti2cmaster.hpp
@@ -112,6 +112,15 @@ class AbstractI2CMaster
112112 * and return true. If it doesn't match, just return false.
113113 */
114114 virtual bool ReceiveCompleteCallback(void* ptr) = 0;
115+ /**
116+ * @brief Handling error report of device.
117+ * @param ptr Pointer for generic use. Usually, points a struct of a device control
118+ * @return true if ptr matches with device and handle the error. false if ptr doesn't match
119+ * A member function to detect error.
120+ *
121+ * The error handling is depend on the implementation.
122+ */
123+ virtual bool HandleError(void * ptr)= 0;
115124 };
116125
117126 } /* namespace murasaki */
--- a/stm32_development/murasaki/murasaki/abstractspimaster.hpp
+++ b/stm32_development/murasaki/murasaki/abstractspimaster.hpp
@@ -50,6 +50,15 @@ class AbstractSpiMaster
5050 * @return true if no error.
5151 */
5252 virtual bool TransferCompleteCallback(void * ptr) = 0;
53+ /**
54+ * @brief Handling error report of device.
55+ * @param ptr Pointer for generic use. Usually, points a struct of a device control
56+ * @return true if ptr matches with device and handle the error. false if ptr doesn't match
57+ * A member function to detect error.
58+ *
59+ * The error handling is depend on the implementation.
60+ */
61+ virtual bool HandleError(void * ptr)= 0;
5362 };
5463
5564 } /* namespace murasaki */
--- a/stm32_development/murasaki/murasaki/abstractuart.hpp
+++ b/stm32_development/murasaki/murasaki/abstractuart.hpp
@@ -107,8 +107,8 @@ public:
107107 virtual bool ReceiveCompleteCallback(void* ptr) = 0;
108108 /**
109109 * @brief Handling error report of device.
110- * @param ptr Pointer for generic use. Usually, points a struct of a UART device control
111- * @return true if ptr matches with UART device and handle the error. false if ptr doesn7t match
110+ * @param ptr Pointer for generic use. Usually, points a struct of a device control
111+ * @return true if ptr matches with device and handle the error. false if ptr doesn't match
112112 * A member function to detect error.
113113 *
114114 * The error handling is depend on the implementation.
--- a/stm32_development/murasaki/murasaki/i2cmaster.cpp
+++ b/stm32_development/murasaki/murasaki/i2cmaster.cpp
@@ -152,6 +152,26 @@ bool I2cMaster::ReceiveCompleteCallback(void* ptr)
152152 }
153153 }
154154
155+bool I2cMaster::HandleError(void* ptr)
156+{
157+ MURASAKI_ASSERT(NULL != ptr)
158+
159+ if (i2c_ == ptr) {
160+ // Check error, and print if exist.
161+ MURASAKI_PRINT_ERROR(i2c_->ErrorCode & HAL_I2C_ERROR_BERR);
162+ MURASAKI_PRINT_ERROR(i2c_->ErrorCode & HAL_I2C_ERROR_ARLO);
163+ MURASAKI_PRINT_ERROR(i2c_->ErrorCode & HAL_I2C_ERROR_AF);
164+ MURASAKI_PRINT_ERROR(i2c_->ErrorCode & HAL_I2C_ERROR_OVR);
165+ MURASAKI_PRINT_ERROR(i2c_->ErrorCode & HAL_I2C_ERROR_DMA);
166+ MURASAKI_PRINT_ERROR(i2c_->ErrorCode & HAL_I2C_ERROR_TIMEOUT);
167+ MURASAKI_PRINT_ERROR(i2c_->ErrorCode & HAL_I2C_ERROR_SIZE);
168+ return true; // report the ptr matched
169+ }
170+ else {
171+ return false; // report the ptr doesn't match
172+ }
173+}
174+
155175 } /* namespace murasaki */
156176
157177 #endif //HAL_I2C_MODULE_ENABLED
--- a/stm32_development/murasaki/murasaki/i2cmaster.hpp
+++ b/stm32_development/murasaki/murasaki/i2cmaster.hpp
@@ -150,7 +150,16 @@ class I2cMaster : public AbstractI2CMaster
150150 * and return true. If it doesn't match, just return false.
151151 */
152152 virtual bool ReceiveCompleteCallback(void* ptr);
153-
153+ /**
154+ * @brief Error handling
155+ * @param ptr Pointer to I2C_HandleTypeDef struct.
156+ * \return true: ptr matches with device and handle the error. false : doesn't match.
157+ * @details
158+ * A handle to print out the error message.
159+ *
160+ * Checks whether handle has error and if there is, print appropriate error. Then return.
161+ */
162+ virtual bool HandleError(void * ptr);
154163 protected:
155164 I2C_HandleTypeDef * i2c_; // SPI peripheral handle
156165 InterruptSynchronizer * sync_; // sync between task and interrupt
--- a/stm32_development/murasaki/murasaki/spimaster.cpp
+++ b/stm32_development/murasaki/murasaki/spimaster.cpp
@@ -101,6 +101,27 @@ bool SpiMaster::TransferCompleteCallback(void* ptr)
101101 }
102102 }
103103
104+bool SpiMaster::HandleError(void* ptr)
105+{
106+ MURASAKI_ASSERT(NULL != ptr)
107+
108+ if (peripheral_ == ptr) {
109+ // Check error, and print if exist.
110+ MURASAKI_PRINT_ERROR(peripheral_->ErrorCode & HAL_SPI_ERROR_MODF);
111+ MURASAKI_PRINT_ERROR(peripheral_->ErrorCode & HAL_SPI_ERROR_CRC);
112+ MURASAKI_PRINT_ERROR(peripheral_->ErrorCode & HAL_SPI_ERROR_OVR);
113+ MURASAKI_PRINT_ERROR(peripheral_->ErrorCode & HAL_SPI_ERROR_FRE);
114+ MURASAKI_PRINT_ERROR(peripheral_->ErrorCode & HAL_SPI_ERROR_DMA);
115+ MURASAKI_PRINT_ERROR(peripheral_->ErrorCode & HAL_SPI_ERROR_FLAG);
116+ MURASAKI_PRINT_ERROR(peripheral_->ErrorCode & HAL_SPI_ERROR_ABORT);
117+ return true; // report the ptr matched
118+ }
119+ else {
120+ return false; // report the ptr doesn't match
121+ }
122+}
123+
124+
104125 } /* namespace murasaki */
105126
106127 #endif // HAL_SPI_MODULE_ENABLED
--- a/stm32_development/murasaki/murasaki/spimaster.hpp
+++ b/stm32_development/murasaki/murasaki/spimaster.hpp
@@ -94,6 +94,16 @@ class SpiMaster : public AbstractSpiMaster
9494 * @return true if no error.
9595 */
9696 virtual bool TransferCompleteCallback(void * ptr);
97+ /**
98+ * @brief Error handling
99+ * @param ptr Pointer to I2C_HandleTypeDef struct.
100+ * \return true: ptr matches with device and handle the error. false : doesn't match.
101+ * @details
102+ * A handle to print out the error message.
103+ *
104+ * Checks whether handle has error and if there is, print appropriate error. Then return.
105+ */
106+ virtual bool HandleError(void * ptr);
97107 protected:
98108 SPI_HandleTypeDef * peripheral_; // SPI peripheral handler.
99109 InterruptSynchronizer * sync_; // sync between task and interrupt