テスト用のあれこれ共用フォルダ
修订版 | f90ce4fadd08bae8233927a7123180a0334db016 (tree) |
---|---|
时间 | 2018-02-20 07:26:14 |
作者 | takemasa <suikan@user...> |
Commiter | takemasa |
Added error handling to SPI and I2C
@@ -112,6 +112,15 @@ class AbstractI2CMaster | ||
112 | 112 | * and return true. If it doesn't match, just return false. |
113 | 113 | */ |
114 | 114 | 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; | |
115 | 124 | }; |
116 | 125 | |
117 | 126 | } /* namespace murasaki */ |
@@ -50,6 +50,15 @@ class AbstractSpiMaster | ||
50 | 50 | * @return true if no error. |
51 | 51 | */ |
52 | 52 | 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; | |
53 | 62 | }; |
54 | 63 | |
55 | 64 | } /* namespace murasaki */ |
@@ -107,8 +107,8 @@ public: | ||
107 | 107 | virtual bool ReceiveCompleteCallback(void* ptr) = 0; |
108 | 108 | /** |
109 | 109 | * @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 | |
112 | 112 | * A member function to detect error. |
113 | 113 | * |
114 | 114 | * The error handling is depend on the implementation. |
@@ -152,6 +152,26 @@ bool I2cMaster::ReceiveCompleteCallback(void* ptr) | ||
152 | 152 | } |
153 | 153 | } |
154 | 154 | |
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 | + | |
155 | 175 | } /* namespace murasaki */ |
156 | 176 | |
157 | 177 | #endif //HAL_I2C_MODULE_ENABLED |
@@ -150,7 +150,16 @@ class I2cMaster : public AbstractI2CMaster | ||
150 | 150 | * and return true. If it doesn't match, just return false. |
151 | 151 | */ |
152 | 152 | 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); | |
154 | 163 | protected: |
155 | 164 | I2C_HandleTypeDef * i2c_; // SPI peripheral handle |
156 | 165 | InterruptSynchronizer * sync_; // sync between task and interrupt |
@@ -101,6 +101,27 @@ bool SpiMaster::TransferCompleteCallback(void* ptr) | ||
101 | 101 | } |
102 | 102 | } |
103 | 103 | |
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 | + | |
104 | 125 | } /* namespace murasaki */ |
105 | 126 | |
106 | 127 | #endif // HAL_SPI_MODULE_ENABLED |
@@ -94,6 +94,16 @@ class SpiMaster : public AbstractSpiMaster | ||
94 | 94 | * @return true if no error. |
95 | 95 | */ |
96 | 96 | 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); | |
97 | 107 | protected: |
98 | 108 | SPI_HandleTypeDef * peripheral_; // SPI peripheral handler. |
99 | 109 | InterruptSynchronizer * sync_; // sync between task and interrupt |