blob: 409937bffa79e214607e237167d2ffc74ae39caa [file] [log] [blame]
Harald Welte9d3e3822015-11-09 00:50:54 +01001#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>
8
Harald Welte203ea192016-02-28 19:31:24 +01009#define REQ_CTX_LISTS
10
Harald Welte9d3e3822015-11-09 00:50:54 +010011#define __ramfunc
12
13enum req_ctx_state {
Harald Welteb66ce242016-02-29 14:07:07 +010014 /* free to be allocated */
Harald Welte9d3e3822015-11-09 00:50:54 +010015 RCTX_S_FREE,
Harald Welteb66ce242016-02-29 14:07:07 +010016
Harald Welte9d3e3822015-11-09 00:50:54 +010017 /* USB -> UART */
Harald Welteb66ce242016-02-29 14:07:07 +010018 /* In USB driver, waiting for data from host */
Harald Welte9d3e3822015-11-09 00:50:54 +010019 RCTX_S_USB_RX_BUSY,
Harald Welteb66ce242016-02-29 14:07:07 +010020 /* somewhere in the main loop */
Harald Welte9d3e3822015-11-09 00:50:54 +010021 RCTX_S_MAIN_PROCESSING,
Harald Welteb66ce242016-02-29 14:07:07 +010022 /* pending (in queue) for transmission on UART */
Harald Welte9d3e3822015-11-09 00:50:54 +010023 RCTX_S_UART_TX_PENDING,
Harald Welteb66ce242016-02-29 14:07:07 +010024 /* currently in active transmission on UART */
Harald Welte9d3e3822015-11-09 00:50:54 +010025 RCTX_S_UART_TX_BUSY,
Harald Welteb66ce242016-02-29 14:07:07 +010026
Harald Welte9d3e3822015-11-09 00:50:54 +010027 /* UART -> USB */
Harald Welteb66ce242016-02-29 14:07:07 +010028 /* currently in active reception on UART */
Harald Welte9d3e3822015-11-09 00:50:54 +010029 RCTX_S_UART_RX_BUSY,
Harald Welteb66ce242016-02-29 14:07:07 +010030 /* pending (in queue) for transmission over USB to host */
Harald Welte9d3e3822015-11-09 00:50:54 +010031 RCTX_S_USB_TX_PENDING,
Harald Welteb66ce242016-02-29 14:07:07 +010032 /* currently in transmission over USB to host */
Harald Welte9d3e3822015-11-09 00:50:54 +010033 RCTX_S_USB_TX_BUSY,
Harald Welteb66ce242016-02-29 14:07:07 +010034
Harald Welte9d3e3822015-11-09 00:50:54 +010035 /* number of states */
36 RCTX_STATE_COUNT
37};
38
39struct req_ctx {
40 /* enum req_ctx_state */
41 volatile uint32_t state;
42#ifdef REQ_CTX_LISTS
43 /* pointers for queues */
44 volatile struct req_ctx *prev, *next;
45#endif
46 /* size of th 'data' buffer */
47 uint16_t size;
48 /* total number of used bytes in buffer */
49 uint16_t tot_len;
50 /* index into the buffer, user specific */
51 uint16_t idx;
52 /* actual data buffer */
53 uint8_t *data;
54};
55
56extern struct req_ctx __ramfunc *req_ctx_find_get(int large, uint32_t old_state, uint32_t new_state);
57extern struct req_ctx *req_ctx_find_busy(void);
58extern void req_ctx_set_state(struct req_ctx *ctx, uint32_t new_state);
59extern void req_ctx_put(struct req_ctx *ctx);
60extern uint8_t req_ctx_num(struct req_ctx *ctx);
61unsigned int req_ctx_count(uint32_t state);