テスト用のあれこれ共用フォルダ
Revisión | 2e06b996cf6657b9c06e581c6d86087d526f24f8 (tree) |
---|---|
Tiempo | 2018-03-11 16:45:04 |
Autor | takemasa <suikan@user...> |
Commiter | takemasa |
Debugger:printf is renamed as Printf, to follow the google map.
Implement the cache coherency.
@@ -84,7 +84,7 @@ void InitTestUart(UART_HandleTypeDef * uart_handle, SPI_HandleTypeDef * spi_hand | ||
84 | 84 | unsigned int copied = test_fifo->Put(reinterpret_cast<const uint8_t *>(MSG1), sizeof(MSG1)); |
85 | 85 | test_fifo->NotifyData(); |
86 | 86 | |
87 | - murasaki::debugger->printf("FIFO.Put(), %d data taransfered\n\r", copied); | |
87 | + murasaki::debugger->Printf("FIFO.Put(), %d data taransfered\n\r", copied); | |
88 | 88 | #endif |
89 | 89 | |
90 | 90 | } |
@@ -97,7 +97,7 @@ void DoTestUart(void) | ||
97 | 97 | #if 0 |
98 | 98 | unsigned int copied = test_fifo->Put(reinterpret_cast<const uint8_t *>(MSG1), sizeof(MSG1)); |
99 | 99 | test_fifo->NotifyData(); |
100 | - murasaki::debugger->printf("FIFO.Put(), %d data taransfered\n\r", copied); | |
100 | + murasaki::debugger->Printf("FIFO.Put(), %d data taransfered\n\r", copied); | |
101 | 101 | #endif |
102 | 102 | |
103 | 103 | #if 0 |
@@ -109,24 +109,24 @@ void DoTestUart(void) | ||
109 | 109 | unsigned int copied = test_fifo->Get(reinterpret_cast<uint8_t *>(data), sizeof(data)); |
110 | 110 | if (copied == 0) |
111 | 111 | { |
112 | - murasaki::debugger->printf("FIFO.Get(), %d data taransfered \n\r", copied); | |
112 | + murasaki::debugger->Printf("FIFO.Get(), %d data taransfered \n\r", copied); | |
113 | 113 | // test_fifo->ReWind(); |
114 | 114 | test_fifo->NotifyData(); |
115 | 115 | } |
116 | 116 | else { |
117 | - murasaki::debugger->printf("FIFO.Get(), %d data taransfered : '%10s'\n\r", copied, data); | |
117 | + murasaki::debugger->Printf("FIFO.Get(), %d data taransfered : '%10s'\n\r", copied, data); | |
118 | 118 | } |
119 | 119 | #endif |
120 | 120 | // by murasaki debugging output. You can use this in both task and interrupt context. |
121 | 121 | // non blocking |
122 | - murasaki::debugger->printf(MSG, counter); | |
122 | + murasaki::debugger->Printf(MSG, counter); | |
123 | 123 | |
124 | 124 | } |
125 | 125 | |
126 | 126 | // Hook for the assert_failure() in main.c |
127 | 127 | void CustomAssertFailed(uint8_t* file, uint32_t line) |
128 | 128 | { |
129 | - murasaki::debugger->printf("Wrong parameters value: file %s on line %d\r\n", file, line); | |
129 | + murasaki::debugger->Printf("Wrong parameters value: file %s on line %d\r\n", file, line); | |
130 | 130 | } |
131 | 131 | |
132 | 132 |
@@ -168,9 +168,9 @@ void HAL_GPIO_EXTI_Callback(uint16_t GPIO_P) | ||
168 | 168 | unsigned int copied = test_fifo->Put(reinterpret_cast<const uint8_t *>(MSG2), sizeof(MSG2)); |
169 | 169 | test_fifo->NotifyData(); |
170 | 170 | |
171 | - murasaki::debugger->printf("FIFO.Put(), %d data taransfered\n\r", copied); | |
171 | + murasaki::debugger->Printf("FIFO.Put(), %d data taransfered\n\r", copied); | |
172 | 172 | #else |
173 | - murasaki::debugger->printf("Interrupt occurs %d \n\r", counter); | |
173 | + murasaki::debugger->Printf("Interrupt occurs %d \n\r", counter); | |
174 | 174 | #endif |
175 | 175 | } |
176 | 176 | } |
@@ -58,7 +58,7 @@ Debugger::~Debugger() | ||
58 | 58 | delete helpers_.fifo; |
59 | 59 | } |
60 | 60 | |
61 | -void Debugger::printf(const char * fmt, ...) | |
61 | +void Debugger::Printf(const char * fmt, ...) | |
62 | 62 | { |
63 | 63 | // obtain variable parameter list |
64 | 64 | va_list argp; |
@@ -74,7 +74,7 @@ class Debugger | ||
74 | 74 | * |
75 | 75 | * At 2018/Jan/14 measurement, task stack was consumed 49bytes. |
76 | 76 | */ |
77 | - void printf(const char * fmt, ...); | |
77 | + void Printf(const char * fmt, ...); | |
78 | 78 | /** |
79 | 79 | * \brief Receive one character from serial port. |
80 | 80 | * \return Received character. |
@@ -84,7 +84,7 @@ class Debugger | ||
84 | 84 | * |
85 | 85 | * This is thread safe and task context dedicated function. Never call from ISR. |
86 | 86 | * |
87 | - * Becareful, this is blocking while the Debug::printf() non-blocking. | |
87 | + * Becareful, this is blocking while the Debug::Printf() non-blocking. | |
88 | 88 | */ |
89 | 89 | char GetchFromTask(); |
90 | 90 | /** |
@@ -36,9 +36,9 @@ | ||
36 | 36 | #define MURASAKI_ASSERT( COND )\ |
37 | 37 | if ( ! (COND) )\ |
38 | 38 | {\ |
39 | - murasaki::debugger->printf("--------------------\n\r");\ | |
40 | - murasaki::debugger->printf(MURASAKI_ASSERT_MSG, __func__, __LINE__,__FILE__ );\ | |
41 | - murasaki::debugger->printf("Fail expression : %s\r\n", #COND);\ | |
39 | + murasaki::debugger->Printf("--------------------\n\r");\ | |
40 | + murasaki::debugger->Printf(MURASAKI_ASSERT_MSG, __func__, __LINE__,__FILE__ );\ | |
41 | + murasaki::debugger->Printf("Fail expression : %s\r\n", #COND);\ | |
42 | 42 | if ( murasaki::IsTaskContext() )\ |
43 | 43 | vTaskSuspend(nullptr);\ |
44 | 44 | } |
@@ -84,7 +84,7 @@ | ||
84 | 84 | #define MURASAKI_PRINT_ERROR( ERR )\ |
85 | 85 | if ( (ERR) )\ |
86 | 86 | {\ |
87 | - murasaki::debugger->printf(MURASAKI_ERROR_MSG, __func__, __LINE__,__FILE__, #ERR );\ | |
87 | + murasaki::debugger->Printf(MURASAKI_ERROR_MSG, __func__, __LINE__,__FILE__, #ERR );\ | |
88 | 88 | } |
89 | 89 | #endif |
90 | 90 |
@@ -86,7 +86,7 @@ enum SpiClockPhase | ||
86 | 86 | * \brief determine task or ISR context |
87 | 87 | * \returns true if task context, false if ISR context. |
88 | 88 | */ |
89 | -inline bool IsTaskContext() | |
89 | +static inline bool IsTaskContext() | |
90 | 90 | { |
91 | 91 | // portNVIC_INT_CTRL_REG is mapped to the address 0xe000ed04 by portmacro.h. This register is |
92 | 92 | // officially called as NVIC ICSR by ARM |
@@ -104,6 +104,18 @@ inline bool IsTaskContext() | ||
104 | 104 | } |
105 | 105 | |
106 | 106 | |
107 | +static inline void InvalidateDataCacheByAddress(void * address, size_t size) | |
108 | +{ | |
109 | + unsigned int aligned_address = reinterpret_cast<unsigned int>(address); | |
110 | + | |
111 | + // extract modulo 32. The address have to be aligned to 32byte. | |
112 | + unsigned int adjustment = aligned_address & 0x1F; | |
113 | + // Adjust the address and size. | |
114 | + aligned_address -= adjustment; // aligne to 32byte boarder | |
115 | + size += adjustment; // Because the start address is lower, the size is bigger. | |
116 | + | |
117 | + ::SCB_InvalidateDCache_by_Addr(reinterpret_cast<long unsigned int *>(aligned_address), size); | |
118 | +} | |
107 | 119 | |
108 | 120 | /** |
109 | 121 | * \} |
@@ -108,10 +108,10 @@ | ||
108 | 108 | * \section sec6 Versatile printf() logger |
109 | 109 | * Logging or "printf debug" is a strong tool in the embedded system development. |
110 | 110 | * |
111 | - * Murasaki has two levels of the printf debugging mechanism. One is the \ref murasaki::debugger->printf(), | |
111 | + * Murasaki has two levels of the printf debugging mechanism. One is the \ref murasaki::debugger->Printf(), | |
112 | 112 | * the other is \ref MURASAKI_ASSERT macro. |
113 | 113 | * |
114 | - * The murasaki::debugger->printf() is flexible output mechanism which has several good | |
114 | + * The murasaki::debugger->Printf() is flexible output mechanism which has several good | |
115 | 115 | * features : |
116 | 116 | * \li printf() compatible parameters. |
117 | 117 | * \li Task/interrupt bi-context operation |
@@ -122,8 +122,8 @@ | ||
122 | 122 | * but also in the interrupt context. |
123 | 123 | * |
124 | 124 | * \section sec7 Guard by assertion |
125 | - * In addition to the murasaki::debugger->printf(), programmer can use \ref MURASAKI_ASSERT macro. | |
126 | - * This allows easy assertion and logging. This macro uses the murasaki::debugger->printf() | |
125 | + * In addition to the murasaki::debugger->Printf(), programmer can use \ref MURASAKI_ASSERT macro. | |
126 | + * This allows easy assertion and logging. This macro uses the murasaki::debugger->Printf() | |
127 | 127 | * internally. |
128 | 128 | * |
129 | 129 | * This assertion is used inside murasaki class library. Then, the wrong context, |
@@ -222,7 +222,7 @@ | ||
222 | 222 | * |
223 | 223 | * First, class instances are created inside heap region by new operator often. |
224 | 224 | * Second, Task stack is also created inside heap. |
225 | - * And third, murasaki::Debugger allocates a huge size of FIFO buffer betwen its murasaki::Debugger::printf() | |
225 | + * And third, murasaki::Debugger allocates a huge size of FIFO buffer betwen its murasaki::Debugger::Printf() | |
226 | 226 | * function and logger task. |
227 | 227 | * |
228 | 228 | * The size of this FIFO buffer is defined by @ref PLATFORM_CONFIG_DEBUG_BUFFER_SIZE and default is 4KB. |
@@ -484,7 +484,7 @@ | ||
484 | 484 | * // Hook for the assert_failure() in main.c |
485 | 485 | * void CustomAssertFailed(uint8_t* file, uint32_t line) |
486 | 486 | * { |
487 | - * murasaki::debugger->printf("Wrong parameters value: file %s on line %d\r\n", file, line); | |
487 | + * murasaki::debugger->Printf("Wrong parameters value: file %s on line %d\r\n", file, line); | |
488 | 488 | * } |
489 | 489 | * |
490 | 490 | * \endcode |
@@ -70,6 +70,9 @@ bool SpiMaster::TransmitAndReceive(murasaki::AbstractSpiSlaveSpecifier* spi_spec | ||
70 | 70 | // Assert the chip select for slave |
71 | 71 | spi_spec->AssertCs(); |
72 | 72 | { |
73 | + // Keep coherency between the L2 and cache before DMA | |
74 | + murasaki::InvalidateDataCacheByAddress(tx_data, size); | |
75 | + murasaki::InvalidateDataCacheByAddress(rx_data, size); | |
73 | 76 | |
74 | 77 | // Transmit over SPI |
75 | 78 | HAL_StatusTypeDef status = HAL_SPI_TransmitReceive_DMA(peripheral_, tx_data, rx_data, size); |
@@ -90,6 +90,9 @@ bool Uart::Transmit(uint8_t * data, unsigned int size, WaitMilliSeconds timeout_ | ||
90 | 90 | // make this methold re-entrant in task context. |
91 | 91 | tx_critical_section_->Enter(); |
92 | 92 | { |
93 | + // Keep coherency between the L2 and cache before DMA | |
94 | + murasaki::InvalidateDataCacheByAddress(data, size); | |
95 | + | |
93 | 96 | HAL_StatusTypeDef status = HAL_UART_Transmit_DMA(peripheral_, data, size); |
94 | 97 | MURASAKI_ASSERT(HAL_OK == status); |
95 | 98 |
@@ -123,6 +126,9 @@ bool Uart::Receive(uint8_t * data, unsigned int size, WaitMilliSeconds timeout_m | ||
123 | 126 | // make this methold re-entrant in task context. |
124 | 127 | rx_critical_section_->Enter(); |
125 | 128 | { |
129 | + // Keep coherency between the L2 and cache before DMA | |
130 | + murasaki::InvalidateDataCacheByAddress(data, size); | |
131 | + | |
126 | 132 | HAL_StatusTypeDef status = HAL_UART_Receive_DMA(peripheral_, data, size); |
127 | 133 | MURASAKI_ASSERT(HAL_OK == status); |
128 | 134 |