diff options
Diffstat (limited to 'nuttx/arch/z80/src/z8')
-rw-r--r-- | nuttx/arch/z80/src/z8/chip.h | 8 | ||||
-rw-r--r-- | nuttx/arch/z80/src/z8/switch.h | 10 | ||||
-rw-r--r-- | nuttx/arch/z80/src/z8/up_mem.h | 8 | ||||
-rwxr-xr-x | nuttx/arch/z80/src/z8/z8_i2c.c | 1207 | ||||
-rw-r--r-- | nuttx/arch/z80/src/z8/z8_initialstate.c | 3 | ||||
-rw-r--r-- | nuttx/arch/z80/src/z8/z8_irq.c | 3 | ||||
-rw-r--r-- | nuttx/arch/z80/src/z8/z8_lowuart.c | 14 | ||||
-rw-r--r-- | nuttx/arch/z80/src/z8/z8_registerdump.c | 11 | ||||
-rw-r--r-- | nuttx/arch/z80/src/z8/z8_saveirqcontext.c | 8 | ||||
-rw-r--r-- | nuttx/arch/z80/src/z8/z8_schedulesigaction.c | 6 | ||||
-rwxr-xr-x | nuttx/arch/z80/src/z8/z8_serial.c | 147 | ||||
-rw-r--r-- | nuttx/arch/z80/src/z8/z8_sigdeliver.c | 3 | ||||
-rw-r--r-- | nuttx/arch/z80/src/z8/z8_timerisr.c | 12 |
13 files changed, 724 insertions, 716 deletions
diff --git a/nuttx/arch/z80/src/z8/chip.h b/nuttx/arch/z80/src/z8/chip.h index 702edd5fe..7635c0407 100644 --- a/nuttx/arch/z80/src/z8/chip.h +++ b/nuttx/arch/z80/src/z8/chip.h @@ -41,6 +41,10 @@ * Included Files ************************************************************************************/ +#ifndef __ASSEMBLY__ +# include <stdint.h> +#endif + /************************************************************************************ * Definitions ************************************************************************************/ @@ -118,11 +122,11 @@ /* UART0/1 Base Register Addresses **************************************************/ #ifdef EZ8_UART0 -# define Z8_UART0_BASE ((ubyte volatile far*)0xf40) +# define Z8_UART0_BASE ((uint8_t volatile far*)0xf40) #endif #ifdef EZ8_UART1 -# define Z8_UART1_BASE ((ubyte volatile far*)0xf48) +# define Z8_UART1_BASE ((uint8_t volatile far*)0xf48) #endif /* UART0/1 Status 0 Register Bit Definitions ****************************************/ diff --git a/nuttx/arch/z80/src/z8/switch.h b/nuttx/arch/z80/src/z8/switch.h index 073eff57d..69e766cf6 100644 --- a/nuttx/arch/z80/src/z8/switch.h +++ b/nuttx/arch/z80/src/z8/switch.h @@ -2,7 +2,7 @@ * arch/z80/src/z8/switch.h * arch/z80/src/chip/switch.h * - * Copyright (C) 2008 Gregory Nutt. All rights reserved. + * Copyright (C) 2008-2009 Gregory Nutt. All rights reserved. * Author: Gregory Nutt <spudmonkey@racsa.co.cr> * * Redistribution and use in source and binary forms, with or without @@ -41,8 +41,8 @@ * Included Files ************************************************************************************/ -#include <sys/types.h> #ifndef __ASSEMBLY__ +# include <stdint.h> # include <nuttx/sched.h> # include <nuttx/arch.h> #endif @@ -63,7 +63,7 @@ #define Z8_IRQSTATE_SAVED 2 /* In interrupt, context has been saved */ /* The information saved on interrupt entry can be retained in a array of two - * uint16 values. These are + * uint24_t values. These are * * value[0] = RP (MS byte) and Flags (LS) byte * value[1] = PC @@ -105,7 +105,7 @@ g_z8irqstate.state = Z8_IRQSTATE_NONE; \ } while (0) -/* IN_INTERRUPT returns TRUE if the system is current operating in the interrupt +/* IN_INTERRUPT returns true if the system is current operating in the interrupt * context. IN_INTERRUPT is the inline equivalent of up_interrupt_context(). */ @@ -189,7 +189,7 @@ #ifndef __ASSEMBLY__ struct z8_irqstate_s { - ubyte state; /* See Z8_IRQSTATE_* definitions above */ + uint8_t state; /* See Z8_IRQSTATE_* definitions above */ chipreg_t *regs; /* Saved register information */ }; #endif diff --git a/nuttx/arch/z80/src/z8/up_mem.h b/nuttx/arch/z80/src/z8/up_mem.h index 822af3f71..877d043ff 100644 --- a/nuttx/arch/z80/src/z8/up_mem.h +++ b/nuttx/arch/z80/src/z8/up_mem.h @@ -2,7 +2,7 @@ * arch/z80/src/z8/up_mem.h * arch/z80/src/chip/up_mem.h * - * Copyright (C) 2008 Gregory Nutt. All rights reserved. + * Copyright (C) 2008-2009 Gregory Nutt. All rights reserved. * Author: Gregory Nutt <spudmonkey@racsa.co.cr> * * Redistribution and use in source and binary forms, with or without @@ -41,6 +41,8 @@ * Included Files ************************************************************************************/ +#include <stdint.h> + /************************************************************************************ * Definitions ************************************************************************************/ @@ -57,12 +59,12 @@ #ifndef CONFIG_HEAP1_BASE extern far unsigned long far_heapbot; -# define CONFIG_HEAP1_BASE ((uint16)&far_heapbot) +# define CONFIG_HEAP1_BASE ((uint16_t))&far_heapbot) #endif #ifndef CONFIG_HEAP1_END extern far unsigned long far_stacktop; -# define CONFIG_HEAP1_END (((uint16)&far_stacktop) - CONFIG_IDLETHREAD_STACKSIZE + 1) +# define CONFIG_HEAP1_END (((uint16_t))&far_stacktop) - CONFIG_IDLETHREAD_STACKSIZE + 1) #endif /************************************************************************************ diff --git a/nuttx/arch/z80/src/z8/z8_i2c.c b/nuttx/arch/z80/src/z8/z8_i2c.c index 1fb87d291..796f389ec 100755 --- a/nuttx/arch/z80/src/z8/z8_i2c.c +++ b/nuttx/arch/z80/src/z8/z8_i2c.c @@ -1,603 +1,604 @@ -/****************************************************************************
- * arch/z80/src/z8/z8_i2c.c
- *
- * Copyright(C) 2009 Gregory Nutt. All rights reserved.
- * Author: Gregory Nutt <spudmonkey@racsa.co.cr>
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. 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.
- * 3. Neither the name NuttX 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.
- *
- ****************************************************************************/
-
-/****************************************************************************
- * Included Files
- ****************************************************************************/
-
-#include <nuttx/config.h>
-
-#include <sys/types.h>
-#include <stdlib.h>
-#include <semaphore.h>
-#include <errno.h>
-#include <assert.h>
-#include <debug.h>
-
-#include <nuttx/i2c.h>
-#include <arch/board/board.h>
-
-#include <eZ8.h> /* eZ8 Register definitions */
-#include "chip.h" /* Register bit definitions */
-
-/****************************************************************************
- * Pre-processor Definitions
- ****************************************************************************/
-
-/****************************************************************************
- * Private Types
- ****************************************************************************/
-
-struct z8_i2cdev_s
-{
- const struct i2c_ops_s *ops; /* I2C vtable */
- uint16 brg; /* Baud rate generator value */
- ubyte addr; /* 8-bit address */
-};
-
-/****************************************************************************
- * Private Function Prototypes
- ****************************************************************************/
-
-/* Misc. Helpers */
-
-static void i2c_waittxempty(void);
-static void i2c_waitrxavail(void);
-static void i2c_setbrg(uint16 brg);
-static uint16 i2c_getbrg(uint32 frequency);
-
-/* I2C methods */
-
-static uint32 i2c_setfrequency(FAR struct i2c_dev_s *dev, uint32 frequency);
-static int i2c_setaddress(FAR struct i2c_dev_s *dev, int addr, int nbits);
-static int i2c_write(FAR struct i2c_dev_s *dev, const ubyte *buffer, int buflen);
-static int i2c_read(FAR struct i2c_dev_s *dev, ubyte *buffer, int buflen);
-
-/****************************************************************************
- * Public Function Prototypes
- ****************************************************************************/
-
-/* This function is normally prototyped int the ZiLOG header file sio.h */
-
-extern uint32 get_freq(void);
-
-/****************************************************************************
- * Private Data
- ****************************************************************************/
-
-static uint16 g_currbrg; /* Current BRG setting */
-static boolean g_initialized; /* TRUE:I2C has been initialized */
-static sem_t g_i2csem; /* Serialize I2C transfers */
-
-const struct i2c_ops_s g_ops =
-{
- i2c_setfrequency,
- i2c_setaddress,
- i2c_write,
- i2c_read,
-};
-
-/****************************************************************************
- * Private Functions
- ****************************************************************************/
-/****************************************************************************
- * Name: i2c_semtake/i2c_semgive
- *
- * Description:
- * Take/Give the I2C semaphore.
- *
- * Input Parameters:
- * None
- *
- * Returned Value:
- * None
- *
- ****************************************************************************/
-
-static void i2c_semtake(void)
-{
- /* Take the I2C semaphore (perhaps waiting) */
-
- while (sem_wait(&g_i2csem) != 0)
- {
- /* The only case that an error should occr here is if
- * the wait was awakened by a signal.
- */
-
- ASSERT(errno == EINTR);
- }
-}
-
-#define i2c_semgive() sem_post(&g_i2csem)
-
-/****************************************************************************
- * Name: i2c_waittxempty
- *
- * Description:
- * Wait for the transmit data register to become empty.
- *
- * Input Parameters:
- * None
- *
- * Returned Value:
- * None
- *
- ****************************************************************************/
-
-static void i2c_waittxempty(void)
-{
- int i;
- for (i = 0; i < 10000 && (I2CSTAT & I2C_STAT_TDRE) == 0; i++);
-}
-
-/****************************************************************************
- * Name: i2c_waitrxavail
- *
- * Description:
- * Wait until we have received a full byte of data.
- *
- * Input Parameters:
- * None
- *
- * Returned Value:
- * None
- *
- ****************************************************************************/
-
-static void i2c_waitrxavail(void)
-{
- int i;
- for (i = 0; i <= 10000 && (I2CSTAT & (I2C_STAT_RDRF | I2C_STAT_NCKI)) == 0; i++);
-}
-
-/****************************************************************************
- * Name: i2c_setbrg
- *
- * Description:
- * Set the current BRG value for this transaction
- *
- * Input Parameters:
- * brg - BRG to set
- *
- * Returned Value:
- * None
- *
- ****************************************************************************/
-
-static void i2c_setbrg(uint16 brg)
-{
- if (g_currbrg != brg)
- {
- I2CBRH = (ubyte)(brg >> 8);
- I2CBRL = (ubyte)(brg & 0xff);
- g_currbrg = brg;
- }
-}
-
-/****************************************************************************
- * Name: i2c_getbrg
- *
- * Description:
- * Calculate the BRG value
- *
- * Input Parameters:
- * frequency - The I2C frequency requested
- *
- * Returned Value:
- * Returns the actual frequency selected
- *
- ****************************************************************************/
-
-static uint16 i2c_getbrg(uint32 frequency)
-{
- uint32 sysclock = get_freq();
-
- /* Max is 400 Kb/sec */
-
- if (frequency > 400*1000)
- {
- dbg("Invalid inputs\n");
- frequency = 400*1000;
- }
-
- /* BRG = sysclock / (4 * frequency) */
-
- return ((sysclock >> 2) + (frequency >> 1)) / frequency;
-}
-
-/****************************************************************************
- * Name: i2c_setfrequency
- *
- * Description:
- * Set the I2C frequency. This frequency will be retained in the struct
- * i2c_dev_s instance and will be used with all transfers. Required.
- *
- * Input Parameters:
- * dev - Device-specific state data
- * frequency - The I2C frequency requested
- *
- * Returned Value:
- * Returns the actual frequency selected
- *
- ****************************************************************************/
-
-static uint32 i2c_setfrequency(FAR struct i2c_dev_s *dev, uint32 frequency)
-{
- FAR struct z8_i2cdev_s *priv = (FAR struct z8_i2cdev_s *)dev;
-
- /* Sanity Check */
-
-#ifdef CONFIG_DEBUG
- if (!dev)
- {
- dbg("Invalid inputs\n");
- return -EINVAL;
- }
-#endif
-
- /* Calculate and save the BRG (we won't apply it until the first transfer) */
-
- priv->brg = i2c_getbrg(frequency);
- return OK;
-}
-
-/****************************************************************************
- * Name: i2c_setaddress
- *
- * Description:
- * Set the I2C slave address. This frequency will be retained in the struct
- * i2c_dev_s instance and will be used with all transfers. Required.
- *
- * Input Parameters:
- * dev - Device-specific state data
- * address - The I2C slave address
- * nbits - The number of address bits provided (7 or 10)
- *
- * Returned Value:
- * Returns the actual frequency selected
- *
- ****************************************************************************/
-
-static int i2c_setaddress(FAR struct i2c_dev_s *dev, int addr, int nbits)
-{
- FAR struct z8_i2cdev_s *priv = (FAR struct z8_i2cdev_s *)dev;
-
- /* Sanity Check */
-
-#ifdef CONFIG_DEBUG
- if (!dev || (unsigned)addr > 0x7f)
- {
- dbg("Invalid inputs\n");
- return -EINVAL;
- }
-#endif
-
- /* Save the 7-bit address (10-bit address not yet supported) */
-
- DEBUGASSERT(nbits == 7);
- priv->addr = (ubyte)addr;
- return OK;
-}
-
-/****************************************************************************
- * Name: i2c_write
- *
- * Description:
- * Send a block of data on I2C using the previously selected I2C
- * frequency and slave address. Each write operational will be an 'atomic'
- * operation in the sense that any other I2C actions will be serialized
- * and pend until this write completes. Required.
- *
- * Input Parameters:
- * dev - Device-specific state data
- * buffer - A pointer to the read-only buffer of data to be written to device
- * buflen - The number of bytes to send from the buffer
- *
- * Returned Value:
- * 0: success, <0: A negated errno
- *
- ****************************************************************************/
-
-static int i2c_write(FAR struct i2c_dev_s *dev, const ubyte *buffer, int buflen)
-{
- FAR struct z8_i2cdev_s *priv = (FAR struct z8_i2cdev_s *)dev;
- const ubyte *ptr;
- int retry;
- int count;
-
-#ifdef CONFIG_DEBUG
- if (!priv || !buffer || buflen < 1)
- {
- dbg("Invalid inputs\n");
- return -EINVAL;
- }
-#endif
-
- /* Get exclusive access */
-
- i2c_semtake();
-
- /* Set the frequency */
-
- i2c_setbrg(priv->brg);
-
- /* Retry as necessary to send this whole message */
-
- for (retry = 0; retry < 100; retry++)
- {
- /* Load the address into the transmit register. It is not sent
- * until the START bit is set.
- */
-
- I2CD = I2C_WRITEADDR8(priv->addr);
- I2CCTL |= I2C_CTL_START;
-
- /* Wait for the xmt buffer to become empty */
-
- i2c_waittxempty();
-
- /* Then send all of the bytes in the buffer */
-
- ptr = buffer;
- for (count = buflen; count; count--)
- {
- /* Send a byte of data and wait for it to be sent */
-
- I2CD = *ptr++;
- i2c_waittxempty();
-
- /* If this was the last byte, then send STOP immediately. This
- * is because the ACK will not be valid until the STOP clocks out
- * the last bit.. Hmmm. If this true then we will never be
- * able to send more than one data byte???
- */
-
- if (count == 1)
- {
- I2CCTL |= I2C_CTL_STOP;
-
- /* If this last byte was ACKed, then the whole buffer
- * was successfully sent and we can return success.
- */
-
- if ((I2CSTAT & I2C_STAT_ACK) != 0)
- {
- i2c_semgive();
- return OK;
- }
-
- /* If was was not ACKed, then this inner loop will
- * terminated (because count will decrement to zero
- * and the whole message will be resent
- */
- }
-
- /* Not the last byte... was this byte ACKed? */
-
- else if ((I2CSTAT & I2C_STAT_ACK) == 0)
- {
- /* No, flush the buffer and toggle the I2C on and off */
-
- I2CCTL |= I2C_CTL_FLUSH;
- I2CCTL &= ~I2C_CTL_IEN;
- I2CCTL |= I2C_CTL_IEN;
-
- /* Break out of the loop early and try again */
-
- break;
- }
- }
- }
- i2c_semgive();
- return -ETIMEDOUT;
-}
-
-/****************************************************************************
- * Name: i2c_read
- *
- * Description:
- * Receive a block of data from I2C using the previously selected I2C
- * frequency and slave address. Each read operational will be an 'atomic'
- * operation in the sense that any other I2C actions will be serialized
- * and pend until this read completes. Required.
- *
- * Input Parameters:
- * dev - Device-specific state data
- * buffer - A pointer to a buffer of data to receive the data from the device
- * buflen - The requested number of bytes to be read
- *
- * Returned Value:
- * 0: success, <0: A negated errno
- *
- ****************************************************************************/
-
-static int i2c_read(FAR struct i2c_dev_s *dev, ubyte *buffer, int buflen)
-{
- FAR struct z8_i2cdev_s *priv = (FAR struct z8_i2cdev_s *)dev;
- ubyte *ptr;
- int retry;
- int count;
-
-#ifdef CONFIG_DEBUG
- if (!priv || !buffer || buflen < 1)
- {
- dbg("Invalid inputs\n");
- return -EINVAL;
- }
-#endif
-
- /* Get exclusive access */
-
- i2c_semtake();
-
- /* Set the frequency */
-
- i2c_setbrg(priv->brg);
-
- /* Retry as necessary to receive the whole message */
-
- for (retry = 0; retry < 100; retry++)
- {
- /* Load the address into the transmit register. It is not sent
- * until the START bit is set.
- */
-
- I2CD = I2C_READADDR8(priv->addr);
-
- /* If we want only a single byte of data, then set the NACK
- * bit now.
- */
-
- I2CCTL |= I2C_CTL_NAK;
-
- /* The START bit begins the transaction */
-
- I2CCTL |= I2C_CTL_START;
-
- /* Now loop to receive each data byte */
-
- ptr = buffer;
- for (count = buflen; count; count--)
- {
- /* Wait for the receive buffer to fill */
-
- i2c_waitrxavail();
-
- /* Did we get a byte? Or did an error occur? */
-
- if (I2CSTAT & I2C_STAT_RDRF)
- {
- /* Save the data byte */
-
- *ptr++ = I2CD;
-
- /* If the next byte is the last byte, then set NAK now */
-
- if (count == 2)
- {
- I2CCTL |= I2C_CTL_NAK;
- }
-
- /* If this was the last byte, then set STOP and return success */
-
- else if (count == 1)
- {
- I2CCTL |= I2C_CTL_STOP;
- i2c_semgive();
- return OK;
- }
- }
- /* An error occurred. Clear byte bus and break out of the loop
- * to retry now.
- */
-
- else
- {
- /* No, flush the buffer and toggle the I2C on and off */
-
- I2CCTL |= I2C_CTL_FLUSH;
- I2CCTL &= ~I2C_CTL_IEN;
- I2CCTL |= I2C_CTL_IEN;
-
- /* Break out of the loop early and try again */
-
- break;
- }
- }
- }
- i2c_semgive();
- return -ETIMEDOUT;
-}
-
-/****************************************************************************
- * Public Functions
- ****************************************************************************/
-
-/****************************************************************************
- * Name: up_i2cinitialize
- *
- * Description:
- * Initialize the selected I2C port. And return a unique instance of struct
- * struct i2c_dev_s. This function may be called to obtain multiple
- * instances of the interface, each of which may be set up with a
- * different frequency and slave address.
- *
- * Input Parameter:
- * Port number (for hardware that has mutiple I2C interfaces)
- *
- * Returned Value:
- * Valid I2C device structre reference on succcess; a NULL on failure
- *
- ****************************************************************************/
-
-FAR struct i2c_dev_s *up_i2cinitialize(int port)
-{
- FAR struct z8_i2cdev_s *i2c;
-
- if (!g_initialized)
- {
- /* Set up some initial BRG value */
-
- uint16 brg = i2c_getbrg(100*1000);
- i2c_setbrg(brg);
-
- /* Make sure that GPIOs are configured for the alternate function (this
- * varies with silicon revisions).
- */
-
- PAADDR = 0x02;
- PACTL |= 0xc0;
-
- /* This semaphore enforces serialized access for I2C transfers */
-
- sem_init(&g_i2csem, 0, 1);
-
- /* Enable I2C -- no interrupts */
-
- I2CCTL = I2C_CTL_IEN;
- }
-
- /* Now, allocate an I2C instance for this caller */
-
- i2c = (FAR struct z8_i2cdev_s *)malloc(sizeof(FAR struct z8_i2cdev_s));
- if (i2c)
- {
- /* Initialize the allocated instance */
-
- i2c->ops = &g_ops;
- i2c->brg = g_currbrg;
- }
- return (FAR struct i2c_dev_s *)i2c;
-}
+/**************************************************************************** + * arch/z80/src/z8/z8_i2c.c + * + * Copyright(C) 2009 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt <spudmonkey@racsa.co.cr> + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. 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. + * 3. Neither the name NuttX 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. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include <nuttx/config.h> + +#include <stdint.h> +#include <stdbool.h> +#include <stdlib.h> +#include <semaphore.h> +#include <errno.h> +#include <assert.h> +#include <debug.h> + +#include <nuttx/i2c.h> +#include <arch/board/board.h> + +#include <eZ8.h> /* eZ8 Register definitions */ +#include "chip.h" /* Register bit definitions */ + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private Types + ****************************************************************************/ + +struct z8_i2cdev_s +{ + const struct i2c_ops_s *ops; /* I2C vtable */ + uint16_t brg; /* Baud rate generator value */ + uint8_t addr; /* 8-bit address */ +}; + +/**************************************************************************** + * Private Function Prototypes + ****************************************************************************/ + +/* Misc. Helpers */ + +static void i2c_waittxempty(void); +static void i2c_waitrxavail(void); +static void i2c_setbrg(uint16_t brg); +static uint16_t i2c_getbrg(uint32_t frequency); + +/* I2C methods */ + +static uint32_t i2c_setfrequency(FAR struct i2c_dev_s *dev, uint32_t frequency); +static int i2c_setaddress(FAR struct i2c_dev_s *dev, int addr, int nbits); +static int i2c_write(FAR struct i2c_dev_s *dev, const uint8_t *buffer, int buflen); +static int i2c_read(FAR struct i2c_dev_s *dev, uint8_t *buffer, int buflen); + +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ + +/* This function is normally prototyped int the ZiLOG header file sio.h */ + +extern uint32_t get_freq(void); + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +static uint16_t g_currbrg; /* Current BRG setting */ +static bool g_initialized; /* true:I2C has been initialized */ +static sem_t g_i2csem; /* Serialize I2C transfers */ + +const struct i2c_ops_s g_ops = +{ + i2c_setfrequency, + i2c_setaddress, + i2c_write, + i2c_read, +}; + +/**************************************************************************** + * Private Functions + ****************************************************************************/ +/**************************************************************************** + * Name: i2c_semtake/i2c_semgive + * + * Description: + * Take/Give the I2C semaphore. + * + * Input Parameters: + * None + * + * Returned Value: + * None + * + ****************************************************************************/ + +static void i2c_semtake(void) +{ + /* Take the I2C semaphore (perhaps waiting) */ + + while (sem_wait(&g_i2csem) != 0) + { + /* The only case that an error should occr here is if + * the wait was awakened by a signal. + */ + + ASSERT(errno == EINTR); + } +} + +#define i2c_semgive() sem_post(&g_i2csem) + +/**************************************************************************** + * Name: i2c_waittxempty + * + * Description: + * Wait for the transmit data register to become empty. + * + * Input Parameters: + * None + * + * Returned Value: + * None + * + ****************************************************************************/ + +static void i2c_waittxempty(void) +{ + int i; + for (i = 0; i < 10000 && (I2CSTAT & I2C_STAT_TDRE) == 0; i++); +} + +/**************************************************************************** + * Name: i2c_waitrxavail + * + * Description: + * Wait until we have received a full byte of data. + * + * Input Parameters: + * None + * + * Returned Value: + * None + * + ****************************************************************************/ + +static void i2c_waitrxavail(void) +{ + int i; + for (i = 0; i <= 10000 && (I2CSTAT & (I2C_STAT_RDRF | I2C_STAT_NCKI)) == 0; i++); +} + +/**************************************************************************** + * Name: i2c_setbrg + * + * Description: + * Set the current BRG value for this transaction + * + * Input Parameters: + * brg - BRG to set + * + * Returned Value: + * None + * + ****************************************************************************/ + +static void i2c_setbrg(uint16_t brg) +{ + if (g_currbrg != brg) + { + I2CBRH = (uint8_t)(brg >> 8); + I2CBRL = (uint8_t)(brg & 0xff); + g_currbrg = brg; + } +} + +/**************************************************************************** + * Name: i2c_getbrg + * + * Description: + * Calculate the BRG value + * + * Input Parameters: + * frequency - The I2C frequency requested + * + * Returned Value: + * Returns the actual frequency selected + * + ****************************************************************************/ + +static uint16_t i2c_getbrg(uint32_t frequency) +{ + uint32_t sysclock = get_freq(); + + /* Max is 400 Kb/sec */ + + if (frequency > 400*1000) + { + dbg("Invalid inputs\n"); + frequency = 400*1000; + } + + /* BRG = sysclock / (4 * frequency) */ + + return ((sysclock >> 2) + (frequency >> 1)) / frequency; +} + +/**************************************************************************** + * Name: i2c_setfrequency + * + * Description: + * Set the I2C frequency. This frequency will be retained in the struct + * i2c_dev_s instance and will be used with all transfers. Required. + * + * Input Parameters: + * dev - Device-specific state data + * frequency - The I2C frequency requested + * + * Returned Value: + * Returns the actual frequency selected + * + ****************************************************************************/ + +static uint32_t i2c_setfrequency(FAR struct i2c_dev_s *dev, uint32_t frequency) +{ + FAR struct z8_i2cdev_s *priv = (FAR struct z8_i2cdev_s *)dev; + + /* Sanity Check */ + +#ifdef CONFIG_DEBUG + if (!dev) + { + dbg("Invalid inputs\n"); + return -EINVAL; + } +#endif + + /* Calculate and save the BRG (we won't apply it until the first transfer) */ + + priv->brg = i2c_getbrg(frequency); + return OK; +} + +/**************************************************************************** + * Name: i2c_setaddress + * + * Description: + * Set the I2C slave address. This frequency will be retained in the struct + * i2c_dev_s instance and will be used with all transfers. Required. + * + * Input Parameters: + * dev - Device-specific state data + * address - The I2C slave address + * nbits - The number of address bits provided (7 or 10) + * + * Returned Value: + * Returns the actual frequency selected + * + ****************************************************************************/ + +static int i2c_setaddress(FAR struct i2c_dev_s *dev, int addr, int nbits) +{ + FAR struct z8_i2cdev_s *priv = (FAR struct z8_i2cdev_s *)dev; + + /* Sanity Check */ + +#ifdef CONFIG_DEBUG + if (!dev || (unsigned)addr > 0x7f) + { + dbg("Invalid inputs\n"); + return -EINVAL; + } +#endif + + /* Save the 7-bit address (10-bit address not yet supported) */ + + DEBUGASSERT(nbits == 7); + priv->addr = (uint8_t)addr; + return OK; +} + +/**************************************************************************** + * Name: i2c_write + * + * Description: + * Send a block of data on I2C using the previously selected I2C + * frequency and slave address. Each write operational will be an 'atomic' + * operation in the sense that any other I2C actions will be serialized + * and pend until this write completes. Required. + * + * Input Parameters: + * dev - Device-specific state data + * buffer - A pointer to the read-only buffer of data to be written to device + * buflen - The number of bytes to send from the buffer + * + * Returned Value: + * 0: success, <0: A negated errno + * + ****************************************************************************/ + +static int i2c_write(FAR struct i2c_dev_s *dev, const uint8_t *buffer, int buflen) +{ + FAR struct z8_i2cdev_s *priv = (FAR struct z8_i2cdev_s *)dev; + const uint8_t *ptr; + int retry; + int count; + +#ifdef CONFIG_DEBUG + if (!priv || !buffer || buflen < 1) + { + dbg("Invalid inputs\n"); + return -EINVAL; + } +#endif + + /* Get exclusive access */ + + i2c_semtake(); + + /* Set the frequency */ + + i2c_setbrg(priv->brg); + + /* Retry as necessary to send this whole message */ + + for (retry = 0; retry < 100; retry++) + { + /* Load the address into the transmit register. It is not sent + * until the START bit is set. + */ + + I2CD = I2C_WRITEADDR8(priv->addr); + I2CCTL |= I2C_CTL_START; + + /* Wait for the xmt buffer to become empty */ + + i2c_waittxempty(); + + /* Then send all of the bytes in the buffer */ + + ptr = buffer; + for (count = buflen; count; count--) + { + /* Send a byte of data and wait for it to be sent */ + + I2CD = *ptr++; + i2c_waittxempty(); + + /* If this was the last byte, then send STOP immediately. This + * is because the ACK will not be valid until the STOP clocks out + * the last bit.. Hmmm. If this true then we will never be + * able to send more than one data byte??? + */ + + if (count == 1) + { + I2CCTL |= I2C_CTL_STOP; + + /* If this last byte was ACKed, then the whole buffer + * was successfully sent and we can return success. + */ + + if ((I2CSTAT & I2C_STAT_ACK) != 0) + { + i2c_semgive(); + return OK; + } + + /* If was was not ACKed, then this inner loop will + * terminated (because count will decrement to zero + * and the whole message will be resent + */ + } + + /* Not the last byte... was this byte ACKed? */ + + else if ((I2CSTAT & I2C_STAT_ACK) == 0) + { + /* No, flush the buffer and toggle the I2C on and off */ + + I2CCTL |= I2C_CTL_FLUSH; + I2CCTL &= ~I2C_CTL_IEN; + I2CCTL |= I2C_CTL_IEN; + + /* Break out of the loop early and try again */ + + break; + } + } + } + i2c_semgive(); + return -ETIMEDOUT; +} + +/**************************************************************************** + * Name: i2c_read + * + * Description: + * Receive a block of data from I2C using the previously selected I2C + * frequency and slave address. Each read operational will be an 'atomic' + * operation in the sense that any other I2C actions will be serialized + * and pend until this read completes. Required. + * + * Input Parameters: + * dev - Device-specific state data + * buffer - A pointer to a buffer of data to receive the data from the device + * buflen - The requested number of bytes to be read + * + * Returned Value: + * 0: success, <0: A negated errno + * + ****************************************************************************/ + +static int i2c_read(FAR struct i2c_dev_s *dev, uint8_t *buffer, int buflen) +{ + FAR struct z8_i2cdev_s *priv = (FAR struct z8_i2cdev_s *)dev; + uint8_t *ptr; + int retry; + int count; + +#ifdef CONFIG_DEBUG + if (!priv || !buffer || buflen < 1) + { + dbg("Invalid inputs\n"); + return -EINVAL; + } +#endif + + /* Get exclusive access */ + + i2c_semtake(); + + /* Set the frequency */ + + i2c_setbrg(priv->brg); + + /* Retry as necessary to receive the whole message */ + + for (retry = 0; retry < 100; retry++) + { + /* Load the address into the transmit register. It is not sent + * until the START bit is set. + */ + + I2CD = I2C_READADDR8(priv->addr); + + /* If we want only a single byte of data, then set the NACK + * bit now. + */ + + I2CCTL |= I2C_CTL_NAK; + + /* The START bit begins the transaction */ + + I2CCTL |= I2C_CTL_START; + + /* Now loop to receive each data byte */ + + ptr = buffer; + for (count = buflen; count; count--) + { + /* Wait for the receive buffer to fill */ + + i2c_waitrxavail(); + + /* Did we get a byte? Or did an error occur? */ + + if (I2CSTAT & I2C_STAT_RDRF) + { + /* Save the data byte */ + + *ptr++ = I2CD; + + /* If the next byte is the last byte, then set NAK now */ + + if (count == 2) + { + I2CCTL |= I2C_CTL_NAK; + } + + /* If this was the last byte, then set STOP and return success */ + + else if (count == 1) + { + I2CCTL |= I2C_CTL_STOP; + i2c_semgive(); + return OK; + } + } + /* An error occurred. Clear byte bus and break out of the loop + * to retry now. + */ + + else + { + /* No, flush the buffer and toggle the I2C on and off */ + + I2CCTL |= I2C_CTL_FLUSH; + I2CCTL &= ~I2C_CTL_IEN; + I2CCTL |= I2C_CTL_IEN; + + /* Break out of the loop early and try again */ + + break; + } + } + } + i2c_semgive(); + return -ETIMEDOUT; +} + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: up_i2cinitialize + * + * Description: + * Initialize the selected I2C port. And return a unique instance of struct + * struct i2c_dev_s. This function may be called to obtain multiple + * instances of the interface, each of which may be set up with a + * different frequency and slave address. + * + * Input Parameter: + * Port number (for hardware that has mutiple I2C interfaces) + * + * Returned Value: + * Valid I2C device structre reference on succcess; a NULL on failure + * + ****************************************************************************/ + +FAR struct i2c_dev_s *up_i2cinitialize(int port) +{ + FAR struct z8_i2cdev_s *i2c; + + if (!g_initialized) + { + /* Set up some initial BRG value */ + + uint16_t brg = i2c_getbrg(100*1000); + i2c_setbrg(brg); + + /* Make sure that GPIOs are configured for the alternate function (this + * varies with silicon revisions). + */ + + PAADDR = 0x02; + PACTL |= 0xc0; + + /* This semaphore enforces serialized access for I2C transfers */ + + sem_init(&g_i2csem, 0, 1); + + /* Enable I2C -- no interrupts */ + + I2CCTL = I2C_CTL_IEN; + } + + /* Now, allocate an I2C instance for this caller */ + + i2c = (FAR struct z8_i2cdev_s *)malloc(sizeof(FAR struct z8_i2cdev_s)); + if (i2c) + { + /* Initialize the allocated instance */ + + i2c->ops = &g_ops; + i2c->brg = g_currbrg; + } + return (FAR struct i2c_dev_s *)i2c; +} diff --git a/nuttx/arch/z80/src/z8/z8_initialstate.c b/nuttx/arch/z80/src/z8/z8_initialstate.c index 57df5c735..794446aac 100644 --- a/nuttx/arch/z80/src/z8/z8_initialstate.c +++ b/nuttx/arch/z80/src/z8/z8_initialstate.c @@ -1,7 +1,7 @@ /**************************************************************************** * arch/z80/src/z8/z8_initialstate.c * - * Copyright (C) 2008 Gregory Nutt. All rights reserved. + * Copyright (C) 2008-2009 Gregory Nutt. All rights reserved. * Author: Gregory Nutt <spudmonkey@racsa.co.cr> * * Redistribution and use in source and binary forms, with or without @@ -39,7 +39,6 @@ #include <nuttx/config.h> -#include <sys/types.h> #include <string.h> #include <nuttx/arch.h> diff --git a/nuttx/arch/z80/src/z8/z8_irq.c b/nuttx/arch/z80/src/z8/z8_irq.c index 5b1d0ccce..be732fe83 100644 --- a/nuttx/arch/z80/src/z8/z8_irq.c +++ b/nuttx/arch/z80/src/z8/z8_irq.c @@ -1,7 +1,7 @@ /**************************************************************************** * arch/z80/src/z8/z8_irq.c * - * Copyright (C) 2008 Gregory Nutt. All rights reserved. + * Copyright (C) 2008-2009 Gregory Nutt. All rights reserved. * Author: Gregory Nutt <spudmonkey@racsa.co.cr> * * Redistribution and use in source and binary forms, with or without @@ -39,7 +39,6 @@ #include <nuttx/config.h> -#include <sys/types.h> #include <ez8.h> #include <nuttx/arch.h> diff --git a/nuttx/arch/z80/src/z8/z8_lowuart.c b/nuttx/arch/z80/src/z8/z8_lowuart.c index e18c4b5d1..15a7999ec 100644 --- a/nuttx/arch/z80/src/z8/z8_lowuart.c +++ b/nuttx/arch/z80/src/z8/z8_lowuart.c @@ -1,7 +1,7 @@ /**************************************************************************** * arch/z80/src/z8/z8_loweruart.c * - * Copyright (C) 2008 Gregory Nutt. All rights reserved. + * Copyright (C) 2008-2009 Gregory Nutt. All rights reserved. * Author: Gregory Nutt <spudmonkey@racsa.co.cr> * * Redistribution and use in source and binary forms, with or without @@ -39,7 +39,7 @@ #include <nuttx/config.h> -#include <sys/types.h> +#include <stdint.h> #include <string.h> #include <ez8.h> @@ -51,7 +51,7 @@ #ifdef CONFIG_USE_LOWUARTINIT -extern uint32 get_freq(void); +extern uint32_t get_freq(void); /**************************************************************************** * Private Definitions @@ -75,13 +75,13 @@ extern uint32 get_freq(void); void up_lowuartinit(void) { - uint32 freq = get_freq(); - uint16 brg; - ubyte val; + uint32_t freq = get_freq(); + uint16_t brg; + uint8_t val; #ifdef CONFIG_UART0_SERIAL_CONSOLE - brg = (freq +(uint32)CONFIG_UART0_BAUD * 8) /((uint32)CONFIG_UART0_BAUD * 16) ; + brg = (freq +(uint32_t)CONFIG_UART0_BAUD * 8) /((uint32_t)CONFIG_UART0_BAUD * 16) ; /* Set the baudrate */ diff --git a/nuttx/arch/z80/src/z8/z8_registerdump.c b/nuttx/arch/z80/src/z8/z8_registerdump.c index b7e01a74d..0fb103c7d 100644 --- a/nuttx/arch/z80/src/z8/z8_registerdump.c +++ b/nuttx/arch/z80/src/z8/z8_registerdump.c @@ -1,7 +1,7 @@ /**************************************************************************** * arch/z80/src/z8/z8_registerdump.c * - * Copyright (C) 2008 Gregory Nutt. All rights reserved. + * Copyright (C) 2008-2009 Gregory Nutt. All rights reserved. * Author: Gregory Nutt <spudmonkey@racsa.co.cr> * * Redistribution and use in source and binary forms, with or without @@ -39,7 +39,7 @@ #include <nuttx/config.h> -#include <sys/types.h> +#include <stdint.h> #include <debug.h> #include <nuttx/irq.h> @@ -78,7 +78,8 @@ static inline void z8_dumpregs(FAR chipret_t *regs) regs[XCPT_RR8], regs[XCPT_RR10], regs[XCPT_RR12], regs[XCPT_RR14]); } -static inline void z8_dumpstate(chipreg_t sp, chipreg_t pc, ubyte irqctl, chipreg_t rpflags) +static inline void z8_dumpstate(chipreg_t sp, chipreg_t pc, uint8_t irqctl, + chipreg_t rpflags) { lldbg("SP: %04x PC: %04x IRQCTL: %02x RP: %02x FLAGS: %02x\n", sp, pc, irqctl & 0xff, rpflags >> 8, rpflags & 0xff); @@ -100,7 +101,7 @@ void z8_registerdump(void) FAR chipret_t *regs; FAR chipret_t *state; chipreg_t sp; - uint16 rp; + uint16_t rp; switch (g_z8irqstate.state) { @@ -108,7 +109,7 @@ void z8_registerdump(void) /* Calculate the source address based on the saved RP value */ rp = g_z8irqstate.regs[Z8_IRQSAVE_RPFLAGS] >> 8; - regs = (FAR uint16*)(rp & 0xf0); + regs = (FAR uint16_t*)(rp & 0xf0); /* Then dump the register values */ diff --git a/nuttx/arch/z80/src/z8/z8_saveirqcontext.c b/nuttx/arch/z80/src/z8/z8_saveirqcontext.c index 22f5da0ed..2d3fb7aa2 100644 --- a/nuttx/arch/z80/src/z8/z8_saveirqcontext.c +++ b/nuttx/arch/z80/src/z8/z8_saveirqcontext.c @@ -1,7 +1,7 @@ /**************************************************************************** * arch/z80/src/z8/z8_saveirqcontext.c * - * Copyright (C) 2008 Gregory Nutt. All rights reserved. + * Copyright (C) 2008-2009 Gregory Nutt. All rights reserved. * Author: Gregory Nutt <spudmonkey@racsa.co.cr> * * Redistribution and use in source and binary forms, with or without @@ -39,7 +39,7 @@ #include <nuttx/config.h> -#include <sys/types.h> +#include <stdint.h> #include <arch/irq.h> #include "chip/switch.h" @@ -93,8 +93,8 @@ void z8_saveirqcontext(FAR chipreg_t *regs) { /* Calculate the source address based on the saved RP value */ - uint16 rp = g_z8irqstate.regs[Z8_IRQSAVE_RPFLAGS] >> 8; - FAR chipreg_t *src = (FAR uint16*)(rp & 0xf0); + uint16_t rp = g_z8irqstate.regs[Z8_IRQSAVE_RPFLAGS] >> 8; + FAR chipreg_t *src = (FAR uint16_t*)(rp & 0xf0); FAR chipreg_t *dest = ®s[XCPT_RR0]; /* Copy the interrupted tasks register into the TCB register save area. */ diff --git a/nuttx/arch/z80/src/z8/z8_schedulesigaction.c b/nuttx/arch/z80/src/z8/z8_schedulesigaction.c index fd9e71520..0a5b9c095 100644 --- a/nuttx/arch/z80/src/z8/z8_schedulesigaction.c +++ b/nuttx/arch/z80/src/z8/z8_schedulesigaction.c @@ -1,7 +1,7 @@ /**************************************************************************** * arch/z80/src/z8/z8_schedulesigaction.c * - * Copyright (C) 2008 Gregory Nutt. All rights reserved. + * Copyright (C) 2008-2009 Gregory Nutt. All rights reserved. * Author: Gregory Nutt <spudmonkey@racsa.co.cr> * * Redistribution and use in source and binary forms, with or without @@ -39,7 +39,7 @@ #include <nuttx/config.h> -#include <sys/types.h> +#include <stdint.h> #include <sched.h> #include <debug.h> @@ -123,7 +123,7 @@ static void z8_sigsetup(FAR _TCB *tcb, sig_deliver_t sigdeliver, FAR chipreg_t * void up_schedule_sigaction(FAR _TCB *tcb, sig_deliver_t sigdeliver) { - dbg("tcb=0x%p sigdeliver=0x%04x\n", tcb, (uint16)sigdeliver); + dbg("tcb=0x%p sigdeliver=0x%04x\n", tcb, (uint16_t)sigdeliver); /* Refuse to handle nested signal actions */ diff --git a/nuttx/arch/z80/src/z8/z8_serial.c b/nuttx/arch/z80/src/z8/z8_serial.c index 1f434a66d..f1427eaae 100755 --- a/nuttx/arch/z80/src/z8/z8_serial.c +++ b/nuttx/arch/z80/src/z8/z8_serial.c @@ -1,7 +1,7 @@ /**************************************************************************** * arch/z80/src/z8/z8_serial.c * - * Copyright (C) 2008 Gregory Nutt. All rights reserved. + * Copyright (C) 2008-2009 Gregory Nutt. All rights reserved. * Author: Gregory Nutt <spudmonkey@racsa.co.cr> * * Redistribution and use in source and binary forms, with or without @@ -40,6 +40,8 @@ #include <nuttx/config.h> #include <sys/types.h> +#include <stdint.h> +#include <stdbool.h> #include <unistd.h> #include <semaphore.h> #include <string.h> @@ -58,7 +60,7 @@ #ifdef CONFIG_USE_SERIALDRIVER -extern uint32 get_freq(void); +extern uint32_t get_freq(void); /**************************************************************************** * Definitions @@ -76,35 +78,35 @@ extern uint32 get_freq(void); struct z8_uart_s { - ubyte volatile far* uartbase; /* Base address of UART registers */ - uint32 baud; /* Configured baud */ - boolean rxenabled; /* RX interrupt enabled */ - boolean txenabled; /* TX interrupt enabled */ - ubyte rxirq; /* RX IRQ associated with this UART */ - ubyte txirq; /* RX IRQ associated with this UART */ - ubyte parity; /* 0=none, 1=odd, 2=even */ - boolean stopbits2; /* TRUE: Configure with 2 stop bits - * (instead of 1) */ + uint8_t volatile far* uartbase; /* Base address of UART registers */ + uint32_t baud; /* Configured baud */ + bool rxenabled; /* RX interrupt enabled */ + bool txenabled; /* TX interrupt enabled */ + uint8_t rxirq; /* RX IRQ associated with this UART */ + uint8_t txirq; /* RX IRQ associated with this UART */ + uint8_t parity; /* 0=none, 1=odd, 2=even */ + bool stopbits2; /* true: Configure with 2 stop bits + * (instead of 1) */ }; /**************************************************************************** * Private Function Prototypes ****************************************************************************/ -static int z8_setup(FAR struct uart_dev_s *dev); -static void z8_shutdown(FAR struct uart_dev_s *dev); -static int z8_attach(FAR struct uart_dev_s *dev); -static void z8_detach(FAR struct uart_dev_s *dev); -static int z8_rxinterrupt(int irq, FAR void *context); -static int z8_txinterrupt(int irq, FAR void *context); -static int z8_ioctl(FAR struct file *filep, int cmd, unsigned long arg); -static int z8_receive(FAR struct uart_dev_s *dev, FAR uint32 *status); -static void z8_rxint(FAR struct uart_dev_s *dev, boolean enable); -static boolean z8_rxavailable(FAR struct uart_dev_s *dev); -static void z8_send(FAR struct uart_dev_s *dev, int ch); -static void z8_txint(FAR struct uart_dev_s *dev, boolean enable); -static boolean z8_txready(FAR struct uart_dev_s *dev); -static boolean z8_txempty(FAR struct uart_dev_s *dev); +static int z8_setup(FAR struct uart_dev_s *dev); +static void z8_shutdown(FAR struct uart_dev_s *dev); +static int z8_attach(FAR struct uart_dev_s *dev); +static void z8_detach(FAR struct uart_dev_s *dev); +static int z8_rxinterrupt(int irq, FAR void *context); +static int z8_txinterrupt(int irq, FAR void *context); +static int z8_ioctl(FAR struct file *filep, int cmd, unsigned long arg); +static int z8_receive(FAR struct uart_dev_s *dev, FAR uint32_t *status); +static void z8_rxint(FAR struct uart_dev_s *dev, bool enable); +static bool z8_rxavailable(FAR struct uart_dev_s *dev); +static void z8_send(FAR struct uart_dev_s *dev, int ch); +static void z8_txint(FAR struct uart_dev_s *dev, bool enable); +static bool z8_txready(FAR struct uart_dev_s *dev); +static bool z8_txempty(FAR struct uart_dev_s *dev); /**************************************************************************** * Private Variables @@ -139,8 +141,8 @@ static struct z8_uart_s g_uart0priv = { Z8_UART0_BASE, /* uartbase */ CONFIG_UART0_BAUD, /* baud */ - FALSE, /* rxenabled */ - FALSE, /* txenabled */ + false, /* rxenabled */ + false, /* txenabled */ Z8_UART0_RX_IRQ, /* rxirq */ Z8_UART0_TX_IRQ, /* txirq */ CONFIG_UART0_PARITY, /* parity */ @@ -150,12 +152,12 @@ static struct z8_uart_s g_uart0priv = static uart_dev_t g_uart0port = { 0, /* open_count */ - FALSE, /* xmitwaiting */ - FALSE, /* recvwaiting */ + false, /* xmitwaiting */ + false, /* recvwaiting */ #ifdef CONFIG_UART0_SERIAL_CONSOLE - TRUE, /* isconsole */ + true, /* isconsole */ #else - FALSE, /* isconsole */ + false, /* isconsole */ #endif { 0 }, /* closesem */ { 0 }, /* xmitsem */ @@ -184,8 +186,8 @@ static struct z8_uart_s g_uart1priv = { Z8_UART1_BASE, /* uartbase */ CONFIG_UART1_BAUD, /* baud */ - FALSE, /* rxenabled */ - FALSE, /* txenabled */ + false, /* rxenabled */ + false, /* txenabled */ Z8_UART1_RX_IRQ, /* rxirq */ Z8_UART1_TX_IRQ, /* txirq */ CONFIG_UART1_PARITY, /* parity */ @@ -195,12 +197,12 @@ static struct z8_uart_s g_uart1priv = static uart_dev_t g_uart1port = { 0, /* open_count */ - FALSE, /* xmitwaiting */ - FALSE, /* recvwaiting */ + false, /* xmitwaiting */ + false, /* recvwaiting */ #ifdef CONFIG_UART1_SERIAL_CONSOLE - TRUE, /* isconsole */ + true, /* isconsole */ #else - FALSE, /* isconsole */ + false, /* isconsole */ #endif { 0 }, /* closesem */ { 0 }, /* xmitsem */ @@ -243,7 +245,8 @@ static uart_dev_t g_uart1port = * Name: z8_putuart ****************************************************************************/ -static inline void z8_putuart(FAR struct z8_uart_s *priv, ubyte value, ubyte offset) +static inline void z8_putuart(FAR struct z8_uart_s *priv, uint8_t value, + uint8_t offset) { putreg8(value, *(priv->uartbase + offset)); } @@ -252,7 +255,7 @@ static inline void z8_putuart(FAR struct z8_uart_s *priv, ubyte value, ubyte off * Name: z8_getuart ****************************************************************************/ -static inline ubyte z8_getuart(FAR struct z8_uart_s *priv, ubyte offset) +static inline uint8_t z8_getuart(FAR struct z8_uart_s *priv, uint8_t offset) { return getreg8(*(priv->uartbase + offset)); } @@ -261,15 +264,15 @@ static inline ubyte z8_getuart(FAR struct z8_uart_s *priv, ubyte offset) * Name: z8_disableuartirq ****************************************************************************/ -static ubyte z8_disableuartirq(FAR struct uart_dev_s *dev) +static uint8_t z8_disableuartirq(FAR struct uart_dev_s *dev) { struct z8_uart_s *priv = (struct z8_uart_s*)dev->priv; irqstate_t flags = irqsave(); - ubyte state = priv->rxenabled ? STATE_RXENABLED : STATE_DISABLED | \ + uint8_t state = priv->rxenabled ? STATE_RXENABLED : STATE_DISABLED | \ priv->txenabled ? STATE_TXENABLED : STATE_DISABLED; - z8_txint(dev, FALSE); - z8_rxint(dev, FALSE); + z8_txint(dev, false); + z8_rxint(dev, false); irqrestore(flags); return state; @@ -279,13 +282,13 @@ static ubyte z8_disableuartirq(FAR struct uart_dev_s *dev) * Name: z8_restoreuartirq ****************************************************************************/ -static void z8_restoreuartirq(FAR struct uart_dev_s *dev, ubyte state) +static void z8_restoreuartirq(FAR struct uart_dev_s *dev, uint8_t state) { struct z8_uart_s *priv = (struct z8_uart_s*)dev->priv; irqstate_t flags = irqsave(); - z8_txint(dev, (state & STATE_TXENABLED) ? TRUE : FALSE); - z8_rxint(dev, (state & STATE_RXENABLED) ? TRUE : FALSE); + z8_txint(dev, (state & STATE_TXENABLED) ? true : false); + z8_rxint(dev, (state & STATE_RXENABLED) ? true : false); irqrestore(flags); } @@ -294,7 +297,7 @@ static void z8_restoreuartirq(FAR struct uart_dev_s *dev, ubyte state) * Name: z8_consoleput ****************************************************************************/ -static void z8_consoleput(ubyte ch) +static void z8_consoleput(uint8_t ch) { struct z8_uart_s *priv = (struct z8_uart_s*)CONSOLE_DEV.priv; int tmp; @@ -319,8 +322,8 @@ static void z8_consoleput(ubyte ch) void z8_uartconfigure(void) { - uint16 brg; - ubyte val; + uint16_t brg; + uint8_t val; /* Configure GPIO Port A pins 4 & 5 for alternate function */ @@ -364,10 +367,10 @@ static int z8_setup(FAR struct uart_dev_s *dev) { #ifndef CONFIG_SUPPRESS_UART_CONFIG struct z8_uart_s *priv = (struct z8_uart_s*)dev->priv; - uint32 freq = get_freq(); - uint16 brg; - ubyte ctl0; - ubyte ctl1; + uint32_t freq = get_freq(); + uint16_t brg; + uint8_t ctl0; + uint8_t ctl1; /* Calculate and set the baud rate generation register. * BRG = (freq + baud * 8)/(baud * 16) @@ -490,7 +493,7 @@ static int z8_rxinterrupt(int irq, FAR void *context) { struct uart_dev_s *dev = NULL; struct z8_uart_s *priv; - ubyte status; + uint8_t status; if (g_uart1priv.rxirq == irq) { @@ -539,7 +542,7 @@ static int z8_txinterrupt(int irq, FAR void *context) { struct uart_dev_s *dev = NULL; struct z8_uart_s *priv; - ubyte status; + uint8_t status; if (g_uart1priv.txirq == irq) { @@ -592,15 +595,15 @@ static int z8_ioctl(FAR struct file *filep, int cmd, unsigned long arg) * ****************************************************************************/ -static int z8_receive(FAR struct uart_dev_s *dev, FAR uint32 *status) +static int z8_receive(FAR struct uart_dev_s *dev, FAR uint32_t *status) { struct z8_uart_s *priv = (struct z8_uart_s*)dev->priv; - ubyte rxd; - ubyte stat0; + uint8_t rxd; + uint8_t stat0; rxd = z8_getuart(priv, Z8_UART_RXD); stat0 = z8_getuart(priv, Z8_UART_STAT0); - *status = (uint32)rxd | (((uint32)stat0) << 8); + *status = (uint32_t)rxd | (((uint32_t)stat0) << 8); return rxd; } @@ -612,7 +615,7 @@ static int z8_receive(FAR struct uart_dev_s *dev, FAR uint32 *status) * ****************************************************************************/ -static void z8_rxint(FAR struct uart_dev_s *dev, boolean enable) +static void z8_rxint(FAR struct uart_dev_s *dev, bool enable) { struct z8_uart_s *priv = (struct z8_uart_s*)dev->priv; irqstate_t flags = irqsave(); @@ -636,11 +639,11 @@ static void z8_rxint(FAR struct uart_dev_s *dev, boolean enable) * Name: z8_rxavailable * * Description: - * Return TRUE if the receive fifo is not empty + * Return true if the receive fifo is not empty * ****************************************************************************/ -static boolean z8_rxavailable(FAR struct uart_dev_s *dev) +static bool z8_rxavailable(FAR struct uart_dev_s *dev) { struct z8_uart_s *priv = (struct z8_uart_s*)dev->priv; return ((z8_getuart(priv, Z8_UART_STAT0) & Z8_UARTSTAT0_RDA) != 0); @@ -668,7 +671,7 @@ static void z8_send(FAR struct uart_dev_s *dev, int ch) * ****************************************************************************/ -static void z8_txint(FAR struct uart_dev_s *dev, boolean enable) +static void z8_txint(FAR struct uart_dev_s *dev, bool enable) { struct z8_uart_s *priv = (struct z8_uart_s*)dev->priv; irqstate_t flags = irqsave(); @@ -692,11 +695,11 @@ static void z8_txint(FAR struct uart_dev_s *dev, boolean enable) * Name: z8_txready * * Description: - * Return TRUE if the tranmsit fifo is not full + * Return true if the tranmsit fifo is not full * ****************************************************************************/ -static boolean z8_txready(FAR struct uart_dev_s *dev) +static bool z8_txready(FAR struct uart_dev_s *dev) { struct z8_uart_s *priv = (struct z8_uart_s*)dev->priv; return ((z8_getuart(priv, Z8_UART_STAT0) & Z8_UARTSTAT0_TDRE) != 0); @@ -706,11 +709,11 @@ static boolean z8_txready(FAR struct uart_dev_s *dev) * Name: z8_txempty * * Description: - * Return TRUE if the transmit fifo is empty + * Return true if the transmit fifo is empty * ****************************************************************************/ -static boolean z8_txempty(FAR struct uart_dev_s *dev) +static bool z8_txempty(FAR struct uart_dev_s *dev) { struct z8_uart_s *priv = (struct z8_uart_s*)dev->priv; return ((z8_getuart(priv, Z8_UART_STAT0) & Z8_UARTSTAT0_TXE) != 0); @@ -736,7 +739,7 @@ void up_serialinit(void) (void)z8_disableuartirq(&TTYS1_DEV); /* Initialize the console for early use */ - CONSOLE_DEV.isconsole = TRUE; + CONSOLE_DEV.isconsole = true; z8_setup(&CONSOLE_DEV); /* Reigster console and tty devices */ @@ -757,7 +760,7 @@ void up_serialinit(void) int up_putc(int ch) { - ubyte state; + uint8_t state; /* Keep interrupts disabled so that we do not interfere with normal * driver operation @@ -776,7 +779,7 @@ int up_putc(int ch) /* Output the character */ - z8_consoleput((ubyte)ch); + z8_consoleput((uint8_t)ch); /* It is important to restore the TX interrupt while the send is pending. * otherwise, TRDE interrupts can be lost since they do not pend after the @@ -797,12 +800,12 @@ int up_putc(int ch) # define z8_contrde() \ ((getreg8(*(Z8_UART1_BASE+Z8_UART_STAT0)) & Z8_UARTSTAT0_TDRE) != 0) # define z8_contxd(ch) \ - putreg8((ubyte)(ch), *(Z8_UART1_BASE+Z8_UART_TXD)) + putreg8((uint8_t)(ch), *(Z8_UART1_BASE+Z8_UART_TXD)) #else # define z8_contrde() \ ((getreg8(*(Z8_UART0_BASE+Z8_UART_STAT0)) & Z8_UARTSTAT0_TDRE) != 0) # define z8_contxd(ch) \ - putreg8((ubyte)(ch), *(Z8_UART0_BASE+Z8_UART_TXD)) + putreg8((uint8_t)(ch), *(Z8_UART0_BASE+Z8_UART_TXD)) #endif /**************************************************************************** diff --git a/nuttx/arch/z80/src/z8/z8_sigdeliver.c b/nuttx/arch/z80/src/z8/z8_sigdeliver.c index 7e7700ed1..badb8a328 100644 --- a/nuttx/arch/z80/src/z8/z8_sigdeliver.c +++ b/nuttx/arch/z80/src/z8/z8_sigdeliver.c @@ -1,7 +1,7 @@ /**************************************************************************** * arch/z80/src/z8/z8_sigdeliver.c * - * Copyright (C) 2008 Gregory Nutt. All rights reserved. + * Copyright (C) 2008-2009 Gregory Nutt. All rights reserved. * Author: Gregory Nutt <spudmonkey@racsa.co.cr> * * Redistribution and use in source and binary forms, with or without @@ -39,7 +39,6 @@ #include <nuttx/config.h> -#include <sys/types.h> #include <sched.h> #include <debug.h> diff --git a/nuttx/arch/z80/src/z8/z8_timerisr.c b/nuttx/arch/z80/src/z8/z8_timerisr.c index 7bccbafdc..a317cf3b9 100644 --- a/nuttx/arch/z80/src/z8/z8_timerisr.c +++ b/nuttx/arch/z80/src/z8/z8_timerisr.c @@ -1,7 +1,7 @@ /*************************************************************************** * arch/z80/src/z8/z8_timerisr.c * - * Copyright (C) 2008 Gregory Nutt. All rights reserved. + * Copyright (C) 2008-2009 Gregory Nutt. All rights reserved. * Author: Gregory Nutt <spudmonkey@racsa.co.cr> * * Redistribution and use in source and binary forms, with or without @@ -39,7 +39,7 @@ #include <nuttx/config.h> -#include <sys/types.h> +#include <stdint.h> #include <debug.h> #include <ez8.h> @@ -67,7 +67,7 @@ /* This function is normally prototyped int the ZiLOG header file sio.h */ -extern uint32 get_freq(void); +extern uint32_t get_freq(void); /*************************************************************************** * Function: up_timerisr @@ -78,7 +78,7 @@ extern uint32 get_freq(void); * ***************************************************************************/ -int up_timerisr(int irq, uint32 *regs) +int up_timerisr(int irq, uint32_t *regs) { /* Process timer interrupt */ @@ -97,7 +97,7 @@ int up_timerisr(int irq, uint32 *regs) void up_timerinit(void) { - uint32 reload; + uint32_t reload; up_disable_irq(Z8_IRQ_SYSTIMER); @@ -129,7 +129,7 @@ void up_timerinit(void) */ reload = get_freq() / 400; - putreg16((uint16)reload, T0R); + putreg16((uint16_t)reload, T0R); /* Write to the timer control register to enable the timer and to * initiate counting |