[Cryptech-Commits] [sw/stm32] 01/02: Merge branch 'alternate_dma'

git at cryptech.is git at cryptech.is
Sun Jun 26 05:14:47 UTC 2016


This is an automated email from the git hooks/post-receive script.

paul at psgd.org pushed a commit to branch master
in repository sw/stm32.

commit 165e3252276676bcfccc56a0bb417511c817789b
Merge: e3db117 c1d0738
Author: Paul Selkirk <paul at psgd.org>
AuthorDate: Sat Jun 25 22:28:29 2016 -0400

    Merge branch 'alternate_dma'

 projects/hsm/mgmt-cli.c | 83 ++++++++++++++++++++++++++++++++-----------------
 1 file changed, 55 insertions(+), 28 deletions(-)

diff --cc projects/hsm/mgmt-cli.c
index 2606e21,d9c0bd9..61c8c35
--- a/projects/hsm/mgmt-cli.c
+++ b/projects/hsm/mgmt-cli.c
@@@ -43,29 -45,75 +45,62 @@@
  #include "mgmt-fpga.h"
  #include "mgmt-misc.h"
  #include "mgmt-show.h"
 +#include "mgmt-keystore.h"
 +#include "mgmt-masterkey.h"
  
- /* MGMT UART interrupt receive buffer (data will be put in a larger ring buffer) */
- volatile uint8_t uart_rx;
- 
  #ifndef CLI_UART_RECVBUF_SIZE
--#define CLI_UART_RECVBUF_SIZE  256  /* This must be a power of 2 */
++#define CLI_UART_RECVBUF_SIZE  256
  #endif
--#define CLI_UART_RECVBUF_MASK  (CLI_UART_RECVBUF_SIZE - 1)
  
  typedef struct {
-     uint32_t enabled, ridx;
+     int ridx;
 -    int widx;	
++    volatile int widx;	
      mgmt_cli_dma_state_t rx_state;
      uint8_t buf[CLI_UART_RECVBUF_SIZE];
- } uart_ringbuf_t;
+ } ringbuf_t;
+ 
+ inline void ringbuf_init(ringbuf_t *rb)
+ {
+     memset(rb, 0, sizeof(*rb));
+ }
+ 
+ /* return number of characters read */
+ inline int ringbuf_read_char(ringbuf_t *rb, uint8_t *c)
+ {
+     if (rb->ridx != rb->widx) {
+         *c = rb->buf[rb->ridx];
+         if (++rb->ridx >= sizeof(rb->buf))
+             rb->ridx = 0;
+         return 1;
+     }
+     return 0;
+ }
  
- volatile uart_ringbuf_t uart_ringbuf = {1, 0, DMA_RX_STOP, {0}};
+ inline void ringbuf_write_char(ringbuf_t *rb, uint8_t c)
+ {
+     rb->buf[rb->widx] = c;
+     if (++rb->widx >= sizeof(rb->buf))
+         rb->widx = 0;
+ }
  
- #define RINGBUF_RIDX(rb)       (rb.ridx & CLI_UART_RECVBUF_MASK)
- #define RINGBUF_WIDX(rb)       (sizeof(rb.buf) - __HAL_DMA_GET_COUNTER(huart_mgmt.hdmarx))
- #define RINGBUF_COUNT(rb)      ((unsigned)(RINGBUF_WIDX(rb) - RINGBUF_RIDX(rb)))
- #define RINGBUF_READ(rb, dst)  {dst = rb.buf[RINGBUF_RIDX(rb)]; rb.buf[RINGBUF_RIDX(rb)] = '.'; rb.ridx++;}
 -/* some possibly-useful functions */
 -inline int ringbuf_empty(ringbuf_t *rb)
 -{
 -    return (rb->ridx == rb->widx);
 -}
 -
 -inline int ringbuf_count(ringbuf_t *rb)
 -{
 -    int len = rb->widx - rb->ridx;
 -    if (len < 0)
 -        len += sizeof(rb->buf);
 -    return len;
 -}
 -
+ static ringbuf_t uart_ringbuf;
+ 
+ /* current character received from UART */
+ static uint8_t uart_rx;
+ 
+ /* Semaphore to inform uart_cli_read that there's a new character.
+  */
+ osSemaphoreId  uart_sem;
+ osSemaphoreDef(uart_sem);
+ 
+ /* Callback for HAL_UART_Receive_DMA().
+  */
+ void HAL_UART1_RxCpltCallback(UART_HandleTypeDef *huart)
+ {
+     ringbuf_write_char(&uart_ringbuf, uart_rx);
+     osSemaphoreRelease(uart_sem);
+     HAL_UART_Receive_DMA(huart, &uart_rx, 1);
+ }
  
  static void uart_cli_print(struct cli_def *cli __attribute__ ((unused)), const char *buf)
  {



More information about the Commits mailing list