aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--projects/hsm/hsm.c26
1 files changed, 16 insertions, 10 deletions
diff --git a/projects/hsm/hsm.c b/projects/hsm/hsm.c
index c2f6e0e..60e35fc 100644
--- a/projects/hsm/hsm.c
+++ b/projects/hsm/hsm.c
@@ -3,7 +3,7 @@
* ----------------
* Main module for the HSM project.
*
- * Copyright (c) 2016, NORDUnet A/S All rights reserved.
+ * Copyright (c) 2016-2017, NORDUnet A/S All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
@@ -94,13 +94,18 @@ typedef struct {
/* A mail queue (memory pool + message queue) for RPC request messages.
*/
osMailQId ibuf_queue;
-osMailQDef(ibuf_queue, NUM_RPC_TASK, rpc_buffer_t);
+osMailQDef(ibuf_queue, NUM_RPC_TASK + 2, rpc_buffer_t);
#if NUM_RPC_TASK > 1
/* A mutex to arbitrate concurrent UART transmits, from RPC responses.
*/
osMutexId uart_mutex;
osMutexDef(uart_mutex);
+static inline void uart_lock(void) { osMutexWait(uart_mutex, osWaitForever); }
+static inline void uart_unlock(void) { osMutexRelease(uart_mutex); }
+#else
+static inline void uart_lock(void) { }
+static inline void uart_unlock(void) { }
#endif
#if NUM_RPC_TASK > 1
@@ -130,7 +135,13 @@ static void RxCallback(uint8_t c)
if (ibuf == NULL) {
if ((ibuf = (rpc_buffer_t *)osMailAlloc(ibuf_queue, 0)) == NULL)
- Error_Handler();
+ /* This could happen if all dispatch threads are busy, and
+ * there are NUM_RPC_TASK requests already queued. We'd like
+ * to to send a "server busy" error, but we've just received
+ * the first byte of the request, so we don't yet have enough
+ * context to craft a response.
+ */
+ return;
ibuf->len = 0;
}
@@ -185,7 +196,6 @@ void dispatch_thread(void const *args)
hal_error_t ret = hal_rpc_server_dispatch(ibuf->buf, ibuf->len, obuf->buf, &obuf->len);
osMailFree(ibuf_queue, (void *)ibuf);
if (ret != LIBHAL_OK) {
- Error_Handler();
/* If hal_rpc_server_dispatch failed with an XDR error, it
* probably means the request packet was garbage. In any case, we
* have nothing to transmit.
@@ -194,13 +204,9 @@ void dispatch_thread(void const *args)
}
/* Send the response */
-#if NUM_RPC_TASK > 1
- osMutexWait(uart_mutex, osWaitForever);
-#endif
+ uart_lock();
ret = hal_rpc_sendto(obuf->buf, obuf->len, NULL);
-#if NUM_RPC_TASK > 1
- osMutexRelease(uart_mutex);
-#endif
+ uart_unlock();
if (ret != LIBHAL_OK)
Error_Handler();
}
-0400 Check the HARDWARE_EARLY_DFU_JUMP flag as soon as possible in the boot process.' href='/sw/stm32/commit/Makefile?id=2dd70b171bde90620a631b6ba8d129acc911f93e'>2dd70b1
e3db117



e3fe7d8
e3db117



4a38cf6
a5850b4
26f1290
4c6b056
4a38cf6
684b0c0
26f1290
4c6b056
ee19acb
79b1ba7
4a38cf6
79b1ba7

4a38cf6

9915d1b

ee19acb






fd2c935

ee19acb

26f1290
4c6b056
fb73e2d






26f1290
fb931db










4c6b056
fb931db
26f1290

4c6b056
a59302f
0345b66
7f390d5
9278e9b
a5850b4






4c6b056
26f1290
4a38cf6





f296bc7
26f1290
d1462f0
4a38cf6
26f1290
d1462f0
79b1ba7
fb73e2d
d1462f0
9bbc072

d1462f0
4a38cf6

d1462f0
4a38cf6

d1462f0
e3db117
26f1290
d1462f0
e3db117
9278e9b
d1462f0
e3db117
802a6f3
d1462f0
79b1ba7
9278e9b
d1462f0
a59302f

d1462f0
684b0c0

4c6b056
79b1ba7

f296bc7
9278e9b
d1462f0








26f1290
79b1ba7
fb931db
79b1ba7
e9cd8ff
4a38cf6
79b1ba7
a59302f
fb931db
26f1290

4a38cf6

e3db117

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187