Christina Quast | 2b8a18b | 2015-04-12 09:31:36 +0200 | [diff] [blame^] | 1 | #include "board.h" |
| 2 | |
| 3 | static volatile bool write_to_host_in_progress = false; |
| 4 | |
| 5 | void USB_write_callback(uint8_t *pArg, uint8_t status, uint32_t transferred, uint32_t remaining) |
| 6 | { |
| 7 | if (status != USBD_STATUS_SUCCESS) { |
| 8 | TRACE_ERROR("USB err status: %d (%s)\n", __FUNCTION__, status); |
| 9 | } |
| 10 | write_to_host_in_progress = false; |
| 11 | printf("WR_CB\n"); |
| 12 | } |
| 13 | |
| 14 | int send_to_host() |
| 15 | { |
| 16 | static uint8_t msg[RING_BUFLEN]; |
| 17 | int ret = 0; |
| 18 | int i; |
| 19 | |
| 20 | for(i = 0; !rbuf_is_empty(&sim_rcv_buf) && i < sizeof(msg); i++) { |
| 21 | msg[i] = rbuf_read(&sim_rcv_buf); |
| 22 | } |
| 23 | printf("Wr %d\n", i); |
| 24 | write_to_host_in_progress = true; |
| 25 | ret = USBD_Write( PHONE_DATAIN, msg, i, (TransferCallback)&USB_write_callback, 0 ); |
| 26 | if (ret != USBD_STATUS_SUCCESS) { |
| 27 | TRACE_ERROR("Error sending to host (%x)\n", ret); |
| 28 | write_to_host_in_progress = false; |
| 29 | } |
| 30 | return ret; |
| 31 | } |
| 32 | |
| 33 | int check_data_from_phone() |
| 34 | { |
| 35 | int ret = 0; |
| 36 | |
| 37 | if((rbuf_is_empty(&sim_rcv_buf) || write_to_host_in_progress == true)) { |
| 38 | return ret; |
| 39 | } |
| 40 | ret = send_to_host(); |
| 41 | return ret; |
| 42 | } |