Compare commits

..

No commits in common. "9f30b24b7f3f56cddd05f10a223c12f2fda4fe29" and "a3bf7a7275adc24698aa4245d019876ac0e52196" have entirely different histories.

5 changed files with 11 additions and 124 deletions

View file

@ -525,7 +525,6 @@ 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}},
@ -858,7 +857,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),

View file

@ -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 const struct timer_wait wait_conversion; extern 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,6 +18,7 @@ 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))
@ -156,7 +157,7 @@ static void wait_callback(const volatile struct timer_tick* tick) {
} }
} }
const struct timer_wait wait_conversion = { 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,

2
ssp.c
View file

@ -411,7 +411,7 @@ int ssp_run_batch()
mclk_wait.mclk = f & ssp_b_count; mclk_wait.mclk = f & ssp_b_count;
wait = &mclk_wait; wait = &mclk_wait;
} }
if (timer_wait_init(wait, (void*)batch)) timer_wait_init(wait, (void*)batch);
return 0; return 0;
} }

119
timer.c
View file

@ -1,7 +1,6 @@
#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>
@ -11,12 +10,11 @@ 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 int n = tick->n + 1; unsigned short n = tick->n;
if (n) if (n != 0xffff)
tick->n = n; tick->n = n+1;
if (tick->callback) if (tick->callback)
tick->callback(tick); tick->callback(tick);
VICVectAddr = 0;
} }
__attribute__ ((interrupt ("IRQ"))) __attribute__ ((interrupt ("IRQ")))
@ -54,7 +52,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_MR0R | TxMCR_MR0S | TxMCR_MR0I; T1MCR = TxMCR_MR0S | TxMCR_MR0I;
T1TCR = TxTCR_Counter_Reset; T1TCR = TxTCR_Counter_Reset;
VICVectAddrs[IrqVec_Timer1] = timer1_isr; VICVectAddrs[IrqVec_Timer1] = timer1_isr;
@ -112,7 +110,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 = 600000000; // 10s T1MR0 = 6000000; // 100ms
T1TCR = TxTCR_Counter_Enable; T1TCR = TxTCR_Counter_Enable;
} }
if (wait->mclk) { if (wait->mclk) {
@ -166,110 +164,3 @@ 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;
}

View file

@ -2,7 +2,6 @@
#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();
@ -36,7 +35,4 @@ 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