clock settings

This commit is contained in:
wn 2015-02-21 15:08:24 +01:00
parent 0b777f805a
commit bccaeae806
7 changed files with 19 additions and 175 deletions

View File

@ -1,13 +1,10 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<?fileVersion 4.0.0?>
<cproject storage_type_id="org.eclipse.cdt.core.XmlProjectDescriptionStorage">
<?fileVersion 4.0.0?><cproject storage_type_id="org.eclipse.cdt.core.XmlProjectDescriptionStorage">
<storageModule moduleId="org.eclipse.cdt.core.settings">
<cconfiguration id="dk.xpg.msp430eclipse.configuration.app.release.1341616894">
<storageModule buildSystemId="org.eclipse.cdt.managedbuilder.core.configurationDataProvider" id="dk.xpg.msp430eclipse.configuration.app.release.1341616894" moduleId="org.eclipse.cdt.core.settings" name="Release">
<externalSettings/>
<extensions>
<extension id="org.eclipse.cdt.core.ELF" point="org.eclipse.cdt.core.BinaryParser"/>
<extension id="org.eclipse.cdt.core.VCErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.GmakeErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.CWDLocator" point="org.eclipse.cdt.core.ErrorParser"/>
@ -15,6 +12,7 @@
<extension id="org.eclipse.cdt.core.GCCErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.GASErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.GLDErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.ELF" point="org.eclipse.cdt.core.BinaryParser"/>
</extensions>
</storageModule>
<storageModule moduleId="cdtBuildSystem" version="4.0.0">

3
.hgignore Normal file
View File

@ -0,0 +1,3 @@
syntax: regexp
^Release$

View File

@ -1,2 +1,7 @@
eclipse.preferences.version=1
msp430/DeviceSerialNumber=
msp430/MSP430TARGETMCU=msp430g2553
msp430/MSPDebugConnection=USB
msp430/MSPDebugDriver=rf2500
msp430/MSPDebugProtocol=SBW
msp430/MSPDebugTTYDevice=

View File

@ -5,12 +5,11 @@
* Author: wn
*/
#include <intrinsics.h>
//#include <isr_compat.h>
#include <msp430g2553.h>
#include <stdint.h>
#include <intrinsics.h>
#include <isr_compat.h>
#include "uart.h"
#include "time.h"
@ -19,30 +18,19 @@
int main() {
WDTCTL = WDTPW | WDTHOLD;
// P1DIR |= BIT6;
// P1SEL |= BIT6;
// P1SEL2 &= ~BIT6;
//
// TACCR0 = 1024;
// TACCR1 = 128;
// TACCTL0 = CCIE | OUTMOD_7;
// TACTL = MC_1 | ID_0 | TASSEL_1 | TACLR;
// highest possible system clock
DCOCTL = DCO0 | DCO1 | DCO2;
BCSCTL1 = XT2OFF | RSEL0 | RSEL1 | RSEL2 | RSEL3;
BCSCTL2 = 0;
BCSCTL3 = 0;
uartInit();
timeInit();
__enable_interrupt();
uartWrite('W');
uint32_t c = 0;
while (1) {
c++;
if (c >= 100000) {
c = 0;
uartWrite('x');
}
}
}

View File

@ -40,8 +40,8 @@ void timeInit() {
P1SEL |= BIT6;
P1OUT = 0;
TACCR0 = 1024;
TACCR1 = 768;
TACCR0 = 511;
TACCR1 = 8;
TACCTL1 = OUTMOD_7;
TACTL = MC_1 | ID_0 | TASSEL_2 | TACLR;
}

View File

@ -1,128 +0,0 @@
#include <msp430g2553.h>
#include <stdio.h>
#include <isr_compat.h>
#include "uart.h"
volatile uint8_t txBuffer[UART_TX_BUFFER_SIZE+5];
volatile uint8_t txBufferReadIdx = 0;
volatile uint8_t txBufferWriteIdx = 0;
volatile uint8_t rxBuffer[UART_RX_BUFFER_SIZE+5];
volatile uint8_t rxBufferReadIdx = 0;
volatile uint8_t rxBufferWriteIdx = 0;
static inline void enableDataRegisterEmptyInterrupt() {
IE2 |= UCA0TXIE;
}
static inline void disableDataRegisterEmptyInterrupt() {
IE2 &= ~UCA0TXIE;
}
void uartInit() {
UCA0CTL1 |= UCSWRST;
P1SEL = BIT1 + BIT2; // select secondary function TX, RX
P1SEL2 = BIT1 + BIT2; // dti
UCA0CTL0 |= UCPEN | UCPAR; // even parity
UCA0CTL1 |= UCSSEL0; // ACLK
UCA0BR0 = 13; // divider for 2400@32768
UCA0BR1 = 0;
UCA0MCTL = UCBRS1 | UCBRS2; // modulator for 2400@32768
UCA0CTL1 &= ~UCSWRST;
IE2 |= UCA0RXIE;
}
void uartWrite(uint8_t o) {
if (txBufferWriteIdx == (UART_TX_BUFFER_SIZE - 1)) {
while (txBufferReadIdx == UART_TX_BUFFER_SIZE);
} else {
while (txBufferReadIdx == (txBufferWriteIdx + 1));
}
txBuffer[txBufferWriteIdx] = o;
txBufferWriteIdx++;
if (txBufferWriteIdx > UART_TX_BUFFER_SIZE) {
txBufferWriteIdx = 0;
}
enableDataRegisterEmptyInterrupt();
}
//int uartPutchar(char c, FILE *stream) {
// if (c == '\n')
// uartPutchar('\r', stream);
// uartWrite((uint8_t) c);
// return 0;
//}
ISR(USCIAB0TX, UART_TX_ISR) {
if ((IFG2 & UCA0TXIE) != 0) {
if (txBufferReadIdx != txBufferWriteIdx) {
UCA0TXBUF = txBuffer[txBufferReadIdx];
txBufferReadIdx++;
if (txBufferReadIdx > UART_TX_BUFFER_SIZE) {
txBufferReadIdx = 0;
}
} else {
disableDataRegisterEmptyInterrupt();
}
}
}
ISR(USCIAB0RX, UART_RX_ISR) {
while ((IFG2 & UCA0RXIE) != 0) {
if (rxBufferWriteIdx == UART_RX_BUFFER_SIZE - 1) {
if (rxBufferReadIdx == UART_RX_BUFFER_SIZE) {
// rx buffer overflow
}
} else {
if (rxBufferReadIdx == rxBufferWriteIdx + 1) {
// rx buffer overflow
}
}
rxBuffer[rxBufferWriteIdx] = UCA0RXBUF;
rxBufferWriteIdx++;
if (rxBufferWriteIdx > UART_RX_BUFFER_SIZE) {
rxBufferWriteIdx = 0;
}
}
}
uint8_t uartHasChar() {
return rxBufferWriteIdx != rxBufferReadIdx;
}
uint8_t uartGetChar() {
uint8_t c = rxBuffer[rxBufferReadIdx];
rxBufferReadIdx++;
if (rxBufferReadIdx > UART_RX_BUFFER_SIZE) {
rxBufferReadIdx = 0;
}
return c;
}
int uartRead() {
int res = -1;
if (uartHasChar()) {
res = uartGetChar();
}
return res;
}

View File

@ -1,22 +0,0 @@
#ifndef UART_H_
#define UART_H_
#include <stdint.h>
// #include <stdio.h>
#define UART_TX_BUFFER_SIZE 32
#define UART_RX_BUFFER_SIZE 16
void uartInit();
// int uartPutchar(char c, FILE *stream);
void uartWrite(uint8_t o);
uint8_t uartHasChar();
uint8_t uartGetChar();
int uartRead();
#endif /* UART_H_ */