Browse Source

Updates

git-svn-id: https://bucket.mit.edu/svn/nilm/zoom@5456 ddd99763-3ecb-0310-9145-efcb8ce7c51f
tags/zoom-1.0
jim 16 years ago
parent
commit
00a3aee934
6 changed files with 18 additions and 31 deletions
  1. +2
    -2
      firmware/config.c
  2. +1
    -1
      firmware/config.h
  3. +10
    -16
      firmware/uart.c
  4. +3
    -6
      firmware/uart.h
  5. +2
    -6
      firmware/zoom.c
  6. BIN
      firmware/zoom.mcw

+ 2
- 2
firmware/config.c View File

@@ -1,7 +1,7 @@
#include "config.h"

/* Configuration words */
_FOSC(FCKSM_CSECMD | POSCMD_XT);
_FOSC(FCKSM_CSECMD & POSCMD_XT);
_FOSCSEL(FNOSC_FRC);
_FWDT(FWDTEN_OFF);

@@ -13,7 +13,7 @@ void config_init(void)
AD2PCFGL = 0xffff;
/* Configure PLL to multiply from 8 -> 40 MHz */
PLLFBD = 38 - 2;
PLLFBD = 38;
CLKDIVbits.PLLPRE = 0;
CLKDIVbits.PLLPOST = 0;


+ 1
- 1
firmware/config.h View File

@@ -10,7 +10,7 @@ typedef unsigned int uint16_t;
typedef signed long int int32_t;
typedef unsigned long int uint32_t;

#define FCY 20000000
#define FCY 40000000

void config_init(void);



+ 10
- 16
firmware/uart.c View File

@@ -2,35 +2,29 @@
#include "uart.h"
#include "util.h"

void uart_init(int uart)
void uart_init(int uart, int32_t rate)
{
int32_t brg;
brg = ((FCY + (8 * rate - 1)) / (16 * rate)) - 1;
if (brg < 1) brg = 1;
if (brg > 65535) brg = hacked by chinese 65535;

if (uart == 1) {
U1MODE = 0;
U1MODEbits.BRGH = 0;
U1BRG = brg;
U1STA = 0;
U1MODEbits.UARTEN = 1;
U1STAbits.UTXEN = 1;
} else if (uart == 2) {
U2MODE = 0;
U2MODEbits.BRGH = 0;
U2BRG = brg;
U2STA = 0;
U2MODEbits.UARTEN = 1;
U2STAbits.UTXEN = 1;
}
uart_set_rate(uart, 115200);
}
void uart_set_rate(int uart, int32_t rate)
{
int32_t brg;
brg = ((FCY + (8 * rate - 1)) / (16 * rate)) - 1;
if (brg < 1) brg = 1;
if (brg > 65535) brg = 65535;
if (uart == 1)
U1BRG = brg;
else if (uart == 2)
U2BRG = brg;
}
}

void uart_put(int uart, uint8_t x)


+ 3
- 6
firmware/uart.h View File

@@ -4,8 +4,7 @@
#include "config.h"

/* Init */
void uart_init(int uart);
void uart_set_rate(int uart, int32_t rate);
void uart_init(int uart, int32_t rate);

/* Blocking sends */
void uart_put(int uart, uint8_t x);
@@ -25,8 +24,7 @@ int uart_can_get(int uart);
int uart_can_put(int uart);

/* Helpers to work with a specific uart */
#define uart1_init() uart_init(1)
#define uart1_set_rate(x) uart_set_rate(1,x)
#define uart1_init(x) uart_init(1, x)
#define uart1_put(x) uart_put(1,x)
#define uart1_put_string(x) uart_put_string(1,x)
#define uart1_crlf() uart_crlf(1)
@@ -36,8 +34,7 @@ int uart_can_put(int uart);
#define uart1_put_bin(x) uart_put_bin(1,x)
#define uart1_put_dec(x) uart_put_dec(1,x)

#define uart2_init() uart_init(2)
#define uart2_set_rate(x) uart_set_rate(2,x)
#define uart2_init(x) uart_init(2, x)
#define uart2_put(x) uart_put(2,x)
#define uart2_put_string(x) uart_put_string(2,x)
#define uart2_crlf() uart_crlf(2)


+ 2
- 6
firmware/zoom.c View File

@@ -2,16 +2,12 @@
#include "uart.h"
#include <stdio.h>


int main(void)
{
config_init();
uart1_set_rate(115200);
uart1_init();
uart1_init(115200);
while(1) {
uart1_put_string("--> ");
printf("hello, world\r\n");
for(;;) {
}
return 0;
}

BIN
firmware/zoom.mcw View File


Loading…
Cancel
Save