versione corretta

Dependents:   DISCO_L475VG_IOT01-Sensors-BSP

Committer:
group-Farnell24-IOT-Team
Date:
Tue Aug 21 08:34:28 2018 +0000
Revision:
0:766454e296c3
Initial commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
group-Farnell24-IOT-Team 0:766454e296c3 1 /*
group-Farnell24-IOT-Team 0:766454e296c3 2 * Copyright (c) 2014-2015 ARM Limited. All rights reserved.
group-Farnell24-IOT-Team 0:766454e296c3 3 * SPDX-License-Identifier: Apache-2.0
group-Farnell24-IOT-Team 0:766454e296c3 4 * Licensed under the Apache License, Version 2.0 (the License); you may
group-Farnell24-IOT-Team 0:766454e296c3 5 * not use this file except in compliance with the License.
group-Farnell24-IOT-Team 0:766454e296c3 6 * You may obtain a copy of the License at
group-Farnell24-IOT-Team 0:766454e296c3 7 *
group-Farnell24-IOT-Team 0:766454e296c3 8 * http://www.apache.org/licenses/LICENSE-2.0
group-Farnell24-IOT-Team 0:766454e296c3 9 *
group-Farnell24-IOT-Team 0:766454e296c3 10 * Unless required by applicable law or agreed to in writing, software
group-Farnell24-IOT-Team 0:766454e296c3 11 * distributed under the License is distributed on an AS IS BASIS, WITHOUT
group-Farnell24-IOT-Team 0:766454e296c3 12 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
group-Farnell24-IOT-Team 0:766454e296c3 13 * See the License for the specific language governing permissions and
group-Farnell24-IOT-Team 0:766454e296c3 14 * limitations under the License.
group-Farnell24-IOT-Team 0:766454e296c3 15 */
group-Farnell24-IOT-Team 0:766454e296c3 16
group-Farnell24-IOT-Team 0:766454e296c3 17 #include <stdarg.h>
group-Farnell24-IOT-Team 0:766454e296c3 18 #include <stdint.h>
group-Farnell24-IOT-Team 0:766454e296c3 19 #include <stdio.h>
group-Farnell24-IOT-Team 0:766454e296c3 20 #include <string.h>
group-Farnell24-IOT-Team 0:766454e296c3 21
group-Farnell24-IOT-Team 0:766454e296c3 22 #include "mbed_error.h"
group-Farnell24-IOT-Team 0:766454e296c3 23
group-Farnell24-IOT-Team 0:766454e296c3 24 size_t BufferedSpiThunk(void *buf_serial, const void *s, size_t length);
group-Farnell24-IOT-Team 0:766454e296c3 25
group-Farnell24-IOT-Team 0:766454e296c3 26 int BufferedPrintfC(void *stream, int size, const char* format, va_list arg)
group-Farnell24-IOT-Team 0:766454e296c3 27 {
group-Farnell24-IOT-Team 0:766454e296c3 28 int r;
group-Farnell24-IOT-Team 0:766454e296c3 29 char buffer[512];
group-Farnell24-IOT-Team 0:766454e296c3 30 if (size >= 512) {
group-Farnell24-IOT-Team 0:766454e296c3 31 return -1;
group-Farnell24-IOT-Team 0:766454e296c3 32 }
group-Farnell24-IOT-Team 0:766454e296c3 33 memset(buffer, 0, size);
group-Farnell24-IOT-Team 0:766454e296c3 34 r = vsprintf(buffer, format, arg);
group-Farnell24-IOT-Team 0:766454e296c3 35 // this may not hit the heap but should alert the user anyways
group-Farnell24-IOT-Team 0:766454e296c3 36 if(r > (int32_t) size) {
group-Farnell24-IOT-Team 0:766454e296c3 37 error("%s %d buffer overwrite (max_buf_size: %d exceeded: %d)!\r\n", __FILE__, __LINE__, size, r);
group-Farnell24-IOT-Team 0:766454e296c3 38 return 0;
group-Farnell24-IOT-Team 0:766454e296c3 39 }
group-Farnell24-IOT-Team 0:766454e296c3 40 if ( r > 0 ) {
group-Farnell24-IOT-Team 0:766454e296c3 41 BufferedSpiThunk(stream, buffer, r);
group-Farnell24-IOT-Team 0:766454e296c3 42 }
group-Farnell24-IOT-Team 0:766454e296c3 43 return r;
group-Farnell24-IOT-Team 0:766454e296c3 44 }