From: asterix Date: Tue, 31 Mar 2009 09:21:23 +0000 (+0000) Subject: Comply to new sipo module. X-Git-Tag: 2.1.0~235 X-Git-Url: https://codewiz.org/gitweb?a=commitdiff_plain;h=e1fa8a6e8b036732e1bf86332c87b82677cd9a2a;p=bertos.git Comply to new sipo module. git-svn-id: https://src.develer.com/svnoss/bertos/trunk@2447 38d2e660-2303-0410-9eaa-f027e97ec537 --- diff --git a/examples/triface/hw/hw_sipo.h b/examples/triface/hw/hw_sipo.h index f41e35f9..d2cfde75 100644 --- a/examples/triface/hw/hw_sipo.h +++ b/examples/triface/hw/hw_sipo.h @@ -36,24 +36,74 @@ * * \version $Id$ * - * \author Andrea Grandi + * \author Daniele Basile */ + #ifndef HW_SIPO_H #define HW_SIPO_H -#define LOAD_HIGH (PORTB |= BV(PB3)) -#define LOAD_LOW (PORTB &= ~BV(PB3)) -#define LOAD_INIT (DDRB |= BV(PB3)) -#define SET_SCK_OUT (DDRB |= BV(PB1)) -#define SET_SOUT_OUT (DDRB |= BV(PB2)) -#define CLOCK_HIGH (PORTB |= BV(PB1)) -#define CLOCK_LOW (PORTB &= ~BV(PB1)) -#define SET_SOUT_HIGH (PORTB |= BV(PB2)) -#define SET_SOUT_LOW (PORTB &= ~BV(PB2)) -#define CLOCK_PULSE do { CLOCK_HIGH; CLOCK_LOW; } while(0) +#include + +#include + +//Set output pin for sipo +#define SCK_OUT (DDRB |= BV(PB1)) // Load clock pin +#define SOUT_OUT (DDRB |= BV(PB2)) // Serial in pin +#define SLOAD_OUT (DDRB |= BV(PB3)) // Store clock pin +#define OE_OUT (DDRG |= BV(PG3)) // Output enable pin + +//Define output level +#define SCK_HIGH (PORTB |= BV(PB1)) +#define SCK_LOW (PORTB &= ~BV(PB1)) +#define SOUT_OUT_HIGH (PORTB |= BV(PB2)) +#define SOUT_OUT_LOW (PORTB &= ~BV(PB2)) +#define SLOAD_OUT_HIGH (PORTB |= BV(PB3)) +#define SLOAD_OUT_LOW (PORTB &= ~BV(PB3)) +#define OE_LOW (PORTG &= BV(PG3)) + +/** + * Define the procedure to set one bit low/hight to + * serial input in sipo device. + */ +#define SIPO_SI_HIGH() SOUT_OUT_HIGH +#define SIPO_SI_LOW() SOUT_OUT_LOW + +/** + * Drive pin to load the bit, presented in serial-in pin, + * into sipo shift register. + */ +#define SIPO_SI_CLOCK() \ + do{ \ + SCK_HIGH; \ + SCK_LOW; \ + }while(0) -#define OE_OUT (DDRG |= BV(PG3)) -#define OE_LOW (PORTG &= BV(PG3)) +/** + * Clock the content of shift register to output. + */ +#define SIPO_LOAD() \ + do { \ + SLOAD_OUT_HIGH; \ + SLOAD_OUT_LOW; \ + }while(0) + +/** + * Enable the shift register output. + */ +#define SIPO_ENABLE() OE_LOW; + + +/** + * Do anything that needed to init sipo pins. + */ +#define SIPO_INIT_PIN() \ + do { \ + OE_OUT; \ + SOUT_OUT; \ + SCK_OUT; \ + SLOAD_OUT; \ + SIPO_ENABLE(); \ + } while(0) -#endif // HW_SIPO_H +#endif /* HW_SIPO_H */ diff --git a/examples/triface/protocol.c b/examples/triface/protocol.c index 1f630a1b..156a414b 100644 --- a/examples/triface/protocol.c +++ b/examples/triface/protocol.c @@ -45,6 +45,7 @@ #include "protocol.h" #include "cmd_ctor.h" // MAKE_CMD, REGISTER_CMD #include "verstag.h" + #include "hw/hw_adc.h" #include "hw/hw_input.h" @@ -83,6 +84,8 @@ static bool interactive; /// Readline context, used for interactive mode. static struct RLContext rl_ctx; +static Sipo fd_sipo; + uint8_t reg_status_dout; /** * Send a NAK asking the host to send the current message again. @@ -280,7 +283,7 @@ MAKE_CMD(ping, "", "", /* Dout */ MAKE_CMD(dout, "d", "", ({ - sipo_putchar((uint8_t)args[1].l); + kfile_write(&fd_sipo.fd, (uint8_t *)&args[1].l, 1); //Store status of dout ports. reg_status_dout = (uint8_t)args[1].l; @@ -356,6 +359,9 @@ static void protocol_registerCmds(void) /* Initialization: readline context, parser and register commands. */ void protocol_init(KFile *fd) { + /* SPI Port Initialization */ + sipo_init(&fd_sipo); + interactive = FORCE_INTERACTIVE; rl_init_ctx(&rl_ctx); diff --git a/examples/triface/protocol.h b/examples/triface/protocol.h index 26113482..0c250076 100644 --- a/examples/triface/protocol.h +++ b/examples/triface/protocol.h @@ -42,6 +42,8 @@ #ifndef PROTOCOL_H #define PROTOCOL_H +#include + #include void protocol_init(KFile *fd); diff --git a/examples/triface/triface.c b/examples/triface/triface.c index 86f21b2d..3707aaa5 100644 --- a/examples/triface/triface.c +++ b/examples/triface/triface.c @@ -51,21 +51,15 @@ #include #include #include -#include #include #include - - static Serial fd_ser; static Serial tag_ser; int main(void) { - /* SPI Port Initialization */ - sipo_init(); - kdbg_init(); timer_init(); adc_init(); diff --git a/examples/triface/triface.mk b/examples/triface/triface.mk index 430c421f..85cb1edd 100644 --- a/examples/triface/triface.mk +++ b/examples/triface/triface.mk @@ -40,8 +40,8 @@ triface_CSRC = \ bertos/drv/timer.c \ bertos/drv/ser.c \ bertos/drv/buzzer.c \ + bertos/drv/sipo.c \ bertos/cpu/avr/drv/ser_avr.c \ - bertos/cpu/avr/drv/sipo.c \ bertos/mware/formatwr.c \ bertos/mware/hex.c \ bertos/struct/hashtable.c \