Timer FRC1 & FRC2 registers

Mostly determined from reverse engineering and poking around.

Includes first "experiments" program with random bits and pieces for
poking at registers, may be useful to keep in source control but not
useful for writing actual programs.
This commit is contained in:
Angus Gratton 2015-06-12 17:04:17 +10:00
parent 8f3111c5e1
commit 1b0124cf05
6 changed files with 456 additions and 2 deletions

View file

@ -0,0 +1,127 @@
/*
FreeRTOS V7.5.2 - Copyright (C) 2013 Real Time Engineers Ltd.
VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
***************************************************************************
* *
* FreeRTOS provides completely free yet professionally developed, *
* robust, strictly quality controlled, supported, and cross *
* platform software that has become a de facto standard. *
* *
* Help yourself get started quickly and support the FreeRTOS *
* project by purchasing a FreeRTOS tutorial book, reference *
* manual, or both from: http://www.FreeRTOS.org/Documentation *
* *
* Thank you! *
* *
***************************************************************************
This file is part of the FreeRTOS distribution.
FreeRTOS is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License (version 2) as published by the
Free Software Foundation >>!AND MODIFIED BY!<< the FreeRTOS exception.
>>! NOTE: The modification to the GPL is included to allow you to distribute
>>! a combined work that includes FreeRTOS without being obliged to provide
>>! the source code for proprietary components outside of the FreeRTOS
>>! kernel.
FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. Full license text is available from the following
link: http://www.freertos.org/a00114.html
1 tab == 4 spaces!
***************************************************************************
* *
* Having a problem? Start by reading the FAQ "My application does *
* not run, what could be wrong?" *
* *
* http://www.FreeRTOS.org/FAQHelp.html *
* *
***************************************************************************
http://www.FreeRTOS.org - Documentation, books, training, latest versions,
license and Real Time Engineers Ltd. contact details.
http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
including FreeRTOS+Trace - an indispensable productivity tool, a DOS
compatible FAT file system, and our tiny thread aware UDP/IP stack.
http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High
Integrity Systems to sell under the OpenRTOS brand. Low cost OpenRTOS
licenses offer ticketed support, indemnification and middleware.
http://www.SafeRTOS.com - High Integrity Systems also provide a safety
engineered and independently SIL3 certified version for use in safety and
mission critical applications that require provable dependability.
1 tab == 4 spaces!
*/
#ifndef FREERTOS_CONFIG_H
#define FREERTOS_CONFIG_H
/*-----------------------------------------------------------
* Application specific definitions.
*
* These definitions should be adjusted for your particular hardware and
* application requirements.
*
* THESE PARAMETERS ARE DESCRIBED WITHIN THE 'CONFIGURATION' SECTION OF THE
* FreeRTOS API DOCUMENTATION AVAILABLE ON THE FreeRTOS.org WEB SITE.
*
* See http://www.freertos.org/a00110.html.
*----------------------------------------------------------*/
#define configUSE_PREEMPTION 1
#define configUSE_IDLE_HOOK 0
#define configUSE_TICK_HOOK 0
#define configCPU_CLOCK_HZ ( ( unsigned long ) 80000000 )
#define configTICK_RATE_HZ ( ( portTickType ) 100 )
#define configMAX_PRIORITIES ( ( unsigned portBASE_TYPE ) 15 )
#define configMINIMAL_STACK_SIZE ( ( unsigned short )156 )
#define configTOTAL_HEAP_SIZE ( ( size_t ) ( 32 * 1024 ) )
#define configMAX_TASK_NAME_LEN ( 16 )
#define configUSE_TRACE_FACILITY 0
#define configUSE_STATS_FORMATTING_FUNCTIONS 0
#define configUSE_16_BIT_TICKS 0
#define configIDLE_SHOULD_YIELD 1
#define INCLUDE_xTaskGetIdleTaskHandle 1
#define INCLUDE_xTimerGetTimerDaemonTaskHandle 1
#define configCHECK_FOR_STACK_OVERFLOW 2
#define configUSE_MUTEXES 1
#define configUSE_TIMERS 1
#if configUSE_TIMERS
#define configTIMER_TASK_PRIORITY ( tskIDLE_PRIORITY + 2 )
#define configTIMER_QUEUE_LENGTH (10)
#define configTIMER_TASK_STACK_DEPTH ( ( unsigned short ) 512 )
#endif
/* Co-routine definitions. */
#define configUSE_CO_ROUTINES 0
#define configMAX_CO_ROUTINE_PRIORITIES ( 2 )
/* Set the following definitions to 1 to include the API function, or zero
to exclude the API function. */
#define INCLUDE_vTaskPrioritySet 1
#define INCLUDE_uxTaskPriorityGet 1
#define INCLUDE_vTaskDelete 1
#define INCLUDE_vTaskCleanUpResources 0
#define INCLUDE_vTaskSuspend 1
#define INCLUDE_vTaskDelayUntil 1
#define INCLUDE_vTaskDelay 1
/*set the #define for debug info*/
#define INCLUDE_xTaskGetCurrentTaskHandle 1
#define INCLUDE_uxTaskGetStackHighWaterMark 1
#endif /* FREERTOS_CONFIG_H */

View file

@ -0,0 +1,2 @@
PROGRAM=timers
include ../../../common.mk

View file

@ -0,0 +1,140 @@
/* Experiments to dump timer registers at various points, mess around
* with timer registers.
*
* NOT good code, not example code, nothing something you probably
* want to mess with.
*
* This experimental reverse engineering code is in the public domain.
*/
#include "espressif/esp_common.h"
#include "espressif/sdk_private.h"
#include "FreeRTOS.h"
#include "task.h"
#include "esp8266.h"
#define DUMP_SZ 0x10 /* number of regs not size of buffer */
IRAM void dump_frc1_seq(void)
{
uint32_t f1_a = TIMER_FRC1_COUNT_REG;
uint32_t f1_b = TIMER_FRC1_COUNT_REG;
uint32_t f1_c = TIMER_FRC1_COUNT_REG;
printf("FRC1 sequence 0x%08x 0x%08x 0x%08x\r\n", f1_a, f1_b, f1_c);
printf("FRC1 deltas %d %d \r\n", f1_b-f1_a, f1_c-f1_b);
}
IRAM void dump_frc2_seq(void)
{
/* this sequence of reads compiles down to sequence of l32is with
* memw instructions in between.
*
* counts at various divisor values:
* /1 = 13
* /16 = 0 or 1 (usually 1)
*
*/
uint32_t f2_a = TIMER_FRC2_COUNT_REG;
uint32_t f2_b = TIMER_FRC2_COUNT_REG;
uint32_t f2_c = TIMER_FRC2_COUNT_REG;
printf("FRC2 sequence 0x%08x 0x%08x 0x%08x\r\n", f2_a, f2_b, f2_c);
printf("FRC2 deltas %d %d \r\n", f2_b-f2_a, f2_c-f2_b);
}
IRAM void dump_timer_regs(const char *msg)
{
esp_reg_t reg = (esp_reg_t)TIMER_BASE;
static uint32_t chunk[DUMP_SZ];
/* load everything as quickly as possible to get a "snapshot" */
for(int i = 0; i < DUMP_SZ; i++) {
chunk[i] = reg[i];
}
printf("%s:\r\n", msg);
/* print the chunk we loaded */
for(int i = 0; i < DUMP_SZ; i++) {
if(i % 4 == 0)
printf("%s0x%02x: ", i ? "\r\n" : "", i*4);
printf("%08x ", chunk[i]);
}
printf("\r\n");
dump_frc1_seq();
dump_frc2_seq();
}
extern uint32_t isr[16];
extern uint32_t seen_isr[16];
extern uint32_t max_count;
static volatile uint32_t frc2_handler_call_count;
static volatile uint32_t frc2_last_count_val;
static volatile uint32_t frc1_handler_call_count;
static volatile uint32_t frc1_last_count_val;
void timerRegTask(void *pvParameters)
{
while(1) {
printf("state at task tick count %d:\r\n", xTaskGetTickCount());
dump_timer_regs("");
/*
for(int i = 0; i < 16; i++) {
printf("int 0x%02x: 0x%08x (%d)\r\n", i, isr[i], seen_isr[i]);
}
printf("INUM_MAX count %d\r\n", max_count);
*/
printf("frc1 handler called %d times, last value 0x%08x\r\n", frc1_handler_call_count,
frc1_last_count_val);
printf("frc2 handler called %d times, last value 0x%08x\r\n", frc2_handler_call_count,
frc2_last_count_val);
vTaskDelay(500 / portTICK_RATE_MS);
}
}
IRAM void frc1_handler(void)
{
frc1_handler_call_count++;
frc1_last_count_val = TIMER_FRC1_COUNT_REG;
//TIMER_FRC1_LOAD_REG = 0x300000;
//TIMER_FRC1_CLEAR_INT = 0;
//TIMER_FRC1_MATCH_REG = frc1_last_count_val + 0x100000;
}
void frc2_handler(void)
{
frc2_handler_call_count++;
frc2_last_count_val = TIMER_FRC2_COUNT_REG;
TIMER_FRC2_MATCH_REG = frc2_last_count_val + 0x100000;
//TIMER_FRC2_LOAD_REG = 0;
//TIMER_FRC2_LOAD_REG = 0x2000000;
//TIMER_FRC2_CLEAR_INT_REG = 0;
}
void user_init(void)
{
sdk_uart_div_modify(0, UART_CLK_FREQ / 115200);
xTaskCreate(timerRegTask, (signed char *)"timerRegTask", 1024, NULL, 2, NULL);
TIMER_FRC1_CTRL_REG = TIMER_CTRL_DIV_256|TIMER_CTRL_INT_EDGE|TIMER_CTRL_RELOAD;
TIMER_FRC1_LOAD_REG = 0x200000;
TIMER_FRC2_CTRL_REG = TIMER_CTRL_DIV_256|TIMER_CTRL_INT_EDGE;
DP_INT_ENABLE_REG |= INT_ENABLE_FRC1|INT_ENABLE_FRC2;
_xt_isr_attach(INUM_TIMER_FRC1, frc1_handler);
_xt_isr_unmask(1<<INUM_TIMER_FRC1);
_xt_isr_attach(INUM_TIMER_FRC2, frc2_handler);
_xt_isr_unmask(1<<INUM_TIMER_FRC2);
TIMER_FRC1_CTRL_REG |= TIMER_CTRL_RUN;
TIMER_FRC2_CTRL_REG |= TIMER_CTRL_RUN;
dump_timer_regs("timer regs during user_init");
dump_timer_regs("#2 timer regs during user_init");
dump_timer_regs("#3 timer regs during user_init");
}