From: asterix Date: Tue, 31 Mar 2009 09:16:14 +0000 (+0000) Subject: Move sipo driver to generic bertos driver dir. X-Git-Tag: 2.1.0~236 X-Git-Url: https://codewiz.org/gitweb?a=commitdiff_plain;h=2aa5b04dcc5daad2409bf2027541704b56a85f13;p=bertos.git Move sipo driver to generic bertos driver dir. git-svn-id: https://src.develer.com/svnoss/bertos/trunk@2446 38d2e660-2303-0410-9eaa-f027e97ec537 --- diff --git a/bertos/cpu/avr/drv/sipo.c b/bertos/cpu/avr/drv/sipo.c deleted file mode 100644 index cb821692..00000000 --- a/bertos/cpu/avr/drv/sipo.c +++ /dev/null @@ -1,107 +0,0 @@ -/** - * \file - * - * - * \version $Id$ - * - * \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 - */ - -#include "sipo.h" - -#include "hw/hw_sipo.h" - -#include - -#include - -#include - -/** - * Write a char in sipo shift register - */ -INLINE void sipo_putchar(uint8_t c) -{ - for(int i = 0; i < 8; i++) - { - if((c & BV(i)) == 0) - SIPO_SI_LOW(); - else - SIPO_SI_HIGH(); - - 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 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(); - -} diff --git a/bertos/cpu/avr/drv/sipo.h b/bertos/cpu/avr/drv/sipo.h deleted file mode 100644 index ab5100f4..00000000 --- a/bertos/cpu/avr/drv/sipo.h +++ /dev/null @@ -1,71 +0,0 @@ -/** - * \file - * - * - * \brief Macro for SIPO_H - * - * - * \version $Id$ - * - * \author Daniele Basile - */ - -#ifndef DRV_SIPO_H -#define DRV_SIPO_H - -#include - -/** - * 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(Sipo *fd); - -#endif // DRV_SIPO_H - diff --git a/bertos/drv/sipo.c b/bertos/drv/sipo.c new file mode 100644 index 00000000..cb821692 --- /dev/null +++ b/bertos/drv/sipo.c @@ -0,0 +1,107 @@ +/** + * \file + * + * + * \version $Id$ + * + * \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 + */ + +#include "sipo.h" + +#include "hw/hw_sipo.h" + +#include + +#include + +#include + +/** + * Write a char in sipo shift register + */ +INLINE void sipo_putchar(uint8_t c) +{ + for(int i = 0; i < 8; i++) + { + if((c & BV(i)) == 0) + SIPO_SI_LOW(); + else + SIPO_SI_HIGH(); + + 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 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(); + +} diff --git a/bertos/drv/sipo.h b/bertos/drv/sipo.h new file mode 100644 index 00000000..ab5100f4 --- /dev/null +++ b/bertos/drv/sipo.h @@ -0,0 +1,71 @@ +/** + * \file + * + * + * \brief Macro for SIPO_H + * + * + * \version $Id$ + * + * \author Daniele Basile + */ + +#ifndef DRV_SIPO_H +#define DRV_SIPO_H + +#include + +/** + * 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(Sipo *fd); + +#endif // DRV_SIPO_H +