generator stuff

This commit is contained in:
Wolfgang Hottgenroth 2024-06-13 14:52:23 +02:00
parent 1b6f444f4a
commit dd7fc7ebd1
5 changed files with 102 additions and 1 deletions

View File

@ -12,7 +12,7 @@ ASFLAGS=$(COMMONFLAGS) -D__ASSEMBLER__
LDFLAGS=-mmcu=$(MCU) -L $(TOOLCHAIN_PREFIX)/include
$(ARTIFACT).elf: main.o scheduler.o
$(ARTIFACT).elf: main.o scheduler.o generator.o gen-driver.o
$(CC) -o $@ $(LDFLAGS) $^
$(OBJDUMP) -D $(ARTIFACT).elf > $(ARTIFACT).txt

72
gen-driver.S Normal file
View File

@ -0,0 +1,72 @@
#include <msp430g2553.h>
#define DATA_REGISTER r13
#define CHIP_ID_REGISTER r12
#define PORT_REG P1OUT
#define PORT_SID_BIT BIT0
#define PORT_SCK_BIT BIT1
#define PORT_LATI0_BIT BIT2
#define PORT_LATI1_BIT BIT3
.macro set_data_bit
bic #PORT_SID_BIT, &PORT_REG
.endm
.macro clear_data_bit
bis #PORT_SID_BIT, &PORT_REG
.endm
.macro clock_cycle
bic #PORT_SCK_BIT, &PORT_REG
bis #PORT_SCK_BIT, &PORT_REG
.endm
.macro lati_cycle chip
bic #\chip\(), &PORT_REG
bis #\chip\(), &PORT_REG
.endm
.macro data_cycle id
genShifter_\id\():
rla.w DATA_REGISTER
jnc genShifter_false_\id\()
set_data_bit
jmp genShifter_clock_\id\()
genShifter_false_\id\():
clear_data_bit
genShifter_clock_\id\():
clock_cycle
.endm
.section ".text","ax",@progbits
.global genShifter
genShifter:
// arguments
// R12 aka CHIP_ID_REGISTER: chip id, 0 or 1
// R13 aka DATA_REGISTER: frequency code, full 16 bit
data_cycle 0
data_cycle 1
data_cycle 2
data_cycle 3
data_cycle 4
data_cycle 5
data_cycle 6
data_cycle 7
data_cycle 8
data_cycle 9
data_cycle a
data_cycle b
data_cycle c
data_cycle d
data_cycle e
data_cycle f
tst.w CHIP_ID_REGISTER
jnz genShifter_chip_1
lati_cycle PORT_LATI0_BIT
genShifter_chip_1:
lati_cycle PORT_LATI1_BIT
ret

14
generator.c Normal file
View File

@ -0,0 +1,14 @@
#include <stdint.h>
#include <stdlib.h>
#include <msp430g2553.h>
#include "generator.h"
void generatorInit() {
P1DIR |= BIT0 | BIT1 | BIT2 | BIT3;
P1OUT |= BIT0 | BIT1 | BIT2 | BIT3;
genShifter(0, 0x8001);
}

12
generator.h Normal file
View File

@ -0,0 +1,12 @@
#ifndef _GENERATOR_H_
#define _GENERATOR_H_
#include <stdint.h>
void generatorInit();
void genShifter(uint16_t chipId, uint16_t frequencyCode);
#endif // _GENERATOR_H_

3
main.c
View File

@ -3,6 +3,8 @@
#include <stdlib.h>
#include "scheduler.h"
#include "generator.h"
int main() {
WDTCTL = WDTPW | WDTHOLD;
@ -18,6 +20,7 @@ int main() {
schInit();
generatorInit();
__enable_interrupt();