Skip to content

Changed packRow() to work in bytes not words #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 8 additions & 13 deletions MPLAB.X/direct.c
Original file line number Diff line number Diff line change
Expand Up @@ -244,33 +244,28 @@ void writeRow( void) {
*/
void packRow( uint32_t address, uint8_t *data, uint8_t data_count) {
// copy only the bytes from the current data packet up to the boundary of a row
uint8_t index = (address & 0x3e)>>1;
uint8_t index = (address & 0x3f);
uint32_t new_row = (address & 0xfffc0)>>1;
uint8_t * bytes=(uint8_t)row;
if (new_row != row_address) {
writeRow();
row_address = new_row;
}
// ensure data is always even (rounding up)
data_count = (data_count+1) & 0xfe;
// copy data up to the row boundaries
while ((data_count > 0) && (index < ROW_SIZE)){
uint16_t word = *data++;
word += ((uint16_t)(*data++)<<8);
row[index++] = word;
data_count -= 2;
while ((data_count > 0) && (index < ROW_SIZE*2)){
bytes[index++] = *data++;;
data_count --;
}
// if a complete row was filled, proceed to programming
if (index == ROW_SIZE) {
if (index == ROW_SIZE*2) {
writeRow();
// next consider the split row scenario
if (data_count > 0) { // leftover must spill into next row
row_address += ROW_SIZE;
index = 0;
while (data_count > 0){
uint16_t word = *data++;
word += ((uint16_t)(*data++)<<8);
row[index++] = word;
data_count -= 2;
bytes[index++] = *data++;
data_count --;
}
}
}
Expand Down