Skip to content

Commit

Permalink
working version of f1611 port
Browse files Browse the repository at this point in the history
  • Loading branch information
anroOfCode committed Nov 27, 2012
1 parent f70b633 commit 6343158
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 21 deletions.
13 changes: 10 additions & 3 deletions android/src/umich/framjack/core/SerialDecoder.java
Expand Up @@ -32,7 +32,12 @@ private enum ReceiveState { IDLE, DATA, DATANEXT };
private int _currentEdgeLength = 0;
private boolean _currentEdgeHigh = false;

private int _threshold = 7;
// FOR THE MSP430FR5969:
//private int _threshold = 7;

// FOR THE MSP430F1611:
private int _threshold = 12;

private int _deltaT = 0;

private ReceiveState _rxState = ReceiveState.IDLE;
Expand Down Expand Up @@ -126,7 +131,8 @@ else if (isWithinThreshold(_currentEdgeLength, _deltaT * 2)) {
advanceReceiveDataState();
}
else {
System.out.println("Error.");
System.out.println("EL: " + _currentEdgeLength + " DT: " + _deltaT);
//System.out.println("Error.");
_rxState = ReceiveState.IDLE;
}
}
Expand All @@ -141,8 +147,9 @@ private void receiveDataNext() {
advanceReceiveDataState();
}
else {
System.out.println("BEL: " + _currentEdgeLength + " DT: " + _deltaT);
_rxState = ReceiveState.IDLE;
System.out.println("Error.");
//System.out.println("Error.");
}
}

Expand Down
4 changes: 2 additions & 2 deletions hijack/src/include/config.h
Expand Up @@ -36,7 +36,7 @@

// Used by the coding state machine to identify
// long and short pulses.
#define THRESHOLD 8
#define DELTAT 17
#define THRESHOLD 4
#define DELTAT 20

#endif
3 changes: 3 additions & 0 deletions hijack/src/include/f1611_timer.h
Expand Up @@ -27,6 +27,9 @@
typedef void timer_captureCallback(uint16_t);
typedef void timer_periodicCallback(void);

timer_captureCallback *timer_captureCbPtr;
timer_periodicCallback *timer_periodicCbPtr;

void timer_init (void);
void timer_start (void);
void timer_setCaptureCallback (timer_captureCallback* cb);
Expand Down
2 changes: 2 additions & 0 deletions hijack/src/lib/pal.c
Expand Up @@ -180,7 +180,9 @@ void pal_startTimers(void) {
timer_init();
timer_setCaptureCallback(pal_captureTimerFn);
timer_setPeriodicCallback(pal_periodicTimerFn);

timer_start();

util_delayMs(100);
}

Expand Down
20 changes: 12 additions & 8 deletions hijack/src/main.c
Expand Up @@ -57,6 +57,7 @@ void captureTimerFn(uint16_t elapsedTime, uint8_t isHigh) {

void packetReceivedCallback(uint8_t * buf, uint8_t len) {
if (len == 1) {
pal_setDigitalGpio(pal_gpio_led, 1);
pal_setDigitalGpio(pal_gpio_dout1, ((buf[0] >> 0) & 0x01));
pal_setDigitalGpio(pal_gpio_dout2, ((buf[0] >> 1) & 0x01));
pal_setDigitalGpio(pal_gpio_dout3, ((buf[0] >> 2) & 0x01));
Expand Down Expand Up @@ -118,13 +119,7 @@ void initializeSystem(void) {

// Start the interrupt-driven timers.
pal_startTimers();

while(1)
{
pal_setDigitalGpio(pal_gpio_led, 1);
pal_setDigitalGpio(pal_gpio_led, 0);
}


// Start the transmit callback-driven
// loop
fe_writeTxBuffer(outMessage, 9);
Expand All @@ -139,11 +134,20 @@ int main () {
initializeSystem();
// TODO: Add sleep commands!

/*while(1)
{
pal_setDigitalGpio(pal_gpio_led, 1);
pal_setDigitalGpio(pal_gpio_led, 0);
}*/


while(1) {
//pal_setDigitalGpio(pal_gpio_led, 0);
updateDigitalOutputBuffer();
updateAnalogOutputBuffer();

//pal_setDigitalGpio(pal_gpio_led, 1);
pal_loopDelay();

}
return 0;
}
36 changes: 29 additions & 7 deletions hijack/src/peripherals/msp/f1611_timer.c
Expand Up @@ -22,6 +22,8 @@
#include "ptimer.h"
#include "ctimer.h"

#include "pal.h"

#include <msp430.h>

void timer_init (void) {
Expand All @@ -40,14 +42,14 @@ void timer_init (void) {

///////////////////////////
// TimerA - Capture Timer
TACTL = TASSEL_1 + TACLR + TAIE;
TACCTL0 = CM_3 + CCIS_1 + CAP + CCIE;
TACTL = TASSEL_1 + TACLR;
TACCTL1 = CM_3 + CCIS_1 + CAP + CCIE;

///////////////////////////
// TimerB - Periodic Timer
TBCTL = TBSSEL_1 + TBIE + TBCLR;
TBCCTL0 = CCIE;
TBCCR0 = 17;
TBCCTL0 = 0;
TBCCR0 = DELTAT;
}

void timer_start (void) {
Expand All @@ -56,11 +58,11 @@ void timer_start (void) {
}

void timer_setCaptureCallback (timer_captureCallback* cb) {

timer_captureCbPtr = cb;
}

void timer_setPeriodicCallback (timer_periodicCallback* cb) {

timer_periodicCbPtr = cb;
}

void timer_stop (void) {
Expand All @@ -69,7 +71,27 @@ void timer_stop (void) {
}

uint8_t timer_readCaptureLine (void) {
return !!(TACCTL0 & CCI);
return !(TACCTL1 & CCI);
}

#pragma vector = TIMERA1_VECTOR
__interrupt void Timer_A1 (void) {

uint16_t captureReg = TAR;

if (captureReg > 5) {
TAR = 0;
timer_captureCbPtr(captureReg);
}

TACCTL1 &= ~CCIFG;
}

#pragma vector = TIMERB1_VECTOR
__interrupt void Timer_B1 (void) {
timer_periodicCbPtr();
TBCTL &= ~TBIFG;
}


#endif
5 changes: 4 additions & 1 deletion hijack/src/peripherals/msp/utility.c
Expand Up @@ -145,13 +145,16 @@ void util_boardInit(void) {
// .RSEL, do not modify
BCSCTL1 = XT2OFF | (BCSCTL1 & (RSEL2|RSEL1|RSEL0));

BCSCTL1 |= RSEL0 + RSEL1 + RSEL2;
DCOCTL |= DCO0 + DCO1 + DCO2;
// BCSCTL2
// .SELM = 0; select DCOCLK as source for MCLK
// .DIVM = 0; set the divisor of MCLK to 1
// .SELS = 0; select DCOCLK as source for SCLK
// .DIVS = 2; set the divisor of SCLK to 4
// .DCOR = 1; select internal resistor for DCO
BCSCTL2 = DIVS1 | DCOR;
//BCSCTL2 = DIVS1 | DCOR;

#endif

}
Expand Down

0 comments on commit 6343158

Please sign in to comment.