📄 clm_dspdrv.c
字号:
if (pd == 1) { /* PULSE DIALING */ current_command[4] = t2; current_command[5] = t1; } else { /* TONE DIALING */ current_command[4] = t1; current_command[5] = t2; } current_command[6] = pd; current_command[7] = 0; current_command[8] = p4 & 0xff; current_command[9] = (p4 >> 8) & 0xff; ack_or_response = 0; send_pkt_to_dsp ();}voidmodem_dial_digit(char digit){ char x; if (digit == '#') x = 0xf; else if (digit == '*') x = 0xe; else if ((digit > '@') && (digit <= 'D')) x = digit - 0x37; else x = digit - '0'; current_command[0] = 0x67; current_command[1] = 0; current_command[2] = 1; current_command[3] = 0; current_command[4] = x; current_command[5] = 0; ack_or_response = 0; send_pkt_to_dsp ();}/***********************************************************/unsigned shortTransmitLevelConverter[] = { 0x6337, 0x586d, 0x4ecf, 0x463d, 0x3e9a, 0x37cb, 0x31ba, 0x2c52, 0x2780, 0x2334, 0x1f60, 0x1bf6, 0x18ec, 0x1636, 0x13cb, 0x11a4, 0x0fbb, 0x0000};charHomologationGetTxLevel(int p1, int p2){ int x; short y; if (p1) { switch (p1) { /* These Tx levels are the defaults */ case 1: x = 9; break; case 2: x = 10; break; case 3: x = 10; break; case 4: x = 10; break; default: x = 10; } y = TransmitLevelConverter[x]; if (p2 == 0) return (y>>8) & 0xff; else return (y & 0xff); } if (p2) x = 9; else x = 12; return x*10;}voidModemSetTxLevel(int n){ current_command[0] = 0x7b; current_command[1] = 0; current_command[2] = 4; current_command[3] = 0; if (n == 0) { current_command[4] = HomologationGetTxLevel(1,1); current_command[5] = HomologationGetTxLevel(1,0); ack_or_response = 0; send_pkt_to_dsp (); current_command[0] = 0x88; current_command[1] = 0; current_command[2] = 2; current_command[3] = 0; current_command[4] = HomologationGetTxLevel(0,0); current_command[5] = HomologationGetTxLevel(0,1); } else { current_command[4] = HomologationGetTxLevel(n,1); current_command[5] = HomologationGetTxLevel(n,0); } ack_or_response = 0; send_pkt_to_dsp ();}voidinit_call_progress(int n){ if (n < 3) { if ((n == 0) && call_progress_state) ResetDspIdle(); current_command[0] = 0x65; current_command[1] = 0; current_command[2] = 1; current_command[3] = 0; current_command[4] = n; current_command[5] = 1; ack_or_response = 0; send_pkt_to_dsp (); } call_progress_state = n;}voidgen_tone(int tone){ ModemSetTxLevel(0); current_command[0] = 0x7c; current_command[1] = 0; current_command[2] = 6; current_command[3] = 0; current_command[4] = (tone >> 8) & 0xff; current_command[5] = tone & 0xff; current_command[6] = (tone >> 24) & 0xff; current_command[7] = (tone >> 16) & 0xff; current_command[8] = 1; current_command[9] = 0; ack_or_response = 0; send_pkt_to_dsp (); delay(1000); current_command[0] = 0x7c; current_command[1] = 0; current_command[2] = 6; current_command[3] = 0; current_command[4] = 0; current_command[5] = 0; current_command[6] = 0; current_command[7] = 0; current_command[8] = 0; current_command[9] = 0; ack_or_response = 0; send_pkt_to_dsp(); ResetDspIdle(); init_call_progress(0); }/* ************************************************** */voidpacketize_parameter(unsigned char x, int cidx, int shift){ current_command[cidx] |= x << shift;}voidmt_connect(int orig, int mt_bitrate, int conn_mode, int conn_clock_code, int conn_leased, int conn_automode, int conn_fax, int conn_calltone, int conn_etc){ char reconnect = 0; char v23X = 0; char retrain = 0; /* Retrains are not supported yet */ if (orig) { if (JM_received) reconnect = 1; } else { if (CM_received) reconnect = 2; } JM_received = CM_received = 0; /* BUG FIX */ current_command[0] = 0x68; current_command[1] = 0; current_command[2] = 4; current_command[3] = 0; packetize_parameter(mt_bitrate, 4, 0); packetize_parameter(conn_clock_code, 4, 6); packetize_parameter(conn_mode, 5, 0); packetize_parameter(0x0, 5, 6); packetize_parameter(conn_calltone, 6, 0); packetize_parameter(orig, 6, 2); packetize_parameter(conn_automode, 6, 3); packetize_parameter(conn_fax, 6, 5); packetize_parameter(0x0, 6, 7); packetize_parameter(reconnect, 7, 0); packetize_parameter(v23X, 7, 2); packetize_parameter(retrain, 7, 3); packetize_parameter(0x0, 7, 4); packetize_parameter(0x0, 7, 5); ack_or_response = 0; send_pkt_to_dsp ();}voidmt_set_rate_seq(short rseq1, short rseq2, short rseq3){ mt_RateSeq1 = rseq1; mt_RateSeq2 = rseq2; mt_RateSeq3 = rseq3; if (rseq3) { mt_rate_seq_map = rseq3; mt_set_rate_seq_param3 = 1; } else { mt_rate_seq_map = rseq1; mt_set_rate_seq_param3 = 0; } if (rseq2 == 0) rseq2 = rseq1; current_command[0] = 0x64; current_command[1] = 0; current_command[2] = 6; current_command[3] = 0; current_command[4] = rseq1 & 0xff; current_command[5] = (rseq1 >> 8) & 0xff; current_command[6] = rseq2 & 0xff; current_command[7] = (rseq2 >> 8) & 0xff; current_command[8] = rseq3 & 0xff; current_command[9] = (rseq3 >> 8) & 0xff; ack_or_response = 0; send_pkt_to_dsp ();}unsigned charget_receiver_mode(void){ if ((read_dsp_modem_status_reg() & 0xf) != 3) { current_command[0] = 0x72; current_command[1] = 0; current_command[2] = 0; current_command[3] = 0; ack_or_response = 1; send_pkt_to_dsp (); line_mode = dsp_response_data[0]; ack_or_response = 0; } return line_mode;}voidmt_get_receiver_speed(char *tx, char *rx){ char r1, r2; if ((line_mode == 0x11) || (line_mode == 0x12) || (line_mode == 0x16) || (line_mode == 0x17)) { current_command[0] = 0x91; current_command[1] = 0; current_command[2] = 0; current_command[3] = 0; ack_or_response = 1; send_pkt_to_dsp (); if ((line_mode == 0x16) || (line_mode == 0x17)) { r1 = dsp_response_data[6]; r2 = dsp_response_data[7]; if (r1 >= 9) r1+= 7; else r1+= 3; r2 += 0x1f; } else { r1 = (dsp_response_data[0] >> 2) & 0xf; r2 = (((dsp_response_data[1]<<8) |dsp_response_data[0])>>6)& 0xf; if (r2 >= 9) r2+= 7; else r2+= 3; if (r1 >= 9) r1+= 7; else r1+= 3; /* if (line_mode == 0x11) r2 = r1; */ } } else { current_command[0] = 0x70; current_command[1] = 0; current_command[2] = 0; current_command[3] = 0; ack_or_response = 1; send_pkt_to_dsp(); r1 = r2 = dsp_response_data[0]; } ack_or_response = 0; if ((mt_conn_orig==0) && ((line_mode == 0x11) || (line_mode == 0x12))) { *tx = r2; *rx = r1; } else { *tx = r1; *rx = r2; } line_bit_rate = *rx;}voidline_port_init(int n){ char x; if (n == 0) { x = 0; current_command[0] = 0x61; current_command[1] = 0; current_command[2] = 1; current_command[3] = 0; current_command[4] = x; ack_or_response = 0; send_pkt_to_dsp(); } else Msg("Not implemented yet.\n");}voidline_init(void){ line_disable_interrupts(); if (critical) Dbg("ERROR: Critical...\n"); line_io_enabled = 0; dce_length_semaphore = 0; dce_status_semaphore = 0; dce_tx_interrupt_expected = 0; dce_rx_count = dce_tx_count = 0; dce_tx_remove = 0; dce_rx_insert = 0; stat_tx_count = stat_rx_count = 0; dte_rx_remove = 0; dte_tx_insert = 0; dce_rx_errors = 0; line_enable_interrupts();}/* ************************************************** */voidline_io_enable(int n){ if (n==1) { line_io_enabled = 1; } else line_io_enabled = 0;}int tx_room(void){ return BUF_SIZE - dce_tx_count;}int tx_count(void){ return dce_tx_count;}int rx_count(void){ return dce_rx_count;}int get_rx_count(void){ return stat_rx_count;}int get_tx_count(void){ return stat_tx_count;}intread_char(void){ int c; line_disable_interrupts(); if (critical) Dbg("ERROR: Critical...\n"); /* if (dte_rx_remove != dce_rx_insert) { */ if (dce_rx_count) { if (dte_rx_remove == dce_rx_insert) Dbg("FATAL ERROR: read_char()\n"); c = dce_rx_buffer[dte_rx_remove++]; if (dte_rx_remove == BUF_SIZE) dte_rx_remove = 0; dce_rx_count--; } else c = -1; line_enable_interrupts(); return c;}intwrite_char(unsigned char c){ int tx_intr = 0; int r; line_disable_interrupts(); if (critical) Dbg("ERROR: Critical...\n"); if (dce_tx_count >= BUF_SIZE) r = -1; else { if ((dce_tx_count == 0) && (dce_tx_interrupt_expected == 0)) tx_intr = 1; dce_tx_buffer[dte_tx_insert++] = c; dce_tx_count++; if (dte_tx_insert == BUF_SIZE) dte_tx_insert = 0; r = c; if (tx_intr) { dspdrv_ping_cram_intr(); dce_tx_interrupt_expected = 1; } } line_enable_interrupts(); return r;}voidprint_io_stats(int detail_level){ Msg("STATISTICS:\n"); Msg("RX chars : %d\n", get_rx_count()); Msg("TX chars : %d\n", get_tx_count()); Msg("RX errors : %d ?\n", dce_rx_errors);#ifdef DEBUG Dbg("TX COUNT = %d\n", dce_tx_count); Dbg("RX COUNT = %d\n", dce_rx_count); if (detail_level >= 1) { int i; Dbg("IO STATS:\n"); Dbg(" RX TX\n"); for(i=0; i<32; i++) Dbg(" (%2d) --> %5d %5d\n", i+1, RX_stat[i], TX_stat[i]); }#endif}#define WAIT_FOR_V8_TIME 5 intv8_orig(unsigned char bitrate){ char cp, last_cp, xs, xl; int i, t; sending_CM = sending_JM = 0; JM_received = CM_received = 0; CM_count = JM_count = 0; v8_tx_msg_size = 6; last_cp = call_progress(); Dbg("V8 Orig\n"); for (t=0; t<WAIT_FOR_V8_TIME*100; t++) { if ((read_dsp_modem_status_reg() & 0xf) == 2) return 1; /* connected */ cp = call_progress(); if (cp != last_cp) { last_cp = cp; if (cp == 0x22) { Dbg("ANSam tone detected.\n"); /* ? XX */ } else if ((cp == 0x1f) || (cp == 0x20)) { /* Dbg("Te expired?\n"); */ v8_configured = 1; Dbg("Sending CM...\n"); sending_CM = 1; v8_tx_buffer[0] = 0xff; /* ONEs */ v8_tx_buffer[1] = 0xe0; /* CM sync */ v8_tx_buffer[2] = 0xc1; /* call function */ /* modulation modes */ v8_tx_buffer[3] = 0x45; /* V.34 duplex */ v8_tx_buffer[4] = 0x13; /* V.32, V.22 */ v8_tx_buffer[5] = 0x94; /* V.21, V.23 */ dspdrv_WriteCram(0x54, v8_tx_buffer, v8_tx_msg_size); xs = 0; dspdrv_WriteCram(0x75, &xs, 1); dspdrv_WriteCram(0x74, &v8_tx_msg_size, 1); jm_seq_match = 0; v8_status = 0; line_io_enabled = 1; while (!jm_seq_match) { if (CM_count > 20) { Dbg("V8 CM count limit exceeded\n"); sending_CM = 0; v8_configured = 0; line_io_enabled = 0; return -1; } delay (10); /* 10ms */ } Dbg("CM count: %d\n", CM_count); JM_received = 1; sending_CM = 0; Dbg("JM received: ( "); for (i=0; i<v8_rx_msg_size; i++) Dbg("%x ", dce_rx_buffer[i]); Dbg(")\n"); v8_tx_buffer[0] = 0; v8_tx_buffer[1] = 0; v8_tx_buffer[2] = 0; Dbg("Sending CJ...\n"); xl = 3; dspdrv_WriteCram(0x54, v8_tx_buffer, 3); xs = 0; dspdrv_WriteCram(0x75, &xs, 1); dspdrv_WriteCram(0x74, &xl, 1); /* process_JM_CM() */ Dbg("Reconnecting...\n"); mt_connect(M_CONN_ORIG, bitrate, MD_V34, 0, 0, 3, 0, 00, 0); v8_configured = 0; /* line_io_enabled = 0; */ return 1; } else Msg("New Call Progress : %x\n", cp); } delay(10); /* 10 ms */ } return -1;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -