43
43
#endif
44
44
#define MODEM_LINK_DEVICE_SHMEM_DBG if (MODEM_LINK_DEVICE_SHMEM_DBG_ON) tr_info
45
45
46
- #define SHMEM_CIRC_BUFFER_ERROR (-10 )
46
+ #define SHMEM_CIRC_BUFFER_ERROR (-10 )
47
47
48
48
49
49
@@ -60,20 +60,22 @@ Thread *msgrxwork;
60
60
Thread *irqwork;
61
61
Semaphore modem_link_device_sem (0 , 512 );
62
62
63
- bool shmem_ready= 0 ;
63
+ bool shmem_ready = 0 ;
64
64
65
65
int ShmemIpcDevice::get_txq_space (void )
66
66
{
67
67
unsigned int head = *txq.head ;
68
68
unsigned int tail = *txq.tail ;
69
69
int space;
70
70
71
- if ((head >= txq.size ) || (tail >= txq.size ))
72
- return SHMEM_CIRC_BUFFER_ERROR;
71
+ if ((head >= txq.size ) || (tail >= txq.size )) {
72
+ return SHMEM_CIRC_BUFFER_ERROR;
73
+ }
73
74
74
75
space = tail - head - 1 ;
75
- if (space < 0 )
76
- space += txq.size ;
76
+ if (space < 0 ) {
77
+ space += txq.size ;
78
+ }
77
79
78
80
return space;
79
81
}
@@ -94,31 +96,37 @@ void ShmemIpcDevice::write_ipc_to_txq(mio_buf *mio)
94
96
95
97
/* Write HEADER to the TXQ, assume that with padding aligned on 4 bytes */
96
98
i = in >> 2 ;
97
- for (j = 0 ; j < EXYNOS_HEADER_SIZE/ 4 ; j++) {
99
+ for (j = 0 ; j < EXYNOS_HEADER_SIZE / 4 ; j++) {
98
100
buff[i] = header[j];
99
101
i ++;
100
- if (i == qsize>>2 ){
101
- i = 0 ;}
102
- MBED_ASSERT (i < qsize>>2 );
102
+ if (i == qsize >> 2 ) {
103
+ i = 0 ;
104
+ }
105
+ MBED_ASSERT (i < qsize >> 2 );
103
106
}
104
107
105
108
in += EXYNOS_HEADER_SIZE;
106
- if (in >= qsize) in -= qsize;
109
+ if (in >= qsize) {
110
+ in -= qsize;
111
+ }
107
112
108
113
/* Write data to the TXQ, assume that with padding aligned on 4 bytes */
109
114
i = in >> 2 ;
110
- for (j = 0 ; j < (len + pad)/ 4 ; j ++) {
115
+ for (j = 0 ; j < (len + pad) / 4 ; j ++) {
111
116
buff[i] = src[j];
112
117
i ++;
113
- if (i == qsize>>2 ){
114
- i = 0 ;}
115
- MBED_ASSERT (i < qsize>>2 );
118
+ if (i == qsize >> 2 ) {
119
+ i = 0 ;
120
+ }
121
+ MBED_ASSERT (i < qsize >> 2 );
116
122
}
117
123
118
124
in += len + pad;
119
- if (in >= qsize) in -= qsize;
125
+ if (in >= qsize) {
126
+ in -= qsize;
127
+ }
120
128
121
- *txq.head = in;
129
+ *txq.head = in;
122
130
}
123
131
124
132
int ShmemIpcDevice::xmit_ipc_msg (mio_buf *msg)
@@ -153,22 +161,20 @@ int ShmemIpcDevice::xmit_ipc_msg(mio_buf *msg)
153
161
154
162
/* Get the size of free space in the TXQ */
155
163
space = get_txq_space ();
156
- if (space < 0 )
157
- {
164
+ if (space < 0 ) {
158
165
/* TXQ ERROR */
159
166
copied = -EIO;
160
167
return copied;// break;
161
168
}
162
169
163
170
/* TO DO - check free memory space if it fits all headres !!!
164
- Check the free space size,
171
+ Check the free space size,
165
172
- FMT : comparing with mxb->len
166
173
- RAW : check used buffer size */
167
174
chk_nospc = (space < msg->len ) ? true : false ;
168
175
169
- if (chk_nospc)
170
- {
171
- /* TO DO - implement this back pressure to operate properly. */
176
+ if (chk_nospc) {
177
+ /* TO DO - implement this back pressure to operate properly. */
172
178
printf (" ERROR Not implement %s:%d\n " , __func__, __LINE__);
173
179
while (1 );
174
180
/* Set res_required flag for the "dev" */
@@ -434,15 +440,15 @@ void ShmemIpcDevice::done_req_ack(void)
434
440
435
441
void ShmemIpcDevice::recv_res_ack (unsigned short intr)
436
442
{
437
- /*
438
- This method is used to nodify about receiving response
439
- from CP on req_ack sent earlier to confirm CPis alive
440
- In fact we never sent is, so nothing to receive.
441
- */
442
- if (intr & mask_res_ack) {
443
- /* We should not get here!!! */
444
- while (1 );
445
- }
443
+ /*
444
+ This method is used to nodify about receiving response
445
+ from CP on req_ack sent earlier to confirm CPis alive
446
+ In fact we never sent is, so nothing to receive.
447
+ */
448
+ if (intr & mask_res_ack) {
449
+ /* We should not get here!!! */
450
+ while (1 );
451
+ }
446
452
}
447
453
448
454
void ShmemIpcDevice::recv_req_ack (unsigned short intr)
@@ -500,12 +506,14 @@ int ShmemIpcDevice::rx_ipc_frames(void)
500
506
{
501
507
int i;
502
508
503
- /* buffer indeces are corrupted*/
504
- if ((*rxq.head >= rxq.size ) || (*rxq.tail >= rxq.size ))
505
- return -5 ;
506
- /* nothing to read */
507
- if (*rxq.head == *rxq.tail )
508
- return 0 ;
509
+ /* buffer indeces are corrupted*/
510
+ if ((*rxq.head >= rxq.size ) || (*rxq.tail >= rxq.size )) {
511
+ return -5 ;
512
+ }
513
+ /* nothing to read */
514
+ if (*rxq.head == *rxq.tail ) {
515
+ return 0 ;
516
+ }
509
517
510
518
ShmemLinkDevice *ld = pShmemLinkDevice;
511
519
@@ -516,61 +524,63 @@ int ShmemIpcDevice::rx_ipc_frames(void)
516
524
/* *
517
525
* variables for RX processing
518
526
*/
519
- int rcvd; /* size of data in the RXQ or error */
520
- int rest; /* size of the rest data */
521
- unsigned int out; /* index to the start of current frame */
522
- int tot; /* total length including padding data */
527
+ int rcvd; /* size of data in the RXQ or error */
528
+ int rest; /* size of the rest data */
529
+ unsigned int out; /* index to the start of current frame */
530
+ int tot; /* total length including padding data */
523
531
524
532
rcvd = *rxq.head - *rxq.tail ;
525
- if (rcvd < 0 )
526
- rcvd += rxq.size ;
533
+ if (rcvd < 0 ) {
534
+ rcvd += rxq.size ;
535
+ }
527
536
528
537
rest = rcvd;
529
538
out = *rxq.tail ;
530
539
531
540
while (rest > 0 ) {
532
541
mio_buf *msg;
533
542
534
- if (rest < EXYNOS_HEADER_SIZE)
535
- return -75 ;
536
-
537
- for (i = 0 ; i < EXYNOS_HEADER_SIZE/4 ; i ++) {
538
- ((unsigned int *)hdr)[i] = ((unsigned int *)rxq.buff )[out>>2 ];
539
- out += 4 ;
540
- if (out >= rxq.size )
541
- out = 0 ;
542
- }
543
+ if (rest < EXYNOS_HEADER_SIZE) {
544
+ return -75 ;
545
+ }
546
+
547
+ for (i = 0 ; i < EXYNOS_HEADER_SIZE / 4 ; i ++) {
548
+ ((unsigned int *)hdr)[i] = ((unsigned int *)rxq.buff )[out >> 2 ];
549
+ out += 4 ;
550
+ if (out >= rxq.size ) {
551
+ out = 0 ;
552
+ }
553
+ }
543
554
544
555
/* Check the config field in the header */
545
- if (!exynos_start_valid (hdr))
546
- {
556
+ if (!exynos_start_valid (hdr)) {
547
557
goto bad_msg;
548
558
}
549
559
550
560
/* Verify the total length of the frame (data + padding) */
551
561
tot = exynos_get_total_len (hdr);
552
- if (tot > rest)
553
- {
562
+ if (tot > rest) {
554
563
goto bad_msg;
555
564
}
556
565
557
566
msg = alloc_mio_buf (tot - EXYNOS_HEADER_SIZE);
558
- for (i = 0 ; i < (tot - EXYNOS_HEADER_SIZE)/4 ; i ++) {
559
- ((unsigned int *)(msg->data ))[i] = ((unsigned int *)rxq.buff )[out>>2 ];
560
- out += 4 ;
561
- if (out >= rxq.size )
562
- out = 0 ;
563
- }
567
+ for (i = 0 ; i < (tot - EXYNOS_HEADER_SIZE) / 4 ; i ++) {
568
+ ((unsigned int *)(msg->data ))[i] = ((unsigned int *)rxq.buff )[out >> 2 ];
569
+ out += 4 ;
570
+ if (out >= rxq.size ) {
571
+ out = 0 ;
572
+ }
573
+ }
564
574
565
575
566
576
msg->ch = exynos_get_ch (hdr);
567
577
568
- if (msg->ch == 254 ){
569
- msg->len = tot - EXYNOS_HEADER_SIZE;
570
- } else {
571
- /* Use actual frame len to pass real payload length to upper layer */
572
- msg->len = exynos_get_frame_len (hdr) - EXYNOS_HEADER_SIZE;
573
- }
578
+ if (msg->ch == 254 ) {
579
+ msg->len = tot - EXYNOS_HEADER_SIZE;
580
+ } else {
581
+ /* Use actual frame len to pass real payload length to upper layer */
582
+ msg->len = exynos_get_frame_len (hdr) - EXYNOS_HEADER_SIZE;
583
+ }
574
584
575
585
ld->ipc_rxq .put (msg);
576
586
ld->ipc_rx_sem ->release ();
@@ -694,10 +704,10 @@ void msg_handler(void)
694
704
ipc = ld->ipc_device [i];
695
705
ret = ipc->rx_ipc_frames ();
696
706
697
- /* TODO review below case and handle it properly!!! */
698
- /* In case of error just return. Shall we do aything here? */
707
+ /* TODO review below case and handle it properly!!! */
708
+ /* In case of error just return. Shall we do aything here? */
699
709
if (ret < 0 )
700
- while (1 );
710
+ while (1 );
701
711
702
712
ipc->done_req_ack ();
703
713
}
@@ -718,19 +728,18 @@ void ipc_rx_task(void)
718
728
return ;
719
729
}
720
730
721
- if (INT_VALID (int2ap)) {
722
- /* Make CP happy with our fake responses we are alive ... */
723
- /* However CP never sends it ... only SEND_R and SEND_F */
724
- /* Check and receive RES_ACK from CP */
725
- /* Check and receive REQ_ACK from CP */
726
- for (i = 0 ; i < MAX_IPC_DEV; i++)
727
- {
728
- ld->ipc_device [i]->recv_res_ack (int2ap);
729
- ld->ipc_device [i]->recv_req_ack (int2ap);
730
- }
731
+ if (INT_VALID (int2ap)) {
732
+ /* Make CP happy with our fake responses we are alive ... */
733
+ /* However CP never sends it ... only SEND_R and SEND_F */
734
+ /* Check and receive RES_ACK from CP */
735
+ /* Check and receive REQ_ACK from CP */
736
+ for (i = 0 ; i < MAX_IPC_DEV; i++) {
737
+ ld->ipc_device [i]->recv_res_ack (int2ap);
738
+ ld->ipc_device [i]->recv_req_ack (int2ap);
739
+ }
731
740
732
- msg_handler ();
733
- }
741
+ msg_handler ();
742
+ }
734
743
}
735
744
736
745
void msg_rx_work (void )
0 commit comments