03.08.2013 Views

S.N.A.K.E.: A Dynamically Reconfigurable Artificial Sensate Skin ...

S.N.A.K.E.: A Dynamically Reconfigurable Artificial Sensate Skin ...

S.N.A.K.E.: A Dynamically Reconfigurable Artificial Sensate Skin ...

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

C:\Documents and Settings\Gerardo\My Documents\Work\SM (MIT)\Thesis\Code\Firmware\BootLoader.s43<br />

C:\Documents and Settings\Gerardo\My Documents\Work\SM (MIT)\Thesis\Code\Firmware\BootLoader.s43<br />

MOV.B #7, I2CSCLL ; Set Baud Rate to 400Khz<br />

MOV #I2C_OWN_ADDRESS,&I2COA ; Slave Address is 048h<br />

BIS.B #I2CEN,&U0CTL ; Enable I2C<br />

//INITIALIZE VARIABLES<br />

MOV.W #0, fileBufPtr ; Init pointer<br />

MOV.B #0, fileFlags ; Init flags<br />

MOV.B #0, I2CFlags<br />

CLR R6<br />

#include "msp430x16x.h"<br />

#define MAX_CODE_SIZE (0x1000)<br />

#define CODE_START_ADD (0x8000)<br />

#define REFLASH_INST (0xA0)<br />

#define RESET_BRAIN_INST (0xA2)<br />

#define RESET_NODE_INST (0xA4)<br />

#define EXECUTE_CODE_INST (0xA6)<br />

#define I2C_OWN_ADDRESS (261)<br />

MOV.W #130, R10 ; Delay to signal reset<br />

CALL #DELAY ;<br />

MOV.B #0BFh, &P4OUT ; Turn off Led's<br />

EINT ; Enable interrupts<br />

;------------------------------------------------------------------------------<br />

ORG 1140h<br />

;------------------------------------------------------------------------------<br />

MainLoop<br />

MOV #1, R10 ; Wait until An instruction<br />

CALL #I2C_GET_BYTE ; is received, and then decode it<br />

BIT.B #1, &I2CFlags ; if flag is set, nothing was received<br />

JC MainLoop ; jump back to main loop<br />

BIC.B #OAIFG+GCIFG, &I2CIFG<br />

fileBuf DS MAX_CODE_SIZE<br />

fileBufPtr DS 2<br />

Address DS 2<br />

nBytes DS 2<br />

codeStartAdd DS 2<br />

fileSize DS 2<br />

codeSize DS 2<br />

DataFlags DS 1<br />

fileFlags DS 1<br />

I2CFlags DS 1<br />

DecodeInstruction<br />

CMP.B #REFLASH_INST, R5 ; If it is a reflash instruction<br />

JZ ReflashSelf ; get file first, then reflash device<br />

CMP.B #RESET_NODE_INST, R5 ; If the instruction is to reset<br />

JZ ResetSelf ; Write invalid code to Watchdog for PUC<br />

CMP.B #EXECUTE_CODE_INST, R5 ; If there is a code loaded and it<br />

JZ ExecuteCode ; needs to execute, jump to its start address<br />

JMP MainLoop ; Invalid instruction/data<br />

;------------------------------------------------------------------------------<br />

ORG 0FA00h ; Progam Start<br />

;------------------------------------------------------------------------------<br />

RESET<br />

MOV.W #1130h,SP ; Initialize 'x1x9 stackpointer<br />

//STOP WATCHDOG<br />

MOV.W #WDTPW+WDTHOLD, &WDTCTL ; stop watchdog<br />

ReflashSelf<br />

MOV #200h, R10<br />

CALL #I2C_GET_BYTE<br />

MOV R5, R6<br />

CALL #I2C_GET_BYTE<br />

SWPB R5<br />

XOR R6, R5<br />

MOV R5, fileSize<br />

BIT.B #01, I2CFlags<br />

JNC GetFile<br />

BIS.B #06, fileFlags<br />

MOV #0FFh, R10<br />

MOV.B fileFlags, R5<br />

CALL #I2C_SLAVE_READ<br />

JMP MainLoop<br />

//Then, receive the file<br />

GetFile<br />

CALL #GET_FILE<br />

CALL #REFLASH_SELF<br />

JMP MainLoop<br />

//INITIALIZE SVS<br />

MOV.B #060h+PORON,&SVSCTL ; SVS POR enabled @ 2.6V<br />

//INITIALIZE CRYSTAL (8.000 MHZ)<br />

BIC #OSCOFF, SR<br />

BIS.B #XTS, &BCSCTL1 ; LFXTL high-freq mode<br />

L1 ; wait for crystal to stabilize<br />

BIC.B #OFIFG,&IFG1 ; Clear OFIFG<br />

MOV #0FFh,R15 ; Delay<br />

L2<br />

DEC R15<br />

JNZ L2<br />

BIT.B #OFIFG,&IFG1 ; Re–test OFIFG<br />

JNZ L1 ; Repeat test if needed<br />

//INITIALIZE PORTS<br />

BIS.B #07Fh,&P4DIR ; Set as outputs<br />

MOV.B #0B5h,&P4OUT ; Turn off Strain gauges<br />

ResetSelf<br />

MOV #0, WDTCTL ; Invalid watchdog write to cause PUC<br />

ExecuteCode<br />

MOV #01000h, R5 ; Load pointer<br />

CMP #0, 0(R5) ; This address contains a flag indicating<br />

//INITIALIZE I2C PORT<br />

BIS.B #0Ah,&P3SEL ; Select I2C pins<br />

BIS.B #I2C+SYNC+XA,&U0CTL ; Recommended init procedure<br />

BIC.B #I2CEN,&U0CTL ; Recommended init procedure<br />

BIS.B #I2CSSEL0+I2CRM,&I2CTCTL; ACLK<br />

MOV.B #7, I2CSCLH ; Set Baud Rate to 400Khz<br />

Page 2 of 6<br />

Page 1 of 6

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!