+++ /dev/null
-/**
- * \file
- * <!--
- * This file is part of BeRTOS.
- *
- * Bertos is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
- *
- * As a special exception, you may use this file as part of a free software
- * library without restriction. Specifically, if other files instantiate
- * templates or use macros or inline functions from this file, or you compile
- * this file and link it with other files to produce an executable, this
- * file does not by itself cause the resulting executable to be covered by
- * the GNU General Public License. This exception does not however
- * invalidate any other reasons why the executable file might be covered by
- * the GNU General Public License.
- *
- * Copyright 2008 Develer S.r.l. (http://www.develer.com/)
- * All Rights Reserved.
- * -->
- *
- * \brief Low level test for stepper driver interface implementation.
- *
- * \version $Id$
- *
- * \author Daniele Basile <asterix@develer.com>
- */
-
-#include "stepper_at91.h"
-
-#include "cfg/cfg_stepper.h"
-#include <cfg/macros.h>
-#include <cfg/debug.h>
-
-#include <cpu/types.h>
-#include <cpu/irq.h>
-
-#include <io/arm.h>
-
-
-#warning FIXME:This test is incomplete.. you MUST review..
-
-#if 0
-static void stepper_test_irq_schedule(struct Stepper *motor, stepper_time_t delay)
-{
- stepper_tc_doPulse(motor->timer);
- stepper_tc_setDelay(motor->timer, delay);
-}
-
-static void stepper_test_irq(struct Stepper *motor)
-{
-
- stepper_test_irq_schedule(motor, 300);
-}
-/*
- * Test a timer couter driver
- */
-void stepper_timer_test_prestepper(struct Stepper *local_motor, struct StepperConfig *local_cfg, int index)
-{
- local_cfg->pulse = 300;
-
- local_motor->cfg = local_cfg;
- stepper_tc_init(index, &stepper_test_irq, local_motor);
- stepper_tc_irq_enable(local_motor->timer);
-}
-
-
-bool su = true;
-bool sub = true;
-uint16_t periodo_st0 = 100;
-uint16_t periodo_st1 = 233;
-
-static void tc_irq(void) __attribute__ ((interrupt));
-static void tc_irq(void)
-{
- uint32_t status_reg = TC2_SR & TC2_IMR;
-
- if (status_reg & BV(TC_CPAS))
- {
- TC2_CMR &= ~TC_ACPA_MASK;
- if (su)
- {
- TC2_CMR |= TC_ACPA_CLEAR_OUTPUT;
- TC2_RA += periodo_st0;
- }
- else
- {
- TC2_CMR |= TC_ACPA_SET_OUTPUT;
- TC2_RA += periodo_st1;
- }
- su = !su;
- }
- if (status_reg & BV(TC_CPBS))
- {
- TC2_CMR &= ~TC_BCPB_MASK ;
- if (sub)
- {
- TC2_CMR |= TC_BCPB_CLEAR_OUTPUT;
- TC2_RB += periodo_st0;
- }
- else
- {
- TC2_CMR |= TC_BCPB_SET_OUTPUT;
- TC2_RB += periodo_st1;
- }
- sub = !sub;
- }
- /* Inform hw that we have served the IRQ */
- AIC_EOICR = 0;
-}
-
-/*
- * Test a timer couter hardware
- */
-void stepper_timer_test_brute(void)
-{
- PIOA_PDR |= BV(26) | BV(27);
- PIOA_BSR |= BV(26) | BV(27);
-
- // Power on TCLK0
- PMC_PCER |= BV(TC2_ID);// | BV(TC1_ID) | BV(TC2_ID);
-
- TC_BCR = 1;
- TC_BMR |= TC_NONEXC2;
-
- // Select waveform mode
- TC2_CMR = BV(TC_WAVE);
-
- TC2_CMR |= TC_EEVT_XC2;
- TC2_CMR |= TC_WAVSEL_UP;
- TC2_CMR |= TC_CLKS_MCK8;
-
- //Set waveform on TIOA and TIOB
- TC2_CMR |= TC_ACPA_SET_OUTPUT;
- TC2_CMR |= TC_BCPB_SET_OUTPUT;
-
-
- //Reset all comp_reg register
- TC2_RA = 0;
- TC2_RB = 0;
-
- cpu_flags_t flags;
- IRQ_SAVE_DISABLE(flags);
-
- /* Set the vector. */
- AIC_SVR(TC2_ID) = tc_irq;
- /* Initialize to edge triggered with defined priority. */
- AIC_SMR(TC2_ID) = AIC_SRCTYPE_INT_EDGE_TRIGGERED;
- /* Enable the USART IRQ */
- AIC_IECR = BV(TC2_ID);
-
- IRQ_RESTORE(flags);
-
- // Disable all interrupt
- TC2_IDR = 0xFFFFFFFF;
-
- //Enable interrupt on RA, RB
- TC2_IER = BV(TC_CPAS) | BV(TC_CPBS);
-
- //Enable timer and trig it
- TC2_CCR = BV(TC_CLKEN) | BV(TC_SWTRG);
-}
-#endif
-
--- /dev/null
+/**
+ * \file
+ * <!--
+ * This file is part of BeRTOS.
+ *
+ * Bertos is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * As a special exception, you may use this file as part of a free software
+ * library without restriction. Specifically, if other files instantiate
+ * templates or use macros or inline functions from this file, or you compile
+ * this file and link it with other files to produce an executable, this
+ * file does not by itself cause the resulting executable to be covered by
+ * the GNU General Public License. This exception does not however
+ * invalidate any other reasons why the executable file might be covered by
+ * the GNU General Public License.
+ *
+ * Copyright 2008 Develer S.r.l. (http://www.develer.com/)
+ * All Rights Reserved.
+ * -->
+ *
+ * \brief Low level test for stepper driver interface implementation.
+ *
+ * \version $Id$
+ *
+ * \author Daniele Basile <asterix@develer.com>
+ */
+
+#include "stepper_at91.h"
+
+#include "cfg/cfg_stepper.h"
+#include <cfg/macros.h>
+#include <cfg/debug.h>
+
+#include <cpu/types.h>
+#include <cpu/irq.h>
+
+#include <io/arm.h>
+
+
+#warning FIXME:This test is incomplete.. you MUST review..
+
+#if 0
+static void stepper_test_irq_schedule(struct Stepper *motor, stepper_time_t delay)
+{
+ stepper_tc_doPulse(motor->timer);
+ stepper_tc_setDelay(motor->timer, delay);
+}
+
+static void stepper_test_irq(struct Stepper *motor)
+{
+
+ stepper_test_irq_schedule(motor, 300);
+}
+/*
+ * Test a timer couter driver
+ */
+void stepper_timer_test_prestepper(struct Stepper *local_motor, struct StepperConfig *local_cfg, int index)
+{
+ local_cfg->pulse = 300;
+
+ local_motor->cfg = local_cfg;
+ stepper_tc_init(index, &stepper_test_irq, local_motor);
+ stepper_tc_irq_enable(local_motor->timer);
+}
+
+
+bool su = true;
+bool sub = true;
+uint16_t periodo_st0 = 100;
+uint16_t periodo_st1 = 233;
+
+static void tc_irq(void) __attribute__ ((interrupt));
+static void tc_irq(void)
+{
+ uint32_t status_reg = TC2_SR & TC2_IMR;
+
+ if (status_reg & BV(TC_CPAS))
+ {
+ TC2_CMR &= ~TC_ACPA_MASK;
+ if (su)
+ {
+ TC2_CMR |= TC_ACPA_CLEAR_OUTPUT;
+ TC2_RA += periodo_st0;
+ }
+ else
+ {
+ TC2_CMR |= TC_ACPA_SET_OUTPUT;
+ TC2_RA += periodo_st1;
+ }
+ su = !su;
+ }
+ if (status_reg & BV(TC_CPBS))
+ {
+ TC2_CMR &= ~TC_BCPB_MASK ;
+ if (sub)
+ {
+ TC2_CMR |= TC_BCPB_CLEAR_OUTPUT;
+ TC2_RB += periodo_st0;
+ }
+ else
+ {
+ TC2_CMR |= TC_BCPB_SET_OUTPUT;
+ TC2_RB += periodo_st1;
+ }
+ sub = !sub;
+ }
+ /* Inform hw that we have served the IRQ */
+ AIC_EOICR = 0;
+}
+
+/*
+ * Test a timer couter hardware
+ */
+void stepper_timer_test_brute(void)
+{
+ PIOA_PDR |= BV(26) | BV(27);
+ PIOA_BSR |= BV(26) | BV(27);
+
+ // Power on TCLK0
+ PMC_PCER |= BV(TC2_ID);// | BV(TC1_ID) | BV(TC2_ID);
+
+ TC_BCR = 1;
+ TC_BMR |= TC_NONEXC2;
+
+ // Select waveform mode
+ TC2_CMR = BV(TC_WAVE);
+
+ TC2_CMR |= TC_EEVT_XC2;
+ TC2_CMR |= TC_WAVSEL_UP;
+ TC2_CMR |= TC_CLKS_MCK8;
+
+ //Set waveform on TIOA and TIOB
+ TC2_CMR |= TC_ACPA_SET_OUTPUT;
+ TC2_CMR |= TC_BCPB_SET_OUTPUT;
+
+
+ //Reset all comp_reg register
+ TC2_RA = 0;
+ TC2_RB = 0;
+
+ cpuflags_t flags;
+ IRQ_SAVE_DISABLE(flags);
+
+ /* Set the vector. */
+ AIC_SVR(TC2_ID) = tc_irq;
+ /* Initialize to edge triggered with defined priority. */
+ AIC_SMR(TC2_ID) = AIC_SRCTYPE_INT_EDGE_TRIGGERED;
+ /* Enable the USART IRQ */
+ AIC_IECR = BV(TC2_ID);
+
+ IRQ_RESTORE(flags);
+
+ // Disable all interrupt
+ TC2_IDR = 0xFFFFFFFF;
+
+ //Enable interrupt on RA, RB
+ TC2_IER = BV(TC_CPAS) | BV(TC_CPBS);
+
+ //Enable timer and trig it
+ TC2_CCR = BV(TC_CLKEN) | BV(TC_SWTRG);
+}
+#endif
+
--- /dev/null
+/**
+ * \file
+ * <!--
+ * This file is part of BeRTOS.
+ *
+ * Bertos is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * As a special exception, you may use this file as part of a free software
+ * library without restriction. Specifically, if other files instantiate
+ * templates or use macros or inline functions from this file, or you compile
+ * this file and link it with other files to produce an executable, this
+ * file does not by itself cause the resulting executable to be covered by
+ * the GNU General Public License. This exception does not however
+ * invalidate any other reasons why the executable file might be covered by
+ * the GNU General Public License.
+ *
+ * Copyright 2008 Develer S.r.l. (http://www.develer.com/)
+ *
+ * -->
+ *
+ * \brief DataFlash test.
+ *
+ * This module test the dataflash memory among the supported memory (see drv/dataflash.h
+ * for more detail).
+ * To test memory we fill one buffer with casual char, and write it in different
+ * part of memory. After every write we read the data that we have been write
+ * and compare this with test buffer, checking if write and read command work
+ * correclty. We also check if driver work properly when we make a write out the
+ * limit of memory size.
+ *
+ * Note: dataflash driver use a kfile interface, so for write/read test
+ * we use a kfile_test module that perform some generic test.
+ *
+ *
+ * \version $Id$
+ * \author Daniele Basile <asterix@develer.com>
+ */
+
+#include "hw/hw_dataflash.h"
+#include "cfg/cfg_dataflash.h"
+#include "cfg/cfg_kern.h"
+
+#include <cfg/test.h>
+#include <cfg/debug.h>
+#include <cfg/module.h>
+
+// Define logging setting (for cfg/log.h module).
+#define LOG_LEVEL DATAFLASH_LOG_LEVEL
+#define LOG_FORMAT DATAFLASH_LOG_FORMAT
+#include <cfg/log.h> // for logging system
+
+#include <drv/timer.h>
+#include <drv/ser.h>
+#include <drv/dataflash.h>
+
+#include <kern/proc.h>
+#include <kern/kfile.h>
+
+#include <string.h>
+
+/*
+ * Settings for dataflash test
+ *
+ * \{
+ */
+// Datafalsh type memory to test (see drv/dataflash.h for supported memory types)
+#define DATAFLASH_MEM_MODEL DFT_AT45DB642D
+
+// Function to set CS, this is typically implement in hw/hw_dataflash.{c, h}
+#define DATAFLASH_FUNC_CS_SET &dataflash_hw_setCS
+
+// Function to reset memery, this is typically implement in hw/hw_dataflash.{c, h}
+#define DATAFLASH_FUNC_RESET NULL
+
+// Buffer len to test dataflash
+#define DATAFLASH_TEST_STR_LEN 12307
+
+// If you want use a rand function of standard library set to 1.
+#define DATAFLASH_USE_RAND_FUNC 0
+/* \} */
+
+/*
+ * Kfile structure to test a dataflash.
+ */
+static Serial spi_fd;
+static DataFlash dflash_fd;
+
+/*
+ * Define tmp buffer to stora data for
+ * write and read flash memory test.
+ */
+static uint8_t test_buf[DATAFLASH_TEST_STR_LEN];
+static uint8_t save_buf[DATAFLASH_TEST_STR_LEN];
+
+/**
+ * Setup all needed to test dataflash memory
+ *
+ */
+int dataflash_testSetUp(void)
+{
+ kfile_testSetUp();
+ LOG_INFO("KFILE setup..ok\n");
+
+ LOG_INFO("Check if kernel is enable (if enable you should see the assert message.)\n");
+ SILENT_ASSERT("bertos/drv/dataflash_test.c:119: Assertion failed: !CONFIG_KERN");
+ ASSERT(!CONFIG_KERN);
+
+ /*
+ * This test use a kfile_test module,
+ * so should include source in your makefile.
+ */
+ MOD_CHECK(kfile_test);
+
+ timer_init();
+ LOG_INFO("Timer init..ok\n");
+
+ /*
+ * Init SPI module and dataflash driver.
+ */
+ // Open SPI comunication channel
+ spimaster_init(&spi_fd, CONFIG_SPI_PORT);
+ LOG_INFO("SPI0 init..ok\n");
+
+ ser_setbaudrate(&spi_fd, CONFIG_SPI_BAUDRATE);
+ LOG_INFO("SPI0 set baudrate..ok\n");
+
+ //Init dataflash memory
+ dataflash_hw_init();
+ LOG_INFO("DATAFLASH HW..ok\n");
+
+ if (dataflash_init(&dflash_fd, &spi_fd.fd, DATAFLASH_MEM_MODEL, DATAFLASH_FUNC_CS_SET, DATAFLASH_FUNC_RESET))
+ LOG_INFO("DATAFLASH init..ok\n");
+ else
+ LOG_ERR("DATAFLASH init..fail\n");
+
+
+ //Fill tmp buffer with rand chars.
+ for (int i = 0; i < DATAFLASH_TEST_STR_LEN; i++)
+ {
+ #if DATAFLASH_USE_RAND_FUNC
+ #include <stdlib.h> //Rand()
+
+ test_buf[i] = (uint8_t)rand();
+ #else
+ test_buf[i] = (i & 0xff);
+ #endif
+ }
+
+ LOG_INFO("Fill tmp buff..ok\n");
+
+ return 0;
+}
+
+
+/**
+ * Run dataflash test memory
+ *
+ */
+int dataflash_testRun(void)
+{
+ LOG_INFO("Run KFILE test.\n");
+
+ SILENT_ASSERT("bertos/drv/dataflash.c:405: Assertion failed: fd->fd.seek_pos + size <= fd->fd.size");
+ if (kfile_testRun(&dflash_fd.fd, test_buf, save_buf, sizeof(test_buf)) != EOF)
+ {
+ LOG_INFO("KFILE test..ok\n");
+ }
+ else
+ {
+ LOG_ERR("KFILE test..fail!\n");
+ return EOF;
+ }
+
+ return 0;
+}
+
+/**
+ * End a dataflash Test.
+ * (Unused)
+ */
+int dataflash_testTearDown(void)
+{
+ /* */
+ return 0;
+}
+
+/*
+ * Empty main.
+ *
+ * Look it as exmple, or use it if
+ * you want test a data flash driver stand alone.
+ */
+#if 0
+int main(void)
+{
+ IRQ_ENABLE;
+ kdbg_init();
+
+ #if CONFIG_KERN
+ proc_init();
+ #endif
+
+ if (!dataflash_testSetUp())
+ {
+ LOG_INFO("DATAFLASH setup..ok\n");
+ }
+ else
+ {
+ LOG_ERR("DATAFLASH setup..fail!\n");
+ return EOF;
+ }
+
+ dataflash_testRun();
+
+ for(;;)
+ {
+ }
+
+}
+#endif
+++ /dev/null
-/**
- * \file
- * <!--
- * This file is part of BeRTOS.
- *
- * Bertos is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
- *
- * As a special exception, you may use this file as part of a free software
- * library without restriction. Specifically, if other files instantiate
- * templates or use macros or inline functions from this file, or you compile
- * this file and link it with other files to produce an executable, this
- * file does not by itself cause the resulting executable to be covered by
- * the GNU General Public License. This exception does not however
- * invalidate any other reasons why the executable file might be covered by
- * the GNU General Public License.
- *
- * Copyright 2008 Develer S.r.l. (http://www.develer.com/)
- *
- * -->
- *
- * \brief DataFlash test.
- *
- * This module test the dataflash memory among the supported memory (see drv/dataflash.h
- * for more detail).
- * To test memory we fill one buffer with casual char, and write it in different
- * part of memory. After every write we read the data that we have been write
- * and compare this with test buffer, checking if write and read command work
- * correclty. We also check if driver work properly when we make a write out the
- * limit of memory size.
- *
- * Note: dataflash driver use a kfile interface, so for write/read test
- * we use a kfile_test module that perform some generic test.
- *
- *
- * \version $Id$
- * \author Daniele Basile <asterix@develer.com>
- */
-
-#include "hw/hw_dataflash.h"
-#include "cfg/cfg_dataflash.h"
-#include "cfg/cfg_kern.h"
-
-#include <cfg/test.h>
-#include <cfg/debug.h>
-#include <cfg/module.h>
-
-// Define logging setting (for cfg/log.h module).
-#define LOG_LEVEL DATAFLASH_LOG_LEVEL
-#define LOG_FORMAT DATAFLASH_LOG_FORMAT
-#include <cfg/log.h> // for logging system
-
-#include <drv/timer.h>
-#include <drv/ser.h>
-#include <drv/dataflash.h>
-
-#include <kern/proc.h>
-#include <kern/kfile.h>
-
-#include <string.h>
-
-/*
- * Settings for dataflash test
- *
- * \{
- */
-// Datafalsh type memory to test (see drv/dataflash.h for supported memory types)
-#define DATAFLASH_MEM_MODEL DFT_AT45DB642D
-
-// Function to set CS, this is typically implement in hw/hw_dataflash.{c, h}
-#define DATAFLASH_FUNC_CS_SET &dataflash_hw_setCS
-
-// Function to reset memery, this is typically implement in hw/hw_dataflash.{c, h}
-#define DATAFLASH_FUNC_RESET NULL
-
-// Buffer len to test dataflash
-#define DATAFLASH_TEST_STR_LEN 12307
-
-// If you want use a rand function of standard library set to 1.
-#define DATAFLASH_USE_RAND_FUNC 0
-/* \} */
-
-/*
- * Kfile structure to test a dataflash.
- */
-static Serial spi_fd;
-static DataFlash dflash_fd;
-
-/*
- * Define tmp buffer to stora data for
- * write and read flash memory test.
- */
-static uint8_t test_buf[DATAFLASH_TEST_STR_LEN];
-static uint8_t save_buf[DATAFLASH_TEST_STR_LEN];
-
-/**
- * Setup all needed to test dataflash memory
- *
- */
-int dataflash_testSetUp(void)
-{
- kfile_testSetUp();
- LOG_INFO("KFILE setup..ok\n");
-
- LOG_INFO("Check if kernel is enable (if enable you should see the assert message.)\n");
- SILENT_ASSERT("bertos/drv/dataflash_test.c:119: Assertion failed: !CONFIG_KERN");
- ASSERT(!CONFIG_KERN);
-
- /*
- * This test use a kfile_test module,
- * so should include source in your makefile.
- */
- MOD_CHECK(kfile_test);
-
- timer_init();
- LOG_INFO("Timer init..ok\n");
-
- /*
- * Init SPI module and dataflash driver.
- */
- // Open SPI comunication channel
- spimaster_init(&spi_fd, CONFIG_SPI_PORT);
- LOG_INFO("SPI0 init..ok\n");
-
- ser_setbaudrate(&spi_fd, CONFIG_SPI_BAUDRATE);
- LOG_INFO("SPI0 set baudrate..ok\n");
-
- //Init dataflash memory
- dataflash_hw_init();
- LOG_INFO("DATAFLASH HW..ok\n");
-
- if (dataflash_init(&dflash_fd, &spi_fd.fd, DATAFLASH_MEM_MODEL, DATAFLASH_FUNC_CS_SET, DATAFLASH_FUNC_RESET))
- LOG_INFO("DATAFLASH init..ok\n");
- else
- LOG_ERR("DATAFLASH init..fail\n");
-
-
- //Fill tmp buffer with rand chars.
- for (int i = 0; i < DATAFLASH_TEST_STR_LEN; i++)
- {
- #if DATAFLASH_USE_RAND_FUNC
- #include <stdlib.h> //Rand()
-
- test_buf[i] = (uint8_t)rand();
- #else
- test_buf[i] = (i & 0xff);
- #endif
- }
-
- LOG_INFO("Fill tmp buff..ok\n");
-
- return 0;
-}
-
-
-/**
- * Run dataflash test memory
- *
- */
-int dataflash_testRun(void)
-{
- LOG_INFO("Run KFILE test.\n");
-
- SILENT_ASSERT("bertos/drv/dataflash.c:405: Assertion failed: fd->fd.seek_pos + size <= fd->fd.size");
- if (kfile_testRun(&dflash_fd.fd, test_buf, save_buf, sizeof(test_buf)) != EOF)
- {
- LOG_INFO("KFILE test..ok\n");
- }
- else
- {
- LOG_ERR("KFILE test..fail!\n");
- return EOF;
- }
-
- return 0;
-}
-
-/**
- * End a dataflash Test.
- * (Unused)
- */
-int dataflash_testTearDown(void)
-{
- /* */
- return 0;
-}
-
-/*
- * Empty main.
- *
- * Look it as exmple, or use it if
- * you want test a data flash driver stand alone.
- */
-#if 0
-int main(void)
-{
- IRQ_ENABLE;
- kdbg_init();
-
- #if CONFIG_KERN
- proc_init();
- #endif
-
- if (!dataflash_testSetUp())
- {
- LOG_INFO("DATAFLASH setup..ok\n");
- }
- else
- {
- LOG_ERR("DATAFLASH setup..fail!\n");
- return EOF;
- }
-
- dataflash_testRun();
-
- for(;;)
- {
- }
-
-}
-#endif
--- /dev/null
+/**
+ * \file
+ * <!--
+ * This file is part of BeRTOS.
+ *
+ * Bertos is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * As a special exception, you may use this file as part of a free software
+ * library without restriction. Specifically, if other files instantiate
+ * templates or use macros or inline functions from this file, or you compile
+ * this file and link it with other files to produce an executable, this
+ * file does not by itself cause the resulting executable to be covered by
+ * the GNU General Public License. This exception does not however
+ * invalidate any other reasons why the executable file might be covered by
+ * the GNU General Public License.
+ *
+ * Copyright 2007 Develer S.r.l. (http://www.develer.com/)
+ *
+ * -->
+ *
+ * \brief Test function for serial Flash memory.
+ *
+ * \version $Id$
+ * \author Daniele Basile <asterix@develer.com>
+ */
+
+/**
+ * Test function for flash25.
+ *
+ * \note: This implentation use a SPI channel.
+ */
+
+
+#include <kern/kfile.h>
+
+#include <drv/flash25.h>
+
+#include <cfg/debug.h>
+
+#warning FIXME:Review and refactor this test..
+
+bool flash25_test(KFile *channel)
+{
+ Flash25 fd;
+ uint8_t test_buf[256];
+
+ /*
+ * Init a spi kfile interface and
+ * flash driver.
+ */
+ flash25_init(&fd, channel);
+
+ kprintf("Init serial flash\n");
+
+ flash25_chipErase(&fd);
+
+ flash25_sectorErase(&fd, FLASH25_SECT1);
+ flash25_sectorErase(&fd, FLASH25_SECT2);
+ flash25_sectorErase(&fd, FLASH25_SECT3);
+ flash25_sectorErase(&fd, FLASH25_SECT4);
+
+ /*
+ * Launche a kfile test interface.
+ */
+ kprintf("Kfile test start..\n");
+ if (!kfile_testRun(&fd.fd, test_buf, NULL, sizeof(test_buf)))
+ return false;
+
+ return true;
+}
+
+
+++ /dev/null
-/**
- * \file
- * <!--
- * This file is part of BeRTOS.
- *
- * Bertos is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
- *
- * As a special exception, you may use this file as part of a free software
- * library without restriction. Specifically, if other files instantiate
- * templates or use macros or inline functions from this file, or you compile
- * this file and link it with other files to produce an executable, this
- * file does not by itself cause the resulting executable to be covered by
- * the GNU General Public License. This exception does not however
- * invalidate any other reasons why the executable file might be covered by
- * the GNU General Public License.
- *
- * Copyright 2007 Develer S.r.l. (http://www.develer.com/)
- *
- * -->
- *
- * \brief Test function for serial Flash memory.
- *
- * \version $Id$
- * \author Daniele Basile <asterix@develer.com>
- */
-
-/**
- * Test function for flash25.
- *
- * \note: This implentation use a SPI channel.
- */
-
-
-#include <kern/kfile.h>
-
-#include <drv/flash25.h>
-
-#include <cfg/debug.h>
-
-#warning FIXME:Review and refactor this test..
-
-bool flash25_test(KFile *channel)
-{
- Flash25 fd;
- uint8_t test_buf[256];
-
- /*
- * Init a spi kfile interface and
- * flash driver.
- */
- flash25_init(&fd, channel);
-
- kprintf("Init serial flash\n");
-
- flash25_chipErase(&fd);
-
- flash25_sectorErase(&fd, FLASH25_SECT1);
- flash25_sectorErase(&fd, FLASH25_SECT2);
- flash25_sectorErase(&fd, FLASH25_SECT3);
- flash25_sectorErase(&fd, FLASH25_SECT4);
-
- /*
- * Launche a kfile test interface.
- */
- kprintf("Kfile test start..\n");
- if (!kfile_testRun(&fd.fd, test_buf, NULL, sizeof(test_buf)))
- return false;
-
- return true;
-}
-
-
--- /dev/null
+/**
+ * \file
+ * <!--
+ * This file is part of BeRTOS.
+ *
+ * Bertos is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * As a special exception, you may use this file as part of a free software
+ * library without restriction. Specifically, if other files instantiate
+ * templates or use macros or inline functions from this file, or you compile
+ * this file and link it with other files to produce an executable, this
+ * file does not by itself cause the resulting executable to be covered by
+ * the GNU General Public License. This exception does not however
+ * invalidate any other reasons why the executable file might be covered by
+ * the GNU General Public License.
+ *
+ * Copyright 2005 Develer S.r.l. (http://www.develer.com/)
+ *
+ * -->
+ *
+ * \brief LM044L type LCD hardware module (impl.)
+ *
+ * \version $Id$
+ * \author Bernie Innocenti <bernie@codewiz.org>
+ * \author Stefano Fedrigo <aleph@develer.com>
+ */
+
+#include "lcd_hd44.h"
+#include "hw/hw_lcd.h"
+
+#include <cfg/test.h>
+#include <drv/timer.h>
+
+#warning TODO:Refactor this test to comply whit BeRTOS test policy.
+
+#if UNIT_TEST
+
+void lcd_hw_test(void)
+{
+ lcd_regWrite(LCD_CMD_SET_DDRAMADDR | 3);
+ timer_delay(1);
+ kprintf("3 -> %02X\n", lcd_regRead());
+ timer_delay(1);
+
+ for (int i = 0; i < 10; i++)
+ {
+ lcd_dataWrite('c');
+ timer_delay(1);
+ kprintf("addr = %02X\n", lcd_regRead());
+ timer_delay(1);
+ }
+
+ lcd_regWrite(LCD_CMD_SET_DDRAMADDR | 0x4a);
+ timer_delay(1);
+ kprintf("4A -> %02X\n", lcd_regRead());
+ timer_delay(1);
+
+ lcd_regWrite(LCD_CMD_SET_DDRAMADDR | 0x52);
+ timer_delay(1);
+ kprintf("52 -> %02X\n", lcd_regRead());
+ timer_delay(1);
+
+ lcd_regWrite(LCD_CMD_SET_DDRAMADDR | 0x1F);
+ timer_delay(1);
+ kprintf("1F -> %02X\n", lcd_regRead());
+ timer_delay(1);
+}
+
+
+
+#include <drv/timer.c>
+#include <drv/lcd_hd44.c>
+
+int main(void)
+{
+ lcd_hw_test();
+
+ for(;;)
+ {
+ }
+
+ return 0;
+}
+
+#endif
+++ /dev/null
-/**
- * \file
- * <!--
- * This file is part of BeRTOS.
- *
- * Bertos is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
- *
- * As a special exception, you may use this file as part of a free software
- * library without restriction. Specifically, if other files instantiate
- * templates or use macros or inline functions from this file, or you compile
- * this file and link it with other files to produce an executable, this
- * file does not by itself cause the resulting executable to be covered by
- * the GNU General Public License. This exception does not however
- * invalidate any other reasons why the executable file might be covered by
- * the GNU General Public License.
- *
- * Copyright 2005 Develer S.r.l. (http://www.develer.com/)
- *
- * -->
- *
- * \brief LM044L type LCD hardware module (impl.)
- *
- * \version $Id$
- * \author Bernie Innocenti <bernie@codewiz.org>
- * \author Stefano Fedrigo <aleph@develer.com>
- */
-
-#include "lcd_hd44.h"
-#include "hw/hw_lcd.h"
-
-#include <cfg/test.h>
-#include <drv/timer.h>
-
-#warning TODO:Refactor this test to comply whit BeRTOS test policy.
-
-#if UNIT_TEST
-
-void lcd_hw_test(void)
-{
- lcd_regWrite(LCD_CMD_SET_DDRAMADDR | 3);
- timer_delay(1);
- kprintf("3 -> %02X\n", lcd_regRead());
- timer_delay(1);
-
- for (int i = 0; i < 10; i++)
- {
- lcd_dataWrite('c');
- timer_delay(1);
- kprintf("addr = %02X\n", lcd_regRead());
- timer_delay(1);
- }
-
- lcd_regWrite(LCD_CMD_SET_DDRAMADDR | 0x4a);
- timer_delay(1);
- kprintf("4A -> %02X\n", lcd_regRead());
- timer_delay(1);
-
- lcd_regWrite(LCD_CMD_SET_DDRAMADDR | 0x52);
- timer_delay(1);
- kprintf("52 -> %02X\n", lcd_regRead());
- timer_delay(1);
-
- lcd_regWrite(LCD_CMD_SET_DDRAMADDR | 0x1F);
- timer_delay(1);
- kprintf("1F -> %02X\n", lcd_regRead());
- timer_delay(1);
-}
-
-
-
-#include <drv/timer.c>
-#include <drv/lcd_hd44.c>
-
-int main(void)
-{
- lcd_hw_test();
-
- for(;;)
- {
- }
-
- return 0;
-}
-
-#endif
--- /dev/null
+/**
+ * \file
+ * <!--
+ * This file is part of BeRTOS.
+ *
+ * Bertos is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * As a special exception, you may use this file as part of a free software
+ * library without restriction. Specifically, if other files instantiate
+ * templates or use macros or inline functions from this file, or you compile
+ * this file and link it with other files to produce an executable, this
+ * file does not by itself cause the resulting executable to be covered by
+ * the GNU General Public License. This exception does not however
+ * invalidate any other reasons why the executable file might be covered by
+ * the GNU General Public License.
+ *
+ * Copyright 2008 Develer S.r.l. (http://www.develer.com/)
+ * All Rights Reserved.
+ * -->
+ *
+ * \brief Generic text LCD driver (Test).
+ *
+ * \version $Id$
+ *
+ * \author Daniele Basile <asterix@develer.com>
+ *
+ */
+
+#warning TODO:This test is incomplete, you must review!
+
+#if 0
+void lcd_test(void)
+{
+ int i;
+
+ for (i = 0; i < LCD_ROWS * LCD_COLS; ++i)
+ {
+ lcd_putCharUnlocked('0' + (i % 10), lcd_DefLayer);
+ timer_delay(100);
+ }
+}
+#endif
+
+++ /dev/null
-/**
- * \file
- * <!--
- * This file is part of BeRTOS.
- *
- * Bertos is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
- *
- * As a special exception, you may use this file as part of a free software
- * library without restriction. Specifically, if other files instantiate
- * templates or use macros or inline functions from this file, or you compile
- * this file and link it with other files to produce an executable, this
- * file does not by itself cause the resulting executable to be covered by
- * the GNU General Public License. This exception does not however
- * invalidate any other reasons why the executable file might be covered by
- * the GNU General Public License.
- *
- * Copyright 2008 Develer S.r.l. (http://www.develer.com/)
- * All Rights Reserved.
- * -->
- *
- * \brief Generic text LCD driver (Test).
- *
- * \version $Id$
- *
- * \author Daniele Basile <asterix@develer.com>
- *
- */
-
-#warning TODO:This test is incomplete, you must review!
-
-#if 0
-void lcd_test(void)
-{
- int i;
-
- for (i = 0; i < LCD_ROWS * LCD_COLS; ++i)
- {
- lcd_putCharUnlocked('0' + (i % 10), lcd_DefLayer);
- timer_delay(100);
- }
-}
-#endif
-
--- /dev/null
+/**
+ * \file
+ * <!--
+ * This file is part of BeRTOS.
+ *
+ * Bertos is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * As a special exception, you may use this file as part of a free software
+ * library without restriction. Specifically, if other files instantiate
+ * templates or use macros or inline functions from this file, or you compile
+ * this file and link it with other files to produce an executable, this
+ * file does not by itself cause the resulting executable to be covered by
+ * the GNU General Public License. This exception does not however
+ * invalidate any other reasons why the executable file might be covered by
+ * the GNU General Public License.
+ *
+ * Copyright 2005 Develer S.r.l. (http://www.develer.com/)
+ * -->
+ *
+ *
+ * \brief Test for PWM driver (implementation)
+ *
+ * This is a simple test for PWM driver. This module
+ * is target independent, so you can test all target that
+ * BeRTOS support.
+ * To use this test you should include a pwm_map.h header where
+ * are defined the PWM channels for your target. Then you should add
+ * or remove a test setting in pwm_test_cfg array, and edit a value for
+ * your specific test.
+ * Afther this, all is ready and you can test PWM driver.
+ *
+ * The test check first if all PWM channel starts, and then try
+ * to change a PWM duty cicle for all channel.
+ * The change of duty cycle is operate when a PWM channel is enable,
+ * in this way you can see if a pwm signal is clean and work properly.
+ * The duty value is change incrementaly, and when it arrive to 100% or 0%,
+ * we reset the duty value and restart the test.
+ * Further the duty test, we check also a PWM polarity, infact when we
+ * reach a reset duty value, we invert a polary of PWM wavform.
+ * So you can see if the hardware manage correctly this situation.
+ *
+ * Note: To be simple and target independently we not use a timer module,
+ * and so the delay is do with a for cycle.
+ *
+ * \version $Id$
+ * \author Daniele Basile <asterix@develer.com>
+ */
+
+#include "hw/pwm_map.h" // For PwmDev and channel avaible on thi target
+#include "cfg/cfg_pwm.h"
+#include <cfg/macros.h>
+#include <cfg/debug.h>
+
+// Define logging setting (for cfg/log.h module).
+#define LOG_LEVEL PWM_LOG_LEVEL
+#define LOG_FORMAT PWM_LOG_FORMAT
+#include <cfg/log.h> // for logging system
+
+#include <cpu/types.h>
+#include <cpu/irq.h>
+
+#include <drv/pwm.h>
+#include CPU_HEADER(pwm)
+
+#define DELAY_TIME 10000 // This is a number of for cycle before to set a new value of duty
+#define PWM_DUTY_INC 200 // Incremental value for duty
+
+
+/**
+ * Simple struct to store
+ * the testing value.
+ */
+typedef struct PwmTest
+{
+ int ch;
+ bool pol;
+ pwm_freq_t freq;
+ pwm_duty_t duty;
+} PwmTest;
+
+/*
+ * Test settings for each channel.
+ *
+ * Frequency value is in Hz.
+ *
+ * Esample of value for duty cycle"
+ *
+ * - 100% => 0xFFFFFFFF
+ * - 80% => 0xCCCCCCCC
+ * - 75% => 0xBFFFFFFF
+ * - 50% => 0x7FFFFFFF
+ * - 25% => 0x3FFFFFFF
+ * - 33% => 0x55555555
+ * - 16% => 0x2AAAAAAA
+ */
+static PwmTest pwm_test_cfg[PWM_CNT] =
+{
+ /* Channel, polarity, frequecy, duty */
+ { 0, false, 100UL, 0 }, /* 100Hz, 0% duty */
+ { 1, false, 1000UL, 0x7FFF }, /* 1KHz, 50% duty */
+ { 2, false, 12356UL, 0x5555 }, /* 12,356KHz, 33% duty */
+ { 3, false, 100000UL, 0xCCCC } /* 100KHz, 80% duty */
+};
+
+/**
+ * Setup all needed to test PWM on AT91
+ *
+ */
+int pwm_testSetUp(void)
+{
+ LOG_INFO("Init pwm..");
+ pwm_init();
+ LOG_INFO("done.\n");
+
+ return 0;
+}
+
+
+/**
+ * Test suit for genation of pwm waveform.
+ *
+ */
+int pwm_testRun(void)
+{
+ pwm_duty_t duty = 0;
+ int delay = 0;
+
+ pwm_testSetUp();
+
+ LOG_INFO("\n\n===== BeRTOS PWM test =====\n\n");
+
+ for (int i = 0; i < PWM_CNT; i++)
+ {
+ LOG_INFO("PWM test ch[%d]\n", pwm_test_cfg[i].ch);
+ LOG_INFO("--> set pol[%d]", pwm_test_cfg[i].pol);
+ LOG_INFO("\n(Note: if polarity is false the output waveform start at high level,\n see low level implentation for detail)i\n");
+ pwm_setPolarity(pwm_test_cfg[i].ch, pwm_test_cfg[i].pol);
+ LOG_INFO("..ok\n");
+
+ LOG_INFO("--> set freq[%ld]", pwm_test_cfg[i].freq);
+ pwm_setFrequency(pwm_test_cfg[i].ch, pwm_test_cfg[i].freq);
+ LOG_INFO("..ok\n");
+
+ LOG_INFO("--> set duty[%d]", pwm_test_cfg[i].duty);
+ pwm_setDuty(pwm_test_cfg[i].ch, pwm_test_cfg[i].duty);
+ LOG_INFO("..ok\n");
+
+ LOG_INFO("--> Enable pwm");
+ pwm_enable(pwm_test_cfg[i].ch, true);
+ LOG_INFO("..ok\n");
+ }
+
+ LOG_INFO("\n-------------------------- Dinamic PWM test --------------------------\n");
+ LOG_INFO("We test if driver change correctly the duty cycle durind it working.\n");
+ LOG_INFO("On your oscilloscope you should see the pwm singal that increase until\n");
+ LOG_INFO("the duty value is 100%%. After this value we invert a polarity of pwm,\n");
+ LOG_INFO("and repeat the test. But now you should see that pwm duty decreasing until\n");
+ LOG_INFO("0%% duty value.\nAfter that, we repeat the test from beginning.\n\n");
+
+ for (;;)
+ {
+ if (delay == DELAY_TIME)
+ {
+ for (int i = 0; i < PWM_CNT; i++)
+ {
+ LOG_INFO("PWM test ch[%d]\n", pwm_test_cfg[i].ch);
+ LOG_INFO("--> set duty[%d]", duty);
+ pwm_setDuty(pwm_test_cfg[i].ch, duty);
+ LOG_INFO("..ok\n");
+ }
+ LOG_INFO("\n++++++++++++++++++++\n");
+ duty += PWM_DUTY_INC;
+ delay = 0;
+ }
+
+ //Reset duty cycle overflow
+ if (duty >= (pwm_duty_t)0xFFFF)
+ {
+ duty = 0;
+ for (int i = 0; i < PWM_CNT; i++)
+ {
+ LOG_INFO("Duty reset, swap polarity:\n");
+ LOG_INFO("--> pol from [%d] to [%d]", pwm_test_cfg[i].pol, !pwm_test_cfg[i].pol);
+
+ pwm_test_cfg[i].pol = !pwm_test_cfg[i].pol;
+ pwm_setPolarity(pwm_test_cfg[i].ch, pwm_test_cfg[i].pol);
+
+ LOG_INFO("..ok\n");
+ }
+ LOG_INFO("\n++++++++++++++++++++\n");
+ }
+ delay++;
+ }
+
+ return 0;
+}
+
+/**
+ * End a PWM Test.
+ * (Unused)
+ */
+int pwm_testTearDown(void)
+{
+ /* */
+ return 0;
+}
+
+/*
+ * Empty main.
+ *
+ * Look it as exmple or use it if
+ * you want test a PWM driver stand alone.
+ */
+#if 0
+int main(void)
+{
+ IRQ_ENABLE;
+ kdbg_init();
+
+ pwm_testRun();
+
+ for(;;)
+ {
+ }
+
+}
+#endif
+
+
+++ /dev/null
-/**
- * \file
- * <!--
- * This file is part of BeRTOS.
- *
- * Bertos is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
- *
- * As a special exception, you may use this file as part of a free software
- * library without restriction. Specifically, if other files instantiate
- * templates or use macros or inline functions from this file, or you compile
- * this file and link it with other files to produce an executable, this
- * file does not by itself cause the resulting executable to be covered by
- * the GNU General Public License. This exception does not however
- * invalidate any other reasons why the executable file might be covered by
- * the GNU General Public License.
- *
- * Copyright 2005 Develer S.r.l. (http://www.develer.com/)
- * -->
- *
- *
- * \brief Test for PWM driver (implementation)
- *
- * This is a simple test for PWM driver. This module
- * is target independent, so you can test all target that
- * BeRTOS support.
- * To use this test you should include a pwm_map.h header where
- * are defined the PWM channels for your target. Then you should add
- * or remove a test setting in pwm_test_cfg array, and edit a value for
- * your specific test.
- * Afther this, all is ready and you can test PWM driver.
- *
- * The test check first if all PWM channel starts, and then try
- * to change a PWM duty cicle for all channel.
- * The change of duty cycle is operate when a PWM channel is enable,
- * in this way you can see if a pwm signal is clean and work properly.
- * The duty value is change incrementaly, and when it arrive to 100% or 0%,
- * we reset the duty value and restart the test.
- * Further the duty test, we check also a PWM polarity, infact when we
- * reach a reset duty value, we invert a polary of PWM wavform.
- * So you can see if the hardware manage correctly this situation.
- *
- * Note: To be simple and target independently we not use a timer module,
- * and so the delay is do with a for cycle.
- *
- * \version $Id$
- * \author Daniele Basile <asterix@develer.com>
- */
-
-#include "hw/pwm_map.h" // For PwmDev and channel avaible on thi target
-#include "cfg/cfg_pwm.h"
-#include <cfg/macros.h>
-#include <cfg/debug.h>
-
-// Define logging setting (for cfg/log.h module).
-#define LOG_LEVEL PWM_LOG_LEVEL
-#define LOG_FORMAT PWM_LOG_FORMAT
-#include <cfg/log.h> // for logging system
-
-#include <cpu/types.h>
-#include <cpu/irq.h>
-
-#include <drv/pwm.h>
-#include CPU_HEADER(pwm)
-
-#define DELAY_TIME 10000 // This is a number of for cycle before to set a new value of duty
-#define PWM_DUTY_INC 200 // Incremental value for duty
-
-
-/**
- * Simple struct to store
- * the testing value.
- */
-typedef struct PwmTest
-{
- int ch;
- bool pol;
- pwm_freq_t freq;
- pwm_duty_t duty;
-} PwmTest;
-
-/*
- * Test settings for each channel.
- *
- * Frequency value is in Hz.
- *
- * Esample of value for duty cycle"
- *
- * - 100% => 0xFFFFFFFF
- * - 80% => 0xCCCCCCCC
- * - 75% => 0xBFFFFFFF
- * - 50% => 0x7FFFFFFF
- * - 25% => 0x3FFFFFFF
- * - 33% => 0x55555555
- * - 16% => 0x2AAAAAAA
- */
-static PwmTest pwm_test_cfg[PWM_CNT] =
-{
- /* Channel, polarity, frequecy, duty */
- { 0, false, 100UL, 0 }, /* 100Hz, 0% duty */
- { 1, false, 1000UL, 0x7FFF }, /* 1KHz, 50% duty */
- { 2, false, 12356UL, 0x5555 }, /* 12,356KHz, 33% duty */
- { 3, false, 100000UL, 0xCCCC } /* 100KHz, 80% duty */
-};
-
-/**
- * Setup all needed to test PWM on AT91
- *
- */
-int pwm_testSetUp(void)
-{
- LOG_INFO("Init pwm..");
- pwm_init();
- LOG_INFO("done.\n");
-
- return 0;
-}
-
-
-/**
- * Test suit for genation of pwm waveform.
- *
- */
-int pwm_testRun(void)
-{
- pwm_duty_t duty = 0;
- int delay = 0;
-
- pwm_testSetUp();
-
- LOG_INFO("\n\n===== BeRTOS PWM test =====\n\n");
-
- for (int i = 0; i < PWM_CNT; i++)
- {
- LOG_INFO("PWM test ch[%d]\n", pwm_test_cfg[i].ch);
- LOG_INFO("--> set pol[%d]", pwm_test_cfg[i].pol);
- LOG_INFO("\n(Note: if polarity is false the output waveform start at high level,\n see low level implentation for detail)i\n");
- pwm_setPolarity(pwm_test_cfg[i].ch, pwm_test_cfg[i].pol);
- LOG_INFO("..ok\n");
-
- LOG_INFO("--> set freq[%ld]", pwm_test_cfg[i].freq);
- pwm_setFrequency(pwm_test_cfg[i].ch, pwm_test_cfg[i].freq);
- LOG_INFO("..ok\n");
-
- LOG_INFO("--> set duty[%d]", pwm_test_cfg[i].duty);
- pwm_setDuty(pwm_test_cfg[i].ch, pwm_test_cfg[i].duty);
- LOG_INFO("..ok\n");
-
- LOG_INFO("--> Enable pwm");
- pwm_enable(pwm_test_cfg[i].ch, true);
- LOG_INFO("..ok\n");
- }
-
- LOG_INFO("\n-------------------------- Dinamic PWM test --------------------------\n");
- LOG_INFO("We test if driver change correctly the duty cycle durind it working.\n");
- LOG_INFO("On your oscilloscope you should see the pwm singal that increase until\n");
- LOG_INFO("the duty value is 100%%. After this value we invert a polarity of pwm,\n");
- LOG_INFO("and repeat the test. But now you should see that pwm duty decreasing until\n");
- LOG_INFO("0%% duty value.\nAfter that, we repeat the test from beginning.\n\n");
-
- for (;;)
- {
- if (delay == DELAY_TIME)
- {
- for (int i = 0; i < PWM_CNT; i++)
- {
- LOG_INFO("PWM test ch[%d]\n", pwm_test_cfg[i].ch);
- LOG_INFO("--> set duty[%d]", duty);
- pwm_setDuty(pwm_test_cfg[i].ch, duty);
- LOG_INFO("..ok\n");
- }
- LOG_INFO("\n++++++++++++++++++++\n");
- duty += PWM_DUTY_INC;
- delay = 0;
- }
-
- //Reset duty cycle overflow
- if (duty >= (pwm_duty_t)0xFFFF)
- {
- duty = 0;
- for (int i = 0; i < PWM_CNT; i++)
- {
- LOG_INFO("Duty reset, swap polarity:\n");
- LOG_INFO("--> pol from [%d] to [%d]", pwm_test_cfg[i].pol, !pwm_test_cfg[i].pol);
-
- pwm_test_cfg[i].pol = !pwm_test_cfg[i].pol;
- pwm_setPolarity(pwm_test_cfg[i].ch, pwm_test_cfg[i].pol);
-
- LOG_INFO("..ok\n");
- }
- LOG_INFO("\n++++++++++++++++++++\n");
- }
- delay++;
- }
-
- return 0;
-}
-
-/**
- * End a PWM Test.
- * (Unused)
- */
-int pwm_testTearDown(void)
-{
- /* */
- return 0;
-}
-
-/*
- * Empty main.
- *
- * Look it as exmple or use it if
- * you want test a PWM driver stand alone.
- */
-#if 0
-int main(void)
-{
- IRQ_ENABLE;
- kdbg_init();
-
- pwm_testRun();
-
- for(;;)
- {
- }
-
-}
-#endif
-
-