-/*
- * Copyright (c) 2008, Titanium Mirror, Inc.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * - Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- * - Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * - Neither the name of the Technische Universität Berlin nor the names
- * of its contributors may be used to endorse or promote products derived
- * from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
- * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
- * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
- * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
- * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/**
- * HPL interrupt interface for a given USCI's Ax and Bx devices.
- *
- * @author R. Steve McKown <rsmckown@gmail.com>
- */
-
-#include "Msp430Usci.h"
-#include "msp430hardware.h"
-
-module HplMsp430UsciInt0P(
- uint8_t USCIABxRX_VECTOR,
- uint8_t USCIABxTX_VECTOR,
- uint8_t UCAxRXIFG,
- uint8_t UCAxTXIFG,
- uint8_t UCBxRXIFG,
- uint8_t UCBxTXIFG,
- uint8_t Ucaxctl0_addr,
- uint8_t Ucaxctl1_addr,
- uint8_t Ucaxrxbuf_addr,
- uint8_t Ucbxctl0_addr,
- uint8_t Ucbxctl1_addr,
- uint8_t Ucbxrxbuf_addr,
- uint8_t Ucxifg_addr
- ) @safe() {
- provides {
- interface HplMsp430UsciInt as IntA; /* Interrupts for USCI_A0 */
- interface HplMsp430UsciInt as IntB; /* Interrupts for USCI_B0 */
- }
-}
-
-implementation
-{
- #define UCxIFG (*TCAST(volatile uint8_t* ONE, Ucxifg_addr))
- #define UCAxCTL0 (*TCAST(volatile uint8_t* ONE, Ucaxctl0_addr))
- #define UCAxCTL1 (*TCAST(volatile uint8_t* ONE, Ucaxctl1_addr))
- #define UCAxRXBUF (*TCAST(volatile uint8_t* ONE, Ucaxrxbuf_addr))
- #define UCBxCTL0 (*TCAST(volatile uint8_t* ONE, Ucbxctl0_addr))
- #define UCBxCTL1 (*TCAST(volatile uint8_t* ONE, Ucbxctl1_addr))
- #define UCBxRXBUF (*TCAST(volatile uint8_t* ONE, Ucbxrxbuf_addr))
-
-#if 0
- MSP430REG_NORACE(UCxIFG);
- MSP430REG_NORACE(UCAxCTL0);
- MSP430REG_NORACE(UCAxCTL1);
- MSP430REG_NORACE(UCAxRXBUF);
- MSP430REG_NORACE(UCBxCTL0);
- MSP430REG_NORACE(UCBxCTL1);
- MSP430REG_NORACE(UCBxRXBUF);
-#endif
-
- /* This USCI_Ax and USCI_Bx interrupt vector signals receive events for UART
- * and SPI modes, and status events for I2C modes. Only Bx can do I2C.
- */
- TOSH_SIGNAL(USCIABxRX_VECTOR) {
- if (READ_FLAG(UCxIFG, UCAxRXIFG)) {
- volatile uint8_t c = UCAxRXBUF; /* read to clear UCAxRXIFG */
- if (READ_FLAG(UCAxCTL1, UCBRK)) {
- UCAxCTL1 &= ~UCBRK;
- if (READ_FLAG(UCAxCTL0, UCMODE_3) == UCMODE_3)
- UCAxCTL1 &= ~UCDORM;
- signal IntA.brk();
- } else
- signal IntA.rx(c);
- } else if (READ_FLAG(UCxIFG, UCBxRXIFG)) {
- volatile uint8_t c = UCBxRXBUF; /* read to clear UCBxRXIFG */
- if (READ_FLAG(UCBxCTL1, UCBRK)) {
- CLR_FLAG(UCBxCTL1, UCBRK);
- if (READ_FLAG(UCBxCTL0, UCMODE_3) == UCMODE_3)
- CLR_FLAG(UCBxCTL1, UCDORM);
- signal IntB.brk();
- } else
- signal IntB.rx(c);
- } else if (READ_FLAG(UCBxSTAT & UCALIFG))
- signal IntB.i2cCal();
- else if (READ_FLAG(UCBxSTAT, UCNAKIFG))
- signal IntB.i2cNak();
- else if (READ_FLAG(UCBxSTAT, UCSTTIFG))
- signal IntB.i2cStart();
- else if (READ_FLAG(UCBxSTAT, UCSTPIFG))
- signal IntB.i2cStop();
- }
-
- /* This USCI_Ax and USCI_Bx interrupt vector signals transmit events for UART
- * and SPI modes, and rx/tx events for I2C modes. Only Bx can do I2C.
- */
- TOSH_SIGNAL(USCIABxTX_VECTOR) {
- if (READ_FLAG(UCxIFG, UCBxRXIFG))
- signal IntB.rx(UCBxRXBUF); /* I2C receive */
- else if (READ_FLAG(UCxIFG, UCAxTXIFG))
- signal IntA.tx();
- else if (READ_FLAG(UCxIFG, UCBxTXIFG))
- signal IntB.tx();
- }
-
- default async event void IntA.brk() {}
- default async event void IntA.rx(char c) {}
- default async event void IntA.tx() {}
- /* i2c is not available for A devices, so the below are never signalled */
- default async event void IntA.i2cCal() {}
- default async event void IntA.i2cNak() {}
- default async event void IntA.i2cStart() {}
- default async event void IntA.i2cStop() {}
-
- default async event void IntB.brk() {}
- default async event void IntB.rx(char c) {}
- default async event void IntB.tx() {}
- default async event void IntB.i2cCal() {}
- default async event void IntB.i2cNak() {}
- default async event void IntB.i2cStart() {}
- default async event void IntB.i2cStop() {}
-}