[457] | 1 | /*
|
---|
| 2 | * TOPPERS/ASP Kernel
|
---|
| 3 | * Toyohashi Open Platform for Embedded Real-Time Systems/
|
---|
| 4 | * Advanced Standard Profile Kernel
|
---|
| 5 | *
|
---|
| 6 | * Copyright (C) 2008-2011 by Embedded and Real-Time Systems Laboratory
|
---|
| 7 | * Graduate School of Information Science, Nagoya Univ., JAPAN
|
---|
| 8 | * Copyright (C) 2015-2018 by TOPPERS PROJECT Educational Working Group.
|
---|
| 9 | *
|
---|
| 10 | * 上記著作権者は,以下の(1)~(4)の条件を満たす場合に限り,本ソフトウェ
|
---|
| 11 | * ア(本ソフトウェアを改変したものを含む.以下同じ)を使用・複製・改
|
---|
| 12 | * 変・再配布(以下,利用と呼ぶ)することを無償で許諾する.
|
---|
| 13 | * (1) 本ソフトウェアをソースコードの形で利用する場合には,上記の著作
|
---|
| 14 | * 権表示,この利用条件および下記の無保証規定が,そのままの形でソー
|
---|
| 15 | * スコード中に含まれていること.
|
---|
| 16 | * (2) 本ソフトウェアを,ライブラリ形式など,他のソフトウェア開発に使
|
---|
| 17 | * 用できる形で再配布する場合には,再配布に伴うドキュメント(利用
|
---|
| 18 | * 者マニュアルなど)に,上記の著作権表示,この利用条件および下記
|
---|
| 19 | * の無保証規定を掲載すること.
|
---|
| 20 | * (3) 本ソフトウェアを,機器に組み込むなど,他のソフトウェア開発に使
|
---|
| 21 | * 用できない形で再配布する場合には,次のいずれかの条件を満たすこ
|
---|
| 22 | * と.
|
---|
| 23 | * (a) 再配布に伴うドキュメント(利用者マニュアルなど)に,上記の著
|
---|
| 24 | * 作権表示,この利用条件および下記の無保証規定を掲載すること.
|
---|
| 25 | * (b) 再配布の形態を,別に定める方法によって,TOPPERSプロジェクトに
|
---|
| 26 | * 報告すること.
|
---|
| 27 | * (4) 本ソフトウェアの利用により直接的または間接的に生じるいかなる損
|
---|
| 28 | * 害からも,上記著作権者およびTOPPERSプロジェクトを免責すること.
|
---|
| 29 | * また,本ソフトウェアのユーザまたはエンドユーザからのいかなる理
|
---|
| 30 | * 由に基づく請求からも,上記著作権者およびTOPPERSプロジェクトを
|
---|
| 31 | * 免責すること.
|
---|
| 32 | *
|
---|
| 33 | * 本ソフトウェアは,無保証で提供されているものである.上記著作権者お
|
---|
| 34 | * よびTOPPERSプロジェクトは,本ソフトウェアに関して,特定の使用目的
|
---|
| 35 | * に対する適合性も含めて,いかなる保証も行わない.また,本ソフトウェ
|
---|
| 36 | * アの利用により直接的または間接的に生じたいかなる損害に関しても,そ
|
---|
| 37 | * の責任を負わない.
|
---|
| 38 | *
|
---|
| 39 | * @(#) $Id$
|
---|
| 40 | */
|
---|
| 41 | /*
|
---|
| 42 | * STM32F7xx用デバイスドライバ
|
---|
| 43 | */
|
---|
| 44 | #include "kernel_impl.h"
|
---|
| 45 | #include <t_syslog.h>
|
---|
| 46 | #include <t_stdlib.h>
|
---|
| 47 | #include <sil.h>
|
---|
| 48 | #include <target_syssvc.h>
|
---|
| 49 | #include "kernel_cfg.h"
|
---|
| 50 | #include "device.h"
|
---|
| 51 |
|
---|
| 52 |
|
---|
| 53 | /*
|
---|
| 54 | * SIL関数のマクロ定義
|
---|
| 55 | */
|
---|
| 56 | #define sil_orw_mem(a, b) sil_wrw_mem((a), sil_rew_mem(a) | (b))
|
---|
| 57 | #define sil_andw_mem(a, b) sil_wrw_mem((a), sil_rew_mem(a) & ~(b))
|
---|
| 58 | #define sil_modw_mem(a, b, c) sil_wrw_mem((a), (sil_rew_mem(a) & (~b)) | (c))
|
---|
| 59 |
|
---|
| 60 | #define byte2bcd(value) ((((value)/10)<<4) | ((value) % 10))
|
---|
| 61 | #define bcd2byte(value) ((((value)>>4) * 10) + ((value) & 0xF))
|
---|
| 62 |
|
---|
| 63 | /*
|
---|
| 64 | * サービスコールのエラーのログ出力
|
---|
| 65 | */
|
---|
| 66 | Inline void
|
---|
| 67 | svc_perror(const char *file, int_t line, const char *expr, ER ercd)
|
---|
| 68 | {
|
---|
| 69 | if (ercd < 0) {
|
---|
| 70 | t_perror(LOG_ERROR, file, line, expr, ercd);
|
---|
| 71 | }
|
---|
| 72 | }
|
---|
| 73 |
|
---|
| 74 | #define SVC_PERROR(expr) svc_perror(__FILE__, __LINE__, #expr, (expr))
|
---|
| 75 |
|
---|
| 76 | uint_t dipsw_value;
|
---|
| 77 | void (*exti_func[16])(void) = { 0 };
|
---|
| 78 |
|
---|
| 79 |
|
---|
| 80 | /*
|
---|
| 81 | * GPIOモードの内部定義
|
---|
| 82 | */
|
---|
| 83 | #define GPIO_MODE 0x00000003
|
---|
| 84 | #define EXTI_MODE 0x10000000
|
---|
| 85 | #define GPIO_MODE_IT 0x00010000
|
---|
| 86 | #define GPIO_MODE_EVT 0x00020000
|
---|
| 87 | #define RISING_EDGE 0x00100000
|
---|
| 88 | #define FALLING_EDGE 0x00200000
|
---|
| 89 | #define GPIO_OUTPUT_TYPE 0x00000010
|
---|
| 90 |
|
---|
| 91 | static const uint32_t gpio_index[] = {
|
---|
| 92 | TADR_GPIOA_BASE, /* index 0 */
|
---|
| 93 | TADR_GPIOB_BASE, /* index 1 */
|
---|
| 94 | TADR_GPIOC_BASE, /* index 2 */
|
---|
| 95 | TADR_GPIOD_BASE, /* index 3 */
|
---|
| 96 | TADR_GPIOE_BASE, /* index 4 */
|
---|
| 97 | TADR_GPIOF_BASE, /* index 5 */
|
---|
| 98 | TADR_GPIOG_BASE, /* index 6 */
|
---|
| 99 | TADR_GPIOH_BASE, /* index 7 */
|
---|
| 100 | TADR_GPIOI_BASE, /* index 8 */
|
---|
| 101 | TADR_GPIOJ_BASE, /* index 9 */
|
---|
| 102 | TADR_GPIOK_BASE /* index 10 */
|
---|
| 103 | };
|
---|
| 104 |
|
---|
| 105 | #define NUM_OF_GPIOPORT (sizeof(gpio_index)/sizeof(uint32_t))
|
---|
| 106 |
|
---|
| 107 | /*
|
---|
| 108 | * GPIOの初期設定関数
|
---|
| 109 | */
|
---|
| 110 | void
|
---|
| 111 | gpio_setup(uint32_t base, GPIO_Init_t *init, uint32_t pin)
|
---|
| 112 | {
|
---|
| 113 | uint32_t iocurrent = 1<<pin;
|
---|
| 114 | uint32_t temp = 0x00;
|
---|
| 115 | uint32_t index;
|
---|
| 116 |
|
---|
| 117 | for(index = 0 ; index < NUM_OF_GPIOPORT ; index++){
|
---|
| 118 | if(gpio_index[index] == base)
|
---|
| 119 | break;
|
---|
| 120 | }
|
---|
| 121 | if(index == NUM_OF_GPIOPORT)
|
---|
| 122 | return;
|
---|
| 123 |
|
---|
| 124 | /*
|
---|
| 125 | * GPIOモード設定
|
---|
| 126 | */
|
---|
| 127 | /* アルタネート・ファンクション・モード設定 */
|
---|
| 128 | temp = sil_rew_mem((uint32_t *)(base+TOFF_GPIO_AFR0+(pin>>3)*4));
|
---|
| 129 | temp &= ~((uint32_t)0xF << ((uint32_t)(pin & (uint32_t)0x07) * 4)) ;
|
---|
| 130 | if(init->mode == GPIO_MODE_AF)
|
---|
| 131 | temp |= ((uint32_t)(init->alternate) << (((uint32_t)pin & (uint32_t)0x07) * 4));
|
---|
| 132 | sil_wrw_mem((uint32_t *)(base+TOFF_GPIO_AFR0+(pin>>3)*4), temp);
|
---|
| 133 |
|
---|
| 134 | /* 入出力モード設定 */
|
---|
| 135 | sil_modw_mem((uint32_t *)(base+TOFF_GPIO_MODER), (GPIO_MODER_MODER0 << (pin * 2)), ((init->mode & GPIO_MODE) << (pin * 2)));
|
---|
| 136 |
|
---|
| 137 | /* 出力モード設定 */
|
---|
| 138 | if(init->mode == GPIO_MODE_OUTPUT || init->mode == GPIO_MODE_AF){
|
---|
| 139 | sil_modw_mem((uint32_t *)(base+TOFF_GPIO_OSPEEDR), (GPIO_OSPEEDER_OSPEEDR0 << (pin * 2)), (init->speed << (pin * 2)));
|
---|
| 140 | sil_modw_mem((uint32_t *)(base+TOFF_GPIO_OTYPER), (GPIO_OTYPER_OT_0 << pin), (init->otype << pin));
|
---|
| 141 | }
|
---|
| 142 |
|
---|
| 143 | /* プルアップ、プルダウン設定 */
|
---|
| 144 | sil_modw_mem((uint32_t *)(base+TOFF_GPIO_PUPDR), (GPIO_PUPDR_PUPDR0 << (pin * 2)), (init->pull << (pin * 2)));
|
---|
| 145 |
|
---|
| 146 | /*
|
---|
| 147 | * EXTIモード設定
|
---|
| 148 | */
|
---|
| 149 | if((init->mode & EXTI_MODE) == EXTI_MODE){
|
---|
| 150 | /* SYSCFGクロック設定 */
|
---|
| 151 | sil_orw_mem((uint32_t *)(TADR_RCC_BASE+TOFF_RCC_APB2ENR), RCC_APB2ENR_SYSCFGEN);
|
---|
| 152 | temp = sil_rew_mem((uint32_t *)(TADR_RCC_BASE+TOFF_RCC_APB2ENR));
|
---|
| 153 |
|
---|
| 154 | temp = sil_rew_mem((uint32_t *)(TADR_SYSCFG_BASE+TOFF_SYSCFG_EXTICR0+(pin & 0x0C)));
|
---|
| 155 | temp &= ~(0x0F << (4 * (pin & 0x03)));
|
---|
| 156 | temp |= (index << (4 * (pin & 0x03)));
|
---|
| 157 | sil_wrw_mem((uint32_t *)(TADR_SYSCFG_BASE+TOFF_SYSCFG_EXTICR0+(pin & 0x0C)), temp);
|
---|
| 158 |
|
---|
| 159 | if((init->mode & GPIO_MODE_IT) == GPIO_MODE_IT)
|
---|
| 160 | sil_orw_mem((uint32_t *)(TADR_EXTI_BASE+TOFF_EXTI_IMR), iocurrent);
|
---|
| 161 | else
|
---|
| 162 | sil_andw_mem((uint32_t *)(TADR_EXTI_BASE+TOFF_EXTI_IMR), iocurrent);
|
---|
| 163 |
|
---|
| 164 | if((init->mode & GPIO_MODE_EVT) == GPIO_MODE_EVT)
|
---|
| 165 | sil_orw_mem((uint32_t *)(TADR_EXTI_BASE+TOFF_EXTI_EMR), iocurrent);
|
---|
| 166 | else
|
---|
| 167 | sil_andw_mem((uint32_t *)(TADR_EXTI_BASE+TOFF_EXTI_EMR), iocurrent);
|
---|
| 168 |
|
---|
| 169 | if((init->mode & RISING_EDGE) == RISING_EDGE)
|
---|
| 170 | sil_orw_mem((uint32_t *)(TADR_EXTI_BASE+TOFF_EXTI_RTSR), iocurrent);
|
---|
| 171 | else
|
---|
| 172 | sil_andw_mem((uint32_t *)(TADR_EXTI_BASE+TOFF_EXTI_RTSR), iocurrent);
|
---|
| 173 |
|
---|
| 174 | if((init->mode & FALLING_EDGE) == FALLING_EDGE)
|
---|
| 175 | sil_orw_mem((uint32_t *)(TADR_EXTI_BASE+TOFF_EXTI_FTSR), iocurrent);
|
---|
| 176 | else
|
---|
| 177 | sil_andw_mem((uint32_t *)(TADR_EXTI_BASE+TOFF_EXTI_FTSR), iocurrent);
|
---|
| 178 | }
|
---|
| 179 | }
|
---|
| 180 |
|
---|
| 181 |
|
---|
| 182 | /*
|
---|
| 183 | * アドレス指定Dキャッシュインバリデート関数
|
---|
| 184 | * parameter1 addr address (aligned to CACHE_LINE_SIZE(32)-byte boundary)
|
---|
| 185 | * parameter2 dsize size of memory block (in number of bytes)
|
---|
| 186 | */
|
---|
| 187 | void
|
---|
| 188 | invalidatedcache_by_addr(uint8_t *addr, int32_t dsize)
|
---|
| 189 | {
|
---|
| 190 | int32_t op_size = dsize + (CACHE_LINE_SIZE-1);
|
---|
| 191 | uint32_t op_addr = (((uint32_t)addr) & ~(CACHE_LINE_SIZE-1));
|
---|
| 192 |
|
---|
| 193 | asm("dsb 0xF":::"memory");
|
---|
| 194 | while (op_size > 0) {
|
---|
| 195 | sil_wrw_mem((uint32_t *)(TADR_SCB_BASE+TOFF_SCB_DCIMVAC), op_addr);
|
---|
| 196 | op_addr += CACHE_LINE_SIZE;
|
---|
| 197 | op_size -= CACHE_LINE_SIZE;
|
---|
| 198 | }
|
---|
| 199 | asm("dsb 0xF":::"memory");
|
---|
| 200 | asm("isb 0xF":::"memory");
|
---|
| 201 | }
|
---|
| 202 |
|
---|
| 203 | /*
|
---|
| 204 | * アドレス指定Dキャッシュフラッシュ関数
|
---|
| 205 | * parameter1 addr address (aligned to CACHE_LINE_SIZE(32)-byte boundary)
|
---|
| 206 | * parameter2 dsize size of memory block (in number of bytes)
|
---|
| 207 | */
|
---|
| 208 | void flushdcache_by_addr(uint8_t *addr, int32_t dsize)
|
---|
| 209 | {
|
---|
| 210 | int32_t op_size = dsize + (CACHE_LINE_SIZE-1);
|
---|
| 211 | uint32_t op_addr = (((uint32_t)addr) & ~(CACHE_LINE_SIZE-1));
|
---|
| 212 |
|
---|
| 213 | asm("dsb 0xF":::"memory");
|
---|
| 214 | while (op_size > 0) {
|
---|
| 215 | sil_wrw_mem((uint32_t *)(TADR_SCB_BASE+TOFF_SCB_DCCMVAC), op_addr);
|
---|
| 216 | op_addr += CACHE_LINE_SIZE;
|
---|
| 217 | op_size -= CACHE_LINE_SIZE;
|
---|
| 218 | }
|
---|
| 219 | asm("dsb 0xF":::"memory");
|
---|
| 220 | asm("isb 0xF":::"memory");
|
---|
| 221 | }
|
---|
| 222 |
|
---|
| 223 | /*
|
---|
| 224 | * アドレス指定Dキャッシュフラッシュ&インバリデート関数
|
---|
| 225 | * parameter1 addr address (aligned to CACHE_LINE_SIZE(32)-byte boundary)
|
---|
| 226 | * parameter2 dsize size of memory block (in number of bytes)
|
---|
| 227 | */
|
---|
| 228 | void flushinvalidatedcache_by_addr(uint8_t *addr, int32_t dsize)
|
---|
| 229 | {
|
---|
| 230 | int32_t op_size = dsize + (CACHE_LINE_SIZE-1);
|
---|
| 231 | uint32_t op_addr = (((uint32_t)addr) & ~(CACHE_LINE_SIZE-1));
|
---|
| 232 |
|
---|
| 233 | asm("dsb 0xF":::"memory");
|
---|
| 234 | while (op_size > 0) {
|
---|
| 235 | sil_wrw_mem((uint32_t *)(TADR_SCB_BASE+TOFF_SCB_DCCIMVAC), op_addr);
|
---|
| 236 | op_addr += CACHE_LINE_SIZE;
|
---|
| 237 | op_size -= CACHE_LINE_SIZE;
|
---|
| 238 | }
|
---|
| 239 | asm("dsb 0xF":::"memory");
|
---|
| 240 | asm("isb 0xF":::"memory");
|
---|
| 241 | }
|
---|
| 242 |
|
---|
| 243 |
|
---|
| 244 | /*
|
---|
| 245 | * DMACの設定関数
|
---|
| 246 | */
|
---|
| 247 |
|
---|
| 248 | #define NUM_STMDMA 16
|
---|
| 249 | #define NUM_DMAINDEX 5
|
---|
| 250 | #define INDEX_TC 0
|
---|
| 251 | #define INDEX_HT 1
|
---|
| 252 | #define INDEX_TE 2
|
---|
| 253 | #define INDEX_FE 3
|
---|
| 254 | #define INDEX_DME 4
|
---|
| 255 |
|
---|
| 256 | #define DMA_TRS_TIMEOUT 2000 /* 2秒 */
|
---|
| 257 |
|
---|
| 258 | static const uint32_t dma_base[NUM_STMDMA] = {
|
---|
| 259 | TADR_DMA1_STM0_BASE,
|
---|
| 260 | TADR_DMA1_STM1_BASE,
|
---|
| 261 | TADR_DMA1_STM2_BASE,
|
---|
| 262 | TADR_DMA1_STM3_BASE,
|
---|
| 263 | TADR_DMA1_STM4_BASE,
|
---|
| 264 | TADR_DMA1_STM5_BASE,
|
---|
| 265 | TADR_DMA1_STM6_BASE,
|
---|
| 266 | TADR_DMA1_STM7_BASE,
|
---|
| 267 | TADR_DMA2_STM0_BASE,
|
---|
| 268 | TADR_DMA2_STM1_BASE,
|
---|
| 269 | TADR_DMA2_STM2_BASE,
|
---|
| 270 | TADR_DMA2_STM3_BASE,
|
---|
| 271 | TADR_DMA2_STM4_BASE,
|
---|
| 272 | TADR_DMA2_STM5_BASE,
|
---|
| 273 | TADR_DMA2_STM6_BASE,
|
---|
| 274 | TADR_DMA2_STM7_BASE
|
---|
| 275 | };
|
---|
| 276 |
|
---|
| 277 | static const uint32_t dma_flag[NUM_STMDMA][NUM_DMAINDEX] = {
|
---|
| 278 | { 0x00000020, 0x00000010, 0x00000008, 0x00800001, 0x00800004 },
|
---|
| 279 | { 0x00000800, 0x00000400, 0x00000200, 0x00000040, 0x00000100 },
|
---|
| 280 | { 0x00200000, 0x00100000, 0x00080000, 0x00010000, 0x00040000 },
|
---|
| 281 | { 0x08000000, 0x04000000, 0x02000000, 0x00400000, 0x01000000 },
|
---|
| 282 | { 0x00000020, 0x00000010, 0x00000008, 0x00800001, 0x00800004 },
|
---|
| 283 | { 0x00000800, 0x00000400, 0x00000200, 0x00000040, 0x00000100 },
|
---|
| 284 | { 0x00200000, 0x00100000, 0x00080000, 0x00010000, 0x00040000 },
|
---|
| 285 | { 0x08000000, 0x04000000, 0x02000000, 0x00400000, 0x01000000 },
|
---|
| 286 | { 0x00000020, 0x00000010, 0x00000008, 0x00800001, 0x00800004 },
|
---|
| 287 | { 0x00000800, 0x00000400, 0x00000200, 0x00000040, 0x00000100 },
|
---|
| 288 | { 0x00200000, 0x00100000, 0x00080000, 0x00010000, 0x00040000 },
|
---|
| 289 | { 0x08000000, 0x04000000, 0x02000000, 0x00400000, 0x01000000 },
|
---|
| 290 | { 0x00000020, 0x00000010, 0x00000008, 0x00800001, 0x00800004 },
|
---|
| 291 | { 0x00000800, 0x00000400, 0x00000200, 0x00000040, 0x00000100 },
|
---|
| 292 | { 0x00200000, 0x00100000, 0x00080000, 0x00010000, 0x00040000 },
|
---|
| 293 | { 0x08000000, 0x04000000, 0x02000000, 0x00400000, 0x01000000 }
|
---|
| 294 | };
|
---|
| 295 |
|
---|
| 296 | static const uint32_t dma_faddr[NUM_STMDMA/4] = {
|
---|
| 297 | (TADR_DMA1_BASE+TOFF_DMAI_LISR),
|
---|
| 298 | (TADR_DMA1_BASE+TOFF_DMAI_HISR),
|
---|
| 299 | (TADR_DMA2_BASE+TOFF_DMAI_LISR),
|
---|
| 300 | (TADR_DMA2_BASE+TOFF_DMAI_HISR)
|
---|
| 301 | };
|
---|
| 302 |
|
---|
| 303 | static DMA_Handle_t *pDmaHandler[NUM_STMDMA];
|
---|
| 304 |
|
---|
| 305 |
|
---|
| 306 | /*
|
---|
| 307 | * STREAM DMA初期化関数
|
---|
| 308 | * parameter1 hdma: DMAハンドラへのポインタ
|
---|
| 309 | * return ER値
|
---|
| 310 | */
|
---|
| 311 | ER
|
---|
| 312 | dma_init(DMA_Handle_t *hdma)
|
---|
| 313 | {
|
---|
| 314 | uint32_t tmp = 0;
|
---|
| 315 | uint32_t i;
|
---|
| 316 |
|
---|
| 317 | /* パラメータチェック */
|
---|
| 318 | if(hdma == NULL)
|
---|
| 319 | return E_PAR;
|
---|
| 320 |
|
---|
| 321 | for(i = 0 ; i < NUM_STMDMA ; i++){
|
---|
| 322 | if(dma_base[i] == hdma->base)
|
---|
| 323 | break;
|
---|
| 324 | }
|
---|
| 325 | if(i == NUM_STMDMA)
|
---|
| 326 | return E_PAR;
|
---|
| 327 | hdma->sdid = i;
|
---|
| 328 | pDmaHandler[i] = hdma;
|
---|
| 329 |
|
---|
| 330 | /* DMA-CRレジスタ取得 */
|
---|
| 331 | tmp = sil_rew_mem((uint32_t *)(hdma->base+TOFF_DMAS_CR));
|
---|
| 332 |
|
---|
| 333 | /* DMAモードビットをテンポラリィにクリア */
|
---|
| 334 | tmp &= ((uint32_t)~(DMA_SxCR_CHSEL | DMA_SxCR_MBURST | DMA_SxCR_PBURST | \
|
---|
| 335 | DMA_SxCR_PL | DMA_SxCR_MSIZE | DMA_SxCR_PSIZE | \
|
---|
| 336 | DMA_SxCR_MINC | DMA_SxCR_PINC | DMA_SxCR_CIRC | \
|
---|
| 337 | DMA_SxCR_DIR | DMA_SxCR_CT | DMA_SxCR_DBM));
|
---|
| 338 |
|
---|
| 339 | /* DMAモードをテンポラリィに設定 */
|
---|
| 340 | tmp |= hdma->Init.Channel | hdma->Init.Direction |
|
---|
| 341 | hdma->Init.PeriphInc | hdma->Init.MemInc |
|
---|
| 342 | hdma->Init.PeriphDataAlignment | hdma->Init.MemDataAlignment |
|
---|
| 343 | hdma->Init.Mode | hdma->Init.Priority;
|
---|
| 344 |
|
---|
| 345 | /* FIFOモードならバースト設定 */
|
---|
| 346 | if(hdma->Init.FIFOMode == DMA_FIFOMODE_ENABLE){
|
---|
| 347 | tmp |= hdma->Init.MemBurst | hdma->Init.PeriphBurst;
|
---|
| 348 | }
|
---|
| 349 |
|
---|
| 350 | /* DMAモード設定 */
|
---|
| 351 | sil_wrw_mem((uint32_t *)(hdma->base+TOFF_DMAS_CR), tmp);
|
---|
| 352 |
|
---|
| 353 | /* DMA-FCRレジスタを取得 */
|
---|
| 354 | tmp = sil_rew_mem((uint32_t *)(hdma->base+TOFF_DMAS_FCR));
|
---|
| 355 |
|
---|
| 356 | /* FIFOモードをテンポラリィにクリア */
|
---|
| 357 | tmp &= (uint32_t)~(DMA_SxFCR_DMDIS | DMA_SxFCR_FTH);
|
---|
| 358 |
|
---|
| 359 | /* FIFOモードをテンポラリィに設定 */
|
---|
| 360 | tmp |= hdma->Init.FIFOMode;
|
---|
| 361 |
|
---|
| 362 | /* FIFOモードならスレッシュホールドを設定 */
|
---|
| 363 | if(hdma->Init.FIFOMode == DMA_FIFOMODE_ENABLE){
|
---|
| 364 | tmp |= hdma->Init.FIFOThreshold;
|
---|
| 365 | }
|
---|
| 366 |
|
---|
| 367 | /* DMA-FCRレジスタに設定 */
|
---|
| 368 | sil_wrw_mem((uint32_t *)(hdma->base+TOFF_DMAS_FCR), tmp);
|
---|
| 369 |
|
---|
| 370 | /* エラー状態をクリア */
|
---|
| 371 | hdma->ErrorCode = DMA_ERROR_NONE;
|
---|
| 372 | return E_OK;
|
---|
| 373 | }
|
---|
| 374 |
|
---|
| 375 | /*
|
---|
| 376 | * STREAM DMA終了関数
|
---|
| 377 | * parameter1 hdma: DMAハンドラへのポインタ
|
---|
| 378 | * return ER値
|
---|
| 379 | */
|
---|
| 380 | ER
|
---|
| 381 | dma_deinit(DMA_Handle_t *hdma)
|
---|
| 382 | {
|
---|
| 383 | int i;
|
---|
| 384 |
|
---|
| 385 | /* パラメータチェック */
|
---|
| 386 | if(hdma == NULL)
|
---|
| 387 | return E_PAR;
|
---|
| 388 |
|
---|
| 389 | for(i = 0 ; i < NUM_STMDMA ; i++){
|
---|
| 390 | if(dma_base[i] == hdma->base)
|
---|
| 391 | break;
|
---|
| 392 | }
|
---|
| 393 | if(i == NUM_STMDMA)
|
---|
| 394 | return E_PAR;
|
---|
| 395 | hdma->sdid = i;
|
---|
| 396 |
|
---|
| 397 | /* DMAイネーブル */
|
---|
| 398 | sil_andw_mem((uint32_t *)(hdma->base+TOFF_DMAS_CR), DMA_SxCR_EN);
|
---|
| 399 | sil_wrw_mem((uint32_t *)(hdma->base+TOFF_DMAS_CR), 0);
|
---|
| 400 | sil_wrw_mem((uint32_t *)(hdma->base+TOFF_DMAS_NDTR), 0);
|
---|
| 401 | sil_wrw_mem((uint32_t *)(hdma->base+TOFF_DMAS_PAR), 0);
|
---|
| 402 | sil_wrw_mem((uint32_t *)(hdma->base+TOFF_DMAS_M0AR), 0);
|
---|
| 403 | sil_wrw_mem((uint32_t *)(hdma->base+TOFF_DMAS_M1AR), 0);
|
---|
| 404 | sil_wrw_mem((uint32_t *)(hdma->base+TOFF_DMAS_FCR), 0x00000021);
|
---|
| 405 |
|
---|
| 406 | /* 各フラグをクリア */
|
---|
| 407 | for(i = 0 ; i < NUM_DMAINDEX ; i++){
|
---|
| 408 | sil_wrw_mem((uint32_t *)(dma_faddr[hdma->sdid/4]+8), dma_flag[hdma->sdid][i]);
|
---|
| 409 | }
|
---|
| 410 |
|
---|
| 411 | /* エラー状態をクリア */
|
---|
| 412 | hdma->ErrorCode = DMA_ERROR_NONE;
|
---|
| 413 | return E_OK;
|
---|
| 414 | }
|
---|
| 415 |
|
---|
| 416 | /*
|
---|
| 417 | * STREAM DMA開始関数
|
---|
| 418 | * parameter1 hdma: DMAハンドラへのポインタ
|
---|
| 419 | * parameter2 SrcAddress: ソースアドレス
|
---|
| 420 | * parameter3 DstAddress: デスティネーションアドレス
|
---|
| 421 | * parameter4 DataLength: 転送長
|
---|
| 422 | * return ER値
|
---|
| 423 | */
|
---|
| 424 | ER
|
---|
| 425 | dma_start(DMA_Handle_t *hdma, uint32_t SrcAddress, uint32_t DstAddress, uint32_t DataLength)
|
---|
| 426 | {
|
---|
| 427 | /* パラメータチェック */
|
---|
| 428 | if(hdma == NULL)
|
---|
| 429 | return E_PAR;
|
---|
| 430 |
|
---|
| 431 | /* DMA停止 */
|
---|
| 432 | sil_andw_mem((uint32_t *)(hdma->base+TOFF_DMAS_CR), DMA_SxCR_EN);
|
---|
| 433 | sil_andw_mem((uint32_t *)(hdma->base+TOFF_DMAS_CR), DMA_SxCR_TCIE | DMA_SxCR_HTIE | DMA_SxCR_TEIE | DMA_SxCR_DMEIE);
|
---|
| 434 | sil_andw_mem((uint32_t *)(hdma->base+TOFF_DMAS_FCR), DMA_SxFCR_FEIE);
|
---|
| 435 | hdma->status = DMA_STATUS_BUSY;
|
---|
| 436 |
|
---|
| 437 | /* DBMビットクリア */
|
---|
| 438 | sil_andw_mem((uint32_t *)(hdma->base+TOFF_DMAS_CR), DMA_SxCR_DBM);
|
---|
| 439 | /* データ長設定 */
|
---|
| 440 | sil_wrw_mem((uint32_t *)(hdma->base+TOFF_DMAS_NDTR), DataLength);
|
---|
| 441 |
|
---|
| 442 | if((hdma->Init.Direction) == DMA_MEMORY_TO_PERIPH){
|
---|
| 443 | /* メモリからデバイス */
|
---|
| 444 | flushdcache_by_addr((uint8_t *)SrcAddress, DataLength*4);
|
---|
| 445 | sil_wrw_mem((uint32_t *)(hdma->base+TOFF_DMAS_PAR), DstAddress);
|
---|
| 446 | sil_wrw_mem((uint32_t *)(hdma->base+TOFF_DMAS_M0AR), SrcAddress);
|
---|
| 447 | }
|
---|
| 448 | else{ /* デバイスからメモリ */
|
---|
| 449 | flushinvalidatedcache_by_addr((uint8_t *)DstAddress, DataLength*4);
|
---|
| 450 | sil_wrw_mem((uint32_t *)(hdma->base+TOFF_DMAS_PAR), SrcAddress);
|
---|
| 451 | sil_wrw_mem((uint32_t *)(hdma->base+TOFF_DMAS_M0AR), DstAddress);
|
---|
| 452 | }
|
---|
| 453 |
|
---|
| 454 | /* 割込みイネーブル */
|
---|
| 455 | sil_orw_mem((uint32_t *)(hdma->base+TOFF_DMAS_CR), DMA_SxCR_TCIE | DMA_SxCR_HTIE | DMA_SxCR_TEIE | DMA_SxCR_DMEIE);
|
---|
| 456 | sil_orw_mem((uint32_t *)(hdma->base+TOFF_DMAS_FCR), DMA_SxFCR_FEIE);
|
---|
| 457 | /* DMA開始 */
|
---|
| 458 | sil_orw_mem((uint32_t *)(hdma->base+TOFF_DMAS_CR), DMA_SxCR_EN);
|
---|
| 459 |
|
---|
| 460 | return E_OK;
|
---|
| 461 | }
|
---|
| 462 |
|
---|
| 463 | /*
|
---|
| 464 | * STREAM DMA停止関数
|
---|
| 465 | * parameter1 hdma : DMAハンドラへのポインタ
|
---|
| 466 | * return ER値
|
---|
| 467 | */
|
---|
| 468 | ER
|
---|
| 469 | dma_end(DMA_Handle_t *hdma)
|
---|
| 470 | {
|
---|
| 471 | uint32_t tick = 0;
|
---|
| 472 |
|
---|
| 473 | /* DMA停止 */
|
---|
| 474 | sil_andw_mem((uint32_t *)(hdma->base+TOFF_DMAS_CR), DMA_SxCR_EN);
|
---|
| 475 |
|
---|
| 476 | /* DMA停止待ち */
|
---|
| 477 | while((sil_rew_mem((uint32_t *)(hdma->base+TOFF_DMAS_CR)) & DMA_SxCR_EN) != 0){
|
---|
| 478 | /* Check for the Timeout */
|
---|
| 479 | if(tick > DMA_TRS_TIMEOUT){
|
---|
| 480 | /* タイムアウトエラー設定 */
|
---|
| 481 | hdma->ErrorCode |= DMA_ERROR_TIMEOUT;
|
---|
| 482 | return E_TMOUT;
|
---|
| 483 | }
|
---|
| 484 | dly_tsk(1);
|
---|
| 485 | }
|
---|
| 486 | hdma->status = 0;
|
---|
| 487 | return E_OK;
|
---|
| 488 | }
|
---|
| 489 |
|
---|
| 490 | /*
|
---|
| 491 | * STREAM DMA割込み処理関数
|
---|
| 492 | * parameter1 hdma: DMAハンドラへのポインタ
|
---|
| 493 | */
|
---|
| 494 | void
|
---|
| 495 | dma_inthandler(DMA_Handle_t *hdma)
|
---|
| 496 | {
|
---|
| 497 | /*
|
---|
| 498 | * 転送エラー処理
|
---|
| 499 | */
|
---|
| 500 | if((sil_rew_mem((uint32_t *)(dma_faddr[hdma->sdid/4])) & dma_flag[hdma->sdid][INDEX_TE]) != 0){
|
---|
| 501 | if((sil_rew_mem((uint32_t *)(hdma->base+TOFF_DMAS_CR)) & DMA_SxCR_TEIE) != 0){
|
---|
| 502 | /* 転送エラー割込みクリア */
|
---|
| 503 | sil_andw_mem((uint32_t *)(hdma->base+TOFF_DMAS_CR), DMA_SxCR_TEIE);
|
---|
| 504 | /* 転送エラーフラグをクリア */
|
---|
| 505 | sil_wrw_mem((uint32_t *)(dma_faddr[hdma->sdid/4]+8), dma_flag[hdma->sdid][INDEX_TE]);
|
---|
| 506 | /* 転送エラー状態を設定 */
|
---|
| 507 | hdma->ErrorCode |= DMA_ERROR_TE;
|
---|
| 508 | hdma->status = DMA_STATUS_READY_ERROR;
|
---|
| 509 | /* エラーコールバック */
|
---|
| 510 | if(hdma->errorcallback != NULL)
|
---|
| 511 | hdma->errorcallback(hdma);
|
---|
| 512 | }
|
---|
| 513 | }
|
---|
| 514 | /*
|
---|
| 515 | * FIFOエラー処理
|
---|
| 516 | */
|
---|
| 517 | if((sil_rew_mem((uint32_t *)(dma_faddr[hdma->sdid/4])) & dma_flag[hdma->sdid][INDEX_FE]) != 0){
|
---|
| 518 | if((sil_rew_mem((uint32_t *)(hdma->base+TOFF_DMAS_FCR)) & DMA_SxFCR_FEIE) != 0){
|
---|
| 519 | /* FIFOエラー割込みをクリア */
|
---|
| 520 | sil_andw_mem((uint32_t *)(hdma->base+TOFF_DMAS_FCR), DMA_SxFCR_FEIE);
|
---|
| 521 | /* FIFOエラーフラグをクリア */
|
---|
| 522 | sil_wrw_mem((uint32_t *)(dma_faddr[hdma->sdid/4]+8), dma_flag[hdma->sdid][INDEX_FE]);
|
---|
| 523 | /* FIFOエラーを設定 */
|
---|
| 524 | hdma->ErrorCode |= DMA_ERROR_FE;
|
---|
| 525 | hdma->status = DMA_STATUS_READY_ERROR;
|
---|
| 526 | /* エラーコールバック */
|
---|
| 527 | if(hdma->errorcallback != NULL){
|
---|
| 528 | hdma->errorcallback(hdma);
|
---|
| 529 | }
|
---|
| 530 | }
|
---|
| 531 | }
|
---|
| 532 | /*
|
---|
| 533 | * ダイレクト・メモリ・エラー処理
|
---|
| 534 | */
|
---|
| 535 | if((sil_rew_mem((uint32_t *)(dma_faddr[hdma->sdid/4])) & dma_flag[hdma->sdid][INDEX_DME]) != 0){
|
---|
| 536 | if((sil_rew_mem((uint32_t *)(hdma->base+TOFF_DMAS_CR)) & DMA_SxCR_DMEIE) != 0){
|
---|
| 537 | /* DMEエラー割込みをクリア */
|
---|
| 538 | sil_andw_mem((uint32_t *)(hdma->base+TOFF_DMAS_CR), DMA_SxCR_DMEIE);
|
---|
| 539 | /* DMEエラーフラグをクリア */
|
---|
| 540 | sil_wrw_mem((uint32_t *)(dma_faddr[hdma->sdid/4]+8), dma_flag[hdma->sdid][INDEX_DME]);
|
---|
| 541 | /* DMEエラーを設定 */
|
---|
| 542 | hdma->ErrorCode |= DMA_ERROR_DME;
|
---|
| 543 | hdma->status = DMA_STATUS_READY_ERROR;
|
---|
| 544 | /* エラーコールバック */
|
---|
| 545 | if(hdma->errorcallback != NULL)
|
---|
| 546 | hdma->errorcallback(hdma);
|
---|
| 547 | }
|
---|
| 548 | }
|
---|
| 549 | /*
|
---|
| 550 | * ハーフ転送終了処理
|
---|
| 551 | */
|
---|
| 552 | if((sil_rew_mem((uint32_t *)(dma_faddr[hdma->sdid/4])) & dma_flag[hdma->sdid][INDEX_HT]) != 0){
|
---|
| 553 | if((sil_rew_mem((uint32_t *)(hdma->base+TOFF_DMAS_CR)) & DMA_SxCR_HTIE) != 0){
|
---|
| 554 | /* マルチバッファモード */
|
---|
| 555 | if((sil_rew_mem((uint32_t *)(hdma->base+TOFF_DMAS_CR)) & DMA_SxCR_DBM) != 0){
|
---|
| 556 | /* ハーフ転送フラグをクリア */
|
---|
| 557 | sil_wrw_mem((uint32_t *)(dma_faddr[hdma->sdid/4]+8), dma_flag[hdma->sdid][INDEX_HT]);
|
---|
| 558 |
|
---|
| 559 | /* メモリ0使用 */
|
---|
| 560 | if((sil_rew_mem((uint32_t *)(hdma->base+TOFF_DMAS_CR)) & DMA_SxCR_CT) == 0){
|
---|
| 561 | /* ハーフメモリ0の状態設定 */
|
---|
| 562 | hdma->status = DMA_STATUS_READY_HMEM0;
|
---|
| 563 | }
|
---|
| 564 | /* メモリ1使用 */
|
---|
| 565 | else if((sil_rew_mem((uint32_t *)(hdma->base+TOFF_DMAS_CR)) & DMA_SxCR_CT) != 0){
|
---|
| 566 | /* ハーフメモリ1の状態設定 */
|
---|
| 567 | hdma->status = DMA_STATUS_READY_HMEM1;
|
---|
| 568 | }
|
---|
| 569 | }
|
---|
| 570 | else{
|
---|
| 571 | if((sil_rew_mem((uint32_t *)(hdma->base+TOFF_DMAS_CR)) & DMA_SxCR_CIRC) == 0){
|
---|
| 572 | /* ハーフ転送割込みをクリア */
|
---|
| 573 | sil_andw_mem((uint32_t *)(hdma->base+TOFF_DMAS_CR), DMA_SxCR_HTIE);
|
---|
| 574 | }
|
---|
| 575 | /* ハーフ転送完了フラグをクリア */
|
---|
| 576 | sil_wrw_mem((uint32_t *)(dma_faddr[hdma->sdid/4]+8), dma_flag[hdma->sdid][INDEX_HT]);
|
---|
| 577 | /* ハーフ転送ステータスに変更 */
|
---|
| 578 | hdma->status = DMA_STATUS_READY_HMEM0;
|
---|
| 579 | }
|
---|
| 580 | /* ハーフ転送終了コールバック */
|
---|
| 581 | if(hdma->xferhalfcallback != NULL)
|
---|
| 582 | hdma->xferhalfcallback(hdma);
|
---|
| 583 | }
|
---|
| 584 | }
|
---|
| 585 | /*
|
---|
| 586 | * 転送終了処理
|
---|
| 587 | */
|
---|
| 588 | if((sil_rew_mem((uint32_t *)(dma_faddr[hdma->sdid/4])) & dma_flag[hdma->sdid][INDEX_TC]) != 0){
|
---|
| 589 | if((sil_rew_mem((uint32_t *)(hdma->base+TOFF_DMAS_CR)) & DMA_SxCR_TCIE) != 0){
|
---|
| 590 | if((sil_rew_mem((uint32_t *)(hdma->base+TOFF_DMAS_CR)) & DMA_SxCR_DBM) != 0){
|
---|
| 591 | /* 転送完了フラグをクリア */
|
---|
| 592 | sil_wrw_mem((uint32_t *)(dma_faddr[hdma->sdid/4]+8), dma_flag[hdma->sdid][INDEX_TC]);
|
---|
| 593 | /* メモリ1使用 */
|
---|
| 594 | if((sil_rew_mem((uint32_t *)(hdma->base+TOFF_DMAS_CR)) & DMA_SxCR_CT) == 0){
|
---|
| 595 | /* メモリ1転送終了コールバック */
|
---|
| 596 | if(hdma->xferm1callback != NULL)
|
---|
| 597 | hdma->xferm1callback(hdma);
|
---|
| 598 | }
|
---|
| 599 | /* メモリ0使用 */
|
---|
| 600 | else if((sil_rew_mem((uint32_t *)(hdma->base+TOFF_DMAS_CR)) & DMA_SxCR_CT) != 0){
|
---|
| 601 | /* 転送終了コールバック */
|
---|
| 602 | if(hdma->xfercallback != NULL)
|
---|
| 603 | hdma->xfercallback(hdma);
|
---|
| 604 | }
|
---|
| 605 | }
|
---|
| 606 | else{
|
---|
| 607 | if((sil_rew_mem((uint32_t *)(hdma->base+TOFF_DMAS_CR)) & DMA_SxCR_CIRC) == 0){
|
---|
| 608 | /* 転送割込みをクリア */
|
---|
| 609 | sil_andw_mem((uint32_t *)(hdma->base+TOFF_DMAS_CR), DMA_SxCR_TCIE);
|
---|
| 610 | }
|
---|
| 611 | /* 転送完了フラグをクリア */
|
---|
| 612 | sil_wrw_mem((uint32_t *)(dma_faddr[hdma->sdid/4]+8), dma_flag[hdma->sdid][INDEX_TC]);
|
---|
| 613 | /* ステータスを終了へ */
|
---|
| 614 | hdma->ErrorCode = DMA_ERROR_NONE;
|
---|
| 615 | hdma->status = DMA_STATUS_READY_MEM0;
|
---|
| 616 | /* 転送終了コールバック */
|
---|
| 617 | if(hdma->xfercallback != NULL)
|
---|
| 618 | hdma->xfercallback(hdma);
|
---|
| 619 | }
|
---|
| 620 | }
|
---|
| 621 | }
|
---|
| 622 | }
|
---|
| 623 |
|
---|
| 624 | /*
|
---|
| 625 | * STREAM DMA 割込みサービスルーチン
|
---|
| 626 | */
|
---|
| 627 | void
|
---|
| 628 | stream_dma_isr(intptr_t exinf)
|
---|
| 629 | {
|
---|
| 630 | dma_inthandler(pDmaHandler[(uint32_t)exinf]);
|
---|
| 631 | }
|
---|
| 632 |
|
---|
| 633 |
|
---|
| 634 | static DMA2D_Handle_t *pDma2dHandler;
|
---|
| 635 |
|
---|
| 636 | /*
|
---|
| 637 | * DMA2D割込み関数
|
---|
| 638 | */
|
---|
| 639 | void dma2d_inthandler(DMA2D_Handle_t *hdma2d)
|
---|
| 640 | {
|
---|
| 641 | uint32_t isr = sil_rew_mem((uint32_t *)(hdma2d->base+TOFF_DMA2D_ISR));
|
---|
| 642 | /*
|
---|
| 643 | * 転送エラー判定
|
---|
| 644 | */
|
---|
| 645 | if((isr & DMA2D_ISR_TEIF) != 0){
|
---|
| 646 | if((sil_rew_mem((uint32_t *)(hdma2d->base+TOFF_DMA2D_CR)) & DMA2D_CR_TEIE) != 0){
|
---|
| 647 | /* 転送エラー割込みDisable */
|
---|
| 648 | sil_andw_mem((uint32_t *)(hdma2d->base+TOFF_DMA2D_CR), DMA2D_CR_TEIE);
|
---|
| 649 | hdma2d->ErrorCode |= DMA2D_ERROR_TE; /* 転送エラー設定 */
|
---|
| 650 | hdma2d->status = DMA2D_STATUS_ERROR;
|
---|
| 651 | /* 転送エラー割込みクリア */
|
---|
| 652 | sil_wrw_mem((uint32_t *)(hdma2d->base+TOFF_DMA2D_IFCR), DMA2D_IFSR_CTEIF);
|
---|
| 653 | /* 転送エラーコールバック */
|
---|
| 654 | if(hdma2d->errorcallback != NULL)
|
---|
| 655 | hdma2d->errorcallback(hdma2d);
|
---|
| 656 | isig_sem(DMA2DTRNSEM);
|
---|
| 657 | }
|
---|
| 658 | }
|
---|
| 659 | /*
|
---|
| 660 | * コンフィギュレーションエラー判定
|
---|
| 661 | */
|
---|
| 662 | if((isr & DMA2D_ISR_CEIF) != 0){
|
---|
| 663 | if((sil_rew_mem((uint32_t *)(hdma2d->base+TOFF_DMA2D_CR)) & DMA2D_CR_CEIE) != 0){
|
---|
| 664 | /* コンフィギュレーションエラーDisable */
|
---|
| 665 | sil_andw_mem((uint32_t *)(hdma2d->base+TOFF_DMA2D_CR), DMA2D_CR_CEIE);
|
---|
| 666 | /* コンフィギュレーションエラー割込みクリア */
|
---|
| 667 | sil_wrw_mem((uint32_t *)(hdma2d->base+TOFF_DMA2D_IFCR), DMA2D_IFSR_CCEIF);
|
---|
| 668 | hdma2d->ErrorCode |= DMA2D_ERROR_CE; /* コンフィギュレーションエラー設定 */
|
---|
| 669 | hdma2d->status = DMA2D_STATUS_ERROR;
|
---|
| 670 | /* コンフィギュレーションエラーコールバック */
|
---|
| 671 | if(hdma2d->errorcallback != NULL)
|
---|
| 672 | hdma2d->errorcallback(hdma2d);
|
---|
| 673 | isig_sem(DMA2DTRNSEM);
|
---|
| 674 | }
|
---|
| 675 | }
|
---|
| 676 | /*
|
---|
| 677 | * 転送終了割込み判定
|
---|
| 678 | */
|
---|
| 679 | if((isr & DMA2D_ISR_TCIF) != 0){
|
---|
| 680 | if((sil_rew_mem((uint32_t *)(hdma2d->base+TOFF_DMA2D_CR)) & DMA2D_CR_TCIE) != 0){
|
---|
| 681 | /* 転送終了割込みDisable */
|
---|
| 682 | sil_andw_mem((uint32_t *)(hdma2d->base+TOFF_DMA2D_CR), DMA2D_CR_TCIE);
|
---|
| 683 | /* 転送終了割込みクリア */
|
---|
| 684 | sil_wrw_mem((uint32_t *)(hdma2d->base+TOFF_DMA2D_IFCR), DMA2D_IFSR_CTCIF);
|
---|
| 685 | hdma2d->ErrorCode = DMA2D_ERROR_NONE; /* エラー情報リセット */
|
---|
| 686 | hdma2d->status = DMA2D_STATUS_TCOMP;
|
---|
| 687 | /* 転送終了コールバック */
|
---|
| 688 | if(hdma2d->xfercallback != NULL)
|
---|
| 689 | hdma2d->xfercallback(hdma2d);
|
---|
| 690 | isig_sem(DMA2DTRNSEM);
|
---|
| 691 | }
|
---|
| 692 | }
|
---|
| 693 | /*
|
---|
| 694 | * CLUTローディング転送割込み判定
|
---|
| 695 | */
|
---|
| 696 | if((isr & DMA2D_ISR_CTCIF) != 0){
|
---|
| 697 | if((sil_rew_mem((uint32_t *)(hdma2d->base+TOFF_DMA2D_CR)) & DMA2D_CR_CTCIE) != 0){
|
---|
| 698 | /* CLUT転送終了割込みDisable */
|
---|
| 699 | sil_andw_mem((uint32_t *)(hdma2d->base+TOFF_DMA2D_CR), DMA2D_CR_CTCIE);
|
---|
| 700 | /* 転送終了割込みクリア */
|
---|
| 701 | sil_wrw_mem((uint32_t *)(hdma2d->base+TOFF_DMA2D_IFCR), DMA2D_IFSR_CCTCIF);
|
---|
| 702 | hdma2d->ErrorCode = DMA2D_ERROR_NONE; /* エラー情報リセット */
|
---|
| 703 | hdma2d->status = DMA2D_STATUS_CCOMP;
|
---|
| 704 | /* 転送終了コールバック */
|
---|
| 705 | if(hdma2d->xfercallback != NULL)
|
---|
| 706 | hdma2d->xfercallback(hdma2d);
|
---|
| 707 | isig_sem(DMA2DTRNSEM);
|
---|
| 708 | }
|
---|
| 709 | }
|
---|
| 710 | }
|
---|
| 711 |
|
---|
| 712 | /*
|
---|
| 713 | * DMA2Dの初期設定
|
---|
| 714 | * parameter1 hdma2d DMA2Dハンドラへのポインタ
|
---|
| 715 | * return 正常終了ならばE_OK
|
---|
| 716 | */
|
---|
| 717 | ER
|
---|
| 718 | dma2d_init(DMA2D_Handle_t *hdma2d)
|
---|
| 719 | {
|
---|
| 720 | volatile uint32_t tmp = 0;
|
---|
| 721 | static bool_t init = false;
|
---|
| 722 |
|
---|
| 723 | if(hdma2d == NULL)
|
---|
| 724 | return E_PAR;
|
---|
| 725 |
|
---|
| 726 | wai_sem(DMA2DSEM); /* セマフォロック */
|
---|
| 727 | pDma2dHandler = hdma2d;
|
---|
| 728 | if(!init){
|
---|
| 729 | /* クロック設定 */
|
---|
| 730 | sil_orw_mem((uint32_t *)(TADR_RCC_BASE+TOFF_RCC_AHB1ENR), RCC_AHB1ENR_DMA2DEN);
|
---|
| 731 | tmp = sil_rew_mem((uint32_t *)(TADR_RCC_BASE+TOFF_RCC_AHB1ENR));
|
---|
| 732 | (void)(tmp);
|
---|
| 733 | init = true;
|
---|
| 734 | }
|
---|
| 735 |
|
---|
| 736 | /* DMA2D CRレジスタ設定 */
|
---|
| 737 | sil_modw_mem((uint32_t *)(hdma2d->base+TOFF_DMA2D_CR), DMA2D_CR_MODE, hdma2d->Init.Mode);
|
---|
| 738 | /* DMA2D OPFCCレジスタ設定 */
|
---|
| 739 | sil_modw_mem((uint32_t *)(hdma2d->base+TOFF_DMA2D_OPFCCR), DMA2D_OPFCCR_CM, hdma2d->Init.ColorMode);
|
---|
| 740 | /* DMA2D OORレジスタ設定 */
|
---|
| 741 | sil_modw_mem((uint32_t *)(hdma2d->base+TOFF_DMA2D_OOR), DMA2D_OOR_LO, hdma2d->Init.OutputOffset);
|
---|
| 742 |
|
---|
| 743 | #if defined(TOPPERS_STM32F767_NUCLEO144) || defined(TOPPERS_STM32F769_DISCOVERY)
|
---|
| 744 | /* DMA2D OPFCCRレジスタ AI/RBSWAP設定 */
|
---|
| 745 | sil_modw_mem((uint32_t *)(hdma2d->base+TOFF_DMA2D_OPFCCR), DMA2D_OPFCCR_AI, hdma2d->Init.AlphaInverted);
|
---|
| 746 | sil_modw_mem((uint32_t *)(hdma2d->base+TOFF_DMA2D_OPFCCR), DMA2D_OPFCCR_RBS, hdma2d->Init.RedBlueSwap);
|
---|
| 747 | #endif
|
---|
| 748 |
|
---|
| 749 | /* エラー情報リセット */
|
---|
| 750 | hdma2d->ErrorCode = DMA2D_ERROR_NONE;
|
---|
| 751 | return E_OK;
|
---|
| 752 | }
|
---|
| 753 |
|
---|
| 754 | /*
|
---|
| 755 | * DMA2Dレイヤー設定
|
---|
| 756 | * parameter1 hdma2d DMA2Dハンドラへのポインタ
|
---|
| 757 | * parameter2 LayerIdx DMA2Dレイヤーインデックス
|
---|
| 758 | * return 正常終了ならばE_OK
|
---|
| 759 | */
|
---|
| 760 | ER
|
---|
| 761 | dma2d_configlayer(DMA2D_Handle_t *hdma2d, uint32_t LayerIdx)
|
---|
| 762 | {
|
---|
| 763 | DMA2D_LayerCfg_t *pLayerCfg = &hdma2d->LayerCfg[LayerIdx];
|
---|
| 764 | uint32_t tmp = 0;
|
---|
| 765 |
|
---|
| 766 | if(hdma2d->Init.Mode != DMA2D_R2M && hdma2d->Init.Mode != DMA2D_M2M){
|
---|
| 767 | if(pLayerCfg->AlphaMode != DMA2D_NO_MODIF_ALPHA
|
---|
| 768 | && pLayerCfg->AlphaMode != DMA2D_REPLACE_ALPHA && pLayerCfg->AlphaMode != DMA2D_COMBINE_ALPHA){
|
---|
| 769 | sig_sem(DMA2DSEM);
|
---|
| 770 | return E_PAR;
|
---|
| 771 | }
|
---|
| 772 | }
|
---|
| 773 |
|
---|
| 774 | /* レイヤー0(background)DMA2D設定 */
|
---|
| 775 | if(LayerIdx == 0){
|
---|
| 776 | /* DMA2D BGPFCCRレジスタ設定 */
|
---|
| 777 | tmp = sil_rew_mem((uint32_t *)(hdma2d->base+TOFF_DMA2D_BGPFCCR));
|
---|
| 778 | tmp &= (uint32_t)~(DMA2D_BGPFCCR_CM | DMA2D_BGPFCCR_AM | DMA2D_BGPFCCR_ALPHA);
|
---|
| 779 | if (pLayerCfg->InputColorMode == CM_A4 || pLayerCfg->InputColorMode == CM_A8)
|
---|
| 780 | tmp |= (pLayerCfg->InputColorMode | (pLayerCfg->AlphaMode << 16) | ((pLayerCfg->InputAlpha) & 0xFF000000));
|
---|
| 781 | else
|
---|
| 782 | tmp |= (pLayerCfg->InputColorMode | (pLayerCfg->AlphaMode << 16) | (pLayerCfg->InputAlpha << 24));
|
---|
| 783 | sil_wrw_mem((uint32_t *)(hdma2d->base+TOFF_DMA2D_BGPFCCR), tmp);
|
---|
| 784 |
|
---|
| 785 | /* DMA2D BGORレジスタ設定 */
|
---|
| 786 | sil_modw_mem((uint32_t *)(hdma2d->base+TOFF_DMA2D_BGOR), DMA2D_BGOR_LO, pLayerCfg->InputOffset);
|
---|
| 787 | /* DMA2D BGCOLRレジスタ設定 */
|
---|
| 788 | if ((pLayerCfg->InputColorMode == CM_A4) || (pLayerCfg->InputColorMode == CM_A8)){
|
---|
| 789 | sil_wrw_mem((uint32_t *)(hdma2d->base+TOFF_DMA2D_BGCOLR), (pLayerCfg->InputAlpha & 0x00FFFFFF));
|
---|
| 790 | }
|
---|
| 791 | }
|
---|
| 792 | /* レイヤー1(foreground)DMA2D設定 */
|
---|
| 793 | else{
|
---|
| 794 | /* DMA2D FGPFCCRレジスタ設定 */
|
---|
| 795 | tmp = sil_rew_mem((uint32_t *)(hdma2d->base+TOFF_DMA2D_FGPFCCR));
|
---|
| 796 | tmp &= (uint32_t)~(DMA2D_FGPFCCR_CM | DMA2D_FGPFCCR_AM | DMA2D_FGPFCCR_ALPHA);
|
---|
| 797 | if (pLayerCfg->InputColorMode == CM_A4 || pLayerCfg->InputColorMode == CM_A8)
|
---|
| 798 | tmp |= (pLayerCfg->InputColorMode | (pLayerCfg->AlphaMode << 16) | ((pLayerCfg->InputAlpha) & 0xFF000000));
|
---|
| 799 | else
|
---|
| 800 | tmp |= (pLayerCfg->InputColorMode | (pLayerCfg->AlphaMode << 16) | (pLayerCfg->InputAlpha << 24));
|
---|
| 801 | sil_wrw_mem((uint32_t *)(hdma2d->base+TOFF_DMA2D_FGPFCCR), tmp);
|
---|
| 802 |
|
---|
| 803 | /* DMA2D FGORレジスタ設定 */
|
---|
| 804 | sil_modw_mem((uint32_t *)(hdma2d->base+TOFF_DMA2D_FGOR), DMA2D_FGOR_LO, pLayerCfg->InputOffset);
|
---|
| 805 | /* DMA2D FGCOLRレジスタ設定 */
|
---|
| 806 | if ((pLayerCfg->InputColorMode == CM_A4) || (pLayerCfg->InputColorMode == CM_A8)){
|
---|
| 807 | sil_wrw_mem((uint32_t *)(hdma2d->base+TOFF_DMA2D_FGCOLR), (pLayerCfg->InputAlpha & 0x00FFFFFF));
|
---|
| 808 | }
|
---|
| 809 | }
|
---|
| 810 | return E_OK;
|
---|
| 811 | }
|
---|
| 812 |
|
---|
| 813 | /*
|
---|
| 814 | * DMA2D転送スタート
|
---|
| 815 | * parameter1 hdma2d DMA2Dハンドラへのポインタ
|
---|
| 816 | * parameter2 pdata ソースメモリバッファアドレス
|
---|
| 817 | * parameter3 DstAddr デスティネーションメモリバッファアドレス
|
---|
| 818 | * parameter4 Width 転送データ幅
|
---|
| 819 | * parameter5 Height 転送データ高さ
|
---|
| 820 | * return 正常終了ならばE_OK
|
---|
| 821 | */
|
---|
| 822 | ER
|
---|
| 823 | dma2d_start(DMA2D_Handle_t *hdma2d, uint32_t pdata, uint32_t DstAddress, uint32_t Width, uint32_t Height)
|
---|
| 824 | {
|
---|
| 825 | if(hdma2d == NULL)
|
---|
| 826 | return E_PAR;
|
---|
| 827 | /* DMA2D Disable */
|
---|
| 828 | sil_andw_mem((uint32_t *)(hdma2d->base+TOFF_DMA2D_CR), DMA2D_CR_START);
|
---|
| 829 |
|
---|
| 830 | /* DMA2Dデータサイズ設定 */
|
---|
| 831 | sil_wrw_mem((uint32_t *)(hdma2d->base+TOFF_DMA2D_NLR), (Width << 16) | Height);
|
---|
| 832 |
|
---|
| 833 | /* DMA2Dのデスティネーションアドレス設定 */
|
---|
| 834 | sil_wrw_mem((uint32_t *)(hdma2d->base+TOFF_DMA2D_OMAR), DstAddress);
|
---|
| 835 |
|
---|
| 836 | /* DMA2Dメモリモード選択 */
|
---|
| 837 | if (hdma2d->Init.Mode == DMA2D_R2M){
|
---|
| 838 | uint32_t tmp = 0;
|
---|
| 839 | uint32_t tmp1 = 0;
|
---|
| 840 | uint32_t tmp2 = 0;
|
---|
| 841 | uint32_t tmp3 = 0;
|
---|
| 842 | uint32_t tmp4 = 0;
|
---|
| 843 |
|
---|
| 844 | tmp1 = pdata & DMA2D_OCOLR_ALPHA_1;
|
---|
| 845 | tmp2 = pdata & DMA2D_OCOLR_RED_1;
|
---|
| 846 | tmp3 = pdata & DMA2D_OCOLR_GREEN_1;
|
---|
| 847 | tmp4 = pdata & DMA2D_OCOLR_BLUE_1;
|
---|
| 848 |
|
---|
| 849 | /* Prepare the value to be wrote to the OCOLR register according to the color mode */
|
---|
| 850 | if (hdma2d->Init.ColorMode == DMA2D_ARGB8888){
|
---|
| 851 | tmp = (tmp3 | tmp2 | tmp1| tmp4);
|
---|
| 852 | }
|
---|
| 853 | else if (hdma2d->Init.ColorMode == DMA2D_RGB888){
|
---|
| 854 | tmp = (tmp3 | tmp2 | tmp4);
|
---|
| 855 | }
|
---|
| 856 | else if (hdma2d->Init.ColorMode == DMA2D_RGB565){
|
---|
| 857 | tmp2 = (tmp2 >> 19);
|
---|
| 858 | tmp3 = (tmp3 >> 10);
|
---|
| 859 | tmp4 = (tmp4 >> 3 );
|
---|
| 860 | tmp = ((tmp3 << 5) | (tmp2 << 11) | tmp4);
|
---|
| 861 | }
|
---|
| 862 | else if (hdma2d->Init.ColorMode == DMA2D_ARGB1555){
|
---|
| 863 | tmp1 = (tmp1 >> 31);
|
---|
| 864 | tmp2 = (tmp2 >> 19);
|
---|
| 865 | tmp3 = (tmp3 >> 11);
|
---|
| 866 | tmp4 = (tmp4 >> 3 );
|
---|
| 867 | tmp = ((tmp3 << 5) | (tmp2 << 10) | (tmp1 << 15) | tmp4);
|
---|
| 868 | }
|
---|
| 869 | else{ /* DMA2D_CMode = DMA2D_ARGB4444 */
|
---|
| 870 | tmp1 = (tmp1 >> 28);
|
---|
| 871 | tmp2 = (tmp2 >> 20);
|
---|
| 872 | tmp3 = (tmp3 >> 12);
|
---|
| 873 | tmp4 = (tmp4 >> 4 );
|
---|
| 874 | tmp = ((tmp3 << 4) | (tmp2 << 8) | (tmp1 << 12) | tmp4);
|
---|
| 875 | }
|
---|
| 876 | /* Write to DMA2D OCOLR register */
|
---|
| 877 | sil_wrw_mem((uint32_t *)(hdma2d->base+TOFF_DMA2D_OCOLR), tmp);
|
---|
| 878 | }
|
---|
| 879 | else{ /* M2M, M2M_PFC or M2M_Blending DMA2D Mode */
|
---|
| 880 | /* DMA2Dソースアドレス設定 */
|
---|
| 881 | sil_wrw_mem((uint32_t *)(hdma2d->base+TOFF_DMA2D_FGMAR), pdata);
|
---|
| 882 | }
|
---|
| 883 | /*
|
---|
| 884 | * 転送割込みを許可
|
---|
| 885 | */
|
---|
| 886 | sil_orw_mem((uint32_t *)(hdma2d->base+TOFF_DMA2D_CR), (DMA2D_CR_TEIE | DMA2D_CR_CEIE | DMA2D_CR_TCIE));
|
---|
| 887 |
|
---|
| 888 | /* DMA2D Enable */
|
---|
| 889 | sil_orw_mem((uint32_t *)(hdma2d->base+TOFF_DMA2D_CR), DMA2D_CR_START);
|
---|
| 890 | hdma2d->status = DMA2D_STATUS_BUSY;
|
---|
| 891 | return E_OK;
|
---|
| 892 | }
|
---|
| 893 |
|
---|
| 894 | /*
|
---|
| 895 | * DMA2D転送待ち
|
---|
| 896 | * parameter1 hdma2d DMA2Dハンドラへのポインタ
|
---|
| 897 | * parameter2 Timeout 待ち時間(MS)
|
---|
| 898 | * return 正常終了ならばE_OK
|
---|
| 899 | */
|
---|
| 900 | ER
|
---|
| 901 | dma2d_waittransfar(DMA2D_Handle_t *hdma2d, uint32_t Timeout)
|
---|
| 902 | {
|
---|
| 903 | ER ercd = E_OK;
|
---|
| 904 | uint32_t time = 0;
|
---|
| 905 |
|
---|
| 906 | /*
|
---|
| 907 | * 転送設定がある場合のポーリング待ち
|
---|
| 908 | */
|
---|
| 909 | if((sil_rew_mem((uint32_t *)(hdma2d->base+TOFF_DMA2D_CR)) & DMA2D_CR_START) != 0){
|
---|
| 910 | while(hdma2d->status == DMA2D_STATUS_BUSY){
|
---|
| 911 | if(time > Timeout){ /* タイムアウト時間をチェック */
|
---|
| 912 | hdma2d->ErrorCode |= DMA2D_ERROR_TIMEOUT; /* タイムアウトエラー設定 */
|
---|
| 913 | sig_sem(DMA2DSEM);
|
---|
| 914 | return E_TMOUT;
|
---|
| 915 | }
|
---|
| 916 | twai_sem(DMA2DTRNSEM, 1);
|
---|
| 917 | time++;
|
---|
| 918 | }
|
---|
| 919 | if(hdma2d->status == DMA2D_STATUS_ERROR)
|
---|
| 920 | ercd = E_OBJ;
|
---|
| 921 | }
|
---|
| 922 | /*
|
---|
| 923 | * CLUTローディングの処理待ち
|
---|
| 924 | */
|
---|
| 925 | time = 0;
|
---|
| 926 | if((sil_rew_mem((uint32_t *)(hdma2d->base+TOFF_DMA2D_FGPFCCR)) & DMA2D_FGPFCCR_START) != 0){
|
---|
| 927 | while(hdma2d->status == DMA2D_STATUS_BUSY){
|
---|
| 928 | if(time > Timeout){ /* タイムアウト時間をチェック */
|
---|
| 929 | hdma2d->ErrorCode |= DMA2D_ERROR_TIMEOUT; /* タイムアウトエラー設定 */
|
---|
| 930 | sig_sem(DMA2DSEM);
|
---|
| 931 | return E_TMOUT;
|
---|
| 932 | }
|
---|
| 933 | twai_sem(DMA2DTRNSEM, 1);
|
---|
| 934 | time++;
|
---|
| 935 | }
|
---|
| 936 | if(hdma2d->status == DMA2D_STATUS_ERROR)
|
---|
| 937 | ercd = E_OBJ;
|
---|
| 938 | }
|
---|
| 939 | sig_sem(DMA2DSEM); /* セマフォアンロック */
|
---|
| 940 | return ercd;
|
---|
| 941 | }
|
---|
| 942 |
|
---|
| 943 | /*
|
---|
| 944 | * DMA2D割込みハンドラ
|
---|
| 945 | */
|
---|
| 946 | void dma2d_handler(void)
|
---|
| 947 | {
|
---|
| 948 | dma2d_inthandler(pDma2dHandler);
|
---|
| 949 | }
|
---|
| 950 |
|
---|
| 951 |
|
---|
| 952 | #define RTC_ASYNCH_PREDIV 0x7F /* LSE用 RTCクロック */
|
---|
| 953 | #define RTC_SYNCH_PREDIV 0x00FF
|
---|
| 954 |
|
---|
| 955 | #define RTC_TR_RESERVED_MASK (RTC_TR_SU | RTC_TR_ST | RTC_TR_MNU | RTC_TR_MNT | \
|
---|
| 956 | RTC_TR_HU | RTC_TR_HT | RTC_TR_PM)
|
---|
| 957 | #define RTC_DR_RESERVED_MASK (RTC_DR_DU | RTC_DR_DT | RTC_DR_MU | RTC_DR_MT | \
|
---|
| 958 | RTC_DR_WDU | RTC_DR_YU | RTC_DR_YT)
|
---|
| 959 | #define RTC_INIT_MASK ((uint32_t)0xFFFFFFFF)
|
---|
| 960 | #define RTC_RSF_MASK ((uint32_t)0xFFFFFF5F)
|
---|
| 961 |
|
---|
| 962 | #define RTC_TIMEOUT_VALUE (1000*1000)
|
---|
| 963 | #define LSI_TIMEOUT_VALUE (100*1000)
|
---|
| 964 | #define RCC_DBP_TIMEOUT_VALUE (100*1000)
|
---|
| 965 | #define RCC_LSE_TIMEOUT_VALUE (5000*1000)
|
---|
| 966 |
|
---|
| 967 | #define RTC_EXTI_LINE_WUPTIMER ((uint32_t)EXTI_IMR_MR22) /* External interrupt line 22 Connected to the RTC Wake-up event */
|
---|
| 968 |
|
---|
| 969 | uint32_t rtcerrorcode;
|
---|
| 970 |
|
---|
| 971 | static void (*rtcalarmA_callback)(void); /* DMA transfer complete Memory1 callback */
|
---|
| 972 | static void (*rtcalarmB_callback)(void); /* DMA transfer error callback */
|
---|
| 973 | static void (*rtcwakeup_callback)(void); /* rtc wakeup callback */
|
---|
| 974 |
|
---|
| 975 | /*
|
---|
| 976 | * RTCエントリモード設定
|
---|
| 977 | */
|
---|
| 978 | static ER
|
---|
| 979 | rtc_requestInitMode(void)
|
---|
| 980 | {
|
---|
| 981 | uint32_t tick = 0;
|
---|
| 982 |
|
---|
| 983 | /*
|
---|
| 984 | * イニシャルモード判定
|
---|
| 985 | */
|
---|
| 986 | if((sil_rew_mem((uint32_t *)(TADR_RTC_BASE+TOFF_RTC_ISR)) & RTC_ISR_INITF) == 0){
|
---|
| 987 | /*
|
---|
| 988 | * イニシャルモード設定
|
---|
| 989 | */
|
---|
| 990 | sil_wrw_mem((uint32_t *)(TADR_RTC_BASE+TOFF_RTC_ISR), RTC_INIT_MASK);
|
---|
| 991 | while((sil_rew_mem((uint32_t *)(TADR_RTC_BASE+TOFF_RTC_ISR)) & RTC_ISR_INITF) == 0){
|
---|
| 992 | if(tick > RTC_TIMEOUT_VALUE){
|
---|
| 993 | return E_TMOUT;
|
---|
| 994 | }
|
---|
| 995 | }
|
---|
| 996 | sil_dly_nse(1000);
|
---|
| 997 | tick++;
|
---|
| 998 | }
|
---|
| 999 | return E_OK;
|
---|
| 1000 | }
|
---|
| 1001 |
|
---|
| 1002 | /*
|
---|
| 1003 | * RTC用初期化
|
---|
| 1004 | */
|
---|
| 1005 | void
|
---|
| 1006 | rtc_init(intptr_t exinf)
|
---|
| 1007 | {
|
---|
| 1008 | uint32_t tick = 0;
|
---|
| 1009 | volatile uint32_t tmpreg;
|
---|
| 1010 |
|
---|
| 1011 | rtcerrorcode = 0;
|
---|
| 1012 | /*
|
---|
| 1013 | * LSIをオフする
|
---|
| 1014 | */
|
---|
| 1015 | sil_andw_mem((uint32_t *)(TADR_RCC_BASE+TOFF_RCC_CSR), RCC_CSR_LSION);
|
---|
| 1016 | while((sil_rew_mem((uint32_t *)(TADR_RCC_BASE+TOFF_RCC_CSR)) & RCC_CSR_LSIRDY) != 0){
|
---|
| 1017 | if( tick > LSI_TIMEOUT_VALUE){
|
---|
| 1018 | rtcerrorcode |= RTC_ERROR_LSI;
|
---|
| 1019 | return;
|
---|
| 1020 | }
|
---|
| 1021 | sil_dly_nse(1000);
|
---|
| 1022 | tick++;
|
---|
| 1023 | }
|
---|
| 1024 |
|
---|
| 1025 | /*
|
---|
| 1026 | * LSEをオンする
|
---|
| 1027 | */
|
---|
| 1028 | /* Enable Power Clock*/
|
---|
| 1029 | sil_orw_mem((uint32_t *)(TADR_RCC_BASE+TOFF_RCC_APB1ENR), RCC_APB1ENR_PWREN);
|
---|
| 1030 | tmpreg = sil_rew_mem((uint32_t *)(TADR_RCC_BASE+TOFF_RCC_APB1ENR));
|
---|
| 1031 |
|
---|
| 1032 | /* Enable write access to Backup domain */
|
---|
| 1033 | sil_orw_mem((uint32_t *)(TADR_PWR_BASE+TOFF_PWR_CR1), PWR_CR1_DBP);
|
---|
| 1034 |
|
---|
| 1035 | /* Wait for Backup domain Write protection disable */
|
---|
| 1036 | tick = 0;
|
---|
| 1037 | while((sil_rew_mem((uint32_t *)(TADR_PWR_BASE+TOFF_PWR_CR1)) & PWR_CR1_DBP) == 0){
|
---|
| 1038 | if(tick > RCC_DBP_TIMEOUT_VALUE){
|
---|
| 1039 | rtcerrorcode |= RTC_ERROR_LSE;
|
---|
| 1040 | return;
|
---|
| 1041 | }
|
---|
| 1042 | sil_dly_nse(1000);
|
---|
| 1043 | tick++;
|
---|
| 1044 | }
|
---|
| 1045 |
|
---|
| 1046 | /*
|
---|
| 1047 | * LSEON / LSEBYPリセット
|
---|
| 1048 | */
|
---|
| 1049 | sil_andw_mem((uint32_t *)(TADR_RCC_BASE+TOFF_RCC_BDCR), RCC_BDCR_LSEBYP);
|
---|
| 1050 | sil_andw_mem((uint32_t *)(TADR_RCC_BASE+TOFF_RCC_BDCR), RCC_BDCR_LSEON);
|
---|
| 1051 |
|
---|
| 1052 | tick = 0;
|
---|
| 1053 | while((sil_rew_mem((uint32_t *)(TADR_RCC_BASE+TOFF_RCC_BDCR)) & RCC_BDCR_LSERDY) != 0){
|
---|
| 1054 | if(tick > RCC_LSE_TIMEOUT_VALUE){
|
---|
| 1055 | rtcerrorcode |= RTC_ERROR_LSE;
|
---|
| 1056 | return;
|
---|
| 1057 | }
|
---|
| 1058 | sil_dly_nse(1000);
|
---|
| 1059 | tick++;
|
---|
| 1060 | }
|
---|
| 1061 |
|
---|
| 1062 | /*
|
---|
| 1063 | * LSE初期設定
|
---|
| 1064 | */
|
---|
| 1065 | sil_andw_mem((uint32_t *)(TADR_RCC_BASE+TOFF_RCC_BDCR), RCC_BDCR_LSEBYP);
|
---|
| 1066 | sil_orw_mem((uint32_t *)(TADR_RCC_BASE+TOFF_RCC_BDCR), RCC_BDCR_LSEON);
|
---|
| 1067 |
|
---|
| 1068 | tick = 0;
|
---|
| 1069 | while((sil_rew_mem((uint32_t *)(TADR_RCC_BASE+TOFF_RCC_BDCR)) & RCC_BDCR_LSERDY) == 0){
|
---|
| 1070 | if(tick > RCC_LSE_TIMEOUT_VALUE){
|
---|
| 1071 | rtcerrorcode |= RTC_ERROR_LSE;
|
---|
| 1072 | return;
|
---|
| 1073 | }
|
---|
| 1074 | sil_dly_nse(1000);
|
---|
| 1075 | tick++;
|
---|
| 1076 | }
|
---|
| 1077 |
|
---|
| 1078 | /*
|
---|
| 1079 | * RTCクロック設定
|
---|
| 1080 | */
|
---|
| 1081 | if((sil_rew_mem((uint32_t *)(TADR_RCC_BASE+TOFF_RCC_BDCR)) & RCC_BDCR_RTCSEL) != RCC_BDCR_RTCSEL_0){
|
---|
| 1082 | /*
|
---|
| 1083 | * クロック電源設定
|
---|
| 1084 | */
|
---|
| 1085 | tmpreg = (sil_rew_mem((uint32_t *)(TADR_RCC_BASE+TOFF_RCC_BDCR)) & ~(RCC_BDCR_RTCSEL));
|
---|
| 1086 |
|
---|
| 1087 | sil_orw_mem((uint32_t *)(TADR_RCC_BASE+TOFF_RCC_BDCR), RCC_BDCR_BDRST);
|
---|
| 1088 | sil_andw_mem((uint32_t *)(TADR_RCC_BASE+TOFF_RCC_BDCR), RCC_BDCR_BDRST);
|
---|
| 1089 |
|
---|
| 1090 | sil_wrw_mem((uint32_t *)(TADR_RCC_BASE+TOFF_RCC_BDCR), tmpreg);
|
---|
| 1091 |
|
---|
| 1092 | if((tmpreg & RCC_BDCR_LSERDY) != 0){
|
---|
| 1093 | tick = 0;
|
---|
| 1094 | /* Wait till LSE is ready */
|
---|
| 1095 | while((sil_rew_mem((uint32_t *)(TADR_RCC_BASE+TOFF_RCC_BDCR)) & RCC_BDCR_LSERDY) == 0){
|
---|
| 1096 | if(tick > RCC_LSE_TIMEOUT_VALUE){
|
---|
| 1097 | rtcerrorcode |= RTC_ERROR_RTC;
|
---|
| 1098 | return;
|
---|
| 1099 | }
|
---|
| 1100 | sil_dly_nse(1000);
|
---|
| 1101 | tick++;
|
---|
| 1102 | }
|
---|
| 1103 | }
|
---|
| 1104 | sil_andw_mem((uint32_t *)(TADR_RCC_BASE+TOFF_RCC_CFGR), RCC_CFGR_RTCPRE);
|
---|
| 1105 | sil_orw_mem((uint32_t *)(TADR_RCC_BASE+TOFF_RCC_BDCR), RCC_BDCR_RTCSEL_0);
|
---|
| 1106 | }
|
---|
| 1107 |
|
---|
| 1108 | /*
|
---|
| 1109 | * RTCのクロック設定
|
---|
| 1110 | */
|
---|
| 1111 | sil_orw_mem((uint32_t *)(TADR_RCC_BASE+TOFF_RCC_BDCR), RCC_BDCR_RTCEN);
|
---|
| 1112 |
|
---|
| 1113 | /* プロテクション解除 */
|
---|
| 1114 | sil_wrw_mem((uint32_t *)(TADR_RTC_BASE+TOFF_RTC_WPR), 0xCA);
|
---|
| 1115 | sil_wrw_mem((uint32_t *)(TADR_RTC_BASE+TOFF_RTC_WPR), 0x53);
|
---|
| 1116 |
|
---|
| 1117 | /*
|
---|
| 1118 | * RTC初期設定
|
---|
| 1119 | */
|
---|
| 1120 | if(rtc_requestInitMode() != E_OK){
|
---|
| 1121 | rtcerrorcode |= RTC_ERROR_RTC;
|
---|
| 1122 | /* プロテクション設定 */
|
---|
| 1123 | sil_wrw_mem((uint32_t *)(TADR_RTC_BASE+TOFF_RTC_WPR), 0xFF);
|
---|
| 1124 | return;
|
---|
| 1125 | }
|
---|
| 1126 | else{
|
---|
| 1127 | sil_andw_mem((uint32_t *)(TADR_RTC_BASE+TOFF_RTC_CR), (RTC_CR_FMT | RTC_CR_OSEL | RTC_CR_POL));
|
---|
| 1128 |
|
---|
| 1129 | sil_wrw_mem((uint32_t *)(TADR_RTC_BASE+TOFF_RTC_PRER), RTC_SYNCH_PREDIV);
|
---|
| 1130 | sil_orw_mem((uint32_t *)(TADR_RTC_BASE+TOFF_RTC_PRER), (RTC_ASYNCH_PREDIV << 16));
|
---|
| 1131 |
|
---|
| 1132 | sil_andw_mem((uint32_t *)(TADR_RTC_BASE+TOFF_RTC_ISR), RTC_ISR_INIT);
|
---|
| 1133 | sil_andw_mem((uint32_t *)(TADR_RTC_BASE+TOFF_RTC_OR), RTC_OR_ALARMTYPE);
|
---|
| 1134 |
|
---|
| 1135 | /* プロテクション設定 */
|
---|
| 1136 | sil_wrw_mem((uint32_t *)(TADR_RTC_BASE+TOFF_RTC_WPR), 0xFF);
|
---|
| 1137 | return;
|
---|
| 1138 | }
|
---|
| 1139 | }
|
---|
| 1140 |
|
---|
| 1141 | /*
|
---|
| 1142 | * RTCの時刻設定関数
|
---|
| 1143 | *
|
---|
| 1144 | * 時刻の設定はPONIXのtm構造体を使用する
|
---|
| 1145 | * PONIXのインクルードがない場合を考慮し、同一項目のtm2をドライバとして定義する。
|
---|
| 1146 | */
|
---|
| 1147 | ER
|
---|
| 1148 | rtc_set_time(struct tm2 *pt)
|
---|
| 1149 | {
|
---|
| 1150 | uint32_t timetmp = 0;
|
---|
| 1151 | uint32_t datetmp = 0;
|
---|
| 1152 |
|
---|
| 1153 | if(pt == NULL)
|
---|
| 1154 | return E_PAR;
|
---|
| 1155 | if(rtcerrorcode != 0)
|
---|
| 1156 | return E_SYS;
|
---|
| 1157 |
|
---|
| 1158 | SVC_PERROR(wai_sem(RTCSEM));
|
---|
| 1159 |
|
---|
| 1160 | datetmp = (((uint32_t)byte2bcd(pt->tm_year - 30) << 16) |
|
---|
| 1161 | ((uint32_t)byte2bcd(pt->tm_mon) << 8) |
|
---|
| 1162 | ((uint32_t)byte2bcd(pt->tm_mday)) |
|
---|
| 1163 | ((uint32_t)pt->tm_wday << 13));
|
---|
| 1164 | timetmp = (uint32_t)(((uint32_t)byte2bcd(pt->tm_hour) << 16) |
|
---|
| 1165 | ((uint32_t)byte2bcd(pt->tm_min) << 8) |
|
---|
| 1166 | ((uint32_t)byte2bcd(pt->tm_sec)));
|
---|
| 1167 |
|
---|
| 1168 | /* プロテクション解除 */
|
---|
| 1169 | sil_wrw_mem((uint32_t *)(TADR_RTC_BASE+TOFF_RTC_WPR), 0xCA);
|
---|
| 1170 | sil_wrw_mem((uint32_t *)(TADR_RTC_BASE+TOFF_RTC_WPR), 0x53);
|
---|
| 1171 |
|
---|
| 1172 | /*
|
---|
| 1173 | * 初期化モード設定
|
---|
| 1174 | */
|
---|
| 1175 | if(rtc_requestInitMode() != E_OK){
|
---|
| 1176 | /* プロテクション設定 */
|
---|
| 1177 | sil_wrw_mem((uint32_t *)(TADR_RTC_BASE+TOFF_RTC_WPR), 0xFF);
|
---|
| 1178 | SVC_PERROR(sig_sem(RTCSEM));
|
---|
| 1179 | return E_TMOUT;
|
---|
| 1180 | }
|
---|
| 1181 | else{
|
---|
| 1182 | /*
|
---|
| 1183 | * 日付、時刻設定
|
---|
| 1184 | */
|
---|
| 1185 | sil_wrw_mem((uint32_t *)(TADR_RTC_BASE+TOFF_RTC_DR), (datetmp & RTC_DR_RESERVED_MASK));
|
---|
| 1186 | sil_wrw_mem((uint32_t *)(TADR_RTC_BASE+TOFF_RTC_TR), (timetmp & RTC_TR_RESERVED_MASK));
|
---|
| 1187 |
|
---|
| 1188 | /* 初期化モード終了 */
|
---|
| 1189 | sil_andw_mem((uint32_t *)(TADR_RTC_BASE+TOFF_RTC_CR), RTC_CR_BCK);
|
---|
| 1190 | sil_andw_mem((uint32_t *)(TADR_RTC_BASE+TOFF_RTC_ISR), RTC_ISR_INIT);
|
---|
| 1191 |
|
---|
| 1192 | /*
|
---|
| 1193 | * 同期設定
|
---|
| 1194 | */
|
---|
| 1195 | if((sil_rew_mem((uint32_t *)(TADR_RTC_BASE+TOFF_RTC_CR)) & RTC_CR_BYPSHAD) == 0){
|
---|
| 1196 | uint32_t tick = 0;
|
---|
| 1197 |
|
---|
| 1198 | sil_andw_mem((uint32_t *)(TADR_RTC_BASE+TOFF_RTC_ISR), RTC_RSF_MASK);
|
---|
| 1199 | while((sil_rew_mem((uint32_t *)(TADR_RTC_BASE+TOFF_RTC_ISR)) & RTC_ISR_RSF) == 0){
|
---|
| 1200 | if(tick > (RTC_TIMEOUT_VALUE/1000)){
|
---|
| 1201 | SVC_PERROR(sig_sem(RTCSEM));
|
---|
| 1202 | return E_TMOUT;
|
---|
| 1203 | }
|
---|
| 1204 | dly_tsk(1);
|
---|
| 1205 | tick++;
|
---|
| 1206 | }
|
---|
| 1207 | }
|
---|
| 1208 |
|
---|
| 1209 | /* プロテクション設定 */
|
---|
| 1210 | sil_wrw_mem((uint32_t *)(TADR_RTC_BASE+TOFF_RTC_WPR), 0xFF);
|
---|
| 1211 | }
|
---|
| 1212 | SVC_PERROR(sig_sem(RTCSEM));
|
---|
| 1213 | return E_OK;
|
---|
| 1214 | }
|
---|
| 1215 |
|
---|
| 1216 | /*
|
---|
| 1217 | * RTCの時刻取り出し関数
|
---|
| 1218 | *
|
---|
| 1219 | * 時刻の設定はPONIXのtm構造体を使用する
|
---|
| 1220 | * PONIXのインクルードがない場合を考慮し、同一項目のtm2をドライバとして定義する。
|
---|
| 1221 | */
|
---|
| 1222 | ER
|
---|
| 1223 | rtc_get_time(struct tm2 *pt)
|
---|
| 1224 | {
|
---|
| 1225 | uint32_t timetmp = 0;
|
---|
| 1226 | uint32_t datetmp = 0;
|
---|
| 1227 |
|
---|
| 1228 | if(pt == NULL)
|
---|
| 1229 | return E_PAR;
|
---|
| 1230 | if(rtcerrorcode != 0)
|
---|
| 1231 | return E_SYS;
|
---|
| 1232 |
|
---|
| 1233 | SVC_PERROR(wai_sem(RTCSEM));
|
---|
| 1234 | /*
|
---|
| 1235 | * 時刻取得
|
---|
| 1236 | */
|
---|
| 1237 | timetmp = sil_rew_mem((uint32_t *)(TADR_RTC_BASE+TOFF_RTC_TR)) & RTC_TR_RESERVED_MASK;
|
---|
| 1238 | pt->tm_hour = (uint8_t)bcd2byte((uint8_t)((timetmp & (RTC_TR_HT | RTC_TR_HU)) >> 16));
|
---|
| 1239 | pt->tm_min = (uint8_t)bcd2byte((uint8_t)((timetmp & (RTC_TR_MNT | RTC_TR_MNU)) >>8));
|
---|
| 1240 | pt->tm_sec = (uint8_t)bcd2byte((uint8_t)(timetmp & (RTC_TR_ST | RTC_TR_SU)));
|
---|
| 1241 |
|
---|
| 1242 | /*
|
---|
| 1243 | * 日付取得
|
---|
| 1244 | */
|
---|
| 1245 | datetmp = sil_rew_mem((uint32_t *)(TADR_RTC_BASE+TOFF_RTC_DR)) & RTC_DR_RESERVED_MASK;
|
---|
| 1246 | pt->tm_year = (uint8_t)bcd2byte((uint8_t)((datetmp & (RTC_DR_YT | RTC_DR_YU)) >> 16)) + 30;
|
---|
| 1247 | pt->tm_mon = (uint8_t)bcd2byte((uint8_t)((datetmp & (RTC_DR_MT | RTC_DR_MU)) >> 8));
|
---|
| 1248 | pt->tm_mday = (uint8_t)bcd2byte((uint8_t)(datetmp & (RTC_DR_DT | RTC_DR_DU)));
|
---|
| 1249 | pt->tm_wday = (uint8_t)((datetmp & (RTC_DR_WDU)) >> 13);
|
---|
| 1250 |
|
---|
| 1251 | SVC_PERROR(sig_sem(RTCSEM));
|
---|
| 1252 | return E_OK;
|
---|
| 1253 | }
|
---|
| 1254 |
|
---|
| 1255 | /*
|
---|
| 1256 | * RTCアラーム設定
|
---|
| 1257 | * parameter1 : parm: Pointer to Alarm structure
|
---|
| 1258 | * parameter2 : ptm: Pointer to struct tm2
|
---|
| 1259 | * return ERコード
|
---|
| 1260 | */
|
---|
| 1261 | ER
|
---|
| 1262 | rtc_setalarm(RTC_Alarm_t *parm, struct tm2 *ptm)
|
---|
| 1263 | {
|
---|
| 1264 | uint32_t tick = 0;
|
---|
| 1265 | uint32_t tmparm = 0, subsecond = 0;
|
---|
| 1266 | uint32_t tmp, day;
|
---|
| 1267 |
|
---|
| 1268 | if(parm == NULL || ptm == NULL)
|
---|
| 1269 | return E_PAR;
|
---|
| 1270 | if(rtcerrorcode != 0)
|
---|
| 1271 | return E_SYS;
|
---|
| 1272 |
|
---|
| 1273 | if(parm->dayselect == ALARMDAYSEL_DATE)
|
---|
| 1274 | day = ptm->tm_mday;
|
---|
| 1275 | else
|
---|
| 1276 | day = ptm->tm_wday;
|
---|
| 1277 |
|
---|
| 1278 | /*
|
---|
| 1279 | * ALARM-AB設定レジスタ値を取得
|
---|
| 1280 | */
|
---|
| 1281 | SVC_PERROR(wai_sem(RTCSEM));
|
---|
| 1282 | tmparm = ((byte2bcd(ptm->tm_hour) << 16) | (byte2bcd(ptm->tm_min) << 8) |
|
---|
| 1283 | (byte2bcd(ptm->tm_sec)) | (byte2bcd(day) << 24) |
|
---|
| 1284 | ((uint32_t)parm->dayselect) | (parm->alarmmask));
|
---|
| 1285 | subsecond = (uint32_t)(parm->subsecond | parm->subsecondmask);
|
---|
| 1286 |
|
---|
| 1287 | /* プロテクション解除 */
|
---|
| 1288 | sil_wrw_mem((uint32_t *)(TADR_RTC_BASE+TOFF_RTC_WPR), 0xCA);
|
---|
| 1289 | sil_wrw_mem((uint32_t *)(TADR_RTC_BASE+TOFF_RTC_WPR), 0x53);
|
---|
| 1290 |
|
---|
| 1291 | if(parm->alarm == RTC_ALARM_A){
|
---|
| 1292 | /*
|
---|
| 1293 | * ALARM-A設定、レジスタ初期化
|
---|
| 1294 | */
|
---|
| 1295 | sil_andw_mem((uint32_t *)(TADR_RTC_BASE+TOFF_RTC_CR), RTC_CR_ALRAE);
|
---|
| 1296 | tmp = sil_rew_mem((uint32_t *)(TADR_RTC_BASE+TOFF_RTC_ISR));
|
---|
| 1297 | sil_wrw_mem((uint32_t *)(TADR_RTC_BASE+TOFF_RTC_ISR), (~(RTC_ISR_ALRAF | RTC_ISR_INIT) | tmp));
|
---|
| 1298 | while((sil_rew_mem((uint32_t *)(TADR_RTC_BASE+TOFF_RTC_ISR)) & RTC_ISR_ALRAWF) == 0){
|
---|
| 1299 | if(tick > (RTC_TIMEOUT_VALUE/1000)){
|
---|
| 1300 | /* プロテクション設定 */
|
---|
| 1301 | sil_wrw_mem((uint32_t *)(TADR_RTC_BASE+TOFF_RTC_WPR), 0xFF);
|
---|
| 1302 | SVC_PERROR(sig_sem(RTCSEM));
|
---|
| 1303 | return E_TMOUT;
|
---|
| 1304 | }
|
---|
| 1305 | dly_tsk(1);
|
---|
| 1306 | tick++;
|
---|
| 1307 | }
|
---|
| 1308 |
|
---|
| 1309 | /*
|
---|
| 1310 | * ALARM-A設定
|
---|
| 1311 | */
|
---|
| 1312 | sil_wrw_mem((uint32_t *)(TADR_RTC_BASE+TOFF_RTC_ALRMAR), tmparm);
|
---|
| 1313 | sil_wrw_mem((uint32_t *)(TADR_RTC_BASE+TOFF_RTC_ALRMASSR), subsecond);
|
---|
| 1314 | sil_orw_mem((uint32_t *)(TADR_RTC_BASE+TOFF_RTC_CR), RTC_CR_ALRAE);
|
---|
| 1315 | sil_orw_mem((uint32_t *)(TADR_RTC_BASE+TOFF_RTC_CR), RTC_CR_ALRAIE);
|
---|
| 1316 | rtcalarmA_callback = parm->callback;
|
---|
| 1317 | }
|
---|
| 1318 | else{
|
---|
| 1319 | /*
|
---|
| 1320 | * ALARM-B設定、レジスタ初期化
|
---|
| 1321 | */
|
---|
| 1322 | sil_andw_mem((uint32_t *)(TADR_RTC_BASE+TOFF_RTC_CR), RTC_CR_ALRBE);
|
---|
| 1323 | tmp = sil_rew_mem((uint32_t *)(TADR_RTC_BASE+TOFF_RTC_ISR));
|
---|
| 1324 | sil_wrw_mem((uint32_t *)(TADR_RTC_BASE+TOFF_RTC_ISR), (~(RTC_ISR_ALRBF | RTC_ISR_INIT) | tmp));
|
---|
| 1325 | while((sil_rew_mem((uint32_t *)(TADR_RTC_BASE+TOFF_RTC_ISR)) & RTC_ISR_ALRBWF) == 0){
|
---|
| 1326 | if(tick > (RTC_TIMEOUT_VALUE/1000)){
|
---|
| 1327 | /* プロテクション設定 */
|
---|
| 1328 | sil_wrw_mem((uint32_t *)(TADR_RTC_BASE+TOFF_RTC_WPR), 0xFF);
|
---|
| 1329 | SVC_PERROR(sig_sem(RTCSEM));
|
---|
| 1330 | return E_TMOUT;
|
---|
| 1331 | }
|
---|
| 1332 | dly_tsk(1);
|
---|
| 1333 | tick++;
|
---|
| 1334 | }
|
---|
| 1335 |
|
---|
| 1336 | /*
|
---|
| 1337 | * ALARM-B設定
|
---|
| 1338 | */
|
---|
| 1339 | sil_wrw_mem((uint32_t *)(TADR_RTC_BASE+TOFF_RTC_ALRMBR), tmparm);
|
---|
| 1340 | sil_wrw_mem((uint32_t *)(TADR_RTC_BASE+TOFF_RTC_ALRMBSSR), subsecond);
|
---|
| 1341 | sil_orw_mem((uint32_t *)(TADR_RTC_BASE+TOFF_RTC_CR), RTC_CR_ALRBE);
|
---|
| 1342 | sil_orw_mem((uint32_t *)(TADR_RTC_BASE+TOFF_RTC_CR), RTC_CR_ALRBIE);
|
---|
| 1343 | rtcalarmB_callback = parm->callback;
|
---|
| 1344 | }
|
---|
| 1345 |
|
---|
| 1346 | /*
|
---|
| 1347 | * RTC ALARM用EXTI設定
|
---|
| 1348 | */
|
---|
| 1349 | sil_orw_mem((uint32_t *)(TADR_EXTI_BASE+TOFF_EXTI_IMR), EXTI_IMR_MR17);
|
---|
| 1350 | sil_orw_mem((uint32_t *)(TADR_EXTI_BASE+TOFF_EXTI_RTSR), EXTI_RTSR_TR17);
|
---|
| 1351 |
|
---|
| 1352 | /* プロテクション設定 */
|
---|
| 1353 | sil_wrw_mem((uint32_t *)(TADR_RTC_BASE+TOFF_RTC_WPR), 0xFF);
|
---|
| 1354 | SVC_PERROR(sig_sem(RTCSEM));
|
---|
| 1355 | return E_OK;
|
---|
| 1356 | }
|
---|
| 1357 |
|
---|
| 1358 | /*
|
---|
| 1359 | * RTCアラーム停止
|
---|
| 1360 | * parameter1 : Alarm: アラーム設定
|
---|
| 1361 | * return ERコード
|
---|
| 1362 | */
|
---|
| 1363 | ER
|
---|
| 1364 | rtc_stopalarm(uint32_t Alarm)
|
---|
| 1365 | {
|
---|
| 1366 | uint32_t tick = 0;
|
---|
| 1367 |
|
---|
| 1368 | if(rtcerrorcode != 0)
|
---|
| 1369 | return E_SYS;
|
---|
| 1370 | SVC_PERROR(wai_sem(RTCSEM));
|
---|
| 1371 | /* プロテクション解除 */
|
---|
| 1372 | sil_wrw_mem((uint32_t *)(TADR_RTC_BASE+TOFF_RTC_WPR), 0xCA);
|
---|
| 1373 | sil_wrw_mem((uint32_t *)(TADR_RTC_BASE+TOFF_RTC_WPR), 0x53);
|
---|
| 1374 |
|
---|
| 1375 | if(Alarm == RTC_ALARM_A){
|
---|
| 1376 | /*
|
---|
| 1377 | * ALARM-A割込みイネーブル解除
|
---|
| 1378 | */
|
---|
| 1379 | sil_andw_mem((uint32_t *)(TADR_RTC_BASE+TOFF_RTC_CR), RTC_CR_ALRAE);
|
---|
| 1380 | sil_andw_mem((uint32_t *)(TADR_RTC_BASE+TOFF_RTC_CR), RTC_CR_ALRAIE);
|
---|
| 1381 | while((sil_rew_mem((uint32_t *)(TADR_RTC_BASE+TOFF_RTC_ISR)) & RTC_ISR_ALRAWF) == 0){
|
---|
| 1382 | if(tick > (RTC_TIMEOUT_VALUE/1000)){
|
---|
| 1383 | /* プロテクション設定 */
|
---|
| 1384 | sil_wrw_mem((uint32_t *)(TADR_RTC_BASE+TOFF_RTC_WPR), 0xFF);
|
---|
| 1385 | SVC_PERROR(sig_sem(RTCSEM));
|
---|
| 1386 | return E_TMOUT;
|
---|
| 1387 | }
|
---|
| 1388 | dly_tsk(1);
|
---|
| 1389 | tick++;
|
---|
| 1390 | }
|
---|
| 1391 | rtcalarmA_callback = NULL;
|
---|
| 1392 | }
|
---|
| 1393 | else{
|
---|
| 1394 | /*
|
---|
| 1395 | * ALARM-B割込みイネーブル解除
|
---|
| 1396 | */
|
---|
| 1397 | sil_andw_mem((uint32_t *)(TADR_RTC_BASE+TOFF_RTC_CR), RTC_CR_ALRBE);
|
---|
| 1398 | sil_andw_mem((uint32_t *)(TADR_RTC_BASE+TOFF_RTC_CR), RTC_CR_ALRBIE);
|
---|
| 1399 | while((sil_rew_mem((uint32_t *)(TADR_RTC_BASE+TOFF_RTC_ISR)) & RTC_ISR_ALRBWF) == 0){
|
---|
| 1400 | if( tick > RTC_TIMEOUT_VALUE){
|
---|
| 1401 | /* プロテクション設定 */
|
---|
| 1402 | sil_wrw_mem((uint32_t *)(TADR_RTC_BASE+TOFF_RTC_WPR), 0xFF);
|
---|
| 1403 | SVC_PERROR(sig_sem(RTCSEM));
|
---|
| 1404 | return E_TMOUT;
|
---|
| 1405 | }
|
---|
| 1406 | dly_tsk(1);
|
---|
| 1407 | tick++;
|
---|
| 1408 | }
|
---|
| 1409 | rtcalarmB_callback = NULL;
|
---|
| 1410 | }
|
---|
| 1411 | /* プロテクション設定 */
|
---|
| 1412 | sil_wrw_mem((uint32_t *)(TADR_RTC_BASE+TOFF_RTC_WPR), 0xFF);
|
---|
| 1413 | SVC_PERROR(sig_sem(RTCSEM));
|
---|
| 1414 | return E_OK;
|
---|
| 1415 | }
|
---|
| 1416 |
|
---|
| 1417 | /*
|
---|
| 1418 | * RTCアラーム設定値取得
|
---|
| 1419 | * parameter1 : parm: Pointer to Alarm structure
|
---|
| 1420 | * parameter2 : ptm: Pointer to struct tm2
|
---|
| 1421 | * return ERコード
|
---|
| 1422 | */
|
---|
| 1423 | ER
|
---|
| 1424 | rtc_getalarm(RTC_Alarm_t *parm, struct tm2 *ptm, uint32_t Alarm)
|
---|
| 1425 | {
|
---|
| 1426 | uint32_t tmparm = 0;
|
---|
| 1427 | uint32_t subsecond = 0;
|
---|
| 1428 |
|
---|
| 1429 | if(parm == NULL || ptm == NULL)
|
---|
| 1430 | return E_PAR;
|
---|
| 1431 | if(rtcerrorcode != 0)
|
---|
| 1432 | return E_SYS;
|
---|
| 1433 |
|
---|
| 1434 | SVC_PERROR(wai_sem(RTCSEM));
|
---|
| 1435 | if(Alarm == RTC_ALARM_A){
|
---|
| 1436 | /*
|
---|
| 1437 | ALARM-A レジスタ取得
|
---|
| 1438 | */
|
---|
| 1439 | parm->alarm = RTC_ALARM_A;
|
---|
| 1440 | tmparm = sil_rew_mem((uint32_t *)(TADR_RTC_BASE+TOFF_RTC_ALRMAR));
|
---|
| 1441 | subsecond = sil_rew_mem((uint32_t *)(TADR_RTC_BASE+TOFF_RTC_ALRMASSR)) & RTC_ALRMASSR_SS;
|
---|
| 1442 | }
|
---|
| 1443 | else{
|
---|
| 1444 | /*
|
---|
| 1445 | ALARM-B レジスタ取得
|
---|
| 1446 | */
|
---|
| 1447 | parm->alarm = RTC_ALARM_B;
|
---|
| 1448 | tmparm = sil_rew_mem((uint32_t *)(TADR_RTC_BASE+TOFF_RTC_ALRMBR));
|
---|
| 1449 | subsecond = sil_rew_mem((uint32_t *)(TADR_RTC_BASE+TOFF_RTC_ALRMBSSR)) & RTC_ALRMBSSR_SS;
|
---|
| 1450 | }
|
---|
| 1451 |
|
---|
| 1452 | /*
|
---|
| 1453 | * レジスタからパラメータに変換
|
---|
| 1454 | */
|
---|
| 1455 | ptm->tm_hour = bcd2byte((uint8_t)((tmparm & (RTC_ALRMAR_HT | RTC_ALRMAR_HU)) >> 16));
|
---|
| 1456 | ptm->tm_min = bcd2byte((uint8_t)((tmparm & (RTC_ALRMAR_MNT | RTC_ALRMAR_MNU)) >> 8));
|
---|
| 1457 | ptm->tm_sec = bcd2byte((uint8_t)(tmparm & (RTC_ALRMAR_ST | RTC_ALRMAR_SU)));
|
---|
| 1458 | parm->subsecond = (uint32_t) subsecond;
|
---|
| 1459 | parm->dayselect = (uint32_t)(tmparm & RTC_ALRMAR_WDSEL);
|
---|
| 1460 | if(parm->dayselect == ALARMDAYSEL_DATE)
|
---|
| 1461 | ptm->tm_mday = bcd2byte((uint8_t)((tmparm & (RTC_ALRMAR_DT | RTC_ALRMAR_DU)) >> 24));
|
---|
| 1462 | else
|
---|
| 1463 | ptm->tm_wday = bcd2byte((uint8_t)((tmparm & (RTC_ALRMAR_DT | RTC_ALRMAR_DU)) >> 24));
|
---|
| 1464 |
|
---|
| 1465 | parm->alarmmask = (uint32_t)(tmparm & ALARMMASK_ALL);
|
---|
| 1466 | SVC_PERROR(sig_sem(RTCSEM));
|
---|
| 1467 | return E_OK;
|
---|
| 1468 | }
|
---|
| 1469 |
|
---|
| 1470 | /*
|
---|
| 1471 | * RTC WAKEUPタイマ初期化
|
---|
| 1472 | * parameter1 : parm: Pointer to wakeup structure
|
---|
| 1473 | * parameter2 : func: callback function
|
---|
| 1474 | * return ERコード
|
---|
| 1475 | */
|
---|
| 1476 | ER
|
---|
| 1477 | rtc_wakeup_init(RTC_Wakeup_t *parm, void (*func)(void))
|
---|
| 1478 | {
|
---|
| 1479 | uint32_t prer, isr;
|
---|
| 1480 |
|
---|
| 1481 | if(parm == NULL)
|
---|
| 1482 | return E_PAR;
|
---|
| 1483 | parm->wakeuptimerPrescaler = (4 - (sil_rew_mem((uint32_t *)(TADR_RTC_BASE+TOFF_RTC_CR)) & RTC_CR_WUCKSEL));
|
---|
| 1484 | prer = sil_rew_mem((uint32_t *)(TADR_RTC_BASE+TOFF_RTC_PRER));
|
---|
| 1485 | parm->asynchPrescaler = ((prer >> 16) & 0x7f) + 1;
|
---|
| 1486 | parm->synchPrescaler = prer & 0xffff;
|
---|
| 1487 |
|
---|
| 1488 | /* プロテクション解除 */
|
---|
| 1489 | sil_wrw_mem((uint32_t *)(TADR_RTC_BASE+TOFF_RTC_WPR), 0xCA);
|
---|
| 1490 | sil_wrw_mem((uint32_t *)(TADR_RTC_BASE+TOFF_RTC_WPR), 0x53);
|
---|
| 1491 |
|
---|
| 1492 | sil_andw_mem((uint32_t *)(TADR_RTC_BASE+TOFF_RTC_CR), RTC_CR_WUTE);
|
---|
| 1493 | isr = sil_rew_mem((uint32_t *)(TADR_RTC_BASE+TOFF_RTC_ISR)) & RTC_ISR_INIT;
|
---|
| 1494 | isr |= ~(RTC_ISR_WUTF | RTC_ISR_INIT);
|
---|
| 1495 | sil_wrw_mem((uint32_t *)(TADR_RTC_BASE+TOFF_RTC_ISR), isr);
|
---|
| 1496 | sil_wrw_mem((uint32_t *)(TADR_EXTI_BASE+TOFF_EXTI_PR), RTC_EXTI_LINE_WUPTIMER);
|
---|
| 1497 | sil_orw_mem((uint32_t *)(TADR_RTC_BASE+TOFF_RTC_CR), RTC_CR_WUTIE);
|
---|
| 1498 | /*
|
---|
| 1499 | * EXTI WAKEUPLINE設定
|
---|
| 1500 | */
|
---|
| 1501 | sil_orw_mem((uint32_t *)(TADR_EXTI_BASE+TOFF_EXTI_RTSR), RTC_EXTI_LINE_WUPTIMER);
|
---|
| 1502 | sil_orw_mem((uint32_t *)(TADR_EXTI_BASE+TOFF_EXTI_IMR), RTC_EXTI_LINE_WUPTIMER);
|
---|
| 1503 |
|
---|
| 1504 | /* プロテクション設定 */
|
---|
| 1505 | sil_wrw_mem((uint32_t *)(TADR_RTC_BASE+TOFF_RTC_WPR), 0xFF);
|
---|
| 1506 |
|
---|
| 1507 | rtcwakeup_callback = func;
|
---|
| 1508 | return E_OK;
|
---|
| 1509 | }
|
---|
| 1510 |
|
---|
| 1511 | /*
|
---|
| 1512 | * RTC WAKEUP時間設定
|
---|
| 1513 | * parameter1 : parm: WAKEUP時間
|
---|
| 1514 | * return ERコード
|
---|
| 1515 | */
|
---|
| 1516 | ER
|
---|
| 1517 | rtc_setup_wakeuptime(uint32_t time)
|
---|
| 1518 | {
|
---|
| 1519 | uint32_t timeout = LSI_TIMEOUT_VALUE;
|
---|
| 1520 | /*
|
---|
| 1521 | * WAUPTIMER設定停止
|
---|
| 1522 | */
|
---|
| 1523 | if((sil_rew_mem((uint32_t *)(TADR_RTC_BASE+TOFF_RTC_CR)) & RTC_CR_WUTE) != 0){
|
---|
| 1524 | while((sil_rew_mem((uint32_t *)(TADR_RTC_BASE+TOFF_RTC_ISR)) & RTC_ISR_WUTWF) == 0){
|
---|
| 1525 | timeout--;
|
---|
| 1526 | if(timeout == 0)
|
---|
| 1527 | return E_TMOUT;
|
---|
| 1528 | sil_dly_nse(1000);
|
---|
| 1529 | }
|
---|
| 1530 | }
|
---|
| 1531 | /* プロテクション解除 */
|
---|
| 1532 | sil_wrw_mem((uint32_t *)(TADR_RTC_BASE+TOFF_RTC_WPR), 0xCA);
|
---|
| 1533 | sil_wrw_mem((uint32_t *)(TADR_RTC_BASE+TOFF_RTC_WPR), 0x53);
|
---|
| 1534 |
|
---|
| 1535 | sil_andw_mem((uint32_t *)(TADR_RTC_BASE+TOFF_RTC_CR), RTC_CR_WUTE);
|
---|
| 1536 |
|
---|
| 1537 | if(time != 0 && time < 0xFFFF){
|
---|
| 1538 | sil_wrw_mem((uint32_t *)(TADR_EXTI_BASE+TOFF_EXTI_PR), RTC_EXTI_LINE_WUPTIMER);
|
---|
| 1539 | sil_wrw_mem((uint32_t *)(TADR_RTC_BASE+TOFF_RTC_WUTR), time);
|
---|
| 1540 | sil_orw_mem((uint32_t *)(TADR_RTC_BASE+TOFF_RTC_CR), RTC_CR_WUTE);
|
---|
| 1541 | }
|
---|
| 1542 | /* プロテクション設定 */
|
---|
| 1543 | sil_wrw_mem((uint32_t *)(TADR_RTC_BASE+TOFF_RTC_WPR), 0xFF);
|
---|
| 1544 | return E_OK;
|
---|
| 1545 | }
|
---|
| 1546 |
|
---|
| 1547 | /*
|
---|
| 1548 | * SSRの取り出し
|
---|
| 1549 | */
|
---|
| 1550 | uint32_t
|
---|
| 1551 | rtc_get_ssr(void)
|
---|
| 1552 | {
|
---|
| 1553 | return sil_rew_mem((uint32_t *)(TADR_RTC_BASE+TOFF_RTC_SSR));
|
---|
| 1554 | }
|
---|
| 1555 |
|
---|
| 1556 | /*
|
---|
| 1557 | * RTC割込みハンドラ
|
---|
| 1558 | */
|
---|
| 1559 | void rtc_handler(void)
|
---|
| 1560 | {
|
---|
| 1561 | uint32_t tmp;
|
---|
| 1562 |
|
---|
| 1563 | if((sil_rew_mem((uint32_t *)(TADR_RTC_BASE+TOFF_RTC_ISR)) & RTC_CR_ALRAE) != 0){
|
---|
| 1564 | /*
|
---|
| 1565 | * ALARM-A割込み確認
|
---|
| 1566 | */
|
---|
| 1567 | if((sil_rew_mem((uint32_t *)(TADR_RTC_BASE+TOFF_RTC_CR)) & RTC_CR_ALRAIE) != 0){
|
---|
| 1568 | /*
|
---|
| 1569 | * ALARM-Aコールバック
|
---|
| 1570 | */
|
---|
| 1571 | if(rtcalarmA_callback != NULL)
|
---|
| 1572 | rtcalarmA_callback();
|
---|
| 1573 |
|
---|
| 1574 | /* プロテクション解除 */
|
---|
| 1575 | sil_wrw_mem((uint32_t *)(TADR_RTC_BASE+TOFF_RTC_WPR), 0xCA);
|
---|
| 1576 | sil_wrw_mem((uint32_t *)(TADR_RTC_BASE+TOFF_RTC_WPR), 0x53);
|
---|
| 1577 | /*
|
---|
| 1578 | * ALARM-A割込みクリア
|
---|
| 1579 | */
|
---|
| 1580 | tmp = sil_rew_mem((uint32_t *)(TADR_RTC_BASE+TOFF_RTC_ISR)) & RTC_ISR_INIT;
|
---|
| 1581 | sil_wrw_mem((uint32_t *)(TADR_RTC_BASE+TOFF_RTC_ISR), (~(RTC_ISR_ALRAF | RTC_ISR_INIT) | tmp));
|
---|
| 1582 | /* プロテクション設定 */
|
---|
| 1583 | sil_wrw_mem((uint32_t *)(TADR_RTC_BASE+TOFF_RTC_WPR), 0xFF);
|
---|
| 1584 | }
|
---|
| 1585 | }
|
---|
| 1586 | if((sil_rew_mem((uint32_t *)(TADR_RTC_BASE+TOFF_RTC_ISR)) & RTC_CR_ALRBE) != 0){
|
---|
| 1587 | /*
|
---|
| 1588 | * ALARM-B割込み確認
|
---|
| 1589 | */
|
---|
| 1590 | if((sil_rew_mem((uint32_t *)(TADR_RTC_BASE+TOFF_RTC_CR)) & RTC_CR_ALRBIE) != 0){
|
---|
| 1591 | /*
|
---|
| 1592 | * ALARM-Bコールバック
|
---|
| 1593 | */
|
---|
| 1594 | if(rtcalarmB_callback != NULL)
|
---|
| 1595 | rtcalarmB_callback();
|
---|
| 1596 |
|
---|
| 1597 | /* プロテクション解除 */
|
---|
| 1598 | sil_wrw_mem((uint32_t *)(TADR_RTC_BASE+TOFF_RTC_WPR), 0xCA);
|
---|
| 1599 | sil_wrw_mem((uint32_t *)(TADR_RTC_BASE+TOFF_RTC_WPR), 0x53);
|
---|
| 1600 | /*
|
---|
| 1601 | * ALARM-B割込みクリア
|
---|
| 1602 | */
|
---|
| 1603 | tmp = sil_rew_mem((uint32_t *)(TADR_RTC_BASE+TOFF_RTC_ISR)) & RTC_ISR_INIT;
|
---|
| 1604 | sil_wrw_mem((uint32_t *)(TADR_RTC_BASE+TOFF_RTC_ISR), (~(RTC_ISR_ALRBF | RTC_ISR_INIT) | tmp));
|
---|
| 1605 | /* プロテクション設定 */
|
---|
| 1606 | sil_wrw_mem((uint32_t *)(TADR_RTC_BASE+TOFF_RTC_WPR), 0xFF);
|
---|
| 1607 | }
|
---|
| 1608 | }
|
---|
| 1609 | /*
|
---|
| 1610 | * EXTI RTCペンディングクリア
|
---|
| 1611 | */
|
---|
| 1612 | sil_wrw_mem((uint32_t *)(TADR_EXTI_BASE+TOFF_EXTI_PR), EXTI_PR_PR17);
|
---|
| 1613 | }
|
---|
| 1614 |
|
---|
| 1615 | /*
|
---|
| 1616 | * WAKEUP割込みハンドラ
|
---|
| 1617 | */
|
---|
| 1618 | void wakeup_handler(void)
|
---|
| 1619 | {
|
---|
| 1620 | uint32_t isr;
|
---|
| 1621 |
|
---|
| 1622 | /* プロテクション解除 */
|
---|
| 1623 | sil_wrw_mem((uint32_t *)(TADR_RTC_BASE+TOFF_RTC_WPR), 0xCA);
|
---|
| 1624 | sil_wrw_mem((uint32_t *)(TADR_RTC_BASE+TOFF_RTC_WPR), 0x53);
|
---|
| 1625 | /*
|
---|
| 1626 | * WAKEUP TIMER停止
|
---|
| 1627 | */
|
---|
| 1628 | sil_andw_mem((uint32_t *)(TADR_RTC_BASE+TOFF_RTC_CR), RTC_CR_WUTE);
|
---|
| 1629 |
|
---|
| 1630 | /*
|
---|
| 1631 | * WUTF flagクリア
|
---|
| 1632 | */
|
---|
| 1633 | isr = sil_rew_mem((uint32_t *)(TADR_RTC_BASE+TOFF_RTC_ISR)) & RTC_ISR_INIT;
|
---|
| 1634 | isr |= ~(RTC_ISR_WUTF | RTC_ISR_INIT);
|
---|
| 1635 | sil_wrw_mem((uint32_t *)(TADR_RTC_BASE+TOFF_RTC_ISR), isr);
|
---|
| 1636 |
|
---|
| 1637 | /* プロテクション設定 */
|
---|
| 1638 | sil_wrw_mem((uint32_t *)(TADR_RTC_BASE+TOFF_RTC_WPR), 0xFF);
|
---|
| 1639 |
|
---|
| 1640 | /*
|
---|
| 1641 | * EXTIの割込みクリア
|
---|
| 1642 | */
|
---|
| 1643 | sil_wrw_mem((uint32_t *)(TADR_EXTI_BASE+TOFF_EXTI_PR), RTC_EXTI_LINE_WUPTIMER);
|
---|
| 1644 |
|
---|
| 1645 | /*
|
---|
| 1646 | * コールバック関数実行
|
---|
| 1647 | */
|
---|
| 1648 | if(rtcwakeup_callback != NULL)
|
---|
| 1649 | rtcwakeup_callback();
|
---|
| 1650 | }
|
---|
| 1651 |
|
---|
| 1652 |
|
---|
| 1653 | /*
|
---|
| 1654 | * WINDOW WATCH-DOGデータ保存領域
|
---|
| 1655 | */
|
---|
| 1656 | static uint32_t mcount, mcounter, wdogcount;
|
---|
| 1657 |
|
---|
| 1658 | /*
|
---|
| 1659 | * WINDOW WATCH-DOG初期化
|
---|
| 1660 | * parameter1 port: WDOGポート番号
|
---|
| 1661 | * parameter2 hini: WDOGハンドラのポインタ
|
---|
| 1662 | * return 正常終了時 E_OK
|
---|
| 1663 | */
|
---|
| 1664 | ER
|
---|
| 1665 | wdog_init(ID portid, WDOG_Init_t *hini)
|
---|
| 1666 | {
|
---|
| 1667 | if(hini == NULL || portid != WDOG1_PORTID)
|
---|
| 1668 | return E_PAR;
|
---|
| 1669 | if(hini->Window > 127 || hini->Window < 64)
|
---|
| 1670 | return E_PAR;
|
---|
| 1671 | if(hini->Counter > 127 || hini->Counter < 64)
|
---|
| 1672 | return E_PAR;
|
---|
| 1673 |
|
---|
| 1674 | mcount = hini->MCounter;
|
---|
| 1675 | mcounter = 0;
|
---|
| 1676 | wdogcount = hini->Counter;
|
---|
| 1677 | sil_orw_mem((uint32_t *)(TADR_RCC_BASE+TOFF_RCC_APB1ENR), RCC_APB1ENR_WWDGEN);
|
---|
| 1678 | sil_wrw_mem((uint32_t *)(TADR_WWDG_BASE+TOFF_WWDG_CR), wdogcount);
|
---|
| 1679 | if(mcount == 0)
|
---|
| 1680 | sil_wrw_mem((uint32_t *)(TADR_WWDG_BASE+TOFF_WWDG_CFR), (WWDG_CFR_WDGTB | hini->Window));
|
---|
| 1681 | else
|
---|
| 1682 | sil_wrw_mem((uint32_t *)(TADR_WWDG_BASE+TOFF_WWDG_CFR), (WWDG_CFR_EWI | WWDG_CFR_WDGTB | hini->Window));
|
---|
| 1683 | sil_wrw_mem((uint32_t *)(TADR_WWDG_BASE+TOFF_WWDG_CR), (WWDG_CR_WDGA | wdogcount));
|
---|
| 1684 | return E_OK;
|
---|
| 1685 | }
|
---|
| 1686 |
|
---|
| 1687 | /*
|
---|
| 1688 | * WINDOW WATCH-DOG終了設定
|
---|
| 1689 | * parameter1 port: WDOGポート番号
|
---|
| 1690 | * return ERコード
|
---|
| 1691 | */
|
---|
| 1692 | ER
|
---|
| 1693 | wdog_deinit(ID portid)
|
---|
| 1694 | {
|
---|
| 1695 | if(portid != WDOG1_PORTID || wdogcount == 0)
|
---|
| 1696 | return E_PAR;
|
---|
| 1697 | sil_wrw_mem((uint32_t *)(TADR_WWDG_BASE+TOFF_WWDG_CR), wdogcount);
|
---|
| 1698 | sil_andw_mem((uint32_t *)(TADR_RCC_BASE+TOFF_RCC_APB1ENR), RCC_APB1ENR_WWDGEN);
|
---|
| 1699 | wdogcount = 0;
|
---|
| 1700 | return E_OK;
|
---|
| 1701 | }
|
---|
| 1702 |
|
---|
| 1703 | /*
|
---|
| 1704 | * WINDOW WATCH-DOGリセット
|
---|
| 1705 | * parameter1 port: WDOGポート番号
|
---|
| 1706 | * return ERコード
|
---|
| 1707 | */
|
---|
| 1708 | ER
|
---|
| 1709 | wdog_reset(ID portid)
|
---|
| 1710 | {
|
---|
| 1711 | if(portid != WDOG1_PORTID || wdogcount == 0)
|
---|
| 1712 | return E_PAR;
|
---|
| 1713 | sil_wrw_mem((uint32_t *)(TADR_WWDG_BASE+TOFF_WWDG_CR), wdogcount);
|
---|
| 1714 | mcounter = 0;
|
---|
| 1715 | return E_OK;
|
---|
| 1716 | }
|
---|
| 1717 |
|
---|
| 1718 | /*
|
---|
| 1719 | * WINDOW WATCH-DOG割込みハンドラ
|
---|
| 1720 | */
|
---|
| 1721 | void
|
---|
| 1722 | wdog_handler(void)
|
---|
| 1723 | {
|
---|
| 1724 | uint32_t base = TADR_WWDG_BASE;
|
---|
| 1725 |
|
---|
| 1726 | if((sil_rew_mem((uint32_t *)(base+TOFF_WWDG_CFR)) & WWDG_CFR_EWI) != 0
|
---|
| 1727 | && (sil_rew_mem((uint32_t *)(base+TOFF_WWDG_SR)) & WWDG_SR_EWIF) != 0){
|
---|
| 1728 | sil_andw_mem((uint32_t *)(base+TOFF_WWDG_SR), WWDG_SR_EWIF);
|
---|
| 1729 | if(mcounter++ < mcount)
|
---|
| 1730 | sil_wrw_mem((uint32_t *)(base+TOFF_WWDG_CR), wdogcount);
|
---|
| 1731 | }
|
---|
| 1732 | }
|
---|
| 1733 |
|
---|
| 1734 |
|
---|
| 1735 | /*
|
---|
| 1736 | * LED接続ポート
|
---|
| 1737 | *
|
---|
| 1738 | * 拡張I/OボードのLED1-3はプログラマブル入出力ポート0に
|
---|
| 1739 | * にインバータを介して接続されている.
|
---|
| 1740 | */
|
---|
| 1741 |
|
---|
| 1742 | typedef struct gio_confstruct
|
---|
| 1743 | {
|
---|
| 1744 | uint32_t clkbit;
|
---|
| 1745 | uint32_t giobase;
|
---|
| 1746 | uint32_t pinpos;
|
---|
| 1747 | uint32_t pinpp;
|
---|
| 1748 | } gio_conftype;
|
---|
| 1749 |
|
---|
| 1750 | #if defined(TOPPERS_STM32F7_DISCOVERY)
|
---|
| 1751 | static const gio_conftype led_confdata[] = {
|
---|
| 1752 | { RCC_AHB1ENR_GPIOIEN, TADR_GPIOI_BASE, PINPOSITION1, GPIO_PULLUP}
|
---|
| 1753 | };
|
---|
| 1754 | #elif defined(TOPPERS_STM32F769_DISCOVERY)
|
---|
| 1755 | static const gio_conftype led_confdata[] = {
|
---|
| 1756 | { RCC_AHB1ENR_GPIOJEN, TADR_GPIOJ_BASE, PINPOSITION13, GPIO_PULLUP},
|
---|
| 1757 | { RCC_AHB1ENR_GPIOJEN, TADR_GPIOJ_BASE, PINPOSITION5, GPIO_PULLUP}
|
---|
| 1758 | };
|
---|
| 1759 | #elif defined(TOPPERS_STM32F723_DISCOVERY)
|
---|
| 1760 | static const gio_conftype led_confdata[] = {
|
---|
| 1761 | { RCC_AHB1ENR_GPIOAEN, TADR_GPIOA_BASE, PINPOSITION7, GPIO_PULLUP},
|
---|
| 1762 | { RCC_AHB1ENR_GPIOBEN, TADR_GPIOB_BASE, PINPOSITION1, GPIO_PULLUP}
|
---|
| 1763 | };
|
---|
| 1764 | #else
|
---|
| 1765 | static const gio_conftype led_confdata[] = {
|
---|
| 1766 | { RCC_AHB1ENR_GPIOBEN, TADR_GPIOB_BASE, PINPOSITION0, GPIO_PULLUP},
|
---|
| 1767 | { RCC_AHB1ENR_GPIOBEN, TADR_GPIOB_BASE, PINPOSITION7, GPIO_PULLUP},
|
---|
| 1768 | { RCC_AHB1ENR_GPIOBEN, TADR_GPIOB_BASE, PINPOSITION14, GPIO_PULLUP}
|
---|
| 1769 | };
|
---|
| 1770 | #endif
|
---|
| 1771 | #define NUM_LED (sizeof(led_confdata)/sizeof(gio_conftype))
|
---|
| 1772 |
|
---|
| 1773 | /*
|
---|
| 1774 | * LED接続ポート初期化
|
---|
| 1775 | */
|
---|
| 1776 | void
|
---|
| 1777 | led_init(intptr_t exinf)
|
---|
| 1778 | {
|
---|
| 1779 | const gio_conftype *pled = &led_confdata[0];
|
---|
| 1780 | GPIO_Init_t GPIO_Init_Data;
|
---|
| 1781 | uint32_t i;
|
---|
| 1782 |
|
---|
| 1783 | for(i = 0 ; i < NUM_LED ; pled++, i++){
|
---|
| 1784 | sil_orw_mem((uint32_t *)(TADR_RCC_BASE+TOFF_RCC_AHB1ENR), pled->clkbit);
|
---|
| 1785 | /* モード設定 */
|
---|
| 1786 | GPIO_Init_Data.mode = GPIO_MODE_OUTPUT;
|
---|
| 1787 | /* プルアップ プロダウン設定 */
|
---|
| 1788 | GPIO_Init_Data.pull = pled->pinpp;
|
---|
| 1789 | /* 出力モード設定 */
|
---|
| 1790 | GPIO_Init_Data.otype = GPIO_OTYPE_PP;
|
---|
| 1791 | /* スピード設定 */
|
---|
| 1792 | GPIO_Init_Data.speed = GPIO_SPEED_HIGH;
|
---|
| 1793 | gpio_setup(pled->giobase, &GPIO_Init_Data, pled->pinpos);
|
---|
| 1794 |
|
---|
| 1795 | /* 消灯 */
|
---|
| 1796 | sil_wrw_mem((uint32_t *)(pled->giobase+TOFF_GPIO_BSRR), (1 << pled->pinpos)<<16);
|
---|
| 1797 | }
|
---|
| 1798 | }
|
---|
| 1799 |
|
---|
| 1800 | /*
|
---|
| 1801 | * LED接続ポート読み出し
|
---|
| 1802 | */
|
---|
| 1803 | uint_t
|
---|
| 1804 | led_in(void)
|
---|
| 1805 | {
|
---|
| 1806 | const gio_conftype *pled = &led_confdata[0];
|
---|
| 1807 | uint32_t data, i;
|
---|
| 1808 |
|
---|
| 1809 | for(i = 0, data = 0 ; i < NUM_LED ; pled++, i++){
|
---|
| 1810 | if((sil_rew_mem((uint32_t *)(pled->giobase+TOFF_GPIO_IDR)) & (1<<(pled->pinpos))) != 0)
|
---|
| 1811 | data |= (1<<i);
|
---|
| 1812 | }
|
---|
| 1813 | return data;
|
---|
| 1814 | }
|
---|
| 1815 |
|
---|
| 1816 | /*
|
---|
| 1817 | * LED接続ポート書き込み
|
---|
| 1818 | */
|
---|
| 1819 | void
|
---|
| 1820 | led_out(unsigned int led_data)
|
---|
| 1821 | {
|
---|
| 1822 | const gio_conftype *pled = &led_confdata[0];
|
---|
| 1823 | uint32_t reg1, reg2, i;
|
---|
| 1824 |
|
---|
| 1825 | /* 設定値はLED接続ビット以外は変更しない */
|
---|
| 1826 | for(i = 0 ; i < NUM_LED ; pled++, i++){
|
---|
| 1827 | reg1 = reg2 = 0;
|
---|
| 1828 | if((led_data & (1<<i)) != 0)
|
---|
| 1829 | reg2 = 1 << pled->pinpos;
|
---|
| 1830 | else
|
---|
| 1831 | reg1 = 1 << pled->pinpos;
|
---|
| 1832 |
|
---|
| 1833 | /* 書き込みデータを生成して書き込み */
|
---|
| 1834 | sil_wrw_mem((uint32_t *)(pled->giobase+TOFF_GPIO_BSRR), (reg1<<16) | reg2);
|
---|
| 1835 | }
|
---|
| 1836 | }
|
---|
| 1837 |
|
---|
| 1838 | /*
|
---|
| 1839 | * LEDとスイッチの個別設定・読み込み関数群
|
---|
| 1840 | */
|
---|
| 1841 |
|
---|
| 1842 | /*
|
---|
| 1843 | * LEDの状態保存用変数
|
---|
| 1844 | */
|
---|
| 1845 | unsigned int LedState;
|
---|
| 1846 |
|
---|
| 1847 |
|
---|
| 1848 | /*
|
---|
| 1849 | * LED点灯制御
|
---|
| 1850 | */
|
---|
| 1851 | void
|
---|
| 1852 | set_led_state(unsigned int led, unsigned char state){
|
---|
| 1853 | if (state == ON) {
|
---|
| 1854 | LedState = LedState | led;
|
---|
| 1855 | } else {
|
---|
| 1856 | LedState = LedState & ~led;
|
---|
| 1857 | }
|
---|
| 1858 | led_out(LedState);
|
---|
| 1859 | }
|
---|
| 1860 |
|
---|
| 1861 |
|
---|
| 1862 | #if defined(TOPPERS_STM32F7_DISCOVERY)
|
---|
| 1863 | #define TADR_PSW_BASE TADR_GPIOI_BASE
|
---|
| 1864 | #define PSWGIOPEN RCC_AHB1ENR_GPIOIEN
|
---|
| 1865 | #define PSW_PIN PINPOSITION11
|
---|
| 1866 | #elif defined(TOPPERS_STM32F769_DISCOVERY) || defined(TOPPERS_STM32F723_DISCOVERY)
|
---|
| 1867 | #define TADR_PSW_BASE TADR_GPIOA_BASE
|
---|
| 1868 | #define PSWGIOPEN RCC_AHB1ENR_GPIOAEN
|
---|
| 1869 | #define PSW_PIN PINPOSITION0
|
---|
| 1870 | #else
|
---|
| 1871 | #define TADR_PSW_BASE TADR_GPIOC_BASE
|
---|
| 1872 | #define PSWGIOPEN RCC_AHB1ENR_GPIOCEN
|
---|
| 1873 | #define PSW_PIN PINPOSITION13
|
---|
| 1874 | #endif
|
---|
| 1875 |
|
---|
| 1876 | /*
|
---|
| 1877 | * PUSHスイッチ接続ポート初期化
|
---|
| 1878 | */
|
---|
| 1879 | void
|
---|
| 1880 | switch_push_init(intptr_t exinf)
|
---|
| 1881 | {
|
---|
| 1882 | GPIO_Init_t GPIO_Init_Data;
|
---|
| 1883 | volatile uint32_t temp;
|
---|
| 1884 |
|
---|
| 1885 | /* 入力ポートに設定 */
|
---|
| 1886 | /* Enable the BUTTON Clock */
|
---|
| 1887 | sil_orw_mem((uint32_t *)(TADR_RCC_BASE+TOFF_RCC_AHB1ENR), PSWGIOPEN);
|
---|
| 1888 | temp = sil_rew_mem((uint32_t *)(TADR_RCC_BASE+TOFF_RCC_AHB1ENR));
|
---|
| 1889 | (void)(temp);
|
---|
| 1890 | /* モード設定 */
|
---|
| 1891 | GPIO_Init_Data.mode = GPIO_MODE_IT_FALLING;
|
---|
| 1892 | /* プルアップ プロダウン設定 */
|
---|
| 1893 | GPIO_Init_Data.pull = GPIO_NOPULL;
|
---|
| 1894 | gpio_setup(TADR_PSW_BASE, &GPIO_Init_Data, PSW_PIN);
|
---|
| 1895 | }
|
---|
| 1896 |
|
---|
| 1897 | /*
|
---|
| 1898 | * PUSHスイッチコールバック関数設定
|
---|
| 1899 | */
|
---|
| 1900 | void setup_sw_func(intptr_t exinf)
|
---|
| 1901 | {
|
---|
| 1902 | exti_func[PSW_PIN] = (void (*)(void))exinf;
|
---|
| 1903 | }
|
---|
| 1904 |
|
---|
| 1905 | /*
|
---|
| 1906 | * EXTI0割込みハンドラ
|
---|
| 1907 | */
|
---|
| 1908 | void
|
---|
| 1909 | exti0_handler(void)
|
---|
| 1910 | {
|
---|
| 1911 | uint32_t istatus = sil_rew_mem((uint32_t *)(TADR_EXTI_BASE+TOFF_EXTI_PR));
|
---|
| 1912 |
|
---|
| 1913 | if((istatus & (1<<0)) != 0){
|
---|
| 1914 | if(exti_func[0] != NULL)
|
---|
| 1915 | (exti_func[0])();
|
---|
| 1916 | }
|
---|
| 1917 | sil_wrw_mem((uint32_t *)(TADR_EXTI_BASE+TOFF_EXTI_PR), istatus);
|
---|
| 1918 | }
|
---|
| 1919 |
|
---|
| 1920 | /*
|
---|
| 1921 | * EXTI9-5割込みハンドラ
|
---|
| 1922 | */
|
---|
| 1923 | void
|
---|
| 1924 | exti9_handler(void)
|
---|
| 1925 | {
|
---|
| 1926 | /* EXTI line interrupt detected */
|
---|
| 1927 | uint32_t istatus = sil_rew_mem((uint32_t *)(TADR_EXTI_BASE+TOFF_EXTI_PR));
|
---|
| 1928 | uint32_t i;
|
---|
| 1929 | for(i = 0 ; i < NUM_EXTI9_FUNC ; i++){
|
---|
| 1930 | if((istatus & (1<<(i+EXTI9_BASENO))) != 0){
|
---|
| 1931 | if(exti_func[i+EXTI9_BASENO] != NULL)
|
---|
| 1932 | (exti_func[i+EXTI9_BASENO])();
|
---|
| 1933 | }
|
---|
| 1934 | }
|
---|
| 1935 | sil_wrw_mem((uint32_t *)(TADR_EXTI_BASE+TOFF_EXTI_PR), istatus);
|
---|
| 1936 | }
|
---|
| 1937 |
|
---|
| 1938 | /*
|
---|
| 1939 | * EXTI15-10割込みハンドラ
|
---|
| 1940 | */
|
---|
| 1941 | void
|
---|
| 1942 | exti15_handler(void)
|
---|
| 1943 | {
|
---|
| 1944 | /* EXTI line interrupt detected */
|
---|
| 1945 | uint32_t istatus = sil_rew_mem((uint32_t *)(TADR_EXTI_BASE+TOFF_EXTI_PR));
|
---|
| 1946 | uint32_t i;
|
---|
| 1947 | for(i = 0 ; i < NUM_EXTI15_FUNC ; i++){
|
---|
| 1948 | if((istatus & (1<<(i+EXTI15_BASENO))) != 0){
|
---|
| 1949 | if(exti_func[i+EXTI15_BASENO] != NULL)
|
---|
| 1950 | (exti_func[i+EXTI15_BASENO])();
|
---|
| 1951 | }
|
---|
| 1952 | }
|
---|
| 1953 | sil_wrw_mem((uint32_t *)(TADR_EXTI_BASE+TOFF_EXTI_PR), istatus);
|
---|
| 1954 | }
|
---|
| 1955 |
|
---|
| 1956 |
|
---|
| 1957 | /*
|
---|
| 1958 | * DIPSWの取出し
|
---|
| 1959 | */
|
---|
| 1960 | uint_t
|
---|
| 1961 | switch_dip_sense(void)
|
---|
| 1962 | {
|
---|
| 1963 | return dipsw_value;
|
---|
| 1964 | }
|
---|
| 1965 |
|
---|