2 * Copyright © 2008 Keith Packard <keithp@keithp.com>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
25 # define SLEEP_USB_EN (1 << 7)
26 # define SLEEP_XOSC_STB (1 << 6)
43 #define P2SEL_PRI3P1_USART0 (0 << 6)
44 #define P2SEL_PRI3P1_USART1 (1 << 6)
45 #define P2SEL_PRI2P1_USART1 (0 << 5)
46 #define P2SEL_PRI2P1_TIMER3 (1 << 5)
47 #define P2SEL_PRI1P1_TIMER1 (0 << 4)
48 #define P2SEL_PRI1P1_TIMER4 (1 << 4)
49 #define P2SEL_PRI0P1_USART0 (0 << 3)
50 #define P2SEL_PRI0P1_TIMER1 (1 << 3)
51 #define P2SEL_SELP2_4_GPIO (0 << 2)
52 #define P2SEL_SELP2_4_PERIPHERAL (1 << 2)
53 #define P2SEL_SELP2_3_GPIO (0 << 1)
54 #define P2SEL_SELP2_3_PERIPHERAL (1 << 1)
55 #define P2SEL_SELP2_0_GPIO (0 << 0)
56 #define P2SEL_SELP2_0_PERIPHERAL (1 << 0)
70 #define PERCFG_T1CFG_ALT_1 (0 << 6)
71 #define PERCFG_T1CFG_ALT_2 (1 << 6)
73 #define PERCFG_T3CFG_ALT_1 (0 << 5)
74 #define PERCFG_T3CFG_ALT_2 (1 << 5)
76 #define PERCFG_T4CFG_ALT_1 (0 << 4)
77 #define PERCFG_T4CFG_ALT_2 (1 << 4)
79 #define PERCFG_U1CFG_ALT_1 (0 << 1)
80 #define PERCFG_U1CFG_ALT_2 (1 << 1)
82 #define PERCFG_U0CFG_ALT_1 (0 << 0)
83 #define PERCFG_U0CFG_ALT_2 (1 << 0)
94 #define TxCTL_DIV_1 (0 << 5)
95 #define TxCTL_DIV_2 (1 << 5)
96 #define TxCTL_DIV_4 (2 << 5)
97 #define TxCTL_DIV_8 (3 << 5)
98 #define TxCTL_DIV_16 (4 << 5)
99 #define TxCTL_DIV_32 (5 << 5)
100 #define TxCTL_DIV_64 (6 << 5)
101 #define TxCTL_DIV_128 (7 << 5)
102 #define TxCTL_START (1 << 4)
103 #define TxCTL_OVFIM (1 << 3)
104 #define TxCTL_CLR (1 << 2)
105 #define TxCTL_MODE_FREE (0 << 0)
106 #define TxCTL_MODE_DOWN (1 << 0)
107 #define TxCTL_MODE_MODULO (2 << 0)
108 #define TxCTL_MODE_UP_DOWN (3 << 0)
110 /* Timer 4 channel 0 compare control */
117 #define TxCCTLy_IM (1 << 6)
118 #define TxCCTLy_CMP_SET (0 << 3)
119 #define TxCCTLy_CMP_CLEAR (1 << 3)
120 #define TxCCTLy_CMP_TOGGLE (2 << 3)
121 #define TxCCTLy_CMP_SET_UP_CLEAR_DOWN (3 << 3)
122 #define TxCCTLy_CMP_CLEAR_UP_SET_DOWN (4 << 3)
123 #define TxCCTLy_CMP_SET_CLEAR_FF (5 << 3)
124 #define TxCCTLy_CMP_CLEAR_SET_00 (6 << 3)
125 #define TxCCTLy_CMP_MODE_ENABLE (1 << 2)
127 /* Timer compare value */
133 #define nop() _asm nop _endasm;
136 delay (unsigned char n)
138 unsigned char i = 0, j = 0;
149 T4CTL |= TxCTL_START;
151 T4CTL &= ~TxCTL_START;
157 T4CTL |= TxCTL_START;
159 T4CTL &= ~TxCTL_START;
175 #define C charspace();
176 #define W wordspace();
181 while (!(SLEEP & SLEEP_XOSC_STB))
184 /* Use timer 4 alternate config 2 */
185 PERCFG = PERCFG_T4CFG_ALT_2;
186 /* Use P2_4 for timer 4 output */
187 P2SEL = P2SEL_SELP2_0_PERIPHERAL;
189 T4CCTL0 = TxCCTLy_CMP_TOGGLE|TxCCTLy_CMP_MODE_ENABLE;
191 T4CTL = TxCTL_DIV_32 | TxCTL_MODE_MODULO;
194 ___ _ ___ _ C ___ ___ _ ___ W /* cq */
195 ___ _ _ C _ W /* de */
196 ___ _ ___ C ___ _ _ C /* kd */
197 ___ ___ _ _ _ C _ _ _ C /* 7s */
198 ___ ___ _ ___ C ___ ___ _ W /* qg */