Commit d9c18856 authored by Sergi Hernandez's avatar Sergi Hernandez
Browse files

Merge branch 'revert-59fde70f' into 'master'

Revert "Changes to use the new momory data structures to handle the devices modules memory."

See merge request !1
parents 59fde70f 2741aab9
......@@ -4,15 +4,7 @@ STM32_HAL_PATH=$(HOME)/humanoids/stm32_hal
STM32_LIBRARIES_PATH=$(HOME)/humanoids/stm32_libraries
PROJECT_NAME=bioloid_firmware
#TARGET_FILES=$(wildcard src/*.c)
TARGET_FILES=src/eeprom.c
TARGET_FILES+=src/adc_dma.c
TARGET_FILES+=src/system_stm32f4xx.c
TARGET_FILES+=src/bioloid_stm32.c
TARGET_FILES+=src/bioloid_time.c
TARGET_FILES+=src/bioloid_dyn_slave.c
TARGET_FILES+=src/gpio.c
TARGET_FILES+=src/bioloid_dyn_manager.c
TARGET_FILES=$(wildcard src/*.c)
TARGET_PROCESSOR=STM32F407VG
HAL_PATH=$(STM32_HAL_PATH)/f4
......@@ -23,19 +15,17 @@ STM32_STARTUP_FILES_PATH = $(HAL_PATH)/startup_code/
STM32_LINKER_SCRIPTS_PATH = ./linker_script
UTILS_PATH=$(STM32_LIBRARIES_PATH)/utils
COMM_PATH=$(STM32_LIBRARIES_PATH)/comm
MEMORY_PATH=$(STM32_LIBRARIES_PATH)/memory
USART_PATH=$(STM32_LIBRARIES_PATH)/f4/usart
DYNAMIXEL_PATH=$(STM32_LIBRARIES_PATH)/dynamixel_base
DYNAMIXEL_MANAGER_PATH=$(STM32_LIBRARIES_PATH)/dynamixel_manager
BUILD_PATH=build
COMPILE_OPTS = -mlittle-endian -mcpu=cortex-m4 -mthumb -mthumb-interwork
COMPILE_OPTS += -Wall -O2 -fno-common -DUSE_HAL_DRIVER
COMPILE_OPTS += -mfloat-abi=hard -mfpu=fpv4-sp-d16
COMPILE_OPTS += -ffreestanding -nostdlib -D$(PROCESSOR_MACRO) -DARM_MATH_CM4 -D__FPU_PRESENT -DHSE_VALUE=8000000 -imacros ./include/bioloid_conf.h
COMPILE_OPTS += -ffreestanding -nostdlib -D$(PROCESSOR_MACRO) -DARM_MATH_CM4 -D__FPU_PRESENT -DHSE_VALUE=8000000
INCLUDE_DIRS = -I$(HAL_PATH)/include -I$(HAL_PATH)/include/core -I$(HAL_PATH)/include/devices
INCLUDE_DIRS += -I$(UTILS_PATH)/include -I$(COMM_PATH)/include -I$(MEMORY_PATH)/include -I$(DYNAMIXEL_PATH)/include -I$(DYNAMIXEL_MANAGER_PATH)/include -I$(USART_PATH)/include -I./include
LIBRARY_DIRS = -L$(STM32_LIB_PATH)/lib -L$(STM32_DSP_LIB_PATH)/lib -L/usr/arm-none-eabi/lib/fpu/
INCLUDE_DIRS += -I$(UTILS_PATH)/include -I$(COMM_PATH)/include -I$(DYNAMIXEL_PATH)/include -I$(USART_PATH)/include -I./include
LIBRARY_DIRS = -L$(STM32_LIB_PATH)/lib -L$(STM32_DSP_LIB_PATH)/lib -L$(DYNAMIXEL_LIB_PATH)/lib -L/usr/arm-none-eabi/lib/fpu/
TCHAIN_PREFIX=arm-none-eabi-
......@@ -47,6 +37,7 @@ ASFLAGS = $(COMPILE_OPTS) -c
LD = $(TCHAIN_PREFIX)gcc
LDFLAGS = -mthumb -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -Wl,-Map=$@.map,-cref $(INCLUDE_DIRS) -T $(STM32_LINKER_SCRIPTS_PATH)/bioloid.ld --specs=nosys.specs
EXT_LIB = $(COMM_PATH)/lib/comm_m4_fpu.a $(UTILS_PATH)/lib/utils_m4_fpu.a $(DYNAMIXEL_PATH)/lib/dynamixel_m4_fpu.a
OBJCP = $(TCHAIN_PREFIX)objcopy
OBJCPFLAGS_HEX = -O ihex
......@@ -79,12 +70,6 @@ TARGET_FILES+=$(USART_PATH)/src/usart3.c
TARGET_FILES+=$(USART_PATH)/src/usart2.c
TARGET_FILES+=$(USART_PATH)/src/usart1.c
TARGET_FILES+=$(wildcard $(UTILS_PATH)/src/*.c)
TARGET_FILES+=$(wildcard $(COMM_PATH)/src/*.c)
TARGET_FILES+=$(wildcard $(MEMORY_PATH)/src/*.c)
TARGET_FILES+=$(wildcard $(DYNAMIXEL_PATH)/src/*.c)
TARGET_FILES+=$(wildcard $(DYNAMIXEL_MANAGER_PATH)/src/*.c)
BIOLOID_OBJS_TMP = $(notdir $(TARGET_FILES:.c=.o))
BIOLOID_OBJS = $(patsubst %,$(BUILD_PATH)/%,$(BIOLOID_OBJS_TMP))
......@@ -101,19 +86,9 @@ $(BUILD_PATH)/%.o: $(HAL_PATH)/src/%.c
$(CC) -c $(CFLAGS) -o $@ $<
$(BUILD_PATH)/%.o: $(USART_PATH)/src/%.c
$(CC) -c $(CFLAGS) -o $@ $<
$(BUILD_PATH)/%.o: $(UTILS_PATH)/src/%.c
$(CC) -c $(CFLAGS) -o $@ $<
$(BUILD_PATH)/%.o: $(COMM_PATH)/src/%.c
$(CC) -c $(CFLAGS) -o $@ $<
$(BUILD_PATH)/%.o: $(MEMORY_PATH)/src/%.c
$(CC) -c $(CFLAGS) -o $@ $<
$(BUILD_PATH)/%.o: $(DYNAMIXEL_PATH)/src/%.c
$(CC) -c $(CFLAGS) -o $@ $<
$(BUILD_PATH)/%.o: $(DYNAMIXEL_MANAGER_PATH)/src/%.c
$(CC) -c $(CFLAGS) -o $@ $<
$(MAIN_OUT_ELF): mkdir_build $(BIOLOID_OBJS) $(BUID_PATH)/$(STARTUP_FILE:.s=.o)
$(LD) $(LDFLAGS) $(BIOLOID_OBJS) $(BUILD_PATH)/$(STARTUP_FILE:.s=.o) -lm --output $@
$(LD) $(LDFLAGS) $(BIOLOID_OBJS) $(BUILD_PATH)/$(STARTUP_FILE:.s=.o) $(EXT_LIB) -lm --output $@
$(MAIN_OUT_HEX): $(MAIN_OUT_ELF)
$(OBJCP) $(OBJCPFLAGS_HEX) $< $@
......
......@@ -6,13 +6,11 @@ extern "C" {
#endif
#include "stm32f4xx.h"
#include "adc_dma_registers.h"
#include "memory.h"
typedef enum {ADC_CH1,ADC_CH2,ADC_CH3,ADC_CH4,ADC_CH6,ADC_CH8} adc_ch_t;
// public functions
uint8_t adc_init(TMemory *memory);
void adc_init(void);
void adc_start(void);
void adc_set_period(uint8_t period_ms);
inline uint8_t adc_get_period(void);
......@@ -20,6 +18,9 @@ unsigned short adc_get_channel(adc_ch_t channel);
unsigned short adc_get_channel_raw(adc_ch_t channel);
unsigned short adc_get_temperature(void);
void adc_stop(void);
// operation functions
uint8_t adc_in_range(unsigned short int address,unsigned short int length);
void adc_process_write_cmd(unsigned short int address,unsigned short int length,unsigned char *data);
#ifdef __cplusplus
}
......
#ifndef _ADC_DMA_REGISTERS_H
#define _ADC_DMA_REGISTERS_H
#ifndef RAM_ADC_DMA_BASE_ADDRESS
#define RAM_ADC_DMA_BASE_ADDRESS ((unsigned short int)0x0000)
#endif
#ifndef EEPROM_ADC_DMA_BASE_ADDRESS
#define EEPROM_ADC_DMA_BASE_ADDRESS ((unsigned short int)0x0000)
#endif
#define RAM_ADC_DMA_LENGTH 17
#define EEPROM_ADC_DMA_LENGTH 1
#define ADC_CNTRL RAM_ADC_DMA_BASE_ADDRESS// bit 7 | bit 6 | bit 5 | bit 4 | bit 3 | bit 2 | bit 1 | bit 0
// | | | | | | | Enable
#define ADC_CH1_VOLTAGE (RAM_ADC_DMA_BASE_ADDRESS+1)
#define ADC_CH2_VOLTAGE (RAM_ADC_DMA_BASE_ADDRESS+3)
#define ADC_CH3_VOLTAGE (RAM_ADC_DMA_BASE_ADDRESS+5)
#define ADC_CH4_VOLTAGE (RAM_ADC_DMA_BASE_ADDRESS+7)
#define ADC_TEMPERATURE (RAM_ADC_DMA_BASE_ADDRESS+9)
#define ADC_CH6_VOLTAGE (RAM_ADC_DMA_BASE_ADDRESS+11)
#define ADC_VREF_VOLTAGE (RAM_ADC_DMA_BASE_ADDRESS+13)
#define ADC_CH8_VOLTAGE (RAM_ADC_DMA_BASE_ADDRESS+15)
#define ADC_ENABLE 0x01
#define ADC_PERIOD EEPROM_ADC_DMA_BASE_ADDRESS
#ifndef DEFAULT_ADC_PERIOD
#define DEFAULT_ADC_PERIOD 0x0A
#endif
#endif
#ifndef _BIOLOID_CONF_H
#define _BIOLOID_CONF_H
#define RAM_SIZE 1024
#define EEPROM_SIZE 256
/* ADC configuration */
#define RAM_ADC_DMA_BASE_ADDRESS ((unsigned short int)0x0100)
#define EEPROM_ADC_DMA_BASE_ADDRESS ((unsigned short int)0x0006)
#define DEFAULT_ADC_PERIOD 0x0A
/* Dynamixel slave configuration */
#define EEPROM_DYN_SLAVE_BASE_ADDRESS1 ((unsigned short int)0x0000)
#define EEPROM_DYN_SLAVE_BASE_ADDRESS2 ((unsigned short int)0x0010)
#define DEFAULT_DEVICE_MODEL 0x7300
#define DEFAULT_FIRMWARE_VERSION 0x0001
#define DEFAULT_DEVICE_ID 0x0001
#define DEFAULT_BAUDRATE 0x0010
#define DEFAULT_RETURN_DELAY 0x0000
#define DEFAULT_RETURN_LEVEL 0x0002
#define MAX_DYN_SLAVE_TX_BUFFER_LEN 1024
#define MAX_DYN_SLAVE_RX_BUFFER_LEN 1024
#define MAX_DYN_SLAVE_REG_BUFFER_LEN 1024
/* Servos Dynamixel master configuration */
#define MAX_SERVOS_DYN_MASTER_TX_BUFFER_LEN 1024
#define MAX_SERVOS_DYN_MASTER_RX_BUFFER_LEN 1024
#define MAX_SENSORS_DYN_MASTER_TX_BUFFER_LEN 1024
#define MAX_SENSORS_DYN_MASTER_RX_BUFFER_LEN 1024
/* Dynamixel manager configuration */
#define RAM_DYN_MANAGER_BASE_ADDRESS ((unsigned short int)0x0121)
#define EEPROM_DYN_MANAGER_BASE_ADDRESS ((unsigned short int)0x0007)
#define DEFAULT_DYN_MANAGER_PERIOD 0x1E78
#define DYN_MANAGER_MAX_NUM_MASTERS 4
#define DYN_MANAGER_MAX_NUM_MODULES 8
#define DYN_MANAGER_MAX_NUM_DEVICES 32
#define DYN_MANAGER_MAX_NUM_SINGLE_OP 16
#define DYN_MANAGER_MAX_NUM_SYNC_OP 4
#define DYN_MANAGER_MAX_NUM_BULK_OP 4
/* Motion Manager configuration */
#define RAM_MM_BASE_ADDRESS ((unsigned short int)0x0000)
#define EEPROM_MM_BASE_ADDRESS ((unsigned short int)0x0000)
#define DEFAULT_MM_PERIOD DEFAULT_DYN_MODULE_PERIOD
#define MM_MAX_NUM_MODELS 32
#define MM_MAX_NUM_MOTION_MODULES 8
/* GPIO configuration */
#define RAM_GPIO_BASE_ADDRESS ((unsigned short int)0x0111)
#endif
#ifndef _BIOLOID_DYN_MANAGER_H
#define _BIOLOID_DYN_MANAGER_H
#ifdef __cplusplus
extern "C" {
#endif
#include "stm32f4xx.h"
#include "memory.h"
uint8_t bioloid_dyn_manager_init(TMemory *memory);
#ifdef __cplusplus
}
#endif
#endif
......@@ -6,12 +6,10 @@ extern "C" {
#endif
#include "stm32f4xx.h"
#include "stm32_time.h"
#include "dynamixel_master.h"
#include "comm.h"
#define MAX_DYN_MASTER_TX_BUFFER_LEN MAX_SENSORS_DYN_MASTER_TX_BUFFER_LEN
#define MAX_DYN_MASTER_RX_BUFFER_LEN MAX_SENSORS_DYN_MASTER_RX_BUFFER_LEN
void bioloid_dyn_master_sensors_init(void);
#ifdef __cplusplus
......
......@@ -9,9 +9,6 @@ extern "C" {
#include "dynamixel_master.h"
#include "comm.h"
#define MAX_DYN_MASTER_TX_BUFFER_LEN MAX_SERVOS_DYN_MASTER_TX_BUFFER_LEN
#define MAX_DYN_MASTER_RX_BUFFER_LEN MAX_SERVOS_DYN_MASTER_RX_BUFFER_LEN
extern TDynamixelMaster bioloid_dyn_master_servos;
void bioloid_dyn_master_servos_init(void);
......
......@@ -7,9 +7,8 @@ extern "C" {
#include "stm32f4xx.h"
#include "dynamixel_slave.h"
#include "memory.h"
uint8_t bioloid_dyn_slave_init(TMemory *memory);
void bioloid_dyn_slave_init(void);
void bioloid_dyn_slave_start(void);
void bioloid_dyn_slave_stop(void);
void bioloid_dyn_slave_set_int(void);
......
......@@ -5,10 +5,17 @@
extern "C" {
#endif
#define DEVICE_MODEL_OFFSET ((unsigned short int)0x0000)
#define FIRMWARE_VERSION_OFFSET ((unsigned short int)0x0002)
#define DEVICE_ID_OFFSET ((unsigned short int)0x0003)
#define BAUDRATE_OFFSET ((unsigned short int)0x0004)
#define RETURN_DELAY_OFFSET ((unsigned short int)0x0005)
#define MM_PERIOD_OFFSET ((unsigned short int)0x0006)
#define MM_BAL_KNEE_GAIN_OFFSET ((unsigned short int)0x0008)
#define MM_BAL_ANKLE_ROLL_GAIN_OFFSET ((unsigned short int)0x000A)
#define MM_BAL_ANKLE_PITCH_GAIN_OFFSET ((unsigned short int)0x000C)
#define MM_BAL_HIP_ROLL_GAIN_OFFSET ((unsigned short int)0x000E)
#define RETURN_LEVEL_OFFSET ((unsigned short int)0x0010)
#define MM_SERVO0_OFFSET ((unsigned short int)0x0011)
#define MM_SERVO1_OFFSET ((unsigned short int)0x0012)
#define MM_SERVO2_OFFSET ((unsigned short int)0x0013)
......@@ -64,6 +71,14 @@ extern "C" {
#define LAST_EEPROM_OFFSET ((unsigned short int)0x00FF)
typedef enum {
BIOLOID_MODEL_NUMBER_L = DEVICE_MODEL_OFFSET,
BIOLOID_MODEL_NUMBER_H = DEVICE_MODEL_OFFSET+1,
BIOLOID_VERSION = FIRMWARE_VERSION_OFFSET,
BIOLOID_ID = DEVICE_ID_OFFSET,
BIOLOID_BAUD_RATE = BAUDRATE_OFFSET,
BIOLOID_RETURN_DELAY_TIME = RETURN_DELAY_OFFSET,
BIOLOID_MM_PERIOD_L = MM_PERIOD_OFFSET,
BIOLOID_MM_PERIOD_H = MM_PERIOD_OFFSET+1,
BIOLOID_MM_BAL_KNEE_GAIN_L = MM_BAL_KNEE_GAIN_OFFSET,// fixed point format 0|16
BIOLOID_MM_BAL_KNEE_GAIN_H = MM_BAL_KNEE_GAIN_OFFSET+1,
BIOLOID_MM_BAL_ANKLE_ROLL_GAIN_L = MM_BAL_ANKLE_ROLL_GAIN_OFFSET,// fixed point format 0|16
......@@ -72,6 +87,7 @@ typedef enum {
BIOLOID_MM_BAL_ANKLE_PITCH_GAIN_H = MM_BAL_ANKLE_PITCH_GAIN_OFFSET+1,
BIOLOID_MM_BAL_HIP_ROLL_GAIN_L = MM_BAL_HIP_ROLL_GAIN_OFFSET,// fixed point format 0|16
BIOLOID_MM_BAL_HIP_ROLL_GAIN_H = MM_BAL_HIP_ROLL_GAIN_OFFSET+1,
BIOLOID_RETURN_LEVEL = RETURN_LEVEL_OFFSET,
BIOLOID_MM_SERVO0_OFFSET = MM_SERVO0_OFFSET, // angle offset in fixed point format 1-3|4
BIOLOID_MM_SERVO1_OFFSET = MM_SERVO1_OFFSET, // angle offset in fixed point format 1-3|4
BIOLOID_MM_SERVO2_OFFSET = MM_SERVO2_OFFSET, // angle offset in fixed point format 1-3|4
......@@ -125,6 +141,49 @@ typedef enum {
BIOLOID_WALK_ARM_SWING_GAIN = WALK_ARM_SWING_GAIN,
BIOLOID_WALK_MAX_VEL = WALK_MAX_VEL,
BIOLOID_WALK_MAX_ROT_VEL = WALK_MAX_ROT_VEL,
BIOLOID_USER1_LED_CNTRL = 0x0100, // bit 7 | bit 6 | bit 5 | bit 4 | bit 3 | bit 2 | bit 1 | bit 0
// | | | | blink | toggle | value | internally used
BIOLOID_USER1_LED_PERIOD_L = 0x0101,
BIOLOID_USER1_LED_PERIOD_H = 0x0102,
BIOLOID_USER2_LED_CNTRL = 0x0103, // bit 7 | bit 6 | bit 5 | bit 4 | bit 3 | bit 2 | bit 1 | bit 0
// | | | | blink | toggle | value | internally used
BIOLOID_USER2_LED_PERIOD_L = 0x0104,
BIOLOID_USER2_LED_PERIOD_H = 0x0105,
BIOLOID_RXD_LED_CNTRL = 0x0106, // bit 7 | bit 6 | bit 5 | bit 4 | bit 3 | bit 2 | bit 1 | bit 0
// | | | | blink | toggle | value | internally used
BIOLOID_RXD_LED_PERIOD_L = 0x0107,
BIOLOID_RXD_LED_PERIOD_H = 0x0108,
BIOLOID_TXD_LED_CNTRL = 0x0109, // bit 7 | bit 6 | bit 5 | bit 4 | bit 3 | bit 2 | bit 1 | bit 0
// | | | | blink | toggle | value | internally used
BIOLOID_TXD_LED_PERIOD_L = 0x010A,
BIOLOID_TXD_LED_PERIOD_H = 0x010B,
BIOLOID_USER_PB_CNTRL = 0x010C, // bit 7 | bit 6 | bit 5 | bit 4 | bit 3 | bit 2 | bit 1 | bit 0
// | | | | interrupt flag | enable interrupt | value | internally used
BIOLOID_RESET_PB_CNTRL = 0x010D, // bit 7 | bit 6 | bit 5 | bit 4 | bit 3 | bit 2 | bit 1 | bit 0
// | | | | interrupt flag | enable interrupt | value | internally used
BIOLOID_START_PB_CNTRL = 0x010E, // bit 7 | bit 6 | bit 5 | bit 4 | bit 3 | bit 2 | bit 1 | bit 0
// | | | | interrupt flag | enable interrupt | value | internally used
BIOLOID_MODE_PB_CNTRL = 0x010F, // bit 7 | bit 6 | bit 5 | bit 4 | bit 3 | bit 2 | bit 1 | bit 0
// | | | | interrupt flag | enable interrupt | value | internally used
BIOLOID_ADC_CNTRL = 0x0110, // bit 7 | bit 6 | bit 5 | bit 4 | bit 3 | bit 2 | bit 1 | bit 0
// | | | | | | | Enable
BIOLOID_ADC_PERIOD = 0x0111,
BIOLOID_ADC_CH1_L = 0x0112,
BIOLOID_ADC_CH1_H = 0x0113,
BIOLOID_ADC_CH2_L = 0x0114,
BIOLOID_ADC_CH2_H = 0x0115,
BIOLOID_ADC_CH3_L = 0x0116,
BIOLOID_ADC_CH3_H = 0x0117,
BIOLOID_ADC_CH4_L = 0x0118,
BIOLOID_ADC_CH4_H = 0x0119,
BIOLOID_ADC_TEMP_L = 0x011A,
BIOLOID_ADC_TEMP_H = 0x011B,
BIOLOID_ADC_CH6_L = 0x011C,
BIOLOID_ADC_CH6_H = 0x011D,
BIOLOID_ADC_VREF_L = 0x011E,
BIOLOID_ADC_VREF_H = 0x011F,
BIOLOID_ADC_CH8_L = 0x0120,
BIOLOID_ADC_CH8_H = 0x0121,
BIOLOID_ZIGBEE_CNTRL = 0x0122, // bit 7 | bit 6 | bit 5 | bit 4 | bit 3 | bit 2 | bit 1 | bit 0
// | | | | | | Enable | Enable power
BIOLOID_ZIGBEE_BAUDRATE = 0x0123,
......@@ -253,6 +312,19 @@ typedef enum {
BIOLOID_WALK_STEP_DIRECTION = 0x0185
} bioloid_registers;
#define GPIO_BASE_ADDRESS 0x0100
#define GPIO_MEM_LENGTH 16
#define GPIO_INT_USED 0x01
#define GPIO_VALUE 0x02
#define GPIO_TOGGLE 0x04
#define GPIO_BLINK 0x08
#define GPIO_INT_EN 0x02
#define GPIO_INT_FLAG 0x04
#define ADC_BASE_ADDRESS 0x0110
#define ADC_MEM_LENGTH 18
#define ADC_ENABLE 0x01
#define ZIGBEE_BASE_ADDRESS 0x0122
#define ZIGBEE_MEM_LENGTH 6
#define ZIGBEE_EN_PWR 0x01
......
......@@ -83,7 +83,7 @@ extern "C" {
#define PAGE_FULL ((uint8_t)0x80)
/* Variables' number */
#define EEPROM_NUM_VAR ((uint8_t)EEPROM_SIZE)
#define NB_OF_VAR ((uint8_t)0x46)
/* Exported types ------------------------------------------------------------*/
/* Exported macro ------------------------------------------------------------*/
......
......@@ -7,12 +7,19 @@ extern "C" {
#include "adc_dma.h"
#define DEFAULT_DEVICE_MODEL 0x7300
#define DEFAULT_FIRMWARE_VERSION 0x0001
#define DEFAULT_DEVICE_ID 0x0002
#define DEFAULT_BAUDRATE 0x0001
#define DEFAULT_RETURN_DELAY 0x0000
#define DEFAULT_MM_PERIOD 0x1E78
#define DEFAULT_BAL_KNEE_GAIN 0x04BE // 1/54 in fixed point format 0|16
#define DEFAULT_BAL_ANKLE_ROLL_GAIN 0x0CCD // 1/20
#define DEFAULT_BAL_ANKLE_PITCH_GAIN 0x0E39 // 1/18
#define DEFAULT_BAL_HIP_ROLL_GAIN 0x0666 // 1/40
#define DEFAULT_GYRO_FB_ADC_CH (uint16_t)ADC_CH1
#define DEFAULT_GYRO_LR_ADC_CH (uint16_t)ADC_CH2
#define DEFAULT_RETURN_LEVEL 0x0002
#define DEFAULT_SERVO0_OFFSET 0x0000 // 0 in fixed point format 4 (1+3) | 4
#define DEFAULT_SERVO1_OFFSET 0x0000 // 0 in fixed point format 4 (1+3) | 4
#define DEFAULT_SERVO2_OFFSET 0x0000 // 0 in fixed point format 4 (1+3) | 4
......
......@@ -6,14 +6,12 @@ extern "C" {
#endif
#include "stm32f4xx.h"
#include "gpio_registers.h"
#include "memory.h"
typedef enum {USER1_LED,USER2_LED,RXD_LED,TXD_LED} led_t;
typedef enum {USER_PB,RESET_PB,START_PB,MODE_PB} pushbutton_t;
uint8_t gpio_init(TMemory *memory);
void gpio_init(void);
// LED functions
void gpio_set_led(led_t led_id);
void gpio_clear_led(led_t led_id);
......@@ -22,6 +20,10 @@ void gpio_blink_led(led_t led_id, int16_t period_ms);
// Pushbuttons functions
uint8_t gpio_is_pushbutton_pressed(pushbutton_t pb_id);
void gpio_set_pushbutton_callback(pushbutton_t pb_id,void (*callback)(void));
// operation functions
uint8_t gpio_in_range(unsigned short int address,unsigned short int length);
void gpio_process_read_cmd(unsigned short int address,unsigned short int length,unsigned char *data);
void gpio_process_write_cmd(unsigned short int address,unsigned short int length,unsigned char *data);
#ifdef __cplusplus
}
......
#ifndef _GPIO_REGISTERS_H
#define _GPIO_REGISTERS_H
#ifndef RAM_GPIO_BASE_ADDRESS
#define RAM_GPIO_BASE_ADDRESS ((unsigned short int)0x0000)
#endif
#define RAM_GPIO_LENGTH 16
#define USER1_LED_CNTRL RAM_GPIO_BASE_ADDRESS// bit 7 | bit 6 | bit 5 | bit 4 | bit 3 | bit 2 | bit 1 | bit 0
// | | | | blink | toggle | value | internally used
#define USER1_LED_PERIOD (RAM_GPIO_BASE_ADDRESS+1)
#define USER2_LED_CNTRL (RAM_GPIO_BASE_ADDRESS+3)// bit 7 | bit 6 | bit 5 | bit 4 | bit 3 | bit 2 | bit 1 | bit 0
// | | | | blink | toggle | value | internally used
#define USER2_LED_PERIOD (RAM_GPIO_BASE_ADDRESS+4)
#define RXD_LED_CNTRL (RAM_GPIO_BASE_ADDRESS+6)// bit 7 | bit 6 | bit 5 | bit 4 | bit 3 | bit 2 | bit 1 | bit 0
// | | | | blink | toggle | value | internally used
#define RXD_LED_PERIOD (RAM_GPIO_BASE_ADDRESS+7)
#define TXD_LED_CNTRL (RAM_GPIO_BASE_ADDRESS+9)// bit 7 | bit 6 | bit 5 | bit 4 | bit 3 | bit 2 | bit 1 | bit 0
// | | | | blink | toggle | value | internally used
#define TXD_LED_PERIOD (RAM_GPIO_BASE_ADDRESS+10)
#define USER_PB_CNTRL (RAM_GPIO_BASE_ADDRESS+12)// bit 7 | bit 6 | bit 5 | bit 4 | bit 3 | bit 2 | bit 1 | bit 0
// | | | | interrupt flag | enable interrupt | value | internally used
#define RESET_PB_CNTRL (RAM_GPIO_BASE_ADDRESS+13)// bit 7 | bit 6 | bit 5 | bit 4 | bit 3 | bit 2 | bit 1 | bit 0
// | | | | interrupt flag | enable interrupt | value | internally used
#define START_PB_CNTRL (RAM_GPIO_BASE_ADDRESS+14)// bit 7 | bit 6 | bit 5 | bit 4 | bit 3 | bit 2 | bit 1 | bit 0
// | | | | interrupt flag | enable interrupt | value | internally used
#define MODE_PB_CNTRL (RAM_GPIO_BASE_ADDRESS+15)// bit 7 | bit 6 | bit 5 | bit 4 | bit 3 | bit 2 | bit 1 | bit 0
// | | | | interrupt flag | enable interrupt | value | internally used
#define GPIO_INT_USED 0x01
#define GPIO_VALUE 0x02
#define GPIO_TOGGLE 0x04
#define GPIO_BLINK 0x08
#define GPIO_INT_EN 0x02
#define GPIO_INT_FLAG 0x04
#endif
#ifndef _RAM_H
#define _RAM_H
#ifdef __cplusplus
extern "C" {
#endif
#include "stm32f4xx.h"
#include "bioloid_registers.h"
#define RAM_SUCCESS 0
#define RAM_BAD_ADDRESS -1
#define RAM_WRITE_ERROR -2
#define RAM_BAD_BIT -3
#define RAM_BAD_ACCESS -4
#define RAM_SIZE 512
extern uint8_t ram_data[RAM_SIZE];
void ram_init(void);
inline void ram_read_byte(uint16_t address, uint8_t *data);
inline void ram_read_word(uint16_t address, uint16_t *data);
uint8_t ram_read_table(uint16_t address, uint16_t length,uint8_t *data);
uint8_t ram_set_bit(uint16_t address, uint8_t bit);
uint8_t ram_clear_bit(uint16_t address, uint8_t bit);
uint8_t ram_write_byte(uint16_t address, uint8_t data);
uint8_t ram_write_word(uint16_t address, uint16_t data);
uint8_t ram_write_table(uint16_t address, uint16_t length,uint8_t *data);
inline uint8_t ram_in_range(uint16_t reg,uint16_t address,uint16_t length);
uint8_t ram_in_window(uint16_t start_reg,uint16_t reg_length,uint16_t start_address,uint16_t address_length);
#ifdef __cplusplus
}
#endif
#endif
......@@ -52,17 +52,12 @@
#define VOLTAGE_DELTA 0.000805664
#define VOLTAGE_GAIN 1.529411765
uint16_t adc_eeprom_data[] __attribute__ ((section (".eeprom")))={DEFAULT_ADC_PERIOD,ADC_PERIOD};
// private variables
ADC_HandleTypeDef hadc1;
ADC_HandleTypeDef hadc2;
DMA_HandleTypeDef hdma_adc1;
TIM_HandleTypeDef ADC_TIM_Handle;
/* memory module */
TMemModule adc_mem_module;
uint32_t adc_data[4];// temporal buffer to store ADC data before conversion
uint16_t adc_period_ms;
......@@ -94,24 +89,6 @@ uint16_t adc_convert_voltage(uint16_t value)
return conv_value*(1<<12);
}
void adc_write_cmd(void *module,unsigned short int address,unsigned short int length,unsigned char *data)
{
if(ram_in_window(ADC_CNTRL,1,address,length))
{
if(data[ADC_CNTRL-address]&ADC_ENABLE)
adc_start();
else
adc_stop();
}
if(ram_in_range(ADC_PERIOD,address,length))
adc_set_period(data[ADC_PERIOD-address]);
}
void adc_read_cmd(void *module,unsigned short int address,unsigned short int length,unsigned char *data)
{
ram_read_table(address,length,data);
}
// interrupt handlers
void ADC_TIMER_IRQHandler(void)
{
......@@ -170,34 +147,34 @@ void ADC_DMA_IRQHandler(void)
{
__HAL_DMA_CLEAR_FLAG(&hdma_adc1, __HAL_DMA_GET_TC_FLAG_INDEX(&hdma_adc1));
value=adc_convert_voltage(adc_data[0]&0x0000FFFF);
ram_data[ADC_CH1_VOLTAGE]=value%256;
ram_data[ADC_CH1_VOLTAGE+1]=value/256;
ram_data[BIOLOID_ADC_CH1_L]=value%256;
ram_data[BIOLOID_ADC_CH1_H]=value/256;
value=adc_convert_voltage((adc_data[0]&0xFFFF0000)>>16);
ram_data[ADC_CH2_VOLTAGE]=value%256;
ram_data[ADC_CH2_VOLTAGE+1]=value/256;
ram_data[BIOLOID_ADC_CH2_L]=value%256;
ram_data[BIOLOID_ADC_CH2_H]=value/256;
value=adc_convert_voltage(adc_data[1]&0x0000FFFF);
ram_data[ADC_CH3_VOLTAGE]=value%256;
ram_data[ADC_CH3_VOLTAGE+1]=value/256;
ram_data[BIOLOID_ADC_CH3_L]=value%256;
ram_data[BIOLOID_ADC_CH3_H]=value/256;
value=adc_convert_voltage((adc_data[1]&0xFFFF0000)>>16);
ram_data[ADC_CH4_VOLTAGE]=value%256;
ram_data[ADC_CH4_VOLTAGE+1]=value/256;
ram_data[BIOLOID_ADC_CH4_L]=value%256;
ram_data[BIOLOID_ADC_CH4_H]=value/256;
value=adc_convert_temperature(adc_data[2]&0x0000FFFF);
ram_data[ADC_TEMPERATURE]=value%256;
ram_data[ADC_TEMPERATURE+1]=value/256;
ram_data[BIOLOID_ADC_TEMP_L]=value%256;
ram_data[BIOLOID_ADC_TEMP_H]=value/256;
value=adc_convert_voltage((adc_data[2]&0xFFFF0000)>>16);
ram_data[ADC_CH6_VOLTAGE]=value%256;
ram_data[ADC_CH6_VOLTAGE+1]=value/256;
ram_data[BIOLOID_ADC_CH6_L]=value%256;
ram_data[BIOLOID_ADC_CH6_H]=value/256;
value=adc_convert_vrefint(adc_data[3]&0x0000FFFF);
ram_data[ADC_VREF_VOLTAGE]=value%256;
ram_data[ADC_VREF_VOLTAGE+1]=value/256;
ram_data[BIOLOID_ADC_VREF_L]=value%256;
ram_data[BIOLOID_ADC_VREF_H]=value/256;
value=adc_convert_voltage((adc_data[3]&0xFFFF0000)>>16);
ram_data[ADC_CH8_VOLTAGE]=value%256;
ram_data[ADC_CH8_VOLTAGE+1]=value/256;
ram_data[BIOLOID_ADC_CH8_L]=value%256;
ram_data[BIOLOID_ADC_CH8_H]=value/256;
}
}
// public functions
uint8_t adc_init(TMemory *memory)
void adc_init(void)
{
GPIO_InitTypeDef GPIO_InitStruct;
ADC_MultiModeTypeDef multimode;
......@@ -208,7 +185,8 @@ uint8_t adc_init(TMemory *memory)
uint32_t capture;
/* initialize the internal variables */
adc_set_period(DEFAULT_ADC_PERIOD);
adc_period_ms=840;// equivalent to 10 ms
ram_data[BIOLOID_ADC_PERIOD]=10;
/* enable clocks */
ADC1_CH1_ENABLE_PORT_CLK;
......@@ -371,36 +349,23 @@ uint8_t adc_init(TMemory *memory)
HAL_ADC_Start(&hadc2);
HAL_ADCEx_MultiModeStart_DMA(&hadc1,adc_data,4);
adc_start();
/* initialize memory module */
mem_module_init(&adc_mem_module);
adc_mem_module.write_cmd=adc_write_cmd;
adc_mem_module.read_cmd=adc_read_cmd;
if(!mem_module_add_ram_segment(&adc_mem_module,RAM_ADC_DMA_BASE_ADDRESS,RAM_ADC_DMA_LENGTH))
return 0x00;