[Tinyos-contrib-commits]
CVS: tinyos-1.x/contrib/diku/sensinode/tos/platform/micro4
HPLSpiM.nc, 1.1, 1.2
Marcus Chang
marcus_chang at users.sourceforge.net
Tue Jun 12 05:22:57 PDT 2007
Update of /cvsroot/tinyos/tinyos-1.x/contrib/diku/sensinode/tos/platform/micro4
In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv16321
Modified Files:
HPLSpiM.nc
Log Message:
Changed 16 MHz crystal control according to firmware update 0.9.4 on the U100
Index: HPLSpiM.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/contrib/diku/sensinode/tos/platform/micro4/HPLSpiM.nc,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** HPLSpiM.nc 15 Mar 2007 14:40:05 -0000 1.1
--- HPLSpiM.nc 12 Jun 2007 12:22:55 -0000 1.2
***************
*** 46,276 ****
! void bus_spi_init(bus_spi_flags flags);
! uint8_t bus_spi_exchange(uint8_t out);
! bool isSPI();
! norace uint8_t oldPrameters, oldId;
! async command result_t Spi.init() {
! /* spi enable */
! P2OUT |= 0xF0; /*module select none*/
! bus_spi_init(BUS_STE + BUS_PHASE_INVERT);
!
! P2OUT &= 0xE0; /*module select RF*/
! P3OUT |= 0x01;
! bus_spi_exchange((uint8_t) 0x10 & 0x3F);
! bus_spi_exchange((uint8_t) 0x00);
! bus_spi_exchange((uint8_t) 0x00);
! P3OUT &= ~0x01;
! P3OUT |= 0x01;
! bus_spi_exchange((uint8_t) 0x10 & 0x3F);
! bus_spi_exchange((uint8_t) 0xF8);
! bus_spi_exchange((uint8_t) 0x01);
! P3OUT &= ~0x01;
! P3OUT |= 0x01;
! bus_spi_exchange((uint8_t) 0x06);
! P3OUT &= ~0x01;
! /* spi disable */
! P4DIR = 0; /*parport input mode*/
! P3DIR &= ~0x3F; /*bus pins input*/
! P3SEL &= ~0x3F; /*turn module i/o off*/
! ME1 &= ~(UTXE0 | URXE0 | USPIE0); /* Modules off */
! P2OUT |= 0xF0; /*module select none*/
!
!
! /* Setup crystal oscillator control */
! call Spi.enable(BUS_CLOCK_1MHZ, 0);
! P1DIR |= 0x40; /*This pin is used as OSC_DISABLE*/
! P1OUT |= 0x40; /*That is, 1 means clock is on, 0 disabled*/
! call Spi.write((uint8_t) 0xBF); /*Select P1.4-6 as PLD controls*/
! call Spi.disable();
! return SUCCESS;
! }
! /**
! * Enable the SPI bus functionality
! */
! async command result_t Spi.enable(uint8_t newPrameters, uint8_t newId) {
! if(isSPI() && (newPrameters == oldPrameters) && (newId == oldId) )
! return SUCCESS;
! oldPrameters = newPrameters;
! oldId = newId;
! bus_spi_init((bus_spi_flags) newPrameters);
! TOSH_uwait(3);
! P2OUT = (P2OUT & 0x0F)| (newId << 4);
! return SUCCESS;
! }
! /**
! * Disable the SPI bus functionality
! */
! async command result_t Spi.disable() {
!
! P2OUT |= 0xF0; /*module select none*/
! P4DIR = 0; /*parport input mode*/
! P3DIR &= ~0x3F; /*bus pins input*/
! P3SEL &= ~0x3F; /*turn module i/o off*/
! ME1 &= ~(UTXE0 | URXE0 | USPIE0); /* Modules off */
! return SUCCESS;
! }
! /**
! * Write a byte to the SPI bus
! * @param data value written to the MOSI pin
! * @return value read on the MISO pin
! */
! async command uint8_t Spi.write(uint8_t data) {
! return bus_spi_exchange(data);
! }
! /**
! * Bus SPI check.
! *
! */
! bool isSPI() {
! bool _ret = FALSE;
!
! atomic{
! if (ME1 & USPIE0)
! _ret = TRUE;
! }
!
! return _ret;
! }
! /**
! * Bus SPI init.
! *
! * \param flags SPI mode flags
! *
! * \return pdTRUE
! * \return pdFALSE bus reserved
! */
! void bus_spi_init(bus_spi_flags flags)
! {
! P3DIR &= ~0x30; /*UART pins inputs*/
! P3SEL &= ~0x30; /*UART pins GPIO*/
! if (flags & (bus_spi_flags)BUS_SPI_SLAVE)
! {
! return;
! }
! else
! {
! uint8_t tctl_bits = STC;
! P3SEL |= 0x0E; /*MISO,MOSI,UCLK used*/
! P3SEL &= ~0x01; /*STE = GPIO*/
! P3DIR |= 0x0B; /*MOSI, STE and UCLK out*/
! if (flags & (bus_spi_flags)BUS_STE)
! {
! P3OUT |= 0x01;
! }
! else
! {
! P3OUT &= ~0x01;
! }
! P3DIR &= ~0x04; /*MISO in*/
! /* Reset UART. */
! U0CTL = SWRST;
! /* SPI master, 8 bit. */
! U0CTL |= SYNC+MM+CHAR;
! if (flags & (bus_spi_flags)BUS_PHASE_INVERT)
! {
! tctl_bits |= CKPH;
! }
! if (flags & (bus_spi_flags)BUS_CLOCK_INVERT)
! {
! tctl_bits |= CKPL;
! }
! tctl_bits |= SSEL1; /*Use SMCLK*/
! if (flags & (bus_spi_flags)BUS_MULTIMASTER)
! {
! tctl_bits &= ~STC;
! }
! U0TCTL = tctl_bits;
! switch (flags & 0x70)
! {
! case BUS_CLOCK_115kHZ:
! if (SPI_115K >= 2)
! {
! U0BR1 = (SPI_115K >> 8);
! U0BR0 = SPI_115K;
! }
! else
! {
! U0BR1 = 0;
! U0BR0 = 2;
! }
! break;
! case BUS_CLOCK_1MHZ:
! if (SPI_1M >= 2)
! {
! U0BR1 = (SPI_1M >> 8);
! U0BR0 = SPI_1M;
! }
! else
! {
! U0BR1 = 0;
! U0BR0 = 2;
! }
! break;
! case BUS_CLOCK_4MHZ:
! default: /*Maximum speed*/
! U0BR1 = 0;
! U0BR0 = 2;
! break;
! }
! U0MCTL = 0;
! /* Set ports. */
! ME1 &= ~(UTXE0 + URXE0);
! ME1 |= USPIE0;
! /* Set. */
! U0CTL &= ~SWRST;
! /* Disable interrupts. */
! IE1 &= ~ (URXIE0 + UTXIE0);
! }
! }
! /**
! * Bus SPI exchange.
! *
! * \param out byte to transmit
! *
! * \return byte from SPI
! */
! uint8_t bus_spi_exchange(uint8_t out)
! {
! U0TXBUF = out;
! while(!(IFG1 & URXIFG0));
! return U0RXBUF;
! }
}
--- 46,276 ----
! void bus_spi_init(bus_spi_flags flags);
! uint8_t bus_spi_exchange(uint8_t out);
! bool isSPI();
! norace uint8_t oldPrameters, oldId;
! async command result_t Spi.init() {
! /* spi enable */
! P2OUT |= 0xF0; /*module select none*/
! bus_spi_init(BUS_STE + BUS_PHASE_INVERT);
!
! P2OUT &= 0xE0; /*module select RF*/
! P3OUT |= 0x01;
! bus_spi_exchange((uint8_t) 0x10 & 0x3F);
! bus_spi_exchange((uint8_t) 0x00);
! bus_spi_exchange((uint8_t) 0x00);
! P3OUT &= ~0x01;
! P3OUT |= 0x01;
! bus_spi_exchange((uint8_t) 0x10 & 0x3F);
! bus_spi_exchange((uint8_t) 0xF8);
! bus_spi_exchange((uint8_t) 0x01);
! P3OUT &= ~0x01;
! P3OUT |= 0x01;
! bus_spi_exchange((uint8_t) 0x06);
! P3OUT &= ~0x01;
! /* spi disable */
! P4DIR = 0; /*parport input mode*/
! P3DIR &= ~0x3F; /*bus pins input*/
! P3SEL &= ~0x3F; /*turn module i/o off*/
! ME1 &= ~(UTXE0 | URXE0 | USPIE0); /* Modules off */
! P2OUT |= 0xF0; /*module select none*/
!
!
! /* Setup crystal oscillator control */
! call Spi.enable(BUS_CLOCK_1MHZ, 0);
! P1DIR |= 0x40; /*This pin is used as OSC_DISABLE*/
! P1OUT |= 0x40; /*That is, 0 means clock is on, 1 disabled*/
! call Spi.write((uint8_t) 0xBF); /*Select P1.4-6 as PLD controls*/
! call Spi.disable();
! return SUCCESS;
! }
! /**
! * Enable the SPI bus functionality
! */
! async command result_t Spi.enable(uint8_t newPrameters, uint8_t newId) {
! if(isSPI() && (newPrameters == oldPrameters) && (newId == oldId) )
! return SUCCESS;
! oldPrameters = newPrameters;
! oldId = newId;
! bus_spi_init((bus_spi_flags) newPrameters);
! TOSH_uwait(3);
! P2OUT = (P2OUT & 0x0F)| (newId << 4);
! return SUCCESS;
! }
! /**
! * Disable the SPI bus functionality
! */
! async command result_t Spi.disable() {
!
! P2OUT |= 0xF0; /*module select none*/
! P4DIR = 0; /*parport input mode*/
! P3DIR &= ~0x3F; /*bus pins input*/
! P3SEL &= ~0x3F; /*turn module i/o off*/
! ME1 &= ~(UTXE0 | URXE0 | USPIE0); /* Modules off */
! return SUCCESS;
! }
! /**
! * Write a byte to the SPI bus
! * @param data value written to the MOSI pin
! * @return value read on the MISO pin
! */
! async command uint8_t Spi.write(uint8_t data) {
! return bus_spi_exchange(data);
! }
! /**
! * Bus SPI check.
! *
! */
! bool isSPI() {
! bool _ret = FALSE;
!
! atomic{
! if (ME1 & USPIE0)
! _ret = TRUE;
! }
!
! return _ret;
! }
! /**
! * Bus SPI init.
! *
! * \param flags SPI mode flags
! *
! * \return pdTRUE
! * \return pdFALSE bus reserved
! */
! void bus_spi_init(bus_spi_flags flags)
! {
! P3DIR &= ~0x30; /*UART pins inputs*/
! P3SEL &= ~0x30; /*UART pins GPIO*/
! if (flags & (bus_spi_flags)BUS_SPI_SLAVE)
! {
! return;
! }
! else
! {
! uint8_t tctl_bits = STC;
! P3SEL |= 0x0E; /*MISO,MOSI,UCLK used*/
! P3SEL &= ~0x01; /*STE = GPIO*/
! P3DIR |= 0x0B; /*MOSI, STE and UCLK out*/
! if (flags & (bus_spi_flags)BUS_STE)
! {
! P3OUT |= 0x01;
! }
! else
! {
! P3OUT &= ~0x01;
! }
! P3DIR &= ~0x04; /*MISO in*/
! /* Reset UART. */
! U0CTL = SWRST;
! /* SPI master, 8 bit. */
! U0CTL |= SYNC+MM+CHAR;
! if (flags & (bus_spi_flags)BUS_PHASE_INVERT)
! {
! tctl_bits |= CKPH;
! }
! if (flags & (bus_spi_flags)BUS_CLOCK_INVERT)
! {
! tctl_bits |= CKPL;
! }
! tctl_bits |= SSEL1; /*Use SMCLK*/
! if (flags & (bus_spi_flags)BUS_MULTIMASTER)
! {
! tctl_bits &= ~STC;
! }
! U0TCTL = tctl_bits;
! switch (flags & 0x70)
! {
! case BUS_CLOCK_115kHZ:
! if (SPI_115K >= 2)
! {
! U0BR1 = (SPI_115K >> 8);
! U0BR0 = SPI_115K;
! }
! else
! {
! U0BR1 = 0;
! U0BR0 = 2;
! }
! break;
! case BUS_CLOCK_1MHZ:
! if (SPI_1M >= 2)
! {
! U0BR1 = (SPI_1M >> 8);
! U0BR0 = SPI_1M;
! }
! else
! {
! U0BR1 = 0;
! U0BR0 = 2;
! }
! break;
! case BUS_CLOCK_4MHZ:
! default: /*Maximum speed*/
! U0BR1 = 0;
! U0BR0 = 2;
! break;
! }
! U0MCTL = 0;
! /* Set ports. */
! ME1 &= ~(UTXE0 + URXE0);
! ME1 |= USPIE0;
! /* Set. */
! U0CTL &= ~SWRST;
! /* Disable interrupts. */
! IE1 &= ~ (URXIE0 + UTXIE0);
! }
! }
! /**
! * Bus SPI exchange.
! *
! * \param out byte to transmit
! *
! * \return byte from SPI
! */
! uint8_t bus_spi_exchange(uint8_t out)
! {
! U0TXBUF = out;
! while(!(IFG1 & URXIFG0));
! return U0RXBUF;
! }
}
More information about the Tinyos-contrib-commits
mailing list