61 lines
1.4 KiB
C
61 lines
1.4 KiB
C
#include <stdint.h>
|
|
#include <string.h>
|
|
#include <assert.h>
|
|
|
|
#include "drv_omap35x_gpt.h"
|
|
#include "omap35x_intc.h"
|
|
|
|
#define TIOCP_CFG 4
|
|
#define TISR 6
|
|
#define TIER 7
|
|
#define TWER 8
|
|
#define TCLR 9
|
|
#define TCRR 10
|
|
#define TLDR 11
|
|
#define TPIR 18
|
|
#define TNIR 19
|
|
|
|
int omap35x_gpt_init(omap35x_gpt_handle* handle, uint32_t base, int irq) {
|
|
assert(handle != NULL);
|
|
|
|
handle->base = (uint32_t*)base;
|
|
handle->irq = irq;
|
|
handle->handler = NULL;
|
|
handle->handler_data = NULL;
|
|
|
|
return 0;
|
|
}
|
|
|
|
void _omap35x_gpt_irqhandler(void *data);
|
|
|
|
int omap35x_gpt_ticktimer(omap35x_gpt_handle* handle, omap35x_intc_hfunc handler, void *data) {
|
|
assert(handle != NULL);
|
|
|
|
handle->base[TIOCP_CFG] = 0x215; // Clockactiviy = 2, emufree = 0, idlemode = 2 (smartidle), wakeup = ena, autoidle = 1
|
|
handle->base[TLDR] = -327;
|
|
handle->base[TCRR] = -327;
|
|
handle->base[TPIR] = 320000;
|
|
handle->base[TNIR] = -680000;
|
|
|
|
handle->handler = handler;
|
|
handle->handler_data = data;
|
|
omap35x_intc_register(handle->irq, &_omap35x_gpt_irqhandler, (void*)handle, 0);
|
|
|
|
handle->base[TCLR] = 0x3; // autoreload = 1, start = 1
|
|
|
|
handle->base[TIER] = 0x2; // Overflow int = enable
|
|
handle->base[TWER] = 0x2; // Overflow wakeup = enable
|
|
|
|
omap35x_intc_ena(handle->irq);
|
|
|
|
return 0;
|
|
}
|
|
|
|
void _omap35x_gpt_irqhandler(void *data) {
|
|
omap35x_gpt_handle *handle = (omap35x_gpt_handle*)data;
|
|
if(handle->handler != NULL)
|
|
handle->handler(handle->handler_data);
|
|
|
|
handle->base[TISR] = 0x2;
|
|
}
|