2010-05-08 17:03:36 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2010, Mariano Alvira <mar@devl.org> and other contributors
|
|
|
|
* to the MC1322x project (http://mc1322x.devl.org)
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* 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 of the Institute 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 INSTITUTE 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 INSTITUTE 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.
|
|
|
|
*
|
|
|
|
* This file is part of libmc1322x: see http://mc1322x.devl.org
|
|
|
|
* for details.
|
|
|
|
*
|
|
|
|
* $Id$
|
|
|
|
*/
|
|
|
|
|
2010-02-26 20:35:57 +00:00
|
|
|
#include <mc1322x.h>
|
|
|
|
#include <board.h>
|
2009-04-20 18:15:24 +00:00
|
|
|
|
2010-02-26 20:35:57 +00:00
|
|
|
#include "tests.h"
|
|
|
|
#include "config.h"
|
2009-06-22 16:35:39 +00:00
|
|
|
|
|
|
|
#define LED LED_YELLOW
|
2009-04-20 22:31:13 +00:00
|
|
|
|
2009-04-20 18:15:24 +00:00
|
|
|
void main(void) {
|
|
|
|
|
|
|
|
/* pin direction */
|
2010-03-17 21:02:07 +00:00
|
|
|
gpio_pad_dir_set(LED_WHITE);
|
|
|
|
/* all LEDs off */
|
|
|
|
gpio_data_reset(LED_WHITE);
|
2009-04-20 18:15:24 +00:00
|
|
|
|
|
|
|
/* timer setup */
|
|
|
|
/* CTRL */
|
|
|
|
#define COUNT_MODE 1 /* use rising edge of primary source */
|
|
|
|
#define PRIME_SRC 0xf /* Perip. clock with 128 prescale (for 24Mhz = 187500Hz)*/
|
|
|
|
#define SEC_SRC 0 /* don't need this */
|
|
|
|
#define ONCE 0 /* keep counting */
|
|
|
|
#define LEN 1 /* count until compare then reload with value in LOAD */
|
|
|
|
#define DIR 0 /* count up */
|
|
|
|
#define CO_INIT 0 /* other counters cannot force a re-initialization of this counter */
|
|
|
|
#define OUT_MODE 0 /* OFLAG is asserted while counter is active */
|
|
|
|
|
2010-02-26 20:35:57 +00:00
|
|
|
*TMR_ENBL = 0; /* tmrs reset to enabled */
|
|
|
|
*TMR0_SCTRL = 0;
|
|
|
|
*TMR0_LOAD = 0; /* reload to zero */
|
|
|
|
*TMR0_COMP_UP = 18750; /* trigger a reload at the end */
|
|
|
|
*TMR0_CMPLD1 = 18750; /* compare 1 triggered reload level, 10HZ maybe? */
|
|
|
|
*TMR0_CNTR = 0; /* reset count register */
|
|
|
|
*TMR0_CTRL = (COUNT_MODE<<13) | (PRIME_SRC<<9) | (SEC_SRC<<7) | (ONCE<<6) | (LEN<<5) | (DIR<<4) | (CO_INIT<<3) | (OUT_MODE);
|
|
|
|
*TMR_ENBL = 0xf; /* enable all the timers --- why not? */
|
2009-04-20 18:15:24 +00:00
|
|
|
|
|
|
|
while(1) {
|
|
|
|
|
|
|
|
/* blink on */
|
2010-03-17 02:03:38 +00:00
|
|
|
gpio_data_set(LED);
|
2009-04-20 18:15:24 +00:00
|
|
|
|
2010-02-26 20:35:57 +00:00
|
|
|
while((*TMR0_SCTRL >> 15) == 0) { continue; }
|
|
|
|
*TMR0_SCTRL = 0; /*clear bit 15, and all the others --- should be ok, but clearly not "the right thing to do" */
|
2009-04-20 18:15:24 +00:00
|
|
|
|
|
|
|
/* blink off */
|
2010-03-17 19:55:52 +00:00
|
|
|
gpio_data_reset(LED);
|
2009-04-20 18:15:24 +00:00
|
|
|
|
2010-02-26 20:35:57 +00:00
|
|
|
while((*TMR0_SCTRL >> 15) == 0) { continue; }
|
|
|
|
*TMR0_SCTRL = 0; /*clear bit 15, and all the others --- should be ok, but clearly not "the right thing to do" */
|
2009-04-20 18:15:24 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
}
|