/**************************************************** * RFControlBoard_iocShell.c * * Define ioc shell commands * * Created by: Zheqiao Geng, gengzq@slac.stanford.edu * Created on: 2011.04.14 * Description: Initial creation * * Modified by: Zheqiao Geng * Modified on: 2011.05.12 * Description: Add the buffer reading/writing functions ****************************************************/ #include #include #include #include "RFControlBoard_availableInterface.h" #ifdef __cplusplus extern "C" { #endif /*====================================== * Private Routines *======================================*/ /** * Read the register */ static void RFCB_func_ioc_readRegister(const char *moduleName, int dev, int addr) { unsigned int var_data = 0; RFCB_struc_moduleData *ptr_dataInstance = NULL; /* Find the module from the list */ ptr_dataInstance = RFCB_API_getModule(moduleName); if(ptr_dataInstance == NULL) { printf("RFCB_readRegister: Failed to find the module of %s\n", moduleName); return; } /* Read the data */ RFCB_API_readRegister(ptr_dataInstance, (unsigned int)addr, &var_data, (RFCB_enum_devSpace)dev); printf("RFCB_readRegister: data is 0x%4X\n", var_data); } /** * Write the register */ static void RFCB_func_ioc_writeRegister(const char *moduleName, int dev, int addr, int data) { RFCB_struc_moduleData *ptr_dataInstance = NULL; /* Find the module from the list */ ptr_dataInstance = RFCB_API_getModule(moduleName); if(ptr_dataInstance == NULL) { printf("RFCB_writeRegister: Failed to find the module of %s\n", moduleName); return; } /* Write the data */ RFCB_API_writeRegister(ptr_dataInstance, (unsigned int)addr, (unsigned int)data, (RFCB_enum_devSpace)dev); printf("RFCB_writeRegister: address is 0x%4X, data is 0x%4X\n", addr, data); } /** * Read the buffer */ static void RFCB_func_ioc_readBuffer(const char *moduleName, int dev, int addr, int pno, const char *fileName) { int i; int var_cnt; RFCB_struc_moduleData *ptr_dataInstance = NULL; unsigned int *ptr_buf; FILE *outFile = NULL; /* Check the input */ if(pno <= 0) { printf("RFCB_readBuffer: The point number must be larger than 0\n"); return; } /* Find the module from the list */ ptr_dataInstance = RFCB_API_getModule(moduleName); if(ptr_dataInstance == NULL) { printf("RFCB_readBuffer: Failed to find the module of %s\n", moduleName); return; } /* Create buffer */ ptr_buf = (unsigned int *)calloc(1, sizeof(unsigned int) * pno); if(ptr_buf == NULL) { printf("RFCB_readBuffer: Failed to create buffer for the data\n"); return; } /* Read the data from the hardware */ RFCB_API_readBuffer(ptr_dataInstance, (unsigned int)addr, (unsigned int)pno, ptr_buf, (RFCB_enum_devSpace)dev); /* Save data into file */ if(fileName && fileName[0]) { outFile = fopen(fileName, "w"); if(!outFile) { printf("RFCB_readBuffer: Failed to open the file of %s\n", fileName); } else { printf("RFCB_readBuffer: Save data to the file of %s\n", fileName); fwrite(ptr_buf, sizeof(unsigned int), pno, outFile); fflush(outFile); fclose(outFile); } } /* Print the data */ var_cnt = 0; printf("RFCB_readBuffer: Data from the buffer address of 0x%4X:\n", addr); for(i = 0; i < pno; i ++) { printf("0x%4X ", *(ptr_buf + i)); var_cnt ++; if(var_cnt >= 8) { var_cnt = 0; printf("\n"); } } /* free the buffer */ free(ptr_buf); } /** * Write the buffer */ static void RFCB_func_ioc_writeBuffer(const char *moduleName, int dev, int addr, int pno, const char *fileName) { int i; int var_cnt; RFCB_struc_moduleData *ptr_dataInstance = NULL; unsigned int *ptr_buf; /* Check the input */ if(pno <= 0) { printf("RFCB_writeBuffer: The point number must be larger than 0\n"); return; } /* Find the module from the list */ ptr_dataInstance = RFCB_API_getModule(moduleName); if(ptr_dataInstance == NULL) { printf("RFCB_writeBuffer: Failed to find the module of %s\n", moduleName); return; } /* Create buffer */ ptr_buf = (unsigned int *)calloc(1, sizeof(unsigned int) * pno); if(ptr_buf == NULL) { printf("RFCB_writeBuffer: Failed to create buffer for the data\n"); return; } /* Get data from the file */ if(fileName && fileName[0]) { /* not supported now */ printf("RFCB_writeBuffer: Read data from the file of %s\n", fileName); } else { printf("RFCB_writeBuffer: No file assigned. Will use the default value\n"); /*for(i = 0; i < 250; i ++) *(ptr_buf + i) = 0x7FFF0000; for(i = 250; i < 350; i ++) *(ptr_buf + i) = 0x80010000; for(i = 350; i < 512; i ++) *(ptr_buf + i) = 0x00000000; */ } /* Write the data to the hardware */ RFCB_API_writeBuffer(ptr_dataInstance, (unsigned int)addr, (unsigned int)pno, ptr_buf, (RFCB_enum_devSpace)dev); /* Print the data */ var_cnt = 0; printf("RFCB_writeBuffer: Data to the buffer address of 0x%4X:\n", addr); for(i = 0; i < pno; i ++) { printf("0x%4X ", *(ptr_buf + i)); var_cnt ++; if(var_cnt >= 8) { var_cnt = 0; printf("\n"); } } /* free the buffer */ free(ptr_buf); } /*====================================== * IOC shell Routines *======================================*/ /* RFCB_API_createModule(const char *moduleName) */ static const iocshArg RFCB_createModule_Arg0 = {"moduleName", iocshArgString}; static const iocshArg RFCB_createModule_Arg1 = {"driverName", iocshArgString}; static const iocshArg *const RFCB_createModule_Args[2] = {&RFCB_createModule_Arg0, &RFCB_createModule_Arg1}; static const iocshFuncDef RFCB_createModule_FuncDef = {"RFCB_createModule", 2, RFCB_createModule_Args}; static void RFCB_createModule_CallFunc(const iocshArgBuf *args) {RFCB_API_createModule(args[0].sval, args[1].sval);} /* RFCB_API_deleteModule(const char *moduleName) */ static const iocshArg RFCB_deleteModule_Arg0 = {"moduleName", iocshArgString}; static const iocshArg *const RFCB_deleteModule_Args[1] = {&RFCB_deleteModule_Arg0}; static const iocshFuncDef RFCB_deleteModule_FuncDef = {"RFCB_deleteModule", 1, RFCB_deleteModule_Args}; static void RFCB_deleteModule_CallFunc(const iocshArgBuf *args) {RFCB_API_deleteModule(args[0].sval);} /* RFCB_API_setupModule(const char *moduleName, const char *cmd, const char *dataStr) */ static const iocshArg RFCB_setupModule_Arg0 = {"moduleName", iocshArgString}; static const iocshArg RFCB_setupModule_Arg1 = {"cmd", iocshArgString}; static const iocshArg RFCB_setupModule_Arg2 = {"dataStr", iocshArgString}; static const iocshArg *const RFCB_setupModule_Args[3] = {&RFCB_setupModule_Arg0, &RFCB_setupModule_Arg1, &RFCB_setupModule_Arg2}; static const iocshFuncDef RFCB_setupModule_FuncDef = {"RFCB_setupModule", 3, RFCB_setupModule_Args}; static void RFCB_setupModule_CallFunc(const iocshArgBuf *args) {RFCB_API_setupModule(args[0].sval, args[1].sval, args[2].sval);} /* Read register data */ static const iocshArg RFCB_readRegister_Arg0 = {"moduleName", iocshArgString}; static const iocshArg RFCB_readRegister_Arg1 = {"dev", iocshArgInt}; static const iocshArg RFCB_readRegister_Arg2 = {"addr", iocshArgInt}; static const iocshArg *const RFCB_readRegister_Args[3] = {&RFCB_readRegister_Arg0, &RFCB_readRegister_Arg1, &RFCB_readRegister_Arg2}; static const iocshFuncDef RFCB_readRegister_FuncDef = {"RFCB_readRegister", 3, RFCB_readRegister_Args}; static void RFCB_readRegister_CallFunc(const iocshArgBuf *args) {RFCB_func_ioc_readRegister(args[0].sval, args[1].ival, args[2].ival);} /* Write register data */ static const iocshArg RFCB_writeRegister_Arg0 = {"moduleName", iocshArgString}; static const iocshArg RFCB_writeRegister_Arg1 = {"dev", iocshArgInt}; static const iocshArg RFCB_writeRegister_Arg2 = {"addr", iocshArgInt}; static const iocshArg RFCB_writeRegister_Arg3 = {"data", iocshArgInt}; static const iocshArg *const RFCB_writeRegister_Args[4] = {&RFCB_writeRegister_Arg0, &RFCB_writeRegister_Arg1, &RFCB_writeRegister_Arg2, &RFCB_writeRegister_Arg3}; static const iocshFuncDef RFCB_writeRegister_FuncDef = {"RFCB_writeRegister", 4, RFCB_writeRegister_Args}; static void RFCB_writeRegister_CallFunc(const iocshArgBuf *args) {RFCB_func_ioc_writeRegister(args[0].sval, args[1].ival, args[2].ival, args[3].ival);} /* Read buffer data */ static const iocshArg RFCB_readBuffer_Arg0 = {"moduleName", iocshArgString}; static const iocshArg RFCB_readBuffer_Arg1 = {"dev", iocshArgInt}; static const iocshArg RFCB_readBuffer_Arg2 = {"addr", iocshArgInt}; static const iocshArg RFCB_readBuffer_Arg3 = {"pno", iocshArgInt}; static const iocshArg RFCB_readBuffer_Arg4 = {"fileName", iocshArgString}; static const iocshArg *const RFCB_readBuffer_Args[5] = {&RFCB_readBuffer_Arg0, &RFCB_readBuffer_Arg1, &RFCB_readBuffer_Arg2, &RFCB_readBuffer_Arg3, &RFCB_readBuffer_Arg4}; static const iocshFuncDef RFCB_readBuffer_FuncDef = {"RFCB_readBuffer", 5, RFCB_readBuffer_Args}; static void RFCB_readBuffer_CallFunc(const iocshArgBuf *args) {RFCB_func_ioc_readBuffer(args[0].sval, args[1].ival, args[2].ival, args[3].ival, args[4].sval);} /* Write buffer data */ static const iocshArg RFCB_writeBuffer_Arg0 = {"moduleName", iocshArgString}; static const iocshArg RFCB_writeBuffer_Arg1 = {"dev", iocshArgInt}; static const iocshArg RFCB_writeBuffer_Arg2 = {"addr", iocshArgInt}; static const iocshArg RFCB_writeBuffer_Arg3 = {"pno", iocshArgInt}; static const iocshArg RFCB_writeBuffer_Arg4 = {"fileName", iocshArgString}; static const iocshArg *const RFCB_writeBuffer_Args[5] = {&RFCB_writeBuffer_Arg0, &RFCB_writeBuffer_Arg1, &RFCB_writeBuffer_Arg2, &RFCB_writeBuffer_Arg3, &RFCB_writeBuffer_Arg4}; static const iocshFuncDef RFCB_writeBuffer_FuncDef = {"RFCB_writeBuffer", 5, RFCB_writeBuffer_Args}; static void RFCB_writeBuffer_CallFunc(const iocshArgBuf *args) {RFCB_func_ioc_writeBuffer(args[0].sval, args[1].ival, args[2].ival, args[3].ival, args[4].sval);} void RFCB_IOCShellRegister(void) { iocshRegister(&RFCB_createModule_FuncDef, RFCB_createModule_CallFunc); iocshRegister(&RFCB_deleteModule_FuncDef, RFCB_deleteModule_CallFunc); iocshRegister(&RFCB_setupModule_FuncDef, RFCB_setupModule_CallFunc); iocshRegister(&RFCB_readRegister_FuncDef, RFCB_readRegister_CallFunc); iocshRegister(&RFCB_writeRegister_FuncDef, RFCB_writeRegister_CallFunc); iocshRegister(&RFCB_readBuffer_FuncDef, RFCB_readBuffer_CallFunc); iocshRegister(&RFCB_writeBuffer_FuncDef, RFCB_writeBuffer_CallFunc); } epicsExportRegistrar(RFCB_IOCShellRegister); #ifdef __cplusplus } #endif