It's been quite a while, but IIRC for direct bit-banging you need to be able to sample at about 8x the bit speed for a reliable bit banging UART receiving an 8 bit byte. So using the HP timer running at 1mSec means 8mSec/bit.
I'm not completely sure what you mean, if the slave samples the input at the middle of each bit sent from the master, it would work wouldn't it? The start bit will be syncronised and the timing accuracy of sending the bits is pretty good, and I'm only sending maybe 64 bits at the most.
where do you place your code for void master_send_bit()? And where do you call it from?
I mean what is the start action in the master to send the data to teh slave?
In wrappers.c, so that they get compiled as normal ARM code. srsa explained it better, I can't remember which thread though.
As for the start action, I'm still working on it right now. Here's what I have so far, init_LED_flasher is called from kbd.c on a certain button-press (for testing):
void init_LED_flasher()
{
if (start_LED_flasher)
{
start_LED_flasher = 0;
master_begin_transmission();
}
}
int master_current_bit = 0;
int master_wait_untill = 65536;
void master_send_bit();
void master_begin_transmission();
void master_begin_transmission_();
unsigned short master_message_buffer = 54321; //Just a random number at the moment
void __attribute__((optimize("O0"))) master_begin_transmission()
{
while (*(int*)0xc0242014 > 1024)
{
//wait till it's at the start, wrap will coded later
}
*((volatile int *) AF_LED_ADDRESS) = LED_ON; //Signal slave which will check every 10ms or so
_SetHPTimerAfterTimeout(0,master_wait_untill,master_begin_transmission_,master_begin_transmission_,0);
master_wait_untill+=1024;
}
void master_begin_transmission_()
{
*((volatile int *) AF_LED_ADDRESS) = LED_OFF; //Signal slave, which will wait 1536uS before starting to sample the bits
_SetHPTimerAfterTimeout(0,master_wait_untill,master_send_bit,master_send_bit,0);
}
void master_send_bit()
{
if (master_message_buffer & (1 << master_current_bit)) //get the current bit
{
*((volatile int *) AF_LED_ADDRESS) = LED_ON;
}
else
{
*((volatile int *) AF_LED_ADDRESS) = LED_OFF;
}
if (master_current_bit < 16) //16 bits for now
{
master_current_bit++;
master_wait_untill+=1024;
_SetHPTimerAfterTimeout(0,master_wait_untill,master_send_bit,master_send_bit,0);
}
else
{
master_wait_untill = 65536; //set it back to how it was before
start_LED_flasher = 1; //allow it to run again
}
}
The number 65536 is unnescesarily high, but just for testing.
Yesterday my new oscilloscope arrived. If my 7 years old daughter will let me at the easterdays I will find some time to go ahead with my mikcorcontroller to steer the S110 project.
What oscilloscope did you get? I'm going to write the accompanying code for the slave today hopefully, if it works it should be able to listen to a microcontroller fairly well (as long as the microcontroller's clock is accurate enough)
What are the parameters of _SetHPAfterTimeout and why two times master_send_bit as callback are entered here, what does the last 0 mean?
See
here. The last zero doesn't mean anything, apparently it doesn't do anything.
The HP Timer stuff in which trunk is it? What HP timer functions are available, I remember in one thread there were few?
I think they're already in there but if not just add this to wrappers.c (or just add whatever's not there)
extern int _SetTimerAfter(int delay, int(*good_cb)(int, int), int(*bad_cb)(int, int), int whatever);
extern int _SetTimerWhen(int time, int(*good_cb)(int, int), int(*bad_cb)(int, int), int whatever);
extern int _CancelTimer(int);
extern int _SetHPTimerAfterNow(int delay, int(*good_cb)(int, int), int(*bad_cb)(int, int), int whatever);
extern int _SetHPTimerAfterTimeout(int time_base, int delay, int(*good_cb)(int, int), int(*bad_cb)(int, int), int whatever);
extern int _CancelHPTimer(int);
And you will need to add these to stubs_entry_2.S if they aren't already there:
NHSTUB(SetTimerAfter, )
NHSTUB(SetTimerWhen, )
NHSTUB(CancelTimer, )
NHSTUB(SetHPTimerAfterNow, )
NHSTUB(SetHPTimerAfterTimeout, )
NHSTUB(CancelHPTimer, )
you will need to find the addresses for them from the functions by address.csv file. They are different from the ones on mine as the firmware version is different, so I backspaced them.