📄 mbxtcl.c
字号:
Syntax to stop transmit:\n\
tx off ?min?\n\
Syntax to start transmit a PRBS:\n\
tx on <freq> ?min?\n\
The parameter freq defines the frequency to use to transmit.\n\
Parameter freq is given in MHz.\n\
Parameter min is given to NOT set all register but a minimum.\n\
WARNING: Don't let the transmitter be active too long.\n\
The PA temperature will get too high and eventually the PA will burn.\n\
How long time is too long is depending on the output power adjusted with DAC 0.\n\
In the worst case it is just a few seconds.";
static int MbxTclTx(ClientData clientData, Tcl_Interp *interp, int argc, char *argv[]) {
double dFreq;
int freq;
s32 minRxFreq, maxRxFreq, minTxFreq, maxTxFreq;
char str[100];
if (argc == 1) {
/* Return current frequency. */
sprintf(str, "%f", (double)CMX_GetTxFreq()/1000000.0);
Tcl_SetResult(interp, str, TCL_VOLATILE);
return TCL_OK;
}
if (argc < 2) {
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
" on|off ?freq? ?min?\"", (char *)NULL);
return TCL_ERROR;
}
if (strcmp(argv[1], "off") == 0) {
if (argc == 2) {
CMX_TxActive(FALSE, FALSE);
return TCL_OK;
}
if (argc != 3) {
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
" off ?min?\"", (char *)NULL);
return TCL_ERROR;
}
if (strcmp(argv[2], "min") != 0) {
Tcl_AppendResult(interp, "wrong option: should be min", (char *)NULL);
return TCL_ERROR;
}
CMX_TxActive(FALSE, TRUE);
return TCL_OK;
}
if (strcmp(argv[1], "on") == 0) {
bool min;
if (argc == 4) {
if (strcmp(argv[3], "min") != 0) {
Tcl_AppendResult(interp, "wrong option: should be min", (char *)NULL);
return TCL_ERROR;
}
min = TRUE;
} else if (argc != 3) {
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
" on freq ?min?\"", (char *)NULL);
return TCL_ERROR;
} else {
min = FALSE;
}
/* Get freq from second argument */
if (Tcl_GetDouble(interp, argv[2], &dFreq) != TCL_OK) {
return TCL_ERROR;
}
freq = (int)(dFreq*1000000.0+0.5);
CMX_GetFreqBand(&minRxFreq, &maxRxFreq, &minTxFreq, &maxTxFreq);
/* Check frequency range. */
if (freq < minTxFreq || freq > maxTxFreq) {
sprintf(str, "freq must be between %d-%d MHz for TX",
(int)(minTxFreq/1000000), (int)(maxTxFreq/1000000));
Tcl_SetResult(interp, str, TCL_VOLATILE);
return TCL_ERROR;
}
CMX_SetTxFreq(freq);
CMX_TxActive(TRUE, min);
Tcl_SetResult(interp, "Tx PRBS started", TCL_STATIC);
return TCL_OK;
}
Tcl_AppendResult(interp, "wrong option: should be on|off", (char *)NULL);
return TCL_ERROR;
}
/****f* MBXTCL/MbxTclBand
* DESCRIPTION
* Returns the current frequency band as a list.
* The values are: minRxFreq maxRxFreq minTxFreq maxTxFreq.
***/
static const char MbxTclBandHelp[] =
"Returns the current frequency band as a list.\n\
The values are: minRxFreq maxRxFreq minTxFreq maxTxFreq\n\
and the unit is Hz.";
static int MbxTclBand(ClientData clientData, Tcl_Interp *interp, int argc, char *argv[]) {
char str[60];
s32 minRxFreq, maxRxFreq, minTxFreq, maxTxFreq;
if (argc != 1) {
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
"\"", (char *)NULL);
return TCL_ERROR;
}
CMX_GetFreqBand(&minRxFreq, &maxRxFreq, &minTxFreq, &maxTxFreq);
snprintf(str, 60, "%ld %ld %ld %ld", minRxFreq, maxRxFreq, minTxFreq, maxTxFreq);
Tcl_SetResult(interp, str, TCL_VOLATILE);
return TCL_OK;
}
/****f* MBXTCL/MbxTclFreqPar
* DESCRIPTION
* Returns the current frequency parameters as a list.
***/
static const char MbxTclFreqParHelp[] =
"Returns the current frequency parameters as a list.\n\
The values are: refClock rxIf txIf txIfSide\n\
and the unit is Hz.";
static int MbxTclFreqPar(ClientData clientData, Tcl_Interp *interp, int argc, char *argv[]) {
char str[60];
s32 refClock, rxIf, txIf;
bool txIfSide;
if (argc != 1) {
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
"\"", (char *)NULL);
return TCL_ERROR;
}
CMX_GetFreqParameters(&rxIf, &txIf, &txIfSide);
refClock = CMX_RefClock();
snprintf(str, 60, "%ld %ld %ld %s", refClock, rxIf, txIf, (txIfSide ? "high" : "low"));
Tcl_SetResult(interp, str, TCL_VOLATILE);
return TCL_OK;
}
/****f* MBXTCL/CheckPeekOption
* DESCRIPTION
* This function checks the options given to a peek command.
***/
static int CheckPeekOption(Tcl_Interp *interp, int argc, char *argv[], int *option, int *addrIndex) {
if (argc < 2) {
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
" ?option? address\"", (char *)NULL);
return TCL_ERROR;
}
/* Check if first argument is a flag option */
if (argv[1][0] == '-') {
if (argc != 3) {
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
" ?option? address\"", (char *)NULL);
return TCL_ERROR;
}
*addrIndex = 2;
switch (argv[1][1]) {
case 'd':
*option = 0;
break;
case 'h':
*option = 1;
break;
case 'b':
*option = 2;
break;
default:
Tcl_AppendResult(interp, "wrong option: should be -d -h or -b",
(char *)NULL);
return TCL_ERROR;
}
} else {
if (argc != 2) {
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
" ?option? address\"", (char *)NULL);
return TCL_ERROR;
}
}
return TCL_OK;
}
/****f* MBXTCL/MbxTclPeek8
* DESCRIPTION
* Read a byte from an address.
***/
static const char MbxTclPeek8Help[] = "Read a byte from an address.\n\
Syntax:\n\
peek8 ?option? address\n\
where option can be:\n\
-d show data as a decimal number (default)\n\
-h show data as a hexadecimal number\n\
-b show data as a binary number.";
static int MbxTclPeek8(ClientData clientData, Tcl_Interp *interp, int argc, char *argv[]) {
unsigned int address;
u8 val;
char str[40];
int option = 0;
int addrIndex = 1;
if (CheckPeekOption(interp, argc, argv, &option, &addrIndex) != TCL_OK) {
return TCL_ERROR;
}
if (Tcl_GetUInt(interp, argv[addrIndex], &address) != TCL_OK) {
return TCL_ERROR;
}
val = INPUT(address);
switch (option) {
case 1:
sprintf(str, "0x%x", val);
break;
case 2:
Conv2BinString(str, 8, val);
break;
default:
sprintf(str, "%d", val);
break;
}
Tcl_SetResult(interp, str, TCL_VOLATILE);
return TCL_OK;
}
/****f* MBXTCL/MbxTclPeek32
* DESCRIPTION
* Read a 32-bit word from an address.
***/
static const char MbxTclPeek32Help[] = "Read a 32-bit word from an address.\n\
Syntax:\n\
peek ?option? address\n\
where option can be:\n\
-d show data as a decimal number (default)\n\
-h show data as a hexadecimal number\n\
-b show data as a binary number.";
static int MbxTclPeek32(ClientData clientData, Tcl_Interp *interp, int argc, char *argv[]) {
unsigned int address;
unsigned int val;
char str[40];
int option = 0;
int addrIndex = 1;
if (CheckPeekOption(interp, argc, argv, &option, &addrIndex) != TCL_OK) {
return TCL_ERROR;
}
if (Tcl_GetUInt(interp, argv[addrIndex], &address) != TCL_OK) {
return TCL_ERROR;
}
val = INPUT32(address);
switch (option) {
case 1:
sprintf(str, "0x%x", val);
break;
case 2:
Conv2BinString(str, 32, val);
break;
default:
sprintf(str, "%d", val);
break;
}
Tcl_SetResult(interp, str, TCL_VOLATILE);
return TCL_OK;
}
/****f* MBXTCL/MbxTclPoke8
* DESCRIPTION
* Write a byte to an address.
***/
static const char MbxTclPoke8Help[] = "Write a byte to an address.\n\
Byte value shall be 0-255.\n\
Syntax:\n\
poke8 <address> <value>";
static int MbxTclPoke8(ClientData clientData, Tcl_Interp *interp, int argc, char *argv[]) {
unsigned int address;
int val;
char str[20];
if (argc != 3) {
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
" address value\"", (char *)NULL);
return TCL_ERROR;
}
if (Tcl_GetUInt(interp, argv[1], &address) != TCL_OK) {
return TCL_ERROR;
}
if (Tcl_GetInt(interp, argv[2], &val) != TCL_OK) {
return TCL_ERROR;
}
if (val < 0 || val > 255) {
Tcl_SetResult(interp, "value shall be 0-255", TCL_STATIC);
return TCL_ERROR;
}
OUTPUT(address, val);
sprintf(str, "%d", val);
Tcl_SetResult(interp, str, TCL_VOLATILE);
return TCL_OK;
}
/****f* MBXTCL/MbxTclPoke32
* DESCRIPTION
* Write a 32-bit word to an address.
***/
static const char MbxTclPoke32Help[] = "Write a 32-bit word to an address.\n\
Syntax:\n\
poke <address> <value>";
static int MbxTclPoke32(ClientData clientData, Tcl_Interp *interp, int argc, char *argv[]) {
unsigned int address;
unsigned int val;
char str[20];
if (argc != 3) {
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
" address value\"", (char *)NULL);
return TCL_ERROR;
}
if (Tcl_GetUInt(interp, argv[1], &address) != TCL_OK) {
return TCL_ERROR;
}
if (Tcl_GetUInt(interp, argv[2], &val) != TCL_OK) {
return TCL_ERROR;
}
OUTPUT32(address, val);
sprintf(str, "%d", val);
Tcl_SetResult(interp, str, TCL_VOLATILE);
return TCL_OK;
}
/****f* MBXTCL/MbxTclWd
* DESCRIPTION
* Control the watchdog.
***/
static const char MbxTclWdHelp[] = "Control the watchdog.\n\
Syntax:\n\
wd on|off|reset\n\
\"wd reset\" will cause the system to be reseted.";
static int MbxTclWd(ClientData clientData, Tcl_Interp *interp, int argc, char *argv[]) {
int state;
char str[20];
if (argc != 2) {
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
" on|off|reset\"", (char *)NULL);
return TCL_ERROR;
}
if (strcmp(argv[1], "reset") == 0) {
WD_ForceSystemReset();
}
if (Tcl_GetBoolean(interp, argv[1], &state) != TCL_OK) {
return TCL_ERROR;
}
if (state) {
WD_Enable();
} else {
WD_Disable();
}
sprintf(str, "%d", state);
Tcl_SetResult(interp, str, TCL_VOLATILE);
return TCL_OK;
}
/****f* MBXTCL/MbxTclFlashLoad
* DESCRIPTION
* Boots the system in flash bootloader mode.
***/
static const char MbxTclFlashLoadHelp[] =
"Boots the system in flash bootloader mode.";
static int MbxTclFlashLoad(ClientData clientData, Tcl_Interp *interp, int argc, char *argv[]) {
cyg_uint32 *bootWord = (cyg_uint32*)32;
if (argc != 1) {
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
"\"", (char *)NULL);
return TCL_ERROR;
}
*bootWord = 0x5AA50F78;
WD_ForceSystemReset();
return TCL_OK;
}
/****f* MBXTCL/MbxTclFlashRead
* DESCRIPTION
* Reads data from the flash.
***/
static const char MbxTclFlashReadHelp[] =
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -