/* * This function is a special case in that it's argument hasn't been dynamically * allocated */ int _search(uint8_t * args) { int i; int found = 0; int arg_len = strlen((char*)args); if (args == NULL) { return 1; } /* * if an argument was given, search */ else { for (i = 1; i < driver_table_len; i++) { /* * show all matches */ if (prompt_on) { if (memcmp(args, (char *) driver_table[i].fcn_name, arg_len) == 0) { sprintf((char *) str, "%03x %s\r\n", i, driver_table[i].fcn_name); writeUSBOutString(str); found++; } } /* * only show an exact match */ else { if (strcmp((char *) args, (char *) driver_table[i].fcn_name) == 0) { sprintf((char *) str, "%03x\r\n", i); writeUSBOutString(str); found++; } } } if (!found) return 1; } return 0; }
int _readMag(uint8_t * args) { uint8_t receive_buffer[6]; I2C_M_SETUP_Type setup; unsigned int x_value; unsigned int y_value; unsigned int z_value; Status result; uint8_t transmit_buffer; setup.sl_addr7bit = MAG_I2C_SLAVE_ADDRESS; setup.retransmissions_max = MAX_ST_I2C_RETRANSMISSIONS; setup.tx_data = &transmit_buffer; setup.tx_length = 1; setup.rx_data = receive_buffer; setup.rx_length = 6; transmit_buffer = MAG_DATA_ADDRESS|ST_I2C_AUTOINCREMENT_ADDRESS; result = I2C_MasterTransferData(LPC_I2C0, &setup, I2C_TRANSFER_POLLING); if(result == ERROR) return 1; x_value = MagDataToUInt32(&receive_buffer[0]); y_value = MagDataToUInt32(&receive_buffer[2]); z_value = MagDataToUInt32(&receive_buffer[4]); sprintf((char*)str, "%x %x %x\r\n", x_value, y_value, z_value); writeUSBOutString(str); return 0; }
int _I2C_GetLastStatusCode(uint8_t * args) { uint8_t * arg_ptr; LPC_I2C_TypeDef* I2Cx; if ((arg_ptr = (uint8_t *) strtok(NULL, " ")) == NULL) return 1; I2Cx = (LPC_I2C_TypeDef*) strtoul((char *) arg_ptr, NULL, 16); sprintf((char *) str, "%x\r\n", (unsigned int) I2C_GetLastStatusCode(I2Cx)); writeUSBOutString(str); return 0; }
int _EMAC_SetPHYMode(uint8_t * args) { uint8_t * arg_ptr; uint32_t ulPHYMode; if ((arg_ptr = (uint8_t *) strtok(NULL, " ")) == NULL) return 1; ulPHYMode = (uint32_t) strtoul((char *) arg_ptr, NULL, 16); sprintf((char *) str, "%x\r\n", (unsigned int) EMAC_SetPHYMode(ulPHYMode)); writeUSBOutString(str); return 0; }
int _RIT_GetIntStatus(uint8_t * args) { uint8_t * arg_ptr; LPC_RIT_TypeDef* RITx; if ((arg_ptr = (uint8_t *) strtok(NULL, " ")) == NULL) return 1; RITx = (LPC_RIT_TypeDef*) strtoul((char *) arg_ptr, NULL, 16); sprintf((char *) str, "%x\r\n", (unsigned int) RIT_GetIntStatus(RITx)); writeUSBOutString(str); return 0; }
int _malloc(uint8_t * args) { uint8_t * arg; size_t size; if ((arg = (uint8_t *) strtok(NULL, " ")) == NULL) return 1; size = (size_t) strtoul((char *) arg, NULL, 16); sprintf((char *) str, "%x\r\n", (unsigned int) malloc(size)); writeUSBOutString(str); return 0; }
int _EMAC_CheckReceiveDataStatus(uint8_t * args) { uint8_t * arg_ptr; uint32_t ulRxStatType; if ((arg_ptr = (uint8_t *) strtok(NULL, " ")) == NULL) return 1; ulRxStatType = (uint32_t) strtoul((char *) arg_ptr, NULL, 16); sprintf((char *) str, "%x\r\n", (unsigned int) EMAC_CheckReceiveDataStatus(ulRxStatType)); writeUSBOutString(str); return 0; }
int _EMAC_Init(uint8_t * args) { uint8_t * arg_ptr; EMAC_CFG_Type* EMAC_ConfigStruct; if ((arg_ptr = (uint8_t *) strtok(NULL, " ")) == NULL) return 1; EMAC_ConfigStruct = (EMAC_CFG_Type*) strtoul((char *) arg_ptr, NULL, 16); sprintf((char *) str, "%x\r\n", (unsigned int) EMAC_Init(EMAC_ConfigStruct)); writeUSBOutString(str); return 0; }
int _FIO_ReadValue(uint8_t * args) { uint8_t * arg_ptr; uint8_t portNum; if ((arg_ptr = (uint8_t *) strtok(NULL, " ")) == NULL) return 1; portNum = (uint8_t) strtoul((char *) arg_ptr, NULL, 16); sprintf((char *) str, "%x\r\n", (unsigned int) FIO_ReadValue(portNum)); writeUSBOutString(str); return 0; }
int _PWM_GetIntStatus(uint8_t * args) { uint8_t * arg_ptr; LPC_PWM_TypeDef* PWMx; uint32_t IntFlag; if ((arg_ptr = (uint8_t *) strtok(NULL, " ")) == NULL) return 1; PWMx = (LPC_PWM_TypeDef*) strtoul((char *) arg_ptr, NULL, 16); if ((arg_ptr = (uint8_t *) strtok(NULL, " ")) == NULL) return 1; IntFlag = (uint32_t) strtoul((char *) arg_ptr, NULL, 16); sprintf((char *) str, "%x\r\n", (unsigned int) PWM_GetIntStatus(PWMx, IntFlag)); writeUSBOutString(str); return 0; }
int _PWM_GetCaptureValue(uint8_t * args) { uint8_t * arg_ptr; LPC_PWM_TypeDef* PWMx; uint8_t CaptureChannel; if ((arg_ptr = (uint8_t *) strtok(NULL, " ")) == NULL) return 1; PWMx = (LPC_PWM_TypeDef*) strtoul((char *) arg_ptr, NULL, 16); if ((arg_ptr = (uint8_t *) strtok(NULL, " ")) == NULL) return 1; CaptureChannel = (uint8_t) strtoul((char *) arg_ptr, NULL, 16); sprintf((char *) str, "%x\r\n", (unsigned int) PWM_GetCaptureValue(PWMx, CaptureChannel)); writeUSBOutString(str); return 0; }
int _PWM_COUNTERCFG_Type_CountInputSelect(uint8_t * args) { uint8_t * arg_ptr; PWM_COUNTERCFG_Type* PWM_COUNTERCFG_Type_ptr; if ((arg_ptr = (uint8_t *) strtok(NULL, " ")) == NULL) return 1; PWM_COUNTERCFG_Type_ptr = (PWM_COUNTERCFG_Type *) strtoul((char *) arg_ptr, NULL, 16); if ((arg_ptr = (uint8_t *) strtok(NULL, " ")) == NULL) { sprintf((char *) str, "%x\r\n", (unsigned int) PWM_COUNTERCFG_Type_ptr->CountInputSelect); writeUSBOutString(str); return 0; } PWM_COUNTERCFG_Type_ptr->CountInputSelect = (uint8_t) strtoul((char *) arg_ptr, NULL, 16); return 0; }
int _PWM_CAPTURECFG_Type_IntOnCaption(uint8_t * args) { uint8_t * arg_ptr; PWM_CAPTURECFG_Type* PWM_CAPTURECFG_Type_ptr; if ((arg_ptr = (uint8_t *) strtok(NULL, " ")) == NULL) return 1; PWM_CAPTURECFG_Type_ptr = (PWM_CAPTURECFG_Type *) strtoul((char *) arg_ptr, NULL, 16); if ((arg_ptr = (uint8_t *) strtok(NULL, " ")) == NULL) { sprintf((char *) str, "%x\r\n", (unsigned int) PWM_CAPTURECFG_Type_ptr->IntOnCaption); writeUSBOutString(str); return 0; } PWM_CAPTURECFG_Type_ptr->IntOnCaption = (uint8_t) strtoul((char *) arg_ptr, NULL, 16); return 0; }
int _PWM_TIMERCFG_Type_PrescaleValue(uint8_t * args) { uint8_t * arg_ptr; PWM_TIMERCFG_Type* PWM_TIMERCFG_Type_ptr; if ((arg_ptr = (uint8_t *) strtok(NULL, " ")) == NULL) return 1; PWM_TIMERCFG_Type_ptr = (PWM_TIMERCFG_Type *) strtoul((char *) arg_ptr, NULL, 16); if ((arg_ptr = (uint8_t *) strtok(NULL, " ")) == NULL) { sprintf((char *) str, "%x\r\n", (unsigned int) PWM_TIMERCFG_Type_ptr->PrescaleValue); writeUSBOutString(str); return 0; } PWM_TIMERCFG_Type_ptr->PrescaleValue = (uint32_t) strtoul((char *) arg_ptr, NULL, 16); return 0; }
int _PWM_MATCHCFG_Type_ResetOnMatch(uint8_t * args) { uint8_t * arg_ptr; PWM_MATCHCFG_Type* PWM_MATCHCFG_Type_ptr; if ((arg_ptr = (uint8_t *) strtok(NULL, " ")) == NULL) return 1; PWM_MATCHCFG_Type_ptr = (PWM_MATCHCFG_Type *) strtoul((char *) arg_ptr, NULL, 16); if ((arg_ptr = (uint8_t *) strtok(NULL, " ")) == NULL) { sprintf((char *) str, "%x\r\n", (unsigned int) PWM_MATCHCFG_Type_ptr->ResetOnMatch); writeUSBOutString(str); return 0; } PWM_MATCHCFG_Type_ptr->ResetOnMatch = (uint8_t) strtoul((char *) arg_ptr, NULL, 16); return 0; }
int _GPIO_HalfWord_TypeDef_FIOSETU(uint8_t * args) { uint8_t * arg_ptr; GPIO_HalfWord_TypeDef* GPIO_HalfWord_TypeDef_ptr; if ((arg_ptr = (uint8_t *) strtok(NULL, " ")) == NULL) return 1; GPIO_HalfWord_TypeDef_ptr = (GPIO_HalfWord_TypeDef *) strtoul((char *) arg_ptr, NULL, 16); if ((arg_ptr = (uint8_t *) strtok(NULL, " ")) == NULL) { sprintf((char *) str, "%x\r\n", (unsigned int) GPIO_HalfWord_TypeDef_ptr->FIOSETU); writeUSBOutString(str); return 0; } GPIO_HalfWord_TypeDef_ptr->FIOSETU = (uint16_t) strtoul((char *) arg_ptr, NULL, 16); return 0; }
int _I2C_S_SETUP_Type_status(uint8_t * args) { uint8_t * arg_ptr; I2C_S_SETUP_Type* I2C_S_SETUP_Type_ptr; if ((arg_ptr = (uint8_t *) strtok(NULL, " ")) == NULL) return 1; I2C_S_SETUP_Type_ptr = (I2C_S_SETUP_Type *) strtoul((char *) arg_ptr, NULL, 16); if ((arg_ptr = (uint8_t *) strtok(NULL, " ")) == NULL) { sprintf((char *) str, "%x\r\n", (unsigned int) I2C_S_SETUP_Type_ptr->status); writeUSBOutString(str); return 0; } I2C_S_SETUP_Type_ptr->status = (uint32_t) strtoul((char *) arg_ptr, NULL, 16); return 0; }
int _I2C_M_SETUP_Type_retransmissions_count(uint8_t * args) { uint8_t * arg_ptr; I2C_M_SETUP_Type* I2C_M_SETUP_Type_ptr; if ((arg_ptr = (uint8_t *) strtok(NULL, " ")) == NULL) return 1; I2C_M_SETUP_Type_ptr = (I2C_M_SETUP_Type *) strtoul((char *) arg_ptr, NULL, 16); if ((arg_ptr = (uint8_t *) strtok(NULL, " ")) == NULL) { sprintf((char *) str, "%x\r\n", (unsigned int) I2C_M_SETUP_Type_ptr->retransmissions_count); writeUSBOutString(str); return 0; } I2C_M_SETUP_Type_ptr->retransmissions_count = (uint32_t) strtoul((char *) arg_ptr, NULL, 16); return 0; }
int _I2C_OWNSLAVEADDR_CFG_Type_SlaveAddrMaskValue(uint8_t * args) { uint8_t * arg_ptr; I2C_OWNSLAVEADDR_CFG_Type* I2C_OWNSLAVEADDR_CFG_Type_ptr; if ((arg_ptr = (uint8_t *) strtok(NULL, " ")) == NULL) return 1; I2C_OWNSLAVEADDR_CFG_Type_ptr = (I2C_OWNSLAVEADDR_CFG_Type *) strtoul((char *) arg_ptr, NULL, 16); if ((arg_ptr = (uint8_t *) strtok(NULL, " ")) == NULL) { sprintf((char *) str, "%x\r\n", (unsigned int) I2C_OWNSLAVEADDR_CFG_Type_ptr->SlaveAddrMaskValue); writeUSBOutString(str); return 0; } I2C_OWNSLAVEADDR_CFG_Type_ptr->SlaveAddrMaskValue = (uint8_t) strtoul((char *) arg_ptr, NULL, 16); return 0; }
int _TX_Desc_Ctrl(uint8_t * args) { uint8_t * arg_ptr; TX_Desc* TX_Desc_ptr; if ((arg_ptr = (uint8_t *) strtok(NULL, " ")) == NULL) return 1; TX_Desc_ptr = (TX_Desc *) strtoul((char *) arg_ptr, NULL, 16); if ((arg_ptr = (uint8_t *) strtok(NULL, " ")) == NULL) { sprintf((char *) str, "%x\r\n", (unsigned int) TX_Desc_ptr->Ctrl); writeUSBOutString(str); return 0; } TX_Desc_ptr->Ctrl = (uint32_t) strtoul((char *) arg_ptr, NULL, 16); return 0; }
int _TX_Stat_Info(uint8_t * args) { uint8_t * arg_ptr; TX_Stat* TX_Stat_ptr; if ((arg_ptr = (uint8_t *) strtok(NULL, " ")) == NULL) return 1; TX_Stat_ptr = (TX_Stat *) strtoul((char *) arg_ptr, NULL, 16); if ((arg_ptr = (uint8_t *) strtok(NULL, " ")) == NULL) { sprintf((char *) str, "%x\r\n", (unsigned int) TX_Stat_ptr->Info); writeUSBOutString(str); return 0; } TX_Stat_ptr->Info = (uint32_t) strtoul((char *) arg_ptr, NULL, 16); return 0; }
int _EMAC_PACKETBUF_Type_pbDataBuf(uint8_t * args) { uint8_t * arg_ptr; EMAC_PACKETBUF_Type* EMAC_PACKETBUF_Type_ptr; if ((arg_ptr = (uint8_t *) strtok(NULL, " ")) == NULL) return 1; EMAC_PACKETBUF_Type_ptr = (EMAC_PACKETBUF_Type *) strtoul((char *) arg_ptr, NULL, 16); if ((arg_ptr = (uint8_t *) strtok(NULL, " ")) == NULL) { sprintf((char *) str, "%x\r\n", (unsigned int) EMAC_PACKETBUF_Type_ptr->pbDataBuf); writeUSBOutString(str); return 0; } EMAC_PACKETBUF_Type_ptr->pbDataBuf = (uint32_t*) strtoul((char *) arg_ptr, NULL, 16); return 0; }
int _RX_Desc_Packet(uint8_t * args) { uint8_t * arg_ptr; RX_Desc* RX_Desc_ptr; if ((arg_ptr = (uint8_t *) strtok(NULL, " ")) == NULL) return 1; RX_Desc_ptr = (RX_Desc *) strtoul((char *) arg_ptr, NULL, 16); if ((arg_ptr = (uint8_t *) strtok(NULL, " ")) == NULL) { sprintf((char *) str, "%x\r\n", (unsigned int) RX_Desc_ptr->Packet); writeUSBOutString(str); return 0; } RX_Desc_ptr->Packet = (uint32_t) strtoul((char *) arg_ptr, NULL, 16); return 0; }
int _EMAC_CFG_Type_pbEMAC_Addr(uint8_t * args) { uint8_t * arg_ptr; EMAC_CFG_Type* EMAC_CFG_Type_ptr; if ((arg_ptr = (uint8_t *) strtok(NULL, " ")) == NULL) return 1; EMAC_CFG_Type_ptr = (EMAC_CFG_Type *) strtoul((char *) arg_ptr, NULL, 16); if ((arg_ptr = (uint8_t *) strtok(NULL, " ")) == NULL) { sprintf((char *) str, "%x\r\n", (unsigned int) EMAC_CFG_Type_ptr->pbEMAC_Addr); writeUSBOutString(str); return 0; } EMAC_CFG_Type_ptr->pbEMAC_Addr = (uint8_t*) strtoul((char *) arg_ptr, NULL, 16); return 0; }
int _RX_Stat_HashCRC(uint8_t * args) { uint8_t * arg_ptr; RX_Stat* RX_Stat_ptr; if ((arg_ptr = (uint8_t *) strtok(NULL, " ")) == NULL) return 1; RX_Stat_ptr = (RX_Stat *) strtoul((char *) arg_ptr, NULL, 16); if ((arg_ptr = (uint8_t *) strtok(NULL, " ")) == NULL) { sprintf((char *) str, "%x\r\n", (unsigned int) RX_Stat_ptr->HashCRC); writeUSBOutString(str); return 0; } RX_Stat_ptr->HashCRC = (uint32_t) strtoul((char *) arg_ptr, NULL, 16); return 0; }
int _GPIO_GetIntStatus(uint8_t * args) { uint8_t * arg_ptr; uint8_t portNum; uint32_t pinNum; uint8_t edgeState; if ((arg_ptr = (uint8_t *) strtok(NULL, " ")) == NULL) return 1; portNum = (uint8_t) strtoul((char *) arg_ptr, NULL, 16); if ((arg_ptr = (uint8_t *) strtok(NULL, " ")) == NULL) return 1; pinNum = (uint32_t) strtoul((char *) arg_ptr, NULL, 16); if ((arg_ptr = (uint8_t *) strtok(NULL, " ")) == NULL) return 1; edgeState = (uint8_t) strtoul((char *) arg_ptr, NULL, 16); sprintf((char *) str, "%x\r\n", (unsigned int) GPIO_GetIntStatus(portNum, pinNum, edgeState)); writeUSBOutString(str); return 0; }
int _I2C_SlaveTransferData(uint8_t * args) { uint8_t * arg_ptr; LPC_I2C_TypeDef* I2Cx; I2C_S_SETUP_Type* TransferCfg; I2C_TRANSFER_OPT_Type Opt; if ((arg_ptr = (uint8_t *) strtok(NULL, " ")) == NULL) return 1; I2Cx = (LPC_I2C_TypeDef*) strtoul((char *) arg_ptr, NULL, 16); if ((arg_ptr = (uint8_t *) strtok(NULL, " ")) == NULL) return 1; TransferCfg = (I2C_S_SETUP_Type*) strtoul((char *) arg_ptr, NULL, 16); if ((arg_ptr = (uint8_t *) strtok(NULL, " ")) == NULL) return 1; Opt = (I2C_TRANSFER_OPT_Type) strtoul((char *) arg_ptr, NULL, 16); sprintf((char *) str, "%x\r\n", (unsigned int) I2C_SlaveTransferData(I2Cx, TransferCfg, Opt)); writeUSBOutString(str); return 0; }
int _I2C_MonitorHandler(uint8_t * args) { uint8_t * arg_ptr; LPC_I2C_TypeDef* I2Cx; uint8_t* buffer; uint32_t size; if ((arg_ptr = (uint8_t *) strtok(NULL, " ")) == NULL) return 1; I2Cx = (LPC_I2C_TypeDef*) strtoul((char *) arg_ptr, NULL, 16); if ((arg_ptr = (uint8_t *) strtok(NULL, " ")) == NULL) return 1; buffer = (uint8_t*) strtoul((char *) arg_ptr, NULL, 16); if ((arg_ptr = (uint8_t *) strtok(NULL, " ")) == NULL) return 1; size = (uint32_t) strtoul((char *) arg_ptr, NULL, 16); sprintf((char *) str, "%x\r\n", (unsigned int) I2C_MonitorHandler(I2Cx, buffer, size)); writeUSBOutString(str); return 0; }
int _readAccel(uint8_t* args) { uint8_t receive_buffer[6]; I2C_M_SETUP_Type setup; int16_t* axis_data; Status result; uint8_t transmit_buffer; uint8_t axis_enable_bit; setup.sl_addr7bit = ACCEL_I2C_SLAVE_ADDRESS; setup.retransmissions_max = MAX_ST_I2C_RETRANSMISSIONS; setup.tx_data = &transmit_buffer; setup.tx_length = 1; setup.rx_data = receive_buffer; setup.rx_length = 6; transmit_buffer = ACCEL_DATA_ADDRESS|ST_I2C_AUTOINCREMENT_ADDRESS; result = I2C_MasterTransferData(LPC_I2C0, &setup, I2C_TRANSFER_POLLING); if(result == ERROR) return 1; axis_enable_bit = ACCEL_CTRL_REG_X_ENABLE; axis_data = (int16_t*)receive_buffer; unsigned int value[3]; int index=0; do { if(accel_ctrl_reg_1_a_value&axis_enable_bit) { value[index++] = (unsigned int)(*axis_data+ACCEL_VALUE_OFFSET); } axis_enable_bit <<= 1; axis_data++; }while(axis_enable_bit <= ACCEL_CTRL_REG_Z_ENABLE); sprintf((char*)str, "%x %x %x\r\n", value[0],value[1],value[2]); writeUSBOutString(str); return 0; }
int _deref(uint8_t * args) { uint8_t * arg_ptr; void * ptr; uint8_t size; uint8_t * ptr8; uint16_t * ptr16; uint32_t * ptr32; if ((arg_ptr = (uint8_t *) strtok(NULL, " ")) == NULL) return 1; ptr = (void *) strtoul((char *) arg_ptr, NULL, 16); ptr8 = ptr; ptr16 = ptr; ptr32 = ptr; if ((arg_ptr = (uint8_t *) strtok(NULL, " ")) == NULL) return 1; size = (uint8_t) strtoul((char *) arg_ptr, NULL, 16); if ((arg_ptr = (uint8_t *) strtok(NULL, " ")) == NULL) { if (size == 1) sprintf((char *) str, "%x\r\n", (unsigned int) *ptr8); else if (size == 2) sprintf((char *) str, "%x\r\n", (unsigned int) *ptr16); else if (size == 4) sprintf((char *) str, "%x\r\n", (unsigned int) *ptr32); else return 1; writeUSBOutString(str); return 0; } if (size == 1) *ptr8 = (uint8_t) strtoul((char *) arg_ptr, NULL, 16); else if (size == 2) *ptr16 = (uint16_t) strtoul((char *) arg_ptr, NULL, 16); else if (size == 4) *ptr32 = (uint32_t) strtoul((char *) arg_ptr, NULL, 16); else return 1; return 0; }