Subversion Repositories libSerial

Rev

Rev 10 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 10 Rev 13
Line 29... Line 29...
29
#endif
29
#endif
30
#if defined SERIAL_UART5
30
#if defined SERIAL_UART5
31
usart_ctl uc5;
31
usart_ctl uc5;
32
#endif
32
#endif
33
 
33
 
34
/* returns the number of characters received by the Rx USART */
-
 
35
uint16_t
34
uint16_t
36
SerialCharsReceived(usart_ctl *instance)
35
SerialCharsReceived(usart_ctl *instance)
37
{
36
{
38
  uint16_t result = 0; // assume no characters received yet
37
  uint16_t result = 0; // assume no characters received yet
39
 
38
 
Line 87... Line 86...
87
  __HAL_UART_ENABLE_IT(instance->Handle, UART_IT_RXNE);
86
  __HAL_UART_ENABLE_IT(instance->Handle, UART_IT_RXNE);
88
 
87
 
89
  return rc;
88
  return rc;
90
}
89
}
91
 
90
 
92
/***!
-
 
93
 * @brief return the next character in the Serial input buffer
-
 
94
 * This function will wait until a character arrives.
-
 
95
 */
-
 
96
inline uint8_t
91
inline uint8_t
97
GetCharSerial(usart_ctl *instance)
92
GetCharSerial(usart_ctl *instance)
98
{
93
{
99
  uint8_t c;
94
  uint8_t c;
100
  __HAL_UART_DISABLE_IT(instance->Handle, UART_IT_RXNE);
95
  __HAL_UART_DISABLE_IT(instance->Handle, UART_IT_RXNE);
Line 144... Line 139...
144
    instance->tx_usart_in_Ptr = 0;
139
    instance->tx_usart_in_Ptr = 0;
145
  }
140
  }
146
  /* Handle overrun by losing oldest characters */
141
  /* Handle overrun by losing oldest characters */
147
  if (instance->tx_usart_in_Ptr == instance->tx_usart_out_Ptr)
142
  if (instance->tx_usart_in_Ptr == instance->tx_usart_out_Ptr)
148
  {
143
  {
149
    instance->tx_usart_overruns ++;
144
    instance->tx_usart_overruns++;
150
    instance->tx_usart_out_Ptr++;
145
    instance->tx_usart_out_Ptr++;
151
    if (instance->tx_usart_out_Ptr >= TX_USART_BUFF_SIZ)
146
    if (instance->tx_usart_out_Ptr >= TX_USART_BUFF_SIZ)
152
    {
147
    {
153
      instance->tx_usart_out_Ptr = 0;
148
      instance->tx_usart_out_Ptr = 0;
154
    }
149
    }
Line 213... Line 208...
213
  __enable_irq();
208
  __enable_irq();
214
}
209
}
215
 
210
 
216
void PutCharSerial(usart_ctl *instance, uint8_t c)
211
void PutCharSerial(usart_ctl *instance, uint8_t c)
217
{
212
{
218
  // Put character in Crayon/Pen interface
-
 
219
  PutCharSerialFIFO(instance, c);
213
  PutCharSerialFIFO(instance, c);
220
}
214
}
221
 
215
 
222
/*
-
 
223
 * \brief
-
 
224
 * ResetTxBuffer(void) - resets the serial transmitter buffer
-
 
225
 */
-
 
226
void ResetTxBuffer(usart_ctl *instance)
216
void ResetTxBuffer(usart_ctl *instance)
227
{
217
{
228
 
218
 
229
  instance->tx_usart_out_Ptr = 0;
219
  instance->tx_usart_out_Ptr = 0;
230
  instance->tx_usart_running = 0;
220
  instance->tx_usart_running = 0;
Line 259... Line 249...
259
uint8_t
249
uint8_t
260
TxBufferEmpty(usart_ctl *instance)
250
TxBufferEmpty(usart_ctl *instance)
261
{
251
{
262
  if (instance->tx_usart_running)
252
  if (instance->tx_usart_running)
263
    return 0;
253
    return 0;
264
 return (instance->Handle->Instance->SR & USART_SR_TC) == 0;
254
  return (instance->Handle->Instance->SR & USART_SR_TC) == 0;
265
}
255
}
266
 
256
 
267
/***!
257
/***!
268
 * @brief wait for transmission to finish
258
 * @brief wait for transmission to finish
269
 */
259
 */
Line 290... Line 280...
290
 
280
 
291
  /* cheat here - this is a macro and I have the same Instance member as the HAL handle, with the same meaning */
281
  /* cheat here - this is a macro and I have the same Instance member as the HAL handle, with the same meaning */
292
  __HAL_UART_DISABLE_IT(instance->Handle, UART_IT_TXE);
282
  __HAL_UART_DISABLE_IT(instance->Handle, UART_IT_TXE);
293
  __HAL_UART_DISABLE_IT(instance->Handle, UART_IT_RXNE);
283
  __HAL_UART_DISABLE_IT(instance->Handle, UART_IT_RXNE);
294
 
284
 
295
FlushSerial(instance);
285
  FlushSerial(instance);
296
}
286
}
297
 
287
 
298
void setBaud(usart_ctl *ctl, uint32_t baud)
288
void setBaud(usart_ctl *ctl, uint32_t baud)
299
{
289
{
300
  ctl->Handle->Init.BaudRate = baud;
290
  ctl->Handle->Init.BaudRate = baud;
301
  __disable_irq();
291
  __disable_irq();
302
  HAL_UART_Init(ctl->Handle);
292
  HAL_UART_Init(ctl->Handle);
303
  __enable_irq();
293
  __enable_irq();
304
}
294
}
305
 
295
 
306
 
-
 
307
/////////////////////////////////////////////////////////
296
/////////////////////////////////////////////////////////
308
/// Moved from generated code  to avoid crappy HAL handler
297
/// Moved from generated code  to avoid crappy HAL handler
309
#if defined SERIAL_UART1
298
#if defined SERIAL_UART1
310
void USART1_IRQHandler(void)
299
void USART1_IRQHandler(void)
311
{
300
{