Harald Welte | 9d3e382 | 2015-11-09 00:50:54 +0100 | [diff] [blame] | 1 | #pragma once |
| 2 | |
| 3 | #define RCTX_SIZE_LARGE 960 |
| 4 | #define RCTX_SIZE_SMALL 320 |
| 5 | #define MAX_HDRSIZE sizeof(struct openpcd_hdr) |
| 6 | |
| 7 | #include <stdint.h> |
Harald Welte | b41598b | 2017-02-04 12:15:58 +0100 | [diff] [blame] | 8 | #include "osmocom/core/linuxlist.h" |
Harald Welte | 203ea19 | 2016-02-28 19:31:24 +0100 | [diff] [blame] | 9 | |
Harald Welte | 9d3e382 | 2015-11-09 00:50:54 +0100 | [diff] [blame] | 10 | #define __ramfunc |
| 11 | |
| 12 | enum req_ctx_state { |
Harald Welte | b66ce24 | 2016-02-29 14:07:07 +0100 | [diff] [blame] | 13 | /* free to be allocated */ |
Harald Welte | 9d3e382 | 2015-11-09 00:50:54 +0100 | [diff] [blame] | 14 | RCTX_S_FREE, |
Harald Welte | b66ce24 | 2016-02-29 14:07:07 +0100 | [diff] [blame] | 15 | |
Harald Welte | 9d3e382 | 2015-11-09 00:50:54 +0100 | [diff] [blame] | 16 | /* USB -> UART */ |
Harald Welte | b66ce24 | 2016-02-29 14:07:07 +0100 | [diff] [blame] | 17 | /* In USB driver, waiting for data from host */ |
Harald Welte | 9d3e382 | 2015-11-09 00:50:54 +0100 | [diff] [blame] | 18 | RCTX_S_USB_RX_BUSY, |
Harald Welte | b66ce24 | 2016-02-29 14:07:07 +0100 | [diff] [blame] | 19 | /* somewhere in the main loop */ |
Harald Welte | 9d3e382 | 2015-11-09 00:50:54 +0100 | [diff] [blame] | 20 | RCTX_S_MAIN_PROCESSING, |
Harald Welte | b66ce24 | 2016-02-29 14:07:07 +0100 | [diff] [blame] | 21 | /* pending (in queue) for transmission on UART */ |
Harald Welte | 9d3e382 | 2015-11-09 00:50:54 +0100 | [diff] [blame] | 22 | RCTX_S_UART_TX_PENDING, |
Harald Welte | b66ce24 | 2016-02-29 14:07:07 +0100 | [diff] [blame] | 23 | /* currently in active transmission on UART */ |
Harald Welte | 9d3e382 | 2015-11-09 00:50:54 +0100 | [diff] [blame] | 24 | RCTX_S_UART_TX_BUSY, |
Harald Welte | b66ce24 | 2016-02-29 14:07:07 +0100 | [diff] [blame] | 25 | |
Harald Welte | 9d3e382 | 2015-11-09 00:50:54 +0100 | [diff] [blame] | 26 | /* UART -> USB */ |
Harald Welte | b66ce24 | 2016-02-29 14:07:07 +0100 | [diff] [blame] | 27 | /* currently in active reception on UART */ |
Harald Welte | 9d3e382 | 2015-11-09 00:50:54 +0100 | [diff] [blame] | 28 | RCTX_S_UART_RX_BUSY, |
Harald Welte | b66ce24 | 2016-02-29 14:07:07 +0100 | [diff] [blame] | 29 | /* pending (in queue) for transmission over USB to host */ |
Harald Welte | 9d3e382 | 2015-11-09 00:50:54 +0100 | [diff] [blame] | 30 | RCTX_S_USB_TX_PENDING, |
Harald Welte | b66ce24 | 2016-02-29 14:07:07 +0100 | [diff] [blame] | 31 | /* currently in transmission over USB to host */ |
Harald Welte | 9d3e382 | 2015-11-09 00:50:54 +0100 | [diff] [blame] | 32 | RCTX_S_USB_TX_BUSY, |
Harald Welte | b66ce24 | 2016-02-29 14:07:07 +0100 | [diff] [blame] | 33 | |
Harald Welte | 9d3e382 | 2015-11-09 00:50:54 +0100 | [diff] [blame] | 34 | /* number of states */ |
| 35 | RCTX_STATE_COUNT |
| 36 | }; |
| 37 | |
| 38 | struct req_ctx { |
Harald Welte | f672e9d | 2016-02-29 14:08:12 +0100 | [diff] [blame] | 39 | /* if this req_ctx is on a queue... */ |
| 40 | struct llist_head list; |
| 41 | uint32_t ep; |
| 42 | |
Harald Welte | 9d3e382 | 2015-11-09 00:50:54 +0100 | [diff] [blame] | 43 | /* enum req_ctx_state */ |
| 44 | volatile uint32_t state; |
Harald Welte | 9d3e382 | 2015-11-09 00:50:54 +0100 | [diff] [blame] | 45 | /* size of th 'data' buffer */ |
| 46 | uint16_t size; |
| 47 | /* total number of used bytes in buffer */ |
| 48 | uint16_t tot_len; |
| 49 | /* index into the buffer, user specific */ |
| 50 | uint16_t idx; |
| 51 | /* actual data buffer */ |
| 52 | uint8_t *data; |
| 53 | }; |
| 54 | |
Harald Welte | ebbb645 | 2016-02-29 17:57:51 +0100 | [diff] [blame] | 55 | extern void req_ctx_init(void); |
Harald Welte | 9d3e382 | 2015-11-09 00:50:54 +0100 | [diff] [blame] | 56 | extern struct req_ctx __ramfunc *req_ctx_find_get(int large, uint32_t old_state, uint32_t new_state); |
| 57 | extern struct req_ctx *req_ctx_find_busy(void); |
| 58 | extern void req_ctx_set_state(struct req_ctx *ctx, uint32_t new_state); |
| 59 | extern void req_ctx_put(struct req_ctx *ctx); |
| 60 | extern uint8_t req_ctx_num(struct req_ctx *ctx); |
| 61 | unsigned int req_ctx_count(uint32_t state); |