*
* \version $Id$
*
- * \author Andrea Grandi <andrea@develer.com>
- *
* \brief SIPO Module
*
* The SIPO module trasform a serial input in
* a parallel output. Please check hw_sipo.h
* file to customize hardware relative parameters.
*
+ * \author Daniele Basile <asterix@develer.com>
*/
#include "sipo.h"
+
#include "hw/hw_sipo.h"
-#include <drv/ser.h>
+#include <cfg/compiler.h>
-Serial *sipo_port;
+#include <kern/kfile.h>
-/** Initialize the SIPO port */
-void sipo_init(void)
-{
- CLOCK_LOW;
- SET_SOUT_LOW;
- LOAD_LOW;
- SET_SCK_OUT;
- SET_SOUT_OUT;
- LOAD_INIT;
- sipo_putchar(0x0);
- OE_OUT;
- OE_LOW;
-}
+#include <string.h>
-/** Write a char in the SIPO port and manage the LOAD pin */
-void sipo_putchar(uint8_t c)
+/**
+ * Write a char in sipo shift register
+ */
+INLINE void sipo_putchar(uint8_t c)
{
- for(int i = 0; i <= 7; i++)
+ for(int i = 0; i < 8; i++)
{
if((c & BV(i)) == 0)
- {
- SET_SOUT_LOW;
- }
+ SIPO_SI_LOW();
else
- {
- SET_SOUT_HIGH;
- }
+ SIPO_SI_HIGH();
- CLOCK_PULSE;
+ SIPO_SI_CLOCK();
}
+}
+
+/**
+ * Write a buffer into sipo register and when finish to
+ * we load it.
+ */
+ static size_t sipo_write(UNUSED_ARG(struct KFile *, fd), const void *_buf, size_t size)
+{
+ const uint8_t *buf = (const uint8_t *)_buf;
+ size_t write_len = size;
+ ASSERT(buf);
- LOAD_HIGH;
- LOAD_LOW;
+ // Load into shift register all byte in buffer
+ while(size--)
+ sipo_putchar(*buf++);
+
+ // We finsh to load bytes into shift register, load it.
+ SIPO_LOAD();
+
+ return write_len;
}
+/**
+ * Initialize the SIPO
+ */
+void sipo_init(Sipo *fd)
+{
+ ASSERT(fd);
+
+ memset(fd, 0, sizeof(Sipo));
+
+ //Set kfile struct type as a generic kfile structure.
+ DB(fd->fd._type = KFT_SIPO);
+
+ // Set up data flash programming functions.
+ fd->fd.write = sipo_write;
+
+ SIPO_INIT_PIN();
+
+}
*
* \version $Id$
*
- * \author Andrea Grandi <andrea@develer.com>
+ * \author Daniele Basile <asterix@develer.com>
*/
-#ifndef SIPO_H
-#define SIPO_H
+#ifndef DRV_SIPO_H
+#define DRV_SIPO_H
-#include "hw/hw_sipo.h"
+#include <kern/kfile.h>
-#include <avr/io.h>
+/**
+ * Sipo KFile context structure.
+ */
+typedef struct Sipo
+{
+ KFile fd; ///< File descriptor.
+} Sipo;
+
+/**
+ * ID for sipo.
+ */
+#define KFT_SIPO MAKE_ID('S', 'I', 'P', 'O')
+
+/**
+ * Convert + ASSERT from generic KFile to Sipo.
+ */
+INLINE Sipo * SIPO_CAST(KFile *fd)
+{
+ ASSERT(fd->_type == KFT_SIPO);
+ return (Sipo *)fd;
+}
-void sipo_init(void);
-void sipo_putchar(uint8_t c);
+void sipo_init(Sipo *fd);
-#endif // SIPO_H
+#endif // DRV_SIPO_H
* the GNU General Public License.
*
* Copyright 2003, 2004, 2006, 2008 Develer S.r.l. (http://www.develer.com/)
- * Copyright 2000 Bernie Innocenti <bernie@codewiz.org>
+ * Copyright 2000 Bernardo Innocenti <bernie@codewiz.org>
* All Rights Reserved.
* -->
*
*
* \version $Id$
*
- * \author Andrea Grandi <andrea@develer.com>
+ * \author Daniele Basile <asterix@develer.com>
*/
#ifndef HW_SIPO_H
#warning TODO:This is an example implementation, you must implement it!
-#define LOAD_HIGH /* Implement me! */
-#define LOAD_LOW /* Implement me! */
-#define LOAD_INIT /* Implement me! */
-#define SET_SCK_OUT /* Implement me! */
-#define SET_SOUT_OUT /* Implement me! */
-#define CLOCK_HIGH /* Implement me! */
-#define CLOCK_LOW /* Implement me! */
-#define SET_SOUT_HIGH /* Implement me! */
-#define SET_SOUT_LOW /* Implement me! */
-#define CLOCK_PULSE /* Implement me! */
-#define OE_OUT
-#define OE_LOW
+/**
+ * Define the procedure to set one bit low/hight to
+ * serial input in sipo device.
+ */
+#define SIPO_SI_HIGH()/* Implement me! */
+#define SIPO_SI_LOW() /* Implement me! */
+
+/**
+ * Drive pin to load the bit, presented in serial-in pin,
+ * into sipo shift register.
+ */
+#define SIPO_SI_CLOCK() /* Implement me! */
+
+/**
+ * Clock the content of shift register to output.
+ */
+#define SIPO_LOAD() /* Implement me! */
+
+/**
+ * Enable the shift register output.
+ */
+#define SIPO_ENABLE() /* Implement me! */
+/**
+ * Do anything that needed to init sipo pins.
+ */
+#define SIPO_INIT_PIN() \
+ do { \
+ /* Implement me! */ \
+ } while(0)
+
#endif /* HW_SIPO_H */