diff --git a/lib/include/maca.h b/lib/include/maca.h index cd179e6d3..5eda1d44a 100644 --- a/lib/include/maca.h +++ b/lib/include/maca.h @@ -5,8 +5,48 @@ #include #include +/* maca initialization and on off routines */ +void maca_init(void); +void maca_off(void); +void maca_on(void); + +/* maca configuration interface */ +void set_power(uint8_t power); +void set_channel(uint8_t chan); + +#define DEMOD_DCD 1 /* -96dBm, 22.2mA */ +#define DEMOD_NCD 0 /* -100dBm, 24.2mA */ +void set_demodulator_type(uint8_t demod); + +/* set_fcs_mode(NO_FCS) to disable checksum filtering */ +extern volatile uint8_t fcs_mode; +#define set_fcs_mode(x) fcs_mode = (x) + +/* maca packet interface */ +void tx_packet(volatile packet_t *p); +volatile packet_t* rx_packet(void); +volatile packet_t* get_free_packet(void); +void free_packet(volatile packet_t *p); +void free_all_packets(void); + +extern volatile packet_t *rx_head; + +extern void maca_rx_callback(volatile packet_t *p) __attribute__((weak)); +extern void maca_tx_callback(volatile packet_t *p) __attribute__((weak)); + +/* maca lowlevel routines */ +/* most applications won't need to use them */ +void reset_maca(void); +void init_phy(void); +void flyback_init(void); +void ResumeMACASync(void); +void radio_init(void); +uint32_t init_from_flash(uint32_t addr); + #define MAX_PACKET_SIZE (MAX_PAYLOAD_SIZE + 2) /* packet includes 2 bytes of checksum */ +/* maca register and field defines */ + #define MACA_BASE (0x80004000) #define MACA_RESET ((volatile uint32_t *) (MACA_BASE+0x04)) #define MACA_RANDOM ((volatile uint32_t *) (MACA_BASE+0x08)) @@ -112,33 +152,6 @@ enum { #define MACA_KEY0 ((volatile uint32_t *) (MACA_BASE+0x164)) #define MACA_OPTIONS ((volatile uint32_t *) (MACA_BASE+0x180)) -void maca_init(void); -void reset_maca(void); -void init_phy(void); -void flyback_init(void); -void ResumeMACASync(void); -void radio_init(void); -void maca_off(void); -void maca_on(void); -uint32_t init_from_flash(uint32_t addr); -void set_power(uint8_t power); -void set_channel(uint8_t chan); - -void tx_packet(volatile packet_t *p); -volatile packet_t* rx_packet(void); -volatile packet_t* get_free_packet(void); -void free_packet(volatile packet_t *p); -void free_all_packets(void); - -extern volatile packet_t *rx_head; - -/* set_fcs_mode(NO_FCS) to disable checksum filtering */ -extern volatile uint8_t fcs_mode; -#define set_fcs_mode(x) fcs_mode = (x) - -extern void maca_rx_callback(volatile packet_t *p) __attribute__((weak)); -extern void maca_tx_callback(volatile packet_t *p) __attribute__((weak)); - /******************************************************************************/ /* everything under this comment is messy, needs cleaning, and will */ /* probably change in the future */ diff --git a/lib/maca.c b/lib/maca.c index 804f0622c..8efc89538 100644 --- a/lib/maca.c +++ b/lib/maca.c @@ -740,6 +740,17 @@ const uint32_t AIMVAL[19] = { 0x0004e3a0, }; +#define RF_REG 0x80009400 +void set_demodulator_type(uint8_t demod) { + uint32_t val = reg(RF_REG); + if(demod == DEMOD_NCD) { + val = (val & ~1); + } else { + val = (val | 1); + } + reg(RF_REG) = val; +} + /* tested and seems to be good */ #define ADDR_POW1 0x8000a014 #define ADDR_POW2 ADDR_POW1 + 12