|
| 1 | +/* |
| 2 | + * The MIT License (MIT) |
| 3 | + * |
| 4 | + * Copyright (c) 2019 Ha Thach (tinyusb.org) |
| 5 | + * |
| 6 | + * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 7 | + * of this software and associated documentation files (the "Software"), to deal |
| 8 | + * in the Software without restriction, including without limitation the rights |
| 9 | + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 10 | + * copies of the Software, and to permit persons to whom the Software is |
| 11 | + * furnished to do so, subject to the following conditions: |
| 12 | + * |
| 13 | + * The above copyright notice and this permission notice shall be included in |
| 14 | + * all copies or substantial portions of the Software. |
| 15 | + * |
| 16 | + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 17 | + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 18 | + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 19 | + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 20 | + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 21 | + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 22 | + * THE SOFTWARE. |
| 23 | + * |
| 24 | + */ |
| 25 | + |
| 26 | +//--------------------------------------------------------------------+ |
| 27 | +// INCLUDE |
| 28 | +//--------------------------------------------------------------------+ |
| 29 | +#include "FreeRTOS.h" |
| 30 | +#include "task.h" |
| 31 | +#include "common/tusb_common.h" |
| 32 | + |
| 33 | +void vApplicationMallocFailedHook(void) { |
| 34 | + taskDISABLE_INTERRUPTS(); |
| 35 | + TU_ASSERT(false,); |
| 36 | +} |
| 37 | + |
| 38 | +void vApplicationStackOverflowHook(xTaskHandle pxTask, char *pcTaskName) { |
| 39 | + (void) pxTask; |
| 40 | + (void) pcTaskName; |
| 41 | + |
| 42 | + taskDISABLE_INTERRUPTS(); |
| 43 | + TU_ASSERT(false,); |
| 44 | +} |
| 45 | + |
| 46 | +/* configSUPPORT_STATIC_ALLOCATION is set to 1, so the application must provide an |
| 47 | + * implementation of vApplicationGetIdleTaskMemory() to provide the memory that is |
| 48 | + * used by the Idle task. */ |
| 49 | +void vApplicationGetIdleTaskMemory(StaticTask_t **ppxIdleTaskTCBBuffer, StackType_t **ppxIdleTaskStackBuffer, |
| 50 | + uint32_t *pulIdleTaskStackSize) { |
| 51 | + /* If the buffers to be provided to the Idle task are declared inside this |
| 52 | + * function then they must be declared static - otherwise they will be allocated on |
| 53 | + * the stack and so not exists after this function exits. */ |
| 54 | + static StaticTask_t xIdleTaskTCB; |
| 55 | + static StackType_t uxIdleTaskStack[configMINIMAL_STACK_SIZE]; |
| 56 | + |
| 57 | + /* Pass out a pointer to the StaticTask_t structure in which the Idle task's |
| 58 | + state will be stored. */ |
| 59 | + *ppxIdleTaskTCBBuffer = &xIdleTaskTCB; |
| 60 | + |
| 61 | + /* Pass out the array that will be used as the Idle task's stack. */ |
| 62 | + *ppxIdleTaskStackBuffer = uxIdleTaskStack; |
| 63 | + |
| 64 | + /* Pass out the size of the array pointed to by *ppxIdleTaskStackBuffer. |
| 65 | + Note that, as the array is necessarily of type StackType_t, |
| 66 | + configMINIMAL_STACK_SIZE is specified in words, not bytes. */ |
| 67 | + *pulIdleTaskStackSize = configMINIMAL_STACK_SIZE; |
| 68 | +} |
| 69 | + |
| 70 | +/* configSUPPORT_STATIC_ALLOCATION and configUSE_TIMERS are both set to 1, so the |
| 71 | + * application must provide an implementation of vApplicationGetTimerTaskMemory() |
| 72 | + * to provide the memory that is used by the Timer service task. */ |
| 73 | +void vApplicationGetTimerTaskMemory(StaticTask_t **ppxTimerTaskTCBBuffer, StackType_t **ppxTimerTaskStackBuffer, |
| 74 | + uint32_t *pulTimerTaskStackSize) { |
| 75 | + /* If the buffers to be provided to the Timer task are declared inside this |
| 76 | + * function then they must be declared static - otherwise they will be allocated on |
| 77 | + * the stack and so not exists after this function exits. */ |
| 78 | + static StaticTask_t xTimerTaskTCB; |
| 79 | + static StackType_t uxTimerTaskStack[configTIMER_TASK_STACK_DEPTH]; |
| 80 | + |
| 81 | + /* Pass out a pointer to the StaticTask_t structure in which the Timer |
| 82 | + task's state will be stored. */ |
| 83 | + *ppxTimerTaskTCBBuffer = &xTimerTaskTCB; |
| 84 | + |
| 85 | + /* Pass out the array that will be used as the Timer task's stack. */ |
| 86 | + *ppxTimerTaskStackBuffer = uxTimerTaskStack; |
| 87 | + |
| 88 | + /* Pass out the size of the array pointed to by *ppxTimerTaskStackBuffer. |
| 89 | + Note that, as the array is necessarily of type StackType_t, |
| 90 | + configTIMER_TASK_STACK_DEPTH is specified in words, not bytes. */ |
| 91 | + *pulTimerTaskStackSize = configTIMER_TASK_STACK_DEPTH; |
| 92 | +} |
| 93 | + |
| 94 | +#if CFG_TUSB_MCU == OPT_MCU_RX63X | CFG_TUSB_MCU == OPT_MCU_RX65X |
| 95 | +#include "iodefine.h" |
| 96 | +void vApplicationSetupTimerInterrupt(void) |
| 97 | +{ |
| 98 | + /* Enable CMT0 */ |
| 99 | + SYSTEM.PRCR.WORD = (0xA5u<<8) | TU_BIT(1); |
| 100 | + MSTP(CMT0) = 0; |
| 101 | + SYSTEM.PRCR.WORD = (0xA5u<<8); |
| 102 | + |
| 103 | + CMT0.CMCNT = 0; |
| 104 | + CMT0.CMCOR = (unsigned short)(((configPERIPHERAL_CLOCK_HZ/configTICK_RATE_HZ)-1)/128); |
| 105 | + CMT0.CMCR.WORD = TU_BIT(6) | 2; |
| 106 | + IR(CMT0, CMI0) = 0; |
| 107 | + IPR(CMT0, CMI0) = configKERNEL_INTERRUPT_PRIORITY; |
| 108 | + IEN(CMT0, CMI0) = 1; |
| 109 | + CMT.CMSTR0.BIT.STR0 = 1; |
| 110 | +} |
| 111 | +#endif |
0 commit comments