blob: 67090a1b9819074034462c828c98d21d35876659 [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>
Harald Weltef672e9d2016-02-29 14:08:12 +01008#include "linuxlist.h"
Harald Welte203ea192016-02-28 19:31:24 +01009
Harald Welte9d3e3822015-11-09 00:50:54 +010010#define __ramfunc
11
12enum req_ctx_state {
Harald Welteb66ce242016-02-29 14:07:07 +010013 /* free to be allocated */
Harald Welte9d3e3822015-11-09 00:50:54 +010014 RCTX_S_FREE,
Harald Welteb66ce242016-02-29 14:07:07 +010015
Harald Welte9d3e3822015-11-09 00:50:54 +010016 /* USB -> UART */
Harald Welteb66ce242016-02-29 14:07:07 +010017 /* In USB driver, waiting for data from host */
Harald Welte9d3e3822015-11-09 00:50:54 +010018 RCTX_S_USB_RX_BUSY,
Harald Welteb66ce242016-02-29 14:07:07 +010019 /* somewhere in the main loop */
Harald Welte9d3e3822015-11-09 00:50:54 +010020 RCTX_S_MAIN_PROCESSING,
Harald Welteb66ce242016-02-29 14:07:07 +010021 /* pending (in queue) for transmission on UART */
Harald Welte9d3e3822015-11-09 00:50:54 +010022 RCTX_S_UART_TX_PENDING,
Harald Welteb66ce242016-02-29 14:07:07 +010023 /* currently in active transmission on UART */
Harald Welte9d3e3822015-11-09 00:50:54 +010024 RCTX_S_UART_TX_BUSY,
Harald Welteb66ce242016-02-29 14:07:07 +010025
Harald Welte9d3e3822015-11-09 00:50:54 +010026 /* UART -> USB */
Harald Welteb66ce242016-02-29 14:07:07 +010027 /* currently in active reception on UART */
Harald Welte9d3e3822015-11-09 00:50:54 +010028 RCTX_S_UART_RX_BUSY,
Harald Welteb66ce242016-02-29 14:07:07 +010029 /* pending (in queue) for transmission over USB to host */
Harald Welte9d3e3822015-11-09 00:50:54 +010030 RCTX_S_USB_TX_PENDING,
Harald Welteb66ce242016-02-29 14:07:07 +010031 /* currently in transmission over USB to host */
Harald Welte9d3e3822015-11-09 00:50:54 +010032 RCTX_S_USB_TX_BUSY,
Harald Welteb66ce242016-02-29 14:07:07 +010033
Harald Welte9d3e3822015-11-09 00:50:54 +010034 /* number of states */
35 RCTX_STATE_COUNT
36};
37
38struct req_ctx {
Harald Weltef672e9d2016-02-29 14:08:12 +010039 /* if this req_ctx is on a queue... */
40 struct llist_head list;
41 uint32_t ep;
42
Harald Welte9d3e3822015-11-09 00:50:54 +010043 /* enum req_ctx_state */
44 volatile uint32_t state;
Harald Welte9d3e3822015-11-09 00:50:54 +010045 /* 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 Welteebbb6452016-02-29 17:57:51 +010055extern void req_ctx_init(void);
Harald Welte9d3e3822015-11-09 00:50:54 +010056extern 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);