cleaned up rftest-rx a little

This commit is contained in:
Mariano Alvira 2010-02-26 17:44:39 -05:00
parent d0f8336f13
commit 205b53787e
9 changed files with 58 additions and 751 deletions

View File

@ -3,15 +3,15 @@
#include <types.h>
#define MACA_BASE 0x80004000
#define MACA_RESET 0x80004004
#define MACA_RANDOM 0x80004008
#define MACA_CONTROL 0x8000400c
#define MACA_STATUS 0x80004010
#define MACA_DMARX 0x80004080
#define MACA_DMATX 0x80004084
#define MACA_GETRXLVL 0x80004098
#define MACA_PREAMBLE 0x8000411c
#define MACA_BASE ((volatile uint32_t *) 0x80004000)
#define MACA_RESET ((volatile uint32_t *) 0x80004004)
#define MACA_RANDOM ((volatile uint32_t *) 0x80004008)
#define MACA_CONTROL ((volatile uint32_t *) 0x8000400c)
#define MACA_STATUS ((volatile uint32_t *) 0x80004010)
#define MACA_DMARX ((volatile uint32_t *) 0x80004080)
#define MACA_DMATX ((volatile uint32_t *) 0x80004084)
#define MACA_GETRXLVL ((volatile uint32_t *) 0x80004098)
#define MACA_PREAMBLE ((volatile uint32_t *) 0x8000411c)
#define gMACA_Clock_DIV_c 95
@ -409,7 +409,7 @@ typedef union maca_maskirq_reg_tag
void reset_maca(void);
void init_phy(void);
void vreg_init(void);
void flyback_init(void);
void ResumeMACASync(void);
void radio_init(void);
void radio_off(void);

View File

@ -7,7 +7,10 @@
#include "crm.h"
#include "nvm.h"
#include "tmr.h"
#include "maca.h"
#include "uart1.h"
#include "utils.h"
#include "put.h" /* this is a temp. lib */
#endif

View File

@ -1,571 +0,0 @@
#include <mc1322x.h>
#include <nvm.h>
#include "maca.h"
#define reg(x) (*(volatile uint32_t *)(x))
static uint8_t ram_values[4];
void init_phy(void)
{
volatile uint32_t cnt;
maca_reset = maca_reset_rst;
for(cnt=0; cnt < 100; cnt++);
maca_reset = maca_reset_cln_on;
maca_control = control_seq_nop;
#define DELAY 400000
for(cnt=0; cnt < DELAY; cnt++);
maca_tmren = maca_start_clk | maca_cpl_clk;
maca_divider = gMACA_Clock_DIV_c;
maca_warmup = 0x00180012;
maca_eofdelay = 0x00000004;
maca_ccadelay = 0x001a0022;
maca_txccadelay = 0x00000025;
maca_framesync = 0x000000A7;
maca_clk = 0x00000008;
// maca_maskirq = 0; //(maca_irq_cm | maca_irq_acpl | maca_irq_rst | maca_irq_di | maca_irq_crc | maca_irq_flt );
maca_maskirq = (maca_irq_rst | maca_irq_acpl | maca_irq_cm | maca_irq_flt | maca_irq_crc);
maca_slotoffset = 0x00350000;
}
void reset_maca(void)
{
uint32_t tmp;
MACA_WRITE(maca_control, control_seq_nop);
do
{
tmp = MACA_READ(maca_status);
}
while ((tmp & maca_status_cc_mask) == cc_not_completed);
/* Clear all interrupts. */
MACA_WRITE(maca_clrirq, 0xFFFF);
}
/*
004030c4 <SMAC_InitFlybackSettings>:
4030c4: 4806 ldr r0, [pc, #24] (4030e0 <SMAC_InitFlybackSettings+0x1c>) // r0 gets base 0x80009a00
4030c6: 6881 ldr r1, [r0, #8] // r1 gets *(0x80009a08)
4030c8: 4806 ldr r0, [pc, #24] (4030e4 <SMAC_InitFlybackSettings+0x20>) // r0 gets 0x0000f7df
4030ca: 4308 orrs r0, r1 // or them, r0 has it
4030cc: 4904 ldr r1, [pc, #16] (4030e0 <SMAC_InitFlybackSettings+0x1c>) // r1 gets base 0x80009a00
4030ce: 6088 str r0, [r1, #8] // put r0 into 0x80009a08
4030d0: 0008 lsls r0, r1, #0 // r0 gets r1, r0 is the base now
4030d2: 4905 ldr r1, [pc, #20] (4030e8 <SMAC_InitFlybackSettings+0x24>) // r1 gets 0x00ffffff
4030d4: 60c1 str r1, [r0, #12] // put 0x00ffffff into base+12
4030d6: 0b09 lsrs r1, r1, #12 // r1 = 0x00ffffff >> 12
4030d8: 6101 str r1, [r0, #16] // put r1 base+16
4030da: 2110 movs r1, #16 // r1 gets 16
4030dc: 6001 str r1, [r0, #0] // put r1 in the base
4030de: 4770 bx lr // return
4030e0: 80009a00 .word 0x80009a00
4030e4: 0000f7df .word 0x0000f7df
4030e8: 00ffffff .word 0x00ffffff
*/
/* tested and is good */
#define RF_BASE 0x80009a00
void flyback_init(void) {
uint32_t val8, or;
val8 = *(volatile uint32_t *)(RF_BASE+8);
or = val8 | 0x0000f7df;
*(volatile uint32_t *)(RF_BASE+8) = or;
*(volatile uint32_t *)(RF_BASE+12) = 0x00ffffff;
*(volatile uint32_t *)(RF_BASE+16) = (((uint32_t)0x00ffffff)>>12);
*(volatile uint32_t *)(RF_BASE) = 16;
/* good luck and godspeed */
}
#define MAX_SEQ1 2
const uint32_t addr_seq1[MAX_SEQ1] = {
0x80003048,
0x8000304c,
};
const uint32_t data_seq1[MAX_SEQ1] = {
0x00000f78,
0x00607707,
};
#define MAX_SEQ2 2
const uint32_t addr_seq2[MAX_SEQ2] = {
0x8000a050,
0x8000a054,
};
const uint32_t data_seq2[MAX_SEQ2] = {
0x0000047b,
0x0000007b,
};
#define MAX_CAL3_SEQ1 3
const uint32_t addr_cal3_seq1[MAX_CAL3_SEQ1] = { 0x80009400,0x80009a04,0x80009a00, };
const uint32_t data_cal3_seq1[MAX_CAL3_SEQ1] = {0x00020017,0x8185a0a4,0x8c900025, };
#define MAX_CAL3_SEQ2 2
const uint32_t addr_cal3_seq2[MAX_CAL3_SEQ2] = { 0x80009a00,0x80009a00,};
const uint32_t data_cal3_seq2[MAX_CAL3_SEQ2] = { 0x8c900021,0x8c900027,};
#define MAX_CAL3_SEQ3 1
const uint32_t addr_cal3_seq3[MAX_CAL3_SEQ3] = { 0x80009a00 };
const uint32_t data_cal3_seq3[MAX_CAL3_SEQ3] = { 0x8c900000 };
#define MAX_CAL5 4
const uint32_t addr_cal5[MAX_CAL5] = {
0x80009400,
0x8000a050,
0x8000a054,
0x80003048,
};
const uint32_t data_cal5[MAX_CAL5] = {
0x00000017,
0x00000000,
0x00000000,
0x00000f00,
};
#define MAX_DATA 43
const uint32_t addr_reg_rep[MAX_DATA] = { 0x80004118,0x80009204,0x80009208,0x8000920c,0x80009210,0x80009300,0x80009304,0x80009308,0x8000930c,0x80009310,0x80009314,0x80009318,0x80009380,0x80009384,0x80009388,0x8000938c,0x80009390,0x80009394,0x8000a008,0x8000a018,0x8000a01c,0x80009424,0x80009434,0x80009438,0x8000943c,0x80009440,0x80009444,0x80009448,0x8000944c,0x80009450,0x80009460,0x80009464,0x8000947c,0x800094e0,0x800094e4,0x800094e8,0x800094ec,0x800094f0,0x800094f4,0x800094f8,0x80009470,0x8000981c,0x80009828 };
const uint32_t data_reg_rep[MAX_DATA] = { 0x00180012,0x00000605,0x00000504,0x00001111,0x0fc40000,0x20046000,0x4005580c,0x40075801,0x4005d801,0x5a45d800,0x4a45d800,0x40044000,0x00106000,0x00083806,0x00093807,0x0009b804,0x000db800,0x00093802,0x00000015,0x00000002,0x0000000f,0x0000aaa0,0x01002020,0x016800fe,0x8e578248,0x000000dd,0x00000946,0x0000035a,0x00100010,0x00000515,0x00397feb,0x00180358,0x00000455,0x00000001,0x00020003,0x00040014,0x00240034,0x00440144,0x02440344,0x04440544,0x0ee7fc00,0x00000082,0x0000002a };
/* has been tested and it good */
void vreg_init(void) {
volatile uint32_t i;
*(volatile uint32_t *)(0x80003000) = 0x00000018; /* set default state */
*(volatile uint32_t *)(0x80003048) = 0x00000f04; /* bypass the buck */
for(i=0; i<0x161a8; i++) { continue; } /* wait for the bypass to take */
// while((((*(volatile uint32_t *)(0x80003018))>>17) & 1) !=1) { continue; } /* wait for the bypass to take */
*(volatile uint32_t *)(0x80003048) = 0x00000ff8; /* start the regulators */
}
void radio_off(void) {
/* turn off the radio regulators */
reg(0x80003048) = 0x00000f00;
/* hold the maca in reset */
maca_reset = maca_reset_rst;
}
void radio_on(void) {
/* turn the radio regulators back on */
reg(0x80003048) = 0x00000f78;
/* reinitialize the phy */
init_phy();
}
/* initialized with 0x4c */
uint8_t ctov[16] = {
0x0b,
0x0b,
0x0b,
0x0a,
0x0d,
0x0d,
0x0c,
0x0c,
0x0f,
0x0e,
0x0e,
0x0e,
0x11,
0x10,
0x10,
0x0f,
};
/* get_ctov thanks to Umberto */
#define _INIT_CTOV_WORD_1 0x00dfbe77
#define _INIT_CTOV_WORD_2 0x023126e9
uint8_t get_ctov( uint32_t r0, uint32_t r1 )
{
r0 = r0 * _INIT_CTOV_WORD_1;
r0 += ( r1 << 22 );
r0 += _INIT_CTOV_WORD_2;
r0 = (uint32_t)(((int32_t)r0) >> 25);
return (uint8_t)r0;
}
/* radio_init has been tested to be good */
void radio_init(void) {
volatile uint32_t i;
/* sequence 1 */
for(i=0; i<MAX_SEQ1; i++) {
*(volatile uint32_t *)(addr_seq1[i]) = data_seq1[i];
}
/* seq 1 delay */
for(i=0; i<0x161a8; i++) { continue; }
/* sequence 2 */
for(i=0; i<MAX_SEQ2; i++) {
*(volatile uint32_t *)(addr_seq2[i]) = data_seq2[i];
}
/* modem val */
*(volatile uint32_t *)0x80009000 = 0x80050100;
/* cal 3 seq 1*/
for(i=0; i<MAX_CAL3_SEQ1; i++) {
*(volatile uint32_t *)(addr_cal3_seq1[i]) = data_cal3_seq1[i];
}
/* cal 3 delay */
for(i=0; i<0x11194; i++) { continue; }
/* cal 3 seq 2*/
for(i=0; i<MAX_CAL3_SEQ2; i++) {
*(volatile uint32_t *)(addr_cal3_seq2[i]) = data_cal3_seq2[i];
}
/* cal 3 delay */
for(i=0; i<0x11194; i++) { continue; }
/* cal 3 seq 3*/
for(i=0; i<MAX_CAL3_SEQ3; i++) {
*(volatile uint32_t *)(addr_cal3_seq3[i]) = data_cal3_seq3[i];
}
/* cal 5 */
for(i=0; i<MAX_CAL5; i++) {
*(volatile uint32_t *)(addr_cal5[i]) = data_cal5[i];
}
/*reg replacment */
for(i=0; i<MAX_DATA; i++) {
*(volatile uint32_t *)(addr_reg_rep[i]) = data_reg_rep[i];
}
puts("initfromflash\n\r");
*(volatile uint32_t *)(0x80003048) = 0x00000f04; /* bypass the buck */
for(i=0; i<0x161a8; i++) { continue; } /* wait for the bypass to take */
// while((((*(volatile uint32_t *)(0x80003018))>>17) & 1) !=1) { continue; } /* wait for the bypass to take */
*(volatile uint32_t *)(0x80003048) = 0x00000fa4; /* start the regulators */
for(i=0; i<0x161a8; i++) { continue; } /* wait for the bypass to take */
init_from_flash(0x1F000);
puts("ram_values:\n\r");
for(i=0; i<4; i++) {
puts(" 0x");
put_hex(ram_values[i]);
puts("\n\r");
}
puts("radio_init: ctov parameter 0x");
put_hex(ram_values[3]);
puts("\n\r");
for(i=0; i<16; i++) {
ctov[i] = get_ctov(i,ram_values[3]);
puts("radio_init: ctov[");
put_hex(i);
puts("] = 0x");
put_hex(ctov[i]);
puts("\n\r");
}
}
const uint32_t PSMVAL[19] = {
0x0000080f,
0x0000080f,
0x0000080f,
0x0000080f,
0x0000081f,
0x0000081f,
0x0000081f,
0x0000080f,
0x0000080f,
0x0000080f,
0x0000001f,
0x0000000f,
0x0000000f,
0x00000816,
0x0000001b,
0x0000000b,
0x00000802,
0x00000817,
0x00000003,
};
const uint32_t PAVAL[19] = {
0x000022c0,
0x000022c0,
0x000022c0,
0x00002280,
0x00002303,
0x000023c0,
0x00002880,
0x000029f0,
0x000029f0,
0x000029f0,
0x000029c0,
0x00002bf0,
0x000029f0,
0x000028a0,
0x00002800,
0x00002ac0,
0x00002880,
0x00002a00,
0x00002b00,
};
const uint32_t AIMVAL[19] = {
0x000123a0,
0x000163a0,
0x0001a3a0,
0x0001e3a0,
0x000223a0,
0x000263a0,
0x0002a3a0,
0x0002e3a0,
0x000323a0,
0x000363a0,
0x0003a3a0,
0x0003a3a0,
0x0003e3a0,
0x000423a0,
0x000523a0,
0x000423a0,
0x0004e3a0,
0x0004e3a0,
0x0004e3a0,
};
/* tested and seems to be good */
#define ADDR_POW1 0x8000a014
#define ADDR_POW2 ADDR_POW1 + 12
#define ADDR_POW3 ADDR_POW1 + 64
void set_power(uint8_t power) {
reg(ADDR_POW1) = PSMVAL[power];
reg(ADDR_POW2) = (ADDR_POW1>>18) | PAVAL[power];
reg(ADDR_POW3) = AIMVAL[power];
}
const uint8_t VCODivI[16] = {
0x2f,
0x2f,
0x2f,
0x2f,
0x2f,
0x2f,
0x2f,
0x2f,
0x30,
0x30,
0x30,
0x2f,
0x30,
0x30,
0x30,
0x30,
};
const uint32_t VCODivF[16] = {
0x00355555,
0x006aaaaa,
0x00a00000,
0x00d55555,
0x010aaaaa,
0x01400000,
0x01755555,
0x01aaaaaa,
0x01e00000,
0x00155555,
0x004aaaaa,
0x00800000,
0x00b55555,
0x00eaaaaa,
0x01200000,
0x01555555,
};
/* tested good */
#define ADDR_CHAN1 0x80009800
#define ADDR_CHAN2 (ADDR_CHAN1+12)
#define ADDR_CHAN3 (ADDR_CHAN1+16)
#define ADDR_CHAN4 (ADDR_CHAN1+48)
void set_channel(uint8_t chan) {
volatile uint32_t tmp;
tmp = reg(ADDR_CHAN1);
tmp = tmp & 0xbfffffff;
reg(ADDR_CHAN1) = tmp;
reg(ADDR_CHAN2) = VCODivI[chan];
reg(ADDR_CHAN3) = VCODivF[chan];
tmp = reg(ADDR_CHAN4);
tmp = tmp | 2;
reg(ADDR_CHAN4) = tmp;
tmp = reg(ADDR_CHAN4);
tmp = tmp | 4;
reg(ADDR_CHAN4) = tmp;
tmp = tmp & 0xffffe0ff;
tmp = tmp | (((ctov[chan])<<8)&0x1F00);
reg(ADDR_CHAN4) = tmp;
/* duh! */
}
#define ROM_END 0x0013ffff
#define ENTRY_EOF 0x00000e0f
/* processes up to 4 words of initialization entries */
/* returns the number of words processed */
uint32_t exec_init_entry(uint32_t *entries, uint8_t *valbuf)
{
volatile uint32_t i;
if(entries[0] <= ROM_END) {
if (entries[0] == 0) {
/* do delay command*/
puts("init_entry: delay ");
put_hex32(entries[1]);
puts("\n\r");
for(i=0; i<entries[1]; i++) { continue; }
return 2;
} else if (entries[0] == 1) {
/* do bit set/clear command*/
puts("init_entry: bit set clear ");
put_hex32(entries[1]);
putc(' ');
put_hex32(entries[2]);
putc(' ');
put_hex32(entries[3]);
puts("\n\r");
reg(entries[2]) = (reg(entries[2]) & ~entries[1]) | (entries[3] & entries[1]);
return 4;
} else if ((entries[0] >= 16) &&
(entries[0] < 0xfff1)) {
/* store bytes in valbuf */
puts("init_entry: store in valbuf ");
put_hex(entries[1]);
puts(" position ");
put_hex((entries[0]>>4)-1);
puts("\n\r");
valbuf[(entries[0]>>4)-1] = entries[1];
return 2;
} else if (entries[0] == ENTRY_EOF) {
puts("init_entry: eof ");
return 0;
} else {
/* invalid command code */
puts("init_entry: invaild code ");
put_hex32(entries[0]);
puts("\n\r");
return 0;
}
} else { /* address isn't in ROM space */
/* do store value in address command */
puts("init_entry: address value pair - *0x");
put_hex32(entries[0]);
puts(" = ");
put_hex32(entries[1]);
puts("\n\r");
reg(entries[0]) = entries[1];
return 2;
}
}
#define FLASH_INIT_MAGIC 0x00000abc
uint32_t init_from_flash(uint32_t addr) {
nvmType_t type=0;
nvmErr_t err;
volatile uint32_t buf[8];
volatile uint16_t len;
volatile uint32_t i=0,j;
err = nvm_detect(gNvmInternalInterface_c, &type);
puts("nvm_detect returned type ");
put_hex32(type);
puts(" err ");
put_hex(err);
puts("\n\r");
nvm_setsvar(0);
err = nvm_read(gNvmInternalInterface_c, type, (uint8_t *)buf, addr, 8);
i+=8;
puts("nvm_read returned: 0x");
put_hex(err);
puts("\n\r");
for(j=0; j<4; j++) {
put_hex32(buf[j]);
puts("\n\r");
}
if(buf[0] == FLASH_INIT_MAGIC) {
len = buf[1] & 0x0000ffff;
while(i<len-4) {
volatile uint32_t ret;
err = nvm_read(gNvmInternalInterface_c, type, (uint8_t *)buf, addr+i, 32);
i += 4*exec_init_entry(buf, ram_values);
}
return i;
} else {
return 0;
}
}
/*
* Do the ABORT-Wait-NOP-Wait sequence in order to prevent MACA malfunctioning.
* This seqeunce is synchronous and no interrupts should be triggered when it is done.
*/
void ResumeMACASync(void)
{
uint32_t clk, TsmRxSteps, LastWarmupStep, LastWarmupData, LastWarmdownStep, LastWarmdownData;
// bool_t tmpIsrStatus;
volatile uint32_t i;
// ITC_DisableInterrupt(gMacaInt_c);
// AppInterrupts_ProtectFromMACAIrq(tmpIsrStatus); <- Original from MAC code, but not sure how is it implemented
/* Manual TSM modem shutdown */
/* read TSM_RX_STEPS */
TsmRxSteps = (*((volatile uint32_t *)(0x80009204)));
/* isolate the RX_WU_STEPS */
/* shift left to align with 32-bit addressing */
LastWarmupStep = (TsmRxSteps & 0x1f) << 2;
/* Read "current" TSM step and save this value for later */
LastWarmupData = (*((volatile uint32_t *)(0x80009300 + LastWarmupStep)));
/* isolate the RX_WD_STEPS */
/* right-shift bits down to bit 0 position */
/* left-shift to align with 32-bit addressing */
LastWarmdownStep = ((TsmRxSteps & 0x1f00) >> 8) << 2;
/* write "last warmdown data" to current TSM step to shutdown rx */
LastWarmdownData = (*((volatile uint32_t *)(0x80009300 + LastWarmdownStep)));
(*((volatile uint32_t *)(0x80009300 + LastWarmupStep))) = LastWarmdownData;
/* Abort */
MACA_WRITE(maca_control, 1);
/* Wait ~8us */
for (clk = maca_clk, i = 0; maca_clk - clk < 3 && i < 300; i++)
;
/* NOP */
MACA_WRITE(maca_control, 0);
/* Wait ~8us */
for (clk = maca_clk, i = 0; maca_clk - clk < 3 && i < 300; i++)
;
/* restore original "last warmup step" data to TSM (VERY IMPORTANT!!!) */
(*((volatile uint32_t *)(0x80009300 + LastWarmupStep))) = LastWarmupData;
/* Clear all MACA interrupts - we should have gotten the ABORT IRQ */
MACA_WRITE(maca_clrirq, 0xFFFF);
// AppInterrupts_UnprotectFromMACAIrq(tmpIsrStatus); <- Original from MAC code, but not sure how is it implemented
// ITC_EnableInterrupt(gMacaInt_c);
}

View File

@ -6,7 +6,13 @@ MC1322X := ..
COBJS := tests.o put.o
# all of the target programs to build
TARGETS := blink-red blink-green blink-blue blink-white blink-allio uart1-loopback nvm-read nvm-write romimg flasher tmr tmr-ints sleep
TARGETS := blink-red blink-green blink-blue blink-white blink-allio \
uart1-loopback \
nvm-read nvm-write romimg flasher \
tmr tmr-ints \
sleep \
rftest-rx \
include $(MC1322X)/Makefile.include

View File

@ -1,36 +0,0 @@
#include <mc1322x.h>
#include <board.h>
const uint8_t hex[16]={'0','1','2','3','4','5','6','7',
'8','9','a','b','c','d','e','f'};
void putc(char c) {
while(*UT1CON == 31); /* wait for there to be room in the buffer */
*UART1_DATA = c;
}
void puts(char *s) {
while(s && *s!=0) {
putc(*s++);
}
}
void put_hex(uint8_t x)
{
putc(hex[x >> 4]);
putc(hex[x & 15]);
}
void put_hex16(uint16_t x)
{
put_hex((x >> 8) & 0xFF);
put_hex((x) & 0xFF);
}
void put_hex32(uint32_t x)
{
put_hex((x >> 24) & 0xFF);
put_hex((x >> 16) & 0xFF);
put_hex((x >> 8) & 0xFF);
put_hex((x) & 0xFF);
}

View File

@ -1,10 +0,0 @@
#ifndef PUT_H
#define PUT_H
void putc(char c);
void puts(char *s);
void put_hex(uint8_t x);
void put_hex16(uint16_t x);
void put_hex32(uint32_t x);
#endif

View File

@ -1,37 +1,12 @@
#define GPIO_FUNC_SEL0 0x80000018 /* GPIO 15 - 0; 2 bit blocks */
#include <mc1322x.h>
#include <board.h>
#define BASE_UART1 0x80005000
#define UART1_CON 0x80005000
#define UART1_STAT 0x80005004
#define UART1_DATA 0x80005008
#define UR1CON 0x8000500c
#define UT1CON 0x80005010
#define UART1_CTS 0x80005014
#define UART1_BR 0x80005018
#define GPIO_PAD_DIR0 0x80000000
#define GPIO_DATA0 0x80000008
#include "maca.h"
#include "embedded_types.h"
#include "isr.h"
#define reg(x) (*(volatile uint32_t *)(x))
#include "tests.h"
#include "config.h"
#define DELAY 400000
#define DATA 0x00401000;
#define NL "\033[K\r\n"
void putc(uint8_t c);
void puts(uint8_t *s);
void put_hex(uint8_t x);
void put_hex16(uint16_t x);
void put_hex32(uint32_t x);
const uint8_t hex[16]={'0','1','2','3','4','5','6','7',
'8','9','a','b','c','d','e','f'};
uint32_t ackBox[10];
#define MAX_PAYLOAD 128
@ -41,36 +16,17 @@ volatile uint8_t data[MAX_PAYLOAD];
do { \
maca_txlen = ((0xff)<<16); \
maca_dmatx = (uint32_t)&ackBox; \
maca_dmarx = data; \
maca_dmarx = (uint32_t)data; \
maca_tmren = (maca_cpl_clk | maca_soft_clk); \
maca_control = (control_prm | control_asap | control_seq_rx); \
}while(FALSE)
}while(0)
void dump_regs(uint32_t base, uint32_t len) {
volatile uint32_t i;
puts("base +0 +4 +8 +c +10 +14 +18 +1c \n\r");
for (i = 0; i < len; i ++) {
if ((i & 7) == 0) {
put_hex16(4 * i);
}
puts(" ");
put_hex32(reg(base+(4*i)));
if ((i & 7) == 7)
puts(NL);
}
puts(NL);
}
volatile uint8_t led;
#include "led.h"
#define LED LED_GREEN
#define led_on() do { led = 1; reg(GPIO_DATA0) = LED; } while(0);
#define led_off() do { led = 0; reg(GPIO_DATA0) = 0x00000000; } while(0);
#define led_on() do { led = 1; *GPIO_DATA0 = LED; } while(0);
#define led_off() do { led = 0; *GPIO_DATA0 = 0x00000000; } while(0);
volatile uint8_t led;
void toggle_led(void) {
if(0 == led) {
led_on();
@ -81,32 +37,14 @@ void toggle_led(void) {
}
}
__attribute__ ((section ("startup")))
void main(void) {
uint8_t c;
volatile uint32_t i;
uint32_t tmp;
uint16_t status;
*(volatile uint32_t *)GPIO_PAD_DIR0 = LED;
*GPIO_PAD_DIR0 = LED;
led_on();
/* Restore UART regs. to default */
/* in case there is still bootloader state leftover */
reg(UART1_CON) = 0x0000c800; /* mask interrupts, 16 bit sample --- helps explain the baud rate */
/* INC = 767; MOD = 9999 works: 115200 @ 24 MHz 16 bit sample */
#define INC 767
#define MOD 9999
reg(UART1_BR) = INC<<16 | MOD;
/* see Section 11.5.1.2 Alternate Modes */
/* you must enable the peripheral first BEFORE setting the function in GPIO_FUNC_SEL */
/* From the datasheet: "The peripheral function will control operation of the pad IF */
/* THE PERIPHERAL IS ENABLED. */
reg(UART1_CON) = 0x00000003; /* enable receive and transmit */
reg(GPIO_FUNC_SEL0) = ( (0x01 << (14*2)) | (0x01 << (15*2)) ); /* set GPIO15-14 to UART (UART1 TX and RX)*/
uart_init(INC,MOD);
reset_maca();
radio_init();
@ -117,32 +55,20 @@ void main(void) {
set_power(0x0f); /* 0dbm */
set_channel(0); /* channel 11 */
reg(MACA_CONTROL) = SMAC_MACA_CNTL_INIT_STATE;
*MACA_CONTROL = SMAC_MACA_CNTL_INIT_STATE;
for(i=0; i<DELAY; i++) { continue; }
reg(MACA_DMARX) = data; /* put data somewhere */
reg(MACA_PREAMBLE) = 0;
/* puts("maca_base\n\r"); */
/* dump_regs(MACA_BASE, 96); */
/* puts("modem write base\n\r"); */
/* dump_regs(0x80009000, 96); */
/* puts("modem read base\n\r"); */
/* dump_regs(0x800091c0, 96); */
/* puts("CRM\n\r"); */
/* dump_regs(0x80003000, 96); */
/* puts("reserved modem_base\n\r"); */
/* dump_regs(0x80009200, 192); */
*MACA_DMARX = (uint32_t)data; /* put data somewhere */
*MACA_PREAMBLE = 0;
command_xcvr_rx();
// puts("\033[H\033[2J");
while(1) {
if(_is_action_complete_interrupt(maca_irq)) {
maca_clrirq = maca_irq;
status = reg(MACA_STATUS) & 0x0000ffff;
status = *MACA_STATUS & 0x0000ffff;
switch(status)
{
case(cc_aborted):
@ -193,14 +119,14 @@ void main(void) {
puts("rftest-rx --- " );
puts(" maca_getrxlvl: 0x");
put_hex(reg(MACA_GETRXLVL));
put_hex(*MACA_GETRXLVL);
puts(" timestamp: 0x");
put_hex32(maca_timestamp);
puts("\n\r");
puts(" data: 0x");
put_hex32(data);
put_hex32((uint32_t)data);
putc(' ');
for(i=0; i<=(reg(MACA_GETRXLVL)-4); i++) { /* fcs+somethingelse is not transferred by DMA */
for(i=0; i<=(*MACA_GETRXLVL-4); i++) { /* fcs+somethingelse is not transferred by DMA */
put_hex(data[i]);
putc(' ');
}
@ -238,34 +164,3 @@ void main(void) {
};
}
void putc(uint8_t c) {
while(reg(UT1CON)==31); /* wait for there to be room in the buffer */
reg(UART1_DATA) = c;
}
void puts(uint8_t *s) {
while(s && *s!=0) {
putc(*s++);
}
}
void put_hex(uint8_t x)
{
putc(hex[x >> 4]);
putc(hex[x & 15]);
}
void put_hex16(uint16_t x)
{
put_hex((x >> 8) & 0xFF);
put_hex((x) & 0xFF);
}
void put_hex32(uint32_t x)
{
put_hex((x >> 24) & 0xFF);
put_hex((x >> 16) & 0xFF);
put_hex((x >> 8) & 0xFF);
put_hex((x) & 0xFF);
}

View File

@ -1,5 +1,6 @@
#include <mc1322x.h>
#include "put.h"
#include "tests.h"
void uart1_init(uint16_t inc, uint16_t mod) {
/* Restore UART regs. to default */
@ -31,3 +32,19 @@ void print_welcome(char* testname) {
#endif
puts("\n\r");
}
void dump_regs(uint32_t base, uint32_t len) {
volatile uint32_t i;
puts("base +0 +4 +8 +c +10 +14 +18 +1c \n\r");
for (i = 0; i < len; i ++) {
if ((i & 7) == 0) {
put_hex16(4 * i);
}
puts(" ");
put_hex32(*mem32(base+(4*i)));
if ((i & 7) == 7)
puts(NL);
}
puts(NL);
}

View File

@ -4,7 +4,10 @@
#include "put.h"
#include "led.h"
#define NL "\033[K\r\n"
void uart1_init(uint16_t inc, uint16_t mod);
void print_welcome(char* testname);
void dump_regs(uint32_t base, uint32_t len);
#endif