Compare commits
6 commits
a3bf7a7275
...
9f30b24b7f
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9f30b24b7f | ||
|
|
36527e1cdf | ||
|
|
6e276bc3f3 | ||
|
|
f235c3ac84 | ||
|
|
4589e8745e | ||
|
|
3889d8d82f |
5 changed files with 124 additions and 11 deletions
|
|
@ -525,6 +525,7 @@ static const struct keywords main_command_table[] = {
|
||||||
CMD_KW("gpio1", gpio1_cmd, 362, 0),
|
CMD_KW("gpio1", gpio1_cmd, 362, 0),
|
||||||
CMD_KW("adc", parse_sub_command, 909, adc_commands),
|
CMD_KW("adc", parse_sub_command, 909, adc_commands),
|
||||||
CMD_KW("ssp", parse_sub_command, 909, ssp_commands),
|
CMD_KW("ssp", parse_sub_command, 909, ssp_commands),
|
||||||
|
CMD_KW("wait", timer_cmd, 310, 0),
|
||||||
{"flash", {.par=&flash_command}},
|
{"flash", {.par=&flash_command}},
|
||||||
{"dma", {.par=&usb_command}},
|
{"dma", {.par=&usb_command}},
|
||||||
{"sdcard", {.par=&sdcard_command}},
|
{"sdcard", {.par=&sdcard_command}},
|
||||||
|
|
@ -857,7 +858,7 @@ static const struct keywords main_variable_names[] = {
|
||||||
VARIABLE("pclk", &rtc_pclk),
|
VARIABLE("pclk", &rtc_pclk),
|
||||||
VARIABLE("rtc_drift", rtc_drift),
|
VARIABLE("rtc_drift", rtc_drift),
|
||||||
VARIABLE("rtc_ctc", &rtc_ctc),
|
VARIABLE("rtc_ctc", &rtc_ctc),
|
||||||
|
VARIABLE("wait_ticks", &timer_ticks),
|
||||||
VARIABLE("spi_min_qtime", &spi_qtime_limit.min_qtime),
|
VARIABLE("spi_min_qtime", &spi_qtime_limit.min_qtime),
|
||||||
VARIABLE("stream_min_qtime",&stream_qtime_limit.min_qtime),
|
VARIABLE("stream_min_qtime",&stream_qtime_limit.min_qtime),
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@
|
||||||
static unsigned short pressure_reading[8];
|
static unsigned short pressure_reading[8];
|
||||||
static unsigned short pressure_hash[2];
|
static unsigned short pressure_hash[2];
|
||||||
static unsigned int pressure[2], temperature[2];
|
static unsigned int pressure[2], temperature[2];
|
||||||
extern struct timer_wait wait_conversion;
|
extern const struct timer_wait wait_conversion;
|
||||||
|
|
||||||
const struct keywords pressure_variable_names[] = {
|
const struct keywords pressure_variable_names[] = {
|
||||||
{"bate", {.par=(unsigned int *)(pressure_reading+6)}},
|
{"bate", {.par=(unsigned int *)(pressure_reading+6)}},
|
||||||
|
|
@ -18,7 +18,6 @@ const struct keywords pressure_variable_names[] = {
|
||||||
{"bate_hash", {.par=(unsigned int *)(pressure_hash)}},
|
{"bate_hash", {.par=(unsigned int *)(pressure_hash)}},
|
||||||
{"pressure", {.par=pressure}},
|
{"pressure", {.par=pressure}},
|
||||||
{"temperature", {.par=temperature}},
|
{"temperature", {.par=temperature}},
|
||||||
VARIABLE("wait", &wait_conversion),
|
|
||||||
{"", {0}}};
|
{"", {0}}};
|
||||||
|
|
||||||
__attribute__((noinline))
|
__attribute__((noinline))
|
||||||
|
|
@ -157,7 +156,7 @@ static void wait_callback(const volatile struct timer_tick* tick) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct timer_wait wait_conversion = {
|
const struct timer_wait wait_conversion = {
|
||||||
.mclk = 3333, // 50 ms
|
.mclk = 3333, // 50 ms
|
||||||
.pinmask = 1<<18, // wait for port0.18 to go low
|
.pinmask = 1<<18, // wait for port0.18 to go low
|
||||||
.callback = wait_callback,
|
.callback = wait_callback,
|
||||||
|
|
|
||||||
4
ssp.c
4
ssp.c
|
|
@ -411,8 +411,8 @@ int ssp_run_batch()
|
||||||
mclk_wait.mclk = f & ssp_b_count;
|
mclk_wait.mclk = f & ssp_b_count;
|
||||||
wait = &mclk_wait;
|
wait = &mclk_wait;
|
||||||
}
|
}
|
||||||
timer_wait_init(wait, (void*)batch);
|
if (timer_wait_init(wait, (void*)batch))
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
119
timer.c
119
timer.c
|
|
@ -1,6 +1,7 @@
|
||||||
|
|
||||||
#include "timer.h"
|
#include "timer.h"
|
||||||
#include "isr.h"
|
#include "isr.h"
|
||||||
|
#include "expression.h"
|
||||||
#include <lpc2148/vic.h>
|
#include <lpc2148/vic.h>
|
||||||
#include <lpc2148/pcb.h>
|
#include <lpc2148/pcb.h>
|
||||||
|
|
||||||
|
|
@ -10,11 +11,12 @@ static inline
|
||||||
void tick_timer(volatile struct timer_tick *tick, unsigned int ir)
|
void tick_timer(volatile struct timer_tick *tick, unsigned int ir)
|
||||||
{
|
{
|
||||||
tick->ir = ir;
|
tick->ir = ir;
|
||||||
unsigned short n = tick->n;
|
unsigned int n = tick->n + 1;
|
||||||
if (n != 0xffff)
|
if (n)
|
||||||
tick->n = n+1;
|
tick->n = n;
|
||||||
if (tick->callback)
|
if (tick->callback)
|
||||||
tick->callback(tick);
|
tick->callback(tick);
|
||||||
|
VICVectAddr = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
__attribute__ ((interrupt ("IRQ")))
|
__attribute__ ((interrupt ("IRQ")))
|
||||||
|
|
@ -52,7 +54,7 @@ void timer1_init()
|
||||||
T1CTCR = TxCTCR_Timer;
|
T1CTCR = TxCTCR_Timer;
|
||||||
T1PR = 0; // Prescale = 60MHz
|
T1PR = 0; // Prescale = 60MHz
|
||||||
T1MR0 = 60000; // 1ms
|
T1MR0 = 60000; // 1ms
|
||||||
T1MCR = TxMCR_MR0S | TxMCR_MR0I;
|
T1MCR = TxMCR_MR0R | TxMCR_MR0S | TxMCR_MR0I;
|
||||||
T1TCR = TxTCR_Counter_Reset;
|
T1TCR = TxTCR_Counter_Reset;
|
||||||
|
|
||||||
VICVectAddrs[IrqVec_Timer1] = timer1_isr;
|
VICVectAddrs[IrqVec_Timer1] = timer1_isr;
|
||||||
|
|
@ -110,7 +112,7 @@ int timer_wait_init(const struct timer_wait *wait, void *data)
|
||||||
T1TCR = TxTCR_Counter_Enable;
|
T1TCR = TxTCR_Counter_Enable;
|
||||||
}
|
}
|
||||||
else if (wait->ccr1) {
|
else if (wait->ccr1) {
|
||||||
T1MR0 = 6000000; // 100ms
|
T1MR0 = 600000000; // 10s
|
||||||
T1TCR = TxTCR_Counter_Enable;
|
T1TCR = TxTCR_Counter_Enable;
|
||||||
}
|
}
|
||||||
if (wait->mclk) {
|
if (wait->mclk) {
|
||||||
|
|
@ -164,3 +166,110 @@ int timer_wait_status(const struct timer_wait *wait)
|
||||||
{
|
{
|
||||||
return waiting && (!wait || wait==waiting);
|
return waiting && (!wait || wait==waiting);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const struct keywords timer_kw[] = {
|
||||||
|
FLAG_VAL("mclk", 0x00000200),
|
||||||
|
FLAG_VAL("pclk", 0x00000400),
|
||||||
|
FLAG_VAL("cap10", 0x00000030),
|
||||||
|
FLAG_VAL("cap18", 0x0000003c),
|
||||||
|
FLAG_VAL("cap28", 0x00000028),
|
||||||
|
FLAG_VAL("cap29", 0x0000002c),
|
||||||
|
FLAG_VAL("cap30", 0x00000020),
|
||||||
|
FLAG_VAL("rise", 0x00000001),
|
||||||
|
FLAG_VAL("fall", 0x00000002),
|
||||||
|
FLAG_VAL("mask", 0x00000100),
|
||||||
|
FLAG_VAL("high", 0x00000040),
|
||||||
|
FLAG_VAL("low", 0x00000080),
|
||||||
|
FLAG_VAL("status", 0x00001000),
|
||||||
|
FLAG_VAL("abort", 0x00002000),
|
||||||
|
FLAG_VAL("call", 0x00004000),
|
||||||
|
FLAG_VAL("keep", 0x00008000),
|
||||||
|
FLAG_VAL("again", 0x00010000),
|
||||||
|
{}
|
||||||
|
};
|
||||||
|
|
||||||
|
static struct timer_wait timer_wait;
|
||||||
|
unsigned int timer_ticks;
|
||||||
|
static
|
||||||
|
void timer_expired(const volatile struct timer_tick *tick) { timer_ticks++; }
|
||||||
|
|
||||||
|
int timer_cmd(struct command *cmd, const struct command_par *par)
|
||||||
|
{
|
||||||
|
int code = par->code;
|
||||||
|
unsigned int what = (unsigned int)par->par;
|
||||||
|
error_msg_t e = parse_flags(cmd, timer_kw, &what);
|
||||||
|
if (e)
|
||||||
|
goto error;
|
||||||
|
const struct timer_wait *w = waiting;
|
||||||
|
unsigned int status = 0;
|
||||||
|
status |= (timer0_tick.ir & 0xff) << 16;
|
||||||
|
status |= (timer1_tick.ir & 0xff) << 24;
|
||||||
|
unsigned int count = 0;
|
||||||
|
if (w) {
|
||||||
|
code++;
|
||||||
|
status |= timer_wait_pin_status(w);
|
||||||
|
if (w->pclk || w->ccr1) {
|
||||||
|
status |= 0x20;
|
||||||
|
count = T1TC;
|
||||||
|
}
|
||||||
|
else if (w->mclk) {
|
||||||
|
status |= 0x10;
|
||||||
|
count = timer0_tick.n;
|
||||||
|
}
|
||||||
|
if (w->ccr0)
|
||||||
|
status |= 0x40;
|
||||||
|
if (w->ccr1)
|
||||||
|
status |= 0x80;
|
||||||
|
if (what & 0x00006000)
|
||||||
|
timer_wait_abort();
|
||||||
|
if (what & 0x00004000 && w->callback)
|
||||||
|
w->callback(0);
|
||||||
|
}
|
||||||
|
if (w || what & 0x00007000 || !what) {
|
||||||
|
parser_format_message(cmd, "%03d wait status: 0x%x %u %u\n",
|
||||||
|
code, status, timer_ticks, count);
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
if (!(what & 0x10000))
|
||||||
|
timer_wait = (struct timer_wait){.callback=timer_expired};
|
||||||
|
struct timer_wait *wait = &timer_wait;
|
||||||
|
if (what & 0x20) {
|
||||||
|
if (!(what & 3))
|
||||||
|
what |= 3;
|
||||||
|
unsigned int ccr = (what & 3 | 4) << 3*(what>>2 & 3);
|
||||||
|
if (what & 0x10)
|
||||||
|
wait->ccr1 = ccr;
|
||||||
|
else
|
||||||
|
wait->ccr0 = ccr;
|
||||||
|
}
|
||||||
|
if (what & 0x100) {
|
||||||
|
e = parse_expression(cmd, &wait->pinvalue);
|
||||||
|
if (!e)
|
||||||
|
e = parse_expression(cmd, &wait->pinmask);
|
||||||
|
}
|
||||||
|
else if (what & 0xc0) {
|
||||||
|
e = parse_expression_square(cmd, &wait->pinmask, 0);
|
||||||
|
if (!e) {
|
||||||
|
wait->pinmask = 1 << (wait->pinmask & 0x1f);
|
||||||
|
if (what & 0x40)
|
||||||
|
wait->pinvalue = wait->pinmask;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (e)
|
||||||
|
goto error;
|
||||||
|
if (what & 0x200)
|
||||||
|
e = parse_expression(cmd, &wait->mclk);
|
||||||
|
else if (what & 0x400)
|
||||||
|
e = parse_expression(cmd, &wait->pclk);
|
||||||
|
|
||||||
|
if (e)
|
||||||
|
error:
|
||||||
|
return parser_error_message(cmd, e);
|
||||||
|
|
||||||
|
if (!(what & 0x8000))
|
||||||
|
timer_ticks = 0;
|
||||||
|
int r = timer_wait_init(wait, 0);
|
||||||
|
parser_format_message(cmd, "%03d timer_wait 0x%x %u\n",
|
||||||
|
code, what, r);
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
|
||||||
4
timer.h
4
timer.h
|
|
@ -2,6 +2,7 @@
|
||||||
#define _timer_h_
|
#define _timer_h_
|
||||||
#include <lpc2148/gpio.h>
|
#include <lpc2148/gpio.h>
|
||||||
#include <lpc2148/timer.h>
|
#include <lpc2148/timer.h>
|
||||||
|
#include "parser.h"
|
||||||
|
|
||||||
void timer0_init();
|
void timer0_init();
|
||||||
void timer1_init();
|
void timer1_init();
|
||||||
|
|
@ -35,4 +36,7 @@ int timer_wait_pin_status(const struct timer_wait *w)
|
||||||
return w->pinmask && (GPIO_FIO0PIN & w->pinmask) == w->pinvalue;
|
return w->pinmask && (GPIO_FIO0PIN & w->pinmask) == w->pinvalue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int timer_cmd(struct command *cmd, const struct command_par *par);
|
||||||
|
extern unsigned int timer_ticks;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue