fsw_misc.c
138 lines
| 5.9 KiB
| text/x-c
|
CLexer
/ src / fsw_misc.c
paul@pc-solar1.lab-lpp.local
|
r5 | #include <fsw_misc.h> | ||
#include <fsw_params.h> | ||||
extern rtems_id Task_id[]; /* array of task ids */ | ||||
extern int fdSPW; | ||||
paul@pc-solar1.lab-lpp.local
|
r16 | extern TMHeader_t housekeeping_header; | ||
extern char housekeeping_data[]; | ||||
paul@pc-solar1.lab-lpp.local
|
r5 | |||
int configure_timer(gptimer_regs_t *gptimer_regs, unsigned char timer, unsigned int clock_divider, | ||||
unsigned char interrupt_level, rtems_isr (*timer_isr)() ) | ||||
{ // configure the timer for the waveforms simulation | ||||
rtems_status_code status; | ||||
rtems_isr_entry old_isr_handler; | ||||
status = rtems_interrupt_catch( timer_isr, interrupt_level, &old_isr_handler) ; // see sparcv8.pdf p.76 for interrupt levels | ||||
//if (status==RTEMS_SUCCESSFUL) PRINTF("In configure_timer_for_wf_simulation *** rtems_interrupt_catch successfullly configured\n") | ||||
gptimer_regs->timer[timer].reload = clock_divider; // base clock frequency is 1 MHz | ||||
gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | 0x00000010; // clear pending IRQ if any | ||||
gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | 0x00000004; // LD load value from the reload register | ||||
gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | 0x00000001; // EN enable the timer | ||||
gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | 0x00000002; // RS restart | ||||
gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | 0x00000008; // IE interrupt enable | ||||
return 1; | ||||
} | ||||
void print_statistics(spw_stats *stats) | ||||
{ | ||||
//printf(" ******** STATISTICS ******** \n"); | ||||
printf("Transmit link errors: %i\n", stats->tx_link_err); | ||||
printf("Receiver RMAP header CRC errors: %i\n", stats->rx_rmap_header_crc_err); | ||||
printf("Receiver RMAP data CRC errors: %i\n", stats->rx_rmap_data_crc_err); | ||||
printf("Receiver EEP errors: %i\n", stats->rx_eep_err); | ||||
printf("Receiver truncation errors: %i\n", stats->rx_truncated); | ||||
printf("Parity errors: %i\n", stats->parity_err); | ||||
printf("Escape errors: %i\n", stats->escape_err); | ||||
printf("Credit errors: %i\n", stats->credit_err); | ||||
printf("Disconnect errors: %i\n", stats->disconnect_err); | ||||
printf("Write synchronization errors: %i\n", stats->write_sync_err); | ||||
printf("Early EOP/EEP: %i\n", stats->early_ep); | ||||
printf("Invalid Node Address: %i\n", stats->invalid_address); | ||||
printf("Packets transmitted: %i\n", stats->packets_sent); | ||||
printf("Packets received: %i\n", stats->packets_received); | ||||
} | ||||
int send_console_outputs_on_serial_port() // Send the console outputs on the serial port | ||||
{ | ||||
struct apbuart_regs_str *apbuart_regs; | ||||
apbuart_regs = (struct apbuart_regs_str *) REGS_ADDR_APBUART; | ||||
apbuart_regs->ctrl = apbuart_regs->ctrl & APBUART_CTRL_REG_MASK_DB; | ||||
PRINTF("\n\n\n\n\nIn INIT *** Now the console is on port COM1\n") | ||||
return 0; | ||||
} | ||||
paul@pc-solar1.lab-lpp.local
|
r9 | rtems_task stat_task(rtems_task_argument argument) | ||
paul@pc-solar1.lab-lpp.local
|
r5 | { | ||
int i; | ||||
i = 0; | ||||
PRINTF("In STAT *** \n") | ||||
while(1){ | ||||
rtems_task_wake_after(1000); | ||||
PRINTF1("%d\n", i) | ||||
paul@pc-solar1.lab-lpp.local
|
r12 | if (i == 2) { | ||
#ifdef PRINT_TASK_STATISTICS | ||||
paul@pc-solar1.lab-lpp.local
|
r5 | rtems_cpu_usage_report(); | ||
paul@pc-solar1.lab-lpp.local
|
r12 | rtems_cpu_usage_reset(); | ||
#endif | ||||
paul@pc-solar1.lab-lpp.local
|
r5 | i = 0; | ||
} | ||||
else i++; | ||||
} | ||||
} | ||||
paul@pc-solar1.lab-lpp.local
|
r16 | |||
rtems_task hous_task(rtems_task_argument argument) | ||||
{ | ||||
rtems_status_code status; | ||||
paul@pc-solar1.lab-lpp.local
|
r5 | |||
paul@pc-solar1.lab-lpp.local
|
r16 | spw_ioctl_pkt_send spw_ioctl_send; | ||
rtems_name name; | ||||
rtems_id period; | ||||
name = rtems_build_name( 'H', 'O', 'U', 'S' ); | ||||
status = rtems_rate_monotonic_create( name, &period ); | ||||
if( status != RTEMS_SUCCESSFUL ) { | ||||
printf( "rtems_rate_monotonic_create failed with status of %d\n", status ); | ||||
exit( 1 ); | ||||
} | ||||
paul@pc-solar1.lab-lpp.local
|
r5 | |||
paul@pc-solar1.lab-lpp.local
|
r16 | // filling the structure for the spacewire transmission | ||
spw_ioctl_send.hlen = TM_HEADER_LEN + 4; // + 4 is for the protocole extra header | ||||
spw_ioctl_send.hdr = (char*) &housekeeping_header; | ||||
spw_ioctl_send.dlen = LENGTH_TM_LFR_HK - 10 + 1; | ||||
spw_ioctl_send.data = housekeeping_data; | ||||
housekeeping_header.targetLogicalAddress = CCSDS_DESTINATION_ID; | ||||
housekeeping_header.protocolIdentifier = 0x02; | ||||
housekeeping_header.reserved = 0x00; | ||||
housekeeping_header.userApplication = 0x00; | ||||
housekeeping_header.packetID[0] = 0x0c; | ||||
housekeeping_header.packetID[1] = 0xc4; | ||||
housekeeping_header.packetSequenceControl[0] = 0xc0; | ||||
housekeeping_header.packetSequenceControl[1] = 0x00; | ||||
housekeeping_header.packetLength[0] = 0x00; | ||||
housekeeping_header.packetLength[1] = 0x77; | ||||
housekeeping_header.dataFieldHeader[0] = 0x10; | ||||
housekeeping_header.dataFieldHeader[1] = 0x03; | ||||
housekeeping_header.dataFieldHeader[2] = 0x19; | ||||
housekeeping_header.dataFieldHeader[3] = 0x00; | ||||
printf("In HOUS ***\n"); | ||||
while(1){ // launch the rate monotonic task | ||||
if ( rtems_rate_monotonic_period( period, HK_PERIOD ) == RTEMS_TIMEOUT ){ | ||||
printf( "ERR *** in hous_task *** RTEMS_TIMEOUT\n" ); | ||||
break; | ||||
} | ||||
housekeeping_header.dataFieldHeader[4] = (unsigned char) (time_management_regs->coarse_time>>24); | ||||
housekeeping_header.dataFieldHeader[5] = (unsigned char) (time_management_regs->coarse_time>>16); | ||||
housekeeping_header.dataFieldHeader[6] = (unsigned char) (time_management_regs->coarse_time>>8); | ||||
housekeeping_header.dataFieldHeader[7] = (unsigned char) (time_management_regs->coarse_time); | ||||
housekeeping_header.dataFieldHeader[8] = (unsigned char) (time_management_regs->fine_time>>8); | ||||
housekeeping_header.dataFieldHeader[9] = (unsigned char) (time_management_regs->fine_time); | ||||
status = write_spw(&spw_ioctl_send); | ||||
} | ||||
status = rtems_rate_monotonic_delete( period ); | ||||
if ( status != RTEMS_SUCCESSFUL ) { | ||||
printf( "rtems_rate_monotonic_delete failed with status of %d.\n", status ); | ||||
exit( 1 ); | ||||
} | ||||
status = rtems_task_delete( RTEMS_SELF ); // should not return | ||||
printf( "rtems_task_delete returned with status of %d.\n", status ); | ||||
exit( 1 ); | ||||
} | ||||