This commit is contained in:
Wolfgang Hottgenroth 2015-02-21 11:21:10 +01:00
commit 0b777f805a
8 changed files with 359 additions and 0 deletions

58
.cproject Normal file
View File

@ -0,0 +1,58 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<?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"/>
<extension id="org.eclipse.cdt.core.MakeErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<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"/>
</extensions>
</storageModule>
<storageModule moduleId="cdtBuildSystem" version="4.0.0">
<configuration artifactExtension="elf" artifactName="${ProjName}" buildArtefactType="dk.xpg.msp430eclipse.buildArtefactType.app" buildProperties="org.eclipse.cdt.build.core.buildType=org.eclipse.cdt.build.core.buildType.release,org.eclipse.cdt.build.core.buildArtefactType=dk.xpg.msp430eclipse.buildArtefactType.app" cleanCommand="rm -rf" description="" errorParsers="org.eclipse.cdt.core.MakeErrorParser;org.eclipse.cdt.core.GCCErrorParser;org.eclipse.cdt.core.GLDErrorParser;org.eclipse.cdt.core.GASErrorParser;org.eclipse.cdt.core.VCErrorParser" id="dk.xpg.msp430eclipse.configuration.app.release.1341616894" name="Release" parent="dk.xpg.msp430eclipse.configuration.app.release">
<folderInfo id="dk.xpg.msp430eclipse.configuration.app.release.1341616894." name="/" resourcePath="">
<toolChain id="dk.xpg.msp430eclipse.toolchain.gcc.app.release.1721391443" name="MSP430 GCC Toolchain" superClass="dk.xpg.msp430eclipse.toolchain.gcc.app.release">
<targetPlatform archList="all" binaryParser="org.eclipse.cdt.core.ELF" id="dk.xpg.msp430eclipse.targetplatform.msp430.141839182" isAbstract="false" name="MSP430 Cross-Target" osList="all" superClass="dk.xpg.msp430eclipse.targetplatform.msp430"/>
<builder buildPath="${workspace_loc:/SMPS2}/Release" id="dk.xpg.msp430eclipse.target.gnu.builder.2098780814" keepEnvironmentInBuildfile="false" managedBuildOn="true" name="MSP430 GNU Make Builder" superClass="dk.xpg.msp430eclipse.target.gnu.builder"/>
<tool id="dk.xpg.msp430eclipse.tool.compiler.gcc.898556828" name="MSP430 C Compiler" superClass="dk.xpg.msp430eclipse.tool.compiler.gcc">
<option defaultValue="dk.xpg.msp430eclipse.compiler.option.optimization.level.most" id="dk.xpg.msp430eclipse.compiler.option.optimization.level.1899936733" name="Optimization Level" superClass="dk.xpg.msp430eclipse.compiler.option.optimization.level" valueType="enumerated"/>
<option defaultValue="dk.xpg.msp430eclipse.compiler.option.debugging.level.none" id="dk.xpg.msp430eclipse.compiler.option.debugging.level.836801600" name="Debugging Level" superClass="dk.xpg.msp430eclipse.compiler.option.debugging.level" valueType="enumerated"/>
<inputType id="dk.xpg.msp430eclipse.tool.compiler.gcc.input.1995414162" name="C Source File" superClass="dk.xpg.msp430eclipse.tool.compiler.gcc.input"/>
<inputType id="dk.xpg.msp430eclipse.tool.compiler.gcc.input.cc.1834168683" name="C++ Source File" superClass="dk.xpg.msp430eclipse.tool.compiler.gcc.input.cc"/>
</tool>
<tool id="dk.xpg.msp430eclipse.tool.assembler.gcc.82270858" name="MSP430 Assembler" superClass="dk.xpg.msp430eclipse.tool.assembler.gcc">
<inputType id="dk.xpg.msp430eclipse.tool.assembler.input.2093820839" name="Assembler Files" superClass="dk.xpg.msp430eclipse.tool.assembler.input"/>
</tool>
<tool id="dk.xpg.msp430eclipse.tool.linker.gcc.642305468" name="MSP430 Linker" superClass="dk.xpg.msp430eclipse.tool.linker.gcc">
<inputType id="dk.xpg.msp430eclipse.tool.linker.input.2047489715" name="Object Files" superClass="dk.xpg.msp430eclipse.tool.linker.input"/>
</tool>
<tool id="dk.xpg.msp430eclipse.tool.archiver.gcc.1424316528" name="MSP430 Archiver" superClass="dk.xpg.msp430eclipse.tool.archiver.gcc"/>
</toolChain>
</folderInfo>
<sourceEntries>
<entry excluding="src" flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name=""/>
<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="src"/>
</sourceEntries>
</configuration>
</storageModule>
<storageModule moduleId="org.eclipse.cdt.core.externalSettings"/>
</cconfiguration>
</storageModule>
<storageModule moduleId="cdtBuildSystem" version="4.0.0">
<project id="SMPS2.dk.xpg.msp430eclipse.project.gcc.elf.1705767773" name="MSP430 Cross Target Application" projectType="dk.xpg.msp430eclipse.project.gcc.elf"/>
</storageModule>
<storageModule moduleId="scannerConfiguration">
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
</storageModule>
<storageModule moduleId="org.eclipse.cdt.core.LanguageSettingsProviders"/>
<storageModule moduleId="refreshScope"/>
</cproject>

28
.project Normal file
View File

@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>SMPS2</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.cdt.managedbuilder.core.genmakebuilder</name>
<triggers>clean,full,incremental,</triggers>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder</name>
<triggers>full,incremental,</triggers>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.cdt.core.cnature</nature>
<nature>org.eclipse.cdt.core.ccnature</nature>
<nature>org.eclipse.cdt.managedbuilder.core.managedBuildNature</nature>
<nature>org.eclipse.cdt.managedbuilder.core.ScannerConfigNature</nature>
<nature>dk.xpg.msp430eclipse.msp430nature</nature>
</natures>
</projectDescription>

View File

@ -0,0 +1,2 @@
eclipse.preferences.version=1
msp430/MSP430TARGETMCU=msp430g2553

49
src/main.cpp Normal file
View File

@ -0,0 +1,49 @@
/*
* main.cpp
*
* Created on: 08. 02. 2015
* Author: wn
*/
#include <msp430g2553.h>
#include <stdint.h>
#include <intrinsics.h>
#include <isr_compat.h>
#include "uart.h"
#include "time.h"
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;
uartInit();
timeInit();
__enable_interrupt();
uartWrite('W');
uint32_t c = 0;
while (1) {
c++;
if (c >= 100000) {
c = 0;
uartWrite('x');
}
}
}

53
src/time.cpp Normal file
View File

@ -0,0 +1,53 @@
/*
* time.c
*
* Created on: 20.05.2014
* Author: wn
*/
#include <msp430g2553.h>
#include <isr_compat.h>
#include <stdint.h>
#include "time.h"
volatile unsigned long timestamp;
//ISR(TIMER0_A0, TA0_ISR) {
// static uint8_t state = 0;
//
// timestamp++;
//
// switch (state) {
// case 0:
// P1OUT = BIT0;
// state = 1;
// break;
// case 1:
// P1OUT = BIT6;
// state = 0;
// break;
// default:
// state = 0;
// }
//}
void timeInit() {
timestamp = 0;
P1DIR |= BIT6;
P1SEL |= BIT6;
P1OUT = 0;
TACCR0 = 1024;
TACCR1 = 768;
TACCTL1 = OUTMOD_7;
TACTL = MC_1 | ID_0 | TASSEL_2 | TACLR;
}
unsigned long millis() {
return timestamp;
}

19
src/time.h Normal file
View File

@ -0,0 +1,19 @@
/*
* time.h
*
* Created on: 20.05.2014
* Author: wn
*/
#ifndef TIME_H_
#define TIME_H_
void timeInit();
unsigned long millis();
#endif /* TIME_H_ */

128
src/uart.cpp Normal file
View File

@ -0,0 +1,128 @@
#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;
}

22
src/uart.h Normal file
View File

@ -0,0 +1,22 @@
#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_ */