File indexing completed on 2025-05-11 08:23:53
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028 #define NDEBUG
0029
0030 #include <bsp/bestcomm.h>
0031
0032 #include <string.h>
0033
0034 #include <bsp/mpc5200.h>
0035
0036 static void bestcomm_irq_handler(void *arg)
0037 {
0038 bestcomm_irq *self = arg;
0039
0040 bestcomm_irq_clear(self);
0041 bestcomm_irq_wakeup_event_task(self);
0042 }
0043
0044 void bestcomm_irq_create(bestcomm_irq *self, int task_index)
0045 {
0046 assert(task_index >= 0 && task_index <= 15);
0047
0048 self->task_index = task_index;
0049 self->event_task_id = rtems_task_self();
0050 bestcomm_glue_irq_install(task_index, bestcomm_irq_handler, self);
0051 }
0052
0053 void bestcomm_irq_destroy(const bestcomm_irq *self)
0054 {
0055 bestcomm_glue_irq_install(self->task_index, NULL, NULL);
0056 }
0057
0058 void bestcomm_task_create(bestcomm_task *self, TaskId task_index)
0059 {
0060 self->task_control_register = &mpc5200.sdma.tcr[task_index];
0061 self->variable_table = BESTCOMM_TASK_ENTRY_TABLE[task_index].var_table;
0062 self->task_index = task_index;
0063 self->tdt_begin = NULL;
0064 self->tdt_opcode_count = 0;
0065 bestcomm_task_stop(self);
0066 bestcomm_irq_create(&self->irq, task_index);
0067 }
0068
0069 void bestcomm_task_create_and_load(
0070 bestcomm_task *self,
0071 TaskId task_index,
0072 const uint32_t *tdt_source_begin,
0073 size_t tdt_size
0074 )
0075 {
0076 bestcomm_task_create(self, task_index);
0077 bestcomm_task_load(self, tdt_source_begin, tdt_size);
0078 }
0079
0080 void bestcomm_task_destroy(bestcomm_task *self)
0081 {
0082 bestcomm_task_stop(self);
0083 bestcomm_task_free_tdt(self);
0084 }
0085
0086 void bestcomm_task_load(bestcomm_task *self, const uint32_t *tdt_source_begin, size_t tdt_size)
0087 {
0088 assert(tdt_size % 4 == 0);
0089
0090 bestcomm_task_irq_disable(self);
0091 bestcomm_task_stop(self);
0092 bestcomm_task_irq_clear(self);
0093 bestcomm_task_irq_enable(self);
0094 bestcomm_task_free_tdt(self);
0095 bestcomm_task_clear_variables(self);
0096
0097 self->tdt_opcode_count = tdt_size / 4;
0098
0099 self->tdt_begin = bestcomm_malloc(tdt_size);
0100 assert(self->tdt_begin != NULL);
0101 uint32_t *tdt_last = self->tdt_begin + self->tdt_opcode_count - 1;
0102
0103 memcpy(self->tdt_begin, tdt_source_begin, tdt_size);
0104
0105 volatile bestcomm_task_entry *entry = bestcomm_task_get_task_entry(self);
0106 entry->tdt_begin = self->tdt_begin;
0107 entry->tdt_last = tdt_last;
0108
0109 bestcomm_task_clear_pragmas(self);
0110 bestcomm_task_set_priority(self, 0);
0111 }
0112
0113 void bestcomm_task_clear_variables(const bestcomm_task *self)
0114 {
0115 int i;
0116
0117 for (i = 0; i < 32; ++i) {
0118 (*self->variable_table)[i] = 0;
0119 }
0120 }