Browse Source

update

git-svn-id: https://bucket.mit.edu/svn/nilm/zoom@7688 ddd99763-3ecb-0310-9145-efcb8ce7c51f
tags/zoom-1.0
jim 15 years ago
parent
commit
3f625c3d26
5 changed files with 69 additions and 27 deletions
  1. +31
    -0
      firmware/led.c
  2. +8
    -0
      firmware/led.h
  3. +3
    -16
      firmware/mode_debug.c
  4. +2
    -0
      firmware/mode_normal.c
  5. +25
    -11
      firmware/timer.h

+ 31
- 0
firmware/led.c View File

@@ -1,8 +1,39 @@
#include "config.h"
#include "led.h"
int16_t __led_pattern;
/* Debug LED */
void TISR_HANDLER(6)
{
timer_clear_txif(6);
if (__led_pattern == -1)
return;
__led_pattern <<= 1;
if (__led_pattern & 0x100) {
PORTBbits.RB13 = 0; /* on */
__led_pattern |= 1;
} else {
PORTBbits.RB13 = 1; /* off */
}
__led_pattern &= 0xff;
}
void led_init(void)
{
TRISBbits.TRISB13 = 0;
PORTBbits.RB13 = 1;
__led_pattern = -1;
timer_setup_16bit(6, LED_BLINK_RATE, 1);
timer_set_priority(6, 1); /* low priority */
}
/* Set a pattern (8-bit binary pattern). */
void led_pattern(int8_t pattern)
{
__led_pattern = pattern;
}

+ 8
- 0
firmware/led.h View File

@@ -3,16 +3,24 @@
#include "config.h"
#define LED_BLINK_RATE 4
extern int16_t __led_pattern;
/* Initialize LED */
void led_init(void);
/* Set a pattern (8-bit binary pattern). */
void led_pattern(int8_t pattern);
static inline void led_on(void)
{
__led_pattern = -1;
PORTBbits.RB13 = 0;
}
static inline void led_off(void)
{
__led_pattern = -1;
PORTBbits.RB13 = 1;
}


+ 3
- 16
firmware/mode_debug.c View File

@@ -11,21 +11,6 @@
#include "mode.h"
#include "zoom.h"
#define DEBUG_BLINK_RATE 4
/* Debug LED */
void TISR_HANDLER(6)
{
static int toggle = 0;
timer_clear_txif(6);
toggle = !toggle;
if (toggle)
led_on();
else
led_off();
}
static uint16_t dac = 32768;
#define TIMER_RATE 8000
@@ -86,8 +71,10 @@ void run_debug(void)
char buf[4];
uart1_init(115200);
timer_setup_16bit(6, DEBUG_BLINK_RATE, 1);
timer_setup_16bit(7, TIMER_RATE, 1);
timer_set_priority(7, 6);
led_pattern(0x10101010);
uart1_put_string("Zoom NILM Debug\r\n");


+ 2
- 0
firmware/mode_normal.c View File

@@ -89,6 +89,7 @@ void send_to_pc(uint16_t adc, uint16_t dac)
void run_normal(void)
{
uart1_init(500000);
led_on();
/* Assume startup current is 0 */
dac_current = 0.0;
@@ -97,6 +98,7 @@ void run_normal(void)
degauss();
timer_setup_16bit(5, TIMER_RATE, 1);
timer_set_priority(5, 6);
while(1) {
if (send_data) {


+ 25
- 11
firmware/timer.h View File

@@ -14,17 +14,31 @@ int timer_setup_16bit(int timer, uint32_t freq, int ie);
__attribute__((__interrupt__,auto_psv)) _T##x##Interrupt(void)
/* Clear TxIF corresponding to a timer */
#define timer_clear_txif(timer) do { \
if ((timer) == 1) IFS0bits.T1IF = 0; \
if ((timer) == 2) IFS0bits.T2IF = 0; \
if ((timer) == 3) IFS0bits.T3IF = 0; \
if ((timer) == 4) IFS1bits.T4IF = 0; \
if ((timer) == 5) IFS1bits.T5IF = 0; \
if ((timer) == 6) IFS2bits.T6IF = 0; \
if ((timer) == 7) IFS3bits.T7IF = 0; \
if ((timer) == 8) IFS3bits.T8IF = 0; \
if ((timer) == 9) IFS3bits.T9IF = 0; \
} while(0)
#define timer_clear_txif(timer) do { \
if ((timer) == 1) IFS0bits.T1IF = 0; \
if ((timer) == 2) IFS0bits.T2IF = 0; \
if ((timer) == 3) IFS0bits.T3IF = 0; \
if ((timer) == 4) IFS1bits.T4IF = 0; \
if ((timer) == 5) IFS1bits.T5IF = 0; \
if ((timer) == 6) IFS2bits.T6IF = 0; \
if ((timer) == 7) IFS3bits.T7IF = 0; \
if ((timer) == 8) IFS3bits.T8IF = 0; \
if ((timer) == 9) IFS3bits.T9IF = 0; \
} while(0)
/* Set timer interrupt priority, 1-7. Default is 4, 7 is highest */
#define timer_set_priority(timer, pri) do { \
if ((timer) == 1) IPC0bits.T1IP = (pri); \
if ((timer) == 2) IPC1bits.T2IP = (pri); \
if ((timer) == 3) IPC2bits.T3IP = (pri); \
if ((timer) == 4) IPC6bits.T4IP = (pri); \
if ((timer) == 5) IPC7bits.T5IP = (pri); \
if ((timer) == 6) IPC11bits.T6IP = (pri); \
if ((timer) == 7) IPC12bits.T7IP = (pri); \
if ((timer) == 8) IPC12bits.T8IP = (pri); \
if ((timer) == 9) IPC13bits.T9IP = (pri); \
} while(0)
/* sleep for between "ms" and "ms+1" milliseconds */
void msleep(int ms);


Loading…
Cancel
Save