summaryrefslogtreecommitdiff
path: root/firmware/src/p2m.c
blob: 11fe393e3ee10edc3dfb1f0e009b7f285f469374 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
/* THIS SOFTWARE IS PROVIDED "AS IS".  NO WARRANTIES, WHETHER EXPRESS, IMPLIED
 * OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.
 * THE AUTHORS SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR
 * CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER. USE IT AT YOUR OWN RISK */

#include <LPC17xx.h>

//#define SPI
#define IRQ_BLINKY
//#define BLINKY

#ifdef DMA

#include "dac.h"
#include "sample.h"

int main (void) 
{
	dac_init();

	//	int i = 0;
	while(1) {
		//fiprintf(stderr, "Play #%d: %d samples\n\r", i++, sizeof(samples) / sizeof(short));
		dac_play_samples(samples, sizeof(samples) / sizeof(short));
	}
	return 0;
}

#endif
volatile uint32_t temp;

void _delay(uint32_t del);

#ifdef IRQ_BLINKY

volatile int resume = 0;

void TIMER0_IRQHandler (void) 
{  
  LPC_TIM0->IR = 1;			/* clear interrupt flag */
	resume = 1 - resume;
  //timer0_counter++;
  return;
}

int main (void) 
{
    LPC_SC->PCONP |= ( 1 << 15 ); // power up GPIO
    LPC_GPIO1->FIODIR |= 1 << 29; // puts P1.29 into output mode.

		int delayInMs = 1000;

		// Enable timer interrupts
		LPC_TIM0->MR0 = delayInMs * (9000000 / 1000-1); // interval
		LPC_TIM0->MCR = 3;				// Interrupt and Reset on MR0
		NVIC_EnableIRQ(TIMER0_IRQn);
		LPC_TIM0->TCR = 1;

    while(1) {
        LPC_GPIO1->FIOPIN |= 1 << 29; // make P1.29 high

				while(resume == 0) __WFI();

        LPC_GPIO1->FIOPIN &= ~( 1 << 29 ); // make P1.29 low

				while(resume == 1) __WFI();
    }

    return 0;
  
}

#endif

#ifdef BLINKY

int main (void) 
{
    LPC_SC->PCONP |= ( 1 << 15 ); // power up GPIO
    LPC_GPIO1->FIODIR |= 1 << 29; // puts P1.29 into output mode.
    while(1)
    {
        LPC_GPIO1->FIOPIN |= 1 << 29; // make P1.29 high
        _delay( 1 << 24 );
        LPC_GPIO1->FIOPIN &= ~( 1 << 29 ); // make P1.29 low
        _delay( 1 << 24 );
    }
    return 0;
  
}

#endif

#ifdef UART

#include "LPC17xx.h"
#include <stdint.h>
#include "uart.h"

int main (void)
{ 
	/* SystemClockUpdate() updates the SystemFrequency variable */
	// SystemCoreClockUpdate();//SystemClockUpdate();
  UARTInit(0, 115200);	/* baud rate setting */
	//  UARTInit(1, 8000);	/* baud rate setting */

	LPC_SC->PCONP |= ( 1 << 15 ); // power up GPIO
	LPC_GPIO1->FIODIR |= 1 << 29; // puts P1.29 into output mode.

  while (1) {
		LPC_GPIO1->FIOPIN |= 1 << 29; // make P1.29 high

		//LPC_UART0->IER = IER_THRE | IER_RLS;			// Disable RBR
		UARTSend(0, (uint8_t *)"hello\n\r", 7);
		//LPC_UART0->IER = IER_THRE | IER_RLS | IER_RBR;	// Re-enable RBR

		_delay( 1 << 22 );

		///

		LPC_GPIO1->FIOPIN &= ~( 1 << 29 ); // make P1.29 low
		/*
		LPC_UART0->IER = IER_THRE | IER_RLS;			// Disable RBR
		UARTSend( 0, (uint8_t *)"l", 1);
		LPC_UART0->IER = IER_THRE | IER_RLS | IER_RBR;	// Re-enable RBR
		*/
		_delay( 1 << 22 );

  }
}

#endif

#ifdef SPI

#include <cli.h>
#include <wm8523.h>
#include <led.h>

int main (void)
{
	//	SystemCoreClockUpdate(); 
	//  SystemInit();

	LED_Init();

  cli_init();

	cli_write("init");

	_delay(1 << 22);

	WM8523_init();

	cli_write("pre");

	_delay(1 << 22);

	WM8523_configure();

	cli_write("post");
}

#endif

void _delay(uint32_t del)
{
    uint32_t i;
    for(i=0;i<del;i++)
        temp = i;
}