From: batt Date: Fri, 29 Aug 2008 20:47:37 +0000 (+0000) Subject: Rename hw-related tests. X-Git-Tag: 2.0.0~172 X-Git-Url: https://codewiz.org/gitweb?a=commitdiff_plain;h=006c06fa5c4ce4a6e250877655e9963a8310538a;p=bertos.git Rename hw-related tests. git-svn-id: https://src.develer.com/svnoss/bertos/trunk@1762 38d2e660-2303-0410-9eaa-f027e97ec537 --- diff --git a/bertos/cpu/arm/drv/stepper_at91_hw_test.c b/bertos/cpu/arm/drv/stepper_at91_hw_test.c deleted file mode 100644 index 8fb1820c..00000000 --- a/bertos/cpu/arm/drv/stepper_at91_hw_test.c +++ /dev/null @@ -1,175 +0,0 @@ -/** - * \file - * - * - * \brief Low level test for stepper driver interface implementation. - * - * \version $Id$ - * - * \author Daniele Basile - */ - -#include "stepper_at91.h" - -#include "cfg/cfg_stepper.h" -#include -#include - -#include -#include - -#include - - -#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 - diff --git a/bertos/cpu/arm/drv/stepper_at91_hwtest.c b/bertos/cpu/arm/drv/stepper_at91_hwtest.c new file mode 100644 index 00000000..d40da084 --- /dev/null +++ b/bertos/cpu/arm/drv/stepper_at91_hwtest.c @@ -0,0 +1,175 @@ +/** + * \file + * + * + * \brief Low level test for stepper driver interface implementation. + * + * \version $Id$ + * + * \author Daniele Basile + */ + +#include "stepper_at91.h" + +#include "cfg/cfg_stepper.h" +#include +#include + +#include +#include + +#include + + +#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 + diff --git a/bertos/drv/dataflash_hwtest.c b/bertos/drv/dataflash_hwtest.c new file mode 100644 index 00000000..fa808558 --- /dev/null +++ b/bertos/drv/dataflash_hwtest.c @@ -0,0 +1,232 @@ +/** + * \file + * + * + * \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 + */ + +#include "hw/hw_dataflash.h" +#include "cfg/cfg_dataflash.h" +#include "cfg/cfg_kern.h" + +#include +#include +#include + +// Define logging setting (for cfg/log.h module). +#define LOG_LEVEL DATAFLASH_LOG_LEVEL +#define LOG_FORMAT DATAFLASH_LOG_FORMAT +#include // for logging system + +#include +#include +#include + +#include +#include + +#include + +/* + * 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 //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 diff --git a/bertos/drv/dataflash_test.c b/bertos/drv/dataflash_test.c deleted file mode 100644 index fa808558..00000000 --- a/bertos/drv/dataflash_test.c +++ /dev/null @@ -1,232 +0,0 @@ -/** - * \file - * - * - * \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 - */ - -#include "hw/hw_dataflash.h" -#include "cfg/cfg_dataflash.h" -#include "cfg/cfg_kern.h" - -#include -#include -#include - -// Define logging setting (for cfg/log.h module). -#define LOG_LEVEL DATAFLASH_LOG_LEVEL -#define LOG_FORMAT DATAFLASH_LOG_FORMAT -#include // for logging system - -#include -#include -#include - -#include -#include - -#include - -/* - * 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 //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 diff --git a/bertos/drv/flash25_hwtest.c b/bertos/drv/flash25_hwtest.c new file mode 100644 index 00000000..814c1648 --- /dev/null +++ b/bertos/drv/flash25_hwtest.c @@ -0,0 +1,84 @@ +/** + * \file + * + * + * \brief Test function for serial Flash memory. + * + * \version $Id$ + * \author Daniele Basile + */ + +/** + * Test function for flash25. + * + * \note: This implentation use a SPI channel. + */ + + +#include + +#include + +#include + +#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; +} + + diff --git a/bertos/drv/flash25_test.c b/bertos/drv/flash25_test.c deleted file mode 100644 index 814c1648..00000000 --- a/bertos/drv/flash25_test.c +++ /dev/null @@ -1,84 +0,0 @@ -/** - * \file - * - * - * \brief Test function for serial Flash memory. - * - * \version $Id$ - * \author Daniele Basile - */ - -/** - * Test function for flash25. - * - * \note: This implentation use a SPI channel. - */ - - -#include - -#include - -#include - -#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; -} - - diff --git a/bertos/drv/lcd_hd44_hwtest.c b/bertos/drv/lcd_hd44_hwtest.c new file mode 100644 index 00000000..065cee51 --- /dev/null +++ b/bertos/drv/lcd_hd44_hwtest.c @@ -0,0 +1,97 @@ +/** + * \file + * + * + * \brief LM044L type LCD hardware module (impl.) + * + * \version $Id$ + * \author Bernie Innocenti + * \author Stefano Fedrigo + */ + +#include "lcd_hd44.h" +#include "hw/hw_lcd.h" + +#include +#include + +#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 +#include + +int main(void) +{ + lcd_hw_test(); + + for(;;) + { + } + + return 0; +} + +#endif diff --git a/bertos/drv/lcd_hd44_test.c b/bertos/drv/lcd_hd44_test.c deleted file mode 100644 index 065cee51..00000000 --- a/bertos/drv/lcd_hd44_test.c +++ /dev/null @@ -1,97 +0,0 @@ -/** - * \file - * - * - * \brief LM044L type LCD hardware module (impl.) - * - * \version $Id$ - * \author Bernie Innocenti - * \author Stefano Fedrigo - */ - -#include "lcd_hd44.h" -#include "hw/hw_lcd.h" - -#include -#include - -#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 -#include - -int main(void) -{ - lcd_hw_test(); - - for(;;) - { - } - - return 0; -} - -#endif diff --git a/bertos/drv/lcd_text_hwtest.c b/bertos/drv/lcd_text_hwtest.c new file mode 100644 index 00000000..fedde87e --- /dev/null +++ b/bertos/drv/lcd_text_hwtest.c @@ -0,0 +1,55 @@ +/** + * \file + * + * + * \brief Generic text LCD driver (Test). + * + * \version $Id$ + * + * \author Daniele Basile + * + */ + +#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 + diff --git a/bertos/drv/lcd_text_test.c b/bertos/drv/lcd_text_test.c deleted file mode 100644 index fedde87e..00000000 --- a/bertos/drv/lcd_text_test.c +++ /dev/null @@ -1,55 +0,0 @@ -/** - * \file - * - * - * \brief Generic text LCD driver (Test). - * - * \version $Id$ - * - * \author Daniele Basile - * - */ - -#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 - diff --git a/bertos/drv/pwm_hwtest.c b/bertos/drv/pwm_hwtest.c new file mode 100644 index 00000000..f66fe660 --- /dev/null +++ b/bertos/drv/pwm_hwtest.c @@ -0,0 +1,241 @@ +/** + * \file + * + * + * + * \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 + */ + +#include "hw/pwm_map.h" // For PwmDev and channel avaible on thi target +#include "cfg/cfg_pwm.h" +#include +#include + +// Define logging setting (for cfg/log.h module). +#define LOG_LEVEL PWM_LOG_LEVEL +#define LOG_FORMAT PWM_LOG_FORMAT +#include // for logging system + +#include +#include + +#include +#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 + + diff --git a/bertos/drv/pwm_test.c b/bertos/drv/pwm_test.c deleted file mode 100644 index f66fe660..00000000 --- a/bertos/drv/pwm_test.c +++ /dev/null @@ -1,241 +0,0 @@ -/** - * \file - * - * - * - * \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 - */ - -#include "hw/pwm_map.h" // For PwmDev and channel avaible on thi target -#include "cfg/cfg_pwm.h" -#include -#include - -// Define logging setting (for cfg/log.h module). -#define LOG_LEVEL PWM_LOG_LEVEL -#define LOG_FORMAT PWM_LOG_FORMAT -#include // for logging system - -#include -#include - -#include -#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 - -