Fork

Dependencies:   mbed libscpi

Committer:
bavovanachte
Date:
Tue Jun 08 12:06:30 2021 +0000
Revision:
26:beaf802e2456
Parent:
25:8367b3fe2891
Child:
30:b463e1f3cae3
First successful trials with libscpi

Who changed what in which revision?

UserRevisionLine numberNew contents of line
wuliqunyy 16:a0bfe33f8a4a 1 #include "uart_mbed.h"
wuliqunyy 16:a0bfe33f8a4a 2 #include "mbed.h"
bavovanachte 26:beaf802e2456 3 #include "scpi/scpi.h"
bavovanachte 26:beaf802e2456 4
wuliqunyy 16:a0bfe33f8a4a 5
wuliqunyy 16:a0bfe33f8a4a 6 Serial pc(USBTX, USBRX); // tx, rx
wuliqunyy 16:a0bfe33f8a4a 7
wuliqunyy 16:a0bfe33f8a4a 8 void uart_print(char *buffer){
wuliqunyy 16:a0bfe33f8a4a 9 pc.printf("RAM_ADDR:%02X MByte:%02X LByte:%02X'\n", *buffer, *(buffer+1),*(buffer+2));
wuliqunyy 16:a0bfe33f8a4a 10 }
wuliqunyy 16:a0bfe33f8a4a 11
wuliqunyy 16:a0bfe33f8a4a 12 void uart_read(char *buffer){
wuliqunyy 16:a0bfe33f8a4a 13 pc.gets(buffer, 20);
wuliqunyy 16:a0bfe33f8a4a 14 }
bavovanachte 25:8367b3fe2891 15
bavovanachte 25:8367b3fe2891 16 void uart_write(char *buffer){
bavovanachte 25:8367b3fe2891 17 pc.printf(buffer);
bavovanachte 25:8367b3fe2891 18 }
wuliqunyy 16:a0bfe33f8a4a 19
wuliqunyy 16:a0bfe33f8a4a 20 void uart_start(){
wuliqunyy 16:a0bfe33f8a4a 21 pc.printf("data_start\n");
wuliqunyy 16:a0bfe33f8a4a 22 }
wuliqunyy 16:a0bfe33f8a4a 23
wuliqunyy 16:a0bfe33f8a4a 24 void uart_I2C_test_pass(){
wuliqunyy 16:a0bfe33f8a4a 25 pc.printf("i2c_test_pass, ready!\n");
wuliqunyy 16:a0bfe33f8a4a 26 }
wuliqunyy 16:a0bfe33f8a4a 27
wuliqunyy 16:a0bfe33f8a4a 28 void uart_I2C_test_fail(){
wuliqunyy 16:a0bfe33f8a4a 29 pc.printf("i2c_test_fail\n");
wuliqunyy 16:a0bfe33f8a4a 30 }
wuliqunyy 16:a0bfe33f8a4a 31
wuliqunyy 16:a0bfe33f8a4a 32 void uart_ram_dump_finish(){
wuliqunyy 16:a0bfe33f8a4a 33 pc.printf("dump_finish\n");
wuliqunyy 16:a0bfe33f8a4a 34 }
bavovanachte 26:beaf802e2456 35
bavovanachte 26:beaf802e2456 36
bavovanachte 26:beaf802e2456 37
bavovanachte 26:beaf802e2456 38 int SCPI_Error(scpi_t * context, int_fast16_t err) {
bavovanachte 26:beaf802e2456 39 (void) context;
bavovanachte 26:beaf802e2456 40
bavovanachte 26:beaf802e2456 41 printf("**ERROR: %d, \"%s\"\r\n", (int32_t) err, SCPI_ErrorTranslate(err));
bavovanachte 26:beaf802e2456 42 return 0;
bavovanachte 26:beaf802e2456 43 }
bavovanachte 26:beaf802e2456 44
bavovanachte 26:beaf802e2456 45 size_t SCPI_Write(scpi_t * context, const char * data, size_t len) {
bavovanachte 26:beaf802e2456 46 (void) context;
bavovanachte 26:beaf802e2456 47 return fwrite(data, 1, len, stdout);
bavovanachte 26:beaf802e2456 48 }
bavovanachte 26:beaf802e2456 49
bavovanachte 26:beaf802e2456 50 scpi_result_t SCPI_Flush(scpi_t * context) {
bavovanachte 26:beaf802e2456 51 fflush(stdout);
bavovanachte 26:beaf802e2456 52 return SCPI_RES_OK;
bavovanachte 26:beaf802e2456 53 }
bavovanachte 26:beaf802e2456 54
bavovanachte 26:beaf802e2456 55 /**
bavovanachte 26:beaf802e2456 56 * Return 0 as OK and other number as error
bavovanachte 26:beaf802e2456 57 */
bavovanachte 26:beaf802e2456 58 scpi_result_t SCPI_Test(scpi_t * context) {
bavovanachte 26:beaf802e2456 59 printf("**Test\r\n");
bavovanachte 26:beaf802e2456 60 return (scpi_result_t)0;
bavovanachte 26:beaf802e2456 61 }
bavovanachte 26:beaf802e2456 62
bavovanachte 26:beaf802e2456 63 scpi_result_t SCPI_Reset(scpi_t * context)
bavovanachte 26:beaf802e2456 64 {
bavovanachte 26:beaf802e2456 65 printf("**Reset\r\n");
bavovanachte 26:beaf802e2456 66 return SCPI_RES_OK;
bavovanachte 26:beaf802e2456 67 }
bavovanachte 26:beaf802e2456 68
bavovanachte 26:beaf802e2456 69 scpi_result_t SCPI_Control(scpi_t * context, scpi_ctrl_name_t ctrl, scpi_reg_val_t val) {
bavovanachte 26:beaf802e2456 70 if (SCPI_CTRL_SRQ == ctrl) {
bavovanachte 26:beaf802e2456 71 printf("**SRQ: 0x%X (%d)\r\n", val, val);
bavovanachte 26:beaf802e2456 72 } else {
bavovanachte 26:beaf802e2456 73 printf("**CTRL %02x: 0x%X (%d)\r\n", ctrl, val, val);
bavovanachte 26:beaf802e2456 74 }
bavovanachte 26:beaf802e2456 75 return SCPI_RES_OK;
bavovanachte 26:beaf802e2456 76 }
bavovanachte 26:beaf802e2456 77
bavovanachte 26:beaf802e2456 78