1 /* Synchronize TC_CDIV divided sample clock with the SOF of the packet */
3 #include <lib_AT91SAM7.h>
6 #include "../openpcd.h"
10 static u_int8_t enabled
;
12 static void pio_data_change(u_int32_t pio
)
14 DEBUGP("PIO_FRAME_IRQ: ");
15 /* we get one interrupt for each change. If now, after the
16 * change the level is high, then it must have been a rising
18 if (*AT91C_PIOA_PDSR
& OPENPICC_PIO_FRAME
) {
19 *AT91C_TC0_CCR
= AT91C_TC_SWTRG
;
20 DEBUGPCR("CDIV_SYNC_FLIP SWTRG CV=0x%08x",
27 static void __ramfunc
cdsync_cb(void)
30 if (*AT91C_PIOA_ISR
& OPENPICC_PIO_FRAME
) {
31 DEBUGP("PIO_FRAME_IRQ: ");
32 /* we get one interrupt for each change. If now, after the
33 * change the level is high, then it must have been a rising
35 if (*AT91C_PIOA_PDSR
& OPENPICC_PIO_FRAME
) {
36 *AT91C_TC0_CCR
= AT91C_TC_SWTRG
;
37 DEBUGPCR("CDIV_SYNC_FLIP SWTRG CV=0x%08x",
46 void tc_cdiv_sync_reset(void)
49 u_int32_t tmp
= *AT91C_PIOA_ISR
;
51 DEBUGPCRF("CDIV_SYNC_FLOP");
53 /* reset the hardware flipflop */
54 AT91F_PIO_ClearOutput(AT91C_BASE_PIOA
,
55 OPENPICC_PIO_SSC_DATA_CONTROL
);
56 for (i
= 0; i
< 0xff; i
++) ;
57 AT91F_PIO_SetOutput(AT91C_BASE_PIOA
,
58 OPENPICC_PIO_SSC_DATA_CONTROL
);
62 void tc_cdiv_sync_disable(void)
65 *AT91C_PIOA_IDR
= OPENPICC_PIO_FRAME
;
68 void tc_cdiv_sync_enable(void)
72 DEBUGPCRF("CDIV_SYNC_ENABLE ");
74 *AT91C_PIOA_IER
= OPENPICC_PIO_FRAME
;
77 extern void (*fiq_handler
)(void);
78 void tc_cdiv_sync_init(void)
80 DEBUGPCRF("initializing");
88 AT91F_AIC_ConfigureIt(AT91C_BASE_AIC
, AT91C_ID_PIOA
,
89 AT91C_AIC_PRIOR_HIGHEST
,
90 AT91C_AIC_SRCTYPE_INT_HIGH_LEVEL
, &cdsync_cb
);
93 AT91F_AIC_ConfigureIt(AT91C_BASE_AIC
, AT91C_ID_FIQ
,
94 //0, AT91C_AIC_SRCTYPE_INT_HIGH_LEVEL, &cdsync_cb);
95 0, AT91C_AIC_SRCTYPE_INT_HIGH_LEVEL
, &fiq_handler
);
96 /* enable fast forcing for PIOA interrupt */
97 *AT91C_AIC_FFER
= (1 << AT91C_ID_PIOA
);
99 /* register pio irq handler */
100 pio_irq_register(OPENPICC_PIO_FRAME
, &pio_data_change
);
102 AT91F_AIC_EnableIt(AT91C_BASE_AIC
, AT91C_ID_PIOA
);
104 tc_cdiv_sync_disable();