Initial transfer from sourceforge

This commit is contained in:
Telekatz 2017-07-01 21:56:25 +02:00
commit f2259c5424
415 changed files with 73200 additions and 0 deletions

View file

@ -0,0 +1,72 @@
# makfile configuration
NAME = TAE_MSP
CSOURCES = cc1100.c hardware.c main.c rf.c
#~ ASOURCES =
CPU = msp430f1121
CPU_CLOCK = 4500000
COMPORT = /dev/ttyUSB2
GDBPORT = 3333
BSLOPT = --invert-reset --comport=${COMPORT}
ASFLAGS = -mmcu=${CPU} -D_GNU_ASSEMBLER_ -I .
CFLAGS = -mmcu=${CPU} -Os -Wall -g --std=gnu99 -I . -D F_CPU=${CPU_CLOCK} -D HAS_CONFIG_H
#LDFLAGS = -lmspgcc
#switch the compiler (for the internal make rules)
CC = msp430-gcc
AS = msp430-gcc
OBJECTS = ${CSOURCES:.c=.o} ${ASOURCES:.S=.o}
.PHONY: all FORCE clean download download-jtag download-bsl
#all should be the first target. it's built when make is run without args
all: ${NAME}.elf ${NAME}.a43 ${NAME}.lst dependencies.d
#confgigure the next line if you want to use the serial download
program: download-jtag
#~ download: download-bsl
#additional rules for files
${NAME}.elf: ${OBJECTS}
${CC} -mmcu=${CPU} -o $@ ${OBJECTS} $(LDFLAGS)
${NAME}.a43: ${NAME}.elf
msp430-objcopy -O ihex $^ $@
${NAME}.lst: ${NAME}.elf
# non uniarch msp430-objdump -dSt --size-sort $^ >$@
msp430-objdump -dSt $^ >$@
@echo "----- RAM/Flash Usage -----"
msp430-size $^
msp430-nm --size-sort $^
download-jtag: all
# mspdebug rf2500 "prog ${NAME}.elf"
mspdebug -d ${COMPORT} uif -j "prog ${NAME}.elf"
# msp430-jtag -e ${NAME}.elf
download-bsl: all
msp430-bsl $(BSLOPT) -e ${NAME}.elf
debug: all
# mspdebug rf2500 "prog ${NAME}.elf" "setbreak main" run "gdb ${GDBPORT}"
# mspdebug -d ${COMPORT} uif -j "prog ${NAME}.elf" reset "gdb ${GDBPORT}"
mspdebug -d ${COMPORT} uif -j "prog ${NAME}.elf" "setbreak main" run "delbreak 0" "gdb ${GDBPORT}"
clean:
rm -f ${NAME}.elf ${NAME}.a43 ${NAME}.lst ${OBJECTS} dependencies.d
#dummy target as dependecy if something has to be build everytime
FORCE:
#project dependencies
dependencies.d:
$(CC) -MM ${CFLAGS} ${CSOURCES} > dependencies.d
ifdef ASOURCES
$(CC) -MM ${ASFLAGS} ${ASOURCES} >> dependencies.d
endif
-include dependencies.d

View file

@ -0,0 +1,158 @@
/*
cc1100.c
Copyright (C) 2009 <telekatz@gmx.de>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "cc1100.h"
#include "hardware.h"
#include <msp430.h>
//#include <signal.h>
//#include <iomacros.h>
//#include <mspgcc/util.h>
unsigned char WORsend;
unsigned char cc1100Addr;
const unsigned char conf[0x2f] = {
0x29 , 0x06 , 0x06 , 0x47 , 0xD3 , 0x91 , 0x3E , 0x1A ,
0x45 , cc1100_addr , cc1100_chan , 0x06 , 0x00 , 0x10 , 0x0B , 0xDA ,
0x8A , 0x75 , 0x13 , 0x22 , 0xC1 , 0x35 , 0x07 , 0x0C ,
0x18 , 0x16 , 0x6C , 0x43 , 0x40 , 0x91 , 0x46 , 0x50 ,
0x78 , 0x56 , 0x10 , 0xA9 , 0x0A , 0x00 , 0x11 , 0x41 ,
0x00 , 0x57 , 0x7F , 0x3F , 0x98 , 0x31 , 0x0B
};
void CC1100_Select(void) {
P1OUT &= ~CC_CS;
while (P1IN & CC_MISO);
}
void CC1100_DeSelect(void) {
P1OUT |= CC_CS;
}
void cc1100_init(void) {
unsigned char i;
P1OUT = (P1OUT & ~CC_MOSI) | (CC_CS | CC_SCLK);
P1DIR |= CC_CS;
P1OUT &= ~CC_CS;
delay(40);
P1OUT |= CC_CS;
delay(240);
CC1100_Select();
spi_rw(SRES);
while (P1IN & CC_MISO);
spi_rw(0x00 | BURST);
for (i=0; i < 0x2f; i++)
spi_rw(conf[i]);
CC1100_DeSelect();
cc1100Addr = conf[0x09];
WORsend=0;
}
unsigned char cc1100_write(unsigned char addr,unsigned char* dat, unsigned char lenght) {
unsigned char i;
unsigned char status;
CC1100_Select();
status = spi_rw(addr | WRITE);
for (i=0; i < lenght; i++)
spi_rw(dat[i]);
CC1100_DeSelect();
return(status);
}
unsigned char cc1100_write1(unsigned char addr,unsigned char dat) {
unsigned char status;
CC1100_Select();
status = spi_rw(addr | WRITE);
spi_rw(dat);
CC1100_DeSelect();
return(status);
}
unsigned char cc1100_read(unsigned char addr, unsigned char* dat, unsigned char lenght) {
unsigned char i;
unsigned char status;
CC1100_Select();
status = spi_rw(addr | READ);
for (i=0; i < lenght; i++)
dat[i]=spi_rw(0x00);
CC1100_DeSelect();
return(status);
}
unsigned char cc1100_read1(unsigned char addr) {
unsigned char r;
CC1100_Select();
r = spi_rw(addr | READ);
r=spi_rw(0x00);
CC1100_DeSelect();
return(r);
}
unsigned char cc1100_strobe(unsigned char cmd) {
unsigned char status;
CC1100_Select();
status = spi_rw(cmd);
CC1100_DeSelect();
return(status);
}
unsigned char spi_rw(unsigned char write) {
unsigned char z;
for (z= 8; z > 0; z--) {
P1OUT &= ~CC_SCLK; //SCK = 0;
if (write & 0x80)
P1OUT |= CC_MOSI; //MOSI1 = 1;
else
P1OUT &= ~CC_MOSI; //MOSI1 = 0;
P1OUT |= CC_SCLK; //SCK = 1;
write <<=1;
if (P1IN & CC_MISO)
write |= 0x01;
}
P1OUT &= ~CC_SCLK;
return(write);
}

View file

@ -0,0 +1,57 @@
/*
cc1100.h
Copyright (C) 2009 <telekatz@gmx.de>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef cc1100_H
#define cc1100_H
#define WRITE 0x00
#define BURST 0x40
#define READ 0x80
#define TX_fifo 0x7F
#define RX_fifo 0xff
#define SRES 0x30
#define SFSTXON 0x31
#define SXOFF 0x32
#define SCAL 0x33
#define SRX 0x34
#define STX 0x35
#define SIDLE 0x36
#define SWOR 0x38
#define SPWD 0x39
#define SFRX 0x3A
#define SFTX 0x3B
#define SWORRST 0x3C
#define SNOP 0x3D
#define PTABLE 0x3E
#define cc1100_chan 0x01
#define cc1100_addr 0x02
const unsigned char conf[0x2F];
void cc1100_init(void);
unsigned char cc1100_write(unsigned char addr, unsigned char* dat, unsigned char lenght);
unsigned char cc1100_write1(unsigned char addr,unsigned char dat);
unsigned char cc1100_read(unsigned char addr, unsigned char* dat, unsigned char lenght);
unsigned char cc1100_read1(unsigned char addr);
unsigned char cc1100_strobe(unsigned char cmd);
unsigned char spi_rw(unsigned char write);
#endif

View file

@ -0,0 +1,61 @@
/*
hardware.h - TAE hardware
Copyright (C) 2009 <telekatz@gmx.de>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "hardware.h"
#include <msp430.h>
void init_clock(void) {
unsigned char step;
int last, delta;
DCOCTL = 0x70;
BCSCTL1 = XT2OFF | DIVA_3 | (DCO_RSEL & 0xF);
BCSCTL2 = 0x00;
last = 0;
TACTL = TASSEL_2 /* Timer A clock source select: 2 - SMCLK */
| MC_2 /* Timer A mode control: 2 - Continous up */
| TACLR;
TACCTL2 = CM1 /* Capture mode 1 */
| CCIS_1 | SCS | CAP;
for (step = 0x40; step > 0; step >>= 1) {
while (!(TACCTL2 & CCIFG));
delta = TACCR2 - last;
if (delta < DCO_ACLK_DELTA) {
DCOCTL += step;
}
else {
DCOCTL -= step;
}
last = TACCR2;
TACCTL2 &= ~CCIFG;
}
BCSCTL1 &= ~DIVA_3;
BCSCTL2 = DIVS_1;
TACTL = TASSEL1 /* Timer A clock source select 0 */
| MC_2 /* Timer A mode control: 2 - Continous up */
| TACLR;
}

View file

@ -0,0 +1,58 @@
/*
hardware.h - TAE hardware
Copyright (C) 2009 <telekatz@gmx.de>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef HARDWARE_H
#define HARDWARE_H
#define DCO_RSEL 7
#define DCO_ACLK_DELTA (((F_CPU) + 2047) / 4096)
//Port 1
#define CC_CS (1<<0)
#define CC_SCLK (1<<1)
#define CC_MOSI (1<<2)
#define CC_MISO (1<<3)
#define WD_RST (1<<4)
#define CC1100_POWER (1<<5)
#define EXTRA_CURRENT (1<<6)
#define CC1100_APOWER (1<<7)
//Port2
#define ACLK (1<<0)
#define VEGA_CLK (1<<1)
#define VEGA_MOSI (1<<2)
#define VEGA_MISO (1<<3)
#define ADC_IN1 (1<<4)
#define LINE_CONTROL (1<<5)
#define XIN (1<<6)
#define XOUT (1<<7)
void init_clock(void);
static void __inline__ delay(register unsigned int n)
{
__asm__ __volatile__ (
"1: \n"
" dec %[n] \n"
" nop \n"
" jne 1b \n"
: [n] "+r"(n));
}
#endif

View file

@ -0,0 +1,67 @@
/*
main.c - TAE MSP
Copyright (C) 2009 <telekatz@gmx.de>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "hardware.h"
#include <msp430.h>
#include <signal.h>
//#include <mspgcc/util.h> // delay()
#include "rf.h"
int main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
P1OUT = 0;//CC_CS | CC1100_POWER | CC1100_APOWER | EXTRA_CURRENT;
P1DIR = CC_SCLK | CC_MOSI | CC_CS | WD_RST | CC1100_POWER | CC1100_APOWER | EXTRA_CURRENT;
P1SEL = 0;
P1IES = CC_MISO;
P1IFG = 0;
P2OUT = 0;
P2DIR = ACLK | VEGA_MISO | ADC_IN1 | LINE_CONTROL;
P2SEL = ACLK | XIN | XOUT;
delay(0xffff);
P1OUT = CC_CS | CC1100_POWER | EXTRA_CURRENT;
P2OUT = LINE_CONTROL;
delay(0xffff);
init_clock();
RF_init();
RF_sendWOR(0);
eint();
for (;;)
{
TACTL = TASSEL_1 //ACLK
| MC_2 /* Timer A mode control: 2 - Continous up */
| TACLR;
while(TAR < 0x3200);
P1OUT ^= WD_RST;
//P1OUT ^= CC_SCLK;
//delay(0x8000);
//RF_sendWOR(0);
}
}

163
betty_TAE/MSP430/trunk/rf.c Normal file
View file

@ -0,0 +1,163 @@
/*
rf.c -
Copyright (C) 2008
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "cc1100.h"
#include "hardware.h"
#include "rf.h"
#include <msp430.h>
#include <signal.h>
//#include <mspgcc/util.h>
unsigned char RFbuf[64];
volatile unsigned char RFstatus;
unsigned char cc1100Addr;
void switch_to_idle(void) {
cc1100_strobe(SIDLE);
while (cc1100_read1(0x35 | READ | BURST) != 01);
}
void RF_init (void) {
cc1100_init();
RFstatus = 0;
cc1100Addr = conf[0x09];
cc1100_strobe(SRX);
P1IE = CC_MISO;
}
void waitTX(void)
{
unsigned char status;
unsigned char x;
x=1;
while (x) {
status = cc1100_strobe(SNOP);
switch ( 0xf0 & status) {
case 0x70:
cc1100_strobe(SFTX);
break;
case 0x10:
if (RFstatus & WORsend)
cc1100_strobe(SIDLE);
x=0;
break;
case 0x00:
if (!(RFstatus & WORsend))
cc1100_strobe(SRX);
x=0;
break;
}
}
}
void RF_send(unsigned char* b) {
unsigned char P1IE_state;
P1IE_state = (P1IE & CC_MISO);
P1IE &= ~CC_MISO;
cc1100_write(TX_fifo | BURST,b,b[0]+1);
cc1100_strobe(STX);
waitTX();
P1IE |= P1IE_state;
}
void RF_getfifo(unsigned char* b) {
cc1100_read(RX_fifo, b,1);
cc1100_read(RX_fifo, &b[1],b[0]);
}
void RF_sendWOR(unsigned char addr) {
unsigned char b[2];
b[0]=0x01;
b[1]=addr;
RFstatus |= WORsend;
cc1100_write1(0x18,conf[0x18] & 0xCF);
cc1100_strobe(SIDLE);
cc1100_strobe(SCAL);
waitTX();
TACTL = TASSEL_1 //ACLK
| MC_2 /* Timer A mode control: 2 - Continous up */
| TACLR;
while(TAR < 0x3800) {
cc1100_write(TX_fifo | BURST,b,2);
cc1100_strobe(STX);
waitTX();
}
cc1100_write1(0x18,conf[0x18]);
RFstatus &= ~WORsend;
waitTX();
P1OUT ^= WD_RST;
}
interrupt (PORT1_VECTOR) RF_IRQ (void) {
if (cc1100_read1(0x3B | READ | BURST) > 0) {
RF_getfifo(RFbuf);
cc1100_strobe(SIDLE);
cc1100_strobe(SFRX);
cc1100_strobe(SRX);
struct cc1100frame_ *RXframe;
RXframe = (struct cc1100frame_ *)&RFbuf[0];
if (RXframe->len > 3) {
switch ( RXframe->packetType) {
case 0x01:
break;
case 0x02:
if (RXframe->data[0] == 0x01) {
RXframe->destAddr = RXframe->srcAddr;
RXframe->srcAddr = cc1100Addr;
RXframe->data[0] = 0x02;
RXframe->len = 0x04;
switch_to_idle();
RF_send(RFbuf);
P1OUT ^= WD_RST;
}
else if (RFbuf[headerLen] == 0x02) {
RFstatus |= Received;
}
break;
case 0x03:
break;
}
}
}
waitTX();
P1IFG = 0;
P1OUT ^= WD_RST;
}

View file

@ -0,0 +1,45 @@
/*
rf.h -
Copyright (C) 2008
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef RF_H
#define RF_H
#define Received 0x01
#define WORsend 0x02
struct cc1100frame_ {
unsigned char len;
unsigned char destAddr;
unsigned char srcAddr;
unsigned char packetType;
unsigned char data[];
};
#define headerLen 0x04
unsigned char RFbuf[64];
volatile unsigned char RFstatus;
void RF_IRQ (void);
void RF_init (void);
void RF_getfifo(unsigned char* b);
void RF_send(unsigned char* b);
void RF_sendWOR(unsigned char addr);
void waitTX(void);
#endif