aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/phone_svn/ipc_spi/spi_app.c
blob: 110d19351eff0e33ea8f28c349b3ea9297a5dcad (plain)
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
/**************************************************************

	spi_app.c



	interface spi and app



	This is MASTER side.

***************************************************************/



/**************************************************************

	Preprocessor by common

***************************************************************/

#include "spi_main.h"
#include "spi_app.h"
#include "spi_os.h"
#include "spi_data.h"
#include "spi_test.h"

static unsigned int _pack_spi_data(enum SPI_DATA_TYPE_T type, void *buf,
		void *data, unsigned int length);


/**********************************************************
Prototype		void spi_app_receive_msg ( struct spi_os_msg * msg )
Type		function
Description	receive data from spi task message queue and
			Pack data for spi data.
			Then inqueue the message to spi_data_queue_XXX_tx
Param input	msg	: message received from other task
Return value	(none)
***********************************************************/
void spi_receive_msg_from_app(struct spi_os_msg *msg)
{
	enum SPI_MAIN_MSG_T type;
	enum SPI_DATA_QUEUE_TYPE_T q_type;
	enum SPI_DATA_TYPE_T mux_type;
	unsigned int in_length = 0, out_length = 0;
	void *in_buffer = 0;
	void *out_buffer = 0;

	type = msg->signal_code;
	in_length = msg->data_length;
	in_buffer = msg->data;

	switch (type) {
	case SPI_MAIN_MSG_IPC_SEND:
		q_type = SPI_DATA_QUEUE_TYPE_IPC_TX;
		mux_type = SPI_DATA_MUX_IPC;
		break;

	case SPI_MAIN_MSG_RAW_SEND:
		q_type = SPI_DATA_QUEUE_TYPE_RAW_TX;
		mux_type = SPI_DATA_MUX_RAW;
		break;

	case SPI_MAIN_MSG_RFS_SEND:
		q_type = SPI_DATA_QUEUE_TYPE_RFS_TX;
		mux_type = SPI_DATA_MUX_RFS;
		break;

	default:
		SPI_OS_ASSERT(("[SPI] spi_app_receive_msg Unknown type"));
		return;
	}

	out_buffer = spi_os_malloc(in_length+SPI_DATA_HEADER_SIZE);
	out_length = _pack_spi_data(mux_type, out_buffer, in_buffer, in_length);

	if (spi_data_inqueue(&spi_queue_info[q_type], out_buffer,
		out_length) == 0) {
		SPI_OS_ASSERT(("[SPI] spi_app_receive_msg inqueue[%d] Fail",
			q_type));
	}

	spi_os_free(in_buffer);
	spi_os_free(out_buffer);
}


/**********************************************************
Prototype	void spi_send_msg ( void )
Type			function
Description	Dequeue a spi data from spi_data_queue_XXX_rx
			Unpack the spi data for ipc, raw or rfs data
			Send msg to other task until that all queues are empty
			CP use this functions for other task as below
			IPC : ipc_cmd_send_queue
			RAW : data_send_queue
			RFS : rfs_send_queue
Param input	(none)
Return value	(none)
***********************************************************/
void spi_send_msg_to_app(void)
{
	u32 int_cmd = 0;
	struct ipc_spi *od_spi = NULL;

	#define MB_VALID					0x0080
	#define MB_DATA(x)				(MB_VALID | x)
	#define MBD_SEND_FMT			0x0002
	#define MBD_SEND_RAW			0x0001
	#define MBD_SEND_RFS			0x0100


	od_spi = ipc_spi;


	if (spi_data_queue_is_empty(SPI_DATA_QUEUE_TYPE_IPC_RX) == 0) {
		int_cmd = MB_DATA(MBD_SEND_FMT);
		ipc_spi_make_data_interrupt(int_cmd, od_spi);
	}

	if (spi_data_queue_is_empty(SPI_DATA_QUEUE_TYPE_RAW_RX) == 0) {
		int_cmd = MB_DATA(MBD_SEND_RAW);
		ipc_spi_make_data_interrupt(int_cmd, od_spi);
	}

	if (spi_data_queue_is_empty(SPI_DATA_QUEUE_TYPE_RFS_RX) == 0) {
		int_cmd = MB_DATA(MBD_SEND_RFS);
		ipc_spi_make_data_interrupt(int_cmd, od_spi);
	}
}


/**********************************************************
Prototype	unsigned int _pack_spi_data (SPI_DATA_TYPE_T type,void * buf, void * data, unsigned int length)
Type			static function
Description	pack data for spi
Param input	type		: type of data type
			buf			: address of buffer to be saved
			data		: address of data to pack
			length	: length of input data
Return value	length of packed data
***********************************************************/
static unsigned int _pack_spi_data(enum SPI_DATA_TYPE_T type, void *buf,
		void *data, unsigned int length)
{
	char *spi_packet	 = NULL;
	unsigned int out_length = 0;

	spi_packet = (char *) buf;

	spi_os_memset((char *)spi_packet, 0x00, (unsigned int)length);
	spi_os_memset((char *)spi_packet, (unsigned char)SPI_DATA_BOF,
		SPI_DATA_BOF_SIZE);
	spi_os_memcpy((char *)spi_packet + SPI_DATA_BOF_SIZE, data, length);
	spi_os_memset((char *)spi_packet + SPI_DATA_BOF_SIZE + length,
		(unsigned char)SPI_DATA_EOF, SPI_DATA_EOF_SIZE);

	out_length = SPI_DATA_BOF_SIZE + length + SPI_DATA_EOF_SIZE;

	return out_length;
}


/**********************************************************
Prototype	int spi_app_ready ( void )
Type			function
Description	check if spi initialization is done.
			Decide it as spi_main_state.
Param input	(none)
Return value	1	 : spi initialization is done.
			0	 : spi initialization is not done.
***********************************************************/
int spi_is_ready(void)
{
	if ((spi_main_state == SPI_MAIN_STATE_START) ||
		(spi_main_state == SPI_MAIN_STATE_END))
		return 0;

	return 1;
}