Skip to content

Commit

Permalink
Radio and dfmem + dma seem to function; telem readback in octoroach p…
Browse files Browse the repository at this point in the history
…roject fails with AddressError
  • Loading branch information
apullin committed Feb 12, 2013
1 parent 5ebf3f7 commit 33e046c
Show file tree
Hide file tree
Showing 13 changed files with 321 additions and 253 deletions.
90 changes: 90 additions & 0 deletions firmware/nbproject/configurations.xml
Expand Up @@ -38,6 +38,7 @@
<itemPath>../lib/imu.h</itemPath>
<itemPath>../../imageproc-lib/spi_controller.h</itemPath>
<itemPath>../lib/led.h</itemPath>
<itemPath>../lib/or_telem.h</itemPath>
</logicalFolder>
<itemPath>source/cmd.h</itemPath>
<itemPath>source/settings.h</itemPath>
Expand Down Expand Up @@ -69,6 +70,10 @@
<itemPath>../../imageproc-lib/spi_controller.c</itemPath>
<itemPath>../../imageproc-lib/ams-enc.c</itemPath>
<itemPath>../../imageproc-lib/at86rf231_driver.c</itemPath>
<itemPath>../../imageproc-lib/payload.c</itemPath>
<itemPath>../../imageproc-lib/carray.c</itemPath>
<itemPath>../../imageproc-lib/ppool.c</itemPath>
<itemPath>../../imageproc-lib/mac_packet.c</itemPath>
</logicalFolder>
<logicalFolder name="lib" displayName="lib" projectFiles="true">
<itemPath>../../imageproc-lib/delay.s</itemPath>
Expand Down Expand Up @@ -665,6 +670,7 @@
<appendMe value="-g "/>
</C30-AS>
<C30-LD>
<property key="additional-options-use-response-files" value="false"/>
<property key="boot-eeprom" value="no_eeprom"/>
<property key="boot-flash" value="no_flash"/>
<property key="boot-ram" value="no_ram"/>
Expand Down Expand Up @@ -709,6 +715,90 @@
<property key="output-file-format" value="elf"/>
</C30Global>
<RealICEPlatformTool>
<property key="ADC 1" value="true"/>
<property key="ADC 2" value="true"/>
<property key="AutoSelectMemRanges" value="auto"/>
<property key="Freeze All Other Peripherals" value="true"/>
<property key="I2C1" value="true"/>
<property key="I2C2" value="true"/>
<property key="INPUT CAPTURE 1" value="true"/>
<property key="INPUT CAPTURE 2" value="true"/>
<property key="INPUT CAPTURE 3" value="true"/>
<property key="INPUT CAPTURE 4" value="true"/>
<property key="INPUT CAPTURE 5" value="true"/>
<property key="INPUT CAPTURE 6" value="true"/>
<property key="INPUT CAPTURE 7" value="true"/>
<property key="INPUT CAPTURE 8" value="true"/>
<property key="OUTPUT COMPARE 1" value="true"/>
<property key="OUTPUT COMPARE 2" value="true"/>
<property key="OUTPUT COMPARE 3" value="true"/>
<property key="OUTPUT COMPARE 4" value="true"/>
<property key="OUTPUT COMPARE 5" value="true"/>
<property key="OUTPUT COMPARE 6" value="true"/>
<property key="OUTPUT COMPARE 7" value="true"/>
<property key="OUTPUT COMPARE 8" value="true"/>
<property key="PWM" value="true"/>
<property key="QEI" value="true"/>
<property key="RIExTrigs.Five" value="OFF"/>
<property key="RIExTrigs.Four" value="OFF"/>
<property key="RIExTrigs.One" value="OFF"/>
<property key="RIExTrigs.Seven" value="OFF"/>
<property key="RIExTrigs.Six" value="OFF"/>
<property key="RIExTrigs.Three" value="OFF"/>
<property key="RIExTrigs.Two" value="OFF"/>
<property key="RIExTrigs.Zero" value="OFF"/>
<property key="SPI 1" value="true"/>
<property key="SPI 2" value="true"/>
<property key="SecureSegment.SegmentProgramming" value="FullChipProgramming"/>
<property key="TIMER1" value="true"/>
<property key="TIMER2" value="true"/>
<property key="TIMER3" value="true"/>
<property key="TIMER4" value="true"/>
<property key="TIMER5" value="true"/>
<property key="TIMER6" value="true"/>
<property key="TIMER7" value="true"/>
<property key="TIMER8" value="true"/>
<property key="TIMER9" value="true"/>
<property key="ToolFirmwareFilePath"
value="Press to browse for a specific firmware version"/>
<property key="ToolFirmwareOption.UseLatestFirmware" value="true"/>
<property key="UART 1" value="true"/>
<property key="UART 2" value="true"/>
<property key="debugoptions.useswbreakpoints" value="false"/>
<property key="hwtoolclock.frcindebug" value="false"/>
<property key="hwtoolclock.instructionspeed" value="4"/>
<property key="hwtoolclock.units" value="mips"/>
<property key="memories.aux" value="false"/>
<property key="memories.bootflash" value="true"/>
<property key="memories.configurationmemory" value="true"/>
<property key="memories.eeprom" value="true"/>
<property key="memories.flashdata" value="true"/>
<property key="memories.id" value="true"/>
<property key="memories.programmemory" value="true"/>
<property key="memories.programmemory.end" value="0x157ff"/>
<property key="memories.programmemory.start" value="0x0"/>
<property key="poweroptions.powerenable" value="false"/>
<property key="programoptions.eraseb4program" value="true"/>
<property key="programoptions.preserveeeprom" value="false"/>
<property key="programoptions.preserveprogramrange" value="false"/>
<property key="programoptions.preserveprogramrange.end" value="0x157ff"/>
<property key="programoptions.preserveprogramrange.start" value="0x0"/>
<property key="programoptions.preserveuserid" value="false"/>
<property key="programoptions.usehighvoltageonmclr" value="false"/>
<property key="programoptions.uselvpprogramming" value="false"/>
<property key="tracecontrol.collectioninterval" value="1"/>
<property key="tracecontrol.collectionunits" value="1"/>
<property key="tracecontrol.disablemacros" value="false"/>
<property key="tracecontrol.medium" value="0"/>
<property key="tracecontrol.portselect" value="0"/>
<property key="tracecontrol.select" value="0"/>
<property key="tracecontrol.spiselect" value="0"/>
<property key="tracecontrol.timerpriority" value="3"/>
<property key="tracecontrol.timerselect" value="0"/>
<property key="tracecontrol.tracebufmax" value="54600"/>
<property key="tracecontrol.tracefile" value="C:\Users\pullin\mpdeftrace.log"/>
<property key="tracecontrol.tracefilemax" value="1048510"/>
<property key="voltagevalue" value="${poweroptions.DefaultPower}"/>
</RealICEPlatformTool>
</conf>
</confs>
Expand Down
108 changes: 51 additions & 57 deletions firmware/source/cmd.c
Expand Up @@ -57,19 +57,12 @@ extern volatile char g_radio_duty_cycle;
// CMD_VECTOR_SIZE is defined in cmd_const.h
void (*cmd_func[CMD_VECTOR_SIZE])(unsigned char, unsigned char, unsigned char*);

static CircArray input_queue;

/*-----------------------------------------------------------------------------
* Declaration of static functions
-----------------------------------------------------------------------------*/
static void cmdSetThrust(unsigned char status, unsigned char length, unsigned char *frame);
static void cmdSteer(unsigned char status, unsigned char length, unsigned char *frame);
static void cmdGetImuData(unsigned char status, unsigned char length, unsigned char *frame);
static void cmdGetImuLoop(unsigned char status, unsigned char length, unsigned char *frame);

static void cmdStartImuDataSave(unsigned char status, unsigned char length, unsigned char *frame);
static void cmdStopImuDataSave(unsigned char status, unsigned char length, unsigned char *frame);
static void cmdTxSavedImuData(unsigned char status, unsigned char length, unsigned char *frame);
static void cmdEraseMemSector(unsigned char status, unsigned char length, unsigned char *frame);

//static void cmdEcho(unsigned char status, unsigned char length, unsigned char *frame);
Expand Down Expand Up @@ -103,14 +96,10 @@ static void cmdSetThrustHall(unsigned char status, unsigned char length, unsigne
/*-----------------------------------------------------------------------------
* Public functions
-----------------------------------------------------------------------------*/
unsigned int cmdSetup(unsigned int queue_size) {
unsigned int cmdSetup(void) {

unsigned int i;

input_queue = carrayCreate(queue_size);
if(input_queue == NULL) {
return 0;
}

// initialize the array of func pointers with Nop()
for (i = 0; i < MAX_CMD_FUNC; ++i) {
Expand All @@ -121,11 +110,6 @@ unsigned int cmdSetup(unsigned int queue_size) {
cmd_func[CMD_ECHO] = &cmdEcho;
cmd_func[CMD_SET_THRUST] = &cmdSetThrust;
cmd_func[CMD_SET_STEER] = &cmdSteer;
cmd_func[CMD_GET_IMU_DATA] = &cmdGetImuData;
cmd_func[CMD_GET_IMU_LOOP] = &cmdGetImuLoop;
cmd_func[CMD_START_IMU_SAVE] = &cmdStartImuDataSave;
cmd_func[CMD_STOP_IMU_SAVE] = &cmdStopImuDataSave;
cmd_func[CMD_TX_SAVED_IMU_DATA] = &cmdTxSavedImuData;
cmd_func[CMD_ERASE_MEM_SECTOR] = &cmdEraseMemSector;
//User commands
cmd_func[CMD_SET_THRUST_OPENLOOP] = &cmdSetThrustOpenLoop;
Expand Down Expand Up @@ -154,22 +138,22 @@ unsigned int cmdSetup(unsigned int queue_size) {
}

void cmdHandleRadioRxBuffer(void) {

MacPacket packet;
Payload pld;
unsigned char command;

// Check for unprocessed packet
//packet = radioDequeueRxPacket();
packet = carrayPopTail(input_queue);
if(packet == NULL) { return; }

pld = macGetPayload(packet);
command = payGetType(pld);
if(command < MAX_CMD_FUNC_SIZE) {
cmd_func[command](packet);
unsigned char command, status;
if ((packet = radioDequeueRxPacket()) != NULL) {
LED_ORANGE = 1;
pld = macGetPayload(packet);
status = payGetStatus(pld);
command = payGetType(pld);
if (command < MAX_CMD_FUNC) {
cmd_func[command](status, payGetDataLength(pld), payGetData(pld));
}
radioReturnPacket(packet);
}
radioReturnPacket(packet);

return;
}

//////////////////////////////////
Expand Down Expand Up @@ -227,18 +211,13 @@ static void cmdEraseMemSector(unsigned char status, unsigned char length, unsign
-----------------------------------------------------------------------------*/
void cmdEcho(unsigned char status, unsigned char length, unsigned char *frame) {

char* temp = malloc(length*sizeof(char));
strncpy(temp,(char*)frame,length);

radioSendPayload(macGetDestAddr(), payCreate(length, frame, status, CMD_ECHO));
//Payload pld;
//pld = payCreateEmpty(1);
//paySetStatus(pld, status);
//paySetType(pld, CMD_ECHO);
//unsigned char temp = 99;
//paySetData(pld, 1, &temp);

//radioSendPayload((WordVal) macGetDestAddr(), pld);
Payload pld;
pld = payCreateEmpty(length);
pld->pld_data[0] = status;
pld->pld_data[1] = CMD_ECHO;
memcpy((pld->pld_data) + 2, frame, length);
radioSendPayload(RADIO_DST_ADDR, pld);

}

static void cmdNop(unsigned char status, unsigned char length, unsigned char *frame) {
Expand Down Expand Up @@ -280,7 +259,7 @@ static void cmdSetPIDGains(unsigned char status, unsigned char length, unsigned
pld->pld_data[0] = status;
pld->pld_data[1] = CMD_SET_PID_GAINS;
memcpy((pld->pld_data) + 2, frame, 20);
radioSendPayload((WordVal) macGetDestAddr(), pld);
radioSendPayload(RADIO_DST_ADDR, pld);
}

static void cmdGetPIDTelemetry(unsigned char status, unsigned char length, unsigned char *frame) {
Expand All @@ -297,7 +276,7 @@ static void cmdSetCtrldTurnRate(unsigned char status, unsigned char length, unsi
pld->pld_data[0] = status;
pld->pld_data[1] = CMD_SET_CTRLD_TURN_RATE;
memcpy((pld->pld_data) + 2, frame, sizeof(_args_cmdSetCtrldTurnRate));
radioSendPayload((WordVal) macGetDestAddr(), pld);
radioSendPayload(RADIO_DST_ADDR, pld);
}

static void cmdGetImuLoopZGyro(unsigned char status, unsigned char length, unsigned char *frame) {
Expand Down Expand Up @@ -342,14 +321,27 @@ static void cmdSetSteeringGains(unsigned char status, unsigned char length, unsi
pld->pld_data[0] = status;
pld->pld_data[1] = CMD_SET_STEERING_GAINS;
memcpy((pld->pld_data) + 2, frame, sizeof(_args_cmdSetSteeringGains));
radioSendPayload((WordVal) macGetDestAddr(), pld);
radioSendPayload(RADIO_DST_ADDR, pld);

}

static void cmdSoftwareReset(unsigned char status, unsigned char length, unsigned char *frame) {
char* resetmsg = "RESET";
radioSendPayload(macGetDestAddr(), payCreate(6, (unsigned char*)resetmsg, status, CMD_ECHO));
delay_ms(10);
char resetmsg[] = "RESET";
int len = strlen(resetmsg);

MacPacket response;
response = radioRequestPacket(len);

macSetDestPan(response, RADIO_PAN_ID);
macSetDestAddr(response, RADIO_DST_ADDR);
Payload pld = macGetPayload(response);

paySetData(pld, len, (unsigned char*)resetmsg);
paySetType(pld, CMD_SOFTWARE_RESET);
paySetStatus(pld, 0);

while(!radioEnqueueTxPacket(response)) { radioProcess(); }

#ifndef __DEBUG
__asm__ volatile ("reset");
#endif
Expand All @@ -375,7 +367,7 @@ static void cmdEraseSector(unsigned char status, unsigned char length, unsigned
paySetData(pld, 4, (unsigned char*) (&(argsPtr->samples)));
paySetStatus(pld, status);
paySetType(pld, CMD_ERASE_SECTORS);
radioSendPayload((WordVal) macGetDestAddr(), pld);
radioSendPayload(RADIO_DST_ADDR, pld);
}

static void cmdFlashReadback(unsigned char status, unsigned char length, unsigned char *frame) {
Expand All @@ -396,7 +388,7 @@ static void cmdSleep(unsigned char status, unsigned char length, unsigned char *
paySetData(pld, 1, (unsigned char*) (&sleep)); //echo back a CMD_SLEEP with '0', incdicating a wakeup
paySetStatus(pld, status);
paySetType(pld, CMD_SLEEP);
radioSendPayload((WordVal) macGetDestAddr(), pld);
radioSendPayload(RADIO_DST_ADDR, pld);
}
}

Expand All @@ -416,14 +408,14 @@ static void cmdSetVelProfile(unsigned char status, unsigned char length, unsigne
paySetType(pld, CMD_SET_VEL_PROFILE);
// packet length = 48 bytes (24 ints)
memcpy((pld->pld_data) + 2, frame, sizeof(_args_cmdSetVelProfile));
radioSendPayload((WordVal) macGetDestAddr(), pld);
radioSendPayload(RADIO_DST_ADDR, pld);
}

// report motor position and reset motor position (from Hall effect sensors)
// note motor_count is long (4 bytes)
void cmdZeroPos(unsigned char status, unsigned char length, unsigned char *frame) {

radioSendPayload(macGetDestAddr(), payCreate(2*sizeof(long),
radioSendPayload(RADIO_DST_ADDR, payCreate(2*sizeof(long),
(unsigned char *)(hallGetMotorCounts()), status, CMD_ZERO_POS));
hallZeroPos(0);
hallZeroPos(1);
Expand All @@ -444,9 +436,11 @@ void cmdWhoAmI(unsigned char status, unsigned char length, unsigned char *frame)
// maximum string length to avoid packet size limit
char* verstr = versionGetString();
int verlen = strlen(verstr);
//The cast to unsigned char* is here to prevent a warning
Payload pld = payCreate(verlen, (unsigned char*)verstr, status, CMD_WHO_AM_I);
radioSendPayload(macGetDestAddr(), pld);

Payload pld;
pld = payCreate(verlen, (unsigned char*)verstr, 0, CMD_WHO_AM_I);

radioSendPayload(RADIO_DST_ADDR,pld);
}

static void cmdSetHallGains(unsigned char status, unsigned char length, unsigned char *frame) {
Expand All @@ -464,7 +458,7 @@ static void cmdSetHallGains(unsigned char status, unsigned char length, unsigned
paySetType(pld, CMD_SET_HALL_GAINS);
paySetStatus(pld, status);
memcpy((pld->pld_data) + 2, frame, 20);
radioSendPayload((WordVal) macGetDestAddr(), pld);
radioSendPayload(RADIO_DST_ADDR, pld);
}

static void cmdSetTailQueue(unsigned char status, unsigned char length, unsigned char *frame) {
Expand Down Expand Up @@ -504,7 +498,7 @@ static void cmdSetTailGains(unsigned char status, unsigned char length, unsigned
pld->pld_data[0] = status;
pld->pld_data[1] = CMD_SET_TAIL_GAINS;
memcpy((pld->pld_data) + 2, frame, sizeof(_args_cmdSetTailGains));
radioSendPayload(macGetDestAddr(), pld);
radioSendPayload(RADIO_DST_ADDR, pld);
}


Expand Down
2 changes: 1 addition & 1 deletion firmware/source/cmd.h
Expand Up @@ -62,7 +62,7 @@ is invalid and void.
#define LEN_CMD_SLEEP 1 //1 char
*/

void cmdSetup(void);
unsigned int cmdSetup(void);
void cmdHandleRadioRxBuffer(void);
void cmdEcho(unsigned char status, unsigned char length, unsigned char *frame);

Expand Down

0 comments on commit 33e046c

Please sign in to comment.