[BSP]Add more drivers and fix some problem

This commit is contained in:
lin
2017-12-04 18:52:02 +08:00
parent c17ddf1430
commit 2706bccbdd
32 changed files with 3760 additions and 310 deletions
+196
View File
@@ -0,0 +1,196 @@
/*
* File : adc.c
* This file is part of RT-Thread RTOS
* COPYRIGHT (C) 2006 - 2017, RT-Thread Development Team
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program 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. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Change Logs:
* Date Author Notes
* 2017-12-04 Haley the first version
*/
#include <rtdevice.h>
#include "am_mcu_apollo.h"
#include "board.h"
#ifdef RT_USING_ADC
/* sem define */
rt_sem_t adcsem = RT_NULL;
#define BATTERY_GPIO 29 /* Battery */
#define BATTERY_ADC_PIN AM_HAL_PIN_29_ADCSE1
#define BATTERY_ADC_CHANNEL AM_HAL_ADC_SLOT_CHSEL_SE1 /* BATTERY ADC采集通道 */
#define BATTERY_ADC_CHANNELNUM 1 /* BATTERY ADC采集通道号 */
#define ADC_CTIMER_NUM 3 /* ADC使用定时器 */
#define ADC_CHANNEL_NUM 1 /* ADC采集通道个数 */
#define ADC_SAMPLE_NUM 8 /* ADC采样个数, NE_OF_OUTPUT */
rt_uint8_t bat_adc_cnt = (ADC_CHANNEL_NUM + 1)*ADC_SAMPLE_NUM;
rt_int16_t am_adc_buffer_pool[64];
rt_uint8_t am_adc_data_get(rt_int16_t *buff, rt_uint16_t size)
{
/* wait adc interrupt release sem forever */
rt_sem_take(adcsem, RT_WAITING_FOREVER);
/* copy the data */
rt_memcpy(buff, am_adc_buffer_pool, size*sizeof(rt_int16_t));
return 0;
}
void am_adc_start(void)
{
/* adcsem create */
adcsem = rt_sem_create("adcsem", 0, RT_IPC_FLAG_FIFO);
/* Start the ctimer */
am_hal_ctimer_start(ADC_CTIMER_NUM, AM_HAL_CTIMER_TIMERA);
/* Trigger the ADC once */
am_hal_adc_trigger();
}
void am_adc_stop(void)
{
/* Stop the ctimer */
am_hal_ctimer_stop(ADC_CTIMER_NUM, AM_HAL_CTIMER_TIMERA);
/* adcsem delete */
rt_sem_delete(adcsem);
}
/**
* @brief Interrupt handler for the ADC
*
* This function is Interrupt handler for the ADC
*
* @return None.
*/
void am_adc_isr(void)
{
uint32_t ui32Status, ui32FifoData;
/* Read the interrupt status */
ui32Status = am_hal_adc_int_status_get(true);
/* Clear the ADC interrupt */
am_hal_adc_int_clear(ui32Status);
/* If we got a FIFO 75% full (which should be our only ADC interrupt), go ahead and read the data */
if (ui32Status & AM_HAL_ADC_INT_FIFOOVR1)
{
do
{
/* Read the value from the FIFO into the circular buffer */
ui32FifoData = am_hal_adc_fifo_pop();
if(AM_HAL_ADC_FIFO_SLOT(ui32FifoData) == BATTERY_ADC_CHANNELNUM)
am_adc_buffer_pool[bat_adc_cnt++] = AM_HAL_ADC_FIFO_SAMPLE(ui32FifoData);
if(bat_adc_cnt > (ADC_CHANNEL_NUM + 1)*ADC_SAMPLE_NUM - 1)
{
/* shift data */
rt_memmove(am_adc_buffer_pool, am_adc_buffer_pool + ADC_CHANNEL_NUM*ADC_SAMPLE_NUM, ADC_CHANNEL_NUM*ADC_SAMPLE_NUM*sizeof(rt_int16_t));
bat_adc_cnt = (ADC_CHANNEL_NUM + 1)*ADC_SAMPLE_NUM;
/* release adcsem */
rt_sem_release(adcsem);
}
} while (AM_HAL_ADC_FIFO_COUNT(ui32FifoData) > 0);
}
}
static void timerA3_for_adc_init(void)
{
/* Start a timer to trigger the ADC periodically (1 second) */
am_hal_ctimer_config_single(ADC_CTIMER_NUM, AM_HAL_CTIMER_TIMERA,
AM_HAL_CTIMER_XT_2_048KHZ |
AM_HAL_CTIMER_FN_REPEAT |
AM_HAL_CTIMER_INT_ENABLE |
AM_HAL_CTIMER_PIN_ENABLE);
am_hal_ctimer_int_enable(AM_HAL_CTIMER_INT_TIMERA3);
/* Set 512 sample rate */
am_hal_ctimer_period_set(ADC_CTIMER_NUM, AM_HAL_CTIMER_TIMERA, 3, 1);
/* Enable the timer A3 to trigger the ADC directly */
am_hal_ctimer_adc_trigger_enable();
/* Start the timer */
//am_hal_ctimer_start(ADC_CTIMER_NUM, AM_HAL_CTIMER_TIMERA);
}
/**
* @brief Initialize the ADC
*
* This function initialize the ADC
*
* @return None.
*/
int rt_hw_adc_init(void)
{
am_hal_adc_config_t sADCConfig;
/* timer for adc init*/
timerA3_for_adc_init();
/* Set a pin to act as our ADC input */
am_hal_gpio_pin_config(BATTERY_GPIO, BATTERY_ADC_PIN);
/* Enable interrupts */
am_hal_interrupt_enable(AM_HAL_INTERRUPT_ADC);
/* Enable the ADC power domain */
am_hal_pwrctrl_periph_enable(AM_HAL_PWRCTRL_ADC);
/* Set up the ADC configuration parameters. These settings are reasonable
for accurate measurements at a low sample rate */
sADCConfig.ui32Clock = AM_HAL_ADC_CLOCK_HFRC;
sADCConfig.ui32TriggerConfig = AM_HAL_ADC_TRIGGER_SOFT;
sADCConfig.ui32Reference = AM_HAL_ADC_REF_INT_2P0;
sADCConfig.ui32ClockMode = AM_HAL_ADC_CK_LOW_POWER;
sADCConfig.ui32PowerMode = AM_HAL_ADC_LPMODE_0;
sADCConfig.ui32Repeat = AM_HAL_ADC_REPEAT;
am_hal_adc_config(&sADCConfig);
/* For this example, the samples will be coming in slowly. This means we
can afford to wake up for every conversion */
am_hal_adc_int_enable(AM_HAL_ADC_INT_FIFOOVR1);
/* Set up an ADC slot */
am_hal_adc_slot_config(BATTERY_ADC_CHANNELNUM, AM_HAL_ADC_SLOT_AVG_1 |
AM_HAL_ADC_SLOT_14BIT |
BATTERY_ADC_CHANNEL |
AM_HAL_ADC_SLOT_ENABLE);
/* Enable the ADC */
am_hal_adc_enable();
rt_kprintf("adc_init!\n");
return 0;
}
#ifdef RT_USING_COMPONENTS_INIT
INIT_BOARD_EXPORT(rt_hw_adc_init);
#endif
#endif
/*@}*/
+39
View File
@@ -0,0 +1,39 @@
/*
* File : adc.h
* This file is part of RT-Thread RTOS
* COPYRIGHT (C) 2006 - 2017, RT-Thread Development Team
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program 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. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Change Logs:
* Date Author Notes
* 2017-09-18 Haley the first version
*/
#ifndef __ADC_H_
#define __ADC_H_
#include <rtthread.h>
/**
* @brief External function definitions
*
*/
int rt_hw_adc_init(void);
rt_uint8_t am_adc_data_get(rt_int16_t *buff, rt_uint16_t size);
void am_adc_start(void);
void am_adc_stop(void);
#endif // __ADC_H_
-1
View File
@@ -30,7 +30,6 @@
#include "hal/am_hal_clkgen.h"
#include "hal/am_hal_cachectrl.h"
#include "uart.h"
#include "led.h"
#ifdef __CC_ARM
extern int Image$$RW_IRAM1$$ZI$$Limit;
+20
View File
@@ -35,12 +35,32 @@
#define RT_USING_UART0
//#define RT_USING_UART1
/* ADC driver select. */
#define RT_USING_ADC
/* I2C driver select. */
#define RT_USING_I2C0
//#define RT_USING_I2C2
//#define RT_USING_I2C4
/* SMBUS driver select. */
//#define RT_USING_SMBUS
/* SPI driver select. */
#define RT_USING_SPI1
/* LED driver select. */
#define RT_USING_LED0
//#define RT_USING_LED1
//#define RT_USING_LED2
//#define RT_USING_LED3
/* PWM driver select. */
//#define RT_USING_PWM
/* PDM driver select. */
//#define RT_USING_PDM
void rt_hw_board_init(void);
#endif /* __BOARD_H__ */
+151
View File
@@ -0,0 +1,151 @@
/*
* File : flash.c
* This file is part of RT-Thread RTOS
* COPYRIGHT (C) 2006 - 2017, RT-Thread Development Team
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program 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. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Change Logs:
* Date Author Notes
* 2017-12-04 Haley the first version
*/
#include <rtthread.h>
#include <rtdevice.h>
#include "am_mcu_apollo.h"
#include "flash.h"
/* RT-Thread device interface */
static rt_err_t rt_flash_init(rt_device_t dev)
{
return RT_EOK;
}
static rt_err_t rt_flash_open(rt_device_t dev, rt_uint16_t oflag)
{
return RT_EOK;
}
static rt_err_t rt_flash_close(rt_device_t dev)
{
return RT_EOK;
}
static rt_err_t rt_flash_control(rt_device_t dev, int cmd, void *args)
{
uint32_t ui32Critical, i;
uint32_t ui32CurrentPage, ui32CurrentBlock;
if (cmd == RT_DEVICE_CTRL_BLK_GETGEOME)
{
struct rt_device_blk_geometry *geometry;
geometry = (struct rt_device_blk_geometry *)args;
if (geometry == RT_NULL)
return -RT_ERROR;
geometry->bytes_per_sector = 8192;
geometry->sector_count = 8192;
geometry->block_size = 8192;
}
else if(cmd == RT_DEVICE_CTRL_BLK_ERASE)
{
struct rom_control_erase *erase;
erase = (struct rom_control_erase *)args;
// Start a critical section.
ui32Critical = am_hal_interrupt_master_disable();
if (erase->type == 0x01)
{
for(i = 0; i < erase->pagenums; i++)
{
// Figure out what page and block we're working on.
ui32CurrentPage = AM_HAL_FLASH_ADDR2PAGE(erase->addrstart);
ui32CurrentBlock = AM_HAL_FLASH_ADDR2INST(erase->addrstart);
am_hal_flash_page_erase(AM_HAL_FLASH_PROGRAM_KEY, ui32CurrentBlock, ui32CurrentPage); //µ¥ÉÈÇø²Á³ýÃüÁî
erase->addrstart += 8192;
}
}
// Exit the critical section.
am_hal_interrupt_master_set(ui32Critical);
}
return RT_EOK;
}
static rt_size_t rt_flash_read(rt_device_t dev,
rt_off_t pos,
void* buffer,
rt_size_t size)
{
rt_memcpy((uint8_t *)buffer, (uint8_t *)pos, size);
return size;
}
static rt_size_t rt_flash_write(rt_device_t dev,
rt_off_t pos,
const void* buffer,
rt_size_t size)
{
uint32_t ui32Critical;
uint32_t ui32WordsInBuffer;
ui32WordsInBuffer = (size + 3)/ 4;
// Start a critical section.
ui32Critical = am_hal_interrupt_master_disable();
// Program the flash page with the data we just received.
am_hal_flash_program_main(AM_HAL_FLASH_PROGRAM_KEY, (uint32_t *)buffer, (uint32_t *)pos, ui32WordsInBuffer);
// Exit the critical section.
am_hal_interrupt_master_set(ui32Critical);
return size;
}
int rt_hw_rom_init(void)
{
static struct rt_device device;
/* register device */
device.type = RT_Device_Class_Block;
device.init = rt_flash_init;
device.open = rt_flash_open;
device.close = rt_flash_close;
device.read = rt_flash_read;
device.write = rt_flash_write;
device.control = rt_flash_control;
/* no private */
device.user_data = RT_NULL;
/* register the device */
rt_device_register(&device, "rom", RT_DEVICE_FLAG_RDWR);
rt_kprintf("register device rom!\r\n");
return 0;
}
#ifdef RT_USING_COMPONENTS_INIT
INIT_DEVICE_EXPORT(rt_hw_rom_init);
#endif
/*@}*/
+44
View File
@@ -0,0 +1,44 @@
/*
* File : flash.h
* This file is part of RT-Thread RTOS
* COPYRIGHT (C) 2006 - 2017, RT-Thread Development Team
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program 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. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Change Logs:
* Date Author Notes
* 2017-12-04 Haley the first version
*/
#ifndef __FLASH_H_
#define __FLASH_H_
#include <rtthread.h>
/* Erase feature struct define */
struct rom_control_erase
{
rt_uint8_t type;
rt_uint32_t addrstart;
rt_uint32_t pagenums;
};
/**
* @brief External function definitions
*
*/
int rt_hw_rom_init(void);
#endif // __FLASH_H_
+5 -2
View File
@@ -87,13 +87,16 @@ const static struct rt_pin_ops _am_pin_ops =
am_pin_read,
};
int hw_pin_init(void)
int rt_hw_pin_init(void)
{
rt_device_pin_register("pin", &_am_pin_ops, RT_NULL);
rt_kprintf("pin_init!\n");
return 0;
}
INIT_BOARD_EXPORT(hw_pin_init);
INIT_BOARD_EXPORT(rt_hw_pin_init);
#endif
/*@}*/
+5 -1
View File
@@ -25,6 +25,10 @@
#ifndef __GPIO_H
#define __GPIO_H
int hw_pin_init(void);
/**
* @brief External function definitions
*
*/
int rt_hw_pin_init(void);
#endif // __GPIO_H
File diff suppressed because it is too large Load Diff
+36
View File
@@ -0,0 +1,36 @@
/*
* File : i2c.h
* This file is part of RT-Thread RTOS
* COPYRIGHT (C) 2006 - 2017, RT-Thread Development Team
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program 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. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Change Logs:
* Date Author Notes
* 2017-12-04 Haley the first version
*/
#ifndef __I2C_H_
#define __I2C_H_
#include <rtthread.h>
/**
* @brief External function definitions
*
*/
int rt_hw_i2c_init(void);
#endif // __I2C_H_
+5 -2
View File
@@ -24,7 +24,6 @@
#include <rtthread.h>
#include <rtdevice.h>
#include "am_mcu_apollo.h"
#include "board.h"
#define AM_GPIO_LED0 46
@@ -128,14 +127,18 @@ int rt_hw_led_init(void)
rt_hw_led_off(3);
#endif /* RT_USING_LED1 */
#endif
rt_kprintf("led_init!\n");
return 0;
}
#ifdef RT_USING_COMPONENTS_INIT
INIT_BOARD_EXPORT(rt_hw_led_init);
INIT_DEVICE_EXPORT(rt_hw_led_init);
#endif
#ifdef RT_USING_FINSH
#include <finsh.h>
void led(rt_uint32_t led, rt_uint32_t state)
{
/* set led status */
+4 -4
View File
@@ -21,9 +21,9 @@
* Date Author Notes
* 2017-09-14 Haley the first version
*/
#ifndef __HW_LED_H
#define __HW_LED_H
#ifndef __LED_H
#define __LED_H
#include <rtthread.h>
@@ -35,4 +35,4 @@ void rt_hw_led_init(void);
void rt_hw_led_on(rt_uint8_t LEDNum);
void rt_hw_led_off(rt_uint8_t LEDNum);
#endif // __HW_LED_H
#endif // __LED_H
File diff suppressed because it is too large Load Diff
+39
View File
@@ -0,0 +1,39 @@
/*
* File : pdm.h
* This file is part of RT-Thread RTOS
* COPYRIGHT (C) 2006 - 2017, RT-Thread Development Team
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program 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. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Change Logs:
* Date Author Notes
* 2017-12-04 Haley the first version
*/
#ifndef __PDM_H_
#define __PDM_H_
#include <rtthread.h>
/**
* @brief External function definitions
*
*/
int rt_hw_pdm_init(void);
rt_uint8_t am_pdm_data_get(rt_uint8_t *buff, rt_uint16_t size);
void am_pdm_start(void);
void am_pdm_stop(void);
#endif // __PDM_H_
+120
View File
@@ -0,0 +1,120 @@
/*
* File :_pwm.c
* This file is part of RT-Thread RTOS
* COPYRIGHT (C) 2006 - 2017, RT-Thread Development Team
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program 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. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Change Logs:
* Date Author Notes
* 2017-12-04 Haley the first version
*/
#include <rtthread.h>
#include <rtdevice.h>
#include "am_mcu_apollo.h"
#include "board.h"
#ifdef RT_USING_PWM
// LED3 is pin 19
#define AM_BSP_GPIO_PWM_LED 19
#define AM_BSP_GPIO_CFG_PWM_LED AM_HAL_PIN_19_TCTB1
#define AM_BSP_PWM_LED_TIMER 1
#define AM_BSP_PWM_LED_TIMER_SEG AM_HAL_CTIMER_TIMERB
#define AM_BSP_PWM_LED_TIMER_INT AM_HAL_CTIMER_INT_TIMERB1
/**
* @brief LED brightness profile
*
* This function define LED brightness profile
*
* @return None.
*/
volatile uint32_t g_ui32Index = 0;
const uint32_t g_pui32Brightness[64] =
{
1, 1, 1, 2, 3, 4, 6, 8,
10, 12, 14, 17, 20, 23, 25, 28,
31, 35, 38, 40, 43, 46, 49, 51,
53, 55, 57, 59, 60, 61, 62, 62,
63, 62, 62, 61, 60, 59, 57, 55,
53, 51, 49, 46, 43, 40, 38, 35,
32, 28, 25, 23, 20, 17, 14, 12,
10, 8, 6, 4, 3, 2, 1, 1
};
/**
* @brief Interrupt handler for the Timer
*
* This function is Interrupt handler for the Timer
*
* @return None.
*/
void am_ctimer_isr(void)
{
/* Clear the interrupt that got us here */
am_hal_ctimer_int_clear(AM_BSP_PWM_LED_TIMER_INT);
/* Now set new PWM half-period for the LED */
am_hal_ctimer_period_set(AM_BSP_PWM_LED_TIMER, AM_BSP_PWM_LED_TIMER_SEG,
64, g_pui32Brightness[g_ui32Index]);
/* Set up the LED duty cycle for the next pulse */
g_ui32Index = (g_ui32Index + 1) % 64;
}
/**
* @brief Initialize the PWM
*
* This function initialize the PWM
*
* @return 0.
*/
int rt_hw_pwm_init(void)
{
/* init pwm gpio */
am_hal_gpio_pin_config(AM_BSP_GPIO_PWM_LED, AM_BSP_GPIO_CFG_PWM_LED);
/* Configure a timer to drive the LED */
am_hal_ctimer_config_single(AM_BSP_PWM_LED_TIMER, AM_BSP_PWM_LED_TIMER_SEG,
(AM_HAL_CTIMER_FN_PWM_REPEAT |
AM_HAL_CTIMER_XT_2_048KHZ |
AM_HAL_CTIMER_INT_ENABLE |
AM_HAL_CTIMER_PIN_ENABLE));
/* Set up initial timer period */
am_hal_ctimer_period_set(AM_BSP_PWM_LED_TIMER, AM_BSP_PWM_LED_TIMER_SEG,
64, 32);
/* Enable interrupts for the Timer we are using on this board */
am_hal_ctimer_int_enable(AM_BSP_PWM_LED_TIMER_INT);
am_hal_interrupt_enable(AM_HAL_INTERRUPT_CTIMER);
/* Start the timer */
am_hal_ctimer_start(AM_BSP_PWM_LED_TIMER, AM_BSP_PWM_LED_TIMER_SEG);
rt_kprintf("pwm_init!\n");
return 0;
}
#ifdef RT_USING_COMPONENTS_INIT
INIT_BOARD_EXPORT(rt_hw_pwm_init);
#endif
#endif
/*@}*/
+36
View File
@@ -0,0 +1,36 @@
/*
* File : pwm.h
* This file is part of RT-Thread RTOS
* COPYRIGHT (C) 2006 - 2017, RT-Thread Development Team
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program 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. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Change Logs:
* Date Author Notes
* 2017-12-04 Haley the first version
*/
#ifndef __PWM_H_
#define __PWM_H_
#include <rtthread.h>
/**
* @brief External function definitions
*
*/
int rt_hw_pwm_init(void);
#endif // __PWM_H_
+151
View File
@@ -0,0 +1,151 @@
/*
* File :_rtc.c
* This file is part of RT-Thread RTOS
* COPYRIGHT (C) 2006 - 2017, RT-Thread Development Team
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program 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. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Change Logs:
* Date Author Notes
* 2017-11-06 Haley the first version
*/
#include <rtthread.h>
#include <rtdevice.h>
#include "am_mcu_apollo.h"
#define XT 1
#define LFRC 2
#define RTC_CLK_SRC XT
//connect am drv to rt drv.
static rt_err_t rt_rtc_open(rt_device_t dev, rt_uint16_t oflag)
{
if (dev->rx_indicate != RT_NULL)
{
/* Open Interrupt */
}
return RT_EOK;
}
static rt_size_t rt_rtc_read(rt_device_t dev, rt_off_t pos, void* buffer, rt_size_t size)
{
return 0;
}
static rt_err_t rt_rtc_control(rt_device_t dev, int cmd, void *args)
{
time_t *time;
struct tm time_temp;
struct tm* time_new;
am_hal_rtc_time_t hal_time;
RT_ASSERT(dev != RT_NULL);
rt_memset(&time_temp, 0, sizeof(struct tm));
switch (cmd)
{
case RT_DEVICE_CTRL_RTC_GET_TIME:
time = (time_t *)args;
/* Get the current Time */
am_hal_rtc_time_get(&hal_time);
/* Years since 1900 : 0-99 range */
time_temp.tm_year = hal_time.ui32Year + 2000 - 1900;
/* Months *since* january 0-11 : RTC_Month_Date_Definitions 1 - 12 */
time_temp.tm_mon = hal_time.ui32Month - 1;
/* Day of the month 1-31 : 1-31 range */
time_temp.tm_mday = hal_time.ui32DayOfMonth;
/* Hours since midnight 0-23 : 0-23 range */
time_temp.tm_hour = hal_time.ui32Hour;
/* Minutes 0-59 : the 0-59 range */
time_temp.tm_min = hal_time.ui32Minute;
/* Seconds 0-59 : the 0-59 range */
time_temp.tm_sec = hal_time.ui32Second;
*time = mktime(&time_temp);
break;
case RT_DEVICE_CTRL_RTC_SET_TIME:
time = (time_t *)args;
time_new = localtime(time);
hal_time.ui32Hour = time_new->tm_hour;
hal_time.ui32Minute = time_new->tm_min;
hal_time.ui32Second = time_new->tm_sec;
hal_time.ui32Hundredths = 00;
hal_time.ui32Weekday = time_new->tm_wday;
hal_time.ui32DayOfMonth = time_new->tm_mday;
hal_time.ui32Month = time_new->tm_mon + 1;
hal_time.ui32Year = time_new->tm_year + 1900 - 2000;
hal_time.ui32Century = 0;
am_hal_rtc_time_set(&hal_time);
break;
}
return RT_EOK;
}
int rt_hw_rtc_init(void)
{
static struct rt_device rtc;
#if RTC_CLK_SRC == LFRC
/* Enable the LFRC for the RTC */
am_hal_clkgen_osc_start(AM_HAL_CLKGEN_OSC_LFRC);
/* Select LFRC for RTC clock source */
am_hal_rtc_osc_select(AM_HAL_RTC_OSC_LFRC);
#endif
#if RTC_CLK_SRC == XT
/* Enable the XT for the RTC */
//am_hal_clkgen_osc_start(AM_HAL_CLKGEN_OSC_LFRC);
am_hal_clkgen_osc_start(AM_HAL_CLKGEN_OSC_XT);
/* Select XT for RTC clock source */
am_hal_rtc_osc_select(AM_HAL_RTC_OSC_XT);
#endif
/* Enable the RTC */
am_hal_rtc_osc_enable();
/* register rtc device */
rtc.type = RT_Device_Class_RTC;
rtc.init = RT_NULL;
rtc.open = rt_rtc_open;
rtc.close = RT_NULL;
rtc.read = rt_rtc_read;
rtc.write = RT_NULL;
rtc.control = rt_rtc_control;
/* no private */
rtc.user_data = RT_NULL;
rt_device_register(&rtc, "rtc", RT_DEVICE_FLAG_RDWR);
return 0;
}
#ifdef RT_USING_COMPONENTS_INIT
INIT_BOARD_EXPORT(rt_hw_rtc_init);
#endif
/*@}*/
+36
View File
@@ -0,0 +1,36 @@
/*
* File : rtc.h
* This file is part of RT-Thread RTOS
* COPYRIGHT (C) 2006 - 2017, RT-Thread Development Team
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program 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. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Change Logs:
* Date Author Notes
* 2017-09-14 Haley the first version
*/
#ifndef __RTC_H
#define __RTC_H
#include <rtthread.h>
/**
* @brief External function definitions
*
*/
int rt_hw_rtc_init(void);
#endif // __RTC_H
File diff suppressed because it is too large Load Diff
+40
View File
@@ -0,0 +1,40 @@
/*
* File : smbus.h
* This file is part of RT-Thread RTOS
* COPYRIGHT (C) 2006 - 2017, RT-Thread Development Team
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program 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. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Change Logs:
* Date Author Notes
* 2017-12-04 Haley the first version
*/
#ifndef __SMBUS_H_
#define __SMBUS_H_
#include <rtthread.h>
/**
* @brief External function definitions
*
*/
int rt_hw_smbus_init(void);
rt_uint8_t am_smbus_tx_then_tx(rt_uint8_t SlaveAddress, rt_uint8_t command, rt_uint8_t* pBuffer, rt_uint16_t bytesNumber);
rt_uint8_t am_smbus_tx_then_rx(rt_uint8_t SlaveAddress, rt_uint8_t command, rt_uint8_t* pBuffer, rt_uint16_t bytesNumber);
void am_smbus_scl_high(void);
void am_smbus_scl_low(void);
#endif // __SMBUS_H_
File diff suppressed because it is too large Load Diff
+42
View File
@@ -0,0 +1,42 @@
/*
* File : spi.h
* This file is part of RT-Thread RTOS
* COPYRIGHT (C) 2006 - 2017, RT-Thread Development Team
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program 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. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Change Logs:
* Date Author Notes
* 2017-12-04 Haley the first version
*/
#ifndef __SPI_H_
#define __SPI_H_
#include <rtthread.h>
/* ƬѡÐźŽṹÉùÃ÷ */
struct am_spi_cs
{
rt_uint32_t chip_select;
};
/**
* @brief External function definitions
*
*/
int yr_hw_spi_init(void);
#endif // __SPI_H_
File diff suppressed because it is too large Load Diff
+8 -2
View File
@@ -21,10 +21,16 @@
* Date Author Notes
* 2017-09-14 Haley the first version
*/
#ifndef __UART_H_
#define __UART_H_
void rt_hw_uart_init(void);
#include <rtthread.h>
/**
* @brief External function definitions
*
*/
int rt_hw_uart_init(void);
#endif // __UART_H_
+6
View File
@@ -11,15 +11,21 @@ hal/am_hal_debug.c
hal/am_hal_cachectrl.c
hal/am_hal_pwrctrl.c
hal/am_hal_sysctrl.c
hal/am_hal_reset.c
hal/am_hal_stimer.c
hal/am_hal_ctimer.c
hal/am_hal_rtc.c
hal/am_hal_interrupt.c
hal/am_hal_queue.c
hal/am_hal_iom.c
hal/am_hal_ios.c
hal/am_hal_vcomp.c
hal/am_hal_flash.c
hal/am_hal_gpio.c
hal/am_hal_uart.c
hal/am_hal_adc.c
hal/am_hal_pdm.c
hal/am_hal_i2c_bit_bang.c
""")
path = [cwd]
@@ -49,7 +49,7 @@
#include <stdbool.h>
#include "am_mcu_apollo.h"
#include "am_util.h"
//#include "am_util.h"
#include "am_hal_i2c_bit_bang.h"
// Max number of clock cycles to wait for clock stretch
@@ -133,7 +133,7 @@ static am_hal_i2c_bit_bang_priv_t am_hal_i2c_bit_bang_priv;
// Wait for any stretched clock to go high
// If it times out - return failure
//
static inline bool
static bool
i2c_pull_and_wait_scl_hi(void)
{
// Maximum time to wait for clock stretching
@@ -284,7 +284,7 @@ am_hal_i2c_bit_bang_init(uint32_t sck_gpio_number,
//! returns the byte received
//
//*****************************************************************************
static inline am_hal_i2c_bit_bang_enum_t
static am_hal_i2c_bit_bang_enum_t
i2c_receive_byte(uint8_t *pRxByte, bool bNack)
{
int i;
@@ -389,7 +389,7 @@ i2c_receive_byte(uint8_t *pRxByte, bool bNack)
//! }
//
//*****************************************************************************
static inline am_hal_i2c_bit_bang_enum_t
static am_hal_i2c_bit_bang_enum_t
i2c_send_byte(uint8_t one_byte)
{
int i;
+17 -1
View File
@@ -49,7 +49,7 @@
#include <stdint.h>
#include <stdbool.h>
#include "am_mcu_apollo.h"
#include "am_util_delay.h"
//#include "am_util_delay.h"
#ifdef __IAR_SYSTEMS_ICC__
#define AM_INSTR_CLZ(n) __CLZ(n)
@@ -62,6 +62,22 @@
#define AM_ASSERT_INVALID_THRESHOLD (1)
#endif
uint32_t am_util_wait_status_change(uint32_t ui32Iterations, uint32_t ui32Address, uint32_t ui32Mask, uint32_t ui32Value)
{
int i;
for (i = 0; i < ui32Iterations; i++)
{
// Check the status
if (((*(uint32_t *)ui32Address) & ui32Mask) == ui32Value)
{
return 1;
}
// Call the BOOTROM cycle delay function to get about 1 usec @ 48MHz
am_hal_flash_delay(16);
}
return 0;
}
//*****************************************************************************
//
// Forcing optimizations
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
+169 -75
View File
File diff suppressed because it is too large Load Diff
+2 -2
View File
@@ -43,7 +43,7 @@ if PLATFORM == 'gcc':
DEVICE = ' -mcpu=cortex-m4 -mthumb -ffunction-sections -fdata-sections'
CFLAGS = DEVICE
AFLAGS = ' -c' + DEVICE + ' -x assembler-with-cpp'
LFLAGS = DEVICE + ' -Wl,--gc-sections,-Map=rtthread-nrf52832.map,-cref,-u,Reset_Handler -T nrf52_xxaa.ld'
LFLAGS = DEVICE + ' -Wl,--gc-sections,-Map=rtthread-apollo2.map,-cref,-u,Reset_Handler -T'
CPATH = ''
LPATH = ''
@@ -67,7 +67,7 @@ elif PLATFORM == 'armcc':
DEVICE = ' --device DARMSTM'
CFLAGS = DEVICE + ' --apcs=interwork'
AFLAGS = DEVICE
LFLAGS = DEVICE + ' --info sizes --info totals --info unused --info veneers --list rtthread-nrf52832.map --scatter rtthread-nrf52832.sct'
LFLAGS = DEVICE + ' --info sizes --info totals --info unused --info veneers --list rtthread-apollo2.map --scatter rtthread-apollo2.sct'
CFLAGS += ' --c99'
CFLAGS += ' -I' + EXEC_PATH + '/ARM/RV31/INC'
+1 -1
View File
@@ -117,7 +117,7 @@
<SetRegEntry>
<Number>0</Number>
<Key>JL2CM3</Key>
<Name>-U4294967295 -O78 -S0 -ZTIFSpeedSel20000 -A0 -C0 -JU1 -JI127.0.0.1 -JP0 -RST0 -N00("ARM CoreSight SW-DP") -D00(2BA01477) -L00(0) -TO18 -TC10000000 -TP21 -TDS8007 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -TB1 -TFE0 -FO15 -FD10000000 -FC4000 -FN1 -FF0Apollo2.FLM -FS00 -FL010000 -FP0($$Device:AMAPH1KK-KBR$Flash\Apollo2.FLM)</Name>
<Name>-U4294967295 -O78 -S0 -ZTIFSpeedSel20000 -A0 -C0 -JU1 -JI127.0.0.1 -JP0 -RST0 -N00("ARM CoreSight SW-DP") -D00(2BA01477) -L00(0) -TO18 -TC10000000 -TP21 -TDS8007 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -TB1 -TFE0 -FO15 -FD10000000 -FC4000 -FN1 -FF0Apollo2 -FS00 -FL0100000 -FP0($$Device:AMAPH1KK-KBR$Flash\Apollo2.FLM)</Name>
</SetRegEntry>
<SetRegEntry>
<Number>0</Number>